xref: /btstack/src/hci_cmd.c (revision 6d34f98e0c6a035be904a5ac00e86a7b4f285631)
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 #define BTSTACK_FILE__ "hci_cmd.c"
39 
40 /*
41  *  hci_cmd.c
42  *
43  *  Created by Matthias Ringwald on 7/23/09.
44  */
45 
46 #include "btstack_config.h"
47 
48 #include "classic/sdp_util.h"
49 #include "hci.h"
50 #include "hci_cmd.h"
51 #include "btstack_debug.h"
52 
53 #include <string.h>
54 
55 // calculate combined ogf/ocf value
56 #define OPCODE(ogf, ocf) ((ocf) | ((ogf) << 10))
57 
58 /**
59  * construct HCI Command based on template
60  *
61  * Format:
62  *   1,2,3,4: one to four byte value
63  *   H: HCI connection handle
64  *   B: Bluetooth Baseband Address (BD_ADDR)
65  *   D: 8 byte data block
66  *   E: Extended Inquiry Result
67  *   N: Name up to 248 chars, \0 terminated
68  *   P: 16 byte data block. Pairing code, Simple Pairing Hash and Randomizer
69  *   A: 31 bytes advertising data
70  *   S: Service Record (Data Element Sequence)
71  *   Q: 32 byte data block, e.g. for X and Y coordinates of P-256 public key
72  */
73 uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr){
74 
75     hci_cmd_buffer[0] = cmd->opcode & 0xffu;
76     hci_cmd_buffer[1] = cmd->opcode >> 8;
77     int pos = 3;
78 
79     const char *format = cmd->format;
80     uint16_t word;
81     uint32_t longword;
82     uint8_t * ptr;
83     while (*format) {
84         switch(*format) {
85             case '1': //  8 bit value
86             case '2': // 16 bit value
87             case 'H': // hci_handle
88                 word = va_arg(argptr, int);  // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
89                 hci_cmd_buffer[pos++] = word & 0xffu;
90                 if (*format == '2') {
91                     hci_cmd_buffer[pos++] = word >> 8;
92                 } else if (*format == 'H') {
93                     // TODO implement opaque client connection handles
94                     //      pass module handle for now
95                     hci_cmd_buffer[pos++] = word >> 8;
96                 }
97                 break;
98             case '3':
99             case '4':
100                 longword = va_arg(argptr, uint32_t);
101                 // longword = va_arg(argptr, int);
102                 hci_cmd_buffer[pos++] = longword;
103                 hci_cmd_buffer[pos++] = longword >> 8;
104                 hci_cmd_buffer[pos++] = longword >> 16;
105                 if (*format == '4'){
106                     hci_cmd_buffer[pos++] = longword >> 24;
107                 }
108                 break;
109             case 'B': // bt-addr
110                 ptr = va_arg(argptr, uint8_t *);
111                 hci_cmd_buffer[pos++] = ptr[5];
112                 hci_cmd_buffer[pos++] = ptr[4];
113                 hci_cmd_buffer[pos++] = ptr[3];
114                 hci_cmd_buffer[pos++] = ptr[2];
115                 hci_cmd_buffer[pos++] = ptr[1];
116                 hci_cmd_buffer[pos++] = ptr[0];
117                 break;
118             case 'D': // 8 byte data block
119                 ptr = va_arg(argptr, uint8_t *);
120                 (void)memcpy(&hci_cmd_buffer[pos], ptr, 8);
121                 pos += 8;
122                 break;
123             case 'E': // Extended Inquiry Information 240 octets
124                 ptr = va_arg(argptr, uint8_t *);
125                 (void)memcpy(&hci_cmd_buffer[pos], ptr, 240);
126                 pos += 240;
127                 break;
128             case 'N': { // UTF-8 string, null terminated
129                 ptr = va_arg(argptr, uint8_t *);
130                 uint16_t len = strlen((const char*) ptr);
131                 if (len > 248u) {
132                     len = 248;
133                 }
134                 (void)memcpy(&hci_cmd_buffer[pos], ptr, len);
135                 if (len < 248u) {
136                     // fill remaining space with zeroes
137                     memset(&hci_cmd_buffer[pos+len], 0u, 248u-len);
138                 }
139                 pos += 248;
140                 break;
141             }
142             case 'P': // 16 byte PIN code or link key
143                 ptr = va_arg(argptr, uint8_t *);
144                 (void)memcpy(&hci_cmd_buffer[pos], ptr, 16);
145                 pos += 16;
146                 break;
147 #ifdef ENABLE_BLE
148             case 'A': // 31 bytes advertising data
149                 ptr = va_arg(argptr, uint8_t *);
150                 (void)memcpy(&hci_cmd_buffer[pos], ptr, 31);
151                 pos += 31;
152                 break;
153 #endif
154 #ifdef ENABLE_SDP
155             case 'S': { // Service Record (Data Element Sequence)
156                 ptr = va_arg(argptr, uint8_t *);
157                 uint16_t len = de_get_len(ptr);
158                 (void)memcpy(&hci_cmd_buffer[pos], ptr, len);
159                 pos += len;
160                 break;
161             }
162 #endif
163 #ifdef ENABLE_LE_SECURE_CONNECTIONS
164             case 'Q':
165                 ptr = va_arg(argptr, uint8_t *);
166                 reverse_bytes(ptr, &hci_cmd_buffer[pos], 32);
167                 pos += 32;
168                 break;
169 #endif
170             default:
171                 break;
172         }
173         format++;
174     };
175     hci_cmd_buffer[2] = pos - 3;
176     return pos;
177 }
178 
179 /**
180  *  Link Control Commands
181  */
182 
183 /**
184  * @param lap
185  * @param inquiry_length
186  * @param num_responses
187  */
188 const hci_cmd_t hci_inquiry = {
189     HCI_OPCODE_HCI_INQUIRY, "311"
190 };
191 
192 /**
193  */
194 const hci_cmd_t hci_inquiry_cancel = {
195     HCI_OPCODE_HCI_INQUIRY_CANCEL, ""
196 };
197 
198 /**
199  * @param bd_addr
200  * @param packet_type
201  * @param page_scan_repetition_mode
202  * @param reserved
203  * @param clock_offset
204  * @param allow_role_switch
205  */
206 const hci_cmd_t hci_create_connection = {
207     HCI_OPCODE_HCI_CREATE_CONNECTION, "B21121"
208 };
209 
210 /**
211  * @param handle
212  * @param reason (0x05, 0x13-0x15, 0x1a, 0x29, see Errors Codes in BT Spec Part D)
213  */
214 const hci_cmd_t hci_disconnect = {
215     HCI_OPCODE_HCI_DISCONNECT, "H1"
216 };
217 
218 /**
219  * @param bd_addr
220  */
221 const hci_cmd_t hci_create_connection_cancel = {
222     HCI_OPCODE_HCI_CREATE_CONNECTION_CANCEL, "B"
223 };
224 
225 /**
226  * @param bd_addr
227  * @param role (become master, stay slave)
228  */
229 const hci_cmd_t hci_accept_connection_request = {
230     HCI_OPCODE_HCI_ACCEPT_CONNECTION_REQUEST, "B1"
231 };
232 
233 /**
234  * @param bd_addr
235  * @param reason (e.g. CONNECTION REJECTED DUE TO LIMITED RESOURCES (0x0d))
236  */
237 const hci_cmd_t hci_reject_connection_request = {
238     HCI_OPCODE_HCI_REJECT_CONNECTION_REQUEST, "B1"
239 };
240 
241 /**
242  * @param bd_addr
243  * @param link_key
244  */
245 const hci_cmd_t hci_link_key_request_reply = {
246     HCI_OPCODE_HCI_LINK_KEY_REQUEST_REPLY, "BP"
247 };
248 
249 /**
250  * @param bd_addr
251  */
252 const hci_cmd_t hci_link_key_request_negative_reply = {
253     HCI_OPCODE_HCI_LINK_KEY_REQUEST_NEGATIVE_REPLY, "B"
254 };
255 
256 /**
257  * @param bd_addr
258  * @param pin_length
259  * @param pin (c-string)
260  */
261 const hci_cmd_t hci_pin_code_request_reply = {
262     HCI_OPCODE_HCI_PIN_CODE_REQUEST_REPLY, "B1P"
263 };
264 
265 /**
266  * @param bd_addr
267  */
268 const hci_cmd_t hci_pin_code_request_negative_reply = {
269     HCI_OPCODE_HCI_PIN_CODE_REQUEST_NEGATIVE_REPLY, "B"
270 };
271 
272 /**
273  * @param handle
274  * @param packet_type
275  */
276 const hci_cmd_t hci_change_connection_packet_type = {
277     HCI_OPCODE_HCI_CHANGE_CONNECTION_PACKET_TYPE, "H2"
278 };
279 
280 /**
281  * @param handle
282  */
283 const hci_cmd_t hci_authentication_requested = {
284     HCI_OPCODE_HCI_AUTHENTICATION_REQUESTED, "H"
285 };
286 
287 /**
288  * @param handle
289  * @param encryption_enable
290  */
291 const hci_cmd_t hci_set_connection_encryption = {
292     HCI_OPCODE_HCI_SET_CONNECTION_ENCRYPTION, "H1"
293 };
294 
295 /**
296  * @param handle
297  */
298 const hci_cmd_t hci_change_connection_link_key = {
299     HCI_OPCODE_HCI_CHANGE_CONNECTION_LINK_KEY, "H"
300 };
301 
302 /**
303  * @param bd_addr
304  * @param page_scan_repetition_mode
305  * @param reserved
306  * @param clock_offset
307  */
308 const hci_cmd_t hci_remote_name_request = {
309     HCI_OPCODE_HCI_REMOTE_NAME_REQUEST, "B112"
310 };
311 
312 
313 /**
314  * @param bd_addr
315  */
316 const hci_cmd_t hci_remote_name_request_cancel = {
317     HCI_OPCODE_HCI_REMOTE_NAME_REQUEST_CANCEL, "B"
318 };
319 
320  /**
321  * @param handle
322  */
323 const hci_cmd_t hci_read_remote_supported_features_command = {
324     HCI_OPCODE_HCI_READ_REMOTE_SUPPORTED_FEATURES_COMMAND, "H"
325 };
326 
327 /**
328 * @param handle
329 */
330 const hci_cmd_t hci_read_remote_extended_features_command = {
331     HCI_OPCODE_HCI_READ_REMOTE_EXTENDED_FEATURES_COMMAND, "H1"
332 };
333 
334 /**
335  * @param handle
336  */
337 const hci_cmd_t hci_read_remote_version_information = {
338     HCI_OPCODE_HCI_READ_REMOTE_VERSION_INFORMATION, "H"
339 };
340 
341 /**
342  * @param handle
343  * @param transmit_bandwidth 8000(64kbps)
344  * @param receive_bandwidth  8000(64kbps)
345  * @param max_latency        >= 7ms for eSCO, 0xFFFF do not care
346  * @param voice_settings     e.g. CVSD, Input Coding: Linear, Input Data Format: 2’s complement, data 16bit: 00011000000 == 0x60
347  * @param retransmission_effort  e.g. 0xFF do not care
348  * @param packet_type        at least EV3 for eSCO
349  */
350 const hci_cmd_t hci_setup_synchronous_connection = {
351     HCI_OPCODE_HCI_SETUP_SYNCHRONOUS_CONNECTION, "H442212"
352 };
353 
354 /**
355  * @param bd_addr
356  * @param transmit_bandwidth
357  * @param receive_bandwidth
358  * @param max_latency
359  * @param voice_settings
360  * @param retransmission_effort
361  * @param packet_type
362  */
363 const hci_cmd_t hci_accept_synchronous_connection = {
364     HCI_OPCODE_HCI_ACCEPT_SYNCHRONOUS_CONNECTION, "B442212"
365 };
366 
367 /**
368  * @param bd_addr
369  * @param IO_capability
370  * @param OOB_data_present
371  * @param authentication_requirements
372  */
373 const hci_cmd_t hci_io_capability_request_reply = {
374     HCI_OPCODE_HCI_IO_CAPABILITY_REQUEST_REPLY, "B111"
375 };
376 
377 /**
378  * @param bd_addr
379  */
380 const hci_cmd_t hci_user_confirmation_request_reply = {
381     HCI_OPCODE_HCI_USER_CONFIRMATION_REQUEST_REPLY, "B"
382 };
383 
384 /**
385  * @param bd_addr
386  */
387 const hci_cmd_t hci_user_confirmation_request_negative_reply = {
388     HCI_OPCODE_HCI_USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, "B"
389 };
390 
391 /**
392  * @param bd_addr
393  * @param numeric_value
394  */
395 const hci_cmd_t hci_user_passkey_request_reply = {
396     HCI_OPCODE_HCI_USER_PASSKEY_REQUEST_REPLY, "B4"
397 };
398 
399 /**
400  * @param bd_addr
401  */
402 const hci_cmd_t hci_user_passkey_request_negative_reply = {
403     HCI_OPCODE_HCI_USER_PASSKEY_REQUEST_NEGATIVE_REPLY, "B"
404 };
405 
406 /**
407  * @param bd_addr
408  * @param c Simple Pairing Hash C
409  * @param r Simple Pairing Randomizer R
410  */
411 const hci_cmd_t hci_remote_oob_data_request_reply = {
412     HCI_OPCODE_HCI_REMOTE_OOB_DATA_REQUEST_REPLY, "BPP"
413 };
414 
415 /**
416  * @param bd_addr
417  */
418 const hci_cmd_t hci_remote_oob_data_request_negative_reply = {
419     HCI_OPCODE_HCI_REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, "B"
420 };
421 
422 /**
423  * @param bd_addr
424  * @param reason (Part D, Error codes)
425  */
426 const hci_cmd_t hci_io_capability_request_negative_reply = {
427     HCI_OPCODE_HCI_IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, "B1"
428 };
429 
430 /**
431  * @param handle
432  * @param transmit_bandwidth
433  * @param receive_bandwidth
434  * @param transmit_coding_format_type
435  * @param transmit_coding_format_company
436  * @param transmit_coding_format_codec
437  * @param receive_coding_format_type
438  * @param receive_coding_format_company
439  * @param receive_coding_format_codec
440  * @param transmit_coding_frame_size
441  * @param receive_coding_frame_size
442  * @param input_bandwidth
443  * @param output_bandwidth
444  * @param input_coding_format_type
445  * @param input_coding_format_company
446  * @param input_coding_format_codec
447  * @param output_coding_format_type
448  * @param output_coding_format_company
449  * @param output_coding_format_codec
450  * @param input_coded_data_size
451  * @param outupt_coded_data_size
452  * @param input_pcm_data_format
453  * @param output_pcm_data_format
454  * @param input_pcm_sample_payload_msb_position
455  * @param output_pcm_sample_payload_msb_position
456  * @param input_data_path
457  * @param output_data_path
458  * @param input_transport_unit_size
459  * @param output_transport_unit_size
460  * @param max_latency
461  * @param packet_type
462  * @param retransmission_effort
463  */
464 const hci_cmd_t hci_enhanced_setup_synchronous_connection = {
465     HCI_OPCODE_HCI_ENHANCED_SETUP_SYNCHRONOUS_CONNECTION, "H4412212222441221222211111111221"
466 };
467 
468 /**
469  * @param bd_addr
470  * @param transmit_bandwidth
471  * @param receive_bandwidth
472  * @param transmit_coding_format_type
473  * @param transmit_coding_format_company
474  * @param transmit_coding_format_codec
475  * @param receive_coding_format_type
476  * @param receive_coding_format_company
477  * @param receive_coding_format_codec
478  * @param transmit_coding_frame_size
479  * @param receive_coding_frame_size
480  * @param input_bandwidth
481  * @param output_bandwidth
482  * @param input_coding_format_type
483  * @param input_coding_format_company
484  * @param input_coding_format_codec
485  * @param output_coding_format_type
486  * @param output_coding_format_company
487  * @param output_coding_format_codec
488  * @param input_coded_data_size
489  * @param outupt_coded_data_size
490  * @param input_pcm_data_format
491  * @param output_pcm_data_format
492  * @param input_pcm_sample_payload_msb_position
493  * @param output_pcm_sample_payload_msb_position
494  * @param input_data_path
495  * @param output_data_path
496  * @param input_transport_unit_size
497  * @param output_transport_unit_size
498  * @param max_latency
499  * @param packet_type
500  * @param retransmission_effort
501  */
502 const hci_cmd_t hci_enhanced_accept_synchronous_connection = {
503     HCI_OPCODE_HCI_ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, "B4412212222441221222211111111221"
504 };
505 
506 /**
507  *  Link Policy Commands
508  */
509 
510 /**
511  * @param handle
512  * @param sniff_max_interval
513  * @param sniff_min_interval
514  * @param sniff_attempt
515  * @param sniff_timeout
516  */
517 const hci_cmd_t hci_sniff_mode = {
518     HCI_OPCODE_HCI_SNIFF_MODE, "H2222"
519 };
520 
521 /**
522  * @param handle
523  */
524 const hci_cmd_t hci_exit_sniff_mode = {
525     HCI_OPCODE_HCI_EXIT_SNIFF_MODE, "H"
526 };
527 
528 /**
529  * @param handle
530  * @param flags
531  * @param service_type
532  * @param token_rate (bytes/s)
533  * @param peak_bandwith (bytes/s)
534  * @param latency (us)
535  * @param delay_variation (us)
536  */
537 const hci_cmd_t hci_qos_setup = {
538     HCI_OPCODE_HCI_QOS_SETUP, "H114444"
539 };
540 
541 /**
542  * @param handle
543  */
544 const hci_cmd_t hci_role_discovery = {
545     HCI_OPCODE_HCI_ROLE_DISCOVERY, "H"
546 };
547 
548 /**
549  * @param bd_addr
550  * @param role (0=master,1=slave)
551  */
552 const hci_cmd_t hci_switch_role_command= {
553     HCI_OPCODE_HCI_SWITCH_ROLE_COMMAND, "B1"
554 };
555 
556 /**
557  * @param handle
558  */
559 const hci_cmd_t hci_read_link_policy_settings = {
560     HCI_OPCODE_HCI_READ_LINK_POLICY_SETTINGS, "H"
561 };
562 
563 /**
564  * @param handle
565  * @param settings
566  */
567 const hci_cmd_t hci_write_link_policy_settings = {
568     HCI_OPCODE_HCI_WRITE_LINK_POLICY_SETTINGS, "H2"
569 };
570 
571 /**
572  * @param policy
573  */
574 const hci_cmd_t hci_write_default_link_policy_setting = {
575     HCI_OPCODE_HCI_WRITE_DEFAULT_LINK_POLICY_SETTING, "2"
576 };
577 
578 
579 /**
580  *  Controller & Baseband Commands
581  */
582 
583 
584 /**
585  * @param event_mask_lover_octets
586  * @param event_mask_higher_octets
587  */
588 const hci_cmd_t hci_set_event_mask = {
589     HCI_OPCODE_HCI_SET_EVENT_MASK, "44"
590 };
591 
592 /**
593  */
594 const hci_cmd_t hci_reset = {
595     HCI_OPCODE_HCI_RESET, ""
596 };
597 
598 /**
599  * @param handle
600  */
601 const hci_cmd_t hci_flush = {
602     HCI_OPCODE_HCI_FLUSH, "H"
603 };
604 
605 /**
606  * @param handle
607  */
608 const hci_cmd_t hci_read_pin_type = {
609     HCI_OPCODE_HCI_READ_PIN_TYPE, ""
610 };
611 
612 /**
613  * @param handle
614  */
615 const hci_cmd_t hci_write_pin_type = {
616     HCI_OPCODE_HCI_WRITE_PIN_TYPE, "1"
617 };
618 
619 /**
620  * @param bd_addr
621  * @param delete_all_flags
622  */
623 const hci_cmd_t hci_delete_stored_link_key = {
624     HCI_OPCODE_HCI_DELETE_STORED_LINK_KEY, "B1"
625 };
626 
627 #ifdef ENABLE_CLASSIC
628 /**
629  * @param local_name (UTF-8, Null Terminated, max 248 octets)
630  */
631 const hci_cmd_t hci_write_local_name = {
632     HCI_OPCODE_HCI_WRITE_LOCAL_NAME, "N"
633 };
634 #endif
635 
636 /**
637  */
638 const hci_cmd_t hci_read_local_name = {
639     HCI_OPCODE_HCI_READ_LOCAL_NAME, ""
640 };
641 
642 /**
643  */
644 const hci_cmd_t hci_read_page_timeout = {
645     HCI_OPCODE_HCI_READ_PAGE_TIMEOUT, ""
646 };
647 
648 /**
649  * @param page_timeout (* 0.625 ms)
650  */
651 const hci_cmd_t hci_write_page_timeout = {
652     HCI_OPCODE_HCI_WRITE_PAGE_TIMEOUT, "2"
653 };
654 
655 /**
656  * @param scan_enable (no, inq, page, inq+page)
657  */
658 const hci_cmd_t hci_write_scan_enable = {
659     HCI_OPCODE_HCI_WRITE_SCAN_ENABLE, "1"
660 };
661 
662 /**
663  */
664 const hci_cmd_t hci_read_page_scan_activity = {
665     HCI_OPCODE_HCI_READ_PAGE_SCAN_ACTIVITY, ""
666 };
667 
668 /**
669  * @param page_scan_interval (* 0.625 ms)
670  * @param page_scan_window (* 0.625 ms, must be <= page_scan_interval)
671  */
672 const hci_cmd_t hci_write_page_scan_activity = {
673     HCI_OPCODE_HCI_WRITE_PAGE_SCAN_ACTIVITY, "22"
674 };
675 
676 /**
677  */
678 const hci_cmd_t hci_read_inquiry_scan_activity = {
679     HCI_OPCODE_HCI_READ_INQUIRY_SCAN_ACTIVITY, ""
680 };
681 
682 /**
683  * @param inquiry_scan_interval (* 0.625 ms)
684  * @param inquiry_scan_window (* 0.625 ms, must be <= inquiry_scan_interval)
685  */
686 const hci_cmd_t hci_write_inquiry_scan_activity = {
687     HCI_OPCODE_HCI_WRITE_INQUIRY_SCAN_ACTIVITY, "22"
688 };
689 
690 /**
691  * @param authentication_enable
692  */
693 const hci_cmd_t hci_write_authentication_enable = {
694     HCI_OPCODE_HCI_WRITE_AUTHENTICATION_ENABLE, "1"
695 };
696 
697 /**
698  * @param class_of_device
699  */
700 const hci_cmd_t hci_write_class_of_device = {
701     HCI_OPCODE_HCI_WRITE_CLASS_OF_DEVICE, "3"
702 };
703 
704 /**
705  */
706 const hci_cmd_t hci_read_num_broadcast_retransmissions = {
707     HCI_OPCODE_HCI_READ_NUM_BROADCAST_RETRANSMISSIONS, ""
708 };
709 
710 /**
711  * @param num_broadcast_retransmissions (e.g. 0 for a single broadcast)
712  */
713 const hci_cmd_t hci_write_num_broadcast_retransmissions = {
714     HCI_OPCODE_HCI_WRITE_NUM_BROADCAST_RETRANSMISSIONS, "1"
715 };
716 
717 /**
718  * @param connection_handle
719  * @param type 0 = current transmit level, 1 = max transmit level
720  */
721 const hci_cmd_t hci_read_transmit_power_level = {
722     HCI_OPCODE_HCI_READ_TRANSMIT_POWER_LEVEL, "11"
723 };
724 
725 /**
726  * @param synchronous_flow_control_enable - if yes, num completed packet everts are sent for SCO packets
727  */
728 const hci_cmd_t hci_write_synchronous_flow_control_enable = {
729     HCI_OPCODE_HCI_WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, "1"
730 };
731 
732 #ifdef ENABLE_HCI_CONTROLLER_TO_HOST_FLOW_CONTROL
733 
734 /**
735  * @param flow_control_enable - 0: off, 1: ACL only, 2: SCO only, 3: ACL + SCO
736  */
737 const hci_cmd_t hci_set_controller_to_host_flow_control = {
738     HCI_OPCODE_HCI_SET_CONTROLLER_TO_HOST_FLOW_CONTROL, "1"
739 };
740 
741 /**
742  * @param host_acl_data_packet_length
743  * @param host_synchronous_data_packet_length
744  * @param host_total_num_acl_data_packets
745  * @param host_total_num_synchronous_data_packets
746  */
747 const hci_cmd_t hci_host_buffer_size = {
748     HCI_OPCODE_HCI_HOST_BUFFER_SIZE, "2122"
749 };
750 
751 
752 #if 0
753 //
754 // command sent manually sent by hci_host_num_completed_packets
755 //
756 /**
757  * @note only single handle supported by BTstack command generator
758  * @param number_of_handles must be 1
759  * @param connection_handle
760  * @param host_num_of_completed_packets for the given connection handle
761  */
762 const hci_cmd_t hci_host_number_of_completed_packets = {
763     HCI_OPCODE_HCI_HOST_NUMBER_OF_COMPLETED_PACKETS, "1H2"
764 };
765 #endif
766 
767 #endif
768 
769 /**
770  * @param handle
771  */
772 const hci_cmd_t hci_read_link_supervision_timeout = {
773     HCI_OPCODE_HCI_READ_LINK_SUPERVISION_TIMEOUT, "H"
774 };
775 
776 /**
777  * @param handle
778  * @param timeout (0x0001 - 0xFFFF Time -> Range: 0.625ms - 40.9 sec)
779  */
780 const hci_cmd_t hci_write_link_supervision_timeout = {
781     HCI_OPCODE_HCI_WRITE_LINK_SUPERVISION_TIMEOUT, "H2"
782 };
783 
784 /**
785  * @param num_current_iac must be 2
786  * @param iac_lap1
787  * @param iac_lap2
788  */
789 const hci_cmd_t hci_write_current_iac_lap_two_iacs = {
790     HCI_OPCODE_HCI_WRITE_CURRENT_IAC_LAP_TWO_IACS, "133"
791 };
792 
793 /**
794  * @param inquiry_mode (0x00 = standard, 0x01 = with RSSI, 0x02 = extended)
795  */
796 const hci_cmd_t hci_write_inquiry_mode = {
797     HCI_OPCODE_HCI_WRITE_INQUIRY_MODE, "1"
798 };
799 
800 /**
801  * @param fec_required
802  * @param exstended_inquiry_response
803  */
804 const hci_cmd_t hci_write_extended_inquiry_response = {
805     HCI_OPCODE_HCI_WRITE_EXTENDED_INQUIRY_RESPONSE, "1E"
806 };
807 
808 /**
809  * @param mode (0 = off, 1 = on)
810  */
811 const hci_cmd_t hci_write_simple_pairing_mode = {
812     HCI_OPCODE_HCI_WRITE_SIMPLE_PAIRING_MODE, "1"
813 };
814 
815 /**
816  */
817 const hci_cmd_t hci_read_local_oob_data = {
818     HCI_OPCODE_HCI_READ_LOCAL_OOB_DATA, ""
819     // return status, C, R
820 };
821 
822 /**
823  * @param mode (0 = off, 1 = on)
824  */
825 const hci_cmd_t hci_write_default_erroneous_data_reporting = {
826     HCI_OPCODE_HCI_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, "1"
827 };
828 
829 /**
830  */
831 const hci_cmd_t hci_read_le_host_supported = {
832     HCI_OPCODE_HCI_READ_LE_HOST_SUPPORTED, ""
833     // return: status, le supported host, simultaneous le host
834 };
835 
836 /**
837  * @param le_supported_host
838  * @param simultaneous_le_host
839  */
840 const hci_cmd_t hci_write_le_host_supported = {
841     HCI_OPCODE_HCI_WRITE_LE_HOST_SUPPORTED, "11"
842     // return: status
843 };
844 
845 /**
846  * @param secure_connections_host_support
847  */
848 const hci_cmd_t hci_write_secure_connections_host_support = {
849     HCI_OPCODE_HCI_WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, "1"
850     // return: status
851 };
852 
853 /**
854  */
855 const hci_cmd_t hci_read_local_extended_ob_data = {
856     HCI_OPCODE_HCI_READ_LOCAL_EXTENDED_OB_DATA, ""
857     // return status, C_192, R_192, R_256, C_256
858 };
859 
860 
861 /**
862  * Testing Commands
863  */
864 
865 
866 /**
867  */
868 const hci_cmd_t hci_read_loopback_mode = {
869     HCI_OPCODE_HCI_READ_LOOPBACK_MODE, ""
870     // return: status, loopback mode (0 = off, 1 = local loopback, 2 = remote loopback)
871 };
872 
873 /**
874  * @param loopback_mode
875  */
876 const hci_cmd_t hci_write_loopback_mode = {
877     HCI_OPCODE_HCI_WRITE_LOOPBACK_MODE, "1"
878     // return: status
879 };
880 
881 /**
882  */
883 const hci_cmd_t hci_enable_device_under_test_mode = {
884     HCI_OPCODE_HCI_ENABLE_DEVICE_UNDER_TEST_MODE, ""
885     // return: status
886 };
887 
888 /**
889  * @param simple_pairing_debug_mode
890  */
891 const hci_cmd_t hci_write_simple_pairing_debug_mode = {
892     HCI_OPCODE_HCI_WRITE_SIMPLE_PAIRING_DEBUG_MODE, "1"
893     // return: status
894 };
895 
896 /**
897  * @param handle
898  * @param dm1_acl_u_mode
899  * @param esco_loopback_mode
900  */
901 const hci_cmd_t hci_write_secure_connections_test_mode = {
902     HCI_OPCODE_HCI_WRITE_SECURE_CONNECTIONS_TEST_MODE, "H11"
903     // return: status
904 };
905 
906 
907 /**
908  * Informational Parameters
909  */
910 
911 const hci_cmd_t hci_read_local_version_information = {
912     HCI_OPCODE_HCI_READ_LOCAL_VERSION_INFORMATION, ""
913 };
914 const hci_cmd_t hci_read_local_supported_commands = {
915     HCI_OPCODE_HCI_READ_LOCAL_SUPPORTED_COMMANDS, ""
916 };
917 const hci_cmd_t hci_read_local_supported_features = {
918     HCI_OPCODE_HCI_READ_LOCAL_SUPPORTED_FEATURES, ""
919 };
920 const hci_cmd_t hci_read_buffer_size = {
921     HCI_OPCODE_HCI_READ_BUFFER_SIZE, ""
922 };
923 const hci_cmd_t hci_read_bd_addr = {
924     HCI_OPCODE_HCI_READ_BD_ADDR, ""
925 };
926 
927 /**
928  * Status Paramters
929  */
930 
931 /**
932  * @param handle
933  */
934 const hci_cmd_t hci_read_rssi = {
935     HCI_OPCODE_HCI_READ_RSSI, "H"
936 };
937 
938 /**
939  * @param handle
940  */
941 const hci_cmd_t hci_read_encryption_key_size = {
942     HCI_OPCODE_HCI_READ_ENCRYPTION_KEY_SIZE, "H"
943 };
944 
945 
946 #ifdef ENABLE_BLE
947 /**
948  * Low Energy Commands
949  */
950 
951 /**
952  * @param event_mask_lower_octets
953  * @param event_mask_higher_octets
954  */
955 const hci_cmd_t hci_le_set_event_mask = {
956     HCI_OPCODE_HCI_LE_SET_EVENT_MASK, "44"
957     // return: status
958 };
959 
960 const hci_cmd_t hci_le_read_buffer_size = {
961     HCI_OPCODE_HCI_LE_READ_BUFFER_SIZE, ""
962     // return: status, le acl data packet len (16), total num le acl data packets(8)
963 };
964 const hci_cmd_t hci_le_read_supported_features = {
965     HCI_OPCODE_HCI_LE_READ_SUPPORTED_FEATURES, ""
966     // return: LE_Features See [Vol 6] Part B, Section 4.6
967 };
968 
969 /**
970  * @param random_bd_addr
971  */
972 const hci_cmd_t hci_le_set_random_address = {
973     HCI_OPCODE_HCI_LE_SET_RANDOM_ADDRESS, "B"
974     // return: status
975 };
976 
977 /**
978  * @param advertising_interval_min ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec)
979  * @param advertising_interval_max ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec)
980  * @param advertising_type (enum from 0: ADV_IND, ADC_DIRECT_IND, ADV_SCAN_IND, ADV_NONCONN_IND)
981  * @param own_address_type (enum from 0: public device address, random device address)
982  * @param direct_address_type ()
983  * @param direct_address (public or random address of device to be connecteed)
984  * @param advertising_channel_map (flags: chan_37(1), chan_38(2), chan_39(4))
985  * @param advertising_filter_policy (enum from 0: scan any conn any, scan whitelist, con any, scan any conn whitelist, scan whitelist, con whitelist)
986  */
987 const hci_cmd_t hci_le_set_advertising_parameters = {
988     HCI_OPCODE_HCI_LE_SET_ADVERTISING_PARAMETERS, "22111B11"
989     // return: status
990 };
991 
992 const hci_cmd_t hci_le_read_advertising_channel_tx_power = {
993     HCI_OPCODE_HCI_LE_READ_ADVERTISING_CHANNEL_TX_POWER, ""
994     // return: status, level [-20,10] signed int (8), units dBm
995 };
996 
997 /**
998  * @param advertising_data_length
999  * @param advertising_data (31 bytes)
1000  */
1001 const hci_cmd_t hci_le_set_advertising_data= {
1002     HCI_OPCODE_HCI_LE_SET_ADVERTISING_DATA, "1A"
1003     // return: status
1004 };
1005 
1006 /**
1007  * @param scan_response_data_length
1008  * @param scan_response_data (31 bytes)
1009  */
1010 const hci_cmd_t hci_le_set_scan_response_data= {
1011     HCI_OPCODE_HCI_LE_SET_SCAN_RESPONSE_DATA, "1A"
1012     // return: status
1013 };
1014 
1015 /**
1016  * @param advertise_enable (off: 0, on: 1)
1017  */
1018 const hci_cmd_t hci_le_set_advertise_enable = {
1019     HCI_OPCODE_HCI_LE_SET_ADVERTISE_ENABLE, "1"
1020     // return: status
1021 };
1022 
1023 /**
1024  * @param le_scan_type (passive (0), active (1))
1025  * @param le_scan_interval ([0x0004,0x4000], unit: 0.625 msec)
1026  * @param le_scan_window   ([0x0004,0x4000], unit: 0.625 msec)
1027  * @param own_address_type (public (0), random (1))
1028  * @param scanning_filter_policy (any (0), only whitelist (1))
1029  */
1030 const hci_cmd_t hci_le_set_scan_parameters = {
1031     HCI_OPCODE_HCI_LE_SET_SCAN_PARAMETERS, "12211"
1032     // return: status
1033 };
1034 
1035 /**
1036  * @param le_scan_enable  (disabled (0), enabled (1))
1037  * @param filter_duplices (disabled (0), enabled (1))
1038  */
1039 const hci_cmd_t hci_le_set_scan_enable = {
1040     HCI_OPCODE_HCI_LE_SET_SCAN_ENABLE, "11"
1041     // return: status
1042 };
1043 
1044 /**
1045  * @param le_scan_interval ([0x0004, 0x4000], unit: 0.625 msec)
1046  * @param le_scan_window ([0x0004, 0x4000], unit: 0.625 msec)
1047  * @param initiator_filter_policy (peer address type + peer address (0), whitelist (1))
1048  * @param peer_address_type (public (0), random (1))
1049  * @param peer_address
1050  * @param own_address_type (public (0), random (1))
1051  * @param conn_interval_min ([0x0006, 0x0c80], unit: 1.25 msec)
1052  * @param conn_interval_max ([0x0006, 0x0c80], unit: 1.25 msec)
1053  * @param conn_latency (number of connection events [0x0000, 0x01f4])
1054  * @param supervision_timeout ([0x000a, 0x0c80], unit: 10 msec)
1055  * @param minimum_CE_length ([0x0000, 0xffff], unit: 0.625 msec)
1056  * @param maximum_CE_length ([0x0000, 0xffff], unit: 0.625 msec)
1057  */
1058 const hci_cmd_t hci_le_create_connection= {
1059     HCI_OPCODE_HCI_LE_CREATE_CONNECTION, "2211B1222222"
1060     // return: none -> le create connection complete event
1061 };
1062 
1063 const hci_cmd_t hci_le_create_connection_cancel = {
1064     HCI_OPCODE_HCI_LE_CREATE_CONNECTION_CANCEL, ""
1065     // return: status
1066 };
1067 
1068 const hci_cmd_t hci_le_read_white_list_size = {
1069     HCI_OPCODE_HCI_LE_READ_WHITE_LIST_SIZE, ""
1070     // return: status, number of entries in controller whitelist
1071 };
1072 
1073 const hci_cmd_t hci_le_clear_white_list = {
1074     HCI_OPCODE_HCI_LE_CLEAR_WHITE_LIST, ""
1075     // return: status
1076 };
1077 
1078 /**
1079  * @param address_type (public (0), random (1))
1080  * @param bd_addr
1081  */
1082 const hci_cmd_t hci_le_add_device_to_white_list = {
1083     HCI_OPCODE_HCI_LE_ADD_DEVICE_TO_WHITE_LIST, "1B"
1084     // return: status
1085 };
1086 
1087 /**
1088  * @param address_type (public (0), random (1))
1089  * @param bd_addr
1090  */
1091 const hci_cmd_t hci_le_remove_device_from_white_list = {
1092     HCI_OPCODE_HCI_LE_REMOVE_DEVICE_FROM_WHITE_LIST, "1B"
1093     // return: status
1094 };
1095 
1096 /**
1097  * @param conn_handle
1098  * @param conn_interval_min ([0x0006,0x0c80], unit: 1.25 msec)
1099  * @param conn_interval_max ([0x0006,0x0c80], unit: 1.25 msec)
1100  * @param conn_latency ([0x0000,0x03e8], number of connection events)
1101  * @param supervision_timeout ([0x000a,0x0c80], unit: 10 msec)
1102  * @param minimum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
1103  * @param maximum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
1104  */
1105 const hci_cmd_t hci_le_connection_update = {
1106     HCI_OPCODE_HCI_LE_CONNECTION_UPDATE, "H222222"
1107     // return: none -> le connection update complete event
1108 };
1109 
1110 /**
1111  * @param channel_map_lower_32bits
1112  * @param channel_map_higher_5bits
1113  */
1114 const hci_cmd_t hci_le_set_host_channel_classification = {
1115     HCI_OPCODE_HCI_LE_SET_HOST_CHANNEL_CLASSIFICATION, "41"
1116     // return: status
1117 };
1118 
1119 /**
1120  * @param conn_handle
1121  */
1122 const hci_cmd_t hci_le_read_channel_map = {
1123     HCI_OPCODE_HCI_LE_READ_CHANNEL_MAP, "H"
1124     // return: status, connection handle, channel map (5 bytes, 37 used)
1125 };
1126 
1127 /**
1128  * @param conn_handle
1129  */
1130 const hci_cmd_t hci_le_read_remote_used_features = {
1131     HCI_OPCODE_HCI_LE_READ_REMOTE_USED_FEATURES, "H"
1132     // return: none -> le read remote used features complete event
1133 };
1134 
1135 /**
1136  * @param key ((128) for AES-128)
1137  * @param plain_text (128)
1138  */
1139 const hci_cmd_t hci_le_encrypt = {
1140     HCI_OPCODE_HCI_LE_ENCRYPT, "PP"
1141     // return: status, encrypted data (128)
1142 };
1143 
1144 const hci_cmd_t hci_le_rand = {
1145     HCI_OPCODE_HCI_LE_RAND, ""
1146     // return: status, random number (64)
1147 };
1148 
1149 /**
1150  * @param conn_handle
1151  * @param random_number_lower_32bits
1152  * @param random_number_higher_32bits
1153  * @param encryption_diversifier (16)
1154  * @param long_term_key (128)
1155  */
1156 const hci_cmd_t hci_le_start_encryption = {
1157     HCI_OPCODE_HCI_LE_START_ENCRYPTION, "H442P"
1158     // return: none -> encryption changed or encryption key refresh complete event
1159 };
1160 
1161 /**
1162  * @param connection_handle
1163  * @param long_term_key (128)
1164  */
1165 const hci_cmd_t hci_le_long_term_key_request_reply = {
1166     HCI_OPCODE_HCI_LE_LONG_TERM_KEY_REQUEST_REPLY, "HP"
1167     // return: status, connection handle
1168 };
1169 
1170 /**
1171  * @param conn_handle
1172  */
1173 const hci_cmd_t hci_le_long_term_key_negative_reply = {
1174     HCI_OPCODE_HCI_LE_LONG_TERM_KEY_NEGATIVE_REPLY, "H"
1175     // return: status, connection handle
1176 };
1177 
1178 /**
1179  * @param conn_handle
1180  */
1181 const hci_cmd_t hci_le_read_supported_states = {
1182     HCI_OPCODE_HCI_LE_READ_SUPPORTED_STATES, "H"
1183     // return: status, LE states (64)
1184 };
1185 
1186 /**
1187  * @param rx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2)
1188  */
1189 const hci_cmd_t hci_le_receiver_test = {
1190     HCI_OPCODE_HCI_LE_RECEIVER_TEST, "1"
1191     // return: status
1192 };
1193 
1194 /**
1195  * @param tx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2)
1196  * @param test_payload_lengh ([0x00,0x25])
1197  * @param packet_payload ([0,7] different patterns)
1198  */
1199 const hci_cmd_t hci_le_transmitter_test = {
1200     HCI_OPCODE_HCI_LE_TRANSMITTER_TEST, "111"
1201     // return: status
1202 };
1203 
1204 /**
1205  * @param end_test_cmd
1206  */
1207 const hci_cmd_t hci_le_test_end = {
1208     HCI_OPCODE_HCI_LE_TEST_END, "1"
1209     // return: status, number of packets (8)
1210 };
1211 
1212 /**
1213  * @param conn_handle
1214  * @param conn_interval_min ([0x0006,0x0c80], unit: 1.25 msec)
1215  * @param conn_interval_max ([0x0006,0x0c80], unit: 1.25 msec)
1216  * @param conn_latency ([0x0000,0x03e8], number of connection events)
1217  * @param supervision_timeout ([0x000a,0x0c80], unit: 10 msec)
1218  * @param minimum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
1219  * @param maximum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
1220  */
1221 const hci_cmd_t hci_le_remote_connection_parameter_request_reply = {
1222     HCI_OPCODE_HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, "H222222"
1223     // return: status, connection handle
1224 };
1225 
1226 /**
1227  * @param con_handle
1228  * @param reason
1229  */
1230 const hci_cmd_t hci_le_remote_connection_parameter_request_negative_reply = {
1231     HCI_OPCODE_HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, "H1"
1232     // return: status, connection handle
1233 };
1234 
1235 /**
1236  * @param con_handle
1237  * @param tx_octets
1238  * @param tx_time
1239  */
1240 const hci_cmd_t hci_le_set_data_length = {
1241     HCI_OPCODE_HCI_LE_SET_DATA_LENGTH, "H22"
1242     // return: status, connection handle
1243 };
1244 
1245 /**
1246  */
1247 const hci_cmd_t hci_le_read_suggested_default_data_length = {
1248     HCI_OPCODE_HCI_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, ""
1249     // return: status, suggested max tx octets, suggested max tx time
1250 };
1251 
1252 /**
1253  * @param suggested_max_tx_octets
1254  * @param suggested_max_tx_time
1255  */
1256 const hci_cmd_t hci_le_write_suggested_default_data_length = {
1257     HCI_OPCODE_HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, "22"
1258     // return: status
1259 };
1260 
1261 /**
1262  */
1263 const hci_cmd_t hci_le_read_local_p256_public_key = {
1264     HCI_OPCODE_HCI_LE_READ_LOCAL_P256_PUBLIC_KEY, ""
1265 //  LE Read Local P-256 Public Key Complete is generated on completion
1266 };
1267 
1268 /**
1269  * @param public key
1270  * @param private key
1271  */
1272 const hci_cmd_t hci_le_generate_dhkey = {
1273     HCI_OPCODE_HCI_LE_GENERATE_DHKEY, "QQ"
1274 // LE Generate DHKey Complete is generated on completion
1275 };
1276 
1277 /**
1278  * @param Peer_Identity_Address_Type
1279  * @param Peer_Identity_Address
1280  * @param Peer_IRK
1281  * @param Local_IRK
1282  */
1283 const hci_cmd_t hci_le_add_device_to_resolving_list = {
1284         HCI_OPCODE_HCI_LE_ADD_DEVICE_TO_RESOLVING_LIST, "1BPP"
1285 };
1286 
1287 /**
1288  * @param Peer_Identity_Address_Type
1289  * @param Peer_Identity_Address
1290  */
1291 const hci_cmd_t hci_le_remove_device_from_resolving_list = {
1292         HCI_OPCODE_HCI_LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, "1B"
1293 };
1294 
1295 /**
1296  */
1297 const hci_cmd_t hci_le_clear_resolving_list = {
1298         HCI_OPCODE_HCI_LE_CLEAR_RESOLVING_LIST, ""
1299 };
1300 
1301 /**
1302  */
1303 const hci_cmd_t hci_le_read_resolving_list_size = {
1304         HCI_OPCODE_HCI_LE_READ_RESOLVING_LIST_SIZE, ""
1305 };
1306 
1307 /**
1308  * @param Peer_Identity_Address_Type
1309  * @param Peer_Identity_Address
1310  */
1311 const hci_cmd_t hci_le_read_peer_resolvable_address = {
1312         HCI_OPCODE_HCI_LE_READ_PEER_RESOLVABLE_ADDRESS, ""
1313 };
1314 
1315 /**
1316  * @param Peer_Identity_Address_Type
1317  * @param Peer_Identity_Address
1318  */
1319 const hci_cmd_t hci_le_read_local_resolvable_address = {
1320         HCI_OPCODE_HCI_LE_READ_LOCAL_RESOLVABLE_ADDRESS, ""
1321 };
1322 
1323 /**
1324  * @param Address_Resolution_Enable
1325  */
1326 const hci_cmd_t hci_le_set_address_resolution_enabled= {
1327         HCI_OPCODE_HCI_LE_SET_ADDRESS_RESOLUTION_ENABLED, "1"
1328 };
1329 
1330 /**
1331  * @param RPA_Timeout in seconds, range 0x0001 to 0x0E10, default: 900 s
1332  */
1333 const hci_cmd_t hci_le_set_resolvable_private_address_timeout= {
1334         HCI_OPCODE_HCI_LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, "2"
1335 };
1336 
1337 /**
1338  */
1339 const hci_cmd_t hci_le_read_maximum_data_length = {
1340     HCI_OPCODE_HCI_LE_READ_MAXIMUM_DATA_LENGTH, ""
1341     // return: status, supported max tx octets, supported max tx time, supported max rx octets, supported max rx time
1342 };
1343 
1344 /**
1345  * @param con_handle
1346  */
1347 const hci_cmd_t hci_le_read_phy = {
1348     HCI_OPCODE_HCI_LE_READ_PHY, "H"
1349     // return: status, connection handler, tx phy, rx phy
1350 };
1351 
1352 /**
1353  * @param all_phys
1354  * @param tx_phys
1355  * @param rx_phys
1356  */
1357 const hci_cmd_t hci_le_set_default_phy = {
1358     HCI_OPCODE_HCI_LE_SET_DEFAULT_PHY, "111"
1359     // return: status
1360 };
1361 
1362 /**
1363  * @param con_handle
1364  * @param all_phys
1365  * @param tx_phys
1366  * @param rx_phys
1367  * @param phy_options
1368  */
1369 const hci_cmd_t hci_le_set_phy = {
1370     HCI_OPCODE_HCI_LE_SET_PHY, "H1111"
1371 // LE PHY Update Complete is generated on completion
1372 };
1373 
1374 
1375 #endif
1376 
1377 // Broadcom / Cypress specific HCI commands
1378 
1379 /**
1380  * @brief Enable Wide-Band Speech / mSBC decoding for PCM
1381  * @param enable_wbs is 0 for disable, 1 for enable
1382  * @param uuid_wbs is 2 for EV2/EV3
1383  */
1384 const hci_cmd_t hci_bcm_enable_wbs = {
1385         HCI_OPCODE_HCI_BCM_ENABLE_WBS, "12"
1386         // return: status
1387 };
1388 
1389 /**
1390  * @brief Configure SCO Routing (BCM)
1391  * @param sco_routing is 0 for PCM, 1 for Transport, 2 for Codec and 3 for I2S
1392  * @param pcm_interface_rate is 0 for 128KBps, 1 for 256 KBps, 2 for 512KBps, 3 for 1024KBps, and 4 for 2048Kbps
1393  * @param frame_type is 0 for short and 1 for long
1394  * @param sync_mode is 0 for slave and 1 for master
1395  * @param clock_mode is 0 for slabe and 1 for master
1396  */
1397 const hci_cmd_t hci_bcm_write_sco_pcm_int = {
1398     HCI_OPCODE_HCI_BCM_WRITE_SCO_PCM_INT, "11111"
1399     // return: status
1400 };
1401 
1402 /**
1403  * @brief Configure the I2S/PCM interface (BCM)
1404  * @param i2s_enable is 0 for off, 1 for on
1405  * @param is_master is 0 for slave, is 1 for master
1406  * @param sample_rate is 0 for 8 kHz, 1 for 16 kHz, 2 for 4 kHz
1407  * @param clock_rate is 0 for 128 kz, 1 for 256 kHz, 2 for 512 khz, 3 for 1024 kHz, 4 for 2048 khz
1408  * @param clock_mode is 0 for slabe and 1 for master
1409  */
1410 const hci_cmd_t hci_bcm_write_i2spcm_interface_param = {
1411         HCI_OPCODE_HCI_BCM_WRITE_I2SPCM_INTERFACE_PARAM, "1111"
1412         // return: status
1413 };
1414 
1415 
1416 /**
1417  * @brief Activates selected Sleep Mode
1418  * @param sleep_mode: 0=no sleep, 1=UART, 2=UART with Messaging, 3=USB, 4=H4IBSS, USB with Host Wake, 6=SDIO, 7=UART CS-N, 8=SPI, 9=H5, 10=H4DS, 12=UART with BREAK
1419  * @param idle_threshold_host (modes 1,2,5,7) time until considered idle, unit roughly 300 ms
1420  * @param idle_threshold_controller (modes 1-7,9) time until considered idle, unit roughly 300 ms
1421  * @param bt_wake_active_mode (modes 1,2,7) 0 = BT_WAKE line is active high, 1 = BT_WAKE is active low
1422  * @param host_wake_active_mode (modes 1,2,5,7) 0 = HOST_WAKE line is active high, 1 = HOST_WAKE is active low
1423  * @param allow_host_sleep_during_sco (modes 1,2,3,5,7)
1424  * @param combine_sleep_mode_and_lpm  (modes 1,2,3,5,7)
1425  * @param enable_tristate_control_of_uart_tx_line (modes 1,2,7)
1426  * @param active_connection_handling_on_suspend (modes 3,5)
1427  * @param resume_timeout (modes 3,5)
1428  * @param enable_break_to_host (mode 12)
1429  * @param pulsed_host_wake (modes 1,12)
1430  */
1431 const hci_cmd_t hci_bcm_set_sleep_mode = {
1432     HCI_OPCODE_HCI_BCM_SET_SLEEP_MODE, "111111111111"
1433 };
1434 
1435 /**
1436  * @brief Set TX Power Table
1437  * @param is_le 0=classic, 1=LE
1438  * @param chip_max_tx_pwr_db chip level max TX power in dBM
1439  */
1440 const hci_cmd_t hci_bcm_write_tx_power_table = {
1441     HCI_OPCODE_HCI_BCM_WRITE_TX_POWER_TABLE, "11"
1442 };
1443 
1444 const hci_cmd_t hci_bcm_set_tx_pwr = {
1445     HCI_OPCODE_HCI_BCM_SET_TX_PWR, "11H"
1446 };
1447 
1448 /**
1449  *
1450  *
1451  * @brief This command tests the RF transceiver in continuous transmission mode.
1452  *        The transmitter is activated by configuring the transmission parameters such as pattern,
1453  *        modulation, and frequency.
1454  * @see   processors.wiki.ti.com/index.php/CC256x_VS_HCI_Commands#HCI_VS_DRPb_Tester_Con_TX.280xFD84.29
1455  * @param modulation
1456  * @param test_patern
1457  * @param frequency
1458  * @param power_level
1459  * @param reserved1
1460  * @param reserved2
1461  */
1462 const hci_cmd_t hci_ti_drpb_tester_con_tx = {
1463     0xFD84, "111144"
1464 };
1465 
1466 /**
1467  * @brief This command starts sending/receiving packets using packet transmission parameters such as
1468  *        frequency channel, packet type, and packet length. It is used for Packet TX/RX.
1469  * @see   processors.wiki.ti.com/index.php/CC256x_VS_HCI_Commands#HCI_VS_DRPb_Tester_Packet_TX_RX_.280xFD85.29
1470  * @param frequency_mode
1471  * @param tx_single_frequency
1472  * @param rx_single_frequency
1473  * @param acl_packet_type
1474  * @paarm acl_packet_data_pattern
1475  * @param reserved
1476  * @param power_level
1477  * @param disable_whitening
1478  * @param prbs9_initialization_value
1479  */
1480 const hci_cmd_t hci_ti_drpb_tester_packet_tx_rx = {
1481     0xFD85, "1111112112"
1482 };
1483 
1484 /**
1485  * @brief This command is used to associate the requested ACL handle with Wide Band Speech configuration.
1486  * @param enable 0=disable, 1=enable
1487  * @param a3dp_role (NL5500, WL128x only) 0=source,1=sink
1488  * @param code_upload (NL5500, WL128x only) 0=do not load a3dp code, 1=load a3dp code
1489  * @param reserved for future use
1490  */
1491 const hci_cmd_t hci_ti_avrp_enable = {
1492         0xFD92, "1112"
1493 };
1494 
1495 /**
1496  * @brief This command is used to associate the requested ACL handle with Wide Band Speech configuration.
1497  * @param acl_con_handle
1498  */
1499 const hci_cmd_t hci_ti_wbs_associate = {
1500         0xFD78, "H"
1501 };
1502 
1503 /**
1504  * @brief This command is used to disassociate Wide Band Speech configuration from any ACL handle.
1505  */
1506 const hci_cmd_t hci_ti_wbs_disassociate = {
1507         0xFD79, ""
1508 };
1509 
1510 /**
1511  * @brief This command configures the codec interface parameters and the PCM clock rate, which is relevant when
1512           the Bluetooth core generates the clock. This command must be used by the host to use the PCM
1513           interface.
1514  * @param clock_rate in kHz
1515  * @param clock_direction 0=master/output, 1=slave/input
1516  * @param frame_sync_frequency in Hz
1517  * @param frame_sync_duty_cycle 0=50% (I2S Format), 0x0001-0xffff number of cycles of PCM clock
1518  * @param frame_sync_edge 0=driven/sampled at rising edge, 1=driven/sampled at falling edge of PCM clock
1519  * @param frame_sync_polariy 0=active high, 1=active low
1520  * @param reserved1
1521  * @param channel_1_data_out_size sample size in bits
1522  * @param channel_1_data_out_offset number of PCM clock cycles between rising of frame sync and data start
1523  * @param channel_1_data_out_edge 0=data driven at rising edge, 1=data driven at falling edge of PCM clock
1524  * @param channel_1_data_in_size sample size in bits
1525  * @param channel_1_data_in_offset number of PCM clock cycles between rising of frame sync and data start
1526  * @param channel_1_data_in_edge 0=data sampled at rising edge, 1=data sampled at falling edge of PCM clock
1527  * @param fsync_multiplier this field is only relevant to CC256XB from service pack 0.2 !!! -> use 0x00
1528  * @param channel_2_data_out_size sample size in bits
1529  * @param channel_2_data_out_offset number of PCM clock cycles between rising of frame sync and data start
1530  * @param channel_2_data_out_edge 0=data driven at rising edge, 1=data driven at falling edge of PCM clock
1531  * @param channel_2_data_in_size sample size in bits
1532  * @param channel_2_data_in_offset number of PCM clock cycles between rising of frame sync and data start
1533  * @param channel_2_data_in_edge 0=data sampled at rising edge, 1=data sampled at falling edge of PCM clock
1534  * @param reserved2
1535  *
1536  */
1537 const hci_cmd_t hci_ti_write_codec_config = {
1538         0xFD06, "214211122122112212211"
1539 };
1540