l2cap.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. BlueZ - Bluetooth protocol stack for Linux
  3. Copyright (C) 2000-2001 Qualcomm Incorporated
  4. Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License version 2 as
  7. published by the Free Software Foundation;
  8. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  10. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  11. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  12. CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  13. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
  17. COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
  18. SOFTWARE IS DISCLAIMED.
  19. */
  20. #ifndef __L2CAP_H
  21. #define __L2CAP_H
  22. /* L2CAP defaults */
  23. #define L2CAP_DEFAULT_MTU 672
  24. #define L2CAP_DEFAULT_FLUSH_TO 0xffff
  25. #define L2CAP_DEFAULT_RX_WINDOW 1
  26. #define L2CAP_DEFAULT_MAX_RECEIVE 1
  27. #define L2CAP_DEFAULT_RETRANS_TO 300 /* 300 milliseconds */
  28. #define L2CAP_DEFAULT_MONITOR_TO 1000 /* 1 second */
  29. #define L2CAP_DEFAULT_MAX_RX_APDU 0xfff7
  30. #define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */
  31. #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */
  32. /* L2CAP socket address */
  33. struct sockaddr_l2 {
  34. sa_family_t l2_family;
  35. __le16 l2_psm;
  36. bdaddr_t l2_bdaddr;
  37. __le16 l2_cid;
  38. };
  39. /* L2CAP socket options */
  40. #define L2CAP_OPTIONS 0x01
  41. struct l2cap_options {
  42. __u16 omtu;
  43. __u16 imtu;
  44. __u16 flush_to;
  45. __u8 mode;
  46. };
  47. #define L2CAP_CONNINFO 0x02
  48. struct l2cap_conninfo {
  49. __u16 hci_handle;
  50. __u8 dev_class[3];
  51. };
  52. #define L2CAP_LM 0x03
  53. #define L2CAP_LM_MASTER 0x0001
  54. #define L2CAP_LM_AUTH 0x0002
  55. #define L2CAP_LM_ENCRYPT 0x0004
  56. #define L2CAP_LM_TRUSTED 0x0008
  57. #define L2CAP_LM_RELIABLE 0x0010
  58. #define L2CAP_LM_SECURE 0x0020
  59. /* L2CAP command codes */
  60. #define L2CAP_COMMAND_REJ 0x01
  61. #define L2CAP_CONN_REQ 0x02
  62. #define L2CAP_CONN_RSP 0x03
  63. #define L2CAP_CONF_REQ 0x04
  64. #define L2CAP_CONF_RSP 0x05
  65. #define L2CAP_DISCONN_REQ 0x06
  66. #define L2CAP_DISCONN_RSP 0x07
  67. #define L2CAP_ECHO_REQ 0x08
  68. #define L2CAP_ECHO_RSP 0x09
  69. #define L2CAP_INFO_REQ 0x0a
  70. #define L2CAP_INFO_RSP 0x0b
  71. /* L2CAP feature mask */
  72. #define L2CAP_FEAT_FLOWCTL 0x00000001
  73. #define L2CAP_FEAT_RETRANS 0x00000002
  74. #define L2CAP_FEAT_ERTM 0x00000008
  75. #define L2CAP_FEAT_STREAMING 0x00000010
  76. #define L2CAP_FEAT_FCS 0x00000020
  77. #define L2CAP_FEAT_FIXED_CHAN 0x00000080
  78. /* L2CAP checksum option */
  79. #define L2CAP_FCS_NONE 0x00
  80. #define L2CAP_FCS_CRC16 0x01
  81. /* L2CAP structures */
  82. struct l2cap_hdr {
  83. __le16 len;
  84. __le16 cid;
  85. } __attribute__ ((packed));
  86. #define L2CAP_HDR_SIZE 4
  87. struct l2cap_cmd_hdr {
  88. __u8 code;
  89. __u8 ident;
  90. __le16 len;
  91. } __attribute__ ((packed));
  92. #define L2CAP_CMD_HDR_SIZE 4
  93. struct l2cap_cmd_rej {
  94. __le16 reason;
  95. } __attribute__ ((packed));
  96. struct l2cap_conn_req {
  97. __le16 psm;
  98. __le16 scid;
  99. } __attribute__ ((packed));
  100. struct l2cap_conn_rsp {
  101. __le16 dcid;
  102. __le16 scid;
  103. __le16 result;
  104. __le16 status;
  105. } __attribute__ ((packed));
  106. /* channel indentifier */
  107. #define L2CAP_CID_SIGNALING 0x0001
  108. #define L2CAP_CID_CONN_LESS 0x0002
  109. #define L2CAP_CID_DYN_START 0x0040
  110. #define L2CAP_CID_DYN_END 0xffff
  111. /* connect result */
  112. #define L2CAP_CR_SUCCESS 0x0000
  113. #define L2CAP_CR_PEND 0x0001
  114. #define L2CAP_CR_BAD_PSM 0x0002
  115. #define L2CAP_CR_SEC_BLOCK 0x0003
  116. #define L2CAP_CR_NO_MEM 0x0004
  117. /* connect status */
  118. #define L2CAP_CS_NO_INFO 0x0000
  119. #define L2CAP_CS_AUTHEN_PEND 0x0001
  120. #define L2CAP_CS_AUTHOR_PEND 0x0002
  121. struct l2cap_conf_req {
  122. __le16 dcid;
  123. __le16 flags;
  124. __u8 data[0];
  125. } __attribute__ ((packed));
  126. struct l2cap_conf_rsp {
  127. __le16 scid;
  128. __le16 flags;
  129. __le16 result;
  130. __u8 data[0];
  131. } __attribute__ ((packed));
  132. #define L2CAP_CONF_SUCCESS 0x0000
  133. #define L2CAP_CONF_UNACCEPT 0x0001
  134. #define L2CAP_CONF_REJECT 0x0002
  135. #define L2CAP_CONF_UNKNOWN 0x0003
  136. struct l2cap_conf_opt {
  137. __u8 type;
  138. __u8 len;
  139. __u8 val[0];
  140. } __attribute__ ((packed));
  141. #define L2CAP_CONF_OPT_SIZE 2
  142. #define L2CAP_CONF_HINT 0x80
  143. #define L2CAP_CONF_MASK 0x7f
  144. #define L2CAP_CONF_MTU 0x01
  145. #define L2CAP_CONF_FLUSH_TO 0x02
  146. #define L2CAP_CONF_QOS 0x03
  147. #define L2CAP_CONF_RFC 0x04
  148. #define L2CAP_CONF_FCS 0x05
  149. #define L2CAP_CONF_MAX_SIZE 22
  150. struct l2cap_conf_rfc {
  151. __u8 mode;
  152. __u8 txwin_size;
  153. __u8 max_transmit;
  154. __le16 retrans_timeout;
  155. __le16 monitor_timeout;
  156. __le16 max_pdu_size;
  157. } __attribute__ ((packed));
  158. #define L2CAP_MODE_BASIC 0x00
  159. #define L2CAP_MODE_RETRANS 0x01
  160. #define L2CAP_MODE_FLOWCTL 0x02
  161. #define L2CAP_MODE_ERTM 0x03
  162. #define L2CAP_MODE_STREAM 0x04
  163. struct l2cap_disconn_req {
  164. __le16 dcid;
  165. __le16 scid;
  166. } __attribute__ ((packed));
  167. struct l2cap_disconn_rsp {
  168. __le16 dcid;
  169. __le16 scid;
  170. } __attribute__ ((packed));
  171. struct l2cap_info_req {
  172. __le16 type;
  173. } __attribute__ ((packed));
  174. struct l2cap_info_rsp {
  175. __le16 type;
  176. __le16 result;
  177. __u8 data[0];
  178. } __attribute__ ((packed));
  179. /* info type */
  180. #define L2CAP_IT_CL_MTU 0x0001
  181. #define L2CAP_IT_FEAT_MASK 0x0002
  182. #define L2CAP_IT_FIXED_CHAN 0x0003
  183. /* info result */
  184. #define L2CAP_IR_SUCCESS 0x0000
  185. #define L2CAP_IR_NOTSUPP 0x0001
  186. /* ----- L2CAP connections ----- */
  187. struct l2cap_chan_list {
  188. struct sock *head;
  189. rwlock_t lock;
  190. long num;
  191. };
  192. struct l2cap_conn {
  193. struct hci_conn *hcon;
  194. bdaddr_t *dst;
  195. bdaddr_t *src;
  196. unsigned int mtu;
  197. __u32 feat_mask;
  198. __u8 info_state;
  199. __u8 info_ident;
  200. struct timer_list info_timer;
  201. spinlock_t lock;
  202. struct sk_buff *rx_skb;
  203. __u32 rx_len;
  204. __u8 rx_ident;
  205. __u8 tx_ident;
  206. __u8 disc_reason;
  207. struct l2cap_chan_list chan_list;
  208. };
  209. #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
  210. #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04
  211. #define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08
  212. /* ----- L2CAP channel and socket info ----- */
  213. #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
  214. struct l2cap_pinfo {
  215. struct bt_sock bt;
  216. __le16 psm;
  217. __u16 dcid;
  218. __u16 scid;
  219. __u16 imtu;
  220. __u16 omtu;
  221. __u16 flush_to;
  222. __u8 sec_level;
  223. __u8 role_switch;
  224. __u8 force_reliable;
  225. __u8 conf_req[64];
  226. __u8 conf_len;
  227. __u8 conf_state;
  228. __u8 conf_retry;
  229. __u8 ident;
  230. __le16 sport;
  231. struct l2cap_conn *conn;
  232. struct sock *next_c;
  233. struct sock *prev_c;
  234. };
  235. #define L2CAP_CONF_REQ_SENT 0x01
  236. #define L2CAP_CONF_INPUT_DONE 0x02
  237. #define L2CAP_CONF_OUTPUT_DONE 0x04
  238. #define L2CAP_CONF_CONNECT_PEND 0x80
  239. #define L2CAP_CONF_MAX_RETRIES 2
  240. void l2cap_load(void);
  241. #endif /* __L2CAP_H */