1 /* 2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef _BTCOREDATA_H 6 #define _BTCOREDATA_H 7 8 9 #include <module.h> 10 #include <lock.h> 11 #include <util/DoublyLinkedList.h> 12 #include <util/VectorMap.h> 13 #include <net_datalink.h> 14 #include <net/if_dl.h> 15 16 17 #include <net_buffer.h> 18 #include <net_device.h> 19 20 #include <bluetooth/bluetooth.h> 21 #include <bluetooth/HCI/btHCI.h> 22 #include <bluetooth/HCI/btHCI_transport.h> 23 #include <l2cap.h> 24 25 26 #define BT_CORE_DATA_MODULE_NAME "bluetooth/btCoreData/v1" 27 28 29 typedef enum _connection_status { 30 HCI_CONN_CLOSED, 31 HCI_CONN_OPEN, 32 } connection_status; 33 34 35 #ifdef __cplusplus 36 37 struct HciConnection : DoublyLinkedListLinkImpl<HciConnection> { 38 HciConnection(hci_id hid); 39 virtual ~HciConnection(); 40 41 hci_id Hid; 42 bluetooth_device* ndevice; 43 bdaddr_t destination; 44 uint16 handle; 45 int type; 46 uint16 mtu; 47 connection_status status; 48 49 net_buffer* currentRxPacket; 50 ssize_t currentRxExpectedLength; 51 52 struct net_interface_address interface_address; 53 struct sockaddr_dl address_dl; 54 struct sockaddr_storage address_dest; 55 56 void (*disconnect_hook)(HciConnection*); 57 58 public: 59 mutex fLock; 60 uint8 fNextIdent; 61 VectorMap<uint8, void*> fInUseIdents; 62 }; 63 64 #else 65 66 struct HciConnection; 67 68 #endif 69 70 71 struct bluetooth_core_data_module_info { 72 module_info info; 73 74 status_t (*PostEvent)(bluetooth_device* ndev, void* event, 75 size_t size); 76 77 // FIXME: We really shouldn't be passing out connection pointers at all... 78 struct HciConnection* (*AddConnection)(uint16 handle, int type, 79 const bdaddr_t& dst, hci_id hid); 80 81 // status_t (*RemoveConnection)(bdaddr_t destination, hci_id hid); 82 status_t (*RemoveConnection)(uint16 handle, hci_id hid); 83 84 hci_id (*RouteConnection)(const bdaddr_t& destination); 85 86 struct HciConnection* (*ConnectionByHandle)(uint16 handle, hci_id hid); 87 struct HciConnection* (*ConnectionByDestination)( 88 const bdaddr_t& destination, hci_id hid); 89 90 uint8 (*allocate_command_ident)(struct HciConnection* conn, void* associated); 91 void* (*lookup_command_ident)(struct HciConnection* conn, uint8 ident); 92 void (*free_command_ident)(struct HciConnection* conn, uint8 ident); 93 }; 94 95 96 inline bool ExistConnectionByDestination(const bdaddr_t& destination, 97 hci_id hid); 98 inline bool ExistConnectionByHandle(uint16 handle, hci_id hid); 99 100 101 #endif // _BTCOREDATA_H 102