- 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:
parent
7976c871ff
commit
d581ede6e2
@ -7,38 +7,123 @@
|
||||
|
||||
#include <bluetooth/DiscoveryAgent.h>
|
||||
#include <bluetooth/DiscoveryListener.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 {
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <bluetooth/RemoteDevice.h>
|
||||
#include <bluetooth/DeviceClass.h>
|
||||
|
||||
#include <bluetooth/HCI/btHCI_event.h>
|
||||
|
||||
#include <bluetoothserver_p.h>
|
||||
|
||||
#include <Message.h>
|
||||
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
85
src/kits/bluetooth/RemoteDevice.cpp
Normal file
85
src/kits/bluetooth/RemoteDevice.cpp
Normal 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 */
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user