• 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 /**
17  * @addtogroup SoftBus
18  * @{
19  *
20  * @brief Provides high-speed, secure communication between devices.
21  *
22  * This module implements unified distributed communication capability management between nearby devices, and provides
23  * link-independent device discovery and transmission interfaces to support service publishing and data transmission.
24  *
25  * @since 1.0
26  * @version 1.0
27  */
28 
29 /**
30  * @file softbus_common.h
31  *
32  * @brief Declares common APIs for the Intelligent Soft Bus.
33  *
34  * This file provides common functions and constants for each submodule of the Intelligent Soft Bus, including: \n
35  *
36  * <ul>
37  * <li>Constants such as the network ID length</li>
38  * <li>Functions such as that for initializing the Intelligent Soft Bus client</li>
39  * </ul>
40  *
41  * @since 1.0
42  * @version 1.0
43  */
44 
45 #ifndef SOFTBUS_CLIENT_COMMON_H
46 #define SOFTBUS_CLIENT_COMMON_H
47 
48 #include <stdbool.h>
49 #include <stdint.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /**
56  * @brief Indicates the length of the Bluetooth device MAC address in string format,
57  * including the terminating null character <b>\0</b>.
58  *
59  * @since 1.0
60  * @version 1.0
61  */
62 #define BT_MAC_LEN 18
63 
64 /**
65  * @brief Indicates the length of the network ID string, including the terminating null character <b>\0</b>.
66  *
67  * @since 1.0
68  * @version 1.0
69  */
70 #define NETWORK_ID_BUF_LEN 65
71 
72 /**
73  * @brief Indicates the length of the UDID string, including the terminating null character <b>\0</b>.
74  *
75  * @since 1.0
76  * @version 1.0
77  */
78 #define UDID_BUF_LEN 65
79 
80 /**
81  * @brief Indicates the length of the UDID hash value.
82  *
83  * @since 1.0
84  * @version 1.0
85  */
86 #define UDID_HASH_LEN 32
87 
88 /**
89  * @brief Indicates the length of the UUID string, including the terminating null character <b>\0</b>.
90  *
91  * @since 1.0
92  * @version 1.0
93  */
94 #define UUID_BUF_LEN 65
95 
96 /**
97  * @brief Indicates the maximum length of an IP address in string format,
98  * including the terminating null character <b>\0</b>. IPv6 addresses are supported.
99  *
100  * @since 1.0
101  * @version 1.0
102  */
103 #define IP_STR_MAX_LEN 46
104 
105 /**
106  * @brief Indicates the maximum length of the account hash code in <b>IDiscoveryCallback</b>.
107  *
108  */
109 #define MAX_ACCOUNT_HASH_LEN 96
110 
111 /**
112  * @brief Indicates the maximum length of the capability data in <b>PublishInfo</b> and <b>SubscribeInfo</b>.
113  *
114  */
115 #define MAX_CAPABILITYDATA_LEN 513
116 
117 /**
118  * @brief Indicates the maximum length of the custom data in <b>IDiscoveryCallback</b>.
119  *
120  */
121 #define DISC_MAX_CUST_DATA_LEN 219
122 
123 /**
124  * @brief Indicates the maximum number of capabilities contained in the bitmap in <b>IDiscoveryCallback</b>.
125  *
126  */
127 #define DISC_MAX_CAPABILITY_NUM 2
128 
129 /**
130  * @brief Indicates the maximum length of the device name in <b>IDiscoveryCallback</b>.
131  *
132  */
133 #define DISC_MAX_DEVICE_NAME_LEN 65
134 
135 /**
136  * @brief Indicates the maximum length of the device ID in <b>IDiscoveryCallback</b>.
137  *
138  */
139 #define DISC_MAX_DEVICE_ID_LEN 96
140 #define NUM_BUF_SIZE 4
141 
142 
143 /**
144  * @brief Enumerates {@link ConnectionAddr} types of a device that is added to a LNN.
145  *
146  * @since 1.0
147  * @version 1.0
148  */
149 typedef enum {
150     CONNECTION_ADDR_WLAN = 0, /**< WLAN */
151     CONNECTION_ADDR_BR,       /**< BR */
152     CONNECTION_ADDR_BLE,      /**< BLE */
153     CONNECTION_ADDR_ETH,      /**< Ethernet */
154     CONNECTION_ADDR_MAX       /**< Invalid type */
155 } ConnectionAddrType;
156 /**
157  * @brief Defines the address of a device that is added to a LNN.
158  * For details, see {@link ConnectionAddr}.
159  *
160  * @since 1.0
161  * @version 1.0
162  */
163 typedef struct {
164     /**< Address type. This field is used to explain the <b>info</b> field. */
165     ConnectionAddrType type;
166     /**< Connection address information */
167     union {
168         /**< BR address */
169         struct BrAddr {
170             char brMac[BT_MAC_LEN];   /**< BR MAC address in string format */
171         } br;
172         /**< BLE address */
173         struct BleAddr {
174             char bleMac[BT_MAC_LEN];  /**< BLE MAC address in string format */
175             uint8_t udidHash[UDID_HASH_LEN];  /**< udid hash value */
176         } ble;
177         /**< IPv4 or IPv6 address */
178         struct IpAddr {
179             /**
180              * IP address in string format. It can be an IPv4 address written in dotted decimal notation
181              * or an IPv6 address written in hexadecimal colon-separated notation.
182              */
183             char ip[IP_STR_MAX_LEN];
184             uint16_t port;            /**< Port number represented by the host byte order */
185         } ip;
186     } info;
187     char peerUid[MAX_ACCOUNT_HASH_LEN];
188 } ConnectionAddr;
189 
190 /**
191  * @brief Enumerates the modes in which services are published.
192  *
193  */
194 typedef enum  {
195     /* Passive */
196     DISCOVER_MODE_PASSIVE = 0x55,
197     /* Proactive */
198     DISCOVER_MODE_ACTIVE  = 0xAA
199 } DiscoverMode;
200 
201 /**
202  * @brief Enumerates media, such as Bluetooth, Wi-Fi, and USB, used for publishing services.
203  *
204  * Currently, only <b>COAP</b> is supported.
205  * When <b>AUTO</b> is selected, all the supported media will be called automatically.
206  */
207 typedef enum {
208     /** Automatic medium selection */
209     AUTO = 0,
210     /** Bluetooth */
211     BLE = 1,
212     /** Wi-Fi */
213     COAP = 2,
214     /** USB */
215     USB = 3,
216     /** HiLink */
217     COAP1 = 4,
218     MEDIUM_BUTT
219 } ExchanageMedium;
220 
221 /**
222  * @brief Enumerates frequencies for publishing services.
223  *
224  * This enumeration applies only to Bluetooth and is not supported currently.
225  */
226 typedef enum {
227     /** Low */
228     LOW = 0,
229     /** Medium */
230     MID = 1,
231     /** High */
232     HIGH = 2,
233     /** Super-high */
234     SUPER_HIGH = 3,
235     FREQ_BUTT
236 } ExchangeFreq;
237 
238 /**
239  * @brief Enumerates supported capabilities published by a device.
240  *
241  */
242 typedef enum {
243     /** MeeTime */
244     HICALL_CAPABILITY_BITMAP = 0,
245     /** Video reverse connection in the smart domain */
246     PROFILE_CAPABILITY_BITMAP = 1,
247     /** Gallery in Vision */
248     HOMEVISIONPIC_CAPABILITY_BITMAP = 2,
249     /** cast+ */
250     CASTPLUS_CAPABILITY_BITMAP,
251     /** Input method in Vision */
252     AA_CAPABILITY_BITMAP,
253     /** Device virtualization tool package */
254     DVKIT_CAPABILITY_BITMAP,
255     /** Distributed middleware */
256     DDMP_CAPABILITY_BITMAP,
257     /** Osd capability */
258     OSD_CAPABILITY_BITMAP
259 } DataBitMap;
260 
261 /**
262  * @brief Defines the mapping between supported capabilities and bitmaps.
263  *
264  */
265 typedef struct {
266     /** Bitmaps. For details, see {@link DataBitMap}. */
267     DataBitMap bitmap;
268     /** Capability. For details, see {@link g_capabilityMap}. */
269     char *capability;
270 } CapabilityMap;
271 
272 /**
273  * @brief Defines the mapping between supported capabilities and bitmaps.
274  *
275  */
276 static const CapabilityMap g_capabilityMap[] = {
277     {HICALL_CAPABILITY_BITMAP, (char *)"hicall"},
278     {PROFILE_CAPABILITY_BITMAP, (char *)"profile"},
279     {HOMEVISIONPIC_CAPABILITY_BITMAP, (char *)"homevisionPic"},
280     {CASTPLUS_CAPABILITY_BITMAP, (char *)"castPlus"},
281     {AA_CAPABILITY_BITMAP, (char *)"aaCapability"},
282     {DVKIT_CAPABILITY_BITMAP, (char *)"dvKit"},
283     {DDMP_CAPABILITY_BITMAP, (char *)"ddmpCapability"},
284     {OSD_CAPABILITY_BITMAP, (char *)"osdCapability"},
285 };
286 
287 /**
288  * @brief Defines service publishing information.
289  *
290  */
291 typedef struct {
292     /** Service ID */
293     int publishId;
294     /** Discovery mode for service publishing. For details, see {@link Discovermode}. */
295     DiscoverMode mode;
296     /** Service publishing medium. For details, see {@link ExchanageMedium}. */
297     ExchanageMedium medium;
298     /** Service publishing frequency. For details, see {@link ExchangeFre}. */
299     ExchangeFreq freq;
300     /** Service publishing capabilities. For details, see {@link g_capabilityMap}. */
301     const char *capability;
302     /** Capability data for service publishing */
303     unsigned char *capabilityData;
304     /** Maximum length of the capability data for service publishing (512 bytes) */
305     unsigned int dataLen;
306 } PublishInfo;
307 
308 /**
309  * @brief Defines service subscription information.
310  *
311  */
312 typedef struct {
313     /** Service ID */
314     int subscribeId;
315     /** Discovery mode for service subscription. For details, see {@link Discovermode}. */
316     DiscoverMode mode;
317     /** Service subscription medium. For details, see {@link ExchanageMedium}. */
318     ExchanageMedium medium;
319     /** Service subscription frequency. For details, see {@link ExchangeFre}. */
320     ExchangeFreq freq;
321     /** only find the device with the same account */
322     bool isSameAccount;
323     /** find the sleeping devices */
324     bool isWakeRemote;
325     /** Service subscription capability. For details, see {@link g_capabilityMap}. */
326     const char *capability;
327     /** Capability data for service subscription */
328     unsigned char *capabilityData;
329     /** Maximum length of the capability data for service subscription (512 bytes) */
330     unsigned int dataLen;
331 } SubscribeInfo;
332 
333 /**
334  * @brief Enumerates device types.
335  *
336  */
337 typedef enum {
338     /* Smart speaker */
339     SMART_SPEAKER = 0x00,
340     /* PC */
341     DESKTOP_PC,
342     /* Laptop */
343     LAPTOP,
344     /* Mobile phone */
345     SMART_PHONE,
346     /* Tablet */
347     SMART_PAD,
348     /* Smart watch */
349     SMART_WATCH,
350     /* Smart car */
351     SMART_CAR,
352     /* Kids' watch */
353     CHILDREN_WATCH,
354     /* Smart TV */
355     SMART_TV,
356 } DeviceType;
357 
358 /**
359  * @brief Defines the device information returned by <b>IDiscoveryCallback</b>.
360  *
361  */
362 typedef struct {
363     /** Device ID. Its maximum length is specified by {@link DISC_MAX_DEVICE_ID_LEN}. */
364     char devId[DISC_MAX_DEVICE_ID_LEN];
365     /** Account hash code. Its maximum length is specified by {@link MAX_ACCOUNT_HASH_LEN}. */
366     char accountHash[MAX_ACCOUNT_HASH_LEN];
367     /** Device type. For details, see {@link DeviceType}. */
368     DeviceType devType;
369     /** Device name. Its maximum length is specified by {@link DISC_MAX_DEVICE_NAME_LEN}. */
370     char devName[DISC_MAX_DEVICE_NAME_LEN];
371     /** Number of available connections */
372     unsigned int addrNum;
373     /** Connection information. For details, see {@link ConnectAddr}. */
374     ConnectionAddr addr[CONNECTION_ADDR_MAX];
375     /** Number of capabilities */
376     unsigned int capabilityBitmapNum;
377     /** Device capability bitmap.
378      * The maximum number of capabilities in the bitmap is specified by {@link DISC_MAX_CAPABILITY_NUM}.
379      */
380     unsigned int capabilityBitmap[DISC_MAX_CAPABILITY_NUM];
381     /** Custom data. Its length is specified by {@link DISC_MAX_CUST_DATA_LEN}. */
382     char custData[DISC_MAX_CUST_DATA_LEN];
383 } DeviceInfo;
384 #ifdef __cplusplus
385 }
386 #endif
387 #endif
388 /** @} */
389