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