l2cap.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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_CONN_TIMEOUT (40000) /* 40 seconds */
  26. #define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */
  27. /* L2CAP socket address */
  28. struct sockaddr_l2 {
  29. sa_family_t l2_family;
  30. __le16 l2_psm;
  31. bdaddr_t l2_bdaddr;
  32. };
  33. /* L2CAP socket options */
  34. #define L2CAP_OPTIONS 0x01
  35. struct l2cap_options {
  36. __u16 omtu;
  37. __u16 imtu;
  38. __u16 flush_to;
  39. __u8 mode;
  40. };
  41. #define L2CAP_CONNINFO 0x02
  42. struct l2cap_conninfo {
  43. __u16 hci_handle;
  44. __u8 dev_class[3];
  45. };
  46. #define L2CAP_LM 0x03
  47. #define L2CAP_LM_MASTER 0x0001
  48. #define L2CAP_LM_AUTH 0x0002
  49. #define L2CAP_LM_ENCRYPT 0x0004
  50. #define L2CAP_LM_TRUSTED 0x0008
  51. #define L2CAP_LM_RELIABLE 0x0010
  52. #define L2CAP_LM_SECURE 0x0020
  53. /* L2CAP command codes */
  54. #define L2CAP_COMMAND_REJ 0x01
  55. #define L2CAP_CONN_REQ 0x02
  56. #define L2CAP_CONN_RSP 0x03
  57. #define L2CAP_CONF_REQ 0x04
  58. #define L2CAP_CONF_RSP 0x05
  59. #define L2CAP_DISCONN_REQ 0x06
  60. #define L2CAP_DISCONN_RSP 0x07
  61. #define L2CAP_ECHO_REQ 0x08
  62. #define L2CAP_ECHO_RSP 0x09
  63. #define L2CAP_INFO_REQ 0x0a
  64. #define L2CAP_INFO_RSP 0x0b
  65. /* L2CAP structures */
  66. struct l2cap_hdr {
  67. __le16 len;
  68. __le16 cid;
  69. } __attribute__ ((packed));
  70. #define L2CAP_HDR_SIZE 4
  71. struct l2cap_cmd_hdr {
  72. __u8 code;
  73. __u8 ident;
  74. __le16 len;
  75. } __attribute__ ((packed));
  76. #define L2CAP_CMD_HDR_SIZE 4
  77. struct l2cap_cmd_rej {
  78. __le16 reason;
  79. } __attribute__ ((packed));
  80. struct l2cap_conn_req {
  81. __le16 psm;
  82. __le16 scid;
  83. } __attribute__ ((packed));
  84. struct l2cap_conn_rsp {
  85. __le16 dcid;
  86. __le16 scid;
  87. __le16 result;
  88. __le16 status;
  89. } __attribute__ ((packed));
  90. /* connect result */
  91. #define L2CAP_CR_SUCCESS 0x0000
  92. #define L2CAP_CR_PEND 0x0001
  93. #define L2CAP_CR_BAD_PSM 0x0002
  94. #define L2CAP_CR_SEC_BLOCK 0x0003
  95. #define L2CAP_CR_NO_MEM 0x0004
  96. /* connect status */
  97. #define L2CAP_CS_NO_INFO 0x0000
  98. #define L2CAP_CS_AUTHEN_PEND 0x0001
  99. #define L2CAP_CS_AUTHOR_PEND 0x0002
  100. struct l2cap_conf_req {
  101. __le16 dcid;
  102. __le16 flags;
  103. __u8 data[0];
  104. } __attribute__ ((packed));
  105. struct l2cap_conf_rsp {
  106. __le16 scid;
  107. __le16 flags;
  108. __le16 result;
  109. __u8 data[0];
  110. } __attribute__ ((packed));
  111. #define L2CAP_CONF_SUCCESS 0x0000
  112. #define L2CAP_CONF_UNACCEPT 0x0001
  113. #define L2CAP_CONF_REJECT 0x0002
  114. #define L2CAP_CONF_UNKNOWN 0x0003
  115. struct l2cap_conf_opt {
  116. __u8 type;
  117. __u8 len;
  118. __u8 val[0];
  119. } __attribute__ ((packed));
  120. #define L2CAP_CONF_OPT_SIZE 2
  121. #define L2CAP_CONF_MTU 0x01
  122. #define L2CAP_CONF_FLUSH_TO 0x02
  123. #define L2CAP_CONF_QOS 0x03
  124. #define L2CAP_CONF_RFC 0x04
  125. #define L2CAP_CONF_MAX_SIZE 22
  126. struct l2cap_conf_rfc {
  127. __u8 mode;
  128. __u8 txwin_size;
  129. __u8 max_transmit;
  130. __le16 retrans_timeout;
  131. __le16 monitor_timeout;
  132. __le16 max_pdu_size;
  133. } __attribute__ ((packed));
  134. #define L2CAP_MODE_BASIC 0x00
  135. #define L2CAP_MODE_RETRANS 0x01
  136. #define L2CAP_MODE_FLOWCTL 0x02
  137. struct l2cap_disconn_req {
  138. __le16 dcid;
  139. __le16 scid;
  140. } __attribute__ ((packed));
  141. struct l2cap_disconn_rsp {
  142. __le16 dcid;
  143. __le16 scid;
  144. } __attribute__ ((packed));
  145. struct l2cap_info_req {
  146. __le16 type;
  147. } __attribute__ ((packed));
  148. struct l2cap_info_rsp {
  149. __le16 type;
  150. __le16 result;
  151. __u8 data[0];
  152. } __attribute__ ((packed));
  153. /* info type */
  154. #define L2CAP_IT_CL_MTU 0x0001
  155. #define L2CAP_IT_FEAT_MASK 0x0002
  156. /* info result */
  157. #define L2CAP_IR_SUCCESS 0x0000
  158. #define L2CAP_IR_NOTSUPP 0x0001
  159. /* ----- L2CAP connections ----- */
  160. struct l2cap_chan_list {
  161. struct sock *head;
  162. rwlock_t lock;
  163. long num;
  164. };
  165. struct l2cap_conn {
  166. struct hci_conn *hcon;
  167. bdaddr_t *dst;
  168. bdaddr_t *src;
  169. unsigned int mtu;
  170. __u32 feat_mask;
  171. __u8 info_state;
  172. __u8 info_ident;
  173. struct timer_list info_timer;
  174. spinlock_t lock;
  175. struct sk_buff *rx_skb;
  176. __u32 rx_len;
  177. __u8 rx_ident;
  178. __u8 tx_ident;
  179. struct l2cap_chan_list chan_list;
  180. };
  181. #define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
  182. #define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x02
  183. /* ----- L2CAP channel and socket info ----- */
  184. #define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
  185. struct l2cap_pinfo {
  186. struct bt_sock bt;
  187. __le16 psm;
  188. __u16 dcid;
  189. __u16 scid;
  190. __u16 imtu;
  191. __u16 omtu;
  192. __u16 flush_to;
  193. __u32 link_mode;
  194. __u8 conf_req[64];
  195. __u8 conf_len;
  196. __u8 conf_state;
  197. __u8 conf_retry;
  198. __u8 ident;
  199. __le16 sport;
  200. struct l2cap_conn *conn;
  201. struct sock *next_c;
  202. struct sock *prev_c;
  203. };
  204. #define L2CAP_CONF_REQ_SENT 0x01
  205. #define L2CAP_CONF_INPUT_DONE 0x02
  206. #define L2CAP_CONF_OUTPUT_DONE 0x04
  207. #define L2CAP_CONF_MAX_RETRIES 2
  208. void l2cap_load(void);
  209. #endif /* __L2CAP_H */