2 * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
11 #include <util/DoublyLinkedList.h>
12 #include <util/DoublyLinkedQueue.h>
14 #include <net_buffer.h>
15 #include <net_device.h>
17 #include <bluetooth/bluetooth.h>
18 #include <bluetooth/HCI/btHCI.h>
19 #include <bluetooth/HCI/btHCI_transport.h>
23 #define BT_CORE_DATA_MODULE_NAME "bluetooth/btCoreData/v1"
30 typedef enum _connection_status
{
38 struct HciConnection
: DoublyLinkedListLinkImpl
<HciConnection
> {
40 virtual ~HciConnection();
43 bluetooth_device
* ndevice
;
44 net_buffer
* currentRxPacket
;
45 ssize_t currentRxExpectedLength
;
50 connection_status status
;
53 DoublyLinkedList
<L2capChannel
> ChannelList
;
54 DoublyLinkedList
<L2capFrame
> ExpectedResponses
;
55 DoublyLinkedList
<L2capFrame
> OutGoingFrames
;
66 typedef enum _channel_status
{
67 L2CAP_CHAN_CLOSED
, /* channel closed */
68 L2CAP_CHAN_W4_L2CAP_CON_RSP
, /* wait for L2CAP resp. */
69 L2CAP_CHAN_W4_L2CA_CON_RSP
, /* wait for upper resp. */
70 L2CAP_CHAN_CONFIG
, /* L2CAP configuration */
71 L2CAP_CHAN_OPEN
, /* channel open */
72 L2CAP_CHAN_W4_L2CAP_DISCON_RSP
, /* wait for L2CAP discon. */
73 L2CAP_CHAN_W4_L2CA_DISCON_RSP
/* wait for upper discon. */
79 typedef struct _ChannelConfiguration
{
81 uint16 imtu
; /* incoming channel MTU */
82 l2cap_flow_t iflow
; /* incoming flow control */
83 uint16 omtu
; /* outgoing channel MTU */
84 l2cap_flow_t oflow
; /* outgoing flow control */
86 uint16 flush_timo
; /* flush timeout */
87 uint16 link_timo
; /* link timeout */
89 } ChannelConfiguration
;
91 struct L2capChannel
: DoublyLinkedListLinkImpl
<L2capChannel
> {
100 ChannelConfiguration
* configuration
;
101 L2capEndpoint
* endpoint
;
107 typedef enum _frametype
{
108 L2CAP_C_FRAME
, // signals
109 L2CAP_G_FRAME
, // CL packets
110 L2CAP_B_FRAME
, // CO packets
118 struct L2capFrame
: DoublyLinkedListLinkImpl
<L2capFrame
> {
121 L2capChannel
* channel
;
123 uint16 flags
; /* command flags */
124 #define L2CAP_CMD_PENDING (1 << 0) /* command is pending */
126 uint8 code
; /* L2CAP command opcode */
127 uint8 ident
; /* L2CAP command ident */
131 net_buffer
* buffer
; // contains 1 l2cap / mutliple acls
133 // TODO :struct callout timo; /* RTX/ERTX timeout */
139 struct bluetooth_core_data_module_info
{
142 status_t (*PostEvent
)(bluetooth_device
* ndev
, void* event
,
144 struct HciConnection
* (*AddConnection
)(uint16 handle
, int type
,
145 const bdaddr_t
& dst
, hci_id hid
);
147 // status_t (*RemoveConnection)(bdaddr_t destination, hci_id hid);
148 status_t (*RemoveConnection
)(uint16 handle
, hci_id hid
);
150 hci_id (*RouteConnection
)(const bdaddr_t
& destination
);
152 void (*SetAclBuffer
)(struct HciConnection
* conn
,
154 void (*SetAclExpectedSize
)(struct HciConnection
* conn
,
156 void (*AclPutting
)(struct HciConnection
* conn
,
158 bool (*AclComplete
)(struct HciConnection
* conn
);
159 bool (*AclOverFlowed
)(struct HciConnection
* conn
);
161 struct HciConnection
* (*ConnectionByHandle
)(uint16 handle
, hci_id hid
);
162 struct HciConnection
* (*ConnectionByDestination
)(
163 const bdaddr_t
& destination
, hci_id hid
);
165 struct L2capChannel
* (*AddChannel
)(struct HciConnection
* conn
,
167 void (*RemoveChannel
)(struct HciConnection
* conn
,
169 struct L2capChannel
* (*ChannelBySourceID
)(struct HciConnection
* conn
,
171 uint16 (*ChannelAllocateCid
)(struct HciConnection
* conn
);
172 uint16 (*ChannelAllocateIdent
)(struct HciConnection
* conn
);
174 struct L2capFrame
* (*SignalByIdent
)(struct HciConnection
* conn
,
176 status_t (*TimeoutSignal
)(struct L2capFrame
* frame
,
178 status_t (*UnTimeoutSignal
)(struct L2capFrame
* frame
);
179 struct L2capFrame
* (*SpawnFrame
)(struct HciConnection
* conn
,
180 struct L2capChannel
* channel
,
181 net_buffer
* buffer
, frame_type frame
);
182 struct L2capFrame
* (*SpawnSignal
)(struct HciConnection
* conn
,
183 struct L2capChannel
* channel
,
184 net_buffer
* buffer
, uint8 ident
, uint8 code
);
185 status_t (*AcknowledgeSignal
)(struct L2capFrame
* frame
);
186 status_t (*QueueSignal
)(struct L2capFrame
* frame
);
191 inline bool ExistConnectionByDestination(const bdaddr_t
& destination
,
193 inline bool ExistConnectionByHandle(uint16 handle
, hci_id hid
);
196 #endif // _BTCOREDATA_H