bluetooth: connection handling refactor

- Introduced cancel connection feature in bluetooth preferences
- Moved the connection handling logic into LocalDeviceImpl
- Made a watchers list to send notices to all concerned applications

Change-Id: Iba87caff68d1b9640fa8d901059daa7a624531f5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/11171
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
mohammedrattia
2026-07-09 16:36:59 +00:00
committed by waddlesplash
parent eb349566e3
commit af619799ef
16 changed files with 632 additions and 260 deletions
+15
View File
@@ -113,13 +113,23 @@ struct hci_command_header {
} __attribute__ ((packed));
#define OCF_READ_CA_TIMEOUT 0x0015
struct hci_rp_read_conn_accept_timeout {
uint8 status;
uint16 conn_accept_timeout;
} __attribute__ ((packed));
#define OCF_WRITE_CA_TIMEOUT 0x0016
struct hci_cp_write_conn_accept_timeout {
uint16 conn_accept_timeout;
} __attribute__ ((packed));
#define OCF_READ_PG_TIMEOUT 0x0017
struct hci_rp_read_page_timeout {
uint8 status;
uint16 page_timeout;
} __attribute__ ((packed));
#define OCF_WRITE_PG_TIMEOUT 0x0018
struct hci_cp_write_page_timeout {
uint16 page_timeout;
} __attribute__ ((packed));
#define OCF_READ_SCAN_ENABLE 0x0019
struct hci_read_scan_enable {
@@ -250,6 +260,11 @@ struct hci_command_header {
uint16 pkt_type;
} __attribute__ ((packed));
#define OCF_CREATE_CONN_CANCEL 0x0008
struct hci_cp_create_conn_cancel {
bdaddr_t bdaddr;
} __attribute__ ((packed));
#define OCF_ACCEPT_CONN_REQ 0x0009
struct hci_cp_accept_conn_req {
bdaddr_t bdaddr;
+34 -28
View File
@@ -9,7 +9,7 @@
#include <bluetooth/bluetooth_error.h>
#include <bluetooth/BluetoothDevice.h>
#include <String.h>
#include <support/String.h>
#define B_BT_WAIT 0x00
#define B_BT_SUCCEEDED 0x01
@@ -26,33 +26,39 @@ public:
static const int WAIT = B_BT_WAIT;
static const int SUCCEEDED = B_BT_SUCCEEDED;
virtual ~RemoteDevice();
virtual ~RemoteDevice();
bool IsTrustedDevice();
BString GetFriendlyName(bool alwaysAsk); /* Throwing */
BString GetFriendlyName(void); /* Throwing */
BString GetCachedFriendlyName();
bdaddr_t GetBluetoothAddress();
DeviceClass GetDeviceClass();
bool IsTrustedDevice();
BString GetFriendlyName(bool alwaysAsk); /* Throwing */
BString GetFriendlyName(void); /* Throwing */
BString GetCachedFriendlyName();
bdaddr_t GetBluetoothAddress();
uint8 GetPageRepetitionMode();
uint8 GetScanMode();
uint8 GetClockOffset();
DeviceClass GetDeviceClass();
bool Equals(RemoteDevice* obj);
bool Equals(RemoteDevice* obj);
status_t Connect();
status_t CancelConnection();
status_t Disconnect();
/*static RemoteDevice* GetRemoteDevice(Connection conn); 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 */
/*bool IsAuthorized(Connection conn); Throwing */
bool IsEncrypted(); /* Throwing */
bool IsAuthenticated(); /* Throwing */
bool IsEncrypted(); /* Throwing */
BString GetProperty(const char* property); /* Throwing */
status_t GetProperty(const char* property, uint32* value); /* Throwing */
BString GetProperty(const char* property); /* Throwing */
status_t GetProperty(const char* property, uint32* value); /* Throwing */
LocalDevice* GetLocalDeviceOwner();
LocalDevice* GetLocalDeviceOwner();
RemoteDevice(const BString& address);
RemoteDevice(const bdaddr_t address, uint8 record[3]);
RemoteDevice(const BString& address);
RemoteDevice(const bdaddr_t address, uint8 record[3]);
protected:
/* called by Discovery[Listener|Agent] */
@@ -61,17 +67,17 @@ protected:
private:
LocalDevice* fDiscovererLocalDevice;
BMessenger* fMessenger;
LocalDevice* fDiscovererLocalDevice;
BMessenger* fMessenger;
uint16 fHandle;
uint8 fPageRepetitionMode;
uint8 fScanPeriodMode;
uint8 fScanMode;
uint16 fClockOffset;
int8 fRSSI;
BString fFriendlyName;
bool fFriendlyNameIsComplete;
uint16 fHandle;
uint8 fPageRepetitionMode;
uint8 fScanPeriodMode;
uint8 fScanMode;
uint16 fClockOffset;
int8 fRSSI;
BString fFriendlyName;
bool fFriendlyNameIsComplete;
};
}
+17 -5
View File
@@ -6,6 +6,9 @@
#define BLUETOOTH_APP_SIGNATURE "application/x-vnd.Haiku-BluetoothPrefs"
/* Kit Comunication */
// Watching
#define BT_START_WATCHING_CONNECTIONS 'wtST'
#define BT_STOP_WATCHING_CONNECTIONS 'wtSP'
// LocalDevice
#define BT_MSG_COUNT_LOCAL_DEVICES 'btCd'
@@ -16,10 +19,19 @@
#define BT_MSG_GET_PROPERTY 'btgP'
// Discovery
#define BT_MSG_INQUIRY_STARTED 'IqSt'
#define BT_MSG_INQUIRY_COMPLETED 'IqCM'
#define BT_MSG_INQUIRY_TERMINATED 'IqTR'
#define BT_MSG_INQUIRY_ERROR 'IqER'
#define BT_MSG_INQUIRY_DEVICE 'IqDE'
#define BT_MSG_INQUIRY_STARTED 'IqSt'
#define BT_MSG_INQUIRY_COMPLETED 'IqCM'
#define BT_MSG_INQUIRY_TERMINATED 'IqTR'
#define BT_MSG_INQUIRY_ERROR 'IqER'
#define BT_MSG_INQUIRY_DEVICE 'IqDE'
// Pairing
#define BT_MSG_CONN_FAILED 'CnFL'
#define BT_MSG_CONN_COMPLETED 'CnCM'
#define BT_MSG_DISCONN_COMPLETED 'DcCM'
#define BT_REQ_CREATE_CONN 'rdCN'
#define BT_REQ_CANCEL_CONN 'rdCC'
#define BT_REQ_DISCONNECT 'rdDC'
#endif