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 134d835ac0fSMat Martineau #define L2CAP_FC_A2MP 0x08 135d835ac0fSMat Martineau 1361c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1371c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1381c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1391c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 14057253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 14157253fd8SAndrei Emeltchenko 1421c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1431c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1441c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1451c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1461c2acffbSGustavo F. Padovan 1471c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 14857253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 149d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT 4 150d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT 7 1511c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1528f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1531c2acffbSGustavo F. Padovan 15457253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 15557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 15657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 15757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 15857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 15957253fd8SAndrei Emeltchenko 16057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 16157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 16257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 16357253fd8SAndrei Emeltchenko 164d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT 1 16557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 16657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 16757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 168d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT 18 16957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 17057253fd8SAndrei Emeltchenko 1711c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 172ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 173ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 174ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 175ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1761c2acffbSGustavo F. Padovan 1771c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1787e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1797e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1807e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1817e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1821c2acffbSGustavo F. Padovan 183e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 184e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 185e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 186e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 187e2fd318eSIlia Kolomisnky 1881da177e4SLinus Torvalds /* L2CAP structures */ 1891da177e4SLinus Torvalds struct l2cap_hdr { 1908e036fc3SAl Viro __le16 len; 1918e036fc3SAl Viro __le16 cid; 19266c853ccSGustavo F. Padovan } __packed; 1931da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 194d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 195d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 196d43cb289SAndrei Emeltchenko 197d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 198d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 199d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 200d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE 2 201d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE 4 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds struct l2cap_cmd_hdr { 2041da177e4SLinus Torvalds __u8 code; 2051da177e4SLinus Torvalds __u8 ident; 2068e036fc3SAl Viro __le16 len; 20766c853ccSGustavo F. Padovan } __packed; 2081da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 2091da177e4SLinus Torvalds 210e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 2118e036fc3SAl Viro __le16 reason; 21266c853ccSGustavo F. Padovan } __packed; 2131da177e4SLinus Torvalds 214e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 215e2fd318eSIlia Kolomisnky __le16 reason; 216e2fd318eSIlia Kolomisnky __le16 max_mtu; 217e2fd318eSIlia Kolomisnky } __packed; 218e2fd318eSIlia Kolomisnky 219e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 220e2fd318eSIlia Kolomisnky __le16 reason; 221e2fd318eSIlia Kolomisnky __le16 scid; 222e2fd318eSIlia Kolomisnky __le16 dcid; 223e2fd318eSIlia Kolomisnky } __packed; 224e2fd318eSIlia Kolomisnky 2251da177e4SLinus Torvalds struct l2cap_conn_req { 2268e036fc3SAl Viro __le16 psm; 2278e036fc3SAl Viro __le16 scid; 22866c853ccSGustavo F. Padovan } __packed; 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds struct l2cap_conn_rsp { 2318e036fc3SAl Viro __le16 dcid; 2328e036fc3SAl Viro __le16 scid; 2338e036fc3SAl Viro __le16 result; 2348e036fc3SAl Viro __le16 status; 23566c853ccSGustavo F. Padovan } __packed; 2361da177e4SLinus Torvalds 2372983fd68SAndrei Emeltchenko /* protocol/service multiplexer (PSM) */ 2382983fd68SAndrei Emeltchenko #define L2CAP_PSM_SDP 0x0001 2392983fd68SAndrei Emeltchenko #define L2CAP_PSM_RFCOMM 0x0003 240*3124b843SMarcel Holtmann #define L2CAP_PSM_3DSP 0x0021 2412983fd68SAndrei Emeltchenko 2428db4dc46SGustavo F. Padovan /* channel indentifier */ 2438db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2448db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 245466f8004SAndrei Emeltchenko #define L2CAP_CID_A2MP 0x0003 246073d1cf3SJohan Hedberg #define L2CAP_CID_ATT 0x0004 247acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 248acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2498db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2508db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 2518db4dc46SGustavo F. Padovan 25238094c75SMat Martineau /* connect/create channel results */ 2531da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2541da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2551da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2561da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2571da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 25838094c75SMat Martineau #define L2CAP_CR_BAD_AMP 0x0005 2591da177e4SLinus Torvalds 26038094c75SMat Martineau /* connect/create channel status */ 2611da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2621da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2631da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds struct l2cap_conf_req { 2668e036fc3SAl Viro __le16 dcid; 2678e036fc3SAl Viro __le16 flags; 2681da177e4SLinus Torvalds __u8 data[0]; 26966c853ccSGustavo F. Padovan } __packed; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds struct l2cap_conf_rsp { 2728e036fc3SAl Viro __le16 scid; 2738e036fc3SAl Viro __le16 flags; 2748e036fc3SAl Viro __le16 result; 2751da177e4SLinus Torvalds __u8 data[0]; 27666c853ccSGustavo F. Padovan } __packed; 2771da177e4SLinus Torvalds 2785dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2795dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2805dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2815dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2820e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 2835a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 2841da177e4SLinus Torvalds 28559e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */ 28659e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION 0x0001 28759e54bd1SAndrei Emeltchenko 2881da177e4SLinus Torvalds struct l2cap_conf_opt { 2891da177e4SLinus Torvalds __u8 type; 2901da177e4SLinus Torvalds __u8 len; 2911da177e4SLinus Torvalds __u8 val[0]; 29266c853ccSGustavo F. Padovan } __packed; 2931da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2941da177e4SLinus Torvalds 295589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 29647ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 297589d2746SGustavo F. Padovan 2981da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2991da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 3001da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 3011da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 30247ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 3035a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 3046327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 3071da177e4SLinus Torvalds 3086464f35fSMarcel Holtmann struct l2cap_conf_rfc { 3096464f35fSMarcel Holtmann __u8 mode; 3106464f35fSMarcel Holtmann __u8 txwin_size; 3116464f35fSMarcel Holtmann __u8 max_transmit; 3126464f35fSMarcel Holtmann __le16 retrans_timeout; 3136464f35fSMarcel Holtmann __le16 monitor_timeout; 3146464f35fSMarcel Holtmann __le16 max_pdu_size; 31566c853ccSGustavo F. Padovan } __packed; 3166464f35fSMarcel Holtmann 3176464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 3186464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 3196464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 32047ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 321c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 3226464f35fSMarcel Holtmann 3235a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 3245a9e7057SAndrei Emeltchenko __u8 id; 3255a9e7057SAndrei Emeltchenko __u8 stype; 3265a9e7057SAndrei Emeltchenko __le16 msdu; 3275a9e7057SAndrei Emeltchenko __le32 sdu_itime; 3285a9e7057SAndrei Emeltchenko __le32 acc_lat; 3295a9e7057SAndrei Emeltchenko __le32 flush_to; 3305a9e7057SAndrei Emeltchenko } __packed; 3315a9e7057SAndrei Emeltchenko 3328f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 3338f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 3348f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 3358f7975b1SAndrei Emeltchenko 3368f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3378f7975b1SAndrei Emeltchenko 3381da177e4SLinus Torvalds struct l2cap_disconn_req { 3398e036fc3SAl Viro __le16 dcid; 3408e036fc3SAl Viro __le16 scid; 34166c853ccSGustavo F. Padovan } __packed; 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3448e036fc3SAl Viro __le16 dcid; 3458e036fc3SAl Viro __le16 scid; 34666c853ccSGustavo F. Padovan } __packed; 3471da177e4SLinus Torvalds 3481da177e4SLinus Torvalds struct l2cap_info_req { 3498e036fc3SAl Viro __le16 type; 35066c853ccSGustavo F. Padovan } __packed; 3511da177e4SLinus Torvalds 3521da177e4SLinus Torvalds struct l2cap_info_rsp { 3538e036fc3SAl Viro __le16 type; 3548e036fc3SAl Viro __le16 result; 3551da177e4SLinus Torvalds __u8 data[0]; 35666c853ccSGustavo F. Padovan } __packed; 3571da177e4SLinus Torvalds 35838094c75SMat Martineau struct l2cap_create_chan_req { 35938094c75SMat Martineau __le16 psm; 36038094c75SMat Martineau __le16 scid; 36138094c75SMat Martineau __u8 amp_id; 36238094c75SMat Martineau } __packed; 36338094c75SMat Martineau 36438094c75SMat Martineau struct l2cap_create_chan_rsp { 36538094c75SMat Martineau __le16 dcid; 36638094c75SMat Martineau __le16 scid; 36738094c75SMat Martineau __le16 result; 36838094c75SMat Martineau __le16 status; 36938094c75SMat Martineau } __packed; 37038094c75SMat Martineau 37138094c75SMat Martineau struct l2cap_move_chan_req { 37238094c75SMat Martineau __le16 icid; 37338094c75SMat Martineau __u8 dest_amp_id; 37438094c75SMat Martineau } __packed; 37538094c75SMat Martineau 37638094c75SMat Martineau struct l2cap_move_chan_rsp { 37738094c75SMat Martineau __le16 icid; 37838094c75SMat Martineau __le16 result; 37938094c75SMat Martineau } __packed; 38038094c75SMat Martineau 38138094c75SMat Martineau #define L2CAP_MR_SUCCESS 0x0000 38238094c75SMat Martineau #define L2CAP_MR_PEND 0x0001 38338094c75SMat Martineau #define L2CAP_MR_BAD_ID 0x0002 38438094c75SMat Martineau #define L2CAP_MR_SAME_ID 0x0003 38538094c75SMat Martineau #define L2CAP_MR_NOT_SUPP 0x0004 38638094c75SMat Martineau #define L2CAP_MR_COLLISION 0x0005 38738094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED 0x0006 38838094c75SMat Martineau 38938094c75SMat Martineau struct l2cap_move_chan_cfm { 39038094c75SMat Martineau __le16 icid; 39138094c75SMat Martineau __le16 result; 39238094c75SMat Martineau } __packed; 39338094c75SMat Martineau 39438094c75SMat Martineau #define L2CAP_MC_CONFIRMED 0x0000 39538094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED 0x0001 39638094c75SMat Martineau 39738094c75SMat Martineau struct l2cap_move_chan_cfm_rsp { 39838094c75SMat Martineau __le16 icid; 39938094c75SMat Martineau } __packed; 40038094c75SMat Martineau 4011da177e4SLinus Torvalds /* info type */ 4021da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 4031da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 404e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds /* info result */ 4071da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 4081da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 4091da177e4SLinus Torvalds 410de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 411de73115aSClaudio Takahasi __le16 min; 412de73115aSClaudio Takahasi __le16 max; 413de73115aSClaudio Takahasi __le16 latency; 414de73115aSClaudio Takahasi __le16 to_multiplier; 415de73115aSClaudio Takahasi } __packed; 416de73115aSClaudio Takahasi 417de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 418de73115aSClaudio Takahasi __le16 result; 419de73115aSClaudio Takahasi } __packed; 420de73115aSClaudio Takahasi 421de73115aSClaudio Takahasi /* Connection Parameters result */ 422de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 423de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 424de73115aSClaudio Takahasi 42548454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 4263c588192SMat Martineau struct l2cap_seq_list { 4273c588192SMat Martineau __u16 head; 4283c588192SMat Martineau __u16 tail; 4293c588192SMat Martineau __u16 mask; 4303c588192SMat Martineau __u16 *list; 4313c588192SMat Martineau }; 4323c588192SMat Martineau 4333c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR 0xFFFF 4343c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL 0x8000 4353c588192SMat Martineau 43648454079SGustavo F. Padovan struct l2cap_chan { 43748454079SGustavo F. Padovan struct sock *sk; 4388c1d787bSGustavo F. Padovan 4398c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 44008333283SMat Martineau struct hci_conn *hs_hcon; 44108333283SMat Martineau struct hci_chan *hs_hchan; 442144ad330SSyam Sidhardhan struct kref kref; 4438c1d787bSGustavo F. Padovan 44489bc500eSGustavo F. Padovan __u8 state; 44589bc500eSGustavo F. Padovan 446fe4128e0SGustavo F. Padovan __le16 psm; 447fe4128e0SGustavo F. Padovan __u16 dcid; 448fe4128e0SGustavo F. Padovan __u16 scid; 4494343478fSGustavo F. Padovan 4500c1bc5c6SGustavo F. Padovan __u16 imtu; 4510c1bc5c6SGustavo F. Padovan __u16 omtu; 4520c1bc5c6SGustavo F. Padovan __u16 flush_to; 4530c1bc5c6SGustavo F. Padovan __u8 mode; 454715ec005SGustavo F. Padovan __u8 chan_type; 4552ea66482SMat Martineau __u8 chan_policy; 4560c1bc5c6SGustavo F. Padovan 4570c1bc5c6SGustavo F. Padovan __le16 sport; 4580c1bc5c6SGustavo F. Padovan 4594343478fSGustavo F. Padovan __u8 sec_level; 4604343478fSGustavo F. Padovan 461fc7f8a7eSGustavo F. Padovan __u8 ident; 462fc7f8a7eSGustavo F. Padovan 46373ffa904SGustavo F. Padovan __u8 conf_req[64]; 46473ffa904SGustavo F. Padovan __u8 conf_len; 46573ffa904SGustavo F. Padovan __u8 num_conf_req; 46673ffa904SGustavo F. Padovan __u8 num_conf_rsp; 46773ffa904SGustavo F. Padovan 46847d1ec61SGustavo F. Padovan __u8 fcs; 46947d1ec61SGustavo F. Padovan 4706327eb98SAndrei Emeltchenko __u16 tx_win; 471836be934SAndrei Emeltchenko __u16 tx_win_max; 472c20f8e35SMat Martineau __u16 ack_win; 47347d1ec61SGustavo F. Padovan __u8 max_tx; 47447d1ec61SGustavo F. Padovan __u16 retrans_timeout; 47547d1ec61SGustavo F. Padovan __u16 monitor_timeout; 47647d1ec61SGustavo F. Padovan __u16 mps; 47747d1ec61SGustavo F. Padovan 478d5f7ac38SMat Martineau __u8 tx_state; 479d5f7ac38SMat Martineau __u8 rx_state; 480d5f7ac38SMat Martineau 481c1360a1cSGustavo F. Padovan unsigned long conf_state; 482e2ab4353SGustavo F. Padovan unsigned long conn_state; 483d57b0e8bSAndrei Emeltchenko unsigned long flags; 484525cd185SGustavo F. Padovan 485fffadc08SAndrei Emeltchenko __u8 remote_amp_id; 48608333283SMat Martineau __u8 local_amp_id; 48708333283SMat Martineau __u8 move_id; 48808333283SMat Martineau __u8 move_state; 48908333283SMat Martineau __u8 move_role; 49008333283SMat Martineau 491fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 492fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 493fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 4940b209faeSAndrei Emeltchenko __u16 buffer_seq; 495fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 496d5f7ac38SMat Martineau __u16 last_acked_seq; 497fb45de7dSAndrei Emeltchenko __u16 frames_sent; 498fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 4996a026610SGustavo F. Padovan __u8 retry_count; 5006f61fd47SGustavo F. Padovan __u16 sdu_len; 5016f61fd47SGustavo F. Padovan struct sk_buff *sdu; 50284084a31SMat Martineau struct sk_buff *sdu_last_frag; 5036f61fd47SGustavo F. Padovan 5046327eb98SAndrei Emeltchenko __u16 remote_tx_win; 5052c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 5062c03a7a4SGustavo F. Padovan __u16 remote_mps; 50742e5c802SGustavo F. Padovan 5085a9e7057SAndrei Emeltchenko __u8 local_id; 5095a9e7057SAndrei Emeltchenko __u8 local_stype; 5105a9e7057SAndrei Emeltchenko __u16 local_msdu; 5115a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 5125a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 5135a9e7057SAndrei Emeltchenko __u32 local_flush_to; 5145a9e7057SAndrei Emeltchenko 5155a9e7057SAndrei Emeltchenko __u8 remote_id; 5165a9e7057SAndrei Emeltchenko __u8 remote_stype; 5175a9e7057SAndrei Emeltchenko __u16 remote_msdu; 5185a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 5195a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 5205a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 5215a9e7057SAndrei Emeltchenko 522721c4181SGustavo F. Padovan struct delayed_work chan_timer; 523721c4181SGustavo F. Padovan struct delayed_work retrans_timer; 524721c4181SGustavo F. Padovan struct delayed_work monitor_timer; 525721c4181SGustavo F. Padovan struct delayed_work ack_timer; 526721c4181SGustavo F. Padovan 52758d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 52858d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 529f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 5303c588192SMat Martineau struct l2cap_seq_list srej_list; 5313c588192SMat Martineau struct l2cap_seq_list retrans_list; 532e92c8e70SGustavo F. Padovan 533baa7e1faSGustavo F. Padovan struct list_head list; 53423691d75SGustavo F. Padovan struct list_head global_l; 53580808e43SGustavo F. Padovan 53680808e43SGustavo F. Padovan void *data; 53780808e43SGustavo F. Padovan struct l2cap_ops *ops; 538c03b355eSAndrei Emeltchenko struct mutex lock; 53980808e43SGustavo F. Padovan }; 54080808e43SGustavo F. Padovan 54180808e43SGustavo F. Padovan struct l2cap_ops { 54280808e43SGustavo F. Padovan char *name; 54380808e43SGustavo F. Padovan 54480b98027SGustavo Padovan struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan); 54580b98027SGustavo Padovan int (*recv) (struct l2cap_chan * chan, 54680b98027SGustavo Padovan struct sk_buff *skb); 547c0df7f6eSAndrei Emeltchenko void (*teardown) (struct l2cap_chan *chan, int err); 54880b98027SGustavo Padovan void (*close) (struct l2cap_chan *chan); 54980b98027SGustavo Padovan void (*state_change) (struct l2cap_chan *chan, 55080b98027SGustavo Padovan int state); 55154a59aa2SAndrei Emeltchenko void (*ready) (struct l2cap_chan *chan); 5522dc4e510SGustavo Padovan void (*defer) (struct l2cap_chan *chan); 5532f7719ceSAndrei Emeltchenko struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 55490338947SGustavo Padovan unsigned long len, int nb); 5551da177e4SLinus Torvalds }; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds struct l2cap_conn { 5581da177e4SLinus Torvalds struct hci_conn *hcon; 55973d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds bdaddr_t *dst; 5621da177e4SLinus Torvalds bdaddr_t *src; 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds unsigned int mtu; 5651da177e4SLinus Torvalds 5664e8402a3SMarcel Holtmann __u32 feat_mask; 567978c93b9SAndrei Emeltchenko __u8 fixed_chan_mask; 568848566b3SMarcel Holtmann bool hs_enabled; 5694e8402a3SMarcel Holtmann 5704e8402a3SMarcel Holtmann __u8 info_state; 5714e8402a3SMarcel Holtmann __u8 info_ident; 5724e8402a3SMarcel Holtmann 573030013d8SGustavo F. Padovan struct delayed_work info_timer; 5744e8402a3SMarcel Holtmann 5751da177e4SLinus Torvalds spinlock_t lock; 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds struct sk_buff *rx_skb; 5781da177e4SLinus Torvalds __u32 rx_len; 5791da177e4SLinus Torvalds __u8 tx_ident; 5801da177e4SLinus Torvalds 5812950f21aSMarcel Holtmann __u8 disc_reason; 5822950f21aSMarcel Holtmann 5836c9d42a1SGustavo F. Padovan struct delayed_work security_timer; 5841c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 5855d3de7dfSVinicius Costa Gomes 586baa7e1faSGustavo F. Padovan struct list_head chan_l; 587d01b2ff4SGustavo F. Padovan struct mutex chan_lock; 5889c903e37SDavid Herrmann struct kref ref; 5892c8e1411SDavid Herrmann struct list_head users; 5902c8e1411SDavid Herrmann }; 5912c8e1411SDavid Herrmann 5922c8e1411SDavid Herrmann struct l2cap_user { 5932c8e1411SDavid Herrmann struct list_head list; 5942c8e1411SDavid Herrmann int (*probe) (struct l2cap_conn *conn, struct l2cap_user *user); 5952c8e1411SDavid Herrmann void (*remove) (struct l2cap_conn *conn, struct l2cap_user *user); 5961da177e4SLinus Torvalds }; 5971da177e4SLinus Torvalds 5984e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 599984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 600984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 6014e8402a3SMarcel Holtmann 602715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 603715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 604715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 605416fa752SAndrei Emeltchenko #define L2CAP_CHAN_CONN_FIX_A2MP 4 606715ec005SGustavo F. Padovan 60748454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 6081da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds struct l2cap_pinfo { 6111da177e4SLinus Torvalds struct bt_sock bt; 61248454079SGustavo F. Padovan struct l2cap_chan *chan; 613e328140fSMat Martineau struct sk_buff *rx_busy_skb; 6141da177e4SLinus Torvalds }; 6151da177e4SLinus Torvalds 616c1360a1cSGustavo F. Padovan enum { 617c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 618c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 619c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 620c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 621c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 622c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 623f2592d3eSAndrei Emeltchenko CONF_RECV_NO_FCS, 624c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 6256327eb98SAndrei Emeltchenko CONF_EWS_RECV, 6260e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 6270e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 6282827011fSMat Martineau CONF_NOT_COMPLETE, 629c1360a1cSGustavo F. Padovan }; 630861d6882SMarcel Holtmann 631f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 632f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 633f2fcfcd6SGustavo F. Padovan 634e2ab4353SGustavo F. Padovan enum { 635e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 636e2ab4353SGustavo F. Padovan CONN_WAIT_F, 637e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 638e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 639e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 640e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 641e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 642e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 643e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 644e2ab4353SGustavo F. Padovan }; 645e90bac06SGustavo F. Padovan 646d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 647d57b0e8bSAndrei Emeltchenko enum { 64843bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 64915770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 650ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 651d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 6526327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 6535a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 654d57b0e8bSAndrei Emeltchenko }; 655d57b0e8bSAndrei Emeltchenko 656d5f7ac38SMat Martineau enum { 657d5f7ac38SMat Martineau L2CAP_TX_STATE_XMIT, 658d5f7ac38SMat Martineau L2CAP_TX_STATE_WAIT_F, 659d5f7ac38SMat Martineau }; 660d5f7ac38SMat Martineau 661d5f7ac38SMat Martineau enum { 662d5f7ac38SMat Martineau L2CAP_RX_STATE_RECV, 663d5f7ac38SMat Martineau L2CAP_RX_STATE_SREJ_SENT, 66408333283SMat Martineau L2CAP_RX_STATE_MOVE, 66508333283SMat Martineau L2CAP_RX_STATE_WAIT_P, 66608333283SMat Martineau L2CAP_RX_STATE_WAIT_F, 667d5f7ac38SMat Martineau }; 668d5f7ac38SMat Martineau 669d5f7ac38SMat Martineau enum { 670d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED, 671d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED_SREJ, 672d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED, 673d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED_SREJ, 674d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE, 675d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE_SREJ, 676d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID, 677d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID_IGNORE, 678d5f7ac38SMat Martineau }; 679d5f7ac38SMat Martineau 680d5f7ac38SMat Martineau enum { 681d5f7ac38SMat Martineau L2CAP_EV_DATA_REQUEST, 682d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_DETECTED, 683d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_CLEAR, 684d5f7ac38SMat Martineau L2CAP_EV_RECV_REQSEQ_AND_FBIT, 685d5f7ac38SMat Martineau L2CAP_EV_RECV_FBIT, 686d5f7ac38SMat Martineau L2CAP_EV_RETRANS_TO, 687d5f7ac38SMat Martineau L2CAP_EV_MONITOR_TO, 688d5f7ac38SMat Martineau L2CAP_EV_EXPLICIT_POLL, 689d5f7ac38SMat Martineau L2CAP_EV_RECV_IFRAME, 690d5f7ac38SMat Martineau L2CAP_EV_RECV_RR, 691d5f7ac38SMat Martineau L2CAP_EV_RECV_REJ, 692d5f7ac38SMat Martineau L2CAP_EV_RECV_RNR, 693d5f7ac38SMat Martineau L2CAP_EV_RECV_SREJ, 694d5f7ac38SMat Martineau L2CAP_EV_RECV_FRAME, 695d5f7ac38SMat Martineau }; 696d5f7ac38SMat Martineau 69708333283SMat Martineau enum { 69808333283SMat Martineau L2CAP_MOVE_ROLE_NONE, 69908333283SMat Martineau L2CAP_MOVE_ROLE_INITIATOR, 70008333283SMat Martineau L2CAP_MOVE_ROLE_RESPONDER, 70108333283SMat Martineau }; 70208333283SMat Martineau 70308333283SMat Martineau enum { 70408333283SMat Martineau L2CAP_MOVE_STABLE, 70508333283SMat Martineau L2CAP_MOVE_WAIT_REQ, 70608333283SMat Martineau L2CAP_MOVE_WAIT_RSP, 70708333283SMat Martineau L2CAP_MOVE_WAIT_RSP_SUCCESS, 70808333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM, 70908333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM_RSP, 71008333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_COMP, 71108333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_CFM, 71208333283SMat Martineau L2CAP_MOVE_WAIT_LOCAL_BUSY, 71308333283SMat Martineau L2CAP_MOVE_WAIT_PREPARE, 71408333283SMat Martineau }; 71508333283SMat Martineau 71630648372SJaganath Kanakkassery void l2cap_chan_hold(struct l2cap_chan *c); 71730648372SJaganath Kanakkassery void l2cap_chan_put(struct l2cap_chan *c); 718371fd835SUlisses Furquim 719c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan) 720c03b355eSAndrei Emeltchenko { 721c03b355eSAndrei Emeltchenko mutex_lock(&chan->lock); 722c03b355eSAndrei Emeltchenko } 723c03b355eSAndrei Emeltchenko 724c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 725c03b355eSAndrei Emeltchenko { 726c03b355eSAndrei Emeltchenko mutex_unlock(&chan->lock); 727c03b355eSAndrei Emeltchenko } 728c03b355eSAndrei Emeltchenko 729c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan, 730c2ec9c1bSGustavo F. Padovan struct delayed_work *work, long timeout) 731c2ec9c1bSGustavo F. Padovan { 732e05dcc32SAndrei Emeltchenko BT_DBG("chan %p state %s timeout %ld", chan, 733e05dcc32SAndrei Emeltchenko state_to_string(chan->state), timeout); 734c2ec9c1bSGustavo F. Padovan 7356f74b6f3SAndrei Emeltchenko /* If delayed work cancelled do not hold(chan) 7366f74b6f3SAndrei Emeltchenko since it is already done with previous set_timer */ 73717cd3f37SUlisses Furquim if (!cancel_delayed_work(work)) 738371fd835SUlisses Furquim l2cap_chan_hold(chan); 7396f74b6f3SAndrei Emeltchenko 740c2ec9c1bSGustavo F. Padovan schedule_delayed_work(work, timeout); 741c2ec9c1bSGustavo F. Padovan } 742c2ec9c1bSGustavo F. Padovan 74375b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan, 744371fd835SUlisses Furquim struct delayed_work *work) 745c2ec9c1bSGustavo F. Padovan { 74675b93b59SSzymon Janc bool ret; 74775b93b59SSzymon Janc 7486f74b6f3SAndrei Emeltchenko /* put(chan) if delayed work cancelled otherwise it 7496f74b6f3SAndrei Emeltchenko is done in delayed work function */ 75017cd3f37SUlisses Furquim ret = cancel_delayed_work(work); 75175b93b59SSzymon Janc if (ret) 752371fd835SUlisses Furquim l2cap_chan_put(chan); 75375b93b59SSzymon Janc 75475b93b59SSzymon Janc return ret; 755c2ec9c1bSGustavo F. Padovan } 756c2ec9c1bSGustavo F. Padovan 757c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 758c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 7591a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 7601a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 7611a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 762b83ddfe2SAndrzej Kaczmarek msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 7631a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 764c74e560cSGustavo F. Padovan 765836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 766836be934SAndrei Emeltchenko { 7675a364bd3SMat Martineau if (seq1 >= seq2) 7685a364bd3SMat Martineau return seq1 - seq2; 7695a364bd3SMat Martineau else 7705a364bd3SMat Martineau return chan->tx_win_max + 1 - seq2 + seq1; 771836be934SAndrei Emeltchenko } 772836be934SAndrei Emeltchenko 773836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 774836be934SAndrei Emeltchenko { 775836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 776836be934SAndrei Emeltchenko } 777836be934SAndrei Emeltchenko 7787e1af8a3SGustavo Padovan static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chan *chan) 7797e1af8a3SGustavo Padovan { 7807e1af8a3SGustavo Padovan return NULL; 7817e1af8a3SGustavo Padovan } 7827e1af8a3SGustavo Padovan 7837e1af8a3SGustavo Padovan static inline void l2cap_chan_no_teardown(struct l2cap_chan *chan, int err) 7847e1af8a3SGustavo Padovan { 7857e1af8a3SGustavo Padovan } 7867e1af8a3SGustavo Padovan 7877e1af8a3SGustavo Padovan static inline void l2cap_chan_no_ready(struct l2cap_chan *chan) 7887e1af8a3SGustavo Padovan { 7897e1af8a3SGustavo Padovan } 7901da177e4SLinus Torvalds 7912dc4e510SGustavo Padovan static inline void l2cap_chan_no_defer(struct l2cap_chan *chan) 7922dc4e510SGustavo Padovan { 7932dc4e510SGustavo Padovan } 7942dc4e510SGustavo Padovan 795eb939922SRusty Russell extern bool disable_ertm; 796bb58f747SGustavo F. Padovan 797bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 798bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 799b3916db3SDavid Herrmann bool l2cap_is_socket(struct socket *sock); 800bb58f747SGustavo F. Padovan 8018c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 802dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 80368983259SGustavo F. Padovan 8049e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 8059e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 8069e4425ffSGustavo F. Padovan 807eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void); 8080f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 809cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 8108e9f9892SAndre Guedes bdaddr_t *dst, u8 dst_type); 8115e59b791SLuiz Augusto von Dentz int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 8125e59b791SLuiz Augusto von Dentz u32 priority); 813e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 814d45fc423SGustavo F. Padovan int l2cap_chan_check_security(struct l2cap_chan *chan); 815bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan); 816466f8004SAndrei Emeltchenko int l2cap_ertm_init(struct l2cap_chan *chan); 817466f8004SAndrei Emeltchenko void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 81893c3e8f5SAndrei Emeltchenko void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 819466f8004SAndrei Emeltchenko void l2cap_chan_del(struct l2cap_chan *chan, int err); 8202766be48SAndrei Emeltchenko void l2cap_send_conn_req(struct l2cap_chan *chan); 8213f7a56c4SMat Martineau void l2cap_move_start(struct l2cap_chan *chan); 82227695fb4SAndrei Emeltchenko void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, 82327695fb4SAndrei Emeltchenko u8 status); 824a514b17fSAndrei Emeltchenko void __l2cap_physical_cfm(struct l2cap_chan *chan, int result); 825bb58f747SGustavo F. Padovan 8269c903e37SDavid Herrmann void l2cap_conn_get(struct l2cap_conn *conn); 8279c903e37SDavid Herrmann void l2cap_conn_put(struct l2cap_conn *conn); 8289c903e37SDavid Herrmann 8292c8e1411SDavid Herrmann int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); 8302c8e1411SDavid Herrmann void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user); 8312c8e1411SDavid Herrmann 8321da177e4SLinus Torvalds #endif /* __L2CAP_H */ 833