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 3547ec1dcdSMarcel Holtmann #define L2CAP_DEFAULT_FLUSH_TO 0xffff 361c2acffbSGustavo F. Padovan #define L2CAP_DEFAULT_TX_WINDOW 63 376327eb98SAndrei Emeltchenko #define L2CAP_DEFAULT_EXT_WINDOW 0x3FFF 38e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX 3 39fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ 40e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 41db12d647SMat Martineau #define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */ 42c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO 200 43b62f328bSVille Tervo #define L2CAP_LE_DEFAULT_MTU 23 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 */ 481da177e4SLinus Torvalds 49ba13ccd9SMarcel Holtmann #define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100) 50ba13ccd9SMarcel Holtmann #define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000) 51ba13ccd9SMarcel Holtmann #define L2CAP_ENC_TIMEOUT msecs_to_jiffies(5000) 52ba13ccd9SMarcel Holtmann #define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000) 53ba13ccd9SMarcel Holtmann #define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000) 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds /* L2CAP socket address */ 561da177e4SLinus Torvalds struct sockaddr_l2 { 571da177e4SLinus Torvalds sa_family_t l2_family; 588e036fc3SAl Viro __le16 l2_psm; 591da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 60f29972deSMarcel Holtmann __le16 l2_cid; 6143ef0b8bSAndre Guedes __u8 l2_bdaddr_type; 621da177e4SLinus Torvalds }; 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds /* L2CAP socket options */ 651da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 661da177e4SLinus Torvalds struct l2cap_options { 671da177e4SLinus Torvalds __u16 omtu; 681da177e4SLinus Torvalds __u16 imtu; 691da177e4SLinus Torvalds __u16 flush_to; 701da177e4SLinus Torvalds __u8 mode; 71fcc203c3SGustavo F. Padovan __u8 fcs; 7268d7f0ceSGustavo F. Padovan __u8 max_tx; 7314b5aa71SGustavo F. Padovan __u16 txwin_size; 741da177e4SLinus Torvalds }; 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 771da177e4SLinus Torvalds struct l2cap_conninfo { 781da177e4SLinus Torvalds __u16 hci_handle; 791da177e4SLinus Torvalds __u8 dev_class[3]; 801da177e4SLinus Torvalds }; 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds #define L2CAP_LM 0x03 831da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 841da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 851da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 861da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 871da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 881da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds /* L2CAP command codes */ 911da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 921da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 931da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 941da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 951da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 961da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 971da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 981da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 991da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 1001da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 1011da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 10238094c75SMat Martineau #define L2CAP_CREATE_CHAN_REQ 0x0c 10338094c75SMat Martineau #define L2CAP_CREATE_CHAN_RSP 0x0d 10438094c75SMat Martineau #define L2CAP_MOVE_CHAN_REQ 0x0e 10538094c75SMat Martineau #define L2CAP_MOVE_CHAN_RSP 0x0f 10638094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM 0x10 10738094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM_RSP 0x11 1083300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 1093300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 1101da177e4SLinus Torvalds 111a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 11247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 11347ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 114a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 11547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 11647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 11747ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 118a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 11947ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 120a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 121a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 12247ec1dcdSMarcel Holtmann 12347ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 12447ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 12547ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 12647ec1dcdSMarcel Holtmann 127d835ac0fSMat Martineau /* L2CAP fixed channels */ 128d835ac0fSMat Martineau #define L2CAP_FC_L2CAP 0x02 129d835ac0fSMat Martineau #define L2CAP_FC_A2MP 0x08 130d835ac0fSMat Martineau 1311c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1321c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1331c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1341c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 13557253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 13657253fd8SAndrei Emeltchenko 1371c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1381c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1391c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1401c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1411c2acffbSGustavo F. Padovan 1421c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 14357253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 144d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT 4 145d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT 7 1461c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1478f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1481c2acffbSGustavo F. Padovan 14957253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 15057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 15157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 15257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 15357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 15457253fd8SAndrei Emeltchenko 15557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 15657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 15757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 15857253fd8SAndrei Emeltchenko 159d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT 1 16057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 16157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 16257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 163d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT 18 16457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 16557253fd8SAndrei Emeltchenko 1661c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 167ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 168ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 169ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 170ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1711c2acffbSGustavo F. Padovan 1721c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1737e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1747e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1757e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1767e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1771c2acffbSGustavo F. Padovan 178e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 179e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 180e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 181e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 182e2fd318eSIlia Kolomisnky 1831da177e4SLinus Torvalds /* L2CAP structures */ 1841da177e4SLinus Torvalds struct l2cap_hdr { 1858e036fc3SAl Viro __le16 len; 1868e036fc3SAl Viro __le16 cid; 18766c853ccSGustavo F. Padovan } __packed; 1881da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 189d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 190d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 191d43cb289SAndrei Emeltchenko 192d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 193d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 194d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 195d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE 2 196d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE 4 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds struct l2cap_cmd_hdr { 1991da177e4SLinus Torvalds __u8 code; 2001da177e4SLinus Torvalds __u8 ident; 2018e036fc3SAl Viro __le16 len; 20266c853ccSGustavo F. Padovan } __packed; 2031da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 2041da177e4SLinus Torvalds 205e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 2068e036fc3SAl Viro __le16 reason; 20766c853ccSGustavo F. Padovan } __packed; 2081da177e4SLinus Torvalds 209e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 210e2fd318eSIlia Kolomisnky __le16 reason; 211e2fd318eSIlia Kolomisnky __le16 max_mtu; 212e2fd318eSIlia Kolomisnky } __packed; 213e2fd318eSIlia Kolomisnky 214e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 215e2fd318eSIlia Kolomisnky __le16 reason; 216e2fd318eSIlia Kolomisnky __le16 scid; 217e2fd318eSIlia Kolomisnky __le16 dcid; 218e2fd318eSIlia Kolomisnky } __packed; 219e2fd318eSIlia Kolomisnky 2201da177e4SLinus Torvalds struct l2cap_conn_req { 2218e036fc3SAl Viro __le16 psm; 2228e036fc3SAl Viro __le16 scid; 22366c853ccSGustavo F. Padovan } __packed; 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds struct l2cap_conn_rsp { 2268e036fc3SAl Viro __le16 dcid; 2278e036fc3SAl Viro __le16 scid; 2288e036fc3SAl Viro __le16 result; 2298e036fc3SAl Viro __le16 status; 23066c853ccSGustavo F. Padovan } __packed; 2311da177e4SLinus Torvalds 2322983fd68SAndrei Emeltchenko /* protocol/service multiplexer (PSM) */ 2332983fd68SAndrei Emeltchenko #define L2CAP_PSM_SDP 0x0001 2342983fd68SAndrei Emeltchenko #define L2CAP_PSM_RFCOMM 0x0003 2352983fd68SAndrei Emeltchenko 2368db4dc46SGustavo F. Padovan /* channel indentifier */ 2378db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2388db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 239acd7d370SVille Tervo #define L2CAP_CID_LE_DATA 0x0004 240acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 241acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2428db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2438db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 2448db4dc46SGustavo F. Padovan 24538094c75SMat Martineau /* connect/create channel results */ 2461da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2471da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2481da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2491da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2501da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 25138094c75SMat Martineau #define L2CAP_CR_BAD_AMP 0x0005 2521da177e4SLinus Torvalds 25338094c75SMat Martineau /* connect/create channel status */ 2541da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2551da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2561da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds struct l2cap_conf_req { 2598e036fc3SAl Viro __le16 dcid; 2608e036fc3SAl Viro __le16 flags; 2611da177e4SLinus Torvalds __u8 data[0]; 26266c853ccSGustavo F. Padovan } __packed; 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds struct l2cap_conf_rsp { 2658e036fc3SAl Viro __le16 scid; 2668e036fc3SAl Viro __le16 flags; 2678e036fc3SAl Viro __le16 result; 2681da177e4SLinus Torvalds __u8 data[0]; 26966c853ccSGustavo F. Padovan } __packed; 2701da177e4SLinus Torvalds 2715dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2725dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2735dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2745dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2750e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 2765a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 2771da177e4SLinus Torvalds 27859e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */ 27959e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION 0x0001 28059e54bd1SAndrei Emeltchenko 2811da177e4SLinus Torvalds struct l2cap_conf_opt { 2821da177e4SLinus Torvalds __u8 type; 2831da177e4SLinus Torvalds __u8 len; 2841da177e4SLinus Torvalds __u8 val[0]; 28566c853ccSGustavo F. Padovan } __packed; 2861da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2871da177e4SLinus Torvalds 288589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 28947ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 290589d2746SGustavo F. Padovan 2911da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2921da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 2931da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 2941da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 29547ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 2965a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 2976327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 2981da177e4SLinus Torvalds 2991da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 3001da177e4SLinus Torvalds 3016464f35fSMarcel Holtmann struct l2cap_conf_rfc { 3026464f35fSMarcel Holtmann __u8 mode; 3036464f35fSMarcel Holtmann __u8 txwin_size; 3046464f35fSMarcel Holtmann __u8 max_transmit; 3056464f35fSMarcel Holtmann __le16 retrans_timeout; 3066464f35fSMarcel Holtmann __le16 monitor_timeout; 3076464f35fSMarcel Holtmann __le16 max_pdu_size; 30866c853ccSGustavo F. Padovan } __packed; 3096464f35fSMarcel Holtmann 3106464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 3116464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 3126464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 31347ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 314c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 3156464f35fSMarcel Holtmann 3165a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 3175a9e7057SAndrei Emeltchenko __u8 id; 3185a9e7057SAndrei Emeltchenko __u8 stype; 3195a9e7057SAndrei Emeltchenko __le16 msdu; 3205a9e7057SAndrei Emeltchenko __le32 sdu_itime; 3215a9e7057SAndrei Emeltchenko __le32 acc_lat; 3225a9e7057SAndrei Emeltchenko __le32 flush_to; 3235a9e7057SAndrei Emeltchenko } __packed; 3245a9e7057SAndrei Emeltchenko 3258f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 3268f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 3278f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 3288f7975b1SAndrei Emeltchenko 3298f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3308f7975b1SAndrei Emeltchenko 3311da177e4SLinus Torvalds struct l2cap_disconn_req { 3328e036fc3SAl Viro __le16 dcid; 3338e036fc3SAl Viro __le16 scid; 33466c853ccSGustavo F. Padovan } __packed; 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3378e036fc3SAl Viro __le16 dcid; 3388e036fc3SAl Viro __le16 scid; 33966c853ccSGustavo F. Padovan } __packed; 3401da177e4SLinus Torvalds 3411da177e4SLinus Torvalds struct l2cap_info_req { 3428e036fc3SAl Viro __le16 type; 34366c853ccSGustavo F. Padovan } __packed; 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds struct l2cap_info_rsp { 3468e036fc3SAl Viro __le16 type; 3478e036fc3SAl Viro __le16 result; 3481da177e4SLinus Torvalds __u8 data[0]; 34966c853ccSGustavo F. Padovan } __packed; 3501da177e4SLinus Torvalds 35138094c75SMat Martineau struct l2cap_create_chan_req { 35238094c75SMat Martineau __le16 psm; 35338094c75SMat Martineau __le16 scid; 35438094c75SMat Martineau __u8 amp_id; 35538094c75SMat Martineau } __packed; 35638094c75SMat Martineau 35738094c75SMat Martineau struct l2cap_create_chan_rsp { 35838094c75SMat Martineau __le16 dcid; 35938094c75SMat Martineau __le16 scid; 36038094c75SMat Martineau __le16 result; 36138094c75SMat Martineau __le16 status; 36238094c75SMat Martineau } __packed; 36338094c75SMat Martineau 36438094c75SMat Martineau struct l2cap_move_chan_req { 36538094c75SMat Martineau __le16 icid; 36638094c75SMat Martineau __u8 dest_amp_id; 36738094c75SMat Martineau } __packed; 36838094c75SMat Martineau 36938094c75SMat Martineau struct l2cap_move_chan_rsp { 37038094c75SMat Martineau __le16 icid; 37138094c75SMat Martineau __le16 result; 37238094c75SMat Martineau } __packed; 37338094c75SMat Martineau 37438094c75SMat Martineau #define L2CAP_MR_SUCCESS 0x0000 37538094c75SMat Martineau #define L2CAP_MR_PEND 0x0001 37638094c75SMat Martineau #define L2CAP_MR_BAD_ID 0x0002 37738094c75SMat Martineau #define L2CAP_MR_SAME_ID 0x0003 37838094c75SMat Martineau #define L2CAP_MR_NOT_SUPP 0x0004 37938094c75SMat Martineau #define L2CAP_MR_COLLISION 0x0005 38038094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED 0x0006 38138094c75SMat Martineau 38238094c75SMat Martineau struct l2cap_move_chan_cfm { 38338094c75SMat Martineau __le16 icid; 38438094c75SMat Martineau __le16 result; 38538094c75SMat Martineau } __packed; 38638094c75SMat Martineau 38738094c75SMat Martineau #define L2CAP_MC_CONFIRMED 0x0000 38838094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED 0x0001 38938094c75SMat Martineau 39038094c75SMat Martineau struct l2cap_move_chan_cfm_rsp { 39138094c75SMat Martineau __le16 icid; 39238094c75SMat Martineau } __packed; 39338094c75SMat Martineau 3941da177e4SLinus Torvalds /* info type */ 3951da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 3961da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 397e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvalds /* info result */ 4001da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 4011da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 4021da177e4SLinus Torvalds 403de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 404de73115aSClaudio Takahasi __le16 min; 405de73115aSClaudio Takahasi __le16 max; 406de73115aSClaudio Takahasi __le16 latency; 407de73115aSClaudio Takahasi __le16 to_multiplier; 408de73115aSClaudio Takahasi } __packed; 409de73115aSClaudio Takahasi 410de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 411de73115aSClaudio Takahasi __le16 result; 412de73115aSClaudio Takahasi } __packed; 413de73115aSClaudio Takahasi 414de73115aSClaudio Takahasi /* Connection Parameters result */ 415de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 416de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 417de73115aSClaudio Takahasi 41848454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 4193c588192SMat Martineau struct l2cap_seq_list { 4203c588192SMat Martineau __u16 head; 4213c588192SMat Martineau __u16 tail; 4223c588192SMat Martineau __u16 mask; 4233c588192SMat Martineau __u16 *list; 4243c588192SMat Martineau }; 4253c588192SMat Martineau 4263c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR 0xFFFF 4273c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL 0x8000 4283c588192SMat Martineau 42948454079SGustavo F. Padovan struct l2cap_chan { 43048454079SGustavo F. Padovan struct sock *sk; 4318c1d787bSGustavo F. Padovan 4328c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 4338c1d787bSGustavo F. Padovan 43489bc500eSGustavo F. Padovan __u8 state; 43589bc500eSGustavo F. Padovan 43671ba0e56SGustavo F. Padovan atomic_t refcnt; 43771ba0e56SGustavo F. Padovan 438fe4128e0SGustavo F. Padovan __le16 psm; 439fe4128e0SGustavo F. Padovan __u16 dcid; 440fe4128e0SGustavo F. Padovan __u16 scid; 4414343478fSGustavo F. Padovan 4420c1bc5c6SGustavo F. Padovan __u16 imtu; 4430c1bc5c6SGustavo F. Padovan __u16 omtu; 4440c1bc5c6SGustavo F. Padovan __u16 flush_to; 4450c1bc5c6SGustavo F. Padovan __u8 mode; 446715ec005SGustavo F. Padovan __u8 chan_type; 4472ea66482SMat Martineau __u8 chan_policy; 4480c1bc5c6SGustavo F. Padovan 4490c1bc5c6SGustavo F. Padovan __le16 sport; 4500c1bc5c6SGustavo F. Padovan 4514343478fSGustavo F. Padovan __u8 sec_level; 4524343478fSGustavo F. Padovan 453fc7f8a7eSGustavo F. Padovan __u8 ident; 454fc7f8a7eSGustavo F. Padovan 45573ffa904SGustavo F. Padovan __u8 conf_req[64]; 45673ffa904SGustavo F. Padovan __u8 conf_len; 45773ffa904SGustavo F. Padovan __u8 num_conf_req; 45873ffa904SGustavo F. Padovan __u8 num_conf_rsp; 45973ffa904SGustavo F. Padovan 46047d1ec61SGustavo F. Padovan __u8 fcs; 46147d1ec61SGustavo F. Padovan 4626327eb98SAndrei Emeltchenko __u16 tx_win; 463836be934SAndrei Emeltchenko __u16 tx_win_max; 46447d1ec61SGustavo F. Padovan __u8 max_tx; 46547d1ec61SGustavo F. Padovan __u16 retrans_timeout; 46647d1ec61SGustavo F. Padovan __u16 monitor_timeout; 46747d1ec61SGustavo F. Padovan __u16 mps; 46847d1ec61SGustavo F. Padovan 469d5f7ac38SMat Martineau __u8 tx_state; 470d5f7ac38SMat Martineau __u8 rx_state; 471d5f7ac38SMat Martineau 472c1360a1cSGustavo F. Padovan unsigned long conf_state; 473e2ab4353SGustavo F. Padovan unsigned long conn_state; 474d57b0e8bSAndrei Emeltchenko unsigned long flags; 475525cd185SGustavo F. Padovan 476fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 477fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 478fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 4790b209faeSAndrei Emeltchenko __u16 buffer_seq; 480fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 481d5f7ac38SMat Martineau __u16 last_acked_seq; 482fb45de7dSAndrei Emeltchenko __u16 frames_sent; 483fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 4846a026610SGustavo F. Padovan __u8 retry_count; 485d5f7ac38SMat Martineau __u16 srej_queue_next; 4866f61fd47SGustavo F. Padovan __u16 sdu_len; 4876f61fd47SGustavo F. Padovan struct sk_buff *sdu; 48884084a31SMat Martineau struct sk_buff *sdu_last_frag; 4896f61fd47SGustavo F. Padovan 4906327eb98SAndrei Emeltchenko __u16 remote_tx_win; 4912c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 4922c03a7a4SGustavo F. Padovan __u16 remote_mps; 49342e5c802SGustavo F. Padovan 4945a9e7057SAndrei Emeltchenko __u8 local_id; 4955a9e7057SAndrei Emeltchenko __u8 local_stype; 4965a9e7057SAndrei Emeltchenko __u16 local_msdu; 4975a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 4985a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 4995a9e7057SAndrei Emeltchenko __u32 local_flush_to; 5005a9e7057SAndrei Emeltchenko 5015a9e7057SAndrei Emeltchenko __u8 remote_id; 5025a9e7057SAndrei Emeltchenko __u8 remote_stype; 5035a9e7057SAndrei Emeltchenko __u16 remote_msdu; 5045a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 5055a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 5065a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 5075a9e7057SAndrei Emeltchenko 508721c4181SGustavo F. Padovan struct delayed_work chan_timer; 509721c4181SGustavo F. Padovan struct delayed_work retrans_timer; 510721c4181SGustavo F. Padovan struct delayed_work monitor_timer; 511721c4181SGustavo F. Padovan struct delayed_work ack_timer; 512721c4181SGustavo F. Padovan 51358d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 51458d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 515f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 5163c588192SMat Martineau struct l2cap_seq_list srej_list; 5173c588192SMat Martineau struct l2cap_seq_list retrans_list; 518e92c8e70SGustavo F. Padovan 519baa7e1faSGustavo F. Padovan struct list_head list; 52023691d75SGustavo F. Padovan struct list_head global_l; 52180808e43SGustavo F. Padovan 52280808e43SGustavo F. Padovan void *data; 52380808e43SGustavo F. Padovan struct l2cap_ops *ops; 524c03b355eSAndrei Emeltchenko struct mutex lock; 52580808e43SGustavo F. Padovan }; 52680808e43SGustavo F. Padovan 52780808e43SGustavo F. Padovan struct l2cap_ops { 52880808e43SGustavo F. Padovan char *name; 52980808e43SGustavo F. Padovan 53080b98027SGustavo Padovan struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan); 53180b98027SGustavo Padovan int (*recv) (struct l2cap_chan * chan, 53280b98027SGustavo Padovan struct sk_buff *skb); 533c0df7f6eSAndrei Emeltchenko void (*teardown) (struct l2cap_chan *chan, int err); 53480b98027SGustavo Padovan void (*close) (struct l2cap_chan *chan); 53580b98027SGustavo Padovan void (*state_change) (struct l2cap_chan *chan, 53680b98027SGustavo Padovan int state); 537*54a59aa2SAndrei Emeltchenko void (*ready) (struct l2cap_chan *chan); 5382f7719ceSAndrei Emeltchenko struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 53990338947SGustavo Padovan unsigned long len, int nb); 5401da177e4SLinus Torvalds }; 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds struct l2cap_conn { 5431da177e4SLinus Torvalds struct hci_conn *hcon; 54473d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds bdaddr_t *dst; 5471da177e4SLinus Torvalds bdaddr_t *src; 5481da177e4SLinus Torvalds 5491da177e4SLinus Torvalds unsigned int mtu; 5501da177e4SLinus Torvalds 5514e8402a3SMarcel Holtmann __u32 feat_mask; 552978c93b9SAndrei Emeltchenko __u8 fixed_chan_mask; 5534e8402a3SMarcel Holtmann 5544e8402a3SMarcel Holtmann __u8 info_state; 5554e8402a3SMarcel Holtmann __u8 info_ident; 5564e8402a3SMarcel Holtmann 557030013d8SGustavo F. Padovan struct delayed_work info_timer; 5584e8402a3SMarcel Holtmann 5591da177e4SLinus Torvalds spinlock_t lock; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds struct sk_buff *rx_skb; 5621da177e4SLinus Torvalds __u32 rx_len; 5631da177e4SLinus Torvalds __u8 tx_ident; 5641da177e4SLinus Torvalds 5652950f21aSMarcel Holtmann __u8 disc_reason; 5662950f21aSMarcel Holtmann 5676c9d42a1SGustavo F. Padovan struct delayed_work security_timer; 5681c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 5695d3de7dfSVinicius Costa Gomes 570baa7e1faSGustavo F. Padovan struct list_head chan_l; 571d01b2ff4SGustavo F. Padovan struct mutex chan_lock; 5721da177e4SLinus Torvalds }; 5731da177e4SLinus Torvalds 5744e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 575984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 576984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 5774e8402a3SMarcel Holtmann 578715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 579715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 580715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 581715ec005SGustavo F. Padovan 58248454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 5831da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds struct l2cap_pinfo { 5861da177e4SLinus Torvalds struct bt_sock bt; 58748454079SGustavo F. Padovan struct l2cap_chan *chan; 588e328140fSMat Martineau struct sk_buff *rx_busy_skb; 5891da177e4SLinus Torvalds }; 5901da177e4SLinus Torvalds 591c1360a1cSGustavo F. Padovan enum { 592c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 593c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 594c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 595c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 596c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 597c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 598c1360a1cSGustavo F. Padovan CONF_NO_FCS_RECV, 599c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 6006327eb98SAndrei Emeltchenko CONF_EWS_RECV, 6010e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 6020e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 6032827011fSMat Martineau CONF_NOT_COMPLETE, 604c1360a1cSGustavo F. Padovan }; 605861d6882SMarcel Holtmann 606f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 607f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 608f2fcfcd6SGustavo F. Padovan 609e2ab4353SGustavo F. Padovan enum { 610e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 611e2ab4353SGustavo F. Padovan CONN_WAIT_F, 612e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 613e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 614e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 615e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 616e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 617e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 618e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 619e2ab4353SGustavo F. Padovan }; 620e90bac06SGustavo F. Padovan 621d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 622d57b0e8bSAndrei Emeltchenko enum { 62343bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 62415770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 625ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 626d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 6276327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 6285a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 629d57b0e8bSAndrei Emeltchenko }; 630d57b0e8bSAndrei Emeltchenko 631d5f7ac38SMat Martineau enum { 632d5f7ac38SMat Martineau L2CAP_TX_STATE_XMIT, 633d5f7ac38SMat Martineau L2CAP_TX_STATE_WAIT_F, 634d5f7ac38SMat Martineau }; 635d5f7ac38SMat Martineau 636d5f7ac38SMat Martineau enum { 637d5f7ac38SMat Martineau L2CAP_RX_STATE_RECV, 638d5f7ac38SMat Martineau L2CAP_RX_STATE_SREJ_SENT, 639d5f7ac38SMat Martineau }; 640d5f7ac38SMat Martineau 641d5f7ac38SMat Martineau enum { 642d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED, 643d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED_SREJ, 644d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED, 645d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED_SREJ, 646d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE, 647d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE_SREJ, 648d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID, 649d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID_IGNORE, 650d5f7ac38SMat Martineau }; 651d5f7ac38SMat Martineau 652d5f7ac38SMat Martineau enum { 653d5f7ac38SMat Martineau L2CAP_EV_DATA_REQUEST, 654d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_DETECTED, 655d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_CLEAR, 656d5f7ac38SMat Martineau L2CAP_EV_RECV_REQSEQ_AND_FBIT, 657d5f7ac38SMat Martineau L2CAP_EV_RECV_FBIT, 658d5f7ac38SMat Martineau L2CAP_EV_RETRANS_TO, 659d5f7ac38SMat Martineau L2CAP_EV_MONITOR_TO, 660d5f7ac38SMat Martineau L2CAP_EV_EXPLICIT_POLL, 661d5f7ac38SMat Martineau L2CAP_EV_RECV_IFRAME, 662d5f7ac38SMat Martineau L2CAP_EV_RECV_RR, 663d5f7ac38SMat Martineau L2CAP_EV_RECV_REJ, 664d5f7ac38SMat Martineau L2CAP_EV_RECV_RNR, 665d5f7ac38SMat Martineau L2CAP_EV_RECV_SREJ, 666d5f7ac38SMat Martineau L2CAP_EV_RECV_FRAME, 667d5f7ac38SMat Martineau }; 668d5f7ac38SMat Martineau 669371fd835SUlisses Furquim static inline void l2cap_chan_hold(struct l2cap_chan *c) 670371fd835SUlisses Furquim { 671371fd835SUlisses Furquim atomic_inc(&c->refcnt); 672371fd835SUlisses Furquim } 673371fd835SUlisses Furquim 674371fd835SUlisses Furquim static inline void l2cap_chan_put(struct l2cap_chan *c) 675371fd835SUlisses Furquim { 676371fd835SUlisses Furquim if (atomic_dec_and_test(&c->refcnt)) 677371fd835SUlisses Furquim kfree(c); 678371fd835SUlisses Furquim } 679371fd835SUlisses Furquim 680c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan) 681c03b355eSAndrei Emeltchenko { 682c03b355eSAndrei Emeltchenko mutex_lock(&chan->lock); 683c03b355eSAndrei Emeltchenko } 684c03b355eSAndrei Emeltchenko 685c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 686c03b355eSAndrei Emeltchenko { 687c03b355eSAndrei Emeltchenko mutex_unlock(&chan->lock); 688c03b355eSAndrei Emeltchenko } 689c03b355eSAndrei Emeltchenko 690c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan, 691c2ec9c1bSGustavo F. Padovan struct delayed_work *work, long timeout) 692c2ec9c1bSGustavo F. Padovan { 693e05dcc32SAndrei Emeltchenko BT_DBG("chan %p state %s timeout %ld", chan, 694e05dcc32SAndrei Emeltchenko state_to_string(chan->state), timeout); 695c2ec9c1bSGustavo F. Padovan 6966f74b6f3SAndrei Emeltchenko /* If delayed work cancelled do not hold(chan) 6976f74b6f3SAndrei Emeltchenko since it is already done with previous set_timer */ 69817cd3f37SUlisses Furquim if (!cancel_delayed_work(work)) 699371fd835SUlisses Furquim l2cap_chan_hold(chan); 7006f74b6f3SAndrei Emeltchenko 701c2ec9c1bSGustavo F. Padovan schedule_delayed_work(work, timeout); 702c2ec9c1bSGustavo F. Padovan } 703c2ec9c1bSGustavo F. Padovan 70475b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan, 705371fd835SUlisses Furquim struct delayed_work *work) 706c2ec9c1bSGustavo F. Padovan { 70775b93b59SSzymon Janc bool ret; 70875b93b59SSzymon Janc 7096f74b6f3SAndrei Emeltchenko /* put(chan) if delayed work cancelled otherwise it 7106f74b6f3SAndrei Emeltchenko is done in delayed work function */ 71117cd3f37SUlisses Furquim ret = cancel_delayed_work(work); 71275b93b59SSzymon Janc if (ret) 713371fd835SUlisses Furquim l2cap_chan_put(chan); 71475b93b59SSzymon Janc 71575b93b59SSzymon Janc return ret; 716c2ec9c1bSGustavo F. Padovan } 717c2ec9c1bSGustavo F. Padovan 718c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 719c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 7201a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 7211a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 7221a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 723b83ddfe2SAndrzej Kaczmarek msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 7241a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 725c74e560cSGustavo F. Padovan 726836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 727836be934SAndrei Emeltchenko { 7285a364bd3SMat Martineau if (seq1 >= seq2) 7295a364bd3SMat Martineau return seq1 - seq2; 7305a364bd3SMat Martineau else 7315a364bd3SMat Martineau return chan->tx_win_max + 1 - seq2 + seq1; 732836be934SAndrei Emeltchenko } 733836be934SAndrei Emeltchenko 734836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 735836be934SAndrei Emeltchenko { 736836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 737836be934SAndrei Emeltchenko } 738836be934SAndrei Emeltchenko 7391da177e4SLinus Torvalds 740eb939922SRusty Russell extern bool disable_ertm; 741bb58f747SGustavo F. Padovan 742bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 743bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 744bb58f747SGustavo F. Padovan 7458c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 746dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 74768983259SGustavo F. Padovan 7489e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 7499e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 7509e4425ffSGustavo F. Padovan 751eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void); 7520f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 75323691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan); 754cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 7558e9f9892SAndre Guedes bdaddr_t *dst, u8 dst_type); 7565e59b791SLuiz Augusto von Dentz int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 7575e59b791SLuiz Augusto von Dentz u32 priority); 758e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 759d45fc423SGustavo F. Padovan int l2cap_chan_check_security(struct l2cap_chan *chan); 760bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan); 761bb58f747SGustavo F. Padovan 7621da177e4SLinus Torvalds #endif /* __L2CAP_H */ 763