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