xref: /openbmc/linux/include/net/bluetooth/l2cap.h (revision 8f7975b153faab4b78369458a892dd705e7c395b)
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 
301da177e4SLinus Torvalds /* L2CAP defaults */
311da177e4SLinus Torvalds #define L2CAP_DEFAULT_MTU		672
32f2fcfcd6SGustavo F. Padovan #define L2CAP_DEFAULT_MIN_MTU		48
3347ec1dcdSMarcel Holtmann #define L2CAP_DEFAULT_FLUSH_TO		0xffff
341c2acffbSGustavo F. Padovan #define L2CAP_DEFAULT_TX_WINDOW		63
356327eb98SAndrei Emeltchenko #define L2CAP_DEFAULT_EXT_WINDOW	0x3FFF
36e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX		3
37fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO	2000    /* 2 seconds */
38e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO	12000   /* 12 seconds */
39db12d647SMat Martineau #define L2CAP_DEFAULT_MAX_PDU_SIZE	1009    /* Sized for 3-DH5 packet */
40c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO		200
41b62f328bSVille Tervo #define L2CAP_LE_DEFAULT_MTU		23
42*8f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_MAX_SDU_SIZE	0xFFFF
43*8f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_SDU_ITIME		0xFFFFFFFF
44*8f7975b1SAndrei Emeltchenko #define L2CAP_DEFAULT_ACC_LAT		0xFFFFFFFF
451da177e4SLinus Torvalds 
464e8402a3SMarcel Holtmann #define L2CAP_CONN_TIMEOUT	(40000) /* 40 seconds */
474e8402a3SMarcel Holtmann #define L2CAP_INFO_TIMEOUT	(4000)  /*  4 seconds */
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds /* L2CAP socket address */
501da177e4SLinus Torvalds struct sockaddr_l2 {
511da177e4SLinus Torvalds 	sa_family_t	l2_family;
528e036fc3SAl Viro 	__le16		l2_psm;
531da177e4SLinus Torvalds 	bdaddr_t	l2_bdaddr;
54f29972deSMarcel Holtmann 	__le16		l2_cid;
551da177e4SLinus Torvalds };
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds /* L2CAP socket options */
581da177e4SLinus Torvalds #define L2CAP_OPTIONS	0x01
591da177e4SLinus Torvalds struct l2cap_options {
601da177e4SLinus Torvalds 	__u16 omtu;
611da177e4SLinus Torvalds 	__u16 imtu;
621da177e4SLinus Torvalds 	__u16 flush_to;
631da177e4SLinus Torvalds 	__u8  mode;
64fcc203c3SGustavo F. Padovan 	__u8  fcs;
6568d7f0ceSGustavo F. Padovan 	__u8  max_tx;
6614b5aa71SGustavo F. Padovan 	__u16 txwin_size;
671da177e4SLinus Torvalds };
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds #define L2CAP_CONNINFO	0x02
701da177e4SLinus Torvalds struct l2cap_conninfo {
711da177e4SLinus Torvalds 	__u16 hci_handle;
721da177e4SLinus Torvalds 	__u8  dev_class[3];
731da177e4SLinus Torvalds };
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds #define L2CAP_LM	0x03
761da177e4SLinus Torvalds #define L2CAP_LM_MASTER		0x0001
771da177e4SLinus Torvalds #define L2CAP_LM_AUTH		0x0002
781da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT	0x0004
791da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED	0x0008
801da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE	0x0010
811da177e4SLinus Torvalds #define L2CAP_LM_SECURE		0x0020
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds /* L2CAP command codes */
841da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ	0x01
851da177e4SLinus Torvalds #define L2CAP_CONN_REQ		0x02
861da177e4SLinus Torvalds #define L2CAP_CONN_RSP		0x03
871da177e4SLinus Torvalds #define L2CAP_CONF_REQ		0x04
881da177e4SLinus Torvalds #define L2CAP_CONF_RSP		0x05
891da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ	0x06
901da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP	0x07
911da177e4SLinus Torvalds #define L2CAP_ECHO_REQ		0x08
921da177e4SLinus Torvalds #define L2CAP_ECHO_RSP		0x09
931da177e4SLinus Torvalds #define L2CAP_INFO_REQ		0x0a
941da177e4SLinus Torvalds #define L2CAP_INFO_RSP		0x0b
953300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ	0x12
963300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP	0x13
971da177e4SLinus Torvalds 
98a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */
9947ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL	0x00000001
10047ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS	0x00000002
101a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS	0x00000004
10247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM		0x00000008
10347ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING	0x00000010
10447ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS		0x00000020
105a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW	0x00000040
10647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN	0x00000080
107a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW	0x00000100
108a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD		0x00000200
10947ec1dcdSMarcel Holtmann 
11047ec1dcdSMarcel Holtmann /* L2CAP checksum option */
11147ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE		0x00
11247ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16		0x01
11347ec1dcdSMarcel Holtmann 
1141c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */
1151c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR			0xC000
1161c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ		0x3F00
1171c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ		0x007E
11857253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE		0x000C
11957253fd8SAndrei Emeltchenko 
1201c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS		0x0080
1211c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL		0x0080
1221c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL			0x0010
1231c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE		0x0001 /* I- or S-Frame */
1241c2acffbSGustavo F. Padovan 
1251c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT		1
12657253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT		2
1271c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT		8
1288f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT		14
1291c2acffbSGustavo F. Padovan 
13057253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */
13157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ		0xFFFC0000
13257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR		0x00030000
13357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE	0x00030000
13457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ		0x0000FFFC
13557253fd8SAndrei Emeltchenko 
13657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL		0x00040000
13757253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL		0x00000002
13857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE	0x00000001 /* I- or S-Frame */
13957253fd8SAndrei Emeltchenko 
14057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT	2
14157253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT	16
14257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT	16
14357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT	18
14457253fd8SAndrei Emeltchenko 
1451c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */
146ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR		0x00
147ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ		0x01
148ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR		0x02
149ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ	0x03
1501c2acffbSGustavo F. Padovan 
1511c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */
1527e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED	0x00
1537e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START		0x01
1547e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END		0x02
1557e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE	0x03
1561c2acffbSGustavo F. Padovan 
157e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */
158e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD	0x0000
159e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED		0x0001
160e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID		0x0002
161e2fd318eSIlia Kolomisnky 
1621da177e4SLinus Torvalds /* L2CAP structures */
1631da177e4SLinus Torvalds struct l2cap_hdr {
1648e036fc3SAl Viro 	__le16     len;
1658e036fc3SAl Viro 	__le16     cid;
16666c853ccSGustavo F. Padovan } __packed;
1671da177e4SLinus Torvalds #define L2CAP_HDR_SIZE		4
168d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE	6
169d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE	8
170d43cb289SAndrei Emeltchenko 
171d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE		2
172d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE	2
173d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE	2
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds struct l2cap_cmd_hdr {
1761da177e4SLinus Torvalds 	__u8       code;
1771da177e4SLinus Torvalds 	__u8       ident;
1788e036fc3SAl Viro 	__le16     len;
17966c853ccSGustavo F. Padovan } __packed;
1801da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE	4
1811da177e4SLinus Torvalds 
182e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk {
1838e036fc3SAl Viro 	__le16     reason;
18466c853ccSGustavo F. Padovan } __packed;
1851da177e4SLinus Torvalds 
186e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu {
187e2fd318eSIlia Kolomisnky 	__le16     reason;
188e2fd318eSIlia Kolomisnky 	__le16     max_mtu;
189e2fd318eSIlia Kolomisnky } __packed;
190e2fd318eSIlia Kolomisnky 
191e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid {
192e2fd318eSIlia Kolomisnky 	__le16     reason;
193e2fd318eSIlia Kolomisnky 	__le16     scid;
194e2fd318eSIlia Kolomisnky 	__le16     dcid;
195e2fd318eSIlia Kolomisnky } __packed;
196e2fd318eSIlia Kolomisnky 
1971da177e4SLinus Torvalds struct l2cap_conn_req {
1988e036fc3SAl Viro 	__le16     psm;
1998e036fc3SAl Viro 	__le16     scid;
20066c853ccSGustavo F. Padovan } __packed;
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds struct l2cap_conn_rsp {
2038e036fc3SAl Viro 	__le16     dcid;
2048e036fc3SAl Viro 	__le16     scid;
2058e036fc3SAl Viro 	__le16     result;
2068e036fc3SAl Viro 	__le16     status;
20766c853ccSGustavo F. Padovan } __packed;
2081da177e4SLinus Torvalds 
2098db4dc46SGustavo F. Padovan /* channel indentifier */
2108db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING	0x0001
2118db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS	0x0002
212acd7d370SVille Tervo #define L2CAP_CID_LE_DATA	0x0004
213acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING	0x0005
214acd7d370SVille Tervo #define L2CAP_CID_SMP		0x0006
2158db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START	0x0040
2168db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END	0xffff
2178db4dc46SGustavo F. Padovan 
2181da177e4SLinus Torvalds /* connect result */
2191da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS	0x0000
2201da177e4SLinus Torvalds #define L2CAP_CR_PEND		0x0001
2211da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM	0x0002
2221da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK	0x0003
2231da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM		0x0004
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds /* connect status */
2261da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO	0x0000
2271da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND	0x0001
2281da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND	0x0002
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds struct l2cap_conf_req {
2318e036fc3SAl Viro 	__le16     dcid;
2328e036fc3SAl Viro 	__le16     flags;
2331da177e4SLinus Torvalds 	__u8       data[0];
23466c853ccSGustavo F. Padovan } __packed;
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds struct l2cap_conf_rsp {
2378e036fc3SAl Viro 	__le16     scid;
2388e036fc3SAl Viro 	__le16     flags;
2398e036fc3SAl Viro 	__le16     result;
2401da177e4SLinus Torvalds 	__u8       data[0];
24166c853ccSGustavo F. Padovan } __packed;
2421da177e4SLinus Torvalds 
2435dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS	0x0000
2445dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT	0x0001
2455dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT	0x0002
2465dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN	0x0003
2475a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT	0x0005
2481da177e4SLinus Torvalds 
2491da177e4SLinus Torvalds struct l2cap_conf_opt {
2501da177e4SLinus Torvalds 	__u8       type;
2511da177e4SLinus Torvalds 	__u8       len;
2521da177e4SLinus Torvalds 	__u8       val[0];
25366c853ccSGustavo F. Padovan } __packed;
2541da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE	2
2551da177e4SLinus Torvalds 
256589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT		0x80
25747ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK		0x7f
258589d2746SGustavo F. Padovan 
2591da177e4SLinus Torvalds #define L2CAP_CONF_MTU		0x01
2601da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO	0x02
2611da177e4SLinus Torvalds #define L2CAP_CONF_QOS		0x03
2621da177e4SLinus Torvalds #define L2CAP_CONF_RFC		0x04
26347ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS		0x05
2645a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS		0x06
2656327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS		0x07
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE	22
2681da177e4SLinus Torvalds 
2696464f35fSMarcel Holtmann struct l2cap_conf_rfc {
2706464f35fSMarcel Holtmann 	__u8       mode;
2716464f35fSMarcel Holtmann 	__u8       txwin_size;
2726464f35fSMarcel Holtmann 	__u8       max_transmit;
2736464f35fSMarcel Holtmann 	__le16     retrans_timeout;
2746464f35fSMarcel Holtmann 	__le16     monitor_timeout;
2756464f35fSMarcel Holtmann 	__le16     max_pdu_size;
27666c853ccSGustavo F. Padovan } __packed;
2776464f35fSMarcel Holtmann 
2786464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC	0x00
2796464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS	0x01
2806464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL	0x02
28147ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM		0x03
282c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING	0x04
2836464f35fSMarcel Holtmann 
2845a9e7057SAndrei Emeltchenko struct l2cap_conf_efs {
2855a9e7057SAndrei Emeltchenko 	__u8	id;
2865a9e7057SAndrei Emeltchenko 	__u8	stype;
2875a9e7057SAndrei Emeltchenko 	__le16	msdu;
2885a9e7057SAndrei Emeltchenko 	__le32	sdu_itime;
2895a9e7057SAndrei Emeltchenko 	__le32	acc_lat;
2905a9e7057SAndrei Emeltchenko 	__le32	flush_to;
2915a9e7057SAndrei Emeltchenko } __packed;
2925a9e7057SAndrei Emeltchenko 
293*8f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC	0x00
294*8f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT	0x01
295*8f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED	0x02
296*8f7975b1SAndrei Emeltchenko 
297*8f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID	0x01
298*8f7975b1SAndrei Emeltchenko 
2991da177e4SLinus Torvalds struct l2cap_disconn_req {
3008e036fc3SAl Viro 	__le16     dcid;
3018e036fc3SAl Viro 	__le16     scid;
30266c853ccSGustavo F. Padovan } __packed;
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds struct l2cap_disconn_rsp {
3058e036fc3SAl Viro 	__le16     dcid;
3068e036fc3SAl Viro 	__le16     scid;
30766c853ccSGustavo F. Padovan } __packed;
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds struct l2cap_info_req {
3108e036fc3SAl Viro 	__le16      type;
31166c853ccSGustavo F. Padovan } __packed;
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds struct l2cap_info_rsp {
3148e036fc3SAl Viro 	__le16      type;
3158e036fc3SAl Viro 	__le16      result;
3161da177e4SLinus Torvalds 	__u8        data[0];
31766c853ccSGustavo F. Padovan } __packed;
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds /* info type */
3201da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU		0x0001
3211da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK	0x0002
322e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN	0x0003
3231da177e4SLinus Torvalds 
3241da177e4SLinus Torvalds /* info result */
3251da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS	0x0000
3261da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP	0x0001
3271da177e4SLinus Torvalds 
328de73115aSClaudio Takahasi struct l2cap_conn_param_update_req {
329de73115aSClaudio Takahasi 	__le16      min;
330de73115aSClaudio Takahasi 	__le16      max;
331de73115aSClaudio Takahasi 	__le16      latency;
332de73115aSClaudio Takahasi 	__le16      to_multiplier;
333de73115aSClaudio Takahasi } __packed;
334de73115aSClaudio Takahasi 
335de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp {
336de73115aSClaudio Takahasi 	__le16      result;
337de73115aSClaudio Takahasi } __packed;
338de73115aSClaudio Takahasi 
339de73115aSClaudio Takahasi /* Connection Parameters result */
340de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED	0x0000
341de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED	0x0001
342de73115aSClaudio Takahasi 
34348454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */
34439d5a3eeSGustavo F. Padovan struct srej_list {
345fb45de7dSAndrei Emeltchenko 	__u16	tx_seq;
34639d5a3eeSGustavo F. Padovan 	struct list_head list;
34739d5a3eeSGustavo F. Padovan };
34839d5a3eeSGustavo F. Padovan 
34948454079SGustavo F. Padovan struct l2cap_chan {
35048454079SGustavo F. Padovan 	struct sock *sk;
3518c1d787bSGustavo F. Padovan 
3528c1d787bSGustavo F. Padovan 	struct l2cap_conn	*conn;
3538c1d787bSGustavo F. Padovan 
35489bc500eSGustavo F. Padovan 	__u8		state;
35589bc500eSGustavo F. Padovan 
35671ba0e56SGustavo F. Padovan 	atomic_t	refcnt;
35771ba0e56SGustavo F. Padovan 
358fe4128e0SGustavo F. Padovan 	__le16		psm;
359fe4128e0SGustavo F. Padovan 	__u16		dcid;
360fe4128e0SGustavo F. Padovan 	__u16		scid;
3614343478fSGustavo F. Padovan 
3620c1bc5c6SGustavo F. Padovan 	__u16		imtu;
3630c1bc5c6SGustavo F. Padovan 	__u16		omtu;
3640c1bc5c6SGustavo F. Padovan 	__u16		flush_to;
3650c1bc5c6SGustavo F. Padovan 	__u8		mode;
366715ec005SGustavo F. Padovan 	__u8		chan_type;
3670c1bc5c6SGustavo F. Padovan 
3680c1bc5c6SGustavo F. Padovan 	__le16		sport;
3690c1bc5c6SGustavo F. Padovan 
3704343478fSGustavo F. Padovan 	__u8		sec_level;
3714343478fSGustavo F. Padovan 
372fc7f8a7eSGustavo F. Padovan 	__u8		ident;
373fc7f8a7eSGustavo F. Padovan 
37473ffa904SGustavo F. Padovan 	__u8		conf_req[64];
37573ffa904SGustavo F. Padovan 	__u8		conf_len;
37673ffa904SGustavo F. Padovan 	__u8		num_conf_req;
37773ffa904SGustavo F. Padovan 	__u8		num_conf_rsp;
37873ffa904SGustavo F. Padovan 
37947d1ec61SGustavo F. Padovan 	__u8		fcs;
38047d1ec61SGustavo F. Padovan 
3816327eb98SAndrei Emeltchenko 	__u16		tx_win;
38247d1ec61SGustavo F. Padovan 	__u8		max_tx;
38347d1ec61SGustavo F. Padovan 	__u16		retrans_timeout;
38447d1ec61SGustavo F. Padovan 	__u16		monitor_timeout;
38547d1ec61SGustavo F. Padovan 	__u16		mps;
38647d1ec61SGustavo F. Padovan 
387c1360a1cSGustavo F. Padovan 	unsigned long	conf_state;
388e2ab4353SGustavo F. Padovan 	unsigned long	conn_state;
389d57b0e8bSAndrei Emeltchenko 	unsigned long	flags;
390525cd185SGustavo F. Padovan 
391fb45de7dSAndrei Emeltchenko 	__u16		next_tx_seq;
392fb45de7dSAndrei Emeltchenko 	__u16		expected_ack_seq;
393fb45de7dSAndrei Emeltchenko 	__u16		expected_tx_seq;
3940b209faeSAndrei Emeltchenko 	__u16		buffer_seq;
395fb45de7dSAndrei Emeltchenko 	__u16		buffer_seq_srej;
396fb45de7dSAndrei Emeltchenko 	__u16		srej_save_reqseq;
397fb45de7dSAndrei Emeltchenko 	__u16		frames_sent;
398fb45de7dSAndrei Emeltchenko 	__u16		unacked_frames;
3996a026610SGustavo F. Padovan 	__u8		retry_count;
4006a026610SGustavo F. Padovan 	__u8		num_acked;
4016f61fd47SGustavo F. Padovan 	__u16		sdu_len;
4026f61fd47SGustavo F. Padovan 	struct sk_buff	*sdu;
40384084a31SMat Martineau 	struct sk_buff	*sdu_last_frag;
4046f61fd47SGustavo F. Padovan 
4056327eb98SAndrei Emeltchenko 	__u16		remote_tx_win;
4062c03a7a4SGustavo F. Padovan 	__u8		remote_max_tx;
4072c03a7a4SGustavo F. Padovan 	__u16		remote_mps;
40842e5c802SGustavo F. Padovan 
4095a9e7057SAndrei Emeltchenko 	__u8		local_id;
4105a9e7057SAndrei Emeltchenko 	__u8		local_stype;
4115a9e7057SAndrei Emeltchenko 	__u16		local_msdu;
4125a9e7057SAndrei Emeltchenko 	__u32		local_sdu_itime;
4135a9e7057SAndrei Emeltchenko 	__u32		local_acc_lat;
4145a9e7057SAndrei Emeltchenko 	__u32		local_flush_to;
4155a9e7057SAndrei Emeltchenko 
4165a9e7057SAndrei Emeltchenko 	__u8		remote_id;
4175a9e7057SAndrei Emeltchenko 	__u8		remote_stype;
4185a9e7057SAndrei Emeltchenko 	__u16		remote_msdu;
4195a9e7057SAndrei Emeltchenko 	__u32		remote_sdu_itime;
4205a9e7057SAndrei Emeltchenko 	__u32		remote_acc_lat;
4215a9e7057SAndrei Emeltchenko 	__u32		remote_flush_to;
4225a9e7057SAndrei Emeltchenko 
423ab07801dSGustavo F. Padovan 	struct timer_list	chan_timer;
424e92c8e70SGustavo F. Padovan 	struct timer_list	retrans_timer;
425e92c8e70SGustavo F. Padovan 	struct timer_list	monitor_timer;
426e92c8e70SGustavo F. Padovan 	struct timer_list	ack_timer;
42758d35f87SGustavo F. Padovan 	struct sk_buff		*tx_send_head;
42858d35f87SGustavo F. Padovan 	struct sk_buff_head	tx_q;
429f1c6775bSGustavo F. Padovan 	struct sk_buff_head	srej_q;
43039d5a3eeSGustavo F. Padovan 	struct list_head	srej_l;
431e92c8e70SGustavo F. Padovan 
432baa7e1faSGustavo F. Padovan 	struct list_head list;
43323691d75SGustavo F. Padovan 	struct list_head global_l;
43480808e43SGustavo F. Padovan 
43580808e43SGustavo F. Padovan 	void		*data;
43680808e43SGustavo F. Padovan 	struct l2cap_ops *ops;
43780808e43SGustavo F. Padovan };
43880808e43SGustavo F. Padovan 
43980808e43SGustavo F. Padovan struct l2cap_ops {
44080808e43SGustavo F. Padovan 	char		*name;
44180808e43SGustavo F. Padovan 
44280808e43SGustavo F. Padovan 	struct l2cap_chan	*(*new_connection) (void *data);
44323070494SGustavo F. Padovan 	int			(*recv) (void *data, struct sk_buff *skb);
444ba3bd0eeSGustavo F. Padovan 	void			(*close) (void *data);
44589bc500eSGustavo F. Padovan 	void			(*state_change) (void *data, int state);
4461da177e4SLinus Torvalds };
4471da177e4SLinus Torvalds 
4481da177e4SLinus Torvalds struct l2cap_conn {
4491da177e4SLinus Torvalds 	struct hci_conn	*hcon;
4501da177e4SLinus Torvalds 
4511da177e4SLinus Torvalds 	bdaddr_t	*dst;
4521da177e4SLinus Torvalds 	bdaddr_t	*src;
4531da177e4SLinus Torvalds 
4541da177e4SLinus Torvalds 	unsigned int	mtu;
4551da177e4SLinus Torvalds 
4564e8402a3SMarcel Holtmann 	__u32		feat_mask;
4574e8402a3SMarcel Holtmann 
4584e8402a3SMarcel Holtmann 	__u8		info_state;
4594e8402a3SMarcel Holtmann 	__u8		info_ident;
4604e8402a3SMarcel Holtmann 
4614e8402a3SMarcel Holtmann 	struct timer_list info_timer;
4624e8402a3SMarcel Holtmann 
4631da177e4SLinus Torvalds 	spinlock_t	lock;
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds 	struct sk_buff *rx_skb;
4661da177e4SLinus Torvalds 	__u32		rx_len;
4671da177e4SLinus Torvalds 	__u8		tx_ident;
4681da177e4SLinus Torvalds 
4692950f21aSMarcel Holtmann 	__u8		disc_reason;
4702950f21aSMarcel Holtmann 
4715d3de7dfSVinicius Costa Gomes 	struct timer_list security_timer;
4721c1def09SVinicius Costa Gomes 	struct smp_chan *smp_chan;
4735d3de7dfSVinicius Costa Gomes 
474baa7e1faSGustavo F. Padovan 	struct list_head chan_l;
475baa7e1faSGustavo F. Padovan 	rwlock_t	chan_lock;
4761da177e4SLinus Torvalds };
4771da177e4SLinus Torvalds 
4784e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT	0x01
479984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT	0x04
480984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE	0x08
4814e8402a3SMarcel Holtmann 
482715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW			1
483715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS		2
484715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED	3
485715ec005SGustavo F. Padovan 
48648454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */
4871da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
4881da177e4SLinus Torvalds 
4891da177e4SLinus Torvalds struct l2cap_pinfo {
4901da177e4SLinus Torvalds 	struct bt_sock	bt;
49148454079SGustavo F. Padovan 	struct l2cap_chan	*chan;
492e328140fSMat Martineau 	struct sk_buff	*rx_busy_skb;
4931da177e4SLinus Torvalds };
4941da177e4SLinus Torvalds 
495c1360a1cSGustavo F. Padovan enum {
496c1360a1cSGustavo F. Padovan 	CONF_REQ_SENT,
497c1360a1cSGustavo F. Padovan 	CONF_INPUT_DONE,
498c1360a1cSGustavo F. Padovan 	CONF_OUTPUT_DONE,
499c1360a1cSGustavo F. Padovan 	CONF_MTU_DONE,
500c1360a1cSGustavo F. Padovan 	CONF_MODE_DONE,
501c1360a1cSGustavo F. Padovan 	CONF_CONNECT_PEND,
502c1360a1cSGustavo F. Padovan 	CONF_NO_FCS_RECV,
503c1360a1cSGustavo F. Padovan 	CONF_STATE2_DEVICE,
5046327eb98SAndrei Emeltchenko 	CONF_EWS_RECV,
505c1360a1cSGustavo F. Padovan };
506861d6882SMarcel Holtmann 
507f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2
508f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2
509f2fcfcd6SGustavo F. Padovan 
510e2ab4353SGustavo F. Padovan enum {
511e2ab4353SGustavo F. Padovan 	CONN_SREJ_SENT,
512e2ab4353SGustavo F. Padovan 	CONN_WAIT_F,
513e2ab4353SGustavo F. Padovan 	CONN_SREJ_ACT,
514e2ab4353SGustavo F. Padovan 	CONN_SEND_PBIT,
515e2ab4353SGustavo F. Padovan 	CONN_REMOTE_BUSY,
516e2ab4353SGustavo F. Padovan 	CONN_LOCAL_BUSY,
517e2ab4353SGustavo F. Padovan 	CONN_REJ_ACT,
518e2ab4353SGustavo F. Padovan 	CONN_SEND_FBIT,
519e2ab4353SGustavo F. Padovan 	CONN_RNR_SENT,
520e2ab4353SGustavo F. Padovan };
521e90bac06SGustavo F. Padovan 
522d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */
523d57b0e8bSAndrei Emeltchenko enum {
52443bd0f32SAndrei Emeltchenko 	FLAG_ROLE_SWITCH,
52515770b1aSAndrei Emeltchenko 	FLAG_FORCE_ACTIVE,
526ecf61bdbSAndrei Emeltchenko 	FLAG_FORCE_RELIABLE,
527d57b0e8bSAndrei Emeltchenko 	FLAG_FLUSHABLE,
5286327eb98SAndrei Emeltchenko 	FLAG_EXT_CTRL,
5295a9e7057SAndrei Emeltchenko 	FLAG_EFS_ENABLE,
530d57b0e8bSAndrei Emeltchenko };
531d57b0e8bSAndrei Emeltchenko 
532c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t))
533c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer)
5341a09bcb9SGustavo F. Padovan #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \
5351a09bcb9SGustavo F. Padovan 		L2CAP_DEFAULT_RETRANS_TO);
5361a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer)
5371a09bcb9SGustavo F. Padovan #define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \
5381a09bcb9SGustavo F. Padovan 		L2CAP_DEFAULT_MONITOR_TO);
5391a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer)
5401a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \
5411a09bcb9SGustavo F. Padovan 		L2CAP_DEFAULT_ACK_TO);
5421a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer)
543c74e560cSGustavo F. Padovan 
54442e5c802SGustavo F. Padovan static inline int l2cap_tx_window_full(struct l2cap_chan *ch)
5451c2acffbSGustavo F. Padovan {
5461c2acffbSGustavo F. Padovan 	int sub;
5471c2acffbSGustavo F. Padovan 
54842e5c802SGustavo F. Padovan 	sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64;
5491c2acffbSGustavo F. Padovan 
5501c2acffbSGustavo F. Padovan 	if (sub < 0)
5511c2acffbSGustavo F. Padovan 		sub += 64;
5521c2acffbSGustavo F. Padovan 
5532c03a7a4SGustavo F. Padovan 	return sub == ch->remote_tx_win;
5541c2acffbSGustavo F. Padovan }
5551c2acffbSGustavo F. Padovan 
5560b209faeSAndrei Emeltchenko static inline __u16 __get_reqseq(struct l2cap_chan *chan, __u32 ctrl)
5570b209faeSAndrei Emeltchenko {
5580b209faeSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
5590b209faeSAndrei Emeltchenko 		return (ctrl & L2CAP_EXT_CTRL_REQSEQ) >>
5600b209faeSAndrei Emeltchenko 						L2CAP_EXT_CTRL_REQSEQ_SHIFT;
5610b209faeSAndrei Emeltchenko 	else
5620b209faeSAndrei Emeltchenko 		return (ctrl & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT;
5630b209faeSAndrei Emeltchenko }
5640b209faeSAndrei Emeltchenko 
5650b209faeSAndrei Emeltchenko static inline __u32 __set_reqseq(struct l2cap_chan *chan, __u32 reqseq)
5660b209faeSAndrei Emeltchenko {
5670b209faeSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
5680b209faeSAndrei Emeltchenko 		return (reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT) &
5690b209faeSAndrei Emeltchenko 							L2CAP_EXT_CTRL_REQSEQ;
5700b209faeSAndrei Emeltchenko 	else
5710b209faeSAndrei Emeltchenko 		return (reqseq << L2CAP_CTRL_REQSEQ_SHIFT) & L2CAP_CTRL_REQSEQ;
5720b209faeSAndrei Emeltchenko }
573fb45de7dSAndrei Emeltchenko 
574fb45de7dSAndrei Emeltchenko static inline __u16 __get_txseq(struct l2cap_chan *chan, __u32 ctrl)
575fb45de7dSAndrei Emeltchenko {
576fb45de7dSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
577fb45de7dSAndrei Emeltchenko 		return (ctrl & L2CAP_EXT_CTRL_TXSEQ) >>
578fb45de7dSAndrei Emeltchenko 						L2CAP_EXT_CTRL_TXSEQ_SHIFT;
579fb45de7dSAndrei Emeltchenko 	else
580fb45de7dSAndrei Emeltchenko 		return (ctrl & L2CAP_CTRL_TXSEQ) >> L2CAP_CTRL_TXSEQ_SHIFT;
581fb45de7dSAndrei Emeltchenko }
582fb45de7dSAndrei Emeltchenko 
583fb45de7dSAndrei Emeltchenko static inline __u32 __set_txseq(struct l2cap_chan *chan, __u32 txseq)
584fb45de7dSAndrei Emeltchenko {
585fb45de7dSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
586fb45de7dSAndrei Emeltchenko 		return (txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT) &
587fb45de7dSAndrei Emeltchenko 							L2CAP_EXT_CTRL_TXSEQ;
588fb45de7dSAndrei Emeltchenko 	else
589fb45de7dSAndrei Emeltchenko 		return (txseq << L2CAP_CTRL_TXSEQ_SHIFT) & L2CAP_CTRL_TXSEQ;
590fb45de7dSAndrei Emeltchenko }
591fb45de7dSAndrei Emeltchenko 
592793c2f1cSAndrei Emeltchenko static inline bool __is_sframe(struct l2cap_chan *chan, __u32 ctrl)
593793c2f1cSAndrei Emeltchenko {
594793c2f1cSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
595793c2f1cSAndrei Emeltchenko 		return ctrl & L2CAP_EXT_CTRL_FRAME_TYPE;
596793c2f1cSAndrei Emeltchenko 	else
597793c2f1cSAndrei Emeltchenko 		return ctrl & L2CAP_CTRL_FRAME_TYPE;
598793c2f1cSAndrei Emeltchenko }
599793c2f1cSAndrei Emeltchenko 
600793c2f1cSAndrei Emeltchenko static inline __u32 __set_sframe(struct l2cap_chan *chan)
601793c2f1cSAndrei Emeltchenko {
602793c2f1cSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
603793c2f1cSAndrei Emeltchenko 		return L2CAP_EXT_CTRL_FRAME_TYPE;
604793c2f1cSAndrei Emeltchenko 	else
605793c2f1cSAndrei Emeltchenko 		return L2CAP_CTRL_FRAME_TYPE;
606793c2f1cSAndrei Emeltchenko }
607793c2f1cSAndrei Emeltchenko 
6087e0ef6eeSAndrei Emeltchenko static inline __u8 __get_ctrl_sar(struct l2cap_chan *chan, __u32 ctrl)
6097e0ef6eeSAndrei Emeltchenko {
6107e0ef6eeSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
6117e0ef6eeSAndrei Emeltchenko 		return (ctrl & L2CAP_EXT_CTRL_SAR) >> L2CAP_EXT_CTRL_SAR_SHIFT;
6127e0ef6eeSAndrei Emeltchenko 	else
6137e0ef6eeSAndrei Emeltchenko 		return (ctrl & L2CAP_CTRL_SAR) >> L2CAP_CTRL_SAR_SHIFT;
6147e0ef6eeSAndrei Emeltchenko }
6157e0ef6eeSAndrei Emeltchenko 
6167e0ef6eeSAndrei Emeltchenko static inline __u32 __set_ctrl_sar(struct l2cap_chan *chan, __u32 sar)
6177e0ef6eeSAndrei Emeltchenko {
6187e0ef6eeSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
6197e0ef6eeSAndrei Emeltchenko 		return (sar << L2CAP_EXT_CTRL_SAR_SHIFT) & L2CAP_EXT_CTRL_SAR;
6207e0ef6eeSAndrei Emeltchenko 	else
6217e0ef6eeSAndrei Emeltchenko 		return (sar << L2CAP_CTRL_SAR_SHIFT) & L2CAP_CTRL_SAR;
6227e0ef6eeSAndrei Emeltchenko }
6237e0ef6eeSAndrei Emeltchenko 
6247e0ef6eeSAndrei Emeltchenko static inline bool __is_sar_start(struct l2cap_chan *chan, __u32 ctrl)
6257e0ef6eeSAndrei Emeltchenko {
6267e0ef6eeSAndrei Emeltchenko 	return __get_ctrl_sar(chan, ctrl) == L2CAP_SAR_START;
6277e0ef6eeSAndrei Emeltchenko }
6287e0ef6eeSAndrei Emeltchenko 
6297e0ef6eeSAndrei Emeltchenko static inline __u32 __get_sar_mask(struct l2cap_chan *chan)
6307e0ef6eeSAndrei Emeltchenko {
6317e0ef6eeSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
6327e0ef6eeSAndrei Emeltchenko 		return L2CAP_EXT_CTRL_SAR;
6337e0ef6eeSAndrei Emeltchenko 	else
6347e0ef6eeSAndrei Emeltchenko 		return L2CAP_CTRL_SAR;
6357e0ef6eeSAndrei Emeltchenko }
6361da177e4SLinus Torvalds 
637ab784b73SAndrei Emeltchenko static inline __u8 __get_ctrl_super(struct l2cap_chan *chan, __u32 ctrl)
638ab784b73SAndrei Emeltchenko {
639ab784b73SAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
640ab784b73SAndrei Emeltchenko 		return (ctrl & L2CAP_EXT_CTRL_SUPERVISE) >>
641ab784b73SAndrei Emeltchenko 						L2CAP_EXT_CTRL_SUPER_SHIFT;
642ab784b73SAndrei Emeltchenko 	else
643ab784b73SAndrei Emeltchenko 		return (ctrl & L2CAP_CTRL_SUPERVISE) >> L2CAP_CTRL_SUPER_SHIFT;
644ab784b73SAndrei Emeltchenko }
645ab784b73SAndrei Emeltchenko 
646ab784b73SAndrei Emeltchenko static inline __u32 __set_ctrl_super(struct l2cap_chan *chan, __u32 super)
647ab784b73SAndrei Emeltchenko {
648ab784b73SAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
649ab784b73SAndrei Emeltchenko 		return (super << L2CAP_EXT_CTRL_SUPER_SHIFT) &
650ab784b73SAndrei Emeltchenko 						L2CAP_EXT_CTRL_SUPERVISE;
651ab784b73SAndrei Emeltchenko 	else
652ab784b73SAndrei Emeltchenko 		return (super << L2CAP_CTRL_SUPER_SHIFT) &
653ab784b73SAndrei Emeltchenko 							L2CAP_CTRL_SUPERVISE;
654ab784b73SAndrei Emeltchenko }
655ab784b73SAndrei Emeltchenko 
65603f6715dSAndrei Emeltchenko static inline __u32 __set_ctrl_final(struct l2cap_chan *chan)
65703f6715dSAndrei Emeltchenko {
65803f6715dSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
65903f6715dSAndrei Emeltchenko 		return L2CAP_EXT_CTRL_FINAL;
66003f6715dSAndrei Emeltchenko 	else
66103f6715dSAndrei Emeltchenko 		return L2CAP_CTRL_FINAL;
66203f6715dSAndrei Emeltchenko }
66303f6715dSAndrei Emeltchenko 
66403f6715dSAndrei Emeltchenko static inline bool __is_ctrl_final(struct l2cap_chan *chan, __u32 ctrl)
66503f6715dSAndrei Emeltchenko {
66603f6715dSAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
66703f6715dSAndrei Emeltchenko 		return ctrl & L2CAP_EXT_CTRL_FINAL;
66803f6715dSAndrei Emeltchenko 	else
66903f6715dSAndrei Emeltchenko 		return ctrl & L2CAP_CTRL_FINAL;
67003f6715dSAndrei Emeltchenko }
671e3781735SAndrei Emeltchenko 
672e3781735SAndrei Emeltchenko static inline __u32 __set_ctrl_poll(struct l2cap_chan *chan)
673e3781735SAndrei Emeltchenko {
674e3781735SAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
675e3781735SAndrei Emeltchenko 		return L2CAP_EXT_CTRL_POLL;
676e3781735SAndrei Emeltchenko 	else
677e3781735SAndrei Emeltchenko 		return L2CAP_CTRL_POLL;
678e3781735SAndrei Emeltchenko }
679e3781735SAndrei Emeltchenko 
680e3781735SAndrei Emeltchenko static inline bool __is_ctrl_poll(struct l2cap_chan *chan, __u32 ctrl)
681e3781735SAndrei Emeltchenko {
682e3781735SAndrei Emeltchenko 	if (test_bit(FLAG_EXT_CTRL, &chan->flags))
683e3781735SAndrei Emeltchenko 		return ctrl & L2CAP_EXT_CTRL_POLL;
684e3781735SAndrei Emeltchenko 	else
685e3781735SAndrei Emeltchenko 		return ctrl & L2CAP_CTRL_POLL;
686e3781735SAndrei Emeltchenko }
687bb58f747SGustavo F. Padovan extern int disable_ertm;
688bb58f747SGustavo F. Padovan 
689bb58f747SGustavo F. Padovan int l2cap_init_sockets(void);
690bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void);
691bb58f747SGustavo F. Padovan 
6928c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan);
693dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk);
69468983259SGustavo F. Padovan 
6959e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm);
6969e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan,  __u16 scid);
6979e4425ffSGustavo F. Padovan 
69823691d75SGustavo F. Padovan struct l2cap_chan *l2cap_chan_create(struct sock *sk);
6990f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason);
70023691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan);
70177a74c7eSGustavo F. Padovan int l2cap_chan_connect(struct l2cap_chan *chan);
7029a91a04aSGustavo F. Padovan int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len);
703e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
704bb58f747SGustavo F. Padovan 
7051da177e4SLinus Torvalds #endif /* __L2CAP_H */
706