[haiku-commits] r36450 - in haiku/trunk: headers/os/bluetooth src/kits/bluetooth src/preferences/bluetooth src/servers/bluetooth

  • From: oliver.ruiz.dorantes@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 24 Apr 2010 18:01:08 +0200 (CEST)

Author: oruizdorantes
Date: 2010-04-24 18:01:08 +0200 (Sat, 24 Apr 2010)
New Revision: 36450
Changeset: http://dev.haiku-os.org/changeset/36450/haiku

Modified:
   haiku/trunk/headers/os/bluetooth/RemoteDevice.h
   haiku/trunk/headers/os/bluetooth/bluetooth_error.h
   haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp
   haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.cpp
   haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.h
   haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp
Log:
- 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



Modified: haiku/trunk/headers/os/bluetooth/RemoteDevice.h
===================================================================
--- haiku/trunk/headers/os/bluetooth/RemoteDevice.h     2010-04-24 13:16:13 UTC 
(rev 36449)
+++ haiku/trunk/headers/os/bluetooth/RemoteDevice.h     2010-04-24 16:01:08 UTC 
(rev 36450)
@@ -6,6 +6,7 @@
 #define _REMOTE_DEVICE_H
 
 #include <bluetooth/bluetooth.h>
+#include <bluetooth/bluetooth_error.h>
 #include <bluetooth/BluetoothDevice.h>
 
 #include <String.h>
@@ -36,7 +37,8 @@
        bool Equals(RemoteDevice* obj);
 
        /*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 Encrypt(Connection conn, bool on);  Throwing */
        bool IsAuthenticated(); /* Throwing */
@@ -61,6 +63,7 @@
        LocalDevice* fDiscovererLocalDevice;
        BMessenger*      fMessenger;
 
+       uint16          fHandle;
        uint8           fPageRepetitionMode;
        uint8           fScanPeriodMode;
        uint8           fScanMode;

Modified: haiku/trunk/headers/os/bluetooth/bluetooth_error.h
===================================================================
--- haiku/trunk/headers/os/bluetooth/bluetooth_error.h  2010-04-24 13:16:13 UTC 
(rev 36449)
+++ haiku/trunk/headers/os/bluetooth/bluetooth_error.h  2010-04-24 16:01:08 UTC 
(rev 36450)
@@ -30,9 +30,9 @@
 #define BT_HOST_TIMEOUT                                                0x10
 #define BT_UNSUPPORTED_FEATURE                         0x11
 #define BT_INVALID_PARAMETERS                          0x12
-#define BT_OE_USER_ENDED_CONNECTION                    0x13
-#define BT_OE_LOW_RESOURCES                                    0x14
-#define BT_OE_POWER_OFF                                                0x15
+#define BT_REMOTE_USER_ENDED_CONNECTION                0x13
+#define BT_REMOTE_LOW_RESOURCES                                0x14
+#define BT_REMOTE_POWER_OFF                                    0x15
 #define BT_CONNECTION_TERMINATED                       0x16
 #define BT_REPEATED_ATTEMPTS                           0x17
 #define BT_PAIRING_NOT_ALLOWED                         0x18

