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