diff --git a/headers/os/bluetooth/HCI/btHCI.h b/headers/os/bluetooth/HCI/btHCI.h index d042d2305d..e9629812f4 100644 --- a/headers/os/bluetooth/HCI/btHCI.h +++ b/headers/os/bluetooth/HCI/btHCI.h @@ -20,6 +20,13 @@ typedef enum { BT_COMMAND = 0, HCI_NUM_PACKET_TYPES } 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 */ #define HCI_MAX_ACL_SIZE 1024 #define HCI_MAX_SCO_SIZE 255 diff --git a/headers/os/bluetooth/HCI/btHCI_command.h b/headers/os/bluetooth/HCI/btHCI_command.h index 575fe15a89..c11584c94d 100644 --- a/headers/os/bluetooth/HCI/btHCI_command.h +++ b/headers/os/bluetooth/HCI/btHCI_command.h @@ -10,12 +10,6 @@ #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 { uint16 opcode; /* OCF & OGF */ uint8 clen; diff --git a/headers/os/bluetooth/HCI/btHCI_event.h b/headers/os/bluetooth/HCI/btHCI_event.h index d639de3be8..bec67a8a04 100644 --- a/headers/os/bluetooth/HCI/btHCI_event.h +++ b/headers/os/bluetooth/HCI/btHCI_event.h @@ -292,7 +292,7 @@ struct hci_ev_sychronous_connection_changed { // TODO: Define remaining Bluetooth 2.1 events structures #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 diff --git a/headers/private/bluetooth/bluetoothserver_p.h b/headers/private/bluetooth/bluetoothserver_p.h index ea5574d67c..45861bea5e 100644 --- a/headers/private/bluetooth/bluetoothserver_p.h +++ b/headers/private/bluetooth/bluetoothserver_p.h @@ -11,6 +11,7 @@ #define BT_MSG_ACQUIRE_LOCAL_DEVICE 'btAd' #define BT_MSG_HANDLE_SIMPLE_REQUEST 'btsR' #define BT_MSG_ADD_DEVICE 'btDD' +#define BT_MSG_REMOVE_DEVICE 'btrD' #define BT_MSG_GET_PROPERTY 'btgP' // Discovery diff --git a/src/kits/bluetooth/CommandManager.cpp b/src/kits/bluetooth/CommandManager.cpp index f01e191c66..84f82658ad 100644 --- a/src/kits/bluetooth/CommandManager.cpp +++ b/src/kits/bluetooth/CommandManager.cpp @@ -596,7 +596,7 @@ const char* bluetoothEvents[] = { "Synchronous Connection Changed", "Reserved", "Extended Inquiry Result", - "Encryption Key Refersh Complete", + "Encryption Key Refresh Complete", "Io Capability Request", "Io Capability Response", "User Confirmation Request", @@ -678,51 +678,51 @@ const char* lmpVersion[] = { "1.0 " , "1.1 " , "1.2 " , "2.0 " , "2.1 "}; const char* -GetHciVersion(uint16 ver) +BluetoothHciVersion(uint16 ver) { return hciVersion[ver]; } const char* -GetLmpVersion(uint16 ver) +BluetoothLmpVersion(uint16 ver) { return lmpVersion[ver]; } 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 // beyond the boundaries of the arrays and crash. // But only our stack could issue them so its under // our control. - switch (GET_OPCODE_OGF(command)) { + switch (GET_OPCODE_OGF(opcode)) { case OGF_LINK_CONTROL: - return linkControlCommands[GET_OPCODE_OCF(command)-1]; + return linkControlCommands[GET_OPCODE_OCF(opcode)-1]; break; case OGF_LINK_POLICY: - return linkPolicyCommands[GET_OPCODE_OCF(command)-1]; + return linkPolicyCommands[GET_OPCODE_OCF(opcode)-1]; break; case OGF_CONTROL_BASEBAND: - return controllerBasebandCommands[GET_OPCODE_OCF(command)-1]; + return controllerBasebandCommands[GET_OPCODE_OCF(opcode)-1]; break; case OGF_INFORMATIONAL_PARAM: - return informationalParametersCommands[GET_OPCODE_OCF(command)-1]; + return informationalParametersCommands[GET_OPCODE_OCF(opcode)-1]; break; case OGF_STATUS_PARAM: - return statusParametersCommands[GET_OPCODE_OCF(command)-1]; + return statusParametersCommands[GET_OPCODE_OCF(opcode)-1]; break; case OGF_TESTING_CMD: - return testingCommands[GET_OPCODE_OCF(command)-1]; + return testingCommands[GET_OPCODE_OCF(opcode)-1]; break; case OGF_VENDOR_CMD: return "Vendor specific command"; @@ -736,8 +736,9 @@ GetCommand(uint16 command) const char* -GetEvent(uint8 event) { - if (event < sizeof(bluetoothEvents)/sizeof(const char*)) { +BluetoothEvent(uint8 event) { + + if (event < sizeof(bluetoothEvents) / sizeof(const char*)) { return bluetoothEvents[event-1]; } else { return "Event out of Range!"; @@ -746,8 +747,9 @@ GetEvent(uint8 event) { const char* -GetManufacturer(uint16 manufacturer) { - if (manufacturer < sizeof(bluetoothManufacturers)/sizeof(const char*)) { +BluetoothManufacturer(uint16 manufacturer) { + + if (manufacturer < sizeof(bluetoothManufacturers) / sizeof(const char*)) { return bluetoothManufacturers[manufacturer]; } else if (manufacturer == 0xFFFF) { return "internal use"; @@ -758,8 +760,9 @@ GetManufacturer(uint16 manufacturer) { const char* -GetError(uint8 error) { - if (error < sizeof(bluetoothErrors)/sizeof(const char*)) { +BluetoothError(uint8 error) { + + if (error < sizeof(bluetoothErrors) / sizeof(const char*)) { return bluetoothErrors[error]; } else { return "not specified"; diff --git a/src/preferences/bluetooth/BluetoothDeviceView.cpp b/src/preferences/bluetooth/BluetoothDeviceView.cpp index 408052f5c5..eed197a7a5 100644 --- a/src/preferences/bluetooth/BluetoothDeviceView.cpp +++ b/src/preferences/bluetooth/BluetoothDeviceView.cpp @@ -105,7 +105,7 @@ BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice) str = ""; 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) str << " HCI rev: " << value ; @@ -113,14 +113,14 @@ BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice) str = ""; 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) str << " LMP subver: " << value; fLMPVersionProperties->SetText(str.String()); str = ""; if (bDevice->GetProperty("manufacturer", &value) == B_OK) - str << "Manufacturer: " << GetManufacturer(value); + str << "Manufacturer: " << BluetoothManufacturer(value); fManufacturerProperties->SetText(str.String()); str = ""; diff --git a/src/servers/bluetooth/BluetoothServer.cpp b/src/servers/bluetooth/BluetoothServer.cpp index a47ef3e9b8..71e0ef5ad6 100644 --- a/src/servers/bluetooth/BluetoothServer.cpp +++ b/src/servers/bluetooth/BluetoothServer.cpp @@ -121,9 +121,8 @@ void BluetoothServer::AppActivated(bool act) void BluetoothServer::MessageReceived(BMessage *message) { BMessage reply; - status_t status = B_WOULD_BLOCK; - // mark somehow.. do not reply anything - + status_t status = B_WOULD_BLOCK; // mark somehow to do not reply anything + switch(message->what) { case BT_MSG_ADD_DEVICE: @@ -132,38 +131,50 @@ void BluetoothServer::MessageReceived(BMessage *message) message->FindString("name", &str); BPath path(str.String()); Output::Instance()->Postf(BLACKBOARD_GENERAL, - "Requested LocalDevice %s\n", str.String()); + "Requested LocalDevice %s\n", str.String()); LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path); if (ldi->GetID() >= 0) { fLocalDevicesList.AddItem(ldi); Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID())); Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), - "LocalDevice %s id=%x added\n", - str.String(), ldi->GetID()); + "LocalDevice %s id=%x added\n", str.String(), ldi->GetID()); + } else { Output::Instance()->Post("Adding LocalDevice failed\n", - BLACKBOARD_GENERAL); + BLACKBOARD_GENERAL); } status = B_WOULD_BLOCK; /* TODO: This should be by user request only! */ 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: status = HandleLocalDevicesCount(message, &reply); - break; + break; + case BT_MSG_ACQUIRE_LOCAL_DEVICE: status = HandleAcquireLocalDevice(message, &reply); - break; + break; case BT_MSG_HANDLE_SIMPLE_REQUEST: status = HandleSimpleRequest(message, &reply); - break; + break; + case BT_MSG_GET_PROPERTY: status = HandleGetProperty(message, &reply); - break; + break; /* Handle if the bluetooth preferences is running?? */ case B_SOME_APP_LAUNCHED: @@ -181,7 +192,7 @@ void BluetoothServer::MessageReceived(BMessage *message) default: BApplication::MessageReceived(message); - break; + break; } // Can we reply right now? diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index b088ad6aa4..4216e17bed 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -85,31 +85,31 @@ LocalDeviceImpl::HandleEvent(struct hci_event_header* event) printf("### \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 // TODO: ML mark as handled pass a reply by parameter and reply in common switch (event->ecode) { case HCI_EVENT_HARDWARE_ERROR: - //HardwareError(event); + HardwareError((struct hci_ev_hardware_error*)(event+1)); return; - break; + case HCI_EVENT_CONN_REQUEST: ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL); return; - break; + 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); return; - break; + case HCI_EVENT_PIN_CODE_REQ: PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL); return; - break; + default: // lets go on - break; + break; } 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()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) for %s\n",__FUNCTION__, - event->ncmd,GetCommand(opcodeExpected)); + event->ncmd, BluetoothCommandOpcode(opcodeExpected)); switch ((uint16)opcodeExpected) { @@ -455,7 +455,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re reply.AddInt8("status", *(uint8*)(event+1)); 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); @@ -482,7 +482,7 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques request->FindInt16("opcodeExpected", index, &opcodeExpected); 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) Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); @@ -584,14 +584,15 @@ LocalDeviceImpl::RemoteNameRequestComplete( BMessage reply; if (remotename->status == BT_OK) { - 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); + + 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)); 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 #pragma mark - Request Methods - #endif diff --git a/src/servers/bluetooth/LocalDeviceImpl.h b/src/servers/bluetooth/LocalDeviceImpl.h index c1f18ae7ba..526325bb29 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.h +++ b/src/servers/bluetooth/LocalDeviceImpl.h @@ -56,6 +56,8 @@ public: void LinkKeyNotify(struct hci_ev_link_key_notify* 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 HardwareError(struct hci_ev_hardware_error *event); };