1 /* 2 * Copyright 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdint> 20 #include <memory> 21 #include <string> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "acl_packet.h" 26 #include "async_manager.h" 27 #include "base/json/json_value_converter.h" 28 #include "base/time/time.h" 29 #include "bt_address.h" 30 31 namespace test_vendor_lib { 32 33 // Emulates a dual mode BR/EDR + LE controller by maintaining the link layer 34 // state machine detailed in the Bluetooth Core Specification Version 4.2, 35 // Volume 6, Part B, Section 1.1 (page 30). Provides methods corresponding to 36 // commands sent by the HCI. These methods will be registered as callbacks from 37 // a controller instance with the HciHandler. To implement a new Bluetooth 38 // command, simply add the method declaration below, with return type void and a 39 // single const std::vector<uint8_t>& argument. After implementing the 40 // method, simply register it with the HciHandler using the SET_HANDLER macro in 41 // the controller's default constructor. Be sure to name your method after the 42 // corresponding Bluetooth command in the Core Specification with the prefix 43 // "Hci" to distinguish it as a controller command. 44 class DeviceProperties { 45 public: 46 explicit DeviceProperties(const std::string& file_name); 47 48 // Access private configuration data 49 50 // Specification Version 4.2, Volume 2, Part E, Section 7.4.1 51 const std::vector<uint8_t>& GetLocalVersionInformation() const; 52 53 // Specification Version 4.2, Volume 2, Part E, Section 7.4.2 GetLocalSupportedCommands()54 const std::vector<uint8_t>& GetLocalSupportedCommands() const { 55 return local_supported_commands_; 56 } 57 58 // Specification Version 4.2, Volume 2, Part E, Section 7.4.3 GetLocalSupportedFeatures()59 uint64_t GetLocalSupportedFeatures() const { 60 return local_extended_features_[0]; 61 }; 62 63 // Specification Version 4.2, Volume 2, Part E, Section 7.4.4 GetLocalExtendedFeaturesMaximumPageNumber()64 uint8_t GetLocalExtendedFeaturesMaximumPageNumber() const { 65 return local_extended_features_.size() - 1; 66 }; 67 GetLocalExtendedFeatures(uint8_t page_number)68 uint64_t GetLocalExtendedFeatures(uint8_t page_number) const { 69 CHECK(page_number < local_extended_features_.size()); 70 return local_extended_features_[page_number]; 71 }; 72 73 // Specification Version 4.2, Volume 2, Part E, Section 7.4.5 GetAclDataPacketSize()74 uint16_t GetAclDataPacketSize() const { return acl_data_packet_size_; } 75 GetSynchronousDataPacketSize()76 uint8_t GetSynchronousDataPacketSize() const { return sco_data_packet_size_; } 77 GetTotalNumAclDataPackets()78 uint16_t GetTotalNumAclDataPackets() const { return num_acl_data_packets_; } 79 GetTotalNumSynchronousDataPackets()80 uint16_t GetTotalNumSynchronousDataPackets() const { 81 return num_sco_data_packets_; 82 } 83 GetAddress()84 const BtAddress& GetAddress() const { return address_; } 85 86 // Specification Version 4.2, Volume 2, Part E, Section 7.4.8 GetSupportedCodecs()87 const std::vector<uint8_t>& GetSupportedCodecs() const { 88 return supported_codecs_; 89 } 90 GetVendorSpecificCodecs()91 const std::vector<uint32_t>& GetVendorSpecificCodecs() const { 92 return vendor_specific_codecs_; 93 } 94 GetLocalName()95 const std::string& GetLocalName() const { return local_name_; } 96 GetVersion()97 uint8_t GetVersion() const { return version_; } 98 GetRevision()99 uint16_t GetRevision() const { return revision_; } 100 GetLmpPalVersion()101 uint8_t GetLmpPalVersion() const { return lmp_pal_version_; } 102 GetLmpPalSubversion()103 uint16_t GetLmpPalSubversion() const { return lmp_pal_subversion_; } 104 GetManufacturerName()105 uint16_t GetManufacturerName() const { return manufacturer_name_; } 106 107 // Specification Version 4.2, Volume 2, Part E, Section 7.8.2 GetLeDataPacketLength()108 uint16_t GetLeDataPacketLength() const { return le_data_packet_length_; } 109 GetTotalNumLeDataPackets()110 uint8_t GetTotalNumLeDataPackets() const { return num_le_data_packets_; } 111 112 // Specification Version 4.2, Volume 2, Part E, Section 7.8.3 GetLeLocalSupportedFeatures()113 uint64_t GetLeLocalSupportedFeatures() const { 114 return le_supported_features_; 115 } 116 117 // Specification Version 4.2, Volume 2, Part E, Section 7.8.14 GetLeWhiteListSize()118 uint8_t GetLeWhiteListSize() const { return le_white_list_size_; } 119 120 // Specification Version 4.2, Volume 2, Part E, Section 7.8.27 GetLeSupportedStates()121 uint64_t GetLeSupportedStates() const { return le_supported_states_; } 122 123 // Vendor-specific commands (see hcidefs.h) GetLeVendorCap()124 const std::vector<uint8_t>& GetLeVendorCap() const { return le_vendor_cap_; } 125 126 static void RegisterJSONConverter( 127 base::JSONValueConverter<DeviceProperties>* converter); 128 129 private: 130 uint16_t acl_data_packet_size_; 131 uint8_t sco_data_packet_size_; 132 uint16_t num_acl_data_packets_; 133 uint16_t num_sco_data_packets_; 134 uint8_t version_; 135 uint16_t revision_; 136 uint8_t lmp_pal_version_; 137 uint16_t manufacturer_name_; 138 uint16_t lmp_pal_subversion_; 139 std::vector<uint8_t> supported_codecs_; 140 std::vector<uint32_t> vendor_specific_codecs_; 141 std::vector<uint8_t> local_supported_commands_; 142 std::string local_name_; 143 std::vector<uint64_t> local_extended_features_; 144 BtAddress address_; 145 146 uint16_t le_data_packet_length_; 147 uint8_t num_le_data_packets_; 148 uint8_t le_white_list_size_; 149 uint64_t le_supported_features_; 150 uint64_t le_supported_states_; 151 std::vector<uint8_t> le_vendor_cap_; 152 }; 153 154 } // namespace test_vendor_lib 155