| 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 */ | 
 | 29 | #define L2CAP_DEFAULT_MTU	672 | 
 | 30 | #define L2CAP_DEFAULT_FLUSH_TO	0xFFFF | 
 | 31 |  | 
| Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 32 | #define L2CAP_CONN_TIMEOUT	(40000) /* 40 seconds */ | 
 | 33 | #define L2CAP_INFO_TIMEOUT	(4000)  /*  4 seconds */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  | 
 | 35 | /* L2CAP socket address */ | 
 | 36 | struct sockaddr_l2 { | 
 | 37 | 	sa_family_t	l2_family; | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 38 | 	__le16		l2_psm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | 	bdaddr_t	l2_bdaddr; | 
| Marcel Holtmann | f29972d | 2009-02-12 05:07:45 +0100 | [diff] [blame] | 40 | 	__le16		l2_cid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | }; | 
 | 42 |  | 
 | 43 | /* L2CAP socket options */ | 
 | 44 | #define L2CAP_OPTIONS	0x01 | 
 | 45 | struct l2cap_options { | 
 | 46 | 	__u16 omtu; | 
 | 47 | 	__u16 imtu; | 
 | 48 | 	__u16 flush_to; | 
 | 49 | 	__u8  mode; | 
 | 50 | }; | 
 | 51 |  | 
 | 52 | #define L2CAP_CONNINFO	0x02 | 
 | 53 | struct l2cap_conninfo { | 
 | 54 | 	__u16 hci_handle; | 
 | 55 | 	__u8  dev_class[3]; | 
 | 56 | }; | 
 | 57 |  | 
 | 58 | #define L2CAP_LM	0x03 | 
 | 59 | #define L2CAP_LM_MASTER		0x0001 | 
 | 60 | #define L2CAP_LM_AUTH		0x0002 | 
 | 61 | #define L2CAP_LM_ENCRYPT	0x0004 | 
 | 62 | #define L2CAP_LM_TRUSTED	0x0008 | 
 | 63 | #define L2CAP_LM_RELIABLE	0x0010 | 
 | 64 | #define L2CAP_LM_SECURE		0x0020 | 
 | 65 |  | 
 | 66 | /* L2CAP command codes */ | 
 | 67 | #define L2CAP_COMMAND_REJ 0x01 | 
 | 68 | #define L2CAP_CONN_REQ    0x02 | 
 | 69 | #define L2CAP_CONN_RSP    0x03 | 
 | 70 | #define L2CAP_CONF_REQ    0x04 | 
 | 71 | #define L2CAP_CONF_RSP    0x05 | 
 | 72 | #define L2CAP_DISCONN_REQ 0x06 | 
 | 73 | #define L2CAP_DISCONN_RSP 0x07 | 
 | 74 | #define L2CAP_ECHO_REQ    0x08 | 
 | 75 | #define L2CAP_ECHO_RSP    0x09 | 
 | 76 | #define L2CAP_INFO_REQ    0x0a | 
 | 77 | #define L2CAP_INFO_RSP    0x0b | 
 | 78 |  | 
 | 79 | /* L2CAP structures */ | 
 | 80 | struct l2cap_hdr { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 81 | 	__le16     len; | 
 | 82 | 	__le16     cid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } __attribute__ ((packed)); | 
 | 84 | #define L2CAP_HDR_SIZE		4 | 
 | 85 |  | 
 | 86 | struct l2cap_cmd_hdr { | 
 | 87 | 	__u8       code; | 
 | 88 | 	__u8       ident; | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 89 | 	__le16     len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } __attribute__ ((packed)); | 
 | 91 | #define L2CAP_CMD_HDR_SIZE	4 | 
 | 92 |  | 
 | 93 | struct l2cap_cmd_rej { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 94 | 	__le16     reason; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } __attribute__ ((packed)); | 
 | 96 |  | 
 | 97 | struct l2cap_conn_req { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 98 | 	__le16     psm; | 
 | 99 | 	__le16     scid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } __attribute__ ((packed)); | 
 | 101 |  | 
 | 102 | struct l2cap_conn_rsp { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 103 | 	__le16     dcid; | 
 | 104 | 	__le16     scid; | 
 | 105 | 	__le16     result; | 
 | 106 | 	__le16     status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } __attribute__ ((packed)); | 
 | 108 |  | 
 | 109 | /* connect result */ | 
 | 110 | #define L2CAP_CR_SUCCESS    0x0000 | 
 | 111 | #define L2CAP_CR_PEND       0x0001 | 
 | 112 | #define L2CAP_CR_BAD_PSM    0x0002 | 
 | 113 | #define L2CAP_CR_SEC_BLOCK  0x0003 | 
 | 114 | #define L2CAP_CR_NO_MEM     0x0004 | 
 | 115 |  | 
 | 116 | /* connect status */ | 
 | 117 | #define L2CAP_CS_NO_INFO      0x0000 | 
 | 118 | #define L2CAP_CS_AUTHEN_PEND  0x0001 | 
 | 119 | #define L2CAP_CS_AUTHOR_PEND  0x0002 | 
 | 120 |  | 
 | 121 | struct l2cap_conf_req { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 122 | 	__le16     dcid; | 
 | 123 | 	__le16     flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | 	__u8       data[0]; | 
 | 125 | } __attribute__ ((packed)); | 
 | 126 |  | 
 | 127 | struct l2cap_conf_rsp { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 128 | 	__le16     scid; | 
 | 129 | 	__le16     flags; | 
 | 130 | 	__le16     result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | 	__u8       data[0]; | 
 | 132 | } __attribute__ ((packed)); | 
 | 133 |  | 
