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