- Add initial code to unregister devices from server

- Handle Hardware error event
- Add function to retrieve an string from a bluetooth error
- Styling



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31376 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2009-07-02 20:07:26 +00:00
parent 1b3303e7ee
commit ddac407426
9 changed files with 85 additions and 56 deletions
+7
View File
@@ -20,6 +20,13 @@ typedef enum { BT_COMMAND = 0,
HCI_NUM_PACKET_TYPES HCI_NUM_PACKET_TYPES
} bt_packet_t; } bt_packet_t;
const char* BluetoothCommandOpcode(uint16 opcode);
const char* BluetoothEvent(uint8 event);
const char* BluetoothManufacturer(uint16 manufacturer);
const char* BluetoothHciVersion(uint16 ver);
const char* BluetoothLmpVersion(uint16 ver);
const char* BluetoothError(uint8 error);
/* packets sizes */ /* packets sizes */
#define HCI_MAX_ACL_SIZE 1024 #define HCI_MAX_ACL_SIZE 1024
#define HCI_MAX_SCO_SIZE 255 #define HCI_MAX_SCO_SIZE 255
-6
View File
@@ -10,12 +10,6 @@
#define HCI_COMMAND_HDR_SIZE 3 #define HCI_COMMAND_HDR_SIZE 3
const char* GetCommand(uint16 command);
const char* GetEvent(uint8 event);
const char* GetManufacturer(uint16 manufacturer);
const char* GetHciVersion(uint16 ver);
const char* GetLmpVersion(uint16 ver);
struct hci_command_header { struct hci_command_header {
uint16 opcode; /* OCF & OGF */ uint16 opcode; /* OCF & OGF */
uint8 clen; uint8 clen;
+1 -1
View File
@@ -292,7 +292,7 @@ struct hci_ev_sychronous_connection_changed {
// TODO: Define remaining Bluetooth 2.1 events structures // TODO: Define remaining Bluetooth 2.1 events structures
#define HCI_EVENT_EXTENDED_INQUIRY_RESULT 0x2F #define HCI_EVENT_EXTENDED_INQUIRY_RESULT 0x2F
#define HCI_EVENT_ENCRYPTION_KEY_REFERSH_COMPLETE 0x30 #define HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30
#define HCI_EVENT_IO_CAPABILITY_REQUEST 0x31 #define HCI_EVENT_IO_CAPABILITY_REQUEST 0x31
@@ -11,6 +11,7 @@
#define BT_MSG_ACQUIRE_LOCAL_DEVICE 'btAd' #define BT_MSG_ACQUIRE_LOCAL_DEVICE 'btAd'
#define BT_MSG_HANDLE_SIMPLE_REQUEST 'btsR' #define BT_MSG_HANDLE_SIMPLE_REQUEST 'btsR'
#define BT_MSG_ADD_DEVICE 'btDD' #define BT_MSG_ADD_DEVICE 'btDD'
#define BT_MSG_REMOVE_DEVICE 'btrD'
#define BT_MSG_GET_PROPERTY 'btgP' #define BT_MSG_GET_PROPERTY 'btgP'
// Discovery // Discovery
+21 -18
View File
@@ -596,7 +596,7 @@ const char* bluetoothEvents[] = {
"Synchronous Connection Changed", "Synchronous Connection Changed",
"Reserved", "Reserved",
"Extended Inquiry Result", "Extended Inquiry Result",
"Encryption Key Refersh Complete", "Encryption Key Refresh Complete",
"Io Capability Request", "Io Capability Request",
"Io Capability Response", "Io Capability Response",
"User Confirmation Request", "User Confirmation Request",
@@ -678,51 +678,51 @@ const char* lmpVersion[] = { "1.0 " , "1.1 " , "1.2 " , "2.0 " , "2.1 "};
const char* const char*
GetHciVersion(uint16 ver) BluetoothHciVersion(uint16 ver)
{ {
return hciVersion[ver]; return hciVersion[ver];
} }
const char* const char*
GetLmpVersion(uint16 ver) BluetoothLmpVersion(uint16 ver)
{ {
return lmpVersion[ver]; return lmpVersion[ver];
} }
const char* const char*
GetCommand(uint16 command) BluetoothCommandOpcode(uint16 opcode)
{ {
// TODO: BT implementations beyond 2.1 // NOTE: BT implementations beyond 2.1
// could specify new commands with OCF numbers // could specify new commands with OCF numbers
// beyond the boundaries of the arrays and crash. // beyond the boundaries of the arrays and crash.
// But only our stack could issue them so its under // But only our stack could issue them so its under
// our control. // our control.
switch (GET_OPCODE_OGF(command)) { switch (GET_OPCODE_OGF(opcode)) {
case OGF_LINK_CONTROL: case OGF_LINK_CONTROL:
return linkControlCommands[GET_OPCODE_OCF(command)-1]; return linkControlCommands[GET_OPCODE_OCF(opcode)-1];
break; break;
case OGF_LINK_POLICY: case OGF_LINK_POLICY:
return linkPolicyCommands[GET_OPCODE_OCF(command)-1]; return linkPolicyCommands[GET_OPCODE_OCF(opcode)-1];
break; break;
case OGF_CONTROL_BASEBAND: case OGF_CONTROL_BASEBAND:
return controllerBasebandCommands[GET_OPCODE_OCF(command)-1]; return controllerBasebandCommands[GET_OPCODE_OCF(opcode)-1];
break; break;
case OGF_INFORMATIONAL_PARAM: case OGF_INFORMATIONAL_PARAM:
return informationalParametersCommands[GET_OPCODE_OCF(command)-1]; return informationalParametersCommands[GET_OPCODE_OCF(opcode)-1];
break; break;
case OGF_STATUS_PARAM: case OGF_STATUS_PARAM:
return statusParametersCommands[GET_OPCODE_OCF(command)-1]; return statusParametersCommands[GET_OPCODE_OCF(opcode)-1];
break; break;
case OGF_TESTING_CMD: case OGF_TESTING_CMD:
return testingCommands[GET_OPCODE_OCF(command)-1]; return testingCommands[GET_OPCODE_OCF(opcode)-1];
break; break;
case OGF_VENDOR_CMD: case OGF_VENDOR_CMD:
return "Vendor specific command"; return "Vendor specific command";
@@ -736,8 +736,9 @@ GetCommand(uint16 command)
const char* const char*
GetEvent(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!";
@@ -746,8 +747,9 @@ GetEvent(uint8 event) {
const char* const char*
GetManufacturer(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";
@@ -758,8 +760,9 @@ GetManufacturer(uint16 manufacturer) {
const char* const char*
GetError(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";
@@ -105,7 +105,7 @@ BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice)
str = ""; str = "";
if (bDevice->GetProperty("hci_version", &value) == B_OK) if (bDevice->GetProperty("hci_version", &value) == B_OK)
str << "HCI ver: " << GetHciVersion(value); str << "HCI ver: " << BluetoothHciVersion(value);
if (bDevice->GetProperty("hci_revision", &value) == B_OK) if (bDevice->GetProperty("hci_revision", &value) == B_OK)
str << " HCI rev: " << value ; str << " HCI rev: " << value ;
@@ -113,14 +113,14 @@ BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice)
str = ""; str = "";
if (bDevice->GetProperty("lmp_version", &value) == B_OK) if (bDevice->GetProperty("lmp_version", &value) == B_OK)
str << "LMP ver: " << GetLmpVersion(value); str << "LMP ver: " << BluetoothLmpVersion(value);
if (bDevice->GetProperty("lmp_subversion", &value) == B_OK) if (bDevice->GetProperty("lmp_subversion", &value) == B_OK)
str << " LMP subver: " << value; str << " LMP subver: " << value;
fLMPVersionProperties->SetText(str.String()); fLMPVersionProperties->SetText(str.String());
str = ""; str = "";
if (bDevice->GetProperty("manufacturer", &value) == B_OK) if (bDevice->GetProperty("manufacturer", &value) == B_OK)
str << "Manufacturer: " << GetManufacturer(value); str << "Manufacturer: " << BluetoothManufacturer(value);
fManufacturerProperties->SetText(str.String()); fManufacturerProperties->SetText(str.String());
str = ""; str = "";
+23 -12
View File
@@ -121,8 +121,7 @@ void BluetoothServer::AppActivated(bool act)
void BluetoothServer::MessageReceived(BMessage *message) void BluetoothServer::MessageReceived(BMessage *message)
{ {
BMessage reply; BMessage reply;
status_t status = B_WOULD_BLOCK; status_t status = B_WOULD_BLOCK; // mark somehow to do not reply anything
// mark somehow.. do not reply anything
switch(message->what) switch(message->what)
{ {
@@ -132,38 +131,50 @@ void BluetoothServer::MessageReceived(BMessage *message)
message->FindString("name", &str); message->FindString("name", &str);
BPath path(str.String()); BPath path(str.String());
Output::Instance()->Postf(BLACKBOARD_GENERAL, Output::Instance()->Postf(BLACKBOARD_GENERAL,
"Requested LocalDevice %s\n", str.String()); "Requested LocalDevice %s\n", str.String());
LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path); LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path);
if (ldi->GetID() >= 0) { if (ldi->GetID() >= 0) {
fLocalDevicesList.AddItem(ldi); fLocalDevicesList.AddItem(ldi);
Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID())); Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID()));
Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()),
"LocalDevice %s id=%x added\n", "LocalDevice %s id=%x added\n", str.String(), ldi->GetID());
str.String(), ldi->GetID());
} else { } else {
Output::Instance()->Post("Adding LocalDevice failed\n", Output::Instance()->Post("Adding LocalDevice failed\n",
BLACKBOARD_GENERAL); BLACKBOARD_GENERAL);
} }
status = B_WOULD_BLOCK; status = B_WOULD_BLOCK;
/* TODO: This should be by user request only! */ /* TODO: This should be by user request only! */
ldi->Launch(); ldi->Launch();
break;
} }
break;
case BT_MSG_REMOVE_DEVICE:
{
LocalDeviceImpl* ldi;
message->FindPointer("device", (void**)&ldi);
fLocalDevicesList.RemoveItem(ldi);
delete ldi;
break;
}
case BT_MSG_COUNT_LOCAL_DEVICES: case BT_MSG_COUNT_LOCAL_DEVICES:
status = HandleLocalDevicesCount(message, &reply); status = HandleLocalDevicesCount(message, &reply);
break; break;
case BT_MSG_ACQUIRE_LOCAL_DEVICE: case BT_MSG_ACQUIRE_LOCAL_DEVICE:
status = HandleAcquireLocalDevice(message, &reply); status = HandleAcquireLocalDevice(message, &reply);
break; break;
case BT_MSG_HANDLE_SIMPLE_REQUEST: case BT_MSG_HANDLE_SIMPLE_REQUEST:
status = HandleSimpleRequest(message, &reply); status = HandleSimpleRequest(message, &reply);
break; break;
case BT_MSG_GET_PROPERTY: case BT_MSG_GET_PROPERTY:
status = HandleGetProperty(message, &reply); status = HandleGetProperty(message, &reply);
break; break;
/* Handle if the bluetooth preferences is running?? */ /* Handle if the bluetooth preferences is running?? */
case B_SOME_APP_LAUNCHED: case B_SOME_APP_LAUNCHED:
@@ -181,7 +192,7 @@ void BluetoothServer::MessageReceived(BMessage *message)
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
break; break;
} }
// Can we reply right now? // Can we reply right now?
+26 -15
View File
@@ -85,31 +85,31 @@ LocalDeviceImpl::HandleEvent(struct hci_event_header* event)
printf("### \n"); printf("### \n");
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"Incomming %s event\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"Incomming %s event\n",
GetEvent(event->ecode)); BluetoothEvent(event->ecode));
// Events here might have not been initated by us // Events here might have not been initated by us
// TODO: ML mark as handled pass a reply by parameter and reply in common // TODO: ML mark as handled pass a reply by parameter and reply in common
switch (event->ecode) { switch (event->ecode) {
case HCI_EVENT_HARDWARE_ERROR: case HCI_EVENT_HARDWARE_ERROR:
//HardwareError(event); HardwareError((struct hci_ev_hardware_error*)(event+1));
return; return;
break;
case HCI_EVENT_CONN_REQUEST: case HCI_EVENT_CONN_REQUEST:
ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL); ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL);
return; return;
break;
case HCI_EVENT_CONN_COMPLETE: case HCI_EVENT_CONN_COMPLETE:
// should belong to a request? can be sporadic or initiated by us¿?... // should belong to a request? can be sporadic or initiated by us¿?...
ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL); ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL);
return; return;
break;
case HCI_EVENT_PIN_CODE_REQ: case HCI_EVENT_PIN_CODE_REQ:
PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL); PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL);
return; return;
break;
default: default:
// lets go on // lets go on
break; break;
} }
BMessage* request = NULL; BMessage* request = NULL;
@@ -272,7 +272,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) for %s\n",__FUNCTION__, Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) for %s\n",__FUNCTION__,
event->ncmd,GetCommand(opcodeExpected)); event->ncmd, BluetoothCommandOpcode(opcodeExpected));
switch ((uint16)opcodeExpected) { switch ((uint16)opcodeExpected) {
@@ -455,7 +455,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
reply.AddInt8("status", *(uint8*)(event+1)); reply.AddInt8("status", *(uint8*)(event+1));
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for %s status %x\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for %s status %x\n",
__FUNCTION__,GetCommand(opcodeExpected), *(uint8*)(event+1)); __FUNCTION__, BluetoothCommandOpcode(opcodeExpected), *(uint8*)(event+1));
request->SendReply(&reply); request->SendReply(&reply);
@@ -482,7 +482,7 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
request->FindInt16("opcodeExpected", index, &opcodeExpected); request->FindInt16("opcodeExpected", index, &opcodeExpected);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) %x for %s\n",__FUNCTION__, Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) %x for %s\n",__FUNCTION__,
event->ncmd, event->status, GetCommand(event->opcode)); event->ncmd, event->status, BluetoothCommandOpcode(event->opcode));
if (request->IsSourceWaiting() == false) if (request->IsSourceWaiting() == false)
Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT);
@@ -584,14 +584,15 @@ LocalDeviceImpl::RemoteNameRequestComplete(
BMessage reply; BMessage reply;
if (remotename->status == BT_OK) { if (remotename->status == BT_OK) {
reply.AddString("friendlyname", (const char*)remotename->remote_name ); reply.AddString("friendlyname", (const char*)remotename->remote_name );
Output::Instance()->Post("Positive reply for remote friendly name\n", BLACKBOARD_KIT);
} else {
Output::Instance()->Post("Negative reply for remote friendly name\n", BLACKBOARD_KIT);
} }
reply.AddInt8("status", remotename->status); reply.AddInt8("status", remotename->status);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for %s with status %s\n",
BluetoothEvent(HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE),
bdaddrUtils::ToString(remotename->bdaddr), BluetoothError(remotename->status));
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
reply.PrintToStream(); reply.PrintToStream();
@@ -724,6 +725,16 @@ LocalDeviceImpl::MaxSlotChange(struct hci_ev_max_slot_change *event,
} }
void
LocalDeviceImpl::HardwareError(struct hci_ev_hardware_error *event)
{
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s: hardware code=%#x\n",
__FUNCTION__, event->hardware_code);
}
#if 0 #if 0
#pragma mark - Request Methods - #pragma mark - Request Methods -
#endif #endif
+2
View File
@@ -57,6 +57,8 @@ public:
void PageScanRepetitionModeChange(struct hci_ev_page_scan_rep_mode_change* event, BMessage* request, int32 index); void PageScanRepetitionModeChange(struct hci_ev_page_scan_rep_mode_change* event, BMessage* request, int32 index);
void MaxSlotChange(struct hci_ev_max_slot_change *event, BMessage *request, int32 index); void MaxSlotChange(struct hci_ev_max_slot_change *event, BMessage *request, int32 index);
void HardwareError(struct hci_ev_hardware_error *event);
}; };
#endif #endif