diff --git a/src/servers/bluetooth/LocalDeviceHandler.cpp b/src/servers/bluetooth/LocalDeviceHandler.cpp index 3f71ddc9b4..3c2cee88a8 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.cpp +++ b/src/servers/bluetooth/LocalDeviceHandler.cpp @@ -63,17 +63,21 @@ LocalDeviceHandler::AddWantedEvent(BMessage* msg) fEventsWanted.Unlock(); } +void +LocalDeviceHandler::ClearWantedEvent(BMessage* msg) +{ + fEventsWanted.Lock(); + fEventsWanted.RemoveMessage(msg); + fEventsWanted.Unlock(); + +} + void -LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event = 0, uint16 opcode = 0) +LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0) { // Remove the whole petition from queue - fEventsWanted.Lock(); -/* - if (event == 0) { - fEventsWanted.RemoveMessage(msg); - goto bail; - } + fEventsWanted.Lock(); int16 eventFound; int16 opcodeFound; @@ -89,17 +93,19 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event = 0, uint16 opc if (eventFound == event) { // there is an opcode specified - if (opcde != 0) + if (opcode != 0) { // The opcode matches if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && ((uint16)opcodeFound != opcode) ) { + // FIX: this should remove only the entry fEventsWanted.RemoveMessage(msg); goto bail; } } else { // Event matches so far + // FIX: this should remove only the entry fEventsWanted.RemoveMessage(msg); goto bail; } @@ -109,9 +115,9 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event = 0, uint16 opc } } -bail: */ - fEventsWanted.RemoveMessage(msg); - +bail: + + fEventsWanted.RemoveMessage(msg); fEventsWanted.Unlock(); } diff --git a/src/servers/bluetooth/LocalDeviceHandler.h b/src/servers/bluetooth/LocalDeviceHandler.h index ea0135f4ee..a676542edc 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.h +++ b/src/servers/bluetooth/LocalDeviceHandler.h @@ -37,7 +37,9 @@ protected: BMessage* fProperties; void AddWantedEvent(BMessage* msg); - void ClearWantedEvent(BMessage* msg, uint16 code, uint16 opcode = 0); + void ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0); + void ClearWantedEvent(BMessage* msg); + BMessage* FindPetition(uint16 event, uint16 opcode = 0); private: diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index 7a01e34ad3..b93a013281 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include @@ -91,8 +93,12 @@ printf("### \n"); (Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS)); request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode ); + } else if ( event->ecode == HCI_EVENT_CMD_STATUS ) { + + (Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS)); + request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode ); + } else - // TODO: Command status should also be considered { request = FindPetition(event->ecode); } @@ -145,6 +151,7 @@ printf("### \n"); break; case HCI_EVENT_CMD_STATUS: + CommandStatus((struct hci_ev_cmd_status*)(event+1), request); break; case HCI_EVENT_FLUSH_OCCUR: @@ -313,6 +320,52 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re } +void +LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* request) { + + int16 opcodeExpected; + BMessage reply; + + Output::Instance()->Post(__FUNCTION__, BLACKBOARD_LD_OFFSET + GetID()); + Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID()); + + // Handle command complete information + request->FindInt16("opcodeExpected", 0 /*REVIEW!*/, &opcodeExpected); + + + if (request->IsSourceWaiting() == false) + Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); + + + switch (opcodeExpected) { + + case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR): + { + struct hci_ev_cmd_status* commandStatus = (struct hci_ev_cmd_status*)(event+1); + + reply.what = BT_MSG_INQUIRY_STARTED; + reply.AddInt8("status", commandStatus->status); + + if (commandStatus->status == BT_OK) { + Output::Instance()->Post("Positive reply for inquiry\n", BLACKBOARD_KIT); + } else { + Output::Instance()->Post("Negative reply for friendly name\n", BLACKBOARD_KIT); + } + + printf("Sending reply ... %ld\n",request->SendReply(&reply)); + reply.PrintToStream(); + + ClearWantedEvent(request, PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); + } + break; + + default: + Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT); + break; + } + +} + #if 0 #pragma mark - Request Methods - #endif diff --git a/src/servers/bluetooth/LocalDeviceImpl.h b/src/servers/bluetooth/LocalDeviceImpl.h index a693fbf2ab..54ab05f644 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.h +++ b/src/servers/bluetooth/LocalDeviceImpl.h @@ -38,6 +38,7 @@ public: /* Events handling */ void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request); + void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request); };