diff --git a/src/kits/bluetooth/DiscoveryAgent.cpp b/src/kits/bluetooth/DiscoveryAgent.cpp index 3ca048affb..82c70ad599 100644 --- a/src/kits/bluetooth/DiscoveryAgent.cpp +++ b/src/kits/bluetooth/DiscoveryAgent.cpp @@ -7,38 +7,123 @@ #include #include - #include +#include + +#include + +#include +#include + +#include +#include + + +#include "KitSupport.h" namespace Bluetooth { -RemoteDevice** +RemoteDevicesList DiscoveryAgent::RetrieveDevices(int option) { - return NULL; + /* No inquiry process initiated */ + if (fLastUsedListener == NULL) + return NULL; + return fLastUsedListener->GetRemoteDevicesList(); } -bool -DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener listener) +status_t +DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener) { - return false; - + return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME); } -bool -DiscoveryAgent::CancelInquiry(DiscoveryListener listener) +status_t +DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) { - return false; + 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; + int8 bt_status = BT_ERROR; + + // 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); + 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)); + + if (btsm->SendMessage(&request, listener) == B_OK) + { + return B_OK; + } + + return B_ERROR; + +} + + +status_t +DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) +{ + BMessenger* btsm = NULL; + + 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()); + // TODO: Add the raw command to the BMessage + expected event(s) + + + + if (btsm->SendMessage(&request, listener) == 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() { - + fLocalDevice = NULL; } + } diff --git a/src/kits/bluetooth/DiscoveryListener.cpp b/src/kits/bluetooth/DiscoveryListener.cpp index ad0b4ee293..f9f836630c 100644 --- a/src/kits/bluetooth/DiscoveryListener.cpp +++ b/src/kits/bluetooth/DiscoveryListener.cpp @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -18,7 +20,7 @@ namespace Bluetooth { /* hooks */ void -DiscoveryListener::DeviceDiscovered(RemoteDevice btDevice, DeviceClass cod) +DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) { @@ -41,51 +43,85 @@ DiscoveryListener::InquiryCompleted(int discType) /* private */ -DiscoveryListener::DiscoveryListener() -{ +/* 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; } -void +RemoteDevicesList +DiscoveryListener::GetRemoteDevicesList(void) +{ + return fRemoteDevicesList; +} + + +void DiscoveryListener::MessageReceived(BMessage* message) { - switch (message->what) + int8 status; + + switch (message->what) { case BT_MSG_INQUIRY_DEVICE: - - /* TODO: Extract info from BMessage to create a - proper RemoteDevice, message should be passed from Agent??? */ - - /* - Instance to be stored/Registered in the Agent? */ - //DeviceDiscovered( RemoteDevice(BString("00:00:00:00:00:00")), DeviceClass(0)); + { + const struct inquiry_info* inquiryInfo; + ssize_t size; + if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK ) + { + RemoteDevice* rd = new RemoteDevice(inquiryInfo->bdaddr); + // DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) + // fRemoteDevicesList.AddItem(rd); + rd->SetLocalDeviceOwner(fLocalDevice); + 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){ + InquiryStarted(status); + } + + break; + case BT_MSG_INQUIRY_COMPLETED: - InquiryCompleted(B_BT_INQUIRY_COMPLETED); + InquiryCompleted(BT_INQUIRY_COMPLETED); break; - case BT_MSG_INQUIRY_TERMINATED: + case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ - InquiryCompleted(B_BT_INQUIRY_TERMINATED); + InquiryCompleted(BT_INQUIRY_TERMINATED); break; case BT_MSG_INQUIRY_ERROR: - InquiryCompleted(B_BT_INQUIRY_ERROR); + InquiryCompleted(BT_INQUIRY_ERROR); break; - + default: BLooper::MessageReceived(message); break; - - } - -} + + } + +} + + +DiscoveryListener::DiscoveryListener() : BLooper() +{ + +} + } diff --git a/src/kits/bluetooth/Jamfile b/src/kits/bluetooth/Jamfile index 0eb026f116..a1a4a8a95c 100644 --- a/src/kits/bluetooth/Jamfile +++ b/src/kits/bluetooth/Jamfile @@ -8,10 +8,12 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) { UsePrivateHeaders bluetooth ; +SharedLibrary libbluetooth.so : SharedLibrary libbluetooth.so : LocalDevice.cpp - DiscoveryAgent.cpp DiscoveryListener.cpp + DiscoveryAgent.cpp + RemoteDevice.cpp CommandManager.cpp KitSupport.cpp : be diff --git a/src/kits/bluetooth/RemoteDevice.cpp b/src/kits/bluetooth/RemoteDevice.cpp new file mode 100644 index 0000000000..7d88ee1295 --- /dev/null +++ b/src/kits/bluetooth/RemoteDevice.cpp @@ -0,0 +1,85 @@ +#include +#include +#include + +#include + +namespace Bluetooth { + + +bool +RemoteDevice::IsTrustedDevice(void) +{ + return true; +} + + +BString +RemoteDevice::GetFriendlyName(bool alwaysAsk) +{ + return BString("Not implemented"); +} + + +BString +RemoteDevice::GetBluetoothAddress() +{ + return BString(bdaddrUtils::ToString(fBdaddr)); +} + + +bool +RemoteDevice::Equals(RemoteDevice* obj) +{ + return true; +} + +// 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; +} + +/* Private */ +void +RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld) +{ + fDiscovererLocalDevice = ld; +} + +/* Constructor */ +RemoteDevice::RemoteDevice(bdaddr_t address) +{ + fBdaddr = address; +} + +RemoteDevice::RemoteDevice(BString address) +{ + /* TODO */ + +} + +} \ No newline at end of file