diff --git a/headers/os/bluetooth/DiscoveryAgent.h b/headers/os/bluetooth/DiscoveryAgent.h index 4fe837d161..2c0e444a19 100644 --- a/headers/os/bluetooth/DiscoveryAgent.h +++ b/headers/os/bluetooth/DiscoveryAgent.h @@ -1,5 +1,5 @@ /* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com * * All rights reserved. Distributed under the terms of the MIT License. * @@ -9,13 +9,19 @@ #define _DISCOVERY_AGENT_H #include +#include -#define B_BT_CACHED 0x00 -#define B_BT_PREKNOWN 0x01 -#define B_BT_NOT_DISCOVERABLE 0x01 -#define B_BT_GIAC 0x9E8B33 -#define B_BT_LIAC 0x9E8B00 +#define BT_CACHED 0x00 +#define BT_PREKNOWN 0x01 +#define BT_NOT_DISCOVERABLE 0x01 + +#define BT_GIAC 0x9E8B33 +#define BT_LIAC 0x9E8B00 + +#define BT_MAX_RESPONSES (32) +#define BT_BASE_INQUIRY_TIME (1.28) +#define BT_DEFAULT_INQUIRY_TIME (0x15*BT_BASE_INQUIRY_TIME) /* TODO: REVIEW SPECS! */ namespace Bluetooth { @@ -26,16 +32,17 @@ class DiscoveryAgent { public: - static const int GIAC = B_BT_GIAC; - static const int LIAC = B_BT_LIAC; + static const int GIAC = BT_GIAC; + static const int LIAC = BT_LIAC; - static const int PREKNOWN = B_BT_PREKNOWN; - static const int CACHED = B_BT_CACHED; - static const int NOT_DISCOVERABLE = B_BT_NOT_DISCOVERABLE; + static const int PREKNOWN = BT_PREKNOWN; + static const int CACHED = BT_CACHED; + static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE; - RemoteDevice** RetrieveDevices(int option); /* TODO */ - bool StartInquiry(int accessCode, DiscoveryListener listener); /* Throwing */ - bool CancelInquiry(DiscoveryListener listener); + RemoteDevicesList RetrieveDevices(int option); /* TODO */ + status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */ + status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs); + status_t CancelInquiry(DiscoveryListener* listener); /* int searchServices(int[] attrSet, @@ -49,7 +56,11 @@ class DiscoveryAgent { private: DiscoveryAgent(); - + void SetLocalDeviceOwner(LocalDevice* ld); + + DiscoveryListener* fLastUsedListener; + LocalDevice* fLocalDevice; + }; } diff --git a/headers/os/bluetooth/DiscoveryListener.h b/headers/os/bluetooth/DiscoveryListener.h index bf8440fde6..2a64347a61 100644 --- a/headers/os/bluetooth/DiscoveryListener.h +++ b/headers/os/bluetooth/DiscoveryListener.h @@ -9,26 +9,31 @@ #define _DISCOVERY_LISTENER_H #include +#include + +#include -#define B_BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs -#define B_BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X -#define B_BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X +#define BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs +#define BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X +#define BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X namespace Bluetooth { +typedef BObjectList RemoteDevicesList; + class RemoteDevice; class DeviceClass; +class LocalDevice; - -class DiscoveryListener : BLooper { +class DiscoveryListener : public BLooper { public: - static const int INQUIRY_COMPLETED = B_BT_INQUIRY_COMPLETED; - static const int INQUIRY_TERMINATED = B_BT_INQUIRY_TERMINATED; - static const int INQUIRY_ERROR = B_BT_INQUIRY_ERROR; + static const int INQUIRY_COMPLETED = BT_INQUIRY_COMPLETED; + static const int INQUIRY_TERMINATED = BT_INQUIRY_TERMINATED; + static const int INQUIRY_ERROR = BT_INQUIRY_ERROR; static const int SERVICE_SEARCH_COMPLETED = 0x01; static const int SERVICE_SEARCH_TERMINATED = 0x02; @@ -36,7 +41,7 @@ class DiscoveryListener : BLooper { static const int SERVICE_SEARCH_NO_RECORDS = 0x04; static const int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 0x06; - virtual void DeviceDiscovered(RemoteDevice btDevice, DeviceClass cod); + virtual void DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod); /* virtual void servicesDiscovered(int transID, ServiceRecord[] servRecord); virtual void serviceSearchCompleted(int transID, int respCode); @@ -48,8 +53,15 @@ class DiscoveryListener : BLooper { private: DiscoveryListener(); + void SetLocalDeviceOwner(LocalDevice* ld); + RemoteDevicesList GetRemoteDevicesList(void); + void MessageReceived(BMessage* msg); - + + LocalDevice* fLocalDevice; + RemoteDevicesList fRemoteDevicesList; + + friend class DiscoveryAgent; }; } diff --git a/headers/os/bluetooth/HCI/btHCI_command.h b/headers/os/bluetooth/HCI/btHCI_command.h index 065eb5c667..f324378b2f 100644 --- a/headers/os/bluetooth/HCI/btHCI_command.h +++ b/headers/os/bluetooth/HCI/btHCI_command.h @@ -181,6 +181,16 @@ struct hci_command_header { /* Link Control Command definition */ #define OGF_LINK_CONTROL 0x01 + + #define OCF_INQUIRY 0x0001 + struct hci_cp_inquiry { + uint8 lap[3]; + uint8 length; + uint8 num_rsp; + } __attribute__ ((packed)); + + #define OCF_INQUIRY_CANCEL 0x0002 + #define OCF_CREATE_CONN 0x0005 struct hci_cp_create_conn { bdaddr_t bdaddr; @@ -190,19 +200,7 @@ struct hci_command_header { uint16 clock_offset; uint8 role_switch; } __attribute__ ((packed)); - - #define OCF_ACCEPT_CONN_REQ 0x0009 - struct hci_cp_accept_conn_req { - bdaddr_t bdaddr; - uint8 role; - } __attribute__ ((packed)); - - #define OCF_REJECT_CONN_REQ 0x000a - struct hci_cp_reject_conn_req { - bdaddr_t bdaddr; - uint8 reason; - } __attribute__ ((packed)); - + #define OCF_DISCONNECT 0x0006 struct hci_disconnect { uint16 handle; @@ -214,19 +212,19 @@ struct hci_command_header { uint16 handle; uint16 pkt_type; } __attribute__ ((packed)); - - #define OCF_INQUIRY 0x0001 - struct hci_cp_inquiry { - uint8 lap[3]; - /* Constants related the inquiry process */ - #define B_BT_GIAC 0x9E8B33 - #define B_BT_LIAC 0x9E8B00 - uint8 length; - uint8 num_rsp; + + #define OCF_ACCEPT_CONN_REQ 0x0009 + struct hci_cp_accept_conn_req { + bdaddr_t bdaddr; + uint8 role; } __attribute__ ((packed)); - #define OCF_INQUIRY_CANCEL 0x0002 - + #define OCF_REJECT_CONN_REQ 0x000a + struct hci_cp_reject_conn_req { + bdaddr_t bdaddr; + uint8 reason; + } __attribute__ ((packed)); + #define OCF_LINK_KEY_REPLY 0x000B struct hci_cp_link_key_reply { bdaddr_t bdaddr; diff --git a/headers/os/bluetooth/HCI/btHCI_event.h b/headers/os/bluetooth/HCI/btHCI_event.h index ef1689b18b..a8078d43fe 100644 --- a/headers/os/bluetooth/HCI/btHCI_event.h +++ b/headers/os/bluetooth/HCI/btHCI_event.h @@ -9,6 +9,7 @@ #define _BTHCI_EVENT_H_ #include +#include #define HCI_EVENT_HDR_SIZE 2 diff --git a/headers/os/bluetooth/LocalDevice.h b/headers/os/bluetooth/LocalDevice.h index 2cba636f58..772daabd2d 100644 --- a/headers/os/bluetooth/LocalDevice.h +++ b/headers/os/bluetooth/LocalDevice.h @@ -49,7 +49,7 @@ class LocalDevice { void updateRecord(ServiceRecord srvRecord); */ private: - LocalDevice(hci_id hid); + LocalDevice(hci_id hid); static LocalDevice* RequestLocalDeviceID(BMessage* request); @@ -57,6 +57,9 @@ class LocalDevice { BMessenger* fMessenger; hci_id hid; + hci_id GetID(void) {return hid;} + + friend class DiscoveryAgent; }; } diff --git a/headers/os/bluetooth/RemoteDevice.h b/headers/os/bluetooth/RemoteDevice.h index ea7bbbec99..0ebeabbd1d 100644 --- a/headers/os/bluetooth/RemoteDevice.h +++ b/headers/os/bluetooth/RemoteDevice.h @@ -19,6 +19,7 @@ namespace Bluetooth { class Connection; +class LocalDevice; class RemoteDevice { @@ -32,12 +33,12 @@ class RemoteDevice { BString GetBluetoothAddress(); bool Equals(RemoteDevice* obj); - static RemoteDevice* GetRemoteDevice(Connection conn); /* Throwing */ + /*static RemoteDevice* GetRemoteDevice(Connection conn); Throwing */ bool Authenticate(); /* Throwing */ - bool Authorize(Connection conn); /* Throwing */ - bool Encrypt(Connection conn, bool on); /* Throwing */ + /* bool Authorize(Connection conn); Throwing */ + /*bool Encrypt(Connection conn, bool on); Throwing */ bool IsAuthenticated(); /* Throwing */ - bool IsAuthorized(Connection conn); /* Throwing */ + /*bool IsAuthorized(Connection conn); Throwing */ bool IsEncrypted(); /* Throwing */ protected: @@ -46,6 +47,12 @@ class RemoteDevice { /* Instances of this class only will be done by Discovery[Listener|Agent] TODO */ friend class DiscoveryListener; + + private: + void SetLocalDeviceOwner(LocalDevice* ld); + + bdaddr_t fBdaddr; + LocalDevice* fDiscovererLocalDevice; };