| Marcel Holtmann | 5dee9e7 | 2007-05-24 14:27:19 +0200 | [diff] [blame] | 134 | #define L2CAP_CONF_SUCCESS	0x0000 | 
 | 135 | #define L2CAP_CONF_UNACCEPT	0x0001 | 
 | 136 | #define L2CAP_CONF_REJECT	0x0002 | 
 | 137 | #define L2CAP_CONF_UNKNOWN	0x0003 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |  | 
 | 139 | struct l2cap_conf_opt { | 
 | 140 | 	__u8       type; | 
 | 141 | 	__u8       len; | 
 | 142 | 	__u8       val[0]; | 
 | 143 | } __attribute__ ((packed)); | 
 | 144 | #define L2CAP_CONF_OPT_SIZE	2 | 
 | 145 |  | 
 | 146 | #define L2CAP_CONF_MTU		0x01 | 
 | 147 | #define L2CAP_CONF_FLUSH_TO	0x02 | 
 | 148 | #define L2CAP_CONF_QOS		0x03 | 
 | 149 | #define L2CAP_CONF_RFC		0x04 | 
 | 150 |  | 
 | 151 | #define L2CAP_CONF_MAX_SIZE	22 | 
 | 152 |  | 
| Marcel Holtmann | 6464f35 | 2007-10-20 13:39:51 +0200 | [diff] [blame] | 153 | struct l2cap_conf_rfc { | 
 | 154 | 	__u8       mode; | 
 | 155 | 	__u8       txwin_size; | 
 | 156 | 	__u8       max_transmit; | 
 | 157 | 	__le16     retrans_timeout; | 
 | 158 | 	__le16     monitor_timeout; | 
 | 159 | 	__le16     max_pdu_size; | 
 | 160 | } __attribute__ ((packed)); | 
 | 161 |  | 
 | 162 | #define L2CAP_MODE_BASIC	0x00 | 
 | 163 | #define L2CAP_MODE_RETRANS	0x01 | 
 | 164 | #define L2CAP_MODE_FLOWCTL	0x02 | 
 | 165 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | struct l2cap_disconn_req { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 167 | 	__le16     dcid; | 
 | 168 | 	__le16     scid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } __attribute__ ((packed)); | 
 | 170 |  | 
 | 171 | struct l2cap_disconn_rsp { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 172 | 	__le16     dcid; | 
 | 173 | 	__le16     scid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } __attribute__ ((packed)); | 
 | 175 |  | 
 | 176 | struct l2cap_info_req { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 177 | 	__le16      type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } __attribute__ ((packed)); | 
 | 179 |  | 
 | 180 | struct l2cap_info_rsp { | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 181 | 	__le16      type; | 
 | 182 | 	__le16      result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | 	__u8        data[0]; | 
 | 184 | } __attribute__ ((packed)); | 
 | 185 |  | 
 | 186 | /* info type */ | 
 | 187 | #define L2CAP_IT_CL_MTU     0x0001 | 
 | 188 | #define L2CAP_IT_FEAT_MASK  0x0002 | 
