132c01b55SOliver Ruiz Dorantes /* 232c01b55SOliver Ruiz Dorantes * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 36e82afccSOliver Ruiz Dorantes * Copyright 2008 Mika Lindqvist 432c01b55SOliver Ruiz Dorantes * All rights reserved. Distributed under the terms of the MIT License. 532c01b55SOliver Ruiz Dorantes */ 632c01b55SOliver Ruiz Dorantes 732c01b55SOliver Ruiz Dorantes #include "CommandManager.h" 832c01b55SOliver Ruiz Dorantes 932c01b55SOliver Ruiz Dorantes inline void* buildCommand(uint8 ogf, uint8 ocf, void** param, size_t psize, size_t* outsize) 1032c01b55SOliver Ruiz Dorantes { 1132c01b55SOliver Ruiz Dorantes struct hci_command_header* header; 1232c01b55SOliver Ruiz Dorantes 1332c01b55SOliver Ruiz Dorantes #ifdef BT_IOCTLS_PASS_SIZE 1432c01b55SOliver Ruiz Dorantes header = (struct hci_command_header*) malloc(psize + sizeof(struct hci_command_header)); 1532c01b55SOliver Ruiz Dorantes *outsize = psize + sizeof(struct hci_command_header); 1632c01b55SOliver Ruiz Dorantes #else 1732c01b55SOliver Ruiz Dorantes size_t* size = (size_t*)malloc(psize + sizeof(struct hci_command_header) + sizeof(size_t)); 1832c01b55SOliver Ruiz Dorantes *outsize = psize + sizeof(struct hci_command_header) + sizeof(size_t); 1932c01b55SOliver Ruiz Dorantes 2032c01b55SOliver Ruiz Dorantes *size = psize + sizeof(struct hci_command_header); 2132c01b55SOliver Ruiz Dorantes header = (struct hci_command_header*) (((uint8*)size)+4); 2232c01b55SOliver Ruiz Dorantes #endif 2332c01b55SOliver Ruiz Dorantes 2432c01b55SOliver Ruiz Dorantes 2532c01b55SOliver Ruiz Dorantes if (header != NULL) { 2632c01b55SOliver Ruiz Dorantes 2732c01b55SOliver Ruiz Dorantes header->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf)); 2832c01b55SOliver Ruiz Dorantes header->clen = psize; 2932c01b55SOliver Ruiz Dorantes 3032c01b55SOliver Ruiz Dorantes if (param != NULL && psize != 0) { 3132c01b55SOliver Ruiz Dorantes *param = ((uint8*)header) + sizeof(struct hci_command_header); 3232c01b55SOliver Ruiz Dorantes } 3332c01b55SOliver Ruiz Dorantes } 3432c01b55SOliver Ruiz Dorantes #ifdef BT_IOCTLS_PASS_SIZE 3532c01b55SOliver Ruiz Dorantes return header; 3632c01b55SOliver Ruiz Dorantes #else 3732c01b55SOliver Ruiz Dorantes return (void*)size; 3832c01b55SOliver Ruiz Dorantes #endif 3932c01b55SOliver Ruiz Dorantes } 4032c01b55SOliver Ruiz Dorantes 4132c01b55SOliver Ruiz Dorantes 4232c01b55SOliver Ruiz Dorantes #if 0 4332c01b55SOliver Ruiz Dorantes #pragma mark - CONTROL BASEBAND - 4432c01b55SOliver Ruiz Dorantes #endif 4532c01b55SOliver Ruiz Dorantes 4632c01b55SOliver Ruiz Dorantes 4732c01b55SOliver Ruiz Dorantes void* buildReset(size_t* outsize) 4832c01b55SOliver Ruiz Dorantes { 4932c01b55SOliver Ruiz Dorantes return buildCommand(OGF_CONTROL_BASEBAND, OCF_RESET, NULL, 0, outsize); 5032c01b55SOliver Ruiz Dorantes } 5132c01b55SOliver Ruiz Dorantes 5232c01b55SOliver Ruiz Dorantes 5332c01b55SOliver Ruiz Dorantes void* buildReadLocalName(size_t* outsize) 5432c01b55SOliver Ruiz Dorantes { 5532c01b55SOliver Ruiz Dorantes return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME, NULL, 0, outsize); 5632c01b55SOliver Ruiz Dorantes } 5732c01b55SOliver Ruiz Dorantes 5832c01b55SOliver Ruiz Dorantes 59a2f8edf7SOliver Ruiz Dorantes void* buildReadClassOfDevice(size_t* outsize) 60a2f8edf7SOliver Ruiz Dorantes { 61a2f8edf7SOliver Ruiz Dorantes return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV, NULL, 0, outsize); 62a2f8edf7SOliver Ruiz Dorantes } 63a2f8edf7SOliver Ruiz Dorantes 64a2f8edf7SOliver Ruiz Dorantes 65631aa548SOliver Ruiz Dorantes void* buildWriteScan(uint8 scanmode, size_t* outsize) 66631aa548SOliver Ruiz Dorantes { 67631aa548SOliver Ruiz Dorantes struct hci_write_scan_enable* param; 68631aa548SOliver Ruiz Dorantes void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE, (void**) ¶m, sizeof(struct hci_write_scan_enable), outsize); 69631aa548SOliver Ruiz Dorantes 70631aa548SOliver Ruiz Dorantes 71631aa548SOliver Ruiz Dorantes if (command != NULL) { 72631aa548SOliver Ruiz Dorantes param->scan = scanmode; 73631aa548SOliver Ruiz Dorantes } 74631aa548SOliver Ruiz Dorantes 75631aa548SOliver Ruiz Dorantes return command; 76631aa548SOliver Ruiz Dorantes 77631aa548SOliver Ruiz Dorantes } 78631aa548SOliver Ruiz Dorantes 79631aa548SOliver Ruiz Dorantes 80631aa548SOliver Ruiz Dorantes void* buildAuthEnable(uint8 auth, size_t* outsize) 81631aa548SOliver Ruiz Dorantes { 82631aa548SOliver Ruiz Dorantes struct hci_write_authentication_enable* param; 83631aa548SOliver Ruiz Dorantes void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_AUTH_ENABLE, (void**) ¶m, sizeof(struct hci_write_authentication_enable), outsize); 84631aa548SOliver Ruiz Dorantes 85631aa548SOliver Ruiz Dorantes 86631aa548SOliver Ruiz Dorantes if (command != NULL) { 87631aa548SOliver Ruiz Dorantes param->authentication = auth; 88631aa548SOliver Ruiz Dorantes } 89631aa548SOliver Ruiz Dorantes 90631aa548SOliver Ruiz Dorantes return command; 91631aa548SOliver Ruiz Dorantes 92631aa548SOliver Ruiz Dorantes } 93631aa548SOliver Ruiz Dorantes 94631aa548SOliver Ruiz Dorantes 9532c01b55SOliver Ruiz Dorantes #if 0 9632c01b55SOliver Ruiz Dorantes #pragma mark - LINK CONTROL - 9732c01b55SOliver Ruiz Dorantes #endif 9832c01b55SOliver Ruiz Dorantes 997434b760SOliver Ruiz Dorantes 100631aa548SOliver Ruiz Dorantes void* buildCreateConnection(bdaddr_t bdaddr) 101631aa548SOliver Ruiz Dorantes { 102631aa548SOliver Ruiz Dorantes /* 103631aa548SOliver Ruiz Dorantes cm4.size = sizeof(struct hci_command_header)+sizeof(struct hci_cp_create_conn); 104631aa548SOliver Ruiz Dorantes cm4.header.opcode = B_HOST_TO_LENDIAN_INT16(hci_opcode_pack(OGF_LINK_CONTROL, OCF_CREATE_CONN)); 105631aa548SOliver Ruiz Dorantes cm4.body.bdaddr.b[0] = 0x92; 106631aa548SOliver Ruiz Dorantes cm4.body.bdaddr.b[1] = 0xd3; 107631aa548SOliver Ruiz Dorantes cm4.body.bdaddr.b[2] = 0xaf; 108631aa548SOliver Ruiz Dorantes cm4.body.bdaddr.b[3] = 0xd9; 109631aa548SOliver Ruiz Dorantes cm4.body.bdaddr.b[4] = 0x0a; 110631aa548SOliver Ruiz Dorantes cm4.body.bdaddr.b[5] = 0x00; 111631aa548SOliver Ruiz Dorantes cm4.body.pkt_type = 0xFFFF; 112631aa548SOliver Ruiz Dorantes cm4.body.pscan_rep_mode = 1; 113631aa548SOliver Ruiz Dorantes cm4.body.pscan_mode = 0; 114631aa548SOliver Ruiz Dorantes cm4.body.clock_offset = 0xc7; 115631aa548SOliver Ruiz Dorantes cm4.body.role_switch = 1; 116631aa548SOliver Ruiz Dorantes cm4.header.clen = 13; 117631aa548SOliver Ruiz Dorantes ioctl(fd1, ISSUE_BT_COMMAND, &cm4, sizeof(cm4)); 118631aa548SOliver Ruiz Dorantes */ 119631aa548SOliver Ruiz Dorantes 120631aa548SOliver Ruiz Dorantes return NULL; 121631aa548SOliver Ruiz Dorantes } 122631aa548SOliver Ruiz Dorantes 12332c01b55SOliver Ruiz Dorantes 12432c01b55SOliver Ruiz Dorantes void* buildRemoteNameRequest(bdaddr_t bdaddr,uint8 pscan_rep_mode, uint16 clock_offset, size_t* outsize) 12532c01b55SOliver Ruiz Dorantes { 12632c01b55SOliver Ruiz Dorantes 12732c01b55SOliver Ruiz Dorantes struct hci_remote_name_request* param; 12832c01b55SOliver Ruiz Dorantes void* command = buildCommand(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST, (void**) ¶m, sizeof(struct hci_remote_name_request), outsize); 12932c01b55SOliver Ruiz Dorantes 13032c01b55SOliver Ruiz Dorantes if (command != NULL) { 13132c01b55SOliver Ruiz Dorantes param->bdaddr = bdaddr; 13232c01b55SOliver Ruiz Dorantes param->pscan_rep_mode = pscan_rep_mode; 13332c01b55SOliver Ruiz Dorantes param->clock_offset = clock_offset; 13432c01b55SOliver Ruiz Dorantes } 13532c01b55SOliver Ruiz Dorantes 13632c01b55SOliver Ruiz Dorantes return command; 13732c01b55SOliver Ruiz Dorantes } 13832c01b55SOliver Ruiz Dorantes 13932c01b55SOliver Ruiz Dorantes 14032c01b55SOliver Ruiz Dorantes void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize) 14132c01b55SOliver Ruiz Dorantes { 14232c01b55SOliver Ruiz Dorantes 14332c01b55SOliver Ruiz Dorantes struct hci_cp_inquiry* param; 14432c01b55SOliver Ruiz Dorantes void* command = buildCommand(OGF_LINK_CONTROL, OCF_INQUIRY, (void**) ¶m, sizeof(struct hci_cp_inquiry), outsize); 14532c01b55SOliver Ruiz Dorantes 14632c01b55SOliver Ruiz Dorantes if (command != NULL) { 14732c01b55SOliver Ruiz Dorantes 14832c01b55SOliver Ruiz Dorantes param->lap[2] = (lap >> 16) & 0xFF; 14932c01b55SOliver Ruiz Dorantes param->lap[1] = (lap >> 8) & 0xFF; 15032c01b55SOliver Ruiz Dorantes param->lap[0] = (lap >> 0) & 0xFF; 15132c01b55SOliver Ruiz Dorantes param->length = length; 15232c01b55SOliver Ruiz Dorantes param->num_rsp = num_rsp; 153350458a6SOliver Ruiz Dorantes } 154350458a6SOliver Ruiz Dorantes 155350458a6SOliver Ruiz Dorantes return command; 156350458a6SOliver Ruiz Dorantes } 157350458a6SOliver Ruiz Dorantes 1587434b760SOliver Ruiz Dorantes 159350458a6SOliver Ruiz Dorantes void* buildInquiryCancel(size_t* outsize) 160350458a6SOliver Ruiz Dorantes { 161350458a6SOliver Ruiz Dorantes 162350458a6SOliver Ruiz Dorantes return buildCommand(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL, NULL, 0, outsize); 163350458a6SOliver Ruiz Dorantes 164350458a6SOliver Ruiz Dorantes } 165350458a6SOliver Ruiz Dorantes 166350458a6SOliver Ruiz Dorantes 167350458a6SOliver Ruiz Dorantes void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16], size_t* outsize) 168350458a6SOliver Ruiz Dorantes { 169350458a6SOliver Ruiz Dorantes 170350458a6SOliver Ruiz Dorantes struct hci_cp_pin_code_reply* param; 171350458a6SOliver Ruiz Dorantes 172350458a6SOliver Ruiz Dorantes if (length > HCI_PIN_SIZE) // PinCode cannot be longer than 16 173350458a6SOliver Ruiz Dorantes return NULL; 174350458a6SOliver Ruiz Dorantes 175350458a6SOliver Ruiz Dorantes void* command = buildCommand(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY, (void**) ¶m, sizeof(struct hci_cp_pin_code_reply), outsize); 176350458a6SOliver Ruiz Dorantes 177350458a6SOliver Ruiz Dorantes if (command != NULL) { 178350458a6SOliver Ruiz Dorantes 179350458a6SOliver Ruiz Dorantes param->bdaddr = bdaddr; 180350458a6SOliver Ruiz Dorantes param->pin_len = length; 181350458a6SOliver Ruiz Dorantes memcpy(¶m->pin_code, pincode, length); 182350458a6SOliver Ruiz Dorantes 183350458a6SOliver Ruiz Dorantes } 184350458a6SOliver Ruiz Dorantes 185350458a6SOliver Ruiz Dorantes return command; 186350458a6SOliver Ruiz Dorantes } 187350458a6SOliver Ruiz Dorantes 188350458a6SOliver Ruiz Dorantes 1890df89492SOliver Ruiz Dorantes void* buildPinCodeRequestNegativeReply(bdaddr_t bdaddr, size_t* outsize) 190350458a6SOliver Ruiz Dorantes { 191350458a6SOliver Ruiz Dorantes 192350458a6SOliver Ruiz Dorantes struct hci_cp_pin_code_neg_reply* param; 193350458a6SOliver Ruiz Dorantes 194350458a6SOliver Ruiz Dorantes void* command = buildCommand(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY, 195350458a6SOliver Ruiz Dorantes (void**) ¶m, sizeof(struct hci_cp_pin_code_neg_reply), outsize); 196350458a6SOliver Ruiz Dorantes 197350458a6SOliver Ruiz Dorantes if (command != NULL) { 198350458a6SOliver Ruiz Dorantes 199350458a6SOliver Ruiz Dorantes param->bdaddr = bdaddr; 200350458a6SOliver Ruiz Dorantes 20132c01b55SOliver Ruiz Dorantes } 20232c01b55SOliver Ruiz Dorantes 20332c01b55SOliver Ruiz Dorantes return command; 20432c01b55SOliver Ruiz Dorantes } 20532c01b55SOliver Ruiz Dorantes 20632c01b55SOliver Ruiz Dorantes 2077434b760SOliver Ruiz Dorantes void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role, size_t* outsize) 2087434b760SOliver Ruiz Dorantes { 2097434b760SOliver Ruiz Dorantes struct hci_cp_accept_conn_req* param; 2107434b760SOliver Ruiz Dorantes 2117434b760SOliver Ruiz Dorantes void* command = buildCommand(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ, 2127434b760SOliver Ruiz Dorantes (void**) ¶m, sizeof(struct hci_cp_accept_conn_req), outsize); 2137434b760SOliver Ruiz Dorantes 2147434b760SOliver Ruiz Dorantes if (command != NULL) { 2157434b760SOliver Ruiz Dorantes param->bdaddr = bdaddr; 2167434b760SOliver Ruiz Dorantes param->role = role; 2177434b760SOliver Ruiz Dorantes } 2187434b760SOliver Ruiz Dorantes 2197434b760SOliver Ruiz Dorantes return command; 2207434b760SOliver Ruiz Dorantes } 2217434b760SOliver Ruiz Dorantes 2227434b760SOliver Ruiz Dorantes 2237434b760SOliver Ruiz Dorantes void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize) 2247434b760SOliver Ruiz Dorantes { 2257434b760SOliver Ruiz Dorantes struct hci_cp_reject_conn_req* param; 2267434b760SOliver Ruiz Dorantes 2277434b760SOliver Ruiz Dorantes void *command = buildCommand(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ, 2287434b760SOliver Ruiz Dorantes (void**) ¶m, sizeof(struct hci_cp_reject_conn_req), outsize); 2297434b760SOliver Ruiz Dorantes 2307434b760SOliver Ruiz Dorantes if (command != NULL) { 2317434b760SOliver Ruiz Dorantes param->bdaddr = bdaddr; 2327434b760SOliver Ruiz Dorantes } 2337434b760SOliver Ruiz Dorantes 2347434b760SOliver Ruiz Dorantes return command; 2357434b760SOliver Ruiz Dorantes } 2367434b760SOliver Ruiz Dorantes 2377434b760SOliver Ruiz Dorantes 23832c01b55SOliver Ruiz Dorantes #if 0 23932c01b55SOliver Ruiz Dorantes #pragma mark - INFORMATIONAL_PARAM - 24032c01b55SOliver Ruiz Dorantes #endif 24132c01b55SOliver Ruiz Dorantes 242b44ee583SOliver Ruiz Dorantes void* buildReadLocalVersionInformation(size_t* outsize) 243b44ee583SOliver Ruiz Dorantes { 244b44ee583SOliver Ruiz Dorantes return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION, NULL, 0, outsize); 245b44ee583SOliver Ruiz Dorantes } 246b44ee583SOliver Ruiz Dorantes 24732c01b55SOliver Ruiz Dorantes 24832c01b55SOliver Ruiz Dorantes void* buildReadBufferSize(size_t* outsize) 24932c01b55SOliver Ruiz Dorantes { 25032c01b55SOliver Ruiz Dorantes return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE, NULL, 0, outsize); 25132c01b55SOliver Ruiz Dorantes } 25232c01b55SOliver Ruiz Dorantes 25332c01b55SOliver Ruiz Dorantes 25432c01b55SOliver Ruiz Dorantes void* buildReadBdAddr(size_t* outsize) 25532c01b55SOliver Ruiz Dorantes { 25632c01b55SOliver Ruiz Dorantes return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR, NULL, 0, outsize); 25732c01b55SOliver Ruiz Dorantes } 258631aa548SOliver Ruiz Dorantes 259631aa548SOliver Ruiz Dorantes 260a7c3c465SOliver Ruiz Dorantes const char* bluetoothManufacturers[] = { 261a7c3c465SOliver Ruiz Dorantes "Ericsson Technology Licensing", 262a7c3c465SOliver Ruiz Dorantes "Nokia Mobile Phones", 263a7c3c465SOliver Ruiz Dorantes "Intel Corp.", 264a7c3c465SOliver Ruiz Dorantes "IBM Corp.", 265a7c3c465SOliver Ruiz Dorantes "Toshiba Corp.", 266a7c3c465SOliver Ruiz Dorantes "3Com", 267a7c3c465SOliver Ruiz Dorantes "Microsoft", 268a7c3c465SOliver Ruiz Dorantes "Lucent", 269a7c3c465SOliver Ruiz Dorantes "Motorola", 270a7c3c465SOliver Ruiz Dorantes "Infineon Technologies AG", 271a7c3c465SOliver Ruiz Dorantes "Cambridge Silicon Radio", 272a7c3c465SOliver Ruiz Dorantes "Silicon Wave", 273a7c3c465SOliver Ruiz Dorantes "Digianswer A/S", 274a7c3c465SOliver Ruiz Dorantes "Texas Instruments Inc.", 275a7c3c465SOliver Ruiz Dorantes "Parthus Technologies Inc.", 276a7c3c465SOliver Ruiz Dorantes "Broadcom Corporation", 277a7c3c465SOliver Ruiz Dorantes "Mitel Semiconductor", 278a7c3c465SOliver Ruiz Dorantes "Widcomm, Inc.", 279a7c3c465SOliver Ruiz Dorantes "Zeevo, Inc.", 280a7c3c465SOliver Ruiz Dorantes "Atmel Corporation", 281a7c3c465SOliver Ruiz Dorantes "Mitsubishi Electric Corporation", 282a7c3c465SOliver Ruiz Dorantes "RTX Telecom A/S", 283a7c3c465SOliver Ruiz Dorantes "KC Technology Inc.", 284a7c3c465SOliver Ruiz Dorantes "Newlogic", 285a7c3c465SOliver Ruiz Dorantes "Transilica, Inc.", 286a7c3c465SOliver Ruiz Dorantes "Rohde & Schwartz GmbH & Co. KG", 287a7c3c465SOliver Ruiz Dorantes "TTPCom Limited", 288a7c3c465SOliver Ruiz Dorantes "Signia Technologies, Inc.", 289a7c3c465SOliver Ruiz Dorantes "Conexant Systems Inc.", 290a7c3c465SOliver Ruiz Dorantes "Qualcomm", 291a7c3c465SOliver Ruiz Dorantes "Inventel", 292a7c3c465SOliver Ruiz Dorantes "AVM Berlin", 293a7c3c465SOliver Ruiz Dorantes "BandSpeed, Inc.", 294a7c3c465SOliver Ruiz Dorantes "Mansella Ltd", 295a7c3c465SOliver Ruiz Dorantes "NEC Corporation", 296a7c3c465SOliver Ruiz Dorantes "WavePlus Technology Co., Ltd.", 297a7c3c465SOliver Ruiz Dorantes "Alcatel", 298a7c3c465SOliver Ruiz Dorantes "Philips Semiconductors", 299a7c3c465SOliver Ruiz Dorantes "C Technologies", 300a7c3c465SOliver Ruiz Dorantes "Open Interface", 301a7c3c465SOliver Ruiz Dorantes "R F Micro Devices", 302a7c3c465SOliver Ruiz Dorantes "Hitachi Ltd", 303a7c3c465SOliver Ruiz Dorantes "Symbol Technologies, Inc.", 304a7c3c465SOliver Ruiz Dorantes "Tenovis", 305a7c3c465SOliver Ruiz Dorantes "Macronix International Co. Ltd.", 306a7c3c465SOliver Ruiz Dorantes "GCT Semiconductor", 307a7c3c465SOliver Ruiz Dorantes "Norwood Systems", 308a7c3c465SOliver Ruiz Dorantes "MewTel Technology Inc.", 309a7c3c465SOliver Ruiz Dorantes "ST Microelectronics", 310a7c3c465SOliver Ruiz Dorantes "Synopsys", 311a7c3c465SOliver Ruiz Dorantes "Red-M (Communications) Ltd", 312a7c3c465SOliver Ruiz Dorantes "Commil Ltd", 313a7c3c465SOliver Ruiz Dorantes "Computer Access Technology Corporation (CATC)", 314b3064a44SOliver Ruiz Dorantes "Eclipse (HQ España) S.L.", 315a7c3c465SOliver Ruiz Dorantes "Renesas Technology Corp.", 316a7c3c465SOliver Ruiz Dorantes "Mobilian Corporation", 317a7c3c465SOliver Ruiz Dorantes "Terax", 3183c2f52adSOliver Ruiz Dorantes "Integrated System Solution Corp.", 319a7c3c465SOliver Ruiz Dorantes "Matsushita Electric Industrial Co., Ltd.", 320a7c3c465SOliver Ruiz Dorantes "Gennum Corporation", 321a7c3c465SOliver Ruiz Dorantes "Research In Motion", 322a7c3c465SOliver Ruiz Dorantes "IPextreme, Inc.", 323a7c3c465SOliver Ruiz Dorantes "Systems and Chips, Inc", 324a7c3c465SOliver Ruiz Dorantes "Bluetooth SIG, Inc", 325a7c3c465SOliver Ruiz Dorantes "Seiko Epson Corporation", 326a7c3c465SOliver Ruiz Dorantes "Integrated Silicon Solution Taiwain, Inc.", 327a7c3c465SOliver Ruiz Dorantes "CONWISE Technology Corporation Ltd", 328b3064a44SOliver Ruiz Dorantes "PARROT SA", 329a7c3c465SOliver Ruiz Dorantes "Socket Communications", 330a7c3c465SOliver Ruiz Dorantes "Atheros Communications, Inc.", 331a7c3c465SOliver Ruiz Dorantes "MediaTek, Inc.", 332a7c3c465SOliver Ruiz Dorantes "Bluegiga", /* (tentative) */ 333a7c3c465SOliver Ruiz Dorantes "Marvell Technology Group Ltd.", 334a7c3c465SOliver Ruiz Dorantes "3DSP Corporation", 335a7c3c465SOliver Ruiz Dorantes "Accel Semiconductor Ltd.", 336a7c3c465SOliver Ruiz Dorantes "Continental Automotive Systems", 337a7c3c465SOliver Ruiz Dorantes "Apple, Inc.", 338a7c3c465SOliver Ruiz Dorantes "Staccato Communications, Inc." 339a7c3c465SOliver Ruiz Dorantes }; 340631aa548SOliver Ruiz Dorantes 341631aa548SOliver Ruiz Dorantes 342a7c3c465SOliver Ruiz Dorantes const char* linkControlCommands[] = { 343a7c3c465SOliver Ruiz Dorantes "Inquiry", 344a7c3c465SOliver Ruiz Dorantes "Inquiry Cancel", 345a7c3c465SOliver Ruiz Dorantes "Periodic Inquiry Mode", 346a7c3c465SOliver Ruiz Dorantes "Exit Periodic Inquiry Mode", 347a7c3c465SOliver Ruiz Dorantes "Create Connection", 348a7c3c465SOliver Ruiz Dorantes "Disconnect", 349a7c3c465SOliver Ruiz Dorantes "Add SCO Connection", // not on 2.1 350a7c3c465SOliver Ruiz Dorantes "Cancel Create Connection", 351a7c3c465SOliver Ruiz Dorantes "Accept Connection Request", 352a7c3c465SOliver Ruiz Dorantes "Reject Connection Request", 353a7c3c465SOliver Ruiz Dorantes "Link Key Request Reply", 354a7c3c465SOliver Ruiz Dorantes "Link Key Request Negative Reply", 355a7c3c465SOliver Ruiz Dorantes "PIN Code Request Reply", 356a7c3c465SOliver Ruiz Dorantes "PIN Code Request Negative Reply", 357a7c3c465SOliver Ruiz Dorantes "Change Connection Packet Type", 358b3064a44SOliver Ruiz Dorantes "Reserved", // not on 2.1", 359a7c3c465SOliver Ruiz Dorantes "Authentication Requested", 360b3064a44SOliver Ruiz Dorantes "Reserved", // not on 2.1", 361a7c3c465SOliver Ruiz Dorantes "Set Connection Encryption", 362b3064a44SOliver Ruiz Dorantes "Reserved", // not on 2.1", 363a7c3c465SOliver Ruiz Dorantes "Change Connection Link Key", 364b3064a44SOliver Ruiz Dorantes "Reserved", // not on 2.1", 365a7c3c465SOliver Ruiz Dorantes "Master Link Key", 366b3064a44SOliver Ruiz Dorantes "Reserved", // not on 2.1", 367a7c3c465SOliver Ruiz Dorantes "Remote Name Request", 368a7c3c465SOliver Ruiz Dorantes "Cancel Remote Name Request", 369a7c3c465SOliver Ruiz Dorantes "Read Remote Supported Features", 370a7c3c465SOliver Ruiz Dorantes "Read Remote Extended Features", 371a7c3c465SOliver Ruiz Dorantes "Read Remote Version Information", 372b3064a44SOliver Ruiz Dorantes "Reserved", // not on 2.1", 373a7c3c465SOliver Ruiz Dorantes "Read Clock Offset", 374a7c3c465SOliver Ruiz Dorantes "Read LMP Handle", 375a7c3c465SOliver Ruiz Dorantes "Reserved", 376a7c3c465SOliver Ruiz Dorantes "Reserved", 377a7c3c465SOliver Ruiz Dorantes "Reserved", 378a7c3c465SOliver Ruiz Dorantes "Reserved", 379a7c3c465SOliver Ruiz Dorantes "Reserved", 380a7c3c465SOliver Ruiz Dorantes "Reserved", 381a7c3c465SOliver Ruiz Dorantes "Reserved", 382a7c3c465SOliver Ruiz Dorantes "Setup Synchronous Connection", 383a7c3c465SOliver Ruiz Dorantes "Accept Synchronous Connection", 384a7c3c465SOliver Ruiz Dorantes "Reject Synchronous Connection", 385a7c3c465SOliver Ruiz Dorantes "IO Capability Request Reply", 386a7c3c465SOliver Ruiz Dorantes "User Confirmation Request Reply", 387a7c3c465SOliver Ruiz Dorantes "User Confirmation Request Negative Reply", 388a7c3c465SOliver Ruiz Dorantes "User Passkey Request Reply", 389a7c3c465SOliver Ruiz Dorantes "User Passkey Request Negative Reply", 390a7c3c465SOliver Ruiz Dorantes "Remote OOB Data Request Reply", 391a7c3c465SOliver Ruiz Dorantes "Reserved", 392a7c3c465SOliver Ruiz Dorantes "Reserved", 393a7c3c465SOliver Ruiz Dorantes "Remote OOB Data Request Negative Reply", 394a7c3c465SOliver Ruiz Dorantes "IO Capabilities Response Negative Reply" 395a7c3c465SOliver Ruiz Dorantes }; 396a7c3c465SOliver Ruiz Dorantes 397a7c3c465SOliver Ruiz Dorantes 398a7c3c465SOliver Ruiz Dorantes const char* linkPolicyCommands[] = { 399a7c3c465SOliver Ruiz Dorantes "Hold Mode", 400a7c3c465SOliver Ruiz Dorantes "Reserved", 401a7c3c465SOliver Ruiz Dorantes "Sniff Mode", 402a7c3c465SOliver Ruiz Dorantes "Exit Sniff Mode", 403a7c3c465SOliver Ruiz Dorantes "Park State", 404a7c3c465SOliver Ruiz Dorantes "Exit Park State", 405a7c3c465SOliver Ruiz Dorantes "QoS Setup", 406a7c3c465SOliver Ruiz Dorantes "Reserved", 407a7c3c465SOliver Ruiz Dorantes "Role Discovery", 408a7c3c465SOliver Ruiz Dorantes "Reserved", 409a7c3c465SOliver Ruiz Dorantes "Switch Role", 410a7c3c465SOliver Ruiz Dorantes "Read Link Policy Settings", 411a7c3c465SOliver Ruiz Dorantes "Write Link Policy Settings", 412a7c3c465SOliver Ruiz Dorantes "Read Default Link Policy Settings", 413a7c3c465SOliver Ruiz Dorantes "Write Default Link Policy Settings", 414a7c3c465SOliver Ruiz Dorantes "Flow Specification", 415a7c3c465SOliver Ruiz Dorantes "Sniff Subrating" 416a7c3c465SOliver Ruiz Dorantes }; 417a7c3c465SOliver Ruiz Dorantes 418a7c3c465SOliver Ruiz Dorantes 419a7c3c465SOliver Ruiz Dorantes const char* controllerBasebandCommands[] = { 420a7c3c465SOliver Ruiz Dorantes "Set Event Mask", 421a7c3c465SOliver Ruiz Dorantes "Reserved", 422a7c3c465SOliver Ruiz Dorantes "Reset", 423a7c3c465SOliver Ruiz Dorantes "Reserved", 424a7c3c465SOliver Ruiz Dorantes "Set Event Filter", 425a7c3c465SOliver Ruiz Dorantes "Reserved", 426a7c3c465SOliver Ruiz Dorantes "Reserved", 427a7c3c465SOliver Ruiz Dorantes "Flush", 428a7c3c465SOliver Ruiz Dorantes "Read PIN Type", 429a7c3c465SOliver Ruiz Dorantes "Write PIN Type", 430a7c3c465SOliver Ruiz Dorantes "Create New Unit Key", 431a7c3c465SOliver Ruiz Dorantes "Reserved", 432a7c3c465SOliver Ruiz Dorantes "Read Stored Link Key", 433a7c3c465SOliver Ruiz Dorantes "Reserved", 434a7c3c465SOliver Ruiz Dorantes "Reserved", 435a7c3c465SOliver Ruiz Dorantes "Reserved", 436a7c3c465SOliver Ruiz Dorantes "Write Stored Link Key", 437a7c3c465SOliver Ruiz Dorantes "Delete Stored Link Key", 438a7c3c465SOliver Ruiz Dorantes "Write Local Name", 439a7c3c465SOliver Ruiz Dorantes "Read Local Name", 440a7c3c465SOliver Ruiz Dorantes "Read Connection Accept Timeout", 441a7c3c465SOliver Ruiz Dorantes "Write Connection Accept Timeout", 442a7c3c465SOliver Ruiz Dorantes "Read Page Timeout", 443a7c3c465SOliver Ruiz Dorantes "Write Page Timeout", 444a7c3c465SOliver Ruiz Dorantes "Read Scan Enable", 445a7c3c465SOliver Ruiz Dorantes "Write Scan Enable", 446a7c3c465SOliver Ruiz Dorantes "Read Page Scan Activity", 447a7c3c465SOliver Ruiz Dorantes "Write Page Scan Activity", 448a7c3c465SOliver Ruiz Dorantes "Read Inquiry Scan Activity", 449a7c3c465SOliver Ruiz Dorantes "Write Inquiry Scan Activity", 450a7c3c465SOliver Ruiz Dorantes "Read Authentication Enable", 451a7c3c465SOliver Ruiz Dorantes "Write Authentication Enable", 452a7c3c465SOliver Ruiz Dorantes "Read Encryption Mode", // not 2.1 453a7c3c465SOliver Ruiz Dorantes "Write Encryption Mode",// not 2.1 454a7c3c465SOliver Ruiz Dorantes "Read Class Of Device", 455a7c3c465SOliver Ruiz Dorantes "Write Class Of Device", 456a7c3c465SOliver Ruiz Dorantes "Read Voice Setting", 457a7c3c465SOliver Ruiz Dorantes "Write Voice Setting", 458a7c3c465SOliver Ruiz Dorantes "Read Automatic Flush Timeout", 459a7c3c465SOliver Ruiz Dorantes "Write Automatic Flush Timeout", 460a7c3c465SOliver Ruiz Dorantes "Read Num Broadcast Retransmissions", 461a7c3c465SOliver Ruiz Dorantes "Write Num Broadcast Retransmissions", 462a7c3c465SOliver Ruiz Dorantes "Read Hold Mode Activity", 463a7c3c465SOliver Ruiz Dorantes "Write Hold Mode Activity", 464a7c3c465SOliver Ruiz Dorantes "Read Transmit Power Level", 465a7c3c465SOliver Ruiz Dorantes "Read Synchronous Flow Control Enable", 466a7c3c465SOliver Ruiz Dorantes "Write Synchronous Flow Control Enable", 467a7c3c465SOliver Ruiz Dorantes "Reserved", 468a7c3c465SOliver Ruiz Dorantes "Set Host Controller To Host Flow Control", 469a7c3c465SOliver Ruiz Dorantes "Reserved", 470a7c3c465SOliver Ruiz Dorantes "Host Buffer Size", 471a7c3c465SOliver Ruiz Dorantes "Reserved", 472a7c3c465SOliver Ruiz Dorantes "Host Number Of Completed Packets", 473a7c3c465SOliver Ruiz Dorantes "Read Link Supervision Timeout", 474a7c3c465SOliver Ruiz Dorantes "Write Link Supervision Timeout", 475a7c3c465SOliver Ruiz Dorantes "Read Number of Supported IAC", 476a7c3c465SOliver Ruiz Dorantes "Read Current IAC LAP", 477a7c3c465SOliver Ruiz Dorantes "Write Current IAC LAP", 478a7c3c465SOliver Ruiz Dorantes "Read Page Scan Period Mode", // not 2.1 479a7c3c465SOliver Ruiz Dorantes "Write Page Scan Period Mode", // not 2.1 480a7c3c465SOliver Ruiz Dorantes "Read Page Scan Mode", // not 2.1 481a7c3c465SOliver Ruiz Dorantes "Write Page Scan Mode", // not 2.1 482a7c3c465SOliver Ruiz Dorantes "Set AFH Channel Classification", 483a7c3c465SOliver Ruiz Dorantes "Reserved", 484a7c3c465SOliver Ruiz Dorantes "Reserved", 485a7c3c465SOliver Ruiz Dorantes "Read Inquiry Scan Type", 486a7c3c465SOliver Ruiz Dorantes "Write Inquiry Scan Type", 487a7c3c465SOliver Ruiz Dorantes "Read Inquiry Mode", 488a7c3c465SOliver Ruiz Dorantes "Write Inquiry Mode", 489a7c3c465SOliver Ruiz Dorantes "Read Page Scan Type", 490a7c3c465SOliver Ruiz Dorantes "Write Page Scan Type", 491a7c3c465SOliver Ruiz Dorantes "Read AFH Channel Assessment Mode", 492a7c3c465SOliver Ruiz Dorantes "Write AFH Channel Assessment Mode", 493a7c3c465SOliver Ruiz Dorantes "Reserved", 494a7c3c465SOliver Ruiz Dorantes "Reserved", 495a7c3c465SOliver Ruiz Dorantes "Reserved", 496a7c3c465SOliver Ruiz Dorantes "Reserved", 497a7c3c465SOliver Ruiz Dorantes "Reserved", 498a7c3c465SOliver Ruiz Dorantes "Reserved", 499a7c3c465SOliver Ruiz Dorantes "Reserved", 500a7c3c465SOliver Ruiz Dorantes "Read Extended Inquiry Response", 501a7c3c465SOliver Ruiz Dorantes "Write Extended Inquiry Response", 502a7c3c465SOliver Ruiz Dorantes "Refresh Encryption Key", 503a7c3c465SOliver Ruiz Dorantes "Reserved", 504a7c3c465SOliver Ruiz Dorantes "Read Simple Pairing Mode", 505a7c3c465SOliver Ruiz Dorantes "Write Simple Pairing Mode", 506a7c3c465SOliver Ruiz Dorantes "Read Local OOB Data", 507a7c3c465SOliver Ruiz Dorantes "Read Inquiry Transmit Power Level", 508a7c3c465SOliver Ruiz Dorantes "Write Inquiry Transmit Power Level", 509a7c3c465SOliver Ruiz Dorantes "Read Default Erroneous Data Reporting", 510a7c3c465SOliver Ruiz Dorantes "Write Default Erroneous Data Reporting", 511a7c3c465SOliver Ruiz Dorantes "Reserved", 512a7c3c465SOliver Ruiz Dorantes "Reserved", 513a7c3c465SOliver Ruiz Dorantes "Reserved", 514a7c3c465SOliver Ruiz Dorantes "Enhanced Flush", 515a7c3c465SOliver Ruiz Dorantes "Send Keypress Notification" 516a7c3c465SOliver Ruiz Dorantes }; 517a7c3c465SOliver Ruiz Dorantes 518a7c3c465SOliver Ruiz Dorantes 519a7c3c465SOliver Ruiz Dorantes const char* informationalParametersCommands[] = { 520a7c3c465SOliver Ruiz Dorantes "Read Local Version Information", 521a7c3c465SOliver Ruiz Dorantes "Read Local Supported Commands", 522a7c3c465SOliver Ruiz Dorantes "Read Local Supported Features", 523a7c3c465SOliver Ruiz Dorantes "Read Local Extended Features", 524a7c3c465SOliver Ruiz Dorantes "Read Buffer Size", 525a7c3c465SOliver Ruiz Dorantes "Reserved", 526a7c3c465SOliver Ruiz Dorantes "Read Country Code", // not 2.1 527a7c3c465SOliver Ruiz Dorantes "Reserved", 528a7c3c465SOliver Ruiz Dorantes "Read BD ADDR" 529a7c3c465SOliver Ruiz Dorantes }; 530a7c3c465SOliver Ruiz Dorantes 531a7c3c465SOliver Ruiz Dorantes 532a7c3c465SOliver Ruiz Dorantes const char* statusParametersCommands[] = { 533a7c3c465SOliver Ruiz Dorantes "Read Failed Contact Counter", 534a7c3c465SOliver Ruiz Dorantes "Reset Failed Contact Counter", 535a7c3c465SOliver Ruiz Dorantes "Read Link Quality", 536a7c3c465SOliver Ruiz Dorantes "Reserved", 537a7c3c465SOliver Ruiz Dorantes "Read RSSI", 538a7c3c465SOliver Ruiz Dorantes "Read AFH Channel Map", 539a7c3c465SOliver Ruiz Dorantes "Read Clock", 540a7c3c465SOliver Ruiz Dorantes }; 541a7c3c465SOliver Ruiz Dorantes 542a7c3c465SOliver Ruiz Dorantes 543a7c3c465SOliver Ruiz Dorantes const char* testingCommands[] = { 544a7c3c465SOliver Ruiz Dorantes "Read Loopback Mode", 545a7c3c465SOliver Ruiz Dorantes "Write Loopback Mode", 546a7c3c465SOliver Ruiz Dorantes "Enable Device Under Test Mode", 547a7c3c465SOliver Ruiz Dorantes "Write Simple Pairing Debug Mode", 548a7c3c465SOliver Ruiz Dorantes }; 549a7c3c465SOliver Ruiz Dorantes 550a7c3c465SOliver Ruiz Dorantes 551*8dc33083SOliver Ruiz Dorantes const char* hciVersion[] = { "1.0B" , "1.1 " , "1.2 " , "2.0 " , "2.1 "}; 552*8dc33083SOliver Ruiz Dorantes const char* lmpVersion[] = { "1.0 " , "1.1 " , "1.2 " , "2.0 " , "2.1 "}; 553bd88ac97SOliver Ruiz Dorantes 554bd88ac97SOliver Ruiz Dorantes 555bd88ac97SOliver Ruiz Dorantes const char* 556bd88ac97SOliver Ruiz Dorantes GetHciVersion(uint16 ver) 557bd88ac97SOliver Ruiz Dorantes { 558bd88ac97SOliver Ruiz Dorantes return hciVersion[ver]; 559bd88ac97SOliver Ruiz Dorantes } 560bd88ac97SOliver Ruiz Dorantes 561bd88ac97SOliver Ruiz Dorantes 562bd88ac97SOliver Ruiz Dorantes const char* 563bd88ac97SOliver Ruiz Dorantes GetLmpVersion(uint16 ver) 564bd88ac97SOliver Ruiz Dorantes { 565bd88ac97SOliver Ruiz Dorantes return lmpVersion[ver]; 566bd88ac97SOliver Ruiz Dorantes } 567bd88ac97SOliver Ruiz Dorantes 568bd88ac97SOliver Ruiz Dorantes 569a7c3c465SOliver Ruiz Dorantes const char* 570a7c3c465SOliver Ruiz Dorantes GetCommand(uint16 command) 571a7c3c465SOliver Ruiz Dorantes { 57232261764SOliver Ruiz Dorantes 573a7c3c465SOliver Ruiz Dorantes // TODO: BT implementations beyond 2.1 574a7c3c465SOliver Ruiz Dorantes // could specify new commands with OCF numbers 575a7c3c465SOliver Ruiz Dorantes // beyond the boundaries of the arrays and crash. 576a7c3c465SOliver Ruiz Dorantes // But only our stack could issue them so its under 577a7c3c465SOliver Ruiz Dorantes // our control. 578a7c3c465SOliver Ruiz Dorantes switch (GET_OPCODE_OGF(command)) { 579a7c3c465SOliver Ruiz Dorantes case OGF_LINK_CONTROL: 58032261764SOliver Ruiz Dorantes return linkControlCommands[GET_OPCODE_OCF(command)-1]; 581a7c3c465SOliver Ruiz Dorantes break; 582a7c3c465SOliver Ruiz Dorantes 583a7c3c465SOliver Ruiz Dorantes case OGF_LINK_POLICY: 58432261764SOliver Ruiz Dorantes return linkPolicyCommands[GET_OPCODE_OCF(command)-1]; 585a7c3c465SOliver Ruiz Dorantes break; 586a7c3c465SOliver Ruiz Dorantes 587a7c3c465SOliver Ruiz Dorantes case OGF_CONTROL_BASEBAND: 58832261764SOliver Ruiz Dorantes return controllerBasebandCommands[GET_OPCODE_OCF(command)-1]; 589a7c3c465SOliver Ruiz Dorantes break; 590a7c3c465SOliver Ruiz Dorantes 591a7c3c465SOliver Ruiz Dorantes case OGF_INFORMATIONAL_PARAM: 59232261764SOliver Ruiz Dorantes return informationalParametersCommands[GET_OPCODE_OCF(command)-1]; 593a7c3c465SOliver Ruiz Dorantes break; 594a7c3c465SOliver Ruiz Dorantes 595a7c3c465SOliver Ruiz Dorantes case OGF_STATUS_PARAM: 59632261764SOliver Ruiz Dorantes return statusParametersCommands[GET_OPCODE_OCF(command)-1]; 597a7c3c465SOliver Ruiz Dorantes break; 598a7c3c465SOliver Ruiz Dorantes 599a7c3c465SOliver Ruiz Dorantes case OGF_TESTING_CMD: 60032261764SOliver Ruiz Dorantes return testingCommands[GET_OPCODE_OCF(command)-1]; 601a7c3c465SOliver Ruiz Dorantes break; 6020b5931e0SOliver Ruiz Dorantes case OGF_VENDOR_CMD: 6030b5931e0SOliver Ruiz Dorantes return "Vendor specific command"; 6040b5931e0SOliver Ruiz Dorantes break; 605a7c3c465SOliver Ruiz Dorantes default: 606a7c3c465SOliver Ruiz Dorantes return "Unknown command"; 607a7c3c465SOliver Ruiz Dorantes break; 608a7c3c465SOliver Ruiz Dorantes } 609a7c3c465SOliver Ruiz Dorantes 610a7c3c465SOliver Ruiz Dorantes } 611a7c3c465SOliver Ruiz Dorantes 612a7c3c465SOliver Ruiz Dorantes 613a7c3c465SOliver Ruiz Dorantes const char* 614a7c3c465SOliver Ruiz Dorantes GetManufacturer(uint16 manufacturer) { 615a7c3c465SOliver Ruiz Dorantes if (manufacturer < sizeof(bluetoothManufacturers)/sizeof(const char*)) { 616a7c3c465SOliver Ruiz Dorantes return bluetoothManufacturers[manufacturer]; 617a7c3c465SOliver Ruiz Dorantes } else if (manufacturer == 0xFFFF) { 618a7c3c465SOliver Ruiz Dorantes return "internal use"; 619a7c3c465SOliver Ruiz Dorantes } else { 620a7c3c465SOliver Ruiz Dorantes return "not assigned"; 621a7c3c465SOliver Ruiz Dorantes } 622a7c3c465SOliver Ruiz Dorantes } 623a7c3c465SOliver Ruiz Dorantes 624