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