• 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 513
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 short hash length of the networkId.
172  *
173  */
174 #define NODEID_SHORT_HASH_LEN 6
175 
176 /**
177  * @brief Indicates the short hash length of the udid.
178  *
179  */
180 #define UDID_SHORT_HASH_LEN 6
181 
182 /**
183  * @brief Indicates the maximum length of the device database status in <b>INodeStateCb</b>.
184  *
185  */
186 #define DATA_CHANGE_FLAG_BUF_LEN 2
187 
188 /**
189  * @brief Indicates the maximum length of the node address.
190  *
191  */
192 #define SHORT_ADDRESS_MAX_LEN 20
193 
194 /**
195  * @brief Indicates the maximum num of the node status.
196  *
197  */
198 #define NODE_STATUS_MAX_NUM 32
199 /**
200  * @brief Enumerates {@link ConnectionAddrType} types of a device that is added to a LNN.
201  *
202  * @since 1.0
203  * @version 1.0
204  */
205 typedef enum {
206     CONNECTION_ADDR_WLAN = 0, /**< WLAN */
207     CONNECTION_ADDR_BR,       /**< BR */
208     CONNECTION_ADDR_BLE,      /**< BLE */
209     CONNECTION_ADDR_ETH,      /**< Ethernet */
210     CONNECTION_ADDR_SESSION,  /**< SESSION */
211     CONNECTION_ADDR_MAX       /**< Invalid type */
212 } ConnectionAddrType;
213 
214 /**
215  * @brief Enumerates {@link BleProtocolType} types of ble connection type
216  *
217  */
218 typedef enum  {
219     BLE_PROTOCOL_ANY = -1,
220     BLE_GATT = 0,
221     BLE_COC,
222     BLE_PROTOCOL_MAX
223 } BleProtocolType;
224 
225 /**
226  * @brief Enumerates secret key types.
227  *
228  * @since 1.0
229  * @verison 1.0
230  */
231 typedef enum {
232     PROXY_TRANSMISION = 0, /**< Proxy Transmision */
233     PROXY_HEARTBEAT = 1, /**< Proxy Heartbeat */
234     PROXY_HICAR = 2,
235     PROXY_SHARE = 4,
236     PROXY_CASTPLUS = 5,
237     PROXY_WEAR = 7,
238     CUSTOM_UNKNOWN = 8, /**< Proxy Unknown*/
239 } MetaNodeType;
240 
241 /**
242  * @brief Defines the address of a device that is added to a LNN.
243  * For details, see {@link ConnectionAddr}.
244  *
245  * @since 1.0
246  * @version 1.0
247  */
248 typedef struct {
249     /**< Address type. This field is used to explain the <b>info</b> field. */
250     ConnectionAddrType type;
251     /**< Connection address information */
252     union {
253         /**< BR address */
254         struct BrAddr {
255             char brMac[BT_MAC_LEN];   /**< BR MAC address in string format */
256         } br;
257         /**< BLE address */
258         struct BleAddr {
259             BleProtocolType protocol;
260             char bleMac[BT_MAC_LEN];  /**< BLE MAC address in string format */
261             uint8_t udidHash[UDID_HASH_LEN];  /**< udid hash value */
262             int32_t psm;
263         } ble;
264         /**< IPv4 or IPv6 address */
265         struct IpAddr {
266             /**
267              * IP address in string format. It can be an IPv4 address written in dotted decimal notation
268              * or an IPv6 address written in hexadecimal colon-separated notation.
269              */
270             char ip[IP_STR_MAX_LEN];
271             uint16_t port;            /**< Port number represented by the host byte order */
272         } ip;
273         /**< Session address */
274         struct SessionAddr {
275             int32_t sessionId;  /**< Session Id in int format */
276             int32_t channelId;  /**< Channel Id in int format */
277             int32_t type;   /**< Session type in int format */
278         } session;
279     } info;
280     char peerUid[MAX_ACCOUNT_HASH_LEN];
281 } ConnectionAddr;
282 
283 /**
284  * @brief Enumerates the modes in which services are published.
285  *
286  */
287 typedef enum  {
288     /* Passive */
289     DISCOVER_MODE_PASSIVE = 0x55,
290     /* Proactive */
291     DISCOVER_MODE_ACTIVE  = 0xAA
292 } DiscoverMode;
293 
294 /**
295  * @brief Enumerates media, such as Bluetooth, Wi-Fi, and USB, used for publishing services.
296  *
297  * Currently, only <b>COAP</b> is supported.
298  * When <b>AUTO</b> is selected, all the supported media will be called automatically.
299  */
300 typedef enum {
301     /** Automatic medium selection */
302     AUTO = 0,
303     /** Bluetooth */
304     BLE = 1,
305     /** Wi-Fi */
306     COAP = 2,
307     /** USB */
308     USB = 3,
309     /** HiLink */
310     COAP1 = 4,
311     MEDIUM_BUTT
312 } ExchangeMedium;
313 
314 /**
315  * @brief Enumerates frequencies for publishing services.
316  *
317  * This enumeration applies only to Bluetooth and is not supported currently.
318  */
319 typedef enum {
320     /** Low */
321     LOW = 0,
322     /** Medium */
323     MID = 1,
324     /** High */
325     HIGH = 2,
326     /** Super-high */
327     SUPER_HIGH = 3,
328     FREQ_BUTT
329 } ExchangeFreq;
330 
331 /**
332  * @brief Enumerates supported capabilities published by a device.
333  *
334  */
335 typedef enum {
336     /** MeeTime */
337     HICALL_CAPABILITY_BITMAP = 0,
338     /** Video reverse connection in the smart domain */
339     PROFILE_CAPABILITY_BITMAP = 1,
340     /** Gallery in Vision */
341     HOMEVISIONPIC_CAPABILITY_BITMAP = 2,
342     /** cast+ */
343     CASTPLUS_CAPABILITY_BITMAP,
344     /** Input method in Vision */
345     AA_CAPABILITY_BITMAP,
346     /** Device virtualization tool package */
347     DVKIT_CAPABILITY_BITMAP,
348     /** Distributed middleware */
349     DDMP_CAPABILITY_BITMAP,
350     /** Osd capability */
351     OSD_CAPABILITY_BITMAP,
352     /**Share capability */
353     SHARE_CAPABILITY_BITMAP,
354     /**Approach capability */
355     APPROACH_CAPABILITY_BITMAP
356 } DataBitMap;
357 
358 /**
359  * @brief Defines the mapping between supported capabilities and bitmaps.
360  *
361  */
362 typedef struct {
363     /** Bitmaps. For details, see {@link DataBitMap}. */
364     DataBitMap bitmap;
365     /** Capability. For details, see {@link g_capabilityMap}. */
366     char *capability;
367 } CapabilityMap;
368 
369 /**
370  * @brief Defines the mapping between supported capabilities and bitmaps.
371  *
372  */
373 static const CapabilityMap g_capabilityMap[] = {
374     {HICALL_CAPABILITY_BITMAP, (char *)"hicall"},
375     {PROFILE_CAPABILITY_BITMAP, (char *)"profile"},
376     {HOMEVISIONPIC_CAPABILITY_BITMAP, (char *)"homevisionPic"},
377     {CASTPLUS_CAPABILITY_BITMAP, (char *)"castPlus"},
378     {AA_CAPABILITY_BITMAP, (char *)"aaCapability"},
379     {DVKIT_CAPABILITY_BITMAP, (char *)"dvKit"},
380     {DDMP_CAPABILITY_BITMAP, (char *)"ddmpCapability"},
381     {OSD_CAPABILITY_BITMAP, (char *)"osdCapability"},
382     {SHARE_CAPABILITY_BITMAP, (char *)"share"},
383     {APPROACH_CAPABILITY_BITMAP, (char *)"approach"},
384 };
385 
386 /**
387  * @brief Defines service publishing information.
388  *
389  */
390 typedef struct {
391     /** Service ID */
392     int publishId;
393     /** Discovery mode for service publishing. For details, see {@link Discovermode}. */
394     DiscoverMode mode;
395     /** Service publishing medium. For details, see {@link ExchangeMedium}. */
396     ExchangeMedium medium;
397     /** Service publishing frequency. For details, see {@link ExchangeFreq}. */
398     ExchangeFreq freq;
399     /** Service publishing capabilities. For details, see {@link g_capabilityMap}. */
400     const char *capability;
401     /** Capability data for service publishing, MUST be c-string format. */
402     unsigned char *capabilityData;
403     /** Maximum length of the capability data for service publishing (512 bytes) */
404     unsigned int dataLen;
405     /** Whether the device should be ranged  by discoverers.*/
406     bool ranging;
407 } PublishInfo;
408 
409 /**
410  * @brief Defines service subscription information.
411  *
412  */
413 typedef struct {
414     /** Service ID */
415     int subscribeId;
416     /** Discovery mode for service subscription. For details, see {@link Discovermode}. */
417     DiscoverMode mode;
418     /** Service subscription medium. For details, see {@link ExchangeMedium}. */
419     ExchangeMedium medium;
420     /** Service subscription frequency. For details, see {@link ExchangeFreq}. */
421     ExchangeFreq freq;
422     /** only find the device with the same account */
423     bool isSameAccount;
424     /** find the sleeping devices */
425     bool isWakeRemote;
426     /** Service subscription capability. For details, see {@link g_capabilityMap}. */
427     const char *capability;
428     /** Capability data for service subscription, MUST be c-string format. */
429     unsigned char *capabilityData;
430     /** Maximum length of the capability data for service subscription (512 bytes) */
431     unsigned int dataLen;
432 } SubscribeInfo;
433 
434 /**
435  * @brief Enumerates single heartbeat cycle parameter.
436  *
437  * @since 1.0
438  * @version 1.0
439  */
440 typedef enum {
441     /**< Heartbeat interval 30 sec */
442     HIGH_FREQ_CYCLE = 30,
443     /**< Heartbeat interval 60 sec */
444     MID_FREQ_CYCLE = 60,
445     /**< Heartbeat interval 5 * 60 sec */
446     LOW_FREQ_CYCLE = 5 * 60,
447 } ModeCycle;
448 
449 /**
450  * @brief Enumerates duration of heartbeat keeping alive parameter.
451  *
452  * @since 1.0
453  * @version 1.0
454  */
455 typedef enum {
456     /**< Heartbeat continues for 60 sec */
457     DEFAULT_DURATION = 60,
458     /**< Heartbeat continues for 10 * 60 sec. */
459     NORMAL_DURATION = 10 * 60,
460     /**< Heartbeat continues for 30 * 60 sec. */
461     LONG_DURATION = 30 * 60,
462 } ModeDuration;
463 
464 /**
465  * @brief Enumerates device types.
466  *
467  */
468 typedef enum {
469     /* Smart speaker */
470     SMART_SPEAKER = 0x00,
471     /* PC */
472     DESKTOP_PC,
473     /* Laptop */
474     LAPTOP,
475     /* Mobile phone */
476     SMART_PHONE,
477     /* Tablet */
478     SMART_PAD,
479     /* Smart watch */
480     SMART_WATCH,
481     /* Smart car */
482     SMART_CAR,
483     /* Kids' watch */
484     CHILDREN_WATCH,
485     /* Smart TV */
486     SMART_TV,
487 } DeviceType;
488 
489 /**
490  * @brief Defines the device information returned by <b>IDiscoveryCallback</b>.
491  *
492  */
493 typedef struct {
494     /** Device ID. Its maximum length is specified by {@link DISC_MAX_DEVICE_ID_LEN}. */
495     char devId[DISC_MAX_DEVICE_ID_LEN];
496     /** Account hash code. Its maximum length is specified by {@link MAX_ACCOUNT_HASH_LEN}. */
497     char accountHash[MAX_ACCOUNT_HASH_LEN];
498     /** Device type. For details, see {@link DeviceType}. */
499     DeviceType devType;
500     /** Device name. Its maximum length is specified by {@link DISC_MAX_DEVICE_NAME_LEN}. */
501     char devName[DISC_MAX_DEVICE_NAME_LEN];
502     /** Device Online Status **/
503     bool isOnline;
504     /** Number of available connections */
505     unsigned int addrNum;
506     /** Connection information. For details, see {@link ConnectionAddr}. */
507     ConnectionAddr addr[CONNECTION_ADDR_MAX];
508     /** Number of capabilities */
509     unsigned int capabilityBitmapNum;
510     /** Device capability bitmap.
511      * The maximum number of capabilities in the bitmap is specified by {@link DISC_MAX_CAPABILITY_NUM}.
512      */
513     unsigned int capabilityBitmap[DISC_MAX_CAPABILITY_NUM];
514     /** Custom data. Its length is specified by {@link DISC_MAX_CUST_DATA_LEN}. */
515     char custData[DISC_MAX_CUST_DATA_LEN];
516     /** The distance of discovered device, in centimeters(cm)*/
517     int32_t range;
518 } DeviceInfo;
519 
520 /**
521  * @brief Defines device additional info used by inner
522  *
523  */
524 typedef struct {
525     /** medium which describe the device found by. */
526     ExchangeMedium medium;
527 } InnerDeviceInfoAddtions;
528 
529 #ifdef __cplusplus
530 }
531 #endif
532 #endif
533 /** @} */
534