11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds BlueZ - Bluetooth protocol stack for Linux 31da177e4SLinus Torvalds Copyright (C) 2000-2001 Qualcomm Incorporated 4ce5706bdSGustavo F. Padovan Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org> 55d8868ffSGustavo F. Padovan Copyright (C) 2010 Google Inc. 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds This program is free software; you can redistribute it and/or modify 101da177e4SLinus Torvalds it under the terms of the GNU General Public License version 2 as 111da177e4SLinus Torvalds published by the Free Software Foundation; 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 141da177e4SLinus Torvalds OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 151da177e4SLinus Torvalds FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 161da177e4SLinus Torvalds IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 171da177e4SLinus Torvalds CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 181da177e4SLinus Torvalds WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 191da177e4SLinus Torvalds ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 201da177e4SLinus Torvalds OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 231da177e4SLinus Torvalds COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 241da177e4SLinus Torvalds SOFTWARE IS DISCLAIMED. 251da177e4SLinus Torvalds */ 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #ifndef __L2CAP_H 281da177e4SLinus Torvalds #define __L2CAP_H 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds /* L2CAP defaults */ 311da177e4SLinus Torvalds #define L2CAP_DEFAULT_MTU 672 32f2fcfcd6SGustavo F. Padovan #define L2CAP_DEFAULT_MIN_MTU 48 3347ec1dcdSMarcel Holtmann #define L2CAP_DEFAULT_FLUSH_TO 0xffff 341c2acffbSGustavo F. Padovan #define L2CAP_DEFAULT_TX_WINDOW 63 35e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX 3 36fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ 37e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 38db12d647SMat Martineau #define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */ 39c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO 200 40b62f328bSVille Tervo #define L2CAP_LE_DEFAULT_MTU 23 411da177e4SLinus Torvalds 424e8402a3SMarcel Holtmann #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ 434e8402a3SMarcel Holtmann #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds /* L2CAP socket address */ 461da177e4SLinus Torvalds struct sockaddr_l2 { 471da177e4SLinus Torvalds sa_family_t l2_family; 488e036fc3SAl Viro __le16 l2_psm; 491da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 50f29972deSMarcel Holtmann __le16 l2_cid; 511da177e4SLinus Torvalds }; 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* L2CAP socket options */ 541da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 551da177e4SLinus Torvalds struct l2cap_options { 561da177e4SLinus Torvalds __u16 omtu; 571da177e4SLinus Torvalds __u16 imtu; 581da177e4SLinus Torvalds __u16 flush_to; 591da177e4SLinus Torvalds __u8 mode; 60fcc203c3SGustavo F. Padovan __u8 fcs; 6168d7f0ceSGustavo F. Padovan __u8 max_tx; 6214b5aa71SGustavo F. Padovan __u16 txwin_size; 631da177e4SLinus Torvalds }; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 661da177e4SLinus Torvalds struct l2cap_conninfo { 671da177e4SLinus Torvalds __u16 hci_handle; 681da177e4SLinus Torvalds __u8 dev_class[3]; 691da177e4SLinus Torvalds }; 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds #define L2CAP_LM 0x03 721da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 731da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 741da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 751da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 761da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 771da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* L2CAP command codes */ 801da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 811da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 821da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 831da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 841da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 851da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 861da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 871da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 881da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 891da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 901da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 913300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 923300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 931da177e4SLinus Torvalds 94a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 9547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 9647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 97a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 9847ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 9947ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 10047ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 101a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 10247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 103a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 104a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 10547ec1dcdSMarcel Holtmann 10647ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 10747ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 10847ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 10947ec1dcdSMarcel Holtmann 1101c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1111c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1121c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1131c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 1141c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1151c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1161c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1171c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SUPERVISE 0x000C 1181c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1191c2acffbSGustavo F. Padovan 1201c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 1211c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1228f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1231c2acffbSGustavo F. Padovan 1241c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 1251c2acffbSGustavo F. Padovan #define L2CAP_SUPER_RCV_READY 0x0000 1261c2acffbSGustavo F. Padovan #define L2CAP_SUPER_REJECT 0x0004 1271c2acffbSGustavo F. Padovan #define L2CAP_SUPER_RCV_NOT_READY 0x0008 1281c2acffbSGustavo F. Padovan #define L2CAP_SUPER_SELECT_REJECT 0x000C 1291c2acffbSGustavo F. Padovan 1301c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1311c2acffbSGustavo F. Padovan #define L2CAP_SDU_UNSEGMENTED 0x0000 1321c2acffbSGustavo F. Padovan #define L2CAP_SDU_START 0x4000 1331c2acffbSGustavo F. Padovan #define L2CAP_SDU_END 0x8000 1341c2acffbSGustavo F. Padovan #define L2CAP_SDU_CONTINUE 0xC000 1351c2acffbSGustavo F. Padovan 136e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 137e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 138e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 139e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 140e2fd318eSIlia Kolomisnky 141e2fd318eSIlia Kolomisnky 1421da177e4SLinus Torvalds /* L2CAP structures */ 1431da177e4SLinus Torvalds struct l2cap_hdr { 1448e036fc3SAl Viro __le16 len; 1458e036fc3SAl Viro __le16 cid; 14666c853ccSGustavo F. Padovan } __packed; 1471da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds struct l2cap_cmd_hdr { 1501da177e4SLinus Torvalds __u8 code; 1511da177e4SLinus Torvalds __u8 ident; 1528e036fc3SAl Viro __le16 len; 15366c853ccSGustavo F. Padovan } __packed; 1541da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 1551da177e4SLinus Torvalds 156e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 1578e036fc3SAl Viro __le16 reason; 15866c853ccSGustavo F. Padovan } __packed; 1591da177e4SLinus Torvalds 160e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 161e2fd318eSIlia Kolomisnky __le16 reason; 162e2fd318eSIlia Kolomisnky __le16 max_mtu; 163e2fd318eSIlia Kolomisnky } __packed; 164e2fd318eSIlia Kolomisnky 165e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 166e2fd318eSIlia Kolomisnky __le16 reason; 167e2fd318eSIlia Kolomisnky __le16 scid; 168e2fd318eSIlia Kolomisnky __le16 dcid; 169e2fd318eSIlia Kolomisnky } __packed; 170e2fd318eSIlia Kolomisnky 1711da177e4SLinus Torvalds struct l2cap_conn_req { 1728e036fc3SAl Viro __le16 psm; 1738e036fc3SAl Viro __le16 scid; 17466c853ccSGustavo F. Padovan } __packed; 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds struct l2cap_conn_rsp { 1778e036fc3SAl Viro __le16 dcid; 1788e036fc3SAl Viro __le16 scid; 1798e036fc3SAl Viro __le16 result; 1808e036fc3SAl Viro __le16 status; 18166c853ccSGustavo F. Padovan } __packed; 1821da177e4SLinus Torvalds 1838db4dc46SGustavo F. Padovan /* channel indentifier */ 1848db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 1858db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 186acd7d370SVille Tervo #define L2CAP_CID_LE_DATA 0x0004 187acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 188acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 1898db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 1908db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 1918db4dc46SGustavo F. Padovan 1921da177e4SLinus Torvalds /* connect result */ 1931da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 1941da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 1951da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 1961da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 1971da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds /* connect status */ 2001da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2011da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2021da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds struct l2cap_conf_req { 2058e036fc3SAl Viro __le16 dcid; 2068e036fc3SAl Viro __le16 flags; 2071da177e4SLinus Torvalds __u8 data[0]; 20866c853ccSGustavo F. Padovan } __packed; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds struct l2cap_conf_rsp { 2118e036fc3SAl Viro __le16 scid; 2128e036fc3SAl Viro __le16 flags; 2138e036fc3SAl Viro __le16 result; 2141da177e4SLinus Torvalds __u8 data[0]; 21566c853ccSGustavo F. Padovan } __packed; 2161da177e4SLinus Torvalds 2175dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2185dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2195dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2205dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds struct l2cap_conf_opt { 2231da177e4SLinus Torvalds __u8 type; 2241da177e4SLinus Torvalds __u8 len; 2251da177e4SLinus Torvalds __u8 val[0]; 22666c853ccSGustavo F. Padovan } __packed; 2271da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2281da177e4SLinus Torvalds 229589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 23047ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 231589d2746SGustavo F. Padovan 2321da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2331da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 2341da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 2351da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 23647ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 2391da177e4SLinus Torvalds 2406464f35fSMarcel Holtmann struct l2cap_conf_rfc { 2416464f35fSMarcel Holtmann __u8 mode; 2426464f35fSMarcel Holtmann __u8 txwin_size; 2436464f35fSMarcel Holtmann __u8 max_transmit; 2446464f35fSMarcel Holtmann __le16 retrans_timeout; 2456464f35fSMarcel Holtmann __le16 monitor_timeout; 2466464f35fSMarcel Holtmann __le16 max_pdu_size; 24766c853ccSGustavo F. Padovan } __packed; 2486464f35fSMarcel Holtmann 2496464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 2506464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 2516464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 25247ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 253c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 2546464f35fSMarcel Holtmann 2551da177e4SLinus Torvalds struct l2cap_disconn_req { 2568e036fc3SAl Viro __le16 dcid; 2578e036fc3SAl Viro __le16 scid; 25866c853ccSGustavo F. Padovan } __packed; 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds struct l2cap_disconn_rsp { 2618e036fc3SAl Viro __le16 dcid; 2628e036fc3SAl Viro __le16 scid; 26366c853ccSGustavo F. Padovan } __packed; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds struct l2cap_info_req { 2668e036fc3SAl Viro __le16 type; 26766c853ccSGustavo F. Padovan } __packed; 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds struct l2cap_info_rsp { 2708e036fc3SAl Viro __le16 type; 2718e036fc3SAl Viro __le16 result; 2721da177e4SLinus Torvalds __u8 data[0]; 27366c853ccSGustavo F. Padovan } __packed; 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds /* info type */ 2761da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 2771da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 278e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds /* info result */ 2811da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 2821da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 2831da177e4SLinus Torvalds 284de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 285de73115aSClaudio Takahasi __le16 min; 286de73115aSClaudio Takahasi __le16 max; 287de73115aSClaudio Takahasi __le16 latency; 288de73115aSClaudio Takahasi __le16 to_multiplier; 289de73115aSClaudio Takahasi } __packed; 290de73115aSClaudio Takahasi 291de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 292de73115aSClaudio Takahasi __le16 result; 293de73115aSClaudio Takahasi } __packed; 294de73115aSClaudio Takahasi 295de73115aSClaudio Takahasi /* Connection Parameters result */ 296de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 297de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 298de73115aSClaudio Takahasi 29948454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 30039d5a3eeSGustavo F. Padovan struct srej_list { 30139d5a3eeSGustavo F. Padovan __u8 tx_seq; 30239d5a3eeSGustavo F. Padovan struct list_head list; 30339d5a3eeSGustavo F. Padovan }; 30439d5a3eeSGustavo F. Padovan 30548454079SGustavo F. Padovan struct l2cap_chan { 30648454079SGustavo F. Padovan struct sock *sk; 3078c1d787bSGustavo F. Padovan 3088c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 3098c1d787bSGustavo F. Padovan 31089bc500eSGustavo F. Padovan __u8 state; 31189bc500eSGustavo F. Padovan 31271ba0e56SGustavo F. Padovan atomic_t refcnt; 31371ba0e56SGustavo F. Padovan 314fe4128e0SGustavo F. Padovan __le16 psm; 315fe4128e0SGustavo F. Padovan __u16 dcid; 316fe4128e0SGustavo F. Padovan __u16 scid; 3174343478fSGustavo F. Padovan 3180c1bc5c6SGustavo F. Padovan __u16 imtu; 3190c1bc5c6SGustavo F. Padovan __u16 omtu; 3200c1bc5c6SGustavo F. Padovan __u16 flush_to; 3210c1bc5c6SGustavo F. Padovan __u8 mode; 322715ec005SGustavo F. Padovan __u8 chan_type; 3230c1bc5c6SGustavo F. Padovan 3240c1bc5c6SGustavo F. Padovan __le16 sport; 3250c1bc5c6SGustavo F. Padovan 3264343478fSGustavo F. Padovan __u8 sec_level; 3274343478fSGustavo F. Padovan __u8 role_switch; 3284343478fSGustavo F. Padovan __u8 force_reliable; 32914b12d0bSJaikumar Ganesh __u8 force_active; 3304343478fSGustavo F. Padovan 331fc7f8a7eSGustavo F. Padovan __u8 ident; 332fc7f8a7eSGustavo F. Padovan 33373ffa904SGustavo F. Padovan __u8 conf_req[64]; 33473ffa904SGustavo F. Padovan __u8 conf_len; 33573ffa904SGustavo F. Padovan __u8 num_conf_req; 33673ffa904SGustavo F. Padovan __u8 num_conf_rsp; 33773ffa904SGustavo F. Padovan 33847d1ec61SGustavo F. Padovan __u8 fcs; 33947d1ec61SGustavo F. Padovan 34047d1ec61SGustavo F. Padovan __u8 tx_win; 34147d1ec61SGustavo F. Padovan __u8 max_tx; 34247d1ec61SGustavo F. Padovan __u16 retrans_timeout; 34347d1ec61SGustavo F. Padovan __u16 monitor_timeout; 34447d1ec61SGustavo F. Padovan __u16 mps; 34547d1ec61SGustavo F. Padovan 346c1360a1cSGustavo F. Padovan unsigned long conf_state; 347e2ab4353SGustavo F. Padovan unsigned long conn_state; 348*d57b0e8bSAndrei Emeltchenko unsigned long flags; 349525cd185SGustavo F. Padovan 35042e5c802SGustavo F. Padovan __u8 next_tx_seq; 35142e5c802SGustavo F. Padovan __u8 expected_ack_seq; 35242e5c802SGustavo F. Padovan __u8 expected_tx_seq; 35342e5c802SGustavo F. Padovan __u8 buffer_seq; 35442e5c802SGustavo F. Padovan __u8 buffer_seq_srej; 3556a026610SGustavo F. Padovan __u8 srej_save_reqseq; 3566a026610SGustavo F. Padovan __u8 frames_sent; 3576a026610SGustavo F. Padovan __u8 unacked_frames; 3586a026610SGustavo F. Padovan __u8 retry_count; 3596a026610SGustavo F. Padovan __u8 num_acked; 3606f61fd47SGustavo F. Padovan __u16 sdu_len; 3616f61fd47SGustavo F. Padovan struct sk_buff *sdu; 36284084a31SMat Martineau struct sk_buff *sdu_last_frag; 3636f61fd47SGustavo F. Padovan 3642c03a7a4SGustavo F. Padovan __u8 remote_tx_win; 3652c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 3662c03a7a4SGustavo F. Padovan __u16 remote_mps; 36742e5c802SGustavo F. Padovan 368ab07801dSGustavo F. Padovan struct timer_list chan_timer; 369e92c8e70SGustavo F. Padovan struct timer_list retrans_timer; 370e92c8e70SGustavo F. Padovan struct timer_list monitor_timer; 371e92c8e70SGustavo F. Padovan struct timer_list ack_timer; 37258d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 37358d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 374f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 37539d5a3eeSGustavo F. Padovan struct list_head srej_l; 376e92c8e70SGustavo F. Padovan 377baa7e1faSGustavo F. Padovan struct list_head list; 37823691d75SGustavo F. Padovan struct list_head global_l; 37980808e43SGustavo F. Padovan 38080808e43SGustavo F. Padovan void *data; 38180808e43SGustavo F. Padovan struct l2cap_ops *ops; 38280808e43SGustavo F. Padovan }; 38380808e43SGustavo F. Padovan 38480808e43SGustavo F. Padovan struct l2cap_ops { 38580808e43SGustavo F. Padovan char *name; 38680808e43SGustavo F. Padovan 38780808e43SGustavo F. Padovan struct l2cap_chan *(*new_connection) (void *data); 38823070494SGustavo F. Padovan int (*recv) (void *data, struct sk_buff *skb); 389ba3bd0eeSGustavo F. Padovan void (*close) (void *data); 39089bc500eSGustavo F. Padovan void (*state_change) (void *data, int state); 3911da177e4SLinus Torvalds }; 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds struct l2cap_conn { 3941da177e4SLinus Torvalds struct hci_conn *hcon; 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds bdaddr_t *dst; 3971da177e4SLinus Torvalds bdaddr_t *src; 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvalds unsigned int mtu; 4001da177e4SLinus Torvalds 4014e8402a3SMarcel Holtmann __u32 feat_mask; 4024e8402a3SMarcel Holtmann 4034e8402a3SMarcel Holtmann __u8 info_state; 4044e8402a3SMarcel Holtmann __u8 info_ident; 4054e8402a3SMarcel Holtmann 4064e8402a3SMarcel Holtmann struct timer_list info_timer; 4074e8402a3SMarcel Holtmann 4081da177e4SLinus Torvalds spinlock_t lock; 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds struct sk_buff *rx_skb; 4111da177e4SLinus Torvalds __u32 rx_len; 4121da177e4SLinus Torvalds __u8 tx_ident; 4131da177e4SLinus Torvalds 4142950f21aSMarcel Holtmann __u8 disc_reason; 4152950f21aSMarcel Holtmann 4165d3de7dfSVinicius Costa Gomes struct timer_list security_timer; 4171c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 4185d3de7dfSVinicius Costa Gomes 419baa7e1faSGustavo F. Padovan struct list_head chan_l; 420baa7e1faSGustavo F. Padovan rwlock_t chan_lock; 4211da177e4SLinus Torvalds }; 4221da177e4SLinus Torvalds 4234e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 424984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 425984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 4264e8402a3SMarcel Holtmann 427715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 428715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 429715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 430715ec005SGustavo F. Padovan 43148454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 4321da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds struct l2cap_pinfo { 4351da177e4SLinus Torvalds struct bt_sock bt; 43648454079SGustavo F. Padovan struct l2cap_chan *chan; 437e328140fSMat Martineau struct sk_buff *rx_busy_skb; 4381da177e4SLinus Torvalds }; 4391da177e4SLinus Torvalds 440c1360a1cSGustavo F. Padovan enum { 441c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 442c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 443c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 444c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 445c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 446c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 447c1360a1cSGustavo F. Padovan CONF_NO_FCS_RECV, 448c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 449c1360a1cSGustavo F. Padovan }; 450861d6882SMarcel Holtmann 451f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 452f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 453f2fcfcd6SGustavo F. Padovan 454e2ab4353SGustavo F. Padovan enum { 455e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 456e2ab4353SGustavo F. Padovan CONN_WAIT_F, 457e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 458e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 459e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 460e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 461e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 462e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 463e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 464e2ab4353SGustavo F. Padovan }; 465e90bac06SGustavo F. Padovan 466*d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 467*d57b0e8bSAndrei Emeltchenko enum { 468*d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 469*d57b0e8bSAndrei Emeltchenko }; 470*d57b0e8bSAndrei Emeltchenko 471c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 472c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 4731a09bcb9SGustavo F. Padovan #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \ 4741a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_RETRANS_TO); 4751a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 4761a09bcb9SGustavo F. Padovan #define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \ 4771a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_MONITOR_TO); 4781a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 4791a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 4801a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_ACK_TO); 4811a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 482c74e560cSGustavo F. Padovan 48342e5c802SGustavo F. Padovan static inline int l2cap_tx_window_full(struct l2cap_chan *ch) 4841c2acffbSGustavo F. Padovan { 4851c2acffbSGustavo F. Padovan int sub; 4861c2acffbSGustavo F. Padovan 48742e5c802SGustavo F. Padovan sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; 4881c2acffbSGustavo F. Padovan 4891c2acffbSGustavo F. Padovan if (sub < 0) 4901c2acffbSGustavo F. Padovan sub += 64; 4911c2acffbSGustavo F. Padovan 4922c03a7a4SGustavo F. Padovan return sub == ch->remote_tx_win; 4931c2acffbSGustavo F. Padovan } 4941c2acffbSGustavo F. Padovan 495894718a6SAndrei Emeltchenko #define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1) 496894718a6SAndrei Emeltchenko #define __get_reqseq(ctrl) (((ctrl) & L2CAP_CTRL_REQSEQ) >> 8) 497894718a6SAndrei Emeltchenko #define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE)) 498894718a6SAndrei Emeltchenko #define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE) 499894718a6SAndrei Emeltchenko #define __is_sar_start(ctrl) (((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START) 5001da177e4SLinus Torvalds 501bb58f747SGustavo F. Padovan extern int disable_ertm; 502bb58f747SGustavo F. Padovan 503bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 504bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 505bb58f747SGustavo F. Padovan 5068c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 507dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 50868983259SGustavo F. Padovan 5099e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 5109e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 5119e4425ffSGustavo F. Padovan 51223691d75SGustavo F. Padovan struct l2cap_chan *l2cap_chan_create(struct sock *sk); 5130f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 51423691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan); 51577a74c7eSGustavo F. Padovan int l2cap_chan_connect(struct l2cap_chan *chan); 5169a91a04aSGustavo F. Padovan int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 517e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 518bb58f747SGustavo F. Padovan 5191da177e4SLinus Torvalds #endif /* __L2CAP_H */ 520