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> 31abe84903SJohan Hedberg #include <linux/atomic.h> 3288843ab0SAndrei Emeltchenko 331da177e4SLinus Torvalds /* L2CAP defaults */ 341da177e4SLinus Torvalds #define L2CAP_DEFAULT_MTU 672 35f2fcfcd6SGustavo F. Padovan #define L2CAP_DEFAULT_MIN_MTU 48 368936fa6dSAndrei Emeltchenko #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 378936fa6dSAndrei Emeltchenko #define L2CAP_EFS_DEFAULT_FLUSH_TO 0xFFFFFFFF 381c2acffbSGustavo F. Padovan #define L2CAP_DEFAULT_TX_WINDOW 63 396327eb98SAndrei Emeltchenko #define L2CAP_DEFAULT_EXT_WINDOW 0x3FFF 40e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX 3 41fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ 42e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 430b4558e3SAndrei Emeltchenko #define L2CAP_DEFAULT_MAX_PDU_SIZE 1492 /* Sized for AMP packet */ 44c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO 200 458f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_MAX_SDU_SIZE 0xFFFF 468f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF 478f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF 4894122bbeSMat Martineau #define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */ 498c3a4f00SAndre Guedes #define L2CAP_LE_MIN_MTU 23 501da177e4SLinus Torvalds 51ba13ccd9SMarcel Holtmann #define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100) 52ba13ccd9SMarcel Holtmann #define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000) 53ba13ccd9SMarcel Holtmann #define L2CAP_ENC_TIMEOUT msecs_to_jiffies(5000) 54ba13ccd9SMarcel Holtmann #define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000) 55ba13ccd9SMarcel Holtmann #define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000) 565b155ef9SMat Martineau #define L2CAP_MOVE_TIMEOUT msecs_to_jiffies(4000) 575b155ef9SMat Martineau #define L2CAP_MOVE_ERTX_TIMEOUT msecs_to_jiffies(60000) 58cb02a255SDean Jenkins #define L2CAP_WAIT_ACK_POLL_PERIOD msecs_to_jiffies(200) 59e432c72cSDean Jenkins #define L2CAP_WAIT_ACK_TIMEOUT msecs_to_jiffies(10000) 601da177e4SLinus Torvalds 61466f8004SAndrei Emeltchenko #define L2CAP_A2MP_DEFAULT_MTU 670 62466f8004SAndrei Emeltchenko 631da177e4SLinus Torvalds /* L2CAP socket address */ 641da177e4SLinus Torvalds struct sockaddr_l2 { 651da177e4SLinus Torvalds sa_family_t l2_family; 668e036fc3SAl Viro __le16 l2_psm; 671da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 68f29972deSMarcel Holtmann __le16 l2_cid; 6943ef0b8bSAndre Guedes __u8 l2_bdaddr_type; 701da177e4SLinus Torvalds }; 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /* L2CAP socket options */ 731da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 741da177e4SLinus Torvalds struct l2cap_options { 751da177e4SLinus Torvalds __u16 omtu; 761da177e4SLinus Torvalds __u16 imtu; 771da177e4SLinus Torvalds __u16 flush_to; 781da177e4SLinus Torvalds __u8 mode; 79fcc203c3SGustavo F. Padovan __u8 fcs; 8068d7f0ceSGustavo F. Padovan __u8 max_tx; 8114b5aa71SGustavo F. Padovan __u16 txwin_size; 821da177e4SLinus Torvalds }; 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 851da177e4SLinus Torvalds struct l2cap_conninfo { 861da177e4SLinus Torvalds __u16 hci_handle; 871da177e4SLinus Torvalds __u8 dev_class[3]; 881da177e4SLinus Torvalds }; 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds #define L2CAP_LM 0x03 911da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 921da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 931da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 941da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 951da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 961da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 977d513e92SMarcel Holtmann #define L2CAP_LM_FIPS 0x0040 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds /* L2CAP command codes */ 1001da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 1011da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 1021da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 1031da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 1041da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 1051da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 1061da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 1071da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 1081da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 1091da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 1101da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 11138094c75SMat Martineau #define L2CAP_CREATE_CHAN_REQ 0x0c 11238094c75SMat Martineau #define L2CAP_CREATE_CHAN_RSP 0x0d 11338094c75SMat Martineau #define L2CAP_MOVE_CHAN_REQ 0x0e 11438094c75SMat Martineau #define L2CAP_MOVE_CHAN_RSP 0x0f 11538094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM 0x10 11638094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM_RSP 0x11 1173300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 1183300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 119ee5ec5cfSJohan Hedberg #define L2CAP_LE_CONN_REQ 0x14 120ee5ec5cfSJohan Hedberg #define L2CAP_LE_CONN_RSP 0x15 121ee5ec5cfSJohan Hedberg #define L2CAP_LE_CREDITS 0x16 122*14572096SLuiz Augusto von Dentz #define L2CAP_ECRED_CONN_REQ 0x17 123*14572096SLuiz Augusto von Dentz #define L2CAP_ECRED_CONN_RSP 0x18 124*14572096SLuiz Augusto von Dentz #define L2CAP_ECRED_RECONF_REQ 0x19 125*14572096SLuiz Augusto von Dentz #define L2CAP_ECRED_RECONF_RSP 0x1a 1261da177e4SLinus Torvalds 127a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 12847ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 12947ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 130a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 13147ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 13247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 13347ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 134a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 13547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 136a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 137a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 13847ec1dcdSMarcel Holtmann 13947ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 14047ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 14147ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 14247ec1dcdSMarcel Holtmann 143d835ac0fSMat Martineau /* L2CAP fixed channels */ 144a6801ca9SMarcel Holtmann #define L2CAP_FC_SIG_BREDR 0x02 145d40bffbcSMarcel Holtmann #define L2CAP_FC_CONNLESS 0x04 146d835ac0fSMat Martineau #define L2CAP_FC_A2MP 0x08 147a6801ca9SMarcel Holtmann #define L2CAP_FC_ATT 0x10 148a6801ca9SMarcel Holtmann #define L2CAP_FC_SIG_LE 0x20 149a6801ca9SMarcel Holtmann #define L2CAP_FC_SMP_LE 0x40 150ef8efe4bSJohan Hedberg #define L2CAP_FC_SMP_BREDR 0x80 151d835ac0fSMat Martineau 1521c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1531c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1541c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1551c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 15657253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 15757253fd8SAndrei Emeltchenko 1581c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1591c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1601c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1611c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1621c2acffbSGustavo F. Padovan 1631c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 16457253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 165d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT 4 166d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT 7 1671c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1688f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1691c2acffbSGustavo F. Padovan 17057253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 17157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 17257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 17357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 17457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 17557253fd8SAndrei Emeltchenko 17657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 17757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 17857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 17957253fd8SAndrei Emeltchenko 180d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT 1 18157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 18257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 18357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 184d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT 18 18557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 18657253fd8SAndrei Emeltchenko 1871c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 188ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 189ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 190ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 191ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1921c2acffbSGustavo F. Padovan 1931c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1947e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1957e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1967e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1977e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1981c2acffbSGustavo F. Padovan 199e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 200e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 201e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 202e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 203e2fd318eSIlia Kolomisnky 2041da177e4SLinus Torvalds /* L2CAP structures */ 2051da177e4SLinus Torvalds struct l2cap_hdr { 2068e036fc3SAl Viro __le16 len; 2078e036fc3SAl Viro __le16 cid; 20866c853ccSGustavo F. Padovan } __packed; 2091da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 210d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 211d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 212d43cb289SAndrei Emeltchenko 213d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 214d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 215d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 216d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE 2 217d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE 4 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds struct l2cap_cmd_hdr { 2201da177e4SLinus Torvalds __u8 code; 2211da177e4SLinus Torvalds __u8 ident; 2228e036fc3SAl Viro __le16 len; 22366c853ccSGustavo F. Padovan } __packed; 2241da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 2251da177e4SLinus Torvalds 226e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 2278e036fc3SAl Viro __le16 reason; 22866c853ccSGustavo F. Padovan } __packed; 2291da177e4SLinus Torvalds 230e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 231e2fd318eSIlia Kolomisnky __le16 reason; 232e2fd318eSIlia Kolomisnky __le16 max_mtu; 233e2fd318eSIlia Kolomisnky } __packed; 234e2fd318eSIlia Kolomisnky 235e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 236e2fd318eSIlia Kolomisnky __le16 reason; 237e2fd318eSIlia Kolomisnky __le16 scid; 238e2fd318eSIlia Kolomisnky __le16 dcid; 239e2fd318eSIlia Kolomisnky } __packed; 240e2fd318eSIlia Kolomisnky 2411da177e4SLinus Torvalds struct l2cap_conn_req { 2428e036fc3SAl Viro __le16 psm; 2438e036fc3SAl Viro __le16 scid; 24466c853ccSGustavo F. Padovan } __packed; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds struct l2cap_conn_rsp { 2478e036fc3SAl Viro __le16 dcid; 2488e036fc3SAl Viro __le16 scid; 2498e036fc3SAl Viro __le16 result; 2508e036fc3SAl Viro __le16 status; 25166c853ccSGustavo F. Padovan } __packed; 2521da177e4SLinus Torvalds 2532983fd68SAndrei Emeltchenko /* protocol/service multiplexer (PSM) */ 2542983fd68SAndrei Emeltchenko #define L2CAP_PSM_SDP 0x0001 2552983fd68SAndrei Emeltchenko #define L2CAP_PSM_RFCOMM 0x0003 2563124b843SMarcel Holtmann #define L2CAP_PSM_3DSP 0x0021 257cab9e3a0SJukka Rissanen #define L2CAP_PSM_IPSP 0x0023 /* 6LoWPAN */ 2582983fd68SAndrei Emeltchenko 259114f9f1eSJohan Hedberg #define L2CAP_PSM_DYN_START 0x1001 260114f9f1eSJohan Hedberg #define L2CAP_PSM_DYN_END 0xffff 261114f9f1eSJohan Hedberg #define L2CAP_PSM_AUTO_END 0x10ff 262114f9f1eSJohan Hedberg #define L2CAP_PSM_LE_DYN_START 0x0080 263114f9f1eSJohan Hedberg #define L2CAP_PSM_LE_DYN_END 0x00ff 264114f9f1eSJohan Hedberg 2653f79410cSMaxime Jayat /* channel identifier */ 2668db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2678db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 268466f8004SAndrei Emeltchenko #define L2CAP_CID_A2MP 0x0003 269073d1cf3SJohan Hedberg #define L2CAP_CID_ATT 0x0004 270acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 271acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 272ef8efe4bSJohan Hedberg #define L2CAP_CID_SMP_BREDR 0x0007 2738db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2748db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 275e77af755SJohan Hedberg #define L2CAP_CID_LE_DYN_END 0x007f 2768db4dc46SGustavo F. Padovan 27738094c75SMat Martineau /* connect/create channel results */ 2781da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2791da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2801da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2811da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2821da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 28338094c75SMat Martineau #define L2CAP_CR_BAD_AMP 0x0005 284dd1a8f8aSMallikarjun Phulari #define L2CAP_CR_INVALID_SCID 0x0006 285dd1a8f8aSMallikarjun Phulari #define L2CAP_CR_SCID_IN_USE 0x0007 286571f7390SMallikarjun Phulari 287571f7390SMallikarjun Phulari /* credit based connect results */ 288571f7390SMallikarjun Phulari #define L2CAP_CR_LE_SUCCESS 0x0000 289571f7390SMallikarjun Phulari #define L2CAP_CR_LE_BAD_PSM 0x0002 290571f7390SMallikarjun Phulari #define L2CAP_CR_LE_NO_MEM 0x0004 291571f7390SMallikarjun Phulari #define L2CAP_CR_LE_AUTHENTICATION 0x0005 292571f7390SMallikarjun Phulari #define L2CAP_CR_LE_AUTHORIZATION 0x0006 293571f7390SMallikarjun Phulari #define L2CAP_CR_LE_BAD_KEY_SIZE 0x0007 294571f7390SMallikarjun Phulari #define L2CAP_CR_LE_ENCRYPTION 0x0008 295571f7390SMallikarjun Phulari #define L2CAP_CR_LE_INVALID_SCID 0x0009 296571f7390SMallikarjun Phulari #define L2CAP_CR_LE_SCID_IN_USE 0X000A 2971da177e4SLinus Torvalds 29838094c75SMat Martineau /* connect/create channel status */ 2991da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 3001da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 3011da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvalds struct l2cap_conf_req { 3048e036fc3SAl Viro __le16 dcid; 3058e036fc3SAl Viro __le16 flags; 306a7e45454SGustavo A. R. Silva __u8 data[]; 30766c853ccSGustavo F. Padovan } __packed; 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds struct l2cap_conf_rsp { 3108e036fc3SAl Viro __le16 scid; 3118e036fc3SAl Viro __le16 flags; 3128e036fc3SAl Viro __le16 result; 313a7e45454SGustavo A. R. Silva __u8 data[]; 31466c853ccSGustavo F. Padovan } __packed; 3151da177e4SLinus Torvalds 3165dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 3175dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 3185dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 3195dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 3200e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 3215a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 3221da177e4SLinus Torvalds 32359e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */ 32459e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION 0x0001 32559e54bd1SAndrei Emeltchenko 3261da177e4SLinus Torvalds struct l2cap_conf_opt { 3271da177e4SLinus Torvalds __u8 type; 3281da177e4SLinus Torvalds __u8 len; 329a7e45454SGustavo A. R. Silva __u8 val[]; 33066c853ccSGustavo F. Padovan } __packed; 3311da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 3321da177e4SLinus Torvalds 333589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 33447ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 335589d2746SGustavo F. Padovan 3361da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 3371da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 3381da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 3391da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 34047ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 3415a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 3426327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 3451da177e4SLinus Torvalds 3466464f35fSMarcel Holtmann struct l2cap_conf_rfc { 3476464f35fSMarcel Holtmann __u8 mode; 3486464f35fSMarcel Holtmann __u8 txwin_size; 3496464f35fSMarcel Holtmann __u8 max_transmit; 3506464f35fSMarcel Holtmann __le16 retrans_timeout; 3516464f35fSMarcel Holtmann __le16 monitor_timeout; 3526464f35fSMarcel Holtmann __le16 max_pdu_size; 35366c853ccSGustavo F. Padovan } __packed; 3546464f35fSMarcel Holtmann 3556464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 3566464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 3576464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 35847ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 359c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 3606464f35fSMarcel Holtmann 36138319713SJohan Hedberg /* Unlike the above this one doesn't actually map to anything that would 36238319713SJohan Hedberg * ever be sent over the air. Therefore, use a value that's unlikely to 36338319713SJohan Hedberg * ever be used in the BR/EDR configuration phase. 36438319713SJohan Hedberg */ 36538319713SJohan Hedberg #define L2CAP_MODE_LE_FLOWCTL 0x80 366*14572096SLuiz Augusto von Dentz #define L2CAP_MODE_EXT_FLOWCTL 0x81 36738319713SJohan Hedberg 3685a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 3695a9e7057SAndrei Emeltchenko __u8 id; 3705a9e7057SAndrei Emeltchenko __u8 stype; 3715a9e7057SAndrei Emeltchenko __le16 msdu; 3725a9e7057SAndrei Emeltchenko __le32 sdu_itime; 3735a9e7057SAndrei Emeltchenko __le32 acc_lat; 3745a9e7057SAndrei Emeltchenko __le32 flush_to; 3755a9e7057SAndrei Emeltchenko } __packed; 3765a9e7057SAndrei Emeltchenko 3778f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 3788f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 3798f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 3808f7975b1SAndrei Emeltchenko 3818f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3828f7975b1SAndrei Emeltchenko 3831da177e4SLinus Torvalds struct l2cap_disconn_req { 3848e036fc3SAl Viro __le16 dcid; 3858e036fc3SAl Viro __le16 scid; 38666c853ccSGustavo F. Padovan } __packed; 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3898e036fc3SAl Viro __le16 dcid; 3908e036fc3SAl Viro __le16 scid; 39166c853ccSGustavo F. Padovan } __packed; 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds struct l2cap_info_req { 3948e036fc3SAl Viro __le16 type; 39566c853ccSGustavo F. Padovan } __packed; 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds struct l2cap_info_rsp { 3988e036fc3SAl Viro __le16 type; 3998e036fc3SAl Viro __le16 result; 400a7e45454SGustavo A. R. Silva __u8 data[]; 40166c853ccSGustavo F. Padovan } __packed; 4021da177e4SLinus Torvalds 40338094c75SMat Martineau struct l2cap_create_chan_req { 40438094c75SMat Martineau __le16 psm; 40538094c75SMat Martineau __le16 scid; 40638094c75SMat Martineau __u8 amp_id; 40738094c75SMat Martineau } __packed; 40838094c75SMat Martineau 40938094c75SMat Martineau struct l2cap_create_chan_rsp { 41038094c75SMat Martineau __le16 dcid; 41138094c75SMat Martineau __le16 scid; 41238094c75SMat Martineau __le16 result; 41338094c75SMat Martineau __le16 status; 41438094c75SMat Martineau } __packed; 41538094c75SMat Martineau 41638094c75SMat Martineau struct l2cap_move_chan_req { 41738094c75SMat Martineau __le16 icid; 41838094c75SMat Martineau __u8 dest_amp_id; 41938094c75SMat Martineau } __packed; 42038094c75SMat Martineau 42138094c75SMat Martineau struct l2cap_move_chan_rsp { 42238094c75SMat Martineau __le16 icid; 42338094c75SMat Martineau __le16 result; 42438094c75SMat Martineau } __packed; 42538094c75SMat Martineau 42638094c75SMat Martineau #define L2CAP_MR_SUCCESS 0x0000 42738094c75SMat Martineau #define L2CAP_MR_PEND 0x0001 42838094c75SMat Martineau #define L2CAP_MR_BAD_ID 0x0002 42938094c75SMat Martineau #define L2CAP_MR_SAME_ID 0x0003 43038094c75SMat Martineau #define L2CAP_MR_NOT_SUPP 0x0004 43138094c75SMat Martineau #define L2CAP_MR_COLLISION 0x0005 43238094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED 0x0006 43338094c75SMat Martineau 43438094c75SMat Martineau struct l2cap_move_chan_cfm { 43538094c75SMat Martineau __le16 icid; 43638094c75SMat Martineau __le16 result; 43738094c75SMat Martineau } __packed; 43838094c75SMat Martineau 43938094c75SMat Martineau #define L2CAP_MC_CONFIRMED 0x0000 44038094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED 0x0001 44138094c75SMat Martineau 44238094c75SMat Martineau struct l2cap_move_chan_cfm_rsp { 44338094c75SMat Martineau __le16 icid; 44438094c75SMat Martineau } __packed; 44538094c75SMat Martineau 4461da177e4SLinus Torvalds /* info type */ 4471da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 4481da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 449e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds /* info result */ 4521da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 4531da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 4541da177e4SLinus Torvalds 455de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 456de73115aSClaudio Takahasi __le16 min; 457de73115aSClaudio Takahasi __le16 max; 458de73115aSClaudio Takahasi __le16 latency; 459de73115aSClaudio Takahasi __le16 to_multiplier; 460de73115aSClaudio Takahasi } __packed; 461de73115aSClaudio Takahasi 462de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 463de73115aSClaudio Takahasi __le16 result; 464de73115aSClaudio Takahasi } __packed; 465de73115aSClaudio Takahasi 466de73115aSClaudio Takahasi /* Connection Parameters result */ 467de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 468de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 469de73115aSClaudio Takahasi 470ee5ec5cfSJohan Hedberg struct l2cap_le_conn_req { 471ee5ec5cfSJohan Hedberg __le16 psm; 472ee5ec5cfSJohan Hedberg __le16 scid; 473ee5ec5cfSJohan Hedberg __le16 mtu; 474ee5ec5cfSJohan Hedberg __le16 mps; 475ee5ec5cfSJohan Hedberg __le16 credits; 476ee5ec5cfSJohan Hedberg } __packed; 477ee5ec5cfSJohan Hedberg 478ee5ec5cfSJohan Hedberg struct l2cap_le_conn_rsp { 479ee5ec5cfSJohan Hedberg __le16 dcid; 480ee5ec5cfSJohan Hedberg __le16 mtu; 481ee5ec5cfSJohan Hedberg __le16 mps; 482ee5ec5cfSJohan Hedberg __le16 credits; 483ee5ec5cfSJohan Hedberg __le16 result; 484ee5ec5cfSJohan Hedberg } __packed; 485ee5ec5cfSJohan Hedberg 486ee5ec5cfSJohan Hedberg struct l2cap_le_credits { 487ee5ec5cfSJohan Hedberg __le16 cid; 488ee5ec5cfSJohan Hedberg __le16 credits; 489ee5ec5cfSJohan Hedberg } __packed; 490ee5ec5cfSJohan Hedberg 491*14572096SLuiz Augusto von Dentz #define L2CAP_ECRED_MIN_MTU 64 492*14572096SLuiz Augusto von Dentz #define L2CAP_ECRED_MIN_MPS 64 493*14572096SLuiz Augusto von Dentz 494*14572096SLuiz Augusto von Dentz struct l2cap_ecred_conn_req { 495*14572096SLuiz Augusto von Dentz __le16 psm; 496*14572096SLuiz Augusto von Dentz __le16 mtu; 497*14572096SLuiz Augusto von Dentz __le16 mps; 498*14572096SLuiz Augusto von Dentz __le16 credits; 499*14572096SLuiz Augusto von Dentz __le16 scid[0]; 500*14572096SLuiz Augusto von Dentz } __packed; 501*14572096SLuiz Augusto von Dentz 502*14572096SLuiz Augusto von Dentz struct l2cap_ecred_conn_rsp { 503*14572096SLuiz Augusto von Dentz __le16 mtu; 504*14572096SLuiz Augusto von Dentz __le16 mps; 505*14572096SLuiz Augusto von Dentz __le16 credits; 506*14572096SLuiz Augusto von Dentz __le16 result; 507*14572096SLuiz Augusto von Dentz __le16 dcid[0]; 508*14572096SLuiz Augusto von Dentz }; 509*14572096SLuiz Augusto von Dentz 510*14572096SLuiz Augusto von Dentz struct l2cap_ecred_reconf_req { 511*14572096SLuiz Augusto von Dentz __le16 mtu; 512*14572096SLuiz Augusto von Dentz __le16 mps; 513*14572096SLuiz Augusto von Dentz __le16 scid[0]; 514*14572096SLuiz Augusto von Dentz } __packed; 515*14572096SLuiz Augusto von Dentz 516*14572096SLuiz Augusto von Dentz #define L2CAP_RECONF_SUCCESS 0x0000 517*14572096SLuiz Augusto von Dentz #define L2CAP_RECONF_INVALID_MTU 0x0001 518*14572096SLuiz Augusto von Dentz #define L2CAP_RECONF_INVALID_MPS 0x0002 519*14572096SLuiz Augusto von Dentz 520*14572096SLuiz Augusto von Dentz struct l2cap_ecred_reconf_rsp { 521*14572096SLuiz Augusto von Dentz __le16 result; 522*14572096SLuiz Augusto von Dentz } __packed; 523*14572096SLuiz Augusto von Dentz 52448454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 5253c588192SMat Martineau struct l2cap_seq_list { 5263c588192SMat Martineau __u16 head; 5273c588192SMat Martineau __u16 tail; 5283c588192SMat Martineau __u16 mask; 5293c588192SMat Martineau __u16 *list; 5303c588192SMat Martineau }; 5313c588192SMat Martineau 5323c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR 0xFFFF 5333c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL 0x8000 5343c588192SMat Martineau 53548454079SGustavo F. Padovan struct l2cap_chan { 5368c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 53708333283SMat Martineau struct hci_conn *hs_hcon; 53808333283SMat Martineau struct hci_chan *hs_hchan; 539144ad330SSyam Sidhardhan struct kref kref; 540abe84903SJohan Hedberg atomic_t nesting; 5418c1d787bSGustavo F. Padovan 54289bc500eSGustavo F. Padovan __u8 state; 54389bc500eSGustavo F. Padovan 5447eafc59eSMarcel Holtmann bdaddr_t dst; 5454f1654e0SMarcel Holtmann __u8 dst_type; 5467eafc59eSMarcel Holtmann bdaddr_t src; 5474f1654e0SMarcel Holtmann __u8 src_type; 548fe4128e0SGustavo F. Padovan __le16 psm; 5494f1654e0SMarcel Holtmann __le16 sport; 550fe4128e0SGustavo F. Padovan __u16 dcid; 551fe4128e0SGustavo F. Padovan __u16 scid; 5524343478fSGustavo F. Padovan 5530c1bc5c6SGustavo F. Padovan __u16 imtu; 5540c1bc5c6SGustavo F. Padovan __u16 omtu; 5550c1bc5c6SGustavo F. Padovan __u16 flush_to; 5560c1bc5c6SGustavo F. Padovan __u8 mode; 557715ec005SGustavo F. Padovan __u8 chan_type; 5582ea66482SMat Martineau __u8 chan_policy; 5590c1bc5c6SGustavo F. Padovan 5604343478fSGustavo F. Padovan __u8 sec_level; 5614343478fSGustavo F. Padovan 562fc7f8a7eSGustavo F. Padovan __u8 ident; 563fc7f8a7eSGustavo F. Padovan 56473ffa904SGustavo F. Padovan __u8 conf_req[64]; 56573ffa904SGustavo F. Padovan __u8 conf_len; 56673ffa904SGustavo F. Padovan __u8 num_conf_req; 56773ffa904SGustavo F. Padovan __u8 num_conf_rsp; 56873ffa904SGustavo F. Padovan 56947d1ec61SGustavo F. Padovan __u8 fcs; 57047d1ec61SGustavo F. Padovan 5716327eb98SAndrei Emeltchenko __u16 tx_win; 572836be934SAndrei Emeltchenko __u16 tx_win_max; 573c20f8e35SMat Martineau __u16 ack_win; 57447d1ec61SGustavo F. Padovan __u8 max_tx; 57547d1ec61SGustavo F. Padovan __u16 retrans_timeout; 57647d1ec61SGustavo F. Padovan __u16 monitor_timeout; 57747d1ec61SGustavo F. Padovan __u16 mps; 57847d1ec61SGustavo F. Padovan 5790cd75f7eSJohan Hedberg __u16 tx_credits; 5800cd75f7eSJohan Hedberg __u16 rx_credits; 5810cd75f7eSJohan Hedberg 582d5f7ac38SMat Martineau __u8 tx_state; 583d5f7ac38SMat Martineau __u8 rx_state; 584d5f7ac38SMat Martineau 585c1360a1cSGustavo F. Padovan unsigned long conf_state; 586e2ab4353SGustavo F. Padovan unsigned long conn_state; 587d57b0e8bSAndrei Emeltchenko unsigned long flags; 588525cd185SGustavo F. Padovan 589fffadc08SAndrei Emeltchenko __u8 remote_amp_id; 59008333283SMat Martineau __u8 local_amp_id; 59108333283SMat Martineau __u8 move_id; 59208333283SMat Martineau __u8 move_state; 59308333283SMat Martineau __u8 move_role; 59408333283SMat Martineau 595fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 596fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 597fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 5980b209faeSAndrei Emeltchenko __u16 buffer_seq; 599fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 600d5f7ac38SMat Martineau __u16 last_acked_seq; 601fb45de7dSAndrei Emeltchenko __u16 frames_sent; 602fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 6036a026610SGustavo F. Padovan __u8 retry_count; 6046f61fd47SGustavo F. Padovan __u16 sdu_len; 6056f61fd47SGustavo F. Padovan struct sk_buff *sdu; 60684084a31SMat Martineau struct sk_buff *sdu_last_frag; 6076f61fd47SGustavo F. Padovan 6086327eb98SAndrei Emeltchenko __u16 remote_tx_win; 6092c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 6102c03a7a4SGustavo F. Padovan __u16 remote_mps; 61142e5c802SGustavo F. Padovan 6125a9e7057SAndrei Emeltchenko __u8 local_id; 6135a9e7057SAndrei Emeltchenko __u8 local_stype; 6145a9e7057SAndrei Emeltchenko __u16 local_msdu; 6155a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 6165a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 6175a9e7057SAndrei Emeltchenko __u32 local_flush_to; 6185a9e7057SAndrei Emeltchenko 6195a9e7057SAndrei Emeltchenko __u8 remote_id; 6205a9e7057SAndrei Emeltchenko __u8 remote_stype; 6215a9e7057SAndrei Emeltchenko __u16 remote_msdu; 6225a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 6235a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 6245a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 6255a9e7057SAndrei Emeltchenko 626721c4181SGustavo F. Padovan struct delayed_work chan_timer; 627721c4181SGustavo F. Padovan struct delayed_work retrans_timer; 628721c4181SGustavo F. Padovan struct delayed_work monitor_timer; 629721c4181SGustavo F. Padovan struct delayed_work ack_timer; 630721c4181SGustavo F. Padovan 63158d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 63258d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 633f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 6343c588192SMat Martineau struct l2cap_seq_list srej_list; 6353c588192SMat Martineau struct l2cap_seq_list retrans_list; 636e92c8e70SGustavo F. Padovan 637baa7e1faSGustavo F. Padovan struct list_head list; 63823691d75SGustavo F. Padovan struct list_head global_l; 63980808e43SGustavo F. Padovan 64080808e43SGustavo F. Padovan void *data; 64167f86a45SMarcel Holtmann const struct l2cap_ops *ops; 642c03b355eSAndrei Emeltchenko struct mutex lock; 64380808e43SGustavo F. Padovan }; 64480808e43SGustavo F. Padovan 64580808e43SGustavo F. Padovan struct l2cap_ops { 64680808e43SGustavo F. Padovan char *name; 64780808e43SGustavo F. Padovan 64880b98027SGustavo Padovan struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan); 64980b98027SGustavo Padovan int (*recv) (struct l2cap_chan * chan, 65080b98027SGustavo Padovan struct sk_buff *skb); 651c0df7f6eSAndrei Emeltchenko void (*teardown) (struct l2cap_chan *chan, int err); 65280b98027SGustavo Padovan void (*close) (struct l2cap_chan *chan); 65380b98027SGustavo Padovan void (*state_change) (struct l2cap_chan *chan, 65453f52121SGustavo Padovan int state, int err); 65554a59aa2SAndrei Emeltchenko void (*ready) (struct l2cap_chan *chan); 6562dc4e510SGustavo Padovan void (*defer) (struct l2cap_chan *chan); 657d97c899bSMarcel Holtmann void (*resume) (struct l2cap_chan *chan); 658837776f7SJohan Hedberg void (*suspend) (struct l2cap_chan *chan); 6595ec1bbe5SGustavo Padovan void (*set_shutdown) (struct l2cap_chan *chan); 6608d836d71SGustavo Padovan long (*get_sndtimeo) (struct l2cap_chan *chan); 6612f7719ceSAndrei Emeltchenko struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 662d9fbd02bSMarcel Holtmann unsigned long hdr_len, 66390338947SGustavo Padovan unsigned long len, int nb); 6641da177e4SLinus Torvalds }; 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds struct l2cap_conn { 6671da177e4SLinus Torvalds struct hci_conn *hcon; 66873d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds unsigned int mtu; 6711da177e4SLinus Torvalds 6724e8402a3SMarcel Holtmann __u32 feat_mask; 6730bd49fc7SJohan Hedberg __u8 remote_fixed_chan; 6740bd49fc7SJohan Hedberg __u8 local_fixed_chan; 6754e8402a3SMarcel Holtmann 6764e8402a3SMarcel Holtmann __u8 info_state; 6774e8402a3SMarcel Holtmann __u8 info_ident; 6784e8402a3SMarcel Holtmann 679030013d8SGustavo F. Padovan struct delayed_work info_timer; 6804e8402a3SMarcel Holtmann 6811da177e4SLinus Torvalds struct sk_buff *rx_skb; 6821da177e4SLinus Torvalds __u32 rx_len; 6831da177e4SLinus Torvalds __u8 tx_ident; 6845a54e7c8SMarcel Holtmann struct mutex ident_lock; 6851da177e4SLinus Torvalds 68661a939c6SJohan Hedberg struct sk_buff_head pending_rx; 68761a939c6SJohan Hedberg struct work_struct pending_rx_work; 68861a939c6SJohan Hedberg 689f3d82d0cSJohan Hedberg struct work_struct id_addr_update_work; 690f3d82d0cSJohan Hedberg 6912950f21aSMarcel Holtmann __u8 disc_reason; 6922950f21aSMarcel Holtmann 69370db83c4SJohan Hedberg struct l2cap_chan *smp; 6945d3de7dfSVinicius Costa Gomes 695baa7e1faSGustavo F. Padovan struct list_head chan_l; 696d01b2ff4SGustavo F. Padovan struct mutex chan_lock; 6979c903e37SDavid Herrmann struct kref ref; 6982c8e1411SDavid Herrmann struct list_head users; 6992c8e1411SDavid Herrmann }; 7002c8e1411SDavid Herrmann 7012c8e1411SDavid Herrmann struct l2cap_user { 7022c8e1411SDavid Herrmann struct list_head list; 7032c8e1411SDavid Herrmann int (*probe) (struct l2cap_conn *conn, struct l2cap_user *user); 7042c8e1411SDavid Herrmann void (*remove) (struct l2cap_conn *conn, struct l2cap_user *user); 7051da177e4SLinus Torvalds }; 7061da177e4SLinus Torvalds 7074e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 708984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 709984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 7104e8402a3SMarcel Holtmann 711715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 712715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 713715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 7142338a7e0SJohan Hedberg #define L2CAP_CHAN_FIXED 4 715715ec005SGustavo F. Padovan 71648454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 7171da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds struct l2cap_pinfo { 7201da177e4SLinus Torvalds struct bt_sock bt; 72148454079SGustavo F. Padovan struct l2cap_chan *chan; 722e328140fSMat Martineau struct sk_buff *rx_busy_skb; 7231da177e4SLinus Torvalds }; 7241da177e4SLinus Torvalds 725c1360a1cSGustavo F. Padovan enum { 726c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 727c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 728c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 729c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 730c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 731c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 732f2592d3eSAndrei Emeltchenko CONF_RECV_NO_FCS, 733c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 7346327eb98SAndrei Emeltchenko CONF_EWS_RECV, 7350e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 7360e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 7372827011fSMat Martineau CONF_NOT_COMPLETE, 738c1360a1cSGustavo F. Padovan }; 739861d6882SMarcel Holtmann 740f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 741f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 742f2fcfcd6SGustavo F. Padovan 743e2ab4353SGustavo F. Padovan enum { 744e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 745e2ab4353SGustavo F. Padovan CONN_WAIT_F, 746e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 747e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 748e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 749e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 750e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 751e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 752e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 753e2ab4353SGustavo F. Padovan }; 754e90bac06SGustavo F. Padovan 755d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 756d57b0e8bSAndrei Emeltchenko enum { 75743bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 75815770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 759ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 760d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 7616327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 7625a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 763bdc25783SMarcel Holtmann FLAG_DEFER_SETUP, 764595177f3SJohan Hedberg FLAG_LE_CONN_REQ_SENT, 765*14572096SLuiz Augusto von Dentz FLAG_ECRED_CONN_REQ_SENT, 766d52deb17SJohan Hedberg FLAG_PENDING_SECURITY, 767c16900cfSJohan Hedberg FLAG_HOLD_HCI_CONN, 768d57b0e8bSAndrei Emeltchenko }; 769d57b0e8bSAndrei Emeltchenko 770abe84903SJohan Hedberg /* Lock nesting levels for L2CAP channels. We need these because lockdep 771abe84903SJohan Hedberg * otherwise considers all channels equal and will e.g. complain about a 772abe84903SJohan Hedberg * connection oriented channel triggering SMP procedures or a listening 773abe84903SJohan Hedberg * channel creating and locking a child channel. 774abe84903SJohan Hedberg */ 775abe84903SJohan Hedberg enum { 776abe84903SJohan Hedberg L2CAP_NESTING_SMP, 777abe84903SJohan Hedberg L2CAP_NESTING_NORMAL, 778abe84903SJohan Hedberg L2CAP_NESTING_PARENT, 779abe84903SJohan Hedberg }; 780abe84903SJohan Hedberg 781d5f7ac38SMat Martineau enum { 782d5f7ac38SMat Martineau L2CAP_TX_STATE_XMIT, 783d5f7ac38SMat Martineau L2CAP_TX_STATE_WAIT_F, 784d5f7ac38SMat Martineau }; 785d5f7ac38SMat Martineau 786d5f7ac38SMat Martineau enum { 787d5f7ac38SMat Martineau L2CAP_RX_STATE_RECV, 788d5f7ac38SMat Martineau L2CAP_RX_STATE_SREJ_SENT, 78908333283SMat Martineau L2CAP_RX_STATE_MOVE, 79008333283SMat Martineau L2CAP_RX_STATE_WAIT_P, 79108333283SMat Martineau L2CAP_RX_STATE_WAIT_F, 792d5f7ac38SMat Martineau }; 793d5f7ac38SMat Martineau 794d5f7ac38SMat Martineau enum { 795d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED, 796d5f7ac38SMat Martineau L2CAP_TXSEQ_EXPECTED_SREJ, 797d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED, 798d5f7ac38SMat Martineau L2CAP_TXSEQ_UNEXPECTED_SREJ, 799d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE, 800d5f7ac38SMat Martineau L2CAP_TXSEQ_DUPLICATE_SREJ, 801d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID, 802d5f7ac38SMat Martineau L2CAP_TXSEQ_INVALID_IGNORE, 803d5f7ac38SMat Martineau }; 804d5f7ac38SMat Martineau 805d5f7ac38SMat Martineau enum { 806d5f7ac38SMat Martineau L2CAP_EV_DATA_REQUEST, 807d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_DETECTED, 808d5f7ac38SMat Martineau L2CAP_EV_LOCAL_BUSY_CLEAR, 809d5f7ac38SMat Martineau L2CAP_EV_RECV_REQSEQ_AND_FBIT, 810d5f7ac38SMat Martineau L2CAP_EV_RECV_FBIT, 811d5f7ac38SMat Martineau L2CAP_EV_RETRANS_TO, 812d5f7ac38SMat Martineau L2CAP_EV_MONITOR_TO, 813d5f7ac38SMat Martineau L2CAP_EV_EXPLICIT_POLL, 814d5f7ac38SMat Martineau L2CAP_EV_RECV_IFRAME, 815d5f7ac38SMat Martineau L2CAP_EV_RECV_RR, 816d5f7ac38SMat Martineau L2CAP_EV_RECV_REJ, 817d5f7ac38SMat Martineau L2CAP_EV_RECV_RNR, 818d5f7ac38SMat Martineau L2CAP_EV_RECV_SREJ, 819d5f7ac38SMat Martineau L2CAP_EV_RECV_FRAME, 820d5f7ac38SMat Martineau }; 821d5f7ac38SMat Martineau 82208333283SMat Martineau enum { 82308333283SMat Martineau L2CAP_MOVE_ROLE_NONE, 82408333283SMat Martineau L2CAP_MOVE_ROLE_INITIATOR, 82508333283SMat Martineau L2CAP_MOVE_ROLE_RESPONDER, 82608333283SMat Martineau }; 82708333283SMat Martineau 82808333283SMat Martineau enum { 82908333283SMat Martineau L2CAP_MOVE_STABLE, 83008333283SMat Martineau L2CAP_MOVE_WAIT_REQ, 83108333283SMat Martineau L2CAP_MOVE_WAIT_RSP, 83208333283SMat Martineau L2CAP_MOVE_WAIT_RSP_SUCCESS, 83308333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM, 83408333283SMat Martineau L2CAP_MOVE_WAIT_CONFIRM_RSP, 83508333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_COMP, 83608333283SMat Martineau L2CAP_MOVE_WAIT_LOGICAL_CFM, 83708333283SMat Martineau L2CAP_MOVE_WAIT_LOCAL_BUSY, 83808333283SMat Martineau L2CAP_MOVE_WAIT_PREPARE, 83908333283SMat Martineau }; 84008333283SMat Martineau 84130648372SJaganath Kanakkassery void l2cap_chan_hold(struct l2cap_chan *c); 84230648372SJaganath Kanakkassery void l2cap_chan_put(struct l2cap_chan *c); 843371fd835SUlisses Furquim 844c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan) 845c03b355eSAndrei Emeltchenko { 846abe84903SJohan Hedberg mutex_lock_nested(&chan->lock, atomic_read(&chan->nesting)); 847c03b355eSAndrei Emeltchenko } 848c03b355eSAndrei Emeltchenko 849c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan) 850c03b355eSAndrei Emeltchenko { 851c03b355eSAndrei Emeltchenko mutex_unlock(&chan->lock); 852c03b355eSAndrei Emeltchenko } 853c03b355eSAndrei Emeltchenko 854c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan, 855c2ec9c1bSGustavo F. Padovan struct delayed_work *work, long timeout) 856c2ec9c1bSGustavo F. Padovan { 857e05dcc32SAndrei Emeltchenko BT_DBG("chan %p state %s timeout %ld", chan, 858e05dcc32SAndrei Emeltchenko state_to_string(chan->state), timeout); 859c2ec9c1bSGustavo F. Padovan 8606f74b6f3SAndrei Emeltchenko /* If delayed work cancelled do not hold(chan) 8616f74b6f3SAndrei Emeltchenko since it is already done with previous set_timer */ 86217cd3f37SUlisses Furquim if (!cancel_delayed_work(work)) 863371fd835SUlisses Furquim l2cap_chan_hold(chan); 8646f74b6f3SAndrei Emeltchenko 865c2ec9c1bSGustavo F. Padovan schedule_delayed_work(work, timeout); 866c2ec9c1bSGustavo F. Padovan } 867c2ec9c1bSGustavo F. Padovan 86875b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan, 869371fd835SUlisses Furquim struct delayed_work *work) 870c2ec9c1bSGustavo F. Padovan { 87175b93b59SSzymon Janc bool ret; 87275b93b59SSzymon Janc 8736f74b6f3SAndrei Emeltchenko /* put(chan) if delayed work cancelled otherwise it 8746f74b6f3SAndrei Emeltchenko is done in delayed work function */ 87517cd3f37SUlisses Furquim ret = cancel_delayed_work(work); 87675b93b59SSzymon Janc if (ret) 877371fd835SUlisses Furquim l2cap_chan_put(chan); 87875b93b59SSzymon Janc 87975b93b59SSzymon Janc return ret; 880c2ec9c1bSGustavo F. Padovan } 881c2ec9c1bSGustavo F. Padovan 882c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 883c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 8841a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 8851a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 8861a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 887b83ddfe2SAndrzej Kaczmarek msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 8881a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 889c74e560cSGustavo F. Padovan 890836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 891836be934SAndrei Emeltchenko { 8925a364bd3SMat Martineau if (seq1 >= seq2) 8935a364bd3SMat Martineau return seq1 - seq2; 8945a364bd3SMat Martineau else 8955a364bd3SMat Martineau return chan->tx_win_max + 1 - seq2 + seq1; 896836be934SAndrei Emeltchenko } 897836be934SAndrei Emeltchenko 898836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 899836be934SAndrei Emeltchenko { 900836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 901836be934SAndrei Emeltchenko } 902836be934SAndrei Emeltchenko 9037e1af8a3SGustavo Padovan static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chan *chan) 9047e1af8a3SGustavo Padovan { 9057e1af8a3SGustavo Padovan return NULL; 9067e1af8a3SGustavo Padovan } 9077e1af8a3SGustavo Padovan 908f193844cSJohan Hedberg static inline int l2cap_chan_no_recv(struct l2cap_chan *chan, struct sk_buff *skb) 909f193844cSJohan Hedberg { 910f193844cSJohan Hedberg return -ENOSYS; 911f193844cSJohan Hedberg } 912f193844cSJohan Hedberg 913f193844cSJohan Hedberg static inline struct sk_buff *l2cap_chan_no_alloc_skb(struct l2cap_chan *chan, 914f193844cSJohan Hedberg unsigned long hdr_len, 915f193844cSJohan Hedberg unsigned long len, int nb) 916f193844cSJohan Hedberg { 917f193844cSJohan Hedberg return ERR_PTR(-ENOSYS); 918f193844cSJohan Hedberg } 919f193844cSJohan Hedberg 9207e1af8a3SGustavo Padovan static inline void l2cap_chan_no_teardown(struct l2cap_chan *chan, int err) 9217e1af8a3SGustavo Padovan { 9227e1af8a3SGustavo Padovan } 9237e1af8a3SGustavo Padovan 924f193844cSJohan Hedberg static inline void l2cap_chan_no_close(struct l2cap_chan *chan) 925f193844cSJohan Hedberg { 926f193844cSJohan Hedberg } 927f193844cSJohan Hedberg 9287e1af8a3SGustavo Padovan static inline void l2cap_chan_no_ready(struct l2cap_chan *chan) 9297e1af8a3SGustavo Padovan { 9307e1af8a3SGustavo Padovan } 9311da177e4SLinus Torvalds 932f193844cSJohan Hedberg static inline void l2cap_chan_no_state_change(struct l2cap_chan *chan, 933f193844cSJohan Hedberg int state, int err) 934f193844cSJohan Hedberg { 935f193844cSJohan Hedberg } 936f193844cSJohan Hedberg 9372dc4e510SGustavo Padovan static inline void l2cap_chan_no_defer(struct l2cap_chan *chan) 9382dc4e510SGustavo Padovan { 9392dc4e510SGustavo Padovan } 9402dc4e510SGustavo Padovan 941f193844cSJohan Hedberg static inline void l2cap_chan_no_suspend(struct l2cap_chan *chan) 942f193844cSJohan Hedberg { 943f193844cSJohan Hedberg } 944f193844cSJohan Hedberg 9452ce5fb51SMarcel Holtmann static inline void l2cap_chan_no_resume(struct l2cap_chan *chan) 9462ce5fb51SMarcel Holtmann { 9472ce5fb51SMarcel Holtmann } 9482ce5fb51SMarcel Holtmann 9495ec1bbe5SGustavo Padovan static inline void l2cap_chan_no_set_shutdown(struct l2cap_chan *chan) 9505ec1bbe5SGustavo Padovan { 9515ec1bbe5SGustavo Padovan } 9525ec1bbe5SGustavo Padovan 9538d836d71SGustavo Padovan static inline long l2cap_chan_no_get_sndtimeo(struct l2cap_chan *chan) 9548d836d71SGustavo Padovan { 9558d836d71SGustavo Padovan return 0; 9568d836d71SGustavo Padovan } 9578d836d71SGustavo Padovan 958eb939922SRusty Russell extern bool disable_ertm; 959bb58f747SGustavo F. Padovan 960bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 961bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 962b3916db3SDavid Herrmann bool l2cap_is_socket(struct socket *sock); 963bb58f747SGustavo F. Padovan 96427e2d4c8SJohan Hedberg void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan); 9658c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 96668983259SGustavo F. Padovan 9679e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 9689e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 9699e4425ffSGustavo F. Padovan 970eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void); 9710f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 972cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, 9738e9f9892SAndre Guedes bdaddr_t *dst, u8 dst_type); 9748d46321cSMarcel Holtmann int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 975e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 976e7cafc45SJohan Hedberg int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator); 977bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan); 978466f8004SAndrei Emeltchenko int l2cap_ertm_init(struct l2cap_chan *chan); 979466f8004SAndrei Emeltchenko void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 98093c3e8f5SAndrei Emeltchenko void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); 981466f8004SAndrei Emeltchenko void l2cap_chan_del(struct l2cap_chan *chan, int err); 9822766be48SAndrei Emeltchenko void l2cap_send_conn_req(struct l2cap_chan *chan); 9833f7a56c4SMat Martineau void l2cap_move_start(struct l2cap_chan *chan); 98427695fb4SAndrei Emeltchenko void l2cap_logical_cfm(struct l2cap_chan *chan, struct hci_chan *hchan, 98527695fb4SAndrei Emeltchenko u8 status); 986a514b17fSAndrei Emeltchenko void __l2cap_physical_cfm(struct l2cap_chan *chan, int result); 987bb58f747SGustavo F. Padovan 98851bb8457SJohan Hedberg struct l2cap_conn *l2cap_conn_get(struct l2cap_conn *conn); 9899c903e37SDavid Herrmann void l2cap_conn_put(struct l2cap_conn *conn); 9909c903e37SDavid Herrmann 9912c8e1411SDavid Herrmann int l2cap_register_user(struct l2cap_conn *conn, struct l2cap_user *user); 9922c8e1411SDavid Herrmann void l2cap_unregister_user(struct l2cap_conn *conn, struct l2cap_user *user); 9932c8e1411SDavid Herrmann 9941da177e4SLinus Torvalds #endif /* __L2CAP_H */ 995