xref: /btstack/src/hci.c (revision aff8ac5c9890c482a12b01b8d42aa436c60d0ce5)
11f504dbdSmatthias.ringwald /*
21f504dbdSmatthias.ringwald  *  hci.c
31f504dbdSmatthias.ringwald  *
41f504dbdSmatthias.ringwald  *  Created by Matthias Ringwald on 4/29/09.
51f504dbdSmatthias.ringwald  *
61f504dbdSmatthias.ringwald  */
71f504dbdSmatthias.ringwald 
8475c8125Smatthias.ringwald #include <unistd.h>
993b8dc03Smatthias.ringwald #include <stdarg.h>
1093b8dc03Smatthias.ringwald #include <string.h>
1156fe0872Smatthias.ringwald #include <stdio.h>
121f504dbdSmatthias.ringwald #include "hci.h"
131f504dbdSmatthias.ringwald 
140a974e0cSmatthias.ringwald // calculate combined ogf/ocf value
150a974e0cSmatthias.ringwald #define OPCODE(ogf, ocf) (ocf | ogf << 10)
1602ea9861Smatthias.ringwald #define OGF_LINK_CONTROL 0x01
1702ea9861Smatthias.ringwald #define OGF_CONTROLLER_BASEBAND 0x03
1868d92d03Smatthias.ringwald #define OGF_INFORMATIONAL_PARAMETERS 0x04
1993b8dc03Smatthias.ringwald 
2093b8dc03Smatthias.ringwald hci_cmd_t hci_inquiry = {
213091b266Smatthias.ringwald     OPCODE(OGF_LINK_CONTROL, 0x01), "311"
223091b266Smatthias.ringwald     // LAP, Inquiry length, Num_responses
233091b266Smatthias.ringwald };
243b9efdc1Smatthias.ringwald hci_cmd_t hci_inquiry_cancel = {
253b9efdc1Smatthias.ringwald 	OPCODE(OGF_LINK_CONTROL, 0x02), ""
263b9efdc1Smatthias.ringwald 	// no params
273b9efdc1Smatthias.ringwald };
28*aff8ac5cSmatthias.ringwald hci_cmd_t hci_create_connection = {
29*aff8ac5cSmatthias.ringwald 	OPCODE(OGF_LINK_CONTROL, 0x05), "B21121"
30*aff8ac5cSmatthias.ringwald 	// BD_ADDR, Packet_Type, Page_Scan_Repetition_Mode, Reserved, Clock_Offset, Allow_Role_Switch
31*aff8ac5cSmatthias.ringwald };
323091b266Smatthias.ringwald hci_cmd_t hci_link_key_request_negative_reply = {
333091b266Smatthias.ringwald     OPCODE(OGF_LINK_CONTROL, 0x0c), "B"
343091b266Smatthias.ringwald };
353091b266Smatthias.ringwald hci_cmd_t hci_pin_code_request_reply = {
363091b266Smatthias.ringwald     OPCODE(OGF_LINK_CONTROL, 0x0d), "B1P"
373091b266Smatthias.ringwald     // BD_ADDR, pin length, PIN: c-string
3893b8dc03Smatthias.ringwald };
39*aff8ac5cSmatthias.ringwald hci_cmd_t hci_remote_name_request = {
40*aff8ac5cSmatthias.ringwald 	OPCODE(OGF_LINK_CONTROL, 0x19), "B112"
41*aff8ac5cSmatthias.ringwald 	// BD_ADDR, Page_Scan_Repetition_Mode, Reserved, Clock_Offset
42*aff8ac5cSmatthias.ringwald };
43*aff8ac5cSmatthias.ringwald 	hci_cmd_t hci_remote_name_request_cancel = {
44*aff8ac5cSmatthias.ringwald 	OPCODE(OGF_LINK_CONTROL, 0x1A), "B"
45*aff8ac5cSmatthias.ringwald 	// BD_ADDR
46*aff8ac5cSmatthias.ringwald };
4793b8dc03Smatthias.ringwald 
4893b8dc03Smatthias.ringwald hci_cmd_t hci_reset = {
4902ea9861Smatthias.ringwald     OPCODE(OGF_CONTROLLER_BASEBAND, 0x03), ""
5002ea9861Smatthias.ringwald };
5102ea9861Smatthias.ringwald hci_cmd_t hci_write_page_timeout = {
5202ea9861Smatthias.ringwald     OPCODE(OGF_CONTROLLER_BASEBAND, 0x18), "2"
5302ea9861Smatthias.ringwald     // Page_Timeout * 0.625 ms
5402ea9861Smatthias.ringwald };
5502ea9861Smatthias.ringwald 
563091b266Smatthias.ringwald hci_cmd_t hci_write_authentication_enable = {
573091b266Smatthias.ringwald     OPCODE(OGF_CONTROLLER_BASEBAND, 0x20), "1"
583091b266Smatthias.ringwald     // Authentication_Enable
593091b266Smatthias.ringwald };
603091b266Smatthias.ringwald 
6102ea9861Smatthias.ringwald hci_cmd_t hci_host_buffer_size = {
6202ea9861Smatthias.ringwald     OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122"
6302ea9861Smatthias.ringwald     // Host_ACL_Data_Packet_Length:, Host_Synchronous_Data_Packet_Length:, Host_Total_Num_ACL_Data_Packets:, Host_Total_Num_Synchronous_Data_Packets:
6493b8dc03Smatthias.ringwald };
6593b8dc03Smatthias.ringwald 
6668d92d03Smatthias.ringwald hci_cmd_t hci_read_bd_addr = {
6768d92d03Smatthias.ringwald 	OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), ""
6868d92d03Smatthias.ringwald 	// no params
6968d92d03Smatthias.ringwald };
7068d92d03Smatthias.ringwald 
7193b8dc03Smatthias.ringwald 
7216833f0aSmatthias.ringwald // the stack is here
7316833f0aSmatthias.ringwald static hci_stack_t       hci_stack;
7416833f0aSmatthias.ringwald 
75475c8125Smatthias.ringwald 
7643625864Smatthias.ringwald void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value){
778b658ebcSmatthias.ringwald     buffer[pos++] = value;
788b658ebcSmatthias.ringwald     buffer[pos++] = value >> 8;
798b658ebcSmatthias.ringwald }
808b658ebcSmatthias.ringwald 
818b658ebcSmatthias.ringwald void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value){
828b658ebcSmatthias.ringwald     buffer[pos++] = value;
838b658ebcSmatthias.ringwald     buffer[pos++] = value >> 8;
848b658ebcSmatthias.ringwald     buffer[pos++] = value >> 16;
858b658ebcSmatthias.ringwald     buffer[pos++] = value >> 24;
8643625864Smatthias.ringwald }
8743625864Smatthias.ringwald 
881281a47eSmatthias.ringwald void bt_flip_addr(bd_addr_t dest, bd_addr_t src){
891281a47eSmatthias.ringwald     dest[0] = src[5];
901281a47eSmatthias.ringwald     dest[1] = src[4];
911281a47eSmatthias.ringwald     dest[2] = src[3];
921281a47eSmatthias.ringwald     dest[3] = src[2];
931281a47eSmatthias.ringwald     dest[4] = src[1];
941281a47eSmatthias.ringwald     dest[5] = src[0];
951281a47eSmatthias.ringwald }
961281a47eSmatthias.ringwald 
9702582713Smatthias.ringwald void hexdump(void *data, int size){
9856fe0872Smatthias.ringwald     int i;
9956fe0872Smatthias.ringwald     for (i=0; i<size;i++){
10002582713Smatthias.ringwald         printf("%02X ", ((uint8_t *)data)[i]);
10156fe0872Smatthias.ringwald     }
10256fe0872Smatthias.ringwald     printf("\n");
10356fe0872Smatthias.ringwald }
10456fe0872Smatthias.ringwald 
10556fe0872Smatthias.ringwald #if 0
10656fe0872Smatthias.ringwald static void *hci_daemon_thread(void *arg){
10756fe0872Smatthias.ringwald     printf("HCI Daemon started\n");
10856fe0872Smatthias.ringwald     hci_run(transport, &config);
10956fe0872Smatthias.ringwald     return NULL;
11056fe0872Smatthias.ringwald }
11156fe0872Smatthias.ringwald #endif
11256fe0872Smatthias.ringwald 
11316833f0aSmatthias.ringwald /**
11497addcc5Smatthias.ringwald  * Linked link list
11597addcc5Smatthias.ringwald  */
11697addcc5Smatthias.ringwald 
11797addcc5Smatthias.ringwald /**
11897addcc5Smatthias.ringwald  * get link for given address
11997addcc5Smatthias.ringwald  *
12097addcc5Smatthias.ringwald  * @return connection OR NULL, if not found
12197addcc5Smatthias.ringwald  */
122145be03fSmatthias.ringwald #if 0
12397addcc5Smatthias.ringwald static hci_connection_t *link_for_addr(bd_addr_t addr){
12497addcc5Smatthias.ringwald     return NULL;
12597addcc5Smatthias.ringwald }
126145be03fSmatthias.ringwald #endif
12797addcc5Smatthias.ringwald 
12897addcc5Smatthias.ringwald /**
12916833f0aSmatthias.ringwald  * Handler called by HCI transport
13016833f0aSmatthias.ringwald  */
13116833f0aSmatthias.ringwald static void dummy_handler(uint8_t *packet, int size){
13216833f0aSmatthias.ringwald }
13316833f0aSmatthias.ringwald 
13416833f0aSmatthias.ringwald static void acl_handler(uint8_t *packet, int size){
13516833f0aSmatthias.ringwald     hci_stack.acl_packet_handler(packet, size);
13694ab26f8Smatthias.ringwald 
13794ab26f8Smatthias.ringwald     // execute main loop
13894ab26f8Smatthias.ringwald     hci_run();
13916833f0aSmatthias.ringwald }
14022909952Smatthias.ringwald 
14116833f0aSmatthias.ringwald static void event_handler(uint8_t *packet, int size){
1421281a47eSmatthias.ringwald     bd_addr_t addr;
14322909952Smatthias.ringwald 
1443429f56bSmatthias.ringwald     // Get Num_HCI_Command_Packets
1453429f56bSmatthias.ringwald     if (packet[0] == HCI_EVENT_COMMAND_COMPLETE ||
1463429f56bSmatthias.ringwald         packet[0] == HCI_EVENT_COMMAND_STATUS){
1473429f56bSmatthias.ringwald         hci_stack.num_cmd_packets = packet[2];
14822909952Smatthias.ringwald     }
14922909952Smatthias.ringwald 
1503429f56bSmatthias.ringwald     // handle BT initialization
1513429f56bSmatthias.ringwald     if (hci_stack.state == HCI_STATE_INITIALIZING){
1527301ad89Smatthias.ringwald         // handle H4 synchronization loss on restart
1537301ad89Smatthias.ringwald         // if (hci_stack.substate == 1 && packet[0] == HCI_EVENT_HARDWARE_ERROR){
1547301ad89Smatthias.ringwald         //    hci_stack.substate = 0;
1557301ad89Smatthias.ringwald         // }
1567301ad89Smatthias.ringwald         // handle normal init sequence
1573429f56bSmatthias.ringwald         if (hci_stack.substate % 2){
1583429f56bSmatthias.ringwald             // odd: waiting for event
1593429f56bSmatthias.ringwald             if (packet[0] == HCI_EVENT_COMMAND_COMPLETE){
1603429f56bSmatthias.ringwald                 hci_stack.substate++;
1613429f56bSmatthias.ringwald             }
1623429f56bSmatthias.ringwald         }
16322909952Smatthias.ringwald     }
16422909952Smatthias.ringwald 
1651281a47eSmatthias.ringwald     // link key request
1663429f56bSmatthias.ringwald     if (packet[0] == HCI_EVENT_LINK_KEY_REQUEST){
1671281a47eSmatthias.ringwald         bt_flip_addr(addr, &packet[2]);
1681281a47eSmatthias.ringwald         hci_send_cmd(&hci_link_key_request_negative_reply, &addr);
1691281a47eSmatthias.ringwald         return;
1701281a47eSmatthias.ringwald     }
1711281a47eSmatthias.ringwald 
1721281a47eSmatthias.ringwald     // pin code request
1733429f56bSmatthias.ringwald     if (packet[0] == HCI_EVENT_PIN_CODE_REQUEST){
1741281a47eSmatthias.ringwald         bt_flip_addr(addr, &packet[2]);
1751281a47eSmatthias.ringwald         hci_send_cmd(&hci_pin_code_request_reply, &addr, 4, "1234");
1761281a47eSmatthias.ringwald     }
1771281a47eSmatthias.ringwald 
17816833f0aSmatthias.ringwald     hci_stack.event_packet_handler(packet, size);
17994ab26f8Smatthias.ringwald 
18094ab26f8Smatthias.ringwald 	// execute main loop
18194ab26f8Smatthias.ringwald 	hci_run();
18216833f0aSmatthias.ringwald }
18316833f0aSmatthias.ringwald 
18416833f0aSmatthias.ringwald /** Register L2CAP handlers */
18516833f0aSmatthias.ringwald void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, int size)){
18616833f0aSmatthias.ringwald     hci_stack.event_packet_handler = handler;
18716833f0aSmatthias.ringwald }
18816833f0aSmatthias.ringwald void hci_register_acl_packet_handler  (void (*handler)(uint8_t *packet, int size)){
18916833f0aSmatthias.ringwald     hci_stack.acl_packet_handler = handler;
19016833f0aSmatthias.ringwald }
19116833f0aSmatthias.ringwald 
1927301ad89Smatthias.ringwald static int null_control_function(void *config){
1937301ad89Smatthias.ringwald     return 0;
1947301ad89Smatthias.ringwald }
1957301ad89Smatthias.ringwald static const char * null_control_name(void *config){
1967301ad89Smatthias.ringwald     return "Hardware unknown";
1977301ad89Smatthias.ringwald }
1987301ad89Smatthias.ringwald 
1997301ad89Smatthias.ringwald static bt_control_t null_control = {
2007301ad89Smatthias.ringwald     null_control_function,
2017301ad89Smatthias.ringwald     null_control_function,
2027301ad89Smatthias.ringwald     null_control_function,
2037301ad89Smatthias.ringwald     null_control_name
2047301ad89Smatthias.ringwald };
2057301ad89Smatthias.ringwald 
20611e23e5fSmatthias.ringwald void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){
207475c8125Smatthias.ringwald 
208475c8125Smatthias.ringwald     // reference to use transport layer implementation
20916833f0aSmatthias.ringwald     hci_stack.hci_transport = transport;
210475c8125Smatthias.ringwald 
21111e23e5fSmatthias.ringwald     // references to used control implementation
2127301ad89Smatthias.ringwald     if (control) {
21311e23e5fSmatthias.ringwald         hci_stack.control = control;
2147301ad89Smatthias.ringwald     } else {
2157301ad89Smatthias.ringwald         hci_stack.control = &null_control;
2167301ad89Smatthias.ringwald     }
21711e23e5fSmatthias.ringwald 
21811e23e5fSmatthias.ringwald     // reference to used config
21911e23e5fSmatthias.ringwald     hci_stack.config = config;
22011e23e5fSmatthias.ringwald 
22102ea9861Smatthias.ringwald     // empty cmd buffer
22216833f0aSmatthias.ringwald     hci_stack.hci_cmd_buffer = malloc(3+255);
22316833f0aSmatthias.ringwald 
22416833f0aSmatthias.ringwald     // higher level handler
22516833f0aSmatthias.ringwald     hci_stack.event_packet_handler = dummy_handler;
22616833f0aSmatthias.ringwald     hci_stack.acl_packet_handler = dummy_handler;
22716833f0aSmatthias.ringwald 
22816833f0aSmatthias.ringwald     // register packet handlers with transport
22916833f0aSmatthias.ringwald     transport->register_event_packet_handler( event_handler);
23016833f0aSmatthias.ringwald     transport->register_acl_packet_handler( acl_handler);
231475c8125Smatthias.ringwald }
232475c8125Smatthias.ringwald 
233475c8125Smatthias.ringwald int hci_power_control(HCI_POWER_MODE power_mode){
23411e23e5fSmatthias.ringwald     if (power_mode == HCI_POWER_ON) {
2357301ad89Smatthias.ringwald 
2367301ad89Smatthias.ringwald         // set up state machine
2377301ad89Smatthias.ringwald         hci_stack.num_cmd_packets = 1; // assume that one cmd can be sent
2387301ad89Smatthias.ringwald         hci_stack.state = HCI_STATE_INITIALIZING;
2397301ad89Smatthias.ringwald         hci_stack.substate = 0;
2407301ad89Smatthias.ringwald 
2417301ad89Smatthias.ringwald         // power on
24211e23e5fSmatthias.ringwald         hci_stack.control->on(hci_stack.config);
2437301ad89Smatthias.ringwald 
2447301ad89Smatthias.ringwald         // open low-level device
2457301ad89Smatthias.ringwald         hci_stack.hci_transport->open(hci_stack.config);
2467301ad89Smatthias.ringwald 
24711e23e5fSmatthias.ringwald     } else if (power_mode == HCI_POWER_OFF){
2487301ad89Smatthias.ringwald 
2497301ad89Smatthias.ringwald         // close low-level device
2507301ad89Smatthias.ringwald         hci_stack.hci_transport->close(hci_stack.config);
2517301ad89Smatthias.ringwald 
2527301ad89Smatthias.ringwald         // power off
25311e23e5fSmatthias.ringwald         hci_stack.control->off(hci_stack.config);
25411e23e5fSmatthias.ringwald     }
25568d92d03Smatthias.ringwald 
25668d92d03Smatthias.ringwald 	// trigger next/first action
25768d92d03Smatthias.ringwald 	hci_run();
25868d92d03Smatthias.ringwald 
259475c8125Smatthias.ringwald     return 0;
260475c8125Smatthias.ringwald }
261475c8125Smatthias.ringwald 
2623429f56bSmatthias.ringwald uint32_t hci_run(){
2633429f56bSmatthias.ringwald     uint8_t micro_packet;
2643429f56bSmatthias.ringwald     switch (hci_stack.state){
2653429f56bSmatthias.ringwald         case HCI_STATE_INITIALIZING:
2663429f56bSmatthias.ringwald             if (hci_stack.substate % 2) {
2673429f56bSmatthias.ringwald                 // odd: waiting for command completion
2683429f56bSmatthias.ringwald                 return 0;
2693429f56bSmatthias.ringwald             }
2703429f56bSmatthias.ringwald             if (hci_stack.num_cmd_packets == 0) {
2713429f56bSmatthias.ringwald                 // cannot send command yet
2723429f56bSmatthias.ringwald                 return 0;
2733429f56bSmatthias.ringwald             }
2743429f56bSmatthias.ringwald             switch (hci_stack.substate/2){
2753429f56bSmatthias.ringwald                 case 0:
27622909952Smatthias.ringwald                     hci_send_cmd(&hci_reset);
2773429f56bSmatthias.ringwald                     break;
2783429f56bSmatthias.ringwald                 case 1:
2793429f56bSmatthias.ringwald                     // ca. 15 sec
2803429f56bSmatthias.ringwald                     hci_send_cmd(&hci_write_page_timeout, 0x6000);
2813429f56bSmatthias.ringwald                     break;
2823429f56bSmatthias.ringwald                 case 2:
2833429f56bSmatthias.ringwald                     // done.
2843429f56bSmatthias.ringwald                     hci_stack.state = HCI_STATE_WORKING;
2853429f56bSmatthias.ringwald                     micro_packet = BTSTACK_EVENT_HCI_WORKING;
2863429f56bSmatthias.ringwald                     hci_stack.event_packet_handler(&micro_packet, 1);
2873429f56bSmatthias.ringwald                     break;
2883429f56bSmatthias.ringwald                 default:
2893429f56bSmatthias.ringwald                     break;
290475c8125Smatthias.ringwald             }
2913429f56bSmatthias.ringwald             hci_stack.substate++;
2923429f56bSmatthias.ringwald             break;
2933429f56bSmatthias.ringwald         default:
2943429f56bSmatthias.ringwald             break;
2951f504dbdSmatthias.ringwald     }
29693b8dc03Smatthias.ringwald 
2973429f56bSmatthias.ringwald     // don't check for timetous yet
2983429f56bSmatthias.ringwald     return 0;
2993429f56bSmatthias.ringwald }
30016833f0aSmatthias.ringwald 
30116833f0aSmatthias.ringwald 
30243625864Smatthias.ringwald int hci_send_acl_packet(uint8_t *packet, int size){
30316833f0aSmatthias.ringwald     return hci_stack.hci_transport->send_acl_packet(packet, size);
30443625864Smatthias.ringwald }
30543625864Smatthias.ringwald 
3063429f56bSmatthias.ringwald 
3073429f56bSmatthias.ringwald /**
3083429f56bSmatthias.ringwald  * pre: numcmds >= 0 - it's allowed to send a command to the controller
3093429f56bSmatthias.ringwald  */
31002ea9861Smatthias.ringwald int hci_send_cmd(hci_cmd_t *cmd, ...){
31116833f0aSmatthias.ringwald     uint8_t * hci_cmd_buffer = hci_stack.hci_cmd_buffer;
31202ea9861Smatthias.ringwald     hci_cmd_buffer[0] = cmd->opcode & 0xff;
31302ea9861Smatthias.ringwald     hci_cmd_buffer[1] = cmd->opcode >> 8;
31493b8dc03Smatthias.ringwald     int pos = 3;
31593b8dc03Smatthias.ringwald 
31693b8dc03Smatthias.ringwald     va_list argptr;
31793b8dc03Smatthias.ringwald     va_start(argptr, cmd);
31893b8dc03Smatthias.ringwald     const char *format = cmd->format;
31993b8dc03Smatthias.ringwald     uint16_t word;
32093b8dc03Smatthias.ringwald     uint32_t longword;
3213091b266Smatthias.ringwald     uint8_t * ptr;
32293b8dc03Smatthias.ringwald     while (*format) {
32393b8dc03Smatthias.ringwald         switch(*format) {
32493b8dc03Smatthias.ringwald             case '1': //  8 bit value
32593b8dc03Smatthias.ringwald             case '2': // 16 bit value
32693b8dc03Smatthias.ringwald             case 'H': // hci_handle
327554588a5Smatthias.ringwald                 word = va_arg(argptr, int);  // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
32802ea9861Smatthias.ringwald                 hci_cmd_buffer[pos++] = word & 0xff;
32993b8dc03Smatthias.ringwald                 if (*format == '2') {
33002ea9861Smatthias.ringwald                     hci_cmd_buffer[pos++] = word >> 8;
33193b8dc03Smatthias.ringwald                 } else if (*format == 'H') {
332554588a5Smatthias.ringwald                     // TODO
33393b8dc03Smatthias.ringwald                 }
33493b8dc03Smatthias.ringwald                 break;
33593b8dc03Smatthias.ringwald             case '3':
33693b8dc03Smatthias.ringwald             case '4':
33793b8dc03Smatthias.ringwald                 longword = va_arg(argptr, uint32_t);
33893b8dc03Smatthias.ringwald                 // longword = va_arg(argptr, int);
33902ea9861Smatthias.ringwald                 hci_cmd_buffer[pos++] = longword;
34002ea9861Smatthias.ringwald                 hci_cmd_buffer[pos++] = longword >> 8;
34102ea9861Smatthias.ringwald                 hci_cmd_buffer[pos++] = longword >> 16;
34293b8dc03Smatthias.ringwald                 if (*format == '4'){
34302ea9861Smatthias.ringwald                     hci_cmd_buffer[pos++] = longword >> 24;
34493b8dc03Smatthias.ringwald                 }
34593b8dc03Smatthias.ringwald                 break;
34693b8dc03Smatthias.ringwald             case 'B': // bt-addr
3473091b266Smatthias.ringwald                 ptr = va_arg(argptr, uint8_t *);
3483091b266Smatthias.ringwald                 hci_cmd_buffer[pos++] = ptr[5];
3493091b266Smatthias.ringwald                 hci_cmd_buffer[pos++] = ptr[4];
3503091b266Smatthias.ringwald                 hci_cmd_buffer[pos++] = ptr[3];
3513091b266Smatthias.ringwald                 hci_cmd_buffer[pos++] = ptr[2];
3523091b266Smatthias.ringwald                 hci_cmd_buffer[pos++] = ptr[1];
3533091b266Smatthias.ringwald                 hci_cmd_buffer[pos++] = ptr[0];
3543091b266Smatthias.ringwald                 break;
3553091b266Smatthias.ringwald             case 'P': // c string passed as pascal string with leading 1-byte len
3563091b266Smatthias.ringwald                 ptr = va_arg(argptr, uint8_t *);
3573091b266Smatthias.ringwald                 memcpy(&hci_cmd_buffer[pos], ptr, 16);
3583091b266Smatthias.ringwald                 pos += 16;
35993b8dc03Smatthias.ringwald                 break;
36093b8dc03Smatthias.ringwald             default:
36193b8dc03Smatthias.ringwald                 break;
36293b8dc03Smatthias.ringwald         }
36393b8dc03Smatthias.ringwald         format++;
36493b8dc03Smatthias.ringwald     };
36593b8dc03Smatthias.ringwald     va_end(argptr);
36602ea9861Smatthias.ringwald     hci_cmd_buffer[2] = pos - 3;
36702ea9861Smatthias.ringwald     // send packet
3683429f56bSmatthias.ringwald     hci_stack.num_cmd_packets--;
36916833f0aSmatthias.ringwald     return hci_stack.hci_transport->send_cmd_packet(hci_cmd_buffer, pos);
37093b8dc03Smatthias.ringwald }