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 * @file btm.h 18 * 19 * @brief BTMNG module. 20 * 21 */ 22 23 #ifndef BTM_H 24 #define BTM_H 25 26 #include <stdint.h> 27 #include <stdbool.h> 28 29 #include "btstack.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /** 36 * @brief Initialize function for bluetooth stack. 37 * 38 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 39 */ 40 int BTSTACK_API BTM_Initialize(); 41 42 /** 43 * @brief Close function for bluetooth stack. 44 * 45 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 46 */ 47 int BTSTACK_API BTM_Close(); 48 49 #define BREDR_CONTROLLER 1 50 #define LE_CONTROLLER 2 51 52 /** 53 * @brief Enable BR/EDR controller or LE controller 54 * 55 * @param controller <b>BREDR_CONTROLLER</b> or <b>LE_CONTROLLER</b>. 56 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 57 */ 58 int BTSTACK_API BTM_Enable(int controller); 59 60 /** 61 * @brief Disable BR/EDR controller or LE controller 62 * 63 * @param controller <b>BREDR_CONTROLLER</b> or <b>LE_CONTROLLER</b>. 64 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 65 */ 66 int BTSTACK_API BTM_Disable(int controller); 67 68 /** 69 * @brief Get current state for BR/EDR controller or LE controller 70 * 71 * @param controller <b>BREDR_CONTROLLER</b> or <b>LE_CONTROLLER</b>. 72 * @return Returns <b>true</b> if the controller is enabled; returns <b>false</b> if the controller is disabled. 73 */ 74 bool BTSTACK_API BTM_IsEnabled(int controller); 75 76 typedef struct { 77 void (*hciFailure)(void *context); 78 } BtmCallbacks; 79 80 /** 81 * @brief Register callback functions. 82 * 83 * @param callbacks Point to <b>BtmCallbacks</b> struct, the struct must be available before calling to 84 * <b>BTM_DeregisterCallbacks</b>. 85 * @param context The context for callback functions. 86 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 87 */ 88 int BTSTACK_API BTM_RegisterCallbacks(const BtmCallbacks *callbacks, void *context); 89 90 /** 91 * @brief Deregister callback functions. 92 * 93 * @param callbacks Point to <b>BtmCallbacks</b> struct. 94 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 95 */ 96 int BTSTACK_API BTM_DeregisterCallbacks(const BtmCallbacks *callbacks); 97 98 /** 99 * ACL 100 */ 101 102 /** 103 * @brief Create ACL connetion to BR/EDR device. 104 * 105 * @param addr The address of BR/EDR device. 106 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 107 */ 108 int BTSTACK_API BTM_AclConnect(const BtAddr *addr); 109 110 /** 111 * @brief Cancel the connect operation to BR/EDR device. 112 * 113 * @param addr The address of BR/EDR device. 114 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 115 */ 116 int BTSTACK_API BTM_AclCancelConnect(const BtAddr *addr); 117 118 /** 119 * @brief Create ACL connetion to LE device. 120 * 121 * @param addr The address of LE device. 122 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 123 */ 124 int BTSTACK_API BTM_LeConnect(const BtAddr *addr); 125 126 /** 127 * @brief Cancel the connect operation to LE device. 128 * 129 * @param addr The address of LE device. 130 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 131 */ 132 int BTSTACK_API BTM_LeCancelConnect(const BtAddr *addr); 133 134 /** 135 * @brief Set LE connection mode to fast. 136 * 137 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 138 */ 139 int BTSTACK_API BTM_SetLeConnectionModeToFast(); 140 141 /** 142 * @brief Set LE connection mode to slow. 143 * 144 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 145 */ 146 int BTSTACK_API BTM_SetLeConnectionModeToSlow(); 147 148 /** 149 * @brief Disconnect an ACL connetion. 150 * 151 * @param connectionHandle The connection handle. 152 * @param reason The reason for peer devcie. 153 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 154 */ 155 int BTSTACK_API BTM_AclDisconnect(uint16_t connectionHandle, uint8_t reason); 156 157 /** 158 * @brief Add a reference to the ACL connetion. 159 * 160 * @param connectionHandle The connection handle. 161 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 162 */ 163 int BTSTACK_API BTM_AclAddRef(uint16_t connectionHandle); 164 165 /** 166 * @brief Release the reference to the ACL connetion. 167 * 168 * @param connectionHandle The connection handle. 169 */ 170 void BTSTACK_API BTM_AclRelease(uint16_t connectionHandle); 171 172 /** 173 * @brief Get the transpot type of the ACL connetion. 174 * 175 * @param connectionHandle The connection handle. 176 * @return <b>TRANSPORT_BREDR</b> or <b>TRANSPORT_LE</b>. 177 */ 178 uint8_t BTSTACK_API BTM_GetAclTranspot(uint16_t connectionHandle); 179 180 /** 181 * @brief Get the RSSI value of remote LE device. 182 * 183 * @param addr The address of remote LE device. 184 * @return The RSSI value. 185 */ 186 int BTSTACK_API BTM_ReadRssi(const BtAddr *addr); 187 188 #define BTM_ROLE_MASTER 0x00 189 #define BTM_ROLE_SLAVE 0x01 190 191 /** 192 * @brief Switch role for a BR/EDR connection. 193 * 194 * @param addr The address device. 195 * @param role <b>BTM_ROLE_MASTER</b> or <b>BTM_ROLE_SLAVE</b>. 196 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 197 */ 198 int BTSTACK_API BTM_SwitchRole(const BtAddr *addr, uint8_t role); 199 200 /** 201 * @brief Determine whether the connection is a secure connection. 202 * 203 * @param addr The address device. 204 * @return Returns <b>true</b> if it's a secure connection; otherwise returns <b>false</b>. 205 */ 206 bool BTSTACK_API BTM_IsSecureConnection(const BtAddr *addr); 207 208 typedef void (*BTMRemoteDeviceSupportCallback)(const BtAddr *addr, bool support); 209 210 void BTSTACK_API BTM_IsRemoteDeviceSupportHostSecureSimplePairing( 211 const BtAddr *addr, BTMRemoteDeviceSupportCallback callback); 212 void BTSTACK_API BTM_IsRemoteDeviceSupportConnectionParametersRequest( 213 const BtAddr *addr, BTMRemoteDeviceSupportCallback callback); 214 void BTSTACK_API BTM_IsRemoteDeviceSupportEdrAcl2MbMode(const BtAddr *addr, BTMRemoteDeviceSupportCallback callback); 215 void BTSTACK_API BTM_IsRemoteDeviceSupportEdrAcl3MbMode(const BtAddr *addr, BTMRemoteDeviceSupportCallback callback); 216 217 #define LE_CONNECTION_ROLE_MASTER 0x00 218 #define LE_CONNECTION_ROLE_SLAVE 0x01 219 220 typedef struct { 221 uint8_t status; 222 uint16_t connectionHandle; 223 const BtAddr *addr; 224 uint8_t classOfDevice[3]; 225 bool encyptionEnabled; 226 } BtmAclConnectCompleteParam; 227 228 typedef struct { 229 void (*connectionComplete)(const BtmAclConnectCompleteParam *param, void *context); 230 231 void (*disconnectionComplete)(uint8_t status, uint16_t connectionHandle, uint8_t reason, void *context); 232 233 void (*leConnectionComplete)( 234 uint8_t status, uint16_t connectionHandle, const BtAddr *addr, uint8_t role, void *context); 235 236 void (*leDisconnectionComplete)(uint8_t status, uint16_t connectionHandle, uint8_t reason, void *context); 237 238 void (*readRssiComplete)(uint8_t status, const BtAddr *addr, int8_t rssi, void *context); 239 240 void (*roleChange)(uint8_t status, const BtAddr *addr, uint8_t newRole, void *context); 241 } BtmAclCallbacks; 242 243 /** 244 * @brief Register callback functions for ACL features. 245 * 246 * @param callbacks Point to <b>BtmAclCallbacks</b> struct, the struct must be available before calling to 247 * <b>BTM_DeregisterAclCallbacks</b>. 248 * @param context The context for callback functions. 249 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 250 */ 251 int BTSTACK_API BTM_RegisterAclCallbacks(const BtmAclCallbacks *callbacks, void *context); 252 253 /** 254 * @brief Deregister callback functions for ACL features. 255 * 256 * @param callbacks Point to <b>BtmAclCallbacks</b> struct. 257 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 258 */ 259 int BTSTACK_API BTM_DeregisterAclCallbacks(const BtmAclCallbacks *callbacks); 260 261 /** 262 * @brief Get local address and peer address for LE connection. 263 * 264 * @param connectionHandle The connection handle. 265 * @param localAddr Point to the local address struct. 266 * @param peerAddr Point to the peer address struct. 267 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 268 */ 269 int BTSTACK_API BTM_GetLeConnectionAddress(uint16_t connectionHandle, BtAddr *localAddr, BtAddr *peerAddr); 270 271 #define BTM_LINK_POLICY_DISABLE_All 0x0000 272 #define BTM_LINK_POLICY_ENABLE_ROLE_SWITCH 0x0001 273 #define BTM_LINK_POLICY_ENABLE_HOLD_MODE 0x0002 274 #define BTM_LINK_POLICY_ENABLE_SNIFF_MODE 0x0004 275 276 /** 277 * @brief Set default Link Policy Settings. 278 * 279 * @param linkPolicySettings The default Link Policy Settings. 280 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 281 */ 282 int BTSTACK_API BTM_SetDefaultLinkPolicySettings(uint16_t linkPolicySettings); 283 284 /** 285 * @brief Set Link Policy Settings for BR/EDR connection. 286 * 287 * @param addr Point to the remote address struct. 288 * @param linkPolicySettings The default Link Policy Settings. 289 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 290 */ 291 int BTSTACK_API BTM_SetLinkPolicySettings(const BtAddr *addr, uint16_t linkPolicySettings); 292 293 #define BTM_ACL_PACKET_TYPE_NO_2_DH1 0x0002 294 #define BTM_ACL_PACKET_TYPE_NO_3_DH1 0x0004 295 #define BTM_ACL_PACKET_TYPE_DM1 0x0008 296 #define BTM_ACL_PACKET_TYPE_DH1 0x0010 297 #define BTM_ACL_PACKET_TYPE_NO_2_DH3 0x0100 298 #define BTM_ACL_PACKET_TYPE_NO_3_DH3 0x0200 299 #define BTM_ACL_PACKET_TYPE_DM3 0x0400 300 #define BTM_ACL_PACKET_TYPE_DH3 0x0800 301 #define BTM_ACL_PACKET_TYPE_NO_2_DH5 0x1000 302 #define BTM_ACL_PACKET_TYPE_NO_3_DH5 0x2000 303 #define BTM_ACL_PACKET_TYPE_DM5 0x4000 304 #define BTM_ACL_PACKET_TYPE_DH5 0x8000 305 306 #define BTM_ACL_PACKET_TYPE_DEFAULT \ 307 (BTM_ACL_PACKET_TYPE_DM1 | BTM_ACL_PACKET_TYPE_DH1 | BTM_ACL_PACKET_TYPE_DM3 | BTM_ACL_PACKET_TYPE_DH3 | \ 308 BTM_ACL_PACKET_TYPE_DM5 | BTM_ACL_PACKET_TYPE_DH5) 309 310 /** 311 * @brief Change packet types for BR/EDR connection. 312 * 313 * @param addr Point to the remote address struct. 314 * @param packetType The packet types. 315 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 316 */ 317 int BTSTACK_API BTM_ChangeConnectionPacketType(const BtAddr *addr, uint16_t packetType); 318 319 /** 320 * Controller 321 */ 322 323 /** 324 * @brief Determine whether the local controller supports BR/EDR. 325 * 326 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 327 */ 328 bool BTSTACK_API BTM_IsControllerSupportBrEdr(); 329 330 /** 331 * @brief Determine whether the local controller supports LE. 332 * 333 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 334 */ 335 bool BTSTACK_API BTM_IsControllerSupportLe(); 336 337 /** 338 * @brief Determine whether the local controller supports RSSI Inquiry Response. 339 * 340 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 341 */ 342 bool BTSTACK_API BTM_IsControllerSupportRssiInquiryResponse(); 343 344 /** 345 * @brief Determine whether the local controller supports EIR Inquiry Response. 346 * 347 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 348 */ 349 bool BTSTACK_API BTM_IsControllerSupportEirInquiryResponse(); 350 351 /** 352 * @brief Determine whether the local controller supports Role Switch. 353 * 354 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 355 */ 356 bool BTSTACK_API BTM_IsControllerSupportRoleSwitch(); 357 358 /** 359 * @brief Determine whether the local controller supports Hold Mode. 360 * 361 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 362 */ 363 bool BTSTACK_API BTM_IsControllerSupportHoldMode(); 364 365 /** 366 * @brief Determine whether the local controller supports Sniff Mode. 367 * 368 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 369 */ 370 bool BTSTACK_API BTM_IsControllerSupportSniffMode(); 371 372 /** 373 * @brief Determine whether the local controller supports eSCO. 374 * 375 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 376 */ 377 bool BTSTACK_API BTM_IsControllerSupportEsco(); 378 379 /** 380 * @brief Determine whether the local controller supports Secure Simple Pairing. 381 * 382 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 383 */ 384 bool BTSTACK_API BTM_IsControllerSupportSecureSimplePairing(); 385 386 /** 387 * @brief Determine whether the local controller supports Secure Connections. 388 * 389 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 390 */ 391 bool BTSTACK_API BTM_IsControllerSupportSecureConnections(); 392 393 /** 394 * @brief Determine whether the local controller supports Non-flushable Packet Boundary Flag. 395 * 396 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 397 */ 398 bool BTSTACK_API BTM_IsControllerSupportNonFlushablePacketBoundaryFlag(); 399 400 /** 401 * @brief Determine whether the local controller supports Connection Parameters Request Procedure. 402 * 403 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 404 */ 405 bool BTSTACK_API BTM_IsControllerSupportConnectionParametersRequestProcedure(); 406 407 /** 408 * @brief Determine whether the local controller supports LE Ping. 409 * 410 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 411 */ 412 bool BTSTACK_API BTM_IsControllerSupportLePing(); 413 414 /** 415 * @brief Determine whether the local controller supports LE Data Packet Length Extension. 416 * 417 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 418 */ 419 bool BTSTACK_API BTM_IsControllerSupportLeDataPacketLengthExtension(); 420 421 /** 422 * @brief Determine whether the local controller supports LL Privacy. 423 * 424 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 425 */ 426 bool BTSTACK_API BTM_IsControllerSupportLlPrivacy(); 427 428 /** 429 * @brief Determine whether the local controller supports LE 2M PHY. 430 * 431 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 432 */ 433 bool BTSTACK_API BTM_IsControllerSupportLe2MPhy(); 434 435 /** 436 * @brief Determine whether the local controller supports LE Coded PHY. 437 * 438 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 439 */ 440 bool BTSTACK_API BTM_IsControllerSupportLeCodedPhy(); 441 442 /** 443 * @brief Determine whether the local controller supports LE Extended Advertising. 444 * 445 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 446 */ 447 bool BTSTACK_API BTM_IsControllerSupportLeExtendedAdvertising(); 448 449 /** 450 * @brief Determine whether the local controller supports LE Periodic Advertising. 451 * 452 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 453 */ 454 bool BTSTACK_API BTM_IsControllerSupportLePeriodicAdvertising(); 455 456 /** 457 * @brief Determine whether the local controller supports Channel Selection Algorithm #2. 458 * 459 * @return Returns <b>true</b> if supported; otherwise returns <b>false</b>. 460 */ 461 bool BTSTACK_API BTM_IsControllerSupportChannelSelectionAlgorithm2(); 462 463 /** 464 * @brief Get local address. 465 * 466 * @param addr Point to <b>BtAddr</b> struct. 467 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 468 */ 469 int BTSTACK_API BTM_GetLocalAddr(BtAddr *addr); 470 471 /** 472 * @brief Get local supported features. 473 * 474 * @param features Point to 8 bytes buffer to obtain the supported features. 475 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 476 */ 477 int BTSTACK_API BTM_GetLocalSupportedFeatures(uint8_t features[8]); 478 479 typedef struct { 480 uint8_t hciVersion; 481 uint16_t hciRevision; 482 uint8_t lmpVersion; 483 uint16_t manufacturerName; 484 uint16_t lmpSubversion; 485 } BtmLocalVersionInformation; 486 487 /** 488 * @brief Get local version information. 489 * 490 * @param localVersion Point to a <b>BtmLocalVersionInformation</b> struct. 491 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 492 */ 493 int BTSTACK_API BTM_GetLocalVersionInformation(BtmLocalVersionInformation *localVersion); 494 495 typedef struct { 496 uint16_t companyID; 497 uint16_t vendorDefinedCodecID; 498 } BtmVendorSpecificCodec; 499 500 typedef struct { 501 uint8_t numberOfSupportedCodecs; 502 uint8_t *supportedCodecs; 503 uint8_t numberOfSupportedVendorSpecificCodecs; 504 BtmVendorSpecificCodec *vendorSpecificCodecs; 505 } BtmLocalSupportedCodecs; 506 507 /** 508 * @brief Get local supported codecs. 509 * 510 * @param localSupportedCodes Point to a <b>BtmLocalSupportedCodecs</b> pointer. Do not free this pointer. 511 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 512 */ 513 int BTSTACK_API BTM_GetLocalSupportedCodecs(BtmLocalSupportedCodecs **localSupportedCodes); 514 515 /** 516 * @brief Get BR/EDR ACL data length. 517 * 518 * @param aclDataPacketLength Obtain the ACL data length. 519 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 520 */ 521 int BTSTACK_API BTM_GetAclDataPacketLength(uint16_t *aclDataPacketLength); 522 523 /** 524 * @brief Get LE ACL data length. 525 * 526 * @param length Obtain the ACL data length. 527 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 528 */ 529 int BTSTACK_API BTM_GetLeAclDataPacketLength(uint16_t *length); 530 531 /** 532 * LE Security 533 */ 534 535 #define KEY_SIZE 16 536 537 typedef struct { 538 uint8_t key[KEY_SIZE]; 539 } BtmKey; 540 541 typedef struct { 542 BtmKey key; 543 uint64_t rand; 544 uint16_t ediv; 545 } BtmLeEncryptionKey; 546 547 typedef struct { 548 BtAddr addr; 549 BtmKey remoteIdentityResolvingKey; 550 BtAddr remoteIdentityAddress; 551 } BtmLePairedDevice; 552 553 /** 554 * @brief Set local Identity Resolving Key. 555 * 556 * @param key The Identity Resolving Key. 557 */ 558 void BTSTACK_API BTM_SetLocalIdentityResolvingKey(const BtmKey *key); 559 560 /** 561 * @brief Set LE Paired Devices. 562 * 563 * @param pairedDevices The array of LE Paired Devices. 564 * @param count The count of array. 565 */ 566 void BTSTACK_API BTM_SetLePairedDevices(const BtmLePairedDevice *pairedDevices, uint16_t count); 567 568 /** 569 * @brief Add a LE Paired Devices. 570 * 571 * @param device Point to a <b>BtmLePairedDevice</b> struct. 572 */ 573 void BTSTACK_API BTM_AddLePairedDevice(const BtmLePairedDevice *device); 574 575 /** 576 * @brief Remove a LE Paired Devices. 577 * 578 * @param addr The address of the removing device. 579 */ 580 void BTSTACK_API BTM_RemoveLePairedDevice(const BtAddr *addr); 581 582 #define OWN_ADDRESS_TYPE_PUBLIC 0x00 583 #define OWN_ADDRESS_TYPE_RANDOM 0x01 584 585 /** 586 * @brief Set local address type for LE. 587 * 588 * @param ownAddressType Should be <b>OWN_ADDRESS_TYPE_PUBLIC</b> or <b>OWN_ADDRESS_TYPE_RANDOM</b>. 589 */ 590 void BTSTACK_API BTM_SetOwnAddressType(uint32_t ownAddressType); 591 592 /** 593 * @brief Get local address type for LE. 594 * 595 * @return Return <b>OWN_ADDRESS_TYPE_PUBLIC</b> or <b>OWN_ADDRESS_TYPE_RANDOM</b>. 596 */ 597 uint8_t BTM_GetOwnAddressType(); 598 599 /** 600 * @brief Set LE random address. 601 * 602 * @param addr The random address. 603 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 604 */ 605 int BTSTACK_API BTM_SetLeRandomAddress(const BtAddr *addr); 606 607 /** 608 * @brief Get LE random address. 609 * 610 * @param addr The random address. 611 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 612 */ 613 int BTSTACK_API BTM_GetLeRandomAddress(BtAddr *addr); 614 615 /** 616 * Power Management 617 */ 618 typedef struct { 619 uint16_t maxInterval; 620 uint16_t minInterval; 621 uint16_t attempt; 622 uint16_t timeout; 623 } BtmSniffParam; 624 625 /** 626 * @brief Enter Sniff mode. 627 * 628 * @param addr The remote device address. 629 * @param param The Sniff parameters. 630 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 631 */ 632 int BTSTACK_API BTM_EnterSniffMode(const BtAddr *addr, const BtmSniffParam *param); 633 634 /** 635 * @brief Exit Sniff mode. 636 * 637 * @param addr The remote device address. 638 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 639 */ 640 int BTSTACK_API BTM_ExitSniffMode(const BtAddr *addr); 641 642 typedef struct { 643 uint16_t maximumLatency; 644 uint16_t minimumRemoteTimeout; 645 uint16_t minimumLocalTimeout; 646 } BtmSniffSubrating; 647 648 /** 649 * @brief Set Sniff Subrating. 650 * 651 * @param addr The remote device address. 652 * @param subRating The Sniff Subrating parameters. 653 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 654 */ 655 int BTSTACK_API BTM_SetSniffSubrating(const BtAddr *addr, const BtmSniffSubrating *subRating); 656 657 #define BTM_PM_ACTIVE_MODE 0x00 658 #define BTM_PM_HOLD_MODE 0x01 659 #define BTM_PM_SNIFF_MODE 0x02 660 661 typedef struct { 662 void (*modeChange)(uint8_t status, const BtAddr *addr, uint8_t currentMode, uint16_t interval, void *context); 663 void (*setSniffSubratingComplete)(uint8_t status, const BtAddr *addr, void *context); 664 } BtmPmCallbacks; 665 666 /** 667 * @brief Register callback functions for Power Management features. 668 * 669 * @param callbacks Point to <b>BtmPmCallbacks</b> struct, the struct must be available before calling to 670 * <b>BTM_DeregisterPmCallbacks</b>. 671 * @param context The context for callback functions. 672 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 673 */ 674 int BTSTACK_API BTM_RegisterPmCallbacks(const BtmPmCallbacks *callbacks, void *context); 675 676 /** 677 * @brief Deregister callback functions for Power Management features. 678 * 679 * @param callbacks Point to <b>BtmPmCallbacks</b> struct. 680 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 681 */ 682 int BTSTACK_API BTM_DeregisterPmCallbacks(const BtmPmCallbacks *callbacks); 683 684 /** 685 * SCO 686 */ 687 typedef struct { 688 BtAddr addr; 689 uint32_t transmitBandwidth; 690 uint32_t receiveBandwidth; 691 uint16_t maxLatency; 692 uint16_t voiceSetting; 693 uint8_t retransmissionEffort; 694 uint16_t packetType; 695 } BtmCreateScoConnectionParam; 696 697 /** 698 * @brief Create SCO connection. 699 * 700 * @param param The parameters of creating a SCO connection. 701 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 702 */ 703 int BTSTACK_API BTM_CreateScoConnection(const BtmCreateScoConnectionParam *param); 704 705 typedef struct { 706 uint16_t connectionHandle; 707 uint32_t transmitBandwidth; 708 uint32_t receiveBandwidth; 709 uint16_t maxLatency; 710 uint16_t voiceSetting; 711 uint8_t retransmissionEffort; 712 uint16_t packetType; 713 } BtmModifyScoConnectionParam; 714 715 /** 716 * @brief Modify SCO connection. 717 * 718 * @param param The parameters of modifing SCO connection. 719 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 720 */ 721 int BTSTACK_API BTM_ModifyScoConnection(const BtmModifyScoConnectionParam *param); 722 723 typedef BtmCreateScoConnectionParam BtmAcceptScoConnectionRequestParam; 724 725 /** 726 * @brief Accept a SCO connection request. 727 * 728 * @param param The parameters of accepting a SCO connection request. 729 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 730 */ 731 int BTSTACK_API BTM_AcceptScoConnectionRequest(const BtmAcceptScoConnectionRequestParam *param); 732 733 typedef struct { 734 BtAddr addr; 735 uint8_t reason; 736 } BtmRejectScoConnectionRequestParam; 737 738 /** 739 * @brief Reject a SCO connection request. 740 * 741 * @param param The parameters of rejecting a SCO connection request. 742 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 743 */ 744 int BTSTACK_API BTM_RejectScoConnectionRequest(const BtmRejectScoConnectionRequestParam *param); 745 746 /** 747 * @brief Diconnect a SCO/eSco connection request. 748 * 749 * @param connectionHandle The connection handle. 750 * @param reason The disconnect reason for remote device. 751 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 752 */ 753 int BTSTACK_API BTM_DisconnectScoConnection(uint16_t connectionHandle, uint8_t reason); 754 755 #define CODEC_CVSD 0 756 #define CODEC_MSBC_T1 1 757 #define CODEC_MSBC_T2 2 758 759 typedef struct { 760 BtAddr addr; 761 uint32_t transmitBandwidth; 762 uint32_t receiveBandwidth; 763 uint8_t codec; 764 uint16_t maxLatency; 765 uint16_t packetType; 766 uint8_t retransmissionEffort; 767 } BtmCreateEscoConnectionParam; 768 769 /** 770 * @brief Create eSCO connection. 771 * 772 * @param param The parameters of creating a eSCO connection. 773 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 774 */ 775 int BTSTACK_API BTM_CreateEscoConnection(const BtmCreateEscoConnectionParam *param); 776 777 typedef struct { 778 uint16_t connectionHandle; 779 uint32_t transmitBandwidth; 780 uint32_t receiveBandwidth; 781 uint8_t codec; 782 uint16_t maxLatency; 783 uint16_t packetType; 784 uint8_t retransmissionEffort; 785 } BtmModifyEscoConnectionParam; 786 787 /** 788 * @brief Modify eSCO connection. 789 * 790 * @param param The parameters of modifing eSCO connection. 791 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 792 */ 793 int BTSTACK_API BTM_ModifyEscoConnection(const BtmModifyEscoConnectionParam *param); 794 795 typedef BtmCreateEscoConnectionParam BtmAcceptEscoConnectionRequestParam; 796 797 /** 798 * @brief Accept a eSCO connection request. 799 * 800 * @param param The parameters of accepting a eSCO connection request. 801 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 802 */ 803 int BTSTACK_API BTM_AcceptEscoConnectionRequest(const BtmAcceptEscoConnectionRequestParam *param); 804 805 #define LINK_TYPE_SCO 0x00 806 #define LINK_TYPE_ESCO 0x02 807 808 typedef struct { 809 uint8_t status; 810 uint16_t connectionHandle; 811 const BtAddr *addr; 812 } BtmScoConnectionCompleteParam; 813 814 typedef struct { 815 uint16_t connectionHandle; 816 uint8_t transmissionInterval; 817 uint8_t retransmissionWindow; 818 uint16_t rxPacketLength; 819 uint16_t txPacketLength; 820 } BtmScoConnectionChangedParam; 821 822 typedef struct { 823 uint8_t status; 824 uint16_t connectionHandle; 825 uint8_t reason; 826 } BtmScoDisconnectionCompleteParam; 827 828 typedef struct { 829 const BtAddr *addr; 830 uint8_t linkType; 831 } BtmScoConnectionRequestParam; 832 833 typedef struct { 834 void (*scoConnectionComplete)(const BtmScoConnectionCompleteParam *param, void *context); 835 836 void (*scoConnectionChanged)(const BtmScoConnectionChangedParam *param, void *context); 837 838 void (*scoDisconnectionComplete)(const BtmScoDisconnectionCompleteParam *param, void *context); 839 840 void (*scoConnectionRequest)(const BtmScoConnectionRequestParam *param, void *context); 841 842 void (*writeVoiceSettingComplete)(uint8_t status, void *context); 843 } BtmScoCallbacks; 844 845 /** 846 * @brief Register callback functions for SCO/eSCO features. 847 * 848 * @param callbacks Point to <b>BtmScoCallbacks</b> struct, the struct must be available before calling to 849 * <b>BTM_DeregisterScoCallbacks</b>. 850 * @param context The context for callback functions. 851 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 852 */ 853 int BTSTACK_API BTM_RegisterScoCallbacks(const BtmScoCallbacks *callbacks, void *context); 854 855 /** 856 * @brief Deregister callback functions for SCO/eSCO features. 857 * 858 * @param callbacks Point to <b>BtmScoCallbacks</b> struct. 859 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 860 */ 861 int BTSTACK_API BTM_DeregisterScoCallbacks(const BtmScoCallbacks *callbacks); 862 863 /** 864 * @brief Write voice setting. 865 * 866 * @param voiceSetting The value of voice setting. 867 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 868 */ 869 int BTSTACK_API BTM_WriteVoiceSetting(uint16_t voiceSetting); 870 871 /** 872 * Snoop 873 */ 874 875 /** 876 * @brief Set snoop file output path. 877 * 878 * @param path Point to the path string. 879 * @param length The length of path. 880 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 881 */ 882 int BTSTACK_API BTM_SetSnoopFilePath(const char *path, uint16_t length); 883 884 /** 885 * @brief Enable snoop file output. 886 * 887 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 888 */ 889 int BTSTACK_API BTM_EnableSnoopFileOutput(bool filter); 890 891 /** 892 * @brief Disable snoop file output. 893 * 894 * @return Returns <b>BT_NO_ERROR</b> if the operation is successful; returns others if the operation fails. 895 */ 896 int BTSTACK_API BTM_DisableSnoopFileOutput(); 897 898 /** 899 * Log 900 */ 901 int BTSTACK_API BTM_EnableHciLogOutput(bool filter); 902 int BTSTACK_API BTM_DisableHciLogOutput(); 903 904 /** 905 * Snoop filter 906 */ 907 908 #define BTM_HCI_LOG_FILTER_MODULE_HFP 0x01 909 #define BTM_HCI_LOG_FILTER_MODULE_PBAP 0x02 910 #define BTM_HCI_LOG_FILTER_MODULE_MAP 0x03 911 #define BTM_HCI_LOG_FILTER_MODULE_RFCOMM 0x04 912 #define BTM_HCI_LOG_FILTER_MODULE_AVCTP 0x05 913 #define BTM_HCI_LOG_FILTER_MODULE_AVCTP_BROWSING 0x06 914 #define BTM_HCI_LOG_FILTER_MODULE_AVDTP 0x07 915 #define BTM_HCI_LOG_FILTER_MODULE_SPP 0x08 916 #define BTM_HCI_LOG_FILTER_MODULE_ATT 0x09 917 #define BTM_HCI_LOG_FILTER_MODULE_SM 0x0A 918 919 void BTSTACK_API BTM_AddLocalL2capPsmForLogging(uint8_t module, uint16_t psm); 920 void BTSTACK_API BTM_AddRemoteL2capPsmForLogging(uint8_t module, uint16_t psm, const BtAddr *remoteAddr); 921 void BTSTACK_API BTM_RemoveLocalL2capPsmForLogging(uint8_t module, uint16_t psm); 922 void BTSTACK_API BTM_RemoveRemoteL2capPsmForLogging(uint8_t module, uint16_t psm, const BtAddr *remoteAddr); 923 924 void BTSTACK_API BTM_AddLocalRfcommScnForLogging(uint8_t module, uint8_t scn); 925 void BTSTACK_API BTM_AddRemoteRfcommScnForLogging(uint8_t module, uint8_t scn, const BtAddr *remoteAddr); 926 void BTSTACK_API BTM_RemoveLocalRfcommScnChannelForLogging(uint8_t module, uint8_t scn); 927 void BTSTACK_API BTM_RemoveRemoteRfcommScnChannelForLogging(uint8_t module, uint8_t scn, const BtAddr *remoteAddr); 928 929 #ifdef __cplusplus 930 } 931 #endif 932 933 #endif // BTM_H 934