OSDN Git Service

external/bluez libs-3.35
[android-x86/external-bluetooth-bluez.git] / libs / include / l2cap.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2000-2001  Qualcomm Incorporated
6  *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
7  *  Copyright (C) 2002-2008  Marcel Holtmann <marcel@holtmann.org>
8  *
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  */
25
26 #ifndef __L2CAP_H
27 #define __L2CAP_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include <sys/socket.h>
34
35 /* L2CAP defaults */
36 #define L2CAP_DEFAULT_MTU       672
37 #define L2CAP_DEFAULT_FLUSH_TO  0xFFFF
38
39 #define L2CAP_CONN_TIMEOUT      (HZ * 40)
40
41 /* L2CAP socket address */
42 struct sockaddr_l2 {
43         sa_family_t     l2_family;
44         unsigned short  l2_psm;
45         bdaddr_t        l2_bdaddr;
46 };
47
48 /* L2CAP socket options */
49 #define L2CAP_OPTIONS   0x01
50 struct l2cap_options {
51         uint16_t        omtu;
52         uint16_t        imtu;
53         uint16_t        flush_to;
54         uint8_t         mode;
55 };
56
57 #define L2CAP_CONNINFO  0x02
58 struct l2cap_conninfo {
59         uint16_t        hci_handle;
60         uint8_t         dev_class[3];
61 };
62
63 #define L2CAP_LM        0x03
64 #define L2CAP_LM_MASTER         0x0001
65 #define L2CAP_LM_AUTH           0x0002
66 #define L2CAP_LM_ENCRYPT        0x0004
67 #define L2CAP_LM_TRUSTED        0x0008
68 #define L2CAP_LM_RELIABLE       0x0010
69 #define L2CAP_LM_SECURE         0x0020
70
71 /* L2CAP command codes */
72 #define L2CAP_COMMAND_REJ       0x01
73 #define L2CAP_CONN_REQ          0x02
74 #define L2CAP_CONN_RSP          0x03
75 #define L2CAP_CONF_REQ          0x04
76 #define L2CAP_CONF_RSP          0x05
77 #define L2CAP_DISCONN_REQ       0x06
78 #define L2CAP_DISCONN_RSP       0x07
79 #define L2CAP_ECHO_REQ          0x08
80 #define L2CAP_ECHO_RSP          0x09
81 #define L2CAP_INFO_REQ          0x0a
82 #define L2CAP_INFO_RSP          0x0b
83
84 /* L2CAP structures */
85 typedef struct {
86         uint16_t        len;
87         uint16_t        cid;
88 } __attribute__ ((packed)) l2cap_hdr;
89 #define L2CAP_HDR_SIZE 4
90
91 typedef struct {
92         uint8_t         code;
93         uint8_t         ident;
94         uint16_t        len;
95 } __attribute__ ((packed)) l2cap_cmd_hdr;
96 #define L2CAP_CMD_HDR_SIZE 4
97
98 typedef struct {
99         uint16_t        reason;
100 } __attribute__ ((packed)) l2cap_cmd_rej;
101 #define L2CAP_CMD_REJ_SIZE 2
102
103 typedef struct {
104         uint16_t        psm;
105         uint16_t        scid;
106 } __attribute__ ((packed)) l2cap_conn_req;
107 #define L2CAP_CONN_REQ_SIZE 4
108
109 typedef struct {
110         uint16_t        dcid;
111         uint16_t        scid;
112         uint16_t        result;
113         uint16_t        status;
114 } __attribute__ ((packed)) l2cap_conn_rsp;
115 #define L2CAP_CONN_RSP_SIZE 8
116
117 /* connect result */
118 #define L2CAP_CR_SUCCESS        0x0000
119 #define L2CAP_CR_PEND           0x0001
120 #define L2CAP_CR_BAD_PSM        0x0002
121 #define L2CAP_CR_SEC_BLOCK      0x0003
122 #define L2CAP_CR_NO_MEM         0x0004
123
124 /* connect status */
125 #define L2CAP_CS_NO_INFO        0x0000
126 #define L2CAP_CS_AUTHEN_PEND    0x0001
127 #define L2CAP_CS_AUTHOR_PEND    0x0002
128
129 typedef struct {
130         uint16_t        dcid;
131         uint16_t        flags;
132         uint8_t         data[0];
133 } __attribute__ ((packed)) l2cap_conf_req;
134 #define L2CAP_CONF_REQ_SIZE 4
135
136 typedef struct {
137         uint16_t        scid;
138         uint16_t        flags;
139         uint16_t        result;
140         uint8_t         data[0];
141 } __attribute__ ((packed)) l2cap_conf_rsp;
142 #define L2CAP_CONF_RSP_SIZE 6
143
144 #define L2CAP_CONF_SUCCESS      0x0000
145 #define L2CAP_CONF_UNACCEPT     0x0001
146 #define L2CAP_CONF_REJECT       0x0002
147 #define L2CAP_CONF_UNKNOWN      0x0003
148
149 typedef struct {
150         uint8_t         type;
151         uint8_t         len;
152         uint8_t         val[0];
153 } __attribute__ ((packed)) l2cap_conf_opt;
154 #define L2CAP_CONF_OPT_SIZE 2
155
156 #define L2CAP_CONF_MTU          0x01
157 #define L2CAP_CONF_FLUSH_TO     0x02
158 #define L2CAP_CONF_QOS          0x03
159 #define L2CAP_CONF_RFC          0x04
160 #define L2CAP_CONF_RFC_MODE     0x04
161
162 #define L2CAP_CONF_MAX_SIZE     22
163
164 #define L2CAP_MODE_BASIC        0x00
165 #define L2CAP_MODE_RETRANS      0x01
166 #define L2CAP_MODE_FLOWCTL      0x02
167
168 typedef struct {
169         uint16_t        dcid;
170         uint16_t        scid;
171 } __attribute__ ((packed)) l2cap_disconn_req;
172 #define L2CAP_DISCONN_REQ_SIZE 4
173
174 typedef struct {
175         uint16_t        dcid;
176         uint16_t        scid;
177 } __attribute__ ((packed)) l2cap_disconn_rsp;
178 #define L2CAP_DISCONN_RSP_SIZE 4
179
180 typedef struct {
181         uint16_t        type;
182 } __attribute__ ((packed)) l2cap_info_req;
183 #define L2CAP_INFO_REQ_SIZE 2
184
185 typedef struct {
186         uint16_t        type;
187         uint16_t        result;
188         uint8_t         data[0];
189 } __attribute__ ((packed)) l2cap_info_rsp;
190 #define L2CAP_INFO_RSP_SIZE 4
191
192 /* info type */
193 #define L2CAP_IT_CL_MTU         0x0001
194 #define L2CAP_IT_FEAT_MASK      0x0002
195
196 /* info result */
197 #define L2CAP_IR_SUCCESS        0x0000
198 #define L2CAP_IR_NOTSUPP        0x0001
199
200 #ifdef __cplusplus
201 }
202 #endif
203
204 #endif /* __L2CAP_H */