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 471da177e4SLinus Torvalds 484e8402a3SMarcel Holtmann #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ 494e8402a3SMarcel Holtmann #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds /* L2CAP socket address */ 521da177e4SLinus Torvalds struct sockaddr_l2 { 531da177e4SLinus Torvalds sa_family_t l2_family; 548e036fc3SAl Viro __le16 l2_psm; 551da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 56f29972deSMarcel Holtmann __le16 l2_cid; 571da177e4SLinus Torvalds }; 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds /* L2CAP socket options */ 601da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 611da177e4SLinus Torvalds struct l2cap_options { 621da177e4SLinus Torvalds __u16 omtu; 631da177e4SLinus Torvalds __u16 imtu; 641da177e4SLinus Torvalds __u16 flush_to; 651da177e4SLinus Torvalds __u8 mode; 66fcc203c3SGustavo F. Padovan __u8 fcs; 6768d7f0ceSGustavo F. Padovan __u8 max_tx; 6814b5aa71SGustavo F. Padovan __u16 txwin_size; 691da177e4SLinus Torvalds }; 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 721da177e4SLinus Torvalds struct l2cap_conninfo { 731da177e4SLinus Torvalds __u16 hci_handle; 741da177e4SLinus Torvalds __u8 dev_class[3]; 751da177e4SLinus Torvalds }; 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds #define L2CAP_LM 0x03 781da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 791da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 801da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 811da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 821da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 831da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds /* L2CAP command codes */ 861da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 871da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 881da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 891da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 901da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 911da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 921da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 931da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 941da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 951da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 961da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 973300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 983300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 991da177e4SLinus Torvalds 100a858393bSAndrei Emeltchenko /* L2CAP extended feature mask */ 10147ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 10247ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 103a858393bSAndrei Emeltchenko #define L2CAP_FEAT_BIDIR_QOS 0x00000004 10447ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 10547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 10647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 107a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_FLOW 0x00000040 10847ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 109a858393bSAndrei Emeltchenko #define L2CAP_FEAT_EXT_WINDOW 0x00000100 110a858393bSAndrei Emeltchenko #define L2CAP_FEAT_UCD 0x00000200 11147ec1dcdSMarcel Holtmann 11247ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 11347ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 11447ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 11547ec1dcdSMarcel Holtmann 1161c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1171c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1181c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1191c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 12057253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPERVISE 0x000C 12157253fd8SAndrei Emeltchenko 1221c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1231c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1241c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1251c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1261c2acffbSGustavo F. Padovan 1271c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 12857253fd8SAndrei Emeltchenko #define L2CAP_CTRL_SUPER_SHIFT 2 1291c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1308f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1311c2acffbSGustavo F. Padovan 13257253fd8SAndrei Emeltchenko /* L2CAP Extended Control Field bit mask */ 13357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000 13457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR 0x00030000 13557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPERVISE 0x00030000 13657253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC 13757253fd8SAndrei Emeltchenko 13857253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_POLL 0x00040000 13957253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FINAL 0x00000002 14057253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 14157253fd8SAndrei Emeltchenko 14257253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 14357253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SAR_SHIFT 16 14457253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 14557253fd8SAndrei Emeltchenko #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 14657253fd8SAndrei Emeltchenko 1471c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 148ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RR 0x00 149ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_REJ 0x01 150ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_RNR 0x02 151ab784b73SAndrei Emeltchenko #define L2CAP_SUPER_SREJ 0x03 1521c2acffbSGustavo F. Padovan 1531c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1547e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_UNSEGMENTED 0x00 1557e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_START 0x01 1567e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_END 0x02 1577e0ef6eeSAndrei Emeltchenko #define L2CAP_SAR_CONTINUE 0x03 1581c2acffbSGustavo F. Padovan 159e2fd318eSIlia Kolomisnky /* L2CAP Command rej. reasons */ 160e2fd318eSIlia Kolomisnky #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 161e2fd318eSIlia Kolomisnky #define L2CAP_REJ_MTU_EXCEEDED 0x0001 162e2fd318eSIlia Kolomisnky #define L2CAP_REJ_INVALID_CID 0x0002 163e2fd318eSIlia Kolomisnky 1641da177e4SLinus Torvalds /* L2CAP structures */ 1651da177e4SLinus Torvalds struct l2cap_hdr { 1668e036fc3SAl Viro __le16 len; 1678e036fc3SAl Viro __le16 cid; 16866c853ccSGustavo F. Padovan } __packed; 1691da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 170d43cb289SAndrei Emeltchenko #define L2CAP_ENH_HDR_SIZE 6 171d43cb289SAndrei Emeltchenko #define L2CAP_EXT_HDR_SIZE 8 172d43cb289SAndrei Emeltchenko 173d43cb289SAndrei Emeltchenko #define L2CAP_FCS_SIZE 2 174d43cb289SAndrei Emeltchenko #define L2CAP_SDULEN_SIZE 2 175d43cb289SAndrei Emeltchenko #define L2CAP_PSMLEN_SIZE 2 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds struct l2cap_cmd_hdr { 1781da177e4SLinus Torvalds __u8 code; 1791da177e4SLinus Torvalds __u8 ident; 1808e036fc3SAl Viro __le16 len; 18166c853ccSGustavo F. Padovan } __packed; 1821da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 1831da177e4SLinus Torvalds 184e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_unk { 1858e036fc3SAl Viro __le16 reason; 18666c853ccSGustavo F. Padovan } __packed; 1871da177e4SLinus Torvalds 188e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_mtu { 189e2fd318eSIlia Kolomisnky __le16 reason; 190e2fd318eSIlia Kolomisnky __le16 max_mtu; 191e2fd318eSIlia Kolomisnky } __packed; 192e2fd318eSIlia Kolomisnky 193e2fd318eSIlia Kolomisnky struct l2cap_cmd_rej_cid { 194e2fd318eSIlia Kolomisnky __le16 reason; 195e2fd318eSIlia Kolomisnky __le16 scid; 196e2fd318eSIlia Kolomisnky __le16 dcid; 197e2fd318eSIlia Kolomisnky } __packed; 198e2fd318eSIlia Kolomisnky 1991da177e4SLinus Torvalds struct l2cap_conn_req { 2008e036fc3SAl Viro __le16 psm; 2018e036fc3SAl Viro __le16 scid; 20266c853ccSGustavo F. Padovan } __packed; 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds struct l2cap_conn_rsp { 2058e036fc3SAl Viro __le16 dcid; 2068e036fc3SAl Viro __le16 scid; 2078e036fc3SAl Viro __le16 result; 2088e036fc3SAl Viro __le16 status; 20966c853ccSGustavo F. Padovan } __packed; 2101da177e4SLinus Torvalds 2118db4dc46SGustavo F. Padovan /* channel indentifier */ 2128db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 2138db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 214acd7d370SVille Tervo #define L2CAP_CID_LE_DATA 0x0004 215acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 216acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 2178db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 2188db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 2198db4dc46SGustavo F. Padovan 2201da177e4SLinus Torvalds /* connect result */ 2211da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 2221da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 2231da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 2241da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 2251da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds /* connect status */ 2281da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 2291da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 2301da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds struct l2cap_conf_req { 2338e036fc3SAl Viro __le16 dcid; 2348e036fc3SAl Viro __le16 flags; 2351da177e4SLinus Torvalds __u8 data[0]; 23666c853ccSGustavo F. Padovan } __packed; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds struct l2cap_conf_rsp { 2398e036fc3SAl Viro __le16 scid; 2408e036fc3SAl Viro __le16 flags; 2418e036fc3SAl Viro __le16 result; 2421da177e4SLinus Torvalds __u8 data[0]; 24366c853ccSGustavo F. Padovan } __packed; 2441da177e4SLinus Torvalds 2455dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 2465dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 2475dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2485dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2490e8b207eSAndrei Emeltchenko #define L2CAP_CONF_PENDING 0x0004 2505a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS_REJECT 0x0005 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds struct l2cap_conf_opt { 2531da177e4SLinus Torvalds __u8 type; 2541da177e4SLinus Torvalds __u8 len; 2551da177e4SLinus Torvalds __u8 val[0]; 25666c853ccSGustavo F. Padovan } __packed; 2571da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2581da177e4SLinus Torvalds 259589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 26047ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 261589d2746SGustavo F. Padovan 2621da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2631da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 2641da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 2651da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 26647ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 2675a9e7057SAndrei Emeltchenko #define L2CAP_CONF_EFS 0x06 2686327eb98SAndrei Emeltchenko #define L2CAP_CONF_EWS 0x07 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 2711da177e4SLinus Torvalds 2726464f35fSMarcel Holtmann struct l2cap_conf_rfc { 2736464f35fSMarcel Holtmann __u8 mode; 2746464f35fSMarcel Holtmann __u8 txwin_size; 2756464f35fSMarcel Holtmann __u8 max_transmit; 2766464f35fSMarcel Holtmann __le16 retrans_timeout; 2776464f35fSMarcel Holtmann __le16 monitor_timeout; 2786464f35fSMarcel Holtmann __le16 max_pdu_size; 27966c853ccSGustavo F. Padovan } __packed; 2806464f35fSMarcel Holtmann 2816464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 2826464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 2836464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 28447ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 285c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 2866464f35fSMarcel Holtmann 2875a9e7057SAndrei Emeltchenko struct l2cap_conf_efs { 2885a9e7057SAndrei Emeltchenko __u8 id; 2895a9e7057SAndrei Emeltchenko __u8 stype; 2905a9e7057SAndrei Emeltchenko __le16 msdu; 2915a9e7057SAndrei Emeltchenko __le32 sdu_itime; 2925a9e7057SAndrei Emeltchenko __le32 acc_lat; 2935a9e7057SAndrei Emeltchenko __le32 flush_to; 2945a9e7057SAndrei Emeltchenko } __packed; 2955a9e7057SAndrei Emeltchenko 2968f7975b1SAndrei Emeltchenko #define L2CAP_SERV_NOTRAFIC 0x00 2978f7975b1SAndrei Emeltchenko #define L2CAP_SERV_BESTEFFORT 0x01 2988f7975b1SAndrei Emeltchenko #define L2CAP_SERV_GUARANTEED 0x02 2998f7975b1SAndrei Emeltchenko 3008f7975b1SAndrei Emeltchenko #define L2CAP_BESTEFFORT_ID 0x01 3018f7975b1SAndrei Emeltchenko 3021da177e4SLinus Torvalds struct l2cap_disconn_req { 3038e036fc3SAl Viro __le16 dcid; 3048e036fc3SAl Viro __le16 scid; 30566c853ccSGustavo F. Padovan } __packed; 3061da177e4SLinus Torvalds 3071da177e4SLinus Torvalds struct l2cap_disconn_rsp { 3088e036fc3SAl Viro __le16 dcid; 3098e036fc3SAl Viro __le16 scid; 31066c853ccSGustavo F. Padovan } __packed; 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds struct l2cap_info_req { 3138e036fc3SAl Viro __le16 type; 31466c853ccSGustavo F. Padovan } __packed; 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds struct l2cap_info_rsp { 3178e036fc3SAl Viro __le16 type; 3188e036fc3SAl Viro __le16 result; 3191da177e4SLinus Torvalds __u8 data[0]; 32066c853ccSGustavo F. Padovan } __packed; 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds /* info type */ 3231da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 3241da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 325e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds /* info result */ 3281da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 3291da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 3301da177e4SLinus Torvalds 331de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 332de73115aSClaudio Takahasi __le16 min; 333de73115aSClaudio Takahasi __le16 max; 334de73115aSClaudio Takahasi __le16 latency; 335de73115aSClaudio Takahasi __le16 to_multiplier; 336de73115aSClaudio Takahasi } __packed; 337de73115aSClaudio Takahasi 338de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 339de73115aSClaudio Takahasi __le16 result; 340de73115aSClaudio Takahasi } __packed; 341de73115aSClaudio Takahasi 342de73115aSClaudio Takahasi /* Connection Parameters result */ 343de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 344de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 345de73115aSClaudio Takahasi 34648454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 34739d5a3eeSGustavo F. Padovan struct srej_list { 348fb45de7dSAndrei Emeltchenko __u16 tx_seq; 34939d5a3eeSGustavo F. Padovan struct list_head list; 35039d5a3eeSGustavo F. Padovan }; 35139d5a3eeSGustavo F. Padovan 35248454079SGustavo F. Padovan struct l2cap_chan { 35348454079SGustavo F. Padovan struct sock *sk; 3548c1d787bSGustavo F. Padovan 3558c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 3568c1d787bSGustavo F. Padovan 35789bc500eSGustavo F. Padovan __u8 state; 35889bc500eSGustavo F. Padovan 35971ba0e56SGustavo F. Padovan atomic_t refcnt; 36071ba0e56SGustavo F. Padovan 361fe4128e0SGustavo F. Padovan __le16 psm; 362fe4128e0SGustavo F. Padovan __u16 dcid; 363fe4128e0SGustavo F. Padovan __u16 scid; 3644343478fSGustavo F. Padovan 3650c1bc5c6SGustavo F. Padovan __u16 imtu; 3660c1bc5c6SGustavo F. Padovan __u16 omtu; 3670c1bc5c6SGustavo F. Padovan __u16 flush_to; 3680c1bc5c6SGustavo F. Padovan __u8 mode; 369715ec005SGustavo F. Padovan __u8 chan_type; 3700c1bc5c6SGustavo F. Padovan 3710c1bc5c6SGustavo F. Padovan __le16 sport; 3720c1bc5c6SGustavo F. Padovan 3734343478fSGustavo F. Padovan __u8 sec_level; 3744343478fSGustavo F. Padovan 375fc7f8a7eSGustavo F. Padovan __u8 ident; 376fc7f8a7eSGustavo F. Padovan 37773ffa904SGustavo F. Padovan __u8 conf_req[64]; 37873ffa904SGustavo F. Padovan __u8 conf_len; 37973ffa904SGustavo F. Padovan __u8 num_conf_req; 38073ffa904SGustavo F. Padovan __u8 num_conf_rsp; 38173ffa904SGustavo F. Padovan 38247d1ec61SGustavo F. Padovan __u8 fcs; 38347d1ec61SGustavo F. Padovan 3846327eb98SAndrei Emeltchenko __u16 tx_win; 385836be934SAndrei Emeltchenko __u16 tx_win_max; 38647d1ec61SGustavo F. Padovan __u8 max_tx; 38747d1ec61SGustavo F. Padovan __u16 retrans_timeout; 38847d1ec61SGustavo F. Padovan __u16 monitor_timeout; 38947d1ec61SGustavo F. Padovan __u16 mps; 39047d1ec61SGustavo F. Padovan 391c1360a1cSGustavo F. Padovan unsigned long conf_state; 392e2ab4353SGustavo F. Padovan unsigned long conn_state; 393d57b0e8bSAndrei Emeltchenko unsigned long flags; 394525cd185SGustavo F. Padovan 395fb45de7dSAndrei Emeltchenko __u16 next_tx_seq; 396fb45de7dSAndrei Emeltchenko __u16 expected_ack_seq; 397fb45de7dSAndrei Emeltchenko __u16 expected_tx_seq; 3980b209faeSAndrei Emeltchenko __u16 buffer_seq; 399fb45de7dSAndrei Emeltchenko __u16 buffer_seq_srej; 400fb45de7dSAndrei Emeltchenko __u16 srej_save_reqseq; 401fb45de7dSAndrei Emeltchenko __u16 frames_sent; 402fb45de7dSAndrei Emeltchenko __u16 unacked_frames; 4036a026610SGustavo F. Padovan __u8 retry_count; 4046a026610SGustavo F. Padovan __u8 num_acked; 4056f61fd47SGustavo F. Padovan __u16 sdu_len; 4066f61fd47SGustavo F. Padovan struct sk_buff *sdu; 40784084a31SMat Martineau struct sk_buff *sdu_last_frag; 4086f61fd47SGustavo F. Padovan 4096327eb98SAndrei Emeltchenko __u16 remote_tx_win; 4102c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 4112c03a7a4SGustavo F. Padovan __u16 remote_mps; 41242e5c802SGustavo F. Padovan 4135a9e7057SAndrei Emeltchenko __u8 local_id; 4145a9e7057SAndrei Emeltchenko __u8 local_stype; 4155a9e7057SAndrei Emeltchenko __u16 local_msdu; 4165a9e7057SAndrei Emeltchenko __u32 local_sdu_itime; 4175a9e7057SAndrei Emeltchenko __u32 local_acc_lat; 4185a9e7057SAndrei Emeltchenko __u32 local_flush_to; 4195a9e7057SAndrei Emeltchenko 4205a9e7057SAndrei Emeltchenko __u8 remote_id; 4215a9e7057SAndrei Emeltchenko __u8 remote_stype; 4225a9e7057SAndrei Emeltchenko __u16 remote_msdu; 4235a9e7057SAndrei Emeltchenko __u32 remote_sdu_itime; 4245a9e7057SAndrei Emeltchenko __u32 remote_acc_lat; 4255a9e7057SAndrei Emeltchenko __u32 remote_flush_to; 4265a9e7057SAndrei Emeltchenko 427ab07801dSGustavo F. Padovan struct timer_list chan_timer; 428e92c8e70SGustavo F. Padovan struct timer_list retrans_timer; 429e92c8e70SGustavo F. Padovan struct timer_list monitor_timer; 430e92c8e70SGustavo F. Padovan struct timer_list ack_timer; 43158d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 43258d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 433f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 43439d5a3eeSGustavo F. Padovan struct list_head srej_l; 435e92c8e70SGustavo F. Padovan 436baa7e1faSGustavo F. Padovan struct list_head list; 43723691d75SGustavo F. Padovan struct list_head global_l; 43880808e43SGustavo F. Padovan 43980808e43SGustavo F. Padovan void *data; 44080808e43SGustavo F. Padovan struct l2cap_ops *ops; 44180808e43SGustavo F. Padovan }; 44280808e43SGustavo F. Padovan 44380808e43SGustavo F. Padovan struct l2cap_ops { 44480808e43SGustavo F. Padovan char *name; 44580808e43SGustavo F. Padovan 44680808e43SGustavo F. Padovan struct l2cap_chan *(*new_connection) (void *data); 44723070494SGustavo F. Padovan int (*recv) (void *data, struct sk_buff *skb); 448ba3bd0eeSGustavo F. Padovan void (*close) (void *data); 44989bc500eSGustavo F. Padovan void (*state_change) (void *data, int state); 4501da177e4SLinus Torvalds }; 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds struct l2cap_conn { 4531da177e4SLinus Torvalds struct hci_conn *hcon; 454*73d80debSLuiz Augusto von Dentz struct hci_chan *hchan; 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvalds bdaddr_t *dst; 4571da177e4SLinus Torvalds bdaddr_t *src; 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds unsigned int mtu; 4601da177e4SLinus Torvalds 4614e8402a3SMarcel Holtmann __u32 feat_mask; 4624e8402a3SMarcel Holtmann 4634e8402a3SMarcel Holtmann __u8 info_state; 4644e8402a3SMarcel Holtmann __u8 info_ident; 4654e8402a3SMarcel Holtmann 4664e8402a3SMarcel Holtmann struct timer_list info_timer; 4674e8402a3SMarcel Holtmann 4681da177e4SLinus Torvalds spinlock_t lock; 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds struct sk_buff *rx_skb; 4711da177e4SLinus Torvalds __u32 rx_len; 4721da177e4SLinus Torvalds __u8 tx_ident; 4731da177e4SLinus Torvalds 4742950f21aSMarcel Holtmann __u8 disc_reason; 4752950f21aSMarcel Holtmann 4765d3de7dfSVinicius Costa Gomes struct timer_list security_timer; 4771c1def09SVinicius Costa Gomes struct smp_chan *smp_chan; 4785d3de7dfSVinicius Costa Gomes 479baa7e1faSGustavo F. Padovan struct list_head chan_l; 480baa7e1faSGustavo F. Padovan rwlock_t chan_lock; 4811da177e4SLinus Torvalds }; 4821da177e4SLinus Torvalds 4834e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 484984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 485984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 4864e8402a3SMarcel Holtmann 487715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 488715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 489715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 490715ec005SGustavo F. Padovan 49148454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 4921da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds struct l2cap_pinfo { 4951da177e4SLinus Torvalds struct bt_sock bt; 49648454079SGustavo F. Padovan struct l2cap_chan *chan; 497e328140fSMat Martineau struct sk_buff *rx_busy_skb; 4981da177e4SLinus Torvalds }; 4991da177e4SLinus Torvalds 500c1360a1cSGustavo F. Padovan enum { 501c1360a1cSGustavo F. Padovan CONF_REQ_SENT, 502c1360a1cSGustavo F. Padovan CONF_INPUT_DONE, 503c1360a1cSGustavo F. Padovan CONF_OUTPUT_DONE, 504c1360a1cSGustavo F. Padovan CONF_MTU_DONE, 505c1360a1cSGustavo F. Padovan CONF_MODE_DONE, 506c1360a1cSGustavo F. Padovan CONF_CONNECT_PEND, 507c1360a1cSGustavo F. Padovan CONF_NO_FCS_RECV, 508c1360a1cSGustavo F. Padovan CONF_STATE2_DEVICE, 5096327eb98SAndrei Emeltchenko CONF_EWS_RECV, 5100e8b207eSAndrei Emeltchenko CONF_LOC_CONF_PEND, 5110e8b207eSAndrei Emeltchenko CONF_REM_CONF_PEND, 512c1360a1cSGustavo F. Padovan }; 513861d6882SMarcel Holtmann 514f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 515f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 516f2fcfcd6SGustavo F. Padovan 517e2ab4353SGustavo F. Padovan enum { 518e2ab4353SGustavo F. Padovan CONN_SREJ_SENT, 519e2ab4353SGustavo F. Padovan CONN_WAIT_F, 520e2ab4353SGustavo F. Padovan CONN_SREJ_ACT, 521e2ab4353SGustavo F. Padovan CONN_SEND_PBIT, 522e2ab4353SGustavo F. Padovan CONN_REMOTE_BUSY, 523e2ab4353SGustavo F. Padovan CONN_LOCAL_BUSY, 524e2ab4353SGustavo F. Padovan CONN_REJ_ACT, 525e2ab4353SGustavo F. Padovan CONN_SEND_FBIT, 526e2ab4353SGustavo F. Padovan CONN_RNR_SENT, 527e2ab4353SGustavo F. Padovan }; 528e90bac06SGustavo F. Padovan 529d57b0e8bSAndrei Emeltchenko /* Definitions for flags in l2cap_chan */ 530d57b0e8bSAndrei Emeltchenko enum { 53143bd0f32SAndrei Emeltchenko FLAG_ROLE_SWITCH, 53215770b1aSAndrei Emeltchenko FLAG_FORCE_ACTIVE, 533ecf61bdbSAndrei Emeltchenko FLAG_FORCE_RELIABLE, 534d57b0e8bSAndrei Emeltchenko FLAG_FLUSHABLE, 5356327eb98SAndrei Emeltchenko FLAG_EXT_CTRL, 5365a9e7057SAndrei Emeltchenko FLAG_EFS_ENABLE, 537d57b0e8bSAndrei Emeltchenko }; 538d57b0e8bSAndrei Emeltchenko 539c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 540c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 5411a09bcb9SGustavo F. Padovan #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \ 5421a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_RETRANS_TO); 5431a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 5441a09bcb9SGustavo F. Padovan #define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \ 5451a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_MONITOR_TO); 5461a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 5471a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 5481a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_ACK_TO); 5491a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 550c74e560cSGustavo F. Padovan 551836be934SAndrei Emeltchenko static inline int __seq_offset(struct l2cap_chan *chan, __u16 seq1, __u16 seq2) 552836be934SAndrei Emeltchenko { 553836be934SAndrei Emeltchenko int offset; 554836be934SAndrei Emeltchenko 555836be934SAndrei Emeltchenko offset = (seq1 - seq2) % (chan->tx_win_max + 1); 556836be934SAndrei Emeltchenko if (offset < 0) 557836be934SAndrei Emeltchenko offset += (chan->tx_win_max + 1); 558836be934SAndrei Emeltchenko 559836be934SAndrei Emeltchenko return offset; 560836be934SAndrei Emeltchenko } 561836be934SAndrei Emeltchenko 562836be934SAndrei Emeltchenko static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq) 563836be934SAndrei Emeltchenko { 564836be934SAndrei Emeltchenko return (seq + 1) % (chan->tx_win_max + 1); 565836be934SAndrei Emeltchenko } 566836be934SAndrei Emeltchenko 56742e5c802SGustavo F. Padovan static inline int l2cap_tx_window_full(struct l2cap_chan *ch) 5681c2acffbSGustavo F. Padovan { 5691c2acffbSGustavo F. Padovan int sub; 5701c2acffbSGustavo F. Padovan 57142e5c802SGustavo F. Padovan sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; 5721c2acffbSGustavo F. Padovan 5731c2acffbSGustavo F. Padovan if (sub < 0) 5741c2acffbSGustavo F. Padovan sub += 64; 5751c2acffbSGustavo F. Padovan 5762c03a7a4SGustavo F. Padovan return sub == ch->remote_tx_win; 5771c2acffbSGustavo F. Padovan } 5781c2acffbSGustavo F. Padovan 5790b209faeSAndrei Emeltchenko static inline __u16 __get_reqseq(struct l2cap_chan *chan, __u32 ctrl) 5800b209faeSAndrei Emeltchenko { 5810b209faeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 5820b209faeSAndrei Emeltchenko return (ctrl & L2CAP_EXT_CTRL_REQSEQ) >> 5830b209faeSAndrei Emeltchenko L2CAP_EXT_CTRL_REQSEQ_SHIFT; 5840b209faeSAndrei Emeltchenko else 5850b209faeSAndrei Emeltchenko return (ctrl & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT; 5860b209faeSAndrei Emeltchenko } 5870b209faeSAndrei Emeltchenko 5880b209faeSAndrei Emeltchenko static inline __u32 __set_reqseq(struct l2cap_chan *chan, __u32 reqseq) 5890b209faeSAndrei Emeltchenko { 5900b209faeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 5910b209faeSAndrei Emeltchenko return (reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT) & 5920b209faeSAndrei Emeltchenko L2CAP_EXT_CTRL_REQSEQ; 5930b209faeSAndrei Emeltchenko else 5940b209faeSAndrei Emeltchenko return (reqseq << L2CAP_CTRL_REQSEQ_SHIFT) & L2CAP_CTRL_REQSEQ; 5950b209faeSAndrei Emeltchenko } 596fb45de7dSAndrei Emeltchenko 597fb45de7dSAndrei Emeltchenko static inline __u16 __get_txseq(struct l2cap_chan *chan, __u32 ctrl) 598fb45de7dSAndrei Emeltchenko { 599fb45de7dSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 600fb45de7dSAndrei Emeltchenko return (ctrl & L2CAP_EXT_CTRL_TXSEQ) >> 601fb45de7dSAndrei Emeltchenko L2CAP_EXT_CTRL_TXSEQ_SHIFT; 602fb45de7dSAndrei Emeltchenko else 603fb45de7dSAndrei Emeltchenko return (ctrl & L2CAP_CTRL_TXSEQ) >> L2CAP_CTRL_TXSEQ_SHIFT; 604fb45de7dSAndrei Emeltchenko } 605fb45de7dSAndrei Emeltchenko 606fb45de7dSAndrei Emeltchenko static inline __u32 __set_txseq(struct l2cap_chan *chan, __u32 txseq) 607fb45de7dSAndrei Emeltchenko { 608fb45de7dSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 609fb45de7dSAndrei Emeltchenko return (txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT) & 610fb45de7dSAndrei Emeltchenko L2CAP_EXT_CTRL_TXSEQ; 611fb45de7dSAndrei Emeltchenko else 612fb45de7dSAndrei Emeltchenko return (txseq << L2CAP_CTRL_TXSEQ_SHIFT) & L2CAP_CTRL_TXSEQ; 613fb45de7dSAndrei Emeltchenko } 614fb45de7dSAndrei Emeltchenko 615793c2f1cSAndrei Emeltchenko static inline bool __is_sframe(struct l2cap_chan *chan, __u32 ctrl) 616793c2f1cSAndrei Emeltchenko { 617793c2f1cSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 618793c2f1cSAndrei Emeltchenko return ctrl & L2CAP_EXT_CTRL_FRAME_TYPE; 619793c2f1cSAndrei Emeltchenko else 620793c2f1cSAndrei Emeltchenko return ctrl & L2CAP_CTRL_FRAME_TYPE; 621793c2f1cSAndrei Emeltchenko } 622793c2f1cSAndrei Emeltchenko 623793c2f1cSAndrei Emeltchenko static inline __u32 __set_sframe(struct l2cap_chan *chan) 624793c2f1cSAndrei Emeltchenko { 625793c2f1cSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 626793c2f1cSAndrei Emeltchenko return L2CAP_EXT_CTRL_FRAME_TYPE; 627793c2f1cSAndrei Emeltchenko else 628793c2f1cSAndrei Emeltchenko return L2CAP_CTRL_FRAME_TYPE; 629793c2f1cSAndrei Emeltchenko } 630793c2f1cSAndrei Emeltchenko 6317e0ef6eeSAndrei Emeltchenko static inline __u8 __get_ctrl_sar(struct l2cap_chan *chan, __u32 ctrl) 6327e0ef6eeSAndrei Emeltchenko { 6337e0ef6eeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 6347e0ef6eeSAndrei Emeltchenko return (ctrl & L2CAP_EXT_CTRL_SAR) >> L2CAP_EXT_CTRL_SAR_SHIFT; 6357e0ef6eeSAndrei Emeltchenko else 6367e0ef6eeSAndrei Emeltchenko return (ctrl & L2CAP_CTRL_SAR) >> L2CAP_CTRL_SAR_SHIFT; 6377e0ef6eeSAndrei Emeltchenko } 6387e0ef6eeSAndrei Emeltchenko 6397e0ef6eeSAndrei Emeltchenko static inline __u32 __set_ctrl_sar(struct l2cap_chan *chan, __u32 sar) 6407e0ef6eeSAndrei Emeltchenko { 6417e0ef6eeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 6427e0ef6eeSAndrei Emeltchenko return (sar << L2CAP_EXT_CTRL_SAR_SHIFT) & L2CAP_EXT_CTRL_SAR; 6437e0ef6eeSAndrei Emeltchenko else 6447e0ef6eeSAndrei Emeltchenko return (sar << L2CAP_CTRL_SAR_SHIFT) & L2CAP_CTRL_SAR; 6457e0ef6eeSAndrei Emeltchenko } 6467e0ef6eeSAndrei Emeltchenko 6477e0ef6eeSAndrei Emeltchenko static inline bool __is_sar_start(struct l2cap_chan *chan, __u32 ctrl) 6487e0ef6eeSAndrei Emeltchenko { 6497e0ef6eeSAndrei Emeltchenko return __get_ctrl_sar(chan, ctrl) == L2CAP_SAR_START; 6507e0ef6eeSAndrei Emeltchenko } 6517e0ef6eeSAndrei Emeltchenko 6527e0ef6eeSAndrei Emeltchenko static inline __u32 __get_sar_mask(struct l2cap_chan *chan) 6537e0ef6eeSAndrei Emeltchenko { 6547e0ef6eeSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 6557e0ef6eeSAndrei Emeltchenko return L2CAP_EXT_CTRL_SAR; 6567e0ef6eeSAndrei Emeltchenko else 6577e0ef6eeSAndrei Emeltchenko return L2CAP_CTRL_SAR; 6587e0ef6eeSAndrei Emeltchenko } 6591da177e4SLinus Torvalds 660ab784b73SAndrei Emeltchenko static inline __u8 __get_ctrl_super(struct l2cap_chan *chan, __u32 ctrl) 661ab784b73SAndrei Emeltchenko { 662ab784b73SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 663ab784b73SAndrei Emeltchenko return (ctrl & L2CAP_EXT_CTRL_SUPERVISE) >> 664ab784b73SAndrei Emeltchenko L2CAP_EXT_CTRL_SUPER_SHIFT; 665ab784b73SAndrei Emeltchenko else 666ab784b73SAndrei Emeltchenko return (ctrl & L2CAP_CTRL_SUPERVISE) >> L2CAP_CTRL_SUPER_SHIFT; 667ab784b73SAndrei Emeltchenko } 668ab784b73SAndrei Emeltchenko 669ab784b73SAndrei Emeltchenko static inline __u32 __set_ctrl_super(struct l2cap_chan *chan, __u32 super) 670ab784b73SAndrei Emeltchenko { 671ab784b73SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 672ab784b73SAndrei Emeltchenko return (super << L2CAP_EXT_CTRL_SUPER_SHIFT) & 673ab784b73SAndrei Emeltchenko L2CAP_EXT_CTRL_SUPERVISE; 674ab784b73SAndrei Emeltchenko else 675ab784b73SAndrei Emeltchenko return (super << L2CAP_CTRL_SUPER_SHIFT) & 676ab784b73SAndrei Emeltchenko L2CAP_CTRL_SUPERVISE; 677ab784b73SAndrei Emeltchenko } 678ab784b73SAndrei Emeltchenko 67903f6715dSAndrei Emeltchenko static inline __u32 __set_ctrl_final(struct l2cap_chan *chan) 68003f6715dSAndrei Emeltchenko { 68103f6715dSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 68203f6715dSAndrei Emeltchenko return L2CAP_EXT_CTRL_FINAL; 68303f6715dSAndrei Emeltchenko else 68403f6715dSAndrei Emeltchenko return L2CAP_CTRL_FINAL; 68503f6715dSAndrei Emeltchenko } 68603f6715dSAndrei Emeltchenko 68703f6715dSAndrei Emeltchenko static inline bool __is_ctrl_final(struct l2cap_chan *chan, __u32 ctrl) 68803f6715dSAndrei Emeltchenko { 68903f6715dSAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 69003f6715dSAndrei Emeltchenko return ctrl & L2CAP_EXT_CTRL_FINAL; 69103f6715dSAndrei Emeltchenko else 69203f6715dSAndrei Emeltchenko return ctrl & L2CAP_CTRL_FINAL; 69303f6715dSAndrei Emeltchenko } 694e3781735SAndrei Emeltchenko 695e3781735SAndrei Emeltchenko static inline __u32 __set_ctrl_poll(struct l2cap_chan *chan) 696e3781735SAndrei Emeltchenko { 697e3781735SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 698e3781735SAndrei Emeltchenko return L2CAP_EXT_CTRL_POLL; 699e3781735SAndrei Emeltchenko else 700e3781735SAndrei Emeltchenko return L2CAP_CTRL_POLL; 701e3781735SAndrei Emeltchenko } 702e3781735SAndrei Emeltchenko 703e3781735SAndrei Emeltchenko static inline bool __is_ctrl_poll(struct l2cap_chan *chan, __u32 ctrl) 704e3781735SAndrei Emeltchenko { 705e3781735SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 706e3781735SAndrei Emeltchenko return ctrl & L2CAP_EXT_CTRL_POLL; 707e3781735SAndrei Emeltchenko else 708e3781735SAndrei Emeltchenko return ctrl & L2CAP_CTRL_POLL; 709e3781735SAndrei Emeltchenko } 71088843ab0SAndrei Emeltchenko 71188843ab0SAndrei Emeltchenko static inline __u32 __get_control(struct l2cap_chan *chan, void *p) 71288843ab0SAndrei Emeltchenko { 71388843ab0SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 71488843ab0SAndrei Emeltchenko return get_unaligned_le32(p); 71588843ab0SAndrei Emeltchenko else 71688843ab0SAndrei Emeltchenko return get_unaligned_le16(p); 71788843ab0SAndrei Emeltchenko } 71888843ab0SAndrei Emeltchenko 71988843ab0SAndrei Emeltchenko static inline void __put_control(struct l2cap_chan *chan, __u32 control, 72088843ab0SAndrei Emeltchenko void *p) 72188843ab0SAndrei Emeltchenko { 72288843ab0SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 72388843ab0SAndrei Emeltchenko return put_unaligned_le32(control, p); 72488843ab0SAndrei Emeltchenko else 72588843ab0SAndrei Emeltchenko return put_unaligned_le16(control, p); 72688843ab0SAndrei Emeltchenko } 72788843ab0SAndrei Emeltchenko 72888843ab0SAndrei Emeltchenko static inline __u8 __ctrl_size(struct l2cap_chan *chan) 72988843ab0SAndrei Emeltchenko { 73088843ab0SAndrei Emeltchenko if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 73188843ab0SAndrei Emeltchenko return L2CAP_EXT_HDR_SIZE - L2CAP_HDR_SIZE; 73288843ab0SAndrei Emeltchenko else 73388843ab0SAndrei Emeltchenko return L2CAP_ENH_HDR_SIZE - L2CAP_HDR_SIZE; 73488843ab0SAndrei Emeltchenko } 73588843ab0SAndrei Emeltchenko 736bb58f747SGustavo F. Padovan extern int disable_ertm; 737bb58f747SGustavo F. Padovan 738bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 739bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 740bb58f747SGustavo F. Padovan 7418c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 742dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 74368983259SGustavo F. Padovan 7449e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 7459e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 7469e4425ffSGustavo F. Padovan 74723691d75SGustavo F. Padovan struct l2cap_chan *l2cap_chan_create(struct sock *sk); 7480f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 74923691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan); 75077a74c7eSGustavo F. Padovan int l2cap_chan_connect(struct l2cap_chan *chan); 7515e59b791SLuiz Augusto von Dentz int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 7525e59b791SLuiz Augusto von Dentz u32 priority); 753e328140fSMat Martineau void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 754bb58f747SGustavo F. Padovan 7551da177e4SLinus Torvalds #endif /* __L2CAP_H */ 756