]> rtime.felk.cvut.cz Git - mirosot.git/blob - bluetooth/l2cap.h
Initial import of Petr's work.
[mirosot.git] / bluetooth / l2cap.h
1 /*******************************************************************
2   bluetooth library
3
4   l2cap.h - list of fce for operation L2CAP protocol and
5             list of L2CAP structures
6
7   Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com
8
9  *******************************************************************/
10
11 #ifndef __L2CAP_H
12 #define __L2CAP_H
13
14
15 /* L2CAP defaults */
16 #define L2CAP_DEFAULT_MTU       672
17 #define L2CAP_DEFAULT_FLUSH_TO  0xFFFF
18
19 #define L2CAP_CONN_TIMEOUT      (HZ * 40)
20
21 /* L2CAP socket address */
22 //struct sockaddr_l2 {
23 //      sa_family_t     l2_family;
24 //      unsigned short  l2_psm;
25 //      bdaddr_t        l2_bdaddr;
26 //};
27
28 /* L2CAP socket options */
29 //#define L2CAP_OPTIONS 0x01
30 //struct l2cap_options {
31 //      uint16_t        omtu;
32 //      uint16_t        imtu;
33 //      uint16_t        flush_to;
34 //      uint8_t         mode;
35 //};
36
37
38 //#define L2CAP_CONNINFO        0x02
39 //struct l2cap_conninfo {
40 //      uint16_t        hci_handle;
41 //      uint8_t         dev_class[3];
42 //};
43
44 #define L2CAP_LM        0x03
45 #define L2CAP_LM_MASTER         0x0001
46 #define L2CAP_LM_AUTH             0x0002
47 #define L2CAP_LM_ENCRYPT        0x0004
48 #define L2CAP_LM_TRUSTED        0x0008
49 #define L2CAP_LM_RELIABLE       0x0010
50 #define L2CAP_LM_SECURE         0x0020
51
52 /* L2CAP command codes */
53 #define L2CAP_COMMAND_REJ       0x01
54 #define L2CAP_CONN_REQ          0x02
55 #define L2CAP_CONN_RSP          0x03
56 #define L2CAP_CONF_REQ          0x04
57 #define L2CAP_CONF_RSP          0x05
58 #define L2CAP_DISCONN_REQ       0x06
59 #define L2CAP_DISCONN_RSP       0x07
60 #define L2CAP_ECHO_REQ          0x08
61 #define L2CAP_ECHO_RSP          0x09
62 #define L2CAP_INFO_REQ          0x0a
63 #define L2CAP_INFO_RSP          0x0b
64
65 /* L2CAP structures */
66 typedef struct {
67         uint16_t        len;
68         uint16_t        cid;
69 } l2cap_hdr;
70 #define L2CAP_HDR____len      0
71 #define L2CAP_HDR____cid      2
72 /*--------------------------------*/
73 #define L2CAP_HDR_SIZE 4
74 /****************************************************************/
75 /****************************************************************/
76
77 typedef struct {
78         uint8_t         code;
79         uint8_t         ident;
80         uint16_t        len;
81 } l2cap_cmd_hdr;
82 #define L2CAP_CMD_HDR____code     0
83 #define L2CAP_CMD_HDR____ident    1
84 #define L2CAP_CMD_HDR____len      2
85 /*--------------------------------*/
86 #define L2CAP_CMD_HDR_SIZE 4
87 /****************************************************************/
88 /****************************************************************/
89
90 typedef struct {
91         uint16_t        reason;
92 }l2cap_cmd_rej;
93 #define L2CAP_CMD_REJ____reason     0
94 /*--------------------------------*/
95 #define L2CAP_CMD_REJ_SIZE 2
96 /****************************************************************/
97 /****************************************************************/
98
99 typedef struct {            //0x02
100         uint16_t        psm;
101         uint16_t        scid;
102 } l2cap_conn_req;
103
104 #define L2CAP_CONN_REQ____psm     0
105 #define L2CAP_CONN_REQ____scid    2
106 /*--------------------------------*/
107 #define L2CAP_CONN_REQ_SIZE 4
108 /****************************************************************/
109 /****************************************************************/
110
111 typedef struct {             //0x03
112         uint16_t        dcid;
113         uint16_t        scid;
114         uint16_t        result;
115         uint16_t        status;
116 } l2cap_conn_rsp;
117 #define L2CAP_CONN_RSP____dcid      0
118 #define L2CAP_CONN_RSP____scid      2
119 #define L2CAP_CONN_RSP____result    4
120 #define L2CAP_CONN_RSP____status    6
121 /*--------------------------------*/
122 #define L2CAP_CONN_RSP_SIZE 8
123 /****************************************************************/
124 /****************************************************************/
125
126 /* connect result */
127 #define L2CAP_CR_SUCCESS        0x0000
128 #define L2CAP_CR_PEND           0x0001
129 #define L2CAP_CR_BAD_PSM        0x0002
130 #define L2CAP_CR_SEC_BLOCK      0x0003
131 #define L2CAP_CR_NO_MEM         0x0004
132
133 /* connect status */
134 #define L2CAP_CS_NO_INFO        0x0000
135 #define L2CAP_CS_AUTHEN_PEND    0x0001
136 #define L2CAP_CS_AUTHOR_PEND    0x0002
137
138 typedef struct {            //0x04
139         uint16_t        dcid;
140         uint16_t        flags;
141         uint8_t         data[0];
142 }  l2cap_conf_req;
143 #define L2CAP_CONF_REQ____dcid    0
144 #define L2CAP_CONF_REQ____flags   2
145 #define L2CAP_CONF_REQ____data    4
146 /*--------------------------------*/
147 #define L2CAP_CONF_REQ_SIZE 4
148 /****************************************************************/
149 /****************************************************************/
150
151 typedef struct {     //0x05
152         uint16_t        scid;
153         uint16_t        flags;
154         uint16_t        result;
155         uint8_t         data[0];
156 } l2cap_conf_rsp;
157 #define L2CAP_CONF_RSP____scid    0
158 #define L2CAP_CONF_RSP____flags   2
159 #define L2CAP_CONF_RSP____result  4
160 #define L2CAP_CONF_RSP____data    6
161 /*--------------------------------*/
162 #define L2CAP_CONF_RSP_SIZE 6
163 /****************************************************************/
164 /****************************************************************/
165
166
167
168 #define L2CAP_CONF_SUCCESS      0x0000
169 #define L2CAP_CONF_UNACCEPT     0x0001
170 #define L2CAP_CONF_REJECT       0x0002
171 #define L2CAP_CONF_UNKNOWN      0x0003
172
173 typedef struct {
174         uint8_t         type;
175         uint8_t         len;
176         uint8_t         val[0];
177 } l2cap_conf_opt;
178 #define L2CAP_CONF_OPT____type    0
179 #define L2CAP_CONF_OPT____len     1
180 #define L2CAP_CONF_OPT____val     2
181 /*--------------------------------*/
182 #define L2CAP_CONF_OPT_SIZE 2
183 /****************************************************************/
184 /****************************************************************/
185
186
187 #define L2CAP_CONF_MTU          0x01
188 #define L2CAP_CONF_FLUSH_TO     0x02
189 #define L2CAP_CONF_QOS          0x03
190 #define L2CAP_CONF_RFC          0x04
191 #define L2CAP_CONF_RFC_MODE     0x04
192
193 #define L2CAP_CONF_MAX_SIZE     22
194
195 typedef struct {
196         uint16_t        dcid;
197         uint16_t        scid;
198 } l2cap_disconn_req;
199 #define L2CAP_DISCONN_REQ____dcid    0
200 #define L2CAP_DISCONN_REQ____scid    2
201 /*--------------------------------*/
202 #define L2CAP_DISCONN_REQ_SIZE 4
203 /****************************************************************/
204 /****************************************************************/
205
206 typedef struct {
207         uint16_t        dcid;
208         uint16_t        scid;
209 } l2cap_disconn_rsp;
210 #define L2CAP_DISCONN_RSP____dcid    0
211 #define L2CAP_DISCONN_RSP____scid    2
212 /*--------------------------------*/
213 #define L2CAP_DISCONN_RSP_SIZE 4
214 /****************************************************************/
215 /****************************************************************/
216
217 typedef struct {
218         uint16_t        type;
219         uint8_t         data[0];
220 } l2cap_info_req;
221 #define L2CAP_INFO_REQ____type    0
222 #define L2CAP_INFO_REQ____data    2
223 /*--------------------------------*/
224 #define L2CAP_INFO_REQ_SIZE 2
225 /****************************************************************/
226 /****************************************************************/
227
228 typedef struct {
229         uint16_t        type;
230         uint16_t        result;
231         uint8_t         data[0];
232 } l2cap_info_rsp;
233 #define L2CAP_INFO_RSP____type    0
234 #define L2CAP_INFO_RSP____result  2
235 #define L2CAP_INFO_RSP____data    4
236 /*--------------------------------*/
237 #define L2CAP_INFO_RSP_SIZE 4
238 /****************************************************************/
239 /****************************************************************/
240
241 /* info type */
242 #define L2CAP_IT_CL_MTU         0x0001
243 #define L2CAP_IT_FEAT_MASK      0x0002
244
245 /* info result */
246 #define L2CAP_IR_SUCCESS        0x0000
247 #define L2CAP_IR_NOTSUPP        0x0001
248
249
250
251
252
253
254
255 /*----------------------- funkce zavisle na code -----------------------------------*/
256 int l2cap_signaling(uint8_t *bth_p, uint16_t size, int dev_num);
257
258 int l2cap_none(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);
259 int l2cap_cod_command_rej(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);    //0x01
260 int l2cap_cod_conn_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x02
261 int l2cap_cod_conn_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x03
262 int l2cap_cod_conf_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x04
263 int l2cap_cod_conf_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x05
264 int l2cap_cod_disconn_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);  //0x06
265 int l2cap_cod_disconn_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);  //0x07
266 int l2cap_cod_echo_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x08
267 int l2cap_cod_echo_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x09
268 int l2cap_cod_info_req(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x0a
269 int l2cap_cod_info_rsp(uint8_t *bth_p, uint16_t size, int dev_num, int pos_chan);     //0x0b
270 //int l2cap_send_data(int inx_handle, int inx_chanal);
271
272 #endif /* __L2CAP_H */