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 1638db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 1648db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 1658db4dc46SGustavo F. Padovan 1661da177e4SLinus Torvalds /* connect result */ 1671da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 1681da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 1691da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 1701da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 1711da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds /* connect status */ 1741da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 1751da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 1761da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds struct l2cap_conf_req { 1798e036fc3SAl Viro __le16 dcid; 1808e036fc3SAl Viro __le16 flags; 1811da177e4SLinus Torvalds __u8 data[0]; 18266c853ccSGustavo F. Padovan } __packed; 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds struct l2cap_conf_rsp { 1858e036fc3SAl Viro __le16 scid; 1868e036fc3SAl Viro __le16 flags; 1878e036fc3SAl Viro __le16 result; 1881da177e4SLinus Torvalds __u8 data[0]; 18966c853ccSGustavo F. Padovan } __packed; 1901da177e4SLinus Torvalds 1915dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 1925dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 1935dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 1945dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds struct l2cap_conf_opt { 1971da177e4SLinus Torvalds __u8 type; 1981da177e4SLinus Torvalds __u8 len; 1991da177e4SLinus Torvalds __u8 val[0]; 20066c853ccSGustavo F. Padovan } __packed; 2011da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2021da177e4SLinus Torvalds 203589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 20447ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 205589d2746SGustavo F. Padovan 2061da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2071da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 2081da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 2091da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 21047ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 2131da177e4SLinus Torvalds 2146464f35fSMarcel Holtmann struct l2cap_conf_rfc { 2156464f35fSMarcel Holtmann __u8 mode; 2166464f35fSMarcel Holtmann __u8 txwin_size; 2176464f35fSMarcel Holtmann __u8 max_transmit; 2186464f35fSMarcel Holtmann __le16 retrans_timeout; 2196464f35fSMarcel Holtmann __le16 monitor_timeout; 2206464f35fSMarcel Holtmann __le16 max_pdu_size; 22166c853ccSGustavo F. Padovan } __packed; 2226464f35fSMarcel Holtmann 2236464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 2246464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 2256464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 22647ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 227c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 2286464f35fSMarcel Holtmann 2291da177e4SLinus Torvalds struct l2cap_disconn_req { 2308e036fc3SAl Viro __le16 dcid; 2318e036fc3SAl Viro __le16 scid; 23266c853ccSGustavo F. Padovan } __packed; 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds struct l2cap_disconn_rsp { 2358e036fc3SAl Viro __le16 dcid; 2368e036fc3SAl Viro __le16 scid; 23766c853ccSGustavo F. Padovan } __packed; 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds struct l2cap_info_req { 2408e036fc3SAl Viro __le16 type; 24166c853ccSGustavo F. Padovan } __packed; 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds struct l2cap_info_rsp { 2448e036fc3SAl Viro __le16 type; 2458e036fc3SAl Viro __le16 result; 2461da177e4SLinus Torvalds __u8 data[0]; 24766c853ccSGustavo F. Padovan } __packed; 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds /* info type */ 2501da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 2511da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 252e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds /* info result */ 2551da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 2561da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds /* ----- L2CAP connections ----- */ 2591da177e4SLinus Torvalds struct l2cap_chan_list { 2601da177e4SLinus Torvalds struct sock *head; 2611da177e4SLinus Torvalds rwlock_t lock; 2621da177e4SLinus Torvalds long num; 2631da177e4SLinus Torvalds }; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds struct l2cap_conn { 2661da177e4SLinus Torvalds struct hci_conn *hcon; 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds bdaddr_t *dst; 2691da177e4SLinus Torvalds bdaddr_t *src; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds unsigned int mtu; 2721da177e4SLinus Torvalds 2734e8402a3SMarcel Holtmann __u32 feat_mask; 2744e8402a3SMarcel Holtmann 2754e8402a3SMarcel Holtmann __u8 info_state; 2764e8402a3SMarcel Holtmann __u8 info_ident; 2774e8402a3SMarcel Holtmann 2784e8402a3SMarcel Holtmann struct timer_list info_timer; 2794e8402a3SMarcel Holtmann 2801da177e4SLinus Torvalds spinlock_t lock; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds struct sk_buff *rx_skb; 2831da177e4SLinus Torvalds __u32 rx_len; 2841da177e4SLinus Torvalds __u8 rx_ident; 2851da177e4SLinus Torvalds __u8 tx_ident; 2861da177e4SLinus Torvalds 2872950f21aSMarcel Holtmann __u8 disc_reason; 2882950f21aSMarcel Holtmann 2891da177e4SLinus Torvalds struct l2cap_chan_list chan_list; 2901da177e4SLinus Torvalds }; 2911da177e4SLinus Torvalds 292cf6c2c0bSGustavo F. Padovan struct sock_del_list { 293cf6c2c0bSGustavo F. Padovan struct sock *sk; 294cf6c2c0bSGustavo F. Padovan struct list_head list; 295cf6c2c0bSGustavo F. Padovan }; 296cf6c2c0bSGustavo F. Padovan 2974e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 298984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 299984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 3004e8402a3SMarcel Holtmann 3011da177e4SLinus Torvalds /* ----- L2CAP channel and socket info ----- */ 3021da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 3031c2acffbSGustavo F. Padovan #define TX_QUEUE(sk) (&l2cap_pi(sk)->tx_queue) 3048f17154fSGustavo F. Padovan #define SREJ_QUEUE(sk) (&l2cap_pi(sk)->srej_queue) 3051890d36bSGustavo F. Padovan #define BUSY_QUEUE(sk) (&l2cap_pi(sk)->busy_queue) 3068f17154fSGustavo F. Padovan #define SREJ_LIST(sk) (&l2cap_pi(sk)->srej_l.list) 3078f17154fSGustavo F. Padovan 3088f17154fSGustavo F. Padovan struct srej_list { 3098f17154fSGustavo F. Padovan __u8 tx_seq; 3108f17154fSGustavo F. Padovan struct list_head list; 3118f17154fSGustavo F. Padovan }; 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds struct l2cap_pinfo { 3141da177e4SLinus Torvalds struct bt_sock bt; 3158e036fc3SAl Viro __le16 psm; 3161da177e4SLinus Torvalds __u16 dcid; 3171da177e4SLinus Torvalds __u16 scid; 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds __u16 imtu; 3201da177e4SLinus Torvalds __u16 omtu; 3211da177e4SLinus Torvalds __u16 flush_to; 322c6b03cf9SMarcel Holtmann __u8 mode; 323f2fcfcd6SGustavo F. Padovan __u8 num_conf_req; 324f2fcfcd6SGustavo F. Padovan __u8 num_conf_rsp; 325f2fcfcd6SGustavo F. Padovan 326c6b03cf9SMarcel Holtmann __u8 fcs; 3272af6b9d5SMarcel Holtmann __u8 sec_level; 3282af6b9d5SMarcel Holtmann __u8 role_switch; 3292af6b9d5SMarcel Holtmann __u8 force_reliable; 330e702112fSAndrei Emeltchenko __u8 flushable; 3311da177e4SLinus Torvalds 3325dee9e7cSMarcel Holtmann __u8 conf_req[64]; 3335dee9e7cSMarcel Holtmann __u8 conf_len; 3341da177e4SLinus Torvalds __u8 conf_state; 335d5392c8fSGustavo F. Padovan __u16 conn_state; 3361da177e4SLinus Torvalds 3371c2acffbSGustavo F. Padovan __u8 next_tx_seq; 3381c2acffbSGustavo F. Padovan __u8 expected_ack_seq; 3391c2acffbSGustavo F. Padovan __u8 expected_tx_seq; 3408f17154fSGustavo F. Padovan __u8 buffer_seq; 3418f17154fSGustavo F. Padovan __u8 buffer_seq_srej; 342ef54fd93SGustavo F. Padovan __u8 srej_save_reqseq; 343d5392c8fSGustavo F. Padovan __u8 frames_sent; 3441c2acffbSGustavo F. Padovan __u8 unacked_frames; 345e90bac06SGustavo F. Padovan __u8 retry_count; 346803020c6SGustavo F. Padovan __u8 num_acked; 347c74e560cSGustavo F. Padovan __u16 sdu_len; 348c74e560cSGustavo F. Padovan __u16 partial_sdu_len; 349c74e560cSGustavo F. Padovan struct sk_buff *sdu; 3501c2acffbSGustavo F. Padovan 3511da177e4SLinus Torvalds __u8 ident; 3521da177e4SLinus Torvalds 35314b5aa71SGustavo F. Padovan __u8 tx_win; 35468d7f0ceSGustavo F. Padovan __u8 max_tx; 355f2fcfcd6SGustavo F. Padovan __u8 remote_tx_win; 356f2fcfcd6SGustavo F. Padovan __u8 remote_max_tx; 357f2fcfcd6SGustavo F. Padovan __u16 retrans_timeout; 358f2fcfcd6SGustavo F. Padovan __u16 monitor_timeout; 3591c762159SGustavo F. Padovan __u16 remote_mps; 3601c762159SGustavo F. Padovan __u16 mps; 361f2fcfcd6SGustavo F. Padovan 3628e036fc3SAl Viro __le16 sport; 3631da177e4SLinus Torvalds 364e90bac06SGustavo F. Padovan struct timer_list retrans_timer; 365e90bac06SGustavo F. Padovan struct timer_list monitor_timer; 366c1b4f43bSGustavo F. Padovan struct timer_list ack_timer; 3671c2acffbSGustavo F. Padovan struct sk_buff_head tx_queue; 3688f17154fSGustavo F. Padovan struct sk_buff_head srej_queue; 3691890d36bSGustavo F. Padovan struct sk_buff_head busy_queue; 3701890d36bSGustavo F. Padovan struct work_struct busy_work; 3718f17154fSGustavo F. Padovan struct srej_list srej_l; 3721da177e4SLinus Torvalds struct l2cap_conn *conn; 3731da177e4SLinus Torvalds struct sock *next_c; 3741da177e4SLinus Torvalds struct sock *prev_c; 3751da177e4SLinus Torvalds }; 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds #define L2CAP_CONF_REQ_SENT 0x01 3781da177e4SLinus Torvalds #define L2CAP_CONF_INPUT_DONE 0x02 3791da177e4SLinus Torvalds #define L2CAP_CONF_OUTPUT_DONE 0x04 380f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MTU_DONE 0x08 381f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MODE_DONE 0x10 382f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_CONNECT_PEND 0x20 383fcc203c3SGustavo F. Padovan #define L2CAP_CONF_NO_FCS_RECV 0x40 384f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_STATE2_DEVICE 0x80 385861d6882SMarcel Holtmann 386f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 387f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 388f2fcfcd6SGustavo F. Padovan 389d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SAR_SDU 0x0001 390d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_SENT 0x0002 391d5392c8fSGustavo F. Padovan #define L2CAP_CONN_WAIT_F 0x0004 392d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_ACT 0x0008 393d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_PBIT 0x0010 394d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REMOTE_BUSY 0x0020 395d5392c8fSGustavo F. Padovan #define L2CAP_CONN_LOCAL_BUSY 0x0040 396d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REJ_ACT 0x0080 397d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_FBIT 0x0100 3981890d36bSGustavo F. Padovan #define L2CAP_CONN_RNR_SENT 0x0200 3991890d36bSGustavo F. Padovan #define L2CAP_CONN_SAR_RETRY 0x0400 400e90bac06SGustavo F. Padovan 401e90bac06SGustavo F. Padovan #define __mod_retrans_timer() mod_timer(&l2cap_pi(sk)->retrans_timer, \ 402e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_RETRANS_TO)); 403e90bac06SGustavo F. Padovan #define __mod_monitor_timer() mod_timer(&l2cap_pi(sk)->monitor_timer, \ 404e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_MONITOR_TO)); 405c1b4f43bSGustavo F. Padovan #define __mod_ack_timer() mod_timer(&l2cap_pi(sk)->ack_timer, \ 406c1b4f43bSGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 407c74e560cSGustavo F. Padovan 4081c2acffbSGustavo F. Padovan static inline int l2cap_tx_window_full(struct sock *sk) 4091c2acffbSGustavo F. Padovan { 4101c2acffbSGustavo F. Padovan struct l2cap_pinfo *pi = l2cap_pi(sk); 4111c2acffbSGustavo F. Padovan int sub; 4121c2acffbSGustavo F. Padovan 4131c2acffbSGustavo F. Padovan sub = (pi->next_tx_seq - pi->expected_ack_seq) % 64; 4141c2acffbSGustavo F. Padovan 4151c2acffbSGustavo F. Padovan if (sub < 0) 4161c2acffbSGustavo F. Padovan sub += 64; 4171c2acffbSGustavo F. Padovan 418a02cec21SEric Dumazet return sub == pi->remote_tx_win; 4191c2acffbSGustavo F. Padovan } 4201c2acffbSGustavo F. Padovan 421894718a6SAndrei Emeltchenko #define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1) 422894718a6SAndrei Emeltchenko #define __get_reqseq(ctrl) (((ctrl) & L2CAP_CTRL_REQSEQ) >> 8) 423894718a6SAndrei Emeltchenko #define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE)) 424894718a6SAndrei Emeltchenko #define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE) 425894718a6SAndrei Emeltchenko #define __is_sar_start(ctrl) (((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START) 4261da177e4SLinus Torvalds 427*bb58f747SGustavo F. Padovan extern int disable_ertm; 428*bb58f747SGustavo F. Padovan extern const struct proto_ops l2cap_sock_ops; 429*bb58f747SGustavo F. Padovan extern struct bt_sock_list l2cap_sk_list; 430*bb58f747SGustavo F. Padovan 431*bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 432*bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 433*bb58f747SGustavo F. Padovan 434*bb58f747SGustavo F. Padovan void l2cap_sock_set_timer(struct sock *sk, long timeout); 435*bb58f747SGustavo F. Padovan void __l2cap_sock_close(struct sock *sk, int reason); 436*bb58f747SGustavo F. Padovan void l2cap_sock_kill(struct sock *sk); 437*bb58f747SGustavo F. Padovan void l2cap_sock_init(struct sock *sk, struct sock *parent); 438*bb58f747SGustavo F. Padovan struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, 439*bb58f747SGustavo F. Padovan int proto, gfp_t prio); 440*bb58f747SGustavo F. Padovan 441*bb58f747SGustavo F. Padovan 4421da177e4SLinus Torvalds void l2cap_load(void); 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds #endif /* __L2CAP_H */ 445