• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
21 #include <vector>
22 
23 #include "base/json/json_value_converter.h"
24 #include "types/address.h"
25 #include "types/class_of_device.h"
26 
27 namespace test_vendor_lib {
28 
29 class DeviceProperties {
30  public:
31   explicit DeviceProperties(const std::string& file_name = "");
32 
33   // Access private configuration data
34 
35   // Specification Version 4.2, Volume 2, Part E, Section 7.4.1
36   const std::vector<uint8_t>& GetVersionInformation() const;
37 
38   // Specification Version 4.2, Volume 2, Part E, Section 7.4.2
GetSupportedCommands()39   const std::vector<uint8_t>& GetSupportedCommands() const {
40     return supported_commands_;
41   }
42 
43   // Specification Version 4.2, Volume 2, Part E, Section 7.4.3
GetSupportedFeatures()44   uint64_t GetSupportedFeatures() const {
45     return extended_features_[0];
46   }
47 
SetSupportedFeatures(uint64_t features)48   void SetSupportedFeatures(uint64_t features) {
49     extended_features_[0] = features;
50   }
51 
52   // Specification Version 4.2, Volume 2, Part E, Section 7.4.4
GetExtendedFeaturesMaximumPageNumber()53   uint8_t GetExtendedFeaturesMaximumPageNumber() const {
54     return extended_features_.size() - 1;
55   }
56 
GetExtendedFeatures(uint8_t page_number)57   uint64_t GetExtendedFeatures(uint8_t page_number) const {
58     CHECK(page_number < extended_features_.size());
59     return extended_features_[page_number];
60   }
61 
62   // Specification Version 4.2, Volume 2, Part E, Section 7.4.5
GetAclDataPacketSize()63   uint16_t GetAclDataPacketSize() const {
64     return acl_data_packet_size_;
65   }
66 
GetSynchronousDataPacketSize()67   uint8_t GetSynchronousDataPacketSize() const {
68     return sco_data_packet_size_;
69   }
70 
GetTotalNumAclDataPackets()71   uint16_t GetTotalNumAclDataPackets() const {
72     return num_acl_data_packets_;
73   }
74 
GetTotalNumSynchronousDataPackets()75   uint16_t GetTotalNumSynchronousDataPackets() const {
76     return num_sco_data_packets_;
77   }
78 
GetAddress()79   const Address& GetAddress() const {
80     return address_;
81   }
82 
SetAddress(const Address & address)83   void SetAddress(const Address& address) {
84     address_ = address;
85   }
86 
87   // Specification Version 4.2, Volume 2, Part E, Section 7.4.8
GetSupportedCodecs()88   const std::vector<uint8_t>& GetSupportedCodecs() const {
89     return supported_codecs_;
90   }
91 
GetVendorSpecificCodecs()92   const std::vector<uint32_t>& GetVendorSpecificCodecs() const {
93     return vendor_specific_codecs_;
94   }
95 
GetVersion()96   uint8_t GetVersion() const {
97     return version_;
98   }
99 
GetRevision()100   uint16_t GetRevision() const {
101     return revision_;
102   }
103 
GetLmpPalVersion()104   uint8_t GetLmpPalVersion() const {
105     return lmp_pal_version_;
106   }
107 
GetLmpPalSubversion()108   uint16_t GetLmpPalSubversion() const {
109     return lmp_pal_subversion_;
110   }
111 
GetManufacturerName()112   uint16_t GetManufacturerName() const {
113     return manufacturer_name_;
114   }
115 
GetAuthenticationEnable()116   uint8_t GetAuthenticationEnable() const {
117     return authentication_enable_;
118   }
119 
SetAuthenticationEnable(uint8_t enable)120   void SetAuthenticationEnable(uint8_t enable) {
121     authentication_enable_ = enable;
122   }
123 
GetClassOfDevice()124   ClassOfDevice GetClassOfDevice() const {
125     return class_of_device_;
126   }
127 
SetClassOfDevice(uint8_t b0,uint8_t b1,uint8_t b2)128   void SetClassOfDevice(uint8_t b0, uint8_t b1, uint8_t b2) {
129     class_of_device_.cod[0] = b0;
130     class_of_device_.cod[1] = b1;
131     class_of_device_.cod[2] = b2;
132   }
133 
SetClassOfDevice(uint32_t class_of_device)134   void SetClassOfDevice(uint32_t class_of_device) {
135     class_of_device_.cod[0] = class_of_device & 0xff;
136     class_of_device_.cod[1] = (class_of_device >> 8) & 0xff;
137     class_of_device_.cod[2] = (class_of_device >> 16) & 0xff;
138   }
139 
SetName(const std::vector<uint8_t> & name)140   void SetName(const std::vector<uint8_t>& name) {
141     name_ = name;
142   }
143 
GetName()144   const std::vector<uint8_t>& GetName() const {
145     return name_;
146   }
147 
SetExtendedInquiryData(const std::vector<uint8_t> & eid)148   void SetExtendedInquiryData(const std::vector<uint8_t>& eid) {
149     extended_inquiry_data_ = eid;
150   }
151 
GetExtendedInquiryData()152   const std::vector<uint8_t>& GetExtendedInquiryData() const {
153     return extended_inquiry_data_;
154   }
155 
GetPageScanRepetitionMode()156   uint8_t GetPageScanRepetitionMode() const {
157     return page_scan_repetition_mode_;
158   }
159 
SetPageScanRepetitionMode(uint8_t mode)160   void SetPageScanRepetitionMode(uint8_t mode) {
161     page_scan_repetition_mode_ = mode;
162   }
163 
GetClockOffset()164   uint16_t GetClockOffset() const {
165     return clock_offset_;
166   }
167 
SetClockOffset(uint16_t offset)168   void SetClockOffset(uint16_t offset) {
169     clock_offset_ = offset;
170   }
171 
172   // Low-Energy functions
GetLeAddress()173   const Address& GetLeAddress() const {
174     return le_address_;
175   }
176 
SetLeAddress(const Address & address)177   void SetLeAddress(const Address& address) {
178     le_address_ = address;
179   }
180 
GetLeAddressType()181   uint8_t GetLeAddressType() const {
182     return le_address_type_;
183   }
184 
SetLeAddressType(uint8_t addr_type)185   void SetLeAddressType(uint8_t addr_type) {
186     le_address_type_ = addr_type;
187   }
188 
GetLeAdvertisementType()189   uint8_t GetLeAdvertisementType() const {
190     return le_advertisement_type_;
191   }
192 
SetLeAdvertisementType(uint8_t ad_type)193   void SetLeAdvertisementType(uint8_t ad_type) {
194     le_advertisement_type_ = ad_type;
195   }
196 
SetLeAdvertisement(const std::vector<uint8_t> & ad)197   void SetLeAdvertisement(const std::vector<uint8_t>& ad) {
198     le_advertisement_ = ad;
199   }
200 
GetLeAdvertisement()201   const std::vector<uint8_t>& GetLeAdvertisement() const {
202     return le_advertisement_;
203   }
204 
SetLeScanResponse(const std::vector<uint8_t> & response)205   void SetLeScanResponse(const std::vector<uint8_t>& response) {
206     le_scan_response_ = response;
207   }
208 
GetLeScanResponse()209   const std::vector<uint8_t>& GetLeScanResponse() const {
210     return le_scan_response_;
211   }
212 
213   // Specification Version 4.2, Volume 2, Part E, Section 7.8.2
GetLeDataPacketLength()214   uint16_t GetLeDataPacketLength() const {
215     return le_data_packet_length_;
216   }
217 
GetTotalNumLeDataPackets()218   uint8_t GetTotalNumLeDataPackets() const {
219     return num_le_data_packets_;
220   }
221 
222   // Specification Version 4.2, Volume 2, Part E, Section 7.8.3
GetLeSupportedFeatures()223   uint64_t GetLeSupportedFeatures() const {
224     return le_supported_features_;
225   }
226 
SetLeSupportedFeatures(uint64_t features)227   void SetLeSupportedFeatures(uint64_t features) {
228     le_supported_features_ = features;
229   }
230 
231   // Specification Version 4.2, Volume 2, Part E, Section 7.8.14
GetLeWhiteListSize()232   uint8_t GetLeWhiteListSize() const {
233     return le_white_list_size_;
234   }
235 
236   // Specification Version 4.2, Volume 2, Part E, Section 7.8.27
GetLeSupportedStates()237   uint64_t GetLeSupportedStates() const {
238     return le_supported_states_;
239   }
240 
241   // Vendor-specific commands
GetLeVendorCap()242   const std::vector<uint8_t>& GetLeVendorCap() const {
243     return le_vendor_cap_;
244   }
245 
246   static void RegisterJSONConverter(base::JSONValueConverter<DeviceProperties>* converter);
247 
248  private:
249   // Classic
250   uint16_t acl_data_packet_size_;
251   uint8_t sco_data_packet_size_;
252   uint16_t num_acl_data_packets_;
253   uint16_t num_sco_data_packets_;
254   uint8_t version_;
255   uint16_t revision_;
256   uint8_t lmp_pal_version_;
257   uint16_t manufacturer_name_;
258   uint16_t lmp_pal_subversion_;
259   uint64_t supported_features_;
260   uint8_t authentication_enable_;
261   std::vector<uint8_t> supported_codecs_;
262   std::vector<uint32_t> vendor_specific_codecs_;
263   std::vector<uint8_t> supported_commands_;
264   std::vector<uint64_t> extended_features_{{0x875b3fd8fe8ffeff, 0x07}};
265   ClassOfDevice class_of_device_{{0, 0, 0}};
266   std::vector<uint8_t> extended_inquiry_data_;
267   std::vector<uint8_t> name_;
268   Address address_;
269   uint8_t page_scan_repetition_mode_;
270   uint16_t clock_offset_;
271 
272   // Low Energy
273   uint16_t le_data_packet_length_;
274   uint8_t num_le_data_packets_;
275   uint8_t le_white_list_size_;
276   uint64_t le_supported_features_{0x075b3fd8fe8ffeff};
277   uint64_t le_supported_states_;
278   std::vector<uint8_t> le_vendor_cap_;
279   Address le_address_;
280   uint8_t le_address_type_;
281   uint8_t le_advertisement_type_;
282   std::vector<uint8_t> le_advertisement_;
283   std::vector<uint8_t> le_scan_response_;
284 };
285 
286 }  // namespace test_vendor_lib
287