btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / bluetooth / btCoreData.h
blob6e0762ab63f430179dd2e179727eaf3bcf3117b0
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
9 #include <module.h>
10 #include <lock.h>
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>
20 #include <l2cap.h>
23 #define BT_CORE_DATA_MODULE_NAME "bluetooth/btCoreData/v1"
26 struct L2capChannel;
27 struct L2capFrame;
28 struct L2capEndpoint;
30 typedef enum _connection_status {
31 HCI_CONN_CLOSED,
32 HCI_CONN_OPEN,
33 } connection_status;
36 #ifdef __cplusplus
38 struct HciConnection : DoublyLinkedListLinkImpl<HciConnection> {
39 HciConnection();
40 virtual ~HciConnection();
42 hci_id Hid;
43 bluetooth_device* ndevice;
44 net_buffer* currentRxPacket;
45 ssize_t currentRxExpectedLength;
46 bdaddr_t destination;
47 uint16 handle;
48 int type;
49 uint16 mtu;
50 connection_status status;
51 uint16 lastCid;
52 uint8 lastIdent;
53 DoublyLinkedList<L2capChannel> ChannelList;
54 DoublyLinkedList<L2capFrame> ExpectedResponses;
55 DoublyLinkedList<L2capFrame> OutGoingFrames;
56 mutex fLock;
57 mutex fLockExpected;
60 #else
62 struct HciConnection;
64 #endif
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. */
74 } channel_status;
77 #ifdef __cplusplus
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> {
92 HciConnection* conn;
93 uint16 scid;
94 uint16 dcid;
95 uint16 psm;
96 uint8 ident;
97 uint8 cfgState;
99 channel_status state;
100 ChannelConfiguration* configuration;
101 L2capEndpoint* endpoint;
104 #endif
107 typedef enum _frametype {
108 L2CAP_C_FRAME, // signals
109 L2CAP_G_FRAME, // CL packets
110 L2CAP_B_FRAME, // CO packets
112 L2CAP_I_FRAME,
113 L2CAP_S_FRAME
114 } frame_type;
116 #ifdef __cplusplus
118 struct L2capFrame : DoublyLinkedListLinkImpl<L2capFrame> {
120 HciConnection* conn;
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 */
129 frame_type type;
131 net_buffer* buffer; // contains 1 l2cap / mutliple acls
133 // TODO :struct callout timo; /* RTX/ERTX timeout */
136 #endif
139 struct bluetooth_core_data_module_info {
140 module_info info;
142 status_t (*PostEvent)(bluetooth_device* ndev, void* event,
143 size_t size);
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,
153 net_buffer* nbuf);
154 void (*SetAclExpectedSize)(struct HciConnection* conn,
155 size_t size);
156 void (*AclPutting)(struct HciConnection* conn,
157 size_t size);
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,
166 uint16 psm);
167 void (*RemoveChannel)(struct HciConnection* conn,
168 uint16 scid);
169 struct L2capChannel* (*ChannelBySourceID)(struct HciConnection* conn,
170 uint16 sid);
171 uint16 (*ChannelAllocateCid)(struct HciConnection* conn);
172 uint16 (*ChannelAllocateIdent)(struct HciConnection* conn);
174 struct L2capFrame* (*SignalByIdent)(struct HciConnection* conn,
175 uint8 ident);
176 status_t (*TimeoutSignal)(struct L2capFrame* frame,
177 uint32 timeo);
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,
192 hci_id hid);
193 inline bool ExistConnectionByHandle(uint16 handle, hci_id hid);
196 #endif // _BTCOREDATA_H