- I expected once Haiku sets a connection with a remote device, such connection
was to expire in a couple of minutes, but not, seems to stay forever. - Implement a Disconnect button in prefrences&kit git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36450 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#define _REMOTE_DEVICE_H
|
#define _REMOTE_DEVICE_H
|
||||||
|
|
||||||
#include <bluetooth/bluetooth.h>
|
#include <bluetooth/bluetooth.h>
|
||||||
|
#include <bluetooth/bluetooth_error.h>
|
||||||
#include <bluetooth/BluetoothDevice.h>
|
#include <bluetooth/BluetoothDevice.h>
|
||||||
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
@@ -36,7 +37,8 @@ public:
|
|||||||
bool Equals(RemoteDevice* obj);
|
bool Equals(RemoteDevice* obj);
|
||||||
|
|
||||||
/*static RemoteDevice* GetRemoteDevice(Connection conn); Throwing */
|
/*static RemoteDevice* GetRemoteDevice(Connection conn); Throwing */
|
||||||
bool Authenticate(); /* Throwing */
|
bool Authenticate(); /* Throwing */
|
||||||
|
status_t Disconnect(int8 reason = BT_REMOTE_USER_ENDED_CONNECTION);
|
||||||
/* bool Authorize(Connection conn); Throwing */
|
/* bool Authorize(Connection conn); Throwing */
|
||||||
/*bool Encrypt(Connection conn, bool on); Throwing */
|
/*bool Encrypt(Connection conn, bool on); Throwing */
|
||||||
bool IsAuthenticated(); /* Throwing */
|
bool IsAuthenticated(); /* Throwing */
|
||||||
@@ -61,6 +63,7 @@ private:
|
|||||||
LocalDevice* fDiscovererLocalDevice;
|
LocalDevice* fDiscovererLocalDevice;
|
||||||
BMessenger* fMessenger;
|
BMessenger* fMessenger;
|
||||||
|
|
||||||
|
uint16 fHandle;
|
||||||
uint8 fPageRepetitionMode;
|
uint8 fPageRepetitionMode;
|
||||||
uint8 fScanPeriodMode;
|
uint8 fScanPeriodMode;
|
||||||
uint8 fScanMode;
|
uint8 fScanMode;
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
#define BT_HOST_TIMEOUT 0x10
|
#define BT_HOST_TIMEOUT 0x10
|
||||||
#define BT_UNSUPPORTED_FEATURE 0x11
|
#define BT_UNSUPPORTED_FEATURE 0x11
|
||||||
#define BT_INVALID_PARAMETERS 0x12
|
#define BT_INVALID_PARAMETERS 0x12
|
||||||
#define BT_OE_USER_ENDED_CONNECTION 0x13
|
#define BT_REMOTE_USER_ENDED_CONNECTION 0x13
|
||||||
#define BT_OE_LOW_RESOURCES 0x14
|
#define BT_REMOTE_LOW_RESOURCES 0x14
|
||||||
#define BT_OE_POWER_OFF 0x15
|
#define BT_REMOTE_POWER_OFF 0x15
|
||||||
#define BT_CONNECTION_TERMINATED 0x16
|
#define BT_CONNECTION_TERMINATED 0x16
|
||||||
#define BT_REPEATED_ATTEMPTS 0x17
|
#define BT_REPEATED_ATTEMPTS 0x17
|
||||||
#define BT_PAIRING_NOT_ALLOWED 0x18
|
#define BT_PAIRING_NOT_ALLOWED 0x18
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
namespace Bluetooth {
|
namespace Bluetooth {
|
||||||
|
|
||||||
|
// TODO: Check headers for valid/reserved ranges
|
||||||
|
static const uint16 invalidConnectionHandle = 0xF000;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
RemoteDevice::IsTrustedDevice(void)
|
RemoteDevice::IsTrustedDevice(void)
|
||||||
@@ -184,13 +186,58 @@ RemoteDevice::Authenticate()
|
|||||||
if (fMessenger->SendMessage(&request, &reply) == B_OK)
|
if (fMessenger->SendMessage(&request, &reply) == B_OK)
|
||||||
reply.FindInt8("status", &btStatus);
|
reply.FindInt8("status", &btStatus);
|
||||||
|
|
||||||
if (btStatus == BT_OK)
|
if (btStatus == BT_OK) {
|
||||||
|
reply.FindInt16("handle", (int16*)&fHandle);
|
||||||
return true;
|
return true;
|
||||||
else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
RemoteDevice::Disconnect(int8 reason)
|
||||||
|
{
|
||||||
|
if (fHandle != invalidConnectionHandle) {
|
||||||
|
|
||||||
|
int8 btStatus = BT_ERROR;
|
||||||
|
|
||||||
|
if (fMessenger == NULL || fDiscovererLocalDevice == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BluetoothCommand<typed_command(struct hci_disconnect)>
|
||||||
|
disconnect(OGF_LINK_CONTROL, OCF_DISCONNECT);
|
||||||
|
|
||||||
|
disconnect->reason = reason;
|
||||||
|
disconnect->handle = fHandle;
|
||||||
|
|
||||||
|
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
|
||||||
|
request.AddInt32("hci_id", fDiscovererLocalDevice->ID());
|
||||||
|
request.AddData("raw command", B_ANY_TYPE,
|
||||||
|
disconnect.Data(), disconnect.Size());
|
||||||
|
|
||||||
|
request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS);
|
||||||
|
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL,
|
||||||
|
OCF_DISCONNECT));
|
||||||
|
|
||||||
|
request.AddInt16("eventExpected", HCI_EVENT_DISCONNECTION_COMPLETE);
|
||||||
|
|
||||||
|
if (fMessenger->SendMessage(&request, &reply) == B_OK)
|
||||||
|
reply.FindInt8("status", &btStatus);
|
||||||
|
|
||||||
|
if (btStatus == BT_OK)
|
||||||
|
fHandle = invalidConnectionHandle;
|
||||||
|
|
||||||
|
return btStatus;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// bool Authorize(Connection conn);
|
// bool Authorize(Connection conn);
|
||||||
// bool Encrypt(Connection conn, bool on);
|
// bool Encrypt(Connection conn, bool on);
|
||||||
|
|
||||||
@@ -231,7 +278,8 @@ RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld)
|
|||||||
RemoteDevice::RemoteDevice(const bdaddr_t address, uint8 record[3])
|
RemoteDevice::RemoteDevice(const bdaddr_t address, uint8 record[3])
|
||||||
:
|
:
|
||||||
BluetoothDevice(),
|
BluetoothDevice(),
|
||||||
fDiscovererLocalDevice(NULL)
|
fDiscovererLocalDevice(NULL),
|
||||||
|
fHandle(invalidConnectionHandle)
|
||||||
{
|
{
|
||||||
fBdaddr = address;
|
fBdaddr = address;
|
||||||
fDeviceClass.SetRecord(record);
|
fDeviceClass.SetRecord(record);
|
||||||
@@ -242,7 +290,8 @@ RemoteDevice::RemoteDevice(const bdaddr_t address, uint8 record[3])
|
|||||||
RemoteDevice::RemoteDevice(const BString& address)
|
RemoteDevice::RemoteDevice(const BString& address)
|
||||||
:
|
:
|
||||||
BluetoothDevice(),
|
BluetoothDevice(),
|
||||||
fDiscovererLocalDevice(NULL)
|
fDiscovererLocalDevice(NULL),
|
||||||
|
fHandle(invalidConnectionHandle)
|
||||||
{
|
{
|
||||||
fBdaddr = bdaddrUtils::FromString((const char*)address.String());
|
fBdaddr = bdaddrUtils::FromString((const char*)address.String());
|
||||||
fMessenger = _RetrieveBluetoothMessenger();
|
fMessenger = _RetrieveBluetoothMessenger();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
static const uint32 kMsgAddDevices = 'ddDv';
|
static const uint32 kMsgAddDevices = 'ddDv';
|
||||||
static const uint32 kMsgRemoveDevice = 'rmDv';
|
static const uint32 kMsgRemoveDevice = 'rmDv';
|
||||||
static const uint32 kMsgPairDevice = 'trDv';
|
static const uint32 kMsgPairDevice = 'trDv';
|
||||||
|
static const uint32 kMsgDisconnectDevice = 'dsDv';
|
||||||
static const uint32 kMsgBlockDevice = 'blDv';
|
static const uint32 kMsgBlockDevice = 'blDv';
|
||||||
static const uint32 kMsgRefreshDevices = 'rfDv';
|
static const uint32 kMsgRefreshDevices = 'rfDv';
|
||||||
|
|
||||||
@@ -50,6 +51,8 @@ RemoteDevicesView::RemoteDevicesView(const char* name, uint32 flags)
|
|||||||
pairButton = new BButton("pair", TR("Pair" B_UTF8_ELLIPSIS),
|
pairButton = new BButton("pair", TR("Pair" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(kMsgPairDevice));
|
new BMessage(kMsgPairDevice));
|
||||||
|
|
||||||
|
disconnectButton = new BButton("disconnect", TR("Disconnect"),
|
||||||
|
new BMessage(kMsgDisconnectDevice));
|
||||||
|
|
||||||
blockButton = new BButton("block", TR("As blocked"),
|
blockButton = new BButton("block", TR("As blocked"),
|
||||||
new BMessage(kMsgBlockDevice));
|
new BMessage(kMsgBlockDevice));
|
||||||
@@ -77,6 +80,7 @@ RemoteDevicesView::RemoteDevicesView(const char* name, uint32 flags)
|
|||||||
.Add(availButton)
|
.Add(availButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(pairButton)
|
.Add(pairButton)
|
||||||
|
.Add(disconnectButton)
|
||||||
.Add(blockButton)
|
.Add(blockButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.SetInsets(0, 15, 0, 15)
|
.SetInsets(0, 15, 0, 15)
|
||||||
@@ -101,6 +105,7 @@ RemoteDevicesView::AttachedToWindow(void)
|
|||||||
addButton->SetTarget(this);
|
addButton->SetTarget(this);
|
||||||
removeButton->SetTarget(this);
|
removeButton->SetTarget(this);
|
||||||
pairButton->SetTarget(this);
|
pairButton->SetTarget(this);
|
||||||
|
disconnectButton->SetTarget(this);
|
||||||
blockButton->SetTarget(this);
|
blockButton->SetTarget(this);
|
||||||
availButton->SetTarget(this);
|
availButton->SetTarget(this);
|
||||||
|
|
||||||
@@ -145,6 +150,17 @@ RemoteDevicesView::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case kMsgDisconnectDevice:
|
||||||
|
{
|
||||||
|
DeviceListItem* device = static_cast<DeviceListItem*>(fDeviceList
|
||||||
|
->ItemAt(fDeviceList->CurrentSelection(0)));
|
||||||
|
RemoteDevice* remote = dynamic_cast<RemoteDevice*>(device->Device());
|
||||||
|
|
||||||
|
if (remote != NULL)
|
||||||
|
remote->Disconnect();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ protected:
|
|||||||
BButton* addButton;
|
BButton* addButton;
|
||||||
BButton* removeButton;
|
BButton* removeButton;
|
||||||
BButton* pairButton;
|
BButton* pairButton;
|
||||||
|
BButton* disconnectButton;
|
||||||
BButton* blockButton;
|
BButton* blockButton;
|
||||||
BButton* availButton;
|
BButton* availButton;
|
||||||
BListView* fDeviceList;
|
BListView* fDeviceList;
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ LocalDeviceImpl::HandleExpectedRequest(struct hci_event_header* event,
|
|||||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
case HCI_EVENT_DISCONNECTION_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¿?...
|
||||||
DisconnectionComplete(
|
DisconnectionComplete(
|
||||||
JumpEventHeader<struct hci_ev_disconnection_complete_reply>(event),
|
JumpEventHeader<struct hci_ev_disconnection_complete_reply>
|
||||||
request);
|
(event), request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_AUTH_COMPLETE:
|
case HCI_EVENT_AUTH_COMPLETE:
|
||||||
@@ -864,6 +864,7 @@ LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event,
|
|||||||
if (event->status == BT_OK) {
|
if (event->status == BT_OK) {
|
||||||
uint8 cod[3] = {0, 0, 0};
|
uint8 cod[3] = {0, 0, 0};
|
||||||
|
|
||||||
|
// TODO: Review, this rDevice is leaked
|
||||||
ConnectionIncoming* iConnection = new ConnectionIncoming(
|
ConnectionIncoming* iConnection = new ConnectionIncoming(
|
||||||
new RemoteDevice(event->bdaddr, cod));
|
new RemoteDevice(event->bdaddr, cod));
|
||||||
iConnection->Show();
|
iConnection->Show();
|
||||||
@@ -883,6 +884,9 @@ LocalDeviceImpl::ConnectionComplete(struct hci_ev_conn_complete* event,
|
|||||||
BMessage reply;
|
BMessage reply;
|
||||||
reply.AddInt8("status", event->status);
|
reply.AddInt8("status", event->status);
|
||||||
|
|
||||||
|
if (event->status == BT_OK)
|
||||||
|
reply.AddInt16("handle", event->handle);
|
||||||
|
|
||||||
request->SendReply(&reply);
|
request->SendReply(&reply);
|
||||||
reply.PrintToStream();
|
reply.PrintToStream();
|
||||||
|
|
||||||
@@ -901,8 +905,15 @@ LocalDeviceImpl::DisconnectionComplete(
|
|||||||
"%s: Handle=%#x, reason=%s status=%x\n", __FUNCTION__, event->handle,
|
"%s: Handle=%#x, reason=%s status=%x\n", __FUNCTION__, event->handle,
|
||||||
BluetoothError(event->reason), event->status);
|
BluetoothError(event->reason), event->status);
|
||||||
|
|
||||||
if (request != NULL)
|
if (request != NULL) {
|
||||||
|
BMessage reply;
|
||||||
|
reply.AddInt8("status", event->status);
|
||||||
|
|
||||||
|
request->SendReply(&reply);
|
||||||
|
reply.PrintToStream();
|
||||||
|
|
||||||
ClearWantedEvent(request);
|
ClearWantedEvent(request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user