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 20*e521ef40Smatthias.ringwald /** 21*e521ef40Smatthias.ringwald * Link Control Commands 22*e521ef40Smatthias.ringwald */ 2393b8dc03Smatthias.ringwald hci_cmd_t hci_inquiry = { 243091b266Smatthias.ringwald OPCODE(OGF_LINK_CONTROL, 0x01), "311" 253091b266Smatthias.ringwald // LAP, Inquiry length, Num_responses 263091b266Smatthias.ringwald }; 273b9efdc1Smatthias.ringwald hci_cmd_t hci_inquiry_cancel = { 283b9efdc1Smatthias.ringwald OPCODE(OGF_LINK_CONTROL, 0x02), "" 293b9efdc1Smatthias.ringwald // no params 303b9efdc1Smatthias.ringwald }; 31aff8ac5cSmatthias.ringwald hci_cmd_t hci_create_connection = { 32aff8ac5cSmatthias.ringwald OPCODE(OGF_LINK_CONTROL, 0x05), "B21121" 33aff8ac5cSmatthias.ringwald // BD_ADDR, Packet_Type, Page_Scan_Repetition_Mode, Reserved, Clock_Offset, Allow_Role_Switch 34aff8ac5cSmatthias.ringwald }; 353091b266Smatthias.ringwald hci_cmd_t hci_link_key_request_negative_reply = { 363091b266Smatthias.ringwald OPCODE(OGF_LINK_CONTROL, 0x0c), "B" 373091b266Smatthias.ringwald }; 383091b266Smatthias.ringwald hci_cmd_t hci_pin_code_request_reply = { 393091b266Smatthias.ringwald OPCODE(OGF_LINK_CONTROL, 0x0d), "B1P" 403091b266Smatthias.ringwald // BD_ADDR, pin length, PIN: c-string 4193b8dc03Smatthias.ringwald }; 42aff8ac5cSmatthias.ringwald hci_cmd_t hci_remote_name_request = { 43aff8ac5cSmatthias.ringwald OPCODE(OGF_LINK_CONTROL, 0x19), "B112" 44aff8ac5cSmatthias.ringwald // BD_ADDR, Page_Scan_Repetition_Mode, Reserved, Clock_Offset 45aff8ac5cSmatthias.ringwald }; 46aff8ac5cSmatthias.ringwald hci_cmd_t hci_remote_name_request_cancel = { 47aff8ac5cSmatthias.ringwald OPCODE(OGF_LINK_CONTROL, 0x1A), "B" 48aff8ac5cSmatthias.ringwald // BD_ADDR 49aff8ac5cSmatthias.ringwald }; 5093b8dc03Smatthias.ringwald 51*e521ef40Smatthias.ringwald /** 52*e521ef40Smatthias.ringwald * Controller & Baseband Commands 53*e521ef40Smatthias.ringwald */ 5493b8dc03Smatthias.ringwald hci_cmd_t hci_reset = { 5502ea9861Smatthias.ringwald OPCODE(OGF_CONTROLLER_BASEBAND, 0x03), "" 56*e521ef40Smatthias.ringwald // no params 57*e521ef40Smatthias.ringwald }; 58*e521ef40Smatthias.ringwald hci_cmd_t hci_delete_stored_link_key = { 59*e521ef40Smatthias.ringwald OPCODE(OGF_CONTROLLER_BASEBAND, 0x12), "B1" 60*e521ef40Smatthias.ringwald // BD_ADDR, Delete_All_Flag 6102ea9861Smatthias.ringwald }; 6202ea9861Smatthias.ringwald hci_cmd_t hci_write_page_timeout = { 6302ea9861Smatthias.ringwald OPCODE(OGF_CONTROLLER_BASEBAND, 0x18), "2" 6402ea9861Smatthias.ringwald // Page_Timeout * 0.625 ms 6502ea9861Smatthias.ringwald }; 663091b266Smatthias.ringwald hci_cmd_t hci_write_authentication_enable = { 673091b266Smatthias.ringwald OPCODE(OGF_CONTROLLER_BASEBAND, 0x20), "1" 683091b266Smatthias.ringwald // Authentication_Enable 693091b266Smatthias.ringwald }; 7002ea9861Smatthias.ringwald hci_cmd_t hci_host_buffer_size = { 7102ea9861Smatthias.ringwald OPCODE(OGF_CONTROLLER_BASEBAND, 0x33), "2122" 7202ea9861Smatthias.ringwald // Host_ACL_Data_Packet_Length:, Host_Synchronous_Data_Packet_Length:, Host_Total_Num_ACL_Data_Packets:, Host_Total_Num_Synchronous_Data_Packets: 7393b8dc03Smatthias.ringwald }; 7493b8dc03Smatthias.ringwald 7568d92d03Smatthias.ringwald hci_cmd_t hci_read_bd_addr = { 7668d92d03Smatthias.ringwald OPCODE(OGF_INFORMATIONAL_PARAMETERS, 0x09), "" 7768d92d03Smatthias.ringwald // no params 7868d92d03Smatthias.ringwald }; 7968d92d03Smatthias.ringwald 8093b8dc03Smatthias.ringwald 8116833f0aSmatthias.ringwald // the stack is here 8216833f0aSmatthias.ringwald static hci_stack_t hci_stack; 8316833f0aSmatthias.ringwald 84475c8125Smatthias.ringwald 8543625864Smatthias.ringwald void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value){ 868b658ebcSmatthias.ringwald buffer[pos++] = value; 878b658ebcSmatthias.ringwald buffer[pos++] = value >> 8; 888b658ebcSmatthias.ringwald } 898b658ebcSmatthias.ringwald 908b658ebcSmatthias.ringwald void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value){ 918b658ebcSmatthias.ringwald buffer[pos++] = value; 928b658ebcSmatthias.ringwald buffer[pos++] = value >> 8; 938b658ebcSmatthias.ringwald buffer[pos++] = value >> 16; 948b658ebcSmatthias.ringwald buffer[pos++] = value >> 24; 9543625864Smatthias.ringwald } 9643625864Smatthias.ringwald 971281a47eSmatthias.ringwald void bt_flip_addr(bd_addr_t dest, bd_addr_t src){ 981281a47eSmatthias.ringwald dest[0] = src[5]; 991281a47eSmatthias.ringwald dest[1] = src[4]; 1001281a47eSmatthias.ringwald dest[2] = src[3]; 1011281a47eSmatthias.ringwald dest[3] = src[2]; 1021281a47eSmatthias.ringwald dest[4] = src[1]; 1031281a47eSmatthias.ringwald dest[5] = src[0]; 1041281a47eSmatthias.ringwald } 1051281a47eSmatthias.ringwald 10602582713Smatthias.ringwald void hexdump(void *data, int size){ 10756fe0872Smatthias.ringwald int i; 10856fe0872Smatthias.ringwald for (i=0; i<size;i++){ 10902582713Smatthias.ringwald printf("%02X ", ((uint8_t *)data)[i]); 11056fe0872Smatthias.ringwald } 11156fe0872Smatthias.ringwald printf("\n"); 11256fe0872Smatthias.ringwald } 11356fe0872Smatthias.ringwald 11456fe0872Smatthias.ringwald #if 0 11556fe0872Smatthias.ringwald static void *hci_daemon_thread(void *arg){ 11656fe0872Smatthias.ringwald printf("HCI Daemon started\n"); 11756fe0872Smatthias.ringwald hci_run(transport, &config); 11856fe0872Smatthias.ringwald return NULL; 11956fe0872Smatthias.ringwald } 12056fe0872Smatthias.ringwald #endif 12156fe0872Smatthias.ringwald 12216833f0aSmatthias.ringwald /** 12397addcc5Smatthias.ringwald * Linked link list 12497addcc5Smatthias.ringwald */ 12597addcc5Smatthias.ringwald 12697addcc5Smatthias.ringwald /** 12797addcc5Smatthias.ringwald * get link for given address 12897addcc5Smatthias.ringwald * 12997addcc5Smatthias.ringwald * @return connection OR NULL, if not found 13097addcc5Smatthias.ringwald */ 131145be03fSmatthias.ringwald #if 0 13297addcc5Smatthias.ringwald static hci_connection_t *link_for_addr(bd_addr_t addr){ 13397addcc5Smatthias.ringwald return NULL; 13497addcc5Smatthias.ringwald } 135145be03fSmatthias.ringwald #endif 13697addcc5Smatthias.ringwald 13797addcc5Smatthias.ringwald /** 13816833f0aSmatthias.ringwald * Handler called by HCI transport 13916833f0aSmatthias.ringwald */ 14016833f0aSmatthias.ringwald static void dummy_handler(uint8_t *packet, int size){ 14116833f0aSmatthias.ringwald } 14216833f0aSmatthias.ringwald 14316833f0aSmatthias.ringwald static void acl_handler(uint8_t *packet, int size){ 14416833f0aSmatthias.ringwald hci_stack.acl_packet_handler(packet, size); 14594ab26f8Smatthias.ringwald 14694ab26f8Smatthias.ringwald // execute main loop 14794ab26f8Smatthias.ringwald hci_run(); 14816833f0aSmatthias.ringwald } 14922909952Smatthias.ringwald 15016833f0aSmatthias.ringwald static void event_handler(uint8_t *packet, int size){ 1511281a47eSmatthias.ringwald bd_addr_t addr; 15222909952Smatthias.ringwald 1533429f56bSmatthias.ringwald // Get Num_HCI_Command_Packets 1543429f56bSmatthias.ringwald if (packet[0] == HCI_EVENT_COMMAND_COMPLETE || 1553429f56bSmatthias.ringwald packet[0] == HCI_EVENT_COMMAND_STATUS){ 1563429f56bSmatthias.ringwald hci_stack.num_cmd_packets = packet[2]; 15722909952Smatthias.ringwald } 15822909952Smatthias.ringwald 1593429f56bSmatthias.ringwald // handle BT initialization 1603429f56bSmatthias.ringwald if (hci_stack.state == HCI_STATE_INITIALIZING){ 1617301ad89Smatthias.ringwald // handle H4 synchronization loss on restart 1627301ad89Smatthias.ringwald // if (hci_stack.substate == 1 && packet[0] == HCI_EVENT_HARDWARE_ERROR){ 1637301ad89Smatthias.ringwald // hci_stack.substate = 0; 1647301ad89Smatthias.ringwald // } 1657301ad89Smatthias.ringwald // handle normal init sequence 1663429f56bSmatthias.ringwald if (hci_stack.substate % 2){ 1673429f56bSmatthias.ringwald // odd: waiting for event 1683429f56bSmatthias.ringwald if (packet[0] == HCI_EVENT_COMMAND_COMPLETE){ 1693429f56bSmatthias.ringwald hci_stack.substate++; 1703429f56bSmatthias.ringwald } 1713429f56bSmatthias.ringwald } 17222909952Smatthias.ringwald } 17322909952Smatthias.ringwald 1741281a47eSmatthias.ringwald // link key request 1753429f56bSmatthias.ringwald if (packet[0] == HCI_EVENT_LINK_KEY_REQUEST){ 1761281a47eSmatthias.ringwald bt_flip_addr(addr, &packet[2]); 1771281a47eSmatthias.ringwald hci_send_cmd(&hci_link_key_request_negative_reply, &addr); 1781281a47eSmatthias.ringwald return; 1791281a47eSmatthias.ringwald } 1801281a47eSmatthias.ringwald 1811281a47eSmatthias.ringwald // pin code request 1823429f56bSmatthias.ringwald if (packet[0] == HCI_EVENT_PIN_CODE_REQUEST){ 1831281a47eSmatthias.ringwald bt_flip_addr(addr, &packet[2]); 1841281a47eSmatthias.ringwald hci_send_cmd(&hci_pin_code_request_reply, &addr, 4, "1234"); 1851281a47eSmatthias.ringwald } 1861281a47eSmatthias.ringwald 18716833f0aSmatthias.ringwald hci_stack.event_packet_handler(packet, size); 18894ab26f8Smatthias.ringwald 18994ab26f8Smatthias.ringwald // execute main loop 19094ab26f8Smatthias.ringwald hci_run(); 19116833f0aSmatthias.ringwald } 19216833f0aSmatthias.ringwald 19316833f0aSmatthias.ringwald /** Register L2CAP handlers */ 19416833f0aSmatthias.ringwald void hci_register_event_packet_handler(void (*handler)(uint8_t *packet, int size)){ 19516833f0aSmatthias.ringwald hci_stack.event_packet_handler = handler; 19616833f0aSmatthias.ringwald } 19716833f0aSmatthias.ringwald void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, int size)){ 19816833f0aSmatthias.ringwald hci_stack.acl_packet_handler = handler; 19916833f0aSmatthias.ringwald } 20016833f0aSmatthias.ringwald 2017301ad89Smatthias.ringwald static int null_control_function(void *config){ 2027301ad89Smatthias.ringwald return 0; 2037301ad89Smatthias.ringwald } 2047301ad89Smatthias.ringwald static const char * null_control_name(void *config){ 2057301ad89Smatthias.ringwald return "Hardware unknown"; 2067301ad89Smatthias.ringwald } 2077301ad89Smatthias.ringwald 2087301ad89Smatthias.ringwald static bt_control_t null_control = { 2097301ad89Smatthias.ringwald null_control_function, 2107301ad89Smatthias.ringwald null_control_function, 2117301ad89Smatthias.ringwald null_control_function, 2127301ad89Smatthias.ringwald null_control_name 2137301ad89Smatthias.ringwald }; 2147301ad89Smatthias.ringwald 21511e23e5fSmatthias.ringwald void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){ 216475c8125Smatthias.ringwald 217475c8125Smatthias.ringwald // reference to use transport layer implementation 21816833f0aSmatthias.ringwald hci_stack.hci_transport = transport; 219475c8125Smatthias.ringwald 22011e23e5fSmatthias.ringwald // references to used control implementation 2217301ad89Smatthias.ringwald if (control) { 22211e23e5fSmatthias.ringwald hci_stack.control = control; 2237301ad89Smatthias.ringwald } else { 2247301ad89Smatthias.ringwald hci_stack.control = &null_control; 2257301ad89Smatthias.ringwald } 22611e23e5fSmatthias.ringwald 22711e23e5fSmatthias.ringwald // reference to used config 22811e23e5fSmatthias.ringwald hci_stack.config = config; 22911e23e5fSmatthias.ringwald 23002ea9861Smatthias.ringwald // empty cmd buffer 23116833f0aSmatthias.ringwald hci_stack.hci_cmd_buffer = malloc(3+255); 23216833f0aSmatthias.ringwald 23316833f0aSmatthias.ringwald // higher level handler 23416833f0aSmatthias.ringwald hci_stack.event_packet_handler = dummy_handler; 23516833f0aSmatthias.ringwald hci_stack.acl_packet_handler = dummy_handler; 23616833f0aSmatthias.ringwald 23716833f0aSmatthias.ringwald // register packet handlers with transport 23816833f0aSmatthias.ringwald transport->register_event_packet_handler( event_handler); 23916833f0aSmatthias.ringwald transport->register_acl_packet_handler( acl_handler); 240475c8125Smatthias.ringwald } 241475c8125Smatthias.ringwald 242475c8125Smatthias.ringwald int hci_power_control(HCI_POWER_MODE power_mode){ 24311e23e5fSmatthias.ringwald if (power_mode == HCI_POWER_ON) { 2447301ad89Smatthias.ringwald 2457301ad89Smatthias.ringwald // set up state machine 2467301ad89Smatthias.ringwald hci_stack.num_cmd_packets = 1; // assume that one cmd can be sent 2477301ad89Smatthias.ringwald hci_stack.state = HCI_STATE_INITIALIZING; 2487301ad89Smatthias.ringwald hci_stack.substate = 0; 2497301ad89Smatthias.ringwald 2507301ad89Smatthias.ringwald // power on 25111e23e5fSmatthias.ringwald hci_stack.control->on(hci_stack.config); 2527301ad89Smatthias.ringwald 2537301ad89Smatthias.ringwald // open low-level device 2547301ad89Smatthias.ringwald hci_stack.hci_transport->open(hci_stack.config); 2557301ad89Smatthias.ringwald 25611e23e5fSmatthias.ringwald } else if (power_mode == HCI_POWER_OFF){ 2577301ad89Smatthias.ringwald 2587301ad89Smatthias.ringwald // close low-level device 2597301ad89Smatthias.ringwald hci_stack.hci_transport->close(hci_stack.config); 2607301ad89Smatthias.ringwald 2617301ad89Smatthias.ringwald // power off 26211e23e5fSmatthias.ringwald hci_stack.control->off(hci_stack.config); 26311e23e5fSmatthias.ringwald } 26468d92d03Smatthias.ringwald 26568d92d03Smatthias.ringwald // trigger next/first action 26668d92d03Smatthias.ringwald hci_run(); 26768d92d03Smatthias.ringwald 268475c8125Smatthias.ringwald return 0; 269475c8125Smatthias.ringwald } 270475c8125Smatthias.ringwald 2713429f56bSmatthias.ringwald uint32_t hci_run(){ 2723429f56bSmatthias.ringwald uint8_t micro_packet; 2733429f56bSmatthias.ringwald switch (hci_stack.state){ 2743429f56bSmatthias.ringwald case HCI_STATE_INITIALIZING: 2753429f56bSmatthias.ringwald if (hci_stack.substate % 2) { 2763429f56bSmatthias.ringwald // odd: waiting for command completion 2773429f56bSmatthias.ringwald return 0; 2783429f56bSmatthias.ringwald } 2793429f56bSmatthias.ringwald if (hci_stack.num_cmd_packets == 0) { 2803429f56bSmatthias.ringwald // cannot send command yet 2813429f56bSmatthias.ringwald return 0; 2823429f56bSmatthias.ringwald } 2833429f56bSmatthias.ringwald switch (hci_stack.substate/2){ 2843429f56bSmatthias.ringwald case 0: 28522909952Smatthias.ringwald hci_send_cmd(&hci_reset); 2863429f56bSmatthias.ringwald break; 2873429f56bSmatthias.ringwald case 1: 2883429f56bSmatthias.ringwald // ca. 15 sec 2893429f56bSmatthias.ringwald hci_send_cmd(&hci_write_page_timeout, 0x6000); 2903429f56bSmatthias.ringwald break; 2913429f56bSmatthias.ringwald case 2: 2923429f56bSmatthias.ringwald // done. 2933429f56bSmatthias.ringwald hci_stack.state = HCI_STATE_WORKING; 2943429f56bSmatthias.ringwald micro_packet = BTSTACK_EVENT_HCI_WORKING; 2953429f56bSmatthias.ringwald hci_stack.event_packet_handler(µ_packet, 1); 2963429f56bSmatthias.ringwald break; 2973429f56bSmatthias.ringwald default: 2983429f56bSmatthias.ringwald break; 299475c8125Smatthias.ringwald } 3003429f56bSmatthias.ringwald hci_stack.substate++; 3013429f56bSmatthias.ringwald break; 3023429f56bSmatthias.ringwald default: 3033429f56bSmatthias.ringwald break; 3041f504dbdSmatthias.ringwald } 30593b8dc03Smatthias.ringwald 3063429f56bSmatthias.ringwald // don't check for timetous yet 3073429f56bSmatthias.ringwald return 0; 3083429f56bSmatthias.ringwald } 30916833f0aSmatthias.ringwald 31016833f0aSmatthias.ringwald 31143625864Smatthias.ringwald int hci_send_acl_packet(uint8_t *packet, int size){ 31216833f0aSmatthias.ringwald return hci_stack.hci_transport->send_acl_packet(packet, size); 31343625864Smatthias.ringwald } 31443625864Smatthias.ringwald 3153429f56bSmatthias.ringwald 3163429f56bSmatthias.ringwald /** 3173429f56bSmatthias.ringwald * pre: numcmds >= 0 - it's allowed to send a command to the controller 3183429f56bSmatthias.ringwald */ 31902ea9861Smatthias.ringwald int hci_send_cmd(hci_cmd_t *cmd, ...){ 32016833f0aSmatthias.ringwald uint8_t * hci_cmd_buffer = hci_stack.hci_cmd_buffer; 32102ea9861Smatthias.ringwald hci_cmd_buffer[0] = cmd->opcode & 0xff; 32202ea9861Smatthias.ringwald hci_cmd_buffer[1] = cmd->opcode >> 8; 32393b8dc03Smatthias.ringwald int pos = 3; 32493b8dc03Smatthias.ringwald 32593b8dc03Smatthias.ringwald va_list argptr; 32693b8dc03Smatthias.ringwald va_start(argptr, cmd); 32793b8dc03Smatthias.ringwald const char *format = cmd->format; 32893b8dc03Smatthias.ringwald uint16_t word; 32993b8dc03Smatthias.ringwald uint32_t longword; 3303091b266Smatthias.ringwald uint8_t * ptr; 33193b8dc03Smatthias.ringwald while (*format) { 33293b8dc03Smatthias.ringwald switch(*format) { 33393b8dc03Smatthias.ringwald case '1': // 8 bit value 33493b8dc03Smatthias.ringwald case '2': // 16 bit value 33593b8dc03Smatthias.ringwald case 'H': // hci_handle 336554588a5Smatthias.ringwald word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs 33702ea9861Smatthias.ringwald hci_cmd_buffer[pos++] = word & 0xff; 33893b8dc03Smatthias.ringwald if (*format == '2') { 33902ea9861Smatthias.ringwald hci_cmd_buffer[pos++] = word >> 8; 34093b8dc03Smatthias.ringwald } else if (*format == 'H') { 341554588a5Smatthias.ringwald // TODO 34293b8dc03Smatthias.ringwald } 34393b8dc03Smatthias.ringwald break; 34493b8dc03Smatthias.ringwald case '3': 34593b8dc03Smatthias.ringwald case '4': 34693b8dc03Smatthias.ringwald longword = va_arg(argptr, uint32_t); 34793b8dc03Smatthias.ringwald // longword = va_arg(argptr, int); 34802ea9861Smatthias.ringwald hci_cmd_buffer[pos++] = longword; 34902ea9861Smatthias.ringwald hci_cmd_buffer[pos++] = longword >> 8; 35002ea9861Smatthias.ringwald hci_cmd_buffer[pos++] = longword >> 16; 35193b8dc03Smatthias.ringwald if (*format == '4'){ 35202ea9861Smatthias.ringwald hci_cmd_buffer[pos++] = longword >> 24; 35393b8dc03Smatthias.ringwald } 35493b8dc03Smatthias.ringwald break; 35593b8dc03Smatthias.ringwald case 'B': // bt-addr 3563091b266Smatthias.ringwald ptr = va_arg(argptr, uint8_t *); 3573091b266Smatthias.ringwald hci_cmd_buffer[pos++] = ptr[5]; 3583091b266Smatthias.ringwald hci_cmd_buffer[pos++] = ptr[4]; 3593091b266Smatthias.ringwald hci_cmd_buffer[pos++] = ptr[3]; 3603091b266Smatthias.ringwald hci_cmd_buffer[pos++] = ptr[2]; 3613091b266Smatthias.ringwald hci_cmd_buffer[pos++] = ptr[1]; 3623091b266Smatthias.ringwald hci_cmd_buffer[pos++] = ptr[0]; 3633091b266Smatthias.ringwald break; 3643091b266Smatthias.ringwald case 'P': // c string passed as pascal string with leading 1-byte len 3653091b266Smatthias.ringwald ptr = va_arg(argptr, uint8_t *); 3663091b266Smatthias.ringwald memcpy(&hci_cmd_buffer[pos], ptr, 16); 3673091b266Smatthias.ringwald pos += 16; 36893b8dc03Smatthias.ringwald break; 36993b8dc03Smatthias.ringwald default: 37093b8dc03Smatthias.ringwald break; 37193b8dc03Smatthias.ringwald } 37293b8dc03Smatthias.ringwald format++; 37393b8dc03Smatthias.ringwald }; 37493b8dc03Smatthias.ringwald va_end(argptr); 37502ea9861Smatthias.ringwald hci_cmd_buffer[2] = pos - 3; 37602ea9861Smatthias.ringwald // send packet 3773429f56bSmatthias.ringwald hci_stack.num_cmd_packets--; 37816833f0aSmatthias.ringwald return hci_stack.hci_transport->send_cmd_packet(hci_cmd_buffer, pos); 37993b8dc03Smatthias.ringwald }