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:
parent
e54b6bb39a
commit
3205e523cd
@ -17,13 +17,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Bluetooth {
|
||||
|
||||
class RemoteDevice;
|
||||
|
||||
class ConnectionView
|
||||
: public BView
|
||||
{
|
||||
public:
|
||||
ConnectionView(BRect frame, const char *name, uint32 resizeMask, uint32 flags);
|
||||
ConnectionView(BRect frame, const char *name);
|
||||
~ConnectionView();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
void Draw(BRect update);
|
||||
@ -35,8 +37,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class ConnectionIncoming
|
||||
: public BWindow
|
||||
class ConnectionIncoming : public BWindow
|
||||
{
|
||||
public:
|
||||
ConnectionIncoming(RemoteDevice* rDevice);
|
||||
@ -48,4 +49,11 @@ private:
|
||||
ConnectionView* _ConnectionView;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifndef _BT_USE_EXPLICIT_NAMESPACE
|
||||
using Bluetooth::ConnectionIncoming;
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -41,15 +41,15 @@ class PincodeView : public BView
|
||||
class PincodeWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
PincodeWindow(RemoteDevice* rDevice);
|
||||
PincodeWindow(bdaddr_t address, hci_id hid);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
private:
|
||||
PincodeView* fView;
|
||||
bdaddr_t bdaddr;
|
||||
RemoteDevice* fRemoteDevice;
|
||||
BMessenger* fMessenger;
|
||||
bdaddr_t fBdaddr;
|
||||
hci_id fHid;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,10 +9,11 @@
|
||||
|
||||
#define B_PULSES_BY_SECOND(x) (2*x)
|
||||
|
||||
namespace Bluetooth {
|
||||
|
||||
ConnectionView::ConnectionView(BRect frame, const char *name, uint32 resizeMask, uint32 flags)
|
||||
: BView(BRect(0, 0, 400, 400), "MyViewName", B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW | B_PULSE_NEEDED)
|
||||
ConnectionView::ConnectionView(BRect frame, const char *name): BView(BRect(0, 0, 400, 400), "MyViewName",
|
||||
B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW | B_PULSE_NEEDED)
|
||||
{
|
||||
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
@ -45,33 +46,34 @@ void ConnectionView::Draw(BRect update)
|
||||
void ConnectionView::Pulse()
|
||||
{
|
||||
static int a = 0;
|
||||
if (a++ == B_PULSES_BY_SECOND(5))
|
||||
|
||||
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)
|
||||
: 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_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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
void ConnectionIncoming::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch(message->what)
|
||||
@ -82,10 +84,10 @@ void ConnectionIncoming::MessageReceived(BMessage *message)
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
bool ConnectionIncoming::QuitRequested()
|
||||
{
|
||||
|
||||
return BWindow::QuitRequested();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,23 +47,23 @@ PincodeView::PincodeView(BRect rect) : BView(rect,"View", B_FOLLOW_NONE, B_WILL_
|
||||
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
fMessage = new BStringView(BRect(0,0,5,5),"Pincode","Please enter the pincode ...", B_FOLLOW_ALL_SIDES);
|
||||
fMessage = new BStringView(BRect(0,0,5,5),"Pincode","Please enter the pincode ...", B_FOLLOW_ALL_SIDES);
|
||||
fMessage->SetFont(be_bold_font);
|
||||
fMessage->ResizeToPreferred();
|
||||
fMessage->MoveBy(20, 20);
|
||||
rect1 = fMessage->Frame();
|
||||
|
||||
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);
|
||||
fRemoteInfo->ResizeToPreferred();
|
||||
rect = fRemoteInfo->Frame();
|
||||
rect1 = fRemoteInfo->Frame();
|
||||
|
||||
// TODO: IT CANNOT BE MORE THAN 16 BYTES
|
||||
fPincodeText = new BTextControl(BRect(rect1.left, rect1.bottom + V_SEPARATION , 0, 0),
|
||||
"pincode TextControl","PIN code:", "", NULL);
|
||||
fPincodeText = new BTextControl(BRect(rect1.left, rect1.bottom + V_SEPARATION , rect1.right, rect1.bottom + V_SEPARATION + 20),
|
||||
"pincode TextControl","PIN code:", "5555", NULL);
|
||||
fPincodeText->ResizeToPreferred();
|
||||
rect1 = fPincodeText->Frame();
|
||||
|
||||
|
||||
fAcceptButton = new BButton(BRect(rect1.left , rect1.bottom + V_SEPARATION ,0, 0 ),
|
||||
"fAcceptButton","Pair",new BMessage(MSG_ACCEPT_BUTTON));
|
||||
fAcceptButton->ResizeToPreferred();
|
||||
@ -73,17 +73,17 @@ PincodeView::PincodeView(BRect rect) : BView(rect,"View", B_FOLLOW_NONE, B_WILL_
|
||||
"fCancelButton","Cancel",new BMessage(MSG_CANCEL_BUTTON));
|
||||
fCancelButton->ResizeToPreferred();
|
||||
|
||||
this->AddChild(fMessage);
|
||||
this->AddChild(fMessage);
|
||||
this->AddChild(fPincodeText);
|
||||
this->AddChild(fAcceptButton);
|
||||
this->AddChild(fCancelButton);
|
||||
this->AddChild(fAcceptButton);
|
||||
this->AddChild(fCancelButton);
|
||||
|
||||
this->AddChild(fRemoteInfo);
|
||||
this->AddChild(fRemoteInfo);
|
||||
|
||||
// Now resize the the view according all what we found here
|
||||
// Now resize the the view according all what we found here
|
||||
rect1 = fMessage->Frame();
|
||||
rect2 = fCancelButton->Frame();
|
||||
ResizeTo(rect1.right + 15 , rect2.bottom +15 );
|
||||
ResizeTo(rect1.right + 15 , rect2.bottom +15 );
|
||||
|
||||
}
|
||||
|
||||
@ -103,10 +103,11 @@ void PincodeView::SetBDaddr(const char* address){
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
PincodeWindow::PincodeWindow(RemoteDevice* rDevice) :
|
||||
BWindow(BRect(700, 100, 900, 150), "Pincode Request", B_MODAL_WINDOW_LOOK, B_FLOATING_ALL_WINDOW_FEEL,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_RESIZABLE ,
|
||||
B_ALL_WORKSPACES), fRemoteDevice(rDevice)
|
||||
PincodeWindow::PincodeWindow(bdaddr_t address, hci_id hid) :
|
||||
BWindow(BRect(700, 100, 900, 150), "Pincode Request",
|
||||
B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,
|
||||
B_ALL_WORKSPACES), fBdaddr(address), fHid(hid)
|
||||
{
|
||||
fView = new PincodeView(Bounds());
|
||||
AddChild(fView);
|
||||
@ -114,7 +115,7 @@ PincodeWindow::PincodeWindow(RemoteDevice* rDevice) :
|
||||
ResizeTo( fView->Bounds().right , fView->Bounds().bottom );
|
||||
|
||||
// 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)
|
||||
@ -130,26 +131,26 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
||||
size_t size;
|
||||
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);
|
||||
|
||||
if (command == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
request.AddInt32("hci_id", (fRemoteDevice->GetLocalDeviceOwner())->GetID());
|
||||
request.AddInt32("hci_id", fHid);
|
||||
request.AddData("raw command", B_ANY_TYPE, command, size);
|
||||
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||
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 ) {
|
||||
break;
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
// TODO: something failed here
|
||||
}
|
||||
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@ -161,25 +162,24 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
||||
size_t size;
|
||||
int8 bt_status = BT_ERROR;
|
||||
|
||||
void* command = buildPinCodeRequestNegativeReply(fRemoteDevice->GetBluetoothAddress(), &size);
|
||||
void* command = buildPinCodeRequestNegativeReply(fBdaddr, &size);
|
||||
|
||||
if (command == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
request.AddInt32("hci_id", (fRemoteDevice->GetLocalDeviceOwner())->GetID());
|
||||
request.AddInt32("hci_id", fHid);
|
||||
request.AddData("raw command", B_ANY_TYPE, command, size);
|
||||
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||
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 ) {
|
||||
break;
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
// TODO: something failed here
|
||||
}
|
||||
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -193,6 +193,7 @@ void PincodeWindow::MessageReceived(BMessage *msg)
|
||||
|
||||
bool PincodeWindow::QuitRequested()
|
||||
{
|
||||
|
||||
return BWindow::QuitRequested();
|
||||
};
|
||||
|
||||
|
@ -18,8 +18,8 @@ public:
|
||||
BPortNot(BluetoothServer* app, const char* name) ;
|
||||
void loop();
|
||||
|
||||
port_id fPort;
|
||||
port_id sdp_request_port;
|
||||
port_id fPort;
|
||||
port_id sdp_request_port;
|
||||
thread_id sdp_server_thread;
|
||||
|
||||
BluetoothServer* ourapp;
|
||||
|
@ -30,14 +30,14 @@ class HCIDelegate {
|
||||
if (fFD > 0) {
|
||||
// find out which ID was assigned
|
||||
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 {
|
||||
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, fHID);
|
||||
fHID = B_ERROR;
|
||||
}
|
||||
|
||||
|
||||
//TODO create such queue
|
||||
|
||||
}
|
||||
|
||||
@ -47,9 +47,20 @@ class HCIDelegate {
|
||||
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;
|
||||
|
||||
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:
|
||||
|
||||
|
||||
|
@ -64,7 +64,8 @@ void
|
||||
LocalDeviceHandler::AddWantedEvent(BMessage* msg)
|
||||
{
|
||||
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.Unlock();
|
||||
}
|
||||
@ -92,11 +93,11 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
||||
// for each Event
|
||||
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) {
|
||||
|
||||
printf("@ Event matches %ld\n", eventIndex);
|
||||
printf("%s:Event matches@%ld", __FUNCTION__, eventIndex);
|
||||
// there is an opcode specified
|
||||
if (opcode != 0) {
|
||||
|
||||
@ -105,24 +106,25 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
||||
((uint16)opcodeFound == opcode) ) {
|
||||
|
||||
// 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("opcodeExpected", eventIndex);
|
||||
goto bail;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
} else {
|
||||
// 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);
|
||||
goto bail;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
}
|
||||
eventIndex++;
|
||||
}
|
||||
printf("%s:Nothing Found/Removed\n",__FUNCTION__);
|
||||
|
||||
bail:
|
||||
|
||||
finish:
|
||||
fEventsWanted.Unlock();
|
||||
|
||||
}
|
||||
@ -140,25 +142,27 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
||||
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
|
||||
BMessage* msg = fEventsWanted.FindMessage(index);
|
||||
|
||||
printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg);
|
||||
msg->PrintToStream();
|
||||
eventIndex = 0;
|
||||
printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index, fEventsWanted.CountMessages(), msg);
|
||||
//msg->PrintToStream();
|
||||
eventIndex = 0;
|
||||
|
||||
// for each Event
|
||||
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
||||
if (eventFound == event) {
|
||||
|
||||
printf("Event found %ld\n", eventIndex);
|
||||
printf("%s:Event found@%ld...", __FUNCTION__, eventIndex);
|
||||
// there is an opcode specified..
|
||||
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) {
|
||||
|
||||
// ensure the opcode
|
||||
if ((uint16)opcodeFound != opcode) {
|
||||
printf("opcode does not match %d\n", opcode);
|
||||
printf("%s:opcode does not match %d\n",__FUNCTION__, opcode);
|
||||
break;
|
||||
}
|
||||
printf("Opcodes match %d %d \n", opcode , opcodeFound);
|
||||
}
|
||||
printf("opcode match %d\n", opcode);
|
||||
} else {
|
||||
printf("no opcode specified\n");
|
||||
}
|
||||
|
||||
fEventsWanted.Unlock();
|
||||
if (indexFound != NULL)
|
||||
@ -170,6 +174,7 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
||||
eventIndex++;
|
||||
}
|
||||
}
|
||||
printf("%s:Nothing found\n",__FUNCTION__);
|
||||
|
||||
fEventsWanted.Unlock();
|
||||
return NULL;
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "CommandManager.h"
|
||||
#include "Output.h"
|
||||
|
||||
#include <bluetooth/bdaddrUtils.h>
|
||||
#include <bluetooth/RemoteDevice.h>
|
||||
#include <bluetooth/bluetooth_error.h>
|
||||
#include <bluetooth/HCI/btHCI_event.h>
|
||||
|
||||
@ -79,27 +81,29 @@ printf("### \n");
|
||||
return;
|
||||
case HCI_EVENT_CONN_REQUEST:
|
||||
ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL); // incoming request
|
||||
return;
|
||||
break;
|
||||
|
||||
case HCI_EVENT_CONN_COMPLETE:
|
||||
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;
|
||||
|
||||
case HCI_EVENT_PIN_CODE_REQ:
|
||||
PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL);
|
||||
return;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
// lets go on
|
||||
break;
|
||||
default:
|
||||
// lets go on
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BMessage* request = NULL;
|
||||
int32 eventIndexLocation;
|
||||
BMessage* request = NULL;
|
||||
int32 eventIndexLocation;
|
||||
|
||||
// Check if its a requested one
|
||||
if ( event->ecode == HCI_EVENT_CMD_COMPLETE ) {
|
||||
@ -163,9 +167,9 @@ printf("### \n");
|
||||
|
||||
case HCI_EVENT_CMD_COMPLETE:
|
||||
CommandComplete((struct hci_ev_cmd_complete*)(event+1), request, eventIndexLocation);
|
||||
break;
|
||||
break;
|
||||
|
||||
case HCI_EVENT_CMD_STATUS:
|
||||
case HCI_EVENT_CMD_STATUS:
|
||||
CommandStatus((struct hci_ev_cmd_status*)(event+1), request, eventIndexLocation);
|
||||
break;
|
||||
|
||||
@ -211,6 +215,7 @@ printf("### \n");
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE:
|
||||
PageScanRepetitionModeChange((struct hci_ev_page_scan_rep_mode_change*)(event+1), request, eventIndexLocation);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_FLOW_SPECIFICATION:
|
||||
@ -324,7 +329,57 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
|
||||
ClearWantedEvent(request);
|
||||
}
|
||||
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:
|
||||
Output::Instance()->Post("Command Complete not handled\n", BLACKBOARD_KIT);
|
||||
break;
|
||||
@ -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));
|
||||
}
|
||||
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:
|
||||
Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT);
|
||||
break;
|
||||
@ -442,6 +511,40 @@ LocalDeviceImpl::RemoteNameRequestComplete(struct hci_ev_remote_name_request_com
|
||||
void
|
||||
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
|
||||
LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event, BMessage* request)
|
||||
{
|
||||
ConnectionIncoming* iConnection = new ConnectionIncoming(NULL);
|
||||
iConnection->Show();
|
||||
|
||||
// TODO: Connection is valid create needed instances here or in KL
|
||||
if (event->status == BT_OK) {
|
||||
|
||||
ConnectionIncoming* iConnection = new ConnectionIncoming(new RemoteDevice(event->bdaddr));
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
ClearWantedEvent(request);
|
||||
|
||||
}
|
||||
|
||||
@ -469,7 +579,8 @@ LocalDeviceImpl::DisconnectionComplete(struct hci_ev_disconnection_complete_repl
|
||||
void
|
||||
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();
|
||||
|
||||
}
|
||||
@ -478,7 +589,13 @@ LocalDeviceImpl::PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* req
|
||||
void
|
||||
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)
|
||||
{
|
||||
|
||||
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) {
|
||||
|
||||
(Output::Instance()->Post("BDADDR already present in server\n", BLACKBOARD_EVENTS));
|
||||
|
||||
/* We have this info, returning back */
|
||||
return B_OK;
|
||||
|
||||
@ -514,7 +633,6 @@ LocalDeviceImpl::GetAddress(bdaddr_t* bdaddr, BMessage* request)
|
||||
request->AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||
request->AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR));
|
||||
|
||||
printf("Adding request... %p\n", request);
|
||||
AddWantedEvent(request);
|
||||
request->PrintToStream();
|
||||
|
||||
@ -547,7 +665,6 @@ LocalDeviceImpl::GetFriendlyName(BString str, BMessage* request)
|
||||
request->AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
||||
request->AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME));
|
||||
|
||||
printf("Adding request... %p\n", request);
|
||||
AddWantedEvent(request);
|
||||
request->PrintToStream();
|
||||
|
||||
@ -568,14 +685,20 @@ LocalDeviceImpl::ProcessSimpleRequest(BMessage* request)
|
||||
ssize_t size;
|
||||
void* command = NULL;
|
||||
|
||||
if (request->FindData("raw command", B_ANY_TYPE, 0, (const void **)&command, &size) == B_OK)
|
||||
if (((HCITransportAccessor*)fHCIDelegate)->IssueCommand(command, size) == B_ERROR)
|
||||
if (request->FindData("raw command", B_ANY_TYPE, 0, (const void **)&command, &size) == B_OK) {
|
||||
|
||||
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
|
||||
{
|
||||
AddWantedEvent(request);
|
||||
}
|
||||
else {
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
}
|
||||
else {
|
||||
(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 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 PageScanRepetitionModeChange(struct hci_ev_page_scan_rep_mode_change* event, BMessage* request, int32 index);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user