Implement pairing with a remote bluetooth device
- Fix PincodeWindow to send the pincode commands dissapear after clicking - Improve the debug output of bluetooth_server - Handle all needed events for the pairing - Simple request could send and receive the event before adding the request to the events wanted list. Inverted the order of this sequence. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26614 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -17,13 +17,15 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
namespace Bluetooth {
|
||||||
|
|
||||||
class RemoteDevice;
|
class RemoteDevice;
|
||||||
|
|
||||||
class ConnectionView
|
class ConnectionView
|
||||||
: public BView
|
: public BView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConnectionView(BRect frame, const char *name, uint32 resizeMask, uint32 flags);
|
ConnectionView(BRect frame, const char *name);
|
||||||
~ConnectionView();
|
~ConnectionView();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
void Draw(BRect update);
|
void Draw(BRect update);
|
||||||
@@ -35,8 +37,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ConnectionIncoming
|
class ConnectionIncoming : public BWindow
|
||||||
: public BWindow
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ConnectionIncoming(RemoteDevice* rDevice);
|
ConnectionIncoming(RemoteDevice* rDevice);
|
||||||
@@ -48,4 +49,11 @@ private:
|
|||||||
ConnectionView* _ConnectionView;
|
ConnectionView* _ConnectionView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef _BT_USE_EXPLICIT_NAMESPACE
|
||||||
|
using Bluetooth::ConnectionIncoming;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -41,15 +41,15 @@ class PincodeView : public BView
|
|||||||
class PincodeWindow : public BWindow
|
class PincodeWindow : public BWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PincodeWindow(RemoteDevice* rDevice);
|
PincodeWindow(bdaddr_t address, hci_id hid);
|
||||||
virtual void MessageReceived(BMessage *msg);
|
virtual void MessageReceived(BMessage *msg);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PincodeView* fView;
|
PincodeView* fView;
|
||||||
bdaddr_t bdaddr;
|
bdaddr_t bdaddr;
|
||||||
RemoteDevice* fRemoteDevice;
|
bdaddr_t fBdaddr;
|
||||||
BMessenger* fMessenger;
|
hci_id fHid;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,10 @@
|
|||||||
|
|
||||||
#define B_PULSES_BY_SECOND(x) (2*x)
|
#define B_PULSES_BY_SECOND(x) (2*x)
|
||||||
|
|
||||||
|
namespace Bluetooth {
|
||||||
|
|
||||||
ConnectionView::ConnectionView(BRect frame, const char *name, uint32 resizeMask, uint32 flags)
|
ConnectionView::ConnectionView(BRect frame, const char *name): BView(BRect(0, 0, 400, 400), "MyViewName",
|
||||||
: BView(BRect(0, 0, 400, 400), "MyViewName", B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
B_WILL_DRAW | B_PULSE_NEEDED)
|
B_WILL_DRAW | B_PULSE_NEEDED)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -45,33 +46,34 @@ void ConnectionView::Draw(BRect update)
|
|||||||
void ConnectionView::Pulse()
|
void ConnectionView::Pulse()
|
||||||
{
|
{
|
||||||
static int a = 0;
|
static int a = 0;
|
||||||
if (a++ == B_PULSES_BY_SECOND(5))
|
|
||||||
Window()->PostMessage(B_QUIT_REQUESTED);
|
|
||||||
|
|
||||||
|
if (a++ == B_PULSES_BY_SECOND(5)) {
|
||||||
|
// BUG: for some reason the window is not being removed...
|
||||||
|
Window()->PostMessage(B_QUIT_REQUESTED);
|
||||||
|
Window()->Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
ConnectionIncoming::ConnectionIncoming(RemoteDevice* rDevice)
|
ConnectionIncoming::ConnectionIncoming(RemoteDevice* rDevice)
|
||||||
: BWindow(BRect(700, 100, 900, 150), "Incomming Connection",
|
: BWindow(BRect(700, 100, 900, 150), "Connection Completed",
|
||||||
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
|
B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
|
||||||
{
|
{
|
||||||
_ConnectionView = new ConnectionView(BRect(0, 0, 400, 400),"mViewName", B_FOLLOW_TOP | B_FOLLOW_LEFT, B_WILL_DRAW);
|
_ConnectionView = new ConnectionView(BRect(0, 0, 400, 400),"mViewName");
|
||||||
|
|
||||||
AddChild(_ConnectionView);
|
AddChild(_ConnectionView);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
ConnectionIncoming::~ConnectionIncoming()
|
ConnectionIncoming::~ConnectionIncoming()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
void ConnectionIncoming::MessageReceived(BMessage *message)
|
void ConnectionIncoming::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch(message->what)
|
switch(message->what)
|
||||||
@@ -82,10 +84,10 @@ void ConnectionIncoming::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
bool ConnectionIncoming::QuitRequested()
|
bool ConnectionIncoming::QuitRequested()
|
||||||
{
|
{
|
||||||
|
|
||||||
return BWindow::QuitRequested();
|
return BWindow::QuitRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,11 +56,11 @@ PincodeView::PincodeView(BRect rect) : BView(rect,"View", B_FOLLOW_NONE, B_WILL_
|
|||||||
fRemoteInfo = new BStringView(BRect(rect1.left, rect1.bottom + V_SEPARATION , 0 , 0),
|
fRemoteInfo = new BStringView(BRect(rect1.left, rect1.bottom + V_SEPARATION , 0 , 0),
|
||||||
"bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES);
|
"bdaddr","BD_ADDR: ", B_FOLLOW_ALL_SIDES);
|
||||||
fRemoteInfo->ResizeToPreferred();
|
fRemoteInfo->ResizeToPreferred();
|
||||||
rect = fRemoteInfo->Frame();
|
rect1 = fRemoteInfo->Frame();
|
||||||
|
|
||||||
// TODO: IT CANNOT BE MORE THAN 16 BYTES
|
// TODO: IT CANNOT BE MORE THAN 16 BYTES
|
||||||
fPincodeText = new BTextControl(BRect(rect1.left, rect1.bottom + V_SEPARATION , 0, 0),
|
fPincodeText = new BTextControl(BRect(rect1.left, rect1.bottom + V_SEPARATION , rect1.right, rect1.bottom + V_SEPARATION + 20),
|
||||||
"pincode TextControl","PIN code:", "", NULL);
|
"pincode TextControl","PIN code:", "5555", NULL);
|
||||||
fPincodeText->ResizeToPreferred();
|
fPincodeText->ResizeToPreferred();
|
||||||
rect1 = fPincodeText->Frame();
|
rect1 = fPincodeText->Frame();
|
||||||
|
|
||||||
@@ -103,10 +103,11 @@ void PincodeView::SetBDaddr(const char* address){
|
|||||||
#pragma mark -
|
#pragma mark -
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PincodeWindow::PincodeWindow(RemoteDevice* rDevice) :
|
PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid) :
|
||||||
BWindow(BRect(700, 100, 900, 150), "Pincode Request", B_MODAL_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL,
|
BWindow(BRect(700, 100, 900, 150), "Pincode Request",
|
||||||
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_RESIZABLE ,
|
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
B_ALL_WORKSPACES), fRemoteDevice(rDevice)
|
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,
|
||||||
|
B_ALL_WORKSPACES), fBdaddr(address), fHid(hid)
|
||||||
{
|
{
|
||||||
fView = new PincodeView(Bounds());
|
fView = new PincodeView(Bounds());
|
||||||
AddChild(fView);
|
AddChild(fView);
|
||||||
@@ -114,7 +115,7 @@ PincodeWindow::PincodeWindow(RemoteDevice* rDevice) :
|
|||||||
ResizeTo( fView->Bounds().right , fView->Bounds().bottom );
|
ResizeTo( fView->Bounds().right , fView->Bounds().bottom );
|
||||||
|
|
||||||
// TODO: Get more info about device" ote name/features/encry/auth... etc
|
// TODO: Get more info about device" ote name/features/encry/auth... etc
|
||||||
fView->SetBDaddr( bdaddrUtils::ToString(rDevice->GetBluetoothAddress()) );
|
fView->SetBDaddr( bdaddrUtils::ToString(fBdaddr) );
|
||||||
};
|
};
|
||||||
|
|
||||||
void PincodeWindow::MessageReceived(BMessage *msg)
|
void PincodeWindow::MessageReceived(BMessage *msg)
|
||||||
@@ -130,26 +131,26 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
size_t size;
|
size_t size;
|
||||||
int8 bt_status = BT_ERROR;
|
int8 bt_status = BT_ERROR;
|
||||||
|
|
||||||
void* command = buildPinCodeRequestReply(fRemoteDevice->GetBluetoothAddress(), strlen(fView->fPincodeText->Text()),
|
void* command = buildPinCodeRequestReply(fBdaddr, strlen(fView->fPincodeText->Text()),
|
||||||
(char*)fView->fPincodeText->Text(), &size);
|
(char*)fView->fPincodeText->Text(), &size);
|
||||||
|
|
||||||
if (command == NULL) {
|
if (command == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.AddInt32("hci_id", (fRemoteDevice->GetLocalDeviceOwner())->GetID());
|
request.AddInt32("hci_id", fHid);
|
||||||
request.AddData("raw command", B_ANY_TYPE, command, size);
|
request.AddData("raw command", B_ANY_TYPE, command, size);
|
||||||
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||||
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY));
|
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY));
|
||||||
|
|
||||||
if (fMessenger->SendMessage(&request, &reply) == B_OK) {
|
if (be_app_messenger.SendMessage(&request, &reply) == B_OK) {
|
||||||
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
||||||
break;
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
// TODO: something failed here
|
// TODO: something failed here
|
||||||
}
|
}
|
||||||
|
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -161,25 +162,24 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
size_t size;
|
size_t size;
|
||||||
int8 bt_status = BT_ERROR;
|
int8 bt_status = BT_ERROR;
|
||||||
|
|
||||||
void* command = buildPinCodeRequestNegativeReply(fRemoteDevice->GetBluetoothAddress(), &size);
|
void* command = buildPinCodeRequestNegativeReply(fBdaddr, &size);
|
||||||
|
|
||||||
if (command == NULL) {
|
if (command == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.AddInt32("hci_id", (fRemoteDevice->GetLocalDeviceOwner())->GetID());
|
request.AddInt32("hci_id", fHid);
|
||||||
request.AddData("raw command", B_ANY_TYPE, command, size);
|
request.AddData("raw command", B_ANY_TYPE, command, size);
|
||||||
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||||
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY));
|
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY));
|
||||||
|
|
||||||
if (fMessenger->SendMessage(&request, &reply) == B_OK) {
|
if (be_app_messenger.SendMessage(&request, &reply) == B_OK) {
|
||||||
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
|
||||||
break;
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
// TODO: something failed here
|
// TODO: something failed here
|
||||||
}
|
}
|
||||||
|
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -193,6 +193,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
bool PincodeWindow::QuitRequested()
|
bool PincodeWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
|
|
||||||
return BWindow::QuitRequested();
|
return BWindow::QuitRequested();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ 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 %ld 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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +47,20 @@ class HCIDelegate {
|
|||||||
return fHID;
|
return fHID;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t IssueCommand(raw_command rc, size_t size)=0;
|
virtual status_t IssueCommand(raw_command rc, size_t size)=0; // TODO means to be private
|
||||||
virtual status_t Launch()=0;
|
virtual status_t Launch()=0;
|
||||||
|
|
||||||
|
void FreeWindow(uint8 slots) { // TODO: hci control flow
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
return IssueCommand(rc, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ void
|
|||||||
LocalDeviceHandler::AddWantedEvent(BMessage* msg)
|
LocalDeviceHandler::AddWantedEvent(BMessage* msg)
|
||||||
{
|
{
|
||||||
fEventsWanted.Lock();
|
fEventsWanted.Lock();
|
||||||
// TODO: review why it is neede to replicate the msg
|
// TODO: review why it is needed to replicate the msg
|
||||||
|
printf("Adding request... %p\n", msg);
|
||||||
fEventsWanted.AddMessage(msg);
|
fEventsWanted.AddMessage(msg);
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
}
|
}
|
||||||
@@ -92,11 +93,11 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
|||||||
// for each Event
|
// for each Event
|
||||||
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
||||||
|
|
||||||
printf("@ Event expected found @%ld\n", eventIndex);
|
printf("%s:Event expected@%ld...\n", __FUNCTION__, eventIndex);
|
||||||
|
|
||||||
if (eventFound == event) {
|
if (eventFound == event) {
|
||||||
|
|
||||||
printf("@ Event matches %ld\n", eventIndex);
|
printf("%s:Event matches@%ld", __FUNCTION__, eventIndex);
|
||||||
// there is an opcode specified
|
// there is an opcode specified
|
||||||
if (opcode != 0) {
|
if (opcode != 0) {
|
||||||
|
|
||||||
@@ -105,24 +106,25 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
|||||||
((uint16)opcodeFound == opcode) ) {
|
((uint16)opcodeFound == opcode) ) {
|
||||||
|
|
||||||
// this should remove only the entry
|
// this should remove only the entry
|
||||||
printf("@ Removed event %d and opcode %d from message %p\n", event, opcode, msg);
|
printf("Removed event@%d 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 bail;
|
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 bail;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
eventIndex++;
|
eventIndex++;
|
||||||
}
|
}
|
||||||
|
printf("%s:Nothing Found/Removed\n",__FUNCTION__);
|
||||||
|
|
||||||
bail:
|
finish:
|
||||||
|
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -140,24 +142,26 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
|||||||
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("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg);
|
printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index, 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("Event found %ld\n", 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("opcode does not match %d\n", opcode);
|
printf("%s:opcode does not match %d\n",__FUNCTION__, opcode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("Opcodes match %d %d \n", opcode , opcodeFound);
|
printf("opcode match %d\n", opcode);
|
||||||
|
} else {
|
||||||
|
printf("no opcode specified\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
@@ -170,6 +174,7 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
|||||||
eventIndex++;
|
eventIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("%s:Nothing found\n",__FUNCTION__);
|
||||||
|
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
#include "CommandManager.h"
|
#include "CommandManager.h"
|
||||||
#include "Output.h"
|
#include "Output.h"
|
||||||
|
|
||||||
|
#include <bluetooth/bdaddrUtils.h>
|
||||||
|
#include <bluetooth/RemoteDevice.h>
|
||||||
#include <bluetooth/bluetooth_error.h>
|
#include <bluetooth/bluetooth_error.h>
|
||||||
#include <bluetooth/HCI/btHCI_event.h>
|
#include <bluetooth/HCI/btHCI_event.h>
|
||||||
|
|
||||||
@@ -79,15 +81,17 @@ printf("### \n");
|
|||||||
return;
|
return;
|
||||||
case HCI_EVENT_CONN_REQUEST:
|
case HCI_EVENT_CONN_REQUEST:
|
||||||
ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL); // incoming request
|
ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL); // incoming request
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_CONN_COMPLETE:
|
case HCI_EVENT_CONN_COMPLETE:
|
||||||
ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL); // should belong to a request?
|
ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL); // should belong to a request?
|
||||||
// can be sporadic or initiated by us¿?...
|
return; // can be sporadic or initiated by us¿?...
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -211,6 +215,7 @@ printf("### \n");
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE:
|
case HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE:
|
||||||
|
PageScanRepetitionModeChange((struct hci_ev_page_scan_rep_mode_change*)(event+1), request, eventIndexLocation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_FLOW_SPECIFICATION:
|
case HCI_EVENT_FLOW_SPECIFICATION:
|
||||||
@@ -324,6 +329,56 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
|
|||||||
ClearWantedEvent(request);
|
ClearWantedEvent(request);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_REPLY):
|
||||||
|
{
|
||||||
|
uint8* statusReply = (uint8*)(event+1);
|
||||||
|
//TODO: This reply has to match the BDADDR of the outgoing message
|
||||||
|
reply.AddInt8("status", *statusReply);
|
||||||
|
|
||||||
|
if (*statusReply == BT_OK) {
|
||||||
|
|
||||||
|
Output::Instance()->Post("Positive reply for pincode accept\n", BLACKBOARD_KIT);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Output::Instance()->Post("Negative reply for pincode accept\n", BLACKBOARD_KIT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Sending reply ... %ld\n",request->SendReply(&reply));
|
||||||
|
reply.PrintToStream();
|
||||||
|
|
||||||
|
// This request is not gonna be used anymore
|
||||||
|
ClearWantedEvent(request);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_PIN_CODE_NEG_REPLY):
|
||||||
|
{
|
||||||
|
uint8* statusReply = (uint8*)(event+1);
|
||||||
|
//TODO: This reply might to match the BDADDR of the outgoing message
|
||||||
|
// xxx:FindPetition should be expanded....
|
||||||
|
reply.AddInt8("status", *statusReply);
|
||||||
|
|
||||||
|
if (*statusReply == BT_OK) {
|
||||||
|
|
||||||
|
Output::Instance()->Post("Positive reply for pincode reject\n", BLACKBOARD_KIT);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Output::Instance()->Post("Negative reply for pincode reject\n", BLACKBOARD_KIT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Sending reply ... %ld\n",request->SendReply(&reply));
|
||||||
|
reply.PrintToStream();
|
||||||
|
|
||||||
|
// This request is not gonna be used anymore
|
||||||
|
ClearWantedEvent(request);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Output::Instance()->Post("Command Complete not handled\n", BLACKBOARD_KIT);
|
Output::Instance()->Post("Command Complete not handled\n", BLACKBOARD_KIT);
|
||||||
@@ -374,6 +429,20 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
|
|||||||
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST));
|
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
/*
|
||||||
|
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ):
|
||||||
|
{
|
||||||
|
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ):
|
||||||
|
{
|
||||||
|
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ));
|
||||||
|
}
|
||||||
|
break;*/
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT);
|
Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT);
|
||||||
break;
|
break;
|
||||||
@@ -442,6 +511,40 @@ LocalDeviceImpl::RemoteNameRequestComplete(struct hci_ev_remote_name_request_com
|
|||||||
void
|
void
|
||||||
LocalDeviceImpl::ConnectionRequest(struct hci_ev_conn_request* event, BMessage* request)
|
LocalDeviceImpl::ConnectionRequest(struct hci_ev_conn_request* event, BMessage* request)
|
||||||
{
|
{
|
||||||
|
size_t size;
|
||||||
|
void* command;
|
||||||
|
|
||||||
|
printf("Connection type %d from %s\n", event->link_type, bdaddrUtils::ToString(event->bdaddr));
|
||||||
|
(Output::Instance()->Post("Connection Incoming ...\n", BLACKBOARD_EVENTS));
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: add a possible request in the queue */
|
||||||
|
if (true) { // Check Preferences if we are to accept this connection
|
||||||
|
command = buildAcceptConnectionRequest(event->bdaddr, 0x01 /*slave*/, &size);
|
||||||
|
|
||||||
|
|
||||||
|
BMessage* newrequest = new BMessage;
|
||||||
|
newrequest->AddInt16("eventExpected", HCI_EVENT_CMD_STATUS);
|
||||||
|
newrequest->AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ));
|
||||||
|
|
||||||
|
newrequest->AddInt16("eventExpected", HCI_EVENT_PIN_CODE_REQ);
|
||||||
|
newrequest->AddInt16("eventExpected", HCI_EVENT_ROLE_CHANGE);
|
||||||
|
newrequest->AddInt16("eventExpected", HCI_EVENT_LINK_KEY_NOTIFY);
|
||||||
|
newrequest->AddInt16("eventExpected", HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE);
|
||||||
|
|
||||||
|
AddWantedEvent(newrequest);
|
||||||
|
|
||||||
|
if ((fHCIDelegate)->IssueCommand(command, size) == B_ERROR) {
|
||||||
|
(Output::Instance()->Post("Command issue error for ConnAccpq\n", BLACKBOARD_EVENTS));
|
||||||
|
// remove the request
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
(Output::Instance()->Post("Command issued for ConnAccp\n", BLACKBOARD_EVENTS));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,12 +552,19 @@ LocalDeviceImpl::ConnectionRequest(struct hci_ev_conn_request* event, BMessage*
|
|||||||
void
|
void
|
||||||
LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event, BMessage* request)
|
LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event, BMessage* request)
|
||||||
{
|
{
|
||||||
ConnectionIncoming* iConnection = new ConnectionIncoming(NULL);
|
|
||||||
|
if (event->status == BT_OK) {
|
||||||
|
|
||||||
|
ConnectionIncoming* iConnection = new ConnectionIncoming(new RemoteDevice(event->bdaddr));
|
||||||
iConnection->Show();
|
iConnection->Show();
|
||||||
|
printf("%s: Address %s handle=%#x type=%d encrypt=%d\n", __FUNCTION__, bdaddrUtils::ToString(event->bdaddr), event->handle,
|
||||||
|
event->link_type, event->encrypt_mode);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("%s: failed with status %#x\n", __FUNCTION__, event->status);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Connection is valid create needed instances here or in KL
|
|
||||||
|
|
||||||
ClearWantedEvent(request);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +579,8 @@ LocalDeviceImpl::DisconnectionComplete(struct hci_ev_disconnection_complete_repl
|
|||||||
void
|
void
|
||||||
LocalDeviceImpl::PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request)
|
LocalDeviceImpl::PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request)
|
||||||
{
|
{
|
||||||
PincodeWindow* iPincode = new PincodeWindow(NULL);
|
|
||||||
|
PincodeWindow* iPincode = new PincodeWindow(event->bdaddr, GetID());
|
||||||
iPincode->Show();
|
iPincode->Show();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -478,7 +589,13 @@ LocalDeviceImpl::PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* req
|
|||||||
void
|
void
|
||||||
LocalDeviceImpl::RoleChange(hci_ev_role_change *event, BMessage* request, int32 index)
|
LocalDeviceImpl::RoleChange(hci_ev_role_change *event, BMessage* request, int32 index)
|
||||||
{
|
{
|
||||||
|
printf("%s: Address %s role=%d status=%d\n", __FUNCTION__, bdaddrUtils::ToString(event->bdaddr), event->role, event->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalDeviceImpl::PageScanRepetitionModeChange(struct hci_ev_page_scan_rep_mode_change* event, BMessage* request, int32 index)
|
||||||
|
{
|
||||||
|
printf("%s: Address %s type=%d\n", __FUNCTION__, bdaddrUtils::ToString(event->bdaddr), event->page_scan_rep_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -486,6 +603,8 @@ void
|
|||||||
LocalDeviceImpl::LinkKeyNotify(hci_ev_link_key_notify *event, BMessage* request, int32 index)
|
LocalDeviceImpl::LinkKeyNotify(hci_ev_link_key_notify *event, BMessage* request, int32 index)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
printf("%s: Address %s [----] type=%d\n", __FUNCTION__, bdaddrUtils::ToString(event->bdaddr), event->key_type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -501,7 +620,7 @@ LocalDeviceImpl::GetAddress(bdaddr_t* bdaddr, BMessage* request)
|
|||||||
|
|
||||||
if (fProperties->FindData("bdaddr", B_ANY_TYPE, 0, (const void **)bdaddr, &ssize) == B_OK) {
|
if (fProperties->FindData("bdaddr", B_ANY_TYPE, 0, (const void **)bdaddr, &ssize) == B_OK) {
|
||||||
|
|
||||||
(Output::Instance()->Post("BDADDR already present in server\n", BLACKBOARD_EVENTS));
|
|
||||||
/* We have this info, returning back */
|
/* We have this info, returning back */
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
@@ -514,7 +633,6 @@ LocalDeviceImpl::GetAddress(bdaddr_t* bdaddr, BMessage* request)
|
|||||||
request->AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
request->AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||||
request->AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR));
|
request->AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR));
|
||||||
|
|
||||||
printf("Adding request... %p\n", request);
|
|
||||||
AddWantedEvent(request);
|
AddWantedEvent(request);
|
||||||
request->PrintToStream();
|
request->PrintToStream();
|
||||||
|
|
||||||
@@ -547,7 +665,6 @@ LocalDeviceImpl::GetFriendlyName(BString str, BMessage* request)
|
|||||||
request->AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
request->AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||||
request->AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME));
|
request->AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME));
|
||||||
|
|
||||||
printf("Adding request... %p\n", request);
|
|
||||||
AddWantedEvent(request);
|
AddWantedEvent(request);
|
||||||
request->PrintToStream();
|
request->PrintToStream();
|
||||||
|
|
||||||
@@ -568,14 +685,20 @@ LocalDeviceImpl::ProcessSimpleRequest(BMessage* request)
|
|||||||
ssize_t size;
|
ssize_t size;
|
||||||
void* command = NULL;
|
void* command = NULL;
|
||||||
|
|
||||||
if (request->FindData("raw command", B_ANY_TYPE, 0, (const void **)&command, &size) == B_OK)
|
if (request->FindData("raw command", B_ANY_TYPE, 0, (const void **)&command, &size) == B_OK) {
|
||||||
if (((HCITransportAccessor*)fHCIDelegate)->IssueCommand(command, size) == B_ERROR)
|
|
||||||
(Output::Instance()->Post("Command issue error\n", BLACKBOARD_EVENTS));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AddWantedEvent(request);
|
AddWantedEvent(request);
|
||||||
|
|
||||||
|
if (((HCITransportAccessor*)fHCIDelegate)->IssueCommand(command, size) == B_ERROR) {
|
||||||
|
// TODO: - Reply the request with error!
|
||||||
|
// - Remove the just added request
|
||||||
|
(Output::Instance()->Post("Command issue error\n", BLACKBOARD_EVENTS));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
(Output::Instance()->Post("No command specified for simple request\n", BLACKBOARD_KIT));
|
(Output::Instance()->Post("No command specified for simple request\n", BLACKBOARD_KIT));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
void PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request);
|
void PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request);
|
||||||
void RoleChange(struct hci_ev_role_change* event, BMessage* request, int32 index);
|
void RoleChange(struct hci_ev_role_change* event, BMessage* request, int32 index);
|
||||||
void LinkKeyNotify(struct hci_ev_link_key_notify* event, BMessage* request, int32 index);
|
void LinkKeyNotify(struct hci_ev_link_key_notify* event, BMessage* request, int32 index);
|
||||||
|
void PageScanRepetitionModeChange(struct hci_ev_page_scan_rep_mode_change* event, BMessage* request, int32 index);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user