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 41b62f328bSVille Tervo #define L2CAP_LE_DEFAULT_MTU 23 421da177e4SLinus Torvalds 434e8402a3SMarcel Holtmann #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */ 444e8402a3SMarcel Holtmann #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */ 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds /* L2CAP socket address */ 471da177e4SLinus Torvalds struct sockaddr_l2 { 481da177e4SLinus Torvalds sa_family_t l2_family; 498e036fc3SAl Viro __le16 l2_psm; 501da177e4SLinus Torvalds bdaddr_t l2_bdaddr; 51f29972deSMarcel Holtmann __le16 l2_cid; 521da177e4SLinus Torvalds }; 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds /* L2CAP socket options */ 551da177e4SLinus Torvalds #define L2CAP_OPTIONS 0x01 561da177e4SLinus Torvalds struct l2cap_options { 571da177e4SLinus Torvalds __u16 omtu; 581da177e4SLinus Torvalds __u16 imtu; 591da177e4SLinus Torvalds __u16 flush_to; 601da177e4SLinus Torvalds __u8 mode; 61fcc203c3SGustavo F. Padovan __u8 fcs; 6268d7f0ceSGustavo F. Padovan __u8 max_tx; 6314b5aa71SGustavo F. Padovan __u16 txwin_size; 641da177e4SLinus Torvalds }; 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds #define L2CAP_CONNINFO 0x02 671da177e4SLinus Torvalds struct l2cap_conninfo { 681da177e4SLinus Torvalds __u16 hci_handle; 691da177e4SLinus Torvalds __u8 dev_class[3]; 701da177e4SLinus Torvalds }; 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds #define L2CAP_LM 0x03 731da177e4SLinus Torvalds #define L2CAP_LM_MASTER 0x0001 741da177e4SLinus Torvalds #define L2CAP_LM_AUTH 0x0002 751da177e4SLinus Torvalds #define L2CAP_LM_ENCRYPT 0x0004 761da177e4SLinus Torvalds #define L2CAP_LM_TRUSTED 0x0008 771da177e4SLinus Torvalds #define L2CAP_LM_RELIABLE 0x0010 781da177e4SLinus Torvalds #define L2CAP_LM_SECURE 0x0020 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds /* L2CAP command codes */ 811da177e4SLinus Torvalds #define L2CAP_COMMAND_REJ 0x01 821da177e4SLinus Torvalds #define L2CAP_CONN_REQ 0x02 831da177e4SLinus Torvalds #define L2CAP_CONN_RSP 0x03 841da177e4SLinus Torvalds #define L2CAP_CONF_REQ 0x04 851da177e4SLinus Torvalds #define L2CAP_CONF_RSP 0x05 861da177e4SLinus Torvalds #define L2CAP_DISCONN_REQ 0x06 871da177e4SLinus Torvalds #define L2CAP_DISCONN_RSP 0x07 881da177e4SLinus Torvalds #define L2CAP_ECHO_REQ 0x08 891da177e4SLinus Torvalds #define L2CAP_ECHO_RSP 0x09 901da177e4SLinus Torvalds #define L2CAP_INFO_REQ 0x0a 911da177e4SLinus Torvalds #define L2CAP_INFO_RSP 0x0b 923300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_REQ 0x12 933300d9a9SClaudio Takahasi #define L2CAP_CONN_PARAM_UPDATE_RSP 0x13 941da177e4SLinus Torvalds 9547ec1dcdSMarcel Holtmann /* L2CAP feature mask */ 9647ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FLOWCTL 0x00000001 9747ec1dcdSMarcel Holtmann #define L2CAP_FEAT_RETRANS 0x00000002 9847ec1dcdSMarcel Holtmann #define L2CAP_FEAT_ERTM 0x00000008 9947ec1dcdSMarcel Holtmann #define L2CAP_FEAT_STREAMING 0x00000010 10047ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FCS 0x00000020 10147ec1dcdSMarcel Holtmann #define L2CAP_FEAT_FIXED_CHAN 0x00000080 10247ec1dcdSMarcel Holtmann 10347ec1dcdSMarcel Holtmann /* L2CAP checksum option */ 10447ec1dcdSMarcel Holtmann #define L2CAP_FCS_NONE 0x00 10547ec1dcdSMarcel Holtmann #define L2CAP_FCS_CRC16 0x01 10647ec1dcdSMarcel Holtmann 1071c2acffbSGustavo F. Padovan /* L2CAP Control Field bit masks */ 1081c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SAR 0xC000 1091c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ 0x3F00 1101c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ 0x007E 1111c2acffbSGustavo F. Padovan #define L2CAP_CTRL_RETRANS 0x0080 1121c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FINAL 0x0080 1131c2acffbSGustavo F. Padovan #define L2CAP_CTRL_POLL 0x0010 1141c2acffbSGustavo F. Padovan #define L2CAP_CTRL_SUPERVISE 0x000C 1151c2acffbSGustavo F. Padovan #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 1161c2acffbSGustavo F. Padovan 1171c2acffbSGustavo F. Padovan #define L2CAP_CTRL_TXSEQ_SHIFT 1 1181c2acffbSGustavo F. Padovan #define L2CAP_CTRL_REQSEQ_SHIFT 8 1198f17154fSGustavo F. Padovan #define L2CAP_CTRL_SAR_SHIFT 14 1201c2acffbSGustavo F. Padovan 1211c2acffbSGustavo F. Padovan /* L2CAP Supervisory Function */ 1221c2acffbSGustavo F. Padovan #define L2CAP_SUPER_RCV_READY 0x0000 1231c2acffbSGustavo F. Padovan #define L2CAP_SUPER_REJECT 0x0004 1241c2acffbSGustavo F. Padovan #define L2CAP_SUPER_RCV_NOT_READY 0x0008 1251c2acffbSGustavo F. Padovan #define L2CAP_SUPER_SELECT_REJECT 0x000C 1261c2acffbSGustavo F. Padovan 1271c2acffbSGustavo F. Padovan /* L2CAP Segmentation and Reassembly */ 1281c2acffbSGustavo F. Padovan #define L2CAP_SDU_UNSEGMENTED 0x0000 1291c2acffbSGustavo F. Padovan #define L2CAP_SDU_START 0x4000 1301c2acffbSGustavo F. Padovan #define L2CAP_SDU_END 0x8000 1311c2acffbSGustavo F. Padovan #define L2CAP_SDU_CONTINUE 0xC000 1321c2acffbSGustavo F. Padovan 1331da177e4SLinus Torvalds /* L2CAP structures */ 1341da177e4SLinus Torvalds struct l2cap_hdr { 1358e036fc3SAl Viro __le16 len; 1368e036fc3SAl Viro __le16 cid; 13766c853ccSGustavo F. Padovan } __packed; 1381da177e4SLinus Torvalds #define L2CAP_HDR_SIZE 4 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds struct l2cap_cmd_hdr { 1411da177e4SLinus Torvalds __u8 code; 1421da177e4SLinus Torvalds __u8 ident; 1438e036fc3SAl Viro __le16 len; 14466c853ccSGustavo F. Padovan } __packed; 1451da177e4SLinus Torvalds #define L2CAP_CMD_HDR_SIZE 4 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds struct l2cap_cmd_rej { 1488e036fc3SAl Viro __le16 reason; 14966c853ccSGustavo F. Padovan } __packed; 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds struct l2cap_conn_req { 1528e036fc3SAl Viro __le16 psm; 1538e036fc3SAl Viro __le16 scid; 15466c853ccSGustavo F. Padovan } __packed; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds struct l2cap_conn_rsp { 1578e036fc3SAl Viro __le16 dcid; 1588e036fc3SAl Viro __le16 scid; 1598e036fc3SAl Viro __le16 result; 1608e036fc3SAl Viro __le16 status; 16166c853ccSGustavo F. Padovan } __packed; 1621da177e4SLinus Torvalds 1638db4dc46SGustavo F. Padovan /* channel indentifier */ 1648db4dc46SGustavo F. Padovan #define L2CAP_CID_SIGNALING 0x0001 1658db4dc46SGustavo F. Padovan #define L2CAP_CID_CONN_LESS 0x0002 166acd7d370SVille Tervo #define L2CAP_CID_LE_DATA 0x0004 167acd7d370SVille Tervo #define L2CAP_CID_LE_SIGNALING 0x0005 168acd7d370SVille Tervo #define L2CAP_CID_SMP 0x0006 1698db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_START 0x0040 1708db4dc46SGustavo F. Padovan #define L2CAP_CID_DYN_END 0xffff 1718db4dc46SGustavo F. Padovan 1721da177e4SLinus Torvalds /* connect result */ 1731da177e4SLinus Torvalds #define L2CAP_CR_SUCCESS 0x0000 1741da177e4SLinus Torvalds #define L2CAP_CR_PEND 0x0001 1751da177e4SLinus Torvalds #define L2CAP_CR_BAD_PSM 0x0002 1761da177e4SLinus Torvalds #define L2CAP_CR_SEC_BLOCK 0x0003 1771da177e4SLinus Torvalds #define L2CAP_CR_NO_MEM 0x0004 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds /* connect status */ 1801da177e4SLinus Torvalds #define L2CAP_CS_NO_INFO 0x0000 1811da177e4SLinus Torvalds #define L2CAP_CS_AUTHEN_PEND 0x0001 1821da177e4SLinus Torvalds #define L2CAP_CS_AUTHOR_PEND 0x0002 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds struct l2cap_conf_req { 1858e036fc3SAl Viro __le16 dcid; 1868e036fc3SAl Viro __le16 flags; 1871da177e4SLinus Torvalds __u8 data[0]; 18866c853ccSGustavo F. Padovan } __packed; 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds struct l2cap_conf_rsp { 1918e036fc3SAl Viro __le16 scid; 1928e036fc3SAl Viro __le16 flags; 1938e036fc3SAl Viro __le16 result; 1941da177e4SLinus Torvalds __u8 data[0]; 19566c853ccSGustavo F. Padovan } __packed; 1961da177e4SLinus Torvalds 1975dee9e7cSMarcel Holtmann #define L2CAP_CONF_SUCCESS 0x0000 1985dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNACCEPT 0x0001 1995dee9e7cSMarcel Holtmann #define L2CAP_CONF_REJECT 0x0002 2005dee9e7cSMarcel Holtmann #define L2CAP_CONF_UNKNOWN 0x0003 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds struct l2cap_conf_opt { 2031da177e4SLinus Torvalds __u8 type; 2041da177e4SLinus Torvalds __u8 len; 2051da177e4SLinus Torvalds __u8 val[0]; 20666c853ccSGustavo F. Padovan } __packed; 2071da177e4SLinus Torvalds #define L2CAP_CONF_OPT_SIZE 2 2081da177e4SLinus Torvalds 209589d2746SGustavo F. Padovan #define L2CAP_CONF_HINT 0x80 21047ec1dcdSMarcel Holtmann #define L2CAP_CONF_MASK 0x7f 211589d2746SGustavo F. Padovan 2121da177e4SLinus Torvalds #define L2CAP_CONF_MTU 0x01 2131da177e4SLinus Torvalds #define L2CAP_CONF_FLUSH_TO 0x02 2141da177e4SLinus Torvalds #define L2CAP_CONF_QOS 0x03 2151da177e4SLinus Torvalds #define L2CAP_CONF_RFC 0x04 21647ec1dcdSMarcel Holtmann #define L2CAP_CONF_FCS 0x05 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds #define L2CAP_CONF_MAX_SIZE 22 2191da177e4SLinus Torvalds 2206464f35fSMarcel Holtmann struct l2cap_conf_rfc { 2216464f35fSMarcel Holtmann __u8 mode; 2226464f35fSMarcel Holtmann __u8 txwin_size; 2236464f35fSMarcel Holtmann __u8 max_transmit; 2246464f35fSMarcel Holtmann __le16 retrans_timeout; 2256464f35fSMarcel Holtmann __le16 monitor_timeout; 2266464f35fSMarcel Holtmann __le16 max_pdu_size; 22766c853ccSGustavo F. Padovan } __packed; 2286464f35fSMarcel Holtmann 2296464f35fSMarcel Holtmann #define L2CAP_MODE_BASIC 0x00 2306464f35fSMarcel Holtmann #define L2CAP_MODE_RETRANS 0x01 2316464f35fSMarcel Holtmann #define L2CAP_MODE_FLOWCTL 0x02 23247ec1dcdSMarcel Holtmann #define L2CAP_MODE_ERTM 0x03 233c6b03cf9SMarcel Holtmann #define L2CAP_MODE_STREAMING 0x04 2346464f35fSMarcel Holtmann 2351da177e4SLinus Torvalds struct l2cap_disconn_req { 2368e036fc3SAl Viro __le16 dcid; 2378e036fc3SAl Viro __le16 scid; 23866c853ccSGustavo F. Padovan } __packed; 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds struct l2cap_disconn_rsp { 2418e036fc3SAl Viro __le16 dcid; 2428e036fc3SAl Viro __le16 scid; 24366c853ccSGustavo F. Padovan } __packed; 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds struct l2cap_info_req { 2468e036fc3SAl Viro __le16 type; 24766c853ccSGustavo F. Padovan } __packed; 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds struct l2cap_info_rsp { 2508e036fc3SAl Viro __le16 type; 2518e036fc3SAl Viro __le16 result; 2521da177e4SLinus Torvalds __u8 data[0]; 25366c853ccSGustavo F. Padovan } __packed; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds /* info type */ 2561da177e4SLinus Torvalds #define L2CAP_IT_CL_MTU 0x0001 2571da177e4SLinus Torvalds #define L2CAP_IT_FEAT_MASK 0x0002 258e1027a7cSMarcel Holtmann #define L2CAP_IT_FIXED_CHAN 0x0003 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds /* info result */ 2611da177e4SLinus Torvalds #define L2CAP_IR_SUCCESS 0x0000 2621da177e4SLinus Torvalds #define L2CAP_IR_NOTSUPP 0x0001 2631da177e4SLinus Torvalds 264de73115aSClaudio Takahasi struct l2cap_conn_param_update_req { 265de73115aSClaudio Takahasi __le16 min; 266de73115aSClaudio Takahasi __le16 max; 267de73115aSClaudio Takahasi __le16 latency; 268de73115aSClaudio Takahasi __le16 to_multiplier; 269de73115aSClaudio Takahasi } __packed; 270de73115aSClaudio Takahasi 271de73115aSClaudio Takahasi struct l2cap_conn_param_update_rsp { 272de73115aSClaudio Takahasi __le16 result; 273de73115aSClaudio Takahasi } __packed; 274de73115aSClaudio Takahasi 275de73115aSClaudio Takahasi /* Connection Parameters result */ 276de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 277de73115aSClaudio Takahasi #define L2CAP_CONN_PARAM_REJECTED 0x0001 278de73115aSClaudio Takahasi 27948454079SGustavo F. Padovan /* ----- L2CAP channels and connections ----- */ 28048454079SGustavo F. Padovan struct l2cap_chan { 28148454079SGustavo F. Padovan struct sock *sk; 282fc7f8a7eSGustavo F. Padovan __u8 ident; 283fc7f8a7eSGustavo F. Padovan 28473ffa904SGustavo F. Padovan __u8 conf_req[64]; 28573ffa904SGustavo F. Padovan __u8 conf_len; 28673ffa904SGustavo F. Padovan __u8 num_conf_req; 28773ffa904SGustavo F. Padovan __u8 num_conf_rsp; 28873ffa904SGustavo F. Padovan 289525cd185SGustavo F. Padovan __u16 conn_state; 290525cd185SGustavo F. Padovan 29142e5c802SGustavo F. Padovan __u8 next_tx_seq; 29242e5c802SGustavo F. Padovan __u8 expected_ack_seq; 29342e5c802SGustavo F. Padovan __u8 expected_tx_seq; 29442e5c802SGustavo F. Padovan __u8 buffer_seq; 29542e5c802SGustavo F. Padovan __u8 buffer_seq_srej; 2966a026610SGustavo F. Padovan __u8 srej_save_reqseq; 2976a026610SGustavo F. Padovan __u8 frames_sent; 2986a026610SGustavo F. Padovan __u8 unacked_frames; 2996a026610SGustavo F. Padovan __u8 retry_count; 3006a026610SGustavo F. Padovan __u8 num_acked; 3016f61fd47SGustavo F. Padovan __u16 sdu_len; 3026f61fd47SGustavo F. Padovan __u16 partial_sdu_len; 3036f61fd47SGustavo F. Padovan struct sk_buff *sdu; 3046f61fd47SGustavo F. Padovan 3052c03a7a4SGustavo F. Padovan __u8 remote_tx_win; 3062c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 3072c03a7a4SGustavo F. Padovan __u16 remote_mps; 30842e5c802SGustavo F. Padovan 309*e92c8e70SGustavo F. Padovan struct timer_list retrans_timer; 310*e92c8e70SGustavo F. Padovan struct timer_list monitor_timer; 311*e92c8e70SGustavo F. Padovan struct timer_list ack_timer; 312*e92c8e70SGustavo F. Padovan 313baa7e1faSGustavo F. Padovan struct list_head list; 3141da177e4SLinus Torvalds }; 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds struct l2cap_conn { 3171da177e4SLinus Torvalds struct hci_conn *hcon; 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds bdaddr_t *dst; 3201da177e4SLinus Torvalds bdaddr_t *src; 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds unsigned int mtu; 3231da177e4SLinus Torvalds 3244e8402a3SMarcel Holtmann __u32 feat_mask; 3254e8402a3SMarcel Holtmann 3264e8402a3SMarcel Holtmann __u8 info_state; 3274e8402a3SMarcel Holtmann __u8 info_ident; 3284e8402a3SMarcel Holtmann 3294e8402a3SMarcel Holtmann struct timer_list info_timer; 3304e8402a3SMarcel Holtmann 3311da177e4SLinus Torvalds spinlock_t lock; 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds struct sk_buff *rx_skb; 3341da177e4SLinus Torvalds __u32 rx_len; 3351da177e4SLinus Torvalds __u8 tx_ident; 3361da177e4SLinus Torvalds 3372950f21aSMarcel Holtmann __u8 disc_reason; 3382950f21aSMarcel Holtmann 339baa7e1faSGustavo F. Padovan struct list_head chan_l; 340baa7e1faSGustavo F. Padovan rwlock_t chan_lock; 3411da177e4SLinus Torvalds }; 3421da177e4SLinus Torvalds 3434e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 344984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 345984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 3464e8402a3SMarcel Holtmann 34748454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 3481da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 3491c2acffbSGustavo F. Padovan #define TX_QUEUE(sk) (&l2cap_pi(sk)->tx_queue) 3508f17154fSGustavo F. Padovan #define SREJ_QUEUE(sk) (&l2cap_pi(sk)->srej_queue) 3511890d36bSGustavo F. Padovan #define BUSY_QUEUE(sk) (&l2cap_pi(sk)->busy_queue) 3528f17154fSGustavo F. Padovan #define SREJ_LIST(sk) (&l2cap_pi(sk)->srej_l.list) 3538f17154fSGustavo F. Padovan 3548f17154fSGustavo F. Padovan struct srej_list { 3558f17154fSGustavo F. Padovan __u8 tx_seq; 3568f17154fSGustavo F. Padovan struct list_head list; 3578f17154fSGustavo F. Padovan }; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds struct l2cap_pinfo { 3601da177e4SLinus Torvalds struct bt_sock bt; 3618e036fc3SAl Viro __le16 psm; 3621da177e4SLinus Torvalds __u16 dcid; 3631da177e4SLinus Torvalds __u16 scid; 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds __u16 imtu; 3661da177e4SLinus Torvalds __u16 omtu; 3671da177e4SLinus Torvalds __u16 flush_to; 368c6b03cf9SMarcel Holtmann __u8 mode; 369f2fcfcd6SGustavo F. Padovan 370c6b03cf9SMarcel Holtmann __u8 fcs; 3712af6b9d5SMarcel Holtmann __u8 sec_level; 3722af6b9d5SMarcel Holtmann __u8 role_switch; 3732af6b9d5SMarcel Holtmann __u8 force_reliable; 374e702112fSAndrei Emeltchenko __u8 flushable; 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds __u8 conf_state; 3771da177e4SLinus Torvalds 37814b5aa71SGustavo F. Padovan __u8 tx_win; 37968d7f0ceSGustavo F. Padovan __u8 max_tx; 380f2fcfcd6SGustavo F. Padovan __u16 retrans_timeout; 381f2fcfcd6SGustavo F. Padovan __u16 monitor_timeout; 3821c762159SGustavo F. Padovan __u16 mps; 383f2fcfcd6SGustavo F. Padovan 3848e036fc3SAl Viro __le16 sport; 3851da177e4SLinus Torvalds 3861c2acffbSGustavo F. Padovan struct sk_buff_head tx_queue; 3878f17154fSGustavo F. Padovan struct sk_buff_head srej_queue; 3881890d36bSGustavo F. Padovan struct sk_buff_head busy_queue; 3891890d36bSGustavo F. Padovan struct work_struct busy_work; 3908f17154fSGustavo F. Padovan struct srej_list srej_l; 3911da177e4SLinus Torvalds struct l2cap_conn *conn; 39248454079SGustavo F. Padovan struct l2cap_chan *chan; 3931da177e4SLinus Torvalds }; 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds #define L2CAP_CONF_REQ_SENT 0x01 3961da177e4SLinus Torvalds #define L2CAP_CONF_INPUT_DONE 0x02 3971da177e4SLinus Torvalds #define L2CAP_CONF_OUTPUT_DONE 0x04 398f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MTU_DONE 0x08 399f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MODE_DONE 0x10 400f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_CONNECT_PEND 0x20 401fcc203c3SGustavo F. Padovan #define L2CAP_CONF_NO_FCS_RECV 0x40 402f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_STATE2_DEVICE 0x80 403861d6882SMarcel Holtmann 404f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 405f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 406f2fcfcd6SGustavo F. Padovan 407d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SAR_SDU 0x0001 408d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_SENT 0x0002 409d5392c8fSGustavo F. Padovan #define L2CAP_CONN_WAIT_F 0x0004 410d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_ACT 0x0008 411d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_PBIT 0x0010 412d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REMOTE_BUSY 0x0020 413d5392c8fSGustavo F. Padovan #define L2CAP_CONN_LOCAL_BUSY 0x0040 414d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REJ_ACT 0x0080 415d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_FBIT 0x0100 4161890d36bSGustavo F. Padovan #define L2CAP_CONN_RNR_SENT 0x0200 4171890d36bSGustavo F. Padovan #define L2CAP_CONN_SAR_RETRY 0x0400 418e90bac06SGustavo F. Padovan 419*e92c8e70SGustavo F. Padovan #define __mod_retrans_timer() mod_timer(&chan->retrans_timer, \ 420e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_RETRANS_TO)); 421*e92c8e70SGustavo F. Padovan #define __mod_monitor_timer() mod_timer(&chan->monitor_timer, \ 422e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_MONITOR_TO)); 423*e92c8e70SGustavo F. Padovan #define __mod_ack_timer() mod_timer(&chan->ack_timer, \ 424c1b4f43bSGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 425c74e560cSGustavo F. Padovan 42642e5c802SGustavo F. Padovan static inline int l2cap_tx_window_full(struct l2cap_chan *ch) 4271c2acffbSGustavo F. Padovan { 4281c2acffbSGustavo F. Padovan int sub; 4291c2acffbSGustavo F. Padovan 43042e5c802SGustavo F. Padovan sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; 4311c2acffbSGustavo F. Padovan 4321c2acffbSGustavo F. Padovan if (sub < 0) 4331c2acffbSGustavo F. Padovan sub += 64; 4341c2acffbSGustavo F. Padovan 4352c03a7a4SGustavo F. Padovan return sub == ch->remote_tx_win; 4361c2acffbSGustavo F. Padovan } 4371c2acffbSGustavo F. Padovan 438894718a6SAndrei Emeltchenko #define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1) 439894718a6SAndrei Emeltchenko #define __get_reqseq(ctrl) (((ctrl) & L2CAP_CTRL_REQSEQ) >> 8) 440894718a6SAndrei Emeltchenko #define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE)) 441894718a6SAndrei Emeltchenko #define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE) 442894718a6SAndrei Emeltchenko #define __is_sar_start(ctrl) (((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START) 4431da177e4SLinus Torvalds 444bb58f747SGustavo F. Padovan extern int disable_ertm; 445bb58f747SGustavo F. Padovan extern const struct proto_ops l2cap_sock_ops; 446bb58f747SGustavo F. Padovan extern struct bt_sock_list l2cap_sk_list; 447bb58f747SGustavo F. Padovan 448bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 449bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 450bb58f747SGustavo F. Padovan 45168983259SGustavo F. Padovan void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data); 452710f9b0aSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct sock *sk); 453dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 45468983259SGustavo F. Padovan 455fd83ccdbSGustavo F. Padovan struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len); 456fd83ccdbSGustavo F. Padovan struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len); 457fd83ccdbSGustavo F. Padovan struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg, size_t len, u16 control, u16 sdulen); 4582c03a7a4SGustavo F. Padovan int l2cap_sar_segment_sdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 459fd83ccdbSGustavo F. Padovan void l2cap_do_send(struct sock *sk, struct sk_buff *skb); 46042e5c802SGustavo F. Padovan void l2cap_streaming_send(struct l2cap_chan *chan); 461525cd185SGustavo F. Padovan int l2cap_ertm_send(struct l2cap_chan *chan); 462fd83ccdbSGustavo F. Padovan 463bb58f747SGustavo F. Padovan void l2cap_sock_set_timer(struct sock *sk, long timeout); 464dcba0dbaSGustavo F. Padovan void l2cap_sock_clear_timer(struct sock *sk); 465bb58f747SGustavo F. Padovan void __l2cap_sock_close(struct sock *sk, int reason); 466bb58f747SGustavo F. Padovan void l2cap_sock_kill(struct sock *sk); 467bb58f747SGustavo F. Padovan void l2cap_sock_init(struct sock *sk, struct sock *parent); 468bb58f747SGustavo F. Padovan struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, 469bb58f747SGustavo F. Padovan int proto, gfp_t prio); 470*e92c8e70SGustavo F. Padovan void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *chan, int err); 47148454079SGustavo F. Padovan void l2cap_chan_del(struct l2cap_chan *chan, int err); 4724e34c50bSGustavo F. Padovan int l2cap_do_connect(struct sock *sk); 473bb58f747SGustavo F. Padovan 4741da177e4SLinus Torvalds #endif /* __L2CAP_H */ 475