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 94*7d513e92SMarcel Holtmann #define L2CAP_LM_FIPS 0x0040 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds /* L2CAP command codes */ 971da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 981da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 991da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 1001da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 1011da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 1021da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 1031da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 1041da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 1051da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 1061da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 1071da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 10838094c75SMat Martineau #define L2CAP_CREATE_CHAN_REQ 0x0c 10938094c75SMat Martineau #define L2CAP_CREATE_CHAN_RSP 0x0d 11038094c75SMat Martineau #define L2CAP_MOVE_CHAN_REQ 0x0e 11138094c75SMat Martineau #define L2CAP_MOVE_CHAN_RSP 0x0f 11238094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM 0x10 11338094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM_RSP 0x11 1143300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 1153300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 116ee5ec5cfSJohan Hedberg #define L2CAP_LE_CONN_REQ 0x14 117ee5ec5cfSJohan Hedberg #define L2CAP_LE_CONN_RSP 0x15 118ee5ec5cfSJohan Hedberg #define L2CAP_LE_CREDITS 0x16 1191da177e4SLinus Torvalds 120a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 12147ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 12247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 123a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 12447ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 12547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 12647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 127a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 12847ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 129a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 130a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 13147ec1dcdSMarcel Holtmann 13247ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 13347ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 13447ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 13547ec1dcdSMarcel Holtmann 136d835ac0fSMat Martineau /* L2CAP fixed channels */ 137d835ac0fSMat Martineau #define L2CAP_FC_L2CAP 0x02 138d40bffbcSMarcel Holtmann #define L2CAP_FC_CONNLESS 0x04 139d835ac0fSMat Martineau #define L2CAP_FC_A2MP 0x08 14018722c24SJukka Rissanen #define L2CAP_FC_6LOWPAN 0x3e /* reserved and temporary value */ 141d835ac0fSMat Martineau 1421c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1431c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1441c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1451c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 14657253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 14757253fd8SAndrei Emeltchenko 1481c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1491c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1501c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1511c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1521c2acffbSGustavo F. Padovan 1531c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 15457253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 155d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT 4 156d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT 7 1571c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1588f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1591c2acffbSGustavo F. Padovan 16057253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 16157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 16257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 16357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 16457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 16557253fd8SAndrei Emeltchenko 16657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 16757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 16857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 16957253fd8SAndrei Emeltchenko 170d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT 1 17157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 17257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 17357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 174d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT 18 17557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 17657253fd8SAndrei Emeltchenko 1771c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 178ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 179ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 180ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 181ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1821c2acffbSGustavo F. Padovan 1831c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1847e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1857e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1867e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1877e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1881c2acffbSGustavo F. Padovan 189e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 190e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 191e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 192e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 193e2fd318eSIlia Kolomisnky 1941da177e4SLinus Torvalds /* L2CAP structures */ 1951da177e4SLinus Torvalds struct l2cap_hdr { 1968e036fc3SAl Viro __le16 len; 1978e036fc3SAl Viro __le16 cid; 19866c853ccSGustavo F. Padovan } __packed; 1991da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 200d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 201d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 202d43cb289SAndrei Emeltchenko 203d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 204d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 205d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 206d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE 2 207d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE 4 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds struct l2cap_cmd_hdr { 2101da177e4SLinus Torvalds __u8 code; 2111da177e4SLinus Torvalds __u8 ident; 2128e036fc3SAl Viro __le16 len; 21366c853ccSGustavo F. Padovan } __packed; 2141da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 2151da177e4SLinus Torvalds 216e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 2178e036fc3SAl Viro __le16 reason; 21866c853ccSGustavo F. Padovan } __packed; 2191da177e4SLinus Torvalds 220e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 221e2fd318eSIlia Kolomisnky __le16 reason; 222e2fd318eSIlia Kolomisnky __le16 max_mtu; 223e2fd318eSIlia Kolomisnky } __packed; 224e2fd318eSIlia Kolomisnky 225e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 226e2fd318eSIlia Kolomisnky __le16 reason; 227e2fd318eSIlia Kolomisnky __le16 scid; 228e2fd318eSIlia Kolomisnky __le16 dcid; 229e2fd318eSIlia Kolomisnky } __packed; 230e2fd318eSIlia Kolomisnky 2311da177e4SLinus Torvalds struct l2cap_conn_req { 2328e036fc3SAl Viro __le16 psm; 2338e036fc3SAl Viro __le16 scid; 23466c853ccSGustavo F. Padovan } __packed; 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds struct l2cap_conn_rsp { 2378e036fc3SAl Viro __le16 dcid; 2388e036fc3SAl Viro __le16 scid; 2398e036fc3SAl Viro __le16 result; 2408e036fc3SAl Viro __le16 status; 24166c853ccSGustavo F. Padovan } __packed; 2421da177e4SLinus Torvalds 2432983fd68SAndrei Emeltchenko /* protocol/service multiplexer (PSM) */ 2442983fd68SAndrei Emeltchenko #define L2CAP_PSM_SDP 0x0001 2452983fd68SAndrei Emeltchenko #define L2CAP_PSM_RFCOMM 0x0003 2463124b843SMarcel Holtmann #define L2CAP_PSM_3DSP 0x0021 2472983fd68SAndrei Emeltchenko 2483f79410cSMaxime Jayat /* channel identifier */ 2498db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2508db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 251466f8004SAndrei Emeltchenko #define L2CAP_CID_A2MP 0x0003 252073d1cf3SJohan Hedberg #define L2CAP_CID_ATT 0x0004 253acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 254acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2558db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2568db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 257e77af755SJohan Hedberg #define L2CAP_CID_LE_DYN_END 0x007f 2588db4dc46SGustavo F. Padovan 25938094c75SMat Martineau /* connect/create channel results */ 2601da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2611da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2621da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2631da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2641da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 26538094c75SMat Martineau #define L2CAP_CR_BAD_AMP 0x0005 266ee5ec5cfSJohan Hedberg #define L2CAP_CR_AUTHENTICATION 0x0005 267ee5ec5cfSJohan Hedberg #define L2CAP_CR_AUTHORIZATION 0x0006 268ee5ec5cfSJohan Hedberg #define L2CAP_CR_BAD_KEY_SIZE 0x0007 269ee5ec5cfSJohan Hedberg #define L2CAP_CR_ENCRYPTION 0x0008 2701da177e4SLinus Torvalds 27138094c75SMat Martineau /* connect/create channel status */ 2721da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2731da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2741da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds struct l2cap_conf_req { 2778e036fc3SAl Viro __le16 dcid; 2788e036fc3SAl Viro __le16 flags; 2791da177e4SLinus Torvalds __u8 data[0]; 28066c853ccSGustavo F. Padovan } __packed; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds struct l2cap_conf_rsp { 2838e036fc3SAl Viro __le16 scid; 2848e036fc3SAl Viro __le16 flags; 2858e036fc3SAl Viro __le16 result; 2861da177e4SLinus Torvalds __u8 data[0]; 28766c853ccSGustavo F. Padovan } __packed; 2881da177e4SLinus Torvalds 2895dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2905dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2915dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2925dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2930e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 2945a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 2951da177e4SLinus Torvalds 29659e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */ 29759e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION 0x0001 29859e54bd1SAndrei Emeltchenko 2991da177e4SLinus Torvalds struct l2cap_conf_opt { 3001da177e4SLinus Torvalds __u8 type; 3011da177e4SLinus Torvalds __u8 len; 3021da177e4SLinus Torvalds __u8 val[0]; 30366c853ccSGustavo F. Padovan } __packed; 3041da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 3051da177e4SLinus Torvalds 306589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 30747ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 308589d2746SGustavo F. Padovan 3091da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 3101da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 3111da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 3121da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 31347ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 3145a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 3156327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 3181da177e4SLinus Torvalds 3196464f35fSMarcel Holtmann struct l2cap_conf_rfc { 3206464f35fSMarcel Holtmann __u8 mode; 3216464f35fSMarcel Holtmann __u8 txwin_size; 3226464f35fSMarcel Holtmann __u8 max_transmit; 3236464f35fSMarcel Holtmann __le16 retrans_timeout; 3246464f35fSMarcel Holtmann __le16 monitor_timeout; 3256464f35fSMarcel Holtmann __le16 max_pdu_size; 32666c853ccSGustavo F. Padovan } __packed; 3276464f35fSMarcel Holtmann 3286464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 3296464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 3306464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 33147ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 332c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 3336464f35fSMarcel Holtmann 33438319713SJohan Hedberg /* Unlike the above this one doesn't actually map to anything that would 33538319713SJohan Hedberg * ever be sent over the air. Therefore, use a value that's unlikely to 33638319713SJohan Hedberg * ever be used in the BR/EDR configuration phase. 33738319713SJohan Hedberg */ 33838319713SJohan Hedberg #define L2CAP_MODE_LE_FLOWCTL 0x80 33938319713SJohan Hedberg 3405a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 3415a9e7057SAndrei Emeltchenko __u8 id; 3425a9e7057SAndrei Emeltchenko __u8 stype; 3435a9e7057SAndrei Emeltchenko __le16 msdu; 3445a9e7057SAndrei Emeltchenko __le32 sdu_itime; 3455a9e7057SAndrei Emeltchenko __le32 acc_lat; 3465a9e7057SAndrei Emeltchenko __le32 flush_to; 3475a9e7057SAndrei Emeltchenko } __packed; 3485a9e7057SAndrei Emeltchenko 3498f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 3508f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 3518f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 3528f7975b1SAndrei Emeltchenko 3538f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3548f7975b1SAndrei Emeltchenko 3551da177e4SLinus Torvalds struct l2cap_disconn_req { 3568e036fc3SAl Viro __le16 dcid; 3578e036fc3SAl Viro __le16 scid; 35866c853ccSGustavo F. Padovan } __packed; 3591da177e4SLinus Torvalds 3601da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3618e036fc3SAl Viro __le16 dcid; 3628e036fc3SAl Viro __le16 scid; 36366c853ccSGustavo F. Padovan } __packed; 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds struct l2cap_info_req { 3668e036fc3SAl Viro __le16 type; 36766c853ccSGustavo F. Padovan } __packed; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvalds struct l2cap_info_rsp { 3708e036fc3SAl Viro __le16 type; 3718e036fc3SAl Viro __le16 result; 3721da177e4SLinus Torvalds __u8 data[0]; 37366c853ccSGustavo F. Padovan } __packed; 3741da177e4SLinus Torvalds 37538094c75SMat Martineau struct l2cap_create_chan_req { 37638094c75SMat Martineau __le16 psm; 37738094c75SMat Martineau __le16 scid; 37838094c75SMat Martineau __u8 amp_id; 37938094c75SMat Martineau } __packed; 38038094c75SMat Martineau 38138094c75SMat Martineau struct l2cap_create_chan_rsp { 38238094c75SMat Martineau __le16 dcid; 38338094c75SMat Martineau __le16 scid; 38438094c75SMat Martineau __le16 result; 38538094c75SMat Martineau __le16 status; 38638094c75SMat Martineau } __packed; 38738094c75SMat Martineau 38838094c75SMat Martineau struct l2cap_move_chan_req { 38938094c75SMat Martineau __le16 icid; 39038094c75SMat Martineau __u8 dest_amp_id; 39138094c75SMat Martineau } __packed; 39238094c75SMat Martineau 39338094c75SMat Martineau struct l2cap_move_chan_rsp { 39438094c75SMat Martineau __le16 icid; 39538094c75SMat Martineau __le16 result; 39638094c75SMat Martineau } __packed; 39738094c75SMat Martineau 39838094c75SMat Martineau #define L2CAP_MR_SUCCESS 0x0000 39938094c75SMat Martineau #define L2CAP_MR_PEND 0x0001 40038094c75SMat Martineau #define L2CAP_MR_BAD_ID 0x0002 40138094c75SMat Martineau #define L2CAP_MR_SAME_ID 0x0003 40238094c75SMat Martineau #define L2CAP_MR_NOT_SUPP 0x0004 40338094c75SMat Martineau #define L2CAP_MR_COLLISION 0x0005 40438094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED 0x0006 40538094c75SMat Martineau 40638094c75SMat Martineau struct l2cap_move_chan_cfm { 40738094c75SMat Martineau __le16 icid; 40838094c75SMat Martineau __le16 result; 40938094c75SMat Martineau } __packed; 41038094c75SMat Martineau 41138094c75SMat Martineau #define L2CAP_MC_CONFIRMED 0x0000 41238094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED 0x0001 41338094c75SMat Martineau 41438094c75SMat Martineau struct l2cap_move_chan_cfm_rsp { 41538094c75SMat Martineau __le16 icid; 41638094c75SMat Martineau } __packed; 41738094c75SMat Martineau 4181da177e4SLinus Torvalds /* info type */ 4191da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 4201da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 421e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds /* info result */ 4241da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 4251da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 4261da177e4SLinus Torvalds 427de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 428de73115aSClaudio Takahasi __le16 min; 429de73115aSClaudio Takahasi __le16 max; 430de73115aSClaudio Takahasi __le16 latency; 431de73115aSClaudio Takahasi __le16 to_multiplier; 432de73115aSClaudio Takahasi } __packed; 433de73115aSClaudio Takahasi 434de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 435de73115aSClaudio Takahasi __le16 result; 436de73115aSClaudio Takahasi } __packed; 437de73115aSClaudio Takahasi 438de73115aSClaudio Takahasi /* Connection Parameters result */ 439de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 440de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 441de73115aSClaudio Takahasi 442ee5ec5cfSJohan Hedberg #define L2CAP_LE_MAX_CREDITS 10 443ee5ec5cfSJohan Hedberg #define L2CAP_LE_DEFAULT_MPS 230 444ee5ec5cfSJohan Hedberg 445ee5ec5cfSJohan Hedberg struct l2cap_le_conn_req { 446ee5ec5cfSJohan Hedberg __le16 psm; 447ee5ec5cfSJohan Hedberg __le16 scid; 448ee5ec5cfSJohan Hedberg __le16 mtu; 449ee5ec5cfSJohan Hedberg __le16 mps; 450ee5ec5cfSJohan Hedberg __le16 credits; 451ee5ec5cfSJohan Hedberg } __packed; 452ee5ec5cfSJohan Hedberg 453ee5ec5cfSJohan Hedberg struct l2cap_le_conn_rsp { 454ee5ec5cfSJohan Hedberg __le16 dcid; 455ee5ec5cfSJohan Hedberg __le16 mtu; 456ee5ec5cfSJohan Hedberg __le16 mps; 457ee5ec5cfSJohan Hedberg __le16 credits; 458ee5ec5cfSJohan Hedberg __le16 result; 459ee5ec5cfSJohan Hedberg } __packed; 460ee5ec5cfSJohan Hedberg 461ee5ec5cfSJohan Hedberg struct l2cap_le_credits { 462ee5ec5cfSJohan Hedberg __le16 cid; 463ee5ec5cfSJohan Hedberg __le16 credits; 464ee5ec5cfSJohan Hedberg } __packed; 465ee5ec5cfSJohan Hedberg 46648454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 4673c588192SMat Martineau struct l2cap_seq_list { 4683c588192SMat Martineau __u16 head; 4693c588192SMat Martineau __u16 tail; 4703c588192SMat Martineau __u16 mask; 4713c588192SMat Martineau __u16 *list; 4723c588192SMat Martineau }; 4733c588192SMat Martineau 4743c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR 0xFFFF 4753c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL 0x8000 4763c588192SMat Martineau 47748454079SGustavo F. Padovan struct l2cap_chan { 4788c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 47908333283SMat Martineau struct hci_conn *hs_hcon; 48008333283SMat Martineau struct hci_chan *hs_hchan; 481144ad330SSyam Sidhardhan struct kref kref; 4828c1d787bSGustavo F. Padovan 48389bc500eSGustavo F. Padovan __u8 state; 48489bc500eSGustavo F. Padovan 4857eafc59eSMarcel Holtmann bdaddr_t dst; 4864f1654e0SMarcel Holtmann __u8 dst_type; 4877eafc59eSMarcel Holtmann bdaddr_t src; 4884f1654e0SMarcel Holtmann __u8 src_type; 489fe4128e0SGustavo F. Padovan __le16 psm; 4904f1654e0SMarcel Holtmann __le16 sport; 491fe4128e0SGustavo F. Padovan __u16 dcid; 492fe4128e0SGustavo F. Padovan __u16 scid; 4934343478fSGustavo F. Padovan 4940c1bc5c6SGustavo F. Padovan __u16 imtu; 4950c1bc5c6SGustavo F. Padovan __u16 omtu; 4960c1bc5c6SGustavo F. Padovan __u16 flush_to; 4970c1bc5c6SGustavo F. Padovan __u8 mode; 498715ec005SGustavo F. Padovan __u8 chan_type; 4992ea66482SMat Martineau __u8 chan_policy; 5000c1bc5c6SGustavo F. Padovan 5014343478fSGustavo F. Padovan __u8 sec_level; 5024343478fSGustavo F. Padovan 503fc7f8a7eSGustavo F. Padovan __u8 ident; 504fc7f8a7eSGustavo F. Padovan 50573ffa904SGustavo F. Padovan __u8 conf_req[64]; 50673ffa904SGustavo F. Padovan __u8 conf_len; 50773ffa904SGustavo F. Padovan __u8 num_conf_req; 50873ffa904SGustavo F. Padovan __u8 num_conf_rsp; 50973ffa904SGustavo F. Padovan 51047d1ec61SGustavo F. Padovan __u8 fcs; 51147d1ec61SGustavo F. Padovan 5126327eb98SAndrei Emeltchenko __u16 tx_win; 513836be934SAndrei Emeltchenko __u16 tx_win_max; 514c20f8e35SMat Martineau __u16 ack_win; 51547d1ec61SGustavo F. Padovan __u8 max_tx; 51647d1ec61SGustavo F. Padovan __u16 retrans_timeout; 51747d1ec61SGustavo F. Padovan __u16 monitor_timeout; 51847d1ec61SGustavo F. Padovan __u16 mps; 51947d1ec61SGustavo F. Padovan 5200cd75f7eSJohan Hedberg __u16 tx_credits; 5210cd75f7eSJohan Hedberg __u16 rx_credits; 5220cd75f7eSJohan Hedberg 523d5f7ac38SMat Martineau __u8 tx_state; 524d5f7ac38SMat Martineau __u8 rx_state; 525d5f7ac38SMat Martineau 526c1360a1cSGustavo F. Padovan unsigned long conf_state; 527e2ab4353SGustavo F. Padovan unsigned long conn_state; 528d57b0e8bSAndrei Emeltchenko unsigned long flags; 529525cd185SGustavo F. Padovan 530fffadc08SAndrei Emeltchenko __u8 remote_amp_id; 53108333283SMat Martineau __u8 local_amp_id; 53208333283SMat Martineau __u8 move_id; 53308333283SMat Martineau __u8 move_state; 53408333283SMat Martineau __u8 move_role; 53508333283SMat Martineau 536fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 537fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 538fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 5390b209faeSAndrei Emeltchenko __u16 buffer_seq; 540fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 541d5f7ac38SMat Martineau __u16 last_acked_seq; 542fb45de7dSAndrei Emeltchenko __u16 frames_sent; 543fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 5446a026610SGustavo F. Padovan __u8 retry_count; 5456f61fd47SGustavo F. Padovan __u16 sdu_len; 5466f61fd47SGustavo F. Padovan struct sk_buff *sdu; 54784084a31SMat Martineau struct sk_buff *sdu_last_frag; 5486f61fd47SGustavo F. Padovan 5496327eb98SAndrei Emeltchenko __u16 remote_tx_win; 5502c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 5512c03a7a4SGustavo F. Padovan __u16 remote_mps; 55242e5c802SGustavo F. Padovan 5535a9e7057SAndrei Emeltchenko __u8 local_id; 5545a9e7057SAndrei Emeltchenko __u8 local_stype; 5555a9e7057SAndrei Emeltchenko __u16 local_msdu; 5565a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 5575a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 5585a9e7057SAndrei Emeltchenko __u32 local_flush_to; 5595a9e7057SAndrei Emeltchenko 5605a9e7057SAndrei Emeltchenko __u8 remote_id; 5615a9e7057SAndrei Emeltchenko __u8 remote_stype; 5625a9e7057SAndrei Emeltchenko __u16 remote_msdu; 5635a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 5645a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 5655a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 5665a9e7057SAndrei Emeltchenko 567721c4181SGustavo F. Padovan struct delayed_work chan_timer; 568721c4181SGustavo F. Padovan struct delayed_work retrans_timer; 569721c4181SGustavo F. Padovan struct delayed_work monitor_timer; 570721c4181SGustavo F. Padovan struct delayed_work ack_timer; 571721c4181SGustavo F. Padovan 57258d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 57358d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 574f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 5753c588192SMat Martineau struct l2cap_seq_list srej_list; 5763c588192SMat Martineau struct l2cap_seq_list retrans_list; 577e92c8e70SGustavo F. Padovan 578baa7e1faSGustavo F. Padovan struct list_head list; 57923691d75SGustavo F. Padovan struct list_head global_l; 58080808e43SGustavo F. Padovan 58180808e43SGustavo F. Padovan void *data; 58280808e43SGustavo F. Padovan struct l2cap_ops *ops; 583c03b355eSAndrei Emeltchenko struct mutex lock; 58480808e43SGustavo F. Padovan }; 58580808e43SGustavo F. Padovan 58680808e43SGustavo F. Padovan struct l2cap_ops { 58780808e43SGustavo F. Padovan char *name; 58880808e43SGustavo F. Padovan 58980b98027SGustavo Padovan struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan); 59080b98027SGustavo Padovan int (*recv) (struct l2cap_chan * chan, 59180b98027SGustavo Padovan struct sk_buff *skb); 592c0df7f6eSAndrei Emeltchenko void (*teardown) (struct l2cap_chan *chan, int err); 59380b98027SGustavo Padovan void (*close) (struct l2cap_chan *chan); 59480b98027SGustavo Padovan void (*state_change) (struct l2cap_chan *chan, 59553f52121SGustavo Padovan int state, int err); 59654a59aa2SAndrei Emeltchenko void (*ready) (struct l2cap_chan *chan); 5972dc4e510SGustavo Padovan void (*defer) (struct l2cap_chan *chan); 598d97c899bSMarcel Holtmann void (*resume) (struct l2cap_chan *chan); 599837776f7SJohan Hedberg void (*suspend) (struct l2cap_chan *chan); 6005ec1bbe5SGustavo Padovan void (*set_shutdown) (struct l2cap_chan *chan); 6018d836d71SGustavo Padovan long (*get_sndtimeo) (struct l2cap_chan *chan); 6022f7719ceSAndrei Emeltchenko struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 60390338947SGustavo Padovan unsigned long len, int nb); 6041da177e4SLinus Torvalds }; 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds struct l2cap_conn { 6071da177e4SLinus Torvalds struct hci_conn *hcon; 60873d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 6091da177e4SLinus Torvalds 6101da177e4SLinus Torvalds unsigned int mtu; 6111da177e4SLinus Torvalds 6124e8402a3SMarcel Holtmann __u32 feat_mask; 613978c93b9SAndrei Emeltchenko __u8 fixed_chan_mask; 614848566b3SMarcel Holtmann bool hs_enabled; 6154e8402a3SMarcel Holtmann 6164e8402a3SMarcel Holtmann __u8 info_state; 6174e8402a3SMarcel Holtmann __u8 info_ident; 6184e8402a3SMarcel Holtmann 619030013d8SGustavo F. Padovan struct delayed_work info_timer; 6204e8402a3SMarcel Holtmann 6211da177e4SLinus Torvalds spinlock_t lock; 6221da177e4SLinus Torvalds 6231da177e4SLinus Torvalds struct sk_buff *rx_skb; 6241da177e4SLinus Torvalds __u32 rx_len; 6251da177e4SLinus Torvalds __u8 tx_ident; 6261da177e4SLinus Torvalds 6272950f21aSMarcel Holtmann __u8 disc_reason; 6282950f21aSMarcel Holtmann 6296c9d42a1SGustavo F. Padovan struct delayed_work security_timer; 6301c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 6315d3de7dfSVinicius Costa Gomes 632baa7e1faSGustavo F. Padovan struct list_head chan_l; 633d01b2ff4SGustavo F. Padovan struct mutex chan_lock; 6349c903e37SDavid Herrmann struct kref ref; 6352c8e1411SDavid Herrmann struct list_head users; 6362c8e1411SDavid Herrmann }; 6372c8e1411SDavid Herrmann 6382c8e1411SDavid Herrmann struct l2cap_user { 6392c8e1411SDavid Herrmann struct list_head list; 6402c8e1411SDavid Herrmann int (*probe) (struct l2cap_conn *conn, struct l2cap_user *user); 6412c8e1411SDavid Herrmann void (*remove) (struct l2cap_conn *conn, struct l2cap_user *user); 6421da177e4SLinus Torvalds }; 6431da177e4SLinus Torvalds 6444e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 645984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 646984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 6474e8402a3SMarcel Holtmann 648715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 649715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 650715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 651416fa752SAndrei Emeltchenko #define L2CAP_CHAN_CONN_FIX_A2MP 4 652715ec005SGustavo F. Padovan 65348454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 6541da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds struct l2cap_pinfo { 6571da177e4SLinus Torvalds struct bt_sock bt; 65848454079SGustavo F. Padovan struct l2cap_chan *chan; 659e328140fSMat Martineau struct sk_buff *rx_busy_skb; 6601da177e4SLinus Torvalds }; 6611da177e4SLinus Torvalds 662c1360a1cSGustavo F. Padovan enum { 663c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 664c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 665c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 666c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 667c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 668c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 669f2592d3eSAndrei Emeltchenko CONF_RECV_NO_FCS, 670c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 6716327eb98SAndrei Emeltchenko CONF_EWS_RECV, 6720e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 6730e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 6742827011fSMat Martineau CONF_NOT_COMPLETE, 675c1360a1cSGustavo F. Padovan }; 676861d6882SMarcel Holtmann 677f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 678f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 679f2fcfcd6SGustavo F. Padovan 680e2ab4353SGustavo F. Padovan enum { 681e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 682e2ab4353SGustavo F. Padovan CONN_WAIT_F, 683e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 684e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 685e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 686e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 687e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 688e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 689e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 690e2ab4353SGustavo F. Padovan }; 691e90bac06SGustavo F. Padovan 692d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 693d57b0e8bSAndrei Emeltchenko enum { 69443bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 69515770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 696ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 697d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 6986327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 6995a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 700bdc25783SMarcel Holtmann FLAG_DEFER_SETUP, 701595177f3SJohan Hedberg FLAG_LE_CONN_REQ_SENT, 702d57b0e8bSAndrei Emeltchenko }; 703d57b0e8bSAndrei Emeltchenko 704d5f7ac38SMat Martineau enum { 705d5f7ac38SMat Martineau L2CAP_TX_STATE_XMIT, 706d5f7ac38SMat Martineau L2CAP_TX_STATE_WAIT_F, 707d5f7ac38SMat Martineau }; 708d5f7ac38SMat Martineau 709d5f7ac38SMat Martineau enum { 710d5f7ac38SMat Martineau L2CAP_RX_STATE_RECV, 711d5f7ac38SMat Martineau L2CAP_RX_STATE_SREJ_SENT, 71208333283SMat Martineau L2CAP_RX_STATE_MOVE, 71308333283SMat Martineau L2CAP_RX_STATE_WAIT_P, 71408333283SMat Martineau L2CAP_RX_STATE_WAIT_F, 715d5f7ac38SMat Martineau }; 716d5f7ac38SMat Martineau 717d5f7ac38SMat Martineau enum { 718d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED, 719d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED_SREJ, 720d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED, 721d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED_SREJ, 722d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE, 723d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE_SREJ, 724d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID, 725d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID_IGNORE, 726d5f7ac38SMat Martineau }; 727d5f7ac38SMat Martineau 728d5f7ac38SMat Martineau enum { 729d5f7ac38SMat Martineau L2CAP_EV_DATA_REQUEST, 730d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_DETECTED, 731d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_CLEAR, 732d5f7ac38SMat Martineau L2CAP_EV_RECV_REQSEQ_AND_FBIT, 733d5f7ac38SMat Martineau L2CAP_EV_RECV_FBIT, 734d5f7ac38SMat Martineau L2CAP_EV_RETRANS_TO, 735d5f7ac38SMat Martineau L2CAP_EV_MONITOR_TO, 736d5f7ac38SMat Martineau L2CAP_EV_EXPLICIT_POLL, 737d5f7ac38SMat Martineau L2CAP_EV_RECV_IFRAME, 738d5f7ac38SMat Martineau L2CAP_EV_RECV_RR, 739d5f7ac38SMat Martineau L2CAP_EV_RECV_REJ, 740d5f7ac38SMat Martineau L2CAP_EV_RECV_RNR, 741d5f7ac38SMat Martineau L2CAP_EV_RECV_SREJ, 742d5f7ac38SMat Martineau L2CAP_EV_RECV_FRAME, 743d5f7ac38SMat Martineau }; 744d5f7ac38SMat Martineau 74508333283SMat Martineau enum { 74608333283SMat Martineau L2CAP_MOVE_ROLE_NONE, 74708333283SMat Martineau L2CAP_MOVE_ROLE_INITIATOR, 74808333283SMat Martineau L2CAP_MOVE_ROLE_RESPONDER, 74908333283SMat Martineau }; 75008333283SMat Martineau 75108333283SMat Martineau enum { 75208333283SMat Martineau L2CAP_MOVE_STABLE, 75308333283SMat Martineau L2CAP_MOVE_WAIT_REQ, 75408333283SMat Martineau L2CAP_MOVE_WAIT_RSP, 75508333283SMat Martineau L2CAP_MOVE_WAIT_RSP_SUCCESS, 75608333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM, 75708333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM_RSP, 75808333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_COMP, 75908333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_CFM, 76008333283SMat Martineau L2CAP_MOVE_WAIT_LOCAL_BUSY, 76108333283SMat Martineau L2CAP_MOVE_WAIT_PREPARE, 76208333283SMat Martineau }; 76308333283SMat Martineau 76430648372SJaganath Kanakkassery void l2cap_chan_hold(struct l2cap_chan *c); 76530648372SJaganath Kanakkassery void l2cap_chan_put(struct l2cap_chan *c); 766371fd835SUlisses Furquim 767c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan) 768c03b355eSAndrei Emeltchenko { 769c03b355eSAndrei Emeltchenko mutex_lock(&chan->lock); 770c03b355eSAndrei Emeltchenko } 771c03b355eSAndrei Emeltchenko 772c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 773c03b355eSAndrei Emeltchenko { 774c03b355eSAndrei Emeltchenko mutex_unlock(&chan->lock); 775c03b355eSAndrei Emeltchenko } 776c03b355eSAndrei Emeltchenko 777c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan, 778c2ec9c1bSGustavo F. Padovan struct delayed_work *work, long timeout) 779c2ec9c1bSGustavo F. Padovan { 780e05dcc32SAndrei Emeltchenko BT_DBG("chan %p state %s timeout %ld", chan, 781e05dcc32SAndrei Emeltchenko state_to_string(chan->state), timeout); 782c2ec9c1bSGustavo F. Padovan 7836f74b6f3SAndrei Emeltchenko /* If delayed work cancelled do not hold(chan) 7846f74b6f3SAndrei Emeltchenko since it is already done with previous set_timer */ 78517cd3f37SUlisses Furquim if (!cancel_delayed_work(work)) 786371fd835SUlisses Furquim l2cap_chan_hold(chan); 7876f74b6f3SAndrei Emeltchenko 788c2ec9c1bSGustavo F. Padovan schedule_delayed_work(work, timeout); 789c2ec9c1bSGustavo F. Padovan } 790c2ec9c1bSGustavo F. Padovan 79175b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan, 792371fd835SUlisses Furquim struct delayed_work *work) 793c2ec9c1bSGustavo F. Padovan { 79475b93b59SSzymon Janc bool ret; 79575b93b59SSzymon Janc 7966f74b6f3SAndrei Emeltchenko /* put(chan) if delayed work cancelled otherwise it 7976f74b6f3SAndrei Emeltchenko is done in delayed work function */ 79817cd3f37SUlisses Furquim ret = cancel_delayed_work(work); 79975b93b59SSzymon Janc if (ret) 800371fd835SUlisses Furquim l2cap_chan_put(chan); 80175b93b59SSzymon Janc 80275b93b59SSzymon Janc return ret; 803c2ec9c1bSGustavo F. Padovan } 804c2ec9c1bSGustavo F. Padovan 805c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 806c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 8071a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 8081a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 8091a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 810b83ddfe2SAndrzej Kaczmarek msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 8111a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 812c74e560cSGustavo F. Padovan 813836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 814836be934SAndrei Emeltchenko { 8155a364bd3SMat Martineau if (seq1 >= seq2) 8165a364bd3SMat Martineau return seq1 - seq2; 8175a364bd3SMat Martineau else 8185a364bd3SMat Martineau return chan->tx_win_max + 1 - seq2 + seq1; 819836be934SAndrei Emeltchenko } 820836be934SAndrei Emeltchenko 821836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 822836be934SAndrei Emeltchenko { 823836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 824836be934SAndrei Emeltchenko } 825836be934SAndrei Emeltchenko 8267e1af8a3SGustavo Padovan static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chan *chan) 8277e1af8a3SGustavo Padovan { 8287e1af8a3SGustavo Padovan return NULL; 8297e1af8a3SGustavo Padovan } 8307e1af8a3SGustavo Padovan 8317e1af8a3SGustavo Padovan static inline void l2cap_chan_no_teardown(struct l2cap_chan *chan, int err) 8327e1af8a3SGustavo Padovan { 8337e1af8a3SGustavo Padovan } 8347e1af8a3SGustavo Padovan 8357e1af8a3SGustavo Padovan static inline void l2cap_chan_no_ready(struct l2cap_chan *chan) 8367e1af8a3SGustavo Padovan { 8377e1af8a3SGustavo Padovan } 8381da177e4SLinus Torvalds 8392dc4e510SGustavo Padovan static inline void l2cap_chan_no_defer(struct l2cap_chan *chan) 8402dc4e510SGustavo Padovan { 8412dc4e510SGustavo Padovan } 8422dc4e510SGustavo Padovan 8432ce5fb51SMarcel Holtmann static inline void l2cap_chan_no_resume(struct l2cap_chan *chan) 8442ce5fb51SMarcel Holtmann { 8452ce5fb51SMarcel Holtmann } 8462ce5fb51SMarcel Holtmann 8475ec1bbe5SGustavo Padovan static inline void l2cap_chan_no_set_shutdown(struct l2cap_chan *chan) 8485ec1bbe5SGustavo Padovan { 8495ec1bbe5SGustavo Padovan } 8505ec1bbe5SGustavo Padovan 8518d836d71SGustavo Padovan static inline long l2cap_chan_no_get_sndtimeo(struct l2cap_chan *chan) 8528d836d71SGustavo Padovan { 8538d836d71SGustavo Padovan return 0; 8548d836d71SGustavo Padovan } 8558d836d71SGustavo Padovan 856eb939922SRusty Russell extern bool disable_ertm; 8579149761aSJohan Hedberg extern bool enable_lecoc; 858bb58f747SGustavo F. Padovan 859bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 860bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 861b3916db3SDavid Herrmann bool l2cap_is_socket(struct socket *sock); 862bb58f747SGustavo F. Padovan 86327e2d4c8SJohan Hedberg void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan); 8648c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 86568983259SGustavo F. Padovan 8669e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 8679e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 8689e4425ffSGustavo F. Padovan 869eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void); 8700f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 871cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 8728e9f9892SAndre Guedes bdaddr_t *dst, u8 dst_type); 8735e59b791SLuiz Augusto von Dentz int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 8745e59b791SLuiz Augusto von Dentz u32 priority); 875e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 876d45fc423SGustavo F. Padovan int l2cap_chan_check_security(struct l2cap_chan *chan); 877bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan); 878466f8004SAndrei Emeltchenko int l2cap_ertm_init(struct l2cap_chan *chan); 879466f8004SAndrei Emeltchenko void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 88093c3e8f5SAndrei Emeltchenko void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 881466f8004SAndrei Emeltchenko void l2cap_chan_del(struct l2cap_chan *chan, int err); 8822766be48SAndrei Emeltchenko void l2cap_send_conn_req(struct l2cap_chan *chan); 8833f7a56c4SMat Martineau void l2cap_move_start(struct l2cap_chan *chan); 88427695fb4SAndrei Emeltchenko void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, 88527695fb4SAndrei Emeltchenko u8 status); 886a514b17fSAndrei Emeltchenko void __l2cap_physical_cfm(struct l2cap_chan *chan, int result); 887bb58f747SGustavo F. Padovan 8889c903e37SDavid Herrmann void l2cap_conn_get(struct l2cap_conn *conn); 8899c903e37SDavid Herrmann void l2cap_conn_put(struct l2cap_conn *conn); 8909c903e37SDavid Herrmann 8912c8e1411SDavid Herrmann int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); 8922c8e1411SDavid Herrmann void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user); 8932c8e1411SDavid Herrmann 8941da177e4SLinus Torvalds #endif /* __L2CAP_H */ 895