xref: /btstack/src/hci_cmd.c (revision f12924e0a61c0582b548a1e70cea1bd59ba21f1d)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 /*
39  *  hci_cmd.c
40  *
41  *  Created by Matthias Ringwald on 7/23/09.
42  */
43 
44 #include "btstack_config.h"
45 
46 #include "classic/sdp_util.h"
47 #include "hci.h"
48 #include "hci_cmd.h"
49 
50 #include <string.h>
51 
52 // calculate combined ogf/ocf value
53 #define OPCODE(ogf, ocf) (ocf | ogf << 10)
54 
55 /**
56  * construct HCI Command based on template
57  *
58  * Format:
59  *   1,2,3,4: one to four byte value
60  *   H: HCI connection handle
61  *   B: Bluetooth Baseband Address (BD_ADDR)
62  *   D: 8 byte data block
63  *   E: Extended Inquiry Result
64  *   N: Name up to 248 chars, \0 terminated
65  *   P: 16 byte data block. Pairing code, Simple Pairing Hash and Randomizer
66  *   A: 31 bytes advertising data
67  *   S: Service Record (Data Element Sequence)
68  *   Q: 32 byte data block, e.g. for X and Y coordinates of P-256 public key
69  */
70 uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr){
71 
72     hci_cmd_buffer[0] = cmd->opcode & 0xff;
73     hci_cmd_buffer[1] = cmd->opcode >> 8;
74     int pos = 3;
75 
76     const char *format = cmd->format;
77     uint16_t word;
78     uint32_t longword;
79     uint8_t * ptr;
80     while (*format) {
81         switch(*format) {
82             case '1': //  8 bit value
83             case '2': // 16 bit value
84             case 'H': // hci_handle
85                 word = va_arg(argptr, int);  // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
86                 hci_cmd_buffer[pos++] = word & 0xff;
87                 if (*format == '2') {
88                     hci_cmd_buffer[pos++] = word >> 8;
89                 } else if (*format == 'H') {
90                     // TODO implement opaque client connection handles
91                     //      pass module handle for now
92                     hci_cmd_buffer[pos++] = word >> 8;
93                 }
94                 break;
95             case '3':
96             case '4':
97                 longword = va_arg(argptr, uint32_t);
98                 // longword = va_arg(argptr, int);
99                 hci_cmd_buffer[pos++] = longword;
100                 hci_cmd_buffer[pos++] = longword >> 8;
101                 hci_cmd_buffer[pos++] = longword >> 16;
102                 if (*format == '4'){
103                     hci_cmd_buffer[pos++] = longword >> 24;
104                 }
105                 break;
106             case 'B': // bt-addr
107                 ptr = va_arg(argptr, uint8_t *);
108                 hci_cmd_buffer[pos++] = ptr[5];
109                 hci_cmd_buffer[pos++] = ptr[4];
110                 hci_cmd_buffer[pos++] = ptr[3];
111                 hci_cmd_buffer[pos++] = ptr[2];
112                 hci_cmd_buffer[pos++] = ptr[1];
113                 hci_cmd_buffer[pos++] = ptr[0];
114                 break;
115             case 'D': // 8 byte data block
116                 ptr = va_arg(argptr, uint8_t *);
117                 memcpy(&hci_cmd_buffer[pos], ptr, 8);
118                 pos += 8;
119                 break;
120             case 'E': // Extended Inquiry Information 240 octets
121                 ptr = va_arg(argptr, uint8_t *);
122                 memcpy(&hci_cmd_buffer[pos], ptr, 240);
123                 pos += 240;
124                 break;
125             case 'N': { // UTF-8 string, null terminated
126                 ptr = va_arg(argptr, uint8_t *);
127                 uint16_t len = strlen((const char*) ptr);
128                 if (len > 248) {
129                     len = 248;
130                 }
131                 memcpy(&hci_cmd_buffer[pos], ptr, len);
132                 if (len < 248) {
133                     // fill remaining space with zeroes
134                     memset(&hci_cmd_buffer[pos+len], 0, 248-len);
135                 }
136                 pos += 248;
137                 break;
138             }
139             case 'P': // 16 byte PIN code or link key
140                 ptr = va_arg(argptr, uint8_t *);
141                 memcpy(&hci_cmd_buffer[pos], ptr, 16);
142                 pos += 16;
143                 break;
144 #ifdef ENABLE_BLE
145             case 'A': // 31 bytes advertising data
146                 ptr = va_arg(argptr, uint8_t *);
147                 memcpy(&hci_cmd_buffer[pos], ptr, 31);
148                 pos += 31;
149                 break;
150 #endif
151 #ifdef ENABLE_SDP
152             case 'S': { // Service Record (Data Element Sequence)
153                 ptr = va_arg(argptr, uint8_t *);
154                 uint16_t len = de_get_len(ptr);
155                 memcpy(&hci_cmd_buffer[pos], ptr, len);
156                 pos += len;
157                 break;
158             }
159 #endif
160 #ifdef ENABLE_LE_SECURE_CONNECTIONS
161             case 'Q':
162                 ptr = va_arg(argptr, uint8_t *);
163                 reverse_bytes(ptr, &hci_cmd_buffer[pos], 32);
164                 pos += 32;
165                 break;
166 #endif
167             default:
168                 break;
169         }
170         format++;
171     };
172     hci_cmd_buffer[2] = pos - 3;
173     return pos;
174 }
175 
176 /**
177  *  Link Control Commands
178  */
179 
180 /**
181  * @param lap
182  * @param inquiry_length
183  * @param num_responses
184  */
185 const hci_cmd_t hci_inquiry = {
186 OPCODE(OGF_LINK_CONTROL, 0x01), "311"
187 };
188 
189 /**
190  */
191 const hci_cmd_t hci_inquiry_cancel = {
192 OPCODE(OGF_LINK_CONTROL, 0x02), ""
193 };
194 
195 /**
196  * @param bd_addr
197  * @param packet_type
198  * @param page_scan_repetition_mode
199  * @param reserved
200  * @param clock_offset
201  * @param allow_role_switch
202  */
203 const hci_cmd_t hci_create_connection = {
204 OPCODE(OGF_LINK_CONTROL, 0x05), "B21121"
205 };
206 
207 /**
208  * @param handle
209  * @param reason (0x05, 0x13-0x15, 0x1a, 0x29, see Errors Codes in BT Spec Part D)
210  */
211 const hci_cmd_t hci_disconnect = {
212 OPCODE(OGF_LINK_CONTROL, 0x06), "H1"
213 };
214 
215 /**
216  * @param bd_addr
217  */
218 const hci_cmd_t hci_create_connection_cancel = {
219 OPCODE(OGF_LINK_CONTROL, 0x08), "B"
220 };
221 
222 /**
223  * @param bd_addr
224  * @param role (become master, stay slave)
225  */
226 const hci_cmd_t hci_accept_connection_request = {
227 OPCODE(OGF_LINK_CONTROL, 0x09), "B1"
228 };
229 
230 /**
231  * @param bd_addr
232  * @param reason (e.g. CONNECTION REJECTED DUE TO LIMITED RESOURCES (0x0d))
233  */
234 const hci_cmd_t hci_reject_connection_request = {
235 OPCODE(OGF_LINK_CONTROL, 0x0a), "B1"
236 };
237 
238 /**
239  * @param bd_addr
240  * @param link_key
241  */
242 const hci_cmd_t hci_link_key_request_reply = {
243 OPCODE(OGF_LINK_CONTROL, 0x0b), "BP"
244 };
245 
246 /**
247  * @param bd_addr
248  */
249 const hci_cmd_t hci_link_key_request_negative_reply = {
250 OPCODE(OGF_LINK_CONTROL, 0x0c), "B"
251 };
252 
253 /**
254  * @param bd_addr
255  * @param pin_length
256  * @param pin (c-string)
257  */
258 const hci_cmd_t hci_pin_code_request_reply = {
259 OPCODE(OGF_LINK_CONTROL, 0x0d), "B1P"
260 };
261 
262 /**
263  * @param bd_addr
264  */
265 const hci_cmd_t hci_pin_code_request_negative_reply = {
266 OPCODE(OGF_LINK_CONTROL, 0x0e), "B"
267 };
268 
269 /**
270  * @param handle
271  * @param packet_type
272  */
273 const hci_cmd_t hci_change_connection_packet_type = {
274 OPCODE(OGF_LINK_CONTROL, 0x0f), "H2"
275 };
276 
277 /**
278  * @param handle
279  */
280 const hci_cmd_t hci_authentication_requested = {
281 OPCODE(OGF_LINK_CONTROL, 0x11), "H"
282 };
283 
284 /**
285  * @param handle
286  * @param encryption_enable
287  */
288 const hci_cmd_t hci_set_connection_encryption = {
289 OPCODE(OGF_LINK_CONTROL, 0x13), "H1"
290 };
291 
292 /**
293  * @param handle
294  */
295 const hci_cmd_t hci_change_connection_link_key = {
296 OPCODE(OGF_LINK_CONTROL, 0x15), "H"
297 };
298 
299 /**
300  * @param bd_addr
301  * @param page_scan_repetition_mode
302  * @param reserved
303  * @param clock_offset
304  */
305 const hci_cmd_t hci_remote_name_request = {
306 OPCODE(OGF_LINK_CONTROL, 0x19), "B112"
307 };
308 
309 
310 /**
311  * @param bd_addr
312  */
313 const hci_cmd_t hci_remote_name_request_cancel = {
314 OPCODE(OGF_LINK_CONTROL, 0x1A), "B"
315 };
316 
317 /**
318  * @param handle
319  */
320 const hci_cmd_t hci_read_remote_supported_features_command = {
321 OPCODE(OGF_LINK_CONTROL, 0x1B), "H"
322 };
323 
324 /**
325  * @param handle
326  * @param transmit_bandwidth 8000(64kbps)
327  * @param receive_bandwidth  8000(64kbps)
328  * @param max_latency        >= 7ms for eSCO, 0xFFFF do not care
329  * @param voice_settings     e.g. CVSD, Input Coding: Linear, Input Data Format: 2’s complement, data 16bit: 00011000000 == 0x60
330  * @param retransmission_effort  e.g. 0xFF do not care
331  * @param packet_type        at least EV3 for eSCO
332  */
333 const hci_cmd_t hci_setup_synchronous_connection = {
334 OPCODE(OGF_LINK_CONTROL, 0x0028), "H442212"
335 };
336 
337 /**
338  * @param bd_addr
339  * @param transmit_bandwidth
340  * @param receive_bandwidth
341  * @param max_latency
342  * @param voice_settings
343  * @param retransmission_effort
344  * @param packet_type
345  */
346 const hci_cmd_t hci_accept_synchronous_connection = {
347 OPCODE(OGF_LINK_CONTROL, 0x0029), "B442212"
348 };
349 
350 /**
351  * @param bd_addr
352  * @param IO_capability
353  * @param OOB_data_present
354  * @param authentication_requirements
355  */
356 const hci_cmd_t hci_io_capability_request_reply = {
357 OPCODE(OGF_LINK_CONTROL, 0x2b), "B111"
358 };
359 
360 /**
361  * @param bd_addr
362  */
363 const hci_cmd_t hci_user_confirmation_request_reply = {
364 OPCODE(OGF_LINK_CONTROL, 0x2c), "B"
365 };
366 
367 /**
368  * @param bd_addr
369  */
370 const hci_cmd_t hci_user_confirmation_request_negative_reply = {
371 OPCODE(OGF_LINK_CONTROL, 0x2d), "B"
372 };
373 
374 /**
375  * @param bd_addr
376  * @param numeric_value
377  */
378 const hci_cmd_t hci_user_passkey_request_reply = {
379 OPCODE(OGF_LINK_CONTROL, 0x2e), "B4"
380 };
381 
382 /**
383  * @param bd_addr
384  */
385 const hci_cmd_t hci_user_passkey_request_negative_reply = {
386 OPCODE(OGF_LINK_CONTROL, 0x2f), "B"
387 };
388 
389 /**
390  * @param bd_addr
391  * @param c Simple Pairing Hash C
392  * @param r Simple Pairing Randomizer R
393  */
394 const hci_cmd_t hci_remote_oob_data_request_reply = {
395 OPCODE(OGF_LINK_CONTROL, 0x30), "BPP"
396 };
397 
398 /**
399  * @param bd_addr
400  */
401 const hci_cmd_t hci_remote_oob_data_request_negative_reply = {
402 OPCODE(OGF_LINK_CONTROL, 0x33), "B"
403 };
404 
405 /**
406  * @param bd_addr
407  * @param reason (Part D, Error codes)
408  */
409 const hci_cmd_t hci_io_capability_request_negative_reply = {
410 OPCODE(OGF_LINK_CONTROL, 0x34), "B1"
411 };
412 
413 /**
414  * @param handle
415  * @param transmit_bandwidth
416  * @param receive_bandwidth
417  * @param transmit_coding_format_type
418  * @param transmit_coding_format_company
419  * @param transmit_coding_format_codec
420  * @param receive_coding_format_type
421  * @param receive_coding_format_company
422  * @param receive_coding_format_codec
423  * @param transmit_coding_frame_size
424  * @param receive_coding_frame_size
425  * @param input_bandwidth
426  * @param output_bandwidth
427  * @param input_coding_format_type
428  * @param input_coding_format_company
429  * @param input_coding_format_codec
430  * @param output_coding_format_type
431  * @param output_coding_format_company
432  * @param output_coding_format_codec
433  * @param input_coded_data_size
434  * @param outupt_coded_data_size
435  * @param input_pcm_data_format
436  * @param output_pcm_data_format
437  * @param input_pcm_sample_payload_msb_position
438  * @param output_pcm_sample_payload_msb_position
439  * @param input_data_path
440  * @param output_data_path
441  * @param input_transport_unit_size
442  * @param output_transport_unit_size
443  * @param max_latency
444  * @param packet_type
445  * @param retransmission_effort
446  */
447 const hci_cmd_t hci_enhanced_setup_synchronous_connection = {
448 OPCODE(OGF_LINK_CONTROL, 0x3d), "H4412212222441221222211111111221"
449 };
450 
451 /**
452  * @param bd_addr
453  * @param transmit_bandwidth
454  * @param receive_bandwidth
455  * @param transmit_coding_format_type
456  * @param transmit_coding_format_company
457  * @param transmit_coding_format_codec
458  * @param receive_coding_format_type
459  * @param receive_coding_format_company
460  * @param receive_coding_format_codec
461  * @param transmit_coding_frame_size
462  * @param receive_coding_frame_size
463  * @param input_bandwidth
464  * @param output_bandwidth
465  * @param input_coding_format_type
466  * @param input_coding_format_company
467  * @param input_coding_format_codec
468  * @param output_coding_format_type
469  * @param output_coding_format_company
470  * @param output_coding_format_codec
471  * @param input_coded_data_size
472  * @param outupt_coded_data_size
473  * @param input_pcm_data_format
474  * @param output_pcm_data_format
475  * @param input_pcm_sample_payload_msb_position
476  * @param output_pcm_sample_payload_msb_position
477  * @param input_data_path
478  * @param output_data_path
479  * @param input_transport_unit_size
480  * @param output_transport_unit_size
481  * @param max_latency
482  * @param packet_type
483  * @param retransmission_effort
484  */
485 const hci_cmd_t hci_enhanced_accept_synchronous_connection = {
486 OPCODE(OGF_LINK_CONTROL, 0x3e), "B4412212222441221222211111111221"
487 };
488 
489 /**
490  *  Link Policy Commands
491  */
492 
493 /**
494  * @param handle
495  * @param sniff_max_interval
496  * @param sniff_min_interval
497  * @param sniff_attempt
498  * @param sniff_timeout
499  */
500 const hci_cmd_t hci_sniff_mode = {
501 OPCODE(OGF_LINK_POLICY, 0x03), "H2222"
502 };
503 
504 /**
505  * @param handle
506  * @param flags
507  * @param service_type
508  * @param token_rate (bytes/s)
509  * @param peak_bandwith (bytes/s)
510  * @param latency (us)
511  * @param delay_variation (us)
512  */
513 const hci_cmd_t hci_qos_setup = {
514 OPCODE(OGF_LINK_POLICY, 0x07), "H114444"
515 };
516 
517 /**
518  * @param handle
519  */
520 const hci_cmd_t hci_role_discovery = {
521 OPCODE(OGF_LINK_POLICY, 0x09), "H"
522 };
523 
524 /**
525  * @param bd_addr
526  * @param role (0=master,1=slave)
527  */
528 const hci_cmd_t hci_switch_role_command= {
529 OPCODE(OGF_LINK_POLICY, 0x0b), "B1"
530 };
531 
532 /**
533  * @param handle
534  */
535 const hci_cmd_t hci_read_link_policy_settings = {
536 OPCODE(OGF_LINK_POLICY, 0x0c), "H"
537 };
538 
539 /**
540  * @param handle
541  * @param settings
542  */
543 const hci_cmd_t hci_write_link_policy_settings = {
544 OPCODE(OGF_LINK_POLICY, 0x0d), "H2"
545 };
546 
547 
548 /**
549  *  Controller & Baseband Commands
550  */
551 
552 /**
553  * @param event_mask_lover_octets
554  * @param event_mask_higher_octets
555  */
556 const hci_cmd_t hci_set_event_mask = {
557 OPCODE(OGF_CONTROLLER_BASEBAND, 0x01), "44"
558 };
559 
560 /**
561  */
562 const hci_cmd_t hci_reset = {
563 OPCODE(OGF_CONTROLLER_BASEBAND, 0x03), ""
564 };
565 
566 /**
567  * @param handle
568  */
569 const hci_cmd_t hci_flush = {
570 OPCODE(OGF_CONTROLLER_BASEBAND, 0x09), "H"
571 };
572 
573 /**
574  * @param bd_addr
575  * @param delete_all_flags
576  */
577 const hci_cmd_t hci_delete_stored_link_key = {
578 OPCODE(OGF_CONTROLLER_BASEBAND, 0x12), "B1"
579 };
580 
581 /**
582  * @param local_name (UTF-8, Null Terminated, max 248 octets)
583  */
584 const hci_cmd_t hci_write_local_name = {
585 OPCODE(OGF_CONTROLLER_BASEBAND, 0x13), "N"
586 };
587 
588 /**
589  */
590 const hci_cmd_t hci_read_local_name = {
591 OPCODE(OGF_CONTROLLER_BASEBAND, 0x14), ""
592 };
593 
594 /**
595  * @param page_timeout (* 0.625 ms)
596  */
597 const hci_cmd_t hci_write_page_timeout = {
598 OPCODE(OGF_CONTROLLER_BASEBAND, 0x18), "2"
599 };
600 
601 /**
602  * @param scan_enable (no, inq, page, inq+page)
603  */
604 const hci_cmd_t hci_write_scan_enable = {
605 OPCODE(OGF_CONTROLLER_BASEBAND, 0x1A), "1"
606 };
607 
608 /**
609  * @param authentication_enable
610  */
611 const hci_cmd_t hci_write_authentication_enable = {
612 OPCODE(OGF_CONTROLLER_BASEBAND, 0x20), "1"
613 };
614 
615 /**
616  * @param class_of_device
617  */
618 const hci_cmd_t hci_write_class_of_device = {
619 OPCODE(OGF_CONTROLLER_BASEBAND, 0x24), "3"
620 };
621 
622 /**
623  */
624 const hci_cmd_t hci_read_num_broadcast_retransmissions = {
625 OPCODE(OGF_CONTROLLER_BASEBAND, 0x29), ""
626 };
627 
628 /**
629  * @param num_broadcast_retransmissions (e.g. 0 for a single broadcast)
630  */
631 const hci_cmd_t hci_write_num_broadcast_retransmissions = {
632 OPCODE(OGF_CONTROLLER_BASEBAND, 0x2a), "1"
633 };
634 
635 /**
636  * @param synchronous_flow_control_enable - if yes, num completed packet everts are sent for SCO packets
637  */
638 const hci_cmd_t hci_write_synchronous_flow_control_enable = {
639 OPCODE(OGF_CONTROLLER_BASEBAND, 0x2f), "1"
640 };
641 
642 /**
643  * @param host_acl_data_packet_length
644  * @param host_synchronous_data_packet_length
645  * @param host_total_num_acl_data_packets
646  * @param host_total_num_synchronous_data_packets
647  */
648 const hci_cmd_t hci_host_buffer_size = {
649 OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122"
650 };
651 
652 /**
653  * @param handle
654  */
655 const hci_cmd_t hci_read_link_supervision_timeout = {
656 OPCODE(OGF_CONTROLLER_BASEBAND, 0x36), "H"
657 };
658 
659 /**
660  * @param handle
661  * @param timeout (0x0001 - 0xFFFF Time -> Range: 0.625ms - 40.9 sec)
662  */
663 const hci_cmd_t hci_write_link_supervision_timeout = {
664 OPCODE(OGF_CONTROLLER_BASEBAND, 0x37), "H2"
665 };
666 
667 /**
668  * @param inquiry_mode (0x00 = standard, 0x01 = with RSSI, 0x02 = extended)
669  */
670 const hci_cmd_t hci_write_inquiry_mode = {
671 OPCODE(OGF_CONTROLLER_BASEBAND, 0x45), "1"
672 };
673 
674 /**
675  * @param fec_required
676  * @param exstended_inquiry_response
677  */
678 const hci_cmd_t hci_write_extended_inquiry_response = {
679 OPCODE(OGF_CONTROLLER_BASEBAND, 0x52), "1E"
680 };
681 
682 /**
683  * @param mode (0 = off, 1 = on)
684  */
685 const hci_cmd_t hci_write_simple_pairing_mode = {
686 OPCODE(OGF_CONTROLLER_BASEBAND, 0x56), "1"
687 };
688 
689 /**
690  */
691 const hci_cmd_t hci_read_local_oob_data = {
692 OPCODE(OGF_CONTROLLER_BASEBAND, 0x57), ""
693 // return status, C, R
694 };
695 
696 /**
697  * @param mode (0 = off, 1 = on)
698  */
699 const hci_cmd_t hci_write_default_erroneous_data_reporting = {
700 OPCODE(OGF_CONTROLLER_BASEBAND, 0x5B), "1"
701 };
702 
703 /**
704  */
705 const hci_cmd_t hci_read_le_host_supported = {
706 OPCODE(OGF_CONTROLLER_BASEBAND, 0x6c), ""
707 // return: status, le supported host, simultaneous le host
708 };
709 
710 /**
711  * @param le_supported_host
712  * @param simultaneous_le_host
713  */
714 const hci_cmd_t hci_write_le_host_supported = {
715 OPCODE(OGF_CONTROLLER_BASEBAND, 0x6d), "11"
716 // return: status
717 };
718 
719 /**
720  */
721 const hci_cmd_t hci_read_local_extended_ob_data = {
722 OPCODE(OGF_CONTROLLER_BASEBAND, 0x7d), ""
723 // return status, C_192, R_192, R_256, C_256
724 };
725 
726 
727 /**
728  * Testing Commands
729  */
730 
731 
732 /**
733  */
734 const hci_cmd_t hci_read_loopback_mode = {
735 OPCODE(OGF_TESTING, 0x01), ""
736 // return: status, loopback mode (0 = off, 1 = local loopback, 2 = remote loopback)
737 };
738 
739 /**
740  * @param loopback_mode
741  */
742 const hci_cmd_t hci_write_loopback_mode = {
743 OPCODE(OGF_TESTING, 0x02), "1"
744 // return: status
745 };
746 
747 
748 /**
749  * Informational Parameters
750  */
751 
752 const hci_cmd_t hci_read_local_version_information = {
753 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x01), ""
754 };
755 const hci_cmd_t hci_read_local_supported_commands = {
756 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x02), ""
757 };
758 const hci_cmd_t hci_read_local_supported_features = {
759 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x03), ""
760 };
761 const hci_cmd_t hci_read_buffer_size = {
762 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x05), ""
763 };
764 const hci_cmd_t hci_read_bd_addr = {
765 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), ""
766 };
767 
768 /**
769  * Status Paramters
770  */
771 
772 /**
773  * @param handle
774  */
775 const hci_cmd_t hci_read_rssi = {
776 OPCODE(OGF_STATUS_PARAMETERS, 0x05), "H"
777 // no params
778 };
779 
780 
781 
782 #ifdef ENABLE_BLE
783 /**
784  * Low Energy Commands
785  */
786 
787 /**
788  * @param event_mask_lower_octets
789  * @param event_mask_higher_octets
790  */
791 const hci_cmd_t hci_le_set_event_mask = {
792 OPCODE(OGF_LE_CONTROLLER, 0x01), "44"
793 // return: status
794 };
795 
796 const hci_cmd_t hci_le_read_buffer_size = {
797 OPCODE(OGF_LE_CONTROLLER, 0x02), ""
798 // return: status, le acl data packet len (16), total num le acl data packets(8)
799 };
800 const hci_cmd_t hci_le_read_supported_features = {
801 OPCODE(OGF_LE_CONTROLLER, 0x03), ""
802 // return: LE_Features See [Vol 6] Part B, Section 4.6
803 };
804 
805 /**
806  * @param random_bd_addr
807  */
808 const hci_cmd_t hci_le_set_random_address = {
809 OPCODE(OGF_LE_CONTROLLER, 0x05), "B"
810 // return: status
811 };
812 
813 /**
814  * @param advertising_interval_min ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec)
815  * @param advertising_interval_max ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec)
816  * @param advertising_type (enum from 0: ADV_IND, ADC_DIRECT_IND, ADV_SCAN_IND, ADV_NONCONN_IND)
817  * @param own_address_type (enum from 0: public device address, random device address)
818  * @param direct_address_type ()
819  * @param direct_address (public or random address of device to be connecteed)
820  * @param advertising_channel_map (flags: chan_37(1), chan_38(2), chan_39(4))
821  * @param advertising_filter_policy (enum from 0: scan any conn any, scan whitelist, con any, scan any conn whitelist, scan whitelist, con whitelist)
822  */
823 const hci_cmd_t hci_le_set_advertising_parameters = {
824 OPCODE(OGF_LE_CONTROLLER, 0x06), "22111B11"
825 // return: status
826 };
827 
828 const hci_cmd_t hci_le_read_advertising_channel_tx_power = {
829 OPCODE(OGF_LE_CONTROLLER, 0x07), ""
830 // return: status, level [-20,10] signed int (8), units dBm
831 };
832 
833 /**
834  * @param advertising_data_length
835  * @param advertising_data (31 bytes)
836  */
837 const hci_cmd_t hci_le_set_advertising_data= {
838 OPCODE(OGF_LE_CONTROLLER, 0x08), "1A"
839 // return: status
840 };
841 
842 /**
843  * @param scan_response_data_length
844  * @param scan_response_data (31 bytes)
845  */
846 const hci_cmd_t hci_le_set_scan_response_data= {
847 OPCODE(OGF_LE_CONTROLLER, 0x09), "1A"
848 // return: status
849 };
850 
851 /**
852  * @param advertise_enable (off: 0, on: 1)
853  */
854 const hci_cmd_t hci_le_set_advertise_enable = {
855 OPCODE(OGF_LE_CONTROLLER, 0x0a), "1"
856 // return: status
857 };
858 
859 /**
860  * @param le_scan_type (passive (0), active (1))
861  * @param le_scan_interval ([0x0004,0x4000], unit: 0.625 msec)
862  * @param le_scan_window   ([0x0004,0x4000], unit: 0.625 msec)
863  * @param own_address_type (public (0), random (1))
864  * @param scanning_filter_policy (any (0), only whitelist (1))
865  */
866 const hci_cmd_t hci_le_set_scan_parameters = {
867 OPCODE(OGF_LE_CONTROLLER, 0x0b), "12211"
868 // return: status
869 };
870 
871 /**
872  * @param le_scan_enable  (disabled (0), enabled (1))
873  * @param filter_duplices (disabled (0), enabled (1))
874  */
875 const hci_cmd_t hci_le_set_scan_enable = {
876 OPCODE(OGF_LE_CONTROLLER, 0x0c), "11"
877 // return: status
878 };
879 
880 /**
881  * @param le_scan_interval ([0x0004, 0x4000], unit: 0.625 msec)
882  * @param le_scan_window ([0x0004, 0x4000], unit: 0.625 msec)
883  * @param initiator_filter_policy (peer address type + peer address (0), whitelist (1))
884  * @param peer_address_type (public (0), random (1))
885  * @param peer_address
886  * @param own_address_type (public (0), random (1))
887  * @param conn_interval_min ([0x0006, 0x0c80], unit: 1.25 msec)
888  * @param conn_interval_max ([0x0006, 0x0c80], unit: 1.25 msec)
889  * @param conn_latency (number of connection events [0x0000, 0x01f4])
890  * @param supervision_timeout ([0x000a, 0x0c80], unit: 10 msec)
891  * @param minimum_CE_length ([0x0000, 0xffff], unit: 0.625 msec)
892  * @param maximum_CE_length ([0x0000, 0xffff], unit: 0.625 msec)
893  */
894 const hci_cmd_t hci_le_create_connection= {
895 OPCODE(OGF_LE_CONTROLLER, 0x0d), "2211B1222222"
896 // return: none -> le create connection complete event
897 };
898 
899 const hci_cmd_t hci_le_create_connection_cancel = {
900 OPCODE(OGF_LE_CONTROLLER, 0x0e), ""
901 // return: status
902 };
903 
904 const hci_cmd_t hci_le_read_white_list_size = {
905 OPCODE(OGF_LE_CONTROLLER, 0x0f), ""
906 // return: status, number of entries in controller whitelist
907 };
908 
909 const hci_cmd_t hci_le_clear_white_list = {
910 OPCODE(OGF_LE_CONTROLLER, 0x10), ""
911 // return: status
912 };
913 
914 /**
915  * @param address_type (public (0), random (1))
916  * @param bd_addr
917  */
918 const hci_cmd_t hci_le_add_device_to_white_list = {
919 OPCODE(OGF_LE_CONTROLLER, 0x11), "1B"
920 // return: status
921 };
922 
923 /**
924  * @param address_type (public (0), random (1))
925  * @param bd_addr
926  */
927 const hci_cmd_t hci_le_remove_device_from_white_list = {
928 OPCODE(OGF_LE_CONTROLLER, 0x12), "1B"
929 // return: status
930 };
931 
932 /**
933  * @param conn_handle
934  * @param conn_interval_min ([0x0006,0x0c80], unit: 1.25 msec)
935  * @param conn_interval_max ([0x0006,0x0c80], unit: 1.25 msec)
936  * @param conn_latency ([0x0000,0x03e8], number of connection events)
937  * @param supervision_timeout ([0x000a,0x0c80], unit: 10 msec)
938  * @param minimum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
939  * @param maximum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
940  */
941 const hci_cmd_t hci_le_connection_update = {
942 OPCODE(OGF_LE_CONTROLLER, 0x13), "H222222"
943 // return: none -> le connection update complete event
944 };
945 
946 /**
947  * @param channel_map_lower_32bits
948  * @param channel_map_higher_5bits
949  */
950 const hci_cmd_t hci_le_set_host_channel_classification = {
951 OPCODE(OGF_LE_CONTROLLER, 0x14), "41"
952 // return: status
953 };
954 
955 /**
956  * @param conn_handle
957  */
958 const hci_cmd_t hci_le_read_channel_map = {
959 OPCODE(OGF_LE_CONTROLLER, 0x15), "H"
960 // return: status, connection handle, channel map (5 bytes, 37 used)
961 };
962 
963 /**
964  * @param conn_handle
965  */
966 const hci_cmd_t hci_le_read_remote_used_features = {
967 OPCODE(OGF_LE_CONTROLLER, 0x16), "H"
968 // return: none -> le read remote used features complete event
969 };
970 
971 /**
972  * @param key ((128) for AES-128)
973  * @param plain_text (128)
974  */
975 const hci_cmd_t hci_le_encrypt = {
976 OPCODE(OGF_LE_CONTROLLER, 0x17), "PP"
977 // return: status, encrypted data (128)
978 };
979 
980 const hci_cmd_t hci_le_rand = {
981 OPCODE(OGF_LE_CONTROLLER, 0x18), ""
982 // return: status, random number (64)
983 };
984 
985 /**
986  * @param conn_handle
987  * @param random_number_lower_32bits
988  * @param random_number_higher_32bits
989  * @param encryption_diversifier (16)
990  * @param long_term_key (128)
991  */
992 const hci_cmd_t hci_le_start_encryption = {
993 OPCODE(OGF_LE_CONTROLLER, 0x19), "H442P"
994 // return: none -> encryption changed or encryption key refresh complete event
995 };
996 
997 /**
998  * @param connection_handle
999  * @param long_term_key (128)
1000  */
1001 const hci_cmd_t hci_le_long_term_key_request_reply = {
1002 OPCODE(OGF_LE_CONTROLLER, 0x1a), "HP"
1003 // return: status, connection handle
1004 };
1005 
1006 /**
1007  * @param conn_handle
1008  */
1009 const hci_cmd_t hci_le_long_term_key_negative_reply = {
1010 OPCODE(OGF_LE_CONTROLLER, 0x1b), "H"
1011 // return: status, connection handle
1012 };
1013 
1014 /**
1015  * @param conn_handle
1016  */
1017 const hci_cmd_t hci_le_read_supported_states = {
1018 OPCODE(OGF_LE_CONTROLLER, 0x1c), "H"
1019 // return: status, LE states (64)
1020 };
1021 
1022 /**
1023  * @param rx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2)
1024  */
1025 const hci_cmd_t hci_le_receiver_test = {
1026 OPCODE(OGF_LE_CONTROLLER, 0x1d), "1"
1027 // return: status
1028 };
1029 
1030 /**
1031  * @param tx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2)
1032  * @param test_payload_lengh ([0x00,0x25])
1033  * @param packet_payload ([0,7] different patterns)
1034  */
1035 const hci_cmd_t hci_le_transmitter_test = {
1036 OPCODE(OGF_LE_CONTROLLER, 0x1e), "111"
1037 // return: status
1038 };
1039 
1040 /**
1041  * @param end_test_cmd
1042  */
1043 const hci_cmd_t hci_le_test_end = {
1044 OPCODE(OGF_LE_CONTROLLER, 0x1f), "1"
1045 // return: status, number of packets (8)
1046 };
1047 
1048 /**
1049  */
1050 const hci_cmd_t hci_le_read_local_p256_public_key = {
1051 OPCODE(OGF_LE_CONTROLLER, 0x25), ""
1052 //  LE Read Local P-256 Public Key Complete is generated on completion
1053 };
1054 
1055 /**
1056  * @param end_test_cmd
1057  */
1058 const hci_cmd_t hci_le_generate_dhkey = {
1059 OPCODE(OGF_LE_CONTROLLER, 0x26), "QQ"
1060 // LE Generate DHKey Complete is generated on completion
1061 };
1062 
1063 #endif
1064 
1065 // Broadcom / Cypress specific HCI commands
1066 
1067 /**
1068  * @brief Configure SCO Routing (BCM)
1069  * @param sco_routing is 0 for PCM, 1 for Transport, 2 for Codec and 3 for I2S
1070  * @param pcm_interface_rate is 0 for 128KBps, 1 for 256 KBps, 2 for 512KBps, 3 for 1024KBps, and 4 for 2048Kbps
1071  * @param frame_type is 0 for short and 1 for long
1072  * @param sync_mode is 0 for slave and 1 for master
1073  * @param clock_mode is 0 for slabe and 1 for master
1074  */
1075 const hci_cmd_t hci_bcm_write_sco_pcm_int = {
1076 OPCODE(0x3f, 0x1c), "11111"
1077 // return: status
1078 };
1079