1 /* 2 * Copyright (C) 2021 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 Generic Access Profile 21 * 22 */ 23 24 /** 25 * @file gap.h 26 * 27 * @brief bluetooth gap interface 28 * 29 */ 30 31 #ifndef GAP_LE_IF_H 32 #define GAP_LE_IF_H 33 34 #include "gap_comm.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /// BLE Roles 41 #define GAP_LE_ROLE_BROADCASTER (1 << 0) 42 #define GAP_LE_ROLE_OBSERVER (1 << 1) 43 #define GAP_LE_ROLE_PREIPHERAL (1 << 2) 44 #define GAP_LE_ROLE_CENTRAL (1 << 3) 45 46 #define GAP_LTK_SIZE 0x10 47 #define GAP_IRK_SIZE 0x10 48 #define GAP_CSRK_SIZE 0x10 49 #define GAP_SIGNATURE_SIZE 12 50 51 typedef void (*GenResPriAddrResult)(uint8_t result, const uint8_t addr[BT_ADDRESS_SIZE], void *context); 52 53 #define GAP_ADVERTISING_DATA_LENGTH_MAX 31 54 55 /// Advertising channel 56 #define GAP_ADVERTISING_CHANNEL_37 (1 << 0) 57 #define GAP_ADVERTISING_CHANNEL_38 (1 << 1) 58 #define GAP_ADVERTISING_CHANNEL_39 (1 << 2) 59 60 /// Advertising filter policy 61 #define GAP_ADVERTISING_NOT_USE_WL (0x00) 62 #define GAP_ADVERTISING_USE_WL_FOR_SCAN (0x01) 63 #define GAP_ADVERTISING_USE_WL_FOR_CONNECTION (0x02) 64 #define GAP_ADVERTISING_USE_WL_FOR_BOTH (0x03) 65 66 /// Intended Advertising property 67 #define GAP_ADVERTISING_PROPERTY_CONNECTABLE (1 << 0) 68 #define GAP_ADVERTISING_PROPERTY_SCANABLE (1 << 1) 69 #define GAP_ADVERTISING_PROPERTY_DIRECTED (1 << 2) 70 #define GAP_ADVERTISING_PROPERTY_HIGH_DUTY_CYCLE_DIRECTED (1 << 3) 71 #define GAP_ADVERTISING_PROPERTY_USE_LEGACY_PDUS (1 << 4) 72 #define GAP_ADVERTISING_PROPERTY_ANONYMOUS (1 << 5) 73 #define GAP_ADVERTISING_PROPERTY_INCLUDE_TXPOWER (1 << 6) 74 75 /// Intended Advertising data operation 76 #define GAP_ADVERTISING_DATA_OPERATION_INTERMEDIATE (0x00) 77 #define GAP_ADVERTISING_DATA_OPERATION_FIRST (0x01) 78 #define GAP_ADVERTISING_DATA_OPERATION_LAST (0x02) 79 #define GAP_ADVERTISING_DATA_OPERATION_COMPLETE (0x03) 80 #define GAP_ADVERTISING_DATA_OPERATION_UNCHANGED (0x04) 81 82 /// Intended Advertising PHY 83 #define GAP_ADVERTISEMENT_PHY_NONE (0x00) 84 #define GAP_ADVERTISEMENT_PHY_1M (0x01) 85 #define GAP_ADVERTISEMENT_PHY_2M (0x02) 86 #define GAP_ADVERTISEMENT_PHY_CODED (0x03) 87 88 /// fragment preference 89 #define GAP_CONTROLLER_MAY_FRAGMENT (0x00) 90 #define GAP_CONTROLLER_SHOULD_NOT_FRAGMENT (0x01) 91 92 /** 93 * @brief Extended Advertising enable parameter structure 94 */ 95 typedef struct { 96 uint8_t advHandle; /// Extended Advertising handle 97 uint16_t duration; /// Advertising duration (n * 10ms, 0 is no limit) 98 uint8_t maxExAdvEvt; /// maximum number of advertising events (0 is no limit) 99 } GapExAdvSet; 100 101 /** 102 * @brief Extended Advertising callback function structure 103 */ 104 typedef struct { 105 void (*exAdvSetRandAddrResult)(uint8_t status, void *context); 106 void (*exAdvSetParamResult)(uint8_t status, uint8_t selectTxPower, void *context); 107 void (*exAdvSetDataResult)(uint8_t status, void *context); 108 void (*exAdvSetScanRspDataResult)(uint8_t status, void *context); 109 void (*exAdvSetEnableResult)(uint8_t status, void *context); 110 void (*exAdvRemoveHandleResult)(uint8_t status, void *context); 111 void (*exAdvClearHandleResult)(uint8_t status, void *context); 112 void (*exAdvScanRequestReceived)(uint8_t advHandle, const BtAddr *scannerAddr, void *context); 113 void (*exAdvTerminatedAdvSet)( 114 uint8_t status, uint8_t advHandle, uint16_t connectionHandle, uint8_t completedNumber, void *context); 115 } GapExAdvCallback; 116 117 /** 118 * @brief Advertising parameter structure 119 */ 120 typedef struct { 121 uint16_t advIntervalMin; /// Minimum advertising interval (0x0020-0x4000) 122 uint16_t advIntervalMax; /// Maximum advertising interval (0x0020-0x4000) 123 uint8_t advChannelMap; /// Used channel of Advertising 124 const BtAddr *peerAddr; /// Target bluetooth address of directed advertising 125 uint8_t advFilterPolicy; /// Advertising filter policy 126 } GapLeAdvParam; 127 128 /** 129 * @brief Extended advertising parameter structure 130 */ 131 typedef struct { 132 uint32_t advIntervalMin; /// Minimum advertising interval (0x000020-0xFFFFFF) 133 uint32_t advIntervalMax; /// Maximum advertising interval (0x000020-0xFFFFFF) 134 uint8_t advChannelMap; /// Used channel of Advertising 135 const BtAddr *peerAddr; /// Target bluetooth address of directed advertising 136 uint8_t advFilterPolicy; /// Advertising filter policy 137 uint8_t primaryAdvPhy; /// Primary Advertising PHY 138 uint8_t secondaryAdvMaxSkip; /// Maximum number that can be skipped before the AUX_ADV_IND. 139 uint8_t secondaryAdvPhy; /// Secondary Advertising PHY 140 uint8_t advSid; /// Value of the Advertising SID subfield in the ADI field of the PDU 141 uint8_t scanRequestNotifyEnable; /// Scan request notifications enabled (0x01 is enabled) 142 } GapLeExAdvParam; 143 144 /// BLE legacy advertising type 145 #define GAP_ADV_TYPE_CONN_UNDIR 0x00 146 #define GAP_ADV_TYPE_CONN_DIR_HIGH_DUTY 0x01 147 #define GAP_ADV_TYPE_SCAN_UNDIR 0x02 148 #define GAP_ADV_TYPE_NON_CONN_UNDIR 0x03 149 #define GAP_ADV_TYPE_CONN_DIR_LOW_DUTY 0x04 150 151 /** 152 * @brief Legacy advertising callback structure 153 */ 154 typedef struct { 155 void (*advSetParamResult)(uint8_t status, void *context); 156 void (*advReadTxPower)(uint8_t status, int8_t txPower, void *context); 157 void (*advSetDataResult)(uint8_t status, void *context); 158 void (*advSetScanRspDataResult)(uint8_t status, void *context); 159 void (*advSetEnableResult)(uint8_t status, void *context); 160 } GapAdvCallback; 161 162 /// Scan filter policy 163 #define GAP_SCAN_NOT_USE_WL (0x00) 164 #define GAP_SCAN_USE_WL (0x01) 165 #define GAP_SCAN_NOT_USE_WL_AND_IDENTITY (0x02) 166 #define GAP_SCAN_USE_WL_AND_IDENTITY (0x03) 167 168 /// Scan PHYs 169 #define GAP_EX_SCAN_PHY_1M (1 << 0) 170 #define GAP_EX_SCAN_PHY_CODED (1 << 2) 171 172 /** 173 * @brief BLE scan internal and window parameter structure 174 */ 175 typedef struct { 176 uint16_t scanInterval; /// scan internal 177 uint16_t scanWindow; /// scan window 178 } GapLeScanParameter; 179 180 /** 181 * @brief BLE scan parameter structure 182 */ 183 typedef struct { 184 uint8_t scanType; /// scan type 185 GapLeScanParameter param; /// scan internal and window parameter 186 } GapLeScanParam; 187 188 /** 189 * @brief Advertising report structure 190 */ 191 typedef struct { 192 uint8_t dataLen; /// Advertising data len 193 uint8_t *data; /// Advertising data 194 int8_t rssi; /// RSSI (127 is information not available) 195 } GapAdvReportParam; 196 197 /** 198 * @brief BLE scan result callback 199 */ 200 typedef struct { 201 void (*advertisingReport)( 202 uint8_t advType, const BtAddr *addr, GapAdvReportParam reportParam, const BtAddr *currentAddr, void *context); 203 void (*scanSetParamResult)(uint8_t status, void *context); 204 void (*scanSetEnableResult)(uint8_t status, void *context); 205 } GapScanCallback; 206 207 /** 208 * @brief Extended advertising report structure 209 */ 210 typedef struct { 211 uint8_t primaryPhy; /// Advertiser PHY 212 uint8_t secondaryPhy; /// Secondary advertiser PHY: 213 uint8_t advertisingSid; /// Value of the Advertising SID subfield in the ADI field of the PDU 214 int8_t txPower; /// TX power (127 is information not available) 215 int8_t rssi; /// RSSI (127 is information not available) 216 uint16_t periodicAdvInterval; /// Periodic advertising interval 217 const BtAddr *directAddr; /// Directed advertising event address 218 uint8_t dataLen; /// Advertising data len 219 uint8_t *data; /// Advertising data 220 } GapExAdvReportParam; 221 222 /** 223 * @brief Directed advertising report structure 224 */ 225 typedef struct { 226 const BtAddr *directAddr; /// Directed advertising event address 227 int8_t rssi; /// RSSI (127 is information not available) 228 } GapDirectedAdvReportParam; 229 230 /** 231 * @brief Extended scan result structure 232 */ 233 typedef struct { 234 void (*exAdvertisingReport)( 235 uint8_t advType, const BtAddr *addr, GapExAdvReportParam reportParam, const BtAddr *currentAddr, void *context); 236 void (*directedAdvertisingReport)(uint8_t advType, const BtAddr *addr, GapDirectedAdvReportParam reportParam, 237 const BtAddr *currentAddr, void *context); 238 void (*scanExSetParamResult)(uint8_t status, void *context); 239 void (*scanExSetEnableResult)(uint8_t status, void *context); 240 void (*scanTimeoutEvent)(void *context); 241 } GapExScanCallback; 242 243 /** 244 * @brief BLE link layer control callback structure 245 */ 246 typedef struct { 247 void (*leConnectionParameterReq)(const BtAddr *addr, uint16_t connIntervalMin, uint16_t connIntervalMax, 248 uint16_t connLatency, uint16_t timeout, void *context); 249 void (*leConnectionUpdateComplete)(uint8_t status, const BtAddr *addr, uint16_t connInterval, uint16_t connLatency, 250 uint16_t timeout, void *context); 251 void (*GapleSetHostChannelClassificationResult)(uint8_t result, void *context); 252 void (*GapleReadChannelMapResult)(uint8_t result, const BtAddr *addr, uint64_t channelMap, void *context); 253 } GapLeConnCallback; 254 255 /** 256 * @brief BLE connection parameter structure 257 */ 258 typedef struct { 259 uint16_t connIntervalMin; /// Minimum value for the connection interval(n * 1.25ms 0x0006-0x0c80) 260 uint16_t connIntervalMax; /// Maximum value for the connection interval(n * 1.25ms 0x0006-0x0c80) 261 uint16_t connLatency; /// Slave latency for the connection (0x0000-0x01F3) 262 uint16_t timeout; /// Supervision timeout for the LE Link (n * 10ms 0x000A-0x0C80) 263 uint16_t minCeLen; /// Minimum length of connection event (n * 0.625ms 0x0000-0xFFFF) 264 uint16_t maxCeLen; /// Maximum length of connection event (n * 0.625ms 0x0000-0xFFFF) 265 } GapLeConnectionParameter; 266 267 /// BLE OOB Authentication data present 268 #define GAP_LE_OOB_DATA_NOT_PRESENT 0x00 269 #define GAP_LE_OOB_DATA_PRESENT 0x01 270 271 /// BLE authentication requirements 272 #define GAP_LE_AUTH_REQ_BONDING (1 << 0) 273 #define GAP_LE_AUTH_REQ_BIT_MITM (1 << 2) 274 #define GAP_LE_AUTH_REQ_BIT_SC (1 << 3) 275 #define GAP_LE_AUTH_REQ_BIT_KEYPRESS (1 << 4) 276 #define GAP_LE_AUTH_REQ_BIT_CT2 (1 << 5) 277 278 /// BLE key distribution 279 #define GAP_LE_KEY_DIST_ENC_KEY (1 << 0) 280 #define GAP_LE_KEY_DIST_ID_KEY (1 << 1) 281 #define GAP_LE_KEY_DIST_SIGN_KEY (1 << 2) 282 283 /** 284 * @brief BLE pair feature structure 285 */ 286 typedef struct { 287 uint8_t ioCapability; /// IO Capability 288 uint8_t oobDataFlag; /// OOB Authentication data present 289 uint8_t authReq; /// Authentication requirements 290 uint8_t maxEncKeySize; /// Maximum of Long Term Key size 291 uint8_t initKeyDis; /// Initiator Key Distribution / Generation 292 uint8_t respKeyDis; /// Responder Key Distribution / Generation 293 } GapLePairFeature; 294 295 /** 296 * @brief BLE encryption key structure 297 */ 298 typedef struct { 299 uint8_t ltk[GAP_LTK_SIZE]; /// Long Term Key 300 uint64_t rand; /// Random Number 301 uint16_t ediv; /// Encrypted Diversifier 302 uint8_t keySize; /// Encryption Key Size 303 } LeEncKey; 304 305 /** 306 * @brief BLE identity key structure 307 */ 308 typedef struct { 309 BtAddr identityAddr; /// Identity Address 310 uint8_t irk[GAP_IRK_SIZE]; /// Identity Resolving Key 311 } LeIdKey; 312 313 /** 314 * @brief BLE signature key structure 315 */ 316 typedef struct { 317 uint8_t csrk[GAP_CSRK_SIZE]; /// Connection Signature Resolving Key 318 uint32_t counter; /// SignCounter 319 } LeSignKey; 320 321 /** 322 * @brief BLE SignCounter type 323 */ 324 typedef enum { 325 LOCAL_SIGN_COUNTER, 326 REMOTE_SIGN_COUNTER, 327 } GAP_SignCounterType; 328 329 /** 330 * @brief Signing Algorithm Info structure 331 */ 332 typedef struct { 333 LeSignKey *localKey; 334 LeSignKey *remoteKey; 335 } GapSigningAlgorithmInfo; 336 337 /** 338 * @brief BLE security callback structure 339 */ 340 typedef struct { 341 void (*encryptionComplete)(uint8_t status, const BtAddr *addr, void *context); 342 void (*leLocalEncryptionKeyReqEvent)(const BtAddr *addr, uint64_t rand, uint16_t ediv, void *context); 343 void (*leRemoteEncryptionKeyReqEvent)(const BtAddr *addr, void *context); 344 void (*GapRequestSigningAlgorithmInfo)(const BtAddr *addr, void *context); 345 void (*leSignCounterChangeNotification)( 346 const BtAddr *addr, GAP_SignCounterType type, uint32_t counter, void *context); 347 } GapLeSecurityCallback; 348 349 /** 350 * @brief level of LE security mode 1 351 */ 352 typedef enum { 353 LE_MODE_1_LEVEL_1, 354 LE_MODE_1_LEVEL_2, 355 LE_MODE_1_LEVEL_3, 356 LE_MODE_1_LEVEL_4, 357 } GAP_LeSecMode1Level; 358 359 /** 360 * @brief level of LE security mode 2 361 */ 362 typedef enum { 363 LE_MODE_2_LEVEL_1, 364 LE_MODE_2_LEVEL_2, 365 } GAP_LeSecMode2Level; 366 367 /** 368 * @brief BLE security status of le connection 369 */ 370 typedef enum { 371 GAP_LE_NO_ENCRYPTION, 372 GAP_LE_UNAUTHENTICATED_ENCRYPTION, 373 GAP_LE_AUTHENTICATED_ENCRYPTION, 374 } GAP_LeSecurityStatus; 375 376 /** 377 * @brief BLE security result callback 378 * @param[in] addr target device address 379 * @param[in] result request result 380 * @param[in] status security status of le connection 381 * @param[in] context callback context 382 * @return @c BT_SUCCESS : The function is executed successfully. 383 * @c otherwise : The function is not executed successfully. 384 */ 385 typedef void (*GapLeRequestSecurityResult)( 386 const BtAddr *addr, uint8_t result, GAP_LeSecurityStatus status, void *context); 387 388 typedef struct { 389 LeEncKey *remoteEncKey; 390 LeIdKey *remoteIdKey; 391 LeSignKey *remoteSignKey; 392 LeEncKey *localEncKey; 393 LeSignKey *localSignKey; 394 } LePairedKeys; 395 396 /** 397 * @brief BLE pair callback structure 398 */ 399 typedef struct { 400 void (*lePairFeatureReq)(const BtAddr *addr, bool localPair, void *context); 401 void (*lePairFeatureInd)(const BtAddr *addr, GapLePairFeature remoteFrature, void *context); 402 void (*lePairMethodNotify)(const BtAddr *addr, uint8_t pairMethod, void *context); 403 void (*lePairKeyPressNotification)(const BtAddr *addr, uint8_t pressType, void *context); 404 void (*lePairPassKeyReq)(const BtAddr *addr, void *context); 405 void (*lePairPassKeyNotification)(const BtAddr *addr, uint32_t number, void *context); 406 void (*lePairOobReq)(const BtAddr *addr, void *context); 407 void (*lePairScOobReq)(const BtAddr *addr, void *context); 408 void (*lePairScOobNotification)(const BtAddr *addr, GapOOBData *oobData, void *context); 409 void (*lePairScUserConfirmReq)(const BtAddr *addr, uint32_t number, void *context); 410 void (*lePairComplete)(const BtAddr *addr, uint8_t result, uint8_t keyType, void *context); 411 void (*lePairKeyNotify)(const BtAddr *addr, LePairedKeys LeKeys, void *context); 412 } GapLePairCallback; 413 414 #define GAP_ENC_KEY_MIN_SIZE 0x07 415 #define GAP_ENC_KEY_MAX_SIZE 0x10 416 417 /** 418 * @brief BLE signature algorithm result 419 */ 420 typedef enum { 421 GAP_SIGNATURE_OK, 422 GAP_SIGNATURE_ERR_EXECUTION, 423 GAP_SIGNATURE_ERR_COUNTER, 424 GAP_SIGNATURE_ERR_ALGORITHM, 425 } GAP_SignatureResult; 426 427 /** 428 * @brief BLE signature algorithm data PDU 429 */ 430 typedef struct { 431 const uint8_t *data; 432 uint16_t dataLen; 433 } GapSignatureData; 434 435 typedef void (*GAPSignatureGenerationResult)( 436 GAP_SignatureResult result, uint8_t signature[GAP_SIGNATURE_SIZE], void *context); 437 438 typedef void (*GAPSignatureConfirmationResult)(GAP_SignatureResult result, void *context); 439 440 /** 441 * @brief Set BLE Roles 442 * @param[in] role BLE Roles 443 * @return @c BT_SUCCESS : The function is executed successfully. 444 * @c otherwise : The function is not executed successfully. 445 */ 446 BTSTACK_API int GAPIF_LeSetRole(uint8_t role); 447 448 /** 449 * @brief Set Static Identity Address if controller does not have a Public Device Address 450 * @param[in/out] addr Static Identity Address 451 * @return @c BT_SUCCESS : The function is executed successfully. 452 * @c otherwise : The function is not executed successfully. 453 */ 454 BTSTACK_API int GAPIF_LeSetStaticIdentityAddr(uint8_t addr[BT_ADDRESS_SIZE]); 455 456 /** 457 * @brief Generate a local resolvable private address 458 * @param[in] callback Generate RPA result function 459 * @param[in] context Generate RPA result function context 460 * @return @c BT_SUCCESS : The function is executed successfully. 461 * @c otherwise : The function is not executed successfully. 462 */ 463 BTSTACK_API int GAPIF_LeGenResPriAddr(GenResPriAddrResult callback, void *context); 464 465 /** 466 * @brief Read the maximum length of intended advertising data supported by the Controller 467 * @param[out] len length of intended advertising data or scan response data 468 * @return @c BT_SUCCESS : The function is executed successfully. 469 * @c otherwise : The function is not executed successfully. 470 */ 471 BTSTACK_API int GAPIF_LeExAdvGetMaxDataLen(uint16_t *len); 472 473 /** 474 * @brief Read the maximum number of advertising sets supported by the advertising Controller at the same time. 475 * @param[out] num maximum number of advertising sets 476 * @return @c BT_SUCCESS : The function is executed successfully. 477 * @c otherwise : The function is not executed successfully. 478 */ 479 BTSTACK_API int GAPIF_LeExAdvGetMaxHandleNum(uint8_t *num); 480 481 /** 482 * @brief Register Extended advertising callback function 483 * @param[in] callback Extended advertising callback structure 484 * @param[in] context Extended advertising result callback context parameter 485 * @return @c BT_SUCCESS : The function is executed successfully. 486 * @c otherwise : The function is not executed successfully. 487 */ 488 BTSTACK_API int GAPIF_RegisterExAdvCallback(const GapExAdvCallback *callback, void *context); 489 490 /** 491 * @brief Degegister Extended advertising callback function 492 * @return @c BT_SUCCESS : The function is executed successfully. 493 * @c otherwise : The function is not executed successfully. 494 */ 495 BTSTACK_API int GAPIF_DeregisterExAdvCallback(void); 496 497 /** 498 * @brief Set the random device address used by advertising. 499 * @param[in] advHandle used to identify an advertising set (0x00-0xEF) 500 * @param[in] addr random device address 501 * @return @c BT_SUCCESS : The function is executed successfully. 502 * @c otherwise : The function is not executed successfully. 503 */ 504 BTSTACK_API int GAPIF_LeExAdvSetRandAddr(uint8_t advHandle, const uint8_t addr[BT_ADDRESS_SIZE]); 505 506 /** 507 * @brief Set the advertising parameter used by advertising. 508 * @param[in] advHandle used to identify an advertising set (0x00-0xEF) 509 * @param[in] properties intended Advertising property 510 * @param[in] txPower advertising TX power 511 * @param[in] advExParam advertising parameter 512 * @return @c BT_SUCCESS : The function is executed successfully. 513 * @c otherwise : The function is not executed successfully. 514 */ 515 BTSTACK_API int GAPIF_LeExAdvSetParam( 516 uint8_t advHandle, uint8_t properties, int8_t txPower, GapLeExAdvParam advExParam); 517 518 /** 519 * @brief Set the advertising data used by advertising. 520 * @param[in] advHandle used to identify an advertising set (0x00-0xEF) 521 * @param[in] operation intended Advertising operation 522 * @param[in] fragmentPreference fragment preference 523 * @param[in] advDataLength advertising data length 524 * @param[in] advData advertising data 525 * @return @c BT_SUCCESS : The function is executed successfully. 526 * @c otherwise : The function is not executed successfully. 527 */ 528 BTSTACK_API int GAPIF_LeExAdvSetData( 529 uint8_t advHandle, uint8_t operation, uint8_t fragmentPreference, uint8_t advDataLength, const uint8_t *advData); 530 531 /** 532 * @brief Set the scan response data used by advertising. 533 * @param[in] advHandle used to identify an advertising set (0x00-0xEF) 534 * @param[in] operation intended Advertising operation 535 * @param[in] fragmentPreference fragment preference 536 * @param[in] scanResponseDataLen scan response data length 537 * @param[in] scanResponseData scan response data 538 * @return @c BT_SUCCESS : The function is executed successfully. 539 * @c otherwise : The function is not executed successfully. 540 */ 541 BTSTACK_API int GAPIF_LeExAdvSetScanRspData(uint8_t advHandle, uint8_t operation, uint8_t fragmentPreference, 542 uint8_t scanResponseDataLen, const uint8_t *scanResponseData); 543 544 /** 545 * @brief Set the advertising enable used by advertising. 546 * @param[in] enable advertising enable (0x00 is disable, 0x01 is enable) 547 * @param[in] numberOfSet number of parameter (When disabled, 0 is to disable all) 548 * @param[in] advSet advertising enable parameter 549 * @return @c BT_SUCCESS : The function is executed successfully. 550 * @c otherwise : The function is not executed successfully. 551 */ 552 BTSTACK_API int GAPIF_LeExAdvSetEnable(uint8_t enable, uint8_t numberOfSet, const GapExAdvSet *advSet); 553 554 /** 555 * @brief Remove all advertising set of advertising. 556 * @return @c BT_SUCCESS : The function is executed successfully. 557 * @c otherwise : The function is not executed successfully. 558 */ 559 BTSTACK_API int GAPIF_LeExAdvClearHandle(void); 560 561 /** 562 * @brief Register legacy advertising result callback 563 * @param[in] callback legacy advertising callback 564 * @param[in] context legacy advertising callback context parameter 565 * @return @c BT_SUCCESS : The function is executed successfully. 566 * @c otherwise : The function is not executed successfully. 567 */ 568 BTSTACK_API int GAPIF_RegisterAdvCallback(const GapAdvCallback *callback, void *context); 569 570 /** 571 * @brief Deregister legacy advertising result callback 572 * @return @c BT_SUCCESS : The function is executed successfully. 573 * @c otherwise : The function is not executed successfully. 574 */ 575 BTSTACK_API int GAPIF_DeregisterAdvCallback(void); 576 577 /** 578 * @brief Set legacy advertising parameter 579 * @param[in] advType legacy advertising type 580 * @param[in] advParam legacy advertising parameter 581 * @return @c BT_SUCCESS : The function is executed successfully. 582 * @c otherwise : The function is not executed successfully. 583 */ 584 BTSTACK_API int GAPIF_LeAdvSetParam(uint8_t advType, GapLeAdvParam advParam); 585 586 /** 587 * @brief Read legacy advertising TX power 588 * @return @c BT_SUCCESS : The function is executed successfully. 589 * @c otherwise : The function is not executed successfully. 590 */ 591 BTSTACK_API int GAPIF_LeAdvReadTxPower(void); 592 593 /** 594 * @brief Set legacy advertising data 595 * @param[in] advDataLength legacy advertising data length 596 * @param[in] advData legacy advertising data 597 * @return @c BT_SUCCESS : The function is executed successfully. 598 * @c otherwise : The function is not executed successfully. 599 */ 600 BTSTACK_API int GAPIF_LeAdvSetData(uint8_t advDataLength, const uint8_t *advData); 601 602 /** 603 * @brief Set legacy advertising scan response data 604 * @param[in] advDataLength legacy advertising scan response data length 605 * @param[in] advData legacy advertising scan response data 606 * @return @c BT_SUCCESS : The function is executed successfully. 607 * @c otherwise : The function is not executed successfully. 608 */ 609 BTSTACK_API int GAPIF_LeAdvSetScanRspData(uint8_t advDataLength, const uint8_t *advData); 610 611 /** 612 * @brief Set legacy advertising enable 613 * @param[in] enable advertising enable (0x00 is disable, 0x01 is enable) 614 * @return @c BT_SUCCESS : The function is executed successfully. 615 * @c otherwise : The function is not executed successfully. 616 */ 617 BTSTACK_API int GAPIF_LeAdvSetEnable(uint8_t enable); 618 619 /** 620 * @brief Register scan result callback 621 * @param[in] callback scan result callback 622 * @param[in] context scan result callback context parameter 623 * @return @c BT_SUCCESS : The function is executed successfully. 624 * @c otherwise : The function is not executed successfully. 625 */ 626 BTSTACK_API int GAPIF_RegisterScanCallback(const GapScanCallback *callback, void *context); 627 628 /** 629 * @brief Deregister scan result callback 630 * @return @c BT_SUCCESS : The function is executed successfully. 631 * @c otherwise : The function is not executed successfully. 632 */ 633 BTSTACK_API int GAPIF_DeregisterScanCallback(void); 634 635 /** 636 * @brief Set scan parameter 637 * @param[in] param scan parameter 638 * @param[in] scanFilterPolity scan filter policy 639 * @return @c BT_SUCCESS : The function is executed successfully. 640 * @c otherwise : The function is not executed successfully. 641 */ 642 BTSTACK_API int GAPIF_LeScanSetParam(GapLeScanParam param, uint8_t scanFilterPolity); 643 644 /** 645 * @brief Set scan enable 646 * @param[in] scanEnable scan enable (0x00 is disable, 0x01 is enable) 647 * @param[in] filterDuplicates filter duplicates (0x00 is disable, 0x01 is enable) 648 * @return @c BT_SUCCESS : The function is executed successfully. 649 * @c otherwise : The function is not executed successfully. 650 */ 651 BTSTACK_API int GAPIF_LeScanSetEnable(uint8_t scanEnable, uint8_t filterDuplicates); 652 653 /** 654 * @brief Register extended scan result callback 655 * @param[in] callback extended scan result callback 656 * @param[in] context extended scan result callback context parameter 657 * @return @c BT_SUCCESS : The function is executed successfully. 658 * @c otherwise : The function is not executed successfully. 659 */ 660 BTSTACK_API int GAPIF_RegisterExScanCallback(const GapExScanCallback *callback, void *context); 661 662 /** 663 * @brief Deregister extended scan result callback 664 * @return @c BT_SUCCESS : The function is executed successfully. 665 * @c otherwise : The function is not executed successfully. 666 */ 667 BTSTACK_API int GAPIF_DeregisterExScanCallback(void); 668 669 /** 670 * @brief Set extended scan parameter 671 * @param[in] scanFilterPolity scan filter policy 672 * @param[in] scanPhys scan PHYs 673 * @param[in] param scan parameter 674 * @return @c BT_SUCCESS : The function is executed successfully. 675 * @c otherwise : The function is not executed successfully. 676 */ 677 BTSTACK_API int GAPIF_LeExScanSetParam(uint8_t scanFilterPolity, uint8_t scanPhys, const GapLeScanParam param[]); 678 679 /** 680 * @brief Set extended scan parameter 681 * @param[in] scanEnable scan enable (0x00 is disable, 0x01 is enable) 682 * @param[in] filterDuplicates filter duplicates (0x00 is disable, 0x01 is enable) 683 * @param[in] duration (n * 10ms, 0 is scan continuously) 684 * @param[in] period (n * 1.28s, 0 is periodic scanning disabled) 685 * @return @c BT_SUCCESS : The function is executed successfully. 686 * @c otherwise : The function is not executed successfully. 687 */ 688 BTSTACK_API int GAPIF_LeExScanSetEnable( 689 uint8_t scanEnable, uint8_t filterDuplicates, uint16_t duration, uint16_t period); 690 691 /** 692 * @brief Register link layer control callback 693 * @param[in] callback link layer control callback 694 * @param[in] context link layer control callback context parameter 695 * @return @c BT_SUCCESS : The function is executed successfully. 696 * @c otherwise : The function is not executed successfully. 697 */ 698 BTSTACK_API int GAPIF_RegisterLeConnCallback(const GapLeConnCallback *callback, void *context); 699 700 /** 701 * @brief Deregister link layer control callback 702 * @return @c BT_SUCCESS : The function is executed successfully. 703 * @c otherwise : The function is not executed successfully. 704 */ 705 BTSTACK_API int GAPIF_DeregisterLeConnCallback(void); 706 707 /** 708 * @brief Send Connection parameter update request 709 * @param[in] addr target device address 710 * @param[in] connParam connection parameter 711 * @return @c BT_SUCCESS : The function is executed successfully. 712 * @c otherwise : The function is not executed successfully. 713 */ 714 BTSTACK_API int GAPIF_LeConnParamUpdate(const BtAddr *addr, const GapLeConnectionParameter *connParam); 715 716 /** 717 * @brief Respond Connection parameter update request 718 * @param[in] addr target device address 719 * @param[in] accept accept or reject 720 * @param[in] connParam connection parameter 721 * @return @c BT_SUCCESS : The function is executed successfully. 722 * @c otherwise : The function is not executed successfully. 723 */ 724 BTSTACK_API int GAPIF_LeConnectionParameterRsp( 725 const BtAddr *addr, uint8_t accept, const GapLeConnectionParameter *connParam); 726 727 /** 728 * @brief Register BLE security callback 729 * @param[in] callback BLE security callback 730 * @param[in] context BLE security callback context parameter 731 * @return @c BT_SUCCESS : The function is executed successfully. 732 * @c otherwise : The function is not executed successfully. 733 */ 734 BTSTACK_API int GAPIF_RegisterLeSecurityCallback(const GapLeSecurityCallback *callback, void *context); 735 736 /** 737 * @brief Deregister BLE security callback 738 * @return @c BT_SUCCESS : The function is executed successfully. 739 * @c otherwise : The function is not executed successfully. 740 */ 741 BTSTACK_API int GAPIF_DeregisterLeSecurityCallback(void); 742 743 /** 744 * @brief Respond remote encryption key of target device 745 * @param[in] addr target device address 746 * @param[in] accept accept or reject 747 * @param[in] remoteEncKey remote encryption key 748 * @param[in] keyType remote encryption key type 749 * @return @c BT_SUCCESS : The function is executed successfully. 750 * @c otherwise : The function is not executed successfully. 751 */ 752 BTSTACK_API int GAPIF_LeRemoteEncryptionKeyRsp( 753 const BtAddr *addr, uint8_t accept, LeEncKey remoteEncKey, uint8_t keyType); 754 755 /** 756 * @brief Respond local encryption key of target device 757 * @param[in] addr target device address 758 * @param[in] accept accept or reject 759 * @param[in] localEncKey local encryption key 760 * @param[in] keyType local encryption key type 761 * @return @c BT_SUCCESS : The function is executed successfully. 762 * @c otherwise : The function is not executed successfully. 763 */ 764 BTSTACK_API int GAPIF_LeLocalEncryptionKeyRsp( 765 const BtAddr *addr, uint8_t accept, LeEncKey localEncKey, uint8_t keyType); 766 767 /** 768 * @brief Respond signing key of target device 769 * @param[in] addr target device address 770 * @param[in] accept accept or reject 771 * @param[in] info signing key info 772 * @return @c BT_SUCCESS : The function is executed successfully. 773 * @c otherwise : The function is not executed successfully. 774 */ 775 BTSTACK_API int GAPIF_RequestSigningAlgorithmInfoRsp(const BtAddr *addr, uint8_t accept, GapSigningAlgorithmInfo info); 776 777 /** 778 * @brief Set BLE bondable mode 779 * @param[in] mode boneable mode 780 * @return @c BT_SUCCESS : The function is executed successfully. 781 * @c otherwise : The function is not executed successfully. 782 */ 783 BTSTACK_API int GAPIF_LeSetBondMode(uint8_t mode); 784 785 /** 786 * @brief Set BLE security mode 787 * @param[in] mode1Level level of LE security mode 1 788 * @param[in] mode2Level level of LE security mode 2 789 * @return @c BT_SUCCESS : The function is executed successfully. 790 * @c otherwise : The function is not executed successfully. 791 */ 792 BTSTACK_API int GAPIF_LeSetSecurityMode(GAP_LeSecMode1Level mode1Level, GAP_LeSecMode2Level mode2Level); 793 794 /** 795 * @brief Get security status of le connection 796 * @param[in] addr target device address 797 * @param[out] status security status of le connection 798 * @param[out] encKeySize encryption Key Size 799 * @return @c BT_SUCCESS : The function is executed successfully. 800 * @c otherwise : The function is not executed successfully. 801 */ 802 BTSTACK_API int GAPIF_LeGetSecurityStatus(const BtAddr *addr, GAP_LeSecurityStatus *status, uint8_t *encKeySize); 803 804 /** 805 * @brief Request security of le connection 806 * @param[in] addr target device address 807 * @param[in] status security status of le connection 808 * @param[in] callback result callback 809 * @param[in] context result callback context parameter 810 * @return @c BT_SUCCESS : The function is executed successfully. 811 * @c otherwise : The function is not executed successfully. 812 */ 813 BTSTACK_API int GAPIF_LeRequestSecurity( 814 const BtAddr *addr, GAP_LeSecurityStatus status, GapLeRequestSecurityResult callback, void *context); 815 816 /** 817 * @brief BLE bonding procedure 818 * @param[in] addr target device address 819 * @return @c BT_SUCCESS : The function is executed successfully. 820 * @c otherwise : The function is not executed successfully. 821 */ 822 BTSTACK_API int GAPIF_LePair(const BtAddr *addr); 823 824 /** 825 * @brief Cancel BLE bonding procedure 826 * @param[in] addr target device address 827 * @return @c BT_SUCCESS : The function is executed successfully. 828 * @c otherwise : The function is not executed successfully. 829 */ 830 BTSTACK_API int GAPIF_LeCancelPair(const BtAddr *addr); 831 832 /** 833 * @brief Set minimum of Long Term Key size 834 * @param[in] minSize minimum of Long Term Key size 835 * @return @c BT_SUCCESS : The function is executed successfully. 836 * @c otherwise : The function is not executed successfully. 837 */ 838 BTSTACK_API int GAPIF_LeSetMinEncKeySize(uint8_t minSize); 839 840 /** 841 * @brief Register BLE pair callback 842 * @param[in] callback BLE pair callback 843 * @param[in] context BLE pair callback context parameter 844 * @return @c BT_SUCCESS : The function is executed successfully. 845 * @c otherwise : The function is not executed successfully. 846 */ 847 BTSTACK_API int GAPIF_RegisterLePairCallback(const GapLePairCallback *callback, void *context); 848 849 /** 850 * @brief Deregister BLE pair callback 851 * @return @c BT_SUCCESS : The function is executed successfully. 852 * @c otherwise : The function is not executed successfully. 853 */ 854 BTSTACK_API int GAPIF_DeregisterLePairCallback(void); 855 856 /** 857 * @brief Respond BLE pair feature request 858 * @param[in] addr target device address 859 * @param[in] localFrature local BLE pair feature 860 * @return @c BT_SUCCESS : The function is executed successfully. 861 * @c otherwise : The function is not executed successfully. 862 */ 863 BTSTACK_API int GAPIF_LePairFeatureRsp(const BtAddr *addr, GapLePairFeature localFrature); 864 865 /** 866 * @brief Respond BLE pair passkey request 867 * @param[in] addr target device address 868 * @param[in] accept accept orr reject 869 * @param[in] number passkey number (000000-999999) 870 * @return @c BT_SUCCESS : The function is executed successfully. 871 * @c otherwise : The function is not executed successfully. 872 */ 873 BTSTACK_API int GAPIF_LePairPassKeyRsp(const BtAddr *addr, uint8_t accept, uint32_t number); 874 875 /** 876 * @brief Respond BLE legacy OOB data request 877 * @param[in] addr target device address 878 * @param[in] accept accept orr reject 879 * @param[in] oobData legacy OOB data 880 * @return @c BT_SUCCESS : The function is executed successfully. 881 * @c otherwise : The function is not executed successfully. 882 */ 883 BTSTACK_API int GAPIF_LePairOobRsp(const BtAddr *addr, uint8_t accept, uint8_t oobData[GAP_OOB_DATA_SIZE]); 884 885 /** 886 * @brief Respond BLE Secure connection OOB data request 887 * @param[in] addr target device address 888 * @param[in] accept accept orr reject 889 * @param[in] oobDataC Secure connection OOB confirm data 890 * @param[in] oobDataR Secure connection OOB random data 891 * @return @c BT_SUCCESS : The function is executed successfully. 892 * @c otherwise : The function is not executed successfully. 893 */ 894 BTSTACK_API int GAPIF_LePairScOobRsp(const BtAddr *addr, uint8_t accept, 895 const uint8_t oobDataC[GAP_OOB_DATA_CONFIRM_SIZE], const uint8_t oobDataR[GAP_OOB_DATA_RANDOM_SIZE]); 896 897 /** 898 * @brief Respond user confirmation request 899 * @param[in] addr target device address 900 * @param[in] accept accept orr reject 901 * @return @c BT_SUCCESS : The function is executed successfully. 902 * @c otherwise : The function is not executed successfully. 903 */ 904 BTSTACK_API int GAPIF_LePairScUserConfirmRsp(const BtAddr *addr, uint8_t accept); 905 906 /** 907 * @brief generation a data signature 908 * @param[in] addr target device address 909 * @param[in] dataInfo data PDU 910 * @param[in] callback result callback function 911 * @param[in] context result callback function context 912 * @return @c BT_SUCCESS : The function is executed successfully. 913 * @c otherwise : The function is not executed successfully. 914 */ 915 BTSTACK_API int GAPIF_LeDataSignatureGenerationAsync( 916 const BtAddr *addr, GapSignatureData dataInfo, GAPSignatureGenerationResult callback, void *context); 917 918 /** 919 * @brief Confirmation a data signature 920 * @param[in] addr target device address 921 * @param[in] dataInfo data PDU 922 * @param[in] signature signature data 923 * @param[in] callback result callback function 924 * @param[in] context result callback function context 925 * @return @c BT_SUCCESS : The function is executed successfully. 926 * @c otherwise : The function is not executed successfully. 927 */ 928 BTSTACK_API int GAPIF_LeDataSignatureConfirmationAsync(const BtAddr *addr, GapSignatureData dataInfo, 929 const uint8_t signature[GAP_SIGNATURE_SIZE], GAPSignatureConfirmationResult callback, void *context); 930 931 #ifdef __cplusplus 932 } 933 #endif 934 935 #endif /* GAP_LE_IF_H */ 936