some cleanups and styling by Mika and me
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28915 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -30,10 +30,10 @@ public:
|
|||||||
static char str[50];
|
static char str[50];
|
||||||
|
|
||||||
sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:"
|
sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:"
|
||||||
"%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
|
"%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
|
||||||
lk.l[0], lk.l[1], lk.l[2], lk.l[3], lk.l[4], lk.l[5],
|
lk.l[0], lk.l[1], lk.l[2], lk.l[3], lk.l[4], lk.l[5],
|
||||||
lk.l[6], lk.l[7], lk.l[8], lk.l[9], lk.l[10], lk.l[11],
|
lk.l[6], lk.l[7], lk.l[8], lk.l[9], lk.l[10], lk.l[11],
|
||||||
lk.l[12], lk.l[13], lk.l[14], lk.l[15]);
|
lk.l[12], lk.l[13], lk.l[14], lk.l[15]);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -43,9 +43,9 @@ public:
|
|||||||
if (lkstr != NULL) {
|
if (lkstr != NULL) {
|
||||||
int l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15;
|
int l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15;
|
||||||
size_t count = sscanf(lkstr, "%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X:"
|
size_t count = sscanf(lkstr, "%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X:"
|
||||||
"%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X", &l0, &l1, &l2, &l3,
|
"%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X", &l0, &l1, &l2, &l3,
|
||||||
&l4, &l5, &l6, &l7, &l8, &l9, &l10, &l11, &l12, &l13,
|
&l4, &l5, &l6, &l7, &l8, &l9, &l10, &l11, &l12, &l13,
|
||||||
&l14, &l15);
|
&l14, &l15);
|
||||||
|
|
||||||
if (count == 16) {
|
if (count == 16) {
|
||||||
return (linkkey_t){{l0, l1, l2, l3, l4, l5, l6, l7, l8,
|
return (linkkey_t){{l0, l1, l2, l3, l4, l5, l6, l7, l8,
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
|
|
||||||
if (addr != NULL) {
|
if (addr != NULL) {
|
||||||
size_t count = sscanf(addr, "%2X:%2X:%2X:%2X:%2X:%2X",
|
size_t count = sscanf(addr, "%2X:%2X:%2X:%2X:%2X:%2X",
|
||||||
&b0, &b1, &b2, &b3, &b4, &b5);
|
&b0, &b1, &b2, &b3, &b4, &b5);
|
||||||
|
|
||||||
if (count == 6)
|
if (count == 6)
|
||||||
return ((bdaddr_t) {{b0, b1, b2, b3, b4, b5}});
|
return ((bdaddr_t) {{b0, b1, b2, b3, b4, b5}});
|
||||||
|
|||||||
@@ -21,28 +21,14 @@ static inline void bacpy(bdaddr_t* dst, bdaddr_t* src)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void baswap(bdaddr_t* dst, bdaddr_t* src) {
|
static inline void baswap(bdaddr_t* dst, bdaddr_t* src)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline char* batostr(bdaddr_t *ba)
|
|
||||||
{
|
{
|
||||||
return "00:00:00:00:00:00";
|
register uint8* d = (uint8*)dst;
|
||||||
|
register uint8* s = (uint8*)src;
|
||||||
|
register int i;
|
||||||
|
|
||||||
}
|
for(i=0; i<6; i++) d[i] = s[5-i];
|
||||||
|
|
||||||
|
|
||||||
static inline void strtoba(const char *str, bdaddr_t *ba)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Link key Management */
|
|
||||||
static inline char* lktostr( uint8 link_key[16] )
|
|
||||||
{
|
|
||||||
return "00:00:00:00:00:00";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
* Copyright 2007-2009 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||||
*
|
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -9,14 +9,12 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <Path.h>
|
|
||||||
#include <Message.h>
|
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <String.h>
|
#include <Message.h>
|
||||||
|
#include <Path.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
@@ -31,7 +29,7 @@
|
|||||||
|
|
||||||
|
|
||||||
BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE)
|
BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE)
|
||||||
{
|
{
|
||||||
Output::Instance()->Run();
|
Output::Instance()->Run();
|
||||||
Output::Instance()->SetTitle("Bluetooth message gathering");
|
Output::Instance()->SetTitle("Bluetooth message gathering");
|
||||||
|
|
||||||
@@ -40,16 +38,15 @@ BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE)
|
|||||||
Output::Instance()->AddTab("Events", BLACKBOARD_EVENTS);
|
Output::Instance()->AddTab("Events", BLACKBOARD_EVENTS);
|
||||||
Output::Instance()->AddTab("Kit", BLACKBOARD_KIT);
|
Output::Instance()->AddTab("Kit", BLACKBOARD_KIT);
|
||||||
|
|
||||||
|
|
||||||
ShowWindow(Output::Instance());
|
ShowWindow(Output::Instance());
|
||||||
|
|
||||||
fDeviceManager = new DeviceManager();
|
fDeviceManager = new DeviceManager();
|
||||||
fLocalDevicesList.MakeEmpty();
|
fLocalDevicesList.MakeEmpty();
|
||||||
|
|
||||||
// TODO: Some events should be handled faster than in KL...
|
// TODO: Some events should be handled faster than in KL...
|
||||||
fEventListener = spawn_thread(notification_Thread, "BT port listener" , B_URGENT_DISPLAY_PRIORITY , this);
|
fEventListener = spawn_thread(notification_Thread, "BT port listener" ,
|
||||||
|
B_URGENT_DISPLAY_PRIORITY , this);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BluetoothServer::QuitRequested(void)
|
bool BluetoothServer::QuitRequested(void)
|
||||||
@@ -58,128 +55,114 @@ bool BluetoothServer::QuitRequested(void)
|
|||||||
Output::Instance()->Lock();
|
Output::Instance()->Lock();
|
||||||
Output::Instance()->Quit();
|
Output::Instance()->Quit();
|
||||||
|
|
||||||
|
LocalDeviceImpl* ldi = NULL;
|
||||||
/* HCIDelegate *hd = NULL;
|
while ((ldi = (LocalDeviceImpl *)fLocalDevicesList.RemoveItem((int32)0))
|
||||||
while ((hd = (HCIDelegate *)fDelegatesList.RemoveItem((int32)0)) !=NULL)
|
!= NULL)
|
||||||
delete hd;
|
delete ldi;
|
||||||
*/
|
|
||||||
|
|
||||||
printf("Accepting quitting of the application\n");
|
printf("Accepting quitting of the application\n");
|
||||||
return BApplication::QuitRequested();
|
return BApplication::QuitRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BluetoothServer::ArgvReceived(int32 argc, char **argv)
|
void BluetoothServer::ArgvReceived(int32 argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc>1) {
|
if (argc>1) {
|
||||||
if (strcmp(argv[1], "--finish") == 0)
|
if (strcmp(argv[1], "--finish") == 0)
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
|
||||||
else {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BluetoothServer::ReadyToRun(void) {
|
void BluetoothServer::ReadyToRun(void)
|
||||||
|
{
|
||||||
fDeviceManager->StartMonitoringDevice("bluetooth/h2generic");
|
fDeviceManager->StartMonitoringDevice("bluetooth/h2generic");
|
||||||
|
|
||||||
|
|
||||||
// Launch the notifier thread
|
// Launch the notifier thread
|
||||||
if ( resume_thread(fEventListener) != B_OK )
|
if ( resume_thread(fEventListener) != B_OK )
|
||||||
{
|
{
|
||||||
Output::Instance()->Post("Bluetooth port listener failed\n", BLACKBOARD_GENERAL);
|
Output::Instance()->Post("Bluetooth port listener failed\n", BLACKBOARD_GENERAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Output::Instance()->Post("Bluetooth server Ready\n", BLACKBOARD_GENERAL);
|
Output::Instance()->Post("Bluetooth server Ready\n", BLACKBOARD_GENERAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothServer::AppActivated(bool act) {
|
|
||||||
|
|
||||||
|
void BluetoothServer::AppActivated(bool act)
|
||||||
|
{
|
||||||
printf("Activated %d\n",act);
|
printf("Activated %d\n",act);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BluetoothServer::MessageReceived(BMessage *message)
|
void BluetoothServer::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
status_t status = B_WOULD_BLOCK; // mark somehow.. do not reply anything
|
status_t status = B_WOULD_BLOCK;
|
||||||
|
// mark somehow.. do not reply anything
|
||||||
|
|
||||||
switch(message->what)
|
switch(message->what)
|
||||||
{
|
{
|
||||||
|
|
||||||
case BT_MSG_ADD_DEVICE:
|
case BT_MSG_ADD_DEVICE:
|
||||||
{
|
{
|
||||||
BString str;
|
BString str;
|
||||||
message->FindString("name", &str);
|
message->FindString("name", &str);
|
||||||
BPath path(str.String());
|
BPath path(str.String());
|
||||||
|
Output::Instance()->Postf(BLACKBOARD_GENERAL,
|
||||||
|
"Requested LocalDevice %s\n", str.String());
|
||||||
|
LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path);
|
||||||
|
|
||||||
(Output::Instance()->Postf(BLACKBOARD_GENERAL, "Requested LocalDevice %s\n", str.String()));
|
if (ldi->GetID() >= 0) {
|
||||||
|
fLocalDevicesList.AddItem(ldi);
|
||||||
LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path);
|
Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID()));
|
||||||
|
Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()),
|
||||||
|
"LocalDevice %s id=%x added\n",
|
||||||
|
str.String(), ldi->GetID());
|
||||||
|
} else {
|
||||||
|
Output::Instance()->Post("Adding LocalDevice failed\n",
|
||||||
|
BLACKBOARD_GENERAL);
|
||||||
|
}
|
||||||
|
|
||||||
if (ldi->GetID() >= 0) {
|
status = B_WOULD_BLOCK;
|
||||||
fLocalDevicesList.AddItem(ldi);
|
/* TODO: This should be by user request only! */
|
||||||
Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID()));
|
ldi->Launch();
|
||||||
(Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), "LocalDevice %s id=%x added\n", str.String(), ldi->GetID()));
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
} else {
|
|
||||||
(Output::Instance()->Post("Adding LocalDevice failed\n", BLACKBOARD_GENERAL));
|
|
||||||
}
|
|
||||||
|
|
||||||
status = B_WOULD_BLOCK;
|
|
||||||
|
|
||||||
/* TODO: This should be by user request only! */
|
|
||||||
ldi->Launch();
|
|
||||||
}
|
|
||||||
|
|
||||||
case BT_MSG_COUNT_LOCAL_DEVICES:
|
case BT_MSG_COUNT_LOCAL_DEVICES:
|
||||||
status = HandleLocalDevicesCount(message, &reply);
|
status = HandleLocalDevicesCount(message, &reply);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BT_MSG_ACQUIRE_LOCAL_DEVICE:
|
case BT_MSG_ACQUIRE_LOCAL_DEVICE:
|
||||||
status = HandleAcquireLocalDevice(message, &reply);
|
status = HandleAcquireLocalDevice(message, &reply);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BT_MSG_HANDLE_SIMPLE_REQUEST:
|
case BT_MSG_HANDLE_SIMPLE_REQUEST:
|
||||||
status = HandleSimpleRequest(message, &reply);
|
status = HandleSimpleRequest(message, &reply);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
/* Handle if the bluetooth preferences is running?? */
|
/* Handle if the bluetooth preferences is running?? */
|
||||||
case B_SOME_APP_LAUNCHED:
|
case B_SOME_APP_LAUNCHED:
|
||||||
{
|
{
|
||||||
const char *signature;
|
const char *signature;
|
||||||
// TODO: what's this for?
|
// TODO: what's this for?
|
||||||
if (message->FindString("be:signature", &signature)==B_OK) {
|
if (message->FindString("be:signature", &signature) == B_OK) {
|
||||||
printf("input_server : %s\n", signature);
|
printf("input_server : %s\n", signature);
|
||||||
if (strcmp(signature, "application/x-vnd.Be-TSKB")==0) {
|
if (strcmp(signature, "application/x-vnd.Be-TSKB") == 0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(message);
|
BApplication::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can we reply right now?
|
// Can we reply right now?
|
||||||
// TOD: review this condition
|
// TOD: review this condition
|
||||||
if (status != B_WOULD_BLOCK) {
|
if (status != B_WOULD_BLOCK) {
|
||||||
reply.AddInt32("status", status);
|
reply.AddInt32("status", status);
|
||||||
message->SendReply(&reply);
|
message->SendReply(&reply);
|
||||||
printf("Sending reply message\n");
|
printf("Sending reply message\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -189,42 +172,36 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
|||||||
LocalDeviceImpl*
|
LocalDeviceImpl*
|
||||||
BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
||||||
{
|
{
|
||||||
LocalDeviceImpl* ldi = NULL;
|
LocalDeviceImpl* ldi = NULL;
|
||||||
hci_id hid;
|
hci_id hid;
|
||||||
|
|
||||||
if (message->FindInt32("hci_id", &hid) == B_OK)
|
|
||||||
{
|
|
||||||
/* Try to find out when a ID was specified */
|
|
||||||
int index;
|
|
||||||
|
|
||||||
for (index = 0; index < fLocalDevicesList.CountItems() ; index ++) {
|
|
||||||
|
|
||||||
|
if (message->FindInt32("hci_id", &hid) == B_OK) {
|
||||||
|
/* Try to find out when a ID was specified */
|
||||||
|
int index;
|
||||||
|
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||||
ldi = fLocalDevicesList.ItemAt(index);
|
ldi = fLocalDevicesList.ItemAt(index);
|
||||||
if (ldi->GetID() == hid) {
|
if (ldi->GetID() == hid)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return ldi;
|
||||||
return ldi;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDeviceImpl*
|
LocalDeviceImpl*
|
||||||
BluetoothServer::LocateLocalDeviceImpl(hci_id hid)
|
BluetoothServer::LocateLocalDeviceImpl(hci_id hid)
|
||||||
{
|
{
|
||||||
|
/* Try to find out when a ID was specified */
|
||||||
|
int index;
|
||||||
|
|
||||||
/* Try to find out when a ID was specified */
|
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||||
int index;
|
LocalDeviceImpl* ldi = fLocalDevicesList.ItemAt(index);
|
||||||
|
if (ldi->GetID() == hid)
|
||||||
for (index = 0; index < fLocalDevicesList.CountItems() ; index ++) {
|
return ldi;
|
||||||
|
}
|
||||||
|
|
||||||
LocalDeviceImpl* ldi = fLocalDevicesList.ItemAt(index);
|
return NULL;
|
||||||
if (ldi->GetID() == hid) {
|
|
||||||
return ldi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -246,52 +223,50 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
|||||||
ssize_t size;
|
ssize_t size;
|
||||||
bdaddr_t bdaddr;
|
bdaddr_t bdaddr;
|
||||||
LocalDeviceImpl* ldi = NULL;
|
LocalDeviceImpl* ldi = NULL;
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
|
|
||||||
if (message->FindInt32("hci_id", &hid) == B_OK)
|
if (message->FindInt32("hci_id", &hid) == B_OK)
|
||||||
{
|
{
|
||||||
Output::Instance()->Post("GetLocalDevice requested with id\n", BLACKBOARD_KIT);
|
Output::Instance()->Post("GetLocalDevice requested with id\n",
|
||||||
ldi = LocateDelegateFromMessage(message);
|
BLACKBOARD_KIT);
|
||||||
|
ldi = LocateDelegateFromMessage(message);
|
||||||
} else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size ) == B_OK)
|
|
||||||
{
|
|
||||||
/* Try to find out when the user specified the address */
|
|
||||||
Output::Instance()->Post("GetLocalDevice requested with bdaddr\n", BLACKBOARD_KIT);
|
|
||||||
for (index = 0; index < fLocalDevicesList.CountItems() ; index ++) {
|
|
||||||
|
|
||||||
bdaddr_t local;
|
|
||||||
ldi = fLocalDevicesList.ItemAt(index);
|
|
||||||
// TODO: Only if the property is available
|
|
||||||
//if ((ldi->GetAddress(&local, message) == B_OK) && bacmp(&local, &bdaddr)) {
|
|
||||||
// break;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
/* Careless, any device not performing operations will be fine */
|
|
||||||
Output::Instance()->Post("GetLocalDevice requested\n", BLACKBOARD_KIT);
|
|
||||||
for (index = 0; index < fLocalDevicesList.CountItems() ; index ++) {
|
|
||||||
|
|
||||||
ldi = fLocalDevicesList.ItemAt(index);
|
|
||||||
printf("Requesting local device %ld\n", ldi->GetID());
|
|
||||||
if (ldi != NULL && ldi->Available())
|
|
||||||
{
|
|
||||||
printf("dev ours %ld\n", ldi->GetID());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available())
|
} else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size )
|
||||||
{
|
== B_OK) {
|
||||||
Output::Instance()->Post("Device acquired\n", BLACKBOARD_KIT);
|
/* Try to find out when the user specified the address */
|
||||||
ldi->Acquire();
|
Output::Instance()->Post("GetLocalDevice requested with bdaddr\n",
|
||||||
return reply->AddInt32("hci_id", hid);
|
BLACKBOARD_KIT);
|
||||||
}
|
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||||
|
bdaddr_t local;
|
||||||
|
ldi = fLocalDevicesList.ItemAt(index);
|
||||||
|
// TODO: Only if the property is available
|
||||||
|
//if ((ldi->GetAddress(&local, message) == B_OK)
|
||||||
|
// && bacmp(&local, &bdaddr)) {
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
return B_ERROR;
|
} else {
|
||||||
|
/* Careless, any device not performing operations will be fine */
|
||||||
|
Output::Instance()->Post("GetLocalDevice requested\n", BLACKBOARD_KIT);
|
||||||
|
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||||
|
ldi = fLocalDevicesList.ItemAt(index);
|
||||||
|
printf("Requesting local device %ld\n", ldi->GetID());
|
||||||
|
if (ldi != NULL && ldi->Available())
|
||||||
|
{
|
||||||
|
printf("dev ours %ld\n", ldi->GetID());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available()) {
|
||||||
|
Output::Instance()->Post("Device acquired\n", BLACKBOARD_KIT);
|
||||||
|
ldi->Acquire();
|
||||||
|
return reply->AddInt32("hci_id", hid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,26 +274,21 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
|||||||
status_t
|
status_t
|
||||||
BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply)
|
BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply)
|
||||||
{
|
{
|
||||||
|
LocalDeviceImpl* ldi = LocateDelegateFromMessage(message);
|
||||||
LocalDeviceImpl* ldi = LocateDelegateFromMessage(message);
|
|
||||||
BString propertyRequested;
|
BString propertyRequested;
|
||||||
|
|
||||||
// Find out if there is a property being requested,
|
// Find out if there is a property being requested,
|
||||||
if (message->FindString("property", &propertyRequested) == B_OK) {
|
if (message->FindString("property", &propertyRequested) == B_OK) {
|
||||||
// Check if the property has been already retrieved
|
// Check if the property has been already retrieved
|
||||||
|
if (ldi->IsPropertyAvailable(propertyRequested)) {
|
||||||
if (ldi->IsPropertyAvailable(propertyRequested)) {
|
// Dump everything
|
||||||
|
reply->AddMessage("properties",ldi->GetPropertiesMessage());
|
||||||
// Dump everything
|
return B_OK;
|
||||||
reply->AddMessage("properties",ldi->GetPropertiesMessage());
|
}
|
||||||
return B_OK;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// we are gonna need issue the command ...
|
// we are gonna need issue the command ...
|
||||||
if (ldi->ProcessSimpleRequest(DetachCurrentMessage()) == B_OK)
|
if (ldi->ProcessSimpleRequest(DetachCurrentMessage()) == B_OK)
|
||||||
// if (ldi->ProcessSimpleRequest(message) == B_OK)
|
|
||||||
return B_WOULD_BLOCK;
|
return B_WOULD_BLOCK;
|
||||||
else
|
else
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -334,7 +304,7 @@ BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply)
|
|||||||
int32
|
int32
|
||||||
BluetoothServer::notification_Thread(void* data)
|
BluetoothServer::notification_Thread(void* data)
|
||||||
{
|
{
|
||||||
BPortNot notifierd( (BluetoothServer*) data , BT_USERLAND_PORT_NAME);
|
BPortNot notifierd((BluetoothServer*)data, BT_USERLAND_PORT_NAME);
|
||||||
|
|
||||||
notifierd.loop();
|
notifierd.loop();
|
||||||
return B_NO_ERROR;
|
return B_NO_ERROR;
|
||||||
@@ -367,7 +337,7 @@ BluetoothServer::ShowWindow(BWindow* pWindow)
|
|||||||
int
|
int
|
||||||
main(int /*argc*/, char** /*argv*/)
|
main(int /*argc*/, char** /*argv*/)
|
||||||
{
|
{
|
||||||
setbuf(stdout,NULL);
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
BluetoothServer* bluetoothServer = new BluetoothServer;
|
BluetoothServer* bluetoothServer = new BluetoothServer;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||||
*
|
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _HCIDELEGATE_H_
|
#ifndef _HCIDELEGATE_H_
|
||||||
#define _HCIDELEGATE_H_
|
#define _HCIDELEGATE_H_
|
||||||
|
|
||||||
@@ -30,43 +28,59 @@ class HCIDelegate {
|
|||||||
if (fFD > 0) {
|
if (fFD > 0) {
|
||||||
// find out which ID was assigned
|
// find out which ID was assigned
|
||||||
status = ioctl(fFD, GET_HCI_ID, &fHID, 0);
|
status = ioctl(fFD, GET_HCI_ID, &fHID, 0);
|
||||||
printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__, fHID, status);
|
printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__,
|
||||||
|
fHID, status);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, fHID);
|
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__,
|
||||||
|
fHID);
|
||||||
fHID = B_ERROR;
|
fHID = B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO create such queue
|
//TODO create such queue
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
hci_id GetID(void)
|
hci_id GetID(void)
|
||||||
{
|
{
|
||||||
return fHID;
|
return fHID;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t IssueCommand(raw_command rc, size_t size)=0; // TODO means to be private
|
|
||||||
|
virtual ~HCIDelegate()
|
||||||
|
{
|
||||||
|
if (fFD > 0)
|
||||||
|
{
|
||||||
|
close (fFD);
|
||||||
|
fFD = -1;
|
||||||
|
fHID = B_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual status_t IssueCommand(raw_command rc, size_t size)=0;
|
||||||
|
// TODO means to be private use QueueCommand
|
||||||
virtual status_t Launch()=0;
|
virtual status_t Launch()=0;
|
||||||
|
|
||||||
void FreeWindow(uint8 slots) { // TODO: hci control flow
|
|
||||||
|
|
||||||
|
void FreeWindow(uint8 slots)
|
||||||
|
{
|
||||||
|
// TODO: hci control flow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t QueueCommand(raw_command rc, size_t size)
|
status_t QueueCommand(raw_command rc, size_t size)
|
||||||
{
|
{
|
||||||
// TODO: this is suposed to queue the command in a queue so all are actually send to HW
|
// TODO: this is suposed to queue the command in a queue so all
|
||||||
|
// are actually send to HW
|
||||||
return IssueCommand(rc, size);
|
return IssueCommand(rc, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
hci_id fHID;
|
hci_id fHID;
|
||||||
int fFD;
|
int fFD;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
* Copyright 2007-2009 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||||
*
|
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "LocalDeviceHandler.h"
|
#include "LocalDeviceHandler.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd)
|
LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd)
|
||||||
{
|
{
|
||||||
fHCIDelegate = hd;
|
fHCIDelegate = hd;
|
||||||
fProperties = new BMessage();
|
fProperties = new BMessage();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LocalDeviceHandler::~LocalDeviceHandler()
|
LocalDeviceHandler::~LocalDeviceHandler()
|
||||||
{
|
{
|
||||||
|
delete fProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +26,7 @@ LocalDeviceHandler::GetID()
|
|||||||
return fHCIDelegate->GetID();
|
return fHCIDelegate->GetID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
LocalDeviceHandler::Launch(void)
|
LocalDeviceHandler::Launch(void)
|
||||||
{
|
{
|
||||||
@@ -37,26 +35,27 @@ LocalDeviceHandler::Launch(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LocalDeviceHandler::Available() {
|
LocalDeviceHandler::Available()
|
||||||
|
{
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalDeviceHandler::Acquire(void) {
|
LocalDeviceHandler::Acquire(void)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
LocalDeviceHandler::IsPropertyAvailable(const BString& property) {
|
LocalDeviceHandler::IsPropertyAvailable(const BString& property)
|
||||||
|
{
|
||||||
type_code typeFound;
|
type_code typeFound;
|
||||||
int32 countFound;
|
int32 countFound;
|
||||||
|
|
||||||
return (fProperties->GetInfo(property.String(), &typeFound, &countFound) == B_OK );
|
return (fProperties->GetInfo(property.String(), &typeFound, &countFound) == B_OK );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -70,28 +69,28 @@ LocalDeviceHandler::AddWantedEvent(BMessage* msg)
|
|||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalDeviceHandler::ClearWantedEvent(BMessage* msg)
|
LocalDeviceHandler::ClearWantedEvent(BMessage* msg)
|
||||||
{
|
{
|
||||||
fEventsWanted.Lock();
|
fEventsWanted.Lock();
|
||||||
fEventsWanted.RemoveMessage(msg);
|
fEventsWanted.RemoveMessage(msg);
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
||||||
{
|
{
|
||||||
// Remove the whole petition from queue
|
// Remove the whole petition from queue
|
||||||
fEventsWanted.Lock();
|
fEventsWanted.Lock();
|
||||||
|
|
||||||
int16 eventFound;
|
int16 eventFound;
|
||||||
int16 opcodeFound;
|
int16 opcodeFound;
|
||||||
int32 eventIndex = 0;
|
int32 eventIndex = 0;
|
||||||
|
|
||||||
// for each Event
|
// for each Event
|
||||||
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK) {
|
||||||
|
|
||||||
printf("%s:Event expected@%ld...\n", __FUNCTION__, eventIndex);
|
printf("%s:Event expected@%ld...\n", __FUNCTION__, eventIndex);
|
||||||
|
|
||||||
@@ -102,19 +101,20 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
|||||||
if (opcode != 0) {
|
if (opcode != 0) {
|
||||||
|
|
||||||
// The opcode matches
|
// The opcode matches
|
||||||
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) &&
|
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK)
|
||||||
((uint16)opcodeFound == opcode) ) {
|
&& ((uint16)opcodeFound == opcode) ) {
|
||||||
|
|
||||||
// this should remove only the entry
|
// this should remove only the entry
|
||||||
printf("Removed event %#x and opcode %d from request %p\n", event, opcode, msg);
|
printf("Removed event %#x and opcode %d from request %p\n",
|
||||||
|
event, opcode, msg);
|
||||||
(void)msg->RemoveData("eventExpected", eventIndex);
|
(void)msg->RemoveData("eventExpected", eventIndex);
|
||||||
(void)msg->RemoveData("opcodeExpected", eventIndex);
|
(void)msg->RemoveData("opcodeExpected", eventIndex);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Event matches so far
|
// Event matches so far
|
||||||
printf("Removed event %d from message %p\n", event, msg);
|
printf("Removed event %d from message %p\n", event, msg);
|
||||||
(void)msg->RemoveData("eventExpected", eventIndex);
|
(void)msg->RemoveData("eventExpected", eventIndex);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
@@ -133,49 +133,49 @@ finish:
|
|||||||
BMessage*
|
BMessage*
|
||||||
LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
||||||
{
|
{
|
||||||
int16 eventFound;
|
int16 eventFound;
|
||||||
int16 opcodeFound;
|
int16 opcodeFound;
|
||||||
int32 eventIndex;
|
int32 eventIndex;
|
||||||
|
|
||||||
fEventsWanted.Lock();
|
fEventsWanted.Lock();
|
||||||
// for each Petition
|
// for each Petition
|
||||||
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
|
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
|
||||||
BMessage* msg = fEventsWanted.FindMessage(index);
|
BMessage* msg = fEventsWanted.FindMessage(index);
|
||||||
|
printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index,
|
||||||
printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index, fEventsWanted.CountMessages(), msg);
|
fEventsWanted.CountMessages(), msg);
|
||||||
//msg->PrintToStream();
|
//msg->PrintToStream();
|
||||||
eventIndex = 0;
|
eventIndex = 0;
|
||||||
|
|
||||||
// for each Event
|
// for each Event
|
||||||
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
||||||
if (eventFound == event) {
|
if (eventFound == event) {
|
||||||
|
|
||||||
printf("%s:Event found@%ld...", __FUNCTION__, eventIndex);
|
printf("%s:Event found@%ld...", __FUNCTION__, eventIndex);
|
||||||
// there is an opcode specified..
|
// there is an opcode specified..
|
||||||
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) {
|
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound)
|
||||||
|
== B_OK) {
|
||||||
// ensure the opcode
|
// ensure the opcode
|
||||||
if ((uint16)opcodeFound != opcode) {
|
if ((uint16)opcodeFound != opcode) {
|
||||||
printf("%s:opcode does not match %d\n",__FUNCTION__, opcode);
|
printf("%s:opcode does not match %d\n",
|
||||||
break;
|
__FUNCTION__, opcode);
|
||||||
}
|
break;
|
||||||
printf("opcode match %d\n", opcode);
|
}
|
||||||
} else {
|
printf("Opcode matches %d\n", opcode);
|
||||||
printf("no opcode specified\n");
|
} else {
|
||||||
}
|
printf("No opcode specified\n");
|
||||||
|
}
|
||||||
fEventsWanted.Unlock();
|
|
||||||
|
fEventsWanted.Unlock();
|
||||||
if (indexFound != NULL)
|
if (indexFound != NULL)
|
||||||
*indexFound = eventIndex;
|
*indexFound = eventIndex;
|
||||||
return msg;
|
return msg;
|
||||||
|
}
|
||||||
|
eventIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%s:Nothing found\n", __FUNCTION__);
|
||||||
|
|
||||||
|
fEventsWanted.Unlock();
|
||||||
|
return NULL;
|
||||||
|
|
||||||
}
|
|
||||||
eventIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("%s:Nothing found\n",__FUNCTION__);
|
|
||||||
|
|
||||||
fEventsWanted.Unlock();
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ LocalDeviceImpl*
|
|||||||
LocalDeviceImpl::CreateControllerAccessor(BPath* path)
|
LocalDeviceImpl::CreateControllerAccessor(BPath* path)
|
||||||
{
|
{
|
||||||
HCIDelegate* hd = new HCIControllerAccessor(path);
|
HCIDelegate* hd = new HCIControllerAccessor(path);
|
||||||
|
|
||||||
if ( hd != NULL)
|
if ( hd != NULL)
|
||||||
return new LocalDeviceImpl(hd);
|
return new LocalDeviceImpl(hd);
|
||||||
else
|
else
|
||||||
@@ -46,11 +46,11 @@ LocalDeviceImpl*
|
|||||||
LocalDeviceImpl::CreateTransportAccessor(BPath* path)
|
LocalDeviceImpl::CreateTransportAccessor(BPath* path)
|
||||||
{
|
{
|
||||||
HCIDelegate* hd = new HCITransportAccessor(path);
|
HCIDelegate* hd = new HCITransportAccessor(path);
|
||||||
|
|
||||||
if ( hd != NULL)
|
if ( hd != NULL)
|
||||||
return new LocalDeviceImpl(hd);
|
return new LocalDeviceImpl(hd);
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -75,30 +75,25 @@ printf("### \n");
|
|||||||
|
|
||||||
// Events here might have not been initated by us
|
// Events here might have not been initated by us
|
||||||
// TODO: ML mark as handled pass a reply by parameter and reply in common
|
// TODO: ML mark as handled pass a reply by parameter and reply in common
|
||||||
switch (event->ecode) {
|
switch (event->ecode) {
|
||||||
case HCI_EVENT_HARDWARE_ERROR:
|
case HCI_EVENT_HARDWARE_ERROR:
|
||||||
//HardwareError(event);
|
//HardwareError(event);
|
||||||
return;
|
return;
|
||||||
case HCI_EVENT_CONN_REQUEST:
|
case HCI_EVENT_CONN_REQUEST:
|
||||||
ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL);
|
ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case HCI_EVENT_CONN_COMPLETE:
|
case HCI_EVENT_CONN_COMPLETE:
|
||||||
// should belong to a request? can be sporadic or initiated by us¿?...
|
// should belong to a request? can be sporadic or initiated by us¿?...
|
||||||
ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL);
|
ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case HCI_EVENT_PIN_CODE_REQ:
|
case HCI_EVENT_PIN_CODE_REQ:
|
||||||
PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL);
|
PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL);
|
||||||
return;
|
return;
|
||||||
|
default:
|
||||||
default:
|
// lets go on
|
||||||
// lets go on
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BMessage* request = NULL;
|
BMessage* request = NULL;
|
||||||
int32 eventIndexLocation;
|
int32 eventIndexLocation;
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
// Connection
|
// Connection
|
||||||
void ConnectionComplete(struct hci_ev_conn_complete* event, BMessage* request);
|
void ConnectionComplete(struct hci_ev_conn_complete* event, BMessage* request);
|
||||||
void ConnectionRequest(struct hci_ev_conn_request* event, BMessage* request);
|
void ConnectionRequest(struct hci_ev_conn_request* event, BMessage* request);
|
||||||
void DisconnectionComplete(struct hci_ev_disconnection_complete_reply* event, BMessage *request);
|
void DisconnectionComplete(struct hci_ev_disconnection_complete_reply* event, BMessage* request);
|
||||||
|
|
||||||
// Pairing
|
// Pairing
|
||||||
void PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request);
|
void PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request);
|
||||||
|
|||||||
Reference in New Issue
Block a user