| Marcel Holtmann | e1027a7 | 2009-02-09 09:18:02 +0100 | [diff] [blame] | 189 | #define L2CAP_IT_FIXED_CHAN 0x0003 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 |  | 
 | 191 | /* info result */ | 
 | 192 | #define L2CAP_IR_SUCCESS    0x0000 | 
 | 193 | #define L2CAP_IR_NOTSUPP    0x0001 | 
 | 194 |  | 
 | 195 | /* ----- L2CAP connections ----- */ | 
 | 196 | struct l2cap_chan_list { | 
 | 197 | 	struct sock	*head; | 
 | 198 | 	rwlock_t	lock; | 
 | 199 | 	long		num; | 
 | 200 | }; | 
 | 201 |  | 
 | 202 | struct l2cap_conn { | 
 | 203 | 	struct hci_conn	*hcon; | 
 | 204 |  | 
 | 205 | 	bdaddr_t	*dst; | 
 | 206 | 	bdaddr_t	*src; | 
 | 207 |  | 
 | 208 | 	unsigned int	mtu; | 
 | 209 |  | 
| Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 210 | 	__u32		feat_mask; | 
 | 211 |  | 
 | 212 | 	__u8		info_state; | 
 | 213 | 	__u8		info_ident; | 
 | 214 |  | 
 | 215 | 	struct timer_list info_timer; | 
 | 216 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | 	spinlock_t	lock; | 
 | 218 |  | 
 | 219 | 	struct sk_buff *rx_skb; | 
 | 220 | 	__u32		rx_len; | 
 | 221 | 	__u8		rx_ident; | 
 | 222 | 	__u8		tx_ident; | 
 | 223 |  | 
| Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 224 | 	__u8		disc_reason; | 
 | 225 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | 	struct l2cap_chan_list chan_list; | 
 | 227 | }; | 
 | 228 |  | 
| Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 229 | #define L2CAP_INFO_CL_MTU_REQ_SENT	0x01 | 
| Marcel Holtmann | 984947d | 2009-02-06 23:35:19 +0100 | [diff] [blame] | 230 | #define L2CAP_INFO_FEAT_MASK_REQ_SENT	0x04 | 
 | 231 | #define L2CAP_INFO_FEAT_MASK_REQ_DONE	0x08 | 
| Marcel Holtmann | 4e8402a | 2007-10-20 13:37:56 +0200 | [diff] [blame] | 232 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* ----- L2CAP channel and socket info ----- */ | 
 | 234 | #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) | 
 | 235 |  | 
 | 236 | struct l2cap_pinfo { | 
 | 237 | 	struct bt_sock	bt; | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 238 | 	__le16		psm; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | 	__u16		dcid; | 
 | 240 | 	__u16		scid; | 
 | 241 |  | 
 | 242 | 	__u16		imtu; | 
 | 243 | 	__u16		omtu; | 
 | 244 | 	__u16		flush_to; | 
| Marcel Holtmann | 2af6b9d | 2009-01-15 21:58:38 +0100 | [diff] [blame] | 245 | 	__u8            sec_level; | 
 | 246 | 	__u8		role_switch; | 
 | 247 | 	__u8            force_reliable; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 |  | 
| Marcel Holtmann | 5dee9e7 | 2007-05-24 14:27:19 +0200 | [diff] [blame] | 249 | 	__u8		conf_req[64]; | 
 | 250 | 	__u8		conf_len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | 	__u8		conf_state; | 
 | 252 | 	__u8		conf_retry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 |  | 
 | 254 | 	__u8		ident; | 
 | 255 |  | 
| Al Viro | 8e036fc | 2007-07-29 00:16:36 -0700 | [diff] [blame] | 256 | 	__le16		sport; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 |  | 
 | 258 | 	struct l2cap_conn	*conn; | 
 | 259 | 	struct sock		*next_c; | 
 | 260 | 	struct sock		*prev_c; | 
 | 261 | }; | 
 | 262 |  | 
| Marcel Holtmann | 861d688 | 2007-10-20 13:37:06 +0200 | [diff] [blame] | 263 | #define L2CAP_CONF_REQ_SENT	0x01 | 
 | 264 | #define L2CAP_CONF_INPUT_DONE	0x02 | 
 | 265 | #define L2CAP_CONF_OUTPUT_DONE	0x04 | 
| Marcel Holtmann | 6a8d301 | 2009-02-06 23:56:36 +0100 | [diff] [blame] | 266 | #define L2CAP_CONF_CONNECT_PEND	0x80 | 
| Marcel Holtmann | 861d688 | 2007-10-20 13:37:06 +0200 | [diff] [blame] | 267 |  | 
 | 268 | #define L2CAP_CONF_MAX_RETRIES	2 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 |  | 
 | 270 | void l2cap_load(void); | 
 | 271 |  | 
 | 272 | #endif /* __L2CAP_H */ |