• 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 /**
31  * @file softbus_common.h
32  *
33  * @brief Declares common APIs for the Intelligent Soft Bus.
34  *
35  * This file provides common functions and constants for each submodule of the Intelligent Soft Bus, including: \n
36  *
37  * <ul>
38  * <li>Constants such as the network ID length</li>
39  * <li>Functions such as that for initializing the Intelligent Soft Bus client</li>
40  * </ul>
41  *
42  * @since 1.0
43  * @version 1.0
44  */
45 
46 #ifndef SOFTBUS_CLIENT_COMMON_H
47 #define SOFTBUS_CLIENT_COMMON_H
48 
49 #include <stdbool.h>
50 #include <stdint.h>
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /**
57  * @brief Permission of softbus component
58  *
59  * @since 3.0
60  * @version 3.0
61 */
62 #define OHOS_PERMISSION_DISTRIBUTED_DATASYNC "ohos.permission.DISTRIBUTED_DATASYNC"
63 #define OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER"
64 
65 /**
66  * @brief Indicates the length of the Bluetooth device MAC address in string format,
67  * including the terminating null character <b>\0</b>.
68  *
69  * @since 1.0
70  * @version 1.0
71  */
72 #define BT_MAC_LEN 18
73 
74 /**
75  * @brief Indicates the length of the network ID string, including the terminating null character <b>\0</b>.
76  *
77  * @since 1.0
78  * @version 1.0
79  */
80 #define NETWORK_ID_BUF_LEN 65
81 
82 /**
83  * @brief Indicates the length of the UDID string, including the terminating null character <b>\0</b>.
84  *
85  * @since 1.0
86  * @version 1.0
87  */
88 #define UDID_BUF_LEN 65
89 
90 /**
91  * @brief Indicates the length of the UDID hash value.
92  *
93  * @since 1.0
94  * @version 1.0
95  */
96 #define UDID_HASH_LEN 32
97 
98 /**
99  * @brief Indicates the length of the UUID string, including the terminating null character <b>\0</b>.
100  *
101  * @since 1.0
102  * @version 1.0
103  */
104 #define UUID_BUF_LEN 65
105 
106 /**
107  * @brief Indicates the maximum length of an IP address in string format,
108  * including the terminating null character <b>\0</b>. IPv6 addresses are supported.
109  *
110  * @since 1.0
111  * @version 1.0
112  */
113 #define IP_STR_MAX_LEN 46
114 
115 /**
116  * @brief Indicates the maximum length of the account hash code in <b>IDiscoveryCallback</b>.
117  *
118  */
119 #define MAX_ACCOUNT_HASH_LEN 96
120 
121 /**
122  * @brief Indicates the maximum length of the hash code in HEX calculated by SHA-256.
123  *
124  */
125 #define SHA_256_HASH_LEN 32
126 
127 /**
128  * @brief Indicates the maximum length of the hash code in string format calculated by SHA-256,
129  * including the terminating null character <b>\0</b>.
130  *
131  */
132 #define SHA_256_HEX_HASH_LEN 65
133 
134 /**
135  * @brief Indicates the maximum length of the capability data in <b>PublishInfo</b> and <b>SubscribeInfo</b>.
136  *
137  */
138 #define MAX_CAPABILITYDATA_LEN 513
139 
140 /**
141  * @brief Indicates the maximum length of the custom data in <b>IDiscoveryCallback</b>.
142  *
143  */
144 #define DISC_MAX_CUST_DATA_LEN 219
145 
146 /**
147  * @brief Indicates the maximum number of capabilities contained in the bitmap in <b>IDiscoveryCallback</b>.
148  *
149  */
150 #define DISC_MAX_CAPABILITY_NUM 2
151 
152 /**
153  * @brief Indicates the maximum length of the device name in <b>IDiscoveryCallback</b>.
154  *
155  */
156 #define DISC_MAX_DEVICE_NAME_LEN 65
157 
158 /**
159  * @brief Indicates the maximum length of the device ID in <b>IDiscoveryCallback</b>.
160  *
161  */
162 #define DISC_MAX_DEVICE_ID_LEN 96
163 
164 /**
165  * @brief Indicates the maximum length of the network commmon length <b>IDiscoveryCallback</b>.
166  *
167  */
168 #define LNN_COMMON_LEN 4
169 
170 /**
171  * @brief Indicates the maximum length of the device database status in <b>INodeStateCb</b>.
172  *
173  */
174 #define DATA_CHANGE_FLAG_BUF_LEN 2
175 
176 /**
177  * @brief Indicates the maximum length of the node address.
178  *
179  */
180 #define SHORT_ADDRESS_MAX_LEN 8
181 
182 /**
183  * @brief Indicates the maximum num of the node status.
184  *
185  */
186 #define NODE_STATUS_MAX_NUM 32
187 /**
188  * @brief Enumerates {@link ConnectionAddr} types of a device that is added to a LNN.
189  *
190  * @since 1.0
191  * @version 1.0
192  */
193 typedef enum {
194     CONNECTION_ADDR_WLAN = 0, /**< WLAN */
195     CONNECTION_ADDR_BR,       /**< BR */
196     CONNECTION_ADDR_BLE,      /**< BLE */
197     CONNECTION_ADDR_ETH,      /**< Ethernet */
198     CONNECTION_ADDR_SESSION,     /**< SESSION */
199     CONNECTION_ADDR_MAX       /**< Invalid type */
200 } ConnectionAddrType;
201 /**
202  * @brief Defines the address of a device that is added to a LNN.
203  * For details, see {@link ConnectionAddr}.
204  *
205  * @since 1.0
206  * @version 1.0
207  */
208 typedef struct {
209     /**< Address type. This field is used to explain the <b>info</b> field. */
210     ConnectionAddrType type;
211     /**< Connection address information */
212     union {
213         /**< BR address */
214         struct BrAddr {
215             char brMac[BT_MAC_LEN];   /**< BR MAC address in string format */
216         } br;
217         /**< BLE address */
218         struct BleAddr {
219             char bleMac[BT_MAC_LEN];  /**< BLE MAC address in string format */
220             uint8_t udidHash[UDID_HASH_LEN];  /**< udid hash value */
221         } ble;
222         /**< IPv4 or IPv6 address */
223         struct IpAddr {
224             /**
225              * IP address in string format. It can be an IPv4 address written in dotted decimal notation
226              * or an IPv6 address written in hexadecimal colon-separated notation.
227              */
228             char ip[IP_STR_MAX_LEN];
229             uint16_t port;            /**< Port number represented by the host byte order */
230         } ip;
231         /**< Session address */
232         struct SessionAddr {
233             int32_t sessionId;  /**< Session Id in int format */
234             int32_t channelId;  /**< Channel Id in int format */
235             int32_t type;   /**< Session type in int format */
236         } session;
237     } info;
238     char peerUid[MAX_ACCOUNT_HASH_LEN];
239 } ConnectionAddr;
240 
241 /**
242  * @brief Enumerates the modes in which services are published.
243  *
244  */
245 typedef enum  {
246     /* Passive */
247     DISCOVER_MODE_PASSIVE = 0x55,
248     /* Proactive */
249     DISCOVER_MODE_ACTIVE  = 0xAA
250 } DiscoverMode;
251 
252 /**
253  * @brief Enumerates media, such as Bluetooth, Wi-Fi, and USB, used for publishing services.
254  *
255  * Currently, only <b>COAP</b> is supported.
256  * When <b>AUTO</b> is selected, all the supported media will be called automatically.
257  */
258 typedef enum {
259     /** Automatic medium selection */
260     AUTO = 0,
261     /** Bluetooth */
262     BLE = 1,
263     /** Wi-Fi */
264     COAP = 2,
265     /** USB */
266     USB = 3,
267     /** HiLink */
268     COAP1 = 4,
269     MEDIUM_BUTT
270 } ExchangeMedium;
271 
272 /**
273  * @brief Enumerates frequencies for publishing services.
274  *
275  * This enumeration applies only to Bluetooth and is not supported currently.
276  */
277 typedef enum {
278     /** Low */
279     LOW = 0,
280     /** Medium */
281     MID = 1,
282     /** High */
283     HIGH = 2,
284     /** Super-high */
285     SUPER_HIGH = 3,
286     FREQ_BUTT
287 } ExchangeFreq;
288 
289 /**
290  * @brief Enumerates supported capabilities published by a device.
291  *
292  */
293 typedef enum {
294     /** MeeTime */
295     HICALL_CAPABILITY_BITMAP = 0,
296     /** Video reverse connection in the smart domain */
297     PROFILE_CAPABILITY_BITMAP = 1,
298     /** Gallery in Vision */
299     HOMEVISIONPIC_CAPABILITY_BITMAP = 2,
300     /** cast+ */
301     CASTPLUS_CAPABILITY_BITMAP,
302     /** Input method in Vision */
303     AA_CAPABILITY_BITMAP,
304     /** Device virtualization tool package */
305     DVKIT_CAPABILITY_BITMAP,
306     /** Distributed middleware */
307     DDMP_CAPABILITY_BITMAP,
308     /** Osd capability */
309     OSD_CAPABILITY_BITMAP,
310     /**Share capability */
311     SHARE_CAPABILITY_BITMAP
312 } DataBitMap;
313 
314 /**
315  * @brief Defines the mapping between supported capabilities and bitmaps.
316  *
317  */
318 typedef struct {
319     /** Bitmaps. For details, see {@link DataBitMap}. */
320     DataBitMap bitmap;
321     /** Capability. For details, see {@link g_capabilityMap}. */
322     char *capability;
323 } CapabilityMap;
324 
325 /**
326  * @brief Defines the mapping between supported capabilities and bitmaps.
327  *
328  */
329 static const CapabilityMap g_capabilityMap[] = {
330     {HICALL_CAPABILITY_BITMAP, (char *)"hicall"},
331     {PROFILE_CAPABILITY_BITMAP, (char *)"profile"},
332     {HOMEVISIONPIC_CAPABILITY_BITMAP, (char *)"homevisionPic"},
333     {CASTPLUS_CAPABILITY_BITMAP, (char *)"castPlus"},
334     {AA_CAPABILITY_BITMAP, (char *)"aaCapability"},
335     {DVKIT_CAPABILITY_BITMAP, (char *)"dvKit"},
336     {DDMP_CAPABILITY_BITMAP, (char *)"ddmpCapability"},
337     {OSD_CAPABILITY_BITMAP, (char *)"osdCapability"},
338     {SHARE_CAPABILITY_BITMAP, (char *)"share"},
339 };
340 
341 /**
342  * @brief Defines service publishing information.
343  *
344  */
345 typedef struct {
346     /** Service ID */
347     int publishId;
348     /** Discovery mode for service publishing. For details, see {@link Discovermode}. */
349     DiscoverMode mode;
350     /** Service publishing medium. For details, see {@link ExchangeMedium}. */
351     ExchangeMedium medium;
352     /** Service publishing frequency. For details, see {@link ExchangeFreq}. */
353     ExchangeFreq freq;
354     /** Service publishing capabilities. For details, see {@link g_capabilityMap}. */
355     const char *capability;
356     /** Capability data for service publishing */
357     unsigned char *capabilityData;
358     /** Maximum length of the capability data for service publishing (512 bytes) */
359     unsigned int dataLen;
360     /** Whether the device should be ranged  by discoverers.*/
361     bool ranging;
362 } PublishInfo;
363 
364 /**
365  * @brief Defines service subscription information.
366  *
367  */
368 typedef struct {
369     /** Service ID */
370     int subscribeId;
371     /** Discovery mode for service subscription. For details, see {@link Discovermode}. */
372     DiscoverMode mode;
373     /** Service subscription medium. For details, see {@link ExchangeMedium}. */
374     ExchangeMedium medium;
375     /** Service subscription frequency. For details, see {@link ExchangeFreq}. */
376     ExchangeFreq freq;
377     /** only find the device with the same account */
378     bool isSameAccount;
379     /** find the sleeping devices */
380     bool isWakeRemote;
381     /** Service subscription capability. For details, see {@link g_capabilityMap}. */
382     const char *capability;
383     /** Capability data for service subscription */
384     unsigned char *capabilityData;
385     /** Maximum length of the capability data for service subscription (512 bytes) */
386     unsigned int dataLen;
387 } SubscribeInfo;
388 
389 /**
390  * @brief Enumerates single heartbeat cycle parameter.
391  *
392  * @since 1.0
393  * @version 1.0
394  */
395 typedef enum {
396     /**< Heartbeat interval 30 sec */
397     HIGH_FREQ_CYCLE = 30,
398     /**< Heartbeat interval 60 sec */
399     MID_FREQ_CYCLE = 60,
400     /**< Heartbeat interval 5 * 60 sec */
401     LOW_FREQ_CYCLE = 5 * 60,
402 } ModeCycle;
403 
404 /**
405  * @brief Enumerates duration of heartbeat keeping alive parameter.
406  *
407  * @since 1.0
408  * @version 1.0
409  */
410 typedef enum {
411     /**< Heartbeat continues for 60 sec */
412     DEFAULT_DURATION = 60,
413     /**< Heartbeat continues for 10 * 60 sec. */
414     NORMAL_DURATION = 10 * 60,
415     /**< Heartbeat continues for 30 * 60 sec. */
416     LONG_DURATION = 30 * 60,
417 } ModeDuration;
418 
419 /**
420  * @brief Enumerates device types.
421  *
422  */
423 typedef enum {
424     /* Smart speaker */
425     SMART_SPEAKER = 0x00,
426     /* PC */
427     DESKTOP_PC,
428     /* Laptop */
429     LAPTOP,
430     /* Mobile phone */
431     SMART_PHONE,
432     /* Tablet */
433     SMART_PAD,
434     /* Smart watch */
435     SMART_WATCH,
436     /* Smart car */
437     SMART_CAR,
438     /* Kids' watch */
439     CHILDREN_WATCH,
440     /* Smart TV */
441     SMART_TV,
442 } DeviceType;
443 
444 /**
445  * @brief Defines the device information returned by <b>IDiscoveryCallback</b>.
446  *
447  */
448 typedef struct {
449     /** Device ID. Its maximum length is specified by {@link DISC_MAX_DEVICE_ID_LEN}. */
450     char devId[DISC_MAX_DEVICE_ID_LEN];
451     /** Account hash code. Its maximum length is specified by {@link MAX_ACCOUNT_HASH_LEN}. */
452     char accountHash[MAX_ACCOUNT_HASH_LEN];
453     /** Device type. For details, see {@link DeviceType}. */
454     DeviceType devType;
455     /** Device name. Its maximum length is specified by {@link DISC_MAX_DEVICE_NAME_LEN}. */
456     char devName[DISC_MAX_DEVICE_NAME_LEN];
457     /** Device Online Status **/
458     bool isOnline;
459     /** Number of available connections */
460     unsigned int addrNum;
461     /** Connection information. For details, see {@link ConnectionAddr}. */
462     ConnectionAddr addr[CONNECTION_ADDR_MAX];
463     /** Number of capabilities */
464     unsigned int capabilityBitmapNum;
465     /** Device capability bitmap.
466      * The maximum number of capabilities in the bitmap is specified by {@link DISC_MAX_CAPABILITY_NUM}.
467      */
468     unsigned int capabilityBitmap[DISC_MAX_CAPABILITY_NUM];
469     /** Custom data. Its length is specified by {@link DISC_MAX_CUST_DATA_LEN}. */
470     char custData[DISC_MAX_CUST_DATA_LEN];
471     /** The distance of discovered device, in centimeters(cm)*/
472     int32_t range;
473 } DeviceInfo;
474 
475 /**
476  * @brief Defines device additional info used by inner
477  *
478  */
479 typedef struct {
480     /** medium which describe the device found by. */
481     ExchangeMedium medium;
482 } InnerDeviceInfoAddtions;
483 
484 #ifdef __cplusplus
485 }
486 #endif
487 #endif
488 /** @} */
489