- Some refactoring on the event handling

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36335 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2010-04-17 20:10:47 +00:00
parent b9d586e9d9
commit 2db900d8f1
2 changed files with 298 additions and 236 deletions
+289 -226
View File
@@ -95,6 +95,160 @@ LocalDeviceImpl::Unregister()
#pragma mark - Event handling methods - #pragma mark - Event handling methods -
#endif #endif
template<typename T, typename Header>
inline T*
JumpEventHeader(Header* event)
{
return (T*)(event + 1);
}
void
LocalDeviceImpl::HandleUnexpectedEvent(struct hci_event_header* event)
{
// 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(
JumpEventHeader<struct hci_ev_hardware_error>(event));
break;
case HCI_EVENT_CONN_REQUEST:
ConnectionRequest(
JumpEventHeader<struct hci_ev_conn_request>(event), NULL);
break;
case HCI_EVENT_CONN_COMPLETE:
// should belong to a request? can be sporadic or initiated by us
ConnectionComplete(
JumpEventHeader<struct hci_ev_conn_complete>(event), NULL);
break;
case HCI_EVENT_PIN_CODE_REQ:
PinCodeRequest(
JumpEventHeader<struct hci_ev_pin_code_req>(event), NULL);
break;
}
}
void
LocalDeviceImpl::HandleExpectedRequest(struct hci_event_header* event, BMessage* request)
{
// we are waiting for a reply
switch (event->ecode) {
case HCI_EVENT_INQUIRY_COMPLETE:
InquiryComplete(JumpEventHeader<uint8>(event), request);
break;
case HCI_EVENT_INQUIRY_RESULT:
InquiryResult(JumpEventHeader<uint8>(event), request);
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
// should belong to a request? can be sporadic or initiated by us¿?...
DisconnectionComplete(
JumpEventHeader<struct hci_ev_disconnection_complete_reply>(event),
request);
break;
case HCI_EVENT_AUTH_COMPLETE:
break;
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
RemoteNameRequestComplete(
JumpEventHeader<struct hci_ev_remote_name_request_complete_reply>
(event), request);
break;
case HCI_EVENT_ENCRYPT_CHANGE:
break;
case HCI_EVENT_CHANGE_CONN_LINK_KEY_COMPLETE:
break;
case HCI_EVENT_MASTER_LINK_KEY_COMPL:
break;
case HCI_EVENT_RMT_FEATURES:
break;
case HCI_EVENT_RMT_VERSION:
break;
case HCI_EVENT_QOS_SETUP_COMPLETE:
break;
case HCI_EVENT_FLUSH_OCCUR:
break;
case HCI_EVENT_ROLE_CHANGE:
RoleChange(JumpEventHeader<struct hci_ev_role_change>(event), request);
break;
case HCI_EVENT_NUM_COMP_PKTS:
break;
case HCI_EVENT_MODE_CHANGE:
break;
case HCI_EVENT_RETURN_LINK_KEYS:
break;
case HCI_EVENT_LINK_KEY_REQ:
break;
case HCI_EVENT_LINK_KEY_NOTIFY:
LinkKeyNotify(JumpEventHeader<struct hci_ev_link_key_notify>
(event), request);
break;
case HCI_EVENT_LOOPBACK_COMMAND:
break;
case HCI_EVENT_DATA_BUFFER_OVERFLOW:
break;
case HCI_EVENT_MAX_SLOT_CHANGE:
MaxSlotChange(JumpEventHeader<struct hci_ev_max_slot_change>(event),
request);
break;
case HCI_EVENT_READ_CLOCK_OFFSET_COMPL:
break;
case HCI_EVENT_CON_PKT_TYPE_CHANGED:
break;
case HCI_EVENT_QOS_VIOLATION:
break;
case HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE:
PageScanRepetitionModeChange(
JumpEventHeader<struct hci_ev_page_scan_rep_mode_change>(event),
request);
break;
case HCI_EVENT_FLOW_SPECIFICATION:
break;
case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:
break;
case HCI_EVENT_REMOTE_EXTENDED_FEATURES:
break;
case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETED:
break;
case HCI_EVENT_SYNCHRONOUS_CONNECTION_CHANGED:
break;
}
}
void void
LocalDeviceImpl::HandleEvent(struct hci_event_header* event) LocalDeviceImpl::HandleEvent(struct hci_event_header* event)
{ {
@@ -105,180 +259,70 @@ LocalDeviceImpl::HandleEvent(struct hci_event_header* event)
} }
printf("### \n"); printf("### \n");
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"Incomming %s event\n", BMessage* request = NULL;
BluetoothEvent(event->ecode)); int32 eventIndexLocation;
// Events here might have not been initated by us // Check if it is a requested one
// 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_CMD_COMPLETE:
HardwareError((struct hci_ev_hardware_error*)(event + 1)); {
return; struct hci_ev_cmd_complete* commandComplete
= JumpEventHeader<struct hci_ev_cmd_complete>(event);
case HCI_EVENT_CONN_REQUEST: Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
ConnectionRequest((struct hci_ev_conn_request*)(event + 1), NULL); "Incomming CommandComplete for %s\n",
return; BluetoothCommandOpcode(commandComplete->opcode));
case HCI_EVENT_CONN_COMPLETE: request = FindPetition(event->ecode, commandComplete->opcode,
// should belong to a request? can be sporadic or initiated by us¿?... &eventIndexLocation);
ConnectionComplete((struct hci_ev_conn_complete*)(event + 1), NULL);
return;
case HCI_EVENT_PIN_CODE_REQ: if (request != NULL)
PinCodeRequest((struct hci_ev_pin_code_req*)(event + 1), NULL); CommandComplete(commandComplete, request, eventIndexLocation);
return;
break;
}
case HCI_EVENT_CMD_STATUS:
{
struct hci_ev_cmd_status* commandStatus
= JumpEventHeader<struct hci_ev_cmd_status>(event);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
"Incomming CommandStatus for %s\n",
BluetoothCommandOpcode(commandStatus->opcode));
request = FindPetition(event->ecode, commandStatus->opcode,
&eventIndexLocation);
if (request != NULL)
CommandStatus(commandStatus, request, eventIndexLocation);
break;
}
default: default:
// lets go on Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"Incomming %s event\n",
BluetoothEvent(event->ecode));
request = FindPetition(event->ecode);
if (request != NULL)
HandleExpectedRequest(event, request);
break; break;
} }
BMessage* request = NULL; if (request == NULL)
int32 eventIndexLocation;
// Check if it is a requested one
if (event->ecode == HCI_EVENT_CMD_COMPLETE) {
request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)
(event + 1))->opcode, &eventIndexLocation);
} else if (event->ecode == HCI_EVENT_CMD_STATUS) {
request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)
(event + 1))->opcode, &eventIndexLocation);
} else {
request = FindPetition(event->ecode);
}
if (request == NULL) {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()), Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
"Event %x could not be understood or delivered\n", event->ecode); "Event %s could not be understood or delivered\n",
return; BluetoothEvent(event->ecode));
}
// we are waiting for a reply HandleUnexpectedEvent(event);
switch (event->ecode) {
case HCI_EVENT_INQUIRY_COMPLETE:
InquiryComplete((uint8*)(event + 1), request);
break;
case HCI_EVENT_INQUIRY_RESULT:
InquiryResult((uint8*)(event + 1), request);
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
// should belong to a request? can be sporadic or initiated by us¿?...
DisconnectionComplete((struct hci_ev_disconnection_complete_reply*)
(event + 1), request);
break;
case HCI_EVENT_AUTH_COMPLETE:
break;
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
RemoteNameRequestComplete((struct hci_ev_remote_name_request_complete_reply*)
(event + 1), request);
break;
case HCI_EVENT_ENCRYPT_CHANGE:
break;
case HCI_EVENT_CHANGE_CONN_LINK_KEY_COMPLETE:
break;
case HCI_EVENT_MASTER_LINK_KEY_COMPL:
break;
case HCI_EVENT_RMT_FEATURES:
break;
case HCI_EVENT_RMT_VERSION:
break;
case HCI_EVENT_QOS_SETUP_COMPLETE:
break;
case HCI_EVENT_CMD_COMPLETE:
CommandComplete((struct hci_ev_cmd_complete*)(event + 1),
request, eventIndexLocation);
break;
case HCI_EVENT_CMD_STATUS:
CommandStatus((struct hci_ev_cmd_status*)(event + 1), request,
eventIndexLocation);
break;
case HCI_EVENT_FLUSH_OCCUR:
break;
case HCI_EVENT_ROLE_CHANGE:
RoleChange((struct hci_ev_role_change*)(event + 1), request,
eventIndexLocation);
break;
case HCI_EVENT_NUM_COMP_PKTS:
break;
case HCI_EVENT_MODE_CHANGE:
break;
case HCI_EVENT_RETURN_LINK_KEYS:
break;
case HCI_EVENT_LINK_KEY_REQ:
break;
case HCI_EVENT_LINK_KEY_NOTIFY:
LinkKeyNotify((struct hci_ev_link_key_notify*)(event + 1),
request, eventIndexLocation);
break;
case HCI_EVENT_LOOPBACK_COMMAND:
break;
case HCI_EVENT_DATA_BUFFER_OVERFLOW:
break;
case HCI_EVENT_MAX_SLOT_CHANGE:
MaxSlotChange((struct hci_ev_max_slot_change*)(event + 1), request,
eventIndexLocation);
break;
case HCI_EVENT_READ_CLOCK_OFFSET_COMPL:
break;
case HCI_EVENT_CON_PKT_TYPE_CHANGED:
break;
case HCI_EVENT_QOS_VIOLATION:
break;
case HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE:
PageScanRepetitionModeChange((struct hci_ev_page_scan_rep_mode_change*)
(event+1), request, eventIndexLocation);
break;
case HCI_EVENT_FLOW_SPECIFICATION:
break;
case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:
break;
case HCI_EVENT_REMOTE_EXTENDED_FEATURES:
break;
case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETED:
break;
case HCI_EVENT_SYNCHRONOUS_CONNECTION_CHANGED:
break;
}
} }
#if 0
#pragma mark -
#endif
void void
LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
BMessage* request, BMessage* request,
@@ -293,14 +337,16 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
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);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) for %s\n",__FUNCTION__, Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s(%d) for %s\n",
event->ncmd, BluetoothCommandOpcode(opcodeExpected)); __FUNCTION__, event->ncmd, BluetoothCommandOpcode(opcodeExpected));
switch ((uint16)opcodeExpected) { switch ((uint16)opcodeExpected) {
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION): case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION):
{ {
struct hci_rp_read_loc_version* version = (struct hci_rp_read_loc_version*)(event + 1); struct hci_rp_read_loc_version* version
= JumpEventHeader<struct hci_rp_read_loc_version,
struct hci_ev_cmd_complete>(event);
if (version->status == BT_OK) { if (version->status == BT_OK) {
@@ -322,7 +368,8 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
} }
Output::Instance()->Postf(BLACKBOARD_KIT, "Reply for Local Version %x\n", version->status); Output::Instance()->Postf(BLACKBOARD_KIT,
"Reply for Local Version %x\n", version->status);
reply.AddInt8("status", version->status); reply.AddInt8("status", version->status);
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
@@ -336,7 +383,8 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_FEATURES): case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_FEATURES):
{ {
struct hci_rp_read_loc_features* features struct hci_rp_read_loc_features* features
= (struct hci_rp_read_loc_features*)(event + 1); = JumpEventHeader<struct hci_rp_read_loc_features,
struct hci_ev_cmd_complete>(event);
if (features->status == BT_OK) { if (features->status == BT_OK) {
@@ -370,7 +418,8 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
} }
Output::Instance()->Postf(BLACKBOARD_KIT, "Reply for Local Features %x\n", features->status); Output::Instance()->Postf(BLACKBOARD_KIT,
"Reply for Local Features %x\n", features->status);
reply.AddInt8("status", features->status); reply.AddInt8("status", features->status);
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
@@ -383,7 +432,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE): case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE):
{ {
struct hci_rp_read_buffer_size* buffer = (struct hci_rp_read_buffer_size*)(event + 1); struct hci_rp_read_buffer_size* buffer
= JumpEventHeader<struct hci_rp_read_buffer_size,
struct hci_ev_cmd_complete>(event);
if (buffer->status == BT_OK) { if (buffer->status == BT_OK) {
@@ -401,8 +452,8 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
} }
Output::Instance()->Postf(BLACKBOARD_KIT, "Reply for Read Buffer Size %x\n", Output::Instance()->Postf(BLACKBOARD_KIT,
buffer->status); "Reply for Read Buffer Size %x\n", buffer->status);
reply.AddInt8("status", buffer->status); reply.AddInt8("status", buffer->status);
@@ -416,15 +467,18 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR): case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR):
{ {
struct hci_rp_read_bd_addr* readbdaddr = (struct hci_rp_read_bd_addr*)(event + 1); struct hci_rp_read_bd_addr* readbdaddr
= JumpEventHeader<struct hci_rp_read_bd_addr,
struct hci_ev_cmd_complete>(event);
if (readbdaddr->status == BT_OK) { if (readbdaddr->status == BT_OK) {
reply.AddData("bdaddr", B_ANY_TYPE, &readbdaddr->bdaddr, sizeof(bdaddr_t)); reply.AddData("bdaddr", B_ANY_TYPE, &readbdaddr->bdaddr,
Output::Instance()->Post("Positive reply for getAddress\n", BLACKBOARD_KIT); sizeof(bdaddr_t));
} else {
Output::Instance()->Post("Negative reply for getAddress\n", BLACKBOARD_KIT);
} }
Output::Instance()->Postf(BLACKBOARD_KIT,
"Read bdaddr status = %x\n", readbdaddr->status);
reply.AddInt8("status", readbdaddr->status); reply.AddInt8("status", readbdaddr->status);
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
reply.PrintToStream(); reply.PrintToStream();
@@ -437,15 +491,19 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV):
{ {
struct hci_read_dev_class_reply* classDev = (struct hci_read_dev_class_reply*)(event + 1); struct hci_read_dev_class_reply* classDev
= JumpEventHeader<struct hci_read_dev_class_reply,
struct hci_ev_cmd_complete>(event);
if (classDev->status == BT_OK) { if (classDev->status == BT_OK) {
reply.AddData("devclass", B_ANY_TYPE, &classDev->dev_class, sizeof(classDev->dev_class)); reply.AddData("devclass", B_ANY_TYPE, &classDev->dev_class,
sizeof(classDev->dev_class));
} }
Output::Instance()->Postf(BLACKBOARD_KIT, Output::Instance()->Postf(BLACKBOARD_KIT,
"Read DeviceClass status = %x DeviceClass = [%x][%x][%x]\n", classDev->status, "Read DeviceClass status = %x DeviceClass = [%x][%x][%x]\n",
classDev->dev_class[0], classDev->dev_class[1], classDev->dev_class[2]); classDev->status, classDev->dev_class[0],
classDev->dev_class[1], classDev->dev_class[2]);
reply.AddInt8("status", classDev->status); reply.AddInt8("status", classDev->status);
@@ -459,16 +517,18 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME):
{ {
struct hci_rp_read_local_name* readLocalName = (struct hci_rp_read_local_name*)(event + 1); struct hci_rp_read_local_name* readLocalName
= JumpEventHeader<struct hci_rp_read_local_name,
struct hci_ev_cmd_complete>(event);
if (readLocalName->status == BT_OK) { if (readLocalName->status == BT_OK) {
reply.AddString("friendlyname", (const char*)readLocalName->local_name ); reply.AddString("friendlyname", (const char*)readLocalName->local_name);
Output::Instance()->Post("Positive reply for friendly name\n", BLACKBOARD_KIT);
} else {
Output::Instance()->Post("Negative reply for friendly name\n", BLACKBOARD_KIT);
} }
Output::Instance()->Postf(BLACKBOARD_KIT, "Friendly name status %x\n",
readLocalName->status);
reply.AddInt8("status", readLocalName->status); reply.AddInt8("status", readLocalName->status);
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
reply.PrintToStream(); reply.PrintToStream();
@@ -483,11 +543,8 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
uint8* statusReply = (uint8*)(event + 1); uint8* statusReply = (uint8*)(event + 1);
// TODO: This reply has to match the BDADDR of the outgoing message // TODO: This reply has to match the BDADDR of the outgoing message
if (*statusReply == BT_OK) { Output::Instance()->Postf(BLACKBOARD_KIT, "pincode accept status %x\n",
Output::Instance()->Post("Positive reply for pincode accept\n", BLACKBOARD_KIT); *statusReply);
} else {
Output::Instance()->Post("Negative reply for pincode accept\n", BLACKBOARD_KIT);
}
reply.AddInt8("status", *statusReply); reply.AddInt8("status", *statusReply);
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
@@ -505,11 +562,8 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
// TODO: This reply might to match the BDADDR of the outgoing message // TODO: This reply might to match the BDADDR of the outgoing message
// => FindPetition should be expanded.... // => FindPetition should be expanded....
if (*statusReply == BT_OK) { Output::Instance()->Postf(BLACKBOARD_KIT, "pincode reject status %x\n",
Output::Instance()->Post("Positive reply for pincode reject\n", BLACKBOARD_KIT); *statusReply);
} else {
Output::Instance()->Post("Negative reply for pincode reject\n", BLACKBOARD_KIT);
}
reply.AddInt8("status", *statusReply); reply.AddInt8("status", *statusReply);
printf("Sending reply ... %ld\n",request->SendReply(&reply)); printf("Sending reply ... %ld\n",request->SendReply(&reply));
@@ -529,7 +583,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event,
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__, BluetoothCommandOpcode(opcodeExpected), *(uint8*)(event+1)); __FUNCTION__, BluetoothCommandOpcode(opcodeExpected), *(uint8*)(event + 1));
request->SendReply(&reply); request->SendReply(&reply);
@@ -555,8 +609,9 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
// Handle command complete information // Handle command complete information
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",
event->ncmd, event->status, BluetoothCommandOpcode(event->opcode)); __FUNCTION__, 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);
@@ -567,11 +622,8 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
{ {
reply.what = BT_MSG_INQUIRY_STARTED; reply.what = BT_MSG_INQUIRY_STARTED;
if (event->status == BT_OK) { Output::Instance()->Postf(BLACKBOARD_KIT,
Output::Instance()->Post("Positive reply for inquiry status\n", BLACKBOARD_KIT); "Inquiry status %x\n", event->status);
} else {
Output::Instance()->Post("Negative reply for inquiry status\n", BLACKBOARD_KIT);
}
reply.AddInt8("status", event->status); reply.AddInt8("status", event->status);
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
@@ -588,7 +640,8 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, ClearWantedEvent(request, HCI_EVENT_CMD_STATUS,
PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST));
} else { } else {
Output::Instance()->Post("Wrong Command Status for remote friendly name\n", BLACKBOARD_KIT); Output::Instance()->Postf(BLACKBOARD_KIT,
"Command Status for remote friendly name %x\n", event->status);
reply.AddInt8("status", event->status); reply.AddInt8("status", event->status);
printf("Sending reply ... %ld\n", request->SendReply(&reply)); printf("Sending reply ... %ld\n", request->SendReply(&reply));
@@ -652,7 +705,8 @@ LocalDeviceImpl::InquiryComplete(uint8* status, BMessage* request)
void void
LocalDeviceImpl::RemoteNameRequestComplete( LocalDeviceImpl::RemoteNameRequestComplete(
struct hci_ev_remote_name_request_complete_reply* remotename, BMessage* request) struct hci_ev_remote_name_request_complete_reply* remotename,
BMessage* request)
{ {
BMessage reply; BMessage reply;
@@ -662,9 +716,11 @@ LocalDeviceImpl::RemoteNameRequestComplete(
reply.AddInt8("status", remotename->status); reply.AddInt8("status", remotename->status);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for %s with status %s\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
"%s for %s with status %s\n",
BluetoothEvent(HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE), BluetoothEvent(HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE),
bdaddrUtils::ToString(remotename->bdaddr), BluetoothError(remotename->status)); 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();
@@ -691,7 +747,8 @@ LocalDeviceImpl::ConnectionRequest(struct hci_ev_conn_request* event, BMessage*
BMessage* newrequest = new BMessage; BMessage* newrequest = new BMessage;
newrequest->AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); newrequest->AddInt16("eventExpected", HCI_EVENT_CMD_STATUS);
newrequest->AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ)); newrequest->AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL,
OCF_ACCEPT_CONN_REQ));
newrequest->AddInt16("eventExpected", HCI_EVENT_PIN_CODE_REQ); newrequest->AddInt16("eventExpected", HCI_EVENT_PIN_CODE_REQ);
newrequest->AddInt16("eventExpected", HCI_EVENT_ROLE_CHANGE); newrequest->AddInt16("eventExpected", HCI_EVENT_ROLE_CHANGE);
@@ -705,7 +762,7 @@ LocalDeviceImpl::ConnectionRequest(struct hci_ev_conn_request* event, BMessage*
if ((fHCIDelegate)->IssueCommand(command, size) == B_ERROR) { if ((fHCIDelegate)->IssueCommand(command, size) == B_ERROR) {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()), Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
"Command issue error for ConnAccept\n"); "Command issue error for ConnAccept\n");
// remove the request ¿? // remove the request?
} else { } else {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()), Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
"Command issue for ConnAccept\n"); "Command issue for ConnAccept\n");
@@ -743,11 +800,11 @@ LocalDeviceImpl::DisconnectionComplete(struct hci_ev_disconnection_complete_repl
{ {
Output::Instance()->Post("Disconnected\n", BLACKBOARD_KIT); Output::Instance()->Post("Disconnected\n", BLACKBOARD_KIT);
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s: Handle=%#x, reason=%x status=%x\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
__FUNCTION__, event->handle, event->reason, event->status); "%s: Handle=%#x, reason=%x status=%x\n", __FUNCTION__, event->handle,
event->reason, event->status);
ClearWantedEvent(request); ClearWantedEvent(request);
} }
@@ -760,46 +817,50 @@ LocalDeviceImpl::PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* req
void void
LocalDeviceImpl::RoleChange(hci_ev_role_change* event, BMessage* request, int32 index) LocalDeviceImpl::RoleChange(hci_ev_role_change* event, BMessage* request)
{ {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s: Address %s role=%d status=%d\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
__FUNCTION__, bdaddrUtils::ToString(event->bdaddr), event->role, event->status); "%s: Address %s role=%d status=%d\n", __FUNCTION__,
bdaddrUtils::ToString(event->bdaddr), event->role, event->status);
} }
void void
LocalDeviceImpl::PageScanRepetitionModeChange(struct hci_ev_page_scan_rep_mode_change* event, LocalDeviceImpl::PageScanRepetitionModeChange(struct hci_ev_page_scan_rep_mode_change* event,
BMessage* request, int32 index) BMessage* request)
{ {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s: Address %s type=%d\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
__FUNCTION__, bdaddrUtils::ToString(event->bdaddr), event->page_scan_rep_mode); "%s: Address %s type=%d\n", __FUNCTION__,
bdaddrUtils::ToString(event->bdaddr), event->page_scan_rep_mode);
} }
void void
LocalDeviceImpl::LinkKeyNotify(hci_ev_link_key_notify* event, LocalDeviceImpl::LinkKeyNotify(hci_ev_link_key_notify* event,
BMessage* request, int32 index) BMessage* request)
{ {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s: Address %s, key=%s, type=%d\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
__FUNCTION__, bdaddrUtils::ToString(event->bdaddr), "%s: Address %s, key=%s, type=%d\n", __FUNCTION__,
bdaddrUtils::ToString(event->bdaddr),
LinkKeyUtils::ToString(event->link_key), event->key_type); LinkKeyUtils::ToString(event->link_key), event->key_type);
} }
void void
LocalDeviceImpl::MaxSlotChange(struct hci_ev_max_slot_change* event, LocalDeviceImpl::MaxSlotChange(struct hci_ev_max_slot_change* event,
BMessage* request, int32 index) BMessage* request)
{ {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s: Handle=%#x, max slots=%d\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
__FUNCTION__, event->handle, event->lmp_max_slots); "%s: Handle=%#x, max slots=%d\n", __FUNCTION__,
event->handle, event->lmp_max_slots);
} }
void void
LocalDeviceImpl::HardwareError(struct hci_ev_hardware_error* event) LocalDeviceImpl::HardwareError(struct hci_ev_hardware_error* event)
{ {
Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s: hardware code=%#x\n", Output::Instance()->Postf(BLACKBOARD_LD(GetID()),
__FUNCTION__, event->hardware_code); "%s: hardware code=%#x\n", __FUNCTION__, event->hardware_code);
} }
@@ -821,9 +882,11 @@ LocalDeviceImpl::ProcessSimpleRequest(BMessage* request)
// LEAK: is command buffer freed within the Message? // LEAK: is command buffer freed within the Message?
if (((HCITransportAccessor*)fHCIDelegate)->IssueCommand(command, size) if (((HCITransportAccessor*)fHCIDelegate)->IssueCommand(command, size)
== B_ERROR) { == B_ERROR) {
// TODO: - Reply the request with error! // TODO:
// - Remove the just added request // Reply the request with error!
(Output::Instance()->Post("## ERROR Command issue, REMOVING!\n", BLACKBOARD_KIT)); // Remove the just added request
(Output::Instance()->Post("## ERROR Command issue, REMOVING!\n",
BLACKBOARD_KIT));
ClearWantedEvent(request); ClearWantedEvent(request);
} else { } else {
+9 -10
View File
@@ -1,10 +1,7 @@
/* /*
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
*/ */
#ifndef _LOCALDEVICE_IMPL_H_ #ifndef _LOCALDEVICE_IMPL_H_
#define _LOCALDEVICE_IMPL_H_ #define _LOCALDEVICE_IMPL_H_
@@ -21,7 +18,7 @@
class LocalDeviceImpl : public LocalDeviceHandler { class LocalDeviceImpl : public LocalDeviceHandler {
private: private:
LocalDeviceImpl(HCIDelegate* hd); LocalDeviceImpl(HCIDelegate* hd);
public: public:
@@ -34,10 +31,12 @@ public:
void HandleEvent(struct hci_event_header* event); void HandleEvent(struct hci_event_header* event);
// Request handling // Request handling
status_t GetAddress(bdaddr_t* bdaddr, BMessage* request);
status_t GetFriendlyName(BString str, BMessage* request);
status_t ProcessSimpleRequest(BMessage* request); status_t ProcessSimpleRequest(BMessage* request);
private:
void HandleUnexpectedEvent(struct hci_event_header* event);
void HandleExpectedRequest(struct hci_event_header* event, BMessage* request);
// Events handling // Events handling
void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index); void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index);
void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index); void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index);
@@ -54,10 +53,10 @@ public:
// Pairing // Pairing
void PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request); void PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request);
void RoleChange(struct hci_ev_role_change* event, BMessage* request, int32 index); void RoleChange(struct hci_ev_role_change* event, BMessage* request);
void LinkKeyNotify(struct hci_ev_link_key_notify* event, BMessage* request, int32 index); void LinkKeyNotify(struct hci_ev_link_key_notify* event, BMessage* request);
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);
void MaxSlotChange(struct hci_ev_max_slot_change* event, BMessage* request, int32 index); void MaxSlotChange(struct hci_ev_max_slot_change* event, BMessage* request);
void HardwareError(struct hci_ev_hardware_error* event); void HardwareError(struct hci_ev_hardware_error* event);