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 947d513e92SMarcel 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 */ 137a6801ca9SMarcel Holtmann #define L2CAP_FC_SIG_BREDR 0x02 138d40bffbcSMarcel Holtmann #define L2CAP_FC_CONNLESS 0x04 139d835ac0fSMat Martineau #define L2CAP_FC_A2MP 0x08 140a6801ca9SMarcel Holtmann #define L2CAP_FC_ATT 0x10 141a6801ca9SMarcel Holtmann #define L2CAP_FC_SIG_LE 0x20 142a6801ca9SMarcel Holtmann #define L2CAP_FC_SMP_LE 0x40 143d835ac0fSMat Martineau 1441c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1451c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1461c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1471c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 14857253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 14957253fd8SAndrei Emeltchenko 1501c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1511c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1521c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1531c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1541c2acffbSGustavo F. Padovan 1551c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 15657253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 157d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT 4 158d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT 7 1591c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1608f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1611c2acffbSGustavo F. Padovan 16257253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 16357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 16457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 16557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 16657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 16757253fd8SAndrei Emeltchenko 16857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 16957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 17057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 17157253fd8SAndrei Emeltchenko 172d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT 1 17357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 17457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 17557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 176d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT 18 17757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 17857253fd8SAndrei Emeltchenko 1791c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 180ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 181ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 182ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 183ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1841c2acffbSGustavo F. Padovan 1851c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1867e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1877e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1887e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1897e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1901c2acffbSGustavo F. Padovan 191e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 192e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 193e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 194e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 195e2fd318eSIlia Kolomisnky 1961da177e4SLinus Torvalds /* L2CAP structures */ 1971da177e4SLinus Torvalds struct l2cap_hdr { 1988e036fc3SAl Viro __le16 len; 1998e036fc3SAl Viro __le16 cid; 20066c853ccSGustavo F. Padovan } __packed; 2011da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 202d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 203d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 204d43cb289SAndrei Emeltchenko 205d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 206d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 207d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 208d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE 2 209d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE 4 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds struct l2cap_cmd_hdr { 2121da177e4SLinus Torvalds __u8 code; 2131da177e4SLinus Torvalds __u8 ident; 2148e036fc3SAl Viro __le16 len; 21566c853ccSGustavo F. Padovan } __packed; 2161da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 2171da177e4SLinus Torvalds 218e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 2198e036fc3SAl Viro __le16 reason; 22066c853ccSGustavo F. Padovan } __packed; 2211da177e4SLinus Torvalds 222e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 223e2fd318eSIlia Kolomisnky __le16 reason; 224e2fd318eSIlia Kolomisnky __le16 max_mtu; 225e2fd318eSIlia Kolomisnky } __packed; 226e2fd318eSIlia Kolomisnky 227e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 228e2fd318eSIlia Kolomisnky __le16 reason; 229e2fd318eSIlia Kolomisnky __le16 scid; 230e2fd318eSIlia Kolomisnky __le16 dcid; 231e2fd318eSIlia Kolomisnky } __packed; 232e2fd318eSIlia Kolomisnky 2331da177e4SLinus Torvalds struct l2cap_conn_req { 2348e036fc3SAl Viro __le16 psm; 2358e036fc3SAl Viro __le16 scid; 23666c853ccSGustavo F. Padovan } __packed; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds struct l2cap_conn_rsp { 2398e036fc3SAl Viro __le16 dcid; 2408e036fc3SAl Viro __le16 scid; 2418e036fc3SAl Viro __le16 result; 2428e036fc3SAl Viro __le16 status; 24366c853ccSGustavo F. Padovan } __packed; 2441da177e4SLinus Torvalds 2452983fd68SAndrei Emeltchenko /* protocol/service multiplexer (PSM) */ 2462983fd68SAndrei Emeltchenko #define L2CAP_PSM_SDP 0x0001 2472983fd68SAndrei Emeltchenko #define L2CAP_PSM_RFCOMM 0x0003 2483124b843SMarcel Holtmann #define L2CAP_PSM_3DSP 0x0021 2492983fd68SAndrei Emeltchenko 2503f79410cSMaxime Jayat /* channel identifier */ 2518db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2528db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 253466f8004SAndrei Emeltchenko #define L2CAP_CID_A2MP 0x0003 254073d1cf3SJohan Hedberg #define L2CAP_CID_ATT 0x0004 255acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 256acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2578db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2588db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 259e77af755SJohan Hedberg #define L2CAP_CID_LE_DYN_END 0x007f 2608db4dc46SGustavo F. Padovan 26138094c75SMat Martineau /* connect/create channel results */ 2621da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2631da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2641da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2651da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2661da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 26738094c75SMat Martineau #define L2CAP_CR_BAD_AMP 0x0005 268ee5ec5cfSJohan Hedberg #define L2CAP_CR_AUTHENTICATION 0x0005 269ee5ec5cfSJohan Hedberg #define L2CAP_CR_AUTHORIZATION 0x0006 270ee5ec5cfSJohan Hedberg #define L2CAP_CR_BAD_KEY_SIZE 0x0007 271ee5ec5cfSJohan Hedberg #define L2CAP_CR_ENCRYPTION 0x0008 2721da177e4SLinus Torvalds 27338094c75SMat Martineau /* connect/create channel status */ 2741da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2751da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2761da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds struct l2cap_conf_req { 2798e036fc3SAl Viro __le16 dcid; 2808e036fc3SAl Viro __le16 flags; 2811da177e4SLinus Torvalds __u8 data[0]; 28266c853ccSGustavo F. Padovan } __packed; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds struct l2cap_conf_rsp { 2858e036fc3SAl Viro __le16 scid; 2868e036fc3SAl Viro __le16 flags; 2878e036fc3SAl Viro __le16 result; 2881da177e4SLinus Torvalds __u8 data[0]; 28966c853ccSGustavo F. Padovan } __packed; 2901da177e4SLinus Torvalds 2915dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2925dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2935dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2945dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2950e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 2965a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 2971da177e4SLinus Torvalds 29859e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */ 29959e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION 0x0001 30059e54bd1SAndrei Emeltchenko 3011da177e4SLinus Torvalds struct l2cap_conf_opt { 3021da177e4SLinus Torvalds __u8 type; 3031da177e4SLinus Torvalds __u8 len; 3041da177e4SLinus Torvalds __u8 val[0]; 30566c853ccSGustavo F. Padovan } __packed; 3061da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 3071da177e4SLinus Torvalds 308589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 30947ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 310589d2746SGustavo F. Padovan 3111da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 3121da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 3131da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 3141da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 31547ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 3165a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 3176327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 3201da177e4SLinus Torvalds 3216464f35fSMarcel Holtmann struct l2cap_conf_rfc { 3226464f35fSMarcel Holtmann __u8 mode; 3236464f35fSMarcel Holtmann __u8 txwin_size; 3246464f35fSMarcel Holtmann __u8 max_transmit; 3256464f35fSMarcel Holtmann __le16 retrans_timeout; 3266464f35fSMarcel Holtmann __le16 monitor_timeout; 3276464f35fSMarcel Holtmann __le16 max_pdu_size; 32866c853ccSGustavo F. Padovan } __packed; 3296464f35fSMarcel Holtmann 3306464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 3316464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 3326464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 33347ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 334c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 3356464f35fSMarcel Holtmann 33638319713SJohan Hedberg /* Unlike the above this one doesn't actually map to anything that would 33738319713SJohan Hedberg * ever be sent over the air. Therefore, use a value that's unlikely to 33838319713SJohan Hedberg * ever be used in the BR/EDR configuration phase. 33938319713SJohan Hedberg */ 34038319713SJohan Hedberg #define L2CAP_MODE_LE_FLOWCTL 0x80 34138319713SJohan Hedberg 3425a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 3435a9e7057SAndrei Emeltchenko __u8 id; 3445a9e7057SAndrei Emeltchenko __u8 stype; 3455a9e7057SAndrei Emeltchenko __le16 msdu; 3465a9e7057SAndrei Emeltchenko __le32 sdu_itime; 3475a9e7057SAndrei Emeltchenko __le32 acc_lat; 3485a9e7057SAndrei Emeltchenko __le32 flush_to; 3495a9e7057SAndrei Emeltchenko } __packed; 3505a9e7057SAndrei Emeltchenko 3518f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 3528f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 3538f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 3548f7975b1SAndrei Emeltchenko 3558f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3568f7975b1SAndrei Emeltchenko 3571da177e4SLinus Torvalds struct l2cap_disconn_req { 3588e036fc3SAl Viro __le16 dcid; 3598e036fc3SAl Viro __le16 scid; 36066c853ccSGustavo F. Padovan } __packed; 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3638e036fc3SAl Viro __le16 dcid; 3648e036fc3SAl Viro __le16 scid; 36566c853ccSGustavo F. Padovan } __packed; 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds struct l2cap_info_req { 3688e036fc3SAl Viro __le16 type; 36966c853ccSGustavo F. Padovan } __packed; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds struct l2cap_info_rsp { 3728e036fc3SAl Viro __le16 type; 3738e036fc3SAl Viro __le16 result; 3741da177e4SLinus Torvalds __u8 data[0]; 37566c853ccSGustavo F. Padovan } __packed; 3761da177e4SLinus Torvalds 37738094c75SMat Martineau struct l2cap_create_chan_req { 37838094c75SMat Martineau __le16 psm; 37938094c75SMat Martineau __le16 scid; 38038094c75SMat Martineau __u8 amp_id; 38138094c75SMat Martineau } __packed; 38238094c75SMat Martineau 38338094c75SMat Martineau struct l2cap_create_chan_rsp { 38438094c75SMat Martineau __le16 dcid; 38538094c75SMat Martineau __le16 scid; 38638094c75SMat Martineau __le16 result; 38738094c75SMat Martineau __le16 status; 38838094c75SMat Martineau } __packed; 38938094c75SMat Martineau 39038094c75SMat Martineau struct l2cap_move_chan_req { 39138094c75SMat Martineau __le16 icid; 39238094c75SMat Martineau __u8 dest_amp_id; 39338094c75SMat Martineau } __packed; 39438094c75SMat Martineau 39538094c75SMat Martineau struct l2cap_move_chan_rsp { 39638094c75SMat Martineau __le16 icid; 39738094c75SMat Martineau __le16 result; 39838094c75SMat Martineau } __packed; 39938094c75SMat Martineau 40038094c75SMat Martineau #define L2CAP_MR_SUCCESS 0x0000 40138094c75SMat Martineau #define L2CAP_MR_PEND 0x0001 40238094c75SMat Martineau #define L2CAP_MR_BAD_ID 0x0002 40338094c75SMat Martineau #define L2CAP_MR_SAME_ID 0x0003 40438094c75SMat Martineau #define L2CAP_MR_NOT_SUPP 0x0004 40538094c75SMat Martineau #define L2CAP_MR_COLLISION 0x0005 40638094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED 0x0006 40738094c75SMat Martineau 40838094c75SMat Martineau struct l2cap_move_chan_cfm { 40938094c75SMat Martineau __le16 icid; 41038094c75SMat Martineau __le16 result; 41138094c75SMat Martineau } __packed; 41238094c75SMat Martineau 41338094c75SMat Martineau #define L2CAP_MC_CONFIRMED 0x0000 41438094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED 0x0001 41538094c75SMat Martineau 41638094c75SMat Martineau struct l2cap_move_chan_cfm_rsp { 41738094c75SMat Martineau __le16 icid; 41838094c75SMat Martineau } __packed; 41938094c75SMat Martineau 4201da177e4SLinus Torvalds /* info type */ 4211da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 4221da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 423e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds /* info result */ 4261da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 4271da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 4281da177e4SLinus Torvalds 429de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 430de73115aSClaudio Takahasi __le16 min; 431de73115aSClaudio Takahasi __le16 max; 432de73115aSClaudio Takahasi __le16 latency; 433de73115aSClaudio Takahasi __le16 to_multiplier; 434de73115aSClaudio Takahasi } __packed; 435de73115aSClaudio Takahasi 436de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 437de73115aSClaudio Takahasi __le16 result; 438de73115aSClaudio Takahasi } __packed; 439de73115aSClaudio Takahasi 440de73115aSClaudio Takahasi /* Connection Parameters result */ 441de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 442de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 443de73115aSClaudio Takahasi 444ee5ec5cfSJohan Hedberg #define L2CAP_LE_MAX_CREDITS 10 445ee5ec5cfSJohan Hedberg #define L2CAP_LE_DEFAULT_MPS 230 446ee5ec5cfSJohan Hedberg 447ee5ec5cfSJohan Hedberg struct l2cap_le_conn_req { 448ee5ec5cfSJohan Hedberg __le16 psm; 449ee5ec5cfSJohan Hedberg __le16 scid; 450ee5ec5cfSJohan Hedberg __le16 mtu; 451ee5ec5cfSJohan Hedberg __le16 mps; 452ee5ec5cfSJohan Hedberg __le16 credits; 453ee5ec5cfSJohan Hedberg } __packed; 454ee5ec5cfSJohan Hedberg 455ee5ec5cfSJohan Hedberg struct l2cap_le_conn_rsp { 456ee5ec5cfSJohan Hedberg __le16 dcid; 457ee5ec5cfSJohan Hedberg __le16 mtu; 458ee5ec5cfSJohan Hedberg __le16 mps; 459ee5ec5cfSJohan Hedberg __le16 credits; 460ee5ec5cfSJohan Hedberg __le16 result; 461ee5ec5cfSJohan Hedberg } __packed; 462ee5ec5cfSJohan Hedberg 463ee5ec5cfSJohan Hedberg struct l2cap_le_credits { 464ee5ec5cfSJohan Hedberg __le16 cid; 465ee5ec5cfSJohan Hedberg __le16 credits; 466ee5ec5cfSJohan Hedberg } __packed; 467ee5ec5cfSJohan Hedberg 46848454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 4693c588192SMat Martineau struct l2cap_seq_list { 4703c588192SMat Martineau __u16 head; 4713c588192SMat Martineau __u16 tail; 4723c588192SMat Martineau __u16 mask; 4733c588192SMat Martineau __u16 *list; 4743c588192SMat Martineau }; 4753c588192SMat Martineau 4763c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR 0xFFFF 4773c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL 0x8000 4783c588192SMat Martineau 47948454079SGustavo F. Padovan struct l2cap_chan { 4808c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 48108333283SMat Martineau struct hci_conn *hs_hcon; 48208333283SMat Martineau struct hci_chan *hs_hchan; 483144ad330SSyam Sidhardhan struct kref kref; 4848c1d787bSGustavo F. Padovan 48589bc500eSGustavo F. Padovan __u8 state; 48689bc500eSGustavo F. Padovan 4877eafc59eSMarcel Holtmann bdaddr_t dst; 4884f1654e0SMarcel Holtmann __u8 dst_type; 4897eafc59eSMarcel Holtmann bdaddr_t src; 4904f1654e0SMarcel Holtmann __u8 src_type; 491fe4128e0SGustavo F. Padovan __le16 psm; 4924f1654e0SMarcel Holtmann __le16 sport; 493fe4128e0SGustavo F. Padovan __u16 dcid; 494fe4128e0SGustavo F. Padovan __u16 scid; 4954343478fSGustavo F. Padovan 4960c1bc5c6SGustavo F. Padovan __u16 imtu; 4970c1bc5c6SGustavo F. Padovan __u16 omtu; 4980c1bc5c6SGustavo F. Padovan __u16 flush_to; 4990c1bc5c6SGustavo F. Padovan __u8 mode; 500715ec005SGustavo F. Padovan __u8 chan_type; 5012ea66482SMat Martineau __u8 chan_policy; 5020c1bc5c6SGustavo F. Padovan 5034343478fSGustavo F. Padovan __u8 sec_level; 5044343478fSGustavo F. Padovan 505fc7f8a7eSGustavo F. Padovan __u8 ident; 506fc7f8a7eSGustavo F. Padovan 50773ffa904SGustavo F. Padovan __u8 conf_req[64]; 50873ffa904SGustavo F. Padovan __u8 conf_len; 50973ffa904SGustavo F. Padovan __u8 num_conf_req; 51073ffa904SGustavo F. Padovan __u8 num_conf_rsp; 51173ffa904SGustavo F. Padovan 51247d1ec61SGustavo F. Padovan __u8 fcs; 51347d1ec61SGustavo F. Padovan 5146327eb98SAndrei Emeltchenko __u16 tx_win; 515836be934SAndrei Emeltchenko __u16 tx_win_max; 516c20f8e35SMat Martineau __u16 ack_win; 51747d1ec61SGustavo F. Padovan __u8 max_tx; 51847d1ec61SGustavo F. Padovan __u16 retrans_timeout; 51947d1ec61SGustavo F. Padovan __u16 monitor_timeout; 52047d1ec61SGustavo F. Padovan __u16 mps; 52147d1ec61SGustavo F. Padovan 5220cd75f7eSJohan Hedberg __u16 tx_credits; 5230cd75f7eSJohan Hedberg __u16 rx_credits; 5240cd75f7eSJohan Hedberg 525d5f7ac38SMat Martineau __u8 tx_state; 526d5f7ac38SMat Martineau __u8 rx_state; 527d5f7ac38SMat Martineau 528c1360a1cSGustavo F. Padovan unsigned long conf_state; 529e2ab4353SGustavo F. Padovan unsigned long conn_state; 530d57b0e8bSAndrei Emeltchenko unsigned long flags; 531525cd185SGustavo F. Padovan 532fffadc08SAndrei Emeltchenko __u8 remote_amp_id; 53308333283SMat Martineau __u8 local_amp_id; 53408333283SMat Martineau __u8 move_id; 53508333283SMat Martineau __u8 move_state; 53608333283SMat Martineau __u8 move_role; 53708333283SMat Martineau 538fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 539fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 540fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 5410b209faeSAndrei Emeltchenko __u16 buffer_seq; 542fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 543d5f7ac38SMat Martineau __u16 last_acked_seq; 544fb45de7dSAndrei Emeltchenko __u16 frames_sent; 545fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 5466a026610SGustavo F. Padovan __u8 retry_count; 5476f61fd47SGustavo F. Padovan __u16 sdu_len; 5486f61fd47SGustavo F. Padovan struct sk_buff *sdu; 54984084a31SMat Martineau struct sk_buff *sdu_last_frag; 5506f61fd47SGustavo F. Padovan 5516327eb98SAndrei Emeltchenko __u16 remote_tx_win; 5522c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 5532c03a7a4SGustavo F. Padovan __u16 remote_mps; 55442e5c802SGustavo F. Padovan 5555a9e7057SAndrei Emeltchenko __u8 local_id; 5565a9e7057SAndrei Emeltchenko __u8 local_stype; 5575a9e7057SAndrei Emeltchenko __u16 local_msdu; 5585a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 5595a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 5605a9e7057SAndrei Emeltchenko __u32 local_flush_to; 5615a9e7057SAndrei Emeltchenko 5625a9e7057SAndrei Emeltchenko __u8 remote_id; 5635a9e7057SAndrei Emeltchenko __u8 remote_stype; 5645a9e7057SAndrei Emeltchenko __u16 remote_msdu; 5655a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 5665a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 5675a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 5685a9e7057SAndrei Emeltchenko 569721c4181SGustavo F. Padovan struct delayed_work chan_timer; 570721c4181SGustavo F. Padovan struct delayed_work retrans_timer; 571721c4181SGustavo F. Padovan struct delayed_work monitor_timer; 572721c4181SGustavo F. Padovan struct delayed_work ack_timer; 573721c4181SGustavo F. Padovan 57458d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 57558d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 576f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 5773c588192SMat Martineau struct l2cap_seq_list srej_list; 5783c588192SMat Martineau struct l2cap_seq_list retrans_list; 579e92c8e70SGustavo F. Padovan 580baa7e1faSGustavo F. Padovan struct list_head list; 58123691d75SGustavo F. Padovan struct list_head global_l; 58280808e43SGustavo F. Padovan 58380808e43SGustavo F. Padovan void *data; 58467f86a45SMarcel Holtmann const struct l2cap_ops *ops; 585c03b355eSAndrei Emeltchenko struct mutex lock; 58680808e43SGustavo F. Padovan }; 58780808e43SGustavo F. Padovan 58880808e43SGustavo F. Padovan struct l2cap_ops { 58980808e43SGustavo F. Padovan char *name; 59080808e43SGustavo F. Padovan 59180b98027SGustavo Padovan struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan); 59280b98027SGustavo Padovan int (*recv) (struct l2cap_chan * chan, 59380b98027SGustavo Padovan struct sk_buff *skb); 594c0df7f6eSAndrei Emeltchenko void (*teardown) (struct l2cap_chan *chan, int err); 59580b98027SGustavo Padovan void (*close) (struct l2cap_chan *chan); 59680b98027SGustavo Padovan void (*state_change) (struct l2cap_chan *chan, 59753f52121SGustavo Padovan int state, int err); 59854a59aa2SAndrei Emeltchenko void (*ready) (struct l2cap_chan *chan); 5992dc4e510SGustavo Padovan void (*defer) (struct l2cap_chan *chan); 600d97c899bSMarcel Holtmann void (*resume) (struct l2cap_chan *chan); 601837776f7SJohan Hedberg void (*suspend) (struct l2cap_chan *chan); 6025ec1bbe5SGustavo Padovan void (*set_shutdown) (struct l2cap_chan *chan); 6038d836d71SGustavo Padovan long (*get_sndtimeo) (struct l2cap_chan *chan); 6042f7719ceSAndrei Emeltchenko struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 605d9fbd02bSMarcel Holtmann unsigned long hdr_len, 60690338947SGustavo Padovan unsigned long len, int nb); 6070498878bSJukka Rissanen int (*memcpy_fromiovec) (struct l2cap_chan *chan, 6080498878bSJukka Rissanen unsigned char *kdata, 6090498878bSJukka Rissanen struct iovec *iov, 6100498878bSJukka Rissanen int len); 6111da177e4SLinus Torvalds }; 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds struct l2cap_conn { 6141da177e4SLinus Torvalds struct hci_conn *hcon; 61573d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds unsigned int mtu; 6181da177e4SLinus Torvalds 6194e8402a3SMarcel Holtmann __u32 feat_mask; 620978c93b9SAndrei Emeltchenko __u8 fixed_chan_mask; 621848566b3SMarcel Holtmann bool hs_enabled; 6224e8402a3SMarcel Holtmann 6234e8402a3SMarcel Holtmann __u8 info_state; 6244e8402a3SMarcel Holtmann __u8 info_ident; 6254e8402a3SMarcel Holtmann 626030013d8SGustavo F. Padovan struct delayed_work info_timer; 6274e8402a3SMarcel Holtmann 6281da177e4SLinus Torvalds struct sk_buff *rx_skb; 6291da177e4SLinus Torvalds __u32 rx_len; 6301da177e4SLinus Torvalds __u8 tx_ident; 6315a54e7c8SMarcel Holtmann struct mutex ident_lock; 6321da177e4SLinus Torvalds 63361a939c6SJohan Hedberg struct sk_buff_head pending_rx; 63461a939c6SJohan Hedberg struct work_struct pending_rx_work; 63561a939c6SJohan Hedberg 6362950f21aSMarcel Holtmann __u8 disc_reason; 6372950f21aSMarcel Holtmann 6386c9d42a1SGustavo F. Padovan struct delayed_work security_timer; 6391c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 6405d3de7dfSVinicius Costa Gomes 641baa7e1faSGustavo F. Padovan struct list_head chan_l; 642d01b2ff4SGustavo F. Padovan struct mutex chan_lock; 6439c903e37SDavid Herrmann struct kref ref; 6442c8e1411SDavid Herrmann struct list_head users; 6452c8e1411SDavid Herrmann }; 6462c8e1411SDavid Herrmann 6472c8e1411SDavid Herrmann struct l2cap_user { 6482c8e1411SDavid Herrmann struct list_head list; 6492c8e1411SDavid Herrmann int (*probe) (struct l2cap_conn *conn, struct l2cap_user *user); 6502c8e1411SDavid Herrmann void (*remove) (struct l2cap_conn *conn, struct l2cap_user *user); 6511da177e4SLinus Torvalds }; 6521da177e4SLinus Torvalds 6534e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 654984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 655984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 6564e8402a3SMarcel Holtmann 657715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 658715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 659715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 6602338a7e0SJohan Hedberg #define L2CAP_CHAN_FIXED 4 661715ec005SGustavo F. Padovan 66248454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 6631da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds struct l2cap_pinfo { 6661da177e4SLinus Torvalds struct bt_sock bt; 66748454079SGustavo F. Padovan struct l2cap_chan *chan; 668e328140fSMat Martineau struct sk_buff *rx_busy_skb; 6691da177e4SLinus Torvalds }; 6701da177e4SLinus Torvalds 671c1360a1cSGustavo F. Padovan enum { 672c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 673c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 674c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 675c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 676c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 677c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 678f2592d3eSAndrei Emeltchenko CONF_RECV_NO_FCS, 679c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 6806327eb98SAndrei Emeltchenko CONF_EWS_RECV, 6810e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 6820e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 6832827011fSMat Martineau CONF_NOT_COMPLETE, 684c1360a1cSGustavo F. Padovan }; 685861d6882SMarcel Holtmann 686f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 687f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 688f2fcfcd6SGustavo F. Padovan 689e2ab4353SGustavo F. Padovan enum { 690e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 691e2ab4353SGustavo F. Padovan CONN_WAIT_F, 692e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 693e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 694e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 695e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 696e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 697e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 698e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 699e2ab4353SGustavo F. Padovan }; 700e90bac06SGustavo F. Padovan 701d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 702d57b0e8bSAndrei Emeltchenko enum { 70343bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 70415770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 705ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 706d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 7076327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 7085a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 709bdc25783SMarcel Holtmann FLAG_DEFER_SETUP, 710595177f3SJohan Hedberg FLAG_LE_CONN_REQ_SENT, 711*d52deb17SJohan Hedberg FLAG_PENDING_SECURITY, 712d57b0e8bSAndrei Emeltchenko }; 713d57b0e8bSAndrei Emeltchenko 714d5f7ac38SMat Martineau enum { 715d5f7ac38SMat Martineau L2CAP_TX_STATE_XMIT, 716d5f7ac38SMat Martineau L2CAP_TX_STATE_WAIT_F, 717d5f7ac38SMat Martineau }; 718d5f7ac38SMat Martineau 719d5f7ac38SMat Martineau enum { 720d5f7ac38SMat Martineau L2CAP_RX_STATE_RECV, 721d5f7ac38SMat Martineau L2CAP_RX_STATE_SREJ_SENT, 72208333283SMat Martineau L2CAP_RX_STATE_MOVE, 72308333283SMat Martineau L2CAP_RX_STATE_WAIT_P, 72408333283SMat Martineau L2CAP_RX_STATE_WAIT_F, 725d5f7ac38SMat Martineau }; 726d5f7ac38SMat Martineau 727d5f7ac38SMat Martineau enum { 728d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED, 729d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED_SREJ, 730d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED, 731d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED_SREJ, 732d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE, 733d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE_SREJ, 734d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID, 735d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID_IGNORE, 736d5f7ac38SMat Martineau }; 737d5f7ac38SMat Martineau 738d5f7ac38SMat Martineau enum { 739d5f7ac38SMat Martineau L2CAP_EV_DATA_REQUEST, 740d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_DETECTED, 741d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_CLEAR, 742d5f7ac38SMat Martineau L2CAP_EV_RECV_REQSEQ_AND_FBIT, 743d5f7ac38SMat Martineau L2CAP_EV_RECV_FBIT, 744d5f7ac38SMat Martineau L2CAP_EV_RETRANS_TO, 745d5f7ac38SMat Martineau L2CAP_EV_MONITOR_TO, 746d5f7ac38SMat Martineau L2CAP_EV_EXPLICIT_POLL, 747d5f7ac38SMat Martineau L2CAP_EV_RECV_IFRAME, 748d5f7ac38SMat Martineau L2CAP_EV_RECV_RR, 749d5f7ac38SMat Martineau L2CAP_EV_RECV_REJ, 750d5f7ac38SMat Martineau L2CAP_EV_RECV_RNR, 751d5f7ac38SMat Martineau L2CAP_EV_RECV_SREJ, 752d5f7ac38SMat Martineau L2CAP_EV_RECV_FRAME, 753d5f7ac38SMat Martineau }; 754d5f7ac38SMat Martineau 75508333283SMat Martineau enum { 75608333283SMat Martineau L2CAP_MOVE_ROLE_NONE, 75708333283SMat Martineau L2CAP_MOVE_ROLE_INITIATOR, 75808333283SMat Martineau L2CAP_MOVE_ROLE_RESPONDER, 75908333283SMat Martineau }; 76008333283SMat Martineau 76108333283SMat Martineau enum { 76208333283SMat Martineau L2CAP_MOVE_STABLE, 76308333283SMat Martineau L2CAP_MOVE_WAIT_REQ, 76408333283SMat Martineau L2CAP_MOVE_WAIT_RSP, 76508333283SMat Martineau L2CAP_MOVE_WAIT_RSP_SUCCESS, 76608333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM, 76708333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM_RSP, 76808333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_COMP, 76908333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_CFM, 77008333283SMat Martineau L2CAP_MOVE_WAIT_LOCAL_BUSY, 77108333283SMat Martineau L2CAP_MOVE_WAIT_PREPARE, 77208333283SMat Martineau }; 77308333283SMat Martineau 77430648372SJaganath Kanakkassery void l2cap_chan_hold(struct l2cap_chan *c); 77530648372SJaganath Kanakkassery void l2cap_chan_put(struct l2cap_chan *c); 776371fd835SUlisses Furquim 777c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan) 778c03b355eSAndrei Emeltchenko { 779c03b355eSAndrei Emeltchenko mutex_lock(&chan->lock); 780c03b355eSAndrei Emeltchenko } 781c03b355eSAndrei Emeltchenko 782c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 783c03b355eSAndrei Emeltchenko { 784c03b355eSAndrei Emeltchenko mutex_unlock(&chan->lock); 785c03b355eSAndrei Emeltchenko } 786c03b355eSAndrei Emeltchenko 787c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan, 788c2ec9c1bSGustavo F. Padovan struct delayed_work *work, long timeout) 789c2ec9c1bSGustavo F. Padovan { 790e05dcc32SAndrei Emeltchenko BT_DBG("chan %p state %s timeout %ld", chan, 791e05dcc32SAndrei Emeltchenko state_to_string(chan->state), timeout); 792c2ec9c1bSGustavo F. Padovan 7936f74b6f3SAndrei Emeltchenko /* If delayed work cancelled do not hold(chan) 7946f74b6f3SAndrei Emeltchenko since it is already done with previous set_timer */ 79517cd3f37SUlisses Furquim if (!cancel_delayed_work(work)) 796371fd835SUlisses Furquim l2cap_chan_hold(chan); 7976f74b6f3SAndrei Emeltchenko 798c2ec9c1bSGustavo F. Padovan schedule_delayed_work(work, timeout); 799c2ec9c1bSGustavo F. Padovan } 800c2ec9c1bSGustavo F. Padovan 80175b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan, 802371fd835SUlisses Furquim struct delayed_work *work) 803c2ec9c1bSGustavo F. Padovan { 80475b93b59SSzymon Janc bool ret; 80575b93b59SSzymon Janc 8066f74b6f3SAndrei Emeltchenko /* put(chan) if delayed work cancelled otherwise it 8076f74b6f3SAndrei Emeltchenko is done in delayed work function */ 80817cd3f37SUlisses Furquim ret = cancel_delayed_work(work); 80975b93b59SSzymon Janc if (ret) 810371fd835SUlisses Furquim l2cap_chan_put(chan); 81175b93b59SSzymon Janc 81275b93b59SSzymon Janc return ret; 813c2ec9c1bSGustavo F. Padovan } 814c2ec9c1bSGustavo F. Padovan 815c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 816c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 8171a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 8181a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 8191a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 820b83ddfe2SAndrzej Kaczmarek msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 8211a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 822c74e560cSGustavo F. Padovan 823836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 824836be934SAndrei Emeltchenko { 8255a364bd3SMat Martineau if (seq1 >= seq2) 8265a364bd3SMat Martineau return seq1 - seq2; 8275a364bd3SMat Martineau else 8285a364bd3SMat Martineau return chan->tx_win_max + 1 - seq2 + seq1; 829836be934SAndrei Emeltchenko } 830836be934SAndrei Emeltchenko 831836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 832836be934SAndrei Emeltchenko { 833836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 834836be934SAndrei Emeltchenko } 835836be934SAndrei Emeltchenko 8367e1af8a3SGustavo Padovan static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chan *chan) 8377e1af8a3SGustavo Padovan { 8387e1af8a3SGustavo Padovan return NULL; 8397e1af8a3SGustavo Padovan } 8407e1af8a3SGustavo Padovan 8417e1af8a3SGustavo Padovan static inline void l2cap_chan_no_teardown(struct l2cap_chan *chan, int err) 8427e1af8a3SGustavo Padovan { 8437e1af8a3SGustavo Padovan } 8447e1af8a3SGustavo Padovan 8457e1af8a3SGustavo Padovan static inline void l2cap_chan_no_ready(struct l2cap_chan *chan) 8467e1af8a3SGustavo Padovan { 8477e1af8a3SGustavo Padovan } 8481da177e4SLinus Torvalds 8492dc4e510SGustavo Padovan static inline void l2cap_chan_no_defer(struct l2cap_chan *chan) 8502dc4e510SGustavo Padovan { 8512dc4e510SGustavo Padovan } 8522dc4e510SGustavo Padovan 8532ce5fb51SMarcel Holtmann static inline void l2cap_chan_no_resume(struct l2cap_chan *chan) 8542ce5fb51SMarcel Holtmann { 8552ce5fb51SMarcel Holtmann } 8562ce5fb51SMarcel Holtmann 8575ec1bbe5SGustavo Padovan static inline void l2cap_chan_no_set_shutdown(struct l2cap_chan *chan) 8585ec1bbe5SGustavo Padovan { 8595ec1bbe5SGustavo Padovan } 8605ec1bbe5SGustavo Padovan 8618d836d71SGustavo Padovan static inline long l2cap_chan_no_get_sndtimeo(struct l2cap_chan *chan) 8628d836d71SGustavo Padovan { 8638d836d71SGustavo Padovan return 0; 8648d836d71SGustavo Padovan } 8658d836d71SGustavo Padovan 8660498878bSJukka Rissanen static inline int l2cap_chan_no_memcpy_fromiovec(struct l2cap_chan *chan, 8670498878bSJukka Rissanen unsigned char *kdata, 8680498878bSJukka Rissanen struct iovec *iov, 8690498878bSJukka Rissanen int len) 8700498878bSJukka Rissanen { 8710498878bSJukka Rissanen /* Following is safe since for compiler definitions of kvec and 8720498878bSJukka Rissanen * iovec are identical, yielding the same in-core layout and alignment 8730498878bSJukka Rissanen */ 8740498878bSJukka Rissanen struct kvec *vec = (struct kvec *)iov; 8750498878bSJukka Rissanen 8760498878bSJukka Rissanen while (len > 0) { 8770498878bSJukka Rissanen if (vec->iov_len) { 8780498878bSJukka Rissanen int copy = min_t(unsigned int, len, vec->iov_len); 8790498878bSJukka Rissanen memcpy(kdata, vec->iov_base, copy); 8800498878bSJukka Rissanen len -= copy; 8810498878bSJukka Rissanen kdata += copy; 8820498878bSJukka Rissanen vec->iov_base += copy; 8830498878bSJukka Rissanen vec->iov_len -= copy; 8840498878bSJukka Rissanen } 8850498878bSJukka Rissanen vec++; 8860498878bSJukka Rissanen } 8870498878bSJukka Rissanen 8880498878bSJukka Rissanen return 0; 8890498878bSJukka Rissanen } 8900498878bSJukka Rissanen 891eb939922SRusty Russell extern bool disable_ertm; 892bb58f747SGustavo F. Padovan 893bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 894bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 895b3916db3SDavid Herrmann bool l2cap_is_socket(struct socket *sock); 896bb58f747SGustavo F. Padovan 89727e2d4c8SJohan Hedberg void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan); 8988c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 89968983259SGustavo F. Padovan 9009e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 9019e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 9029e4425ffSGustavo F. Padovan 903eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void); 9040f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 905cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 9068e9f9892SAndre Guedes bdaddr_t *dst, u8 dst_type); 9078d46321cSMarcel Holtmann int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 908e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 909e7cafc45SJohan Hedberg int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator); 910bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan); 911466f8004SAndrei Emeltchenko int l2cap_ertm_init(struct l2cap_chan *chan); 912466f8004SAndrei Emeltchenko void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 91393c3e8f5SAndrei Emeltchenko void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 914466f8004SAndrei Emeltchenko void l2cap_chan_del(struct l2cap_chan *chan, int err); 915387a33e3SJohan Hedberg void l2cap_conn_update_id_addr(struct hci_conn *hcon); 9162766be48SAndrei Emeltchenko void l2cap_send_conn_req(struct l2cap_chan *chan); 9173f7a56c4SMat Martineau void l2cap_move_start(struct l2cap_chan *chan); 91827695fb4SAndrei Emeltchenko void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, 91927695fb4SAndrei Emeltchenko u8 status); 920a514b17fSAndrei Emeltchenko void __l2cap_physical_cfm(struct l2cap_chan *chan, int result); 921bb58f747SGustavo F. Padovan 9229c903e37SDavid Herrmann void l2cap_conn_get(struct l2cap_conn *conn); 9239c903e37SDavid Herrmann void l2cap_conn_put(struct l2cap_conn *conn); 9249c903e37SDavid Herrmann 9252c8e1411SDavid Herrmann int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); 9262c8e1411SDavid Herrmann void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user); 9272c8e1411SDavid Herrmann 9281da177e4SLinus Torvalds #endif /* __L2CAP_H */ 929