Modified: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp
===================================================================
--- haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp     2010-04-24 13:16:13 UTC 
(rev 36449)
+++ haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp     2010-04-24 16:01:08 UTC 
(rev 36450)
@@ -24,6 +24,8 @@
 
 namespace Bluetooth {
 
+// TODO: Check headers for valid/reserved ranges
+static const uint16 invalidConnectionHandle = 0xF000;
 
 bool
 RemoteDevice::IsTrustedDevice(void)
@@ -184,13 +186,58 @@
        if (fMessenger->SendMessage(&request, &reply) == B_OK)
                reply.FindInt8("status", &btStatus);
 
-       if (btStatus == BT_OK)
+       if (btStatus == BT_OK) {
+               reply.FindInt16("handle", (int16*)&fHandle);
                return true;
-       else
+       } else
                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 Encrypt(Connection conn, bool on);
 
@@ -231,7 +278,8 @@
 RemoteDevice::RemoteDevice(const bdaddr_t address, uint8 record[3])
        :
        BluetoothDevice(),
-       fDiscovererLocalDevice(NULL)
+       fDiscovererLocalDevice(NULL),
+       fHandle(invalidConnectionHandle)
 {
        fBdaddr = address;
        fDeviceClass.SetRecord(record);
@@ -242,7 +290,8 @@
 RemoteDevice::RemoteDevice(const BString& address)
        :
        BluetoothDevice(),
-       fDiscovererLocalDevice(NULL)
+       fDiscovererLocalDevice(NULL),
+       fHandle(invalidConnectionHandle)
 {
        fBdaddr = bdaddrUtils::FromString((const char*)address.String());
        fMessenger = _RetrieveBluetoothMessenger();

Modified: haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.cpp
===================================================================
--- haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.cpp 2010-04-24 
13:16:13 UTC (rev 36449)
+++ haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.cpp 2010-04-24 
16:01:08 UTC (rev 36450)
@@ -31,6 +31,7 @@
 static const uint32 kMsgAddDevices = 'ddDv';
 static const uint32 kMsgRemoveDevice = 'rmDv';
 static const uint32 kMsgPairDevice = 'trDv';
+static const uint32 kMsgDisconnectDevice = 'dsDv';
 static const uint32 kMsgBlockDevice = 'blDv';
 static const uint32 kMsgRefreshDevices = 'rfDv';
 
@@ -50,6 +51,8 @@
        pairButton = new BButton("pair", TR("Pair" B_UTF8_ELLIPSIS),
                new BMessage(kMsgPairDevice));
 
+       disconnectButton = new BButton("disconnect", TR("Disconnect"),
+               new BMessage(kMsgDisconnectDevice));
 
        blockButton = new BButton("block", TR("As blocked"),
                new BMessage(kMsgBlockDevice));
@@ -77,6 +80,7 @@
                        .Add(availButton)
                        .AddGlue()
                        .Add(pairButton)
+                       .Add(disconnectButton)
                        .Add(blockButton)
                        .AddGlue()
                        .SetInsets(0, 15, 0, 15)
@@ -101,6 +105,7 @@
        addButton->SetTarget(this);
        removeButton->SetTarget(this);
        pairButton->SetTarget(this);
+       disconnectButton->SetTarget(this);
        blockButton->SetTarget(this);
        availButton->SetTarget(this);
 
@@ -145,7 +150,18 @@
 
                        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:
                        BView::MessageReceived(message);
                        break;

Modified: haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.h
===================================================================
--- haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.h   2010-04-24 
13:16:13 UTC (rev 36449)
+++ haiku/trunk/src/preferences/bluetooth/RemoteDevicesView.h   2010-04-24 
16:01:08 UTC (rev 36450)
@@ -42,6 +42,7 @@
        BButton*                addButton;
        BButton*                removeButton;
        BButton*                pairButton;
+       BButton*                disconnectButton;
        BButton*                blockButton;
        BButton*                availButton;
        BListView*              fDeviceList;

Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp
===================================================================
--- haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp       2010-04-24 
13:16:13 UTC (rev 36449)
+++ haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp       2010-04-24 
16:01:08 UTC (rev 36450)
@@ -163,8 +163,8 @@
                case HCI_EVENT_DISCONNECTION_COMPLETE:
                        // should belong to a request?  can be sporadic or 
initiated by us¿?...
                        DisconnectionComplete(
-                               JumpEventHeader<struct 
hci_ev_disconnection_complete_reply>(event),
-                               request);
+                               JumpEventHeader<struct 
hci_ev_disconnection_complete_reply>
+                               (event), request);
                        break;
 
                case HCI_EVENT_AUTH_COMPLETE:
@@ -864,6 +864,7 @@
        if (event->status == BT_OK) {
                uint8 cod[3] = {0, 0, 0};
 
+               // TODO: Review, this rDevice is leaked
                ConnectionIncoming* iConnection = new ConnectionIncoming(
                        new RemoteDevice(event->bdaddr, cod));
                iConnection->Show();
@@ -883,6 +884,9 @@
                BMessage reply;
                reply.AddInt8("status", event->status);
 
+               if (event->status == BT_OK)
+                       reply.AddInt16("handle", event->handle);
+
                request->SendReply(&reply);
                reply.PrintToStream();
 
@@ -901,8 +905,15 @@
                "%s: Handle=%#x, reason=%s status=%x\n", __FUNCTION__, 
event->handle,
                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);
+       }
 }
 
 


Other related posts:

  • » [haiku-commits] r36450 - in haiku/trunk: headers/os/bluetooth src/kits/bluetooth src/preferences/bluetooth src/servers/bluetooth - oliver . ruiz . dorantes