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 406 private: 407 /** 408 * @brief Inquiry result callback. 409 * 410 * @param addr Device address. 411 * @param classOfDevice Device class. 412 * @param context Classic adapter object. 413 */ 414 static void InquiryResultCallback(const BtAddr *addr, uint32_t classOfDevice, void *context); 415 416 /** 417 * @brief Inquiry result rssi callback. 418 * 419 * @param addr Device address. 420 * @param classOfDevice Device class. 421 * @param rssi Device rssi. 422 * @param context Classic adapter object. 423 */ 424 static void InquiryResultRssiCallback(const BtAddr *addr, uint32_t classOfDevice, int8_t rssi, void *context); 425 426 /** 427 * @brief Extended inquiry result callback. 428 * 429 * @param addr Device address. 430 * @param classOfDevice Device class. 431 * @param rssi Device rssi. 432 * @param eir Eir data. 433 * @param context Classic adapter object. 434 */ 435 static void ExtendedInquiryResultCallback(const BtAddr *addr, uint32_t classOfDevice, int8_t rssi, 436 const uint8_t eir[MAX_EXTEND_INQUIRY_RESPONSE_LEN], void *context); 437 438 /** 439 * @brief Inquiry complete callback. 440 * 441 * @param status Inquire status. 442 * @param context Classic adapter object. 443 */ 444 static void InquiryCompleteCallback(uint8_t status, void *context); 445 446 /** 447 * @brief Remote device name callback. 448 * 449 * @param status Inquire status. 450 * @param addr Device address. 451 * @param name Device name. 452 * @param context Classic adapter object. 453 */ 454 static void RemoteNameCallback( 455 uint8_t status, const BtAddr *addr, const uint8_t name[MAX_LOC_BT_NAME_LEN], void *context); 456 /** 457 * @brief User confirm request callback. 458 * 459 * @param addr Device address. 460 * @param number Pass key. 461 * @param context Classic adapter object. 462 */ 463 static void UserConfirmReqCallback(const BtAddr *addr, uint32_t number, void *context); 464 465 /** 466 * @brief User pass key request callback. 467 * 468 * @param addr Device address. 469 * @param context Classic adapter object. 470 */ 471 static void UserPasskeyReqCallback(const BtAddr *addr, void *context); 472 473 /** 474 * @brief User pass key notification callback. 475 * 476 * @param addr Device address. 477 * @param number Pass key. 478 * @param context Classic adapter object. 479 */ 480 static void UserPasskeyNotificationCallback(const BtAddr *addr, uint32_t number, void *context); 481 482 /** 483 * @brief Remote oob key request callback. 484 * 485 * @param addr Device address. 486 * @param context Classic adapter object. 487 */ 488 static void RemoteOobReqCallback(const BtAddr *addr, void *context); 489 490 /** 491 * @brief Pin code request callback. 492 * 493 * @param addr Device address. 494 * @param context Classic adapter object. 495 */ 496 static void PinCodeReqCallback(const BtAddr *addr, void *context); 497 498 /** 499 * @brief Link key request callback. 500 * 501 * @param addr Device address. 502 * @param context Classic adapter object. 503 */ 504 static void LinkKeyReqCallback(const BtAddr *addr, void *context); 505 506 /** 507 * @brief Io capability request callback. 508 * 509 * @param addr Device address. 510 * @param context Classic adapter object. 511 */ 512 static void IoCapabilityReqCallback(const BtAddr *addr, void *context); 513 514 /** 515 * @brief Io capability response callback. 516 * 517 * @param addr Device address. 518 * @param ioCapability Device iocapability. 519 * @param context Classic adapter object. 520 */ 521 static void IoCapabilityRspCallback(const BtAddr *addr, uint8_t ioCapability, void *context); 522 523 /** 524 * @brief Link key notification. 525 * 526 * @param addr Device address. 527 * @param linkkey Link key. 528 * @param keyType Link key type. 529 * @param context Classic adapter object. 530 */ 531 static void LinkKeyNotification( 532 const BtAddr *addr, const uint8_t linkKey[GAP_LINKKEY_SIZE], uint8_t keyType, void *context); 533 534 /** 535 * @brief Simple pair complete callback. 536 * 537 * @param addr Device address. 538 * @param status Pair status. 539 * @param context Classic adapter object. 540 */ 541 static void SimplePairCompleteCallback(const BtAddr *addr, uint8_t status, void *context); 542 543 /** 544 * @brief Authentication complete callback. 545 * 546 * @param addr Device address. 547 * @param status Authentication status. 548 * @param context Classic adapter object. 549 */ 550 static void AuthenticationCompleteCallback(const BtAddr *addr, uint8_t status, void *context); 551 552 /** 553 * @brief Encryption change complete callback. 554 * 555 * @param addr Device address. 556 * @param status Encryption status. 557 * @param context Classic adapter object. 558 */ 559 static void EncryptionChangeCallback(const BtAddr *addr, uint8_t status, void *context); 560 561 /** 562 * @brief Authorize ind callback. 563 * 564 * @param addr Device address. 565 * @param service Gap service. 566 * @param context Classic adapter object. 567 */ 568 static void AuthorizeIndCallback(const BtAddr *addr, GAP_Service service, void *context); 569 570 /// BTM ACL Change status callback. 571 /** 572 * @brief Acl connection complete callback. 573 * 574 * @param status Connection status. 575 * @param connectionHandle Connection handle. 576 * @param addr Device address. 577 * @param encyptionEnabled Encyption enable status. 578 * @param context Classic adapter object. 579 */ 580 static void ConnectionComplete(const BtmAclConnectCompleteParam *param, void *context); 581 582 /** 583 * @brief Acl disconnection complete callback. 584 * 585 * @param status Connection status. 586 * @param connectionHandle Connection handle. 587 * @param reason Disconnection reason. 588 * @param context Classic adapter object. 589 */ 590 static void DisconnectionComplete(uint8_t status, uint16_t connectionHandle, uint8_t reason, void *context); 591 592 /// SDP search remote device supported uuid callback. 593 /** 594 * @brief Service search attribute callback. 595 * 596 * @param addr Device address. 597 * @param serviceArray Service array. 598 * @param serviceNum Service number. 599 * @param context Classic adapter object. 600 */ 601 static void ServiceSearchAttributeCb( 602 const BtAddr *addr, const SdpService *serviceArray, uint16_t serviceNum, void *context); 603 604 /** 605 * @brief Handle inquiry event. 606 * 607 * @param event inquiry callback event. 608 * @param param Gap callback paramer. 609 */ 610 void HandleInquiryEvent(GAP_CB_EVENT event, const GapCallbackParam ¶m); 611 612 /** 613 * @brief Handle security event. 614 * 615 * @param event security callback event. 616 * @param param Gap callback paramer. 617 */ 618 void HandleSecurityEvent(GAP_CB_EVENT event, const GapCallbackParam ¶m); 619 620 /** 621 * @brief ClassicAdater start up. Load config file and enable stack. 622 * 623 */ 624 void StartUp(); 625 626 /** 627 * @brief ClassicAdater shut down. Save config file and disable stack. 628 * 629 */ 630 void ShutDown(); 631 632 /** 633 * @brief Process post enable. 634 * 635 */ 636 void ProcessPostEnable(); 637 638 /** 639 * @brief Set scan mode. 640 * 641 * @param mode Scan mode. 642 * @return Returns <b>true</b> if the operation is successful; 643 * returns <b>false</b> if the operation fails. 644 */ 645 bool SetScanMode(int mode); 646 647 /** 648 * @brief Set scan mode result callback. 649 * 650 * @param status Scan status. 651 * @param context ClassicAdapterProperties object. 652 */ 653 static void SetScanModeResultCallback(uint8_t status, void *context); 654 655 /** 656 * @brief Receive SetScanMode callback. 657 * 658 * @param status SetScanMode result. 659 */ 660 void ReceiveSetScanModeCallback(uint8_t status); 661 662 /** 663 * @brief ScanMode timeout. 664 * 665 */ 666 void ScanModeTimeout(); 667 668 /** 669 * @brief Hw(Controller) process timeout. 670 * 671 */ 672 void HwProcessTimeout(); 673 void HwTimeout(); 674 675 /** 676 * @brief Register callback. 677 * 678 */ 679 bool RegisterCallback(); 680 681 /** 682 * @brief Deregister callback. 683 * 684 */ 685 bool DeregisterCallback() const; 686 687 /** 688 * @brief Get remote device name. 689 * 690 * @param addr Device address. 691 * @return Returns <b>true</b> if the operation is successful; 692 * returns <b>false</b> if the operation fails. 693 */ 694 bool GetRemoteName(const BtAddr &addr) const; 695 696 /** 697 * @brief Set link key. 698 * 699 * @param addr Device address. 700 */ 701 void SetLinkKey(const BtAddr &addr); 702 703 /** 704 * @brief Set Io capability. 705 * 706 * @param addr Device address. 707 */ 708 void SetIoCapability(const BtAddr &addr); 709 710 /** 711 * @brief Parser eir data. 712 * 713 * @param remote Remote device. 714 * @param data Eir data. 715 */ 716 void ParserEirData(std::shared_ptr<ClassicRemoteDevice> remote, const std::vector<uint8_t> &data) const; 717 718 /** 719 * @brief Load paired device info from config file. 720 * 721 */ 722 void LoadPairedDeviceInfo(); 723 724 /** 725 * @brief Save paired devices info. 726 * 727 */ 728 void SavePairedDevices() const; 729 730 /** 731 * @brief Get service uuid from device uuid. 732 * 733 * @param uuid Device uuid. 734 * @return Returns service uuid. 735 */ 736 Uuid GetUuidFromBtUuid(const BtUuid &inUuid) const; 737 738 /** 739 * @brief Get local support uuids then update the uuids to EIR data. 740 * 741 */ 742 void UpdateSupportedUuids() const; 743 744 /** 745 * @brief Save remote device Io capability. 746 * 747 * @param addr Remote device address. 748 * @param ioCapability Device Io capability 749 */ 750 void SaveRemoteIoCapability(const BtAddr &addr, uint8_t ioCapability); 751 752 /** 753 * @brief Send scan mode changed. 754 * 755 * @param mode ScamMode. 756 */ 757 void SendScanModeChanged(int mode) const; 758 759 /** 760 * @brief Send discovery state changed. 761 * 762 */ 763 void SendDiscoveryStateChanged(int discoveryState) const; 764 765 /** 766 * @brief Send discovery result. 767 * 768 * @param device Remote device. 769 */ 770 void SendDiscoveryResult(const RawAddress &device) const; 771 772 /** 773 * @brief Send remote device cod changed. 774 * 775 * @param device Remote device. 776 * @param cod Remote device cod. 777 */ 778 void SendRemoteCodChanged(const RawAddress &device, int cod) const; 779 780 /** 781 * @brief Send remote device battery level changed. 782 * 783 * @param device Remote device. 784 * @param batteryLevel Remote device battery level. 785 */ 786 void SendRemoteBatteryLevelChanged(const RawAddress &device, int batteryLevel) const; 787 788 /** 789 * @brief Send remote device name changed. 790 * 791 * @param device Remote device. 792 * @param deviceName Remote device name. 793 */ 794 void SendRemoteNameChanged(const RawAddress &device, const std::string &deviceName) const; 795 796 /** 797 * @brief Send pair status changed. 798 * 799 * @param transport Remote device transport. 800 * @param device Remote device. 801 * @param status Pair status. 802 */ 803 void SendPairStatusChanged(const BTTransport transport, const RawAddress &device, int status) const; 804 805 /** 806 * @brief Send pair request. 807 * 808 * @param transport Remote device transport. 809 * @param device Remote device. 810 */ 811 void SendPairRequested(const BTTransport transport, const RawAddress &device) const; 812 813 /** 814 * @brief Send pair confirmed. 815 * 816 * @param device Remote device. 817 * @param reqType confirmed type (SSP/Pin Code). 818 * @param number confirmed number. 819 */ 820 void SendPairConfirmed(const RawAddress &device, int reqType, int number) const; 821 822 /** 823 * @brief Send remote device uuid changed. 824 * 825 * @param device Remote device. 826 * @param uuids Device uuid. 827 */ 828 void SendRemoteUuidChanged(const RawAddress &device, const std::vector<Uuid> &uuids) const; 829 830 /** 831 * @brief Send remote alias name changed. 832 * 833 * @param device Remote device. 834 * @param aliasName alias name. 835 */ 836 void SendRemoteAliasChanged(const RawAddress &device, const std::string &aliasName) const; 837 838 /** 839 * @brief Handle inquire result. 840 * 841 * @param addr Device address. 842 * @param classOfDevice Device class. 843 * @param rssi Device rssi. 844 * @param eir Eir data. 845 */ 846 void HandleInquiryResult(const BtAddr &addr, uint32_t classOfDevice, std::vector<uint8_t> eir, int8_t rssi = 0); 847 848 /** 849 * @brief Handle inquire complete. 850 * 851 * @param status Inquire status. 852 */ 853 void HandleInquiryComplete(uint8_t status); 854 855 /** 856 * @brief Receive remote device name. 857 * 858 * @param status Receive status. 859 * @param addr Remote device address. 860 * @param name Remote device name. 861 */ 862 void ReceiveRemoteName(uint8_t status, const BtAddr &addr, const uint8_t name[MAX_LOC_BT_NAME_LEN]); 863 864 /** 865 * @brief SSP confirm request. 866 * 867 * @param addr Remote device address. 868 * @param reqType Request type. 869 * @param number Pass key. 870 */ 871 void SSPConfirmReq(const BtAddr &addr, int reqType, int number); 872 873 /** 874 * @brief Set authorize response. 875 * 876 * @param addr Remote device address. 877 * @param service Gap service. 878 */ 879 void SetAuthorizeRes(const BtAddr &addr, GAP_Service service) const; 880 881 /** 882 * @brief Receive link key notification. 883 * 884 * @param addr Remote device address. 885 * @param linkKey Link key. 886 * @param keyType Link key type. 887 */ 888 void ReceiveLinkKeyNotification(const BtAddr &addr, const uint8_t linkKey[GAP_LINKKEY_SIZE], uint8_t keyType); 889 890 /** 891 * @brief Receive simple pair complete. 892 * 893 * @param addr Remote device address. 894 * @param status Pair status. 895 */ 896 void ReceiveSimplePairComplete(const BtAddr &addr, uint8_t status); 897 898 /** 899 * @brief Receive authentication complete. 900 * 901 * @param addr Remote device address. 902 * @param status Authentication status. 903 */ 904 void ReceiveAuthenticationComplete(const BtAddr &addr, uint8_t status); 905 906 /** 907 * @brief Receive encryption change. 908 * 909 * @param addr Remote device address. 910 * @param status Encryption status. 911 */ 912 void ReceiveEncryptionChange(const BtAddr &addr, uint8_t status); 913 914 /** 915 * @brief Receive acl connection complete. 916 * 917 * @param status Connection status. 918 * @param connectionHandle Connection handle. 919 * @param remoteAddr Device address. 920 * @param encyptionEnabled Encyption enable status. 921 */ 922 void ReceiveConnectionComplete(uint8_t status, uint16_t connectionHandle, const RawAddress &device, 923 uint32_t classOfDevice, bool encyptionEnabled); 924 925 /** 926 * @brief Receive acl disconnection complete. 927 * 928 * @param status Connection status. 929 * @param connectionHandle Connection handle. 930 * @param reason Disconnection reason. 931 */ 932 void ReceiveDisconnectionComplete(uint8_t status, uint16_t connectionHandle, uint8_t reason); 933 934 /** 935 * @brief User confirm auto reply. 936 * 937 * @param device Remote device. 938 * @param reqType Request type. 939 * @param accept Request accept or not. 940 */ 941 void UserConfirmAutoReply(const RawAddress &device, int reqType, bool accept) const; 942 943 /** 944 * @brief Set pin code. 945 * 946 * @param device Remote device. 947 * @param pin Pin code. 948 * @param accept Request accept or not. 949 * @return Returns <b>true</b> if the operation is successful; 950 * returns <b>false</b> if the operation fails. 951 */ 952 bool SetPinCode(const RawAddress &device, const std::vector<uint8_t> &pin, bool accept) const; 953 954 /** 955 * @brief Check if auto reply. 956 * 957 * @param remoteIo Remote device Io capability. 958 * @return Returns <b>true</b> if the operation is successful; 959 * returns <b>false</b> if the operation fails. 960 */ 961 bool CheckAutoReply(int remoteIo) const; 962 963 /** 964 * @brief Check ssp confirm type. 965 * 966 * @param remoteIo Remote device Io capability. 967 * @param type Confirm type. 968 * @return Returns confirm type. 969 */ 970 int CheckSspConfirmType(int remoteIo, int type) const; 971 972 /** 973 * @brief Find remote device. 974 * 975 * @param remoteAddr Remote device address. 976 * @return Returns remote device. 977 */ 978 std::shared_ptr<ClassicRemoteDevice> FindRemoteDevice(const RawAddress &device); 979 980 /** 981 * @brief Parser remote name from eir data. 982 * 983 * @param remote Remote device. 984 * @param type type of Eir data structure. 985 * @param value Eir data of Eir data structure. 986 * @return Returns <b>true</b> if the operation is successful; 987 * returns <b>false</b> if the operation fails. 988 */ 989 bool ParserRemoteNameFromEir( 990 std::shared_ptr<ClassicRemoteDevice> remote, int type, const std::vector<uint8_t> &value) const; 991 992 /** 993 * @brief Parser service uuid from eir data. 994 * 995 * @param type type of Eir data structure. 996 * @param value Eir data of Eir data structure. 997 * @return Returns uuids parser from eir data. 998 */ 999 std::vector<Uuid> ParserUuidFromEir(int type, const std::vector<uint8_t> &value) const; 1000 1001 /** 1002 * @brief Parser 16 bit service uuid from eir data. 1003 * 1004 * @param value Eir data of Eir data structure. 1005 * @return Returns 16 Bit uuids parser from eir data. 1006 */ 1007 std::vector<Uuid> Parser16BitUuidFromEir(const std::vector<uint8_t> &value) const; 1008 1009 /** 1010 * @brief Parser 32 bit service uuid from eir data. 1011 * 1012 * @param value Eir data of Eir data structure. 1013 * @return Returns 32 Bit uuids parses from eir data. 1014 */ 1015 std::vector<Uuid> Parser32BitUuidFromEir(const std::vector<uint8_t> &value) const; 1016 1017 /** 1018 * @brief Parser 128 bit service uuid from eir data. 1019 * 1020 * @param value Eir data of Eir data structure. 1021 * @return Returns 128 Bit uuids parser from eir data. 1022 */ 1023 std::vector<Uuid> Parser128BitUuidFromEir(const std::vector<uint8_t> &value) const; 1024 1025 /** 1026 * @brief Save remote device uuids. 1027 * If uuids is changed, send OnRemoteUuidChanged to client. 1028 * 1029 * @param remote Remote device. 1030 * @param uuids Remote device uuids. 1031 */ 1032 void SaveRemoteDeviceUuids(std::shared_ptr<ClassicRemoteDevice> remote, const std::vector<Uuid> &uuids) const; 1033 1034 /** 1035 * @brief Check uuids1 is equal with uuids2. 1036 * 1037 * @param uuids1 uuids. 1038 * @param uuids2 uuids. 1039 * @return Returns <b>true</b> if the operation is successful; 1040 * returns <b>false</b> if the operation fails. 1041 */ 1042 bool IsUuidsEqual(const std::vector<Uuid> &uuids1, const std::vector<Uuid> &uuids2) const; 1043 1044 void InitMode(); 1045 void FreeMemory(); 1046 void DisableBTM(); 1047 bool DiscoverRemoteName(); 1048 bool CancelGetRemoteName() const; 1049 void SearchRemoteUuids(const RawAddress &device, uint16_t uuid); 1050 void ResetScanMode(); 1051 void DeleteLinkKey(std::shared_ptr<ClassicRemoteDevice> remoteDevice) const; 1052 BtAddr ConvertToBtAddr(const RawAddress &device) const; 1053 void DisablePairProcess(); 1054 void SearchAttributeEnd(const RawAddress &device, const std::vector<Uuid> &uuids); 1055 void PinCodeReq(const BtAddr &addr); 1056 ClassicAdapterProperties &adapterProperties_; 1057 std::unique_ptr<utility::Timer> timer_ {}; 1058 std::unique_ptr<utility::Timer> hwTimer_ {}; 1059 int discoveryState_ {}; 1060 int scanMode_ {}; 1061 long discoveryEndMs_ {}; 1062 bool pinMode_ {}; 1063 bool btmEnableSuccess_ {}; 1064 bool isDisable_ {}; 1065 bool receiveInquiryComplete_ {}; 1066 bool cancelDiscovery_ {}; 1067 bool waitPairResult_ {}; 1068 uint16_t searchUuid_ {}; 1069 std::vector<Uuid> uuids_ {}; 1070 std::string remoteNameAddr_ {INVALID_MAC_ADDRESS}; 1071 std::map<std::string, std::shared_ptr<ClassicRemoteDevice>> devices_ {}; 1072 BtmAclCallbacks btmAclCbs_ {}; 1073 ClassicBluetoothData eirData_ {}; 1074 std::unique_ptr<ClassicBatteryObserverHf> batteryObserverHf_ {}; 1075 IProfileHfpHf *hfService_ {nullptr}; 1076 std::unique_ptr<ClassicBatteryObserverAg> batteryObserverAg_ {}; 1077 IProfileHfpAg *agService_ {nullptr}; 1078 1079 DECLARE_IMPL(); 1080 BT_DISALLOW_COPY_AND_ASSIGN(ClassicAdapter); 1081 }; 1082 } // namespace bluetooth 1083 } // namespace OHOS 1084 #endif // CLASSIC_ADAPTER_H