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 356327eb98SAndrei Emeltchenko #define L2CAP_DEFAULT_EXT_WINDOW 0x3FFF 36e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX 3 37fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ 38e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 39db12d647SMat Martineau #define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */ 40c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO 200 41b62f328bSVille Tervo #define L2CAP_LE_DEFAULT_MTU 23 421da177e4SLinus Torvalds 434e8402a3SMarcel Holtmann #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ 444e8402a3SMarcel Holtmann #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds /* L2CAP socket address */ 471da177e4SLinus Torvalds struct sockaddr_l2 { 481da177e4SLinus Torvalds sa_family_t l2_family; 498e036fc3SAl Viro __le16 l2_psm; 501da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 51f29972deSMarcel Holtmann __le16 l2_cid; 521da177e4SLinus Torvalds }; 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds /* L2CAP socket options */ 551da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 561da177e4SLinus Torvalds struct l2cap_options { 571da177e4SLinus Torvalds __u16 omtu; 581da177e4SLinus Torvalds __u16 imtu; 591da177e4SLinus Torvalds __u16 flush_to; 601da177e4SLinus Torvalds __u8 mode; 61fcc203c3SGustavo F. Padovan __u8 fcs; 6268d7f0ceSGustavo F. Padovan __u8 max_tx; 6314b5aa71SGustavo F. Padovan __u16 txwin_size; 641da177e4SLinus Torvalds }; 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 671da177e4SLinus Torvalds struct l2cap_conninfo { 681da177e4SLinus Torvalds __u16 hci_handle; 691da177e4SLinus Torvalds __u8 dev_class[3]; 701da177e4SLinus Torvalds }; 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds #define L2CAP_LM 0x03 731da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 741da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 751da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 761da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 771da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 781da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds /* L2CAP command codes */ 811da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 821da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 831da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 841da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 851da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 861da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 871da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 881da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 891da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 901da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 911da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 923300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 933300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 941da177e4SLinus Torvalds 95a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 9647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 9747ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 98a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 9947ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 10047ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 10147ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 102a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 10347ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 104a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 105a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 10647ec1dcdSMarcel Holtmann 10747ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 10847ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 10947ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 11047ec1dcdSMarcel Holtmann 1111c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1121c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1131c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1141c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 11557253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 11657253fd8SAndrei Emeltchenko 1171c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1181c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1191c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1201c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1211c2acffbSGustavo F. Padovan 1221c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 12357253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 1241c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1258f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1261c2acffbSGustavo F. Padovan 12757253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 12857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 12957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 13057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 13157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 13257253fd8SAndrei Emeltchenko 13357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 13457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 13557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 13657253fd8SAndrei Emeltchenko 13757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 13857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 13957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 14057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 14157253fd8SAndrei Emeltchenko 1421c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 143ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 144ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 145ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 146ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1471c2acffbSGustavo F. Padovan 1481c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1497e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1507e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1517e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1527e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1531c2acffbSGustavo F. Padovan 154e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 155e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 156e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 157e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 158e2fd318eSIlia Kolomisnky 1591da177e4SLinus Torvalds /* L2CAP structures */ 1601da177e4SLinus Torvalds struct l2cap_hdr { 1618e036fc3SAl Viro __le16 len; 1628e036fc3SAl Viro __le16 cid; 16366c853ccSGustavo F. Padovan } __packed; 1641da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds struct l2cap_cmd_hdr { 1671da177e4SLinus Torvalds __u8 code; 1681da177e4SLinus Torvalds __u8 ident; 1698e036fc3SAl Viro __le16 len; 17066c853ccSGustavo F. Padovan } __packed; 1711da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 1721da177e4SLinus Torvalds 173e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 1748e036fc3SAl Viro __le16 reason; 17566c853ccSGustavo F. Padovan } __packed; 1761da177e4SLinus Torvalds 177e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 178e2fd318eSIlia Kolomisnky __le16 reason; 179e2fd318eSIlia Kolomisnky __le16 max_mtu; 180e2fd318eSIlia Kolomisnky } __packed; 181e2fd318eSIlia Kolomisnky 182e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 183e2fd318eSIlia Kolomisnky __le16 reason; 184e2fd318eSIlia Kolomisnky __le16 scid; 185e2fd318eSIlia Kolomisnky __le16 dcid; 186e2fd318eSIlia Kolomisnky } __packed; 187e2fd318eSIlia Kolomisnky 1881da177e4SLinus Torvalds struct l2cap_conn_req { 1898e036fc3SAl Viro __le16 psm; 1908e036fc3SAl Viro __le16 scid; 19166c853ccSGustavo F. Padovan } __packed; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds struct l2cap_conn_rsp { 1948e036fc3SAl Viro __le16 dcid; 1958e036fc3SAl Viro __le16 scid; 1968e036fc3SAl Viro __le16 result; 1978e036fc3SAl Viro __le16 status; 19866c853ccSGustavo F. Padovan } __packed; 1991da177e4SLinus Torvalds 2008db4dc46SGustavo F. Padovan /* channel indentifier */ 2018db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2028db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 203acd7d370SVille Tervo #define L2CAP_CID_LE_DATA 0x0004 204acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 205acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2068db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2078db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 2088db4dc46SGustavo F. Padovan 2091da177e4SLinus Torvalds /* connect result */ 2101da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2111da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2121da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2131da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2141da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds /* connect status */ 2171da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2181da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2191da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2201da177e4SLinus Torvalds 2211da177e4SLinus Torvalds struct l2cap_conf_req { 2228e036fc3SAl Viro __le16 dcid; 2238e036fc3SAl Viro __le16 flags; 2241da177e4SLinus Torvalds __u8 data[0]; 22566c853ccSGustavo F. Padovan } __packed; 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds struct l2cap_conf_rsp { 2288e036fc3SAl Viro __le16 scid; 2298e036fc3SAl Viro __le16 flags; 2308e036fc3SAl Viro __le16 result; 2311da177e4SLinus Torvalds __u8 data[0]; 23266c853ccSGustavo F. Padovan } __packed; 2331da177e4SLinus Torvalds 2345dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2355dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2365dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2375dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds struct l2cap_conf_opt { 2401da177e4SLinus Torvalds __u8 type; 2411da177e4SLinus Torvalds __u8 len; 2421da177e4SLinus Torvalds __u8 val[0]; 24366c853ccSGustavo F. Padovan } __packed; 2441da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2451da177e4SLinus Torvalds 246589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 24747ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 248589d2746SGustavo F. Padovan 2491da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2501da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 2511da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 2521da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 25347ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 2546327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 2571da177e4SLinus Torvalds 2586464f35fSMarcel Holtmann struct l2cap_conf_rfc { 2596464f35fSMarcel Holtmann __u8 mode; 2606464f35fSMarcel Holtmann __u8 txwin_size; 2616464f35fSMarcel Holtmann __u8 max_transmit; 2626464f35fSMarcel Holtmann __le16 retrans_timeout; 2636464f35fSMarcel Holtmann __le16 monitor_timeout; 2646464f35fSMarcel Holtmann __le16 max_pdu_size; 26566c853ccSGustavo F. Padovan } __packed; 2666464f35fSMarcel Holtmann 2676464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 2686464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 2696464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 27047ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 271c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 2726464f35fSMarcel Holtmann 2731da177e4SLinus Torvalds struct l2cap_disconn_req { 2748e036fc3SAl Viro __le16 dcid; 2758e036fc3SAl Viro __le16 scid; 27666c853ccSGustavo F. Padovan } __packed; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds struct l2cap_disconn_rsp { 2798e036fc3SAl Viro __le16 dcid; 2808e036fc3SAl Viro __le16 scid; 28166c853ccSGustavo F. Padovan } __packed; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds struct l2cap_info_req { 2848e036fc3SAl Viro __le16 type; 28566c853ccSGustavo F. Padovan } __packed; 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds struct l2cap_info_rsp { 2888e036fc3SAl Viro __le16 type; 2898e036fc3SAl Viro __le16 result; 2901da177e4SLinus Torvalds __u8 data[0]; 29166c853ccSGustavo F. Padovan } __packed; 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds /* info type */ 2941da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 2951da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 296e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds /* info result */ 2991da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 3001da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 3011da177e4SLinus Torvalds 302de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 303de73115aSClaudio Takahasi __le16 min; 304de73115aSClaudio Takahasi __le16 max; 305de73115aSClaudio Takahasi __le16 latency; 306de73115aSClaudio Takahasi __le16 to_multiplier; 307de73115aSClaudio Takahasi } __packed; 308de73115aSClaudio Takahasi 309de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 310de73115aSClaudio Takahasi __le16 result; 311de73115aSClaudio Takahasi } __packed; 312de73115aSClaudio Takahasi 313de73115aSClaudio Takahasi /* Connection Parameters result */ 314de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 315de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 316de73115aSClaudio Takahasi 31748454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 31839d5a3eeSGustavo F. Padovan struct srej_list { 31939d5a3eeSGustavo F. Padovan __u8 tx_seq; 32039d5a3eeSGustavo F. Padovan struct list_head list; 32139d5a3eeSGustavo F. Padovan }; 32239d5a3eeSGustavo F. Padovan 32348454079SGustavo F. Padovan struct l2cap_chan { 32448454079SGustavo F. Padovan struct sock *sk; 3258c1d787bSGustavo F. Padovan 3268c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 3278c1d787bSGustavo F. Padovan 32889bc500eSGustavo F. Padovan __u8 state; 32989bc500eSGustavo F. Padovan 33071ba0e56SGustavo F. Padovan atomic_t refcnt; 33171ba0e56SGustavo F. Padovan 332fe4128e0SGustavo F. Padovan __le16 psm; 333fe4128e0SGustavo F. Padovan __u16 dcid; 334fe4128e0SGustavo F. Padovan __u16 scid; 3354343478fSGustavo F. Padovan 3360c1bc5c6SGustavo F. Padovan __u16 imtu; 3370c1bc5c6SGustavo F. Padovan __u16 omtu; 3380c1bc5c6SGustavo F. Padovan __u16 flush_to; 3390c1bc5c6SGustavo F. Padovan __u8 mode; 340715ec005SGustavo F. Padovan __u8 chan_type; 3410c1bc5c6SGustavo F. Padovan 3420c1bc5c6SGustavo F. Padovan __le16 sport; 3430c1bc5c6SGustavo F. Padovan 3444343478fSGustavo F. Padovan __u8 sec_level; 3454343478fSGustavo F. Padovan 346fc7f8a7eSGustavo F. Padovan __u8 ident; 347fc7f8a7eSGustavo F. Padovan 34873ffa904SGustavo F. Padovan __u8 conf_req[64]; 34973ffa904SGustavo F. Padovan __u8 conf_len; 35073ffa904SGustavo F. Padovan __u8 num_conf_req; 35173ffa904SGustavo F. Padovan __u8 num_conf_rsp; 35273ffa904SGustavo F. Padovan 35347d1ec61SGustavo F. Padovan __u8 fcs; 35447d1ec61SGustavo F. Padovan 3556327eb98SAndrei Emeltchenko __u16 tx_win; 35647d1ec61SGustavo F. Padovan __u8 max_tx; 35747d1ec61SGustavo F. Padovan __u16 retrans_timeout; 35847d1ec61SGustavo F. Padovan __u16 monitor_timeout; 35947d1ec61SGustavo F. Padovan __u16 mps; 36047d1ec61SGustavo F. Padovan 361c1360a1cSGustavo F. Padovan unsigned long conf_state; 362e2ab4353SGustavo F. Padovan unsigned long conn_state; 363d57b0e8bSAndrei Emeltchenko unsigned long flags; 364525cd185SGustavo F. Padovan 36542e5c802SGustavo F. Padovan __u8 next_tx_seq; 36642e5c802SGustavo F. Padovan __u8 expected_ack_seq; 36742e5c802SGustavo F. Padovan __u8 expected_tx_seq; 36842e5c802SGustavo F. Padovan __u8 buffer_seq_srej; 3696a026610SGustavo F. Padovan __u8 srej_save_reqseq; 3706a026610SGustavo F. Padovan __u8 frames_sent; 3716a026610SGustavo F. Padovan __u8 unacked_frames; 372*0b209faeSAndrei Emeltchenko __u16 buffer_seq; 3736a026610SGustavo F. Padovan __u8 retry_count; 3746a026610SGustavo F. Padovan __u8 num_acked; 3756f61fd47SGustavo F. Padovan __u16 sdu_len; 3766f61fd47SGustavo F. Padovan struct sk_buff *sdu; 37784084a31SMat Martineau struct sk_buff *sdu_last_frag; 3786f61fd47SGustavo F. Padovan 3796327eb98SAndrei Emeltchenko __u16 remote_tx_win; 3802c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 3812c03a7a4SGustavo F. Padovan __u16 remote_mps; 38242e5c802SGustavo F. Padovan 383ab07801dSGustavo F. Padovan struct timer_list chan_timer; 384e92c8e70SGustavo F. Padovan struct timer_list retrans_timer; 385e92c8e70SGustavo F. Padovan struct timer_list monitor_timer; 386e92c8e70SGustavo F. Padovan struct timer_list ack_timer; 38758d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 38858d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 389f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 39039d5a3eeSGustavo F. Padovan struct list_head srej_l; 391e92c8e70SGustavo F. Padovan 392baa7e1faSGustavo F. Padovan struct list_head list; 39323691d75SGustavo F. Padovan struct list_head global_l; 39480808e43SGustavo F. Padovan 39580808e43SGustavo F. Padovan void *data; 39680808e43SGustavo F. Padovan struct l2cap_ops *ops; 39780808e43SGustavo F. Padovan }; 39880808e43SGustavo F. Padovan 39980808e43SGustavo F. Padovan struct l2cap_ops { 40080808e43SGustavo F. Padovan char *name; 40180808e43SGustavo F. Padovan 40280808e43SGustavo F. Padovan struct l2cap_chan *(*new_connection) (void *data); 40323070494SGustavo F. Padovan int (*recv) (void *data, struct sk_buff *skb); 404ba3bd0eeSGustavo F. Padovan void (*close) (void *data); 40589bc500eSGustavo F. Padovan void (*state_change) (void *data, int state); 4061da177e4SLinus Torvalds }; 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds struct l2cap_conn { 4091da177e4SLinus Torvalds struct hci_conn *hcon; 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds bdaddr_t *dst; 4121da177e4SLinus Torvalds bdaddr_t *src; 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvalds unsigned int mtu; 4151da177e4SLinus Torvalds 4164e8402a3SMarcel Holtmann __u32 feat_mask; 4174e8402a3SMarcel Holtmann 4184e8402a3SMarcel Holtmann __u8 info_state; 4194e8402a3SMarcel Holtmann __u8 info_ident; 4204e8402a3SMarcel Holtmann 4214e8402a3SMarcel Holtmann struct timer_list info_timer; 4224e8402a3SMarcel Holtmann 4231da177e4SLinus Torvalds spinlock_t lock; 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds struct sk_buff *rx_skb; 4261da177e4SLinus Torvalds __u32 rx_len; 4271da177e4SLinus Torvalds __u8 tx_ident; 4281da177e4SLinus Torvalds 4292950f21aSMarcel Holtmann __u8 disc_reason; 4302950f21aSMarcel Holtmann 4315d3de7dfSVinicius Costa Gomes struct timer_list security_timer; 4321c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 4335d3de7dfSVinicius Costa Gomes 434baa7e1faSGustavo F. Padovan struct list_head chan_l; 435baa7e1faSGustavo F. Padovan rwlock_t chan_lock; 4361da177e4SLinus Torvalds }; 4371da177e4SLinus Torvalds 4384e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 439984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 440984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 4414e8402a3SMarcel Holtmann 442715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 443715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 444715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 445715ec005SGustavo F. Padovan 44648454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 4471da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds struct l2cap_pinfo { 4501da177e4SLinus Torvalds struct bt_sock bt; 45148454079SGustavo F. Padovan struct l2cap_chan *chan; 452e328140fSMat Martineau struct sk_buff *rx_busy_skb; 4531da177e4SLinus Torvalds }; 4541da177e4SLinus Torvalds 455c1360a1cSGustavo F. Padovan enum { 456c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 457c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 458c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 459c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 460c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 461c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 462c1360a1cSGustavo F. Padovan CONF_NO_FCS_RECV, 463c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 4646327eb98SAndrei Emeltchenko CONF_EWS_RECV, 465c1360a1cSGustavo F. Padovan }; 466861d6882SMarcel Holtmann 467f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 468f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 469f2fcfcd6SGustavo F. Padovan 470e2ab4353SGustavo F. Padovan enum { 471e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 472e2ab4353SGustavo F. Padovan CONN_WAIT_F, 473e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 474e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 475e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 476e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 477e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 478e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 479e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 480e2ab4353SGustavo F. Padovan }; 481e90bac06SGustavo F. Padovan 482d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 483d57b0e8bSAndrei Emeltchenko enum { 48443bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 48515770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 486ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 487d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 4886327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 489d57b0e8bSAndrei Emeltchenko }; 490d57b0e8bSAndrei Emeltchenko 491c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 492c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 4931a09bcb9SGustavo F. Padovan #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \ 4941a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_RETRANS_TO); 4951a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 4961a09bcb9SGustavo F. Padovan #define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \ 4971a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_MONITOR_TO); 4981a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 4991a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 5001a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_ACK_TO); 5011a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 502c74e560cSGustavo F. Padovan 50342e5c802SGustavo F. Padovan static inline int l2cap_tx_window_full(struct l2cap_chan *ch) 5041c2acffbSGustavo F. Padovan { 5051c2acffbSGustavo F. Padovan int sub; 5061c2acffbSGustavo F. Padovan 50742e5c802SGustavo F. Padovan sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; 5081c2acffbSGustavo F. Padovan 5091c2acffbSGustavo F. Padovan if (sub < 0) 5101c2acffbSGustavo F. Padovan sub += 64; 5111c2acffbSGustavo F. Padovan 5122c03a7a4SGustavo F. Padovan return sub == ch->remote_tx_win; 5131c2acffbSGustavo F. Padovan } 5141c2acffbSGustavo F. Padovan 515*0b209faeSAndrei Emeltchenko static inline __u16 __get_reqseq(struct l2cap_chan *chan, __u32 ctrl) 516*0b209faeSAndrei Emeltchenko { 517*0b209faeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 518*0b209faeSAndrei Emeltchenko return (ctrl & L2CAP_EXT_CTRL_REQSEQ) >> 519*0b209faeSAndrei Emeltchenko L2CAP_EXT_CTRL_REQSEQ_SHIFT; 520*0b209faeSAndrei Emeltchenko else 521*0b209faeSAndrei Emeltchenko return (ctrl & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT; 522*0b209faeSAndrei Emeltchenko } 523*0b209faeSAndrei Emeltchenko 524*0b209faeSAndrei Emeltchenko static inline __u32 __set_reqseq(struct l2cap_chan *chan, __u32 reqseq) 525*0b209faeSAndrei Emeltchenko { 526*0b209faeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 527*0b209faeSAndrei Emeltchenko return (reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT) & 528*0b209faeSAndrei Emeltchenko L2CAP_EXT_CTRL_REQSEQ; 529*0b209faeSAndrei Emeltchenko else 530*0b209faeSAndrei Emeltchenko return (reqseq << L2CAP_CTRL_REQSEQ_SHIFT) & L2CAP_CTRL_REQSEQ; 531*0b209faeSAndrei Emeltchenko } 532894718a6SAndrei Emeltchenko #define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1) 533894718a6SAndrei Emeltchenko #define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE)) 534894718a6SAndrei Emeltchenko #define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE) 5357e0ef6eeSAndrei Emeltchenko static inline __u8 __get_ctrl_sar(struct l2cap_chan *chan, __u32 ctrl) 5367e0ef6eeSAndrei Emeltchenko { 5377e0ef6eeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 5387e0ef6eeSAndrei Emeltchenko return (ctrl & L2CAP_EXT_CTRL_SAR) >> L2CAP_EXT_CTRL_SAR_SHIFT; 5397e0ef6eeSAndrei Emeltchenko else 5407e0ef6eeSAndrei Emeltchenko return (ctrl & L2CAP_CTRL_SAR) >> L2CAP_CTRL_SAR_SHIFT; 5417e0ef6eeSAndrei Emeltchenko } 5427e0ef6eeSAndrei Emeltchenko 5437e0ef6eeSAndrei Emeltchenko static inline __u32 __set_ctrl_sar(struct l2cap_chan *chan, __u32 sar) 5447e0ef6eeSAndrei Emeltchenko { 5457e0ef6eeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 5467e0ef6eeSAndrei Emeltchenko return (sar << L2CAP_EXT_CTRL_SAR_SHIFT) & L2CAP_EXT_CTRL_SAR; 5477e0ef6eeSAndrei Emeltchenko else 5487e0ef6eeSAndrei Emeltchenko return (sar << L2CAP_CTRL_SAR_SHIFT) & L2CAP_CTRL_SAR; 5497e0ef6eeSAndrei Emeltchenko } 5507e0ef6eeSAndrei Emeltchenko 5517e0ef6eeSAndrei Emeltchenko static inline bool __is_sar_start(struct l2cap_chan *chan, __u32 ctrl) 5527e0ef6eeSAndrei Emeltchenko { 5537e0ef6eeSAndrei Emeltchenko return __get_ctrl_sar(chan, ctrl) == L2CAP_SAR_START; 5547e0ef6eeSAndrei Emeltchenko } 5557e0ef6eeSAndrei Emeltchenko 5567e0ef6eeSAndrei Emeltchenko static inline __u32 __get_sar_mask(struct l2cap_chan *chan) 5577e0ef6eeSAndrei Emeltchenko { 5587e0ef6eeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 5597e0ef6eeSAndrei Emeltchenko return L2CAP_EXT_CTRL_SAR; 5607e0ef6eeSAndrei Emeltchenko else 5617e0ef6eeSAndrei Emeltchenko return L2CAP_CTRL_SAR; 5627e0ef6eeSAndrei Emeltchenko } 5631da177e4SLinus Torvalds 564ab784b73SAndrei Emeltchenko static inline __u8 __get_ctrl_super(struct l2cap_chan *chan, __u32 ctrl) 565ab784b73SAndrei Emeltchenko { 566ab784b73SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 567ab784b73SAndrei Emeltchenko return (ctrl & L2CAP_EXT_CTRL_SUPERVISE) >> 568ab784b73SAndrei Emeltchenko L2CAP_EXT_CTRL_SUPER_SHIFT; 569ab784b73SAndrei Emeltchenko else 570ab784b73SAndrei Emeltchenko return (ctrl & L2CAP_CTRL_SUPERVISE) >> L2CAP_CTRL_SUPER_SHIFT; 571ab784b73SAndrei Emeltchenko } 572ab784b73SAndrei Emeltchenko 573ab784b73SAndrei Emeltchenko static inline __u32 __set_ctrl_super(struct l2cap_chan *chan, __u32 super) 574ab784b73SAndrei Emeltchenko { 575ab784b73SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 576ab784b73SAndrei Emeltchenko return (super << L2CAP_EXT_CTRL_SUPER_SHIFT) & 577ab784b73SAndrei Emeltchenko L2CAP_EXT_CTRL_SUPERVISE; 578ab784b73SAndrei Emeltchenko else 579ab784b73SAndrei Emeltchenko return (super << L2CAP_CTRL_SUPER_SHIFT) & 580ab784b73SAndrei Emeltchenko L2CAP_CTRL_SUPERVISE; 581ab784b73SAndrei Emeltchenko } 582ab784b73SAndrei Emeltchenko 583bb58f747SGustavo F. Padovan extern int disable_ertm; 584bb58f747SGustavo F. Padovan 585bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 586bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 587bb58f747SGustavo F. Padovan 5888c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 589dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 59068983259SGustavo F. Padovan 5919e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 5929e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 5939e4425ffSGustavo F. Padovan 59423691d75SGustavo F. Padovan struct l2cap_chan *l2cap_chan_create(struct sock *sk); 5950f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 59623691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan); 59777a74c7eSGustavo F. Padovan int l2cap_chan_connect(struct l2cap_chan *chan); 5989a91a04aSGustavo F. Padovan int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 599e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 600bb58f747SGustavo F. Padovan 6011da177e4SLinus Torvalds #endif /* __L2CAP_H */ 602