- Introduce template methods for single or non parameter commands

- Remove some old legacy command creation functions



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36444 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2010-04-24 11:16:49 +00:00
parent 8e23974bbe
commit 40c666a5ab
2 changed files with 468 additions and 409 deletions
+56 -10
View File
@@ -6,17 +6,22 @@
#ifndef _COMMAND_MANAGER_H #ifndef _COMMAND_MANAGER_H
#define _COMMAND_MANAGER_H #define _COMMAND_MANAGER_H
#include <bluetooth/bluetooth.h>
#include <bluetooth/HCI/btHCI_command.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h>
#include <Message.h>
#include <Messenger.h>
#include <bluetoothserver_p.h>
#define typed_command(type) type, sizeof(type) #define typed_command(type) type, sizeof(type)
/* Experimental stack allocated alternative to build commands */ template <typename Type = void, int paramSize = 0,
template <typename Type = void, int paramSize = 0, int HeaderSize = HCI_COMMAND_HDR_SIZE> int HeaderSize = HCI_COMMAND_HDR_SIZE>
class BluetoothCommand { class BluetoothCommand {
public: public:
@@ -27,7 +32,8 @@ public:
if (paramSize != 0) if (paramSize != 0)
fContent = (Type*)(fHeader + 1); fContent = (Type*)(fHeader + 1);
else else
fContent = (Type*)fHeader; // avoid pointing outside in case of not having parameters // avoid pointing outside in case of not having parameters
fContent = (Type*)fHeader;
fHeader->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf)); fHeader->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf));
fHeader->clen = paramSize; fHeader->clen = paramSize;
@@ -56,20 +62,60 @@ private:
struct hci_command_header* fHeader; struct hci_command_header* fHeader;
}; };
status_t
NonParameterCommandRequest(uint8 ofg, uint8 ocf, int32* result, hci_id hId,
BMessenger* messenger);
template<typename PARAMETERCONTAINER, typename PARAMETERTYPE>
status_t
SingleParameterCommandRequest(uint8 ofg, uint8 ocf, PARAMETERTYPE parameter,
int32* result, hci_id hId, BMessenger* messenger)
{
int8 bt_status = BT_ERROR;
BluetoothCommand<typed_command(PARAMETERCONTAINER)>
simpleCommand(ofg, ocf);
simpleCommand->param = parameter;
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
simpleCommand->param = parameter;
request.AddInt32("hci_id", hId);
request.AddData("raw command", B_ANY_TYPE, simpleCommand.Data(),
simpleCommand.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(ofg, ocf));
if (messenger->SendMessage(&request, &reply) == B_OK) {
reply.FindInt8("status", &bt_status);
if (result != NULL)
reply.FindInt32("result", result);
}
return bt_status;
}
/* CONTROL BASEBAND */ /* CONTROL BASEBAND */
void* buildReset(size_t* outsize); void* buildReset(size_t* outsize);
void* buildReadLocalName(size_t* outsize); void* buildReadLocalName(size_t* outsize);
void* buildWriteScan(uint8 scanmode, size_t* outsize); void* buildWriteScan(uint8 scanmode, size_t* outsize);
void* buildAuthEnable(uint8 auth, size_t* outsize);
void* buildReadClassOfDevice(size_t* outsize); void* buildReadClassOfDevice(size_t* outsize);
/* LINK CONTROL */ /* LINK CONTROL */
void* buildRemoteNameRequest(bdaddr_t bdaddr,uint8 pscan_rep_mode, uint16 clock_offset, size_t* outsize); void* buildRemoteNameRequest(bdaddr_t bdaddr, uint8 pscan_rep_mode,
uint16 clock_offset, size_t* outsize);
void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize); void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize);
void* buildInquiryCancel(size_t* outsize); void* buildInquiryCancel(size_t* outsize);
void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16], size_t* outsize); void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16],
size_t* outsize);
void* buildPinCodeRequestNegativeReply(bdaddr_t bdaddr, size_t* outsize); void* buildPinCodeRequestNegativeReply(bdaddr_t bdaddr, size_t* outsize);
void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role, size_t* outsize); void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role,
size_t* outsize);
void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize); void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize);
/* OGF_INFORMATIONAL_PARAM */ /* OGF_INFORMATIONAL_PARAM */
+325 -312
View File
@@ -6,15 +6,21 @@
#include "CommandManager.h" #include "CommandManager.h"
inline void* buildCommand(uint8 ogf, uint8 ocf, void** param, size_t psize, size_t* outsize)
#include <bluetooth/bluetooth_error.h>
inline void* buildCommand(uint8 ogf, uint8 ocf, void** param, size_t psize,
size_t* outsize)
{ {
struct hci_command_header* header; struct hci_command_header* header;
#ifdef BT_IOCTLS_PASS_SIZE #ifdef BT_IOCTLS_PASS_SIZE
header = (struct hci_command_header*) malloc(psize + sizeof(struct hci_command_header)); header = (struct hci_command_header*) malloc(psize
+ sizeof(struct hci_command_header));
*outsize = psize + sizeof(struct hci_command_header); *outsize = psize + sizeof(struct hci_command_header);
#else #else
size_t* size = (size_t*)malloc(psize + sizeof(struct hci_command_header) + sizeof(size_t)); size_t* size = (size_t*)malloc(psize + sizeof(struct hci_command_header)
+ sizeof(size_t));
*outsize = psize + sizeof(struct hci_command_header) + sizeof(size_t); *outsize = psize + sizeof(struct hci_command_header) + sizeof(size_t);
*size = psize + sizeof(struct hci_command_header); *size = psize + sizeof(struct hci_command_header);
@@ -39,6 +45,41 @@ inline void* buildCommand(uint8 ogf, uint8 ocf, void** param, size_t psize, size
} }
// This is for request that only require a Command complete in reply.
// Propagate to ReadBufferSize => reply stored in server side
// ReadLocalVersion => reply stored in server side
// Reset => no reply
// Request that do not need any input parameter
// Output reply can be fit in 32 bits field without talking status into account
status_t
NonParameterCommandRequest(uint8 ofg, uint8 ocf, int32* result, hci_id hId,
BMessenger* messenger)
{
int8 bt_status = BT_ERROR;
BluetoothCommand<> simpleCommand(ofg, ocf);
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", hId);
request.AddData("raw command", B_ANY_TYPE,
simpleCommand.Data(), simpleCommand.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(ofg, ocf));
if (messenger->SendMessage(&request, &reply) == B_OK) {
reply.FindInt8("status", &bt_status);
if (result != NULL)
reply.FindInt32("result", result);
}
return bt_status;
}
#if 0 #if 0
#pragma mark - CONTROL BASEBAND - #pragma mark - CONTROL BASEBAND -
#endif #endif
@@ -46,26 +87,30 @@ inline void* buildCommand(uint8 ogf, uint8 ocf, void** param, size_t psize, size
void* buildReset(size_t* outsize) void* buildReset(size_t* outsize)
{ {
return buildCommand(OGF_CONTROL_BASEBAND, OCF_RESET, NULL, 0, outsize); return buildCommand(OGF_CONTROL_BASEBAND, OCF_RESET,
NULL, 0, outsize);
} }
void* buildReadLocalName(size_t* outsize) void* buildReadLocalName(size_t* outsize)
{ {
return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME, NULL, 0, outsize); return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME,
NULL, 0, outsize);
} }
void* buildReadClassOfDevice(size_t* outsize) void* buildReadClassOfDevice(size_t* outsize)
{ {
return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV, NULL, 0, outsize); return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV,
NULL, 0, outsize);
} }
void* buildWriteScan(uint8 scanmode, size_t* outsize) void* buildWriteScan(uint8 scanmode, size_t* outsize)
{ {
struct hci_write_scan_enable* param; struct hci_write_scan_enable* param;
void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE, (void**) &param, sizeof(struct hci_write_scan_enable), outsize); void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE,
(void**) &param, sizeof(struct hci_write_scan_enable), outsize);
if (command != NULL) { if (command != NULL) {
@@ -77,55 +122,18 @@ void* buildWriteScan(uint8 scanmode, size_t* outsize)
} }
void* buildAuthEnable(uint8 auth, size_t* outsize)
{
struct hci_write_authentication_enable* param;
void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_AUTH_ENABLE, (void**) &param, sizeof(struct hci_write_authentication_enable), outsize);
if (command != NULL) {
param->authentication = auth;
}
return command;
}
#if 0 #if 0
#pragma mark - LINK CONTROL - #pragma mark - LINK CONTROL -
#endif #endif
void* buildCreateConnection(bdaddr_t bdaddr) void* buildRemoteNameRequest(bdaddr_t bdaddr, uint8 pscan_rep_mode,
{ uint16 clock_offset, size_t* outsize)
/*
cm4.size = sizeof(struct hci_command_header)+sizeof(struct hci_cp_create_conn);
cm4.header.opcode = B_HOST_TO_LENDIAN_INT16(hci_opcode_pack(OGF_LINK_CONTROL, OCF_CREATE_CONN));
cm4.body.bdaddr.b[0] = 0x92;
cm4.body.bdaddr.b[1] = 0xd3;
cm4.body.bdaddr.b[2] = 0xaf;
cm4.body.bdaddr.b[3] = 0xd9;
cm4.body.bdaddr.b[4] = 0x0a;
cm4.body.bdaddr.b[5] = 0x00;
cm4.body.pkt_type = 0xFFFF;
cm4.body.pscan_rep_mode = 1;
cm4.body.pscan_mode = 0;
cm4.body.clock_offset = 0xc7;
cm4.body.role_switch = 1;
cm4.header.clen = 13;
ioctl(fd1, ISSUE_BT_COMMAND, &cm4, sizeof(cm4));
*/
return NULL;
}
void* buildRemoteNameRequest(bdaddr_t bdaddr,uint8 pscan_rep_mode, uint16 clock_offset, size_t* outsize)
{ {
struct hci_remote_name_request* param; struct hci_remote_name_request* param;
void* command = buildCommand(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST, (void**) &param, sizeof(struct hci_remote_name_request), outsize); void* command = buildCommand(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST,
(void**)&param, sizeof(struct hci_remote_name_request), outsize);
if (command != NULL) { if (command != NULL) {
param->bdaddr = bdaddr; param->bdaddr = bdaddr;
@@ -141,7 +149,8 @@ void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize)
{ {
struct hci_cp_inquiry* param; struct hci_cp_inquiry* param;
void* command = buildCommand(OGF_LINK_CONTROL, OCF_INQUIRY, (void**) &param, sizeof(struct hci_cp_inquiry), outsize); void* command = buildCommand(OGF_LINK_CONTROL, OCF_INQUIRY,
(void**) &param, sizeof(struct hci_cp_inquiry), outsize);
if (command != NULL) { if (command != NULL) {
@@ -164,22 +173,21 @@ void* buildInquiryCancel(size_t* outsize)
} }
void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16], size_t* outsize) void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16],
size_t* outsize)
{ {
struct hci_cp_pin_code_reply* param; struct hci_cp_pin_code_reply* param;
if (length > HCI_PIN_SIZE) // PinCode cannot be longer than 16 if (length > HCI_PIN_SIZE) // PinCode cannot be longer than 16
return NULL; return NULL;
void* command = buildCommand(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY, (void**) &param, sizeof(struct hci_cp_pin_code_reply), outsize); void* command = buildCommand(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY,
(void**)&param, sizeof(struct hci_cp_pin_code_reply), outsize);
if (command != NULL) { if (command != NULL) {
param->bdaddr = bdaddr; param->bdaddr = bdaddr;
param->pin_len = length; param->pin_len = length;
memcpy(&param->pin_code, pincode, length); memcpy(&param->pin_code, pincode, length);
} }
return command; return command;
@@ -225,7 +233,8 @@ void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize)
struct hci_cp_reject_conn_req* param; struct hci_cp_reject_conn_req* param;
void* command = buildCommand(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ, void* command = buildCommand(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ,
(void**) &param, sizeof(struct hci_cp_reject_conn_req), outsize); (void**)&param, sizeof(struct hci_cp_reject_conn_req),
outsize);
if (command != NULL) { if (command != NULL) {
param->bdaddr = bdaddr; param->bdaddr = bdaddr;
@@ -241,19 +250,22 @@ void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize)
void* buildReadLocalVersionInformation(size_t* outsize) void* buildReadLocalVersionInformation(size_t* outsize)
{ {
return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION, NULL, 0, outsize); return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION,
NULL, 0, outsize);
} }
void* buildReadBufferSize(size_t* outsize) void* buildReadBufferSize(size_t* outsize)
{ {
return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE, NULL, 0, outsize); return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE,
NULL, 0, outsize);
} }
void* buildReadBdAddr(size_t* outsize) void* buildReadBdAddr(size_t* outsize)
{ {
return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR, NULL, 0, outsize); return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR,
NULL, 0, outsize);
} }
@@ -341,37 +353,37 @@ const char* bluetoothManufacturers[] = {
const char* linkControlCommands[] = { const char* linkControlCommands[] = {
"Inquiry", "Inquiry",
"Inquiry cancel", "Inquiry Cancel",
"Periodic inquiry mode", "Periodic Inquiry Mode",
"Exit periodic inquiry mode", "Exit Periodic Inquiry Mode",
"Create connection", "Create Connection",
"Disconnect", "Disconnect",
"Add SCO connection", // not on 2.1 "Add SCO Connection", // not on 2.1
"Cancel create connection", "Cancel Create Connection",
"Accept connection request", "Accept Connection Request",
"Reject connection request", "Reject Connection Request",
"Link key request reply", "Link Key Request Reply",
"Link key request negative reply", "Link Key Request Negative Reply",
"PIN code request reply", "PIN Code Request Reply",
"PIN code request negative reply", "PIN Code Request Negative Reply",
"Change connection packet type", "Change Connection Packet Type",
"Reserved", // not on 2.1", "Reserved", // not on 2.1",
"Authentication requested", "Authentication Requested",
"Reserved", // not on 2.1", "Reserved", // not on 2.1",
"Set connection encryption", "Set Connection Encryption",
"Reserved", // not on 2.1", "Reserved", // not on 2.1",
"Change connection link key", "Change Connection Link Key",
"Reserved", // not on 2.1", "Reserved", // not on 2.1",
"Master link key", "Master Link Key",
"Reserved", // not on 2.1", "Reserved", // not on 2.1",
"Remote name request", "Remote Name Request",
"Cancel remote name request", "Cancel Remote Name Request",
"Read remote supported features", "Read Remote Supported Features",
"Read remote extended features", "Read Remote Extended Features",
"Read remote version information", "Read Remote Version Information",
"Reserved", // not on 2.1", "Reserved", // not on 2.1",
"Read clock offset", "Read Clock Offset",
"Read LMP handle", "Read LMP Handle",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
@@ -379,117 +391,117 @@ const char* linkControlCommands[] = {
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Setup synchronous connection", "Setup Synchronous Connection",
"Accept synchronous connection", "Accept Synchronous Connection",
"Reject synchronous connection", "Reject Synchronous Connection",
"IO capability request reply", "IO Capability Request Reply",
"User confirmation request reply", "User Confirmation Request Reply",
"User confirmation request negative reply", "User Confirmation Request Negative Reply",
"User passkey request reply", "User Passkey Request Reply",
"User passkey request negative reply", "User Passkey Request Negative Reply",
"Remote OOB data request reply", "Remote OOB Data Request Reply",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Remote OOB data request negative reply", "Remote OOB Data Request Negative Reply",
"IO capabilities response negative reply" "IO Capabilities Response Negative Reply"
}; };
const char* linkPolicyCommands[] = { const char* linkPolicyCommands[] = {
"Hold mode", "Hold Mode",
"Reserved", "Reserved",
"Sniff mode", "Sniff Mode",
"Exit sniff mode", "Exit Sniff Mode",
"Park state", "Park State",
"Exit park state", "Exit Park State",
"QoS setup", "QoS Setup",
"Reserved", "Reserved",
"Role discovery", "Role Discovery",
"Reserved", "Reserved",
"Switch role", "Switch Role",
"Read link policy settings", "Read Link Policy Settings",
"Write link policy settings", "Write Link Policy Settings",
"Read default link policy settings", "Read Default Link Policy Settings",
"Write default link policy settings", "Write Default Link Policy Settings",
"Flow specification", "Flow Specification",
"Sniff subrating" "Sniff Subrating"
}; };
const char* controllerBasebandCommands[] = { const char* controllerBasebandCommands[] = {
"Set event mask", "Set Event Mask",
"Reserved", "Reserved",
"Reset", "Reset",
"Reserved", "Reserved",
"Set event filter", "Set Event Filter",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Flush", "Flush",
"Read PIN type", "Read PIN Type",
"Write PIN type", "Write PIN Type",
"Create new unit key", "Create New Unit Key",
"Reserved", "Reserved",
"Read stored link key", "Read Stored Link Key",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Write stored link key", "Write Stored Link Key",
"Delete stored link key", "Delete Stored Link Key",
"Write local name", "Write Local Name",
"Read local name", "Read Local Name",
"Read connection accept timeout", "Read Connection Accept Timeout",
"Write connection accept timeout", "Write Connection Accept Timeout",
"Read page timeout", "Read Page Timeout",
"Write page timeout", "Write Page Timeout",
"Read scan enable", "Read Scan Enable",
"Write scan enable", "Write Scan Enable",
"Read page scan activity", "Read Page Scan Activity",
"Write page scan activity", "Write Page Scan Activity",
"Read inquiry scan activity", "Read Inquiry Scan Activity",
"Write inquiry scan activity", "Write Inquiry Scan Activity",
"Read authentication enable", "Read Authentication Enable",
"Write authentication enable", "Write Authentication Enable",
"Read encryption mode", // not 2.1 "Read Encryption Mode", // not 2.1
"Write encryption mode",// not 2.1 "Write Encryption Mode",// not 2.1
"Read class of device", "Read Class Of Device",
"Write class of device", "Write Class Of Device",
"Read voice setting", "Read Voice Setting",
"Write voice setting", "Write Voice Setting",
"Read automatic flush timeout", "Read Automatic Flush Timeout",
"Write automatic flush timeout", "Write Automatic Flush Timeout",
"Read num broadcast retransmissions", "Read Num Broadcast Retransmissions",
"Write num broadcast retransmissions", "Write Num Broadcast Retransmissions",
"Read hold mode activity", "Read Hold Mode Activity",
"Write hold mode activity", "Write Hold Mode Activity",
"Read transmit power level", "Read Transmit Power Level",
"Read synchronous flow control enable", "Read Synchronous Flow Control Enable",
"Write synchronous flow control enable", "Write Synchronous Flow Control Enable",
"Reserved", "Reserved",
"Set host controller to host flow control", "Set Host Controller To Host Flow Control",
"Reserved", "Reserved",
"Host buffer size", "Host Buffer Size",
"Reserved", "Reserved",
"Host number of completed packets", "Host Number Of Completed Packets",
"Read link supervision timeout", "Read Link Supervision Timeout",
"Write link supervision timeout", "Write Link Supervision Timeout",
"Read number of supported IAC", "Read Number of Supported IAC",
"Read current IAC LAP", "Read Current IAC LAP",
"Write current IAC LAP", "Write Current IAC LAP",
"Read page scan period mode", // not 2.1 "Read Page Scan Period Mode", // not 2.1
"Write page scan period mode", // not 2.1 "Write Page Scan Period Mode", // not 2.1
"Read page scan mode", // not 2.1 "Read Page Scan Mode", // not 2.1
"Write page scan mode", // not 2.1 "Write Page Scan Mode", // not 2.1
"Set AFH channel classification", "Set AFH Channel Classification",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Read inquiry scan type", "Read Inquiry Scan Type",
"Write inquiry scan type", "Write Inquiry Scan Type",
"Read inquiry mode", "Read Inquiry Mode",
"Write inquiry mode", "Write Inquiry Mode",
"Read page scan type", "Read Page Scan Type",
"Write page scan type", "Write Page Scan Type",
"Read AFH channel assessment mode", "Read AFH Channel Assessment Mode",
"Write AFH channel assessment mode", "Write AFH Channel Assessment Mode",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
@@ -497,93 +509,93 @@ const char* controllerBasebandCommands[] = {
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Read extended inquiry response", "Read Extended Inquiry Response",
"Write extended inquiry response", "Write Extended Inquiry Response",
"Refresh encryption key", "Refresh Encryption Key",
"Reserved", "Reserved",
"Read simple pairing mode", "Read Simple Pairing Mode",
"Write simple pairing mode", "Write Simple Pairing Mode",
"Read local OOB data", "Read Local OOB Data",
"Read inquiry transmit power level", "Read Inquiry Transmit Power Level",
"Write inquiry transmit power level", "Write Inquiry Transmit Power Level",
"Read default erroneous data reporting", "Read Default Erroneous Data Reporting",
"Write default erroneous data reporting", "Write Default Erroneous Data Reporting",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Enhanced flush", "Enhanced Flush",
"Send keypress notification" "Send Keypress Notification"
}; };
const char* informationalParametersCommands[] = { const char* informationalParametersCommands[] = {
"Read local version information", "Read Local Version Information",
"Read local supported commands", "Read Local Supported Commands",
"Read local supported features", "Read Local Supported Features",
"Read local extended features", "Read Local Extended Features",
"Read buffer size", "Read Buffer Size",
"Reserved", "Reserved",
"Read country code", // not 2.1 "Read Country Code", // not 2.1
"Reserved", "Reserved",
"Read BD ADDR" "Read BD ADDR"
}; };
const char* statusParametersCommands[] = { const char* statusParametersCommands[] = {
"Read failed contact counter", "Read Failed Contact Counter",
"Reset failed contact counter", "Reset Failed Contact Counter",
"Read link quality", "Read Link Quality",
"Reserved", "Reserved",
"Read RSSI", "Read RSSI",
"Read AFH channel map", "Read AFH Channel Map",
"Read clock", "Read Clock",
}; };
const char* testingCommands[] = { const char* testingCommands[] = {
"Read loopback mode", "Read Loopback Mode",
"Write loopback mode", "Write Loopback Mode",
"Enable device under test mode", "Enable Device Under Test Mode",
"Write simple pairing debug mode", "Write Simple Pairing Debug Mode",
}; };
const char* bluetoothEvents[] = { const char* bluetoothEvents[] = {
"Inquiry complete", "Inquiry Complete",
"Inquiry result", "Inquiry Result",
"Conn complete", "Conn Complete",
"Conn request", "Conn Request",
"Disconnection complete", "Disconnection Complete",
"Auth complete", "Auth Complete",
"Remote name request complete", "Remote Name Request Complete",
"Encrypt change", "Encrypt Change",
"Change conn link key complete", "Change Conn Link Key Complete",
"Master link key compl", "Master Link Key Compl",
"Rmt features", "Rmt Features",
"Rmt version", "Rmt Version",
"QoS setup complete", "Qos Setup Complete",
"Command complete", "Command Complete",
"Command status", "Command Status",
"Hardware error", "Hardware Error",
"Flush occur", "Flush Occur",
"Role change", "Role Change",
"Num comp Pkts", "Num Comp Pkts",
"Mode change", "Mode Change",
"Return link keys", "Return Link Keys",
"Pin code req", "Pin Code Req",
"Link key req", "Link Key Req",
"Link key notify", "Link Key Notify",
"Loopback command", "Loopback Command",
"Data buffer overflow", "Data Buffer Overflow",
"Max slot change", "Max Slot Change",
"Read clock offset compl", "Read Clock Offset Compl",
"Con Pkt type changed", "Con Pkt Type Changed",
"QoS violation", "Qos Violation",
"Reserved", "Reserved",
"Page scan Rep mode change", "Page Scan Rep Mode Change",
"Flow specification", "Flow Specification",
"Inquiry result with RSSI", "Inquiry Result With Rssi",
"Remote extended features", "Remote Extended Features",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
@@ -592,84 +604,84 @@ const char* bluetoothEvents[] = {
"Reserved", "Reserved",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Synchronous connection completed", "Synchronous Connection Completed",
"Synchronous connection changed", "Synchronous Connection Changed",
"Reserved", "Reserved",
"Extended inquiry result", "Extended Inquiry Result",
"Encryption key refresh complete", "Encryption Key Refresh Complete",
"IO capability request", "Io Capability Request",
"IO capability response", "Io Capability Response",
"User confirmation request", "User Confirmation Request",
"User passkey request", "User Passkey Request",
"OOB data request", "Oob Data Request",
"Simple pairing complete", "Simple Pairing Complete",
"Reserved", "Reserved",
"Link supervision timeout changed", "Link Supervision Timeout Changed",
"Enhanced flush complete", "Enhanced Flush Complete",
"Reserved", "Reserved",
"Reserved", "Reserved",
"Keypress notification", "Keypress Notification",
"Remote host supported features notification" "Remote Host Supported Features Notification"
}; };
const char* bluetoothErrors[] = { const char* bluetoothErrors[] = {
"No error", "No Error",
"Unknown command", "Unknown Command",
"No connection", "No Connection",
"Hardware failure", "Hardware Failure",
"Page timeout", "Page Timeout",
"Authentication failure", "Authentication Failure",
"Pin or key missing", "Pin Or Key Missing",
"Memory full", "Memory Full",
"Connection timeout", "Connection Timeout",
"Max number of connections", "Max Number Of Connections",
"Max number of SCO connections", "Max Number Of Sco Connections",
"Acl connection exists", "Acl Connection Exists",
"Command disallowed", "Command Disallowed",
"Rejected limited resources", "Rejected Limited Resources",
"Rejected security", "Rejected Security",
"Rejected personal", "Rejected Personal",
"Host timeout", "Host Timeout",
"Unsupported feature", "Unsupported Feature",
"Invalid parameters", "Invalid Parameters",
"Remote user ended connection", "Remote User Ended Connection",
"Remote low resources", "Remote Low Resources",
"Remote power off", "Remote Power Off",
"Connection terminated", "Connection Terminated",
"Repeated attempts", "Repeated Attempts",
"Pairing not allowed", "Pairing Not Allowed",
"Unknown LMP Pdu", "Unknown Lmp Pdu",
"Unsupported remote feature", "Unsupported Remote Feature",
"SCO offset rejected", "Sco Offset Rejected",
"SCO interval rejected", "Sco Interval Rejected",
"Air mode rejected", "Air Mode Rejected",
"Invalid LMP parameters", "Invalid Lmp Parameters",
"Unspecified error", "Unspecified Error",
"Unsupported LMP parameter value", "Unsupported Lmp Parameter Value",
"Role change not allowed", "Role Change Not Allowed",
"LMP response timeout", "Lmp Response Timeout",
"LMP error transaction collision", "Lmp Error Transaction Collision",
"LMP Pdu not allowed", "Lmp Pdu Not Allowed",
"Encryption mode not accepted", "Encryption Mode Not Accepted",
"Unit link key used", "Unit Link Key Used",
"QoS not supported", "Qos Not Supported",
"Instant passed", "Instant Passed",
"Pairing with unit key not supported", "Pairing With Unit Key Not Supported",
"Different transaction collision", "Different Transaction Collision",
"QoS unacceptable parameter", "Qos Unacceptable Parameter",
"QoS rejected", "Qos Rejected",
"Classification not supported", "Classification Not Supported",
"Insufficient security", "Insufficient Security",
"Parameter out of range", "Parameter Out Of Range",
"Reserved", "Reserved",
"Role switch pending", "Role Switch Pending",
"Reserved", "Reserved",
"Slot violation", "Slot Violation",
"Role switch failed", "Role Switch Failed",
"Extended inquiry response too Large", "Extended Inquiry Response Too Large",
"Simple pairing not supported by host", "Simple Pairing Not Supported By Host",
"Host busy pairing" "Host Busy Pairing"
}; };
@@ -677,6 +689,11 @@ const char* hciVersion[] = { "1.0B" , "1.1 " , "1.2 " , "2.0 " , "2.1 "};
const char* lmpVersion[] = { "1.0 " , "1.1 " , "1.2 " , "2.0 " , "2.1 "}; const char* lmpVersion[] = { "1.0 " , "1.1 " , "1.2 " , "2.0 " , "2.1 "};
#if 0
#pragma mark -
#endif
const char* const char*
BluetoothHciVersion(uint16 ver) BluetoothHciVersion(uint16 ver)
{ {
@@ -736,36 +753,32 @@ BluetoothCommandOpcode(uint16 opcode)
const char* const char*
BluetoothEvent(uint8 event) { BluetoothEvent(uint8 event)
{
if (event < sizeof(bluetoothEvents) / sizeof(const char*)) { if (event < sizeof(bluetoothEvents) / sizeof(const char*))
return bluetoothEvents[event - 1]; return bluetoothEvents[event - 1];
} else { else
return "Event out of range!"; return "Event out of Range!";
}
} }
const char* const char*
BluetoothManufacturer(uint16 manufacturer) { BluetoothManufacturer(uint16 manufacturer)
{
if (manufacturer < sizeof(bluetoothManufacturers) / sizeof(const char*)) { if (manufacturer < sizeof(bluetoothManufacturers) / sizeof(const char*))
return bluetoothManufacturers[manufacturer]; return bluetoothManufacturers[manufacturer];
} else if (manufacturer == 0xFFFF) { else if (manufacturer == 0xFFFF)
return "internal use"; return "internal use";
} else { else
return "not assigned"; return "not assigned";
} }
}
const char* const char*
BluetoothError(uint8 error) { BluetoothError(uint8 error)
{
if (error < sizeof(bluetoothErrors) / sizeof(const char*)) { if (error < sizeof(bluetoothErrors) / sizeof(const char*))
return bluetoothErrors[error]; return bluetoothErrors[error];
} else { else
return "not specified"; return "not specified";
} }
}