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