l2cap.h 5.1 KB

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