• 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 #include <pw_bluetooth/hci_common.emb.h>
17 #include <pw_bluetooth/hci_events.emb.h>
18 
19 #include <array>
20 #include <cstdint>
21 
22 #include "pw_bluetooth_sapphire/internal/host/common/device_address.h"
23 #include "pw_bluetooth_sapphire/internal/host/common/device_class.h"
24 #include "pw_bluetooth_sapphire/internal/host/common/macros.h"
25 #include "pw_bluetooth_sapphire/internal/host/common/uint128.h"
26 #include "pw_bluetooth_sapphire/internal/host/hci-spec/constants.h"
27 
28 // This file contains general opcode/number and static packet definitions for
29 // the Bluetooth Host-Controller Interface. Each packet payload structure
30 // contains parameter descriptions based on their respective documentation in
31 // the Bluetooth Core Specification version 5.0
32 //
33 // NOTE: Avoid casting raw buffer pointers to the packet payload structure types
34 // below; use as template parameter to PacketView::payload(),
35 // MutableBufferView::mutable_payload(), or CommandPacket::mutable_payload()
36 // instead. Take extra care when accessing flexible array members.
37 
38 #pragma clang diagnostic ignored "-Wc99-extensions"
39 
40 namespace bt::hci_spec {
41 
42 using pw::bluetooth::emboss::ConnectionRole;
43 using pw::bluetooth::emboss::GenericEnableParam;
44 using pw::bluetooth::emboss::StatusCode;
45 
46 // HCI opcode as used in command packets.
47 using OpCode = uint16_t;
48 
49 // HCI event code as used in event packets.
50 using EventCode = uint8_t;
51 
52 // Data Connection Handle used for ACL and SCO logical link connections.
53 using ConnectionHandle = uint16_t;
54 
55 // Handle used to identify an advertising set used in the 5.0 Extended
56 // Advertising feature.
57 using AdvertisingHandle = uint8_t;
58 
59 // Handle used to identify a periodic advertiser used in the 5.0 Periodic
60 // Advertising feature.
61 using PeriodicAdvertiserHandle = uint16_t;
62 
63 // Returns the OGF (OpCode Group Field) which occupies the upper 6-bits of the
64 // opcode.
GetOGF(const OpCode opcode)65 inline uint8_t GetOGF(const OpCode opcode) { return opcode >> 10; }
66 
67 // Returns the OCF (OpCode Command Field) which occupies the lower 10-bits of
68 // the opcode.
GetOCF(const OpCode opcode)69 inline uint16_t GetOCF(const OpCode opcode) { return opcode & 0x3FF; }
70 
71 // Returns the opcode based on the given OGF and OCF fields.
DefineOpCode(const uint8_t ogf,const uint16_t ocf)72 constexpr OpCode DefineOpCode(const uint8_t ogf, const uint16_t ocf) {
73   return static_cast<uint16_t>(((ogf & 0x3F) << 10) | (ocf & 0x03FF));
74 }
75 
76 // ========================= HCI packet headers ==========================
77 // NOTE(armansito): The definitions below are incomplete since they get added as
78 // needed. This list will grow as we support more features.
79 
80 struct CommandHeader {
81   uint16_t opcode;
82   uint8_t parameter_total_size;
83 } __attribute__((packed));
84 
85 struct EventHeader {
86   uint8_t event_code;
87   uint8_t parameter_total_size;
88 } __attribute__((packed));
89 
90 struct ACLDataHeader {
91   // The first 16-bits contain the following fields, in order:
92   //   - 12-bits: Connection Handle
93   //   - 2-bits: Packet Boundary Flags
94   //   - 2-bits: Broadcast Flags
95   uint16_t handle_and_flags;
96 
97   // Length of data following the header.
98   uint16_t data_total_length;
99 } __attribute__((packed));
100 
101 struct SynchronousDataHeader {
102   // The first 16-bits contain the following fields, in order:
103   // - 12-bits: Connection Handle
104   // - 2-bits: Packet Status Flag
105   // - 2-bits: RFU
106   uint16_t handle_and_flags;
107 
108   // Length of the data following the header.
109   uint8_t data_total_length;
110 } __attribute__((packed));
111 
112 // Generic return parameter struct for commands that only return a status. This
113 // can also be used to check the status of HCI commands with more complex return
114 // parameters.
115 struct SimpleReturnParams {
116   // See enum StatusCode in hci_constants.h.
117   StatusCode status;
118 } __attribute__((packed));
119 
120 // ============= HCI Command and Event (op)code and payloads =============
121 
122 // No-Op
123 constexpr OpCode kNoOp = 0x0000;
124 
125 // The following is a list of HCI command and event declarations sorted by OGF
126 // category. Within each category the commands are sorted by their OCF. Each
127 // declaration is preceded by the name of the command or event followed by the
128 // Bluetooth Core Specification version in which it was introduced. Commands
129 // that apply to a specific Bluetooth sub-technology
130 // (e.g. BR/EDR, LE, AMP) will also contain that definition.
131 //
132 // NOTE(armansito): This list is incomplete. Entries will be added as needed.
133 
134 // ======= Link Control Commands =======
135 // Core Spec v5.0, Vol 2, Part E, Section 7.1
136 constexpr uint8_t kLinkControlOGF = 0x01;
LinkControlOpCode(const uint16_t ocf)137 constexpr OpCode LinkControlOpCode(const uint16_t ocf) {
138   return DefineOpCode(kLinkControlOGF, ocf);
139 }
140 
141 // ===============================
142 // Inquiry Command (v1.1) (BR/EDR)
143 constexpr OpCode kInquiry = LinkControlOpCode(0x0001);
144 
145 // ======================================
146 // Inquiry Cancel Command (v1.1) (BR/EDR)
147 constexpr OpCode kInquiryCancel = LinkControlOpCode(0x0002);
148 
149 // Inquiry Cancel Command has no command parameters.
150 
151 // =================================
152 // Create Connection (v1.1) (BR/EDR)
153 constexpr OpCode kCreateConnection = LinkControlOpCode(0x0005);
154 
155 // =======================================
156 // Disconnect Command (v1.1) (BR/EDR & LE)
157 constexpr OpCode kDisconnect = LinkControlOpCode(0x0006);
158 
159 // ========================================
160 // Create Connection Cancel (v1.1) (BR/EDR)
161 constexpr OpCode kCreateConnectionCancel = LinkControlOpCode(0x0008);
162 
163 struct CreateConnectionCancelReturnParams {
164   // See enum StatusCode in hci_constants.h.
165   StatusCode status;
166 
167   // BD_ADDR of the Create Connection Command Request
168   DeviceAddressBytes bd_addr;
169 } __attribute__((packed));
170 
171 // =========================================
172 // Accept Connection Request (v1.1) (BR/EDR)
173 constexpr OpCode kAcceptConnectionRequest = LinkControlOpCode(0x0009);
174 
175 // =========================================
176 // Reject Connection Request (v1.1) (BR/EDR)
177 constexpr OpCode kRejectConnectionRequest = LinkControlOpCode(0x000A);
178 
179 // ==============================================
180 // Link Key Request Reply Command (v1.1) (BR/EDR)
181 constexpr OpCode kLinkKeyRequestReply = LinkControlOpCode(0x000B);
182 
183 constexpr size_t kBrEdrLinkKeySize = 16;
184 
185 struct LinkKeyRequestReplyReturnParams {
186   // See enum StatusCode in hci_constants.h.
187   StatusCode status;
188 
189   // BD_ADDR of the device whose Link Key Request was fulfilled.
190   DeviceAddressBytes bd_addr;
191 } __attribute__((packed));
192 
193 // =======================================================
194 // Link Key Request Negative Reply Command (v1.1) (BR/EDR)
195 constexpr OpCode kLinkKeyRequestNegativeReply = LinkControlOpCode(0x000C);
196 
197 struct LinkKeyRequestNegativeReplyReturnParams {
198   // See enum StatusCode in hci_constants.h.
199   StatusCode status;
200 
201   // BD_ADDR of the device whose Link Key Request was denied.
202   DeviceAddressBytes bd_addr;
203 } __attribute__((packed));
204 
205 // ================================================
206 // Authentication Requested Command (v1.1) (BR/EDR)
207 constexpr OpCode kAuthenticationRequested = LinkControlOpCode(0x0011);
208 
209 // =================================================
210 // Set Connection Encryption Command (v1.1) (BR/EDR)
211 constexpr OpCode kSetConnectionEncryption = LinkControlOpCode(0x0013);
212 
213 // ============================================================
214 // Remote Name Request Command (v1.1) (BR/EDR)
215 constexpr OpCode kRemoteNameRequest = LinkControlOpCode(0x0019);
216 
217 // ======================================================
218 // Read Remote Supported Features Command (v1.1) (BR/EDR)
219 constexpr OpCode kReadRemoteSupportedFeatures = LinkControlOpCode(0x001B);
220 
221 // =====================================================
222 // Read Remote Extended Features Command (v1.2) (BR/EDR)
223 constexpr OpCode kReadRemoteExtendedFeatures = LinkControlOpCode(0x001C);
224 
225 // ============================================================
226 // Read Remote Version Information Command (v1.1) (BR/EDR & LE)
227 constexpr OpCode kReadRemoteVersionInfo = LinkControlOpCode(0x001D);
228 
229 // =============================================
230 // Reject Synchronous Connection Command (BR/EDR)
231 constexpr OpCode kRejectSynchronousConnectionRequest =
232     LinkControlOpCode(0x002A);
233 
234 // =========================================================
235 // IO Capability Request Reply Command (v2.1 + EDR) (BR/EDR)
236 constexpr OpCode kIOCapabilityRequestReply = LinkControlOpCode(0x002B);
237 
238 struct IOCapabilityRequestReplyReturnParams {
239   // See enum StatusCode in hci_constants.h.
240   StatusCode status;
241 
242   // BD_ADDR of the remote device involved in simple pairing process
243   DeviceAddressBytes bd_addr;
244 } __attribute__((packed));
245 
246 // =============================================================
247 // User Confirmation Request Reply Command (v2.1 + EDR) (BR/EDR)
248 constexpr OpCode kUserConfirmationRequestReply = LinkControlOpCode(0x002C);
249 
250 // ======================================================================
251 // User Confirmation Request Negative Reply Command (v2.1 + EDR) (BR/EDR)
252 constexpr OpCode kUserConfirmationRequestNegativeReply =
253     LinkControlOpCode(0x002D);
254 
255 // ========================================================
256 // User Passkey Request Reply Command (v2.1 + EDR) (BR/EDR)
257 constexpr OpCode kUserPasskeyRequestReply = LinkControlOpCode(0x002E);
258 
259 // =================================================================
260 // User Passkey Request Negative Reply Command (v2.1 + EDR) (BR/EDR)
261 constexpr OpCode kUserPasskeyRequestNegativeReply = LinkControlOpCode(0x002F);
262 
263 // ==================================================================
264 // IO Capability Request Negative Reply Command (v2.1 + EDR) (BR/EDR)
265 constexpr OpCode kIOCapabilityRequestNegativeReply = LinkControlOpCode(0x0034);
266 
267 struct IOCapabilityRequestNegativeReplyReturnParams {
268   // See enum StatusCode in hci_constants.h.
269   StatusCode status;
270 
271   // BD_ADDR of the remote device involved in simple pairing process
272   DeviceAddressBytes bd_addr;
273 } __attribute__((packed));
274 
275 // ======================================================
276 // Enhanced Setup Synchronous Connection Command (BR/EDR)
277 constexpr OpCode kEnhancedSetupSynchronousConnection =
278     LinkControlOpCode(0x003D);
279 
280 // ===============================================================
281 // Enhanced Accept Synchronous Connection Request Command (BR/EDR)
282 constexpr OpCode kEnhancedAcceptSynchronousConnectionRequest =
283     LinkControlOpCode(0x003E);
284 
285 // ======= Controller & Baseband Commands =======
286 // Core Spec v5.0 Vol 2, Part E, Section 7.3
287 constexpr uint8_t kControllerAndBasebandOGF = 0x03;
ControllerAndBasebandOpCode(const uint16_t ocf)288 constexpr OpCode ControllerAndBasebandOpCode(const uint16_t ocf) {
289   return DefineOpCode(kControllerAndBasebandOGF, ocf);
290 }
291 
292 // =============================
293 // Set Event Mask Command (v1.1)
294 constexpr OpCode kSetEventMask = ControllerAndBasebandOpCode(0x0001);
295 
296 // ====================
297 // Reset Command (v1.1)
298 constexpr OpCode kReset = ControllerAndBasebandOpCode(0x0003);
299 
300 // ========================================
301 // Write Local Name Command (v1.1) (BR/EDR)
302 constexpr OpCode kWriteLocalName = ControllerAndBasebandOpCode(0x0013);
303 
304 // =======================================
305 // Read Local Name Command (v1.1) (BR/EDR)
306 constexpr OpCode kReadLocalName = ControllerAndBasebandOpCode(0x0014);
307 
308 struct ReadLocalNameReturnParams {
309   // See enum StatusCode in hci_constants.h.
310   StatusCode status;
311 
312   // A UTF-8 encoded User Friendly Descriptive Name for the device.
313   // If the name contained in the parameter is shorter than 248 octets, the end
314   // of the name is indicated by a NULL octet (0x00), and the following octets
315   // (to fill up 248 octets, which is the length of the parameter) do not have
316   // valid values.
317   uint8_t local_name[kMaxNameLength];
318 } __attribute__((packed));
319 
320 // ==========================================
321 // Write Page Timeout Command (v1.1) (BR/EDR)
322 constexpr OpCode kWritePageTimeout = ControllerAndBasebandOpCode(0x0018);
323 
324 struct WritePageTimeoutReturnParams {
325   // See enum StatusCode in hci_constants.h.
326   StatusCode status;
327 } __attribute__((packed));
328 
329 // ========================================
330 // Read Scan Enable Command (v1.1) (BR/EDR)
331 constexpr OpCode kReadScanEnable = ControllerAndBasebandOpCode(0x0019);
332 
333 struct ReadScanEnableReturnParams {
334   // See enum StatusCode in hci_constants.h.
335   StatusCode status;
336 
337   // Bit Mask of enabled scans. See enum class ScanEnableBit in hci_constants.h
338   // for how to interpret this bitfield.
339   ScanEnableType scan_enable;
340 } __attribute__((packed));
341 
342 // =========================================
343 // Write Scan Enable Command (v1.1) (BR/EDR)
344 constexpr OpCode kWriteScanEnable = ControllerAndBasebandOpCode(0x001A);
345 
346 // ===============================================
347 // Read Page Scan Activity Command (v1.1) (BR/EDR)
348 constexpr OpCode kReadPageScanActivity = ControllerAndBasebandOpCode(0x001B);
349 
350 struct ReadPageScanActivityReturnParams {
351   // See enum StatusCode in hci_constants.h.
352   StatusCode status;
353 
354   // Page_Scan_Interval, in time slices (0.625ms)
355   // Range: kPageScanIntervalMin - kPageScanIntervalMax in hci_constants.h
356   uint16_t page_scan_interval;
357 
358   // Page_Scan_Window, in time slices
359   // Range: kPageScanWindowMin - kPageScanWindowMax in hci_constants.h
360   uint16_t page_scan_window;
361 } __attribute__((packed));
362 
363 // ================================================
364 // Write Page Scan Activity Command (v1.1) (BR/EDR)
365 constexpr OpCode kWritePageScanActivity = ControllerAndBasebandOpCode(0x001C);
366 
367 // ===============================================
368 // Read Inquiry Scan Activity Command (v1.1) (BR/EDR)
369 constexpr OpCode kReadInquiryScanActivity = ControllerAndBasebandOpCode(0x001D);
370 
371 struct ReadInquiryScanActivityReturnParams {
372   // See enum StatusCode in hci_constants.h.
373   StatusCode status;
374 
375   // Inquiry_Scan_Interval, in time slices (0.625ms)
376   // Range: kInquiryScanIntervalMin - kInquiryScanIntervalMax in hci_constants.h
377   uint16_t inquiry_scan_interval;
378 
379   // Inquiry_Scan_Window, in time slices
380   // Range: kInquiryScanWindowMin - kInquiryScanWindowMax in hci_constants.h
381   uint16_t inquiry_scan_window;
382 } __attribute__((packed));
383 
384 // ================================================
385 // Write Inquiry Scan Activity Command (v1.1) (BR/EDR)
386 constexpr OpCode kWriteInquiryScanActivity =
387     ControllerAndBasebandOpCode(0x001E);
388 
389 // ============================================
390 // Read Class of Device Command (v1.1) (BR/EDR)
391 constexpr OpCode kReadClassOfDevice = ControllerAndBasebandOpCode(0x0023);
392 
393 struct ReadClassOfDeviceReturnParams {
394   // See enum StatusCode in hci_constants.h.
395   StatusCode status;
396 
397   DeviceClass class_of_device;
398 } __attribute__((packed));
399 
400 // =============================================
401 // Write Class Of Device Command (v1.1) (BR/EDR)
402 constexpr OpCode kWriteClassOfDevice = ControllerAndBasebandOpCode(0x0024);
403 
404 // =============================================
405 // Write Automatic Flush Timeout Command (v1.1) (BR/EDR)
406 constexpr OpCode kWriteAutomaticFlushTimeout =
407     ControllerAndBasebandOpCode(0x0028);
408 
409 // ===============================================================
410 // Read Transmit Transmit Power Level Command (v1.1) (BR/EDR & LE)
411 constexpr OpCode kReadTransmitPowerLevel = ControllerAndBasebandOpCode(0x002D);
412 
413 struct ReadTransmitPowerLevelCommandParams {
414   // Connection_Handle (only the lower 12-bits are meaningful).
415   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
416   ConnectionHandle connection_handle;
417 
418   // The type of transmit power level to read.
419   ReadTransmitPowerType type;
420 } __attribute__((packed));
421 
422 struct ReadTransmitPowerLevelReturnParams {
423   // See enum StatusCode in hci_constants.h.
424   StatusCode status;
425 
426   // Connection_Handle (only the lower 12-bits are meaningful).
427   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
428   ConnectionHandle connection_handle;
429 
430   // Transmit power level.
431   //
432   //   Range: -30 ≤ N ≤ 20
433   //   Units: dBm
434   int8_t tx_power_level;
435 } __attribute__((packed));
436 
437 // ===============================================================
438 // Write Synchonous Flow Control Enable Command (BR/EDR)
439 constexpr OpCode kWriteSynchronousFlowControlEnable =
440     ControllerAndBasebandOpCode(0x002F);
441 
442 // ===================================
443 // Read Inquiry Scan Type (v1.2) (BR/EDR)
444 constexpr OpCode kReadInquiryScanType = ControllerAndBasebandOpCode(0x0042);
445 
446 struct ReadInquiryScanTypeReturnParams {
447   // See enum StatusCode in hci_constants.h.
448   StatusCode status;
449 
450   // See enum class InquiryScanType in hci_constants.h for possible values.
451   InquiryScanType inquiry_scan_type;
452 } __attribute__((packed));
453 
454 // ====================================
455 // Write Inquiry Scan Type (v1.2) (BR/EDR)
456 constexpr OpCode kWriteInquiryScanType = ControllerAndBasebandOpCode(0x0043);
457 
458 // =================================
459 // Read Inquiry Mode (v1.2) (BR/EDR)
460 constexpr OpCode kReadInquiryMode = ControllerAndBasebandOpCode(0x0044);
461 
462 struct ReadInquiryModeReturnParams {
463   // See enum StatusCode in hci_constants.h.
464   StatusCode status;
465 
466   pw::bluetooth::emboss::InquiryMode inquiry_mode;
467 } __attribute__((packed));
468 
469 // ==================================
470 // Write Inquiry Mode (v1.2) (BR/EDR)
471 constexpr OpCode kWriteInquiryMode = ControllerAndBasebandOpCode(0x0045);
472 
473 // ===================================
474 // Read Page Scan Type (v1.2) (BR/EDR)
475 constexpr OpCode kReadPageScanType = ControllerAndBasebandOpCode(0x0046);
476 
477 struct ReadPageScanTypeReturnParams {
478   // See enum StatusCode in hci_constants.h.
479   StatusCode status;
480 
481   // See enum class PageScanType in hci_constants.h for possible values.
482   pw::bluetooth::emboss::PageScanType page_scan_type;
483 } __attribute__((packed));
484 
485 // ====================================
486 // Write Page Scan Type (v1.2) (BR/EDR)
487 constexpr OpCode kWritePageScanType = ControllerAndBasebandOpCode(0x0047);
488 
489 // =================================
490 // Write Extended Inquiry Response (v1.2) (BR/EDR)
491 constexpr OpCode kWriteExtendedInquiryResponse =
492     ControllerAndBasebandOpCode(0x0052);
493 
494 // ==============================================
495 // Read Simple Pairing Mode (v2.1 + EDR) (BR/EDR)
496 constexpr OpCode kReadSimplePairingMode = ControllerAndBasebandOpCode(0x0055);
497 
498 struct ReadSimplePairingModeReturnParams {
499   // See enum StatusCode in hci_constants.h
500   StatusCode status;
501 
502   // Simple pairing Mode.
503   GenericEnableParam simple_pairing_mode;
504 } __attribute__((packed));
505 
506 // ===============================================
507 // Write Simple Pairing Mode (v2.1 + EDR) (BR/EDR)
508 constexpr OpCode kWriteSimplePairingMode = ControllerAndBasebandOpCode(0x0056);
509 
510 // =========================================
511 // Set Event Mask Page 2 Command (v3.0 + HS)
512 constexpr OpCode kSetEventMaskPage2 = ControllerAndBasebandOpCode(0x0063);
513 
514 struct SetEventMaskPage2CommandParams {
515   // Bit mask used to control which HCI events are generated by the HCI for the
516   // Host. See enum class EventMaskPage2 in hci_constants.h
517   uint64_t event_mask;
518 } __attribute__((packed));
519 
520 // =========================================================
521 // Read Flow Control Mode Command (v3.0 + HS) (BR/EDR & AMP)
522 constexpr OpCode kReadFlowControlMode = ControllerAndBasebandOpCode(0x0066);
523 
524 struct ReadFlowControlModeReturnParams {
525   // See enum StatusCode in hci_constants.h.
526   StatusCode status;
527 
528   // See enum class FlowControlMode in hci_constants.h for possible values.
529   FlowControlMode flow_control_mode;
530 } __attribute__((packed));
531 
532 // ==========================================================
533 // Write Flow Control Mode Command (v3.0 + HS) (BR/EDR & AMP)
534 constexpr OpCode kWriteFlowControlMode = ControllerAndBasebandOpCode(0x0067);
535 
536 struct WriteFlowControlModeCommandParams {
537   // See enum class FlowControlMode in hci_constants.h for possible values.
538   FlowControlMode flow_control_mode;
539 } __attribute__((packed));
540 
541 // ============================================
542 // Read LE Host Support Command (v4.0) (BR/EDR)
543 constexpr OpCode kReadLEHostSupport = ControllerAndBasebandOpCode(0x006C);
544 
545 struct ReadLEHostSupportReturnParams {
546   // See enum StatusCode in hci_constants.h.
547   StatusCode status;
548 
549   GenericEnableParam le_supported_host;
550 
551   // Core Spec v5.0, Vol 2, Part E, Section 6.35: This value is set to "disabled
552   // (0x00)" by default and "shall be ignored".
553   uint8_t simultaneous_le_host;
554 } __attribute__((packed));
555 
556 // =============================================
557 // Write LE Host Support Command (v4.0) (BR/EDR)
558 constexpr OpCode kWriteLEHostSupport = ControllerAndBasebandOpCode(0x006D);
559 
560 // =============================================
561 // Write Secure Connections Host Support Command (v4.1) (BR/EDR)
562 constexpr OpCode kWriteSecureConnectionsHostSupport =
563     ControllerAndBasebandOpCode(0x007A);
564 
565 // ===============================================================
566 // Read Authenticated Payload Timeout Command (v4.1) (BR/EDR & LE)
567 constexpr OpCode kReadAuthenticatedPayloadTimeout =
568     ControllerAndBasebandOpCode(0x007B);
569 
570 struct ReadAuthenticatedPayloadTimeoutCommandParams {
571   // Connection_Handle (only the lower 12-bits are meaningful).
572   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
573   ConnectionHandle connection_handle;
574 } __attribute__((packed));
575 
576 struct ReadAuthenticatedPayloadTimeoutReturnParams {
577   // See enum StatusCode in hci_constants.h.
578   StatusCode status;
579 
580   // Connection_Handle (only the lower 12-bits are meaningful).
581   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
582   ConnectionHandle connection_handle;
583 
584   // Default = 0x0BB8 (30 s)
585   // Range: 0x0001 to 0xFFFF
586   // Time = N * 10 ms
587   // Time Range: 10 ms to 655,350 ms
588   uint16_t authenticated_payload_timeout;
589 } __attribute__((packed));
590 
591 // ================================================================
592 // Write Authenticated Payload Timeout Command (v4.1) (BR/EDR & LE)
593 constexpr OpCode kWriteAuthenticatedPayloadTimeout =
594     ControllerAndBasebandOpCode(0x007C);
595 
596 struct WriteAuthenticatedPayloadTimeoutCommandParams {
597   // Connection_Handle (only the lower 12-bits are meaningful).
598   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
599   ConnectionHandle connection_handle;
600 
601   // Default = 0x0BB8 (30 s)
602   // Range: 0x0001 to 0xFFFF
603   // Time = N * 10 ms
604   // Time Range: 10 ms to 655,350 ms
605   uint16_t authenticated_payload_timeout;
606 } __attribute__((packed));
607 
608 struct WriteAuthenticatedPayloadTimeoutReturnParams {
609   // See enum StatusCode in hci_constants.h.
610   StatusCode status;
611 
612   // Connection_Handle (only the lower 12-bits are meaningful).
613   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
614   ConnectionHandle connection_handle;
615 } __attribute__((packed));
616 
617 // ======= Informational Parameters =======
618 // Core Spec v5.0 Vol 2, Part E, Section 7.4
619 constexpr uint8_t kInformationalParamsOGF = 0x04;
InformationalParamsOpCode(const uint16_t ocf)620 constexpr OpCode InformationalParamsOpCode(const uint16_t ocf) {
621   return DefineOpCode(kInformationalParamsOGF, ocf);
622 }
623 
624 // =============================================
625 // Read Local Version Information Command (v1.1)
626 constexpr OpCode kReadLocalVersionInfo = InformationalParamsOpCode(0x0001);
627 
628 struct ReadLocalVersionInfoReturnParams {
629   // See enum StatusCode in hci_constants.h.
630   StatusCode status;
631 
632   pw::bluetooth::emboss::CoreSpecificationVersion hci_version;
633 
634   uint16_t hci_revision;
635   uint8_t lmp_pal_version;
636   uint16_t manufacturer_name;
637   uint16_t lmp_pal_subversion;
638 } __attribute__((packed));
639 
640 // ============================================
641 // Read Local Supported Commands Command (v1.2)
642 constexpr OpCode kReadLocalSupportedCommands =
643     InformationalParamsOpCode(0x0002);
644 
645 struct ReadLocalSupportedCommandsReturnParams {
646   // See enum StatusCode in hci_constants.h.
647   StatusCode status;
648 
649   // See enum class SupportedCommand in hci_constants.h for how to interpret
650   // this bitfield.
651   uint8_t supported_commands[64];
652 } __attribute__((packed));
653 
654 // ============================================
655 // Read Local Supported Features Command (v1.1)
656 constexpr OpCode kReadLocalSupportedFeatures =
657     InformationalParamsOpCode(0x0003);
658 
659 struct ReadLocalSupportedFeaturesReturnParams {
660   // See enum StatusCode in hci_constants.h.
661   StatusCode status;
662 
663   // Bit Mask List of LMP features. See enum class LMPFeature in hci_constants.h
664   // for how to interpret this bitfield.
665   uint64_t lmp_features;
666 } __attribute__((packed));
667 
668 // ====================================================
669 // Read Local Extended Features Command (v1.2) (BR/EDR)
670 constexpr OpCode kReadLocalExtendedFeatures = InformationalParamsOpCode(0x0004);
671 
672 struct ReadLocalExtendedFeaturesReturnParams {
673   // See enum StatusCode in hci_constants.h.
674   StatusCode status;
675   uint8_t page_number;
676   uint8_t maximum_page_number;
677   uint64_t extended_lmp_features;
678 } __attribute__((packed));
679 
680 // ===============================
681 // Read Buffer Size Command (v1.1)
682 constexpr OpCode kReadBufferSize = InformationalParamsOpCode(0x0005);
683 
684 struct ReadBufferSizeReturnParams {
685   // See enum StatusCode in hci_constants.h.
686   StatusCode status;
687 
688   uint16_t hc_acl_data_packet_length;
689   uint8_t hc_synchronous_data_packet_length;
690   uint16_t hc_total_num_acl_data_packets;
691   uint16_t hc_total_num_synchronous_data_packets;
692 } __attribute__((packed));
693 
694 // ========================================
695 // Read BD_ADDR Command (v1.1) (BR/EDR, LE)
696 constexpr OpCode kReadBDADDR = InformationalParamsOpCode(0x0009);
697 
698 struct ReadBDADDRReturnParams {
699   // See enum StatusCode in hci_constants.h.
700   StatusCode status;
701 
702   DeviceAddressBytes bd_addr;
703 } __attribute__((packed));
704 
705 // =======================================================
706 // Read Data Block Size Command (v3.0 + HS) (BR/EDR & AMP)
707 constexpr OpCode kReadDataBlockSize = InformationalParamsOpCode(0x000A);
708 
709 struct ReadDataBlockSizeReturnParams {
710   // See enum StatusCode in hci_constants.h.
711   StatusCode status;
712 
713   uint16_t max_acl_data_packet_length;
714   uint16_t data_block_length;
715   uint16_t total_num_data_blocks;
716 } __attribute__((packed));
717 
718 // ======= Events =======
719 // Core Spec v5.0 Vol 2, Part E, Section 7.7
720 
721 // Reserved for vendor-specific debug events
722 // (Vol 2, Part E, Section 5.4.4)
723 constexpr EventCode kVendorDebugEventCode = 0xFF;
724 
725 // ======================================
726 // Inquiry Complete Event (v1.1) (BR/EDR)
727 constexpr EventCode kInquiryCompleteEventCode = 0x01;
728 
729 // ====================================
730 // Inquiry Result Event (v1.1) (BR/EDR)
731 constexpr EventCode kInquiryResultEventCode = 0x02;
732 
733 // =========================================
734 // Connection Complete Event (v1.1) (BR/EDR)
735 constexpr EventCode kConnectionCompleteEventCode = 0x03;
736 
737 // ========================================
738 // Connection Request Event (v1.1) (BR/EDR)
739 constexpr EventCode kConnectionRequestEventCode = 0x04;
740 
741 // =================================================
742 // Disconnection Complete Event (v1.1) (BR/EDR & LE)
743 constexpr EventCode kDisconnectionCompleteEventCode = 0x05;
744 
745 // =============================================
746 // Authentication Complete Event (v1.1) (BR/EDR)
747 constexpr EventCode kAuthenticationCompleteEventCode = 0x06;
748 
749 // ==================================================
750 // Remote Name Request Complete Event (v1.1) (BR/EDR)
751 constexpr EventCode kRemoteNameRequestCompleteEventCode = 0x07;
752 
753 // ============================================
754 // Encryption Change Event (v1.1) (BR/EDR & LE)
755 constexpr EventCode kEncryptionChangeEventCode = 0x08;
756 
757 // =========================================================
758 // Change Connection Link Key Complete Event (v1.1) (BR/EDR)
759 constexpr EventCode kChangeConnectionLinkKeyCompleteEventCode = 0x09;
760 
761 struct ChangeConnectionLinkKeyCompleteEventParams {
762   // See enum StatusCode in hci_constants.h.
763   StatusCode status;
764 
765   // Connection_Handle (only the lower 12-bits are meaningful).
766   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
767   ConnectionHandle connection_handle;
768 } __attribute__((packed));
769 
770 // =============================================================
771 // Read Remote Supported Features Complete Event (v1.1) (BR/EDR)
772 constexpr EventCode kReadRemoteSupportedFeaturesCompleteEventCode = 0x0B;
773 
774 struct ReadRemoteSupportedFeaturesCompleteEventParams {
775   // See enum StatusCode in hci_constants.h.
776   StatusCode status;
777 
778   // A connection handle for an ACL connection.
779   //  Range: 0x0000 to kConnectionHandleMax in hci_constants.h
780   ConnectionHandle connection_handle;
781 
782   // Bit Mask List of LMP features. See enum class LMPFeature in hci_constants.h
783   // for how to interpret this bitfield.
784   uint64_t lmp_features;
785 } __attribute__((packed));
786 
787 // ===================================================================
788 // Read Remote Version Information Complete Event (v1.1) (BR/EDR & LE)
789 constexpr EventCode kReadRemoteVersionInfoCompleteEventCode = 0x0C;
790 
791 // =============================
792 // Command Complete Event (v1.1)
793 constexpr EventCode kCommandCompleteEventCode = 0x0E;
794 
795 struct CommandCompleteEventParams {
796   CommandCompleteEventParams() = delete;
797   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(CommandCompleteEventParams);
798 
799   // The Number of HCI command packets which are allowed to be sent to the
800   // Controller from the Host.
801   uint8_t num_hci_command_packets;
802 
803   // OpCode of the command which caused this event.
804   uint16_t command_opcode;
805 
806   // This is the return parameter(s) for the command specified in the
807   // |command_opcode| event parameter. Refer to the Bluetooth Core Specification
808   // v5.0, Vol 2, Part E for each command’s definition for the list of return
809   // parameters associated with that command.
810   uint8_t return_parameters[];
811 } __attribute__((packed));
812 
813 // ===========================
814 // Command Status Event (v1.1)
815 constexpr EventCode kCommandStatusEventCode = 0x0F;
816 constexpr uint8_t kCommandStatusPending = 0x00;
817 
818 struct CommandStatusEventParams {
819   // See enum StatusCode in hci_constants.h.
820   StatusCode status;
821 
822   // The Number of HCI command packets which are allowed to be sent to the
823   // Controller from the Host.
824   uint8_t num_hci_command_packets;
825 
826   // OpCode of the command which caused this event and is pending completion.
827   uint16_t command_opcode;
828 } __attribute__((packed));
829 
830 // ===========================
831 // Hardware Error Event (v1.1)
832 constexpr EventCode kHardwareErrorEventCode = 0x10;
833 
834 struct HardwareErrorEventParams {
835   // These Hardware_Codes will be implementation-specific, and can be assigned
836   // to indicate various hardware problems.
837   uint8_t hardware_code;
838 } __attribute__((packed));
839 
840 // ========================================
841 // Role Change Event (BR/EDR) (v1.1)
842 constexpr EventCode kRoleChangeEventCode = 0x12;
843 
844 // ========================================
845 // Number Of Completed Packets Event (v1.1)
846 constexpr EventCode kNumberOfCompletedPacketsEventCode = 0x13;
847 
848 struct NumberOfCompletedPacketsEventData {
849   uint16_t connection_handle;
850   uint16_t hc_num_of_completed_packets;
851 } __attribute__((packed));
852 
853 struct NumberOfCompletedPacketsEventParams {
854   NumberOfCompletedPacketsEventParams() = delete;
855   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(NumberOfCompletedPacketsEventParams);
856 
857   uint8_t number_of_handles;
858   NumberOfCompletedPacketsEventData data[];
859 } __attribute__((packed));
860 
861 // ======================================
862 // Link Key Request Event (v1.1) (BR/EDR)
863 constexpr EventCode kLinkKeyRequestEventCode = 0x17;
864 
865 // ===========================================
866 // Link Key Notification Event (v1.1) (BR/EDR)
867 constexpr EventCode kLinkKeyNotificationEventCode = 0x18;
868 
869 // ===========================================
870 // Data Buffer Overflow Event (v1.1) (BR/EDR & LE)
871 constexpr EventCode kDataBufferOverflowEventCode = 0x1A;
872 
873 // ==============================================
874 // Inquiry Result with RSSI Event (v1.2) (BR/EDR)
875 constexpr EventCode kInquiryResultWithRSSIEventCode = 0x22;
876 
877 // ============================================================
878 // Read Remote Extended Features Complete Event (v1.1) (BR/EDR)
879 constexpr EventCode kReadRemoteExtendedFeaturesCompleteEventCode = 0x23;
880 
881 // ============================================================
882 // Synchronous Connection Complete Event (BR/EDR)
883 constexpr EventCode kSynchronousConnectionCompleteEventCode = 0x2C;
884 
885 // =============================================
886 // Extended Inquiry Result Event (v1.2) (BR/EDR)
887 constexpr EventCode kExtendedInquiryResultEventCode = 0x2F;
888 
889 // ================================================================
890 // Encryption Key Refresh Complete Event (v2.1 + EDR) (BR/EDR & LE)
891 constexpr EventCode kEncryptionKeyRefreshCompleteEventCode = 0x30;
892 
893 // =================================================
894 // IO Capability Request Event (v2.1 + EDR) (BR/EDR)
895 constexpr EventCode kIOCapabilityRequestEventCode = 0x31;
896 
897 // ==================================================
898 // IO Capability Response Event (v2.1 + EDR) (BR/EDR)
899 constexpr EventCode kIOCapabilityResponseEventCode = 0x32;
900 
901 // =====================================================
902 // User Confirmation Request Event (v2.1 + EDR) (BR/EDR)
903 constexpr EventCode kUserConfirmationRequestEventCode = 0x33;
904 
905 struct UserConfirmationRequestEventParams {
906   // Address of the device involved in simple pairing process
907   DeviceAddressBytes bd_addr;
908 
909   // Numeric value to be displayed. Valid values are 0 - 999999.
910   uint32_t numeric_value;
911 } __attribute__((packed));
912 
913 // ================================================
914 // User Passkey Request Event (v2.1 + EDR) (BR/EDR)
915 constexpr EventCode kUserPasskeyRequestEventCode = 0x34;
916 
917 struct UserPasskeyRequestEventParams {
918   // Address of the device involved in simple pairing process
919   DeviceAddressBytes bd_addr;
920 } __attribute__((packed));
921 
922 // ===================================================
923 // Simple Pairing Complete Event (v2.1 + EDR) (BR/EDR)
924 constexpr EventCode kSimplePairingCompleteEventCode = 0x36;
925 
926 struct SimplePairingCompleteEventParams {
927   // See enum StatusCode in hci_constants.h.
928   StatusCode status;
929 
930   // Address of the device involved in simple pairing process
931   DeviceAddressBytes bd_addr;
932 } __attribute__((packed));
933 
934 // =====================================================
935 // User Passkey Notification Event (v2.1 + EDR) (BR/EDR)
936 constexpr EventCode kUserPasskeyNotificationEventCode = 0x3B;
937 
938 struct UserPasskeyNotificationEventParams {
939   // Address of the device involved in simple pairing process
940   DeviceAddressBytes bd_addr;
941 
942   // Numeric value (passkey) entered by user. Valid values are 0 - 999999.
943   uint32_t numeric_value;
944 } __attribute__((packed));
945 
946 // =========================
947 // LE Meta Event (v4.0) (LE)
948 constexpr EventCode kLEMetaEventCode = 0x3E;
949 
950 struct LEMetaEventParams {
951   LEMetaEventParams() = delete;
952   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(LEMetaEventParams);
953 
954   // The event code for the LE subevent.
955   EventCode subevent_code;
956 
957   // Beginning of parameters that are specific to the LE subevent.
958   uint8_t subevent_parameters[];
959 } __attribute__((packed));
960 
961 // LE Connection Complete Event (v4.0) (LE)
962 constexpr EventCode kLEConnectionCompleteSubeventCode = 0x01;
963 
964 // LE Advertising Report Event (v4.0) (LE)
965 constexpr EventCode kLEAdvertisingReportSubeventCode = 0x02;
966 
967 struct LEAdvertisingReportData {
968   LEAdvertisingReportData() = delete;
969   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(LEAdvertisingReportData);
970 
971   // The event type.
972   LEAdvertisingEventType event_type;
973 
974   // Type of |address| for the advertising device.
975   LEAddressType address_type;
976 
977   // Public Device Address, Random Device Address, Public Identity Address or
978   // Random (static) Identity Address of the advertising device.
979   DeviceAddressBytes address;
980 
981   // Length of the advertising data payload.
982   uint8_t length_data;
983 
984   // The beginning of |length_data| octets of advertising or scan response data
985   // formatted as defined in Core Spec v5.0, Vol 3, Part C, Section 11.
986   uint8_t data[];
987 
988   // Immediately following |data| there is a single octet field containing the
989   // received signal strength for this advertising report. Since |data| has a
990   // variable length we do not declare it as a field within this struct.
991   //
992   //   Range: -127 <= N <= +20
993   //   Units: dBm
994   //   If N == 127: RSSI is not available.
995   //
996   // int8_t rssi;
997 } __attribute__((packed));
998 
999 struct LEAdvertisingReportSubeventParams {
1000   LEAdvertisingReportSubeventParams() = delete;
1001   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(LEAdvertisingReportSubeventParams);
1002 
1003   // Number of LEAdvertisingReportData instances contained in the array
1004   // |reports|.
1005   uint8_t num_reports;
1006 
1007   // Beginning of LEAdvertisingReportData array. Since each report data has a
1008   // variable length, the contents of |reports| this is declared as an array of
1009   // uint8_t.
1010   uint8_t reports[];
1011 } __attribute__((packed));
1012 
1013 // LE Connection Update Complete Event (v4.0) (LE)
1014 constexpr EventCode kLEConnectionUpdateCompleteSubeventCode = 0x03;
1015 
1016 // LE Read Remote Features Complete Event (v4.0) (LE)
1017 constexpr EventCode kLEReadRemoteFeaturesCompleteSubeventCode = 0x04;
1018 
1019 // LE Long Term Key Request Event (v4.0) (LE)
1020 constexpr EventCode kLELongTermKeyRequestSubeventCode = 0x05;
1021 
1022 struct LELongTermKeyRequestSubeventParams {
1023   // Connection Handle (only the lower 12-bits are meaningful).
1024   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1025   ConnectionHandle connection_handle;
1026 
1027   // 64-bit random number.
1028   uint64_t random_number;
1029 
1030   // 16-bit encrypted diversifier.
1031   uint16_t encrypted_diversifier;
1032 } __attribute__((packed));
1033 
1034 // LE Remote Connection Parameter Request Event (v4.1) (LE)
1035 constexpr EventCode kLERemoteConnectionParameterRequestSubeventCode = 0x06;
1036 
1037 struct LERemoteConnectionParameterRequestSubeventParams {
1038   // Connection Handle (only the lower 12-bits are meaningful).
1039   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1040   ConnectionHandle connection_handle;
1041 
1042   // Range: see kLEConnectionInterval[Min|Max] in hci_constants.h
1043   // Time: N * 1.25 ms
1044   // Time Range: 7.5 ms to 4 s.
1045   uint16_t interval_min;
1046   uint16_t interval_max;
1047 
1048   // Range: 0x0000 to kLEConnectionLatencyMax in hci_constants.h
1049   uint16_t latency;
1050 
1051   // Range: see kLEConnectionSupervisionTimeout[Min|Max] in hci_constants.h
1052   // Time: N * 10 ms
1053   // Time Range: 100 ms to 32 s
1054   uint16_t timeout;
1055 } __attribute__((packed));
1056 
1057 // LE Data Length Change Event (v4.2) (LE)
1058 constexpr EventCode kLEDataLengthChangeSubeventCode = 0x07;
1059 
1060 struct LEDataLengthChangeSubeventParams {
1061   // Connection Handle (only the lower 12-bits are meaningful).
1062   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1063   ConnectionHandle connection_handle;
1064 
1065   // Range: see kLEMaxTxOctets[Min|Max] in hci_constants.h
1066   uint16_t max_tx_octets;
1067 
1068   // Range: see kLEMaxTxTime[Min|Max] in hci_constants.h
1069   uint16_t max_tx_time;
1070 
1071   // Range: see kLEMaxTxOctets[Min|Max] in hci_constants.h
1072   uint16_t max_rx_octets;
1073 
1074   // Range: see kLEMaxTxTime[Min|Max] in hci_constants.h
1075   uint16_t max_rx_time;
1076 } __attribute__((packed));
1077 
1078 // LE Read Local P-256 Public Key Complete Event (v4.2) (LE)
1079 constexpr EventCode kLEReadLocalP256PublicKeyCompleteSubeventCode = 0x08;
1080 
1081 struct LEReadLOcalP256PublicKeyCompleteSubeventParams {
1082   // See enum StatusCode in hci_constants.h.
1083   StatusCode status;
1084 
1085   // Local P-256 public key.
1086   uint8_t local_p256_public_key[64];
1087 } __attribute__((packed));
1088 
1089 // LE Generate DHKey Complete Event (v4.2) (LE)
1090 constexpr EventCode kLEGenerateDHKeyCompleteSubeventCode = 0x09;
1091 
1092 struct LEGenerateDHKeyCompleteSubeventParams {
1093   // See enum StatusCode in hci_constants.h.
1094   StatusCode status;
1095 
1096   // Diffie Hellman Key.
1097   uint8_t dh_key[32];
1098 } __attribute__((packed));
1099 
1100 // LE Enhanced Connection Complete Event (v4.2) (LE)
1101 constexpr EventCode kLEEnhancedConnectionCompleteSubeventCode = 0x0A;
1102 
1103 struct LEEnhancedConnectionCompleteSubeventParams {
1104   // See enum StatusCode in hci_constants.h.
1105   StatusCode status;
1106 
1107   // Connection Handle (only the lower 12-bits are meaningful).
1108   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1109   ConnectionHandle connection_handle;
1110 
1111   ConnectionRole role;
1112   LEAddressType peer_address_type;
1113 
1114   // Public Device Address, or Random Device Address, Public Identity Address or
1115   // Random (static) Identity Address of the device to be connected.
1116   DeviceAddressBytes peer_address;
1117 
1118   DeviceAddressBytes local_resolvable_private_address;
1119   DeviceAddressBytes peer_resolvable_private_address;
1120 
1121   // Range: see kLEConnectionInterval[Min|Max] in hci_constants.h
1122   // Time: N * 1.25 ms
1123   // Time Range: 7.5 ms to 4 s.
1124   uint16_t conn_interval;
1125 
1126   // Range: 0x0000 to kLEConnectionLatencyMax in hci_constants.h
1127   uint16_t conn_latency;
1128 
1129   // Range: see kLEConnectionSupervisionTimeout[Min|Max] in hci_constants.h
1130   // Time: N * 10 ms
1131   // Time Range: 100 ms to 32 s
1132   uint16_t supervision_timeout;
1133 
1134   // The Central_Clock_Accuracy parameter is only valid for a peripheral. On a
1135   // central, this parameter shall be set to 0x00.
1136   pw::bluetooth::emboss::LEClockAccuracy central_clock_accuracy;
1137 } __attribute__((packed));
1138 
1139 // LE Directed Advertising Report Event (v4.2) (LE)
1140 constexpr EventCode kLEDirectedAdvertisingReportSubeventCode = 0x0B;
1141 
1142 struct LEDirectedAdvertisingReportData {
1143   // The event type. This is always equal to
1144   // LEAdvertisingEventType::kAdvDirectInd.
1145   LEAdvertisingEventType event_type;
1146 
1147   // Type of |address| for the advertising device.
1148   LEAddressType address_type;
1149 
1150   // Public Device Address, Random Device Address, Public Identity Address or
1151   // Random (static) Identity Address of the advertising device.
1152   DeviceAddressBytes address;
1153 
1154   // By default this is set to LEAddressType::kRandom and |direct_address| will
1155   // contain a random device address.
1156   LEAddressType direct_address_type;
1157   DeviceAddressBytes direct_address;
1158 
1159   // Range: -127 <= N <= +20
1160   // Units: dBm
1161   // If N == 127: RSSI is not available.
1162   int8_t rssi;
1163 } __attribute__((packed));
1164 
1165 struct LEDirectedAdvertisingReportSubeventParams {
1166   LEDirectedAdvertisingReportSubeventParams() = delete;
1167   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(LEDirectedAdvertisingReportSubeventParams);
1168 
1169   // Number of LEAdvertisingReportData instances contained in the array
1170   // |reports|.
1171   uint8_t num_reports;
1172 
1173   // The report array parameters.
1174   LEDirectedAdvertisingReportData reports[];
1175 } __attribute__((packed));
1176 
1177 // LE PHY Update Complete Event (v5.0) (LE)
1178 constexpr EventCode kLEPHYUpdateCompleteSubeventCode = 0x0C;
1179 
1180 struct LEPHYUpdateCompleteSubeventParams {
1181   // See enum StatusCode in hci_constants.h.
1182   StatusCode status;
1183 
1184   // Connection Handle (only the lower 12-bits are meaningful).
1185   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1186   ConnectionHandle connection_handle;
1187 
1188   // The transmitter PHY.
1189   LEPHY tx_phy;
1190 
1191   // The receiver PHY.
1192   LEPHY rx_phy;
1193 } __attribute__((packed));
1194 
1195 // LE Extended Advertising Report Event (v5.0) (LE)
1196 constexpr EventCode kLEExtendedAdvertisingReportSubeventCode = 0x0D;
1197 
1198 // LE Periodic Advertising Sync Established Event (v5.0) (LE)
1199 constexpr EventCode kLEPeriodicAdvertisingSyncEstablishedSubeventCode = 0x0E;
1200 
1201 struct LEPeriodicAdvertisingSyncEstablishedSubeventParams {
1202   // See enum StatusCode in hci_constants.h.
1203   StatusCode status;
1204 
1205   // Handle used to identify the periodic advertiser (only the lower 12 bits are
1206   // meaningful).
1207   PeriodicAdvertiserHandle sync_handle;
1208 
1209   // Value of the Advertising SID subfield in the ADI field of the PDU.
1210   uint8_t advertising_sid;
1211 
1212   // Address type of the advertiser.
1213   LEAddressType advertiser_address_type;
1214 
1215   // Public Device Address, Random Device Address, Public Identity Address, or
1216   // Random (static) Identity Address of the advertiser.
1217   DeviceAddressBytes advertiser_address;
1218 
1219   // Advertiser_PHY.
1220   LEPHY advertiser_phy;
1221 
1222   // Range: See kLEPeriodicAdvertisingInterval[Min|Max] in hci_constants.h
1223   // Time = N * 1.25 ms
1224   // Time Range: 7.5ms to 81.91875 s
1225   uint16_t periodic_adv_interval;
1226 
1227   // Advertiser_Clock_Accuracy.
1228   pw::bluetooth::emboss::LEClockAccuracy advertiser_clock_accuracy;
1229 } __attribute__((packed));
1230 
1231 // LE Periodic Advertising Report Event (v5.0) (LE)
1232 constexpr EventCode kLEPeriodicAdvertisingReportSubeventCode = 0x0F;
1233 
1234 struct LEPeriodicAdvertisingReportSubeventParams {
1235   LEPeriodicAdvertisingReportSubeventParams() = delete;
1236   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(LEPeriodicAdvertisingReportSubeventParams);
1237 
1238   // (only the lower 12 bits are meaningful).
1239   PeriodicAdvertiserHandle sync_handle;
1240 
1241   // Range: -127 <= N <= +126
1242   // Units: dBm
1243   int8_t tx_power;
1244 
1245   // Range: -127 <= N <= +20
1246   // Units: dBm
1247   // If N == 127: RSSI is not available.
1248   int8_t rssi;
1249 
1250   // As of Core Spec v5.0 this parameter is intended to be used in a future
1251   // feature.
1252   uint8_t unused;
1253 
1254   // Data status of the periodic advertisement. Indicates whether or not the
1255   // controller has split the data into multiple reports.
1256   LEAdvertisingDataStatus data_status;
1257 
1258   // Length of the Data field.
1259   uint8_t data_length;
1260 
1261   // |data_length| octets of data received from a Periodic Advertising packet.
1262   uint8_t data[];
1263 } __attribute__((packed));
1264 
1265 // LE Periodic Advertising Sync Lost Event (v5.0) (LE)
1266 constexpr EventCode kLEPeriodicAdvertisingSyncLostSubeventCode = 0x10;
1267 
1268 struct LEPeriodicAdvertisingSyncLostSubeventParams {
1269   // Used to identify the periodic advertiser (only the lower 12 bits are
1270   // meaningful).
1271   PeriodicAdvertiserHandle sync_handle;
1272 } __attribute__((packed));
1273 
1274 // LE Scan Timeout Event (v5.0) (LE)
1275 constexpr EventCode kLEScanTimeoutSubeventCode = 0x11;
1276 
1277 // LE Advertising Set Terminated Event (v5.0) (LE)
1278 constexpr EventCode kLEAdvertisingSetTerminatedSubeventCode = 0x012;
1279 
1280 struct LEAdvertisingSetTerminatedSubeventParams {
1281   // See enum StatusCode in hci_constants.h.
1282   StatusCode status;
1283 
1284   // Advertising Handle in which advertising has ended.
1285   AdvertisingHandle adv_handle;
1286 
1287   // Connection Handle of the connection whose creation ended the advertising.
1288   ConnectionHandle connection_handle;
1289 
1290   // Number of completed extended advertising events transmitted by the
1291   // Controller.
1292   uint8_t num_completed_extended_adv_events;
1293 } __attribute__((packed));
1294 
1295 // LE Scan Request Received Event (v5.0) (LE)
1296 constexpr EventCode kLEScanRequestReceivedSubeventCode = 0x13;
1297 
1298 struct LEScanRequestReceivedSubeventParams {
1299   // Used to identify an advertising set.
1300   AdvertisingHandle adv_handle;
1301 
1302   // Address type of the scanner address.
1303   LEAddressType scanner_address_type;
1304 
1305   // Public Device Address, Random Device Address, Public Identity Address or
1306   // Random (static) Identity Address of the scanning device.
1307   DeviceAddressBytes scanner_address;
1308 } __attribute__((packed));
1309 
1310 // LE Channel Selection Algorithm Event (v5.0) (LE)
1311 constexpr EventCode kLEChannelSelectionAlgorithmSubeventCode = 0x014;
1312 
1313 // ================================================================
1314 // Number Of Completed Data Blocks Event (v3.0 + HS) (BR/EDR & AMP)
1315 constexpr EventCode kNumberOfCompletedDataBlocksEventCode = 0x48;
1316 
1317 struct NumberOfCompletedDataBlocksEventData {
1318   // Handle (Connection Handle for a BR/EDR Controller or a Logical_Link Handle
1319   // for an AMP Controller).
1320   uint16_t handle;
1321   uint16_t num_of_completed_packets;
1322   uint16_t num_of_completed_blocks;
1323 } __attribute__((packed));
1324 
1325 struct NumberOfCompletedDataBlocksEventParams {
1326   NumberOfCompletedDataBlocksEventParams() = delete;
1327   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(NumberOfCompletedDataBlocksEventParams);
1328 
1329   uint16_t total_num_data_blocks;
1330   uint8_t number_of_handles;
1331   NumberOfCompletedDataBlocksEventData data[];
1332 } __attribute__((packed));
1333 
1334 // ================================================================
1335 // Authenticated Payload Timeout Expired Event (v4.1) (BR/EDR & LE)
1336 constexpr EventCode kAuthenticatedPayloadTimeoutExpiredEventCode = 0x57;
1337 
1338 struct AuthenticatedPayloadTimeoutExpiredEventParams {
1339   // Connection_Handle (only the lower 12-bits are meaningful).
1340   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1341   ConnectionHandle connection_handle;
1342 } __attribute__((packed));
1343 
1344 // ======= Status Parameters =======
1345 // Core Spec v5.0, Vol 2, Part E, Section 7.5
1346 constexpr uint8_t kStatusParamsOGF = 0x05;
StatusParamsOpCode(const uint16_t ocf)1347 constexpr OpCode StatusParamsOpCode(const uint16_t ocf) {
1348   return DefineOpCode(kStatusParamsOGF, ocf);
1349 }
1350 
1351 // ========================
1352 // Read RSSI Command (v1.1)
1353 constexpr OpCode kReadRSSI = StatusParamsOpCode(0x0005);
1354 
1355 struct ReadRSSICommandParams {
1356   // The Handle for the connection for which the RSSI is to be read (only the
1357   // lower 12-bits are meaningful).
1358   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1359   ConnectionHandle handle;
1360 } __attribute__((packed));
1361 
1362 struct ReadRSSIReturnParams {
1363   // See enum StatusCode in hci_constants.h.
1364   StatusCode status;
1365 
1366   // The Handle for the connection for which the RSSI has been read (only the
1367   // lower 12-bits are meaningful).
1368   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1369   ConnectionHandle handle;
1370 
1371   // The Received Signal Strength Value.
1372   //
1373   // - BR/EDR:
1374   //     Range: -128 ≤ N ≤ 127 (signed integer)
1375   //     Units: dB
1376   //
1377   // - AMP:
1378   //     Range: AMP type specific (signed integer)
1379   //     Units: dBm
1380   //
1381   // - LE:
1382   //     Range: -127 to 20, 127 (signed integer)
1383   //     Units: dBm
1384   int8_t rssi;
1385 } __attribute__((packed));
1386 
1387 // ========================================
1388 // Read Encryption Key Size (v1.1) (BR/EDR)
1389 constexpr OpCode kReadEncryptionKeySize = StatusParamsOpCode(0x0008);
1390 
1391 struct ReadEncryptionKeySizeReturnParams {
1392   // See enum StatusCode in hci_constants.h.
1393   StatusCode status;
1394 
1395   // Handle of the ACL connection whose encryption key size was read.
1396   ConnectionHandle connection_handle;
1397 
1398   // Encryption key size. See v5.0 Vol 2 Part C, Section 5.2.
1399   uint8_t key_size;
1400 } __attribute__((packed));
1401 
1402 // ======= LE Controller Commands =======
1403 // Core Spec v5.0 Vol 2, Part E, Section 7.8
1404 constexpr uint8_t kLEControllerCommandsOGF = 0x08;
LEControllerCommandOpCode(const uint16_t ocf)1405 constexpr OpCode LEControllerCommandOpCode(const uint16_t ocf) {
1406   return DefineOpCode(kLEControllerCommandsOGF, ocf);
1407 }
1408 
1409 // Returns true if the given |opcode| corresponds to a LE controller command.
IsLECommand(OpCode opcode)1410 inline bool IsLECommand(OpCode opcode) {
1411   return GetOGF(opcode) == kLEControllerCommandsOGF;
1412 }
1413 
1414 // =====================================
1415 // LE Set Event Mask Command (v4.0) (LE)
1416 constexpr OpCode kLESetEventMask = LEControllerCommandOpCode(0x0001);
1417 
1418 // =======================================
1419 // LE Read Buffer Size [v1] Command (v4.0) (LE)
1420 constexpr OpCode kLEReadBufferSizeV1 = LEControllerCommandOpCode(0x0002);
1421 
1422 struct LEReadBufferSizeV1ReturnParams {
1423   // See enum StatusCode in hci_constants.h.
1424   StatusCode status;
1425 
1426   uint16_t hc_le_acl_data_packet_length;
1427   uint8_t hc_total_num_le_acl_data_packets;
1428 } __attribute__((packed));
1429 
1430 // ====================================================
1431 // LE Read Local Supported Features Command (v4.0) (LE)
1432 constexpr OpCode kLEReadLocalSupportedFeatures =
1433     LEControllerCommandOpCode(0x0003);
1434 
1435 struct LEReadLocalSupportedFeaturesReturnParams {
1436   // See enum StatusCode in hci_constants.h.
1437   StatusCode status;
1438 
1439   // Bit Mask List of supported LE features. See enum class LESupportedFeature
1440   // in hci_constants.h.
1441   uint64_t le_features;
1442 } __attribute__((packed));
1443 
1444 // =========================================
1445 // LE Set Random Address Command (v4.0) (LE)
1446 constexpr OpCode kLESetRandomAddress = LEControllerCommandOpCode(0x0005);
1447 
1448 struct LESetRandomAddressCommandParams {
1449   DeviceAddressBytes random_address;
1450 } __attribute__((packed));
1451 
1452 // =================================================
1453 // LE Set Advertising Parameters Command (v4.0) (LE)
1454 constexpr OpCode kLESetAdvertisingParameters =
1455     LEControllerCommandOpCode(0x0006);
1456 
1457 // ========================================================
1458 // LE Read Advertising Channel Tx Power Command (v4.0) (LE)
1459 constexpr OpCode kLEReadAdvertisingChannelTxPower =
1460     LEControllerCommandOpCode(0x0007);
1461 
1462 struct LEReadAdvertisingChannelTxPowerReturnParams {
1463   // See enum StatusCode in hci_constants.h.
1464   StatusCode status;
1465 
1466   // The transmit power level used for LE advertising channel packets.
1467   //
1468   //   Range: -20 <= N <= +10
1469   //   Units: dBm
1470   //   Accuracy: +/- 4 dB
1471   int8_t tx_power;
1472 } __attribute__((packed));
1473 
1474 // ===========================================
1475 // LE Set Advertising Data Command (v4.0) (LE)
1476 constexpr OpCode kLESetAdvertisingData = LEControllerCommandOpCode(0x0008);
1477 
1478 // =============================================
1479 // LE Set Scan Response Data Command (v4.0) (LE)
1480 constexpr OpCode kLESetScanResponseData = LEControllerCommandOpCode(0x0009);
1481 
1482 // =============================================
1483 // LE Set Advertising Enable Command (v4.0) (LE)
1484 constexpr OpCode kLESetAdvertisingEnable = LEControllerCommandOpCode(0x000A);
1485 
1486 // ==========================================
1487 // LE Set Scan Parameters Command (v4.0) (LE)
1488 constexpr OpCode kLESetScanParameters = LEControllerCommandOpCode(0x000B);
1489 
1490 // ======================================
1491 // LE Set Scan Enable Command (v4.0) (LE)
1492 constexpr OpCode kLESetScanEnable = LEControllerCommandOpCode(0x000C);
1493 
1494 // ========================================
1495 // LE Create Connection Command (v4.0) (LE)
1496 constexpr OpCode kLECreateConnection = LEControllerCommandOpCode(0x000D);
1497 
1498 // NOTE on ReturnParams: No Command Complete event is sent by the Controller to
1499 // indicate that this command has been completed. Instead, the LE Connection
1500 // Complete or LE Enhanced Connection Complete event indicates that this command
1501 // has been completed.
1502 
1503 // ===============================================
1504 // LE Create Connection Cancel Command (v4.0) (LE)
1505 constexpr OpCode kLECreateConnectionCancel = LEControllerCommandOpCode(0x000E);
1506 
1507 // ===========================================
1508 // LE Read Filter Accept List Size Command (v4.0) (LE)
1509 constexpr OpCode kLEReadFilterAcceptListSize =
1510     LEControllerCommandOpCode(0x000F);
1511 
1512 struct LEReadFilterAcceptListSizeReturnParams {
1513   // See enum StatusCode in hci_constants.h.
1514   StatusCode status;
1515   uint8_t filter_accept_list_size;
1516 } __attribute__((packed));
1517 
1518 // =======================================
1519 // LE Clear Filter Accept List Command (v4.0) (LE)
1520 constexpr OpCode kLEClearFilterAcceptList = LEControllerCommandOpCode(0x0010);
1521 
1522 // ===============================================
1523 // LE Add Device To Filter Accept List Command (v4.0) (LE)
1524 constexpr OpCode kLEAddDeviceToFilterAcceptList =
1525     LEControllerCommandOpCode(0x0011);
1526 
1527 struct LEAddDeviceToFilterAcceptListCommandParams {
1528   // The address type of the peer. The |address| parameter will be ignored if
1529   // |address_type| is set to LEPeerAddressType::kAnonymous.
1530   LEPeerAddressType address_type;
1531 
1532   // Public Device Address or Random Device Address of the device to be added to
1533   // the Filter Accept List
1534   DeviceAddressBytes address;
1535 } __attribute__((packed));
1536 
1537 // ====================================================
1538 // LE Remove Device From Filter Accept List Command (v4.0) (LE)
1539 constexpr OpCode kLERemoveDeviceFromFilterAcceptList =
1540     LEControllerCommandOpCode(0x0012);
1541 
1542 struct LERemoveDeviceFromFilterAcceptListCommandParams {
1543   // The address type of the peer. The |address| parameter will be ignored if
1544   // |address_type| is set to LEPeerAddressType::kAnonymous.
1545   LEPeerAddressType address_type;
1546 
1547   // Public Device Address or Random Device Address of the device to be removed
1548   // from the Filter Accept List
1549   DeviceAddressBytes address;
1550 } __attribute__((packed));
1551 
1552 // ========================================
1553 // LE Connection Update Command (v4.0) (LE)
1554 constexpr OpCode kLEConnectionUpdate = LEControllerCommandOpCode(0x0013);
1555 
1556 // NOTE on Return Params: A Command Complete event is not sent by the Controller
1557 // to indicate that this command has been completed. Instead, the LE Connection
1558 // Update Complete event indicates that this command has been completed.
1559 
1560 // ======================================================
1561 // LE Set Host Channel Classification Command (v4.0) (LE)
1562 constexpr OpCode kLESetHostChannelClassification =
1563     LEControllerCommandOpCode(0x0014);
1564 
1565 struct LESetHostChannelClassificationCommandParams {
1566   // This parameter contains 37 1-bit fields (only the lower 37-bits of the
1567   // 5-octet value are meaningful).
1568   //
1569   // The nth such field (in the range 0 to 36) contains the value for the link
1570   // layer channel index n.
1571   //
1572   // Channel n is bad = 0. Channel n is unknown = 1.
1573   //
1574   // The most significant bits are reserved and shall be set to 0 for future
1575   // use.
1576   //
1577   // At least one channel shall be marked as unknown.
1578   uint8_t channel_map[5];
1579 } __attribute__((packed));
1580 
1581 // =======================================
1582 // LE Read Channel Map Command (v4.0) (LE)
1583 constexpr OpCode kLEReadChannelMap = LEControllerCommandOpCode(0x0015);
1584 
1585 struct LEReadChannelMapCommandParams {
1586   // Connection Handle (only the lower 12-bits are meaningful).
1587   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1588   ConnectionHandle connection_handle;
1589 } __attribute__((packed));
1590 
1591 struct LEReadChannelMapReturnParams {
1592   // See enum StatusCode in hci_constants.h.
1593   StatusCode status;
1594 
1595   // Connection Handle (only the lower 12-bits are meaningful).
1596   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1597   ConnectionHandle connection_handle;
1598 
1599   // This parameter contains 37 1-bit fields (only the lower 37-bits of the
1600   // 5-octet value are meaningful).
1601   //
1602   // The nth such field (in the range 0 to 36) contains the value for the link
1603   // layer channel index n.
1604   //
1605   // Channel n is bad = 0. Channel n is unknown = 1.
1606   //
1607   // The most significant bits are reserved and shall be set to 0 for future
1608   // use.
1609   //
1610   // At least one channel shall be marked as unknown.
1611   uint8_t channel_map[5];
1612 } __attribute__((packed));
1613 
1614 // ===========================================
1615 // LE Read Remote Features Command (v4.0) (LE)
1616 constexpr OpCode kLEReadRemoteFeatures = LEControllerCommandOpCode(0x0016);
1617 
1618 struct LEReadRemoteFeaturesCommandParams {
1619   // Connection Handle (only the lower 12-bits are meaningful).
1620   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1621   ConnectionHandle connection_handle;
1622 } __attribute__((packed));
1623 
1624 // Note on ReturnParams: A Command Complete event is not sent by the Controller
1625 // to indicate that this command has been completed. Instead, the LE Read Remote
1626 // Features Complete event indicates that this command has been completed.
1627 
1628 // ==============================
1629 // LE Encrypt Command (v4.0) (LE)
1630 constexpr OpCode kLEEncrypt = LEControllerCommandOpCode(0x0017);
1631 
1632 struct LEEncryptCommandParams {
1633   // 128 bit key for the encryption of the data given in the command.
1634   UInt128 key;
1635 
1636   // 128 bit data block that is requested to be encrypted.
1637   uint8_t plaintext_data[16];
1638 } __attribute__((packed));
1639 
1640 struct LEEncryptReturnParams {
1641   // See enum StatusCode in hci_constants.h.
1642   StatusCode status;
1643 
1644   // 128 bit encrypted data block.
1645   uint8_t encrypted_data[16];
1646 } __attribute__((packed));
1647 
1648 // ===========================
1649 // LE Rand Command (v4.0) (LE)
1650 constexpr OpCode kLERand = LEControllerCommandOpCode(0x0018);
1651 
1652 struct LERandReturnParams {
1653   // See enum StatusCode in hci_constants.h.
1654   StatusCode status;
1655 
1656   // Random Number
1657   uint64_t random_number;
1658 } __attribute__((packed));
1659 
1660 // =======================================
1661 // LE Start Encryption Command (v4.0) (LE)
1662 constexpr OpCode kLEStartEncryption = LEControllerCommandOpCode(0x0019);
1663 
1664 // NOTE on Return Params: A Command Complete event is not sent by the Controller
1665 // to indicate that this command has been completed. Instead, the Encryption
1666 // Change or Encryption Key Refresh Complete events indicate that this command
1667 // has been completed.
1668 
1669 // ==================================================
1670 // LE Long Term Key Request Reply Command (v4.0) (LE)
1671 constexpr OpCode kLELongTermKeyRequestReply = LEControllerCommandOpCode(0x001A);
1672 
1673 struct LELongTermKeyRequestReplyCommandParams {
1674   // Connection Handle (only the lower 12-bits are meaningful).
1675   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1676   ConnectionHandle connection_handle;
1677 
1678   // 128-bit long term key for the current connection.
1679   UInt128 long_term_key;
1680 } __attribute__((packed));
1681 
1682 struct LELongTermKeyRequestReplyReturnParams {
1683   // See enum StatusCode in hci_constants.h.
1684   StatusCode status;
1685 
1686   // Connection Handle (only the lower 12-bits are meaningful).
1687   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1688   ConnectionHandle connection_handle;
1689 } __attribute__((packed));
1690 
1691 // ===========================================================
1692 // LE Long Term Key Request Negative Reply Command (v4.0) (LE)
1693 constexpr OpCode kLELongTermKeyRequestNegativeReply =
1694     LEControllerCommandOpCode(0x001B);
1695 
1696 struct LELongTermKeyRequestNegativeReplyReturnParams {
1697   // See enum StatusCode in hci_constants.h.
1698   StatusCode status;
1699 
1700   // Connection Handle (only the lower 12-bits are meaningful).
1701   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1702   ConnectionHandle connection_handle;
1703 } __attribute__((packed));
1704 
1705 // ============================================
1706 // LE Read Supported States Command (v4.0) (LE)
1707 constexpr OpCode kLEReadSupportedStates = LEControllerCommandOpCode(0x001C);
1708 
1709 struct LEReadSupportedStatesReturnParams {
1710   // See enum StatusCode in hci_constants.h.
1711   StatusCode status;
1712 
1713   // Bit-mask of supported state or state combinations. See Core Spec v4.2,
1714   // Volume 2, Part E, Section 7.8.27 "LE Read Supported States Command".
1715   uint64_t le_states;
1716 } __attribute__((packed));
1717 
1718 // ====================================
1719 // LE Receiver Test Command (v4.0) (LE)
1720 constexpr OpCode kLEReceiverTest = LEControllerCommandOpCode(0x001D);
1721 
1722 struct LEReceiverTestCommandParams {
1723   // N = (F - 2402) / 2
1724   // Range: 0x00 - 0x27. Frequency Range : 2402 MHz to 2480 MHz.
1725   uint8_t rx_channel;
1726 } __attribute__((packed));
1727 
1728 // ======================================
1729 // LE Transmitter Test Command (v4.0) (LE)
1730 constexpr OpCode kLETransmitterTest = LEControllerCommandOpCode(0x001E);
1731 
1732 struct LETransmitterTestCommandParams {
1733   // N = (F - 2402) / 2
1734   // Range: 0x00 - 0x27. Frequency Range : 2402 MHz to 2480 MHz.
1735   uint8_t tx_channel;
1736 
1737   // Length in bytes of payload data in each packet
1738   uint8_t length_of_test_data;
1739 
1740   // The packet payload sequence. See Core Spec 5.0, Vol 2, Part E,
1741   // Section 7.8.29 for a description of possible values.
1742   uint8_t packet_payload;
1743 } __attribute__((packed));
1744 
1745 // ===============================
1746 // LE Test End Command (v4.0) (LE)
1747 constexpr OpCode kLETestEnd = LEControllerCommandOpCode(0x001F);
1748 
1749 struct LETestEndReturnParams {
1750   // See enum StatusCode in hci_constants.h.
1751   StatusCode status;
1752 
1753   // Number of packets received
1754   uint16_t number_of_packets;
1755 } __attribute__((packed));
1756 
1757 // ================================================================
1758 // LE Remote Connection Parameter Request Reply Command (v4.1) (LE)
1759 constexpr OpCode kLERemoteConnectionParameterRequestReply =
1760     LEControllerCommandOpCode(0x0020);
1761 
1762 struct LERemoteConnectionParameterRequestReplyCommandParams {
1763   // Connection Handle (only the lower 12-bits are meaningful).
1764   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1765   ConnectionHandle connection_handle;
1766 
1767   // Range: see kLEConnectionInterval[Min|Max] in hci_constants.h
1768   // Time: N * 1.25 ms
1769   // Time Range: 7.5 ms to 4 s.
1770   uint16_t conn_interval_min;
1771   uint16_t conn_interval_max;
1772 
1773   // Range: 0x0000 to kLEConnectionLatencyMax in hci_constants.h
1774   uint16_t conn_latency;
1775 
1776   // Range: see kLEConnectionSupervisionTimeout[Min|Max] in hci_constants.h
1777   // Time: N * 10 ms
1778   // Time Range: 100 ms to 32 s
1779   uint16_t supervision_timeout;
1780 
1781   // Range: 0x0000 - 0xFFFF
1782   // Time: N * 0x625 ms
1783   uint16_t minimum_ce_length;
1784   uint16_t maximum_ce_length;
1785 } __attribute__((packed));
1786 
1787 struct LERemoteConnectionParameterRequestReplyReturnParams {
1788   // See enum StatusCode in hci_constants.h.
1789   StatusCode status;
1790 
1791   // Connection Handle (only the lower 12-bits are meaningful).
1792   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1793   ConnectionHandle connection_handle;
1794 } __attribute__((packed));
1795 
1796 // =========================================================================
1797 // LE Remote Connection Parameter Request Negative Reply Command (v4.1) (LE)
1798 constexpr OpCode kLERemoteConnectionParameterRequestNegativeReply =
1799     LEControllerCommandOpCode(0x0021);
1800 
1801 struct LERemoteConnectionParamReqNegativeReplyCommandParams {
1802   // Connection Handle (only the lower 12-bits are meaningful).
1803   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1804   ConnectionHandle connection_handle;
1805 
1806   // Reason that the connection parameter request was rejected.
1807   StatusCode reason;
1808 } __attribute__((packed));
1809 
1810 struct LERemoteConnectionParamReqNegativeReplyReturnParams {
1811   // See enum StatusCode in hci_constants.h.
1812   StatusCode status;
1813 
1814   // Connection Handle (only the lower 12-bits are meaningful).
1815   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1816   ConnectionHandle connection_handle;
1817 } __attribute__((packed));
1818 
1819 // ======================================
1820 // LE Set Data Length Command (v4.2) (LE)
1821 constexpr OpCode kLESetDataLength = LEControllerCommandOpCode(0x0022);
1822 
1823 struct LESetDataLengthCommandParams {
1824   // Connection Handle (only the lower 12-bits are meaningful).
1825   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1826   ConnectionHandle connection_handle;
1827 
1828   // Range: see kLEMaxTxOctets[Min|Max] in hci_constants.h
1829   uint16_t tx_octets;
1830 
1831   // Range: see kLEMaxTxTime[Min|Max] in hci_constants.h
1832   uint16_t tx_time;
1833 } __attribute__((packed));
1834 
1835 struct LESetDataLengthReturnParams {
1836   // See enum StatusCode in hci_constants.h.
1837   StatusCode status;
1838 
1839   // Connection Handle (only the lower 12-bits are meaningful).
1840   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
1841   ConnectionHandle connection_handle;
1842 } __attribute__((packed));
1843 
1844 // =========================================================
1845 // LE Read Suggested Default Data Length Command (v4.2) (LE)
1846 constexpr OpCode kLEReadSuggestedDefaultDataLength =
1847     LEControllerCommandOpCode(0x0023);
1848 
1849 struct LEReadSuggestedDefaultDataLengthReturnParams {
1850   // See enum StatusCode in hci_constants.h.
1851   StatusCode status;
1852 
1853   // Range: see kLEMaxTxOctets[Min|Max] in hci_constants.h
1854   uint16_t suggested_max_tx_octets;
1855 
1856   // Range: see kLEMaxTxTime[Min|Max] in hci_constants.h
1857   uint16_t suggested_max_tx_time;
1858 } __attribute__((packed));
1859 
1860 // ==========================================================
1861 // LE Write Suggested Default Data Length Command (v4.2) (LE)
1862 constexpr OpCode kLEWriteSuggestedDefaultDataLength =
1863     LEControllerCommandOpCode(0x0024);
1864 
1865 struct LEWriteSuggestedDefaultDataLengthCommandParams {
1866   // Range: see kLEMaxTxOctets[Min|Max] in hci_constants.h
1867   uint16_t suggested_max_tx_octets;
1868 
1869   // Range: see kLEMaxTxTime[Min|Max] in hci_constants.h
1870   uint16_t suggested_max_tx_time;
1871 } __attribute__((packed));
1872 
1873 // ==================================================
1874 // LE Read Local P-256 Public Key Command (v4.2) (LE)
1875 constexpr OpCode kLEReadLocalP256PublicKey = LEControllerCommandOpCode(0x0025);
1876 
1877 // NOTE on ReturnParams: When the Controller receives the
1878 // LE_Read_Local_P-256_Public_Key command, the Controller shall send the Command
1879 // Status event to the Host. When the local P-256 public key generation
1880 // finishes, an LE Read Local P-256 Public Key Complete event shall be
1881 // generated.
1882 //
1883 // No Command Complete event is sent by the Controller to indicate that this
1884 // command has been completed.
1885 
1886 // ======================================
1887 // LE Generate DH Key Command (v4.2) (LE)
1888 constexpr OpCode kLEGenerateDHKey = LEControllerCommandOpCode(0x0026);
1889 
1890 struct LEGenerateDHKeyCommandParams {
1891   // The remote P-256 public key:
1892   //   X, Y format
1893   //   Octets 31-0: X co-ordinate
1894   //   Octets 63-32: Y co-ordinate Little Endian Format
1895   uint8_t remote_p256_public_key[64];
1896 } __attribute__((packed));
1897 
1898 // NOTE on ReturnParams: When the Controller receives the LE_Generate_DHKey
1899 // command, the Controller shall send the Command Status event to the Host. When
1900 // the DHKey generation finishes, an LE DHKey Generation Complete event shall be
1901 // generated.
1902 //
1903 // No Command Complete event is sent by the Controller to indicate that this
1904 // command has been completed.
1905 
1906 // ===================================================
1907 // LE Add Device To Resolving List Command (v4.2) (LE)
1908 constexpr OpCode kLEAddDeviceToResolvingList =
1909     LEControllerCommandOpCode(0x0027);
1910 
1911 struct LEAddDeviceToResolvingListCommandParams {
1912   // The peer device's identity address type.
1913   LEPeerAddressType peer_identity_address_type;
1914 
1915   // Public or Random (static) Identity address of the peer device
1916   DeviceAddressBytes peer_identity_address;
1917 
1918   // IRK (Identity Resolving Key) of the peer device
1919   UInt128 peer_irk;
1920 
1921   // IRK (Identity Resolving Key) of the local device
1922   UInt128 local_irk;
1923 } __attribute__((packed));
1924 
1925 // ========================================================
1926 // LE Remove Device From Resolving List Command (v4.2) (LE)
1927 constexpr OpCode kLERemoveDeviceFromResolvingList =
1928     LEControllerCommandOpCode(0x0028);
1929 
1930 struct LERemoveDeviceFromResolvingListCommandParams {
1931   // The peer device's identity address type.
1932   LEPeerAddressType peer_identity_address_type;
1933 
1934   // Public or Random (static) Identity address of the peer device
1935   DeviceAddressBytes peer_identity_address;
1936 } __attribute__((packed));
1937 
1938 // ===========================================
1939 // LE Clear Resolving List Command (v4.2) (LE)
1940 constexpr OpCode kLEClearResolvingList = LEControllerCommandOpCode(0x0029);
1941 
1942 // ===============================================
1943 // LE Read Resolving List Size Command (v4.2) (LE)
1944 constexpr OpCode kLEReadResolvingListSize = LEControllerCommandOpCode(0x002A);
1945 
1946 struct LEReadResolvingListReturnParams {
1947   // See enum StatusCode in hci_constants.h.
1948   StatusCode status;
1949 
1950   // Number of address translation entries in the resolving list.
1951   uint8_t resolving_list_size;
1952 } __attribute__((packed));
1953 
1954 // ===================================================
1955 // LE Read Peer Resolvable Address Command (v4.2) (LE)
1956 constexpr OpCode kLEReadPeerResolvableAddress =
1957     LEControllerCommandOpCode(0x002B);
1958 
1959 struct LEReadPeerResolvableAddressCommandParams {
1960   // The peer device's identity address type.
1961   LEPeerAddressType peer_identity_address_type;
1962 
1963   // Public or Random (static) Identity address of the peer device.
1964   DeviceAddressBytes peer_identity_address;
1965 } __attribute__((packed));
1966 
1967 struct LEReadPeerResolvableAddressReturnParams {
1968   // See enum StatusCode in hci_constants.h.
1969   StatusCode status;
1970 
1971   // Resolvable Private Address being used by the peer device.
1972   DeviceAddressBytes peer_resolvable_address;
1973 } __attribute__((packed));
1974 
1975 // ====================================================
1976 // LE Read Local Resolvable Address Command (v4.2) (LE)
1977 constexpr OpCode kLEReadLocalResolvableAddress =
1978     LEControllerCommandOpCode(0x002C);
1979 
1980 struct LEReadLocalResolvableAddressCommandParams {
1981   // The peer device's identity address type.
1982   LEPeerAddressType peer_identity_address_type;
1983 
1984   // Public or Random (static) Identity address of the peer device
1985   DeviceAddressBytes peer_identity_address;
1986 } __attribute__((packed));
1987 
1988 struct LEReadLocalResolvableAddressReturnParams {
1989   // See enum StatusCode in hci_constants.h.
1990   StatusCode status;
1991 
1992   // Resolvable Private Address being used by the local device.
1993   DeviceAddressBytes local_resolvable_address;
1994 } __attribute__((packed));
1995 
1996 // ====================================================
1997 // LE Set Address Resolution Enable Command (v4.2) (LE)
1998 constexpr OpCode kLESetAddressResolutionEnable =
1999     LEControllerCommandOpCode(0x002D);
2000 
2001 struct LESetAddressResolutionEnableCommandParams {
2002   GenericEnableParam address_resolution_enable;
2003 } __attribute__((packed));
2004 
2005 // =============================================================
2006 // LE Set Resolvable Private Address Timeout Command (v4.2) (LE)
2007 constexpr OpCode kLESetResolvablePrivateAddressTimeout =
2008     LEControllerCommandOpCode(0x002E);
2009 
2010 struct LESetResolvablePrivateAddressTimeoutCommandParams {
2011   // Range: See kLERPATimeout[Min|Max] in hci_constants.h
2012   // Default: See kLERPATimeoutDefault in hci_constants.h
2013   uint16_t rpa_timeout;
2014 } __attribute__((packed));
2015 
2016 // ===============================================
2017 // LE Read Maximum Data Length Command (v4.2) (LE)
2018 constexpr OpCode kLEReadMaximumDataLength = LEControllerCommandOpCode(0x002F);
2019 
2020 struct LEReadMaximumDataLengthReturnParams {
2021   // See enum StatusCode in hci_constants.h.
2022   StatusCode status;
2023 
2024   // Range: see kLEMaxTxOctets[Min|Max] in hci_constants.h
2025   uint16_t supported_max_tx_octets;
2026 
2027   // Range: see kLEMaxTxTime[Min|Max] in hci_constants.h
2028   uint16_t supported_max_tx_time;
2029 
2030   // Range: see kLEMaxTxOctets[Min|Max] in hci_constants.h
2031   uint16_t supported_max_rx_octets;
2032 
2033   // Range: see kLEMaxTxTime[Min|Max] in hci_constants.h
2034   uint16_t supported_max_rx_time;
2035 } __attribute__((packed));
2036 
2037 // ===============================
2038 // LE Read PHY Command (v5.0) (LE)
2039 constexpr OpCode kLEReadPHY = LEControllerCommandOpCode(0x0030);
2040 
2041 struct LEReadPHYCommandParams {
2042   // Connection Handle (only the lower 12-bits are meaningful).
2043   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
2044   ConnectionHandle connection_handle;
2045 } __attribute__((packed));
2046 
2047 struct LEReadPHYReturnParams {
2048   // See enum StatusCode in hci_constants.h.
2049   StatusCode status;
2050 
2051   // Connection Handle (only the lower 12-bits are meaningful).
2052   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
2053   ConnectionHandle connection_handle;
2054 
2055   // The transmitter PHY.
2056   LEPHY tx_phy;
2057 
2058   // The receiver PHY.
2059   LEPHY rx_phy;
2060 } __attribute__((packed));
2061 
2062 // ======================================
2063 // LE Set Default PHY Command (v5.0) (LE)
2064 constexpr OpCode kLESetDefaultPHY = LEControllerCommandOpCode(0x0031);
2065 
2066 struct LESetDefaultPHYCommandParams {
2067   // See the kLEAllPHYSBit* constants in hci_constants.h for possible bitfield
2068   // values.
2069   uint8_t all_phys;
2070 
2071   // See the kLEPHYBit* constants in hci_constants.h for possible bitfield
2072   // values.
2073   uint8_t tx_phys;
2074 
2075   // See the kLEPHYBit* constants in hci_constants.h for possible bitfield
2076   // values.
2077   uint8_t rx_phys;
2078 } __attribute__((packed));
2079 
2080 // ==============================
2081 // LE Set PHY Command (v5.0) (LE)
2082 constexpr OpCode kLESetPHY = LEControllerCommandOpCode(0x0032);
2083 
2084 struct LESetPHYCommandParams {
2085   // Connection Handle (only the lower 12-bits are meaningful).
2086   //   Range: 0x0000 to kConnectionHandleMax in hci_constants.h
2087   ConnectionHandle connection_handle;
2088 
2089   // See the kLEAllPHYSBit* constants in hci_constants.h for possible bitfield
2090   // values.
2091   uint8_t all_phys;
2092 
2093   // See the kLEPHYBit* constants in hci_constants.h for possible bitfield
2094   // values.
2095   uint8_t tx_phys;
2096 
2097   // See the kLEPHYBit* constants in hci_constants.h for possible bitfield
2098   // values.
2099   uint8_t rx_phys;
2100 
2101   LEPHYOptions phy_options;
2102 } __attribute__((packed));
2103 
2104 // NOTE on ReturnParams: A Command Complete event is not sent by the Controller
2105 // to indicate that this command has been completed. Instead, the LE PHY Update
2106 // Complete event indicates that this command has been completed. The LE PHY
2107 // Update Complete event may also be issued autonomously by the Link Layer.
2108 
2109 // =============================================
2110 // LE Enhanced Receiver Test Command (v5.0) (LE)
2111 constexpr OpCode kLEEnhancedReceiverText = LEControllerCommandOpCode(0x0033);
2112 
2113 struct LEEnhancedReceiverTestCommandParams {
2114   // N = (F - 2402) / 2
2115   // Range: 0x00 - 0x27. Frequency Range : 2402 MHz to 2480 MHz.
2116   uint8_t rx_channel;
2117 
2118   // Receiver PHY.
2119   LEPHY phy;
2120 
2121   // Transmitter modulation index that should be assumed.
2122   LETestModulationIndex modulation_index;
2123 } __attribute__((packed));
2124 
2125 // ================================================
2126 // LE Enhanced Transmitter Test Command (v5.0) (LE)
2127 constexpr OpCode kLEEnhancedTransmitterTest = LEControllerCommandOpCode(0x0034);
2128 
2129 struct LEEnhancedTransmitterTestCommandParams {
2130   // N = (F - 2402) / 2
2131   // Range: 0x00 - 0x27. Frequency Range : 2402 MHz to 2480 MHz.
2132   uint8_t tx_channel;
2133 
2134   // Length in bytes of payload data in each packet
2135   uint8_t length_of_test_data;
2136 
2137   // The packet payload sequence. See Core Spec 5.0, Vol 2, Part E,
2138   // Section 7.8.51 for a description of possible values.
2139   uint8_t packet_payload;
2140 
2141   // Transmitter PHY.
2142   LEPHY phy;
2143 } __attribute__((packed));
2144 
2145 // =========================================================
2146 // LE Set Advertising Set Random Address Command (v5.0) (LE)
2147 constexpr OpCode kLESetAdvertisingSetRandomAddress =
2148     LEControllerCommandOpCode(0x0035);
2149 
2150 // ==========================================================
2151 // LE Set Extended Advertising Parameters Command (v5.0) (LE)
2152 constexpr OpCode kLESetExtendedAdvertisingParameters =
2153     LEControllerCommandOpCode(0x0036);
2154 
2155 struct LESetExtendedAdvertisingParametersReturnParams {
2156   // See enum StatusCode in hci_constants.h.
2157   StatusCode status;
2158   int8_t selected_tx_power;
2159 } __attribute__((packed));
2160 
2161 // ====================================================
2162 // LE Set Extended Advertising Data Command (v5.0) (LE)
2163 constexpr OpCode kLESetExtendedAdvertisingData =
2164     LEControllerCommandOpCode(0x0037);
2165 
2166 // ======================================================
2167 // LE Set Extended Scan Response Data Command (v5.0) (LE)
2168 constexpr OpCode kLESetExtendedScanResponseData =
2169     LEControllerCommandOpCode(0x0038);
2170 
2171 // ======================================================
2172 // LE Set Extended Advertising Enable Command (v5.0) (LE)
2173 constexpr OpCode kLESetExtendedAdvertisingEnable =
2174     LEControllerCommandOpCode(0x0039);
2175 
2176 // ===========================================================
2177 // LE Read Maximum Advertising Data Length Command (v5.0) (LE)
2178 constexpr OpCode kLEReadMaxAdvertisingDataLength =
2179     LEControllerCommandOpCode(0x003A);
2180 
2181 struct LEReadMaxAdvertisingDataLengthReturnParams {
2182   // See enum StatusCode in hci_constants.h.
2183   StatusCode status;
2184 
2185   uint16_t max_adv_data_length;
2186 } __attribute__((packed));
2187 
2188 // ================================================================
2189 // LE Read Number of Supported Advertising Sets Command (v5.0) (LE)
2190 constexpr OpCode kLEReadNumSupportedAdvertisingSets =
2191     LEControllerCommandOpCode(0x003B);
2192 
2193 struct LEReadNumSupportedAdvertisingSetsReturnParams {
2194   // See enum StatusCode in hci_constants.h.
2195   StatusCode status;
2196 
2197   uint8_t num_supported_adv_sets;
2198 } __attribute__((packed));
2199 
2200 // =============================================
2201 // LE Remove Advertising Set Command (v5.0) (LE)
2202 constexpr OpCode kLERemoveAdvertisingSet = LEControllerCommandOpCode(0x003C);
2203 
2204 struct LERemoveAdvertisingSetCommandParams {
2205   // Handle used to identify an advertising set.
2206   AdvertisingHandle adv_handle;
2207 } __attribute__((packed));
2208 
2209 // =============================================
2210 // LE Clear Advertising Sets Command (v5.0) (LE)
2211 constexpr OpCode kLEClearAdvertisingSets = LEControllerCommandOpCode(0x003D);
2212 
2213 // ==========================================================
2214 // LE Set Periodic Advertising Parameters Command (v5.0) (LE)
2215 constexpr OpCode kLESetPeriodicAdvertisingParameters =
2216     LEControllerCommandOpCode(0x003E);
2217 
2218 struct LESetPeriodicAdvertisingParametersCommandParams {
2219   // Identifies the advertising set whose periodic advertising parameters are
2220   // being configured.
2221   AdvertisingHandle adv_handle;
2222 
2223   // Range: See kLEPeriodicAdvertisingInterval[Min|Max] in hci_constants.h
2224   // Time = N * 1.25 ms
2225   // Time Range: 7.5ms to 81.91875 s
2226   uint16_t periodic_adv_interval_min;
2227   uint16_t periodic_adv_interval_max;
2228 
2229   // See the kLEPeriodicAdvPropBit* constants in hci_constants.h for possible
2230   // bit values.
2231   uint16_t periodic_adv_properties;
2232 } __attribute__((packed));
2233 
2234 // ====================================================
2235 // LE Set Periodic Advertising Data Command (v5.0) (LE)
2236 constexpr OpCode kLESetPeriodicAdvertisingData =
2237     LEControllerCommandOpCode(0x003F);
2238 
2239 struct LESetPeriodicAdvertisingDataCommandParams {
2240   LESetPeriodicAdvertisingDataCommandParams() = delete;
2241   BT_DISALLOW_COPY_ASSIGN_AND_MOVE(LESetPeriodicAdvertisingDataCommandParams);
2242 
2243   // Handle used to identify an advertising set.
2244   AdvertisingHandle adv_handle;
2245 
2246   // See hci_constants.h for possible values.
2247   // LESetExtendedAdvDataOp::kUnchangedData is excluded for this command.
2248   LESetExtendedAdvDataOp operation;
2249 
2250   // Length of the advertising data included in this command packet, up to
2251   // kMaxLEExtendedAdvertisingDataLength bytes.
2252   uint8_t adv_data_length;
2253 
2254   // Variable length advertising data.
2255   uint8_t adv_data[];
2256 } __attribute__((packed));
2257 
2258 // ======================================================
2259 // LE Set Periodic Advertising Enable Command (v5.0) (LE)
2260 constexpr OpCode kLESetPeriodicAdvertisingEnable =
2261     LEControllerCommandOpCode(0x0040);
2262 
2263 struct LESetPeriodicAdvertisingEnableCommandParams {
2264   // Enable or Disable periodic advertising.
2265   GenericEnableParam enable;
2266 
2267   // Handle used to identify an advertising set.
2268   AdvertisingHandle adv_handle;
2269 } __attribute__((packed));
2270 
2271 // ===================================================
2272 // LE Set Extended Scan Parameters Command (v5.0) (LE)
2273 constexpr OpCode kLESetExtendedScanParameters =
2274     LEControllerCommandOpCode(0x0041);
2275 
2276 // ===============================================
2277 // LE Set Extended Scan Enable Command (v5.0) (LE)
2278 constexpr OpCode kLESetExtendedScanEnable = LEControllerCommandOpCode(0x0042);
2279 
2280 // =================================================
2281 // LE Extended Create Connection Command (v5.0) (LE)
2282 constexpr OpCode kLEExtendedCreateConnection =
2283     LEControllerCommandOpCode(0x0043);
2284 
2285 // =======================================================
2286 // LE Periodic Advertising Create Sync Command (v5.0) (LE)
2287 constexpr OpCode kLEPeriodicAdvertisingCreateSync =
2288     LEControllerCommandOpCode(0x0044);
2289 
2290 // NOTE on ReturnParams: No Command Complete event is sent by the Controller to
2291 // indicate that this command has been completed. Instead, the LE Periodic
2292 // Advertising Sync Established event indicates that this command has been
2293 // completed.
2294 
2295 // ==============================================================
2296 // LE Periodic Advertising Create Sync Cancel Command (v5.0) (LE)
2297 constexpr OpCode kLEPeriodicAdvertisingCreateSyncCancel =
2298     LEControllerCommandOpCode(0x0045);
2299 
2300 // ==========================================================
2301 // LE Periodic Advertising Terminate Sync Command (v5.0) (LE)
2302 constexpr OpCode kLEPeriodicAdvertisingTerminateSync =
2303     LEControllerCommandOpCode(0x0046);
2304 
2305 // =============================================================
2306 // LE Add Device To Periodic Advertiser List Command (v5.0) (LE)
2307 constexpr OpCode kLEAddDeviceToPeriodicAdvertiserList =
2308     LEControllerCommandOpCode(0x0047);
2309 
2310 // ==================================================================
2311 // LE Remove Device From Periodic Advertiser List Command (v5.0) (LE)
2312 constexpr OpCode kLERemoveDeviceFromPeriodicAdvertiserList =
2313     LEControllerCommandOpCode(0x0048);
2314 
2315 // =====================================================
2316 // LE Clear Periodic Advertiser List Command (v5.0) (LE)
2317 constexpr OpCode kLEClearPeriodicAdvertiserList =
2318     LEControllerCommandOpCode(0x0049);
2319 
2320 // =========================================================
2321 // LE Read Periodic Advertiser List Size Command (v5.0) (LE)
2322 constexpr OpCode kLEReadPeriodicAdvertiserListSize =
2323     LEControllerCommandOpCode(0x004A);
2324 
2325 struct LEReadPeriodicAdvertiserListSizeReturnParams {
2326   // See enum StatusCode in hci_constants.h.
2327   StatusCode status;
2328 
2329   // Total number of Periodic Advertiser list entries that can be stored in the
2330   // Controller.
2331   uint8_t periodic_advertiser_list_size;
2332 } __attribute__((packed));
2333 
2334 // ==========================================
2335 // LE Read Transmit Power Command (v5.0) (LE)
2336 constexpr OpCode kLEReadTransmitPower = LEControllerCommandOpCode(0x004B);
2337 
2338 struct LEReadTransmitPowerReturnParams {
2339   // See enum StatusCode in hci_constants.h.
2340   StatusCode status;
2341 
2342   // Range: -127 <= N <= +126
2343   // Units: dBm
2344   int8_t min_tx_power;
2345   int8_t max_tx_power;
2346 } __attribute__((packed));
2347 
2348 // ================================================
2349 // LE Read RF Path Compensation Command (v5.0) (LE)
2350 constexpr OpCode kLEReadRFPathCompensation = LEControllerCommandOpCode(0x004C);
2351 
2352 struct LEReadRFPathCompensationReturnParams {
2353   // See enum StatusCode in hci_constants.h.
2354   StatusCode status;
2355 
2356   // The RF Path Compensation Values parameters used in the Tx Power Level and
2357   // RSSI calculation.
2358   //   Range: -128.0 dB (0xFB00) ≤ N ≤ 128.0 dB (0x0500)
2359   //   Units: 0.1 dB
2360   int16_t rf_tx_path_comp_value;
2361   int16_t rf_rx_path_comp_value;
2362 } __attribute__((packed));
2363 
2364 // =================================================
2365 // LE Write RF Path Compensation Command (v5.0) (LE)
2366 constexpr OpCode kLEWriteRFPathCompensation = LEControllerCommandOpCode(0x004D);
2367 
2368 // =======================================
2369 // LE Set Privacy Mode Command (v5.0) (LE)
2370 constexpr OpCode kLESetPrivacyMode = LEControllerCommandOpCode(0x004E);
2371 
2372 // =======================================
2373 // LE Read Buffer Size [v2] Command (v5.2) (LE)
2374 constexpr OpCode kLEReadBufferSizeV2 = LEControllerCommandOpCode(0x0060);
2375 
2376 // =======================================
2377 // LE Set Host Feature Command (v5.2) (LE)
2378 constexpr OpCode kLESetHostFeature = LEControllerCommandOpCode(0x0074);
2379 
2380 // ======= Vendor Command =======
2381 // Core Spec v5.0, Vol 2, Part E, Section 5.4.1
2382 constexpr uint8_t kVendorOGF = 0x3F;
VendorOpCode(const uint16_t ocf)2383 constexpr OpCode VendorOpCode(const uint16_t ocf) {
2384   return DefineOpCode(kVendorOGF, ocf);
2385 }
2386 
2387 }  // namespace bt::hci_spec
2388