- Implementation of the discovery classes & RemoteDevice

. Support for StartInquiry method



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24699 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-03-30 21:48:17 +00:00
parent 7976c871ff
commit d581ede6e2
4 changed files with 242 additions and 34 deletions

View File

@ -7,38 +7,123 @@
#include <bluetooth/DiscoveryAgent.h> #include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/DiscoveryListener.h> #include <bluetooth/DiscoveryListener.h>
#include <bluetooth/RemoteDevice.h> #include <bluetooth/RemoteDevice.h>
#include <bluetooth/LocalDevice.h>
#include <bluetooth/bluetooth_error.h>
#include <bluetooth/bluetoothserver_p.h>
#include <bluetooth/CommandManager.h>
#include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h>
#include "KitSupport.h"
namespace Bluetooth { namespace Bluetooth {
RemoteDevice** RemoteDevicesList
DiscoveryAgent::RetrieveDevices(int option) DiscoveryAgent::RetrieveDevices(int option)
{ {
return NULL; /* No inquiry process initiated */
if (fLastUsedListener == NULL)
return NULL;
return fLastUsedListener->GetRemoteDevicesList();
} }
bool status_t
DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener listener) DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener)
{ {
return false; return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME);
} }
bool status_t
DiscoveryAgent::CancelInquiry(DiscoveryListener listener) 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() DiscoveryAgent::DiscoveryAgent()
{ {
fLocalDevice = NULL;
} }
} }

View File

@ -9,6 +9,8 @@
#include <bluetooth/RemoteDevice.h> #include <bluetooth/RemoteDevice.h>
#include <bluetooth/DeviceClass.h> #include <bluetooth/DeviceClass.h>
#include <bluetooth/HCI/btHCI_event.h>
#include <bluetoothserver_p.h> #include <bluetoothserver_p.h>
#include <Message.h> #include <Message.h>
@ -18,7 +20,7 @@ namespace Bluetooth {
/* hooks */ /* hooks */
void void
DiscoveryListener::DeviceDiscovered(RemoteDevice btDevice, DeviceClass cod) DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod)
{ {
@ -41,40 +43,67 @@ DiscoveryListener::InquiryCompleted(int discType)
/* private */ /* 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;
}
RemoteDevicesList
DiscoveryListener::GetRemoteDevicesList(void)
{
return fRemoteDevicesList;
} }
void void
DiscoveryListener::MessageReceived(BMessage* message) DiscoveryListener::MessageReceived(BMessage* message)
{ {
int8 status;
switch (message->what) switch (message->what)
{ {
case BT_MSG_INQUIRY_DEVICE: case BT_MSG_INQUIRY_DEVICE:
{
const struct inquiry_info* inquiryInfo;
ssize_t size;
/* TODO: Extract info from BMessage to create a if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK )
proper RemoteDevice, message should be passed from Agent??? */ {
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 ));
/* - Instance to be stored/Registered in the Agent? */ }
//DeviceDiscovered( RemoteDevice(BString("00:00:00:00:00:00")), DeviceClass(0)); }
break;
case BT_MSG_INQUIRY_STARTED:
if (message->FindInt8("status", &status) == B_OK){
InquiryStarted(status);
}
break; break;
case BT_MSG_INQUIRY_COMPLETED: case BT_MSG_INQUIRY_COMPLETED:
InquiryCompleted(B_BT_INQUIRY_COMPLETED); InquiryCompleted(BT_INQUIRY_COMPLETED);
break; break;
case BT_MSG_INQUIRY_TERMINATED: case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */
InquiryCompleted(B_BT_INQUIRY_TERMINATED); InquiryCompleted(BT_INQUIRY_TERMINATED);
break; break;
case BT_MSG_INQUIRY_ERROR: case BT_MSG_INQUIRY_ERROR:
InquiryCompleted(B_BT_INQUIRY_ERROR); InquiryCompleted(BT_INQUIRY_ERROR);
break; break;
@ -88,4 +117,11 @@ DiscoveryListener::MessageReceived(BMessage* message)
} }
DiscoveryListener::DiscoveryListener() : BLooper()
{
}
} }

View File

@ -8,10 +8,12 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
UsePrivateHeaders bluetooth ; UsePrivateHeaders bluetooth ;
SharedLibrary libbluetooth.so :
SharedLibrary libbluetooth.so : SharedLibrary libbluetooth.so :
LocalDevice.cpp LocalDevice.cpp
DiscoveryAgent.cpp
DiscoveryListener.cpp DiscoveryListener.cpp
DiscoveryAgent.cpp
RemoteDevice.cpp
CommandManager.cpp CommandManager.cpp
KitSupport.cpp KitSupport.cpp
: be : be

View File

@ -0,0 +1,85 @@
#include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/DiscoveryListener.h>
#include <bluetooth/bdaddrUtils.h>
#include <bluetooth/RemoteDevice.h>
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 */
}
}