xref: /openbmc/linux/include/net/bluetooth/l2cap.h (revision 59e54bd1)
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
3547ec1dcdSMarcel Holtmann #define L2CAP_DEFAULT_FLUSH_TO		0xffff
361c2acffbSGustavo F. Padovan #define L2CAP_DEFAULT_TX_WINDOW		63
376327eb98SAndrei Emeltchenko #define L2CAP_DEFAULT_EXT_WINDOW	0x3FFF
38e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX		3
39fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO	2000    /* 2 seconds */
40e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO	12000   /* 12 seconds */
41db12d647SMat Martineau #define L2CAP_DEFAULT_MAX_PDU_SIZE	1009    /* Sized for 3-DH5 packet */
42c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO		200
43b62f328bSVille Tervo #define L2CAP_LE_DEFAULT_MTU		23
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 */
481da177e4SLinus Torvalds 
49ba13ccd9SMarcel Holtmann #define L2CAP_DISC_TIMEOUT		msecs_to_jiffies(100)
50ba13ccd9SMarcel Holtmann #define L2CAP_DISC_REJ_TIMEOUT		msecs_to_jiffies(5000)
51ba13ccd9SMarcel Holtmann #define L2CAP_ENC_TIMEOUT		msecs_to_jiffies(5000)
52ba13ccd9SMarcel Holtmann #define L2CAP_CONN_TIMEOUT		msecs_to_jiffies(40000)
53ba13ccd9SMarcel Holtmann #define L2CAP_INFO_TIMEOUT		msecs_to_jiffies(4000)
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /* L2CAP socket address */
561da177e4SLinus Torvalds struct sockaddr_l2 {
571da177e4SLinus Torvalds 	sa_family_t	l2_family;
588e036fc3SAl Viro 	__le16		l2_psm;
591da177e4SLinus Torvalds 	bdaddr_t	l2_bdaddr;
60f29972deSMarcel Holtmann 	__le16		l2_cid;
6143ef0b8bSAndre Guedes 	__u8		l2_bdaddr_type;
621da177e4SLinus Torvalds };
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds /* L2CAP socket options */
651da177e4SLinus Torvalds #define L2CAP_OPTIONS	0x01
661da177e4SLinus Torvalds struct l2cap_options {
671da177e4SLinus Torvalds 	__u16 omtu;
681da177e4SLinus Torvalds 	__u16 imtu;
691da177e4SLinus Torvalds 	__u16 flush_to;
701da177e4SLinus Torvalds 	__u8  mode;
71fcc203c3SGustavo F. Padovan 	__u8  fcs;
7268d7f0ceSGustavo F. Padovan 	__u8  max_tx;
7314b5aa71SGustavo F. Padovan 	__u16 txwin_size;
741da177e4SLinus Torvalds };
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds #define L2CAP_CONNINFO	0x02
771da177e4SLinus Torvalds struct l2cap_conninfo {
781da177e4SLinus Torvalds 	__u16 hci_handle;
791da177e4SLinus Torvalds 	__u8  dev_class[3];
801da177e4SLinus Torvalds };
811da177e4SLinus Torvalds 
821da177e4SLinus Torvalds #define L2CAP_LM	0x03
831da177e4SLinus Torvalds #define L2CAP_LM_MASTER		0x0001
841da177e4SLinus Torvalds #define L2CAP_LM_AUTH		0x0002
851da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT	0x0004
861da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED	0x0008
871da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE	0x0010
881da177e4SLinus Torvalds #define L2CAP_LM_SECURE		0x0020
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds /* L2CAP command codes */
911da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ	0x01
921da177e4SLinus Torvalds #define L2CAP_CONN_REQ		0x02
931da177e4SLinus Torvalds #define L2CAP_CONN_RSP		0x03
941da177e4SLinus Torvalds #define L2CAP_CONF_REQ		0x04
951da177e4SLinus Torvalds #define L2CAP_CONF_RSP		0x05
961da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ	0x06
971da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP	0x07
981da177e4SLinus Torvalds #define L2CAP_ECHO_REQ		0x08
991da177e4SLinus Torvalds #define L2CAP_ECHO_RSP		0x09
1001da177e4SLinus Torvalds #define L2CAP_INFO_REQ		0x0a
1011da177e4SLinus Torvalds #define L2CAP_INFO_RSP		0x0b
10238094c75SMat Martineau #define L2CAP_CREATE_CHAN_REQ	0x0c
10338094c75SMat Martineau #define L2CAP_CREATE_CHAN_RSP	0x0d
10438094c75SMat Martineau #define L2CAP_MOVE_CHAN_REQ	0x0e
10538094c75SMat Martineau #define L2CAP_MOVE_CHAN_RSP	0x0f
10638094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM	0x10
10738094c75SMat Martineau #define L2CAP_MOVE_CHAN_CFM_RSP	0x11
1083300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ	0x12
1093300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP	0x13
1101da177e4SLinus Torvalds 
111a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */
11247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL	0x00000001
11347ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS	0x00000002
114a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS	0x00000004
11547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM		0x00000008
11647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING	0x00000010
11747ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS		0x00000020
118a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW	0x00000040
11947ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN	0x00000080
120a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW	0x00000100
121a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD		0x00000200
12247ec1dcdSMarcel Holtmann 
12347ec1dcdSMarcel Holtmann /* L2CAP checksum option */
12447ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE		0x00
12547ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16		0x01
12647ec1dcdSMarcel Holtmann 
127d835ac0fSMat Martineau /* L2CAP fixed channels */
128d835ac0fSMat Martineau #define L2CAP_FC_L2CAP		0x02
129d835ac0fSMat Martineau #define L2CAP_FC_A2MP		0x08
130d835ac0fSMat Martineau 
1311c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */
1321c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR			0xC000
1331c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ		0x3F00
1341c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ		0x007E
13557253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE		0x000C
13657253fd8SAndrei Emeltchenko 
1371c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS		0x0080
1381c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL		0x0080
1391c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL			0x0010
1401c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE		0x0001 /* I- or S-Frame */
1411c2acffbSGustavo F. Padovan 
1421c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT		1
14357253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT		2
144d5f7ac38SMat Martineau #define L2CAP_CTRL_POLL_SHIFT		4
145d5f7ac38SMat Martineau #define L2CAP_CTRL_FINAL_SHIFT		7
1461c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT		8
1478f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT		14
1481c2acffbSGustavo F. Padovan 
14957253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */
15057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ		0xFFFC0000
15157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR		0x00030000
15257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE	0x00030000
15357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ		0x0000FFFC
15457253fd8SAndrei Emeltchenko 
15557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL		0x00040000
15657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL		0x00000002
15757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE	0x00000001 /* I- or S-Frame */
15857253fd8SAndrei Emeltchenko 
159d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_FINAL_SHIFT	1
16057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT	2
16157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT	16
16257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT	16
163d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_POLL_SHIFT	18
16457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT	18
16557253fd8SAndrei Emeltchenko 
1661c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */
167ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR		0x00
168ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ		0x01
169ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR		0x02
170ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ	0x03
1711c2acffbSGustavo F. Padovan 
1721c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */
1737e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED	0x00
1747e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START		0x01
1757e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END		0x02
1767e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE	0x03
1771c2acffbSGustavo F. Padovan 
178e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */
179e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD	0x0000
180e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED		0x0001
181e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID		0x0002
182e2fd318eSIlia Kolomisnky 
1831da177e4SLinus Torvalds /* L2CAP structures */
1841da177e4SLinus Torvalds struct l2cap_hdr {
1858e036fc3SAl Viro 	__le16     len;
1868e036fc3SAl Viro 	__le16     cid;
18766c853ccSGustavo F. Padovan } __packed;
1881da177e4SLinus Torvalds #define L2CAP_HDR_SIZE		4
189d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE	6
190d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE	8
191d43cb289SAndrei Emeltchenko 
192d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE		2
193d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE	2
194d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE	2
195d5f7ac38SMat Martineau #define L2CAP_ENH_CTRL_SIZE	2
196d5f7ac38SMat Martineau #define L2CAP_EXT_CTRL_SIZE	4
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds struct l2cap_cmd_hdr {
1991da177e4SLinus Torvalds 	__u8       code;
2001da177e4SLinus Torvalds 	__u8       ident;
2018e036fc3SAl Viro 	__le16     len;
20266c853ccSGustavo F. Padovan } __packed;
2031da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE	4
2041da177e4SLinus Torvalds 
205e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk {
2068e036fc3SAl Viro 	__le16     reason;
20766c853ccSGustavo F. Padovan } __packed;
2081da177e4SLinus Torvalds 
209e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu {
210e2fd318eSIlia Kolomisnky 	__le16     reason;
211e2fd318eSIlia Kolomisnky 	__le16     max_mtu;
212e2fd318eSIlia Kolomisnky } __packed;
213e2fd318eSIlia Kolomisnky 
214e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid {
215e2fd318eSIlia Kolomisnky 	__le16     reason;
216e2fd318eSIlia Kolomisnky 	__le16     scid;
217e2fd318eSIlia Kolomisnky 	__le16     dcid;
218e2fd318eSIlia Kolomisnky } __packed;
219e2fd318eSIlia Kolomisnky 
2201da177e4SLinus Torvalds struct l2cap_conn_req {
2218e036fc3SAl Viro 	__le16     psm;
2228e036fc3SAl Viro 	__le16     scid;
22366c853ccSGustavo F. Padovan } __packed;
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds struct l2cap_conn_rsp {
2268e036fc3SAl Viro 	__le16     dcid;
2278e036fc3SAl Viro 	__le16     scid;
2288e036fc3SAl Viro 	__le16     result;
2298e036fc3SAl Viro 	__le16     status;
23066c853ccSGustavo F. Padovan } __packed;
2311da177e4SLinus Torvalds 
2328db4dc46SGustavo F. Padovan /* channel indentifier */
2338db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING	0x0001
2348db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS	0x0002
235acd7d370SVille Tervo #define L2CAP_CID_LE_DATA	0x0004
236acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING	0x0005
237acd7d370SVille Tervo #define L2CAP_CID_SMP		0x0006
2388db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START	0x0040
2398db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END	0xffff
2408db4dc46SGustavo F. Padovan 
24138094c75SMat Martineau /* connect/create channel results */
2421da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS	0x0000
2431da177e4SLinus Torvalds #define L2CAP_CR_PEND		0x0001
2441da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM	0x0002
2451da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK	0x0003
2461da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM		0x0004
24738094c75SMat Martineau #define L2CAP_CR_BAD_AMP	0x0005
2481da177e4SLinus Torvalds 
24938094c75SMat Martineau /* connect/create channel status */
2501da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO	0x0000
2511da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND	0x0001
2521da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND	0x0002
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds struct l2cap_conf_req {
2558e036fc3SAl Viro 	__le16     dcid;
2568e036fc3SAl Viro 	__le16     flags;
2571da177e4SLinus Torvalds 	__u8       data[0];
25866c853ccSGustavo F. Padovan } __packed;
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds struct l2cap_conf_rsp {
2618e036fc3SAl Viro 	__le16     scid;
2628e036fc3SAl Viro 	__le16     flags;
2638e036fc3SAl Viro 	__le16     result;
2641da177e4SLinus Torvalds 	__u8       data[0];
26566c853ccSGustavo F. Padovan } __packed;
2661da177e4SLinus Torvalds 
2675dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS	0x0000
2685dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT	0x0001
2695dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT	0x0002
2705dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN	0x0003
2710e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING	0x0004
2725a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT	0x0005
2731da177e4SLinus Torvalds 
27459e54bd1SAndrei Emeltchenko /* configuration req/rsp continuation flag */
27559e54bd1SAndrei Emeltchenko #define L2CAP_CONF_FLAG_CONTINUATION	0x0001
27659e54bd1SAndrei Emeltchenko 
2771da177e4SLinus Torvalds struct l2cap_conf_opt {
2781da177e4SLinus Torvalds 	__u8       type;
2791da177e4SLinus Torvalds 	__u8       len;
2801da177e4SLinus Torvalds 	__u8       val[0];
28166c853ccSGustavo F. Padovan } __packed;
2821da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE	2
2831da177e4SLinus Torvalds 
284589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT		0x80
28547ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK		0x7f
286589d2746SGustavo F. Padovan 
2871da177e4SLinus Torvalds #define L2CAP_CONF_MTU		0x01
2881da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO	0x02
2891da177e4SLinus Torvalds #define L2CAP_CONF_QOS		0x03
2901da177e4SLinus Torvalds #define L2CAP_CONF_RFC		0x04
29147ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS		0x05
2925a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS		0x06
2936327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS		0x07
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE	22
2961da177e4SLinus Torvalds 
2976464f35fSMarcel Holtmann struct l2cap_conf_rfc {
2986464f35fSMarcel Holtmann 	__u8       mode;
2996464f35fSMarcel Holtmann 	__u8       txwin_size;
3006464f35fSMarcel Holtmann 	__u8       max_transmit;
3016464f35fSMarcel Holtmann 	__le16     retrans_timeout;
3026464f35fSMarcel Holtmann 	__le16     monitor_timeout;
3036464f35fSMarcel Holtmann 	__le16     max_pdu_size;
30466c853ccSGustavo F. Padovan } __packed;
3056464f35fSMarcel Holtmann 
3066464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC	0x00
3076464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS	0x01
3086464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL	0x02
30947ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM		0x03
310c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING	0x04
3116464f35fSMarcel Holtmann 
3125a9e7057SAndrei Emeltchenko struct l2cap_conf_efs {
3135a9e7057SAndrei Emeltchenko 	__u8	id;
3145a9e7057SAndrei Emeltchenko 	__u8	stype;
3155a9e7057SAndrei Emeltchenko 	__le16	msdu;
3165a9e7057SAndrei Emeltchenko 	__le32	sdu_itime;
3175a9e7057SAndrei Emeltchenko 	__le32	acc_lat;
3185a9e7057SAndrei Emeltchenko 	__le32	flush_to;
3195a9e7057SAndrei Emeltchenko } __packed;
3205a9e7057SAndrei Emeltchenko 
3218f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC	0x00
3228f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT	0x01
3238f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED	0x02
3248f7975b1SAndrei Emeltchenko 
3258f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID	0x01
3268f7975b1SAndrei Emeltchenko 
3271da177e4SLinus Torvalds struct l2cap_disconn_req {
3288e036fc3SAl Viro 	__le16     dcid;
3298e036fc3SAl Viro 	__le16     scid;
33066c853ccSGustavo F. Padovan } __packed;
3311da177e4SLinus Torvalds 
3321da177e4SLinus Torvalds struct l2cap_disconn_rsp {
3338e036fc3SAl Viro 	__le16     dcid;
3348e036fc3SAl Viro 	__le16     scid;
33566c853ccSGustavo F. Padovan } __packed;
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds struct l2cap_info_req {
3388e036fc3SAl Viro 	__le16      type;
33966c853ccSGustavo F. Padovan } __packed;
3401da177e4SLinus Torvalds 
3411da177e4SLinus Torvalds struct l2cap_info_rsp {
3428e036fc3SAl Viro 	__le16      type;
3438e036fc3SAl Viro 	__le16      result;
3441da177e4SLinus Torvalds 	__u8        data[0];
34566c853ccSGustavo F. Padovan } __packed;
3461da177e4SLinus Torvalds 
34738094c75SMat Martineau struct l2cap_create_chan_req {
34838094c75SMat Martineau 	__le16      psm;
34938094c75SMat Martineau 	__le16      scid;
35038094c75SMat Martineau 	__u8        amp_id;
35138094c75SMat Martineau } __packed;
35238094c75SMat Martineau 
35338094c75SMat Martineau struct l2cap_create_chan_rsp {
35438094c75SMat Martineau 	__le16      dcid;
35538094c75SMat Martineau 	__le16      scid;
35638094c75SMat Martineau 	__le16      result;
35738094c75SMat Martineau 	__le16      status;
35838094c75SMat Martineau } __packed;
35938094c75SMat Martineau 
36038094c75SMat Martineau struct l2cap_move_chan_req {
36138094c75SMat Martineau 	__le16      icid;
36238094c75SMat Martineau 	__u8        dest_amp_id;
36338094c75SMat Martineau } __packed;
36438094c75SMat Martineau 
36538094c75SMat Martineau struct l2cap_move_chan_rsp {
36638094c75SMat Martineau 	__le16      icid;
36738094c75SMat Martineau 	__le16      result;
36838094c75SMat Martineau } __packed;
36938094c75SMat Martineau 
37038094c75SMat Martineau #define L2CAP_MR_SUCCESS	0x0000
37138094c75SMat Martineau #define L2CAP_MR_PEND		0x0001
37238094c75SMat Martineau #define L2CAP_MR_BAD_ID		0x0002
37338094c75SMat Martineau #define L2CAP_MR_SAME_ID	0x0003
37438094c75SMat Martineau #define L2CAP_MR_NOT_SUPP	0x0004
37538094c75SMat Martineau #define L2CAP_MR_COLLISION	0x0005
37638094c75SMat Martineau #define L2CAP_MR_NOT_ALLOWED	0x0006
37738094c75SMat Martineau 
37838094c75SMat Martineau struct l2cap_move_chan_cfm {
37938094c75SMat Martineau 	__le16      icid;
38038094c75SMat Martineau 	__le16      result;
38138094c75SMat Martineau } __packed;
38238094c75SMat Martineau 
38338094c75SMat Martineau #define L2CAP_MC_CONFIRMED	0x0000
38438094c75SMat Martineau #define L2CAP_MC_UNCONFIRMED	0x0001
38538094c75SMat Martineau 
38638094c75SMat Martineau struct l2cap_move_chan_cfm_rsp {
38738094c75SMat Martineau 	__le16      icid;
38838094c75SMat Martineau } __packed;
38938094c75SMat Martineau 
3901da177e4SLinus Torvalds /* info type */
3911da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU		0x0001
3921da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK	0x0002
393e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN	0x0003
3941da177e4SLinus Torvalds 
3951da177e4SLinus Torvalds /* info result */
3961da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS	0x0000
3971da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP	0x0001
3981da177e4SLinus Torvalds 
399de73115aSClaudio Takahasi struct l2cap_conn_param_update_req {
400de73115aSClaudio Takahasi 	__le16      min;
401de73115aSClaudio Takahasi 	__le16      max;
402de73115aSClaudio Takahasi 	__le16      latency;
403de73115aSClaudio Takahasi 	__le16      to_multiplier;
404de73115aSClaudio Takahasi } __packed;
405de73115aSClaudio Takahasi 
406de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp {
407de73115aSClaudio Takahasi 	__le16      result;
408de73115aSClaudio Takahasi } __packed;
409de73115aSClaudio Takahasi 
410de73115aSClaudio Takahasi /* Connection Parameters result */
411de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED	0x0000
412de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED	0x0001
413de73115aSClaudio Takahasi 
41448454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */
4153c588192SMat Martineau struct l2cap_seq_list {
4163c588192SMat Martineau 	__u16	head;
4173c588192SMat Martineau 	__u16	tail;
4183c588192SMat Martineau 	__u16	mask;
4193c588192SMat Martineau 	__u16	*list;
4203c588192SMat Martineau };
4213c588192SMat Martineau 
4223c588192SMat Martineau #define L2CAP_SEQ_LIST_CLEAR	0xFFFF
4233c588192SMat Martineau #define L2CAP_SEQ_LIST_TAIL	0x8000
4243c588192SMat Martineau 
42548454079SGustavo F. Padovan struct l2cap_chan {
42648454079SGustavo F. Padovan 	struct sock *sk;
4278c1d787bSGustavo F. Padovan 
4288c1d787bSGustavo F. Padovan 	struct l2cap_conn	*conn;
4298c1d787bSGustavo F. Padovan 
43089bc500eSGustavo F. Padovan 	__u8		state;
43189bc500eSGustavo F. Padovan 
43271ba0e56SGustavo F. Padovan 	atomic_t	refcnt;
43371ba0e56SGustavo F. Padovan 
434fe4128e0SGustavo F. Padovan 	__le16		psm;
435fe4128e0SGustavo F. Padovan 	__u16		dcid;
436fe4128e0SGustavo F. Padovan 	__u16		scid;
4374343478fSGustavo F. Padovan 
4380c1bc5c6SGustavo F. Padovan 	__u16		imtu;
4390c1bc5c6SGustavo F. Padovan 	__u16		omtu;
4400c1bc5c6SGustavo F. Padovan 	__u16		flush_to;
4410c1bc5c6SGustavo F. Padovan 	__u8		mode;
442715ec005SGustavo F. Padovan 	__u8		chan_type;
4432ea66482SMat Martineau 	__u8		chan_policy;
4440c1bc5c6SGustavo F. Padovan 
4450c1bc5c6SGustavo F. Padovan 	__le16		sport;
4460c1bc5c6SGustavo F. Padovan 
4474343478fSGustavo F. Padovan 	__u8		sec_level;
4484343478fSGustavo F. Padovan 
449fc7f8a7eSGustavo F. Padovan 	__u8		ident;
450fc7f8a7eSGustavo F. Padovan 
45173ffa904SGustavo F. Padovan 	__u8		conf_req[64];
45273ffa904SGustavo F. Padovan 	__u8		conf_len;
45373ffa904SGustavo F. Padovan 	__u8		num_conf_req;
45473ffa904SGustavo F. Padovan 	__u8		num_conf_rsp;
45573ffa904SGustavo F. Padovan 
45647d1ec61SGustavo F. Padovan 	__u8		fcs;
45747d1ec61SGustavo F. Padovan 
4586327eb98SAndrei Emeltchenko 	__u16		tx_win;
459836be934SAndrei Emeltchenko 	__u16		tx_win_max;
46047d1ec61SGustavo F. Padovan 	__u8		max_tx;
46147d1ec61SGustavo F. Padovan 	__u16		retrans_timeout;
46247d1ec61SGustavo F. Padovan 	__u16		monitor_timeout;
46347d1ec61SGustavo F. Padovan 	__u16		mps;
46447d1ec61SGustavo F. Padovan 
465d5f7ac38SMat Martineau 	__u8		tx_state;
466d5f7ac38SMat Martineau 	__u8		rx_state;
467d5f7ac38SMat Martineau 
468c1360a1cSGustavo F. Padovan 	unsigned long	conf_state;
469e2ab4353SGustavo F. Padovan 	unsigned long	conn_state;
470d57b0e8bSAndrei Emeltchenko 	unsigned long	flags;
471525cd185SGustavo F. Padovan 
472fb45de7dSAndrei Emeltchenko 	__u16		next_tx_seq;
473fb45de7dSAndrei Emeltchenko 	__u16		expected_ack_seq;
474fb45de7dSAndrei Emeltchenko 	__u16		expected_tx_seq;
4750b209faeSAndrei Emeltchenko 	__u16		buffer_seq;
476fb45de7dSAndrei Emeltchenko 	__u16		srej_save_reqseq;
477d5f7ac38SMat Martineau 	__u16		last_acked_seq;
478fb45de7dSAndrei Emeltchenko 	__u16		frames_sent;
479fb45de7dSAndrei Emeltchenko 	__u16		unacked_frames;
4806a026610SGustavo F. Padovan 	__u8		retry_count;
481d5f7ac38SMat Martineau 	__u16		srej_queue_next;
4826f61fd47SGustavo F. Padovan 	__u16		sdu_len;
4836f61fd47SGustavo F. Padovan 	struct sk_buff	*sdu;
48484084a31SMat Martineau 	struct sk_buff	*sdu_last_frag;
4856f61fd47SGustavo F. Padovan 
4866327eb98SAndrei Emeltchenko 	__u16		remote_tx_win;
4872c03a7a4SGustavo F. Padovan 	__u8		remote_max_tx;
4882c03a7a4SGustavo F. Padovan 	__u16		remote_mps;
48942e5c802SGustavo F. Padovan 
4905a9e7057SAndrei Emeltchenko 	__u8		local_id;
4915a9e7057SAndrei Emeltchenko 	__u8		local_stype;
4925a9e7057SAndrei Emeltchenko 	__u16		local_msdu;
4935a9e7057SAndrei Emeltchenko 	__u32		local_sdu_itime;
4945a9e7057SAndrei Emeltchenko 	__u32		local_acc_lat;
4955a9e7057SAndrei Emeltchenko 	__u32		local_flush_to;
4965a9e7057SAndrei Emeltchenko 
4975a9e7057SAndrei Emeltchenko 	__u8		remote_id;
4985a9e7057SAndrei Emeltchenko 	__u8		remote_stype;
4995a9e7057SAndrei Emeltchenko 	__u16		remote_msdu;
5005a9e7057SAndrei Emeltchenko 	__u32		remote_sdu_itime;
5015a9e7057SAndrei Emeltchenko 	__u32		remote_acc_lat;
5025a9e7057SAndrei Emeltchenko 	__u32		remote_flush_to;
5035a9e7057SAndrei Emeltchenko 
504721c4181SGustavo F. Padovan 	struct delayed_work	chan_timer;
505721c4181SGustavo F. Padovan 	struct delayed_work	retrans_timer;
506721c4181SGustavo F. Padovan 	struct delayed_work	monitor_timer;
507721c4181SGustavo F. Padovan 	struct delayed_work	ack_timer;
508721c4181SGustavo F. Padovan 
50958d35f87SGustavo F. Padovan 	struct sk_buff		*tx_send_head;
51058d35f87SGustavo F. Padovan 	struct sk_buff_head	tx_q;
511f1c6775bSGustavo F. Padovan 	struct sk_buff_head	srej_q;
5123c588192SMat Martineau 	struct l2cap_seq_list	srej_list;
5133c588192SMat Martineau 	struct l2cap_seq_list	retrans_list;
514e92c8e70SGustavo F. Padovan 
515baa7e1faSGustavo F. Padovan 	struct list_head	list;
51623691d75SGustavo F. Padovan 	struct list_head	global_l;
51780808e43SGustavo F. Padovan 
51880808e43SGustavo F. Padovan 	void			*data;
51980808e43SGustavo F. Padovan 	struct l2cap_ops	*ops;
520c03b355eSAndrei Emeltchenko 	struct mutex		lock;
52180808e43SGustavo F. Padovan };
52280808e43SGustavo F. Padovan 
52380808e43SGustavo F. Padovan struct l2cap_ops {
52480808e43SGustavo F. Padovan 	char			*name;
52580808e43SGustavo F. Padovan 
52680808e43SGustavo F. Padovan 	struct l2cap_chan	*(*new_connection) (void *data);
52723070494SGustavo F. Padovan 	int			(*recv) (void *data, struct sk_buff *skb);
528ba3bd0eeSGustavo F. Padovan 	void			(*close) (void *data);
52989bc500eSGustavo F. Padovan 	void			(*state_change) (void *data, int state);
5302f7719ceSAndrei Emeltchenko 	struct sk_buff		*(*alloc_skb) (struct l2cap_chan *chan,
53190338947SGustavo Padovan 					       unsigned long len, int nb);
5321da177e4SLinus Torvalds };
5331da177e4SLinus Torvalds 
5341da177e4SLinus Torvalds struct l2cap_conn {
5351da177e4SLinus Torvalds 	struct hci_conn		*hcon;
53673d80debSLuiz Augusto von Dentz 	struct hci_chan		*hchan;
5371da177e4SLinus Torvalds 
5381da177e4SLinus Torvalds 	bdaddr_t		*dst;
5391da177e4SLinus Torvalds 	bdaddr_t		*src;
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds 	unsigned int		mtu;
5421da177e4SLinus Torvalds 
5434e8402a3SMarcel Holtmann 	__u32			feat_mask;
544978c93b9SAndrei Emeltchenko 	__u8			fixed_chan_mask;
5454e8402a3SMarcel Holtmann 
5464e8402a3SMarcel Holtmann 	__u8			info_state;
5474e8402a3SMarcel Holtmann 	__u8			info_ident;
5484e8402a3SMarcel Holtmann 
549030013d8SGustavo F. Padovan 	struct delayed_work	info_timer;
5504e8402a3SMarcel Holtmann 
5511da177e4SLinus Torvalds 	spinlock_t		lock;
5521da177e4SLinus Torvalds 
5531da177e4SLinus Torvalds 	struct sk_buff		*rx_skb;
5541da177e4SLinus Torvalds 	__u32			rx_len;
5551da177e4SLinus Torvalds 	__u8			tx_ident;
5561da177e4SLinus Torvalds 
5572950f21aSMarcel Holtmann 	__u8			disc_reason;
5582950f21aSMarcel Holtmann 
5596c9d42a1SGustavo F. Padovan 	struct delayed_work	security_timer;
5601c1def09SVinicius Costa Gomes 	struct smp_chan		*smp_chan;
5615d3de7dfSVinicius Costa Gomes 
562baa7e1faSGustavo F. Padovan 	struct list_head	chan_l;
563d01b2ff4SGustavo F. Padovan 	struct mutex		chan_lock;
5641da177e4SLinus Torvalds };
5651da177e4SLinus Torvalds 
5664e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT	0x01
567984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT	0x04
568984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE	0x08
5694e8402a3SMarcel Holtmann 
570715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW			1
571715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS		2
572715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED	3
573715ec005SGustavo F. Padovan 
57448454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */
5751da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
5761da177e4SLinus Torvalds 
5771da177e4SLinus Torvalds struct l2cap_pinfo {
5781da177e4SLinus Torvalds 	struct bt_sock		bt;
57948454079SGustavo F. Padovan 	struct l2cap_chan	*chan;
580e328140fSMat Martineau 	struct sk_buff		*rx_busy_skb;
5811da177e4SLinus Torvalds };
5821da177e4SLinus Torvalds 
583c1360a1cSGustavo F. Padovan enum {
584c1360a1cSGustavo F. Padovan 	CONF_REQ_SENT,
585c1360a1cSGustavo F. Padovan 	CONF_INPUT_DONE,
586c1360a1cSGustavo F. Padovan 	CONF_OUTPUT_DONE,
587c1360a1cSGustavo F. Padovan 	CONF_MTU_DONE,
588c1360a1cSGustavo F. Padovan 	CONF_MODE_DONE,
589c1360a1cSGustavo F. Padovan 	CONF_CONNECT_PEND,
590c1360a1cSGustavo F. Padovan 	CONF_NO_FCS_RECV,
591c1360a1cSGustavo F. Padovan 	CONF_STATE2_DEVICE,
5926327eb98SAndrei Emeltchenko 	CONF_EWS_RECV,
5930e8b207eSAndrei Emeltchenko 	CONF_LOC_CONF_PEND,
5940e8b207eSAndrei Emeltchenko 	CONF_REM_CONF_PEND,
5952827011fSMat Martineau 	CONF_NOT_COMPLETE,
596c1360a1cSGustavo F. Padovan };
597861d6882SMarcel Holtmann 
598f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2
599f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2
600f2fcfcd6SGustavo F. Padovan 
601e2ab4353SGustavo F. Padovan enum {
602e2ab4353SGustavo F. Padovan 	CONN_SREJ_SENT,
603e2ab4353SGustavo F. Padovan 	CONN_WAIT_F,
604e2ab4353SGustavo F. Padovan 	CONN_SREJ_ACT,
605e2ab4353SGustavo F. Padovan 	CONN_SEND_PBIT,
606e2ab4353SGustavo F. Padovan 	CONN_REMOTE_BUSY,
607e2ab4353SGustavo F. Padovan 	CONN_LOCAL_BUSY,
608e2ab4353SGustavo F. Padovan 	CONN_REJ_ACT,
609e2ab4353SGustavo F. Padovan 	CONN_SEND_FBIT,
610e2ab4353SGustavo F. Padovan 	CONN_RNR_SENT,
611e2ab4353SGustavo F. Padovan };
612e90bac06SGustavo F. Padovan 
613d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */
614d57b0e8bSAndrei Emeltchenko enum {
61543bd0f32SAndrei Emeltchenko 	FLAG_ROLE_SWITCH,
61615770b1aSAndrei Emeltchenko 	FLAG_FORCE_ACTIVE,
617ecf61bdbSAndrei Emeltchenko 	FLAG_FORCE_RELIABLE,
618d57b0e8bSAndrei Emeltchenko 	FLAG_FLUSHABLE,
6196327eb98SAndrei Emeltchenko 	FLAG_EXT_CTRL,
6205a9e7057SAndrei Emeltchenko 	FLAG_EFS_ENABLE,
621d57b0e8bSAndrei Emeltchenko };
622d57b0e8bSAndrei Emeltchenko 
623d5f7ac38SMat Martineau enum {
624d5f7ac38SMat Martineau 	L2CAP_TX_STATE_XMIT,
625d5f7ac38SMat Martineau 	L2CAP_TX_STATE_WAIT_F,
626d5f7ac38SMat Martineau };
627d5f7ac38SMat Martineau 
628d5f7ac38SMat Martineau enum {
629d5f7ac38SMat Martineau 	L2CAP_RX_STATE_RECV,
630d5f7ac38SMat Martineau 	L2CAP_RX_STATE_SREJ_SENT,
631d5f7ac38SMat Martineau };
632d5f7ac38SMat Martineau 
633d5f7ac38SMat Martineau enum {
634d5f7ac38SMat Martineau 	L2CAP_TXSEQ_EXPECTED,
635d5f7ac38SMat Martineau 	L2CAP_TXSEQ_EXPECTED_SREJ,
636d5f7ac38SMat Martineau 	L2CAP_TXSEQ_UNEXPECTED,
637d5f7ac38SMat Martineau 	L2CAP_TXSEQ_UNEXPECTED_SREJ,
638d5f7ac38SMat Martineau 	L2CAP_TXSEQ_DUPLICATE,
639d5f7ac38SMat Martineau 	L2CAP_TXSEQ_DUPLICATE_SREJ,
640d5f7ac38SMat Martineau 	L2CAP_TXSEQ_INVALID,
641d5f7ac38SMat Martineau 	L2CAP_TXSEQ_INVALID_IGNORE,
642d5f7ac38SMat Martineau };
643d5f7ac38SMat Martineau 
644d5f7ac38SMat Martineau enum {
645d5f7ac38SMat Martineau 	L2CAP_EV_DATA_REQUEST,
646d5f7ac38SMat Martineau 	L2CAP_EV_LOCAL_BUSY_DETECTED,
647d5f7ac38SMat Martineau 	L2CAP_EV_LOCAL_BUSY_CLEAR,
648d5f7ac38SMat Martineau 	L2CAP_EV_RECV_REQSEQ_AND_FBIT,
649d5f7ac38SMat Martineau 	L2CAP_EV_RECV_FBIT,
650d5f7ac38SMat Martineau 	L2CAP_EV_RETRANS_TO,
651d5f7ac38SMat Martineau 	L2CAP_EV_MONITOR_TO,
652d5f7ac38SMat Martineau 	L2CAP_EV_EXPLICIT_POLL,
653d5f7ac38SMat Martineau 	L2CAP_EV_RECV_IFRAME,
654d5f7ac38SMat Martineau 	L2CAP_EV_RECV_RR,
655d5f7ac38SMat Martineau 	L2CAP_EV_RECV_REJ,
656d5f7ac38SMat Martineau 	L2CAP_EV_RECV_RNR,
657d5f7ac38SMat Martineau 	L2CAP_EV_RECV_SREJ,
658d5f7ac38SMat Martineau 	L2CAP_EV_RECV_FRAME,
659d5f7ac38SMat Martineau };
660d5f7ac38SMat Martineau 
661371fd835SUlisses Furquim static inline void l2cap_chan_hold(struct l2cap_chan *c)
662371fd835SUlisses Furquim {
663371fd835SUlisses Furquim 	atomic_inc(&c->refcnt);
664371fd835SUlisses Furquim }
665371fd835SUlisses Furquim 
666371fd835SUlisses Furquim static inline void l2cap_chan_put(struct l2cap_chan *c)
667371fd835SUlisses Furquim {
668371fd835SUlisses Furquim 	if (atomic_dec_and_test(&c->refcnt))
669371fd835SUlisses Furquim 		kfree(c);
670371fd835SUlisses Furquim }
671371fd835SUlisses Furquim 
672c03b355eSAndrei Emeltchenko static inline void l2cap_chan_lock(struct l2cap_chan *chan)
673c03b355eSAndrei Emeltchenko {
674c03b355eSAndrei Emeltchenko 	mutex_lock(&chan->lock);
675c03b355eSAndrei Emeltchenko }
676c03b355eSAndrei Emeltchenko 
677c03b355eSAndrei Emeltchenko static inline void l2cap_chan_unlock(struct l2cap_chan *chan)
678c03b355eSAndrei Emeltchenko {
679c03b355eSAndrei Emeltchenko 	mutex_unlock(&chan->lock);
680c03b355eSAndrei Emeltchenko }
681c03b355eSAndrei Emeltchenko 
682c2ec9c1bSGustavo F. Padovan static inline void l2cap_set_timer(struct l2cap_chan *chan,
683c2ec9c1bSGustavo F. Padovan 				   struct delayed_work *work, long timeout)
684c2ec9c1bSGustavo F. Padovan {
685e05dcc32SAndrei Emeltchenko 	BT_DBG("chan %p state %s timeout %ld", chan,
686e05dcc32SAndrei Emeltchenko 	       state_to_string(chan->state), timeout);
687c2ec9c1bSGustavo F. Padovan 
6886f74b6f3SAndrei Emeltchenko 	/* If delayed work cancelled do not hold(chan)
6896f74b6f3SAndrei Emeltchenko 	   since it is already done with previous set_timer */
69017cd3f37SUlisses Furquim 	if (!cancel_delayed_work(work))
691371fd835SUlisses Furquim 		l2cap_chan_hold(chan);
6926f74b6f3SAndrei Emeltchenko 
693c2ec9c1bSGustavo F. Padovan 	schedule_delayed_work(work, timeout);
694c2ec9c1bSGustavo F. Padovan }
695c2ec9c1bSGustavo F. Padovan 
69675b93b59SSzymon Janc static inline bool l2cap_clear_timer(struct l2cap_chan *chan,
697371fd835SUlisses Furquim 				     struct delayed_work *work)
698c2ec9c1bSGustavo F. Padovan {
69975b93b59SSzymon Janc 	bool ret;
70075b93b59SSzymon Janc 
7016f74b6f3SAndrei Emeltchenko 	/* put(chan) if delayed work cancelled otherwise it
7026f74b6f3SAndrei Emeltchenko 	   is done in delayed work function */
70317cd3f37SUlisses Furquim 	ret = cancel_delayed_work(work);
70475b93b59SSzymon Janc 	if (ret)
705371fd835SUlisses Furquim 		l2cap_chan_put(chan);
70675b93b59SSzymon Janc 
70775b93b59SSzymon Janc 	return ret;
708c2ec9c1bSGustavo F. Padovan }
709c2ec9c1bSGustavo F. Padovan 
710c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t))
711c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer)
7121a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer)
7131a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer)
7141a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \
715b83ddfe2SAndrzej Kaczmarek 		msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO));
7161a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer)
717c74e560cSGustavo F. Padovan 
718836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2)
719836be934SAndrei Emeltchenko {
7205a364bd3SMat Martineau 	if (seq1 >= seq2)
7215a364bd3SMat Martineau 		return seq1 - seq2;
7225a364bd3SMat Martineau 	else
7235a364bd3SMat Martineau 		return chan->tx_win_max + 1 - seq2 + seq1;
724836be934SAndrei Emeltchenko }
725836be934SAndrei Emeltchenko 
726836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq)
727836be934SAndrei Emeltchenko {
728836be934SAndrei Emeltchenko 	return (seq + 1) % (chan->tx_win_max + 1);
729836be934SAndrei Emeltchenko }
730836be934SAndrei Emeltchenko 
7311da177e4SLinus Torvalds 
732eb939922SRusty Russell extern bool disable_ertm;
733bb58f747SGustavo F. Padovan 
734bb58f747SGustavo F. Padovan int l2cap_init_sockets(void);
735bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void);
736bb58f747SGustavo F. Padovan 
7378c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
738dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk);
73968983259SGustavo F. Padovan 
7409e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm);
7419e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan,  __u16 scid);
7429e4425ffSGustavo F. Padovan 
743eef1d9b6SGustavo Padovan struct l2cap_chan *l2cap_chan_create(void);
7440f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason);
74523691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan);
746cbe8fed4SJohan Hedberg int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
7478e9f9892SAndre Guedes 		       bdaddr_t *dst, u8 dst_type);
7485e59b791SLuiz Augusto von Dentz int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
7495e59b791SLuiz Augusto von Dentz 								u32 priority);
750e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
751d45fc423SGustavo F. Padovan int l2cap_chan_check_security(struct l2cap_chan *chan);
752bd4b1653SAndrei Emeltchenko void l2cap_chan_set_defaults(struct l2cap_chan *chan);
753bb58f747SGustavo F. Padovan 
7541da177e4SLinus Torvalds #endif /* __L2CAP_H */
755