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 3088843ab0SAndrei Emeltchenko #include <asm/unaligned.h> 3188843ab0SAndrei Emeltchenko 321da177e4SLinus Torvalds /* L2CAP defaults */ 331da177e4SLinus Torvalds #define L2CAP_DEFAULT_MTU 672 34f2fcfcd6SGustavo F. Padovan #define L2CAP_DEFAULT_MIN_MTU 48 358936fa6dSAndrei Emeltchenko #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 368936fa6dSAndrei Emeltchenko #define L2CAP_EFS_DEFAULT_FLUSH_TO 0xFFFFFFFF 371c2acffbSGustavo F. Padovan #define L2CAP_DEFAULT_TX_WINDOW 63 386327eb98SAndrei Emeltchenko #define L2CAP_DEFAULT_EXT_WINDOW 0x3FFF 39e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX 3 40fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ 41e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 420b4558e3SAndrei Emeltchenko #define L2CAP_DEFAULT_MAX_PDU_SIZE 1492 /* Sized for AMP packet */ 43c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO 200 448f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_MAX_SDU_SIZE 0xFFFF 458f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF 468f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF 4794122bbeSMat Martineau #define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */ 488c3a4f00SAndre Guedes #define L2CAP_LE_MIN_MTU 23 491da177e4SLinus Torvalds 50ba13ccd9SMarcel Holtmann #define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100) 51ba13ccd9SMarcel Holtmann #define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000) 52ba13ccd9SMarcel Holtmann #define L2CAP_ENC_TIMEOUT msecs_to_jiffies(5000) 53ba13ccd9SMarcel Holtmann #define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000) 54ba13ccd9SMarcel Holtmann #define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000) 555b155ef9SMat Martineau #define L2CAP_MOVE_TIMEOUT msecs_to_jiffies(4000) 565b155ef9SMat Martineau #define L2CAP_MOVE_ERTX_TIMEOUT msecs_to_jiffies(60000) 571da177e4SLinus Torvalds 58466f8004SAndrei Emeltchenko #define L2CAP_A2MP_DEFAULT_MTU 670 59466f8004SAndrei Emeltchenko 601da177e4SLinus Torvalds /* L2CAP socket address */ 611da177e4SLinus Torvalds struct sockaddr_l2 { 621da177e4SLinus Torvalds sa_family_t l2_family; 638e036fc3SAl Viro __le16 l2_psm; 641da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 65f29972deSMarcel Holtmann __le16 l2_cid; 6643ef0b8bSAndre Guedes __u8 l2_bdaddr_type; 671da177e4SLinus Torvalds }; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* L2CAP socket options */ 701da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 711da177e4SLinus Torvalds struct l2cap_options { 721da177e4SLinus Torvalds __u16 omtu; 731da177e4SLinus Torvalds __u16 imtu; 741da177e4SLinus Torvalds __u16 flush_to; 751da177e4SLinus Torvalds __u8 mode; 76fcc203c3SGustavo F. Padovan __u8 fcs; 7768d7f0ceSGustavo F. Padovan __u8 max_tx; 7814b5aa71SGustavo F. Padovan __u16 txwin_size; 791da177e4SLinus Torvalds }; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 821da177e4SLinus Torvalds struct l2cap_conninfo { 831da177e4SLinus Torvalds __u16 hci_handle; 841da177e4SLinus Torvalds __u8 dev_class[3]; 851da177e4SLinus Torvalds }; 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds #define L2CAP_LM 0x03 881da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 891da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 901da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 911da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 921da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 931da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* L2CAP command codes */ 961da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 971da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 981da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 991da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 1001da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 1011da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 1021da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 1031da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 1041da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 1051da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 1061da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 10738094c75SMat Martineau #define L2CAP_CREATE_CHAN_REQ 0x0c 10838094c75SMat Martineau #define L2CAP_CREATE_CHAN_RSP 0x0d 10938094c75SMat Martineau #define L2CAP_MOVE_CHAN_REQ 0x0e 11038094c75SMat Martineau #define L2CAP_MOVE_CHAN_RSP 0x0f 11138094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM 0x10 11238094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM_RSP 0x11 1133300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 1143300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 1151da177e4SLinus Torvalds 116a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 11747ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 11847ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 119a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 12047ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 12147ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 12247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 123a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 12447ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 125a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 126a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 12747ec1dcdSMarcel Holtmann 12847ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 12947ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 13047ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 13147ec1dcdSMarcel Holtmann 132d835ac0fSMat Martineau /* L2CAP fixed channels */ 133d835ac0fSMat Martineau #define L2CAP_FC_L2CAP 0x02 134d40bffbcSMarcel Holtmann #define L2CAP_FC_CONNLESS 0x04 135d835ac0fSMat Martineau #define L2CAP_FC_A2MP 0x08 136d835ac0fSMat Martineau 1371c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1381c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1391c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1401c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 14157253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 14257253fd8SAndrei Emeltchenko 1431c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1441c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1451c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1461c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1471c2acffbSGustavo F. Padovan 1481c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 14957253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 150d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT 4 151d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT 7 1521c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1538f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1541c2acffbSGustavo F. Padovan 15557253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 15657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 15757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 15857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 15957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 16057253fd8SAndrei Emeltchenko 16157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 16257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 16357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 16457253fd8SAndrei Emeltchenko 165d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT 1 16657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 16757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 16857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 169d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT 18 17057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 17157253fd8SAndrei Emeltchenko 1721c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 173ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 174ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 175ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 176ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1771c2acffbSGustavo F. Padovan 1781c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1797e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1807e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1817e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1827e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1831c2acffbSGustavo F. Padovan 184e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 185e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 186e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 187e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 188e2fd318eSIlia Kolomisnky 1891da177e4SLinus Torvalds /* L2CAP structures */ 1901da177e4SLinus Torvalds struct l2cap_hdr { 1918e036fc3SAl Viro __le16 len; 1928e036fc3SAl Viro __le16 cid; 19366c853ccSGustavo F. Padovan } __packed; 1941da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 195d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 196d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 197d43cb289SAndrei Emeltchenko 198d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 199d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 200d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 201d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE 2 202d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE 4 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds struct l2cap_cmd_hdr { 2051da177e4SLinus Torvalds __u8 code; 2061da177e4SLinus Torvalds __u8 ident; 2078e036fc3SAl Viro __le16 len; 20866c853ccSGustavo F. Padovan } __packed; 2091da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 2101da177e4SLinus Torvalds 211e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 2128e036fc3SAl Viro __le16 reason; 21366c853ccSGustavo F. Padovan } __packed; 2141da177e4SLinus Torvalds 215e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 216e2fd318eSIlia Kolomisnky __le16 reason; 217e2fd318eSIlia Kolomisnky __le16 max_mtu; 218e2fd318eSIlia Kolomisnky } __packed; 219e2fd318eSIlia Kolomisnky 220e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 221e2fd318eSIlia Kolomisnky __le16 reason; 222e2fd318eSIlia Kolomisnky __le16 scid; 223e2fd318eSIlia Kolomisnky __le16 dcid; 224e2fd318eSIlia Kolomisnky } __packed; 225e2fd318eSIlia Kolomisnky 2261da177e4SLinus Torvalds struct l2cap_conn_req { 2278e036fc3SAl Viro __le16 psm; 2288e036fc3SAl Viro __le16 scid; 22966c853ccSGustavo F. Padovan } __packed; 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds struct l2cap_conn_rsp { 2328e036fc3SAl Viro __le16 dcid; 2338e036fc3SAl Viro __le16 scid; 2348e036fc3SAl Viro __le16 result; 2358e036fc3SAl Viro __le16 status; 23666c853ccSGustavo F. Padovan } __packed; 2371da177e4SLinus Torvalds 2382983fd68SAndrei Emeltchenko /* protocol/service multiplexer (PSM) */ 2392983fd68SAndrei Emeltchenko #define L2CAP_PSM_SDP 0x0001 2402983fd68SAndrei Emeltchenko #define L2CAP_PSM_RFCOMM 0x0003 2413124b843SMarcel Holtmann #define L2CAP_PSM_3DSP 0x0021 2422983fd68SAndrei Emeltchenko 2438db4dc46SGustavo F. Padovan /* channel indentifier */ 2448db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2458db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 246466f8004SAndrei Emeltchenko #define L2CAP_CID_A2MP 0x0003 247073d1cf3SJohan Hedberg #define L2CAP_CID_ATT 0x0004 248acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 249acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2508db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2518db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 2528db4dc46SGustavo F. Padovan 25338094c75SMat Martineau /* connect/create channel results */ 2541da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2551da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2561da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2571da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2581da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 25938094c75SMat Martineau #define L2CAP_CR_BAD_AMP 0x0005 2601da177e4SLinus Torvalds 26138094c75SMat Martineau /* connect/create channel status */ 2621da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2631da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2641da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds struct l2cap_conf_req { 2678e036fc3SAl Viro __le16 dcid; 2688e036fc3SAl Viro __le16 flags; 2691da177e4SLinus Torvalds __u8 data[0]; 27066c853ccSGustavo F. Padovan } __packed; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds struct l2cap_conf_rsp { 2738e036fc3SAl Viro __le16 scid; 2748e036fc3SAl Viro __le16 flags; 2758e036fc3SAl Viro __le16 result; 2761da177e4SLinus Torvalds __u8 data[0]; 27766c853ccSGustavo F. Padovan } __packed; 2781da177e4SLinus Torvalds 2795dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2805dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2815dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2825dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2830e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 2845a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 2851da177e4SLinus Torvalds 28659e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */ 28759e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION 0x0001 28859e54bd1SAndrei Emeltchenko 2891da177e4SLinus Torvalds struct l2cap_conf_opt { 2901da177e4SLinus Torvalds __u8 type; 2911da177e4SLinus Torvalds __u8 len; 2921da177e4SLinus Torvalds __u8 val[0]; 29366c853ccSGustavo F. Padovan } __packed; 2941da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2951da177e4SLinus Torvalds 296589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 29747ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 298589d2746SGustavo F. Padovan 2991da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 3001da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 3011da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 3021da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 30347ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 3045a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 3056327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 3061da177e4SLinus Torvalds 3071da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 3081da177e4SLinus Torvalds 3096464f35fSMarcel Holtmann struct l2cap_conf_rfc { 3106464f35fSMarcel Holtmann __u8 mode; 3116464f35fSMarcel Holtmann __u8 txwin_size; 3126464f35fSMarcel Holtmann __u8 max_transmit; 3136464f35fSMarcel Holtmann __le16 retrans_timeout; 3146464f35fSMarcel Holtmann __le16 monitor_timeout; 3156464f35fSMarcel Holtmann __le16 max_pdu_size; 31666c853ccSGustavo F. Padovan } __packed; 3176464f35fSMarcel Holtmann 3186464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 3196464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 3206464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 32147ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 322c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 3236464f35fSMarcel Holtmann 3245a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 3255a9e7057SAndrei Emeltchenko __u8 id; 3265a9e7057SAndrei Emeltchenko __u8 stype; 3275a9e7057SAndrei Emeltchenko __le16 msdu; 3285a9e7057SAndrei Emeltchenko __le32 sdu_itime; 3295a9e7057SAndrei Emeltchenko __le32 acc_lat; 3305a9e7057SAndrei Emeltchenko __le32 flush_to; 3315a9e7057SAndrei Emeltchenko } __packed; 3325a9e7057SAndrei Emeltchenko 3338f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 3348f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 3358f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 3368f7975b1SAndrei Emeltchenko 3378f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3388f7975b1SAndrei Emeltchenko 3391da177e4SLinus Torvalds struct l2cap_disconn_req { 3408e036fc3SAl Viro __le16 dcid; 3418e036fc3SAl Viro __le16 scid; 34266c853ccSGustavo F. Padovan } __packed; 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3458e036fc3SAl Viro __le16 dcid; 3468e036fc3SAl Viro __le16 scid; 34766c853ccSGustavo F. Padovan } __packed; 3481da177e4SLinus Torvalds 3491da177e4SLinus Torvalds struct l2cap_info_req { 3508e036fc3SAl Viro __le16 type; 35166c853ccSGustavo F. Padovan } __packed; 3521da177e4SLinus Torvalds 3531da177e4SLinus Torvalds struct l2cap_info_rsp { 3548e036fc3SAl Viro __le16 type; 3558e036fc3SAl Viro __le16 result; 3561da177e4SLinus Torvalds __u8 data[0]; 35766c853ccSGustavo F. Padovan } __packed; 3581da177e4SLinus Torvalds 35938094c75SMat Martineau struct l2cap_create_chan_req { 36038094c75SMat Martineau __le16 psm; 36138094c75SMat Martineau __le16 scid; 36238094c75SMat Martineau __u8 amp_id; 36338094c75SMat Martineau } __packed; 36438094c75SMat Martineau 36538094c75SMat Martineau struct l2cap_create_chan_rsp { 36638094c75SMat Martineau __le16 dcid; 36738094c75SMat Martineau __le16 scid; 36838094c75SMat Martineau __le16 result; 36938094c75SMat Martineau __le16 status; 37038094c75SMat Martineau } __packed; 37138094c75SMat Martineau 37238094c75SMat Martineau struct l2cap_move_chan_req { 37338094c75SMat Martineau __le16 icid; 37438094c75SMat Martineau __u8 dest_amp_id; 37538094c75SMat Martineau } __packed; 37638094c75SMat Martineau 37738094c75SMat Martineau struct l2cap_move_chan_rsp { 37838094c75SMat Martineau __le16 icid; 37938094c75SMat Martineau __le16 result; 38038094c75SMat Martineau } __packed; 38138094c75SMat Martineau 38238094c75SMat Martineau #define L2CAP_MR_SUCCESS 0x0000 38338094c75SMat Martineau #define L2CAP_MR_PEND 0x0001 38438094c75SMat Martineau #define L2CAP_MR_BAD_ID 0x0002 38538094c75SMat Martineau #define L2CAP_MR_SAME_ID 0x0003 38638094c75SMat Martineau #define L2CAP_MR_NOT_SUPP 0x0004 38738094c75SMat Martineau #define L2CAP_MR_COLLISION 0x0005 38838094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED 0x0006 38938094c75SMat Martineau 39038094c75SMat Martineau struct l2cap_move_chan_cfm { 39138094c75SMat Martineau __le16 icid; 39238094c75SMat Martineau __le16 result; 39338094c75SMat Martineau } __packed; 39438094c75SMat Martineau 39538094c75SMat Martineau #define L2CAP_MC_CONFIRMED 0x0000 39638094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED 0x0001 39738094c75SMat Martineau 39838094c75SMat Martineau struct l2cap_move_chan_cfm_rsp { 39938094c75SMat Martineau __le16 icid; 40038094c75SMat Martineau } __packed; 40138094c75SMat Martineau 4021da177e4SLinus Torvalds /* info type */ 4031da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 4041da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 405e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds /* info result */ 4081da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 4091da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 4101da177e4SLinus Torvalds 411de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 412de73115aSClaudio Takahasi __le16 min; 413de73115aSClaudio Takahasi __le16 max; 414de73115aSClaudio Takahasi __le16 latency; 415de73115aSClaudio Takahasi __le16 to_multiplier; 416de73115aSClaudio Takahasi } __packed; 417de73115aSClaudio Takahasi 418de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 419de73115aSClaudio Takahasi __le16 result; 420de73115aSClaudio Takahasi } __packed; 421de73115aSClaudio Takahasi 422de73115aSClaudio Takahasi /* Connection Parameters result */ 423de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 424de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 425de73115aSClaudio Takahasi 42648454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 4273c588192SMat Martineau struct l2cap_seq_list { 4283c588192SMat Martineau __u16 head; 4293c588192SMat Martineau __u16 tail; 4303c588192SMat Martineau __u16 mask; 4313c588192SMat Martineau __u16 *list; 4323c588192SMat Martineau }; 4333c588192SMat Martineau 4343c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR 0xFFFF 4353c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL 0x8000 4363c588192SMat Martineau 43748454079SGustavo F. Padovan struct l2cap_chan { 43848454079SGustavo F. Padovan struct sock *sk; 4398c1d787bSGustavo F. Padovan 4408c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 44108333283SMat Martineau struct hci_conn *hs_hcon; 44208333283SMat Martineau struct hci_chan *hs_hchan; 443144ad330SSyam Sidhardhan struct kref kref; 4448c1d787bSGustavo F. Padovan 44589bc500eSGustavo F. Padovan __u8 state; 44689bc500eSGustavo F. Padovan 4477eafc59eSMarcel Holtmann bdaddr_t dst; 4484f1654e0SMarcel Holtmann __u8 dst_type; 4497eafc59eSMarcel Holtmann bdaddr_t src; 4504f1654e0SMarcel Holtmann __u8 src_type; 451fe4128e0SGustavo F. Padovan __le16 psm; 4524f1654e0SMarcel Holtmann __le16 sport; 453fe4128e0SGustavo F. Padovan __u16 dcid; 454fe4128e0SGustavo F. Padovan __u16 scid; 4554343478fSGustavo F. Padovan 4560c1bc5c6SGustavo F. Padovan __u16 imtu; 4570c1bc5c6SGustavo F. Padovan __u16 omtu; 4580c1bc5c6SGustavo F. Padovan __u16 flush_to; 4590c1bc5c6SGustavo F. Padovan __u8 mode; 460715ec005SGustavo F. Padovan __u8 chan_type; 4612ea66482SMat Martineau __u8 chan_policy; 4620c1bc5c6SGustavo F. Padovan 4634343478fSGustavo F. Padovan __u8 sec_level; 4644343478fSGustavo F. Padovan 465fc7f8a7eSGustavo F. Padovan __u8 ident; 466fc7f8a7eSGustavo F. Padovan 46773ffa904SGustavo F. Padovan __u8 conf_req[64]; 46873ffa904SGustavo F. Padovan __u8 conf_len; 46973ffa904SGustavo F. Padovan __u8 num_conf_req; 47073ffa904SGustavo F. Padovan __u8 num_conf_rsp; 47173ffa904SGustavo F. Padovan 47247d1ec61SGustavo F. Padovan __u8 fcs; 47347d1ec61SGustavo F. Padovan 4746327eb98SAndrei Emeltchenko __u16 tx_win; 475836be934SAndrei Emeltchenko __u16 tx_win_max; 476c20f8e35SMat Martineau __u16 ack_win; 47747d1ec61SGustavo F. Padovan __u8 max_tx; 47847d1ec61SGustavo F. Padovan __u16 retrans_timeout; 47947d1ec61SGustavo F. Padovan __u16 monitor_timeout; 48047d1ec61SGustavo F. Padovan __u16 mps; 48147d1ec61SGustavo F. Padovan 482d5f7ac38SMat Martineau __u8 tx_state; 483d5f7ac38SMat Martineau __u8 rx_state; 484d5f7ac38SMat Martineau 485c1360a1cSGustavo F. Padovan unsigned long conf_state; 486e2ab4353SGustavo F. Padovan unsigned long conn_state; 487d57b0e8bSAndrei Emeltchenko unsigned long flags; 488525cd185SGustavo F. Padovan 489fffadc08SAndrei Emeltchenko __u8 remote_amp_id; 49008333283SMat Martineau __u8 local_amp_id; 49108333283SMat Martineau __u8 move_id; 49208333283SMat Martineau __u8 move_state; 49308333283SMat Martineau __u8 move_role; 49408333283SMat Martineau 495fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 496fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 497fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 4980b209faeSAndrei Emeltchenko __u16 buffer_seq; 499fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 500d5f7ac38SMat Martineau __u16 last_acked_seq; 501fb45de7dSAndrei Emeltchenko __u16 frames_sent; 502fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 5036a026610SGustavo F. Padovan __u8 retry_count; 5046f61fd47SGustavo F. Padovan __u16 sdu_len; 5056f61fd47SGustavo F. Padovan struct sk_buff *sdu; 50684084a31SMat Martineau struct sk_buff *sdu_last_frag; 5076f61fd47SGustavo F. Padovan 5086327eb98SAndrei Emeltchenko __u16 remote_tx_win; 5092c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 5102c03a7a4SGustavo F. Padovan __u16 remote_mps; 51142e5c802SGustavo F. Padovan 5125a9e7057SAndrei Emeltchenko __u8 local_id; 5135a9e7057SAndrei Emeltchenko __u8 local_stype; 5145a9e7057SAndrei Emeltchenko __u16 local_msdu; 5155a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 5165a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 5175a9e7057SAndrei Emeltchenko __u32 local_flush_to; 5185a9e7057SAndrei Emeltchenko 5195a9e7057SAndrei Emeltchenko __u8 remote_id; 5205a9e7057SAndrei Emeltchenko __u8 remote_stype; 5215a9e7057SAndrei Emeltchenko __u16 remote_msdu; 5225a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 5235a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 5245a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 5255a9e7057SAndrei Emeltchenko 526721c4181SGustavo F. Padovan struct delayed_work chan_timer; 527721c4181SGustavo F. Padovan struct delayed_work retrans_timer; 528721c4181SGustavo F. Padovan struct delayed_work monitor_timer; 529721c4181SGustavo F. Padovan struct delayed_work ack_timer; 530721c4181SGustavo F. Padovan 53158d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 53258d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 533f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 5343c588192SMat Martineau struct l2cap_seq_list srej_list; 5353c588192SMat Martineau struct l2cap_seq_list retrans_list; 536e92c8e70SGustavo F. Padovan 537baa7e1faSGustavo F. Padovan struct list_head list; 53823691d75SGustavo F. Padovan struct list_head global_l; 53980808e43SGustavo F. Padovan 54080808e43SGustavo F. Padovan void *data; 54180808e43SGustavo F. Padovan struct l2cap_ops *ops; 542c03b355eSAndrei Emeltchenko struct mutex lock; 54380808e43SGustavo F. Padovan }; 54480808e43SGustavo F. Padovan 54580808e43SGustavo F. Padovan struct l2cap_ops { 54680808e43SGustavo F. Padovan char *name; 54780808e43SGustavo F. Padovan 54880b98027SGustavo Padovan struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan); 54980b98027SGustavo Padovan int (*recv) (struct l2cap_chan * chan, 55080b98027SGustavo Padovan struct sk_buff *skb); 551c0df7f6eSAndrei Emeltchenko void (*teardown) (struct l2cap_chan *chan, int err); 55280b98027SGustavo Padovan void (*close) (struct l2cap_chan *chan); 55380b98027SGustavo Padovan void (*state_change) (struct l2cap_chan *chan, 55480b98027SGustavo Padovan int state); 55554a59aa2SAndrei Emeltchenko void (*ready) (struct l2cap_chan *chan); 5562dc4e510SGustavo Padovan void (*defer) (struct l2cap_chan *chan); 557*d97c899bSMarcel Holtmann void (*resume) (struct l2cap_chan *chan); 5582f7719ceSAndrei Emeltchenko struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 55990338947SGustavo Padovan unsigned long len, int nb); 5601da177e4SLinus Torvalds }; 5611da177e4SLinus Torvalds 5621da177e4SLinus Torvalds struct l2cap_conn { 5631da177e4SLinus Torvalds struct hci_conn *hcon; 56473d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds unsigned int mtu; 5671da177e4SLinus Torvalds 5684e8402a3SMarcel Holtmann __u32 feat_mask; 569978c93b9SAndrei Emeltchenko __u8 fixed_chan_mask; 570848566b3SMarcel Holtmann bool hs_enabled; 5714e8402a3SMarcel Holtmann 5724e8402a3SMarcel Holtmann __u8 info_state; 5734e8402a3SMarcel Holtmann __u8 info_ident; 5744e8402a3SMarcel Holtmann 575030013d8SGustavo F. Padovan struct delayed_work info_timer; 5764e8402a3SMarcel Holtmann 5771da177e4SLinus Torvalds spinlock_t lock; 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds struct sk_buff *rx_skb; 5801da177e4SLinus Torvalds __u32 rx_len; 5811da177e4SLinus Torvalds __u8 tx_ident; 5821da177e4SLinus Torvalds 5832950f21aSMarcel Holtmann __u8 disc_reason; 5842950f21aSMarcel Holtmann 5856c9d42a1SGustavo F. Padovan struct delayed_work security_timer; 5861c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 5875d3de7dfSVinicius Costa Gomes 588baa7e1faSGustavo F. Padovan struct list_head chan_l; 589d01b2ff4SGustavo F. Padovan struct mutex chan_lock; 5909c903e37SDavid Herrmann struct kref ref; 5912c8e1411SDavid Herrmann struct list_head users; 5922c8e1411SDavid Herrmann }; 5932c8e1411SDavid Herrmann 5942c8e1411SDavid Herrmann struct l2cap_user { 5952c8e1411SDavid Herrmann struct list_head list; 5962c8e1411SDavid Herrmann int (*probe) (struct l2cap_conn *conn, struct l2cap_user *user); 5972c8e1411SDavid Herrmann void (*remove) (struct l2cap_conn *conn, struct l2cap_user *user); 5981da177e4SLinus Torvalds }; 5991da177e4SLinus Torvalds 6004e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 601984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 602984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 6034e8402a3SMarcel Holtmann 604715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 605715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 606715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 607416fa752SAndrei Emeltchenko #define L2CAP_CHAN_CONN_FIX_A2MP 4 608715ec005SGustavo F. Padovan 60948454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 6101da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds struct l2cap_pinfo { 6131da177e4SLinus Torvalds struct bt_sock bt; 61448454079SGustavo F. Padovan struct l2cap_chan *chan; 615e328140fSMat Martineau struct sk_buff *rx_busy_skb; 6161da177e4SLinus Torvalds }; 6171da177e4SLinus Torvalds 618c1360a1cSGustavo F. Padovan enum { 619c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 620c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 621c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 622c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 623c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 624c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 625f2592d3eSAndrei Emeltchenko CONF_RECV_NO_FCS, 626c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 6276327eb98SAndrei Emeltchenko CONF_EWS_RECV, 6280e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 6290e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 6302827011fSMat Martineau CONF_NOT_COMPLETE, 631c1360a1cSGustavo F. Padovan }; 632861d6882SMarcel Holtmann 633f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 634f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 635f2fcfcd6SGustavo F. Padovan 636e2ab4353SGustavo F. Padovan enum { 637e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 638e2ab4353SGustavo F. Padovan CONN_WAIT_F, 639e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 640e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 641e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 642e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 643e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 644e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 645e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 646e2ab4353SGustavo F. Padovan }; 647e90bac06SGustavo F. Padovan 648d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 649d57b0e8bSAndrei Emeltchenko enum { 65043bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 65115770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 652ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 653d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 6546327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 6555a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 656bdc25783SMarcel Holtmann FLAG_DEFER_SETUP, 657d57b0e8bSAndrei Emeltchenko }; 658d57b0e8bSAndrei Emeltchenko 659d5f7ac38SMat Martineau enum { 660d5f7ac38SMat Martineau L2CAP_TX_STATE_XMIT, 661d5f7ac38SMat Martineau L2CAP_TX_STATE_WAIT_F, 662d5f7ac38SMat Martineau }; 663d5f7ac38SMat Martineau 664d5f7ac38SMat Martineau enum { 665d5f7ac38SMat Martineau L2CAP_RX_STATE_RECV, 666d5f7ac38SMat Martineau L2CAP_RX_STATE_SREJ_SENT, 66708333283SMat Martineau L2CAP_RX_STATE_MOVE, 66808333283SMat Martineau L2CAP_RX_STATE_WAIT_P, 66908333283SMat Martineau L2CAP_RX_STATE_WAIT_F, 670d5f7ac38SMat Martineau }; 671d5f7ac38SMat Martineau 672d5f7ac38SMat Martineau enum { 673d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED, 674d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED_SREJ, 675d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED, 676d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED_SREJ, 677d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE, 678d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE_SREJ, 679d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID, 680d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID_IGNORE, 681d5f7ac38SMat Martineau }; 682d5f7ac38SMat Martineau 683d5f7ac38SMat Martineau enum { 684d5f7ac38SMat Martineau L2CAP_EV_DATA_REQUEST, 685d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_DETECTED, 686d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_CLEAR, 687d5f7ac38SMat Martineau L2CAP_EV_RECV_REQSEQ_AND_FBIT, 688d5f7ac38SMat Martineau L2CAP_EV_RECV_FBIT, 689d5f7ac38SMat Martineau L2CAP_EV_RETRANS_TO, 690d5f7ac38SMat Martineau L2CAP_EV_MONITOR_TO, 691d5f7ac38SMat Martineau L2CAP_EV_EXPLICIT_POLL, 692d5f7ac38SMat Martineau L2CAP_EV_RECV_IFRAME, 693d5f7ac38SMat Martineau L2CAP_EV_RECV_RR, 694d5f7ac38SMat Martineau L2CAP_EV_RECV_REJ, 695d5f7ac38SMat Martineau L2CAP_EV_RECV_RNR, 696d5f7ac38SMat Martineau L2CAP_EV_RECV_SREJ, 697d5f7ac38SMat Martineau L2CAP_EV_RECV_FRAME, 698d5f7ac38SMat Martineau }; 699d5f7ac38SMat Martineau 70008333283SMat Martineau enum { 70108333283SMat Martineau L2CAP_MOVE_ROLE_NONE, 70208333283SMat Martineau L2CAP_MOVE_ROLE_INITIATOR, 70308333283SMat Martineau L2CAP_MOVE_ROLE_RESPONDER, 70408333283SMat Martineau }; 70508333283SMat Martineau 70608333283SMat Martineau enum { 70708333283SMat Martineau L2CAP_MOVE_STABLE, 70808333283SMat Martineau L2CAP_MOVE_WAIT_REQ, 70908333283SMat Martineau L2CAP_MOVE_WAIT_RSP, 71008333283SMat Martineau L2CAP_MOVE_WAIT_RSP_SUCCESS, 71108333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM, 71208333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM_RSP, 71308333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_COMP, 71408333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_CFM, 71508333283SMat Martineau L2CAP_MOVE_WAIT_LOCAL_BUSY, 71608333283SMat Martineau L2CAP_MOVE_WAIT_PREPARE, 71708333283SMat Martineau }; 71808333283SMat Martineau 71930648372SJaganath Kanakkassery void l2cap_chan_hold(struct l2cap_chan *c); 72030648372SJaganath Kanakkassery void l2cap_chan_put(struct l2cap_chan *c); 721371fd835SUlisses Furquim 722c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan) 723c03b355eSAndrei Emeltchenko { 724c03b355eSAndrei Emeltchenko mutex_lock(&chan->lock); 725c03b355eSAndrei Emeltchenko } 726c03b355eSAndrei Emeltchenko 727c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 728c03b355eSAndrei Emeltchenko { 729c03b355eSAndrei Emeltchenko mutex_unlock(&chan->lock); 730c03b355eSAndrei Emeltchenko } 731c03b355eSAndrei Emeltchenko 732c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan, 733c2ec9c1bSGustavo F. Padovan struct delayed_work *work, long timeout) 734c2ec9c1bSGustavo F. Padovan { 735e05dcc32SAndrei Emeltchenko BT_DBG("chan %p state %s timeout %ld", chan, 736e05dcc32SAndrei Emeltchenko state_to_string(chan->state), timeout); 737c2ec9c1bSGustavo F. Padovan 7386f74b6f3SAndrei Emeltchenko /* If delayed work cancelled do not hold(chan) 7396f74b6f3SAndrei Emeltchenko since it is already done with previous set_timer */ 74017cd3f37SUlisses Furquim if (!cancel_delayed_work(work)) 741371fd835SUlisses Furquim l2cap_chan_hold(chan); 7426f74b6f3SAndrei Emeltchenko 743c2ec9c1bSGustavo F. Padovan schedule_delayed_work(work, timeout); 744c2ec9c1bSGustavo F. Padovan } 745c2ec9c1bSGustavo F. Padovan 74675b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan, 747371fd835SUlisses Furquim struct delayed_work *work) 748c2ec9c1bSGustavo F. Padovan { 74975b93b59SSzymon Janc bool ret; 75075b93b59SSzymon Janc 7516f74b6f3SAndrei Emeltchenko /* put(chan) if delayed work cancelled otherwise it 7526f74b6f3SAndrei Emeltchenko is done in delayed work function */ 75317cd3f37SUlisses Furquim ret = cancel_delayed_work(work); 75475b93b59SSzymon Janc if (ret) 755371fd835SUlisses Furquim l2cap_chan_put(chan); 75675b93b59SSzymon Janc 75775b93b59SSzymon Janc return ret; 758c2ec9c1bSGustavo F. Padovan } 759c2ec9c1bSGustavo F. Padovan 760c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 761c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 7621a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 7631a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 7641a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 765b83ddfe2SAndrzej Kaczmarek msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 7661a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 767c74e560cSGustavo F. Padovan 768836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 769836be934SAndrei Emeltchenko { 7705a364bd3SMat Martineau if (seq1 >= seq2) 7715a364bd3SMat Martineau return seq1 - seq2; 7725a364bd3SMat Martineau else 7735a364bd3SMat Martineau return chan->tx_win_max + 1 - seq2 + seq1; 774836be934SAndrei Emeltchenko } 775836be934SAndrei Emeltchenko 776836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 777836be934SAndrei Emeltchenko { 778836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 779836be934SAndrei Emeltchenko } 780836be934SAndrei Emeltchenko 7817e1af8a3SGustavo Padovan static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chan *chan) 7827e1af8a3SGustavo Padovan { 7837e1af8a3SGustavo Padovan return NULL; 7847e1af8a3SGustavo Padovan } 7857e1af8a3SGustavo Padovan 7867e1af8a3SGustavo Padovan static inline void l2cap_chan_no_teardown(struct l2cap_chan *chan, int err) 7877e1af8a3SGustavo Padovan { 7887e1af8a3SGustavo Padovan } 7897e1af8a3SGustavo Padovan 7907e1af8a3SGustavo Padovan static inline void l2cap_chan_no_ready(struct l2cap_chan *chan) 7917e1af8a3SGustavo Padovan { 7927e1af8a3SGustavo Padovan } 7931da177e4SLinus Torvalds 7942dc4e510SGustavo Padovan static inline void l2cap_chan_no_defer(struct l2cap_chan *chan) 7952dc4e510SGustavo Padovan { 7962dc4e510SGustavo Padovan } 7972dc4e510SGustavo Padovan 798eb939922SRusty Russell extern bool disable_ertm; 799bb58f747SGustavo F. Padovan 800bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 801bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 802b3916db3SDavid Herrmann bool l2cap_is_socket(struct socket *sock); 803bb58f747SGustavo F. Padovan 8048c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 805dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 80668983259SGustavo F. Padovan 8079e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 8089e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 8099e4425ffSGustavo F. Padovan 810eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void); 8110f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 812cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 8138e9f9892SAndre Guedes bdaddr_t *dst, u8 dst_type); 8145e59b791SLuiz Augusto von Dentz int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 8155e59b791SLuiz Augusto von Dentz u32 priority); 816e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 817d45fc423SGustavo F. Padovan int l2cap_chan_check_security(struct l2cap_chan *chan); 818bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan); 819466f8004SAndrei Emeltchenko int l2cap_ertm_init(struct l2cap_chan *chan); 820466f8004SAndrei Emeltchenko void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 82193c3e8f5SAndrei Emeltchenko void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 822466f8004SAndrei Emeltchenko void l2cap_chan_del(struct l2cap_chan *chan, int err); 8232766be48SAndrei Emeltchenko void l2cap_send_conn_req(struct l2cap_chan *chan); 8243f7a56c4SMat Martineau void l2cap_move_start(struct l2cap_chan *chan); 82527695fb4SAndrei Emeltchenko void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, 82627695fb4SAndrei Emeltchenko u8 status); 827a514b17fSAndrei Emeltchenko void __l2cap_physical_cfm(struct l2cap_chan *chan, int result); 828bb58f747SGustavo F. Padovan 8299c903e37SDavid Herrmann void l2cap_conn_get(struct l2cap_conn *conn); 8309c903e37SDavid Herrmann void l2cap_conn_put(struct l2cap_conn *conn); 8319c903e37SDavid Herrmann 8322c8e1411SDavid Herrmann int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); 8332c8e1411SDavid Herrmann void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user); 8342c8e1411SDavid Herrmann 8351da177e4SLinus Torvalds #endif /* __L2CAP_H */ 836