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_bus_center.h 32 * 33 * @brief Declares functions and constants for the bus center of the Intelligent Soft Bus. 34 * 35 * The functions are used to perform 36 * the following operations: \n 37 * <ul> 38 * <li>Adding a device to and removing a device from a LNN</li> 39 * <li>Listening for device online, offline, and information change events</li> 40 * 41 * @since 1.0 42 * @version 1.0 43 */ 44 45 #ifndef SOFTBUS_BUS_CENTER_H 46 #define SOFTBUS_BUS_CENTER_H 47 48 #include "softbus_common.h" 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 /** 55 * @brief Indicates the length of a device name buffer, including the terminating null character <b>\0</b>. 56 * 57 * @since 1.0 58 * @version 1.0 59 */ 60 #define DEVICE_NAME_BUF_LEN 128 61 62 /** 63 * @brief Indicates the mask bit for a device online event. 64 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 65 * 66 * @since 1.0 67 * @version 1.0 68 */ 69 #define EVENT_NODE_STATE_ONLINE 0x1 70 71 /** 72 * @brief Indicates the mask bit for a device offline event. 73 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 74 * 75 * @since 1.0 76 * @version 1.0 77 */ 78 #define EVENT_NODE_STATE_OFFLINE 0x02 79 80 /** 81 * @brief Indicates the mask bit for a peer device information change event. 82 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 83 * 84 * @since 1.0 85 * @version 1.0 86 */ 87 #define EVENT_NODE_STATE_INFO_CHANGED 0x04 88 89 /** 90 * @brief Indicates the mask bit for a LNN node running status change event. 91 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 92 * 93 * @since 1.0 94 * @version 1.0 95 */ 96 #define EVENT_NODE_STATUS_CHANGED 0x08 97 98 /** 99 * @brief Indicates the mask bit for a LNN node network status change event. 100 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 101 * 102 * @since 1.0 103 * @version 1.0 104 */ 105 #define EVENT_NODE_STATE_NETWORK_CHANGED 0x10 106 107 /** 108 * @brief Indicates mask bits for {@link INodeStateCb.events}. 109 * 110 * @since 1.0 111 * @version 1.0 112 */ 113 #define EVENT_NODE_STATE_MASK 0xF 114 115 /** 116 * @brief Indicates the mask bit for a peer device hichain proof exception event. 117 * If you want to receive such events, set the mask bit in {@link INodeStateCb.events}. 118 * 119 * @since 1.0 120 * @version 1.0 121 */ 122 #define EVENT_NODE_HICHAIN_PROOF_EXCEPTION 0x20 123 124 /** 125 * @brief The maximum length of meta node bypass info {@link MetaNodeConfigInfo.bypassInfo}. 126 * 127 * @since 1.0 128 * @version 1.0 129 */ 130 #define META_NODE_BYPASS_INFO_LEN 64 131 132 /** 133 * @brief Indicates the maximum length of the callerId, including the terminating null character <b>\0</b>. 134 * 135 * @since 1.0 136 * @version 1.0 137 */ 138 #define CALLER_ID_MAX_LEN 128 139 140 /** 141 * @brief Indicates the maximum length of the custom user data. 142 * 143 * @since 1.0 144 * @version 1.0 145 */ 146 #define USER_DATA_MAX_LEN 256 147 148 /** 149 * @brief The maximum of meta node {@link MetaNodeConfigInfo.bypassInfo}. 150 * 151 * @since 1.0 152 * @version 1.0 153 */ 154 #define MAX_META_NODE_NUM 3 155 156 /** 157 * @brief Indicates the length of os version buffer, including the terminating null character <b>\0</b>. 158 * 159 * @since 1.0 160 * @version 1.0 161 */ 162 #define OS_VERSION_BUF_LEN 128 163 164 /** 165 * @brief Enumerates keys for an online device. 166 * The key can be obtained via {@link GetNodeKeyInfo}. 167 * 168 * @since 1.0 169 * @version 1.0 170 */ 171 typedef enum { 172 NODE_KEY_UDID = 0, /**< UDID in string format*/ 173 NODE_KEY_UUID, /**< UUID in string format */ 174 NODE_KEY_MASTER_UDID, /**< UDID of device in string format */ 175 NODE_KEY_BR_MAC, /**< BR MAC in string format */ 176 NODE_KEY_IP_ADDRESS, /**< IP address in string format */ 177 NODE_KEY_DEV_NAME, /**< Device name in string format */ 178 NODE_KEY_NETWORK_CAPABILITY, /**< Network capability in number format */ 179 NODE_KEY_NETWORK_TYPE, /**< Network type in number format */ 180 NODE_KEY_BLE_OFFLINE_CODE, /**< Ble offlinecode in string format */ 181 NODE_KEY_DATA_CHANGE_FLAG, /**< Device info change flag in number format */ 182 NODE_KEY_NODE_ADDRESS, /**< Node address in string format */ 183 NODE_KEY_P2P_IP_ADDRESS, /**< P2P IP address in string format */ 184 NODE_KEY_DEVICE_SECURITY_LEVEL, /**< device security level in number format */ 185 NODE_KEY_DEVICE_SCREEN_STATUS, /**< device screen status in bool format */ 186 NODE_KEY_STATIC_NETWORK_CAP, /**< Static Network capability in number format */ 187 } NodeDeviceInfoKey; 188 189 /** 190 * @brief Enumerates supported network capabilities. 191 * 192 * @since 1.0 193 * @version 1.0 194 */ 195 typedef enum { 196 BIT_BLE = 0, /**< Support BLE */ 197 BIT_BR, /**< Support BR */ 198 BIT_WIFI, /**< Support WIFI */ 199 BIT_WIFI_P2P, /**< Support WIFI P2P */ 200 BIT_WIFI_24G, /**< Support WIFI 2.4G */ 201 BIT_WIFI_5G, /**< Support WIFI 5G */ 202 BIT_ETH, /**< Support ETH */ 203 BIT_USB, /**< Support USB */ 204 BIT_SLE, /**< Support SLE */ 205 BIT_COUNT, /**< Invalid type */ 206 } NetCapability; 207 208 /** 209 * @brief Enumerates supported static capabilities. 210 * 211 * @since 1.0 212 * @version 1.0 213 */ 214 typedef enum { 215 STATIC_CAP_BIT_BLE = 0, /**< Support BLE */ 216 STATIC_CAP_BIT_BR, /**< Support BR */ 217 STATIC_CAP_BIT_WIFI, /**< Support WIFI */ 218 STATIC_CAP_BIT_P2P, /**< Support WIFI P2P */ 219 STATIC_CAP_BIT_ENHANCED_P2P, /**< Support WIFI ENHANCED P2P */ 220 STATIC_CAP_BIT_ETH, /**< Support ETH */ 221 STATIC_CAP_BIT_USB, /**< Support USB */ 222 STATIC_CAP_BIT_SLE, /**< Support SLE */ 223 STATIC_CAP_BIT_COUNT, /**< Invalid type */ 224 } StaticNetCapability; 225 226 /** 227 * @brief Enumerates network types for an online device. 228 * 229 * @since 1.0 230 * @version 1.0 231 */ 232 typedef enum { 233 BIT_NETWORK_TYPE_UNKNOWN = 0, /**< Unknown network type */ 234 BIT_NETWORK_TYPE_WIFI, /**< WIFI network type */ 235 BIT_NETWORK_TYPE_BLE, /**< BLE network type */ 236 BIT_NETWORK_TYPE_BR, /**< BR network type */ 237 BIT_NETWORK_TYPE_P2P, /**< P2P network type */ 238 BIT_NETWORK_TYPE_USB = 8, /**< USB network type */ 239 BIT_NETWORK_TYPE_COUNT, /**< Invalid type */ 240 } NetworkType; 241 242 /** 243 * @brief Enumerates accuracy for time synchronize among device. 244 * 245 * @since 1.0 246 * @version 1.0 247 */ 248 typedef enum { 249 LOW_ACCURACY = 0, /**< Low accuracy */ 250 NORMAL_ACCURACY, /**< Normal accuracy */ 251 HIGH_ACCURACY, /**< High accuracy */ 252 SUPER_HIGH_ACCURACY, /**< Super high accuracy */ 253 UNAVAIL_ACCURACY, /**< Invalid accuracy */ 254 } TimeSyncAccuracy; 255 256 /** 257 * @brief Enumerates time synchronize period among device. 258 * 259 * @since 1.0 260 * @version 1.0 261 */ 262 typedef enum { 263 SHORT_PERIOD = 0, /**< Short accuracy */ 264 NORMAL_PERIOD, /**< Normal accuracy */ 265 LONG_PERIOD, /**< Long accuracy */ 266 } TimeSyncPeriod; 267 268 /** 269 * @brief Enumerates time synchronize flag. 270 * 271 * @since 1.0 272 * @version 1.0 273 */ 274 typedef enum { 275 NODE_SPECIFIC = 0, /**< Time sync in a specific mode */ 276 ALL_LNN, /**< Time sync during the entire networking */ 277 WRITE_RTC, /**< Write RTC synchronization */ 278 } TimeSyncFlag; 279 280 /** 281 * @brief Defines the basic information of a device. 282 * 283 * @since 1.0 284 * @version 1.0 285 */ 286 typedef struct { 287 char networkId[NETWORK_ID_BUF_LEN]; /**< Device network id */ 288 char deviceName[DEVICE_NAME_BUF_LEN]; /**< Device name */ 289 uint16_t deviceTypeId; /**< Device type id */ 290 int32_t osType; /**< Os type */ 291 char osVersion[OS_VERSION_BUF_LEN]; /**< Os version */ 292 } NodeBasicInfo; 293 294 /** 295 * @brief Enumerates device information change types. For details, see {@link INodeStateCb.onNodeBasicInfoChanged}. 296 * 297 * @since 1.0 298 * @version 1.0 299 */ 300 typedef enum { 301 TYPE_NETWORK_ID = 0, /**< Network ID change */ 302 TYPE_DEVICE_NAME, /**< Device name change */ 303 TYPE_NETWORK_INFO, /**< Device network info change */ 304 } NodeBasicInfoType; 305 306 /** 307 * @brief Defines the running status about a device. see {@link INodeStateCb.onNodeStatusChanged} 308 * 309 * @since 1.0 310 * @version 1.0 311 */ 312 typedef struct { 313 NodeBasicInfo basicInfo; /**< The basic info of device */ 314 uint16_t authStatus; /**< The auth state of device */ 315 uint16_t dataBaseStatus; /**< The data base state of device */ 316 uint16_t meshType; /**< The mesh type of device */ 317 uint16_t reserved[NODE_STATUS_MAX_NUM - 3]; /**< The reserved data of device */ 318 } NodeStatus; 319 320 /** 321 * @brief Enumerates device information change types. For details, see {@link INodeStateCb.onNodeStatusChanged}. 322 * 323 * @since 1.0 324 * @version 1.0 325 */ 326 typedef enum { 327 TYPE_AUTH_STATUS = 2, /**< Certify status change */ 328 TYPE_DATABASE_STATUS = 3, /**< Database change */ 329 TYPE_MESH_TYPE = 4, /**< Lnn mesh type change */ 330 TYPE_SCREEN_STATUS = 5, /**< Screen status change */ 331 TYPE_STATUS_MAX = 6, /**< Max num */ 332 } NodeStatusType; 333 334 /** 335 * @brief Defines time synchronize result. 336 * 337 * @since 1.0 338 * @version 1.0 339 */ 340 typedef struct { 341 int32_t millisecond; /**< Number of milli second */ 342 int32_t microsecond; /**< Number of micro second */ 343 TimeSyncAccuracy accuracy; /**< Time sync accuracy */ 344 } TimeSyncResult; 345 346 /** 347 * @brief Defines time synchronize result info. 348 * 349 * @since 1.0 350 * @version 1.0 351 */ 352 typedef struct { 353 TimeSyncResult result; /**< Time synchronize result */ 354 TimeSyncFlag flag; /**< Time synchronize flag */ 355 union { 356 char targetNetworkId[NETWORK_ID_BUF_LEN]; /**< The network id of time sync target device */ 357 char masterNetworkId[NETWORK_ID_BUF_LEN]; /**< The network id of node */ 358 } target; 359 } TimeSyncResultInfo; 360 361 /** 362 * @brief Enumerates error codes for service publishing failures. 363 * 364 * The error codes are returned to the caller through <b>IPublishCallback</b>. 365 * 366 * @since 1.0 367 * @version 1.0 368 */ 369 typedef enum { 370 PUBLISH_LNN_SUCCESS = 0, /**< Publish success */ 371 PUBLISH_LNN_NOT_SUPPORT_MEDIUM = 1, /**< Unsupported medium */ 372 PUBLISH_LNN_INTERNAL = 2, /**< Internal error */ 373 PUBLISH_LNN_UNKNOWN = 0xFF /**< Unknown reason */ 374 } PublishResult; 375 376 /** 377 * @brief Enumerates error codes for service subscription failures. 378 * 379 * The error codes are returned to the caller through <b>IDiscoveryCallback</b>. 380 * 381 * @since 1.0 382 * @version 1.0 383 */ 384 typedef enum { 385 REFRESH_LNN_SUCCESS = 0, /**< Refresh success */ 386 REFRESH_LNN_NOT_SUPPORT_MEDIUM = 1, /**< Unsupported medium */ 387 REFRESH_LNN_INTERNAL = 2, /**< Internal error */ 388 REFRESH_LNN_UNKNOWN = 0xFF /**< Unknown error */ 389 } RefreshResult; 390 391 /** 392 * @brief Defines the callbacks for successful and failed service publishing. 393 * 394 * @since 1.0 395 * @version 1.0 396 */ 397 typedef struct { 398 /** 399 * @brief Callback for publish result. 400 * 401 * @param publishId the publish Id which has been published. 402 * @param reason the publish result of this time. 403 * 404 * @since 1.0 405 * @version 1.0 406 */ 407 void (*OnPublishResult)(int publishId, PublishResult reason); 408 } IPublishCb; 409 410 /** 411 * @brief Defines a callback for service subscription. 412 * 413 * Three types of callbacks are available. 414 * 415 * @since 1.0 416 * @version 1.0 417 */ 418 typedef struct { 419 /** 420 * @brief Callback that is invoked when a device is found. 421 * 422 * @param device Indicates the pointer to the device info about device. 423 * For details, see {@link DeviceInfo}. 424 * 425 * @since 1.0 426 * @version 1.0 427 */ 428 void (*OnDeviceFound)(const DeviceInfo *device); 429 /** 430 * @brief Callback for a subscription result. 431 * 432 * @param refreshId Indicates the refresh Id which. 433 * @param reason Indicates the result of this time. For details, see {@link RefreshResult}. 434 * 435 * @since 1.0 436 * @version 1.0 437 */ 438 void (*OnDiscoverResult)(int32_t refreshId, RefreshResult reason); 439 } IRefreshCallback; 440 441 /** 442 * @brief Enumerates error codes for trust relationship change type. 443 * 444 * @since 1.0 445 * @version 1.0 446 */ 447 typedef enum { 448 DEVICE_NOT_TRUSTED = 0, /**< device not trusted */ 449 DEVICE_TRUST_RELATIONSHIP_CHANGE = 1, /**< device trust relationship change */ 450 DEVICE_FOREGROUND_USERID_CHANGE = 2, /**< device useridchecksum change*/ 451 } TrustChangeType; 452 453 /** 454 * @brief Defines a callback that is invoked when the device state or information changes. 455 * For details, see {@link RegNodeDeviceStateCb}. 456 * 457 * @since 1.0 458 * @version 1.0 459 */ 460 typedef struct { 461 /** 462 * Mask of an event that is listened for. 463 * The event can be received only if the corresponding mask bit is set and the callback is specified. 464 */ 465 uint32_t events; 466 /** 467 * @brief Called when a specified device, rather than a specified ability, gets online. 468 * 469 * @param info Indicates the pointer to the basic information about the device. 470 * For details, see {@link NodeBasicInfo}. 471 * 472 * @since 1.0 473 * @version 1.0 474 */ 475 void (*onNodeOnline)(NodeBasicInfo *info); 476 /** 477 * @brief Called when a specified device, rather than a specified ability, gets offline. 478 * 479 * @param info Indicates the pointer to the basic information about the device. 480 * For details, see {@link NodeBasicInfo}. 481 * 482 * @since 1.0 483 * @version 1.0 484 */ 485 void (*onNodeOffline)(NodeBasicInfo *info); 486 /** 487 * @brief Called when the basic information of a device changes. 488 * 489 * @param type Indicates the device type. For details, see {@link NodeBasicInfoType}. 490 * @param info Indicates the pointer to the new basic information of the device. 491 * For details, see {@link NodeBasicInfo}. 492 * 493 * @since 1.0 494 * @version 1.0 495 */ 496 void (*onNodeBasicInfoChanged)(NodeBasicInfoType type, NodeBasicInfo *info); 497 /** 498 * @brief Called when the local networkId of a device changes. 499 * 500 * @since 1.0 501 * @version 1.0 502 */ 503 void (*onLocalNetworkIdChanged)(void); 504 /** 505 * @brief Called when the device trust relationship change. 506 * 507 * @param type type Indicates the trust relationship change type. 508 * @param msg Indicates the pointer to relationship change information. 509 * @param msgLen The length of msg. 510 * 511 * @since 1.0 512 * @version 1.0 513 */ 514 void (*onNodeDeviceTrustedChange)(TrustChangeType type, const char *msg, uint32_t msgLen); 515 /** 516 * @brief Called when the running status of a device changes. 517 * 518 * @param type Indicates the device type. For details, see {@link NodeStatusType}. 519 * @param status Indicates the pointer to the new status of the device. 520 * For details, see {@link NodeStatus}. 521 * 522 * @since 1.0 523 * @version 1.0 524 */ 525 void (*onNodeStatusChanged)(NodeStatusType type, NodeStatus *status); 526 /** 527 * @brief Called when the devices have non-consistent group relationship. 528 * 529 * @param proofInfo The device proof info. 530 * @param proofLen The device proof info length. 531 * @param deviceTypeId The device type id. 532 * @param errcode Indicates the result code. 533 * 534 * @since 1.0 535 * @version 1.0 536 */ 537 void (*onHichainProofException)( 538 const char *proofInfo, uint32_t proofLen, uint16_t deviceTypeId, int32_t errCode); 539 } INodeStateCb; 540 541 /** 542 * @brief Defines a callback that is invoked when the time synchronize has result. 543 * 544 * @since 1.0 545 * @version 1.0 546 */ 547 typedef struct { 548 /** 549 * @brief Called when the time synchronize has result. 550 * 551 * @param info Contains the time synchronize result info, see {@link TimeSyncResultInfo}. 552 * @param retCode Indicates the result code. Value <b>0</b> indicates that the time synchronize is successful and 553 * result is valid, and any other value indicates the opposite. 554 * 555 * @since 1.0 556 * @version 1.0 557 */ 558 void (*onTimeSyncResult)(const TimeSyncResultInfo *info, int32_t retCode); 559 } ITimeSyncCb; 560 561 /** 562 * @brief Defines a meta node configuration, see {@link ActiveMetaNode}. 563 * 564 * @since 1.0 565 * @version 1.0 566 */ 567 typedef struct { 568 char udid[UDID_BUF_LEN]; /**< The udid of meta node */ 569 char deviceName[DEVICE_NAME_BUF_LEN]; /**< The name of meta node */ 570 uint16_t deviceTypeId; /**< The device type id of meta node */ 571 uint8_t addrNum; /**< The connection addr type of meta node */ 572 ConnectionAddr addr[CONNECTION_ADDR_MAX]; /**< The connection addr of meta node */ 573 char bypassInfo[META_NODE_BYPASS_INFO_LEN]; /**< The pass info of meta node */ 574 } MetaNodeConfigInfo; 575 576 /** 577 * @brief Defines a meta node information, see {@link MetaNodeInfo}. 578 * 579 * @since 1.0 580 * @version 1.0 581 */ 582 typedef struct { 583 char metaNodeId[NETWORK_ID_BUF_LEN]; /**< The id of meta node */ 584 bool isOnline; /**< The online state of meta node */ 585 MetaNodeConfigInfo configInfo; /**< The node ConfigInfo of meta node */ 586 } MetaNodeInfo; 587 588 /** 589 * @brief Defines an action mode, see {@link ModeAction}. 590 * 591 * @since 1.0 592 * @version 1.0 593 */ 594 typedef enum { 595 FLUSH_DEVICE_LIST, /**< The action of flush device list */ 596 CHANGE_TCP_KEEPALIVE, /**< The action of change tcp keepalive */ 597 ACTION_MAX /**< The action max */ 598 } ModeAction; 599 600 /** 601 * @brief Defines heartbeat mode parameter, see {@link GearMode}. 602 * 603 * @since 1.0 604 * @version 1.0 605 */ 606 typedef struct { 607 ModeCycle cycle; /**< Heartbeat mode cycle */ 608 ModeDuration duration; /**< Heartbeat mode duration */ 609 bool wakeupFlag; /**< Heartbeat wakeup peer device or not */ 610 ModeAction action; /**< Heartbeat mode action */ 611 } GearMode; 612 613 /** 614 * @brief Called when a device is added to a LNN via {@link JoinLNN}. 615 * 616 * @param addr Indicates the pointer to the address of the peer device. 617 * @param networkId Indicates the pointer to the network ID of the device if it is successfully added to the LNN. 618 * This parameter makes no sense if the device fails to be added to the LNN. 619 * @param retCode Indicates the result code. Value <b>0</b> indicates that the device is successfully added to the LNN, 620 * and any other value indicates the opposite. 621 * 622 * @since 1.0 623 * @version 1.0 624 */ 625 typedef void (*OnJoinLNNResult)(ConnectionAddr *addr, const char *networkId, int32_t retCode); 626 627 /** 628 * @brief Called when a device is removed from a LNN via {@link LeaveLNN}. 629 * 630 * @param networkId Indicates the pointer to the network ID of the device. 631 * @param retCode Indicates the result code. Value <b>0</b> indicates that the device is successfully 632 * removed from the LNN, and any other value indicates the opposite. 633 * 634 * @since 1.0 635 * @version 1.0 636 */ 637 typedef void (*OnLeaveLNNResult)(const char *networkId, int32_t retCode); 638 639 /** 640 * @brief Adds the current device to the LNN where a specified device resides. 641 * 642 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 643 * For the same caller, the value of this parameter must be the same for all functions. 644 * @param target Indicates the pointer to the address of the specified device. For details, see {@link ConnectionAddr}. 645 * @param cb Indicates the callback for the result. If you set this parameter to NULL, you will not receive the result. 646 * 647 * @return Returns <b>0</b> if the request to add the device is accepted, and the result can be obtained from the 648 * callback; returns any other value if the device fails to be added to the network, in which case you will not receive 649 * the result. 650 * 651 * @since 1.0 652 * @version 1.0 653 */ 654 int32_t JoinLNN(const char *pkgName, ConnectionAddr *target, OnJoinLNNResult cb, bool isForceJoin); 655 656 /** 657 * @brief Removes the current device from the LNN. 658 * 659 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 660 * For the same caller, the value of this parameter must be the same for all functions. 661 * @param networkId Indicates the pointer to the network ID that is returned 662 * after the device is added to the LNN via {@link JoinLNN}. 663 * @param cb Indicates the callback for the result. If you set this parameter to <b>NULL</b>, 664 * you will not receive the result. 665 * 666 * @return Returns <b>0</b> if the request to remove the device is accepted, and the result can be obtained from the 667 * callback; returns any other value if the device fails to be removed from the network, in which case you will not 668 * receive the result. 669 * 670 * @since 1.0 671 * @version 1.0 672 */ 673 int32_t LeaveLNN(const char *pkgName, const char *networkId, OnLeaveLNNResult cb); 674 675 /** 676 * @brief Registers a callback for device state changes, rather than a specified ability, gets online. 677 * 678 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 679 * For the same caller, the value of this parameter must be the same for all functions. 680 * @param callback Indicates the pointer to the callback to register. For details, see {@link INodeStateCb}. 681 * 682 * @return Returns <b>0</b> if the registration is successful; returns any other value otherwise. 683 * 684 * @since 1.0 685 * @version 1.0 686 */ 687 int32_t RegNodeDeviceStateCb(const char *pkgName, INodeStateCb *callback); 688 689 /** 690 * @brief Unregisters a callback for device state changes. 691 * 692 * @param callback Indicates the pointer to the callback to unregister. For details, see {@link INodeStateCb}. 693 * 694 * @return Returns <b>0</b> if the unregistration is successful; returns any other value otherwise. 695 * 696 * @since 1.0 697 * @version 1.0 698 */ 699 int32_t UnregNodeDeviceStateCb(INodeStateCb *callback); 700 701 /** 702 * @brief Obtains basic information about all the online devices. 703 * 704 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 705 * For the same caller, the value of this parameter must be the same for all functions. 706 * @param info Indicates the double pointer to the memory that stores the obtained basic information. 707 * @param infoNum Indicates the pointer to the number of devices. 708 * 709 * @return Returns <b>0</b> if the basic information is obtained, in which case <b>info</b> and <b>infoNum</b> are 710 * valid; returns any other value otherwise. 711 * 712 * @since 1.0 713 * @version 1.0 714 */ 715 int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum); 716 717 /** 718 * @brief Releases the memory returned by {@link GetAllNodeDeviceInfo}. 719 * 720 * @param info Indicates the pointer to the memory returned by {@link GetAllNodeDeviceInfo}. 721 * 722 * @since 1.0 723 * @version 1.0 724 */ 725 void FreeNodeInfo(NodeBasicInfo *info); 726 727 /** 728 * @brief Obtains basic information about the current device. 729 * 730 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 731 * For the same caller, the value of this parameter must be the same for all functions. 732 * @param info Indicates the double pointer to the memory that stores the obtained basic information. 733 * 734 * @return Returns <b>0</b> if the basic information is obtained, in which case <b>info</b> is valid; 735 * returns any other value otherwise. 736 * 737 * @since 1.0 738 * @version 1.0 739 */ 740 int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info); 741 742 /** 743 * @brief Set the Node Data Change Flag object. 744 * 745 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 746 * For the same caller, the value of this parameter must be the same for all functions. 747 * @param networkId Indicates the pointer to the network ID of the device. 748 * @param dataChangeFlag Indicates the data change flag. 749 * 750 * @return Returns <b>0</b> if set change flag success, returns any other value otherwise. 751 * 752 * @since 1.0 753 * @version 1.0 754 */ 755 int32_t SetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag); 756 757 /** 758 * @brief Obtains a specified {@link NodeDeviceInfoKey} of an online device. 759 * 760 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 761 * For the same caller, the value of this parameter must be the same for all functions. 762 * @param networkId Indicates the pointer to the network ID of the device. 763 * @param key Indicates the key to be obtained. 764 * @param info Indicates the pointer to the buffer that stores the obtained key. 765 * @param infoLen Indicates the buffer length. 766 * 767 * @return Returns <b>0</b> if the {@link NodeDeviceInfoKey} is obtained, in which case <b>info</b> is valid; 768 * returns any other value otherwise. 769 * 770 * @since 1.0 771 * @version 1.0 772 */ 773 int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, 774 NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen); 775 776 /** 777 * @brief Start the time synchronize with specific target node. 778 * 779 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 780 * For the same caller, the value of this parameter must be the same for all functions. 781 * @param targetNetworkId Indicates the pointer to the address of the specified device. 782 * @param accuracy Time synchronize accuracy. 783 * @param period Time synchronize period 784 * @param cb Indicates the callback for the result. 785 * 786 * @return Returns <b>0</b> if the request is accepted, and the result can be obtained from the 787 * callback; returns any other value if the request fails, in which case you will not receive 788 * the result. 789 * 790 * @since 1.0 791 * @version 1.0 792 */ 793 int32_t StartTimeSync(const char *pkgName, const char *targetNetworkId, TimeSyncAccuracy accuracy, 794 TimeSyncPeriod period, ITimeSyncCb *cb); 795 796 /** 797 * @brief Stop the time synchronize with specific target node. 798 * 799 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 800 * For the same caller, the value of this parameter must be the same for all functions. 801 * @param targetNetworkId Indicates the pointer to the address of the specified device. 802 * 803 * @return Returns <b>0</b> if the request is removed; returns any other value if the request fails. 804 * 805 * @since 1.0 806 * @version 1.0 807 */ 808 int32_t StopTimeSync(const char *pkgName, const char *targetNetworkId); 809 810 /** 811 * @brief Publishes a specified service. 812 * 813 * Peer devices in the same LAN as the device that publishes this service can discover this service as needed. 814 * The service is identified by <b>publicId</b> and <b>pkgName</b>. 815 * 816 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 817 * @param info Indicates the pointer to the service publishing information. For details, see {@link PublishInfo}. 818 * @param cb Indicates the pointer to the service publishing callback {@link IPublishCb}. 819 * 820 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 821 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 822 * @return Returns <b>SOFTBUS_LOCK_ERR</b> if the mutex fails to be locked. 823 * @return Returns <b>SOFTBUS_OK</b> if the service is successfully published. 824 * 825 * @since 1.0 826 * @version 1.0 827 */ 828 int32_t PublishLNN(const char *pkgName, const PublishInfo *info, const IPublishCb *cb); 829 830 /** 831 * @brief stoppublishes a specified service. 832 * 833 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 834 * @param publishId Indicates the service ID. 835 * 836 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>pkgName</b> is invalid. 837 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 838 * @return Returns <b>SOFTBUS_OK</b> if the service is successfully unpublished. 839 * 840 * @since 1.0 841 * @version 1.0 842 */ 843 int32_t StopPublishLNN(const char *pkgName, int32_t publishId); 844 845 /** 846 * @brief Subscribes to a specified service. 847 * 848 * Information about the device that publishes the service will be reported to the device that subscribes to 849 * the service. 850 * The service is identified by <b>subscribeId</b> and <b>pkgName</b>. 851 * 852 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 853 * @param info Indicates the pointer to the service subscription information. For details, see {@link SubscribeInfo}. 854 * @param cb Indicates the service subscription callback {@link IRefreshCallback}. 855 * 856 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 857 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 858 * @return Returns <b>SOFTBUS_LOCK_ERR</b> if the mutex fails to be locked. 859 * @return Returns <b>SOFTBUS_OK</b> if the service subscription is successful. 860 * 861 * @since 1.0 862 * @version 1.0 863 */ 864 int32_t RefreshLNN(const char *pkgName, const SubscribeInfo *info, const IRefreshCallback *cb); 865 866 /** 867 * @brief Unsubscribes from a specified service. 868 * 869 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 870 * @param refreshId Indicates the service ID. 871 * 872 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if <b>pkgName</b> is invalid. 873 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 874 * @return Returns <b>SOFTBUS_OK</b> if the service unsubscription is successful. 875 * 876 * @since 1.0 877 * @version 1.0 878 */ 879 int32_t StopRefreshLNN(const char *pkgName, int32_t refreshId); 880 881 /** 882 * @brief Active meta node. The meta node online status will be notified by {@link INodeStateCb} 883 * 884 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 885 * For the same caller, the value of this parameter must be the same for all functions. 886 * @param info Meta node configuration information, see {@link MetaNodeConfigInfo}. 887 * @param metaNodeId Save meta node ID when it is activated successfully, its buffer length must be not 888 * less then NETWORK_ID_BUF_LEN. 889 * 890 * @return Returns <b>0</b> if the meta node is activated; returns any other value if the request fails. 891 * 892 * @since 1.0 893 * @version 1.0 894 */ 895 int32_t ActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId); 896 897 /** 898 * @brief Deactive meta node. The meta node will be removed. 899 * 900 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 901 * For the same caller, the value of this parameter must be the same for all functions. 902 * @param metaNodeId The meta node ID which deactivated, it's obtained by {@link ActiveMetaNode}. 903 * 904 * @return Returns <b>0</b> if the meta node is deactivated; returns any other value if the request fails. 905 * 906 * @since 1.0 907 * @version 1.0 908 */ 909 int32_t DeactiveMetaNode(const char *pkgName, const char *metaNodeId); 910 911 /** 912 * @brief Get all meta node by {@link ActiveMetaNode}. 913 * 914 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 915 * For the same caller, the value of this parameter must be the same for all functions. 916 * @param infos The buffer for save meta node info. 917 * @param infoNum The infos buffer num which maximum is {@link MAX_META_NODE_NUM}. 918 * 919 * @return Returns <b>0</b> if the call is success; returns any other value if it fails. 920 * 921 * @since 1.0 922 * @version 1.0 923 */ 924 int32_t GetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum); 925 926 /** 927 * @brief Modify heartbeat parameters and trigger a temporary heartbeat. 928 * 929 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 930 * For the same caller, the value of this parameter must be the same for all functions. 931 * @param callerId The id of the caller, whitch cannot be <b>NULL</b>, and maxium length is {@link CALLER_ID_MAX_LEN}. 932 * @param targetNetworkId The networkId of the target device to refresh online state, and could be <b>NULL</b>. 933 * @param mode The duration or cycle parameter of heartbeat. For details, see {@link GearMode}. 934 * 935 * @return Returns <b>0</b> if the call is success; returns any other value if it fails. 936 * 937 * @since 1.0 938 * @version 1.0 939 */ 940 int32_t ShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId, const GearMode *mode); 941 942 /** 943 * @brief For dm use only. Broadcast notification of device trust relation changes. 944 * 945 * @param pkgName Indicates the pointer to the caller ID, for example, the package name. 946 * For the same caller, the value of this parameter must be the same for all functions. 947 * @param msg The value must be in JSON format and comply with the API usage restrictions. 948 * @param msgLen The length of msg. 949 * 950 * @return Returns <b>0</b> if the call is success; returns any other value if it fails. 951 * 952 * @since 1.0 953 * @version 1.0 954 */ 955 int32_t SyncTrustedRelationShip(const char *pkgName, const char *msg, uint32_t msgLen); 956 957 /** 958 * @brief Set Local device display name. 959 * 960 * @param pkgName Indicates the pointer to the service package name, which can contain a maximum of 64 bytes. 961 * @param nameData Indicates the pointer to the display name, MUST be cJSON format. 962 * @param len Len Indicates the length of nameData. 963 * 964 * @return Returns <b>SOFTBUS_INVALID_PARAM</b> if parameters is null or invalid. 965 * @return Returns <b>SOFTBUS_DISCOVER_NOT_INIT</b> if the Intelligent Soft Bus client fails to be initialized. 966 * @return Returns <b>SOFTBUS_LOCK_ERR</b> if the mutex fails to be locked. 967 * @return Returns <b>SOFTBUS_OK</b> if the service subscription is successful 968 * 969 * @since 5.1 970 * @version 1.0 971 */ 972 int32_t SetDisplayName(const char *pkgName, const char *nameData, uint32_t len); 973 #ifdef __cplusplus 974 } 975 #endif 976 977 #endif 978