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 ----- */ 28039d5a3eeSGustavo F. Padovan struct srej_list { 28139d5a3eeSGustavo F. Padovan __u8 tx_seq; 28239d5a3eeSGustavo F. Padovan struct list_head list; 28339d5a3eeSGustavo F. Padovan }; 28439d5a3eeSGustavo F. Padovan 28548454079SGustavo F. Padovan struct l2cap_chan { 28648454079SGustavo F. Padovan struct sock *sk; 2878c1d787bSGustavo F. Padovan 2888c1d787bSGustavo F. Padovan struct l2cap_conn *conn; 2898c1d787bSGustavo F. Padovan 290fe4128e0SGustavo F. Padovan __le16 psm; 291fe4128e0SGustavo F. Padovan __u16 dcid; 292fe4128e0SGustavo F. Padovan __u16 scid; 2934343478fSGustavo F. Padovan 2940c1bc5c6SGustavo F. Padovan __u16 imtu; 2950c1bc5c6SGustavo F. Padovan __u16 omtu; 2960c1bc5c6SGustavo F. Padovan __u16 flush_to; 2970c1bc5c6SGustavo F. Padovan __u8 mode; 298715ec005SGustavo F. Padovan __u8 chan_type; 2990c1bc5c6SGustavo F. Padovan 3000c1bc5c6SGustavo F. Padovan __le16 sport; 3010c1bc5c6SGustavo F. Padovan 3024343478fSGustavo F. Padovan __u8 sec_level; 3034343478fSGustavo F. Padovan __u8 role_switch; 3044343478fSGustavo F. Padovan __u8 force_reliable; 3054343478fSGustavo F. Padovan __u8 flushable; 30614b12d0bSJaikumar Ganesh __u8 force_active; 3074343478fSGustavo F. Padovan 308fc7f8a7eSGustavo F. Padovan __u8 ident; 309fc7f8a7eSGustavo F. Padovan 31073ffa904SGustavo F. Padovan __u8 conf_req[64]; 31173ffa904SGustavo F. Padovan __u8 conf_len; 31273ffa904SGustavo F. Padovan __u8 num_conf_req; 31373ffa904SGustavo F. Padovan __u8 num_conf_rsp; 31473ffa904SGustavo F. Padovan 31547d1ec61SGustavo F. Padovan __u8 fcs; 31647d1ec61SGustavo F. Padovan 31747d1ec61SGustavo F. Padovan __u8 tx_win; 31847d1ec61SGustavo F. Padovan __u8 max_tx; 31947d1ec61SGustavo F. Padovan __u16 retrans_timeout; 32047d1ec61SGustavo F. Padovan __u16 monitor_timeout; 32147d1ec61SGustavo F. Padovan __u16 mps; 32247d1ec61SGustavo F. Padovan 323b4450035SGustavo F. Padovan __u8 conf_state; 324525cd185SGustavo F. Padovan __u16 conn_state; 325525cd185SGustavo F. Padovan 32642e5c802SGustavo F. Padovan __u8 next_tx_seq; 32742e5c802SGustavo F. Padovan __u8 expected_ack_seq; 32842e5c802SGustavo F. Padovan __u8 expected_tx_seq; 32942e5c802SGustavo F. Padovan __u8 buffer_seq; 33042e5c802SGustavo F. Padovan __u8 buffer_seq_srej; 3316a026610SGustavo F. Padovan __u8 srej_save_reqseq; 3326a026610SGustavo F. Padovan __u8 frames_sent; 3336a026610SGustavo F. Padovan __u8 unacked_frames; 3346a026610SGustavo F. Padovan __u8 retry_count; 3356a026610SGustavo F. Padovan __u8 num_acked; 3366f61fd47SGustavo F. Padovan __u16 sdu_len; 3376f61fd47SGustavo F. Padovan __u16 partial_sdu_len; 3386f61fd47SGustavo F. Padovan struct sk_buff *sdu; 3396f61fd47SGustavo F. Padovan 3402c03a7a4SGustavo F. Padovan __u8 remote_tx_win; 3412c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 3422c03a7a4SGustavo F. Padovan __u16 remote_mps; 34342e5c802SGustavo F. Padovan 344ab07801dSGustavo F. Padovan struct timer_list chan_timer; 345e92c8e70SGustavo F. Padovan struct timer_list retrans_timer; 346e92c8e70SGustavo F. Padovan struct timer_list monitor_timer; 347e92c8e70SGustavo F. Padovan struct timer_list ack_timer; 34858d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 34958d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 350f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 351f1c6775bSGustavo F. Padovan struct sk_buff_head busy_q; 352311bb895SGustavo F. Padovan struct work_struct busy_work; 35339d5a3eeSGustavo F. Padovan struct list_head srej_l; 354e92c8e70SGustavo F. Padovan 355baa7e1faSGustavo F. Padovan struct list_head list; 35623691d75SGustavo F. Padovan struct list_head global_l; 357*80808e43SGustavo F. Padovan 358*80808e43SGustavo F. Padovan void *data; 359*80808e43SGustavo F. Padovan struct l2cap_ops *ops; 360*80808e43SGustavo F. Padovan }; 361*80808e43SGustavo F. Padovan 362*80808e43SGustavo F. Padovan struct l2cap_ops { 363*80808e43SGustavo F. Padovan char *name; 364*80808e43SGustavo F. Padovan 365*80808e43SGustavo F. Padovan struct l2cap_chan *(*new_connection) (void *data); 3661da177e4SLinus Torvalds }; 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds struct l2cap_conn { 3691da177e4SLinus Torvalds struct hci_conn *hcon; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds bdaddr_t *dst; 3721da177e4SLinus Torvalds bdaddr_t *src; 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds unsigned int mtu; 3751da177e4SLinus Torvalds 3764e8402a3SMarcel Holtmann __u32 feat_mask; 3774e8402a3SMarcel Holtmann 3784e8402a3SMarcel Holtmann __u8 info_state; 3794e8402a3SMarcel Holtmann __u8 info_ident; 3804e8402a3SMarcel Holtmann 3814e8402a3SMarcel Holtmann struct timer_list info_timer; 3824e8402a3SMarcel Holtmann 3831da177e4SLinus Torvalds spinlock_t lock; 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds struct sk_buff *rx_skb; 3861da177e4SLinus Torvalds __u32 rx_len; 3871da177e4SLinus Torvalds __u8 tx_ident; 3881da177e4SLinus Torvalds 3892950f21aSMarcel Holtmann __u8 disc_reason; 3902950f21aSMarcel Holtmann 391baa7e1faSGustavo F. Padovan struct list_head chan_l; 392baa7e1faSGustavo F. Padovan rwlock_t chan_lock; 3931da177e4SLinus Torvalds }; 3941da177e4SLinus Torvalds 3954e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 396984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 397984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 3984e8402a3SMarcel Holtmann 399715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 400715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 401715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 402715ec005SGustavo F. Padovan 40348454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 4041da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds struct l2cap_pinfo { 4071da177e4SLinus Torvalds struct bt_sock bt; 40848454079SGustavo F. Padovan struct l2cap_chan *chan; 4091da177e4SLinus Torvalds }; 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds #define L2CAP_CONF_REQ_SENT 0x01 4121da177e4SLinus Torvalds #define L2CAP_CONF_INPUT_DONE 0x02 4131da177e4SLinus Torvalds #define L2CAP_CONF_OUTPUT_DONE 0x04 414f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MTU_DONE 0x08 415f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MODE_DONE 0x10 416f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_CONNECT_PEND 0x20 417fcc203c3SGustavo F. Padovan #define L2CAP_CONF_NO_FCS_RECV 0x40 418f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_STATE2_DEVICE 0x80 419861d6882SMarcel Holtmann 420f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 421f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 422f2fcfcd6SGustavo F. Padovan 423d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SAR_SDU 0x0001 424d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_SENT 0x0002 425d5392c8fSGustavo F. Padovan #define L2CAP_CONN_WAIT_F 0x0004 426d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_ACT 0x0008 427d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_PBIT 0x0010 428d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REMOTE_BUSY 0x0020 429d5392c8fSGustavo F. Padovan #define L2CAP_CONN_LOCAL_BUSY 0x0040 430d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REJ_ACT 0x0080 431d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_FBIT 0x0100 4321890d36bSGustavo F. Padovan #define L2CAP_CONN_RNR_SENT 0x0200 4331890d36bSGustavo F. Padovan #define L2CAP_CONN_SAR_RETRY 0x0400 434e90bac06SGustavo F. Padovan 435e92c8e70SGustavo F. Padovan #define __mod_retrans_timer() mod_timer(&chan->retrans_timer, \ 436e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_RETRANS_TO)); 437e92c8e70SGustavo F. Padovan #define __mod_monitor_timer() mod_timer(&chan->monitor_timer, \ 438e90bac06SGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_MONITOR_TO)); 439e92c8e70SGustavo F. Padovan #define __mod_ack_timer() mod_timer(&chan->ack_timer, \ 440c1b4f43bSGustavo F. Padovan jiffies + msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 441c74e560cSGustavo F. Padovan 44242e5c802SGustavo F. Padovan static inline int l2cap_tx_window_full(struct l2cap_chan *ch) 4431c2acffbSGustavo F. Padovan { 4441c2acffbSGustavo F. Padovan int sub; 4451c2acffbSGustavo F. Padovan 44642e5c802SGustavo F. Padovan sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; 4471c2acffbSGustavo F. Padovan 4481c2acffbSGustavo F. Padovan if (sub < 0) 4491c2acffbSGustavo F. Padovan sub += 64; 4501c2acffbSGustavo F. Padovan 4512c03a7a4SGustavo F. Padovan return sub == ch->remote_tx_win; 4521c2acffbSGustavo F. Padovan } 4531c2acffbSGustavo F. Padovan 454894718a6SAndrei Emeltchenko #define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1) 455894718a6SAndrei Emeltchenko #define __get_reqseq(ctrl) (((ctrl) & L2CAP_CTRL_REQSEQ) >> 8) 456894718a6SAndrei Emeltchenko #define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE)) 457894718a6SAndrei Emeltchenko #define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE) 458894718a6SAndrei Emeltchenko #define __is_sar_start(ctrl) (((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START) 4591da177e4SLinus Torvalds 460bb58f747SGustavo F. Padovan extern int disable_ertm; 461bb58f747SGustavo F. Padovan 462bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 463bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 464bb58f747SGustavo F. Padovan 4658c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 466dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 46768983259SGustavo F. Padovan 4689e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 4699e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 4709e4425ffSGustavo F. Padovan 471bb58f747SGustavo F. Padovan void l2cap_sock_kill(struct sock *sk); 472ab07801dSGustavo F. Padovan 47323691d75SGustavo F. Padovan struct l2cap_chan *l2cap_chan_create(struct sock *sk); 4740f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 47523691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan); 47677a74c7eSGustavo F. Padovan int l2cap_chan_connect(struct l2cap_chan *chan); 4779a91a04aSGustavo F. Padovan int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 478bb58f747SGustavo F. Padovan 4791da177e4SLinus Torvalds #endif /* __L2CAP_H */ 480