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