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