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 <array> 20 #include <cstdint> 21 #include <optional> 22 #include <string> 23 #include <vector> 24 25 #include "hci/address.h" 26 #include "hci/hci_packets.h" 27 28 namespace rootcanal { 29 using bluetooth::hci::HciVersion; 30 using bluetooth::hci::LmpVersion; 31 32 // Local controller information. 33 // 34 // Provide the Informational Parameters returned by HCI commands 35 // in the range of the same name (cf. [4] E.7.4). 36 // The informational parameters are fixed by the manufacturer of the Bluetooth 37 // hardware. These parameters provide information about the BR/EDR Controller 38 // and the capabilities of the Link Manager and Baseband in the BR/EDR 39 // Controller. The Host device cannot modify any of these parameters. 40 struct ControllerProperties { 41 public: 42 explicit ControllerProperties(const std::string& filename = ""); 43 ~ControllerProperties() = default; 44 45 // Perform a bitwise and operation on the supported commands mask; 46 // the default bit setting is either loaded from the configuration 47 // file or all 1s. 48 void SetSupportedCommands(std::array<uint8_t, 64> supported_commands); 49 50 // Check if the feature masks are valid according to the specification. 51 bool CheckSupportedFeatures() const; 52 53 // Local Version Information (Vol 4, Part E § 7.4.1). 54 HciVersion hci_version{HciVersion::V_5_3}; 55 LmpVersion lmp_version{LmpVersion::V_5_3}; 56 uint16_t hci_subversion{0}; 57 uint16_t lmp_subversion{0}; 58 uint16_t company_identifier{0x00E0}; // Google 59 60 // Local Supported Commands (Vol 4, Part E § 7.4.2). 61 std::array<uint8_t, 64> supported_commands; 62 63 // Local Supported Features (Vol 4, Part E § 7.4.3) and 64 // Local Extended Features (Vol 4, Part E § 7.4.3). 65 std::array<uint64_t, 3> lmp_features; 66 67 // LE Local Supported Features (Vol 4, Part E § 7.8.3). 68 uint64_t le_features; 69 70 // Buffer Size (Vol 4, Part E § 7.4.5). 71 uint16_t acl_data_packet_length{1024}; 72 uint8_t sco_data_packet_length{255}; 73 uint16_t total_num_acl_data_packets{10}; 74 uint16_t total_num_sco_data_packets{10}; 75 76 // LE Buffer Size (Vol 4, Part E § 7.8.2). 77 uint16_t le_acl_data_packet_length{27}; 78 uint16_t iso_data_packet_length{1021}; 79 uint8_t total_num_le_acl_data_packets{20}; 80 uint8_t total_num_iso_data_packets{12}; 81 82 // Number of Supported IAC (Vol 4, Part E § 7.3.43). 83 uint8_t num_supported_iac{4}; 84 85 // LE Advertising Physical Channel TX Power (Vol 4, Part E § 7.8.6). 86 uint8_t le_advertising_physical_channel_tx_power{static_cast<uint8_t>(-10)}; 87 88 // Supported Codecs (Vol 4, Part E § 7.4.8). 89 // Implements the [v1] version only. 90 std::vector<uint8_t> supported_standard_codecs{0}; 91 std::vector<uint32_t> supported_vendor_specific_codecs{}; 92 93 // LE Filter Accept List Size (Vol 4, Part E § 7.8.14). 94 uint8_t le_filter_accept_list_size{16}; 95 96 // LE Resolving List Size (Vol 4, Part E § 7.8.41). 97 uint8_t le_resolving_list_size{16}; 98 99 // LE Supported States (Vol 4, Part E § 7.8.27). 100 uint64_t le_supported_states{0x3ffffffffff}; 101 102 // LE Maximum Advertising Data Length (Vol 4, Part E § 7.8.57). 103 // Note: valid range 0x001F to 0x0672. 104 uint16_t le_max_advertising_data_length{512}; 105 106 // LE Number of Supported Advertising Sets (Vol 4, Part E § 7.8.58) 107 // Note: the controller can change the number of advertising sets 108 // at any time. This behaviour is not emulated here. 109 uint8_t le_num_supported_advertising_sets{8}; 110 111 // Vendor Information. 112 // Provide parameters returned by vendor specific commands. 113 std::vector<uint8_t> le_vendor_capabilities{}; 114 SupportsLMPFeatureControllerProperties115 bool SupportsLMPFeature(bluetooth::hci::LMPFeaturesPage0Bits bit) const { 116 return (lmp_features[0] & static_cast<uint64_t>(bit)) != 0; 117 } 118 SupportsLMPFeatureControllerProperties119 bool SupportsLMPFeature(bluetooth::hci::LMPFeaturesPage2Bits bit) const { 120 return (lmp_features[2] & static_cast<uint64_t>(bit)) != 0; 121 } 122 }; 123 124 } // namespace rootcanal 125