diff --git a/src/kits/bluetooth/DiscoveryAgent.cpp b/src/kits/bluetooth/DiscoveryAgent.cpp index 7bb4a0779d..c1bc3db444 100644 --- a/src/kits/bluetooth/DiscoveryAgent.cpp +++ b/src/kits/bluetooth/DiscoveryAgent.cpp @@ -1,138 +1,138 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -#include "KitSupport.h" - -namespace Bluetooth { - - -RemoteDevicesList -DiscoveryAgent::RetrieveDevices(int option) -{ - /* No inquiry process initiated */ - if (fLastUsedListener == NULL) - return NULL; // xxx: Fix me - - return fLastUsedListener->GetRemoteDevicesList(); -} - - -status_t -DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener) -{ - return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME); -} - - -status_t -DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) -{ - BMessenger* btsm = NULL; - size_t size; - - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) - return B_ERROR; - - if (secs < 1 || secs > 61 ) - return B_TIMED_OUT; - - void* startInquiryCommand = NULL; - - // keep the listener whats the current listener for our inquiry state - fLastUsedListener = listener; - - // Inform the listener who is gonna be its owner LocalDevice - // and its discovered devices - listener->SetLocalDeviceOwner(fLocalDevice); - - /* Issue inquiry command */ - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); - BMessage reply; - - request.AddInt32("hci_id", fLocalDevice->GetID()); - - startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size); - - // For stating the inquiry - request.AddData("raw command", B_ANY_TYPE, startInquiryCommand, size); - request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); - - // For getting each discovered message - request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_RESULT); - - // For finishing each discovered message - request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_COMPLETE); - - - if (btsm->SendMessage(&request, listener) == B_OK) - { - return B_OK; - } - - return B_ERROR; - -} - - -status_t -DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) -{ - BMessenger* btsm = NULL; //TODO: this should be a member field - size_t size; - - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) - return B_ERROR; - - void* cancelInquiryCommand = NULL; - int8 bt_status = BT_ERROR; - - /* Issue inquiry command */ - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); - BMessage reply; - - request.AddInt32("hci_id", fLocalDevice->GetID()); - - cancelInquiryCommand = buildInquiryCancel(&size); - request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size); - request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL)); - - if (btsm->SendMessage(&request, &reply) == B_OK) { - if (reply.FindInt8("status", &bt_status ) == B_OK ) { - return bt_status; - } - } - - return B_ERROR; -} - -void -DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) -{ - fLocalDevice = ld; -} - -DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) -{ - fLocalDevice = ld; -} - - -} +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +#include "KitSupport.h" + +namespace Bluetooth { + + +RemoteDevicesList +DiscoveryAgent::RetrieveDevices(int option) +{ + /* No inquiry process initiated */ + if (fLastUsedListener == NULL) + return NULL; // xxx: Fix me + + return fLastUsedListener->GetRemoteDevicesList(); +} + + +status_t +DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener) +{ + return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME); +} + + +status_t +DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) +{ + BMessenger* btsm = NULL; + size_t size; + + if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + return B_ERROR; + + if (secs < 1 || secs > 61 ) + return B_TIMED_OUT; + + void* startInquiryCommand = NULL; + + // keep the listener whats the current listener for our inquiry state + fLastUsedListener = listener; + + // Inform the listener who is gonna be its owner LocalDevice + // and its discovered devices + listener->SetLocalDeviceOwner(fLocalDevice); + + /* Issue inquiry command */ + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + + request.AddInt32("hci_id", fLocalDevice->GetID()); + + startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size); + + // For stating the inquiry + request.AddData("raw command", B_ANY_TYPE, startInquiryCommand, size); + request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); + + // For getting each discovered message + request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_RESULT); + + // For finishing each discovered message + request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_COMPLETE); + + + if (btsm->SendMessage(&request, listener) == B_OK) + { + return B_OK; + } + + return B_ERROR; + +} + + +status_t +DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) +{ + BMessenger* btsm = NULL; //TODO: this should be a member field + size_t size; + + if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + return B_ERROR; + + void* cancelInquiryCommand = NULL; + int8 bt_status = BT_ERROR; + + /* Issue inquiry command */ + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + + request.AddInt32("hci_id", fLocalDevice->GetID()); + + cancelInquiryCommand = buildInquiryCancel(&size); + request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size); + request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL)); + + if (btsm->SendMessage(&request, &reply) == B_OK) { + if (reply.FindInt8("status", &bt_status ) == B_OK ) { + return bt_status; + } + } + + return B_ERROR; +} + +void +DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) +{ + fLocalDevice = ld; +} + +DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) +{ + fLocalDevice = ld; +} + + +} diff --git a/src/kits/bluetooth/DiscoveryListener.cpp b/src/kits/bluetooth/DiscoveryListener.cpp index 79ac6fc76e..ebebf5e304 100644 --- a/src/kits/bluetooth/DiscoveryListener.cpp +++ b/src/kits/bluetooth/DiscoveryListener.cpp @@ -1,161 +1,161 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -namespace Bluetooth { - - -/* hooks */ -void -DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) -{ - -} - - -void -DiscoveryListener::InquiryStarted(status_t status) -{ - -} - - -void -DiscoveryListener::InquiryCompleted(int discType) -{ - -} - - -/* private */ - -/* A LocalDevice is always referenced in any request to the - Bluetooth server therefore is going to be needed in any */ -void -DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) -{ - fLocalDevice = ld; -} - - -RemoteDevicesList -DiscoveryListener::GetRemoteDevicesList(void) -{ - return fRemoteDevicesList; -} - - -void -DiscoveryListener::MessageReceived(BMessage* message) -{ - int8 status; - - switch (message->what) - { - case BT_MSG_INQUIRY_DEVICE: - { - const struct inquiry_info* inquiryInfo; - ssize_t size; - RemoteDevice* rd = NULL; - bool duplicatedFound = false; - - if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK ) - { - - // Skip duplicated replies - for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) { - - bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress(); - - if (bdaddrUtils::Compare( (bdaddr_t*) &inquiryInfo->bdaddr, &b1 )) { - - // update these values - fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; - fRemoteDevicesList.ItemAt(index)->fScanPeriodMode = inquiryInfo->pscan_period_mode; - fRemoteDevicesList.ItemAt(index)->fScanMode = inquiryInfo->pscan_mode; - fRemoteDevicesList.ItemAt(index)->fClockOffset = inquiryInfo->clock_offset; - - duplicatedFound = true; - break; - } - - } - - if (!duplicatedFound) { - - // TODO: DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) - rd = new RemoteDevice(inquiryInfo->bdaddr); - fRemoteDevicesList.AddItem(rd); - // keep all inquiry reported data - rd->SetLocalDeviceOwner(fLocalDevice); - rd->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; - rd->fScanPeriodMode = inquiryInfo->pscan_period_mode; - rd->fScanMode = inquiryInfo->pscan_mode; - rd->fClockOffset = inquiryInfo->clock_offset; - - DeviceDiscovered( rd, DeviceClass(inquiryInfo->dev_class[0] | - inquiryInfo->dev_class[1]<<8 | - inquiryInfo->dev_class[2]<<16 )); - } - } - } - break; - - case BT_MSG_INQUIRY_STARTED: - if (message->FindInt8("status", &status) == B_OK){ - fRemoteDevicesList.MakeEmpty(); - InquiryStarted(status); - } - - break; - - case BT_MSG_INQUIRY_COMPLETED: - - InquiryCompleted(BT_INQUIRY_COMPLETED); - - break; - case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ - - InquiryCompleted(BT_INQUIRY_TERMINATED); - - break; - case BT_MSG_INQUIRY_ERROR: - - InquiryCompleted(BT_INQUIRY_ERROR); - - break; - - default: - - BLooper::MessageReceived(message); - - break; - - } - -} - - -DiscoveryListener::DiscoveryListener() : BLooper() , fRemoteDevicesList(BT_MAX_RESPONSES) -{ - // TODO: Make a better handling of the running not running state - Run(); -} - - -} +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include +#include +#include +#include +#include + +#include + +#include + +#include + +namespace Bluetooth { + + +/* hooks */ +void +DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) +{ + +} + + +void +DiscoveryListener::InquiryStarted(status_t status) +{ + +} + + +void +DiscoveryListener::InquiryCompleted(int discType) +{ + +} + + +/* private */ + +/* A LocalDevice is always referenced in any request to the + Bluetooth server therefore is going to be needed in any */ +void +DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) +{ + fLocalDevice = ld; +} + + +RemoteDevicesList +DiscoveryListener::GetRemoteDevicesList(void) +{ + return fRemoteDevicesList; +} + + +void +DiscoveryListener::MessageReceived(BMessage* message) +{ + int8 status; + + switch (message->what) + { + case BT_MSG_INQUIRY_DEVICE: + { + const struct inquiry_info* inquiryInfo; + ssize_t size; + RemoteDevice* rd = NULL; + bool duplicatedFound = false; + + if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK ) + { + + // Skip duplicated replies + for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) { + + bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress(); + + if (bdaddrUtils::Compare( (bdaddr_t*) &inquiryInfo->bdaddr, &b1 )) { + + // update these values + fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; + fRemoteDevicesList.ItemAt(index)->fScanPeriodMode = inquiryInfo->pscan_period_mode; + fRemoteDevicesList.ItemAt(index)->fScanMode = inquiryInfo->pscan_mode; + fRemoteDevicesList.ItemAt(index)->fClockOffset = inquiryInfo->clock_offset; + + duplicatedFound = true; + break; + } + + } + + if (!duplicatedFound) { + + // TODO: DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) + rd = new RemoteDevice(inquiryInfo->bdaddr); + fRemoteDevicesList.AddItem(rd); + // keep all inquiry reported data + rd->SetLocalDeviceOwner(fLocalDevice); + rd->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; + rd->fScanPeriodMode = inquiryInfo->pscan_period_mode; + rd->fScanMode = inquiryInfo->pscan_mode; + rd->fClockOffset = inquiryInfo->clock_offset; + + DeviceDiscovered( rd, DeviceClass(inquiryInfo->dev_class[0] | + inquiryInfo->dev_class[1]<<8 | + inquiryInfo->dev_class[2]<<16 )); + } + } + } + break; + + case BT_MSG_INQUIRY_STARTED: + if (message->FindInt8("status", &status) == B_OK){ + fRemoteDevicesList.MakeEmpty(); + InquiryStarted(status); + } + + break; + + case BT_MSG_INQUIRY_COMPLETED: + + InquiryCompleted(BT_INQUIRY_COMPLETED); + + break; + case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ + + InquiryCompleted(BT_INQUIRY_TERMINATED); + + break; + case BT_MSG_INQUIRY_ERROR: + + InquiryCompleted(BT_INQUIRY_ERROR); + + break; + + default: + + BLooper::MessageReceived(message); + + break; + + } + +} + + +DiscoveryListener::DiscoveryListener() : BLooper() , fRemoteDevicesList(BT_MAX_RESPONSES) +{ + // TODO: Make a better handling of the running not running state + Run(); +} + + +} diff --git a/src/kits/bluetooth/LocalDevice.cpp b/src/kits/bluetooth/LocalDevice.cpp index 10e7bcb24f..7d13efbbf8 100644 --- a/src/kits/bluetooth/LocalDevice.cpp +++ b/src/kits/bluetooth/LocalDevice.cpp @@ -1,265 +1,265 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include "KitSupport.h" - -/* TODO: remove me */ -#include - -namespace Bluetooth { - -BMessenger* LocalDevice::sfMessenger = NULL; - - -LocalDevice* -LocalDevice::RequestLocalDeviceID(BMessage* request) -{ - BMessage reply; - hci_id hid; - - if (sfMessenger->SendMessage(request, &reply) == B_OK && - reply.FindInt32("hci_id", &hid) == B_OK ){ - - if (hid >= 0) { - return new LocalDevice(hid); - } - } - - return NULL; -} - - -#if 0 -#pragma - -#endif - - -LocalDevice* -LocalDevice::GetLocalDevice() -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - - return RequestLocalDeviceID(&request); -} - - -LocalDevice* -LocalDevice::GetLocalDevice(hci_id hid) -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - request.AddInt32("hci_id", hid); - - return RequestLocalDeviceID(&request); - -} - - -LocalDevice* -LocalDevice::GetLocalDevice(bdaddr_t bdaddr) -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t)); - - - return RequestLocalDeviceID(&request); -} - - -uint32 -LocalDevice::GetLocalDeviceCount() -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return 0; - - BMessage request(BT_MSG_COUNT_LOCAL_DEVICES); - BMessage reply; - - if (sfMessenger->SendMessage(&request, &reply) == B_OK) - return reply.FindInt32("count"); - else - return 0; - -} - - -DiscoveryAgent* -LocalDevice::GetDiscoveryAgent() -{ - /* TODO: Study a singleton here */ - return new DiscoveryAgent(this); -} - - -BString -LocalDevice::GetProperty(const char* property) -{ - - return NULL; - -} - - -void -LocalDevice::GetProperty(const char* property, uint32* value) -{ - - *value = 0; -} - - -int -LocalDevice::GetDiscoverable() -{ - - return 0; -} - - -status_t -LocalDevice::SetDiscoverable(int mode) -{ - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return B_ERROR; - - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); - BMessage reply; - - size_t size; - int8 bt_status = BT_ERROR; - - - request.AddInt32("hci_id", hid); - - - void* command = buildWriteScan(mode, &size); - - if (command == NULL) { - return B_NO_MEMORY; - } - - 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_WRITE_SCAN_ENABLE)); - - if (fMessenger->SendMessage(&request, &reply) == B_OK) { - if (reply.FindInt8("status", &bt_status ) == B_OK ) { - return bt_status; - - } - - } - - return B_ERROR; -} - - -bdaddr_t -LocalDevice::GetBluetoothAddress() -{ - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return bdaddrUtils::NullAddress(); - - const bdaddr_t* bdaddr; - BMessage request(BT_MSG_GET_ADDRESS); - BMessage reply; - ssize_t size; - - /* ADD ID */ - request.AddInt32("hci_id", hid); - - if (fMessenger->SendMessage(&request, &reply) == B_OK) { - - if (reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &size) == B_OK ){ - - return *bdaddr; - - } else { - return bdaddrUtils::NullAddress(); - } - - } - - return bdaddrUtils::NullAddress(); -} - - -BString -LocalDevice::GetFriendlyName() -{ - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BString friendlyname; - BMessage request(BT_MSG_GET_FRIENDLY_NAME); - BMessage reply; - - /* ADD ID */ - request.AddInt32("hci_id", hid); - - if (fMessenger->SendMessage(&request, &reply) == B_OK && - reply.FindString("friendlyname", &friendlyname) == B_OK ){ - - return friendlyname; - } - - return BString("Unknown"); -} - - -DeviceClass -LocalDevice::GetDeviceClass() -{ - - return DeviceClass(0); - -} - - -/* -ServiceRecord -LocalDevice::getRecord(Connection notifier) { - -} - -void -LocalDevice::updateRecord(ServiceRecord srvRecord) { - -} -*/ - - -LocalDevice::LocalDevice(hci_id hid) : hid(hid) -{ - -} - - -} +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "KitSupport.h" + +/* TODO: remove me */ +#include + +namespace Bluetooth { + +BMessenger* LocalDevice::sfMessenger = NULL; + + +LocalDevice* +LocalDevice::RequestLocalDeviceID(BMessage* request) +{ + BMessage reply; + hci_id hid; + + if (sfMessenger->SendMessage(request, &reply) == B_OK && + reply.FindInt32("hci_id", &hid) == B_OK ){ + + if (hid >= 0) { + return new LocalDevice(hid); + } + } + + return NULL; +} + + +#if 0 +#pragma - +#endif + + +LocalDevice* +LocalDevice::GetLocalDevice() +{ + if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) + return NULL; + + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); + + return RequestLocalDeviceID(&request); +} + + +LocalDevice* +LocalDevice::GetLocalDevice(hci_id hid) +{ + if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) + return NULL; + + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); + request.AddInt32("hci_id", hid); + + return RequestLocalDeviceID(&request); + +} + + +LocalDevice* +LocalDevice::GetLocalDevice(bdaddr_t bdaddr) +{ + if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) + return NULL; + + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); + request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t)); + + + return RequestLocalDeviceID(&request); +} + + +uint32 +LocalDevice::GetLocalDeviceCount() +{ + if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) + return 0; + + BMessage request(BT_MSG_COUNT_LOCAL_DEVICES); + BMessage reply; + + if (sfMessenger->SendMessage(&request, &reply) == B_OK) + return reply.FindInt32("count"); + else + return 0; + +} + + +DiscoveryAgent* +LocalDevice::GetDiscoveryAgent() +{ + /* TODO: Study a singleton here */ + return new DiscoveryAgent(this); +} + + +BString +LocalDevice::GetProperty(const char* property) +{ + + return NULL; + +} + + +void +LocalDevice::GetProperty(const char* property, uint32* value) +{ + + *value = 0; +} + + +int +LocalDevice::GetDiscoverable() +{ + + return 0; +} + + +status_t +LocalDevice::SetDiscoverable(int mode) +{ + if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) + return B_ERROR; + + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + + size_t size; + int8 bt_status = BT_ERROR; + + + request.AddInt32("hci_id", hid); + + + void* command = buildWriteScan(mode, &size); + + if (command == NULL) { + return B_NO_MEMORY; + } + + 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_WRITE_SCAN_ENABLE)); + + if (fMessenger->SendMessage(&request, &reply) == B_OK) { + if (reply.FindInt8("status", &bt_status ) == B_OK ) { + return bt_status; + + } + + } + + return B_ERROR; +} + + +bdaddr_t +LocalDevice::GetBluetoothAddress() +{ + if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) + return bdaddrUtils::NullAddress(); + + const bdaddr_t* bdaddr; + BMessage request(BT_MSG_GET_ADDRESS); + BMessage reply; + ssize_t size; + + /* ADD ID */ + request.AddInt32("hci_id", hid); + + if (fMessenger->SendMessage(&request, &reply) == B_OK) { + + if (reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &size) == B_OK ){ + + return *bdaddr; + + } else { + return bdaddrUtils::NullAddress(); + } + + } + + return bdaddrUtils::NullAddress(); +} + + +BString +LocalDevice::GetFriendlyName() +{ + if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) + return NULL; + + BString friendlyname; + BMessage request(BT_MSG_GET_FRIENDLY_NAME); + BMessage reply; + + /* ADD ID */ + request.AddInt32("hci_id", hid); + + if (fMessenger->SendMessage(&request, &reply) == B_OK && + reply.FindString("friendlyname", &friendlyname) == B_OK ){ + + return friendlyname; + } + + return BString("Unknown"); +} + + +DeviceClass +LocalDevice::GetDeviceClass() +{ + + return DeviceClass(0); + +} + + +/* +ServiceRecord +LocalDevice::getRecord(Connection notifier) { + +} + +void +LocalDevice::updateRecord(ServiceRecord srvRecord) { + +} +*/ + + +LocalDevice::LocalDevice(hci_id hid) : hid(hid) +{ + +} + + +} diff --git a/src/kits/bluetooth/RemoteDevice.cpp b/src/kits/bluetooth/RemoteDevice.cpp index 466a1c3f9b..08f9063841 100644 --- a/src/kits/bluetooth/RemoteDevice.cpp +++ b/src/kits/bluetooth/RemoteDevice.cpp @@ -1,187 +1,187 @@ -/* - * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include "KitSupport.h" - - - -namespace Bluetooth { - - -bool -RemoteDevice::IsTrustedDevice(void) -{ - return true; -} - - -BString -RemoteDevice::GetFriendlyName(bool alwaysAsk) -{ - - if (!alwaysAsk) { - // Check if the name is already retrieved - return BString("Not implemented"); - - // TODO: Check if It is known from a KnownDevicesList - } - - if (fDiscovererLocalDevice == NULL) - return BString("#NoOwnerError#Not Valid name"); - - BMessenger* btsm = NULL; - size_t size; - - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) - return BString("#ServerNotReady#Not Valid name"); - - void* remoteNameCommand = NULL; - - /* Issue inquiry command */ - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); - BMessage reply; - - request.AddInt32("hci_id", fDiscovererLocalDevice->GetID()); - - // Fill the request - remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily - - request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size); - - request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); - //request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); - - if (btsm->SendMessage(&request, &reply) == B_OK) - { - BString name; - int8 status; - - if (reply.FindInt8("status", &status) == B_OK && - reply.FindString("friendlyname", &name) == B_OK ) { - return name; - } - } - - return BString("#NotCompletedRequestr#Not Valid name"); -} - - -BString -RemoteDevice::GetFriendlyName() -{ - return GetFriendlyName(true); -} - - -bdaddr_t -RemoteDevice::GetBluetoothAddress() -{ - return fBdaddr; -} - - -bool -RemoteDevice::Equals(RemoteDevice* obj) -{ - bdaddr_t ba = obj->GetBluetoothAddress(); - - return bdaddrUtils::Compare(&fBdaddr, &ba); -} - -// static RemoteDevice* GetRemoteDevice(Connection conn); - -bool -RemoteDevice::Authenticate() -{ - return true; -} - - -// bool Authorize(Connection conn); -// bool Encrypt(Connection conn, bool on); - - -bool -RemoteDevice::IsAuthenticated() -{ - return true; -} - - -// bool IsAuthorized(Connection conn); - - -bool -RemoteDevice::IsEncrypted() -{ - return true; -} - -LocalDevice* -RemoteDevice::GetLocalDeviceOwner() -{ - return fDiscovererLocalDevice; -} - -/* Private */ -void -RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld) -{ - fDiscovererLocalDevice = ld; -} - - -/* Constructor */ -RemoteDevice::RemoteDevice(bdaddr_t address) -{ - fBdaddr = address; -} - - -RemoteDevice::RemoteDevice(BString address) -{ - /* TODO */ - -} - - -BString -RemoteDevice::GetProperty(const char* property) /* Throwing */ -{ - - return NULL; -} - - -void -RemoteDevice::GetProperty(const char* property, uint32* value) /* Throwing */ -{ - -} - - -} - - -DeviceClass -RemoteDevice::GetDeviceClass() -{ - return fDeviceClass; -} +/* + * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "KitSupport.h" + + + +namespace Bluetooth { + + +bool +RemoteDevice::IsTrustedDevice(void) +{ + return true; +} + + +BString +RemoteDevice::GetFriendlyName(bool alwaysAsk) +{ + + if (!alwaysAsk) { + // Check if the name is already retrieved + return BString("Not implemented"); + + // TODO: Check if It is known from a KnownDevicesList + } + + if (fDiscovererLocalDevice == NULL) + return BString("#NoOwnerError#Not Valid name"); + + BMessenger* btsm = NULL; + size_t size; + + if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + return BString("#ServerNotReady#Not Valid name"); + + void* remoteNameCommand = NULL; + + /* Issue inquiry command */ + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + + request.AddInt32("hci_id", fDiscovererLocalDevice->GetID()); + + // Fill the request + remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily + + request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size); + + request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); + //request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); + + if (btsm->SendMessage(&request, &reply) == B_OK) + { + BString name; + int8 status; + + if (reply.FindInt8("status", &status) == B_OK && + reply.FindString("friendlyname", &name) == B_OK ) { + return name; + } + } + + return BString("#NotCompletedRequestr#Not Valid name"); +} + + +BString +RemoteDevice::GetFriendlyName() +{ + return GetFriendlyName(true); +} + + +bdaddr_t +RemoteDevice::GetBluetoothAddress() +{ + return fBdaddr; +} + + +bool +RemoteDevice::Equals(RemoteDevice* obj) +{ + bdaddr_t ba = obj->GetBluetoothAddress(); + + return bdaddrUtils::Compare(&fBdaddr, &ba); +} + +// static RemoteDevice* GetRemoteDevice(Connection conn); + +bool +RemoteDevice::Authenticate() +{ + return true; +} + + +// bool Authorize(Connection conn); +// bool Encrypt(Connection conn, bool on); + + +bool +RemoteDevice::IsAuthenticated() +{ + return true; +} + + +// bool IsAuthorized(Connection conn); + + +bool +RemoteDevice::IsEncrypted() +{ + return true; +} + +LocalDevice* +RemoteDevice::GetLocalDeviceOwner() +{ + return fDiscovererLocalDevice; +} + +/* Private */ +void +RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld) +{ + fDiscovererLocalDevice = ld; +} + + +/* Constructor */ +RemoteDevice::RemoteDevice(bdaddr_t address) +{ + fBdaddr = address; +} + + +RemoteDevice::RemoteDevice(BString address) +{ + /* TODO */ + +} + + +BString +RemoteDevice::GetProperty(const char* property) /* Throwing */ +{ + + return NULL; +} + + +void +RemoteDevice::GetProperty(const char* property, uint32* value) /* Throwing */ +{ + +} + + +} + + +DeviceClass +RemoteDevice::GetDeviceClass() +{ + return fDeviceClass; +}