11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds BlueZ - Bluetooth protocol stack for Linux 31da177e4SLinus Torvalds Copyright (C) 2000-2001 Qualcomm Incorporated 4ce5706bdSGustavo F. Padovan Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org> 55d8868ffSGustavo F. Padovan Copyright (C) 2010 Google Inc. 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds This program is free software; you can redistribute it and/or modify 101da177e4SLinus Torvalds it under the terms of the GNU General Public License version 2 as 111da177e4SLinus Torvalds published by the Free Software Foundation; 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 141da177e4SLinus Torvalds OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 151da177e4SLinus Torvalds FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 161da177e4SLinus Torvalds IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 171da177e4SLinus Torvalds CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 181da177e4SLinus Torvalds WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 191da177e4SLinus Torvalds ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 201da177e4SLinus Torvalds OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 231da177e4SLinus Torvalds COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 241da177e4SLinus Torvalds SOFTWARE IS DISCLAIMED. 251da177e4SLinus Torvalds */ 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #ifndef __L2CAP_H 281da177e4SLinus Torvalds #define __L2CAP_H 291da177e4SLinus Torvalds 3088843ab0SAndrei Emeltchenko #include <asm/unaligned.h> 3188843ab0SAndrei Emeltchenko 321da177e4SLinus Torvalds /* L2CAP defaults */ 331da177e4SLinus Torvalds #define L2CAP_DEFAULT_MTU 672 34f2fcfcd6SGustavo F. Padovan #define L2CAP_DEFAULT_MIN_MTU 48 358936fa6dSAndrei Emeltchenko #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 368936fa6dSAndrei Emeltchenko #define L2CAP_EFS_DEFAULT_FLUSH_TO 0xFFFFFFFF 371c2acffbSGustavo F. Padovan #define L2CAP_DEFAULT_TX_WINDOW 63 386327eb98SAndrei Emeltchenko #define L2CAP_DEFAULT_EXT_WINDOW 0x3FFF 39e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX 3 40fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ 41e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 420b4558e3SAndrei Emeltchenko #define L2CAP_DEFAULT_MAX_PDU_SIZE 1492 /* Sized for AMP packet */ 43c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO 200 448f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_MAX_SDU_SIZE 0xFFFF 458f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF 468f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF 4794122bbeSMat Martineau #define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */ 488c3a4f00SAndre Guedes #define L2CAP_LE_MIN_MTU 23 491da177e4SLinus Torvalds 50ba13ccd9SMarcel Holtmann #define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100) 51ba13ccd9SMarcel Holtmann #define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000) 52ba13ccd9SMarcel Holtmann #define L2CAP_ENC_TIMEOUT msecs_to_jiffies(5000) 53ba13ccd9SMarcel Holtmann #define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000) 54ba13ccd9SMarcel Holtmann #define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000) 555b155ef9SMat Martineau #define L2CAP_MOVE_TIMEOUT msecs_to_jiffies(4000) 565b155ef9SMat Martineau #define L2CAP_MOVE_ERTX_TIMEOUT msecs_to_jiffies(60000) 571da177e4SLinus Torvalds 58466f8004SAndrei Emeltchenko #define L2CAP_A2MP_DEFAULT_MTU 670 59466f8004SAndrei Emeltchenko 601da177e4SLinus Torvalds /* L2CAP socket address */ 611da177e4SLinus Torvalds struct sockaddr_l2 { 621da177e4SLinus Torvalds sa_family_t l2_family; 638e036fc3SAl Viro __le16 l2_psm; 641da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 65f29972deSMarcel Holtmann __le16 l2_cid; 6643ef0b8bSAndre Guedes __u8 l2_bdaddr_type; 671da177e4SLinus Torvalds }; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* L2CAP socket options */ 701da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 711da177e4SLinus Torvalds struct l2cap_options { 721da177e4SLinus Torvalds __u16 omtu; 731da177e4SLinus Torvalds __u16 imtu; 741da177e4SLinus Torvalds __u16 flush_to; 751da177e4SLinus Torvalds __u8 mode; 76fcc203c3SGustavo F. Padovan __u8 fcs; 7768d7f0ceSGustavo F. Padovan __u8 max_tx; 7814b5aa71SGustavo F. Padovan __u16 txwin_size; 791da177e4SLinus Torvalds }; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 821da177e4SLinus Torvalds struct l2cap_conninfo { 831da177e4SLinus Torvalds __u16 hci_handle; 841da177e4SLinus Torvalds __u8 dev_class[3]; 851da177e4SLinus Torvalds }; 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds #define L2CAP_LM 0x03 881da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 891da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 901da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 911da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 921da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 931da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* L2CAP command codes */ 961da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 971da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 981da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 991da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 1001da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 1011da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 1021da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 1031da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 1041da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 1051da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 1061da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 10738094c75SMat Martineau #define L2CAP_CREATE_CHAN_REQ 0x0c 10838094c75SMat Martineau #define L2CAP_CREATE_CHAN_RSP 0x0d 10938094c75SMat Martineau #define L2CAP_MOVE_CHAN_REQ 0x0e 11038094c75SMat Martineau #define L2CAP_MOVE_CHAN_RSP 0x0f 11138094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM 0x10 11238094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM_RSP 0x11 1133300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 1143300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 115ee5ec5cfSJohan Hedberg #define L2CAP_LE_CONN_REQ 0x14 116ee5ec5cfSJohan Hedberg #define L2CAP_LE_CONN_RSP 0x15 117ee5ec5cfSJohan Hedberg #define L2CAP_LE_CREDITS 0x16 1181da177e4SLinus Torvalds 119a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 12047ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 12147ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 122a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 12347ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 12447ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 12547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 126a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 12747ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 128a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 129a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 13047ec1dcdSMarcel Holtmann 13147ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 13247ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 13347ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 13447ec1dcdSMarcel Holtmann 135d835ac0fSMat Martineau /* L2CAP fixed channels */ 136d835ac0fSMat Martineau #define L2CAP_FC_L2CAP 0x02 137d40bffbcSMarcel Holtmann #define L2CAP_FC_CONNLESS 0x04 138d835ac0fSMat Martineau #define L2CAP_FC_A2MP 0x08 139d835ac0fSMat Martineau 1401c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1411c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1421c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1431c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 14457253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 14557253fd8SAndrei Emeltchenko 1461c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1471c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1481c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1491c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1501c2acffbSGustavo F. Padovan 1511c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 15257253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 153d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT 4 154d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT 7 1551c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1568f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1571c2acffbSGustavo F. Padovan 15857253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 15957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 16057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 16157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 16257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 16357253fd8SAndrei Emeltchenko 16457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 16557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 16657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 16757253fd8SAndrei Emeltchenko 168d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT 1 16957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 17057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 17157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 172d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT 18 17357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 17457253fd8SAndrei Emeltchenko 1751c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 176ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 177ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 178ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 179ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1801c2acffbSGustavo F. Padovan 1811c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1827e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1837e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1847e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1857e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1861c2acffbSGustavo F. Padovan 187e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 188e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 189e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 190e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 191e2fd318eSIlia Kolomisnky 1921da177e4SLinus Torvalds /* L2CAP structures */ 1931da177e4SLinus Torvalds struct l2cap_hdr { 1948e036fc3SAl Viro __le16 len; 1958e036fc3SAl Viro __le16 cid; 19666c853ccSGustavo F. Padovan } __packed; 1971da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 198d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 199d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 200d43cb289SAndrei Emeltchenko 201d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 202d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 203d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 204d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE 2 205d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE 4 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds struct l2cap_cmd_hdr { 2081da177e4SLinus Torvalds __u8 code; 2091da177e4SLinus Torvalds __u8 ident; 2108e036fc3SAl Viro __le16 len; 21166c853ccSGustavo F. Padovan } __packed; 2121da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 2131da177e4SLinus Torvalds 214e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 2158e036fc3SAl Viro __le16 reason; 21666c853ccSGustavo F. Padovan } __packed; 2171da177e4SLinus Torvalds 218e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 219e2fd318eSIlia Kolomisnky __le16 reason; 220e2fd318eSIlia Kolomisnky __le16 max_mtu; 221e2fd318eSIlia Kolomisnky } __packed; 222e2fd318eSIlia Kolomisnky 223e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 224e2fd318eSIlia Kolomisnky __le16 reason; 225e2fd318eSIlia Kolomisnky __le16 scid; 226e2fd318eSIlia Kolomisnky __le16 dcid; 227e2fd318eSIlia Kolomisnky } __packed; 228e2fd318eSIlia Kolomisnky 2291da177e4SLinus Torvalds struct l2cap_conn_req { 2308e036fc3SAl Viro __le16 psm; 2318e036fc3SAl Viro __le16 scid; 23266c853ccSGustavo F. Padovan } __packed; 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds struct l2cap_conn_rsp { 2358e036fc3SAl Viro __le16 dcid; 2368e036fc3SAl Viro __le16 scid; 2378e036fc3SAl Viro __le16 result; 2388e036fc3SAl Viro __le16 status; 23966c853ccSGustavo F. Padovan } __packed; 2401da177e4SLinus Torvalds 2412983fd68SAndrei Emeltchenko /* protocol/service multiplexer (PSM) */ 2422983fd68SAndrei Emeltchenko #define L2CAP_PSM_SDP 0x0001 2432983fd68SAndrei Emeltchenko #define L2CAP_PSM_RFCOMM 0x0003 2443124b843SMarcel Holtmann #define L2CAP_PSM_3DSP 0x0021 2452983fd68SAndrei Emeltchenko 2463f79410cSMaxime Jayat /* channel identifier */ 2478db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2488db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 249466f8004SAndrei Emeltchenko #define L2CAP_CID_A2MP 0x0003 250073d1cf3SJohan Hedberg #define L2CAP_CID_ATT 0x0004 251acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 252acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2538db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2548db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 255*e77af755SJohan Hedberg #define L2CAP_CID_LE_DYN_END 0x007f 2568db4dc46SGustavo F. Padovan 25738094c75SMat Martineau /* connect/create channel results */ 2581da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2591da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2601da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2611da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2621da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 26338094c75SMat Martineau #define L2CAP_CR_BAD_AMP 0x0005 264ee5ec5cfSJohan Hedberg #define L2CAP_CR_AUTHENTICATION 0x0005 265ee5ec5cfSJohan Hedberg #define L2CAP_CR_AUTHORIZATION 0x0006 266ee5ec5cfSJohan Hedberg #define L2CAP_CR_BAD_KEY_SIZE 0x0007 267ee5ec5cfSJohan Hedberg #define L2CAP_CR_ENCRYPTION 0x0008 2681da177e4SLinus Torvalds 26938094c75SMat Martineau /* connect/create channel status */ 2701da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2711da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2721da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds struct l2cap_conf_req { 2758e036fc3SAl Viro __le16 dcid; 2768e036fc3SAl Viro __le16 flags; 2771da177e4SLinus Torvalds __u8 data[0]; 27866c853ccSGustavo F. Padovan } __packed; 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds struct l2cap_conf_rsp { 2818e036fc3SAl Viro __le16 scid; 2828e036fc3SAl Viro __le16 flags; 2838e036fc3SAl Viro __le16 result; 2841da177e4SLinus Torvalds __u8 data[0]; 28566c853ccSGustavo F. Padovan } __packed; 2861da177e4SLinus Torvalds 2875dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2885dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2895dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2905dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2910e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 2925a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 2931da177e4SLinus Torvalds 29459e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */ 29559e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION 0x0001 29659e54bd1SAndrei Emeltchenko 2971da177e4SLinus Torvalds struct l2cap_conf_opt { 2981da177e4SLinus Torvalds __u8 type; 2991da177e4SLinus Torvalds __u8 len; 3001da177e4SLinus Torvalds __u8 val[0]; 30166c853ccSGustavo F. Padovan } __packed; 3021da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 3031da177e4SLinus Torvalds 304589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 30547ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 306589d2746SGustavo F. Padovan 3071da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 3081da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 3091da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 3101da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 31147ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 3125a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 3136327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 3161da177e4SLinus Torvalds 3176464f35fSMarcel Holtmann struct l2cap_conf_rfc { 3186464f35fSMarcel Holtmann __u8 mode; 3196464f35fSMarcel Holtmann __u8 txwin_size; 3206464f35fSMarcel Holtmann __u8 max_transmit; 3216464f35fSMarcel Holtmann __le16 retrans_timeout; 3226464f35fSMarcel Holtmann __le16 monitor_timeout; 3236464f35fSMarcel Holtmann __le16 max_pdu_size; 32466c853ccSGustavo F. Padovan } __packed; 3256464f35fSMarcel Holtmann 3266464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 3276464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 3286464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 32947ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 330c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 3316464f35fSMarcel Holtmann 33238319713SJohan Hedberg /* Unlike the above this one doesn't actually map to anything that would 33338319713SJohan Hedberg * ever be sent over the air. Therefore, use a value that's unlikely to 33438319713SJohan Hedberg * ever be used in the BR/EDR configuration phase. 33538319713SJohan Hedberg */ 33638319713SJohan Hedberg #define L2CAP_MODE_LE_FLOWCTL 0x80 33738319713SJohan Hedberg 3385a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 3395a9e7057SAndrei Emeltchenko __u8 id; 3405a9e7057SAndrei Emeltchenko __u8 stype; 3415a9e7057SAndrei Emeltchenko __le16 msdu; 3425a9e7057SAndrei Emeltchenko __le32 sdu_itime; 3435a9e7057SAndrei Emeltchenko __le32 acc_lat; 3445a9e7057SAndrei Emeltchenko __le32 flush_to; 3455a9e7057SAndrei Emeltchenko } __packed; 3465a9e7057SAndrei Emeltchenko 3478f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 3488f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 3498f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 3508f7975b1SAndrei Emeltchenko 3518f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3528f7975b1SAndrei Emeltchenko 3531da177e4SLinus Torvalds struct l2cap_disconn_req { 3548e036fc3SAl Viro __le16 dcid; 3558e036fc3SAl Viro __le16 scid; 35666c853ccSGustavo F. Padovan } __packed; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3598e036fc3SAl Viro __le16 dcid; 3608e036fc3SAl Viro __le16 scid; 36166c853ccSGustavo F. Padovan } __packed; 3621da177e4SLinus Torvalds 3631da177e4SLinus Torvalds struct l2cap_info_req { 3648e036fc3SAl Viro __le16 type; 36566c853ccSGustavo F. Padovan } __packed; 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds struct l2cap_info_rsp { 3688e036fc3SAl Viro __le16 type; 3698e036fc3SAl Viro __le16 result; 3701da177e4SLinus Torvalds __u8 data[0]; 37166c853ccSGustavo F. Padovan } __packed; 3721da177e4SLinus Torvalds 37338094c75SMat Martineau struct l2cap_create_chan_req { 37438094c75SMat Martineau __le16 psm; 37538094c75SMat Martineau __le16 scid; 37638094c75SMat Martineau __u8 amp_id; 37738094c75SMat Martineau } __packed; 37838094c75SMat Martineau 37938094c75SMat Martineau struct l2cap_create_chan_rsp { 38038094c75SMat Martineau __le16 dcid; 38138094c75SMat Martineau __le16 scid; 38238094c75SMat Martineau __le16 result; 38338094c75SMat Martineau __le16 status; 38438094c75SMat Martineau } __packed; 38538094c75SMat Martineau 38638094c75SMat Martineau struct l2cap_move_chan_req { 38738094c75SMat Martineau __le16 icid; 38838094c75SMat Martineau __u8 dest_amp_id; 38938094c75SMat Martineau } __packed; 39038094c75SMat Martineau 39138094c75SMat Martineau struct l2cap_move_chan_rsp { 39238094c75SMat Martineau __le16 icid; 39338094c75SMat Martineau __le16 result; 39438094c75SMat Martineau } __packed; 39538094c75SMat Martineau 39638094c75SMat Martineau #define L2CAP_MR_SUCCESS 0x0000 39738094c75SMat Martineau #define L2CAP_MR_PEND 0x0001 39838094c75SMat Martineau #define L2CAP_MR_BAD_ID 0x0002 39938094c75SMat Martineau #define L2CAP_MR_SAME_ID 0x0003 40038094c75SMat Martineau #define L2CAP_MR_NOT_SUPP 0x0004 40138094c75SMat Martineau #define L2CAP_MR_COLLISION 0x0005 40238094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED 0x0006 40338094c75SMat Martineau 40438094c75SMat Martineau struct l2cap_move_chan_cfm { 40538094c75SMat Martineau __le16 icid; 40638094c75SMat Martineau __le16 result; 40738094c75SMat Martineau } __packed; 40838094c75SMat Martineau 40938094c75SMat Martineau #define L2CAP_MC_CONFIRMED 0x0000 41038094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED 0x0001 41138094c75SMat Martineau 41238094c75SMat Martineau struct l2cap_move_chan_cfm_rsp { 41338094c75SMat Martineau __le16 icid; 41438094c75SMat Martineau } __packed; 41538094c75SMat Martineau 4161da177e4SLinus Torvalds /* info type */ 4171da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 4181da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 419e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds /* info result */ 4221da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 4231da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 4241da177e4SLinus Torvalds 425de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 426de73115aSClaudio Takahasi __le16 min; 427de73115aSClaudio Takahasi __le16 max; 428de73115aSClaudio Takahasi __le16 latency; 429de73115aSClaudio Takahasi __le16 to_multiplier; 430de73115aSClaudio Takahasi } __packed; 431de73115aSClaudio Takahasi 432de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 433de73115aSClaudio Takahasi __le16 result; 434de73115aSClaudio Takahasi } __packed; 435de73115aSClaudio Takahasi 436de73115aSClaudio Takahasi /* Connection Parameters result */ 437de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 438de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 439de73115aSClaudio Takahasi 440ee5ec5cfSJohan Hedberg #define L2CAP_LE_MAX_CREDITS 10 441ee5ec5cfSJohan Hedberg #define L2CAP_LE_DEFAULT_MPS 230 442ee5ec5cfSJohan Hedberg 443ee5ec5cfSJohan Hedberg struct l2cap_le_conn_req { 444ee5ec5cfSJohan Hedberg __le16 psm; 445ee5ec5cfSJohan Hedberg __le16 scid; 446ee5ec5cfSJohan Hedberg __le16 mtu; 447ee5ec5cfSJohan Hedberg __le16 mps; 448ee5ec5cfSJohan Hedberg __le16 credits; 449ee5ec5cfSJohan Hedberg } __packed; 450ee5ec5cfSJohan Hedberg 451ee5ec5cfSJohan Hedberg struct l2cap_le_conn_rsp { 452ee5ec5cfSJohan Hedberg __le16 dcid; 453ee5ec5cfSJohan Hedberg __le16 mtu; 454ee5ec5cfSJohan Hedberg __le16 mps; 455ee5ec5cfSJohan Hedberg __le16 credits; 456ee5ec5cfSJohan Hedberg __le16 result; 457ee5ec5cfSJohan Hedberg } __packed; 458ee5ec5cfSJohan Hedberg 459ee5ec5cfSJohan Hedberg struct l2cap_le_credits { 460ee5ec5cfSJohan Hedberg __le16 cid; 461ee5ec5cfSJohan Hedberg __le16 credits; 462ee5ec5cfSJohan Hedberg } __packed; 463ee5ec5cfSJohan Hedberg 46448454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 4653c588192SMat Martineau struct l2cap_seq_list { 4663c588192SMat Martineau __u16 head; 4673c588192SMat Martineau __u16 tail; 4683c588192SMat Martineau __u16 mask; 4693c588192SMat Martineau __u16 *list; 4703c588192SMat Martineau }; 4713c588192SMat Martineau 4723c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR 0xFFFF 4733c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL 0x8000 4743c588192SMat Martineau 47548454079SGustavo F. Padovan struct l2cap_chan { 4768c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 47708333283SMat Martineau struct hci_conn *hs_hcon; 47808333283SMat Martineau struct hci_chan *hs_hchan; 479144ad330SSyam Sidhardhan struct kref kref; 4808c1d787bSGustavo F. Padovan 48189bc500eSGustavo F. Padovan __u8 state; 48289bc500eSGustavo F. Padovan 4837eafc59eSMarcel Holtmann bdaddr_t dst; 4844f1654e0SMarcel Holtmann __u8 dst_type; 4857eafc59eSMarcel Holtmann bdaddr_t src; 4864f1654e0SMarcel Holtmann __u8 src_type; 487fe4128e0SGustavo F. Padovan __le16 psm; 4884f1654e0SMarcel Holtmann __le16 sport; 489fe4128e0SGustavo F. Padovan __u16 dcid; 490fe4128e0SGustavo F. Padovan __u16 scid; 4914343478fSGustavo F. Padovan 4920c1bc5c6SGustavo F. Padovan __u16 imtu; 4930c1bc5c6SGustavo F. Padovan __u16 omtu; 4940c1bc5c6SGustavo F. Padovan __u16 flush_to; 4950c1bc5c6SGustavo F. Padovan __u8 mode; 496715ec005SGustavo F. Padovan __u8 chan_type; 4972ea66482SMat Martineau __u8 chan_policy; 4980c1bc5c6SGustavo F. Padovan 4994343478fSGustavo F. Padovan __u8 sec_level; 5004343478fSGustavo F. Padovan 501fc7f8a7eSGustavo F. Padovan __u8 ident; 502fc7f8a7eSGustavo F. Padovan 50373ffa904SGustavo F. Padovan __u8 conf_req[64]; 50473ffa904SGustavo F. Padovan __u8 conf_len; 50573ffa904SGustavo F. Padovan __u8 num_conf_req; 50673ffa904SGustavo F. Padovan __u8 num_conf_rsp; 50773ffa904SGustavo F. Padovan 50847d1ec61SGustavo F. Padovan __u8 fcs; 50947d1ec61SGustavo F. Padovan 5106327eb98SAndrei Emeltchenko __u16 tx_win; 511836be934SAndrei Emeltchenko __u16 tx_win_max; 512c20f8e35SMat Martineau __u16 ack_win; 51347d1ec61SGustavo F. Padovan __u8 max_tx; 51447d1ec61SGustavo F. Padovan __u16 retrans_timeout; 51547d1ec61SGustavo F. Padovan __u16 monitor_timeout; 51647d1ec61SGustavo F. Padovan __u16 mps; 51747d1ec61SGustavo F. Padovan 5180cd75f7eSJohan Hedberg __u16 tx_credits; 5190cd75f7eSJohan Hedberg __u16 rx_credits; 5200cd75f7eSJohan Hedberg 521d5f7ac38SMat Martineau __u8 tx_state; 522d5f7ac38SMat Martineau __u8 rx_state; 523d5f7ac38SMat Martineau 524c1360a1cSGustavo F. Padovan unsigned long conf_state; 525e2ab4353SGustavo F. Padovan unsigned long conn_state; 526d57b0e8bSAndrei Emeltchenko unsigned long flags; 527525cd185SGustavo F. Padovan 528fffadc08SAndrei Emeltchenko __u8 remote_amp_id; 52908333283SMat Martineau __u8 local_amp_id; 53008333283SMat Martineau __u8 move_id; 53108333283SMat Martineau __u8 move_state; 53208333283SMat Martineau __u8 move_role; 53308333283SMat Martineau 534fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 535fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 536fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 5370b209faeSAndrei Emeltchenko __u16 buffer_seq; 538fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 539d5f7ac38SMat Martineau __u16 last_acked_seq; 540fb45de7dSAndrei Emeltchenko __u16 frames_sent; 541fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 5426a026610SGustavo F. Padovan __u8 retry_count; 5436f61fd47SGustavo F. Padovan __u16 sdu_len; 5446f61fd47SGustavo F. Padovan struct sk_buff *sdu; 54584084a31SMat Martineau struct sk_buff *sdu_last_frag; 5466f61fd47SGustavo F. Padovan 5476327eb98SAndrei Emeltchenko __u16 remote_tx_win; 5482c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 5492c03a7a4SGustavo F. Padovan __u16 remote_mps; 55042e5c802SGustavo F. Padovan 5515a9e7057SAndrei Emeltchenko __u8 local_id; 5525a9e7057SAndrei Emeltchenko __u8 local_stype; 5535a9e7057SAndrei Emeltchenko __u16 local_msdu; 5545a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 5555a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 5565a9e7057SAndrei Emeltchenko __u32 local_flush_to; 5575a9e7057SAndrei Emeltchenko 5585a9e7057SAndrei Emeltchenko __u8 remote_id; 5595a9e7057SAndrei Emeltchenko __u8 remote_stype; 5605a9e7057SAndrei Emeltchenko __u16 remote_msdu; 5615a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 5625a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 5635a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 5645a9e7057SAndrei Emeltchenko 565721c4181SGustavo F. Padovan struct delayed_work chan_timer; 566721c4181SGustavo F. Padovan struct delayed_work retrans_timer; 567721c4181SGustavo F. Padovan struct delayed_work monitor_timer; 568721c4181SGustavo F. Padovan struct delayed_work ack_timer; 569721c4181SGustavo F. Padovan 57058d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 57158d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 572f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 5733c588192SMat Martineau struct l2cap_seq_list srej_list; 5743c588192SMat Martineau struct l2cap_seq_list retrans_list; 575e92c8e70SGustavo F. Padovan 576baa7e1faSGustavo F. Padovan struct list_head list; 57723691d75SGustavo F. Padovan struct list_head global_l; 57880808e43SGustavo F. Padovan 57980808e43SGustavo F. Padovan void *data; 58080808e43SGustavo F. Padovan struct l2cap_ops *ops; 581c03b355eSAndrei Emeltchenko struct mutex lock; 58280808e43SGustavo F. Padovan }; 58380808e43SGustavo F. Padovan 58480808e43SGustavo F. Padovan struct l2cap_ops { 58580808e43SGustavo F. Padovan char *name; 58680808e43SGustavo F. Padovan 58780b98027SGustavo Padovan struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan); 58880b98027SGustavo Padovan int (*recv) (struct l2cap_chan * chan, 58980b98027SGustavo Padovan struct sk_buff *skb); 590c0df7f6eSAndrei Emeltchenko void (*teardown) (struct l2cap_chan *chan, int err); 59180b98027SGustavo Padovan void (*close) (struct l2cap_chan *chan); 59280b98027SGustavo Padovan void (*state_change) (struct l2cap_chan *chan, 59353f52121SGustavo Padovan int state, int err); 59454a59aa2SAndrei Emeltchenko void (*ready) (struct l2cap_chan *chan); 5952dc4e510SGustavo Padovan void (*defer) (struct l2cap_chan *chan); 596d97c899bSMarcel Holtmann void (*resume) (struct l2cap_chan *chan); 597837776f7SJohan Hedberg void (*suspend) (struct l2cap_chan *chan); 5985ec1bbe5SGustavo Padovan void (*set_shutdown) (struct l2cap_chan *chan); 5998d836d71SGustavo Padovan long (*get_sndtimeo) (struct l2cap_chan *chan); 6002f7719ceSAndrei Emeltchenko struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 60190338947SGustavo Padovan unsigned long len, int nb); 6021da177e4SLinus Torvalds }; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds struct l2cap_conn { 6051da177e4SLinus Torvalds struct hci_conn *hcon; 60673d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds unsigned int mtu; 6091da177e4SLinus Torvalds 6104e8402a3SMarcel Holtmann __u32 feat_mask; 611978c93b9SAndrei Emeltchenko __u8 fixed_chan_mask; 612848566b3SMarcel Holtmann bool hs_enabled; 6134e8402a3SMarcel Holtmann 6144e8402a3SMarcel Holtmann __u8 info_state; 6154e8402a3SMarcel Holtmann __u8 info_ident; 6164e8402a3SMarcel Holtmann 617030013d8SGustavo F. Padovan struct delayed_work info_timer; 6184e8402a3SMarcel Holtmann 6191da177e4SLinus Torvalds spinlock_t lock; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds struct sk_buff *rx_skb; 6221da177e4SLinus Torvalds __u32 rx_len; 6231da177e4SLinus Torvalds __u8 tx_ident; 6241da177e4SLinus Torvalds 6252950f21aSMarcel Holtmann __u8 disc_reason; 6262950f21aSMarcel Holtmann 6276c9d42a1SGustavo F. Padovan struct delayed_work security_timer; 6281c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 6295d3de7dfSVinicius Costa Gomes 630baa7e1faSGustavo F. Padovan struct list_head chan_l; 631d01b2ff4SGustavo F. Padovan struct mutex chan_lock; 6329c903e37SDavid Herrmann struct kref ref; 6332c8e1411SDavid Herrmann struct list_head users; 6342c8e1411SDavid Herrmann }; 6352c8e1411SDavid Herrmann 6362c8e1411SDavid Herrmann struct l2cap_user { 6372c8e1411SDavid Herrmann struct list_head list; 6382c8e1411SDavid Herrmann int (*probe) (struct l2cap_conn *conn, struct l2cap_user *user); 6392c8e1411SDavid Herrmann void (*remove) (struct l2cap_conn *conn, struct l2cap_user *user); 6401da177e4SLinus Torvalds }; 6411da177e4SLinus Torvalds 6424e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 643984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 644984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 6454e8402a3SMarcel Holtmann 646715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 647715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 648715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 649416fa752SAndrei Emeltchenko #define L2CAP_CHAN_CONN_FIX_A2MP 4 650715ec005SGustavo F. Padovan 65148454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 6521da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds struct l2cap_pinfo { 6551da177e4SLinus Torvalds struct bt_sock bt; 65648454079SGustavo F. Padovan struct l2cap_chan *chan; 657e328140fSMat Martineau struct sk_buff *rx_busy_skb; 6581da177e4SLinus Torvalds }; 6591da177e4SLinus Torvalds 660c1360a1cSGustavo F. Padovan enum { 661c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 662c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 663c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 664c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 665c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 666c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 667f2592d3eSAndrei Emeltchenko CONF_RECV_NO_FCS, 668c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 6696327eb98SAndrei Emeltchenko CONF_EWS_RECV, 6700e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 6710e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 6722827011fSMat Martineau CONF_NOT_COMPLETE, 673c1360a1cSGustavo F. Padovan }; 674861d6882SMarcel Holtmann 675f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 676f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 677f2fcfcd6SGustavo F. Padovan 678e2ab4353SGustavo F. Padovan enum { 679e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 680e2ab4353SGustavo F. Padovan CONN_WAIT_F, 681e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 682e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 683e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 684e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 685e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 686e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 687e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 688e2ab4353SGustavo F. Padovan }; 689e90bac06SGustavo F. Padovan 690d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 691d57b0e8bSAndrei Emeltchenko enum { 69243bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 69315770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 694ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 695d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 6966327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 6975a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 698bdc25783SMarcel Holtmann FLAG_DEFER_SETUP, 699595177f3SJohan Hedberg FLAG_LE_CONN_REQ_SENT, 700d57b0e8bSAndrei Emeltchenko }; 701d57b0e8bSAndrei Emeltchenko 702d5f7ac38SMat Martineau enum { 703d5f7ac38SMat Martineau L2CAP_TX_STATE_XMIT, 704d5f7ac38SMat Martineau L2CAP_TX_STATE_WAIT_F, 705d5f7ac38SMat Martineau }; 706d5f7ac38SMat Martineau 707d5f7ac38SMat Martineau enum { 708d5f7ac38SMat Martineau L2CAP_RX_STATE_RECV, 709d5f7ac38SMat Martineau L2CAP_RX_STATE_SREJ_SENT, 71008333283SMat Martineau L2CAP_RX_STATE_MOVE, 71108333283SMat Martineau L2CAP_RX_STATE_WAIT_P, 71208333283SMat Martineau L2CAP_RX_STATE_WAIT_F, 713d5f7ac38SMat Martineau }; 714d5f7ac38SMat Martineau 715d5f7ac38SMat Martineau enum { 716d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED, 717d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED_SREJ, 718d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED, 719d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED_SREJ, 720d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE, 721d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE_SREJ, 722d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID, 723d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID_IGNORE, 724d5f7ac38SMat Martineau }; 725d5f7ac38SMat Martineau 726d5f7ac38SMat Martineau enum { 727d5f7ac38SMat Martineau L2CAP_EV_DATA_REQUEST, 728d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_DETECTED, 729d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_CLEAR, 730d5f7ac38SMat Martineau L2CAP_EV_RECV_REQSEQ_AND_FBIT, 731d5f7ac38SMat Martineau L2CAP_EV_RECV_FBIT, 732d5f7ac38SMat Martineau L2CAP_EV_RETRANS_TO, 733d5f7ac38SMat Martineau L2CAP_EV_MONITOR_TO, 734d5f7ac38SMat Martineau L2CAP_EV_EXPLICIT_POLL, 735d5f7ac38SMat Martineau L2CAP_EV_RECV_IFRAME, 736d5f7ac38SMat Martineau L2CAP_EV_RECV_RR, 737d5f7ac38SMat Martineau L2CAP_EV_RECV_REJ, 738d5f7ac38SMat Martineau L2CAP_EV_RECV_RNR, 739d5f7ac38SMat Martineau L2CAP_EV_RECV_SREJ, 740d5f7ac38SMat Martineau L2CAP_EV_RECV_FRAME, 741d5f7ac38SMat Martineau }; 742d5f7ac38SMat Martineau 74308333283SMat Martineau enum { 74408333283SMat Martineau L2CAP_MOVE_ROLE_NONE, 74508333283SMat Martineau L2CAP_MOVE_ROLE_INITIATOR, 74608333283SMat Martineau L2CAP_MOVE_ROLE_RESPONDER, 74708333283SMat Martineau }; 74808333283SMat Martineau 74908333283SMat Martineau enum { 75008333283SMat Martineau L2CAP_MOVE_STABLE, 75108333283SMat Martineau L2CAP_MOVE_WAIT_REQ, 75208333283SMat Martineau L2CAP_MOVE_WAIT_RSP, 75308333283SMat Martineau L2CAP_MOVE_WAIT_RSP_SUCCESS, 75408333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM, 75508333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM_RSP, 75608333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_COMP, 75708333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_CFM, 75808333283SMat Martineau L2CAP_MOVE_WAIT_LOCAL_BUSY, 75908333283SMat Martineau L2CAP_MOVE_WAIT_PREPARE, 76008333283SMat Martineau }; 76108333283SMat Martineau 76230648372SJaganath Kanakkassery void l2cap_chan_hold(struct l2cap_chan *c); 76330648372SJaganath Kanakkassery void l2cap_chan_put(struct l2cap_chan *c); 764371fd835SUlisses Furquim 765c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan) 766c03b355eSAndrei Emeltchenko { 767c03b355eSAndrei Emeltchenko mutex_lock(&chan->lock); 768c03b355eSAndrei Emeltchenko } 769c03b355eSAndrei Emeltchenko 770c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 771c03b355eSAndrei Emeltchenko { 772c03b355eSAndrei Emeltchenko mutex_unlock(&chan->lock); 773c03b355eSAndrei Emeltchenko } 774c03b355eSAndrei Emeltchenko 775c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan, 776c2ec9c1bSGustavo F. Padovan struct delayed_work *work, long timeout) 777c2ec9c1bSGustavo F. Padovan { 778e05dcc32SAndrei Emeltchenko BT_DBG("chan %p state %s timeout %ld", chan, 779e05dcc32SAndrei Emeltchenko state_to_string(chan->state), timeout); 780c2ec9c1bSGustavo F. Padovan 7816f74b6f3SAndrei Emeltchenko /* If delayed work cancelled do not hold(chan) 7826f74b6f3SAndrei Emeltchenko since it is already done with previous set_timer */ 78317cd3f37SUlisses Furquim if (!cancel_delayed_work(work)) 784371fd835SUlisses Furquim l2cap_chan_hold(chan); 7856f74b6f3SAndrei Emeltchenko 786c2ec9c1bSGustavo F. Padovan schedule_delayed_work(work, timeout); 787c2ec9c1bSGustavo F. Padovan } 788c2ec9c1bSGustavo F. Padovan 78975b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan, 790371fd835SUlisses Furquim struct delayed_work *work) 791c2ec9c1bSGustavo F. Padovan { 79275b93b59SSzymon Janc bool ret; 79375b93b59SSzymon Janc 7946f74b6f3SAndrei Emeltchenko /* put(chan) if delayed work cancelled otherwise it 7956f74b6f3SAndrei Emeltchenko is done in delayed work function */ 79617cd3f37SUlisses Furquim ret = cancel_delayed_work(work); 79775b93b59SSzymon Janc if (ret) 798371fd835SUlisses Furquim l2cap_chan_put(chan); 79975b93b59SSzymon Janc 80075b93b59SSzymon Janc return ret; 801c2ec9c1bSGustavo F. Padovan } 802c2ec9c1bSGustavo F. Padovan 803c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 804c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 8051a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 8061a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 8071a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 808b83ddfe2SAndrzej Kaczmarek msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 8091a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 810c74e560cSGustavo F. Padovan 811836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 812836be934SAndrei Emeltchenko { 8135a364bd3SMat Martineau if (seq1 >= seq2) 8145a364bd3SMat Martineau return seq1 - seq2; 8155a364bd3SMat Martineau else 8165a364bd3SMat Martineau return chan->tx_win_max + 1 - seq2 + seq1; 817836be934SAndrei Emeltchenko } 818836be934SAndrei Emeltchenko 819836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 820836be934SAndrei Emeltchenko { 821836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 822836be934SAndrei Emeltchenko } 823836be934SAndrei Emeltchenko 8247e1af8a3SGustavo Padovan static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chan *chan) 8257e1af8a3SGustavo Padovan { 8267e1af8a3SGustavo Padovan return NULL; 8277e1af8a3SGustavo Padovan } 8287e1af8a3SGustavo Padovan 8297e1af8a3SGustavo Padovan static inline void l2cap_chan_no_teardown(struct l2cap_chan *chan, int err) 8307e1af8a3SGustavo Padovan { 8317e1af8a3SGustavo Padovan } 8327e1af8a3SGustavo Padovan 8337e1af8a3SGustavo Padovan static inline void l2cap_chan_no_ready(struct l2cap_chan *chan) 8347e1af8a3SGustavo Padovan { 8357e1af8a3SGustavo Padovan } 8361da177e4SLinus Torvalds 8372dc4e510SGustavo Padovan static inline void l2cap_chan_no_defer(struct l2cap_chan *chan) 8382dc4e510SGustavo Padovan { 8392dc4e510SGustavo Padovan } 8402dc4e510SGustavo Padovan 8412ce5fb51SMarcel Holtmann static inline void l2cap_chan_no_resume(struct l2cap_chan *chan) 8422ce5fb51SMarcel Holtmann { 8432ce5fb51SMarcel Holtmann } 8442ce5fb51SMarcel Holtmann 8455ec1bbe5SGustavo Padovan static inline void l2cap_chan_no_set_shutdown(struct l2cap_chan *chan) 8465ec1bbe5SGustavo Padovan { 8475ec1bbe5SGustavo Padovan } 8485ec1bbe5SGustavo Padovan 8498d836d71SGustavo Padovan static inline long l2cap_chan_no_get_sndtimeo(struct l2cap_chan *chan) 8508d836d71SGustavo Padovan { 8518d836d71SGustavo Padovan return 0; 8528d836d71SGustavo Padovan } 8538d836d71SGustavo Padovan 854eb939922SRusty Russell extern bool disable_ertm; 8559149761aSJohan Hedberg extern bool enable_lecoc; 856bb58f747SGustavo F. Padovan 857bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 858bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 859b3916db3SDavid Herrmann bool l2cap_is_socket(struct socket *sock); 860bb58f747SGustavo F. Padovan 86127e2d4c8SJohan Hedberg void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan); 8628c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 86368983259SGustavo F. Padovan 8649e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 8659e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 8669e4425ffSGustavo F. Padovan 867eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void); 8680f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 869cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 8708e9f9892SAndre Guedes bdaddr_t *dst, u8 dst_type); 8715e59b791SLuiz Augusto von Dentz int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 8725e59b791SLuiz Augusto von Dentz u32 priority); 873e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 874d45fc423SGustavo F. Padovan int l2cap_chan_check_security(struct l2cap_chan *chan); 875bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan); 87638319713SJohan Hedberg void l2cap_le_flowctl_init(struct l2cap_chan *chan); 877466f8004SAndrei Emeltchenko int l2cap_ertm_init(struct l2cap_chan *chan); 878466f8004SAndrei Emeltchenko void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 87993c3e8f5SAndrei Emeltchenko void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 880466f8004SAndrei Emeltchenko void l2cap_chan_del(struct l2cap_chan *chan, int err); 8812766be48SAndrei Emeltchenko void l2cap_send_conn_req(struct l2cap_chan *chan); 8823f7a56c4SMat Martineau void l2cap_move_start(struct l2cap_chan *chan); 88327695fb4SAndrei Emeltchenko void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, 88427695fb4SAndrei Emeltchenko u8 status); 885a514b17fSAndrei Emeltchenko void __l2cap_physical_cfm(struct l2cap_chan *chan, int result); 886bb58f747SGustavo F. Padovan 8879c903e37SDavid Herrmann void l2cap_conn_get(struct l2cap_conn *conn); 8889c903e37SDavid Herrmann void l2cap_conn_put(struct l2cap_conn *conn); 8899c903e37SDavid Herrmann 8902c8e1411SDavid Herrmann int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); 8912c8e1411SDavid Herrmann void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user); 8922c8e1411SDavid Herrmann 8931da177e4SLinus Torvalds #endif /* __L2CAP_H */ 894