hrev44586 adds 1 changeset to branch 'master' old head: 9089ab06bdf75de4116252a549f25b8d723c0267 new head: 7a74a5df454197933bc6e80a542102362ee98703 ---------------------------------------------------------------------------- 7a74a5d: WIP... Updating Bluetooth. * Some bugfixes. * added scan mode read. * inactivated some printout for now. Was a lot of noice in terminal [ Fredrik Modéen <fredrik@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev44586 Commit: 7a74a5df454197933bc6e80a542102362ee98703 URL: http://cgit.haiku-os.org/haiku/commit/?id=7a74a5d Author: Fredrik Modéen <fredrik@xxxxxxxxx> Date: Mon Aug 27 19:22:35 2012 UTC ---------------------------------------------------------------------------- 12 files changed, 231 insertions(+), 115 deletions(-) headers/os/bluetooth/HCI/btHCI_command.h | 12 +- headers/private/bluetooth/CommandManager.h | 2 + src/kits/bluetooth/CommandManager.cpp | 8 +- src/kits/bluetooth/LocalDevice.cpp | 26 +++- .../bluetooth/BluetoothSettingsView.cpp | 103 +++++++------- src/preferences/bluetooth/BluetoothSettingsView.h | 2 + .../bluetooth/ExtendedLocalDeviceView.cpp | 47 ++++++- .../bluetooth/ExtendedLocalDeviceView.h | 1 + src/servers/bluetooth/BluetoothServer.cpp | 4 +- src/servers/bluetooth/HCITransportAccessor.cpp | 4 +- src/servers/bluetooth/LocalDeviceHandler.cpp | 21 +-- src/servers/bluetooth/LocalDeviceImpl.cpp | 116 +++++++++++----- ---------------------------------------------------------------------------- diff --git a/headers/os/bluetooth/HCI/btHCI_command.h b/headers/os/bluetooth/HCI/btHCI_command.h index e0f5619..e1da81f 100644 --- a/headers/os/bluetooth/HCI/btHCI_command.h +++ b/headers/os/bluetooth/HCI/btHCI_command.h @@ -115,11 +115,17 @@ struct hci_command_header { } __attribute__ ((packed)); #define OCF_WRITE_PG_TIMEOUT 0x0018 + #define OCF_READ_SCAN_ENABLE 0x0019 + struct hci_read_scan_enable { + uint8 status; + uint8 enable; + } __attribute__ ((packed)); + #define OCF_WRITE_SCAN_ENABLE 0x001A #define HCI_SCAN_DISABLED 0x00 - #define HCI_SCAN_INQUIRY 0x01 - #define HCI_SCAN_PAGE 0x02 - #define HCI_SCAN_INQUIRY_PAGE 0x03 + #define HCI_SCAN_INQUIRY 0x01 //Page Scan disabled + #define HCI_SCAN_PAGE 0x02 //Inquiry Scan disabled + #define HCI_SCAN_INQUIRY_PAGE 0x03 //All enabled struct hci_write_scan_enable { uint8 scan; } __attribute__ ((packed)); diff --git a/headers/private/bluetooth/CommandManager.h b/headers/private/bluetooth/CommandManager.h index 46876e4..5464764 100644 --- a/headers/private/bluetooth/CommandManager.h +++ b/headers/private/bluetooth/CommandManager.h @@ -1,6 +1,7 @@ /* * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com * Copyright 2008 Mika Lindqvist + * Copyright 2012 Fredrik Modéen [firstname]@[lastname].se * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef _COMMAND_MANAGER_H @@ -104,6 +105,7 @@ SingleParameterCommandRequest(uint8 ofg, uint8 ocf, PARAMETERTYPE parameter, /* CONTROL BASEBAND */ void* buildReset(size_t* outsize); void* buildReadLocalName(size_t* outsize); +void* buildReadScan(size_t* outsize); void* buildWriteScan(uint8 scanmode, size_t* outsize); void* buildReadClassOfDevice(size_t* outsize); diff --git a/src/kits/bluetooth/CommandManager.cpp b/src/kits/bluetooth/CommandManager.cpp index 00b9957..fad66ca 100644 --- a/src/kits/bluetooth/CommandManager.cpp +++ b/src/kits/bluetooth/CommandManager.cpp @@ -106,6 +106,13 @@ void* buildReadClassOfDevice(size_t* outsize) } +void* buildReadScan(size_t* outsize) +{ + return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_SCAN_ENABLE, + NULL, 0, outsize); +} + + void* buildWriteScan(uint8 scanmode, size_t* outsize) { struct hci_write_scan_enable* param; @@ -118,7 +125,6 @@ void* buildWriteScan(uint8 scanmode, size_t* outsize) } return command; - } diff --git a/src/kits/bluetooth/LocalDevice.cpp b/src/kits/bluetooth/LocalDevice.cpp index 7d76a92..8862546 100644 --- a/src/kits/bluetooth/LocalDevice.cpp +++ b/src/kits/bluetooth/LocalDevice.cpp @@ -1,6 +1,7 @@ /* * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com + * Copyright 2012 Fredrik Modéen, [firstname]@[lastname] * All rights reserved. Distributed under the terms of the MIT License. */ @@ -147,9 +148,29 @@ LocalDevice::GetProperty(const char* property, uint32* value) int LocalDevice::GetDiscoverable() -{ +{ + if (fMessenger == NULL) + return -1; + + size_t size; + void* command = buildReadScan(&size); + if (command == NULL) + return -1; - return 0; + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + request.AddInt32("hci_id", fHid); + request.AddData("raw command", B_ANY_TYPE, command, size); + request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, + OCF_READ_SCAN_ENABLE)); + + int8 discoverable; + BMessage reply; + if (fMessenger->SendMessage(&request, &reply) == B_OK + && reply.FindInt8("scan_enable", &discoverable) == B_OK) + return discoverable; + + return -1; } @@ -184,7 +205,6 @@ LocalDevice::SetDiscoverable(int mode) return bt_status; } - } return B_ERROR; diff --git a/src/preferences/bluetooth/BluetoothSettingsView.cpp b/src/preferences/bluetooth/BluetoothSettingsView.cpp index f2e893d..b9ba836 100644 --- a/src/preferences/bluetooth/BluetoothSettingsView.cpp +++ b/src/preferences/bluetooth/BluetoothSettingsView.cpp @@ -30,13 +30,7 @@ #define B_TRANSLATION_CONTEXT "Settings view" static const int32 kMsgSetConnectionPolicy = 'sCpo'; - -static const int32 kMsgSetDeviceClassDesktop = 'sDCd'; -static const int32 kMsgSetDeviceClassServer = 'sDCs'; -static const int32 kMsgSetDeviceClassLaptop = 'sDCl'; -static const int32 kMsgSetDeviceClassHandheld = 'sDCh'; -static const int32 kMsgSetDeviceClassSmartPhone = 'sDCp'; - +static const int32 kMsgSetDeviceClass = 'sDC0'; static const int32 kMsgSetInquiryTime = 'afEa'; static const int32 kMsgLocalSwitched = 'lDsW'; @@ -108,7 +102,6 @@ BluetoothSettingsView::BluetoothSettingsView(const char* name) .SetInsets(10, 10, 10, 10) ); - } @@ -136,9 +129,6 @@ BluetoothSettingsView::AttachedToWindow() void BluetoothSettingsView::MessageReceived(BMessage* message) { - - DeviceClass devClass; - switch (message->what) { case kMsgLocalSwitched: { @@ -151,44 +141,29 @@ BluetoothSettingsView::MessageReceived(BMessage* message) } } break; - - case kMsgSetDeviceClassDesktop: - { - devClass.SetRecord(1, 1, 0x72); - if (ActiveLocalDevice != NULL) - ActiveLocalDevice->SetDeviceClass(devClass); - break; - } - - case kMsgSetDeviceClassServer: - { - devClass.SetRecord(1, 2, 0x72); - if (ActiveLocalDevice != NULL) - ActiveLocalDevice->SetDeviceClass(devClass); - break; - } - - case kMsgSetDeviceClassLaptop: +/* + To be fixed :) + case kMsgSetConnectionPolicy: { - devClass.SetRecord(1, 3, 0x72); - if (ActiveLocalDevice != NULL) - ActiveLocalDevice->SetDeviceClass(devClass); + //uint8 Policy; + //if (message->FindInt8("Policy", (int8*)&Policy) == B_OK) break; } - - case kMsgSetDeviceClassHandheld: + + case kMsgSetInquiryTime: { - devClass.SetRecord(1, 4, 0x72); - if (ActiveLocalDevice != NULL) - ActiveLocalDevice->SetDeviceClass(devClass); break; - } + }*/ - case kMsgSetDeviceClassSmartPhone: + case kMsgSetDeviceClass: { - devClass.SetRecord(2, 3, 0x72); - if (ActiveLocalDevice != NULL) - ActiveLocalDevice->SetDeviceClass(devClass); + uint8 deviceClass; + if (message->FindInt8("DeviceClass", (int8*)&deviceClass) == B_OK) { + if (deviceClass == 5) + _SetDeviceClass(2, 3, 0x72); + else + _SetDeviceClass(1, deviceClass, 0x72); + } break; } @@ -202,6 +177,22 @@ BluetoothSettingsView::MessageReceived(BMessage* message) } +bool +BluetoothSettingsView::_SetDeviceClass(uint8 major, uint8 minor, uint16 service) +{ + bool haveRun = true; + + DeviceClass devClass; + devClass.SetRecord(major, minor, service); + if (ActiveLocalDevice != NULL) + ActiveLocalDevice->SetDeviceClass(devClass); + else + haveRun = false; + + return haveRun; +} + + void BluetoothSettingsView::_BuildConnectionPolicy() { @@ -216,46 +207,50 @@ BluetoothSettingsView::_BuildConnectionPolicy() fPolicyMenu->AddItem(item); message = new BMessage(kMsgSetConnectionPolicy); - message->AddBool("Policy", 2); + message->AddInt8("Policy", 2); item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kTrustedLabel), message); fPolicyMenu->AddItem(item); message = new BMessage(kMsgSetConnectionPolicy); - message->AddBool("Policy", 3); + message->AddInt8("Policy", 3); item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kAlwaysLabel), NULL); fPolicyMenu->AddItem(item); - } void BluetoothSettingsView::_BuildClassMenu() { + + BMessage* message = NULL; + BMenuItem* item = NULL; fClassMenu = new BPopUpMenu(B_TRANSLATE("Identify us as...")); - BMessage* message; - message = new BMessage(kMsgSetDeviceClassDesktop); - BMenuItem* item - = new BMenuItem(B_TRANSLATE_NOCOLLECT(kDesktopLabel), message); + message = new BMessage(kMsgSetDeviceClass); + message->AddInt8("DeviceClass", 1); + item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kDesktopLabel), message); fClassMenu->AddItem(item); - message = new BMessage(kMsgSetDeviceClassServer); + message = new BMessage(kMsgSetDeviceClass); + message->AddInt8("DeviceClass", 2); item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kServerLabel), message); fClassMenu->AddItem(item); - message = new BMessage(kMsgSetDeviceClassLaptop); + message = new BMessage(kMsgSetDeviceClass); + message->AddInt8("DeviceClass", 3); item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kLaptopLabel), message); fClassMenu->AddItem(item); - message = new BMessage(kMsgSetDeviceClassHandheld); + message = new BMessage(kMsgSetDeviceClass); + message->AddInt8("DeviceClass", 4); item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kHandheldLabel), message); fClassMenu->AddItem(item); - message = new BMessage(kMsgSetDeviceClassSmartPhone); + message = new BMessage(kMsgSetDeviceClass); + message->AddInt8("DeviceClass", 5); item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kPhoneLabel), message); fClassMenu->AddItem(item); - } diff --git a/src/preferences/bluetooth/BluetoothSettingsView.h b/src/preferences/bluetooth/BluetoothSettingsView.h index 455c47e..d46bd16 100644 --- a/src/preferences/bluetooth/BluetoothSettingsView.h +++ b/src/preferences/bluetooth/BluetoothSettingsView.h @@ -28,6 +28,8 @@ private: void _BuildConnectionPolicy(); void _BuildClassMenu(); void _BuildLocalDevicesMenu(); + bool _SetDeviceClass(uint8 major, uint8 minor + , uint16 service); protected: float fDivider; diff --git a/src/preferences/bluetooth/ExtendedLocalDeviceView.cpp b/src/preferences/bluetooth/ExtendedLocalDeviceView.cpp index afa5bce..575c044 100644 --- a/src/preferences/bluetooth/ExtendedLocalDeviceView.cpp +++ b/src/preferences/bluetooth/ExtendedLocalDeviceView.cpp @@ -41,8 +41,7 @@ ExtendedLocalDeviceView::ExtendedLocalDeviceView(BRect frame, fAuthentication = new BCheckBox(iDontCare, "Authenticate", B_TRANSLATE("Authenticate"), new BMessage(SET_AUTHENTICATION)); - fDiscoverable->SetEnabled(false); - fVisible->SetEnabled(false); + SetEnabled(false); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .Add(fDeviceView) @@ -56,7 +55,6 @@ ExtendedLocalDeviceView::ExtendedLocalDeviceView(BRect frame, .Add(BSpaceLayoutItem::CreateVerticalStrut(0)) .SetInsets(5, 5, 5, 5) ); - } @@ -69,10 +67,24 @@ ExtendedLocalDeviceView::~ExtendedLocalDeviceView(void) void ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice) { + printf("ExtendedLocalDeviceView::SetLocalDevice\n"); if (lDevice != NULL) { fDevice = lDevice; SetName(lDevice->GetFriendlyName().String()); fDeviceView->SetBluetoothDevice(lDevice); + + ClearDevice(); + + int value = fDevice->GetDiscoverable(); + printf("ExtendedLocalDeviceView::SetLocalDevice value = %d\n", value); + if (value == 1) + fDiscoverable->SetValue(true); + else if (value == 2) + fVisible->SetValue(true); + else if (value == 3) { + fDiscoverable->SetValue(true); + fVisible->SetValue(true); + } } } @@ -80,6 +92,7 @@ ExtendedLocalDeviceView::SetLocalDevice(LocalDevice* lDevice) void ExtendedLocalDeviceView::AttachedToWindow() { + printf("ExtendedLocalDeviceView::AttachedToWindow\n"); fDiscoverable->SetTarget(this); fVisible->SetTarget(this); fAuthentication->SetTarget(this); @@ -89,13 +102,20 @@ ExtendedLocalDeviceView::AttachedToWindow() void ExtendedLocalDeviceView::SetTarget(BHandler* target) { - + printf("ExtendedLocalDeviceView::SetTarget\n"); } void ExtendedLocalDeviceView::MessageReceived(BMessage* message) { + printf("ExtendedLocalDeviceView::MessageReceived\n"); + + if (fDevice == NULL) { + printf("ExtendedLocalDeviceView::Device missing\n"); + return; + } + if (message->WasDropped()) { } @@ -116,12 +136,14 @@ ExtendedLocalDeviceView::MessageReceived(BMessage* message) if (fVisible->Value()) fScanMode |= 2; + if (fDevice != NULL) fDevice->SetDiscoverable(fScanMode); break; case SET_AUTHENTICATION: - fDevice->SetAuthentication(fAuthentication->Value()); + if (fDevice != NULL) + fDevice->SetAuthentication(fAuthentication->Value()); break; default: @@ -134,5 +156,20 @@ ExtendedLocalDeviceView::MessageReceived(BMessage* message) void ExtendedLocalDeviceView::SetEnabled(bool value) { + printf("ExtendedLocalDeviceView::SetEnabled\n"); + + fVisible->SetEnabled(value); + fAuthentication->SetEnabled(value); fDiscoverable->SetEnabled(value); } + + +void +ExtendedLocalDeviceView::ClearDevice() +{ + printf("ExtendedLocalDeviceView::ClearDevice\n"); + + fVisible->SetValue(false); + fAuthentication->SetValue(false); + fDiscoverable->SetValue(false); +} diff --git a/src/preferences/bluetooth/ExtendedLocalDeviceView.h b/src/preferences/bluetooth/ExtendedLocalDeviceView.h index efd7437..3a3526c 100644 --- a/src/preferences/bluetooth/ExtendedLocalDeviceView.h +++ b/src/preferences/bluetooth/ExtendedLocalDeviceView.h @@ -34,6 +34,7 @@ public: virtual void AttachedToWindow(); virtual void SetTarget(BHandler* target); virtual void SetEnabled(bool value); + void ClearDevice(); protected: LocalDevice* fDevice; diff --git a/src/servers/bluetooth/BluetoothServer.cpp b/src/servers/bluetooth/BluetoothServer.cpp index 14c4a1c..40da9da 100644 --- a/src/servers/bluetooth/BluetoothServer.cpp +++ b/src/servers/bluetooth/BluetoothServer.cpp @@ -246,8 +246,8 @@ void BluetoothServer::MessageReceived(BMessage* message) if (status != B_WOULD_BLOCK) { reply.AddInt32("status", status); message->SendReply(&reply); - printf("Sending reply message for->\n"); - message->PrintToStream(); +// printf("Sending reply message for->\n"); +// message->PrintToStream(); } } diff --git a/src/servers/bluetooth/HCITransportAccessor.cpp b/src/servers/bluetooth/HCITransportAccessor.cpp index fd758ea..2c070d6 100644 --- a/src/servers/bluetooth/HCITransportAccessor.cpp +++ b/src/servers/bluetooth/HCITransportAccessor.cpp @@ -47,13 +47,13 @@ HCITransportAccessor::IssueCommand(raw_command rc, size_t size) { if (Id() < 0 || fDescriptor < 0) return B_ERROR; - +/* printf("### Command going: len = %ld\n", size); for (uint16 index = 0 ; index < size; index++ ) { printf("%x:",((uint8*)rc)[index]); } printf("### \n"); - +*/ return ioctl(fDescriptor, ISSUE_BT_COMMAND, rc, size); } diff --git a/src/servers/bluetooth/LocalDeviceHandler.cpp b/src/servers/bluetooth/LocalDeviceHandler.cpp index 0d3d0d9..8a0e7ff 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.cpp +++ b/src/servers/bluetooth/LocalDeviceHandler.cpp @@ -65,7 +65,7 @@ LocalDeviceHandler::AddWantedEvent(BMessage* msg) { fEventsWanted.Lock(); // TODO: review why it is needed to replicate the msg - printf("Adding request... %p\n", msg); +// printf("Adding request... %p\n", msg); fEventsWanted.AddMessage(msg); fEventsWanted.Unlock(); } @@ -134,6 +134,7 @@ finish: BMessage* LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) { + //debug data int16 eventFound; int16 opcodeFound; int32 eventIndex; @@ -142,29 +143,29 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) // for each Petition for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { BMessage* msg = fEventsWanted.FindMessage(index); - printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index, - fEventsWanted.CountMessages(), msg); - msg->PrintToStream(); +// printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index, +// fEventsWanted.CountMessages(), msg); +// msg->PrintToStream(); eventIndex = 0; // for each Event while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { if (eventFound == event) { - printf("%s:Event %d found@%ld...", __FUNCTION__, event, eventIndex); +// printf("%s:Event %d found@%ld...", __FUNCTION__, event, eventIndex); // there is an opcode specified.. if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) { // ensure the opcode if ((uint16)opcodeFound != opcode) { - printf("%s:opcode does not match %d\n", - __FUNCTION__, opcode); +// printf("%s:opcode does not match %d\n", +// __FUNCTION__, opcode); eventIndex++; continue; } - printf("Opcode matches %d\n", opcode); +// printf("Opcode matches %d\n", opcode); } else { - printf("No opcode specified\n"); +// printf("No opcode specified\n"); } fEventsWanted.Unlock(); @@ -175,7 +176,7 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) eventIndex++; } } - printf("%s:Event %d not found\n", __FUNCTION__, event); +// printf("%s:Event %d not found\n", __FUNCTION__, event); fEventsWanted.Unlock(); return NULL; diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index 51161d9..b3ed9b5 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -266,13 +266,14 @@ LocalDeviceImpl::HandleExpectedRequest(struct hci_event_header* event, void LocalDeviceImpl::HandleEvent(struct hci_event_header* event) { +/* printf("### Incoming event: len = %d\n", event->elen); for (int16 index = 0; index < event->elen + 2; index++) { printf("%x:", ((uint8*)event)[index]); } printf("### \n"); - +*/ BMessage* request = NULL; int32 eventIndexLocation; @@ -344,6 +345,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, int16 opcodeExpected; BMessage reply; + status_t status; // Handle command complete information request->FindInt16("opcodeExpected", index, &opcodeExpected); @@ -383,8 +385,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, "Reply for Local Version %x\n", version->status); reply.AddInt8("status", version->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -407,8 +410,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, reply.AddInt8("status", pageTimeout->status); reply.AddInt32("result", pageTimeout->page_timeout); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -457,8 +461,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, "Reply for Local Features %x\n", features->status); reply.AddInt8("status", features->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -492,8 +497,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, reply.AddInt8("status", buffer->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -515,8 +521,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, "Read bdaddr status = %x\n", readbdaddr->status); reply.AddInt8("status", readbdaddr->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -542,8 +549,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, reply.AddInt8("status", classDev->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -565,8 +573,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, readLocalName->status); reply.AddInt8("status", readLocalName->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -582,8 +591,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, *statusReply); reply.AddInt8("status", *statusReply); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request/*, HCI_EVENT_CMD_COMPLETE, opcodeExpected*/); @@ -600,8 +610,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, *statusReply); reply.AddInt8("status", *statusReply); - printf("Sending reply ... %ld\n",request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request, HCI_EVENT_CMD_COMPLETE, opcodeExpected); @@ -620,8 +631,9 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, linkKeyRetrieval->max_num_keys, linkKeyRetrieval->num_keys_read); reply.AddInt8("status", linkKeyRetrieval->status); - printf("Sending reply ... %ld\n",request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); ClearWantedEvent(request); break; @@ -642,6 +654,30 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, break; } + case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_SCAN_ENABLE): + { + struct hci_read_scan_enable* scanEnable + = JumpEventHeader<struct hci_read_scan_enable, + struct hci_ev_cmd_complete>(event); + + if (scanEnable->status == BT_OK) { + fProperties->AddInt8("scan_enable", scanEnable->enable); + + Output::Instance()->Postf(BLACKBOARD_LD(GetID()), "enable = %x\n", + scanEnable->enable); + } + + reply.AddInt8("status", scanEnable->status); + reply.AddInt8("scan_enable", scanEnable->enable); + status = request->SendReply(&reply); + printf("Sending reply. scan_enable = %d\n", scanEnable->enable); + // debug reply.PrintToStream(); + + // This request is not gonna be used anymore + ClearWantedEvent(request); + break; + } + // place here all CC that just replies a uint8 status case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_RESET): case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE): @@ -657,7 +693,8 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, Output::Instance()->Postf(BLACKBOARD_LD(GetID()),"%s for %s status %x\n", __FUNCTION__, BluetoothCommandOpcode(opcodeExpected), *(uint8*)(event + 1)); - request->SendReply(&reply); + status = request->SendReply(&reply); + printf("Sending reply write ... %ld\n", status); ClearWantedEvent(request); break; @@ -678,6 +715,7 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, int16 opcodeExpected; BMessage reply; + status_t status; // Handle command complete information request->FindInt16("opcodeExpected", index, &opcodeExpected); @@ -695,8 +733,9 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, "Inquiry status %x\n", event->status); reply.AddInt8("status", event->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); @@ -713,8 +752,9 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, "Command Status for remote friendly name %x\n", event->status); reply.AddInt8("status", event->status); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status = request->SendReply(&reply); + //printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, opcodeExpected); } @@ -770,7 +810,8 @@ LocalDeviceImpl::InquiryResult(uint8* numberOfResponses, BMessage* request) info++; } - printf("%s: Sending reply ... %ld\n",__FUNCTION__, request->SendReply(&reply)); + status_t status = request->SendReply(&reply); + printf("%s: Sending reply ... %ld\n",__FUNCTION__, status); } @@ -780,7 +821,8 @@ LocalDeviceImpl::InquiryComplete(uint8* status, BMessage* request) BMessage reply(BT_MSG_INQUIRY_COMPLETED); reply.AddInt8("status", *status); - printf("%s: Sending reply ... %ld\n",__FUNCTION__, request->SendReply(&reply)); + status_t stat = request->SendReply(&reply); + printf("%s: Sending reply ... %ld\n",__FUNCTION__, stat); ClearWantedEvent(request); } @@ -805,8 +847,9 @@ LocalDeviceImpl::RemoteNameRequestComplete( bdaddrUtils::ToString(remotename->bdaddr), BluetoothError(remotename->status)); - printf("Sending reply ... %ld\n", request->SendReply(&reply)); - reply.PrintToStream(); + status_t status = request->SendReply(&reply); + printf("Sending reply ... %ld\n", status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -877,7 +920,8 @@ LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event, } else { Output::Instance()->Postf(BLACKBOARD_LD(GetID()), - "%s: failed with error %s\n", __FUNCTION__, BluetoothError(event->status)); + "%s: failed with error %s\n", __FUNCTION__, + BluetoothError(event->status)); } // it was expected @@ -888,8 +932,9 @@ LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event, if (event->status == BT_OK) reply.AddInt16("handle", event->handle); - request->SendReply(&reply); - reply.PrintToStream(); + status_t status = request->SendReply(&reply); + printf("%s: Sending reply ... %ld\n",__FUNCTION__, status); + // debug reply.PrintToStream(); // This request is not gonna be used anymore ClearWantedEvent(request); @@ -910,8 +955,9 @@ LocalDeviceImpl::DisconnectionComplete( BMessage reply; reply.AddInt8("status", event->status); - request->SendReply(&reply); - reply.PrintToStream(); + status_t status = request->SendReply(&reply); + printf("%s: Sending reply ... %ld\n",__FUNCTION__, status); + // debug reply.PrintToStream(); ClearWantedEvent(request); }