1 /* 2 * Copyright (C) 2021-2022 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 Bluetooth 18 * @{ 19 * 20 * @brief Provides basic Bluetooth capabilities. 21 * 22 * This module allows you to enable and disable Bluetooth, and access basic Bluetooth capabilities.\n 23 * Bluetooth uses profiles such as BT-GAP, BLE, BLE-GATT, BT-data transmission, HFP, A2DP, AVRCP, MAP, and PBAP. 24 * 25 * @since 6 26 */ 27 28 /** 29 * @file ohos_bt_gatt.h 30 * 31 * @brief Declares basic GATT data structures and functions, such as advertising and scan functions. 32 * 33 * @since 6 34 */ 35 36 37 #ifndef OHOS_BT_GATT_H 38 #define OHOS_BT_GATT_H 39 40 #include "ohos_bt_def.h" 41 #include <stdint.h> 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @brief Enumerates ble address type 49 * 50 * @since 6 51 */ 52 typedef enum { 53 BLE_ADDR_RANDOM = 0x01, 54 } BleAddrType; 55 56 /** 57 * @brief Enumerates advertising filtering parameters. 58 * 59 * The parameters specify whether the advertiser uses a whitelist to filter scan or connection requests from scanners. 60 * 61 * @since 6 62 */ 63 typedef enum { 64 /** Processing scan and connection requests from all devices */ 65 OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00, 66 /** Processing connection requests from all devices and only the scan requests from devices in the whitelist */ 67 OHOS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY = 0x01, 68 /** Processing scan requests from all devices and only the connection requests from devices in the whitelist */ 69 OHOS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST = 0x02, 70 /** Processing only the scan and connection requests from devices in the whitelist */ 71 OHOS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST = 0x03, 72 } BleAdvFilter; 73 74 /** 75 * @brief Enumerates advertisement types. 76 * 77 * @since 6 78 */ 79 typedef enum { 80 /** Connectable and scannable undirected advertisement (default) */ 81 OHOS_BLE_ADV_IND = 0x00, 82 /** Connectable directed advertisement with a high duty ratio */ 83 OHOS_BLE_ADV_DIRECT_IND_HIGH = 0x01, 84 /** Scannable undirected advertisement */ 85 OHOS_BLE_ADV_SCAN_IND = 0x02, 86 /** Unconnectable undirected advertisement */ 87 OHOS_BLE_ADV_NONCONN_IND = 0x03, 88 /** Connectable directed advertisement with a low duty ratio */ 89 OHOS_BLE_ADV_DIRECT_IND_LOW = 0x04, 90 } BleAdvType; 91 92 /** 93 * @brief Enumerates I/O capability modes. 94 * 95 * @since 6 96 */ 97 typedef enum { 98 /** <b>DisplayOnly</b>: display capability only */ 99 OHOS_BLE_IO_CAP_OUT = 0x00, 100 /** <b>DisplayYesNo</b>: YES/NO input and display capabilities */ 101 OHOS_BLE_IO_CAP_IO, 102 /** 103 * <b>KeyboardOnly</b>: Input of a number from 0 to 9, the confirmation key, and YES/NO, 104 * with no display capability 105 */ 106 OHOS_BLE_IO_CAP_IN, 107 /** <b>NoInputNoOutput</b>: no I/O capability */ 108 OHOS_BLE_IO_CAP_NONE, 109 /** 110 * <b>KeyboardDisplay</b>: Input of a number from 0 to 9, the confirmation key, and YES/NO, 111 * with the display capability 112 */ 113 OHOS_BLE_IO_CAP_KBDISP 114 } BleIoCapMode; 115 116 /** 117 * @brief Enumerates authentication modes for secure connection requests. 118 * 119 * @since 6 120 */ 121 typedef enum { 122 /** No bonding */ 123 OHOS_BLE_AUTH_NO_BOND = 0x00, 124 /** Bonding */ 125 OHOS_BLE_AUTH_BOND, 126 /** MITM only */ 127 OHOS_BLE_AUTH_REQ_MITM, 128 /** Secure connection only */ 129 OHOS_BLE_AUTH_REQ_SC_ONLY, 130 /** Secure connection and bonding */ 131 OHOS_BLE_AUTH_REQ_SC_BOND, 132 /** Secure connection and MITM */ 133 OHOS_BLE_AUTH_REQ_SC_MITM, 134 /** Secure connection, MITM, and bonding */ 135 OHOS_BLE_AUTH_REQ_SC_MITM_BOND 136 } BleAuthReqMode; 137 138 /** 139 * @brief Enumerates BLE scan types. 140 * 141 * @since 6 142 */ 143 typedef enum { 144 /** A passive scan with no scan request */ 145 OHOS_BLE_SCAN_TYPE_PASSIVE = 0x00, 146 /** An active scan that may contain a scan request */ 147 OHOS_BLE_SCAN_TYPE_ACTIVE, 148 } BleScanType; 149 150 /** 151 * @brief Enumerates BLE scan modes. 152 * 153 * @since 6 154 */ 155 typedef enum { 156 /** Low power */ 157 OHOS_BLE_SCAN_MODE_LOW_POWER = 0x00, 158 /** Balance */ 159 OHOS_BLE_SCAN_MODE_BALANCED = 0x01, 160 /** Low latency */ 161 OHOS_BLE_SCAN_MODE_LOW_LATENCY = 0x02, 162 /** Duty cycle 2 */ 163 OHOS_BLE_SCAN_MODE_OP_P2_60_3000 = 0x03, 164 /** Duty cycle 10 */ 165 OHOS_BLE_SCAN_MODE_OP_P10_60_600 = 0x04, 166 /** Duty cycle 25 */ 167 OHOS_BLE_SCAN_MODE_OP_P25_60_240 = 0x05, 168 /** Duty cycle 100 */ 169 OHOS_BLE_SCAN_MODE_OP_P100_1000_1000 = 0x06, 170 /** Duty cycle 50 */ 171 OHOS_BLE_SCAN_MODE_OP_P50_100_200 = 0x07, 172 /** Duty cycle 10 30/300 */ 173 OHOS_BLE_SCAN_MODE_OP_P10_30_300 = 0x08, 174 /** Duty cycle 2 30/1500 */ 175 OHOS_BLE_SCAN_MODE_OP_P2_30_1500 = 0x09, 176 /** Duty cycle 75 30/40 */ 177 OHOS_BLE_SCAN_MODE_OP_P75_30_40 = 0x0A, 178 /** Duty cycle 50 30/60 */ 179 OHOS_BLE_SCAN_MODE_OP_P50_30_60 = 0x0B, 180 } BleScanMode; 181 182 /** 183 * @brief Enumerates policies for filtering advertisements in a BLE scan. 184 * 185 * @since 6 186 */ 187 typedef enum { 188 /** 189 * Accepting all advertisements except the directed advertisements 190 * that are not sent to the current device (default) 191 */ 192 OHOS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL = 0x00, 193 /** 194 * Accepting advertisements from devices in the whitelist and ignoring the directed advertisements 195 * that are not sent to the current device */ 196 OHOS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST, 197 /** 198 * Accepting all undirected advertisements, directed advertisements sent by advertisers with 199 * resolvable private addresses, and all the directed advertisements sent to the current device 200 */ 201 OHOS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL_AND_RPA, 202 /** 203 * Accepting all undirected advertisements from the devices in the whitelist, 204 * directed advertisements sent by advertisers with resolvable private addresses, 205 * and all the directed advertisements sent to the current device 206 */ 207 OHOS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST_AND_RPA 208 } BleScanFilterPolicy; 209 210 /** 211 * @brief Enumerates advertisement types in the BLE scan result. 212 * 213 * @since 6 214 */ 215 typedef enum { 216 /** Extended, unconnectable, unscannable, and undirected advertisement */ 217 OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00, 218 /** Extended, unconnectable, unscannable, and directed advertisement */ 219 OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04, 220 /** Extended, connectable, and undirected advertisement */ 221 OHOS_BLE_EVT_CONNECTABLE = 0x01, 222 /** Extended, connectable, and directed advertisement */ 223 OHOS_BLE_EVT_CONNECTABLE_DIRECTED = 0x05, 224 /** Extended, scannable, and undirected advertisement */ 225 OHOS_BLE_EVT_SCANNABLE = 0x02, 226 /** Extended, scannable, and directed advertisement */ 227 OHOS_BLE_EVT_SCANNABLE_DIRECTED = 0x06, 228 229 /** Legacy, unconnectable, and undirected advertisement */ 230 OHOS_BLE_EVT_LEGACY_NON_CONNECTABLE = 0x10, 231 /** Legacy, scannable, and undirected advertisement */ 232 OHOS_BLE_EVT_LEGACY_SCANNABLE = 0x12, 233 /** Legacy, connectable, scannable, and undirected advertisement */ 234 OHOS_BLE_EVT_LEGACY_CONNECTABLE = 0x13, 235 /** Legacy, connectable, and directed advertisement */ 236 OHOS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED = 0x15, 237 /** Legacy scan response corresponding to <b>ADV_SCAN_IND</b> */ 238 OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN = 0x1A, 239 /** Legacy scan response corresponding to <b>ADV_IND</b> */ 240 OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV = 0x1B 241 } BleScanResultEvtType; 242 243 /** 244 * @brief Enumerates data integrity types for a BLE scan result. 245 * 246 * @since 6 247 */ 248 typedef enum { 249 /** Complete data or the last segment */ 250 OHOS_BLE_DATA_COMPLETE = 0x00, 251 /** Incomplete data, with more data to come */ 252 OHOS_BLE_DATA_INCOMPLETE_MORE_TO_COME = 0x01, 253 /** Incomplete truncated data, with no more data to come */ 254 OHOS_BLE_DATA_INCOMPLETE_TRUNCATED = 0x02, 255 } BleScanResultDataStatus; 256 257 /** 258 * @brief Enumerates address types for a BLE scan result. 259 * 260 * @since 6 261 */ 262 typedef enum { 263 /** Public device address */ 264 OHOS_BLE_PUBLIC_DEVICE_ADDRESS = 0x00, 265 /** Random device address */ 266 OHOS_BLE_RANDOM_DEVICE_ADDRESS = 0x01, 267 /** Public identity address */ 268 OHOS_BLE_PUBLIC_IDENTITY_ADDRESS = 0x02, 269 /** Random (static) identity address */ 270 OHOS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS = 0x03, 271 /** Unresolvable random device address */ 272 OHOS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS = 0xFE, 273 /** No address (anonymous advertisement) */ 274 OHOS_BLE_NO_ADDRESS = 0xFF, 275 } BleScanResultAddrType; 276 277 /** 278 * @brief Enumerates PHY types for a BLE scan result. 279 * 280 * @since 6 281 */ 282 typedef enum { 283 /** No advertisement packet */ 284 OHOS_BLE_SCAN_PHY_NO_PACKET = 0x00, 285 /** 1M PHY */ 286 OHOS_BLE_SCAN_PHY_1M = 0x01, 287 /** 2M PHY */ 288 OHOS_BLE_SCAN_PHY_2M = 0x02, 289 /** Coded PHY */ 290 OHOS_BLE_SCAN_PHY_CODED = 0x03 291 } BleScanResultPhyType; 292 293 /** 294 * @brief Defines BLE advertising own address parameters. 295 * 296 * @since 6 297 */ 298 typedef struct { 299 uint8_t addr[OHOS_BD_ADDR_LEN]; // little endian 300 BleAddrType addrType; 301 } AdvOwnAddrParams; 302 303 /** 304 * @brief Defines BLE advertising parameters. 305 * 306 * @since 6 307 */ 308 typedef struct { 309 /** 310 * Minimum advertising interval. 311 * It is calculated as follows: [N * 0.625 ms], where N indicates the value of this field. 312 */ 313 int minInterval; 314 /** 315 * Maximum advertising interval. 316 * It is calculated as follows: [N * 0.625 ms], where N indicates the value of this field. 317 */ 318 int maxInterval; 319 /** Advertising type */ 320 BleAdvType advType; 321 /** Local address type */ 322 unsigned char ownAddrType; 323 /** Peer address type */ 324 unsigned char peerAddrType; 325 /** Peer address */ 326 BdAddr peerAddr; 327 /** 328 * Advertising channel to be used. For example, <b>0x01</b> indicates that channel 37 is to be used, 329 * and <b>0x07</b> indicates that channels 37, 38, and 39 are used. 330 */ 331 int channelMap; 332 /** Advertisement filtering policy based on a whitelist */ 333 BleAdvFilter advFilterPolicy; 334 /** Transmit power (dBm) */ 335 int txPower; 336 /** Advertising duration. It is calculated as follows: [N * 10 ms], where N indicates the value of this field. */ 337 int duration; 338 } BleAdvParams; 339 340 /** 341 * @brief Defines BLE scan parameters. 342 * 343 * @since 6 344 */ 345 typedef struct { 346 /** Scan interval. It is calculated as follows: [N * 0.625 ms], where N indicates the value of this field. */ 347 unsigned short scanInterval; 348 /** Scan window. It is calculated as follows: [N * 0.625 ms], where N indicates the value of this field. */ 349 unsigned short scanWindow; 350 /** Scan type, as enumerated in {@link BleScanType} */ 351 unsigned char scanType; 352 /** 353 * PHY on which the advertising packets are received. 354 * <b>bit0</b> indicates 1M PHY and <b>bit2</b> indicates LE Coded PHY. 355 * <b>bit0</b> and <b>bit2</b> can both be set to <b>1</b>. All other bits are reserved for future use. 356 */ 357 unsigned char scanPhy; 358 /** Policy for filtering the scan result, as enumerated in {@link BleScanFilterPolicy} */ 359 unsigned char scanFilterPolicy; 360 } BleScanParams; 361 362 /** 363 * @brief Defines BLE scan native filter. 364 * 365 * @since 6 366 */ 367 typedef struct { 368 /** Handling advertisments sent by advertisers with specific address */ 369 char *address; 370 /** Handling advertisments sent by advertisers with specific deviceName */ 371 char *deviceName; 372 /** The length of the service uuid */ 373 unsigned int serviceUuidLength; 374 /** Handling advertisments sent by advertisers with specific service uuid */ 375 unsigned char *serviceUuid; 376 /** Handling advertisments sent by advertisers with specific service uuid mask */ 377 unsigned char *serviceUuidMask; 378 /** The length of the service data */ 379 unsigned int serviceDataLength; 380 /** Handling advertisments sent by advertisers with specific serviceData */ 381 unsigned char *serviceData; 382 /** Handling advertisments sent by advertisers with specific serviceDataMask */ 383 unsigned char *serviceDataMask; 384 /** The length of the manufacture data */ 385 unsigned int manufactureDataLength; 386 /** Handling advertisments sent by advertisers with specific manufactureData */ 387 unsigned char *manufactureData; 388 /** Handling advertisments sent by advertisers with specific manufactureDataMask */ 389 unsigned char *manufactureDataMask; 390 /** Handling advertisments sent by advertisers with specific manufactureId */ 391 unsigned short manufactureId; 392 /** Adv_Ind Report */ 393 bool advIndReport; 394 } BleScanNativeFilter; 395 396 /** 397 * @brief Defines BLE scan configurations. 398 * 399 * @since 6 400 */ 401 typedef struct { 402 /** Repport delay time */ 403 long reportDelayMillis; 404 /** Scan mode */ 405 int scanMode; 406 /** Legacy */ 407 bool legacy; 408 /** Phy */ 409 int phy; 410 } BleScanConfigs; 411 412 /** 413 * @brief Defines raw data for the BLE advertising and scan response. 414 * 415 * This structure is available for system applications only. 416 * 417 * @since 6 418 */ 419 typedef struct { 420 /** Advertising data */ 421 unsigned char *advData; 422 /** Advertising data length */ 423 unsigned int advDataLen; 424 /** Scan response data */ 425 unsigned char *rspData; 426 /** Scan response data length */ 427 unsigned int rspDataLen; 428 } StartAdvRawData; 429 430 /** 431 * @brief Defines the BLE scan result data. 432 * 433 * @since 6 434 */ 435 typedef struct { 436 /** Advertisement type, as enumerated in {@link BleScanResultEvtType} */ 437 unsigned char eventType; 438 /** Data status, as enumerated in {@link BleScanResultDataStatus} */ 439 unsigned char dataStatus; 440 /** Address type, as enumerated in {@link BleScanResultAddrType}. Value <b>0xFE</b> is unavailable. */ 441 unsigned char addrType; 442 /** Address */ 443 BdAddr addr; 444 /** 445 * PHY type of a primary advertisement, as enumerated in {@link BleScanResultPhyType}. 446 * The value can only be <b>0x01</b> or <b>0x03</b>. 447 */ 448 unsigned char primaryPhy; 449 /** 450 * PHY type of a secondary advertisement. 451 * The value can be any of the enumerations of {@link BleScanResultPhyType}. 452 */ 453 unsigned char secondaryPhy; 454 /** 455 * Advertising SID in the ADI field of the PDU or of the original scannable advertisement (for scan responses). 456 * Value <b>0xFF</b> indicates that no ADI field is available. 457 */ 458 unsigned char advSid; 459 /** 460 * Transmit power. The value ranges from -127 to +20 dBm. 461 * Value <b>0x7F</b> indicates that this field is invalid. 462 */ 463 char txPower; 464 /** RSSI. The value ranges from -127 to +20 dBm. Value <b>0x7F</b> indicates that this field is invalid. */ 465 char rssi; 466 /** 467 * Periodic advertising interval. 468 * It is calculated as follows: [N * 1.25 ms], where N indicates the value of this field. 469 * Value <b>0x00</b> indicates that this field is invalid. 470 */ 471 unsigned short periodicAdvInterval; 472 /** 473 * Address type for directed advertising, as enumerated in {@link BleScanResultAddrType}. 474 * Value <b>0xFF</b> is unavailable. 475 */ 476 unsigned char directAddrType; 477 /** Address for directed advertising */ 478 BdAddr directAddr; 479 /** Advertising data length */ 480 unsigned char advLen; 481 /** Advertising data */ 482 unsigned char *advData; 483 } BtScanResultData; 484 485 typedef struct { 486 char deviceId[OHOS_ACTIVE_DEVICE_ID_LEN]; 487 int status; 488 int timeOut; 489 } BtActiveDeviceInfo; 490 491 typedef struct { 492 BleScanConfigs *scanConfig; 493 BleScanNativeFilter *filter; 494 unsigned int filterSize; 495 BleAdvParams advParam; 496 StartAdvRawData rawData; 497 BtUuid uuid; 498 BtActiveDeviceInfo *activeDeviceInfo; 499 unsigned int activeDeviceSize; 500 int advHandle; 501 int duration; 502 int deliveryMode; 503 } BtLpDeviceParam; 504 505 /** 506 * @brief Called when advertising is enabled. For details, see {@link BleStartAdv}. 507 * 508 * @since 6 509 */ 510 typedef void (*AdvEnableCallback)(int advId, int status); 511 512 /** 513 * @brief Called when advertising is disabled. For details, see {@link BleStopAdv}. 514 * 515 * @since 6 516 */ 517 typedef void (*AdvDisableCallback)(int advId, int status); 518 519 /** 520 * @brief Called when advertising data is set. For details, see {@link BleSetAdvData}. 521 * 522 * @since 6 523 */ 524 typedef void (*AdvDataCallback)(int advId, int status); 525 526 /** 527 * @brief Called when advertising parameters are updated. For details, see {@link BleUpdateAdv} 528 * 529 * @since 6 530 */ 531 typedef void (*AdvUpdateCallback)(int advId, int status); 532 533 /** 534 * @brief Called when a secure access request is received. 535 * 536 * {@link BleGattSecurityRsp} is used to grant the secure access permission. 537 * 538 * @since 6 539 */ 540 typedef void (*SecurityRespondCallback)(const BdAddr *bdAddr); 541 542 /** 543 * @brief Called when the scan result is received. 544 * 545 * @since 6 546 */ 547 typedef void (*ScanResultCallback)(BtScanResultData *scanResultdata); 548 549 /** 550 * @brief Called when scan parameters are set. 551 * 552 * @since 6 553 */ 554 typedef void (*ScanParameterSetCompletedCallback)(int clientId, int status); 555 556 typedef void (*LpDeviceInfoCallback)(BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize); 557 558 typedef void (*ScanStateChangeCallback)(int32_t resultCode, bool isStartScan); 559 560 /** 561 * @brief Defines GATT callbacks. 562 * 563 * @since 6 564 */ 565 typedef struct { 566 /** Called when advertising is enabled. */ 567 AdvEnableCallback advEnableCb; 568 /** Called when advertising is disabled. */ 569 AdvDisableCallback advDisableCb; 570 /** Called when advertising data is set. */ 571 AdvDataCallback advDataCb; 572 /** Called when advertising parameters are updated. */ 573 AdvUpdateCallback advUpdateCb; 574 /** Called when a secure access request is received. */ 575 SecurityRespondCallback securityRespondCb; 576 } BtGattCallbacks; 577 578 /** 579 * @brief Defines ble scan callbacks. 580 * 581 * @since 6 582 */ 583 typedef struct { 584 /** Called when the scan result is received. */ 585 ScanResultCallback scanResultCb; 586 /** Called when scan state change. */ 587 ScanStateChangeCallback scanStateChangeCb; 588 /** Called when low power device notify msg. */ 589 LpDeviceInfoCallback lpDeviceInfoCb; 590 } BleScanCallbacks; 591 592 /** 593 * @brief Initializes the Bluetooth protocol stack. 594 * 595 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the Bluetooth protocol stack is initialized; 596 * returns an error code defined in {@link BtStatus} otherwise. 597 * @since 6 598 */ 599 int InitBtStack(void); 600 601 /** 602 * @brief Enables the Bluetooth protocol stack. 603 * 604 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the Bluetooth protocol stack is enabled; 605 * returns an error code defined in {@link BtStatus} otherwise. 606 * @since 6 607 */ 608 int EnableBtStack(void); 609 610 /** 611 * @brief Disables the Bluetooth protocol stack. 612 * 613 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the Bluetooth protocol stack is disabled; 614 * returns an error code defined in {@link BtStatus} otherwise. 615 * @since 6 616 */ 617 int DisableBtStack(void); 618 619 /** 620 * @brief Sets the Bluetooth device name. 621 * 622 * @param name Indicates the pointer to the name to set. 623 * @param len Indicates the length of the name to set. 624 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the Bluetooth device name is set; 625 * returns an error code defined in {@link BtStatus} otherwise. 626 * @since 6 627 */ 628 int SetDeviceName(const char *name, unsigned int len); 629 630 /** 631 * @brief Sets advertising data. 632 * 633 * @param advId Indicates the advertisement ID, which is allocated by the upper layer of the advertiser. 634 * @param data Indicates the pointer to the advertising data. For details, see {@link StartAdvRawData}. 635 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if advertising data is set; 636 * returns an error code defined in {@link BtStatus} otherwise. 637 * @since 6 638 */ 639 int BleSetAdvData(int advId, const StartAdvRawData data); 640 641 /** 642 * @brief Starts advertising. 643 * 644 * @param advId Indicates the advertisement ID, which is allocated by the upper layer of the advertiser. 645 * @param param Indicates the pointer to the advertising parameters. For details, see {@link BleAdvParams}. 646 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if advertising is started; 647 * returns an error code defined in {@link BtStatus} otherwise. 648 * @since 6 649 */ 650 int BleStartAdv(int advId, const BleAdvParams *param); 651 652 /** 653 * @brief Stops advertising. 654 * 655 * @param advId Indicates the advertisement ID, which is allocated by the upper layer of the advertiser. 656 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if advertising is stopped; 657 * returns an error code defined in {@link BtStatus} otherwise. 658 * @since 6 659 */ 660 int BleStopAdv(int advId); 661 662 /** 663 * @brief Updates advertising parameters. 664 * 665 * @param advId Indicates the advertisement ID, which is allocated by the upper layer of the advertiser. 666 * @param param Indicates the pointer to the advertising parameters. For details, see {@link BleAdvParams}. 667 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if advertising parameters are updated; 668 * returns an error code defined in {@link BtStatus} otherwise. 669 * @since 6 670 */ 671 int BleUpdateAdv(int advId, const BleAdvParams *param); 672 673 /** 674 * @brief Sets the secure I/O capability mode. 675 * 676 * @param mode Indicates the capability mode to set. For details, see {@link BleIoCapMode}. 677 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the capability mode is set; 678 * returns an error code defined in {@link BtStatus} otherwise. 679 * @since 6 680 */ 681 int BleSetSecurityIoCap(BleIoCapMode mode); 682 683 /** 684 * @brief Sets the authentication mode for secure connection requests. 685 * 686 * @param mode Indicates the authentication mode to set. For details, see {@link BleAuthReqMode}. 687 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the authentication mode is set; 688 * returns an error code defined in {@link BtStatus} otherwise. 689 * @since 6 690 */ 691 int BleSetSecurityAuthReq(BleAuthReqMode mode); 692 693 /** 694 * @brief Responds to a secure connection request. 695 * 696 * @param bdAddr Indicates the address of the device that sends the request. 697 * @param accept Specifies whether to accept the request. The value <b>true</b> means to accept the request, 698 * and <b>false</b> means to reject the request. 699 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the request is responded to; 700 * returns an error code defined in {@link BtStatus} otherwise. 701 * @since 6 702 */ 703 int BleGattSecurityRsp(BdAddr bdAddr, bool accept); 704 705 /** 706 * @brief Obtains the device MAC address. 707 * 708 * @param mac Indicates the pointer to the device MAC address. 709 * @param len Indicates the length of the device MAC address. 710 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the device MAC address is obtained; 711 * returns an error code defined in {@link BtStatus} otherwise. 712 * @since 6 713 */ 714 int ReadBtMacAddr(unsigned char *mac, unsigned int len); 715 716 /** 717 * @brief Sets scan parameters. 718 * 719 * @param clientId Indicates the client ID, which is obtained during client registration. 720 * @param param Indicates the pointer to the scan parameters. For details, see {@link BleScanParams}. 721 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the scan parameters are set; 722 * returns an error code defined in {@link BtStatus} otherwise. 723 * @since 6 724 */ 725 int BleSetScanParameters(int clientId, BleScanParams *param); 726 727 /** 728 * @brief Starts a scan. 729 * 730 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the scan is started; 731 * returns an error code defined in {@link BtStatus} otherwise. 732 * @since 6 733 */ 734 int BleStartScan(void); 735 736 /** 737 * @brief Stops a scan. 738 * 739 * @param scannerId Indicates the scanner id. 740 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the scan is stopped; 741 * returns an error code defined in {@link BtStatus} otherwise. 742 * @since 6 743 */ 744 int BleStopScan(int32_t scannerId); 745 746 /** 747 * @brief Registers GATT callbacks. 748 * 749 * @param func Indicates the pointer to the callbacks to register. For details, see {@link BtGattCallbacks}. 750 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the GATT callbacks are registered; 751 * returns an error code defined in {@link BtStatus} otherwise. 752 * @since 6 753 */ 754 int BleGattRegisterCallbacks(BtGattCallbacks *func); 755 756 /** 757 * @brief Register ble scan callbacks. 758 * 759 * @param func Indicates the pointer to the callbacks to register. For details, see {@link BleScanCallbacks}. 760 * @param scannerId Indicates the pointer to the scannerId, identify one scan. 761 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the BLE callbacks are registered; 762 * returns an error code defined in {@link BtStatus} otherwise. 763 * @since 6 764 */ 765 int BleRegisterScanCallbacks(BleScanCallbacks *func, int32_t *scannerId); 766 767 /** 768 * @brief Deregister ble scan callbacks. 769 * 770 * @param scannerId Indicates the scanner id. 771 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the BLE callbacks are deregistered; 772 * returns an error code defined in {@link BtStatus} otherwise. 773 * @since 6 774 */ 775 int BleDeregisterScanCallbacks(int32_t scannerId); 776 777 /** 778 * @brief Sets own address, own address type, advertising data and parameters and starts advertising. 779 * 780 * This function is available for softbus only. 781 * 782 * @param advId Indicates the pointer to the advertisement ID. 783 * @param rawData Indicates the advertising data. For details, see {@link StartAdvRawData}. 784 * @param advParam Indicates the advertising parameters. For details, see {@link BleAdvParams}. 785 * @param ownAddrParams Indicates the own address(little endian) and own address type. 786 * For details, see {@link AdvOwnAddrParams}. 787 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the operation is successful; 788 * returns an error code defined in {@link BtStatus} otherwise. 789 * @since 6 790 */ 791 int BleStartAdvWithAddr(int *advId, const StartAdvRawData *rawData, const BleAdvParams *advParam, 792 const AdvOwnAddrParams *ownAddrParams); 793 794 /** 795 * @brief Sets advertising data and parameters and starts advertising. 796 * 797 * This function is available for system applications only. \n 798 * 799 * @param advId Indicates the pointer to the advertisement ID. 800 * @param rawData Indicates the advertising data. For details, see {@link StartAdvRawData}. 801 * @param advParam Indicates the advertising parameters. For details, see {@link BleAdvParams}. 802 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the operation is successful; 803 * returns an error code defined in {@link BtStatus} otherwise. 804 * @since 6 805 */ 806 int BleStartAdvEx(int *advId, const StartAdvRawData rawData, BleAdvParams advParam); 807 808 /** 809 * @brief Enable advertising. 810 * 811 * This function is available for system applications only. \n 812 * 813 * @param advId Indicates the pointer to the advertisement ID. 814 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the operation is successful; 815 * returns an error code defined in {@link BtStatus} otherwise. 816 * @since 11 817 */ 818 int BleEnableAdvEx(int advId); 819 820 /** 821 * @brief Disable advertising. 822 * 823 * This function is available for system applications only. \n 824 * 825 * @param advId Indicates the pointer to the advertisement ID. 826 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the operation is successful; 827 * returns an error code defined in {@link BtStatus} otherwise. 828 * @since 11 829 */ 830 int BleDisableAdvEx(int advId); 831 832 /** 833 * @brief Starts a scan with BleScanConfigs. 834 * If don't need ble scan filter, set BleScanNativeFilter to NULL or filterSize to zero. 835 * If one of the ble scan filtering rules is not required, set it to NULL. 836 * For example, set the address to NULL when you don't need it. 837 * Don't support only using manufactureId as filter conditions, need to use it with manufactureData. 838 * The manufactureId need to be set a related number when you need a filtering condition of manufactureData. 839 * 840 * @param scannerId Indicates the scanner id. 841 * @param configs Indicates the pointer to the scan filter. For details, see {@link BleScanConfigs}. 842 * @param filter Indicates the pointer to the scan filter. For details, see {@link BleScanNativeFilter}. 843 * @param filterSize Indicates the number of the scan filter. 844 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if the scan is started; 845 * returns an error code defined in {@link BtStatus} otherwise. 846 * @since 6 847 */ 848 int BleStartScanEx(int32_t scannerId, const BleScanConfigs *configs, const BleScanNativeFilter *filter, 849 uint32_t filterSize); 850 /** 851 * @brief set low power device adv param. 852 * 853 * @param duration advertise duration. 854 * @param maxExtAdvEvents maximum number of extended advertising events. 855 * @param window work window. 856 * @param interval work interval. 857 * @param advHandle Indicates the advertise handle. 858 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if set success; 859 * returns an error code defined in {@link BtStatus} otherwise. 860 * @since 6 861 */ 862 int SetLpDeviceAdvParam(int duration, int maxExtAdvEvents, int window, int interval, int advHandle); 863 864 /** 865 * @brief Set scan report channel. 866 * 867 * @param scannerId Indicates the scanner id. 868 * @param enable true:report to low power device; false:not report to low power device. 869 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if set report channel success; 870 * returns an error code defined in {@link BtStatus} otherwise. 871 * @since 6 872 */ 873 int SetScanReportChannelToLpDevice(int32_t scannerId, bool enable); 874 875 /** 876 * @brief Enable synchronizing data to low power device. 877 * 878 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if enable sync success; 879 * returns an error code defined in {@link BtStatus} otherwise. 880 * @since 6 881 */ 882 int EnableSyncDataToLpDevice(void); 883 884 /** 885 * @brief Disable synchronizing data to the low power device. 886 * 887 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if disable sync success; 888 * returns an error code defined in {@link BtStatus} otherwise. 889 * @since 6 890 */ 891 int DisableSyncDataToLpDevice(void); 892 893 /** 894 * @brief Get advertiser handle. 895 * 896 * @param advId Indicates the advertisement ID. 897 * @param advHandle Indicates the pointer to the advertiser handle. 898 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if get success; 899 * returns an error code defined in {@link BtStatus} otherwise. 900 * @since 6 901 */ 902 int GetAdvHandle(int advId, int *advHandle); 903 904 /** 905 * @brief Translate ParamData to low power device. 906 * 907 * @param data Indicates the pointer to the data. 908 * @param dataSize Indicates the data size. 909 * @param type Indicates the data type. 910 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if set param to low power device success; 911 * returns an error code defined in {@link BtStatus} otherwise. 912 * @since 6 913 */ 914 int SendParamsToLpDevice(const uint8_t *data, uint32_t dataSize, int32_t type); 915 916 /** 917 * @brief Get whether low power device available. 918 * 919 * @return true: available; false: not available. 920 * @since 6 921 */ 922 bool IsLpDeviceAvailable(void); 923 924 /** 925 * @brief Set low power device Param. 926 * 927 * @param lpDeviceParam the param set to low power device. 928 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if set lpDeviceParam success; 929 * returns an error code defined in {@link BtStatus} otherwise. 930 * @since 6 931 */ 932 int SetLpDeviceParam(const BtLpDeviceParam *lpDeviceParam); 933 934 /** 935 * @brief Remove low power device Param. 936 * 937 * @param uuid Uuid. 938 * @return Returns {@link OHOS_BT_STATUS_SUCCESS} if remove success; 939 * returns an error code defined in {@link BtStatus} otherwise. 940 * @since 6 941 */ 942 int RemoveLpDeviceParam(BtUuid uuid); 943 944 /** 945 * @brief Clear global resource when ble turn on or bluetooth_serivce unload. 946 * @since 11 947 */ 948 void ClearGlobalResource(void); 949 950 /** 951 * @brief start RPA adv addr timer 952 * @param advHandle Indicates the advertise handle. 953 * @param ownAddrParams Indicates the own address(little endian) and own address type. 954 * @return true: start timer; false: start timer fail. 955 * @since 12 956 */ 957 bool StartAdvAddrTimer(int advHandle, const AdvOwnAddrParams *ownAddrParams); 958 959 /** 960 * @brief Allocate adv handle 961 * @return advertiser handle. 962 * @since 12 963 */ 964 int AllocateAdvHandle(void); 965 #ifdef __cplusplus 966 } 967 #endif 968 #endif 969 /** @} */