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 29089bc500eSGustavo F. Padovan __u8 state; 29189bc500eSGustavo F. Padovan 29271ba0e56SGustavo F. Padovan atomic_t refcnt; 29371ba0e56SGustavo F. Padovan 294fe4128e0SGustavo F. Padovan __le16 psm; 295fe4128e0SGustavo F. Padovan __u16 dcid; 296fe4128e0SGustavo F. Padovan __u16 scid; 2974343478fSGustavo F. Padovan 2980c1bc5c6SGustavo F. Padovan __u16 imtu; 2990c1bc5c6SGustavo F. Padovan __u16 omtu; 3000c1bc5c6SGustavo F. Padovan __u16 flush_to; 3010c1bc5c6SGustavo F. Padovan __u8 mode; 302715ec005SGustavo F. Padovan __u8 chan_type; 3030c1bc5c6SGustavo F. Padovan 3040c1bc5c6SGustavo F. Padovan __le16 sport; 3050c1bc5c6SGustavo F. Padovan 3064343478fSGustavo F. Padovan __u8 sec_level; 3074343478fSGustavo F. Padovan __u8 role_switch; 3084343478fSGustavo F. Padovan __u8 force_reliable; 3094343478fSGustavo F. Padovan __u8 flushable; 31014b12d0bSJaikumar Ganesh __u8 force_active; 3114343478fSGustavo F. Padovan 312fc7f8a7eSGustavo F. Padovan __u8 ident; 313fc7f8a7eSGustavo F. Padovan 31473ffa904SGustavo F. Padovan __u8 conf_req[64]; 31573ffa904SGustavo F. Padovan __u8 conf_len; 31673ffa904SGustavo F. Padovan __u8 num_conf_req; 31773ffa904SGustavo F. Padovan __u8 num_conf_rsp; 31873ffa904SGustavo F. Padovan 31947d1ec61SGustavo F. Padovan __u8 fcs; 32047d1ec61SGustavo F. Padovan 32147d1ec61SGustavo F. Padovan __u8 tx_win; 32247d1ec61SGustavo F. Padovan __u8 max_tx; 32347d1ec61SGustavo F. Padovan __u16 retrans_timeout; 32447d1ec61SGustavo F. Padovan __u16 monitor_timeout; 32547d1ec61SGustavo F. Padovan __u16 mps; 32647d1ec61SGustavo F. Padovan 327b4450035SGustavo F. Padovan __u8 conf_state; 328525cd185SGustavo F. Padovan __u16 conn_state; 329525cd185SGustavo F. Padovan 33042e5c802SGustavo F. Padovan __u8 next_tx_seq; 33142e5c802SGustavo F. Padovan __u8 expected_ack_seq; 33242e5c802SGustavo F. Padovan __u8 expected_tx_seq; 33342e5c802SGustavo F. Padovan __u8 buffer_seq; 33442e5c802SGustavo F. Padovan __u8 buffer_seq_srej; 3356a026610SGustavo F. Padovan __u8 srej_save_reqseq; 3366a026610SGustavo F. Padovan __u8 frames_sent; 3376a026610SGustavo F. Padovan __u8 unacked_frames; 3386a026610SGustavo F. Padovan __u8 retry_count; 3396a026610SGustavo F. Padovan __u8 num_acked; 3406f61fd47SGustavo F. Padovan __u16 sdu_len; 3416f61fd47SGustavo F. Padovan __u16 partial_sdu_len; 3426f61fd47SGustavo F. Padovan struct sk_buff *sdu; 3436f61fd47SGustavo F. Padovan 3442c03a7a4SGustavo F. Padovan __u8 remote_tx_win; 3452c03a7a4SGustavo F. Padovan __u8 remote_max_tx; 3462c03a7a4SGustavo F. Padovan __u16 remote_mps; 34742e5c802SGustavo F. Padovan 348ab07801dSGustavo F. Padovan struct timer_list chan_timer; 349e92c8e70SGustavo F. Padovan struct timer_list retrans_timer; 350e92c8e70SGustavo F. Padovan struct timer_list monitor_timer; 351e92c8e70SGustavo F. Padovan struct timer_list ack_timer; 35258d35f87SGustavo F. Padovan struct sk_buff *tx_send_head; 35358d35f87SGustavo F. Padovan struct sk_buff_head tx_q; 354f1c6775bSGustavo F. Padovan struct sk_buff_head srej_q; 355f1c6775bSGustavo F. Padovan struct sk_buff_head busy_q; 356311bb895SGustavo F. Padovan struct work_struct busy_work; 35739d5a3eeSGustavo F. Padovan struct list_head srej_l; 358e92c8e70SGustavo F. Padovan 359baa7e1faSGustavo F. Padovan struct list_head list; 36023691d75SGustavo F. Padovan struct list_head global_l; 36180808e43SGustavo F. Padovan 36280808e43SGustavo F. Padovan void *data; 36380808e43SGustavo F. Padovan struct l2cap_ops *ops; 36480808e43SGustavo F. Padovan }; 36580808e43SGustavo F. Padovan 36680808e43SGustavo F. Padovan struct l2cap_ops { 36780808e43SGustavo F. Padovan char *name; 36880808e43SGustavo F. Padovan 36980808e43SGustavo F. Padovan struct l2cap_chan *(*new_connection) (void *data); 37023070494SGustavo F. Padovan int (*recv) (void *data, struct sk_buff *skb); 371ba3bd0eeSGustavo F. Padovan void (*close) (void *data); 37289bc500eSGustavo F. Padovan void (*state_change) (void *data, int state); 3731da177e4SLinus Torvalds }; 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds struct l2cap_conn { 3761da177e4SLinus Torvalds struct hci_conn *hcon; 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds bdaddr_t *dst; 3791da177e4SLinus Torvalds bdaddr_t *src; 3801da177e4SLinus Torvalds 3811da177e4SLinus Torvalds unsigned int mtu; 3821da177e4SLinus Torvalds 3834e8402a3SMarcel Holtmann __u32 feat_mask; 3844e8402a3SMarcel Holtmann 3854e8402a3SMarcel Holtmann __u8 info_state; 3864e8402a3SMarcel Holtmann __u8 info_ident; 3874e8402a3SMarcel Holtmann 3884e8402a3SMarcel Holtmann struct timer_list info_timer; 3894e8402a3SMarcel Holtmann 3901da177e4SLinus Torvalds spinlock_t lock; 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds struct sk_buff *rx_skb; 3931da177e4SLinus Torvalds __u32 rx_len; 3941da177e4SLinus Torvalds __u8 tx_ident; 3951da177e4SLinus Torvalds 3962950f21aSMarcel Holtmann __u8 disc_reason; 3972950f21aSMarcel Holtmann 398f01ead31SAnderson Briglia __u8 preq[7]; /* SMP Pairing Request */ 399f01ead31SAnderson Briglia __u8 prsp[7]; /* SMP Pairing Response */ 400f01ead31SAnderson Briglia __u8 prnd[16]; /* SMP Pairing Random */ 401f01ead31SAnderson Briglia __u8 pcnf[16]; /* SMP Pairing Confirm */ 4027d24ddccSAnderson Briglia __u8 tk[16]; /* SMP Temporary Key */ 403f01ead31SAnderson Briglia 404*5d3de7dfSVinicius Costa Gomes struct timer_list security_timer; 405*5d3de7dfSVinicius Costa Gomes 406baa7e1faSGustavo F. Padovan struct list_head chan_l; 407baa7e1faSGustavo F. Padovan rwlock_t chan_lock; 4081da177e4SLinus Torvalds }; 4091da177e4SLinus Torvalds 4104e8402a3SMarcel Holtmann #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01 411984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04 412984947dcSMarcel Holtmann #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08 4134e8402a3SMarcel Holtmann 414715ec005SGustavo F. Padovan #define L2CAP_CHAN_RAW 1 415715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_LESS 2 416715ec005SGustavo F. Padovan #define L2CAP_CHAN_CONN_ORIENTED 3 417715ec005SGustavo F. Padovan 41848454079SGustavo F. Padovan /* ----- L2CAP socket info ----- */ 4191da177e4SLinus Torvalds #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds struct l2cap_pinfo { 4221da177e4SLinus Torvalds struct bt_sock bt; 42348454079SGustavo F. Padovan struct l2cap_chan *chan; 4241da177e4SLinus Torvalds }; 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds #define L2CAP_CONF_REQ_SENT 0x01 4271da177e4SLinus Torvalds #define L2CAP_CONF_INPUT_DONE 0x02 4281da177e4SLinus Torvalds #define L2CAP_CONF_OUTPUT_DONE 0x04 429f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MTU_DONE 0x08 430f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MODE_DONE 0x10 431f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_CONNECT_PEND 0x20 432fcc203c3SGustavo F. Padovan #define L2CAP_CONF_NO_FCS_RECV 0x40 433f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_STATE2_DEVICE 0x80 434861d6882SMarcel Holtmann 435f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_REQ 2 436f2fcfcd6SGustavo F. Padovan #define L2CAP_CONF_MAX_CONF_RSP 2 437f2fcfcd6SGustavo F. Padovan 438d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SAR_SDU 0x0001 439d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_SENT 0x0002 440d5392c8fSGustavo F. Padovan #define L2CAP_CONN_WAIT_F 0x0004 441d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SREJ_ACT 0x0008 442d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_PBIT 0x0010 443d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REMOTE_BUSY 0x0020 444d5392c8fSGustavo F. Padovan #define L2CAP_CONN_LOCAL_BUSY 0x0040 445d5392c8fSGustavo F. Padovan #define L2CAP_CONN_REJ_ACT 0x0080 446d5392c8fSGustavo F. Padovan #define L2CAP_CONN_SEND_FBIT 0x0100 4471890d36bSGustavo F. Padovan #define L2CAP_CONN_RNR_SENT 0x0200 4481890d36bSGustavo F. Padovan #define L2CAP_CONN_SAR_RETRY 0x0400 449e90bac06SGustavo F. Padovan 450c9b66675SGustavo F. Padovan #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 451c9b66675SGustavo F. Padovan #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 4521a09bcb9SGustavo F. Padovan #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \ 4531a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_RETRANS_TO); 4541a09bcb9SGustavo F. Padovan #define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 4551a09bcb9SGustavo F. Padovan #define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \ 4561a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_MONITOR_TO); 4571a09bcb9SGustavo F. Padovan #define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 4581a09bcb9SGustavo F. Padovan #define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 4591a09bcb9SGustavo F. Padovan L2CAP_DEFAULT_ACK_TO); 4601a09bcb9SGustavo F. Padovan #define __clear_ack_timer(c) l2cap_clear_timer(c, &c->ack_timer) 461c74e560cSGustavo F. Padovan 46242e5c802SGustavo F. Padovan static inline int l2cap_tx_window_full(struct l2cap_chan *ch) 4631c2acffbSGustavo F. Padovan { 4641c2acffbSGustavo F. Padovan int sub; 4651c2acffbSGustavo F. Padovan 46642e5c802SGustavo F. Padovan sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64; 4671c2acffbSGustavo F. Padovan 4681c2acffbSGustavo F. Padovan if (sub < 0) 4691c2acffbSGustavo F. Padovan sub += 64; 4701c2acffbSGustavo F. Padovan 4712c03a7a4SGustavo F. Padovan return sub == ch->remote_tx_win; 4721c2acffbSGustavo F. Padovan } 4731c2acffbSGustavo F. Padovan 474894718a6SAndrei Emeltchenko #define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1) 475894718a6SAndrei Emeltchenko #define __get_reqseq(ctrl) (((ctrl) & L2CAP_CTRL_REQSEQ) >> 8) 476894718a6SAndrei Emeltchenko #define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE)) 477894718a6SAndrei Emeltchenko #define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE) 478894718a6SAndrei Emeltchenko #define __is_sar_start(ctrl) (((ctrl) & L2CAP_CTRL_SAR) == L2CAP_SDU_START) 4791da177e4SLinus Torvalds 480bb58f747SGustavo F. Padovan extern int disable_ertm; 481bb58f747SGustavo F. Padovan 482bb58f747SGustavo F. Padovan int l2cap_init_sockets(void); 483bb58f747SGustavo F. Padovan void l2cap_cleanup_sockets(void); 484bb58f747SGustavo F. Padovan 4858c1d787bSGustavo F. Padovan void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); 486dcba0dbaSGustavo F. Padovan int __l2cap_wait_ack(struct sock *sk); 48768983259SGustavo F. Padovan 4889e4425ffSGustavo F. Padovan int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); 4899e4425ffSGustavo F. Padovan int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid); 4909e4425ffSGustavo F. Padovan 49123691d75SGustavo F. Padovan struct l2cap_chan *l2cap_chan_create(struct sock *sk); 4920f852724SGustavo F. Padovan void l2cap_chan_close(struct l2cap_chan *chan, int reason); 49323691d75SGustavo F. Padovan void l2cap_chan_destroy(struct l2cap_chan *chan); 49477a74c7eSGustavo F. Padovan int l2cap_chan_connect(struct l2cap_chan *chan); 4959a91a04aSGustavo F. Padovan int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); 496bb58f747SGustavo F. Padovan 4971da177e4SLinus Torvalds #endif /* __L2CAP_H */ 498