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