Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | BlueZ - Bluetooth protocol stack for Linux |
| 3 | Copyright (C) 2000-2001 Qualcomm Incorporated |
| 4 | |
| 5 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License version 2 as |
| 9 | published by the Free Software Foundation; |
| 10 | |
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 12 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 14 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
| 15 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 16 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 18 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 | |
| 20 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 21 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
| 22 | SOFTWARE IS DISCLAIMED. |
| 23 | */ |
| 24 | |
| 25 | #ifndef __L2CAP_H |
| 26 | #define __L2CAP_H |
| 27 | |
| 28 | /* L2CAP defaults */ |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 29 | #define L2CAP_DEFAULT_MTU 672 |
Gustavo F. Padovan | f2fcfcd | 2009-07-04 15:06:24 -0300 | [diff] [blame] | 30 | #define L2CAP_DEFAULT_MIN_MTU 48 |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 31 | #define L2CAP_DEFAULT_FLUSH_TO 0xffff |
Gustavo F. Padovan | f2fcfcd | 2009-07-04 15:06:24 -0300 | [diff] [blame] | 32 | #define L2CAP_DEFAULT_TX_WINDOW 1 |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 33 | #define L2CAP_DEFAULT_MAX_RECEIVE 1 |
| 34 | #define L2CAP_DEFAULT_RETRANS_TO 300 /* 300 milliseconds */ |
| 35 | #define L2CAP_DEFAULT_MONITOR_TO 1000 /* 1 second */ |
| 36 | #define L2CAP_DEFAULT_MAX_RX_APDU 0xfff7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 38 | #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ |
| 39 | #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | /* L2CAP socket address */ |
| 42 | struct sockaddr_l2 { |
| 43 | sa_family_t l2_family; |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 44 | __le16 l2_psm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | bdaddr_t l2_bdaddr; |
Marcel Holtmann | f29972d | 2009-02-12 05:07:45 +0100 | [diff] [blame] | 46 | __le16 l2_cid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /* L2CAP socket options */ |
| 50 | #define L2CAP_OPTIONS 0x01 |
| 51 | struct l2cap_options { |
| 52 | __u16 omtu; |
| 53 | __u16 imtu; |
| 54 | __u16 flush_to; |
| 55 | __u8 mode; |
| 56 | }; |
| 57 | |
| 58 | #define L2CAP_CONNINFO 0x02 |
| 59 | struct l2cap_conninfo { |
| 60 | __u16 hci_handle; |
| 61 | __u8 dev_class[3]; |
| 62 | }; |
| 63 | |
| 64 | #define L2CAP_LM 0x03 |
| 65 | #define L2CAP_LM_MASTER 0x0001 |
| 66 | #define L2CAP_LM_AUTH 0x0002 |
| 67 | #define L2CAP_LM_ENCRYPT 0x0004 |
| 68 | #define L2CAP_LM_TRUSTED 0x0008 |
| 69 | #define L2CAP_LM_RELIABLE 0x0010 |
| 70 | #define L2CAP_LM_SECURE 0x0020 |
| 71 | |
| 72 | /* L2CAP command codes */ |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 73 | #define L2CAP_COMMAND_REJ 0x01 |
| 74 | #define L2CAP_CONN_REQ 0x02 |
| 75 | #define L2CAP_CONN_RSP 0x03 |
| 76 | #define L2CAP_CONF_REQ 0x04 |
| 77 | #define L2CAP_CONF_RSP 0x05 |
| 78 | #define L2CAP_DISCONN_REQ 0x06 |
| 79 | #define L2CAP_DISCONN_RSP 0x07 |
| 80 | #define L2CAP_ECHO_REQ 0x08 |
| 81 | #define L2CAP_ECHO_RSP 0x09 |
| 82 | #define L2CAP_INFO_REQ 0x0a |
| 83 | #define L2CAP_INFO_RSP 0x0b |
| 84 | |
| 85 | /* L2CAP feature mask */ |
| 86 | #define L2CAP_FEAT_FLOWCTL 0x00000001 |
| 87 | #define L2CAP_FEAT_RETRANS 0x00000002 |
| 88 | #define L2CAP_FEAT_ERTM 0x00000008 |
| 89 | #define L2CAP_FEAT_STREAMING 0x00000010 |
| 90 | #define L2CAP_FEAT_FCS 0x00000020 |
| 91 | #define L2CAP_FEAT_FIXED_CHAN 0x00000080 |
| 92 | |
| 93 | /* L2CAP checksum option */ |
| 94 | #define L2CAP_FCS_NONE 0x00 |
| 95 | #define L2CAP_FCS_CRC16 0x01 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | /* L2CAP structures */ |
| 98 | struct l2cap_hdr { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 99 | __le16 len; |
| 100 | __le16 cid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } __attribute__ ((packed)); |
| 102 | #define L2CAP_HDR_SIZE 4 |
| 103 | |
| 104 | struct l2cap_cmd_hdr { |
| 105 | __u8 code; |
| 106 | __u8 ident; |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 107 | __le16 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } __attribute__ ((packed)); |
| 109 | #define L2CAP_CMD_HDR_SIZE 4 |
| 110 | |
| 111 | struct l2cap_cmd_rej { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 112 | __le16 reason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } __attribute__ ((packed)); |
| 114 | |
| 115 | struct l2cap_conn_req { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 116 | __le16 psm; |
| 117 | __le16 scid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } __attribute__ ((packed)); |
| 119 | |
| 120 | struct l2cap_conn_rsp { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 121 | __le16 dcid; |
| 122 | __le16 scid; |
| 123 | __le16 result; |
| 124 | __le16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } __attribute__ ((packed)); |
| 126 | |
Gustavo F. Padovan | 8db4dc4 | 2009-04-20 01:31:05 -0300 | [diff] [blame] | 127 | /* channel indentifier */ |
| 128 | #define L2CAP_CID_SIGNALING 0x0001 |
| 129 | #define L2CAP_CID_CONN_LESS 0x0002 |
| 130 | #define L2CAP_CID_DYN_START 0x0040 |
| 131 | #define L2CAP_CID_DYN_END 0xffff |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /* connect result */ |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 134 | #define L2CAP_CR_SUCCESS 0x0000 |
| 135 | #define L2CAP_CR_PEND 0x0001 |
| 136 | #define L2CAP_CR_BAD_PSM 0x0002 |
| 137 | #define L2CAP_CR_SEC_BLOCK 0x0003 |
| 138 | #define L2CAP_CR_NO_MEM 0x0004 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* connect status */ |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 141 | #define L2CAP_CS_NO_INFO 0x0000 |
| 142 | #define L2CAP_CS_AUTHEN_PEND 0x0001 |
| 143 | #define L2CAP_CS_AUTHOR_PEND 0x0002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | struct l2cap_conf_req { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 146 | __le16 dcid; |
| 147 | __le16 flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | __u8 data[0]; |
| 149 | } __attribute__ ((packed)); |
| 150 | |
| 151 | struct l2cap_conf_rsp { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 152 | __le16 scid; |
| 153 | __le16 flags; |
| 154 | __le16 result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | __u8 data[0]; |
| 156 | } __attribute__ ((packed)); |
| 157 | |
Marcel Holtmann | 5dee9e7 | 2007-05-24 14:27:19 +0200 | [diff] [blame] | 158 | #define L2CAP_CONF_SUCCESS 0x0000 |
| 159 | #define L2CAP_CONF_UNACCEPT 0x0001 |
| 160 | #define L2CAP_CONF_REJECT 0x0002 |
| 161 | #define L2CAP_CONF_UNKNOWN 0x0003 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | struct l2cap_conf_opt { |
| 164 | __u8 type; |
| 165 | __u8 len; |
| 166 | __u8 val[0]; |
| 167 | } __attribute__ ((packed)); |
| 168 | #define L2CAP_CONF_OPT_SIZE 2 |
| 169 | |
Gustavo F. Padovan | 589d274 | 2009-04-20 01:31:07 -0300 | [diff] [blame] | 170 | #define L2CAP_CONF_HINT 0x80 |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 171 | #define L2CAP_CONF_MASK 0x7f |
Gustavo F. Padovan | 589d274 | 2009-04-20 01:31:07 -0300 | [diff] [blame] | 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | #define L2CAP_CONF_MTU 0x01 |
| 174 | #define L2CAP_CONF_FLUSH_TO 0x02 |
| 175 | #define L2CAP_CONF_QOS 0x03 |
| 176 | #define L2CAP_CONF_RFC 0x04 |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 177 | #define L2CAP_CONF_FCS 0x05 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | #define L2CAP_CONF_MAX_SIZE 22 |
| 180 | |
Marcel Holtmann | 6464f35 | 2007-10-20 13:39:51 +0200 | [diff] [blame] | 181 | struct l2cap_conf_rfc { |
| 182 | __u8 mode; |
| 183 | __u8 txwin_size; |
| 184 | __u8 max_transmit; |
| 185 | __le16 retrans_timeout; |
| 186 | __le16 monitor_timeout; |
| 187 | __le16 max_pdu_size; |
| 188 | } __attribute__ ((packed)); |
| 189 | |
| 190 | #define L2CAP_MODE_BASIC 0x00 |
| 191 | #define L2CAP_MODE_RETRANS 0x01 |
| 192 | #define L2CAP_MODE_FLOWCTL 0x02 |
Marcel Holtmann | 47ec1dcd | 2009-05-02 18:57:55 -0700 | [diff] [blame] | 193 | #define L2CAP_MODE_ERTM 0x03 |
Marcel Holtmann | c6b03cf | 2009-05-02 22:31:10 -0700 | [diff] [blame] | 194 | #define L2CAP_MODE_STREAMING 0x04 |
Marcel Holtmann | 6464f35 | 2007-10-20 13:39:51 +0200 | [diff] [blame] | 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | struct l2cap_disconn_req { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 197 | __le16 dcid; |
| 198 | __le16 scid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } __attribute__ ((packed)); |
| 200 | |
| 201 | struct l2cap_disconn_rsp { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 202 | __le16 dcid; |
| 203 | __le16 scid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } __attribute__ ((packed)); |
| 205 | |
| 206 | struct l2cap_info_req { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 207 | __le16 type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } __attribute__ ((packed)); |
| 209 | |
| 210 | struct l2cap_info_rsp { |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 211 | __le16 type; |
| 212 | __le16 result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | __u8 data[0]; |
| 214 | } __attribute__ ((packed)); |
| 215 | |
| 216 | /* info type */ |
| 217 | #define L2CAP_IT_CL_MTU 0x0001 |
| 218 | #define L2CAP_IT_FEAT_MASK 0x0002 |
Marcel Holtmann | e1027a7 | 2009-02-09 09:18:02 +0100 | [diff] [blame] | 219 | #define L2CAP_IT_FIXED_CHAN 0x0003 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /* info result */ |
| 222 | #define L2CAP_IR_SUCCESS 0x0000 |
| 223 | #define L2CAP_IR_NOTSUPP 0x0001 |
| 224 | |
| 225 | /* ----- L2CAP connections ----- */ |
| 226 | struct l2cap_chan_list { |
| 227 | struct sock *head; |
| 228 | rwlock_t lock; |
| 229 | long num; |
| 230 | }; |
| 231 | |
| 232 | struct l2cap_conn { |
| 233 | struct hci_conn *hcon; |
| 234 | |
| 235 | bdaddr_t *dst; |
| 236 | bdaddr_t *src; |
| 237 | |
| 238 | unsigned int mtu; |
| 239 | |
Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 240 | __u32 feat_mask; |
| 241 | |
| 242 | __u8 info_state; |
| 243 | __u8 info_ident; |
| 244 | |
| 245 | struct timer_list info_timer; |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | spinlock_t lock; |
| 248 | |
| 249 | struct sk_buff *rx_skb; |
| 250 | __u32 rx_len; |
| 251 | __u8 rx_ident; |
| 252 | __u8 tx_ident; |
| 253 | |
Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 254 | __u8 disc_reason; |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | struct l2cap_chan_list chan_list; |
| 257 | }; |
| 258 | |
Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 259 | #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 |
Marcel Holtmann | 984947d | 2009-02-06 23:35:19 +0100 | [diff] [blame] | 260 | #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 |
| 261 | #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 |
Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | /* ----- L2CAP channel and socket info ----- */ |
| 264 | #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) |
| 265 | |
| 266 | struct l2cap_pinfo { |
| 267 | struct bt_sock bt; |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 268 | __le16 psm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | __u16 dcid; |
| 270 | __u16 scid; |
| 271 | |
| 272 | __u16 imtu; |
| 273 | __u16 omtu; |
| 274 | __u16 flush_to; |
Marcel Holtmann | c6b03cf | 2009-05-02 22:31:10 -0700 | [diff] [blame] | 275 | __u8 mode; |
Gustavo F. Padovan | f2fcfcd | 2009-07-04 15:06:24 -0300 | [diff] [blame] | 276 | __u8 num_conf_req; |
| 277 | __u8 num_conf_rsp; |
| 278 | |
Marcel Holtmann | c6b03cf | 2009-05-02 22:31:10 -0700 | [diff] [blame] | 279 | __u8 fcs; |
| 280 | __u8 sec_level; |
Marcel Holtmann | 2af6b9d | 2009-01-15 21:58:38 +0100 | [diff] [blame] | 281 | __u8 role_switch; |
Marcel Holtmann | c6b03cf | 2009-05-02 22:31:10 -0700 | [diff] [blame] | 282 | __u8 force_reliable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Marcel Holtmann | 5dee9e7 | 2007-05-24 14:27:19 +0200 | [diff] [blame] | 284 | __u8 conf_req[64]; |
| 285 | __u8 conf_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | __u8 conf_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | __u8 ident; |
| 289 | |
Gustavo F. Padovan | f2fcfcd | 2009-07-04 15:06:24 -0300 | [diff] [blame] | 290 | __u8 remote_tx_win; |
| 291 | __u8 remote_max_tx; |
| 292 | __u16 retrans_timeout; |
| 293 | __u16 monitor_timeout; |
| 294 | __u16 max_pdu_size; |
| 295 | |
Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 296 | __le16 sport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | struct l2cap_conn *conn; |
| 299 | struct sock *next_c; |
| 300 | struct sock *prev_c; |
| 301 | }; |
| 302 | |
Gustavo F. Padovan | f2fcfcd | 2009-07-04 15:06:24 -0300 | [diff] [blame] | 303 | #define L2CAP_CONF_REQ_SENT 0x01 |
| 304 | #define L2CAP_CONF_INPUT_DONE 0x02 |
| 305 | #define L2CAP_CONF_OUTPUT_DONE 0x04 |
| 306 | #define L2CAP_CONF_MTU_DONE 0x08 |
| 307 | #define L2CAP_CONF_MODE_DONE 0x10 |
| 308 | #define L2CAP_CONF_CONNECT_PEND 0x20 |
| 309 | #define L2CAP_CONF_STATE2_DEVICE 0x80 |
Marcel Holtmann | 861d688 | 2007-10-20 13:37:06 +0200 | [diff] [blame] | 310 | |
Gustavo F. Padovan | f2fcfcd | 2009-07-04 15:06:24 -0300 | [diff] [blame] | 311 | #define L2CAP_CONF_MAX_CONF_REQ 2 |
| 312 | #define L2CAP_CONF_MAX_CONF_RSP 2 |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | void l2cap_load(void); |
| 316 | |
| 317 | #endif /* __L2CAP_H */ |