• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #pragma once
16 // clang-format off
17 
18 #include <array>
19 #include <cstddef>
20 #include <cstdint>
21 
22 #include <pw_bluetooth/hci_commands.emb.h>
23 #include <pw_chrono/system_clock.h>
24 #include "pw_bluetooth_sapphire/internal/host/common/advertising_data.h"
25 
26 // This file contains constants and numbers used in HCI packet payloads.
27 
28 namespace bt::hci_spec {
29 
30 // Bitmask values for the 8-octet Local Supported LMP Features bit-field. See
31 // Core Specv5.0, Volume 2, Part C, Section 3.3 "Feature Mask Definition".
32 enum class LMPFeature : uint64_t {
33   // Extended features (Page 0): Octet 0
34   k3SlotPackets   = (1 << 0),
35   k5SlotPackets   = (1 << 1),
36   kEncryption     = (1 << 2),
37   kSlotOffset     = (1 << 3),
38   kTimingAccuracy = (1 << 4),
39   kRoleSwitch     = (1 << 5),
40   kHoldMode       = (1 << 6),
41   kSniffMode      = (1 << 7),
42 
43   // Extended features (Page 0): Octet 1
44   // kPreviouslyUsed               = (1ull << 8),
45   kPowerControlRequests         = (1ull << 9),
46   kChannelQualityDrivenDataRate = (1ull << 10),
47   kSCOLink                      = (1ull << 11),
48   kHV2Packets                   = (1ull << 12),
49   kHV3Packets                   = (1ull << 13),
50   kmLawLogSynchronousData       = (1ull << 14),
51   kALawLogSynchronousData       = (1ull << 15),
52 
53   // Extended features (Page 0): Octet 2
54   kCVSDSynchronousData        = (1ull << 16),
55   kPagingParameterNegotiation = (1ull << 17),
56   kPowerControl               = (1ull << 18),
57   kTransparentSynchronousData = (1ull << 19),
58   kFCLLeastSignificantBit     = (1ull << 20),
59   kFCLMiddleBit               = (1ull << 21),
60   kFCLMostSignificantBit      = (1ull << 22),
61   kBroadcastEncryption        = (1ull << 23),
62 
63   // Extended features (Page 0): Octet 3
64   // Reserved (1ull << 24)
65   kEDRACL2MbitMode        = (1ull << 25),
66   kEDRACL3MbitMode        = (1ull << 26),
67   kEnhancedInquiryScan    = (1ull << 27),
68   kInterlacedInquiryScan  = (1ull << 28),
69   kInterlacedPageScan     = (1ull << 29),
70   kRSSIwithInquiryResults = (1ull << 30),
71   kEV3Packets             = (1ull << 31),
72 
73   // Extended features (Page 0): Octet 4
74   kEV4Packets                  = (1ull << 32),
75   kEV5Packets                  = (1ull << 33),
76   // Reserved
77   kAFHCapablePeripheral        = (1ull << 35),
78   kAFHClassificationPeripheral = (1ull << 36),
79   kBREDRNotSupported           = (1ull << 37),
80   kLESupportedController       = (1ull << 38),
81   k3SlotEDRACLPackets          = (1ull << 39),
82 
83   // Extended features (Page 0): Octet 5
84   k5SlotEDRACLPackets       = (1ull << 40),
85   kSniffSubrating           = (1ull << 41),
86   kPauseEncryption          = (1ull << 42),
87   kAFHCapableCentral        = (1ull << 43),
88   kAFHClassificationCentral = (1ull << 44),
89   kEDReSCO2MbitMode         = (1ull << 45),
90   kEDReSCO3MbitMode         = (1ull << 46),
91   k3SlotEDReSCOPackets      = (1ull << 47),
92 
93   // Extended features (Page 0): Octet 6
94   kExtendedInquiryResponse              = (1ull << 48),
95   kSimultaneousLEAndBREDR               = (1ull << 49),
96   // Reserved
97   kSecureSimplePairingControllerSupport = (1ull << 51),
98   kEncapsulatedPDU                      = (1ull << 52),
99   kErroneousDataReporting               = (1ull << 53),
100   kNonflushablePacketBoundaryFlag       = (1ull << 54),
101   // Reserved
102 
103   // Extended features (Page 0): Octet 7
104   kLinkSupervisionTimeoutChangedEvent = (1ull << 56),
105   kVariableInquiryTxPowerLevel        = (1ull << 57),
106   kEnhancedPowerControl               = (1ull << 58),
107   // Reserved
108   // Reserved
109   // Reserved
110   // Reserved
111   kExtendedFeatures                   = (1ull << 63),
112 
113   // Extended features (Page 1): Octet 0
114   kSecureSimplePairingHostSupport = (1ull << 0),
115   kLESupportedHost                = (1ull << 1),
116   kSimultaneousLEAndBREDRHost     = (1ull << 2),
117   kSecureConnectionsHostSupport   = (1ull << 3),
118 
119   // Extended features (Page 2): Octet 0
120   kCPBTransmitterOperation          = (1ull << 0),
121   kCPBReceiverOperation             = (1ull << 1),
122   kSynchronizationTrain             = (1ull << 2),
123   kSynchronizationScan              = (1ull << 3),
124   kInquiryResponseNotificationEvent = (1ull << 4),
125   kGeneralizedInterlacedScan        = (1ull << 5),
126   kCoarseClockAdjustment            = (1ull << 6),
127   // Reserved
128 
129   // Extended features (Page 2): Octet 1
130   kSecureConnectionsControllerSupport = (1ull << 8),
131   kPing                               = (1ull << 9),
132   kSlotAvailabilityMask               = (1ull << 10),
133   kTrainNudging                       = (1ull << 11)
134 };
135 
136 // Bitmask values for the 64-octet Supported Commands bit-field. See Core Spec
137 // v5.0, Volume 2, Part E, Section 6.27 "Supported Commands".
138 enum class SupportedCommand : uint8_t {
139   // Octet 0
140   kInquiry                 = (1 << 0),
141   kInquiryCancel           = (1 << 1),
142   kPeriodicInquiryMode     = (1 << 2),
143   kExitPeriodicInquiryMode = (1 << 3),
144   kCreateConnection        = (1 << 4),
145   kDisconnect              = (1 << 5),
146   kAddSCOConnection        = (1 << 6),  // deprecated
147   kCreateConnectionCancel  = (1 << 7),
148 
149   // Octet 1
150   kAcceptConnectionRequest     = (1 << 0),
151   kRejectConnectionRequest     = (1 << 1),
152   kLinkKeyRequestReply         = (1 << 2),
153   kLinkKeyRequestNegativeReply = (1 << 3),
154   kPINCodeRequestReply         = (1 << 4),
155   kPINCodeRequestNegativeReply = (1 << 5),
156   kChangeConnectionPacketType  = (1 << 6),
157   kAuthenticationRequested     = (1 << 7),
158 
159   // Octet 2
160   kSetConnectionEncryption      = (1 << 0),
161   kChangeConnectionLinkKey      = (1 << 1),
162   kLinkKeySelection             = (1 << 2),
163   kRemoteNameRequest            = (1 << 3),
164   kRemoteNameRequestCancel      = (1 << 4),
165   kReadRemoteSupportedFeatures  = (1 << 5),
166   kReadRemoteExtendedFeatures   = (1 << 6),
167   kReadRemoteVersionInformation = (1 << 7),
168 
169   // Octet 3
170   kReadClockOffset = (1 << 0),
171   kReadLMPHandle   = (1 << 1),
172   // kReserved     = (1 << 2),
173   // kReserved     = (1 << 3),
174   // kReserved     = (1 << 4),
175   // kReserved     = (1 << 5),
176   // kReserved     = (1 << 6),
177   // kReserved     = (1 << 7),
178 
179   // Octet 4
180   // kReserved   = (1 << 0),
181   kHoldMode      = (1 << 1),
182   kSniffMode     = (1 << 2),
183   kExitSniffMode = (1 << 3),
184   kParkState     = (1 << 4),  // reserved in 5.0
185   kExitParkState = (1 << 5),  // reserved in 5.0
186   kQOSSetup      = (1 << 6),
187   kRoleDiscovery = (1 << 7),
188 
189   // Octet 5
190   kSwitchRole                     = (1 << 0),
191   kReadLinkPolicySettings         = (1 << 1),
192   kWriteLinkPolicySettings        = (1 << 2),
193   kReadDefaultLinkPolicySettings  = (1 << 3),
194   kWriteDefaultLinkPolicySettings = (1 << 4),
195   kFlowSpecification              = (1 << 5),
196   kSetEventMask                   = (1 << 6),
197   kReset                          = (1 << 7),
198 
199   // Octet 6
200   kSetEventFilter       = (1 << 0),
201   kFlush                = (1 << 1),
202   kReadPINType          = (1 << 2),
203   kWritePINType         = (1 << 3),
204   kCreateNewUnitKey     = (1 << 4),  // reserved in 5.0
205   kReadStoredLinkKey    = (1 << 5),
206   kWriteStoredLinkKey   = (1 << 6),
207   kDeletedStoredLinkKey = (1 << 7),
208 
209   // Octet 7
210   kWriteLocalName                = (1 << 0),
211   kReadLocalName                 = (1 << 1),
212   kReadConnectionAttemptTimeout  = (1 << 2),
213   kWriteConnectionAttemptTimeout = (1 << 3),
214   kReadPageTimeout               = (1 << 4),
215   kWritePageTimeout              = (1 << 5),
216   kReadScanEnable                = (1 << 6),
217   kWriteScanEnable               = (1 << 7),
218 
219   // Octet 8
220   kReadPageScanActivity      = (1 << 0),
221   kWritePageScanActivity     = (1 << 1),
222   kReadInquiryScanActivity   = (1 << 2),
223   kWriteInquiryScanActivity  = (1 << 3),
224   kReadAuthenticationEnable  = (1 << 4),
225   kWriteAuthenticationEnable = (1 << 5),
226   kReadEncryptionMode        = (1 << 6),  // deprecated
227   kWriteEncryptionMode       = (1 << 7),  // deprecated
228 
229   // Octet 9
230   kReadClassOfDevice                = (1 << 0),
231   kWriteClassOfDevice               = (1 << 1),
232   kReadVoiceSetting                 = (1 << 2),
233   kWriteVoiceSetting                = (1 << 3),
234   kReadAutomaticFlushTimeout        = (1 << 4),
235   kWriteAutomaticFlushTimeout       = (1 << 5),
236   kReadNumBroadcastRetransmissions  = (1 << 6),
237   kWriteNumBroadcastRetransmissions = (1 << 7),
238 
239   // Octet 10
240   kReadHoldModeActivity              = (1 << 0),
241   kWriteHoldModeActivity             = (1 << 1),
242   kReadTransmitPowerLevel            = (1 << 2),
243   kReadSynchronousFlowControlEnable  = (1 << 3),
244   kWriteSynchronousFlowControlEnable = (1 << 4),
245   kSetControllerToHostFlowControl    = (1 << 5),
246   kHostBufferSize                    = (1 << 6),
247   kHostNumberOfCompletedPackets      = (1 << 7),
248 
249   // Octet 11
250   kReadLinkSupervisionTimeout        = (1 << 0),
251   kWriteLinkSupervisionTimeout       = (1 << 1),
252   kReadNumberOfSupportedIAC          = (1 << 2),
253   kReadCurrentIACLAP                 = (1 << 3),
254   kWriteCurrentIACLAP                = (1 << 4),
255   kReadPageScanModePeriod            = (1 << 5),  // deprecated
256   kWritePageScanModePeriod           = (1 << 6),  // deprecated
257   kReadPageScanMode                  = (1 << 7),  // deprecated
258 
259   // Octet 12
260   kWritePageScanMode               = (1 << 0),  // deprecated
261   kSetAFHHostChannelClassification = (1 << 1),
262   // kReserved                     = (1 << 2),
263   // kReserved                     = (1 << 3),
264   kReadInquiryScanType             = (1 << 4),
265   kWriteInquiryScanType            = (1 << 5),
266   kReadInquiryMode                 = (1 << 6),
267   kWriteInquiryMode                = (1 << 7),
268 
269   // Octet 13
270   kReadPageScanType              = (1 << 0),
271   kWritePageScanType             = (1 << 1),
272   kReadAFHChannelAssessmentMode  = (1 << 2),
273   kWriteAFHChannelAssessmentMode = (1 << 3),
274   // kReserved                   = (1 << 4),
275   // kReserved                   = (1 << 5),
276   // kReserved                   = (1 << 6),
277   // kReserved                   = (1 << 7),
278 
279   // Octet 14
280   // kReserved                 = (1 << 0),
281   // kReserved                 = (1 << 1),
282   // kReserved                 = (1 << 2),
283   kReadLocalVersionInformation = (1 << 3),
284   // kReserved                 = (1 << 4),
285   kReadLocalSupportedFeatures  = (1 << 5),
286   kReadLocalExtendedFeatures   = (1 << 6),
287   kReadBufferSize              = (1 << 7),
288 
289   // Octet 15
290   kReadCountryCode           = (1 << 0),  // deprecated
291   kReadBDADDR                = (1 << 1),
292   kReadFailedContactCounter  = (1 << 2),
293   kResetFailedContactCOunter = (1 << 3),
294   kReadLinkQuality           = (1 << 4),
295   kReadRSSI                  = (1 << 5),
296   kReadAFHChannelMap         = (1 << 6),
297   kReadClock                 = (1 << 7),
298 
299   // Octet 16
300   kReadLoopbackMode                   = (1 << 0),
301   kWriteLoopbackMode                  = (1 << 1),
302   kEnableDeviceUnderTestMode          = (1 << 2),
303   kSetupSynchronousConnectionRequest  = (1 << 3),
304   kAcceptSynchronousConnectionRequest = (1 << 4),
305   kRejectSynchronousConnectionRequest = (1 << 5),
306   // kReserved                        = (1 << 6),
307   // kReserved                        = (1 << 7),
308 
309   // Octet 17
310   kReadExtendedInquiryResponse  = (1 << 0),
311   kWriteExtendedInquiryResponse = (1 << 1),
312   kRefreshEncryptionKey         = (1 << 2),
313   // kReserved                  = (1 << 3),
314   kSniffSubrating               = (1 << 4),
315   kReadSimplePairingMode        = (1 << 5),
316   kWriteSimplePairingMode       = (1 << 6),
317   kReadLocalOOBData             = (1 << 7),
318 
319   // Octet 18
320   kReadInquiryResponseTransmitPowerLevel = (1 << 0),
321   kWriteInquiryTransmitPowerLevel        = (1 << 1),
322   kReadDefaultErroneousDataReporting     = (1 << 2),
323   kWriteDefaultErroneousDataReporting    = (1 << 3),
324   // kReserved                           = (1 << 4),
325   // kReserved                           = (1 << 5),
326   // kReserved                           = (1 << 6),
327   kIOCapabilityRequestReply              = (1 << 7),
328 
329   // Octet 19
330   kUserConfirmationRequestReply         = (1 << 0),
331   kUserConfirmationRequestNegativeReply = (1 << 1),
332   kUserPasskeyRequestReply              = (1 << 2),
333   kUserPasskeyRequestNegativeReply      = (1 << 3),
334   kRemoteOOBDataRequestReply            = (1 << 4),
335   kWriteSimplePairingDebugMode          = (1 << 5),
336   kEnhancedFlush                        = (1 << 6),
337   kRemoteOOBDataRequestNegativeReply    = (1 << 7),
338 
339   // Octet 20
340   // kReserved                      = (1 << 0),
341   // kReserved                      = (1 << 1),
342   kSendKeypressNotification         = (1 << 2),
343   kIOCapabilityRequestNegativeReply = (1 << 3),
344   kReadEncryptionKeySize            = (1 << 4),
345   // kReserved                      = (1 << 5),
346   // kReserved                      = (1 << 6),
347   // kReserved                      = (1 << 7),
348 
349   // Octet 21
350   kCreatePhysicalLink     = (1 << 0),
351   kAcceptPhysicalLink     = (1 << 1),
352   kDisconnectPhysicalLink = (1 << 2),
353   kCreateLogicalLink      = (1 << 3),
354   kAcceptLogicalLink      = (1 << 4),
355   kDisconnectLogicalLink  = (1 << 5),
356   kLogicalLinkCancel      = (1 << 6),
357   kFlowSpecModify         = (1 << 7),
358 
359   // Octet 22
360   kReadLogicalLinkAcceptTimeout  = (1 << 0),
361   kWriteLogicalLinkAcceptTimeout = (1 << 1),
362   kSetEventMaskPage2             = (1 << 2),
363   kReadLocationData              = (1 << 3),
364   kWriteLocationData             = (1 << 4),
365   kReadLocalAMPInfo              = (1 << 5),
366   kReadLocalAMPASSOC             = (1 << 6),
367   kWriteRemoteAMPASSOC           = (1 << 7),
368 
369   // Octet 23
370   kReadFlowControlMode      = (1 << 0),
371   kWriteFlowControlMode     = (1 << 1),
372   kReadDataBlockSize        = (1 << 2),
373   // kReserved              = (1 << 3),
374   // kReserved              = (1 << 4),
375   kEnableAMPReceiverReports = (1 << 5),
376   kAMPTestEnd               = (1 << 6),
377   kAMPTest                  = (1 << 7),
378 
379   // Octet 24
380   kReadEnhancedTransmitPowerLevel = (1 << 0),
381   // kReserved                    = (1 << 1),
382   kReadBestEffortFlushTimeout     = (1 << 2),
383   kWriteBestEffortFlushTimeout    = (1 << 3),
384   kShortRangeMode                 = (1 << 4),
385   kReadLEHostSupported            = (1 << 5),
386   kWriteLEHostSupport             = (1 << 6),
387   // kReserved                    = (1 << 7),
388 
389   // Octet 25
390   kLESetEventMask                  = (1 << 0),
391   kLEReadBufferSizeV1              = (1 << 1),
392   kLEReadLocalSupportedFeatures    = (1 << 2),
393   // kReserved                     = (1 << 3),
394   kLESetRandomAddress              = (1 << 4),
395   kLESetAdvertisingParameters      = (1 << 5),
396   kLEReadAdvertisingChannelTXPower = (1 << 6),
397   kLESetAdvertisingData            = (1 << 7),
398 
399   // Octet 26
400   kLESetScanResponseData      = (1 << 0),
401   kLESetAdvertisingEnable     = (1 << 1),
402   kLESetScanParameters        = (1 << 2),
403   kLESetScanEnable            = (1 << 3),
404   kLECreateConnection         = (1 << 4),
405   kLECreateConnectionCancel   = (1 << 5),
406   kLEReadFilterAcceptListSize = (1 << 6),
407   kLEClearFilterAcceptList    = (1 << 7),
408 
409   // Octet 27
410   kLEAddDeviceToFilterAcceptList      = (1 << 0),
411   kLERemoveDeviceFromFilterAcceptList = (1 << 1),
412   kLEConnectionUpdate                 = (1 << 2),
413   kLESetHostChannelClassification     = (1 << 3),
414   kLEReadChannelMap                   = (1 << 4),
415   kLEReadRemoteFeatures               = (1 << 5),
416   kLEEncrypt                          = (1 << 6),
417   kLERand                             = (1 << 7),
418 
419   // Octet 28
420   kLEStartEncryption                 = (1 << 0),
421   kLELongTermKeyRequestReply         = (1 << 1),
422   kLELongTermKeyRequestNegativeReply = (1 << 2),
423   kLEReadSupportedStates             = (1 << 3),
424   kLEReceiverTestV1                  = (1 << 4),
425   kLETransmitterTestV1               = (1 << 5),
426   kLETestEnd                         = (1 << 6),
427   // kReserved                       = (1 << 7),
428 
429   // Octet 29
430   // kReserved                         = (1 << 0),
431   // kReserved                         = (1 << 1),
432   // kReserved                         = (1 << 2),
433   kEnhancedSetupSynchronousConnection  = (1 << 3),
434   kEnhancedAcceptSynchronousConnection = (1 << 4),
435   kReadLocalSupportedCodecs            = (1 << 5),
436   kSetMWSChannelParameters             = (1 << 6),
437   kSetExternalFrameConfiguration       = (1 << 7),
438 
439   // Octet 30
440   kSetMWSSignaling                   = (1 << 0),
441   kSetMWSTransportLayer              = (1 << 1),
442   kSetMWSScanFrequencyTable          = (1 << 2),
443   kGetMWSTransportLayerConfiguration = (1 << 3),
444   kSetMWSPATTERNConfiguration        = (1 << 4),
445   kSetTriggeredClockCapture          = (1 << 5),
446   kTruncatedPage                     = (1 << 6),
447   kTruncatedPageCancel               = (1 << 7),
448 
449   // Octet 31
450   kSetConnectionlessPeripheralBroadcast        = (1 << 0),
451   kSetConnectionlessPeripheralBroadcastReceive = (1 << 1),
452   kStartSynchronizationTrain                   = (1 << 2),
453   kReceiveSynchronizationTrain                 = (1 << 3),
454   kSetReservedLTADDR                           = (1 << 4),
455   kDeleteReservedLTADDR                        = (1 << 5),
456   kSetConnectionlessPeripheralBroadcastData    = (1 << 6),
457   kReadSynchronizationTrainParameters          = (1 << 7),
458 
459   // Octet 32
460   kWriteSynchronizationTrainParameters = (1 << 0),
461   kRemoteOOBExtendedDataRequestReply   = (1 << 1),
462   kReadSecureConnectionsHostSupport    = (1 << 2),
463   kWriteSecureConnectionsHostSupport   = (1 << 3),
464   kReadAuthenticatedPayloadTimeout     = (1 << 4),
465   kWriteAuthenticatedPayloadTimeout    = (1 << 5),
466   kReadLocalOOBExtendedData            = (1 << 6),
467   kWriteSecureConnectionsTestMode      = (1 << 7),
468 
469   // Octet 33
470   kReadExtendedPageTimeout                         = (1 << 0),
471   kWriteExtendedPageTimeout                        = (1 << 1),
472   kReadExtendedInquiryLength                       = (1 << 2),
473   kWriteExtendedInquiryLength                      = (1 << 3),
474   kLERemoteConnectionParameterRequestReply         = (1 << 4),
475   kLERemoteConnectionParameterRequestNegativeReply = (1 << 5),
476   kLESetDataLength                                 = (1 << 6),
477   kLEReadSuggestedDefaultDataLength                = (1 << 7),
478 
479   // Octet 34
480   kLEWriteSuggestedDefaultDataLength = (1 << 0),
481   kLEReadLocalP256PublicKey          = (1 << 1),
482   kLEGenerateDHKeyV1                 = (1 << 2),
483   kLEAddDeviceToResolvingList        = (1 << 3),
484   kLERemoveDeviceFromResolvingList   = (1 << 4),
485   kLEClearResolvingList              = (1 << 5),
486   kLEReadResolvingListSize           = (1 << 6),
487   kLEReadPeerResolvableAddress       = (1 << 7),
488 
489   // Octet 35
490   kLEReadLocalResolvableAddress         = (1 << 0),
491   kLESetAddressResolutionEnable         = (1 << 1),
492   kLESetResolvablePrivateAddressTimeout = (1 << 2),
493   kLEReadMaximumDataLength              = (1 << 3),
494   kLEReadPHY                            = (1 << 4),
495   kLESetDefaultPHY                      = (1 << 5),
496   kLESetPHY                             = (1 << 6),
497   kLEEnhancedReceiverTestV2             = (1 << 7),
498 
499   // Octet 36
500   kLEEnhancedTransmitterTestV2              = (1 << 0),
501   kLESetAdvertisingSetRandomAddress       = (1 << 1),
502   kLESetExtendedAdvertisingParameters     = (1 << 2),
503   kLESetExtendedAdvertisingData           = (1 << 3),
504   kLESetExtendedScanResponseData          = (1 << 4),
505   kLESetExtendedAdvertisingEnable         = (1 << 5),
506   kLEReadMaximumAdvertisingDataLength     = (1 << 6),
507   kLEReadNumberOfSupportedAdvertisingSets = (1 << 7),
508 
509   // Octet 37
510   kLERemoveAdvertisingSet             = (1 << 0),
511   kLEClearAdvertisingSets             = (1 << 1),
512   kLESetPeriodicAdvertisingParameters = (1 << 2),
513   kLESetPeriodicAdvertisingData       = (1 << 3),
514   kLESetPeriodicAdvertisingEnable     = (1 << 4),
515   kLESetExtendedScanParameters        = (1 << 5),
516   kLESetExtendedScanEnable            = (1 << 6),
517   kLEExtendedCreateConnection         = (1 << 7),
518 
519   // Octet 38
520   kLEPeriodicAdvertisingCreateSync          = (1 << 0),
521   kLEPeriodicAdvertisingCreateSyncCancel    = (1 << 1),
522   kLEPeriodicAdvertisingTerminateSync       = (1 << 2),
523   kLEAddDeviceToPeriodicAdvertiserList      = (1 << 3),
524   kLERemoveDeviceFromPeriodicAdvertiserList = (1 << 4),
525   kLEClearPeriodicAdvertiserList            = (1 << 5),
526   kLEReadPeriodicAdvertiserListSize         = (1 << 6),
527   kLEReadTransmitPower                      = (1 << 7),
528 
529   // Octet 39
530   kLEReadRFPathCompensation                 = (1 << 0),
531   kLEWriteRFPathCompensation                = (1 << 1),
532   kLESetPrivacyMode                         = (1 << 2),
533   kLEReceiverTestV3                         = (1 << 3),
534   kLETransmitterTestV3                      = (1 << 4),
535   kLESetConnectionlessCTETransmitParameters = (1 << 5),
536   kLESetConnectionlessCTETransmitEnable     = (1 << 6),
537   kLESetConnectionlessIQSamplingEnable      = (1 << 7),
538 
539   // Octet 40
540   kLESetConnectionCTEReceiveParameters   = (1 << 0),
541   kLESetConnectionCTETransmitParameters  = (1 << 1),
542   kLEConnectionCTERequestEnable          = (1 << 2),
543   kLEConnectionCTEResponseEnable         = (1 << 3),
544   kLEReadAntennaInformation              = (1 << 4),
545   kLESetPeriodicAdvertisingReceiveEnable = (1 << 5),
546   kLEPeriodicAdvertisingSyncTransfer     = (1 << 6),
547   kLEPeriodicAdvertisingSetInfoTransfer  = (1 << 7),
548 
549   // Octet 41
550   kLESetPeriodicAdvertisingSyncTransferParameters        = (1 << 0),
551   kLESetDefaultPeriodicAdvertisingSyncTransferParameters = (1 << 1),
552   kLEGenerateDHKeyV3                                     = (1 << 2),
553   kReadLocalSimplePairingOptions                         = (1 << 3),
554   kLEModifySleepClockAccuracy                            = (1 << 4),
555   kLEReadBufferSizeV2                                    = (1 << 5),
556   kLEReadISOTXSync                                       = (1 << 6),
557   kLESetCIGParameters                                    = (1 << 7),
558 
559   // Octet 42
560   kLESetCIGParametersTest = (1 << 0),
561   kLECreateCIS            = (1 << 1),
562   kLERemoveCIG            = (1 << 2),
563   kLEAcceptCISRequest     = (1 << 3),
564   kLERejectCISRequest     = (1 << 4),
565   kLECreateBIG            = (1 << 5),
566   kLECreateBIGTest        = (1 << 6),
567   kLETerminateBIG         = (1 << 7),
568 
569   // Octet 43
570   kLEBIGCreateSync       = (1 << 0),
571   kLEBIGTerminateSync    = (1 << 1),
572   kLERequestPeerSCA      = (1 << 2),
573   kLESetupISODataPath    = (1 << 3),
574   kLERemoveISODataPath   = (1 << 4),
575   kLEISOTransmitTest     = (1 << 5),
576   kLEISOReceiveTest      = (1 << 6),
577   kLEISOReadTestCounters = (1 << 7),
578 
579   // Octet 44
580   kLEISOTestEnd                      = (1 << 0),
581   kLESetHostFeature                  = (1 << 1),
582   kLEReadISOLinkQuality              = (1 << 2),
583   kLEEnhancedReadTransmitPowerLevel  = (1 << 3),
584   kLEReadRemoteTransmitPowerLevel    = (1 << 4),
585   kLESetPathLossReportingParameters  = (1 << 5),
586   kLESetPathLossReportingEnable      = (1 << 6),
587   kLESetTransmitPowerReportingEnable = (1 << 7),
588 
589   // Octet 45
590   kLETransmitterTestV4                 = (1 << 0),
591   kSetEcosystemBaseInterval            = (1 << 1),
592   kReadLocalSupportedCodecsV2          = (1 << 2),
593   kReadLocalSupportedCodecCapabilities = (1 << 3),
594   kReadLocalSupportedControllerDelay   = (1 << 4),
595   kConfigureDataPath                   = (1 << 5),
596   // kReserved                         = (1 << 6),
597   // kReserved                         = (1 << 7),
598 };
599 
600 // Bitmask of 8-octet LE supported features field. See Core Spec
601 // v5.0, Volume 6, Part B, Section 4.6 "Feature Support".
602 struct LESupportedFeatures {
603   uint64_t le_features;
604 } __attribute__((packed));
605 
606 // Bitmask values for the 8-octet LE Supported Features bit-field. See Core Spec
607 // v5.0, Volume 6, Part B, Section 4.6 "Feature Support".
608 enum class LESupportedFeature : uint64_t {
609   kLEEncryption                         = (1 << 0),
610   kConnectionParametersRequestProcedure = (1 << 1),
611   kExtendedRejectIndication             = (1 << 2),
612   kPeripheralInitiatedFeaturesExchange       = (1 << 3),
613   kLEPing                               = (1 << 4),
614   kLEDataPacketLengthExtension          = (1 << 5),
615   kLLPrivacy                            = (1 << 6),
616   kExtendedScannerFilterPolicies        = (1 << 7),
617 
618   // Added in 5.0
619   kLE2MPHY                                  = (1 << 8),
620   kStableModulationIndexTransmitter         = (1 << 9),
621   kStableModulationIndexReceiver            = (1 << 10),
622   kLECodedPHY                               = (1 << 11),
623   kLEExtendedAdvertising                    = (1 << 12),
624   kLEPeriodicAdvertising                    = (1 << 13),
625   kChannelSelectionAlgorithm2               = (1 << 14),
626   kLEPowerClass1                            = (1 << 15),
627   kMinimumNumberOfUsedChannelsProcedure     = (1 << 16),
628 
629   // Added in 5.1
630   kConnectionCTERequest                     = (1 << 17),
631   kConnectionCTEResponse                    = (1 << 18),
632   kConnectionlessCTETransmitter             = (1 << 19),
633   kConnectionlessCTEReceiver                = (1 << 20),
634   kAntennaSwitchingDuringCTETransmission    = (1 << 21),
635   kAntennaSwitchingDuringCTEReception       = (1 << 22),
636   kReceivingConstantToneExtensions          = (1 << 23),
637   kPeriodicAdvertisingSyncTransferSender    = (1 << 24),
638   kPeriodicAdvertisingSyncTransferRecipient = (1 << 25),
639   kSleepClockAccuracyUpdates                = (1 << 26),
640   kRemotePublicKeyValidation                = (1 << 27),
641 
642   // Added in 5.2
643   kConnectedIsochronousStreamCentral     = (1 << 28),
644   kConnectedIsochronousStreamPeripheral  = (1 << 29),
645   kIsochronousBoradcaster                = (1 << 30),
646   kSynchronizedReceiver                  = (1ul << 31),
647   kConnectedIsochronousStreamHostSupport = (1ul << 32),
648   kLEPowerControlRequest                 = (1ul << 33),
649   kLEPowerChangeIndication               = (1ul << 34),
650   kLEPathLossMonitoring                  = (1ul << 35),
651 
652   // The rest is reserved for future use.
653 };
654 
655 // Bitmask values for the 8-octet HCI_Set_Event_Mask command parameter.
656 enum class EventMask : uint64_t {
657   kInquiryCompleteEvent                         = (1 << 0),
658   kInquiryResultEvent                           = (1 << 1),
659   kConnectionCompleteEvent                      = (1 << 2),
660   kConnectionRequestEvent                       = (1 << 3),
661   kDisconnectionCompleteEvent                   = (1 << 4),
662   kAuthenticationCompleteEvent                  = (1 << 5),
663   kRemoteNameRequestCompleteEvent               = (1 << 6),
664   kEncryptionChangeEvent                        = (1 << 7),
665   kChangeConnectionLinkKeyCompleteEvent         = (1 << 8),
666   kLinkKeyTypeChangedEvent                      = (1 << 9),
667   kReadRemoteSupportedFeaturesCompleteEvent     = (1 << 10),
668   kReadRemoteVersionInformationCompleteEvent    = (1 << 11),
669   kQoSSetupCompleteEvent                        = (1 << 12),
670   // Reserved For Future Use: (1 << 13)
671   // Reserved For Future Use: (1 << 14)
672   kHardwareErrorEvent                           = (1 << 15),
673   kFlushOccurredEvent                           = (1 << 16),
674   kRoleChangeEvent                              = (1 << 17),
675   // Reserved For Future Use: (1 << 18)
676   kModeChangeEvent                              = (1 << 19),
677   kReturnLinkKeysEvent                          = (1 << 20),
678   kPINCodeRequestEvent                          = (1 << 21),
679   kLinkKeyRequestEvent                          = (1 << 22),
680   kLinkKeyNotificationEvent                     = (1 << 23),
681   kLoopbackCommandEvent                         = (1 << 24),
682   kDataBufferOverflowEvent                      = (1 << 25),
683   kMaxSlotsChangeEvent                          = (1 << 26),
684   kReadClockOffsetCompleteEvent                 = (1 << 27),
685   kConnectionPacketTypeChangedEvent             = (1 << 28),
686   kQoSViolationEvent                            = (1 << 29),
687   kPageScanModeChangeEvent                      = (1 << 30),  // deprecated
688   kPageScanRepetitionModeChangeEvent            = (1ull << 31),
689   kFlowSpecificationCompleteEvent               = (1ull << 32),
690   kInquiryResultWithRSSIEvent                   = (1ull << 33),
691   kReadRemoteExtendedFeaturesCompleteEvent      = (1ull << 34),
692   // Reserved For Future Use: (1ull << 35)
693   // Reserved For Future Use: (1ull << 36)
694   // Reserved For Future Use: (1ull << 37)
695   // Reserved For Future Use: (1ull << 38)
696   // Reserved For Future Use: (1ull << 39)
697   // Reserved For Future Use: (1ull << 40)
698   // Reserved For Future Use: (1ull << 41)
699   // Reserved For Future Use: (1ull << 42)
700   kSynchronousConnectionCompleteEvent           = (1ull << 43),
701   kSynchronousConnectionChangedEvent            = (1ull << 44),
702   kSniffSubratingEvent                          = (1ull << 45),
703   kExtendedInquiryResultEvent                   = (1ull << 46),
704   kEncryptionKeyRefreshCompleteEvent            = (1ull << 47),
705   kIOCapabilityRequestEvent                     = (1ull << 48),
706   kIOCapabilityResponseEvent                    = (1ull << 49),
707   kUserConfirmationRequestEvent                 = (1ull << 50),
708   kUserPasskeyRequestEvent                      = (1ull << 51),
709   kRemoteOOBDataRequestEvent                    = (1ull << 52),
710   kSimplePairingCompleteEvent                   = (1ull << 53),
711   // Reserved For Future Use: (1ull << 54)
712   kLinkSupervisionTimeoutChangedEvent           = (1ull << 55),
713   kEnhancedFlushCompleteEvent                   = (1ull << 56),
714   // Reserved For Future Use: (1ull << 57)
715   kUserPasskeyNotificationEvent                 = (1ull << 58),
716   kKeypressNotificationEvent                    = (1ull << 59),
717   kRemoteHostSupportedFeaturesNotificationEvent = (1ull << 60),
718   kLEMetaEvent                                  = (1ull << 61),
719   // Reserved For Future Use: (1ull << 62)
720   // Reserved For Future Use: (1ull << 63)
721 };
722 
723 // Bitmask values for the 8-octet HCI_Set_Event_Mask_Page_2 command parameter.
724 enum class EventMaskPage2 : uint64_t {
725   kPhysicalLinkCompleteEvent                              = (1 << 0),
726   kChannelSelectedEvent                                   = (1 << 1),
727   kDisconnectionPhysicalLinkCompleteEvent                 = (1 << 2),
728   kPhysicalLinkLossEarlyWarningEvent                      = (1 << 3),
729   kPhysicalLinkRecoveryEvent                              = (1 << 4),
730   kLogicalLinkCompleteEvent                               = (1 << 5),
731   kDisconnectionLogicalLinkCompleteEvent                  = (1 << 6),
732   kFlowSpecModifyCompleteEvent                            = (1 << 7),
733   kNumberOfCompletedDataBlocksEvent                       = (1 << 8),
734   kAMPStartTestEvent                                      = (1 << 9),
735   kAMPTestEndEvent                                        = (1 << 10),
736   kAMPReceiverReportEvent                                 = (1 << 11),
737   kShortRangeModeChangeCompleteEvent                      = (1 << 12),
738   kAMPStatusChangeEvent                                   = (1 << 13),
739   kTriggeredClockCaptureEvent                             = (1 << 14),
740   kSynchronizationTrainCompleteEvent                      = (1 << 15),
741   kSynchronizationTrainReceivedEvent                      = (1 << 16),
742   kConnectionlessPeripheralBroadcastReceiveEvent          = (1 << 17),
743   kConnectionlessPeripheralBroadcastTimeoutEvent          = (1 << 18),
744   kTruncatedPageCompleteEvent                             = (1 << 19),
745   kPeripheralPageResponseTimeoutEvent                     = (1 << 20),
746   kConnectionlessPeripheralBroadcastChannelMapChangeEvent = (1 << 21),
747   kInquiryResponseNotificationEvent                       = (1 << 22),
748   kAuthenticatedPayloadTimeoutExpiredEvent                = (1 << 23),
749   kSAMStatusChangeEvent                                   = (1 << 24),
750 };
751 
752 // Bitmask values for the 8-octet HCI_LE_Set_Event_Mask command parameter.
753 enum class LEEventMask : uint64_t {
754   kLEConnectionComplete                 = (1 << 0),
755   kLEAdvertisingReport                  = (1 << 1),
756   kLEConnectionUpdateComplete           = (1 << 2),
757   kLEReadRemoteFeaturesComplete         = (1 << 3),
758   kLELongTermKeyRequest                 = (1 << 4),
759   kLERemoteConnectionParameterRequest   = (1 << 5),
760   kLEDataLengthChange                   = (1 << 6),
761   kLEReadLocalP256PublicKeyComplete     = (1 << 7),
762   kLEGenerateDHKeyComplete              = (1 << 8),
763   kLEEnhancedConnectionComplete         = (1 << 9),
764   kLEDirectedAdvertisingReport          = (1 << 10),
765   kLEPHYUpdateComplete                  = (1 << 11),
766   kLEExtendedAdvertisingReport          = (1 << 12),
767   kLEPeriodicAdvertisingSyncEstablished = (1 << 13),
768   kLEPeriodicAdvertisingReport          = (1 << 14),
769   kLEPeriodicAdvertisingSyncLost        = (1 << 15),
770   kLEExtendedScanTimeout                = (1 << 16),
771   kLEExtendedAdvertisingSetTerminated   = (1 << 17),
772   kLEScanRequestReceived                = (1 << 18),
773   kLEChannelSelectionAlgorithm          = (1 << 19),
774 };
775 
776 // Values that can be passed to the Type parameter in a
777 // HCI_Read_Transmit_Power_Level command.
778 enum class ReadTransmitPowerType : uint8_t {
779   // Read Current Transmit Power Level.
780   kCurrent = 0x00,
781 
782   // Read Maximum Transmit Power Level.
783   kMax = 0x01,
784 };
785 
786 // Possible values for the Encryption_Enabled parameter in a HCI_Encryption_Change event
787 // (see Vol 2, Part E, 7.7.8).
788 enum class EncryptionStatus : uint8_t {
789   // Link Level Encryption is OFF.
790   kOff = 0x00,
791 
792   // Link Level Encryption is ON with E0 for BR/EDR and AES-CCM for LE.
793   kOn = 0x01,
794 
795   // Link Level Encryption is ON with AES-CCM for BR/EDR.
796   kBredrSecureConnections = 0x02,
797 };
798 
799 // HCI command timeout interval (milliseconds)
800 // TODO(fxbug.dev/42070690,fxbug.dev/42070801) This was increased to handle flaking integration tests.
801 // We may want to reduce this to something lower again once we have a better
802 // resolution to this issue.
803 constexpr pw::chrono::SystemClock::duration kCommandTimeout = std::chrono::seconds(10);
804 
805 // The minimum and maximum range values for the LE advertising interval
806 // parameters.
807 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.5)
808 constexpr uint16_t kLEAdvertisingIntervalMin = 0x0020;
809 constexpr uint16_t kLEAdvertisingIntervalMax = 0x4000;
810 
811 // The minimum and maximum range values for the LE periodic advertising interval
812 // parameters.
813 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.61)
814 constexpr uint16_t kLEPeriodicAdvertisingIntervalMin = 0x0006;
815 constexpr uint16_t kLEPeriodicAdvertisingIntervalMax = 0xFFFF;
816 
817 // The minimum and maximum range values for the LE extended advertising interval
818 // parameters.
819 constexpr uint32_t kLEExtendedAdvertisingIntervalMin = 0x000020;
820 constexpr uint32_t kLEExtendedAdvertisingIntervalMax = 0xFFFFFF;
821 
822 // The default LE advertising interval parameter value, corresponding to 1.28
823 // seconds (see Core Spec v5.0, Vol 2, Part E, Section 7.8.5).
824 constexpr uint16_t kLEAdvertisingIntervalDefault = 0x0800;
825 
826 // The minimum and maximum range values for the LE scan interval parameters.
827 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.10)
828 constexpr uint16_t kLEScanIntervalMin = 0x0004;
829 constexpr uint16_t kLEScanIntervalMax = 0x4000;
830 
831 // The minimum and maximum range values for the LE extended scan interval
832 // parameters.
833 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.64)
834 constexpr uint16_t kLEExtendedScanIntervalMin = 0x0004;
835 constexpr uint16_t kLEExtendedScanIntervalMax = 0xFFFF;
836 
837 // The default LE scan interval parameter value, corresponding to 10
838 // milliseconds (see Core Spec v5.0, Vol 2, Part E, Section 7.8.10).
839 constexpr uint16_t kLEScanIntervalDefault = 0x0010;
840 
841 // The minimum and maximum range values for the LE connection interval parameters.
842 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.12)
843 constexpr uint16_t kLEConnectionIntervalMin = 0x0006;
844 constexpr uint16_t kLEConnectionIntervalMax = 0x0C80;
845 
846 // The maximum value that can be used for the |conn_latency| parameter in a
847 // HCI_LE_Create_Connection
848 // command (see Core Spec v5.0, Vol 2, Part E, Section 7.8.12).
849 constexpr uint16_t kLEConnectionLatencyMax = 0x01F3;
850 
851 // The minimum and maximum range values for LE connection supervision timeout
852 // parameters.
853 constexpr uint16_t kLEConnectionSupervisionTimeoutMin = 0x000A;
854 constexpr uint16_t kLEConnectionSupervisionTimeoutMax = 0x0C80;
855 
856 // The minimum and maximum range values for LE link layer tx PDU used on
857 // connections.
858 constexpr uint16_t kLEMaxTxOctetsMin = 0x001B;
859 constexpr uint16_t kLEMaxTxOctetsMax = 0x00FB;
860 
861 // The minimum and maximum range values for LE link layer tx maximum packet
862 // transmission time used on connections.
863 constexpr uint16_t kLEMaxTxTimeMin = 0x0148;
864 constexpr uint16_t kLEMaxTxTimeMax = 0x4290;
865 
866 // Minimum, maximum, default values for the Resolvable Private Address timeout
867 // parameter.
868 constexpr uint16_t kLERPATimeoutMin = 0x0001;      // 1 second
869 constexpr uint16_t kLERPATimeoutMax = 0xA1B8;      // Approx. 11.5 hours
870 constexpr uint16_t kLERPATimeoutDefault = 0x0384;  // 900 seconds or 15 minutes.
871 
872 // The maximum length of advertising data that can get passed to the
873 // HCI_LE_Set_Advertising_Data command.
874 //
875 // This constant should be used on pre-5.0 controllers. On controllers that
876 // support 5.0+ the host should use the
877 // HCI_LE_Read_Maximum_Advertising_Data_Length command to obtain this
878 // information.
879 constexpr size_t kMaxLEAdvertisingDataLength = 0x1F;  // (31)
880 
881 // The number of bytes of advertising data that can be sent in a single extended
882 // advertisement. The Bluetooth spec allows for a larger amount of bytes (based
883 // on the value returned for the LE Read Maximum Advertising Data Length
884 // parameter) but they must be fragmented across multiple extended advertising
885 // PDUs. We don't currently support data framgentation when advertising, nor do
886 // we support the use of extended advertising PDUs when advertising.
887 constexpr size_t kMaxPduLEExtendedAdvertisingDataLength = 252;
888 
889 // Core Spec Version 5.4, Volume 6, Part B, Section 2.3.4.9: the total
890 // amount of Host Advertising Data before fragmentation shall not exceed 1650
891 // octets.
892 constexpr size_t kMaxLEExtendedAdvertisingDataLength = 1650;
893 
894 // Tx Power values, See Core Spec v5.0 Vol 4, Part E, 7.8.6.
895 constexpr int8_t kTxPowerInvalid = 127;
896 constexpr int8_t kLEAdvertisingTxPowerMin = -127;
897 constexpr int8_t kLEAdvertisingTxPowerMax = 20;
898 constexpr int8_t kLEExtendedAdvertisingTxPowerNoPreference = 0x7F; // Vol 4, Part E, 7.8.53
899 
900 // Values used in enabling extended advertising. See Core Spec v5.0 Vol 4, Part E, 7.8.56.
901 constexpr uint8_t kMaxAdvertisingHandle = 0xEF;
902 constexpr uint8_t kNoMaxExtendedAdvertisingEvents = 0;
903 constexpr uint8_t kNoAdvertisingDuration = 0;
904 
905 // LE Advertising event types that can be reported in a LE Advertising Report
906 // event.
907 enum class LEAdvertisingEventType : uint8_t {
908   // Connectable and scannable undirected advertising (ADV_IND)
909   kAdvInd = 0x00,
910 
911   // Connectable directed advertising (ADV_DIRECT_IND)
912   kAdvDirectInd = 0x01,
913 
914   // Scannable undirected advertising (ADV_SCAN_IND)
915   kAdvScanInd = 0x02,
916 
917   // Non connectable undirected advertising (ADV_NONCONN_IND)
918   kAdvNonConnInd = 0x03,
919 
920   // Scan Response (SCAN_RSP)
921   kScanRsp = 0x04,
922 
923   // The rest is reserved for future use
924 };
925 
926 // Possible values that can be reported for the |address_type| parameter in a LE
927 // Advertising Report event.
928 enum class LEAddressType : uint8_t {
929   // Public Device Address
930   kPublic = 0x00,
931 
932   // Random Device Address
933   kRandom = 0x01,
934 
935   // Public Identity Address (Corresponds to Resolved Private Address)
936   kPublicIdentity = 0x02,
937 
938   // Random (static) Identity Address (Corresponds to Resolved Private Address)
939   kRandomIdentity = 0x03,
940 
941   // This is a special value used in LE Extended Advertising Report events to
942   // indicate a random address that the controller was unable to resolve.
943   kRandomUnresolved = 0xFE,
944 
945   // This is a special value that is only used in LE Directed Advertising Report
946   // events.
947   // Meaning: No address provided (anonymous advertisement)
948   kAnonymous = 0xFF,
949 };
950 
951 // Possible values that can be used for the |peer_address_type| parameter in a
952 // HCI_LE_Set_Advertising_Parameters command.
953 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.5)
954 enum class LEPeerAddressType : uint8_t {
955   // Public Device Address (default) or Public Identity Address
956   kPublic = 0x00,
957 
958   // Random Device Address or Random (static) Identity Address
959   kRandom = 0x01,
960 
961   // This is a special value that should only be used with the
962   // HCI_LE_Add_Device_To_Filter_Accept_List and HCI_LE_Remove_Device_From_Filter_Accept_List
963   // commands for peer devices sending anonymous advertisements.
964   kAnonymous = 0xFF,
965 };
966 
967 // Possible values that can be used for the |adv_channel_map| bitfield in a
968 // HCI_LE_Set_Advertising_Parameters command.
969 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.5)
970 constexpr uint8_t kLEAdvertisingChannel37 = 0x01;
971 constexpr uint8_t kLEAdvertisingChannel38 = 0x02;
972 constexpr uint8_t kLEAdvertisingChannel39 = 0x04;
973 constexpr uint8_t kLEAdvertisingChannelAll = 0x07;
974 
975 // Possible values that can be used for the |adv_filter_policy| parameter in a
976 // HCI_LE_Set_Advertising_Parameters command.
977 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.5)
978 enum class LEAdvFilterPolicy : uint8_t {
979   // Process scan and connection requests from all devices (i.e., the Filter Accept List is not in
980   // use) (default).
981   kAllowAll = 0x00,
982 
983   // Process connection requests from all devices and only scan requests from
984   // devices that are in the filter accept policy list.
985   kConnAllScanFilterAcceptList = 0x01,
986 
987   // Process scan requests from all devices and only connection requests from devices that are in
988   // the Filter Accept List.
989   kScanAllConnFilterAcceptList = 0x02,
990 
991   // Process scan and connection requests only from devices in the Filter Accept List.
992   kFilterAcceptListOnly = 0x03,
993 
994   // The rest is reserved for future use.
995 };
996 
997 // Possible values that can be used for the Filter_Policy parameter in a
998 // HCI_LE_Periodic_Advertising_Create_Sync command.
999 // (see Core Spec v5.0, Vol 2, Part E, Section 7.8.67)
1000 enum class LEPeriodicAdvFilterPolicy : uint8_t {
1001   // Use the Advertising_SID, Advertising_Address_Type, and Advertising_Address
1002   // parameters to determine which advertiser to listen to.
1003   kListNotUsed = 0x00,
1004 
1005   // Use the Periodic Advertiser List to determine which advertiser to listen to.
1006   kUsePeriodicAdvList = 0x01,
1007 };
1008 
1009 // The PHY bitfield values that can be used in HCI_LE_Set_PHY and
1010 // HCI_LE_Set_Default_PHY commands that can be used for the TX_PHYS and RX_PHYS
1011 // parameters.
1012 constexpr uint8_t kLEPHYBit1M = (1 << 0);
1013 constexpr uint8_t kLEPHYBit2M = (1 << 1);
1014 constexpr uint8_t kLEPHYBitCoded = (1 << 2);
1015 
1016 // The PHY bitfield values that can be used in HCI_LE_Set_PHY and
1017 // HCI_LE_Set_Default_PHY commands that can be used for the ALL_PHYS parameter.
1018 constexpr uint8_t kLEAllPHYSBitTxNoPreference = (1 << 0);
1019 constexpr uint8_t kLEAllPHYSBitRxNoPreference = (1 << 1);
1020 
1021 // Potential values that can be used for the LE PHY parameters in HCI commands
1022 // and events.
1023 enum class LEPHY : uint8_t {
1024   kLE1M = 0x01,
1025   kLE2M = 0x02,
1026 
1027   // Only for the HCI_LE_Enhanced_Transmitter_Test command this value implies
1028   // S=8 data coding. Otherwise this refers to general LE Coded PHY.
1029   kLECoded = 0x03,
1030 
1031   // This should ony be used with the HCI_LE_Enhanced_Transmitter_Test command.
1032   kLECodedS2 = 0x04,
1033 
1034   // Some HCI events may use this value to indicate that no packets were sent
1035   // on a particular PHY, specifically the LE Extended Advertising Report event.
1036   kNone = 0x00,
1037 };
1038 
1039 // Potential values that can be used for the PHY_options parameter in a
1040 // HCI_LE_Set_PHY command.
1041 enum class LEPHYOptions : uint16_t {
1042   kNoPreferredEncoding = 0x00,
1043   kPreferS2Coding = 0x01,
1044   kPreferS8Coding = 0x02,
1045 };
1046 
1047 // Potential values that can be passed for the Modulation_Index parameter in a
1048 // HCI_LE_Enhanced_Receiver_Test command.
1049 enum class LETestModulationIndex : uint8_t {
1050   kAssumeStandard = 0x00,
1051   kAssumeStable = 0x01,
1052 };
1053 
1054 // Potential values for the Operation parameter in a
1055 // HCI_LE_Set_Extended_Advertising_Data command.
1056 enum class LESetExtendedAdvDataOp : uint8_t {
1057   // Intermediate fragment of fragmented extended advertising data.
1058   kIntermediateFragment = 0x00,
1059 
1060   // First fragment of fragmented extended advertising data.
1061   kFirstFragment = 0x01,
1062 
1063   // Last fragment of fragmented extended advertising data.
1064   kLastFragment = 0x02,
1065 
1066   // Complete extended advertising data.
1067   kComplete = 0x03,
1068 
1069   // Unchanged data (just update the Advertising DID)
1070   kUnchangedData = 0x04,
1071 };
1072 
1073 // Potential values for the Fragment_Preference parameter in a
1074 // HCI_LE_Set_Extended_Advertising_Data command.
1075 enum class LEExtendedAdvFragmentPreference : uint8_t {
1076   // The Controller may fragment all Host advertising data
1077   kMayFragment = 0x00,
1078 
1079   // The Controller should not fragment or should minimize fragmentation of Host
1080   // advertising data
1081   kShouldNotFragment = 0x01,
1082 };
1083 
1084 // The Advertising_Event_Properties bitfield values used in a
1085 // HCI_LE_Set_Extended_Advertising_Parameters command.
1086 constexpr uint16_t kLEAdvEventPropBitConnectable                      = (1 << 0);
1087 constexpr uint16_t kLEAdvEventPropBitScannable                        = (1 << 1);
1088 constexpr uint16_t kLEAdvEventPropBitDirected                         = (1 << 2);
1089 constexpr uint16_t kLEAdvEventPropBitHighDutyCycleDirectedConnectable = (1 << 3);
1090 constexpr uint16_t kLEAdvEventPropBitUseLegacyPDUs                    = (1 << 4);
1091 constexpr uint16_t kLEAdvEventPropBitAnonymousAdvertising             = (1 << 5);
1092 constexpr uint16_t kLEAdvEventPropBitIncludeTxPower                   = (1 << 6);
1093 
1094 // The Event_Type bitfield values reported in a LE Extended Advertising Report Event.
1095 constexpr uint16_t kLEExtendedAdvEventTypeConnectable  = (1 << 0);
1096 constexpr uint16_t kLEExtendedAdvEventTypeScannable    = (1 << 1);
1097 constexpr uint16_t kLEExtendedAdvEventTypeDirected     = (1 << 2);
1098 constexpr uint16_t kLEExtendedAdvEventTypeScanResponse = (1 << 3);
1099 constexpr uint16_t kLEExtendedAdvEventTypeLegacy       = (1 << 4);
1100 
1101 // LE Advertising data status properties stored in bits 5 and 6 of the
1102 // Event_Type bitfield of a LE Extended Advertising Report event and in a LE
1103 // Periodic Advertising Report event.
1104 enum class LEAdvertisingDataStatus : uint16_t {
1105   // Data is complete.
1106   kComplete = 0x00,
1107 
1108   // Data is incomplete, more data to come in future events.
1109   kIncomplete = 0x01,
1110 
1111   // Data is incomplete and truncated, no more data to come.
1112   kIncompleteTruncated = 0x02,
1113 };
1114 
1115 // The Periodic_Advertising_Properties bitfield used in a
1116 // HCI_LE_Set_Periodic_Advertising_Parameters command.
1117 constexpr uint16_t kLEPeriodicAdvPropBitIncludeTxPower = (1 << 6);
1118 
1119 // The maximum length of LE data packets when the LE Data Packet Length Extension
1120 // feature is supported. See v5.0, Vol 6, Part B, 4.5.10, Table 4.3.
1121 constexpr size_t kMaxLEExtendedDataLength = 251;
1122 
1123 // Maximum value of the Advertising SID subfield in the ADI field of the PDU
1124 constexpr uint8_t kLEAdvertsingSIDMax = 0xEF;
1125 
1126 // Invalid RSSI value.
1127 constexpr int8_t kRSSIInvalid = 127;
1128 
1129 // The maximum length of a friendly name that can be assigned to a BR/EDR
1130 // controller, in octets.
1131 constexpr size_t kMaxNameLength = bt::kMaxNameLength;
1132 
1133 // The maximum number of bytes in a HCI Command Packet payload, excluding the
1134 // header. See Core Spec v5.0 Vol 2, Part E, 5.4.1, paragraph 2.
1135 constexpr size_t kMaxCommandPacketPayloadSize = 255;
1136 
1137 // The maximum number of bytes in a HCI event Packet payload, excluding the
1138 // header. See Core Spec v5.0 Vol 2, Part E, 5.4.4, paragraph 1.
1139 constexpr size_t kMaxEventPacketPayloadSize = 255;
1140 
1141 // The maximum number of bytes in a HCI ACL data packet payload supported by our
1142 // stack.
1143 constexpr size_t kMaxACLPayloadSize = 1024;
1144 
1145 // The maximum number of bytes in a HCI Synchronous Data packet payload.
1146 // This is based on the maximum value of the 1-byte Data_Total_Length field of a Synchronous Data packet.
1147 constexpr size_t kMaxSynchronousDataPacketPayloadSize = 255;
1148 
1149 // Values that can be used in HCI Read|WriteFlowControlMode commands.
1150 enum class FlowControlMode : uint8_t {
1151   // Packet based data flow control mode (default for a Primary Controller)
1152   kPacketBased = 0x00,
1153 
1154   // Data block based flow control mode (default for an AMP Controller)
1155   kDataBlockBased = 0x01
1156 };
1157 
1158 // The Packet Boundary Flag is contained in bits 4 and 5 in the second octet of
1159 // a HCI ACL Data packet.
1160 enum class ACLPacketBoundaryFlag : uint8_t {
1161   kFirstNonFlushable  = 0x00,
1162   kContinuingFragment = 0x01,
1163   kFirstFlushable     = 0x02,
1164   kCompletePDU        = 0x03,
1165 };
1166 
1167 // The Broadcast Flag is contained in bits 6 and 7 in the second octet of a HCI
1168 // ACL Data packet.
1169 enum class ACLBroadcastFlag : uint8_t {
1170   kPointToPoint              = 0x00,
1171   kActivePeripheralBroadcast = 0x01,
1172 };
1173 
1174 // The Packet Status Flag is contained in bits 4 to 5 of the second octet of
1175 // a HCI Synchronous Data packet (Core Spec v5.2, Vol 4, Part E, Sec 5.4.3).
1176 enum class SynchronousDataPacketStatusFlag : uint8_t {
1177   kCorrectlyReceived  = 0x00,
1178   kPossiblyInvalid  = 0x01,
1179   kNoDataReceived  = 0x02,
1180   kDataPartiallyLost = 0x03,
1181 };
1182 
1183 // Possible values that can be reported in a LE Channel Selection Algorithm event.
1184 enum class LEChannelSelectionAlgorithm : uint8_t {
1185   kAlgorithm1 = 0x00,
1186   kAlgorithm2 = 0x01,
1187 };
1188 
1189 // "Hosts and Controllers shall be able to accept HCI ACL Data Packets with up
1190 // to 27 bytes of data excluding the HCI ACL Data Packet header on Connection
1191 // Handles associated with an LE-U logical link." (See Core Spec v5.0, Volume 2,
1192 // Part E, Section 5.4.2)
1193 constexpr size_t kMinLEACLDataBufferLength = 27;
1194 
1195 // The maximum value that can be used for a 12-bit connection handle.
1196 constexpr uint16_t kConnectionHandleMax = 0x0EFF;
1197 
1198 // The maximum value that can ve used for a 8-bit advertising set handle.
1199 constexpr uint8_t kAdvertisingHandleMax = 0xEF;
1200 
1201 // The maximum value that can be set for the length of an Inquiry
1202 constexpr uint8_t kInquiryLengthMax = 0x30;
1203 
1204 // Bit 15, or "Clock_Offset_Valid_Flag" of the 16-bit clock offset field.
1205 // Some HCI commands that require a clock offset expect this bit to be set (e.g.
1206 // see HCI_Remote_Name_Request command, Vol 2, Part E, 7.1.19).
1207 constexpr uint16_t kClockOffsetValidFlagBit = 0x8000;
1208 
1209 // Masks the lower 15 bits of a Clock_Offset, excluding the bit 15 - the reserved/validity bit.
1210 constexpr uint16_t kClockOffsetMask = 0x7FFF;
1211 
1212 // Bitmask Values for the Scan_Enable parameter in a
1213 // HCI_(Read,Write)_Scan_Enable command.
1214 enum class ScanEnableBit : uint8_t {
1215   kInquiry  = (1 << 0), // Inquiry scan enabled
1216   kPage     = (1 << 1), // Page scan enabled.
1217 };
1218 
1219 using ScanEnableType = uint8_t;
1220 
1221 // Constant values for common scanning modes
1222 // See Spec 5.0, Vol 3, Part C, Section 4.2.2.1, Table 4.2
1223 constexpr uint16_t kPageScanR0Interval = 0x0800; // 1.28s
1224 constexpr uint16_t kPageScanR0Window = 0x0800; // 1.28s
1225 constexpr uint16_t kPageScanR1Interval = 0x0800; // 1.28s
1226 constexpr uint16_t kPageScanR1Window = 0x0011; // 10.625ms
1227 constexpr uint16_t kPageScanR2Interval = 0x1000; // 2.56s
1228 constexpr uint16_t kPageScanR2Window = 0x0011; // 10.625ms
1229 
1230 enum class InquiryScanType : uint8_t {
1231   kStandardScan = 0x00, // Standard scan (default) (mandatory)
1232   kInterlacedScan = 0x01, // Interlaced scan
1233 };
1234 
1235 // Link Types for BR/EDR connections.
1236 enum class LinkType : uint8_t {
1237   kSCO = 0x00,         // SCO
1238   kACL = 0x01,         // ACL (data channel)
1239   kExtendedSCO = 0x02, // eSCO
1240 };
1241 
1242 // Length of the Extended Inquiry Response data. (Vol 3, Part C, Section 8)
1243 constexpr size_t kExtendedInquiryResponseBytes = 240;
1244 
1245 // Maximum length of a local name in the Extended Inquiry Response data.
1246 // Length: 1 byte, DataType: 1 byte, Remaining buffer: 238 bytes.
1247 // (Vol 3, Part C, Section 8)
1248 constexpr size_t kExtendedInquiryResponseMaxNameBytes = kExtendedInquiryResponseBytes - 2;
1249 
1250 // Minimum supported encryption key size for ACL-U links, as queried by Read
1251 // Encryption Key Size. This isn't specified so the value is taken from the LE
1252 // limit for SM Long Term Keys (v5.0 Vol 3, Part H, 2.3.4). This limit applies
1253 // to the per-session encryption key, not the semi-permanent Link Key (v5.0
1254 // Vol 2, Part H, 1).
1255 constexpr uint8_t kMinEncryptionKeySize = 7;
1256 
1257 // Key types for BR/EDR link encryption as reported to the host using the Link
1258 // Key Notification event upon pairing or key changes (v5.0 Vol 2, Part E,
1259 // Section 7.7.24).
1260 //
1261 // "Combination" refers to keys created from contributions of two devices
1262 // according to v5.0 Vol 2, Part H, Section 3.2.4 and as opposed to "unit" keys
1263 // that are generated on a single device but used by both parties (Section 3.2.3
1264 // and deprecated in Section 3.1).
1265 //
1266 // Authenticated keys were generated using a challenge-response scheme described
1267 // inclusive-language: ignore
1268 // in v5.0 Vol 2, Part H, Section 5 to protect against man-in-the-middle (MITM)
1269 // attacks.
1270 //
1271 // When Secure Connections is used, the key exchange uses keys generated from
1272 // points on a 256-bit elliptic curve (v5.0 Vol 2, Part H, Section 7.1) and
1273 // authentication uses Secure Authentication procedures described in Section 5.
1274 enum class LinkKeyType : uint8_t {
1275   // Legacy pairing (pre-v2.1) key types
1276   kCombination = 0x00,
1277   kLocalUnit = 0x01,
1278   kRemoteUnit = 0x02,
1279 
1280   // Secure Simple Pairing key types
1281   kDebugCombination = 0x03,
1282   kUnauthenticatedCombination192 = 0x04,
1283   kAuthenticatedCombination192 = 0x05,
1284 
1285   // Special value indicating key generated due to a Change Connection Link Key
1286   // command. The actual key type is the same as before the change.
1287   kChangedCombination = 0x06,
1288 
1289   // Secure Simple Pairing with Secure Connections key types
1290   kUnauthenticatedCombination256 = 0x07,
1291   kAuthenticatedCombination256 = 0x08,
1292 };
1293 
1294 // Bitmask values for supported Packet Types
1295 // Used for HCI_Create_Connection and HCI_Change_Connection_Packet_Type
1296 enum class PacketTypeBits : uint16_t {
1297   // Reserved (1 << 0)
1298   kDisable2DH1 = (1 << 1),
1299   kDisable3DH1 = (1 << 2),
1300   kEnableDM1 = (1 << 3), // Note: always on in >= v1.2
1301   kEnableDH1 = (1 << 4),
1302   // Reserved (1 << 5)
1303   // Reserved (1 << 6)
1304   // Reserved (1 << 7)
1305   kDisable2DH3 = (1 << 8),
1306   kDisable3DH3 = (1 << 9),
1307   kEnableDM3 = (1 << 10),
1308   kEnableDH3 = (1 << 11),
1309   kDisable2DH5 = (1 << 12),
1310   kDisable3DH5 = (1 << 13),
1311   kEnableDM5 = (1 << 14),
1312   kEnableDH5 = (1 << 15),
1313 };
1314 
1315 using PacketTypeType = uint16_t;
1316 
1317 enum class RoleSwitchBits : uint8_t {
1318   kDisallowRoleSwitch = 0x0,
1319   kAllowRoleSwitch = 0x1
1320 };
1321 
1322 enum class ScoRetransmissionEffort : uint8_t {
1323   // SCO or eSCO
1324   kNone = 0x00,
1325 
1326   // eSCO only
1327   kPowerOptimized  = 0x01,
1328 
1329   // eSCO only
1330   kQualityOptimized  = 0x02,
1331 
1332   // SCO or eSCO
1333   kDontCare = 0xFF,
1334 };
1335 
1336 // Flush Timeout = N * 0.625ms (Core Spec v5.2, Vol 4, Part E, Sec 7.3.30).
1337 constexpr float kFlushTimeoutCommandParameterToMillisecondsConversionFactor = 0.625f;
1338 constexpr float kFlushTimeoutMsToCommandParameterConversionFactor = 1.0f / kFlushTimeoutCommandParameterToMillisecondsConversionFactor;
1339 
1340 // See Core Spec v5.2, Vol 4, Part E, Sec 7.3.30
1341 constexpr uint16_t kMaxAutomaticFlushTimeoutCommandParameterValue = 0x07FF;
1342 constexpr pw::chrono::SystemClock::duration kMaxAutomaticFlushTimeoutDuration = std::chrono::milliseconds(static_cast<int64_t>(kMaxAutomaticFlushTimeoutCommandParameterValue * kFlushTimeoutCommandParameterToMillisecondsConversionFactor));
1343 
1344 // Page Timeout = N * 0.625 ms (Core Spec v5.2, Vol 4, Part E, Sec 7.3.16).
1345 // The default is 5.12 sec.
1346 constexpr pw::chrono::SystemClock::duration kDurationPerPageTimeoutUnit = std::chrono::microseconds(625);
1347 constexpr pw::chrono::SystemClock::duration kMinPageTimeoutDuration = kDurationPerPageTimeoutUnit * static_cast<uint16_t>(pw::bluetooth::emboss::PageTimeout::MIN);
1348 constexpr pw::chrono::SystemClock::duration kDefaultPageTimeoutDuration = kDurationPerPageTimeoutUnit * static_cast<uint16_t>(pw::bluetooth::emboss::PageTimeout::DEFAULT);
1349 constexpr pw::chrono::SystemClock::duration kMaxPageTimeoutDuration = kDurationPerPageTimeoutUnit * static_cast<uint16_t>(pw::bluetooth::emboss::PageTimeout::MAX);
1350 
1351 }  // namespace bt::hci_spec
1352