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 #include "model/controller/controller_properties.h"
18 
19 #include <array>
20 #include <cstdint>
21 #include <utility>
22 #include <vector>
23 
24 #include "log.h"
25 #include "packets/hci_packets.h"
26 #include "rootcanal/configuration.pb.h"
27 
28 namespace rootcanal {
29 using namespace bluetooth::hci;
30 
Page0LmpFeatures()31 static constexpr uint64_t Page0LmpFeatures() {
32   LMPFeaturesPage0Bits features[] = {
33           LMPFeaturesPage0Bits::LMP_3_SLOT_PACKETS,
34           LMPFeaturesPage0Bits::LMP_5_SLOT_PACKETS,
35           LMPFeaturesPage0Bits::ENCRYPTION,
36           LMPFeaturesPage0Bits::SLOT_OFFSET,
37           LMPFeaturesPage0Bits::TIMING_ACCURACY,
38           LMPFeaturesPage0Bits::ROLE_SWITCH,
39           LMPFeaturesPage0Bits::HOLD_MODE,
40           LMPFeaturesPage0Bits::SNIFF_MODE,
41           LMPFeaturesPage0Bits::POWER_CONTROL_REQUESTS,
42           LMPFeaturesPage0Bits::CHANNEL_QUALITY_DRIVEN_DATA_RATE,
43           LMPFeaturesPage0Bits::SCO_LINK,
44           LMPFeaturesPage0Bits::HV2_PACKETS,
45           LMPFeaturesPage0Bits::HV3_PACKETS,
46           LMPFeaturesPage0Bits::M_LAW_LOG_SYNCHRONOUS_DATA,
47           LMPFeaturesPage0Bits::A_LAW_LOG_SYNCHRONOUS_DATA,
48           LMPFeaturesPage0Bits::CVSD_SYNCHRONOUS_DATA,
49           LMPFeaturesPage0Bits::PAGING_PARAMETER_NEGOTIATION,
50           LMPFeaturesPage0Bits::POWER_CONTROL,
51           LMPFeaturesPage0Bits::TRANSPARENT_SYNCHRONOUS_DATA,
52           LMPFeaturesPage0Bits::BROADCAST_ENCRYPTION,
53           LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE,
54           LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE,
55           LMPFeaturesPage0Bits::ENHANCED_INQUIRY_SCAN,
56           LMPFeaturesPage0Bits::INTERLACED_INQUIRY_SCAN,
57           LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN,
58           LMPFeaturesPage0Bits::RSSI_WITH_INQUIRY_RESULTS,
59           LMPFeaturesPage0Bits::EXTENDED_SCO_LINK,
60           LMPFeaturesPage0Bits::EV4_PACKETS,
61           LMPFeaturesPage0Bits::EV5_PACKETS,
62           LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL,
63           LMPFeaturesPage0Bits::AFH_CLASSIFICATION_PERIPHERAL,
64           LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER,
65           LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS,
66           LMPFeaturesPage0Bits::LMP_5_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS,
67           LMPFeaturesPage0Bits::SNIFF_SUBRATING,
68           LMPFeaturesPage0Bits::PAUSE_ENCRYPTION,
69           LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL,
70           LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL,
71           LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE,
72           LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_3_MB_S_MODE,
73           LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS,
74           LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE,
75           LMPFeaturesPage0Bits::SIMULTANEOUS_LE_AND_BR_CONTROLLER,
76           LMPFeaturesPage0Bits::SECURE_SIMPLE_PAIRING_CONTROLLER,
77           LMPFeaturesPage0Bits::ENCAPSULATED_PDU,
78           LMPFeaturesPage0Bits::HCI_LINK_SUPERVISION_TIMEOUT_CHANGED_EVENT,
79           LMPFeaturesPage0Bits::VARIABLE_INQUIRY_TX_POWER_LEVEL,
80           LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL,
81           LMPFeaturesPage0Bits::EXTENDED_FEATURES};
82 
83   uint64_t value = 0;
84   for (auto feature : features) {
85     value |= static_cast<uint64_t>(feature);
86   }
87   return value;
88 }
89 
Page2LmpFeatures()90 static constexpr uint64_t Page2LmpFeatures() {
91   LMPFeaturesPage2Bits features[] = {
92           LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT,
93           LMPFeaturesPage2Bits::PING,
94   };
95 
96   uint64_t value = 0;
97   for (auto feature : features) {
98     value |= static_cast<uint64_t>(feature);
99   }
100   return value;
101 }
102 
LlFeatures()103 static constexpr uint64_t LlFeatures() {
104   LLFeaturesBits features[] = {
105           LLFeaturesBits::LE_ENCRYPTION,
106           LLFeaturesBits::CONNECTION_PARAMETERS_REQUEST_PROCEDURE,
107           LLFeaturesBits::EXTENDED_REJECT_INDICATION,
108           LLFeaturesBits::PERIPHERAL_INITIATED_FEATURES_EXCHANGE,
109           LLFeaturesBits::LE_PING,
110           LLFeaturesBits::LL_PRIVACY,
111           LLFeaturesBits::EXTENDED_SCANNER_FILTER_POLICIES,
112           LLFeaturesBits::LE_2M_PHY,
113           LLFeaturesBits::LE_CODED_PHY,
114           LLFeaturesBits::LE_EXTENDED_ADVERTISING,
115           LLFeaturesBits::LE_PERIODIC_ADVERTISING,
116 
117           LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL,
118           LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL,
119   };
120 
121   uint64_t value = 0;
122   for (auto feature : features) {
123     value |= static_cast<uint64_t>(feature);
124   }
125   return value;
126 }
127 
SupportedCommands()128 static std::array<uint8_t, 64> SupportedCommands() {
129   OpCodeIndex supported_commands[] = {
130           // LINK_CONTROL
131           OpCodeIndex::INQUIRY, OpCodeIndex::INQUIRY_CANCEL,
132           // OpCodeIndex::PERIODIC_INQUIRY_MODE,
133           // OpCodeIndex::EXIT_PERIODIC_INQUIRY_MODE,
134           OpCodeIndex::CREATE_CONNECTION, OpCodeIndex::DISCONNECT, OpCodeIndex::ADD_SCO_CONNECTION,
135           OpCodeIndex::CREATE_CONNECTION_CANCEL, OpCodeIndex::ACCEPT_CONNECTION_REQUEST,
136           OpCodeIndex::REJECT_CONNECTION_REQUEST, OpCodeIndex::LINK_KEY_REQUEST_REPLY,
137           OpCodeIndex::LINK_KEY_REQUEST_NEGATIVE_REPLY, OpCodeIndex::PIN_CODE_REQUEST_REPLY,
138           OpCodeIndex::PIN_CODE_REQUEST_NEGATIVE_REPLY, OpCodeIndex::CHANGE_CONNECTION_PACKET_TYPE,
139           OpCodeIndex::AUTHENTICATION_REQUESTED, OpCodeIndex::SET_CONNECTION_ENCRYPTION,
140           OpCodeIndex::CHANGE_CONNECTION_LINK_KEY, OpCodeIndex::CENTRAL_LINK_KEY,
141           OpCodeIndex::REMOTE_NAME_REQUEST,
142           // OpCodeIndex::REMOTE_NAME_REQUEST_CANCEL,
143           OpCodeIndex::READ_REMOTE_SUPPORTED_FEATURES, OpCodeIndex::READ_REMOTE_EXTENDED_FEATURES,
144           OpCodeIndex::READ_REMOTE_VERSION_INFORMATION, OpCodeIndex::READ_CLOCK_OFFSET,
145           OpCodeIndex::READ_LMP_HANDLE, OpCodeIndex::SETUP_SYNCHRONOUS_CONNECTION,
146           OpCodeIndex::ACCEPT_SYNCHRONOUS_CONNECTION, OpCodeIndex::REJECT_SYNCHRONOUS_CONNECTION,
147           OpCodeIndex::IO_CAPABILITY_REQUEST_REPLY, OpCodeIndex::USER_CONFIRMATION_REQUEST_REPLY,
148           OpCodeIndex::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY,
149           OpCodeIndex::USER_PASSKEY_REQUEST_REPLY, OpCodeIndex::USER_PASSKEY_REQUEST_NEGATIVE_REPLY,
150           OpCodeIndex::REMOTE_OOB_DATA_REQUEST_REPLY,
151           OpCodeIndex::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY,
152           OpCodeIndex::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY,
153           OpCodeIndex::ENHANCED_SETUP_SYNCHRONOUS_CONNECTION,
154           OpCodeIndex::ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION,
155           // OpCodeIndex::TRUNCATED_PAGE,
156           // OpCodeIndex::TRUNCATED_PAGE_CANCEL,
157           // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST,
158           // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE,
159           // OpCodeIndex::START_SYNCHRONIZATION_TRAIN,
160           // OpCodeIndex::RECEIVE_SYNCHRONIZATION_TRAIN,
161           OpCodeIndex::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY,
162 
163           // LINK_POLICY
164           OpCodeIndex::HOLD_MODE, OpCodeIndex::SNIFF_MODE, OpCodeIndex::EXIT_SNIFF_MODE,
165           OpCodeIndex::QOS_SETUP, OpCodeIndex::ROLE_DISCOVERY, OpCodeIndex::SWITCH_ROLE,
166           OpCodeIndex::READ_LINK_POLICY_SETTINGS, OpCodeIndex::WRITE_LINK_POLICY_SETTINGS,
167           OpCodeIndex::READ_DEFAULT_LINK_POLICY_SETTINGS,
168           OpCodeIndex::WRITE_DEFAULT_LINK_POLICY_SETTINGS, OpCodeIndex::FLOW_SPECIFICATION,
169           OpCodeIndex::SNIFF_SUBRATING,
170 
171           // CONTROLLER_AND_BASEBAND
172           OpCodeIndex::SET_EVENT_MASK, OpCodeIndex::RESET, OpCodeIndex::SET_EVENT_FILTER,
173           OpCodeIndex::FLUSH,
174           // OpCodeIndex::READ_PIN_TYPE,
175           // OpCodeIndex::WRITE_PIN_TYPE,
176           // OpCodeIndex::READ_STORED_LINK_KEY,
177           // OpCodeIndex::WRITE_STORED_LINK_KEY,
178           OpCodeIndex::DELETE_STORED_LINK_KEY, OpCodeIndex::WRITE_LOCAL_NAME,
179           OpCodeIndex::READ_LOCAL_NAME, OpCodeIndex::READ_CONNECTION_ACCEPT_TIMEOUT,
180           OpCodeIndex::WRITE_CONNECTION_ACCEPT_TIMEOUT, OpCodeIndex::READ_PAGE_TIMEOUT,
181           OpCodeIndex::WRITE_PAGE_TIMEOUT, OpCodeIndex::READ_SCAN_ENABLE,
182           OpCodeIndex::WRITE_SCAN_ENABLE, OpCodeIndex::READ_PAGE_SCAN_ACTIVITY,
183           OpCodeIndex::WRITE_PAGE_SCAN_ACTIVITY, OpCodeIndex::READ_INQUIRY_SCAN_ACTIVITY,
184           OpCodeIndex::WRITE_INQUIRY_SCAN_ACTIVITY, OpCodeIndex::READ_AUTHENTICATION_ENABLE,
185           OpCodeIndex::WRITE_AUTHENTICATION_ENABLE, OpCodeIndex::READ_CLASS_OF_DEVICE,
186           OpCodeIndex::WRITE_CLASS_OF_DEVICE, OpCodeIndex::READ_VOICE_SETTING,
187           OpCodeIndex::WRITE_VOICE_SETTING, OpCodeIndex::READ_AUTOMATIC_FLUSH_TIMEOUT,
188           OpCodeIndex::WRITE_AUTOMATIC_FLUSH_TIMEOUT,
189           // OpCodeIndex::READ_NUM_BROADCAST_RETRANSMITS,
190           // OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS,
191           OpCodeIndex::READ_HOLD_MODE_ACTIVITY, OpCodeIndex::WRITE_HOLD_MODE_ACTIVITY,
192           OpCodeIndex::READ_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE,
193           OpCodeIndex::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE,
194           OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL, OpCodeIndex::HOST_BUFFER_SIZE,
195           OpCodeIndex::HOST_NUMBER_OF_COMPLETED_PACKETS, OpCodeIndex::READ_LINK_SUPERVISION_TIMEOUT,
196           OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT, OpCodeIndex::READ_NUMBER_OF_SUPPORTED_IAC,
197           OpCodeIndex::READ_CURRENT_IAC_LAP, OpCodeIndex::WRITE_CURRENT_IAC_LAP,
198           OpCodeIndex::SET_AFH_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::READ_INQUIRY_SCAN_TYPE,
199           OpCodeIndex::WRITE_INQUIRY_SCAN_TYPE, OpCodeIndex::READ_INQUIRY_MODE,
200           OpCodeIndex::WRITE_INQUIRY_MODE, OpCodeIndex::READ_PAGE_SCAN_TYPE,
201           OpCodeIndex::WRITE_PAGE_SCAN_TYPE, OpCodeIndex::READ_AFH_CHANNEL_ASSESSMENT_MODE,
202           OpCodeIndex::WRITE_AFH_CHANNEL_ASSESSMENT_MODE,
203           OpCodeIndex::READ_EXTENDED_INQUIRY_RESPONSE, OpCodeIndex::WRITE_EXTENDED_INQUIRY_RESPONSE,
204           OpCodeIndex::REFRESH_ENCRYPTION_KEY, OpCodeIndex::READ_SIMPLE_PAIRING_MODE,
205           OpCodeIndex::WRITE_SIMPLE_PAIRING_MODE, OpCodeIndex::READ_LOCAL_OOB_DATA,
206           OpCodeIndex::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL,
207           OpCodeIndex::WRITE_INQUIRY_TRANSMIT_POWER_LEVEL,
208           // OpCodeIndex::READ_DEFAULT_ERRONEOUS_DATA_REPORTING,
209           // OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING,
210           OpCodeIndex::ENHANCED_FLUSH, OpCodeIndex::SEND_KEYPRESS_NOTIFICATION,
211           OpCodeIndex::SET_EVENT_MASK_PAGE_2,
212           // OpCodeIndex::READ_FLOW_CONTROL_MODE,
213           // OpCodeIndex::WRITE_FLOW_CONTROL_MODE,
214           OpCodeIndex::READ_ENHANCED_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_LE_HOST_SUPPORT,
215           OpCodeIndex::WRITE_LE_HOST_SUPPORT,
216           // OpCodeIndex::SET_MWS_CHANNEL_PARAMETERS,
217           // OpCodeIndex::SET_EXTERNAL_FRAME_CONFIGURATION,
218           // OpCodeIndex::SET_MWS_SIGNALING,
219           // OpCodeIndex::SET_MWS_TRANSPORT_LAYER,
220           // OpCodeIndex::SET_MWS_SCAN_FREQUENCY_TABLE,
221           // OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION,
222           // OpCodeIndex::SET_RESERVED_LT_ADDR,
223           // OpCodeIndex::DELETE_RESERVED_LT_ADDR,
224           // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA,
225           // OpCodeIndex::READ_SYNCHRONIZATION_TRAIN_PARAMETERS,
226           // OpCodeIndex::WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS,
227           OpCodeIndex::READ_SECURE_CONNECTIONS_HOST_SUPPORT,
228           OpCodeIndex::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT,
229           OpCodeIndex::READ_AUTHENTICATED_PAYLOAD_TIMEOUT,
230           OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT,
231           OpCodeIndex::READ_LOCAL_OOB_EXTENDED_DATA,
232           // OpCodeIndex::READ_EXTENDED_PAGE_TIMEOUT,
233           // OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT,
234           // OpCodeIndex::READ_EXTENDED_INQUIRY_LENGTH,
235           // OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH,
236           // OpCodeIndex::SET_ECOSYSTEM_BASE_INTERVAL,
237           // OpCodeIndex::CONFIGURE_DATA_PATH,
238           // OpCodeIndex::SET_MIN_ENCRYPTION_KEY_SIZE,
239 
240           // INFORMATIONAL_PARAMETERS
241           OpCodeIndex::READ_LOCAL_VERSION_INFORMATION, OpCodeIndex::READ_LOCAL_SUPPORTED_FEATURES,
242           OpCodeIndex::READ_LOCAL_EXTENDED_FEATURES, OpCodeIndex::READ_BUFFER_SIZE,
243           OpCodeIndex::READ_BD_ADDR,
244           // OpCodeIndex::READ_DATA_BLOCK_SIZE,
245           OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V1,
246           // OpCodeIndex::READ_LOCAL_SIMPLE_PAIRING_OPTIONS,
247           // OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2,
248           // OpCodeIndex::READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES,
249           // OpCodeIndex::READ_LOCAL_SUPPORTED_CONTROLLER_DELAY,
250 
251           // STATUS_PARAMETERS
252           OpCodeIndex::READ_FAILED_CONTACT_COUNTER, OpCodeIndex::RESET_FAILED_CONTACT_COUNTER,
253           // OpCodeIndex::READ_LINK_QUALITY,
254           OpCodeIndex::READ_RSSI, OpCodeIndex::READ_AFH_CHANNEL_MAP,
255           // OpCodeIndex::READ_CLOCK,
256           OpCodeIndex::READ_ENCRYPTION_KEY_SIZE,
257           // OpCodeIndex::GET_MWS_TRANSPORT_LAYER_CONFIGURATION,
258           // OpCodeIndex::SET_TRIGGERED_CLOCK_CAPTURE,
259 
260           // TESTING
261           OpCodeIndex::READ_LOOPBACK_MODE, OpCodeIndex::WRITE_LOOPBACK_MODE,
262           OpCodeIndex::ENABLE_IMPLEMENTATION_UNDER_TEST_MODE,
263           OpCodeIndex::WRITE_SIMPLE_PAIRING_DEBUG_MODE,
264           OpCodeIndex::WRITE_SECURE_CONNECTIONS_TEST_MODE,
265 
266           // LE_CONTROLLER
267           OpCodeIndex::LE_SET_EVENT_MASK, OpCodeIndex::LE_READ_BUFFER_SIZE_V1,
268           OpCodeIndex::LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0, OpCodeIndex::LE_SET_RANDOM_ADDRESS,
269           OpCodeIndex::LE_SET_ADVERTISING_PARAMETERS,
270           OpCodeIndex::LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER,
271           OpCodeIndex::LE_SET_ADVERTISING_DATA, OpCodeIndex::LE_SET_SCAN_RESPONSE_DATA,
272           OpCodeIndex::LE_SET_ADVERTISING_ENABLE, OpCodeIndex::LE_SET_SCAN_PARAMETERS,
273           OpCodeIndex::LE_SET_SCAN_ENABLE, OpCodeIndex::LE_CREATE_CONNECTION,
274           OpCodeIndex::LE_CREATE_CONNECTION_CANCEL, OpCodeIndex::LE_READ_FILTER_ACCEPT_LIST_SIZE,
275           OpCodeIndex::LE_CLEAR_FILTER_ACCEPT_LIST,
276           OpCodeIndex::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST,
277           OpCodeIndex::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, OpCodeIndex::LE_CONNECTION_UPDATE,
278           OpCodeIndex::LE_SET_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::LE_READ_CHANNEL_MAP,
279           OpCodeIndex::LE_READ_REMOTE_FEATURES_PAGE_0, OpCodeIndex::LE_ENCRYPT,
280           OpCodeIndex::LE_RAND, OpCodeIndex::LE_START_ENCRYPTION,
281           OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_REPLY,
282           OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY,
283           OpCodeIndex::LE_READ_SUPPORTED_STATES, OpCodeIndex::LE_RECEIVER_TEST_V1,
284           OpCodeIndex::LE_TRANSMITTER_TEST_V1, OpCodeIndex::LE_TEST_END,
285           OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY,
286           OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY,
287           // OpCodeIndex::LE_SET_DATA_LENGTH,
288           OpCodeIndex::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH,
289           OpCodeIndex::LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH,
290           OpCodeIndex::LE_READ_LOCAL_P_256_PUBLIC_KEY,
291           // OpCodeIndex::LE_GENERATE_DHKEY_V1,
292           OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST,
293           OpCodeIndex::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, OpCodeIndex::LE_CLEAR_RESOLVING_LIST,
294           OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE, OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS,
295           OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS,
296           OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE,
297           OpCodeIndex::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT,
298           OpCodeIndex::LE_READ_MAXIMUM_DATA_LENGTH, OpCodeIndex::LE_READ_PHY,
299           OpCodeIndex::LE_SET_DEFAULT_PHY, OpCodeIndex::LE_SET_PHY,
300           // OpCodeIndex::LE_RECEIVER_TEST_V2,
301           // OpCodeIndex::LE_TRANSMITTER_TEST_V2,
302           OpCodeIndex::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS,
303           OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1,
304           OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA,
305           OpCodeIndex::LE_SET_EXTENDED_SCAN_RESPONSE_DATA,
306           OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_ENABLE,
307           OpCodeIndex::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH,
308           OpCodeIndex::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS,
309           OpCodeIndex::LE_REMOVE_ADVERTISING_SET, OpCodeIndex::LE_CLEAR_ADVERTISING_SETS,
310           OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1,
311           OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA,
312           OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_ENABLE,
313           OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS, OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE,
314           OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V1,
315           OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC,
316           OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL,
317           OpCodeIndex::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC,
318           OpCodeIndex::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST,
319           OpCodeIndex::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST,
320           OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST,
321           OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE,
322           // OpCodeIndex::LE_READ_TRANSMIT_POWER,
323           OpCodeIndex::LE_READ_RF_PATH_COMPENSATION_POWER,
324           OpCodeIndex::LE_WRITE_RF_PATH_COMPENSATION_POWER, OpCodeIndex::LE_SET_PRIVACY_MODE,
325           // OpCodeIndex::LE_RECEIVER_TEST_V3,
326           // OpCodeIndex::LE_TRANSMITTER_TEST_V3,
327           // OpCodeIndex::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS,
328           // OpCodeIndex::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_ENABLE,
329           // OpCodeIndex::LE_SET_CONNECTIONLESS_IQ_SAMPLING_ENABLE,
330           // OpCodeIndex::LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS,
331           // OpCodeIndex::LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS,
332           // OpCodeIndex::LE_CONNECTION_CTE_REQUEST_ENABLE,
333           // OpCodeIndex::LE_CONNECTION_CTE_RESPONSE_ENABLE,
334           // OpCodeIndex::LE_READ_ANTENNA_INFORMATION,
335           // OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE,
336           // OpCodeIndex::LE_PERIODIC_ADVERTISING_SYNC_TRANSFER,
337           // OpCodeIndex::LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER,
338           // OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS,
339           // OpCodeIndex::LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS,
340           // OpCodeIndex::LE_GENERATE_DHKEY_V2,
341           // OpCodeIndex::LE_MODIFY_SLEEP_CLOCK_ACCURACY,
342           OpCodeIndex::LE_READ_BUFFER_SIZE_V2,
343           // OpCodeIndex::LE_READ_ISO_TX_SYNC,
344           OpCodeIndex::LE_SET_CIG_PARAMETERS, OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST,
345           OpCodeIndex::LE_CREATE_CIS, OpCodeIndex::LE_REMOVE_CIG,
346           OpCodeIndex::LE_ACCEPT_CIS_REQUEST, OpCodeIndex::LE_REJECT_CIS_REQUEST,
347           // OpCodeIndex::LE_CREATE_BIG,
348           // OpCodeIndex::LE_CREATE_BIG_TEST,
349           // OpCodeIndex::LE_TERMINATE_BIG,
350           // OpCodeIndex::LE_BIG_CREATE_SYNC,
351           // OpCodeIndex::LE_BIG_TERMINATE_SYNC,
352           OpCodeIndex::LE_REQUEST_PEER_SCA, OpCodeIndex::LE_SETUP_ISO_DATA_PATH,
353           OpCodeIndex::LE_REMOVE_ISO_DATA_PATH,
354           // OpCodeIndex::LE_ISO_TRANSMIT_TEST,
355           // OpCodeIndex::LE_ISO_RECEIVE_TEST,
356           // OpCodeIndex::LE_ISO_READ_TEST_COUNTERS,
357           // OpCodeIndex::LE_ISO_TEST_END,
358           OpCodeIndex::LE_SET_HOST_FEATURE_V1,
359           // OpCodeIndex::LE_READ_ISO_LINK_QUALITY,
360           // OpCodeIndex::LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL,
361           // OpCodeIndex::LE_READ_REMOTE_TRANSMIT_POWER_LEVEL,
362           // OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_PARAMETERS,
363           // OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_ENABLE,
364           // OpCodeIndex::LE_SET_TRANSMIT_POWER_REPORTING_ENABLE,
365           // OpCodeIndex::LE_TRANSMITTER_TEST_V4,
366           // OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES,
367           // OpCodeIndex::LE_SET_DEFAULT_SUBRATE,
368           // OpCodeIndex::LE_SUBRATE_REQUEST,
369   };
370 
371   std::array<uint8_t, 64> value{};
372   for (auto command : supported_commands) {
373     int index = static_cast<int>(command);
374     value[index / 10] |= 1U << (index % 10);
375   }
376 
377   return value;
378 }
379 
CheckSupportedFeatures() const380 bool ControllerProperties::CheckSupportedFeatures() const {
381   // Vol 2, Part C § 3.3 Feature mask definition.
382   // Check for reserved or deprecated feature bits.
383   //
384   // Note: the specification for v1.0 and v1.1 is no longer available for
385   // download, the reserved feature bits are copied over from v1.2.
386   uint64_t lmp_page_0_reserved_bits = 0;
387   uint64_t lmp_page_2_reserved_bits = 0;
388   switch (lmp_version) {
389     case bluetooth::hci::LmpVersion::V_1_0B:
390       lmp_page_0_reserved_bits = UINT64_C(0x7fffe7e407000000);
391       lmp_page_2_reserved_bits = UINT64_C(0xffffffffffffffff);
392       break;
393     case bluetooth::hci::LmpVersion::V_1_1:
394       lmp_page_0_reserved_bits = UINT64_C(0x7fffe7e407000000);
395       lmp_page_2_reserved_bits = UINT64_C(0xffffffffffffffff);
396       break;
397     case bluetooth::hci::LmpVersion::V_1_2:
398       lmp_page_0_reserved_bits = UINT64_C(0x7fffe7e407000000);
399       lmp_page_2_reserved_bits = UINT64_C(0xffffffffffffffff);
400       break;
401     case bluetooth::hci::LmpVersion::V_2_0:
402       lmp_page_0_reserved_bits = UINT64_C(0x7fff066401000000);
403       lmp_page_2_reserved_bits = UINT64_C(0xffffffffffffffff);
404       break;
405     case bluetooth::hci::LmpVersion::V_2_1:
406       lmp_page_0_reserved_bits = UINT64_C(0x7c86006401000000);
407       lmp_page_2_reserved_bits = UINT64_C(0xffffffffffffffff);
408       break;
409     case bluetooth::hci::LmpVersion::V_3_0:
410       lmp_page_0_reserved_bits = UINT64_C(0x7886006401000000);
411       lmp_page_2_reserved_bits = UINT64_C(0xffffffffffffffff);
412       break;
413     case bluetooth::hci::LmpVersion::V_4_0:
414       lmp_page_0_reserved_bits = UINT64_C(0x7884000401000000);
415       lmp_page_2_reserved_bits = UINT64_C(0xffffffffffffffff);
416       break;
417     case bluetooth::hci::LmpVersion::V_4_1:
418       lmp_page_0_reserved_bits = UINT64_C(0x7884000401000000);
419       lmp_page_2_reserved_bits = UINT64_C(0xfffffffffffff480);
420       break;
421     case bluetooth::hci::LmpVersion::V_4_2:
422       lmp_page_0_reserved_bits = UINT64_C(0x7884000401000000);
423       lmp_page_2_reserved_bits = UINT64_C(0xfffffffffffff480);
424       break;
425     case bluetooth::hci::LmpVersion::V_5_0:
426       lmp_page_0_reserved_bits = UINT64_C(0x7884000401000100);
427       lmp_page_2_reserved_bits = UINT64_C(0xfffffffffffff480);
428       break;
429     case bluetooth::hci::LmpVersion::V_5_1:
430       lmp_page_0_reserved_bits = UINT64_C(0x7884000401000100);
431       lmp_page_2_reserved_bits = UINT64_C(0xfffffffffffff080);
432       break;
433     case bluetooth::hci::LmpVersion::V_5_2:
434       lmp_page_0_reserved_bits = UINT64_C(0x7884000401000100);
435       lmp_page_2_reserved_bits = UINT64_C(0xfffffffffffff080);
436       break;
437     case bluetooth::hci::LmpVersion::V_5_3:
438     default:
439       lmp_page_0_reserved_bits = UINT64_C(0x7884000401000100);
440       lmp_page_2_reserved_bits = UINT64_C(0xfffffffffffff080);
441       break;
442   }
443 
444   if ((lmp_page_0_reserved_bits & lmp_features[0]) != 0) {
445     INFO("The page 0 feature bits 0x{:016x}"
446          " are reserved in the specification {}",
447          lmp_page_0_reserved_bits & lmp_features[0], LmpVersionText(lmp_version));
448     return false;
449   }
450 
451   if ((lmp_page_2_reserved_bits & lmp_features[2]) != 0) {
452     INFO("The page 2 feature bits 0x{:016x}"
453          " are reserved in the specification {}",
454          lmp_page_2_reserved_bits & lmp_features[2], LmpVersionText(lmp_version));
455     return false;
456   }
457 
458   // Vol 2, Part C § 3.5 Feature requirements.
459   // RootCanal always support BR/EDR mode, this function implements
460   // the feature requirements from the subsection 1. Devices supporting BR/EDR.
461   //
462   // Note: the feature requirements were introduced in version v5.1 of the
463   // specification, for previous versions it is assumed that the same
464   // requirements apply for the subset of defined feature bits.
465 
466   // The features listed in Table 3.5 are mandatory in this version of the
467   // specification (see Section 3.1) and these feature bits shall be set.
468   if (!SupportsLMPFeature(LMPFeaturesPage0Bits::ENCRYPTION) ||
469       !SupportsLMPFeature(LMPFeaturesPage0Bits::SECURE_SIMPLE_PAIRING_CONTROLLER) ||
470       !SupportsLMPFeature(LMPFeaturesPage0Bits::ENCAPSULATED_PDU)) {
471     INFO("Table 3.5 validation failed");
472     return false;
473   }
474 
475   // The features listed in Table 3.6 are forbidden in this version of the
476   // specification and these feature bits shall not be set.
477   if (SupportsLMPFeature(LMPFeaturesPage0Bits::BR_EDR_NOT_SUPPORTED)) {
478     INFO("Table 3.6 validation failed");
479     return false;
480   }
481 
482   // For each row of Table 3.7, either every feature named in that row shall be
483   // supported or none of the features named in that row shall be supported.
484   if (SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_MODE) !=
485       SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_SUBRATING)) {
486     INFO("Table 3.7 validation failed");
487     return false;
488   }
489 
490   // For each row of Table 3.8, not more than one feature in that row shall be
491   // supported.
492   if (SupportsLMPFeature(LMPFeaturesPage0Bits::BROADCAST_ENCRYPTION) &&
493       SupportsLMPFeature(LMPFeaturesPage2Bits::COARSE_CLOCK_ADJUSTMENT)) {
494     INFO("Table 3.8 validation failed");
495     return false;
496   }
497 
498   // For each row of Table 3.9, if the feature named in the first column is
499   // supported then the feature named in the second column shall be supported.
500   if (SupportsLMPFeature(LMPFeaturesPage0Bits::ROLE_SWITCH) &&
501       !SupportsLMPFeature(LMPFeaturesPage0Bits::SLOT_OFFSET)) {
502     INFO("Table 3.9 validation failed; expected Slot Offset");
503     return false;
504   }
505   if (SupportsLMPFeature(LMPFeaturesPage0Bits::HV2_PACKETS) &&
506       !SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK)) {
507     INFO("Table 3.9 validation failed; expected Sco Link");
508     return false;
509   }
510   if (SupportsLMPFeature(LMPFeaturesPage0Bits::HV3_PACKETS) &&
511       !SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK)) {
512     INFO("Table 3.9 validation failed; expected Sco Link");
513     return false;
514   }
515   if (SupportsLMPFeature(LMPFeaturesPage0Bits::M_LAW_LOG_SYNCHRONOUS_DATA) &&
516       !SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) &&
517       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
518     INFO("Table 3.9 validation failed; expected Sco Link or Extended Sco Link");
519     return false;
520   }
521   if (SupportsLMPFeature(LMPFeaturesPage0Bits::A_LAW_LOG_SYNCHRONOUS_DATA) &&
522       !SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) &&
523       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
524     INFO("Table 3.9 validation failed; expected Sco Link or Extended Sco Link");
525     return false;
526   }
527   if (SupportsLMPFeature(LMPFeaturesPage0Bits::CVSD_SYNCHRONOUS_DATA) &&
528       !SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) &&
529       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
530     INFO("Table 3.9 validation failed; expected Sco Link or Extended Sco Link");
531     return false;
532   }
533   if (SupportsLMPFeature(LMPFeaturesPage0Bits::TRANSPARENT_SYNCHRONOUS_DATA) &&
534       !SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) &&
535       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
536     INFO("Table 3.9 validation failed; expected Sco Link or Extended Sco Link");
537     return false;
538   }
539   if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE) &&
540       !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) {
541     INFO("Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s "
542          "mode");
543     return false;
544   }
545   if (SupportsLMPFeature(LMPFeaturesPage0Bits::EV4_PACKETS) &&
546       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
547     INFO("Table 3.9 validation failed; expected Extended Sco Link");
548     return false;
549   }
550   if (SupportsLMPFeature(LMPFeaturesPage0Bits::EV5_PACKETS) &&
551       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
552     INFO("Table 3.9 validation failed; expected Extended Sco Link");
553     return false;
554   }
555   if (SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_PERIPHERAL) &&
556       !SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL)) {
557     INFO("Table 3.9 validation failed; expected AFH Capable Peripheral");
558     return false;
559   }
560   if (SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS) &&
561       !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) {
562     INFO("Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s "
563          "mode");
564     return false;
565   }
566   if (SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_5_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS) &&
567       !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) {
568     INFO("Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s "
569          "mode");
570     return false;
571   }
572   if (SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL) &&
573       !SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL)) {
574     INFO("Table 3.9 validation failed; expected AFH Capable Central");
575     return false;
576   }
577   if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE) &&
578       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
579     INFO("Table 3.9 validation failed; expected Extended Sco Link");
580     return false;
581   }
582   if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_3_MB_S_MODE) &&
583       !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE)) {
584     INFO("Table 3.9 validation failed; expected Enhanced Data Rate eSCO 2Mb/s "
585          "mode");
586     return false;
587   }
588   if (SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS) &&
589       !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE)) {
590     INFO("Table 3.9 validation failed; expected Enhanced Data Rate eSCO 2Mb/s "
591          "mode");
592     return false;
593   }
594   if (SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE) &&
595       !SupportsLMPFeature(LMPFeaturesPage0Bits::RSSI_WITH_INQUIRY_RESULTS)) {
596     INFO("Table 3.9 validation failed; expected RSSI with Inquiry Results");
597     return false;
598   }
599   if (SupportsLMPFeature(LMPFeaturesPage0Bits::SIMULTANEOUS_LE_AND_BR_CONTROLLER) &&
600       !SupportsLMPFeature(LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER)) {
601     INFO("Table 3.9 validation failed; expected LE Supported (Controller)");
602     return false;
603   }
604   if (SupportsLMPFeature(LMPFeaturesPage0Bits::ERRONEOUS_DATA_REPORTING) &&
605       !SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) &&
606       !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) {
607     INFO("Table 3.9 validation failed; expected Sco Link or Extended Sco Link");
608     return false;
609   }
610   if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL) &&
611       (!SupportsLMPFeature(LMPFeaturesPage0Bits::POWER_CONTROL_REQUESTS) ||
612        !SupportsLMPFeature(LMPFeaturesPage0Bits::POWER_CONTROL))) {
613     INFO("Table 3.9 validation failed; expected Power Control Request and Power "
614          "Control");
615     return false;
616   }
617   if (SupportsLMPFeature(
618               LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_TRANSMITTER_OPERATION) &&
619       !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_TRAIN)) {
620     INFO("Table 3.9 validation failed; expected Synchronization Train");
621     return false;
622   }
623   if (SupportsLMPFeature(
624               LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVER_OPERATION) &&
625       !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_SCAN)) {
626     INFO("Table 3.9 validation failed; expected Synchronization Scan");
627     return false;
628   }
629   if (SupportsLMPFeature(LMPFeaturesPage2Bits::GENERALIZED_INTERLACED_SCAN) &&
630       !SupportsLMPFeature(LMPFeaturesPage0Bits::INTERLACED_INQUIRY_SCAN) &&
631       !SupportsLMPFeature(LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN)) {
632     INFO("Table 3.9 validation failed; expected Interlaced Inquiry Scan or "
633          "Interlaced Page Scan");
634     return false;
635   }
636   if (SupportsLMPFeature(LMPFeaturesPage2Bits::COARSE_CLOCK_ADJUSTMENT) &&
637       (!SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL) ||
638        !SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL) ||
639        !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_TRAIN) ||
640        !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_SCAN))) {
641     INFO("Table 3.9 validation failed; expected AFH Capable Central/Peripheral "
642          "and Synchronization Train/Scan");
643     return false;
644   }
645   if (SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT) &&
646       (!SupportsLMPFeature(LMPFeaturesPage0Bits::PAUSE_ENCRYPTION) ||
647        !SupportsLMPFeature(LMPFeaturesPage2Bits::PING))) {
648     INFO("Table 3.9 validation failed; expected Pause Encryption and Ping");
649     return false;
650   }
651 
652   return true;
653 }
654 
CheckSupportedCommands() const655 bool ControllerProperties::CheckSupportedCommands() const {
656   // Vol 4, Part E § 3 Overview of commands and events.
657   //
658   // A Controller shall support the command or event if it is shown as mandatory
659   // for at least one of the transports (i.e. BR/EDR or LE) that the Controller
660   // supports, otherwise the Controller may support the command or event if it
661   // is shown as optional for at least one of the transports that the Controller
662   // supports, otherwise it shall not support the command or event.
663   //
664   // RootCanal always support BR/EDR and LE modes, this function implements
665   // the feature requirements from both BR/EDR and LE commands.
666 
667   // Some controller features are always set as supported in the RootCanal
668   // controller:
669   //  - The controller supports transmitting packets.
670   //  - The controller supports receiving packets.
671   //  - The controller supports Connection State.
672   //  - The controller supports Initiating State.
673   //  - The controller supports Synchronization State.
674   //  - The controller supports Scanning State.
675   //  - The controller supports Advertising State.
676   //  - The controller supports Central Role.
677   //  - The controller supports Peripheral Role.
678   //  - The controller supports LE transport.
679   //  - The controller supports Inquiry.
680   // Some controller features are always set as not supported in the RootCanal
681   // controller:
682   //  - The controller can not change its sleep clock accuracy.
683   //  - The controller does not support Test Mode.
684   //  - The controller does not support Data block based flow control.
685   //  - The controller does not support Truncated Page State.
686 
687   enum Requirement {
688     kMandatory,
689     kOptional,
690     kExcluded,
691   };
692 
693   constexpr auto mandatory = kMandatory;
694   constexpr auto optional = kOptional;
695   constexpr auto excluded = kExcluded;
696   auto mandatory_or_excluded = [](bool cond) { return cond ? kMandatory : kExcluded; };
697   auto mandatory_or_optional = [](bool cond) { return cond ? kMandatory : kOptional; };
698   auto optional_or_excluded = [](bool cond) { return cond ? kMandatory : kExcluded; };
699   auto mandatory_or_optional_or_excluded = [](bool cond1, bool cond2) {
700     return cond1 ? kMandatory : cond2 ? kOptional : kExcluded;
701   };
702 
703   // A Controller shall support the command or event if it is shown as
704   // mandatory for at least one of the transports (i.e. BR/EDR or LE) that
705   // the Controller supports, otherwise the Controller may support the command
706   // or event if it is shown as optional for at least one of the transports
707   // that the Controller supports, otherwise it shall not support the
708   // command or event.
709   auto check_command_requirement = [](bool br_supported, Requirement br_requirement,
710                                       bool le_supported, Requirement le_requirement,
711                                       bool command_supported) {
712     Requirement command_requirement =
713             !br_supported                                                  ? le_requirement
714             : !le_supported                                                ? br_requirement
715             : le_requirement == kMandatory || br_requirement == kMandatory ? kMandatory
716             : le_requirement == kOptional || br_requirement == kOptional   ? kOptional
717                                                                            : kExcluded;
718 
719     if (command_requirement == kMandatory && !command_supported) {
720       return false;
721     }
722     if (command_requirement == kExcluded && command_supported) {
723       return false;
724     }
725     return true;
726   };
727 
728   // C1: Mandatory if the LE Controller supports transmitting packets, otherwise
729   // excluded.
730   auto c1 = mandatory;
731   // C2: Mandatory if the LE Controller supports receiving packets, otherwise
732   // excluded.
733   auto c2 = mandatory;
734   // C3: Mandatory if the LE Controller supports Connection State, otherwise
735   // excluded.
736   auto c3 = mandatory;
737   // C4: Mandatory if LE Feature (LE Encryption) is supported, otherwise
738   // excluded.
739   auto c4 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION));
740   // C6: Mandatory if LE Feature (Connection Parameters Request procedure) is
741   // supported, otherwise excluded.
742   auto c6 = mandatory_or_excluded(
743           SupportsLLFeature(LLFeaturesBits::CONNECTION_PARAMETERS_REQUEST_PROCEDURE));
744   // C7: Mandatory if LE Feature (LE Encryption) and LE Feature (LE Ping) are
745   // supported, otherwise excluded.
746   auto c7 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION) &&
747                                   SupportsLLFeature(LLFeaturesBits::LE_PING));
748   // C8: Mandatory if LE Feature (LE Data Packet Length Extension) is supported,
749   // otherwise optional.
750   auto c8 =
751           mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::LE_DATA_PACKET_LENGTH_EXTENSION));
752   // C9: Mandatory if LE Feature (LL Privacy) is supported, otherwise excluded.
753   auto c9 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LL_PRIVACY));
754   // C10: Optional if LE Feature (LL Privacy) is supported, otherwise excluded.
755   auto c10 = optional_or_excluded(SupportsLLFeature(LLFeaturesBits::LL_PRIVACY));
756   // C11: Mandatory if LE Feature (LE 2M PHY) or LE Feature (LE Coded PHY) is
757   // supported, otherwise optional.
758   auto c11 = mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) ||
759                                    SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY));
760   // C12: Mandatory if LE Feature (LE 2M PHY) or LE Feature (LE Coded PHY) or
761   // LE Feature (Stable Modulation Index - Transmitter) is supported, otherwise
762   // optional if the LE Controller supports transmitting packets, otherwise
763   // excluded.
764   auto c12 = mandatory_or_excluded(
765           SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) ||
766           SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY) ||
767           SupportsLLFeature(LLFeaturesBits::STABLE_MODULATION_INDEX_TRANSMITTER));
768   // C13: Mandatory if LE Feature (LE 2M PHY) or LE Feature (LE Coded PHY) or LE
769   // Feature (Stable Modulation Index - Receiver) is supported, otherwise
770   // optional if the LE Controller supports receiving packets, otherwise
771   // excluded.
772   auto c13 = mandatory_or_excluded(
773           SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) ||
774           SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY) ||
775           SupportsLLFeature(LLFeaturesBits::STABLE_MODULATION_INDEX_RECEIVER));
776   // C15: Mandatory if LE Controller supports transmitting scannable
777   // advertisements, otherwise excluded.
778   auto c15 = mandatory;
779   // C16: Mandatory if LE Feature (Periodic Advertising) is supported and the LE
780   // Controller supports both Scanning State and Synchronization State,
781   // otherwise excluded.
782   auto c16 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING));
783   // C17: Mandatory if LE Feature (Extended Advertising) is supported and the LE
784   // Controller supports Advertising State, otherwise excluded.
785   auto c17 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING));
786   // C18: Mandatory if LE Feature (Periodic Advertising) is supported and the LE
787   // Controller supports Advertising State, otherwise excluded.
788   auto c18 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING));
789   // C19: Mandatory if LE Feature (Extended Advertising) is supported and the LE
790   // Controller supports Scanning State, otherwise excluded.
791   auto c19 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING));
792   // C20: Mandatory if LE Feature (Extended Advertising) is supported and the LE
793   // Controller supports Initiating State, otherwise excluded.
794   auto c20 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING));
795   // C21: Mandatory if LE Feature (Periodic Advertising) is supported and the LE
796   // Controller supports Synchronization State, otherwise excluded.
797   auto c21 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING));
798   // C22: Mandatory if the LE Controller supports sending Transmit Power in
799   // advertisements or if LE Feature (LE Power Control Request) is supported,
800   // otherwise optional.
801   auto c22 = mandatory;
802   // C23: Mandatory if LE Feature (LE Channel Selection Algorithm #2) is
803   // supported, otherwise excluded.
804   //
805   // C24: Mandatory if the LE Controller supports
806   // Connection State and either LE Feature (LL Privacy) or LE Feature (Extended
807   // Advertising) is supported, otherwise optional if the LE Controller supports
808   // Connection State, otherwise excluded.
809   //
810   // C25: Mandatory if LE Feature
811   // (Connection CTE Request) is supported, otherwise excluded.
812   auto c25 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST));
813   // C26: Mandatory if LE Feature (Connection CTE Response) is supported,
814   // otherwise excluded.
815   auto c26 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE));
816   // C27: Mandatory if LE Feature (Connectionless CTE Transmitter) is supported,
817   // otherwise excluded.
818   auto c27 =
819           mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER));
820   // C28: Mandatory if LE Feature (Connectionless CTE Receiver) is supported,
821   // otherwise excluded.
822   auto c28 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER));
823   // C29: Mandatory if LE Feature (Connection CTE Response) or LE Feature
824   // (Connectionless CTE Transmitter) is supported, otherwise optional if the LE
825   // Controller supports transmitting packets, otherwise excluded.
826   auto c29 =
827           mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE) ||
828                                 SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER));
829   // C30: Mandatory if LE Feature (Connection CTE Request) or LE Feature
830   // (Connectionless CTE Receiver) is supported, otherwise optional if the LE
831   // Controller supports receiving packets, otherwise excluded.
832   auto c30 = mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST) ||
833                                    SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER));
834   // C31: Mandatory if LE Feature (Connection CTE Request) or LE Feature
835   // (Connection CTE Response) or LE Feature (Connectionless CTE Transmitter) or
836   // LE Feature (Connectionless CTE Receiver) is supported, otherwise excluded.
837   auto c31 =
838           mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST) ||
839                                 SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE) ||
840                                 SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER) ||
841                                 SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER));
842   // C32: Mandatory if LE Feature (Periodic Advertising Sync Transfer –
843   // Recipient) is supported, otherwise optional if LE Feature (Periodic
844   // Advertising) is supported and the LE Controller supports Synchronization
845   // State, otherwise excluded.
846   auto c32 = mandatory_or_optional_or_excluded(
847           SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT),
848           SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING));
849   // C33: Mandatory if LE Feature (Periodic Advertising Sync Transfer – Sender)
850   // is supported and the LE Controller supports Scanning State, otherwise
851   // excluded.
852   auto c33 = mandatory_or_excluded(
853           SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER));
854   // C34: Mandatory if LE Feature (Periodic Advertising Sync Transfer – Sender)
855   // is supported and the LE Controller supports Advertising State, otherwise
856   // excluded.
857   auto c34 = mandatory_or_excluded(
858           SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER));
859   // C35: Mandatory if LE Feature (Periodic Advertising Sync Transfer –
860   // Recipient) is supported, otherwise excluded.
861   auto c35 = mandatory_or_excluded(
862           SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT));
863   // C36: Mandatory if the LE Controller supports Central role or supports both
864   // Peripheral role and LE Feature (Channel Classification), otherwise optional
865   // if LE Feature (Extended Advertising) is supported and the LE Controller
866   // supports Advertising State or if LE Feature (Isochronous Broadcaster) is
867   // supported, otherwise excluded.
868   auto c36 = mandatory;
869   // C37: Mandatory if the LE Controller can change its sleep clock accuracy,
870   // otherwise excluded.
871   auto c37 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES));
872   // C38: Mandatory if LE Feature (Connected Isochronous Stream - Central) or
873   // LE Feature (Connected Isochronous Stream - Peripheral) is supported,
874   // otherwise excluded.
875   //
876   // C39: Mandatory if LE Feature (Connected Isochronous
877   // Stream - Central) is supported, otherwise excluded.
878   auto c39 = mandatory_or_excluded(
879           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL));
880   // C40: Mandatory if LE Feature (Connected Isochronous Stream - Peripheral) is
881   // supported, otherwise excluded.
882   auto c40 = mandatory_or_excluded(
883           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL));
884   // C41: Mandatory if LE Feature (Isochronous Broadcaster) is supported,
885   // otherwise excluded.
886   auto c41 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER));
887   // C42: Mandatory if LE Feature (Synchronized Receiver role) is supported,
888   // otherwise excluded.
889   auto c42 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER));
890   // C44: Mandatory if LE Feature (Sleep Clock Accuracy Updates) and either LE
891   // Feature (Connected Isochronous Stream - Central) or LE Feature (Connected
892   // Isochronous Stream - Peripheral) are supported, otherwise optional if LE
893   // Feature (Sleep Clock Accuracy Updates) is supported, otherwise excluded.
894   auto c44 = mandatory_or_optional_or_excluded(
895           SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES) &&
896                   (SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) ||
897                    SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL)),
898           SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES));
899   // C45: Mandatory if LE Feature (Connected Isochronous Stream - Central), or
900   // LE Feature (Connected Isochronous Stream - Peripheral), or
901   // LE Feature (Isochronous Broadcaster) is supported, otherwise excluded.
902   auto c45 = mandatory_or_excluded(
903           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) ||
904           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) ||
905           SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER));
906   // C46: Mandatory if LE Feature (Connected Isochronous Stream - Central), or
907   // LE Feature (Connected Isochronous Stream - Peripheral), or
908   // LE Feature (Synchronized Receiver role) is supported, otherwise excluded.
909   auto c46 = mandatory_or_excluded(
910           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) ||
911           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) ||
912           SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER));
913   // C47: Mandatory if LE Feature (Connected Isochronous Stream - Central), or
914   // LE Feature (Connected Isochronous Stream - Peripheral), or
915   // LE Feature (Isochronous Broadcaster), or
916   // LE Feature (Synchronized Receiver role) is supported, otherwise excluded.
917   auto c47 = mandatory_or_excluded(
918           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) ||
919           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) ||
920           SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER) ||
921           SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER));
922   // C49: Mandatory if LE Feature (Connected Isochronous Stream - Central) or
923   // LE Feature (Connected Isochronous Stream - Peripheral) or
924   // LE Feature (Connection Subrating) is supported, otherwise optional.
925   auto c49 = mandatory_or_optional(
926           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) ||
927           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) ||
928           SupportsLLFeature(LLFeaturesBits::CONNECTION_SUBRATING));
929   // C50: Optional if LE Feature (Connected Isochronous Stream - Central), or
930   // LE Feature (Connected Isochronous Stream - Peripheral), or
931   // LE Feature (Synchronized Receiver role) is supported, otherwise excluded.
932   auto c50 = optional_or_excluded(
933           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) ||
934           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) ||
935           SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER));
936   // C51: Mandatory if LE Feature (LE Power Control Request) is supported,
937   // otherwise excluded.
938   auto c51 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_POWER_CONTROL_REQUEST));
939   // C52: Mandatory if LE Feature (LE Path Loss Monitoring) is supported,
940   // otherwise excluded.
941   auto c52 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PATH_LOSS_MONITORING));
942   // C53: Mandatory if LE Feature (LE Power Control Request) is supported,
943   // otherwise optional if the LE Controller supports transmitting packets,
944   // otherwise excluded.
945   auto c53 = mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::LE_POWER_CONTROL_REQUEST));
946   // C54: Mandatory if LE Feature (Synchronized Receiver) is supported,
947   // otherwise optional.
948   //
949   // C55: Mandatory if LE Feature (Connected Isochronous
950   // Stream - Central), or LE Feature (Connected Isochronous Stream -
951   // Peripheral), or LE Feature (Isochronous Broadcaster) is supported,
952   // otherwise optional if the LE Controller supports Connection State,
953   // otherwise excluded.
954   auto c55 = mandatory_or_optional(
955           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) ||
956           SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) ||
957           SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER));
958   // C56: Optional if LE Feature (LE Encryption) is supported, otherwise
959   // excluded.
960   //
961   // C57: Mandatory if LE Feature (Connection Subrating) is supported,
962   // otherwise excluded.
963   auto c57 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_SUBRATING));
964   // C58: Mandatory if LE Feature (Channel Classification) is supported,
965   // otherwise excluded.
966   auto c58 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CHANNEL_CLASSIFICATION));
967   // C59: Mandatory if the LE Controller supports Central role, otherwise
968   // excluded.
969   auto c59 = mandatory;
970   // C60: Mandatory if the LE Controller supports Central role and LE Feature
971   // (LE Encryption), otherwise excluded.
972   auto c60 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION));
973   // C61: Mandatory if the LE Controller supports Peripheral role and LE Feature
974   // (LE Encryption), otherwise excluded.
975   auto c61 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION));
976   // C62: Mandatory if the LE Controller supports Central role or supports both
977   // Peripheral role and LE Feature (Connection Parameters Request Procedure),
978   // otherwise excluded.
979   auto c62 = mandatory;
980   // C63: Mandatory if the LE Controller supports Scanning state and LE Feature
981   // (LL Privacy), otherwise excluded.
982   //
983   // C64: Optional if the Controller supports
984   // transmitting packets, otherwise excluded.
985   auto c64 = optional;
986   // C94: Mandatory if the LE Create Connection or LE Extended Create Connection
987   // command is supported, otherwise excluded.
988   auto c94 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::LE_CREATE_CONNECTION) ||
989                                    SupportsCommand(OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V1));
990   // C95: Mandatory if the LE Request Peer SCA command is supported, otherwise
991   // excluded.
992   //
993   // C96: Optional if the LE Controller supports Connection State,
994   // otherwise excluded.
995   auto c96 = optional;
996   // C97: Mandatory if Advertising State is supported, otherwise excluded.
997   auto c97 = mandatory;
998   // C98: Mandatory if Scanning State is supported, otherwise excluded.
999   auto c98 = mandatory;
1000   // C99: Mandatory if LE Generate DHKey command [v2] is supported, otherwise
1001   // optional.
1002   auto c99 = mandatory_or_optional(SupportsCommand(OpCodeIndex::LE_GENERATE_DHKEY_V2));
1003   // C101: Mandatory if the Authentication Requested command is supported,
1004   // otherwise excluded.
1005   //
1006   // C102: Mandatory if the Change Connection Link Key command is supported,
1007   // otherwise excluded.
1008   //
1009   // C103: Mandatory if the Periodic
1010   // Inquiry Mode command is supported, otherwise excluded.
1011   auto c103 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::PERIODIC_INQUIRY_MODE));
1012   // C104: Mandatory if the Read Clock Offset command is supported, otherwise
1013   // excluded.
1014   //
1015   // C105: Mandatory if the Read Remote Version Information command is
1016   // supported, otherwise excluded.
1017   //
1018   // C106: Mandatory if the Remote Name Request
1019   // command is supported, otherwise excluded.
1020   auto c106 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::REMOTE_NAME_REQUEST));
1021   // C107: Mandatory if the Set Controller To Host Flow Control command is
1022   // supported, otherwise excluded.
1023   auto c107 =
1024           mandatory_or_excluded(SupportsCommand(OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL));
1025   // C108: Mandatory if the Set MWS_PATTERN Configuration command is supported,
1026   // otherwise optional.
1027   auto c108 = mandatory_or_optional(SupportsCommand(OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION));
1028   // C109: Mandatory if the Set MWS Signaling command is supported, otherwise
1029   // excluded.
1030   auto c109 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::SET_MWS_SIGNALING));
1031   // C110: Mandatory if the Set Triggered Clock Capture command is supported,
1032   // otherwise excluded.
1033   //
1034   // C111: Mandatory if the Write Authentication Enable
1035   // command is supported, otherwise excluded.
1036   auto c111 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_AUTHENTICATION_ENABLE));
1037   // C112: Mandatory if the Write Default Erroneous Data Reporting command is
1038   // supported, otherwise excluded.
1039   auto c112 = mandatory_or_excluded(
1040           SupportsCommand(OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING));
1041   // C113: Mandatory if the Write Extended Inquiry Length command is supported,
1042   // otherwise excluded.
1043   auto c113 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH));
1044   // C114: Mandatory if the Write Extended Page Timeout command is supported,
1045   // otherwise excluded.
1046   auto c114 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT));
1047   // C115: Mandatory if the Write Inquiry Mode command is supported, otherwise
1048   // excluded.
1049   auto c115 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_INQUIRY_MODE));
1050   // C116: Mandatory if the Write LE Host Support command is supported,
1051   // otherwise excluded.
1052   auto c116 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_LE_HOST_SUPPORT));
1053   // C117: Mandatory if the Write Link Supervision Timeout command is supported,
1054   // otherwise excluded.
1055   auto c117 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT));
1056   // C118: Mandatory if the Write Num Broadcast Retransmissions command is
1057   // supported, otherwise excluded.
1058   auto c118 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS));
1059   // C119: Mandatory if the Write Page Scan Type command is supported, otherwise
1060   // excluded.
1061   auto c119 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_PAGE_SCAN_TYPE));
1062   // C120: Mandatory if the Write PIN Type command is supported, otherwise
1063   // excluded.
1064   auto c120 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_PIN_TYPE));
1065   // C121: Mandatory if the Write Stored Link Key command is supported,
1066   // otherwise excluded.
1067   auto c121 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_STORED_LINK_KEY));
1068   // C122: Mandatory if the Write Synchronous Flow Control Enable command is
1069   // supported, otherwise excluded.
1070   auto c122 = mandatory_or_excluded(
1071           SupportsCommand(OpCodeIndex::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE));
1072   // C123: Mandatory if BR/EDR test mode is supported, otherwise excluded.
1073   auto c123 = mandatory;
1074   // C124: Mandatory if Data block based flow control is supported, otherwise
1075   // excluded.
1076   auto c124 = excluded;
1077   // C125: Mandatory if Inquiry Scan is supported, otherwise excluded.
1078   auto c125 = mandatory;
1079   // C126: Optional if Inquiry Scan is supported, otherwise excluded.
1080   //
1081   // C127: Mandatory if Inquiry is supported, otherwise excluded.
1082   auto c127 = mandatory;
1083   // C128: Optional if Inquiry is supported, otherwise excluded.
1084   auto c128 = optional;
1085   // C129: Mandatory if Truncated page state is supported, otherwise excluded.
1086   auto c129 = excluded;
1087   // C132: Mandatory if multi-slot ACL packets are is supported, otherwise
1088   // excluded.
1089   //
1090   // C133: Mandatory if HV2, HV3, or multi-slot or EDR ACL packets are
1091   // supported, otherwise excluded.
1092   auto c133 = mandatory_or_excluded(
1093           SupportsLMPFeature(LMPFeaturesPage0Bits::HV2_PACKETS) ||
1094           SupportsLMPFeature(LMPFeaturesPage0Bits::HV3_PACKETS) ||
1095           SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE) ||
1096           SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE) ||
1097           SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS));
1098   // C134: Mandatory if SCO or eSCO is supported, otherwise excluded.
1099   auto c134 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) ||
1100                                     SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK));
1101   // C135: Optional if SCO or eSCO is supported, otherwise excluded.
1102   auto c135 = optional_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) ||
1103                                    SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK));
1104   // C136: Optional if Slot Availability Mask is supported, otherwise excluded.
1105   auto c136 =
1106           optional_or_excluded(SupportsLMPFeature(LMPFeaturesPage2Bits::SLOT_AVAILABILITY_MASK));
1107   // C138: Mandatory if Secure Connections (Controller) is supported, otherwise
1108   // optional if eSCO is supported, otherwise excluded.
1109   auto c138 = mandatory_or_optional_or_excluded(
1110           SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT),
1111           SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK));
1112   // C139: Mandatory if the Controller is AFH capable in either role, otherwise
1113   // excluded.
1114   auto c139 =
1115           mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL) ||
1116                                 SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL));
1117   // C140: Mandatory if the Controller supports AFH classification in either
1118   // role or is an AFH capable Central, otherwise excluded.
1119   auto c140 = mandatory_or_excluded(
1120           SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL) ||
1121           SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_PERIPHERAL) ||
1122           SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL));
1123   // C141: Mandatory if Role Switch, Hold mode, or Sniff mode is supported,
1124   // otherwise excluded.
1125   auto c141 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::ROLE_SWITCH) ||
1126                                     SupportsLMPFeature(LMPFeaturesPage0Bits::HOLD_MODE) ||
1127                                     SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_MODE));
1128   // C142: Mandatory if Secure Connections (Host) is supported, otherwise
1129   // excluded.
1130   auto c142 = mandatory;
1131   // C143: Mandatory if Secure Connections (both Host and Controller) is
1132   // supported, otherwise excluded.
1133   auto c143 = mandatory_or_excluded(
1134           SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT));
1135   // C144: Mandatory if Hold Mode or Sniff Mode is supported, otherwise
1136   // excluded.
1137   //
1138   // C145: Mandatory if any event in event mask page 2 is supported,
1139   // otherwise optional.
1140   auto c145 = mandatory;
1141   // C146: Mandatory if the Extended Inquiry Result event or the IO Capability
1142   // Request event is supported, otherwise optional if Inquiry is supported,
1143   // otherwise excluded.
1144   auto c146 = mandatory;
1145   // C147: Optional if the Inquiry Result with RSSI event is supported,
1146   // otherwise excluded.
1147   //
1148   // C148: Optional if any of the Connection Complete,
1149   // Connection Request, Extended Inquiry Result, Inquiry Result with RSSI, IO
1150   // Capability Request, or Synchronous Connection Complete events is supported,
1151   // otherwise excluded.
1152   auto c148 = mandatory;
1153   // C151: Mandatory if Secure Connections (Controller) and Ping are supported,
1154   // otherwise excluded.
1155   auto c151 = mandatory_or_excluded(
1156           SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT) &&
1157           SupportsLMPFeature(LMPFeaturesPage2Bits::PING));
1158   // C152: Mandatory if Power Control is supported, otherwise optional.
1159   auto c152 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::POWER_CONTROL));
1160   // C153: Mandatory if LE supported in the Controller, otherwise optional.
1161   auto c153 =
1162           mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER));
1163   // C154: Mandatory if Interlaced Page Scan is supported, otherwise optional.
1164   auto c154 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN));
1165   // C155: Mandatory if the Write Authenticated Payload Timeout command is
1166   // supported, otherwise excluded.
1167   auto c155 =
1168           mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT));
1169   // C156: Mandatory if the Read Local Supported Codecs command [v2] is
1170   // supported, otherwise excluded.
1171   auto c156 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2));
1172   // C157: Mandatory if the Read Local Supported Codecs command [v2] is
1173   // supported, otherwise optional.
1174   auto c157 = mandatory_or_optional(SupportsCommand(OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2));
1175   // C158: Mandatory if the Set Min Encryption Key Size command is supported,
1176   // otherwise optional.
1177   //
1178   // C201: Mandatory if Connectionless Peripheral Broadcast - Transmitter is
1179   // supported, otherwise excluded.
1180   auto c201 = mandatory_or_excluded(SupportsLMPFeature(
1181           LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_TRANSMITTER_OPERATION));
1182   // C202: Mandatory if Connectionless Peripheral Broadcast - Receiver is
1183   // supported, otherwise excluded.
1184   auto c202 = mandatory_or_excluded(SupportsLMPFeature(
1185           LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVER_OPERATION));
1186   // C203: Mandatory if Synchronization Train is supported, otherwise excluded.
1187   auto c203 =
1188           mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_TRAIN));
1189   // C204: Mandatory if Synchronization Scan is supported, otherwise excluded.
1190   auto c204 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_SCAN));
1191   // C205: Mandatory if Extended Inquiry Response is supported, otherwise
1192   // excluded.
1193   auto c205 = mandatory_or_excluded(
1194           SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE));
1195   // C212: Mandatory if Role Switch is supported, otherwise excluded.
1196   auto c212 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::ROLE_SWITCH));
1197   // C213: Mandatory if Hold mode is supported, otherwise excluded.
1198   auto c213 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::HOLD_MODE));
1199   // C214: Mandatory if Sniff mode is supported, otherwise excluded.
1200   auto c214 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_MODE));
1201   // C215: Mandatory if Broadcast Encryption is supported, otherwise excluded.
1202   auto c215 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::BROADCAST_ENCRYPTION));
1203   // C217: Mandatory if BR/EDR Enhanced Power Control is supported, otherwise
1204   // excluded.
1205   auto c217 =
1206           mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL));
1207   // C218: Mandatory if Secure Connections (Controller) is supported, otherwise
1208   // excluded.
1209   auto c218 = mandatory_or_excluded(
1210           SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT));
1211   // C219: Mandatory if Slot Availability Mask is supported, otherwise excluded.
1212   // C220: Mandatory if LMP Extended Features mask is supported, otherwise
1213   // excluded.
1214   auto c220 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_FEATURES));
1215   // C221: Mandatory if Sniff subrating is supported, otherwise excluded.
1216   auto c221 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_SUBRATING));
1217 
1218 #define check_command_(op_code, br_requirement, le_requirement)                                \
1219   {                                                                                            \
1220     bool command_supported = SupportsCommand(bluetooth::hci::OpCodeIndex::op_code);            \
1221     if (!check_command_requirement(br_supported, br_requirement, le_supported, le_requirement, \
1222                                    command_supported)) {                                       \
1223       INFO(#op_code " command validation failed (" #br_requirement "," #le_requirement ")");   \
1224     }                                                                                          \
1225   }
1226 
1227   // Table 3.1: Alphabetical list of commands and events (Sheet 1 of 49)
1228   check_command_(ACCEPT_CONNECTION_REQUEST, mandatory, excluded);
1229   check_command_(ACCEPT_SYNCHRONOUS_CONNECTION, c134, excluded);
1230   // Table 3.1: Alphabetical list of commands and events (Sheet 2 of 49)
1231   check_command_(CHANGE_CONNECTION_PACKET_TYPE, c133, excluded);
1232   check_command_(CONFIGURE_DATA_PATH, c156, c156);
1233   // Table 3.1: Alphabetical list of commands and events (Sheet 3 of 49)
1234   check_command_(CREATE_CONNECTION_CANCEL, mandatory, excluded);
1235   // Table 3.1: Alphabetical list of commands and events (Sheet 4 of 49)
1236   check_command_(CREATE_CONNECTION, mandatory, excluded);
1237   check_command_(DELETE_RESERVED_LT_ADDR, c201, excluded);
1238   check_command_(DELETE_STORED_LINK_KEY, c121, excluded);
1239   check_command_(DISCONNECT, mandatory, c3);
1240   check_command_(ENABLE_IMPLEMENTATION_UNDER_TEST_MODE, c123, excluded);
1241   // Table 3.1: Alphabetical list of commands and events (Sheet 5 of 49)
1242   check_command_(ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, c135, excluded);
1243   check_command_(ENHANCED_FLUSH, mandatory, excluded);
1244   check_command_(ENHANCED_SETUP_SYNCHRONOUS_CONNECTION, c135, excluded);
1245   check_command_(EXIT_PERIODIC_INQUIRY_MODE, c103, excluded);
1246   check_command_(EXIT_SNIFF_MODE, c214, excluded);
1247   // Table 3.1: Alphabetical list of commands and events (Sheet 6 of 49)
1248   check_command_(FLOW_SPECIFICATION, mandatory, excluded);
1249   check_command_(FLUSH, mandatory, excluded);
1250   check_command_(GET_MWS_TRANSPORT_LAYER_CONFIGURATION, c109, c109);
1251   check_command_(HOLD_MODE, c213, excluded);
1252   check_command_(HOST_BUFFER_SIZE, c107, c107);
1253   // Table 3.1: Alphabetical list of commands and events (Sheet 7 of 49)
1254   check_command_(HOST_NUMBER_OF_COMPLETED_PACKETS, c107, c107);
1255   check_command_(INQUIRY_CANCEL, c127, excluded);
1256   check_command_(INQUIRY, c127, excluded);
1257   check_command_(IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, mandatory, excluded);
1258   // Table 3.1: Alphabetical list of commands and events (Sheet 8 of 49)
1259   check_command_(IO_CAPABILITY_REQUEST_REPLY, mandatory, excluded);
1260   check_command_(LE_ACCEPT_CIS_REQUEST, excluded, c40);
1261   check_command_(LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST, excluded, mandatory);
1262   check_command_(LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, excluded, c21);
1263   check_command_(LE_ADD_DEVICE_TO_RESOLVING_LIST, excluded, c9);
1264   // Table 3.1: Alphabetical list of commands and events (Sheet 9 of 49)
1265   check_command_(LE_BIG_CREATE_SYNC, excluded, c42);
1266   check_command_(LE_BIG_TERMINATE_SYNC, excluded, c42);
1267   check_command_(LE_CLEAR_ADVERTISING_SETS, excluded, c17);
1268   check_command_(LE_CLEAR_FILTER_ACCEPT_LIST, excluded, mandatory);
1269   check_command_(LE_CLEAR_PERIODIC_ADVERTISER_LIST, excluded, c21);
1270   check_command_(LE_CLEAR_RESOLVING_LIST, excluded, c9);
1271   // Table 3.1: Alphabetical list of commands and events (Sheet 10 of 49)
1272   check_command_(LE_CONNECTION_CTE_REQUEST_ENABLE, excluded, c25);
1273   check_command_(LE_CONNECTION_CTE_RESPONSE_ENABLE, excluded, c26);
1274   check_command_(LE_CONNECTION_UPDATE, excluded, c62);
1275   check_command_(LE_CREATE_BIG, excluded, c41);
1276   // Table 3.1: Alphabetical list of commands and events (Sheet 11 of 49)
1277   check_command_(LE_CREATE_BIG_TEST, excluded, c41);
1278   check_command_(LE_CREATE_CIS, excluded, c39);
1279   check_command_(LE_CREATE_CONNECTION_CANCEL, excluded, c94);
1280   check_command_(LE_CREATE_CONNECTION, excluded, c59);
1281   check_command_(LE_START_ENCRYPTION, excluded, c60);
1282   check_command_(LE_ENCRYPT, excluded, c4);
1283   // Table 3.1: Alphabetical list of commands and events (Sheet 12 of 49)
1284   check_command_(LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL, excluded, c51);
1285   check_command_(LE_EXTENDED_CREATE_CONNECTION_V1, excluded, c20);
1286   check_command_(LE_GENERATE_DHKEY_V1, excluded, c99);
1287   check_command_(LE_GENERATE_DHKEY_V2, excluded, optional);
1288   check_command_(LE_ISO_READ_TEST_COUNTERS, excluded, c46);
1289   check_command_(LE_ISO_RECEIVE_TEST, excluded, c46);
1290   check_command_(LE_ISO_TEST_END, excluded, c47);
1291   // Table 3.1: Alphabetical list of commands and events (Sheet 13 of 49)
1292   check_command_(LE_ISO_TRANSMIT_TEST, excluded, c45);
1293   check_command_(LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY, excluded, c61);
1294   check_command_(LE_LONG_TERM_KEY_REQUEST_REPLY, excluded, c61);
1295   check_command_(LE_MODIFY_SLEEP_CLOCK_ACCURACY, excluded, c37);
1296   check_command_(LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, excluded, c16);
1297   check_command_(LE_PERIODIC_ADVERTISING_CREATE_SYNC, excluded, c16);
1298   // Table 3.1: Alphabetical list of commands and events (Sheet 14 of 49)
1299   check_command_(LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, excluded, c34);
1300   check_command_(LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, excluded, c33);
1301   check_command_(LE_PERIODIC_ADVERTISING_TERMINATE_SYNC, excluded, c21);
1302   check_command_(LE_RAND, excluded, c4);
1303   check_command_(LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER, excluded, c97);
1304   // Table 3.1: Alphabetical list of commands and events (Sheet 15 of 49)
1305   check_command_(LE_READ_ANTENNA_INFORMATION, excluded, c31);
1306   check_command_(LE_READ_BUFFER_SIZE_V1, excluded, c3);
1307   check_command_(LE_READ_BUFFER_SIZE_V2, excluded, c55);
1308   check_command_(LE_READ_CHANNEL_MAP, excluded, c3);
1309   check_command_(LE_READ_FILTER_ACCEPT_LIST_SIZE, excluded, mandatory);
1310   check_command_(LE_READ_ISO_LINK_QUALITY, excluded, c50);
1311   check_command_(LE_READ_ISO_TX_SYNC, excluded, c45);
1312   check_command_(LE_READ_LOCAL_RESOLVABLE_ADDRESS, excluded, c10);
1313   // Table 3.1: Alphabetical list of commands and events (Sheet 16 of 49)
1314   check_command_(LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0, excluded, mandatory);
1315   check_command_(LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, excluded, c17);
1316   check_command_(LE_READ_MAXIMUM_DATA_LENGTH, excluded, c8);
1317   check_command_(LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, excluded, c17);
1318   check_command_(LE_READ_PEER_RESOLVABLE_ADDRESS, excluded, c10);
1319   check_command_(LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, excluded, c21);
1320   check_command_(LE_READ_PHY, excluded, c11);
1321   check_command_(LE_READ_REMOTE_FEATURES_PAGE_0, excluded, c3);
1322   // Table 3.1: Alphabetical list of commands and events (Sheet 17 of 49)
1323   check_command_(LE_READ_REMOTE_TRANSMIT_POWER_LEVEL, excluded, c51);
1324   check_command_(LE_READ_RESOLVING_LIST_SIZE, excluded, c9);
1325   check_command_(LE_READ_RF_PATH_COMPENSATION_POWER, excluded, c22);
1326   check_command_(LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, excluded, c8);
1327   check_command_(LE_READ_SUPPORTED_STATES, excluded, mandatory);
1328   check_command_(LE_READ_TRANSMIT_POWER, excluded, c64);
1329   check_command_(LE_RECEIVER_TEST_V1, excluded, c2);
1330   check_command_(LE_RECEIVER_TEST_V2, excluded, c13);
1331   check_command_(LE_RECEIVER_TEST_V3, excluded, c30);
1332   // Table 3.1: Alphabetical list of commands and events (Sheet 18 of 49)
1333   check_command_(LE_REJECT_CIS_REQUEST, excluded, c40);
1334   check_command_(LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, excluded, c6);
1335   check_command_(LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, excluded, c6);
1336   check_command_(LE_REMOVE_ADVERTISING_SET, excluded, c17);
1337   check_command_(LE_REMOVE_CIG, excluded, c39);
1338   check_command_(LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, excluded, mandatory);
1339   check_command_(LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, excluded, c21);
1340   check_command_(LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, excluded, c9);
1341   // Table 3.1: Alphabetical list of commands and events (Sheet 19 of 49)
1342   check_command_(LE_REMOVE_ISO_DATA_PATH, excluded, c47);
1343   check_command_(LE_REQUEST_PEER_SCA, excluded, c44);
1344   check_command_(LE_SET_ADDRESS_RESOLUTION_ENABLE, excluded, c9);
1345   check_command_(LE_SET_ADVERTISING_DATA, excluded, c97);
1346   check_command_(LE_SET_ADVERTISING_ENABLE, excluded, c97);
1347   check_command_(LE_SET_ADVERTISING_PARAMETERS, excluded, c97);
1348   check_command_(LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, excluded, c17);
1349   check_command_(LE_SET_CIG_PARAMETERS, excluded, c39);
1350   // Table 3.1: Alphabetical list of commands and events (Sheet 20 of 49)
1351   check_command_(LE_SET_CIG_PARAMETERS_TEST, excluded, c39);
1352   check_command_(LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS, excluded, c25);
1353   check_command_(LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS, excluded, c26);
1354   check_command_(LE_SET_CONNECTIONLESS_CTE_TRANSMIT_ENABLE, excluded, c27);
1355   check_command_(LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS, excluded, c27);
1356   check_command_(LE_SET_CONNECTIONLESS_IQ_SAMPLING_ENABLE, excluded, c28);
1357   check_command_(LE_SET_DATA_LENGTH, excluded, c8);
1358   // Table 3.1: Alphabetical list of commands and events (Sheet 21 of 49)
1359   check_command_(LE_SET_DATA_RELATED_ADDRESS_CHANGES, excluded, c10);
1360   check_command_(LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, excluded, c35);
1361   check_command_(LE_SET_DEFAULT_PHY, excluded, c11);
1362   check_command_(LE_SET_DEFAULT_SUBRATE, excluded, c57);
1363   check_command_(LE_SET_EVENT_MASK, excluded, mandatory);
1364   check_command_(LE_SET_EXTENDED_ADVERTISING_DATA, excluded, c17);
1365   check_command_(LE_SET_EXTENDED_ADVERTISING_ENABLE, excluded, c17);
1366   check_command_(LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1, excluded, c17);
1367   check_command_(LE_SET_EXTENDED_SCAN_ENABLE, excluded, c19);
1368   // Table 3.1: Alphabetical list of commands and events (Sheet 22 of 49)
1369   check_command_(LE_SET_EXTENDED_SCAN_PARAMETERS, excluded, c19);
1370   check_command_(LE_SET_EXTENDED_SCAN_RESPONSE_DATA, excluded, c17);
1371   check_command_(LE_SET_HOST_CHANNEL_CLASSIFICATION, excluded, c36);
1372   check_command_(LE_SET_HOST_FEATURE_V1, excluded, c49);
1373   check_command_(LE_SET_PATH_LOSS_REPORTING_ENABLE, excluded, c52);
1374   check_command_(LE_SET_PATH_LOSS_REPORTING_PARAMETERS, excluded, c52);
1375   check_command_(LE_SET_PERIODIC_ADVERTISING_DATA, excluded, c18);
1376   check_command_(LE_SET_PERIODIC_ADVERTISING_ENABLE, excluded, c18);
1377   check_command_(LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1, excluded, c18);
1378   // Table 3.1: Alphabetical list of commands and events (Sheet 23 of 49)
1379   check_command_(LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, excluded, c32);
1380   check_command_(LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, excluded, c35);
1381   check_command_(LE_SET_PHY, excluded, c11);
1382   check_command_(LE_SET_PRIVACY_MODE, excluded, c9);
1383   check_command_(LE_SET_RANDOM_ADDRESS, excluded, c1);
1384   check_command_(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, excluded, c9);
1385   check_command_(LE_SET_SCAN_ENABLE, excluded, c98);
1386   check_command_(LE_SET_SCAN_PARAMETERS, excluded, c98);
1387   check_command_(LE_SET_SCAN_RESPONSE_DATA, excluded, c15);
1388   // Table 3.1: Alphabetical list of commands and events (Sheet 24 of 49)
1389   check_command_(LE_SET_TRANSMIT_POWER_REPORTING_ENABLE, excluded, c51);
1390   check_command_(LE_SETUP_ISO_DATA_PATH, excluded, c47);
1391   check_command_(LE_SUBRATE_REQUEST, excluded, c57);
1392   check_command_(LE_TERMINATE_BIG, excluded, c41);
1393   check_command_(LE_TEST_END, excluded, mandatory);
1394   check_command_(LE_TRANSMITTER_TEST_V1, excluded, c1);
1395   check_command_(LE_TRANSMITTER_TEST_V2, excluded, c12);
1396   check_command_(LE_TRANSMITTER_TEST_V3, excluded, c29);
1397   check_command_(LE_TRANSMITTER_TEST_V4, excluded, c53);
1398   // Table 3.1: Alphabetical list of commands and events (Sheet 25 of 49)
1399   check_command_(LE_WRITE_RF_PATH_COMPENSATION_POWER, excluded, c22);
1400   check_command_(LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, excluded, c8);
1401   check_command_(LINK_KEY_REQUEST_NEGATIVE_REPLY, mandatory, excluded);
1402   check_command_(LINK_KEY_REQUEST_REPLY, mandatory, excluded);
1403   check_command_(CENTRAL_LINK_KEY, c215, excluded);
1404   // Table 3.1: Alphabetical list of commands and events (Sheet 26 of 49)
1405   // Table 3.1: Alphabetical list of commands and events (Sheet 27 of 49)
1406   check_command_(PERIODIC_INQUIRY_MODE, c128, excluded);
1407   check_command_(PIN_CODE_REQUEST_NEGATIVE_REPLY, mandatory, excluded);
1408   check_command_(PIN_CODE_REQUEST_REPLY, mandatory, excluded);
1409   check_command_(QOS_SETUP, mandatory, excluded);
1410   check_command_(READ_AFH_CHANNEL_ASSESSMENT_MODE, c140, c58);
1411   // Table 3.1: Alphabetical list of commands and events (Sheet 28 of 49)
1412   check_command_(READ_AFH_CHANNEL_MAP, c139, excluded);
1413   check_command_(READ_AUTHENTICATED_PAYLOAD_TIMEOUT, c155, c155);
1414   check_command_(READ_AUTHENTICATION_ENABLE, c111, excluded);
1415   check_command_(READ_AUTOMATIC_FLUSH_TIMEOUT, mandatory, excluded);
1416   check_command_(READ_BD_ADDR, mandatory, mandatory);
1417   check_command_(READ_BUFFER_SIZE, mandatory, excluded);
1418   check_command_(READ_CLASS_OF_DEVICE, mandatory, excluded);
1419   check_command_(READ_CLOCK, optional, excluded);
1420   // Table 3.1: Alphabetical list of commands and events (Sheet 29 of 49)
1421   check_command_(READ_CLOCK_OFFSET, optional, excluded);
1422   check_command_(READ_CONNECTION_ACCEPT_TIMEOUT, mandatory, c40);
1423   check_command_(READ_CURRENT_IAC_LAP, c125, excluded);
1424   check_command_(READ_DATA_BLOCK_SIZE, c124, excluded);
1425   check_command_(READ_DEFAULT_ERRONEOUS_DATA_REPORTING, c112, excluded);
1426   check_command_(READ_DEFAULT_LINK_POLICY_SETTINGS, c141, excluded);
1427   // Table 3.1: Alphabetical list of commands and events (Sheet 30 of 49)
1428   check_command_(READ_ENCRYPTION_KEY_SIZE, mandatory, excluded);
1429   check_command_(READ_ENHANCED_TRANSMIT_POWER_LEVEL, c217, excluded);
1430   check_command_(READ_EXTENDED_INQUIRY_LENGTH, c113, excluded);
1431   check_command_(READ_EXTENDED_INQUIRY_RESPONSE, c205, excluded);
1432   check_command_(READ_EXTENDED_PAGE_TIMEOUT, c114, excluded);
1433   check_command_(READ_FAILED_CONTACT_COUNTER, mandatory, excluded);
1434   check_command_(READ_FLOW_CONTROL_MODE, c124, excluded);
1435   check_command_(READ_HOLD_MODE_ACTIVITY, c213, excluded);
1436   check_command_(READ_INQUIRY_MODE, c115, excluded);
1437   // Table 3.1: Alphabetical list of commands and events (Sheet 31 of 49)
1438   check_command_(READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL, c125, excluded);
1439   check_command_(READ_INQUIRY_SCAN_ACTIVITY, c125, excluded);
1440   check_command_(READ_INQUIRY_SCAN_TYPE, c125, excluded);
1441   check_command_(READ_LE_HOST_SUPPORT, c116, c116);
1442   check_command_(READ_LINK_POLICY_SETTINGS, c141, excluded);
1443   check_command_(READ_LINK_QUALITY, optional, excluded);
1444   // Table 3.1: Alphabetical list of commands and events (Sheet 32 of 49)
1445   check_command_(READ_LINK_SUPERVISION_TIMEOUT, c117, excluded);
1446   check_command_(READ_LMP_HANDLE, c134, excluded);
1447   check_command_(READ_LOCAL_EXTENDED_FEATURES, c220, excluded);
1448   check_command_(READ_LOCAL_NAME, mandatory, excluded);
1449   check_command_(READ_LOCAL_OOB_DATA, mandatory, excluded);
1450   check_command_(READ_LOCAL_OOB_EXTENDED_DATA, c142, excluded);
1451   check_command_(READ_LOCAL_SIMPLE_PAIRING_OPTIONS, optional, excluded);
1452   check_command_(READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES, c156, c156);
1453   check_command_(READ_LOCAL_SUPPORTED_CODECS_V1, c157, excluded);
1454   check_command_(READ_LOCAL_SUPPORTED_CODECS_V2, optional, optional);
1455   // Table 3.1: Alphabetical list of commands and events (Sheet 33 of 49)
1456   // check_command_(READ_LOCAL_SUPPORTED_COMMANDS, mandatory, mandatory);
1457   check_command_(READ_LOCAL_SUPPORTED_CONTROLLER_DELAY, c156, c156);
1458   check_command_(READ_LOCAL_SUPPORTED_FEATURES, mandatory, mandatory);
1459   check_command_(READ_LOCAL_VERSION_INFORMATION, mandatory, mandatory);
1460   check_command_(READ_LOOPBACK_MODE, c123, excluded);
1461   check_command_(READ_NUM_BROADCAST_RETRANSMITS, c118, excluded);
1462   check_command_(READ_NUMBER_OF_SUPPORTED_IAC, c125, excluded);
1463   check_command_(READ_PAGE_SCAN_ACTIVITY, mandatory, excluded);
1464   // Table 3.1: Alphabetical list of commands and events (Sheet 34 of 49)
1465   check_command_(READ_PAGE_SCAN_TYPE, c119, excluded);
1466   check_command_(READ_PAGE_TIMEOUT, mandatory, excluded);
1467   check_command_(READ_PIN_TYPE, c120, excluded);
1468   check_command_(READ_REMOTE_EXTENDED_FEATURES, c220, excluded);
1469   check_command_(READ_REMOTE_SUPPORTED_FEATURES, mandatory, excluded);
1470   // Table 3.1: Alphabetical list of commands and events (Sheet 35 of 49)
1471   check_command_(READ_REMOTE_VERSION_INFORMATION, optional, c3);
1472   check_command_(READ_RSSI, optional, c3);
1473   check_command_(READ_SCAN_ENABLE, mandatory, excluded);
1474   check_command_(READ_SECURE_CONNECTIONS_HOST_SUPPORT, c218, excluded);
1475   check_command_(READ_SIMPLE_PAIRING_MODE, mandatory, excluded);
1476   check_command_(READ_STORED_LINK_KEY, c121, excluded);
1477   check_command_(READ_SYNCHRONIZATION_TRAIN_PARAMETERS, c203, excluded);
1478   // Table 3.1: Alphabetical list of commands and events (Sheet 36 of 49)
1479   check_command_(READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, c122, excluded);
1480   check_command_(READ_TRANSMIT_POWER_LEVEL, c152, c3);
1481   check_command_(READ_VOICE_SETTING, c134, excluded);
1482   check_command_(RECEIVE_SYNCHRONIZATION_TRAIN, c204, excluded);
1483   check_command_(REFRESH_ENCRYPTION_KEY, mandatory, excluded);
1484   check_command_(REJECT_CONNECTION_REQUEST, mandatory, excluded);
1485   check_command_(REJECT_SYNCHRONOUS_CONNECTION, c134, excluded);
1486   // Table 3.1: Alphabetical list of commands and events (Sheet 37 of 49)
1487   check_command_(REMOTE_NAME_REQUEST_CANCEL, c106, excluded);
1488   check_command_(REMOTE_NAME_REQUEST, optional, excluded);
1489   check_command_(REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, mandatory, excluded);
1490   check_command_(REMOTE_OOB_DATA_REQUEST_REPLY, mandatory, excluded);
1491   check_command_(REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY, c143, excluded);
1492   check_command_(RESET, mandatory, mandatory);
1493   // Table 3.1: Alphabetical list of commands and events (Sheet 38 of 49)
1494   check_command_(RESET_FAILED_CONTACT_COUNTER, mandatory, excluded);
1495   check_command_(ROLE_DISCOVERY, optional, excluded);
1496   check_command_(SEND_KEYPRESS_NOTIFICATION, mandatory, excluded);
1497   check_command_(SET_AFH_HOST_CHANNEL_CLASSIFICATION, c140, excluded);
1498   check_command_(SET_CONNECTION_ENCRYPTION, mandatory, excluded);
1499   // Table 3.1: Alphabetical list of commands and events (Sheet 39 of 49)
1500   check_command_(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST, c201, excluded);
1501   check_command_(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA, c201, excluded);
1502   check_command_(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, c202, excluded);
1503   check_command_(SET_CONTROLLER_TO_HOST_FLOW_CONTROL, optional, c96);
1504   check_command_(SET_ECOSYSTEM_BASE_INTERVAL, optional, optional);
1505   check_command_(SET_EVENT_FILTER, c148, excluded);
1506   check_command_(SET_EVENT_MASK, mandatory, mandatory);
1507   check_command_(SET_EVENT_MASK_PAGE_2, c145, c145);
1508   // Table 3.1: Alphabetical list of commands and events (Sheet 40 of 49)
1509   check_command_(SET_EXTERNAL_FRAME_CONFIGURATION, c108, optional);
1510   check_command_(SET_MIN_ENCRYPTION_KEY_SIZE, optional, excluded);
1511   check_command_(SET_MWS_CHANNEL_PARAMETERS, optional, optional);
1512   check_command_(SET_MWS_SCAN_FREQUENCY_TABLE, optional, optional);
1513   check_command_(SET_MWS_SIGNALING, optional, optional);
1514   check_command_(SET_MWS_TRANSPORT_LAYER, c109, c109);
1515   check_command_(SET_MWS_PATTERN_CONFIGURATION, c136, excluded);
1516   check_command_(SET_RESERVED_LT_ADDR, c201, excluded);
1517   check_command_(SET_TRIGGERED_CLOCK_CAPTURE, optional, excluded);
1518   // Table 3.1: Alphabetical list of commands and events (Sheet 41 of 49)
1519   check_command_(SETUP_SYNCHRONOUS_CONNECTION, c134, excluded);
1520   check_command_(SNIFF_MODE, c214, excluded);
1521   check_command_(SNIFF_SUBRATING, c221, excluded);
1522   check_command_(START_SYNCHRONIZATION_TRAIN, c203, excluded);
1523   check_command_(SWITCH_ROLE, c212, excluded);
1524   // Table 3.1: Alphabetical list of commands and events (Sheet 42 of 49)
1525   check_command_(TRUNCATED_PAGE_CANCEL, c129, excluded);
1526   check_command_(TRUNCATED_PAGE, c129, excluded);
1527   check_command_(USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, mandatory, excluded);
1528   // Table 3.1: Alphabetical list of commands and events (Sheet 43 of 49)
1529   check_command_(USER_CONFIRMATION_REQUEST_REPLY, mandatory, excluded);
1530   check_command_(USER_PASSKEY_REQUEST_NEGATIVE_REPLY, mandatory, excluded);
1531   check_command_(USER_PASSKEY_REQUEST_REPLY, mandatory, excluded);
1532   check_command_(WRITE_AFH_CHANNEL_ASSESSMENT_MODE, c140, c58);
1533   // Table 3.1: Alphabetical list of commands and events (Sheet 44 of 49)
1534   check_command_(WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT, c151, c7);
1535   check_command_(WRITE_AUTHENTICATION_ENABLE, optional, excluded);
1536   check_command_(WRITE_AUTOMATIC_FLUSH_TIMEOUT, mandatory, excluded);
1537   check_command_(WRITE_CLASS_OF_DEVICE, mandatory, excluded);
1538   check_command_(WRITE_CONNECTION_ACCEPT_TIMEOUT, mandatory, c40);
1539   check_command_(WRITE_CURRENT_IAC_LAP, c125, excluded);
1540   // Table 3.1: Alphabetical list of commands and events (Sheet 45 of 49)
1541   check_command_(WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, c135, excluded);
1542   check_command_(WRITE_DEFAULT_LINK_POLICY_SETTINGS, c141, excluded);
1543   check_command_(WRITE_EXTENDED_INQUIRY_LENGTH, c128, excluded);
1544   check_command_(WRITE_EXTENDED_INQUIRY_RESPONSE, c205, excluded);
1545   check_command_(WRITE_EXTENDED_PAGE_TIMEOUT, optional, excluded);
1546   check_command_(WRITE_FLOW_CONTROL_MODE, c124, excluded);
1547   check_command_(WRITE_HOLD_MODE_ACTIVITY, c213, excluded);
1548   check_command_(WRITE_INQUIRY_MODE, c146, excluded);
1549   // Table 3.1: Alphabetical list of commands and events (Sheet 46 of 49)
1550   check_command_(WRITE_INQUIRY_SCAN_ACTIVITY, c125, excluded);
1551   check_command_(WRITE_INQUIRY_SCAN_TYPE, c125, excluded);
1552   check_command_(WRITE_INQUIRY_TRANSMIT_POWER_LEVEL, c127, excluded);
1553   check_command_(WRITE_LE_HOST_SUPPORT, c153, optional);
1554   check_command_(WRITE_LINK_POLICY_SETTINGS, c141, excluded);
1555   check_command_(WRITE_LINK_SUPERVISION_TIMEOUT, optional, excluded);
1556   check_command_(WRITE_LOCAL_NAME, mandatory, excluded);
1557   // Table 3.1: Alphabetical list of commands and events (Sheet 47 of 49)
1558   check_command_(WRITE_LOOPBACK_MODE, c123, excluded);
1559   check_command_(WRITE_NUM_BROADCAST_RETRANSMITS, optional, excluded);
1560   check_command_(WRITE_PAGE_SCAN_ACTIVITY, mandatory, excluded);
1561   check_command_(WRITE_PAGE_SCAN_TYPE, c154, excluded);
1562   check_command_(WRITE_PAGE_TIMEOUT, mandatory, excluded);
1563   check_command_(WRITE_PIN_TYPE, optional, excluded);
1564   // Table 3.1: Alphabetical list of commands and events (Sheet 48 of 49)
1565   check_command_(WRITE_SCAN_ENABLE, mandatory, excluded);
1566   check_command_(WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, c218, excluded);
1567   check_command_(WRITE_SECURE_CONNECTIONS_TEST_MODE, c138, excluded);
1568   check_command_(WRITE_SIMPLE_PAIRING_DEBUG_MODE, mandatory, excluded);
1569   check_command_(WRITE_SIMPLE_PAIRING_MODE, mandatory, excluded);
1570   check_command_(WRITE_STORED_LINK_KEY, optional, excluded);
1571   check_command_(WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS, c203, excluded);
1572   // Table 3.1: Alphabetical list of commands and events (Sheet 49 of 49)
1573   check_command_(WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, c135, excluded);
1574   check_command_(WRITE_VOICE_SETTING, c134, excluded);
1575   return true;
1576 }
1577 
ControllerProperties()1578 ControllerProperties::ControllerProperties()
1579     : supported_commands(SupportedCommands()),
1580       lmp_features({Page0LmpFeatures(), 0, Page2LmpFeatures()}),
1581       le_features(LlFeatures()) {
1582   if (!CheckSupportedFeatures()) {
1583     INFO("Warning: initial LMP and/or LE are not consistent. Please make sure"
1584          " that the features are correct w.r.t. the rules described"
1585          " in Vol 2, Part C 3.5 Feature requirements");
1586   }
1587 
1588   if (!CheckSupportedCommands()) {
1589     INFO("Warning: initial supported commands are not consistent. Please make"
1590          " sure that the supported commands are correct w.r.t. the rules"
1591          " described in Vol 4, Part E § 3 Overview of commands and events");
1592   }
1593 }
1594 
1595 // Commands enabled by the LE Extended Advertising feature bit.
1596 static std::vector<OpCodeIndex> le_extended_advertising_commands_ = {
1597         OpCodeIndex::LE_CLEAR_ADVERTISING_SETS,
1598         OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V1,
1599         OpCodeIndex::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH,
1600         OpCodeIndex::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS,
1601         OpCodeIndex::LE_RECEIVER_TEST_V2,
1602         OpCodeIndex::LE_REMOVE_ADVERTISING_SET,
1603         OpCodeIndex::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS,
1604         OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES,
1605         OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA,
1606         OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_ENABLE,
1607         OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1,
1608         OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE,
1609         OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS,
1610         OpCodeIndex::LE_SET_EXTENDED_SCAN_RESPONSE_DATA,
1611 };
1612 
1613 // Commands enabled by the LE Periodic Advertising feature bit.
1614 static std::vector<OpCodeIndex> le_periodic_advertising_commands_ = {
1615         OpCodeIndex::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST,
1616         OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST,
1617         OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL,
1618         OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC,
1619         OpCodeIndex::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC,
1620         OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE,
1621         OpCodeIndex::LE_RECEIVER_TEST_V2,
1622         OpCodeIndex::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST,
1623         OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES,
1624         OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA,
1625         OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_ENABLE,
1626         OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1,
1627 };
1628 
1629 // Commands enabled by the LL Privacy feature bit.
1630 static std::vector<OpCodeIndex> ll_privacy_commands_ = {
1631         OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST,
1632         OpCodeIndex::LE_CLEAR_RESOLVING_LIST,
1633         OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS,
1634         OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS,
1635         OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE,
1636         OpCodeIndex::LE_RECEIVER_TEST_V2,
1637         OpCodeIndex::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST,
1638         OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE,
1639         OpCodeIndex::LE_SET_PRIVACY_MODE,
1640         OpCodeIndex::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT,
1641 };
1642 
1643 // Commands enabled by the LL Connected Isochronous Stream feature bit.
1644 // Central and Peripheral support bits are enabled together.
1645 static std::vector<OpCodeIndex> ll_connected_isochronous_stream_commands_ = {
1646         OpCodeIndex::LE_SET_CIG_PARAMETERS,  OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST,
1647         OpCodeIndex::LE_CREATE_CIS,          OpCodeIndex::LE_REMOVE_CIG,
1648         OpCodeIndex::LE_ACCEPT_CIS_REQUEST,  OpCodeIndex::LE_REJECT_CIS_REQUEST,
1649         OpCodeIndex::LE_SETUP_ISO_DATA_PATH, OpCodeIndex::LE_REMOVE_ISO_DATA_PATH,
1650         OpCodeIndex::LE_REQUEST_PEER_SCA,
1651 };
1652 
SetLLFeatureBit(uint64_t & le_features,LLFeaturesBits bit,bool set)1653 static void SetLLFeatureBit(uint64_t& le_features, LLFeaturesBits bit, bool set) {
1654   if (set) {
1655     le_features |= static_cast<uint64_t>(bit);
1656   } else {
1657     le_features &= ~static_cast<uint64_t>(bit);
1658   }
1659 }
1660 
SetSupportedCommandBits(std::array<uint8_t,64> & supported_commands,std::vector<OpCodeIndex> const & commands,bool set)1661 static void SetSupportedCommandBits(std::array<uint8_t, 64>& supported_commands,
1662                                     std::vector<OpCodeIndex> const& commands, bool set) {
1663   for (auto command : commands) {
1664     int index = static_cast<int>(command);
1665     if (set) {
1666       supported_commands[index / 10] |= 1U << (index % 10);
1667     } else {
1668       supported_commands[index / 10] &= ~(1U << (index % 10));
1669     }
1670   }
1671 }
1672 
ControllerProperties(rootcanal::configuration::Controller const & config)1673 ControllerProperties::ControllerProperties(rootcanal::configuration::Controller const& config)
1674     : strict(!config.has_strict() || config.strict()),
1675       supported_commands(SupportedCommands()),
1676       lmp_features({Page0LmpFeatures(), 0, Page2LmpFeatures()}),
1677       le_features(LlFeatures()) {
1678   using namespace rootcanal::configuration;
1679 
1680   // Set the base configuration.
1681   if (config.has_preset()) {
1682     switch (config.preset()) {
1683       case ControllerPreset::DEFAULT:
1684         break;
1685 
1686       case ControllerPreset::LAIRD_BL654:
1687         // Configuration extracted with the helper script controller_info.py
1688         br_supported = false;
1689         le_supported = true;
1690         hci_version = bluetooth::hci::HciVersion::V_5_4;
1691         hci_subversion = 0x5ad2;
1692         lmp_version = bluetooth::hci::LmpVersion::V_5_4;
1693         lmp_subversion = 0x5ad2;
1694         company_identifier = 0x7e8;
1695         supported_commands = std::array<uint8_t, 64>{
1696                 0x20, 0x00, 0x80, 0x00, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x00,
1697                 0x00, 0x28, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0xf7,
1698                 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x30, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
1699                 0x1f, 0xe0, 0xf7, 0xff, 0xff, 0xff, 0xc1, 0xe3, 0x03, 0x00, 0x00, 0x00, 0x00,
1700                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1701         };
1702         lmp_features = std::array<uint64_t, 3>{0x6000000000, 0x0, 0x0};
1703         le_features = 0x19beff017fff;
1704         le_acl_data_packet_length = 512;
1705         total_num_le_acl_data_packets = 4;
1706         iso_data_packet_length = 512;
1707         total_num_iso_data_packets = 5;
1708         le_filter_accept_list_size = 4;
1709         le_resolving_list_size = 4;
1710         le_supported_states = 0x3ffffffffff;
1711         le_max_advertising_data_length = 256;
1712         le_num_supported_advertising_sets = 4;
1713         le_periodic_advertiser_list_size = 4;
1714         break;
1715 
1716       case ControllerPreset::CSR_RCK_PTS_DONGLE:
1717         // Configuration extracted with the helper script controller_info.py
1718         supports_csr_vendor_command = true;
1719         br_supported = true;
1720         le_supported = true;
1721         hci_version = bluetooth::hci::HciVersion::V_4_2;
1722         hci_subversion = 0x30e8;
1723         lmp_version = bluetooth::hci::LmpVersion::V_4_2;
1724         lmp_subversion = 0x30e8;
1725         company_identifier = 0xa;
1726         supported_commands = std::array<uint8_t, 64>{
1727                 0xff, 0xff, 0xff, 0x03, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3,
1728                 0x0f, 0xe8, 0xfe, 0x3f, 0xf7, 0x83, 0xff, 0x1c, 0x00, 0x04, 0x00, 0x61, 0xf7,
1729                 0xff, 0xff, 0x7f, 0x00, 0xc0, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
1730                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1731                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1732         };
1733         lmp_features = std::array<uint64_t, 3>{0x875b1fd87e8fffff, 0x0, 0x30f};
1734         acl_data_packet_length = 310;
1735         total_num_acl_data_packets = 10;
1736         sco_data_packet_length = 64;
1737         total_num_sco_data_packets = 8;
1738         num_supported_iac = 2;
1739         le_features = 0x1f;
1740         le_acl_data_packet_length = 0;
1741         total_num_le_acl_data_packets = 0;
1742         le_filter_accept_list_size = 25;
1743         le_supported_states = 0x3ffffffffff;
1744         break;
1745 
1746       default:
1747         break;
1748     }
1749   }
1750 
1751   // Apply selected features.
1752   if (config.has_features()) {
1753     ControllerFeatures const& features = config.features();
1754     if (features.has_le_extended_advertising()) {
1755       SetLLFeatureBit(le_features, LLFeaturesBits::LE_EXTENDED_ADVERTISING,
1756                       features.le_extended_advertising());
1757       SetSupportedCommandBits(supported_commands, le_extended_advertising_commands_,
1758                               features.le_extended_advertising());
1759     }
1760     if (features.has_le_periodic_advertising()) {
1761       SetLLFeatureBit(le_features, LLFeaturesBits::LE_PERIODIC_ADVERTISING,
1762                       features.le_periodic_advertising());
1763       SetSupportedCommandBits(supported_commands, le_periodic_advertising_commands_,
1764                               features.le_periodic_advertising());
1765     }
1766     if (features.has_ll_privacy()) {
1767       SetLLFeatureBit(le_features, LLFeaturesBits::LL_PRIVACY, features.ll_privacy());
1768       SetSupportedCommandBits(supported_commands, ll_privacy_commands_, features.ll_privacy());
1769     }
1770     if (features.has_le_2m_phy()) {
1771       SetLLFeatureBit(le_features, LLFeaturesBits::LE_2M_PHY, features.le_2m_phy());
1772     }
1773     if (features.has_le_coded_phy()) {
1774       SetLLFeatureBit(le_features, LLFeaturesBits::LE_CODED_PHY, features.le_coded_phy());
1775     }
1776     if (features.has_le_connected_isochronous_stream()) {
1777       SetLLFeatureBit(le_features, LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL,
1778                       features.le_connected_isochronous_stream());
1779       SetLLFeatureBit(le_features, LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL,
1780                       features.le_connected_isochronous_stream());
1781       SetSupportedCommandBits(supported_commands, ll_connected_isochronous_stream_commands_,
1782                               features.le_connected_isochronous_stream());
1783     }
1784   }
1785 
1786   // Apply selected quirks.
1787   if (config.has_quirks()) {
1788     if (config.quirks().has_has_default_random_address()) {
1789       quirks.has_default_random_address = config.quirks().has_default_random_address();
1790     }
1791     if (config.quirks().has_hardware_error_before_reset()) {
1792       quirks.hardware_error_before_reset = config.quirks().hardware_error_before_reset();
1793     }
1794     // TODO(b/270606199): support send_acl_data_before_connection_complete
1795   }
1796 
1797   // Apply selected vendor features.
1798   if (config.has_vendor()) {
1799     if (config.vendor().has_csr()) {
1800       supports_csr_vendor_command = config.vendor().csr();
1801     }
1802     if (config.vendor().has_android()) {
1803       supports_le_get_vendor_capabilities_command = config.vendor().android();
1804       supports_le_apcf_vendor_command = config.vendor().android();
1805     }
1806   }
1807 
1808   if (!CheckSupportedFeatures()) {
1809     INFO("Warning: LMP and/or LE features are not consistent. Please make sure"
1810          " that the features are correct w.r.t. the rules described"
1811          " in Vol 2, Part C 3.5 Feature requirements");
1812   }
1813 
1814   if (!CheckSupportedCommands()) {
1815     INFO("Warning: supported commands are not consistent. Please make"
1816          " sure that the supported commands are correct w.r.t. the rules"
1817          " described in Vol 4, Part E § 3 Overview of commands and events");
1818   }
1819 }
1820 
1821 }  // namespace rootcanal
1822