1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef BR_PROXY_H 16 #define BR_PROXY_H 17 18 #include "trans_log.h" 19 #ifdef __cplusplus 20 extern "C" { 21 #endif /* __cplusplus */ 22 23 #define BR_MAC_LEN 33 24 #define UUID_LEN 38 25 #define ERR_DESC_STR_LEN 128 26 27 #define MAC_MIN_LENGTH 12 // 无分隔符格式最小长度 28 #define MAC_MAX_LENGTH 17 // 标准格式最大长度 29 #define MAC_SHA256_LEN 32 // MAC经SHA-256转换后长度 30 #define UUID_STD_LENGTH 36 // 标准格式UUID长度(含连字符) 31 #define UUID_NO_HYPHEN_LENGTH 32 // 无连字符UUID长度 32 33 typedef enum { 34 CHANNEL_WAIT_RESUME = 0, 35 CHANNEL_RESUME, 36 CHANNEL_EXCEPTION_SOFTWARE_FAILED, 37 CHANNEL_BR_NO_PAIRED, 38 } ChannelState; 39 40 typedef enum { 41 LINK_BR = 0, 42 } TSLinkType; 43 44 // 对应 TypeScript 中的 ChannelInfo 接口 45 typedef struct { 46 TSLinkType linktype; 47 char peerBRMacAddr[BR_MAC_LEN]; 48 char peerBRUuid[UUID_LEN]; 49 int32_t recvPri; 50 bool recvPriSet; // 用于标记 recvPri 是否被设置 51 } BrProxyChannelInfo; 52 53 typedef enum { 54 DATA_RECEIVE, 55 CHANNEL_STATE, 56 LISTENER_TYPE_MAX, 57 } ListenerType; 58 59 #define COMM_PKGNAME_BRPROXY "BrProxyPkgName" 60 #define PKGNAME_MAX_LEN 30 61 #define DEFAULT_CHANNEL_ID (-1) 62 #define BR_PROXY_SEND_MAX_LEN (4 * 1024 * 1024) 63 #define COMM_PKGNAME_PUSH "PUSH_SERVICE" 64 65 typedef struct { 66 int32_t (*onChannelOpened)(int32_t sessionId, int32_t channelId, int32_t result); 67 void (*onDataReceived)(int32_t channelId, const char *data, uint32_t dataLen); 68 void (*onChannelStatusChanged)(int32_t channelId, int32_t state); 69 } IBrProxyListener; 70 71 typedef struct { 72 int32_t (*queryPermission)(const char *bundleName, bool *isEmpowered); 73 } PermissonHookCb; 74 75 int32_t OpenBrProxy(int32_t sessionId, BrProxyChannelInfo *channelInfo, IBrProxyListener *listener); 76 int32_t CloseBrProxy(int32_t channelId); 77 int32_t SendBrProxyData(int32_t channelId, char* data, uint32_t dataLen); 78 int32_t SetListenerState(int32_t channelId, ListenerType type, bool isEnable); 79 bool IsProxyChannelEnabled(int32_t uid); 80 int32_t RegisterAccessHook(PermissonHookCb *cb); 81 82 int32_t ClientTransOnBrProxyOpened(int32_t channelId, const char *brMac, const char *uuid, int32_t result); 83 int32_t ClientTransBrProxyDataReceived(int32_t channelId, const uint8_t *data, uint32_t len); 84 int32_t ClientTransBrProxyChannelChange(int32_t channelId, int32_t errCode); 85 int32_t ClientTransBrProxyQueryPermission(const char *bundleName, bool *isEmpowered); 86 87 #ifdef __cplusplus 88 } 89 #endif /* __cplusplus */ 90 #endif // BR_PROXY_H