xref: /btstack/src/hci_cmd.c (revision 25234a7e05f3e69524e0ba3eec834a229a86d91b)
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 handle
559  */
560 const hci_cmd_t hci_flush = {
561 OPCODE(OGF_CONTROLLER_BASEBAND, 0x09), "H"
562 };
563 
564 /**
565  * @param bd_addr
566  * @param delete_all_flags
567  */
568 const hci_cmd_t hci_delete_stored_link_key = {
569 OPCODE(OGF_CONTROLLER_BASEBAND, 0x12), "B1"
570 };
571 
572 /**
573  * @param local_name (UTF-8, Null Terminated, max 248 octets)
574  */
575 const hci_cmd_t hci_write_local_name = {
576 OPCODE(OGF_CONTROLLER_BASEBAND, 0x13), "N"
577 };
578 
579 /**
580  */
581 const hci_cmd_t hci_read_local_name = {
582 OPCODE(OGF_CONTROLLER_BASEBAND, 0x14), ""
583 };
584 
585 /**
586  * @param page_timeout (* 0.625 ms)
587  */
588 const hci_cmd_t hci_write_page_timeout = {
589 OPCODE(OGF_CONTROLLER_BASEBAND, 0x18), "2"
590 };
591 
592 /**
593  * @param scan_enable (no, inq, page, inq+page)
594  */
595 const hci_cmd_t hci_write_scan_enable = {
596 OPCODE(OGF_CONTROLLER_BASEBAND, 0x1A), "1"
597 };
598 
599 /**
600  * @param authentication_enable
601  */
602 const hci_cmd_t hci_write_authentication_enable = {
603 OPCODE(OGF_CONTROLLER_BASEBAND, 0x20), "1"
604 };
605 
606 /**
607  * @param class_of_device
608  */
609 const hci_cmd_t hci_write_class_of_device = {
610 OPCODE(OGF_CONTROLLER_BASEBAND, 0x24), "3"
611 };
612 
613 /**
614  */
615 const hci_cmd_t hci_read_num_broadcast_retransmissions = {
616 OPCODE(OGF_CONTROLLER_BASEBAND, 0x29), ""
617 };
618 
619 /**
620  * @param num_broadcast_retransmissions (e.g. 0 for a single broadcast)
621  */
622 const hci_cmd_t hci_write_num_broadcast_retransmissions = {
623 OPCODE(OGF_CONTROLLER_BASEBAND, 0x2a), "1"
624 };
625 
626 /**
627  * @param synchronous_flow_control_enable - if yes, num completed packet everts are sent for SCO packets
628  */
629 const hci_cmd_t hci_write_synchronous_flow_control_enable = {
630 OPCODE(OGF_CONTROLLER_BASEBAND, 0x2f), "1"
631 };
632 
633 /**
634  * @param host_acl_data_packet_length
635  * @param host_synchronous_data_packet_length
636  * @param host_total_num_acl_data_packets
637  * @param host_total_num_synchronous_data_packets
638  */
639 const hci_cmd_t hci_host_buffer_size = {
640 OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122"
641 };
642 
643 /**
644  * @param handle
645  */
646 const hci_cmd_t hci_read_link_supervision_timeout = {
647 OPCODE(OGF_CONTROLLER_BASEBAND, 0x36), "H"
648 };
649 
650 /**
651  * @param handle
652  * @param timeout (0x0001 - 0xFFFF Time -> Range: 0.625ms - 40.9 sec)
653  */
654 const hci_cmd_t hci_write_link_supervision_timeout = {
655 OPCODE(OGF_CONTROLLER_BASEBAND, 0x37), "H2"
656 };
657 
658 /**
659  * @param inquiry_mode (0x00 = standard, 0x01 = with RSSI, 0x02 = extended)
660  */
661 const hci_cmd_t hci_write_inquiry_mode = {
662 OPCODE(OGF_CONTROLLER_BASEBAND, 0x45), "1"
663 };
664 
665 /**
666  * @param fec_required
667  * @param exstended_inquiry_response
668  */
669 const hci_cmd_t hci_write_extended_inquiry_response = {
670 OPCODE(OGF_CONTROLLER_BASEBAND, 0x52), "1E"
671 };
672 
673 /**
674  * @param mode (0 = off, 1 = on)
675  */
676 const hci_cmd_t hci_write_simple_pairing_mode = {
677 OPCODE(OGF_CONTROLLER_BASEBAND, 0x56), "1"
678 };
679 
680 
681 /**
682  * @param mode (0 = off, 1 = on)
683  */
684 const hci_cmd_t hci_write_default_erroneous_data_reporting = {
685 OPCODE(OGF_CONTROLLER_BASEBAND, 0x5B), "1"
686 };
687 
688 /**
689  */
690 const hci_cmd_t hci_read_le_host_supported = {
691 OPCODE(OGF_CONTROLLER_BASEBAND, 0x6c), ""
692 // return: status, le supported host, simultaneous le host
693 };
694 
695 /**
696  * @param le_supported_host
697  * @param simultaneous_le_host
698  */
699 const hci_cmd_t hci_write_le_host_supported = {
700 OPCODE(OGF_CONTROLLER_BASEBAND, 0x6d), "11"
701 // return: status
702 };
703 
704 /**
705  * Testing Commands
706  */
707 
708 
709 /**
710  */
711 const hci_cmd_t hci_read_loopback_mode = {
712 OPCODE(OGF_TESTING, 0x01), ""
713 // return: status, loopback mode (0 = off, 1 = local loopback, 2 = remote loopback)
714 };
715 
716 /**
717  * @param loopback_mode
718  */
719 const hci_cmd_t hci_write_loopback_mode = {
720 OPCODE(OGF_TESTING, 0x02), "1"
721 // return: status
722 };
723 
724 
725 /**
726  * Informational Parameters
727  */
728 
729 const hci_cmd_t hci_read_local_version_information = {
730 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x01), ""
731 };
732 const hci_cmd_t hci_read_local_supported_commands = {
733 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x02), ""
734 };
735 const hci_cmd_t hci_read_local_supported_features = {
736 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x03), ""
737 };
738 const hci_cmd_t hci_read_buffer_size = {
739 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x05), ""
740 };
741 const hci_cmd_t hci_read_bd_addr = {
742 OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), ""
743 };
744 
745 /**
746  * Status Paramters
747  */
748 
749 /**
750  * @param handle
751  */
752 const hci_cmd_t hci_read_rssi = {
753 OPCODE(OGF_STATUS_PARAMETERS, 0x05), "H"
754 // no params
755 };
756 
757 
758 
759 #ifdef ENABLE_BLE
760 /**
761  * Low Energy Commands
762  */
763 
764 /**
765  * @param event_mask_lower_octets
766  * @param event_mask_higher_octets
767  */
768 const hci_cmd_t hci_le_set_event_mask = {
769 OPCODE(OGF_LE_CONTROLLER, 0x01), "44"
770 // return: status
771 };
772 
773 const hci_cmd_t hci_le_read_buffer_size = {
774 OPCODE(OGF_LE_CONTROLLER, 0x02), ""
775 // return: status, le acl data packet len (16), total num le acl data packets(8)
776 };
777 const hci_cmd_t hci_le_read_supported_features = {
778 OPCODE(OGF_LE_CONTROLLER, 0x03), ""
779 // return: LE_Features See [Vol 6] Part B, Section 4.6
780 };
781 
782 /**
783  * @param random_bd_addr
784  */
785 const hci_cmd_t hci_le_set_random_address = {
786 OPCODE(OGF_LE_CONTROLLER, 0x05), "B"
787 // return: status
788 };
789 
790 /**
791  * @param advertising_interval_min ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec)
792  * @param advertising_interval_max ([0x0020,0x4000], default: 0x0800, unit: 0.625 msec)
793  * @param advertising_type (enum from 0: ADV_IND, ADC_DIRECT_IND, ADV_SCAN_IND, ADV_NONCONN_IND)
794  * @param own_address_type (enum from 0: public device address, random device address)
795  * @param direct_address_type ()
796  * @param direct_address (public or random address of device to be connecteed)
797  * @param advertising_channel_map (flags: chan_37(1), chan_38(2), chan_39(4))
798  * @param advertising_filter_policy (enum from 0: scan any conn any, scan whitelist, con any, scan any conn whitelist, scan whitelist, con whitelist)
799  */
800 const hci_cmd_t hci_le_set_advertising_parameters = {
801 OPCODE(OGF_LE_CONTROLLER, 0x06), "22111B11"
802 // return: status
803 };
804 
805 const hci_cmd_t hci_le_read_advertising_channel_tx_power = {
806 OPCODE(OGF_LE_CONTROLLER, 0x07), ""
807 // return: status, level [-20,10] signed int (8), units dBm
808 };
809 
810 /**
811  * @param advertising_data_length
812  * @param advertising_data (31 bytes)
813  */
814 const hci_cmd_t hci_le_set_advertising_data= {
815 OPCODE(OGF_LE_CONTROLLER, 0x08), "1A"
816 // return: status
817 };
818 
819 /**
820  * @param scan_response_data_length
821  * @param scan_response_data (31 bytes)
822  */
823 const hci_cmd_t hci_le_set_scan_response_data= {
824 OPCODE(OGF_LE_CONTROLLER, 0x09), "1A"
825 // return: status
826 };
827 
828 /**
829  * @param advertise_enable (off: 0, on: 1)
830  */
831 const hci_cmd_t hci_le_set_advertise_enable = {
832 OPCODE(OGF_LE_CONTROLLER, 0x0a), "1"
833 // return: status
834 };
835 
836 /**
837  * @param le_scan_type (passive (0), active (1))
838  * @param le_scan_interval ([0x0004,0x4000], unit: 0.625 msec)
839  * @param le_scan_window   ([0x0004,0x4000], unit: 0.625 msec)
840  * @param own_address_type (public (0), random (1))
841  * @param scanning_filter_policy (any (0), only whitelist (1))
842  */
843 const hci_cmd_t hci_le_set_scan_parameters = {
844 OPCODE(OGF_LE_CONTROLLER, 0x0b), "12211"
845 // return: status
846 };
847 
848 /**
849  * @param le_scan_enable  (disabled (0), enabled (1))
850  * @param filter_duplices (disabled (0), enabled (1))
851  */
852 const hci_cmd_t hci_le_set_scan_enable = {
853 OPCODE(OGF_LE_CONTROLLER, 0x0c), "11"
854 // return: status
855 };
856 
857 /**
858  * @param le_scan_interval ([0x0004, 0x4000], unit: 0.625 msec)
859  * @param le_scan_window ([0x0004, 0x4000], unit: 0.625 msec)
860  * @param initiator_filter_policy (peer address type + peer address (0), whitelist (1))
861  * @param peer_address_type (public (0), random (1))
862  * @param peer_address
863  * @param own_address_type (public (0), random (1))
864  * @param conn_interval_min ([0x0006, 0x0c80], unit: 1.25 msec)
865  * @param conn_interval_max ([0x0006, 0x0c80], unit: 1.25 msec)
866  * @param conn_latency (number of connection events [0x0000, 0x01f4])
867  * @param supervision_timeout ([0x000a, 0x0c80], unit: 10 msec)
868  * @param minimum_CE_length ([0x0000, 0xffff], unit: 0.625 msec)
869  * @param maximum_CE_length ([0x0000, 0xffff], unit: 0.625 msec)
870  */
871 const hci_cmd_t hci_le_create_connection= {
872 OPCODE(OGF_LE_CONTROLLER, 0x0d), "2211B1222222"
873 // return: none -> le create connection complete event
874 };
875 
876 const hci_cmd_t hci_le_create_connection_cancel = {
877 OPCODE(OGF_LE_CONTROLLER, 0x0e), ""
878 // return: status
879 };
880 
881 const hci_cmd_t hci_le_read_white_list_size = {
882 OPCODE(OGF_LE_CONTROLLER, 0x0f), ""
883 // return: status, number of entries in controller whitelist
884 };
885 
886 const hci_cmd_t hci_le_clear_white_list = {
887 OPCODE(OGF_LE_CONTROLLER, 0x10), ""
888 // return: status
889 };
890 
891 /**
892  * @param address_type (public (0), random (1))
893  * @param bd_addr
894  */
895 const hci_cmd_t hci_le_add_device_to_white_list = {
896 OPCODE(OGF_LE_CONTROLLER, 0x11), "1B"
897 // return: status
898 };
899 
900 /**
901  * @param address_type (public (0), random (1))
902  * @param bd_addr
903  */
904 const hci_cmd_t hci_le_remove_device_from_white_list = {
905 OPCODE(OGF_LE_CONTROLLER, 0x12), "1B"
906 // return: status
907 };
908 
909 /**
910  * @param conn_handle
911  * @param conn_interval_min ([0x0006,0x0c80], unit: 1.25 msec)
912  * @param conn_interval_max ([0x0006,0x0c80], unit: 1.25 msec)
913  * @param conn_latency ([0x0000,0x03e8], number of connection events)
914  * @param supervision_timeout ([0x000a,0x0c80], unit: 10 msec)
915  * @param minimum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
916  * @param maximum_CE_length ([0x0000,0xffff], unit: 0.625 msec)
917  */
918 const hci_cmd_t hci_le_connection_update = {
919 OPCODE(OGF_LE_CONTROLLER, 0x13), "H222222"
920 // return: none -> le connection update complete event
921 };
922 
923 /**
924  * @param channel_map_lower_32bits
925  * @param channel_map_higher_5bits
926  */
927 const hci_cmd_t hci_le_set_host_channel_classification = {
928 OPCODE(OGF_LE_CONTROLLER, 0x14), "41"
929 // return: status
930 };
931 
932 /**
933  * @param conn_handle
934  */
935 const hci_cmd_t hci_le_read_channel_map = {
936 OPCODE(OGF_LE_CONTROLLER, 0x15), "H"
937 // return: status, connection handle, channel map (5 bytes, 37 used)
938 };
939 
940 /**
941  * @param conn_handle
942  */
943 const hci_cmd_t hci_le_read_remote_used_features = {
944 OPCODE(OGF_LE_CONTROLLER, 0x16), "H"
945 // return: none -> le read remote used features complete event
946 };
947 
948 /**
949  * @param key ((128) for AES-128)
950  * @param plain_text (128)
951  */
952 const hci_cmd_t hci_le_encrypt = {
953 OPCODE(OGF_LE_CONTROLLER, 0x17), "PP"
954 // return: status, encrypted data (128)
955 };
956 
957 const hci_cmd_t hci_le_rand = {
958 OPCODE(OGF_LE_CONTROLLER, 0x18), ""
959 // return: status, random number (64)
960 };
961 
962 /**
963  * @param conn_handle
964  * @param random_number_lower_32bits
965  * @param random_number_higher_32bits
966  * @param encryption_diversifier (16)
967  * @param long_term_key (128)
968  */
969 const hci_cmd_t hci_le_start_encryption = {
970 OPCODE(OGF_LE_CONTROLLER, 0x19), "H442P"
971 // return: none -> encryption changed or encryption key refresh complete event
972 };
973 
974 /**
975  * @param connection_handle
976  * @param long_term_key (128)
977  */
978 const hci_cmd_t hci_le_long_term_key_request_reply = {
979 OPCODE(OGF_LE_CONTROLLER, 0x1a), "HP"
980 // return: status, connection handle
981 };
982 
983 /**
984  * @param conn_handle
985  */
986 const hci_cmd_t hci_le_long_term_key_negative_reply = {
987 OPCODE(OGF_LE_CONTROLLER, 0x1b), "H"
988 // return: status, connection handle
989 };
990 
991 /**
992  * @param conn_handle
993  */
994 const hci_cmd_t hci_le_read_supported_states = {
995 OPCODE(OGF_LE_CONTROLLER, 0x1c), "H"
996 // return: status, LE states (64)
997 };
998 
999 /**
1000  * @param rx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2)
1001  */
1002 const hci_cmd_t hci_le_receiver_test = {
1003 OPCODE(OGF_LE_CONTROLLER, 0x1d), "1"
1004 // return: status
1005 };
1006 
1007 /**
1008  * @param tx_frequency ([0x00 0x27], frequency (MHz): 2420 + N*2)
1009  * @param test_payload_lengh ([0x00,0x25])
1010  * @param packet_payload ([0,7] different patterns)
1011  */
1012 const hci_cmd_t hci_le_transmitter_test = {
1013 OPCODE(OGF_LE_CONTROLLER, 0x1e), "111"
1014 // return: status
1015 };
1016 
1017 /**
1018  * @param end_test_cmd
1019  */
1020 const hci_cmd_t hci_le_test_end = {
1021 OPCODE(OGF_LE_CONTROLLER, 0x1f), "1"
1022 // return: status, number of packets (8)
1023 };
1024 
1025 /**
1026  */
1027 const hci_cmd_t hci_le_read_local_p256_public_key = {
1028 OPCODE(OGF_LE_CONTROLLER, 0x25), ""
1029 //  LE Read Local P-256 Public Key Complete is generated on completion
1030 };
1031 
1032 /**
1033  * @param end_test_cmd
1034  */
1035 const hci_cmd_t hci_le_generate_dhkey = {
1036 OPCODE(OGF_LE_CONTROLLER, 0x26), "QQ"
1037 // LE Generate DHKey Complete is generated on completion
1038 };
1039 
1040 #endif
1041