1 /* 2 * Copyright (c) 2021-2024 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 database dynamic level in <b>IDataLevelCb</b>. 190 * 191 */ 192 #define DATA_DYNAMIC_LEVEL_BUF_LEN 2 193 194 /** 195 * @brief Indicates the maximum length of the database static level in <b>IDataLevelCb</b>. 196 * 197 */ 198 #define DATA_STATIC_LEVEL_BUF_LEN 2 199 200 /** 201 * @brief Indicates the maximum length of the database switch level in <b>IDataLevelCb</b>. 202 * 203 */ 204 #define DATA_SWITCH_LEVEL_BUF_LEN 4 205 206 /** 207 * @brief Device screen on/off bool data. 208 * 209 */ 210 #define DATA_DEVICE_SCREEN_STATUS_LEN 1 211 212 /** 213 * @brief Indicates the maximum length of the database switch length in <b>IDataLevelCb</b>. 214 * 215 */ 216 #define DATA_SWITCH_LENGTH_BUF_LEN 2 217 218 /** 219 * @brief Indicates the maximum length of the node address. 220 * 221 */ 222 #define SHORT_ADDRESS_MAX_LEN 20 223 224 /** 225 * @brief Indicates the maximum num of the node status. 226 * 227 */ 228 #define NODE_STATUS_MAX_NUM 32 229 230 /** 231 * @brief Indicates the maximum num of the device type size. 232 * 233 */ 234 #define DEVICE_TYPE_MAX_SIZE 3 235 236 /** 237 * @brief Indicates the length of the node screen status. 238 * 239 */ 240 #define NODE_SCREEN_STATUS_LEN 1 241 242 /** 243 * @brief Enumerates {@link ConnectionAddrType} types of a device that is added to a LNN. 244 * 245 * @since 1.0 246 * @version 1.0 247 */ 248 typedef enum { 249 CONNECTION_ADDR_WLAN = 0, /**< WLAN */ 250 CONNECTION_ADDR_BR, /**< BR */ 251 CONNECTION_ADDR_BLE, /**< BLE */ 252 CONNECTION_ADDR_ETH, /**< Ethernet */ 253 CONNECTION_ADDR_SESSION, /**< SESSION */ 254 CONNECTION_ADDR_USB, /**< USB */ 255 CONNECTION_ADDR_SESSION_WITH_KEY, /**< Session with key */ 256 CONNECTION_ADDR_MAX /**< Invalid type */ 257 } ConnectionAddrType; 258 259 /** 260 * @brief Enumerates {@link BleProtocolType} types of ble connection type 261 * 262 */ 263 typedef enum { 264 BLE_PROTOCOL_ANY = -1, 265 BLE_GATT = 0, 266 BLE_COC, 267 BLE_PROTOCOL_MAX 268 } BleProtocolType; 269 270 /** 271 * @brief Enumerates {@link BlePriority} types of ble priority 272 * 273 */ 274 typedef enum { 275 BLE_PRIORITY_DEFAULT = 0, 276 BLE_PRIORITY_BALANCED, 277 BLE_PRIORITY_HIGH, 278 BLE_PRIORITY_LOW_POWER, 279 BLE_PRIORITY_MAX 280 } BlePriority; 281 282 /** 283 * @brief Defines the address of a device that is added to a LNN. 284 * For details, see {@link ConnectionAddr}. 285 * 286 * @since 1.0 287 * @version 1.0 288 */ 289 typedef struct { 290 /**< Address type. This field is used to explain the <b>info</b> field. */ 291 ConnectionAddrType type; 292 /**< Connection address information */ 293 union { 294 /**< BR address */ 295 struct BrAddr { 296 char brMac[BT_MAC_LEN]; /**< BR MAC address in string format */ 297 } br; 298 /**< BLE address */ 299 struct BleAddr { 300 BleProtocolType protocol; 301 char bleMac[BT_MAC_LEN]; /**< BLE MAC address in string format */ 302 uint8_t udidHash[UDID_HASH_LEN]; /**< udid hash value */ 303 uint32_t psm; 304 BlePriority priority; 305 } ble; 306 /**< IPv4 or IPv6 address */ 307 struct IpAddr { 308 /** 309 * IP address in string format. It can be an IPv4 address written in dotted decimal notation 310 * or an IPv6 address written in hexadecimal colon-separated notation. 311 */ 312 char ip[IP_STR_MAX_LEN]; 313 uint16_t port; /**< Port number represented by the host byte order */ 314 uint8_t udidHash[UDID_HASH_LEN]; /**< udid hash value */ 315 } ip; 316 /**< Session address */ 317 struct SessionAddr { 318 int32_t sessionId; /**< Session Id in int format */ 319 int32_t channelId; /**< Channel Id in int format */ 320 int32_t type; /**< Session type in int format */ 321 int32_t localDeviceKeyId; 322 int32_t remoteDeviceKeyId; 323 } session; 324 } info; 325 char peerUid[MAX_ACCOUNT_HASH_LEN]; 326 } ConnectionAddr; 327 328 /** 329 * @brief Enumerates the modes in which services are published. 330 * 331 */ 332 typedef enum { 333 /* Passive */ 334 DISCOVER_MODE_PASSIVE = 0x55, 335 /* Proactive */ 336 DISCOVER_MODE_ACTIVE = 0xAA 337 } DiscoverMode; 338 339 /** 340 * @brief Enumerates media, such as Bluetooth, Wi-Fi, and USB, used for publishing services. 341 * 342 * Currently, only <b>COAP</b> is supported. 343 * When <b>AUTO</b> is selected, all the supported media will be called automatically. 344 */ 345 typedef enum { 346 /** Automatic medium selection */ 347 AUTO = 0, 348 /** Bluetooth */ 349 BLE = 1, 350 /** Wi-Fi */ 351 COAP = 2, 352 /** USB */ 353 USB = 3, 354 /** HiLink */ 355 COAP1 = 4, 356 MEDIUM_BUTT 357 } ExchangeMedium; 358 359 /** 360 * @brief Enumerates frequencies for publishing services. 361 * 362 * This enumeration applies only to Bluetooth and is not supported currently. 363 */ 364 typedef enum { 365 /** Low */ 366 LOW = 0, 367 /** Medium */ 368 MID = 1, 369 /** High */ 370 HIGH = 2, 371 /** Super-high */ 372 SUPER_HIGH = 3, 373 /** Extreme-high */ 374 EXTREME_HIGH = 4, 375 FREQ_BUTT 376 } ExchangeFreq; 377 378 /** 379 * @brief Enumerates supported capabilities published by a device. 380 * 381 */ 382 typedef enum { 383 /** MeeTime */ 384 HICALL_CAPABILITY_BITMAP = 0, 385 /** Video reverse connection in the smart domain */ 386 PROFILE_CAPABILITY_BITMAP = 1, 387 /** Gallery in Vision */ 388 HOMEVISIONPIC_CAPABILITY_BITMAP = 2, 389 /** cast+ */ 390 CASTPLUS_CAPABILITY_BITMAP, 391 /** Input method in Vision */ 392 AA_CAPABILITY_BITMAP, 393 /** Device virtualization tool package */ 394 DVKIT_CAPABILITY_BITMAP, 395 /** Distributed middleware */ 396 DDMP_CAPABILITY_BITMAP, 397 /** Osd capability */ 398 OSD_CAPABILITY_BITMAP, 399 /**Share capability */ 400 SHARE_CAPABILITY_BITMAP, 401 /**Approach capability */ 402 APPROACH_CAPABILITY_BITMAP, 403 /**virtual link capability */ 404 VLINK_CAPABILITY_BITMAP, 405 /**Touch capability */ 406 TOUCH_CAPABILITY_BITMAP, 407 /**Oop capability */ 408 OOP_CAPABILITY_BITMAP, 409 /**Oh Approach capability */ 410 OH_APPROACH_CAPABILITY_BITMAP 411 } DataBitMap; 412 413 typedef struct { 414 int64_t authId; 415 uint32_t type; 416 } AuthHandle; 417 418 /** 419 * @brief Defines the mapping between supported capabilities and bitmaps. 420 * 421 */ 422 typedef struct { 423 /** Bitmaps. For details, see {@link DataBitMap}. */ 424 DataBitMap bitmap; 425 /** Capability. For details, see {@link g_capabilityMap}. */ 426 char *capability; 427 } CapabilityMap; 428 429 /** 430 * @brief Defines the mapping between supported capabilities and bitmaps. 431 * 432 */ 433 static const CapabilityMap g_capabilityMap[] = { 434 {HICALL_CAPABILITY_BITMAP, (char *)"hicall"}, 435 {PROFILE_CAPABILITY_BITMAP, (char *)"profile"}, 436 {HOMEVISIONPIC_CAPABILITY_BITMAP, (char *)"homevisionPic"}, 437 {CASTPLUS_CAPABILITY_BITMAP, (char *)"castPlus"}, 438 {AA_CAPABILITY_BITMAP, (char *)"aaCapability"}, 439 {DVKIT_CAPABILITY_BITMAP, (char *)"dvKit"}, 440 {DDMP_CAPABILITY_BITMAP, (char *)"ddmpCapability"}, 441 {OSD_CAPABILITY_BITMAP, (char *)"osdCapability"}, 442 {SHARE_CAPABILITY_BITMAP, (char *)"share"}, 443 {APPROACH_CAPABILITY_BITMAP, (char *)"approach"}, 444 {VLINK_CAPABILITY_BITMAP, (char *)"virtualLink"}, 445 {TOUCH_CAPABILITY_BITMAP, (char *)"touch"}, 446 {OOP_CAPABILITY_BITMAP, (char *)"oop"}, 447 {OH_APPROACH_CAPABILITY_BITMAP, (char *)"oh_approach"} 448 }; 449 450 /** 451 * @brief Defines service publishing information. 452 * 453 */ 454 typedef struct { 455 /** Service ID */ 456 int publishId; 457 /** Discovery mode for service publishing. For details, see {@link Discovermode}. */ 458 DiscoverMode mode; 459 /** Service publishing medium. For details, see {@link ExchangeMedium}. */ 460 ExchangeMedium medium; 461 /** Service publishing frequency. For details, see {@link ExchangeFreq}. */ 462 ExchangeFreq freq; 463 /** Service publishing capabilities. For details, see {@link g_capabilityMap}. */ 464 const char *capability; 465 /** Capability data for service publishing, MUST be c-string format. */ 466 unsigned char *capabilityData; 467 /** Maximum length of the capability data for service publishing (512 bytes) */ 468 unsigned int dataLen; 469 /** Whether the device should be ranged by discoverers.*/ 470 bool ranging; 471 } PublishInfo; 472 473 /** 474 * @brief Defines service subscription information. 475 * 476 */ 477 typedef struct { 478 /** Service ID */ 479 int subscribeId; 480 /** Discovery mode for service subscription. For details, see {@link Discovermode}. */ 481 DiscoverMode mode; 482 /** Service subscription medium. For details, see {@link ExchangeMedium}. */ 483 ExchangeMedium medium; 484 /** Service subscription frequency. For details, see {@link ExchangeFreq}. */ 485 ExchangeFreq freq; 486 /** only find the device with the same account */ 487 bool isSameAccount; 488 /** find the sleeping devices */ 489 bool isWakeRemote; 490 /** Service subscription capability. For details, see {@link g_capabilityMap}. */ 491 const char *capability; 492 /** Capability data for service subscription, MUST be c-string format. */ 493 unsigned char *capabilityData; 494 /** Maximum length of the capability data for service subscription (512 bytes) */ 495 unsigned int dataLen; 496 } SubscribeInfo; 497 498 /** 499 * @brief Enumerates single heartbeat cycle parameter. 500 * 501 * @since 1.0 502 * @version 1.0 503 */ 504 typedef enum { 505 /**< Heartbeat interval 30 sec */ 506 HIGH_FREQ_CYCLE = 30, 507 /**< Heartbeat interval 60 sec */ 508 MID_FREQ_CYCLE = 60, 509 /**< Heartbeat interval 5 * 60 sec */ 510 LOW_FREQ_CYCLE = 5 * 60, 511 /**< Heartbeat interval 10 * 60 sec */ 512 DEFAULT_FREQ_CYCLE = 10 * 60, 513 } ModeCycle; 514 515 /** 516 * @brief Enumerates duration of heartbeat keeping alive parameter. 517 * 518 * @since 1.0 519 * @version 1.0 520 */ 521 typedef enum { 522 /**< Heartbeat continues for 60 sec */ 523 DEFAULT_DURATION = 60, 524 /**< Heartbeat continues for 10 * 60 sec. */ 525 NORMAL_DURATION = 10 * 60, 526 /**< Heartbeat continues for 30 * 60 sec. */ 527 LONG_DURATION = 30 * 60, 528 } ModeDuration; 529 530 /** 531 * @brief Enumerates device types. 532 * 533 */ 534 typedef enum { 535 /* Smart speaker */ 536 SMART_SPEAKER = 0x00, 537 /* PC */ 538 DESKTOP_PC, 539 /* Laptop */ 540 LAPTOP, 541 /* Mobile phone */ 542 SMART_PHONE, 543 /* Tablet */ 544 SMART_PAD, 545 /* Smart watch */ 546 SMART_WATCH, 547 /* Smart car */ 548 SMART_CAR, 549 /* Kids' watch */ 550 CHILDREN_WATCH, 551 /* Smart TV */ 552 SMART_TV, 553 } DeviceType; 554 555 /** 556 * @brief Defines the device information returned by <b>IDiscoveryCallback</b>. 557 * 558 */ 559 typedef struct { 560 /** Device ID. Its maximum length is specified by {@link DISC_MAX_DEVICE_ID_LEN}. */ 561 char devId[DISC_MAX_DEVICE_ID_LEN]; 562 /** Account hash code. Its maximum length is specified by {@link MAX_ACCOUNT_HASH_LEN}. */ 563 char accountHash[MAX_ACCOUNT_HASH_LEN]; 564 /** Device type. For details, see {@link DeviceType}. */ 565 DeviceType devType; 566 /** Device name. Its maximum length is specified by {@link DISC_MAX_DEVICE_NAME_LEN}. */ 567 char devName[DISC_MAX_DEVICE_NAME_LEN]; 568 /** Device Online Status **/ 569 bool isOnline; 570 /** Number of available connections */ 571 unsigned int addrNum; 572 /** Connection information. For details, see {@link ConnectionAddr}. */ 573 ConnectionAddr addr[CONNECTION_ADDR_MAX]; 574 /** Number of capabilities */ 575 unsigned int capabilityBitmapNum; 576 /** Device capability bitmap. 577 * The maximum number of capabilities in the bitmap is specified by {@link DISC_MAX_CAPABILITY_NUM}. 578 */ 579 unsigned int capabilityBitmap[DISC_MAX_CAPABILITY_NUM]; 580 /** Custom data. Its length is specified by {@link DISC_MAX_CUST_DATA_LEN}. */ 581 char custData[DISC_MAX_CUST_DATA_LEN]; 582 /** The distance of discovered device, in centimeters(cm)*/ 583 int32_t range; 584 } DeviceInfo; 585 586 /** 587 * @brief Defines device additional info used by inner 588 * 589 */ 590 typedef struct { 591 /** medium which describe the device found by. */ 592 ExchangeMedium medium; 593 } InnerDeviceInfoAddtions; 594 595 /** 596 * @brief Defines the capability enumeration of suppressing and restoring ble. 597 * the value same as lnn_heartbeat_utils.h 598 * 599 */ 600 typedef enum { 601 /* Suppress ble */ 602 REQUEST_DISABLE_BLE_DISCOVERY = 100, 603 /* Restore ble */ 604 REQUEST_ENABLE_BLE_DISCOVERY, 605 /* Same accout device suppress ble */ 606 SAME_ACCOUNT_REQUEST_DISABLE_BLE_DISCOVERY, 607 /* Same accout device restore ble */ 608 SAME_ACCOUNT_REQUEST_ENABLE_BLE_DISCOVERY, 609 } StrategyForBle; 610 611 #ifdef __cplusplus 612 } 613 #endif 614 #endif 615 /** @} */ 616