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