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 #ifndef CLASSIC_ADAPTER_H 17 #define CLASSIC_ADAPTER_H 18 19 #include <map> 20 #include <vector> 21 22 #include "base_def.h" 23 #include "bt_uuid.h" 24 #include "btm.h" 25 #include "classic_adapter_properties.h" 26 #include "classic_battery_observer.h" 27 #include "classic_bluetooth_data.h" 28 #include "classic_remote_device.h" 29 #include "context.h" 30 #include "gap_if.h" 31 #include "interface_adapter_classic.h" 32 #include "log.h" 33 #include "log_util.h" 34 #include "raw_address.h" 35 #include "sdp.h" 36 37 /** 38 * @addtogroup Bluetooth 39 * @{ 40 * 41 * @brief Defines adapter classic common functions. 42 * 43 */ 44 45 /** 46 * @file classic_adapter.h 47 * 48 * @brief Adapter classic. 49 * 50 */ 51 52 namespace OHOS { 53 namespace bluetooth { 54 /** 55 * @brief Represents classic adapter. 56 * 57 */ 58 class ClassicAdapter : public IAdapterClassic, public utility::Context { 59 public: 60 /** 61 * @brief A constructor used to create a <b>ClassicAdapter</b> instance. 62 * 63 */ 64 ClassicAdapter(); 65 66 /** 67 * @brief A destructor used to delete the <b>ClassicAdapter</b> instance. 68 * 69 */ 70 ~ClassicAdapter(); 71 72 /** 73 * @brief Get local device address. 74 * 75 * @return Returns local device address. 76 */ 77 std::string GetLocalAddress() const override; 78 79 /** 80 * @brief Get local device name. 81 * 82 * @return Returns local device name. 83 */ 84 std::string GetLocalName() const override; 85 86 /** 87 * @brief Set local device name. 88 * 89 * @param name Device name. 90 * @return Returns <b>true</b> if the operation is successful; 91 * returns <b>false</b> if the operation fails. 92 */ 93 bool SetLocalName(const std::string &name) const override; 94 95 /** 96 * @brief Set bondable mode. 97 * 98 * @param mode Bondable mode. 99 * @return Returns <b>true</b> if the operation is successful; 100 * returns <b>false</b> if the operation fails. 101 */ 102 bool SetBondableMode(int mode) const override; 103 104 /** 105 * @brief Get bondable mode. 106 * 107 * @return Returns bondable mode. 108 */ 109 int GetBondableMode() const override; 110 111 /** 112 * @brief Get remote device name. 113 * 114 * @param device Remote device. 115 * @return Returns device name. 116 */ 117 std::string GetDeviceName(const RawAddress &device) const override; 118 119 /** 120 * @brief Get remote device uuids. 121 * 122 * @param device Remote device. 123 * @return Returns device uuids. 124 */ 125 std::vector<Uuid> GetDeviceUuids(const RawAddress &device) const override; 126 127 /** 128 * @brief Get paired devices. 129 * 130 * @return Returns device list. 131 */ 132 std::vector<RawAddress> GetPairedDevices() const override; 133 134 /** 135 * @brief Local device start pair. 136 * 137 * @param device Remote device. 138 * @return Returns <b>true</b> if the operation is successful; 139 * returns <b>false</b> if the operation fails. 140 */ 141 bool StartPair(const RawAddress &device) override; 142 143 /** 144 * @brief Check if remote device was bonded from local. 145 * 146 * @param device Remote device. 147 * @return Returns <b>true</b> if device was bonded from local; 148 * returns <b>false</b> if device was not bonded from local. 149 */ 150 bool IsBondedFromLocal(const RawAddress &device) const override; 151 152 /** 153 * @brief Cancel pair operation. 154 * 155 * @param device Remote device. 156 * @return Returns <b>true</b> if the operation is successful; 157 * returns <b>false</b> if the operation fails. 158 */ 159 bool CancelPairing(const RawAddress &device) override; 160 161 /** 162 * @brief Remove pair. 163 * 164 * @param device Remote device. 165 * @return Returns <b>true</b> if the operation is successful; 166 * returns <b>false</b> if the operation fails. 167 */ 168 bool RemovePair(const RawAddress &device) override; 169 170 /** 171 * @brief Get device pair state. 172 * 173 * @param device Remote device. 174 * @return Returns device pair state. 175 */ 176 int GetPairState(const RawAddress &device) const override; 177 178 /** 179 * @brief Set device pairing confirmation. 180 * 181 * @param device Remote device. 182 * @param accept Set gap accept flag. 183 * @return Returns <b>true</b> if the operation is successful; 184 * returns <b>false</b> if the operation fails. 185 */ 186 bool SetDevicePairingConfirmation(const RawAddress &device, bool accept) const override; 187 188 /** 189 * @brief Set device pair passkey. 190 * 191 * @param device Remote device. 192 * @param passkey Device passkey. 193 * @param accept Set gap accept flag. 194 * @return Returns <b>true</b> if the operation is successful; 195 * returns <b>false</b> if the operation fails. 196 */ 197 bool SetDevicePasskey(const RawAddress &device, int passkey, bool accept) const override; 198 199 /** 200 * @brief Check remote device pair request reply. 201 * 202 * @param device Remote device. 203 * @param accept Set gap accept flag. 204 * @return Returns <b>true</b> if the operation is successful; 205 * returns <b>false</b> if the operation fails. 206 */ 207 bool PairRequestReply(const RawAddress &device, bool accept) const override; 208 209 /** 210 * @brief Check if acl connected with remote device. 211 * 212 * @param device Remote device. 213 * @return Returns <b>true</b> if device acl connected; 214 * returns <b>false</b> if device does not acl connect. 215 */ 216 bool IsAclConnected(const RawAddress &device) const override; 217 218 /** 219 * @brief Check if remote device acl Encrypted. 220 * 221 * @return Returns <b>true</b> if device acl Encrypted; 222 * returns <b>false</b> if device does not acl Encrypt. 223 */ 224 bool IsAclEncrypted(const RawAddress &device) const override; 225 226 /** 227 * @brief Get the instance of the ClassicAdapter. 228 * 229 * @return Returns the instance of the ClassicAdapter. 230 */ 231 utility::Context *GetContext() override; 232 233 /** 234 * @brief Enable classic service. 235 * 236 */ 237 void Enable() override; 238 239 /** 240 * @brief Disable classic service. 241 * 242 */ 243 void Disable() override; 244 245 /** 246 * @brief PostEnable classic service. 247 * 248 */ 249 void PostEnable() override; 250 251 /** 252 * @brief Get remote device type. 253 * 254 * @param device Remote device. 255 * @return Returns remote device type. 256 */ 257 int GetDeviceType(const RawAddress &device) const override; 258 259 /** 260 * @brief Get remote device class. 261 * 262 * @param device Remote device. 263 * @return Returns remote device class. 264 */ 265 int GetDeviceClass(const RawAddress &device) const override; 266 267 /** 268 * @brief Get remote device alias name. 269 * 270 * @param device Remote device 271 * @return Returns remote device alias name. 272 */ 273 std::string GetAliasName(const RawAddress &device) const override; 274 275 /** 276 * @brief Set remote device alias name. 277 * 278 * @param device Remote device which setted alias name. 279 * @param name Alias name. 280 * @return Returns <b>true</b> if the operation is successful; 281 * returns <b>false</b> if the operation fails. 282 */ 283 bool SetAliasName(const RawAddress &device, const std::string &name) const override; 284 285 /** 286 * @brief Register remote device observer. 287 * 288 * @param observer Class IClassicRemoteDeviceObserver pointer to register observer. 289 * @return Returns <b>true</b> if the operation is successful; 290 * returns <b>false</b> if the operation fails. 291 */ 292 bool RegisterRemoteDeviceObserver(IClassicRemoteDeviceObserver &observer) const override; 293 294 /** 295 * @brief Deregister remote device observer. 296 * 297 * @param observer Class IClassicRemoteDeviceObserver pointer to register observer. 298 * @return Returns <b>true</b> if the operation is successful; 299 * returns <b>false</b> if the operation fails. 300 */ 301 bool DeregisterRemoteDeviceObserver(IClassicRemoteDeviceObserver &observer) const override; 302 303 /** 304 * @brief Register classic adapter observer. 305 * 306 * @param observer Class IAdapterClassicObserver pointer to register observer. 307 * @return Returns <b>true</b> if the operation is successful; 308 * returns <b>false</b> if the operation fails. 309 */ 310 bool RegisterClassicAdapterObserver(IAdapterClassicObserver &observer) const override; 311 312 /** 313 * @brief Deregister classic adapter observer. 314 * 315 * @param observer Class IAdapterClassicObserver pointer to register observer. 316 * @return Returns <b>true</b> if the operation is successful; 317 * returns <b>false</b> if the operation fails. 318 */ 319 bool DeregisterClassicAdapterObserver(IAdapterClassicObserver &observer) const override; 320 321 /** 322 * @brief Remove all pairs. 323 * 324 * @return Returns <b>true</b> if the operation is successful; 325 * returns <b>false</b> if the operation fails. 326 */ 327 bool RemoveAllPairs() override; 328 329 /** 330 * @brief Set device pair pin. 331 * 332 * @param device Remote device address. 333 * @param pin Pin code. 334 * @param length Pin code length. 335 * @return Returns <b>true</b> if the operation is successful; 336 * returns <b>false</b> if the operation fails. 337 */ 338 bool SetDevicePin(const RawAddress &device, const std::string &pinCode) const override; 339 340 /** 341 * @brief Set device scan mode. 342 * 343 * @param mode Scan mode. 344 * @param duration Scan time. 345 * @return Returns <b>true</b> if the operation is successful; 346 * returns <b>false</b> if the operation fails. 347 */ 348 bool SetBtScanMode(int mode, int duration) override; 349 350 /** 351 * @brief Get device scan mode. 352 * 353 * @return Returns bluetooth scan mode. 354 */ 355 int GetBtScanMode() const override; 356 357 /** 358 * @brief Get local device class. 359 * 360 * @return Returns local device class. 361 */ 362 int GetLocalDeviceClass() const override; 363 364 /** 365 * @brief Set local device class. 366 * 367 * @param deviceClass Device class. 368 * @return Returns <b>true</b> if the operation is successful; 369 * returns <b>false</b> if the operation fails. 370 */ 371 bool SetLocalDeviceClass(int deviceClass) const override; 372 373 /** 374 * @brief Get device address. 375 * 376 * @return Returns <b>true</b> if the operation is successful; 377 * returns <b>false</b> if the operation fails. 378 */ 379 bool StartBtDiscovery() override; 380 381 /** 382 * @brief Cancel device discovery. 383 * 384 * @return Returns <b>true</b> if the operation is successful; 385 * returns <b>false</b> if the operation fails. 386 */ 387 bool CancelBtDiscovery() override; 388 389 /** 390 * @brief Check if device is discovering. 391 * 392 * @return Returns <b>true</b> if device is discovering; 393 * returns <b>false</b> if device is not discovering. 394 */ 395 bool IsBtDiscovering() const override; 396 397 /** 398 * @brief Get device discovery end time. 399 * 400 * @return Returns device discovery end time. 401 */ 402 long GetBtDiscoveryEndMillis() const override; 403 int GetDeviceBatteryLevel(const RawAddress &device) const override; 404 void SetDeviceBatteryLevel(const RawAddress &device, int batteryLevel) const override; 405 bool IsHfpCodSupported(const RawAddress &device) override; 406 407 private: 408 /** 409 * @brief Inquiry result callback. 410 * 411 * @param addr Device address. 412 * @param classOfDevice Device class. 413 * @param context Classic adapter object. 414 */ 415 static void InquiryResultCallback(const BtAddr *addr, uint32_t classOfDevice, void *context); 416 417 /** 418 * @brief Inquiry result rssi callback. 419 * 420 * @param addr Device address. 421 * @param classOfDevice Device class. 422 * @param rssi Device rssi. 423 * @param context Classic adapter object. 424 */ 425 static void InquiryResultRssiCallback(const BtAddr *addr, uint32_t classOfDevice, int8_t rssi, void *context); 426 427 /** 428 * @brief Extended inquiry result callback. 429 * 430 * @param addr Device address. 431 * @param classOfDevice Device class. 432 * @param rssi Device rssi. 433 * @param eir Eir data. 434 * @param context Classic adapter object. 435 */ 436 static void ExtendedInquiryResultCallback(const BtAddr *addr, uint32_t classOfDevice, int8_t rssi, 437 const uint8_t eir[MAX_EXTEND_INQUIRY_RESPONSE_LEN], void *context); 438 439 /** 440 * @brief Inquiry complete callback. 441 * 442 * @param status Inquire status. 443 * @param context Classic adapter object. 444 */ 445 static void InquiryCompleteCallback(uint8_t status, void *context); 446 447 /** 448 * @brief Remote device name callback. 449 * 450 * @param status Inquire status. 451 * @param addr Device address. 452 * @param name Device name. 453 * @param context Classic adapter object. 454 */ 455 static void RemoteNameCallback( 456 uint8_t status, const BtAddr *addr, const uint8_t name[MAX_LOC_BT_NAME_LEN], void *context); 457 /** 458 * @brief User confirm request callback. 459 * 460 * @param addr Device address. 461 * @param number Pass key. 462 * @param context Classic adapter object. 463 */ 464 static void UserConfirmReqCallback(const BtAddr *addr, uint32_t number, int localMitmRequired, int remoteMitmRequired, void *context); 465 466 /** 467 * @brief User pass key request callback. 468 * 469 * @param addr Device address. 470 * @param context Classic adapter object. 471 */ 472 static void UserPasskeyReqCallback(const BtAddr *addr, void *context); 473 474 /** 475 * @brief User pass key notification callback. 476 * 477 * @param addr Device address. 478 * @param number Pass key. 479 * @param context Classic adapter object. 480 */ 481 static void UserPasskeyNotificationCallback(const BtAddr *addr, uint32_t number, void *context); 482 483 /** 484 * @brief Remote oob key request callback. 485 * 486 * @param addr Device address. 487 * @param context Classic adapter object. 488 */ 489 static void RemoteOobReqCallback(const BtAddr *addr, void *context); 490 491 /** 492 * @brief Pin code request callback. 493 * 494 * @param addr Device address. 495 * @param context Classic adapter object. 496 */ 497 static void PinCodeReqCallback(const BtAddr *addr, void *context); 498 499 /** 500 * @brief Link key request callback. 501 * 502 * @param addr Device address. 503 * @param context Classic adapter object. 504 */ 505 static void LinkKeyReqCallback(const BtAddr *addr, void *context); 506 507 /** 508 * @brief Io capability request callback. 509 * 510 * @param addr Device address. 511 * @param context Classic adapter object. 512 */ 513 static void IoCapabilityReqCallback(const BtAddr *addr, void *context); 514 515 /** 516 * @brief Io capability response callback. 517 * 518 * @param addr Device address. 519 * @param ioCapability Device iocapability. 520 * @param context Classic adapter object. 521 */ 522 static void IoCapabilityRspCallback(const BtAddr *addr, uint8_t ioCapability, void *context); 523 524 /** 525 * @brief Link key notification. 526 * 527 * @param addr Device address. 528 * @param linkkey Link key. 529 * @param keyType Link key type. 530 * @param context Classic adapter object. 531 */ 532 static void LinkKeyNotification( 533 const BtAddr *addr, const uint8_t linkKey[GAP_LINKKEY_SIZE], uint8_t keyType, void *context); 534 535 /** 536 * @brief Simple pair complete callback. 537 * 538 * @param addr Device address. 539 * @param status Pair status. 540 * @param context Classic adapter object. 541 */ 542 static void SimplePairCompleteCallback(const BtAddr *addr, uint8_t status, void *context); 543 544 /** 545 * @brief Authentication complete callback. 546 * 547 * @param addr Device address. 548 * @param status Authentication status. 549 * @param context Classic adapter object. 550 */ 551 static void AuthenticationCompleteCallback(const BtAddr *addr, uint8_t status, void *context); 552 553 /** 554 * @brief Encryption change complete callback. 555 * 556 * @param addr Device address. 557 * @param status Encryption status. 558 * @param context Classic adapter object. 559 */ 560 static void EncryptionChangeCallback(const BtAddr *addr, uint8_t status, void *context); 561 562 /** 563 * @brief Authorize ind callback. 564 * 565 * @param addr Device address. 566 * @param service Gap service. 567 * @param context Classic adapter object. 568 */ 569 static void AuthorizeIndCallback(const BtAddr *addr, GAP_Service service, void *context); 570 571 /// BTM ACL Change status callback. 572 /** 573 * @brief Acl connection complete callback. 574 * 575 * @param status Connection status. 576 * @param connectionHandle Connection handle. 577 * @param addr Device address. 578 * @param encyptionEnabled Encyption enable status. 579 * @param context Classic adapter object. 580 */ 581 static void ConnectionComplete(const BtmAclConnectCompleteParam *param, void *context); 582 583 /** 584 * @brief Acl disconnection complete callback. 585 * 586 * @param status Connection status. 587 * @param connectionHandle Connection handle. 588 * @param reason Disconnection reason. 589 * @param context Classic adapter object. 590 */ 591 static void DisconnectionComplete(uint8_t status, uint16_t connectionHandle, uint8_t reason, void *context); 592 593 /// SDP search remote device supported uuid callback. 594 /** 595 * @brief Service search attribute callback. 596 * 597 * @param addr Device address. 598 * @param serviceArray Service array. 599 * @param serviceNum Service number. 600 * @param context Classic adapter object. 601 */ 602 static void ServiceSearchAttributeCb( 603 const BtAddr *addr, const SdpService *serviceArray, uint16_t serviceNum, void *context); 604 605 /** 606 * @brief Handle inquiry event. 607 * 608 * @param event inquiry callback event. 609 * @param param Gap callback paramer. 610 */ 611 void HandleInquiryEvent(GAP_CB_EVENT event, const GapCallbackParam ¶m); 612 613 /** 614 * @brief Handle security event. 615 * 616 * @param event security callback event. 617 * @param param Gap callback paramer. 618 */ 619 void HandleSecurityEvent(GAP_CB_EVENT event, const GapCallbackParam ¶m); 620 621 /** 622 * @brief ClassicAdater start up. Load config file and enable stack. 623 * 624 */ 625 void StartUp(); 626 627 /** 628 * @brief ClassicAdater shut down. Save config file and disable stack. 629 * 630 */ 631 void ShutDown(); 632 633 /** 634 * @brief Process post enable. 635 * 636 */ 637 void ProcessPostEnable(); 638 639 /** 640 * @brief Set scan mode. 641 * 642 * @param mode Scan mode. 643 * @return Returns <b>true</b> if the operation is successful; 644 * returns <b>false</b> if the operation fails. 645 */ 646 bool SetScanMode(int mode); 647 648 /** 649 * @brief Set scan mode result callback. 650 * 651 * @param status Scan status. 652 * @param context ClassicAdapterProperties object. 653 */ 654 static void SetScanModeResultCallback(uint8_t status, void *context); 655 656 /** 657 * @brief Receive SetScanMode callback. 658 * 659 * @param status SetScanMode result. 660 */ 661 void ReceiveSetScanModeCallback(uint8_t status); 662 663 /** 664 * @brief ScanMode timeout. 665 * 666 */ 667 void ScanModeTimeout(); 668 669 /** 670 * @brief Hw(Controller) process timeout. 671 * 672 */ 673 void HwProcessTimeout(); 674 void HwTimeout(); 675 676 /** 677 * @brief Register callback. 678 * 679 */ 680 bool RegisterCallback(); 681 682 /** 683 * @brief Deregister callback. 684 * 685 */ 686 bool DeregisterCallback() const; 687 688 /** 689 * @brief Get remote device name. 690 * 691 * @param addr Device address. 692 * @return Returns <b>true</b> if the operation is successful; 693 * returns <b>false</b> if the operation fails. 694 */ 695 bool GetRemoteName(const BtAddr &addr) const; 696 697 /** 698 * @brief Set link key. 699 * 700 * @param addr Device address. 701 */ 702 void SetLinkKey(const BtAddr &addr); 703 704 /** 705 * @brief Set Io capability. 706 * 707 * @param addr Device address. 708 */ 709 void SetIoCapability(const BtAddr &addr); 710 711 /** 712 * @brief Parser eir data. 713 * 714 * @param remote Remote device. 715 * @param data Eir data. 716 */ 717 void ParserEirData(std::shared_ptr<ClassicRemoteDevice> remote, const std::vector<uint8_t> &data) const; 718 719 /** 720 * @brief Load paired device info from config file. 721 * 722 */ 723 void LoadPairedDeviceInfo(); 724 725 /** 726 * @brief Save paired devices info. 727 * 728 */ 729 void SavePairedDevices() const; 730 731 /** 732 * @brief Get service uuid from device uuid. 733 * 734 * @param uuid Device uuid. 735 * @return Returns service uuid. 736 */ 737 Uuid GetUuidFromBtUuid(const BtUuid &inUuid) const; 738 739 /** 740 * @brief Get local support uuids then update the uuids to EIR data. 741 * 742 */ 743 void UpdateSupportedUuids() const; 744 745 /** 746 * @brief Save remote device Io capability. 747 * 748 * @param addr Remote device address. 749 * @param ioCapability Device Io capability 750 */ 751 void SaveRemoteIoCapability(const BtAddr &addr, uint8_t ioCapability); 752 753 /** 754 * @brief Send scan mode changed. 755 * 756 * @param mode ScamMode. 757 */ 758 void SendScanModeChanged(int mode) const; 759 760 /** 761 * @brief Send discovery state changed. 762 * 763 */ 764 void SendDiscoveryStateChanged(int discoveryState) const; 765 766 /** 767 * @brief Send discovery result. 768 * 769 * @param device Remote device. 770 */ 771 void SendDiscoveryResult(const RawAddress &device) const; 772 773 /** 774 * @brief Send remote device cod changed. 775 * 776 * @param device Remote device. 777 * @param cod Remote device cod. 778 */ 779 void SendRemoteCodChanged(const RawAddress &device, int cod) const; 780 781 /** 782 * @brief Send remote device battery level changed. 783 * 784 * @param device Remote device. 785 * @param batteryLevel Remote device battery level. 786 */ 787 void SendRemoteBatteryLevelChanged(const RawAddress &device, int batteryLevel) const; 788 789 /** 790 * @brief Send remote device name changed. 791 * 792 * @param device Remote device. 793 * @param deviceName Remote device name. 794 */ 795 void SendRemoteNameChanged(const RawAddress &device, const std::string &deviceName) const; 796 797 /** 798 * @brief Send pair status changed. 799 * 800 * @param transport Remote device transport. 801 * @param device Remote device. 802 * @param status Pair status. 803 */ 804 void SendPairStatusChanged(const BTTransport transport, const RawAddress &device, int status) const; 805 806 /** 807 * @brief Send pair request. 808 * 809 * @param transport Remote device transport. 810 * @param device Remote device. 811 */ 812 void SendPairRequested(const BTTransport transport, const RawAddress &device) const; 813 814 /** 815 * @brief Send pair confirmed. 816 * 817 * @param device Remote device. 818 * @param reqType confirmed type (SSP/Pin Code). 819 * @param number confirmed number. 820 */ 821 void SendPairConfirmed(const RawAddress &device, int reqType, int number) const; 822 823 /** 824 * @brief Send remote device uuid changed. 825 * 826 * @param device Remote device. 827 * @param uuids Device uuid. 828 */ 829 void SendRemoteUuidChanged(const RawAddress &device, const std::vector<Uuid> &uuids) const; 830 831 /** 832 * @brief Send remote alias name changed. 833 * 834 * @param device Remote device. 835 * @param aliasName alias name. 836 */ 837 void SendRemoteAliasChanged(const RawAddress &device, const std::string &aliasName) const; 838 839 /** 840 * @brief Handle inquire result. 841 * 842 * @param addr Device address. 843 * @param classOfDevice Device class. 844 * @param rssi Device rssi. 845 * @param eir Eir data. 846 */ 847 void HandleInquiryResult(const BtAddr &addr, uint32_t classOfDevice, std::vector<uint8_t> eir, int8_t rssi = 0); 848 849 /** 850 * @brief Handle inquire complete. 851 * 852 * @param status Inquire status. 853 */ 854 void HandleInquiryComplete(uint8_t status); 855 856 /** 857 * @brief Receive remote device name. 858 * 859 * @param status Receive status. 860 * @param addr Remote device address. 861 * @param name Remote device name. 862 */ 863 void ReceiveRemoteName(uint8_t status, const BtAddr &addr, const uint8_t name[MAX_LOC_BT_NAME_LEN]); 864 865 /** 866 * @brief SSP confirm request. 867 * 868 * @param addr Remote device address. 869 * @param reqType Request type. 870 * @param number Pass key. 871 */ 872 void SSPConfirmReq(const BtAddr &addr, int reqType, int number, int localMitmRequired, int remoteMitmRequired); 873 874 /** 875 * @brief Set authorize response. 876 * 877 * @param addr Remote device address. 878 * @param service Gap service. 879 */ 880 void SetAuthorizeRes(const BtAddr &addr, GAP_Service service) const; 881 882 /** 883 * @brief Receive link key notification. 884 * 885 * @param addr Remote device address. 886 * @param linkKey Link key. 887 * @param keyType Link key type. 888 */ 889 void ReceiveLinkKeyNotification(const BtAddr &addr, const uint8_t linkKey[GAP_LINKKEY_SIZE], uint8_t keyType); 890 891 /** 892 * @brief Receive simple pair complete. 893 * 894 * @param addr Remote device address. 895 * @param status Pair status. 896 */ 897 void ReceiveSimplePairComplete(const BtAddr &addr, uint8_t status); 898 899 /** 900 * @brief Receive authentication complete. 901 * 902 * @param addr Remote device address. 903 * @param status Authentication status. 904 */ 905 void ReceiveAuthenticationComplete(const BtAddr &addr, uint8_t status); 906 907 /** 908 * @brief Receive encryption change. 909 * 910 * @param addr Remote device address. 911 * @param status Encryption status. 912 */ 913 void ReceiveEncryptionChange(const BtAddr &addr, uint8_t status); 914 915 /** 916 * @brief Receive acl connection complete. 917 * 918 * @param status Connection status. 919 * @param connectionHandle Connection handle. 920 * @param remoteAddr Device address. 921 * @param encyptionEnabled Encyption enable status. 922 */ 923 void ReceiveConnectionComplete(uint8_t status, uint16_t connectionHandle, const RawAddress &device, 924 uint32_t classOfDevice, bool encyptionEnabled); 925 926 /** 927 * @brief Receive acl disconnection complete. 928 * 929 * @param status Connection status. 930 * @param connectionHandle Connection handle. 931 * @param reason Disconnection reason. 932 */ 933 void ReceiveDisconnectionComplete(uint8_t status, uint16_t connectionHandle, uint8_t reason); 934 935 /** 936 * @brief User confirm auto reply. 937 * 938 * @param device Remote device. 939 * @param reqType Request type. 940 * @param accept Request accept or not. 941 */ 942 void UserConfirmAutoReply(const RawAddress &device, int reqType, bool accept) const; 943 944 /** 945 * @brief Set pin code. 946 * 947 * @param device Remote device. 948 * @param pin Pin code. 949 * @param accept Request accept or not. 950 * @return Returns <b>true</b> if the operation is successful; 951 * returns <b>false</b> if the operation fails. 952 */ 953 bool SetPinCode(const RawAddress &device, const std::vector<uint8_t> &pin, bool accept) const; 954 955 /** 956 * @brief Check if auto reply. 957 * 958 * @param remoteIo Remote device Io capability. 959 * @return Returns <b>true</b> if the operation is successful; 960 * returns <b>false</b> if the operation fails. 961 */ 962 bool CheckAutoReply(int remoteIo, int localMitmRequired, int remoteMitmRequired) const; 963 964 /** 965 * @brief Check ssp confirm type. 966 * 967 * @param remoteIo Remote device Io capability. 968 * @param type Confirm type. 969 * @return Returns confirm type. 970 */ 971 int CheckSspConfirmType(int remoteIo, int type) const; 972 973 /** 974 * @brief Find remote device. 975 * 976 * @param remoteAddr Remote device address. 977 * @return Returns remote device. 978 */ 979 std::shared_ptr<ClassicRemoteDevice> FindRemoteDevice(const RawAddress &device); 980 981 /** 982 * @brief Parser remote name from eir data. 983 * 984 * @param remote Remote device. 985 * @param type type of Eir data structure. 986 * @param value Eir data of Eir data structure. 987 * @return Returns <b>true</b> if the operation is successful; 988 * returns <b>false</b> if the operation fails. 989 */ 990 bool ParserRemoteNameFromEir( 991 std::shared_ptr<ClassicRemoteDevice> remote, int type, const std::vector<uint8_t> &value) const; 992 993 /** 994 * @brief Parser service uuid from eir data. 995 * 996 * @param type type of Eir data structure. 997 * @param value Eir data of Eir data structure. 998 * @return Returns uuids parser from eir data. 999 */ 1000 std::vector<Uuid> ParserUuidFromEir(int type, const std::vector<uint8_t> &value) const; 1001 1002 /** 1003 * @brief Parser 16 bit service uuid from eir data. 1004 * 1005 * @param value Eir data of Eir data structure. 1006 * @return Returns 16 Bit uuids parser from eir data. 1007 */ 1008 std::vector<Uuid> Parser16BitUuidFromEir(const std::vector<uint8_t> &value) const; 1009 1010 /** 1011 * @brief Parser 32 bit service uuid from eir data. 1012 * 1013 * @param value Eir data of Eir data structure. 1014 * @return Returns 32 Bit uuids parses from eir data. 1015 */ 1016 std::vector<Uuid> Parser32BitUuidFromEir(const std::vector<uint8_t> &value) const; 1017 1018 /** 1019 * @brief Parser 128 bit service uuid from eir data. 1020 * 1021 * @param value Eir data of Eir data structure. 1022 * @return Returns 128 Bit uuids parser from eir data. 1023 */ 1024 std::vector<Uuid> Parser128BitUuidFromEir(const std::vector<uint8_t> &value) const; 1025 1026 /** 1027 * @brief Save remote device uuids. 1028 * If uuids is changed, send OnRemoteUuidChanged to client. 1029 * 1030 * @param remote Remote device. 1031 * @param uuids Remote device uuids. 1032 */ 1033 void SaveRemoteDeviceUuids(std::shared_ptr<ClassicRemoteDevice> remote, const std::vector<Uuid> &uuids) const; 1034 1035 /** 1036 * @brief Check uuids1 is equal with uuids2. 1037 * 1038 * @param uuids1 uuids. 1039 * @param uuids2 uuids. 1040 * @return Returns <b>true</b> if the operation is successful; 1041 * returns <b>false</b> if the operation fails. 1042 */ 1043 bool IsUuidsEqual(const std::vector<Uuid> &uuids1, const std::vector<Uuid> &uuids2) const; 1044 1045 void InitMode(); 1046 void FreeMemory(); 1047 void DisableBTM(); 1048 bool DiscoverRemoteName(); 1049 bool CancelGetRemoteName() const; 1050 void SearchRemoteUuids(const RawAddress &device, uint16_t uuid); 1051 void ResetScanMode(); 1052 void DeleteLinkKey(std::shared_ptr<ClassicRemoteDevice> remoteDevice) const; 1053 BtAddr ConvertToBtAddr(const RawAddress &device) const; 1054 void DisablePairProcess(); 1055 void SearchAttributeEnd(const RawAddress &device, const std::vector<Uuid> &uuids); 1056 void PinCodeReq(const BtAddr &addr); 1057 ClassicAdapterProperties &adapterProperties_; 1058 std::unique_ptr<utility::Timer> timer_ {}; 1059 std::unique_ptr<utility::Timer> hwTimer_ {}; 1060 int discoveryState_ {}; 1061 int scanMode_ {}; 1062 long discoveryEndMs_ {}; 1063 bool pinMode_ {}; 1064 bool btmEnableSuccess_ {}; 1065 bool isDisable_ {}; 1066 bool receiveInquiryComplete_ {}; 1067 bool cancelDiscovery_ {}; 1068 bool waitPairResult_ {}; 1069 uint16_t searchUuid_ {}; 1070 std::vector<Uuid> uuids_ {}; 1071 std::string remoteNameAddr_ {INVALID_MAC_ADDRESS}; 1072 std::map<std::string, std::shared_ptr<ClassicRemoteDevice>> devices_ {}; 1073 BtmAclCallbacks btmAclCbs_ {}; 1074 ClassicBluetoothData eirData_ {}; 1075 std::unique_ptr<ClassicBatteryObserverHf> batteryObserverHf_ {}; 1076 IProfileHfpHf *hfService_ {nullptr}; 1077 std::unique_ptr<ClassicBatteryObserverAg> batteryObserverAg_ {}; 1078 IProfileHfpAg *agService_ {nullptr}; 1079 1080 DECLARE_IMPL(); 1081 BT_DISALLOW_COPY_AND_ASSIGN(ClassicAdapter); 1082 }; 1083 } // namespace bluetooth 1084 } // namespace OHOS 1085 #endif // CLASSIC_ADAPTER_H