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 35e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MAX_TX 3 36fa235562SMat Martineau #define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */ 37e90bac06SGustavo F. Padovan #define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 38db12d647SMat Martineau #define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */ 39c1b4f43bSGustavo F. Padovan #define L2CAP_DEFAULT_ACK_TO 200 401890d36bSGustavo F. Padovan #define L2CAP_LOCAL_BUSY_TRIES 12 411da177e4SLinus Torvalds 424e8402a3SMarcel Holtmann #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ 434e8402a3SMarcel Holtmann #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds /* L2CAP socket address */ 461da177e4SLinus Torvalds struct sockaddr_l2 { 471da177e4SLinus Torvalds sa_family_t l2_family; 488e036fc3SAl Viro __le16 l2_psm; 491da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 50f29972deSMarcel Holtmann __le16 l2_cid; 511da177e4SLinus Torvalds }; 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* L2CAP socket options */ 541da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 551da177e4SLinus Torvalds struct l2cap_options { 561da177e4SLinus Torvalds __u16 omtu; 571da177e4SLinus Torvalds __u16 imtu; 581da177e4SLinus Torvalds __u16 flush_to; 591da177e4SLinus Torvalds __u8 mode; 60fcc203c3SGustavo F. Padovan __u8 fcs; 6168d7f0ceSGustavo F. Padovan __u8 max_tx; 6214b5aa71SGustavo F. Padovan __u16 txwin_size; 631da177e4SLinus Torvalds }; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 661da177e4SLinus Torvalds struct l2cap_conninfo { 671da177e4SLinus Torvalds __u16 hci_handle; 681da177e4SLinus Torvalds __u8 dev_class[3]; 691da177e4SLinus Torvalds }; 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds #define L2CAP_LM 0x03 721da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 731da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 741da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 751da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 761da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 771da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* L2CAP command codes */ 801da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 811da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 821da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 831da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 841da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 851da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 861da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 871da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 881da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 891da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 901da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 911da177e4SLinus Torvalds 9247ec1dcdSMarcel Holtmann /* L2CAP feature mask */ 9347ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 9447ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 9547ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 9647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 9747ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 9847ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 9947ec1dcdSMarcel Holtmann 10047ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 10147ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 10247ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 10347ec1dcdSMarcel Holtmann 1041c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1051c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1061c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1071c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 1081c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1091c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1101c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1111c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SUPERVISE 0x000C 1121c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1131c2acffbSGustavo F. Padovan 1141c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 1151c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1168f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1171c2acffbSGustavo F. Padovan 1181c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 1191c2acffbSGustavo F. Padovan #define L2CAP_SUPER_RCV_READY 0x0000 1201c2acffbSGustavo F. Padovan #define L2CAP_SUPER_REJECT 0x0004 1211c2acffbSGustavo F. Padovan #define L2CAP_SUPER_RCV_NOT_READY 0x0008 1221c2acffbSGustavo F. Padovan #define L2CAP_SUPER_SELECT_REJECT 0x000C 1231c2acffbSGustavo F. Padovan 1241c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1251c2acffbSGustavo F. Padovan #define L2CAP_SDU_UNSEGMENTED 0x0000 1261c2acffbSGustavo F. Padovan #define L2CAP_SDU_START 0x4000 1271c2acffbSGustavo F. Padovan #define L2CAP_SDU_END 0x8000 1281c2acffbSGustavo F. Padovan #define L2CAP_SDU_CONTINUE 0xC000 1291c2acffbSGustavo F. Padovan 1301da177e4SLinus Torvalds /* L2CAP structures */ 1311da177e4SLinus Torvalds struct l2cap_hdr { 1328e036fc3SAl Viro __le16 len; 1338e036fc3SAl Viro __le16 cid; 13466c853ccSGustavo F. Padovan } __packed; 1351da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds struct l2cap_cmd_hdr { 1381da177e4SLinus Torvalds __u8 code; 1391da177e4SLinus Torvalds __u8 ident; 1408e036fc3SAl Viro __le16 len; 14166c853ccSGustavo F. Padovan } __packed; 1421da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 1431da177e4SLinus Torvalds 1441da177e4SLinus Torvalds struct l2cap_cmd_rej { 1458e036fc3SAl Viro __le16 reason; 14666c853ccSGustavo F. Padovan } __packed; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds struct l2cap_conn_req { 1498e036fc3SAl Viro __le16 psm; 1508e036fc3SAl Viro __le16 scid; 15166c853ccSGustavo F. Padovan } __packed; 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds struct l2cap_conn_rsp { 1548e036fc3SAl Viro __le16 dcid; 1558e036fc3SAl Viro __le16 scid; 1568e036fc3SAl Viro __le16 result; 1578e036fc3SAl Viro __le16 status; 15866c853ccSGustavo F. Padovan } __packed; 1591da177e4SLinus Torvalds 1608db4dc46SGustavo F. Padovan /* channel indentifier */ 1618db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 1628db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 163*acd7d370SVille Tervo #define L2CAP_CID_LE_DATA 0x0004 164*acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 165*acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 1668db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 1678db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 1688db4dc46SGustavo F. Padovan 1691da177e4SLinus Torvalds /* connect result */ 1701da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 1711da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 1721da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 1731da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 1741da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds /* connect status */ 1771da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 1781da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 1791da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds struct l2cap_conf_req { 1828e036fc3SAl Viro __le16 dcid; 1838e036fc3SAl Viro __le16 flags; 1841da177e4SLinus Torvalds __u8 data[0]; 18566c853ccSGustavo F. Padovan } __packed; 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds struct l2cap_conf_rsp { 1888e036fc3SAl Viro __le16 scid; 1898e036fc3SAl Viro __le16 flags; 1908e036fc3SAl Viro __le16 result; 1911da177e4SLinus Torvalds __u8 data[0]; 19266c853ccSGustavo F. Padovan } __packed; 1931da177e4SLinus Torvalds 1945dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 1955dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 1965dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 1975dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds struct l2cap_conf_opt { 2001da177e4SLinus Torvalds __u8 type; 2011da177e4SLinus Torvalds __u8 len; 2021da177e4SLinus Torvalds __u8 val[0]; 20366c853ccSGustavo F. Padovan } __packed; 2041da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2051da177e4SLinus Torvalds 206589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 20747ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 208589d2746SGustavo F. Padovan 2091da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2101da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 2111da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 2121da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 21347ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 2161da177e4SLinus Torvalds 2176464f35fSMarcel Holtmann struct l2cap_conf_rfc { 2186464f35fSMarcel Holtmann __u8 mode; 2196464f35fSMarcel Holtmann __u8 txwin_size; 2206464f35fSMarcel Holtmann __u8 max_transmit; 2216464f35fSMarcel Holtmann __le16 retrans_timeout; 2226464f35fSMarcel Holtmann __le16 monitor_timeout; 2236464f35fSMarcel Holtmann __le16 max_pdu_size; 22466c853ccSGustavo F. Padovan } __packed; 2256464f35fSMarcel Holtmann 2266464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 2276464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 2286464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 22947ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 230c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 2316464f35fSMarcel Holtmann 2321da177e4SLinus Torvalds struct l2cap_disconn_req { 2338e036fc3SAl Viro __le16 dcid; 2348e036fc3SAl Viro __le16 scid; 23566c853ccSGustavo F. Padovan } __packed; 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds struct l2cap_disconn_rsp { 2388e036fc3SAl Viro __le16 dcid; 2398e036fc3SAl Viro __le16 scid; 24066c853ccSGustavo F. Padovan } __packed; 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds struct l2cap_info_req { 2438e036fc3SAl Viro __le16 type; 24466c853ccSGustavo F. Padovan } __packed; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds struct l2cap_info_rsp { 2478e036fc3SAl Viro __le16 type; 2488e036fc3SAl Viro __le16 result; 2491da177e4SLinus Torvalds __u8 data[0]; 25066c853ccSGustavo F. Padovan } __packed; 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds /* info type */ 2531da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 2541da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 255e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds /* info result */ 2581da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 2591da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds /* ----- L2CAP connections ----- */ 2621da177e4SLinus Torvalds struct l2cap_chan_list { 2631da177e4SLinus Torvalds struct sock *head; 2641da177e4SLinus Torvalds rwlock_t lock; 2651da177e4SLinus Torvalds long num; 2661da177e4SLinus Torvalds }; 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds struct l2cap_conn { 2691da177e4SLinus Torvalds struct hci_conn *hcon; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds bdaddr_t *dst; 2721da177e4SLinus Torvalds bdaddr_t *src; 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds unsigned int mtu; 2751da177e4SLinus Torvalds 2764e8402a3SMarcel Holtmann __u32 feat_mask; 2774e8402a3SMarcel Holtmann 2784e8402a3SMarcel Holtmann __u8 info_state; 2794e8402a3SMarcel Holtmann __u8 info_ident; 2804e8402a3SMarcel Holtmann 2814e8402a3SMarcel Holtmann struct timer_list info_timer; 2824e8402a3SMarcel Holtmann 2831da177e4SLinus Torvalds spinlock_t lock; 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds struct sk_buff *rx_skb; 2861da177e4SLinus Torvalds __u32 rx_len; 2871da177e4SLinus Torvalds __u8 rx_ident; 2881da177e4SLinus Torvalds __u8 tx_ident; 2891da177e4SLinus Torvalds 2902950f21aSMarcel Holtmann __u8 disc_reason; 2912950f21aSMarcel Holtmann 2921da177e4SLinus Torvalds struct l2cap_chan_list chan_list; 2931da177e4SLinus Torvalds }; 2941da177e4SLinus Torvalds 295cf6c2c0bSGustavo F. Padovan struct sock_del_list { 296cf6c2c0bSGustavo F. Padovan struct sock *sk; 297cf6c2c0bSGustavo F. Padovan struct list_head list; 298cf6c2c0bSGustavo F. Padovan }; 299cf6c2c0bSGustavo F. Padovan 3004e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 301984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 302984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 3034e8402a3SMarcel Holtmann 3041da177e4SLinus Torvalds /* ----- L2CAP channel and socket info ----- */ 3051da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 3061c2acffbSGustavo F. Padovan #define TX_QUEUE(sk) (&l2cap_pi(sk)->tx_queue) 3078f17154fSGustavo F. Padovan #define SREJ_QUEUE(sk) (&l2cap_pi(sk)->srej_queue) 3081890d36bSGustavo F. Padovan #define BUSY_QUEUE(sk) (&l2cap_pi(sk)->busy_queue) 3098f17154fSGustavo F. Padovan #define SREJ_LIST(sk) (&l2cap_pi(sk)->srej_l.list) 3108f17154fSGustavo F. Padovan 3118f17154fSGustavo F. Padovan struct srej_list { 3128f17154fSGustavo F. Padovan __u8 tx_seq; 3138f17154fSGustavo F. Padovan struct list_head list; 3148f17154fSGustavo F. Padovan }; 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds struct l2cap_pinfo { 3171da177e4SLinus Torvalds struct bt_sock bt; 3188e036fc3SAl Viro __le16 psm; 3191da177e4SLinus Torvalds __u16 dcid; 3201da177e4SLinus Torvalds __u16 scid; 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds __u16 imtu; 3231da177e4SLinus Torvalds __u16 omtu; 3241da177e4SLinus Torvalds __u16 flush_to; 325c6b03cf9SMarcel Holtmann __u8 mode; 326f2fcfcd6SGustavo F. Padovan __u8 num_conf_req; 327f2fcfcd6SGustavo F. Padovan __u8 num_conf_rsp; 328f2fcfcd6SGustavo F. Padovan 329c6b03cf9SMarcel Holtmann __u8 fcs; 3302af6b9d5SMarcel Holtmann __u8 sec_level; 3312af6b9d5SMarcel Holtmann __u8 role_switch; 3322af6b9d5SMarcel Holtmann __u8 force_reliable; 333e702112fSAndrei Emeltchenko __u8 flushable; 3341da177e4SLinus Torvalds 3355dee9e7cSMarcel Holtmann __u8 conf_req[64]; 3365dee9e7cSMarcel Holtmann __u8 conf_len; 3371da177e4SLinus Torvalds __u8 conf_state; 338d5392c8fSGustavo F. Padovan __u16 conn_state; 3391da177e4SLinus Torvalds 3401c2acffbSGustavo F. Padovan __u8 next_tx_seq; 3411c2acffbSGustavo F. Padovan __u8 expected_ack_seq; 3421c2acffbSGustavo F. Padovan __u8 expected_tx_seq; 3438f17154fSGustavo F. Padovan __u8 buffer_seq; 3448f17154fSGustavo F. Padovan __u8 buffer_seq_srej; 345ef54fd93SGustavo F. Padovan __u8 srej_save_reqseq; 346d5392c8fSGustavo F. Padovan __u8 frames_sent; 3471c2acffbSGustavo F. Padovan __u8 unacked_frames; 348e90bac06SGustavo F. Padovan __u8 retry_count; 349803020c6SGustavo F. Padovan __u8 num_acked; 350c74e560cSGustavo F. Padovan __u16 sdu_len; 351c74e560cSGustavo F. Padovan __u16 partial_sdu_len; 352c74e560cSGustavo F. Padovan struct sk_buff *sdu; 3531c2acffbSGustavo F. Padovan 3541da177e4SLinus Torvalds __u8 ident; 3551da177e4SLinus Torvalds 35614b5aa71SGustavo F. Padovan __u8 tx_win; 35768d7f0ceSGustavo F. Padovan __u8 max_tx; 358f2fcfcd6SGustavo F. Padovan __u8 remote_tx_win; 359f2fcfcd6SGustavo F. Padovan __u8 remote_max_tx; 360f2fcfcd6SGustavo F. Padovan __u16 retrans_timeout; 361f2fcfcd6SGustavo F. Padovan __u16 monitor_timeout; 3621c762159SGustavo F. Padovan __u16 remote_mps; 3631c762159SGustavo F. Padovan __u16 mps; 364f2fcfcd6SGustavo F. Padovan 3658e036fc3SAl Viro __le16 sport; 3661da177e4SLinus Torvalds 367e90bac06SGustavo F. Padovan struct timer_list retrans_timer; 368e90bac06SGustavo F. Padovan struct timer_list monitor_timer; 369c1b4f43bSGustavo F. Padovan struct timer_list ack_timer; 3701c2acffbSGustavo F. Padovan struct sk_buff_head tx_queue; 3718f17154fSGustavo F. Padovan struct sk_buff_head srej_queue; 3721890d36bSGustavo F. Padovan struct sk_buff_head busy_queue; 3731890d36bSGustavo F. Padovan struct work_struct busy_work; 3748f17154fSGustavo F. Padovan struct srej_list srej_l; 3751da177e4SLinus Torvalds struct l2cap_conn *conn; 3761da177e4SLinus Torvalds struct sock *next_c; 3771da177e4SLinus Torvalds struct sock *prev_c; 3781da177e4SLinus Torvalds }; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds #define L2CAP_CONF_REQ_SENT 0x01 3811da177e4SLinus Torvalds #define L2CAP_CONF_INPUT_DONE 0x02 3821da177e4SLinus Torvalds #define L2CAP_CONF_OUTPUT_DONE 0x04 383f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MTU_DONE 0x08 384f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MODE_DONE 0x10 385f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_CONNECT_PEND 0x20 386fcc203c3SGustavo F. Padovan #define L2CAP_CONF_NO_FCS_RECV 0x40 387f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_STATE2_DEVICE 0x80 388861d6882SMarcel Holtmann 389f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 390f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 391f2fcfcd6SGustavo F. Padovan 392d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SAR_SDU 0x0001 393d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_SENT 0x0002 394d5392c8fSGustavo F. Padovan #define L2CAP_CONN_WAIT_F 0x0004 395d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_ACT 0x0008 396d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_PBIT 0x0010 397d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REMOTE_BUSY 0x0020 398d5392c8fSGustavo F. Padovan #define L2CAP_CONN_LOCAL_BUSY 0x0040 399d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REJ_ACT 0x0080 400d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_FBIT 0x0100 4011890d36bSGustavo F. Padovan #define L2CAP_CONN_RNR_SENT 0x0200 4021890d36bSGustavo F. Padovan #define L2CAP_CONN_SAR_RETRY 0x0400 403e90bac06SGustavo F. Padovan 404e90bac06SGustavo F. Padovan #define __mod_retrans_timer() mod_timer(&l2cap_pi(sk)->retrans_timer, \ 405e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_RETRANS_TO)); 406e90bac06SGustavo F. Padovan #define __mod_monitor_timer() mod_timer(&l2cap_pi(sk)->monitor_timer, \ 407e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_MONITOR_TO)); 408c1b4f43bSGustavo F. Padovan #define __mod_ack_timer() mod_timer(&l2cap_pi(sk)->ack_timer, \ 409c1b4f43bSGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 410c74e560cSGustavo F. Padovan 4111c2acffbSGustavo F. Padovan static inline int l2cap_tx_window_full(struct sock *sk) 4121c2acffbSGustavo F. Padovan { 4131c2acffbSGustavo F. Padovan struct l2cap_pinfo *pi = l2cap_pi(sk); 4141c2acffbSGustavo F. Padovan int sub; 4151c2acffbSGustavo F. Padovan 4161c2acffbSGustavo F. Padovan sub = (pi->next_tx_seq - pi->expected_ack_seq) % 64; 4171c2acffbSGustavo F. Padovan 4181c2acffbSGustavo F. Padovan if (sub < 0) 4191c2acffbSGustavo F. Padovan sub += 64; 4201c2acffbSGustavo F. Padovan 421a02cec21SEric Dumazet return sub == pi->remote_tx_win; 4221c2acffbSGustavo F. Padovan } 4231c2acffbSGustavo F. Padovan 424894718a6SAndrei Emeltchenko #define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1) 425894718a6SAndrei Emeltchenko #define __get_reqseq(ctrl) (((ctrl) & L2CAP_CTRL_REQSEQ) >> 8) 426894718a6SAndrei Emeltchenko #define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE)) 427894718a6SAndrei Emeltchenko #define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE) 428894718a6SAndrei Emeltchenko #define __is_sar_start(ctrl) (((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START) 4291da177e4SLinus Torvalds 430bb58f747SGustavo F. Padovan extern int disable_ertm; 431bb58f747SGustavo F. Padovan extern const struct proto_ops l2cap_sock_ops; 432bb58f747SGustavo F. Padovan extern struct bt_sock_list l2cap_sk_list; 433bb58f747SGustavo F. Padovan 434bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 435bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 436bb58f747SGustavo F. Padovan 43768983259SGustavo F. Padovan u8 l2cap_get_ident(struct l2cap_conn *conn); 43868983259SGustavo F. Padovan void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data); 43968983259SGustavo F. Padovan int l2cap_build_conf_req(struct sock *sk, void *data); 440dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 44168983259SGustavo F. Padovan 442fd83ccdbSGustavo F. Padovan struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len); 443fd83ccdbSGustavo F. Padovan struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len); 444fd83ccdbSGustavo F. Padovan struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg, size_t len, u16 control, u16 sdulen); 445fd83ccdbSGustavo F. Padovan int l2cap_sar_segment_sdu(struct sock *sk, struct msghdr *msg, size_t len); 446fd83ccdbSGustavo F. Padovan void l2cap_do_send(struct sock *sk, struct sk_buff *skb); 447fd83ccdbSGustavo F. Padovan void l2cap_streaming_send(struct sock *sk); 448fd83ccdbSGustavo F. Padovan int l2cap_ertm_send(struct sock *sk); 449fd83ccdbSGustavo F. Padovan 450bb58f747SGustavo F. Padovan void l2cap_sock_set_timer(struct sock *sk, long timeout); 451dcba0dbaSGustavo F. Padovan void l2cap_sock_clear_timer(struct sock *sk); 452bb58f747SGustavo F. Padovan void __l2cap_sock_close(struct sock *sk, int reason); 453bb58f747SGustavo F. Padovan void l2cap_sock_kill(struct sock *sk); 454bb58f747SGustavo F. Padovan void l2cap_sock_init(struct sock *sk, struct sock *parent); 455bb58f747SGustavo F. Padovan struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, 456bb58f747SGustavo F. Padovan int proto, gfp_t prio); 4576de0702bSGustavo F. Padovan void l2cap_send_disconn_req(struct l2cap_conn *conn, struct sock *sk, int err); 4586de0702bSGustavo F. Padovan void l2cap_chan_del(struct sock *sk, int err); 4594e34c50bSGustavo F. Padovan int l2cap_do_connect(struct sock *sk); 460bb58f747SGustavo F. Padovan 4611da177e4SLinus Torvalds #endif /* __L2CAP_H */ 462