• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #ifndef SOFTBUS_CONN_INTERFACE_H
17 #define SOFTBUS_CONN_INTERFACE_H
18 #include <stdint.h>
19 #include "softbus_common.h"
20 #include "softbus_def.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 typedef enum {
28     MODULE_TRUST_ENGINE = 1,
29     MODULE_HICHAIN = 2,
30     MODULE_AUTH_SDK = 3,
31     MODULE_AUTH_CONNECTION = 5,
32     MODULE_MESSAGE_SERVICE = 8,
33     MODULE_AUTH_CHANNEL = 8,
34     MODULE_AUTH_MSG = 9,
35     MODULE_BLUETOOTH_MANAGER = 9,
36     MODULE_CONNECTION = 11,
37     MODULE_DIRECT_CHANNEL = 12,
38     MODULE_PROXY_CHANNEL = 13,
39     MODULE_DEVICE_AUTH = 14,
40     MODULE_P2P_LINK = 15,
41     MODULE_P2P_LISTEN = 16,
42     MODULE_UDP_INFO = 17,
43     MODULE_TIME_SYNC = 18,
44     MODULE_PKG_VERIFY = 20,
45     MODULE_BLE_NET = 100,
46     MODULE_BLE_CONN = 101
47 } ConnModule;
48 
49 typedef enum {
50     CONNECT_TCP = 1,
51     CONNECT_BR,
52     CONNECT_BLE,
53     CONNECT_P2P,
54     CONNECT_TYPE_MAX
55 } ConnectType;
56 
57 typedef struct {
58     int32_t isAvailable;
59     int32_t isServer;
60     ConnectType type;
61     union {
62         struct BrInfo {
63             char brMac[BT_MAC_LEN];
64         } brInfo;
65         struct BleInfo {
66             char bleMac[BT_MAC_LEN];
67             char deviceIdHash[UDID_HASH_LEN];
68         } bleInfo;
69         struct IpInfo {
70             char ip[IP_LEN];
71             int32_t port;
72             int32_t fd;
73             int32_t moduleId; /* For details, see {@link ListenerModule}. */
74         } ipInfo;
75     } info;
76 } ConnectionInfo;
77 
78 typedef struct {
79     void (*OnConnected)(uint32_t connectionId, const ConnectionInfo *info);
80     void (*OnDisconnected)(uint32_t connectionId, const ConnectionInfo *info);
81     void (*OnDataReceived)(uint32_t connectionId, ConnModule moduleId, int64_t seq, char *data, int32_t len);
82 } ConnectCallback;
83 
84 typedef enum {
85     CONN_DEFAULT = 0,
86     CONN_LOW,
87     CONN_MIDDLE,
88     CONN_HIGH
89 } SendPriority;
90 
91 typedef enum {
92     CONN_SIDE_ANY = 0,
93     CONN_SIDE_CLIENT,
94     CONN_SIDE_SERVER
95 } ConnSideType;
96 
97 typedef struct {
98     int32_t module; // ConnModule
99     int64_t seq;
100     int32_t flag; // SendPriority
101     int32_t pid;
102     uint32_t len;
103     char *buf;
104 } ConnPostData;
105 
106 typedef struct {
107     void (*OnConnectSuccessed)(uint32_t requestId, uint32_t connectionId, const ConnectionInfo *info);
108     void (*OnConnectFailed)(uint32_t requestId, int32_t reason);
109 } ConnectResult;
110 
111 typedef struct {
112     ConnectType type;
113     union {
114         struct BrOption {
115             char brMac[BT_MAC_LEN];
116             ConnSideType sideType;
117         } brOption;
118         struct BleOption {
119             char bleMac[BT_MAC_LEN];
120             char deviceIdHash[UDID_HASH_LEN];
121         } bleOption;
122         struct IpOption {
123             char ip[IP_LEN];
124             int32_t port;
125             int32_t moduleId; /* For details, see {@link ListenerModule}. */
126         } ipOption;
127     } info;
128 } ConnectOption;
129 
130 typedef struct {
131     ConnectType type;
132     union {
133         struct IpListenerInfo {
134             char ip[IP_LEN];
135             int32_t port;
136             int32_t moduleId; /* For details, see {@link ListenerModule}. */
137         } ipListenerInfo;
138     } info;
139 } LocalListenerInfo;
140 
141 uint32_t ConnGetHeadSize(void);
142 
143 int32_t ConnServerInit(void);
144 
145 void ConnServerDeinit(void);
146 
147 int32_t ConnSetConnectCallback(ConnModule moduleId, const ConnectCallback *callback);
148 
149 void ConnUnSetConnectCallback(ConnModule moduleId);
150 
151 int32_t ConnPostBytes(uint32_t connectionId, ConnPostData *data);
152 
153 int32_t ConnTypeIsSupport(ConnectType type);
154 
155 int32_t ConnGetConnectionInfo(uint32_t connectionId, ConnectionInfo *info);
156 
157 uint32_t ConnGetNewRequestId(ConnModule moduleId);
158 
159 int32_t ConnConnectDevice(const ConnectOption *option, uint32_t requestId, const ConnectResult *result);
160 
161 int32_t ConnDisconnectDevice(uint32_t connectionId);
162 
163 int32_t ConnDisconnectDeviceAllConn(const ConnectOption *option);
164 
165 int32_t ConnStopLocalListening(const LocalListenerInfo *info);
166 
167 int32_t ConnStartLocalListening(const LocalListenerInfo *info);
168 
169 bool CheckActiveConnection(const ConnectOption *option);
170 
171 #ifdef __cplusplus
172 #if __cplusplus
173 }
174 #endif /* __cplusplus */
175 #endif /* __cplusplus */
176 
177 #endif
178