• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PROXY_CHANNEL_MANAGER_H
16 #define PROXY_CHANNEL_MANAGER_H
17 
18 #include "common_list.h"
19 #include "softbus_adapter_thread.h"
20 #include "softbus_common.h"
21 #include "softbus_def.h"
22 #include "softbus_utils.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define UUID_STRING_LEN 38
29 // the length of the latter half of the hexString representing the sha256 hash value of mac address
30 #define BT_MAC_MAX_LEN 33
31 
32 typedef struct {
33     uint32_t requestId;
34     char brMac[BT_MAC_MAX_LEN];
35     char uuid[UUID_STRING_LEN];
36     uint64_t timeoutMs;
37 } ProxyChannelParam;
38 
39 typedef enum {
40     PROXY_CHANNEL_CONNECTING,
41     PROXY_CHANNEL_CONNECTED,
42     PROXY_CHANNEL_DISCONNECTING,
43     PROXY_CHANNEL_DISCONNECTED,
44     PROXY_CHANNEL_MAX_STATE
45 } ProxyChannelState;
46 
47 struct ProxyChannel {
48     uint32_t requestId;
49     uint32_t channelId;
50     char brMac[BT_MAC_MAX_LEN];
51     char uuid[UUID_STRING_LEN];
52     int32_t (*send)(struct ProxyChannel *channel, const uint8_t *data, uint32_t dataLen);
53     void (*close)(struct ProxyChannel *channel);
54 };
55 
56 struct ProxyConnection {
57     struct ProxyChannel proxyChannel;
58     char brMac[BT_MAC_LEN];
59     SoftBusMutex lock;
60     uint32_t channelId;
61     void (*reference)(struct ProxyConnection *proxyConnection);
62     void (*dereference)(struct ProxyConnection *proxyConnection);
63     uint32_t refCount;
64     ProxyChannelState state;
65     int32_t socketHandle;
66     ListNode node;
67 };
68 
69 typedef struct {
70     void (*onProxyChannelDataReceived)(struct ProxyChannel *channel, const uint8_t *data, uint32_t dataLen);
71     void (*onProxyChannelDisconnected)(struct ProxyChannel *channel, int32_t reason);
72     void (*onProxyChannelReconnected)(char *addr, struct ProxyChannel *channel);
73 } ProxyConnectListener;
74 
75 typedef struct {
76     void (*onOpenSuccess)(uint32_t requestId, struct ProxyChannel *channel);
77     void (*onOpenFail)(uint32_t requestId, int32_t reason);
78 } OpenProxyChannelCallback;
79 
80 typedef struct {
81     uint32_t requestId;
82     bool isInnerRequest;
83     uint32_t innerRetryNum;
84     bool isRealMac;
85     char brMac[BT_MAC_LEN];
86     char brHashMac[BT_MAC_MAX_LEN];
87     char uuid[UUID_STRING_LEN];
88     uint64_t timeoutMs;
89     OpenProxyChannelCallback result;
90     bool isAclConnected;
91     ListNode node;
92 } ProxyConnectInfo;
93 
94 typedef struct {
95     uint32_t (*generateRequestId)(void);
96     int32_t (*openProxyChannel)(ProxyChannelParam *param, const OpenProxyChannelCallback *callback);
97     int32_t (*registerProxyChannelListener)(ProxyConnectListener *listener);
98 
99     // inner
100     SoftBusList *proxyConnectionList;
101     struct ProxyConnection *(*getConnectionById)(uint32_t channelId);
102     // current process request info
103     ProxyConnectInfo *proxyChannelRequestInfo;
104     ListNode reconnectDeviceInfos;
105 } ProxyChannelManager;
106 
107 ProxyChannelManager *GetProxyChannelManager(void);
108 int32_t ProxyChannelManagerInit(void);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 #endif /* PROXY_CHANNEL_MANAGER_H */