l2cap.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. *
  3. * BlueZ - Bluetooth protocol stack for Linux
  4. *
  5. * Copyright (C) 2000-2001 Qualcomm Incorporated
  6. * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
  7. * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
  8. * Copyright (c) 2012 Code Aurora Forum. All rights reserved.
  9. *
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. */
  26. #ifndef __L2CAP_H
  27. #define __L2CAP_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include <sys/socket.h>
  32. /* L2CAP defaults */
  33. #define L2CAP_DEFAULT_MTU 672
  34. #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF
  35. /* L2CAP socket address */
  36. struct sockaddr_l2 {
  37. sa_family_t l2_family;
  38. unsigned short l2_psm;
  39. bdaddr_t l2_bdaddr;
  40. unsigned short l2_cid;
  41. uint8_t l2_bdaddr_type;
  42. };
  43. /* L2CAP socket options */
  44. #define L2CAP_OPTIONS 0x01
  45. struct l2cap_options {
  46. uint16_t omtu;
  47. uint16_t imtu;
  48. uint16_t flush_to;
  49. uint8_t mode;
  50. uint8_t fcs;
  51. uint8_t max_tx;
  52. uint16_t txwin_size;
  53. };
  54. #define L2CAP_CONNINFO 0x02
  55. struct l2cap_conninfo {
  56. uint16_t hci_handle;
  57. uint8_t dev_class[3];
  58. };
  59. #define L2CAP_LM 0x03
  60. #define L2CAP_LM_MASTER 0x0001
  61. #define L2CAP_LM_AUTH 0x0002
  62. #define L2CAP_LM_ENCRYPT 0x0004
  63. #define L2CAP_LM_TRUSTED 0x0008
  64. #define L2CAP_LM_RELIABLE 0x0010
  65. #define L2CAP_LM_SECURE 0x0020
  66. /* L2CAP command codes */
  67. #define L2CAP_COMMAND_REJ 0x01
  68. #define L2CAP_CONN_REQ 0x02
  69. #define L2CAP_CONN_RSP 0x03
  70. #define L2CAP_CONF_REQ 0x04
  71. #define L2CAP_CONF_RSP 0x05
  72. #define L2CAP_DISCONN_REQ 0x06
  73. #define L2CAP_DISCONN_RSP 0x07
  74. #define L2CAP_ECHO_REQ 0x08
  75. #define L2CAP_ECHO_RSP 0x09
  76. #define L2CAP_INFO_REQ 0x0a
  77. #define L2CAP_INFO_RSP 0x0b
  78. #define L2CAP_CREATE_REQ 0x0c
  79. #define L2CAP_CREATE_RSP 0x0d
  80. #define L2CAP_MOVE_REQ 0x0e
  81. #define L2CAP_MOVE_RSP 0x0f
  82. #define L2CAP_MOVE_CFM 0x10
  83. #define L2CAP_MOVE_CFM_RSP 0x11
  84. /* L2CAP extended feature mask */
  85. #define L2CAP_FEAT_FLOWCTL 0x00000001
  86. #define L2CAP_FEAT_RETRANS 0x00000002
  87. #define L2CAP_FEAT_BIDIR_QOS 0x00000004
  88. #define L2CAP_FEAT_ERTM 0x00000008
  89. #define L2CAP_FEAT_STREAMING 0x00000010
  90. #define L2CAP_FEAT_FCS 0x00000020
  91. #define L2CAP_FEAT_EXT_FLOW 0x00000040
  92. #define L2CAP_FEAT_FIXED_CHAN 0x00000080
  93. #define L2CAP_FEAT_EXT_WINDOW 0x00000100
  94. #define L2CAP_FEAT_UCD 0x00000200
  95. /* L2CAP fixed channels */
  96. #define L2CAP_FC_L2CAP 0x02
  97. #define L2CAP_FC_CONNLESS 0x04
  98. #define L2CAP_FC_A2MP 0x08
  99. /* L2CAP structures */
  100. typedef struct {
  101. uint16_t len;
  102. uint16_t cid;
  103. } __attribute__ ((packed)) l2cap_hdr;
  104. #define L2CAP_HDR_SIZE 4
  105. typedef struct {
  106. uint8_t code;
  107. uint8_t ident;
  108. uint16_t len;
  109. } __attribute__ ((packed)) l2cap_cmd_hdr;
  110. #define L2CAP_CMD_HDR_SIZE 4
  111. typedef struct {
  112. uint16_t reason;
  113. } __attribute__ ((packed)) l2cap_cmd_rej;
  114. #define L2CAP_CMD_REJ_SIZE 2
  115. typedef struct {
  116. uint16_t psm;
  117. uint16_t scid;
  118. } __attribute__ ((packed)) l2cap_conn_req;
  119. #define L2CAP_CONN_REQ_SIZE 4
  120. typedef struct {
  121. uint16_t dcid;
  122. uint16_t scid;
  123. uint16_t result;
  124. uint16_t status;
  125. } __attribute__ ((packed)) l2cap_conn_rsp;
  126. #define L2CAP_CONN_RSP_SIZE 8
  127. /* connect result */
  128. #define L2CAP_CR_SUCCESS 0x0000
  129. #define L2CAP_CR_PEND 0x0001
  130. #define L2CAP_CR_BAD_PSM 0x0002
  131. #define L2CAP_CR_SEC_BLOCK 0x0003
  132. #define L2CAP_CR_NO_MEM 0x0004
  133. /* connect status */
  134. #define L2CAP_CS_NO_INFO 0x0000
  135. #define L2CAP_CS_AUTHEN_PEND 0x0001
  136. #define L2CAP_CS_AUTHOR_PEND 0x0002
  137. typedef struct {
  138. uint16_t dcid;
  139. uint16_t flags;
  140. uint8_t data[0];
  141. } __attribute__ ((packed)) l2cap_conf_req;
  142. #define L2CAP_CONF_REQ_SIZE 4
  143. typedef struct {
  144. uint16_t scid;
  145. uint16_t flags;
  146. uint16_t result;
  147. uint8_t data[0];
  148. } __attribute__ ((packed)) l2cap_conf_rsp;
  149. #define L2CAP_CONF_RSP_SIZE 6
  150. #define L2CAP_CONF_SUCCESS 0x0000
  151. #define L2CAP_CONF_UNACCEPT 0x0001
  152. #define L2CAP_CONF_REJECT 0x0002
  153. #define L2CAP_CONF_UNKNOWN 0x0003
  154. #define L2CAP_CONF_PENDING 0x0004
  155. #define L2CAP_CONF_EFS_REJECT 0x0005
  156. typedef struct {
  157. uint8_t type;
  158. uint8_t len;
  159. uint8_t val[0];
  160. } __attribute__ ((packed)) l2cap_conf_opt;
  161. #define L2CAP_CONF_OPT_SIZE 2
  162. #define L2CAP_CONF_MTU 0x01
  163. #define L2CAP_CONF_FLUSH_TO 0x02
  164. #define L2CAP_CONF_QOS 0x03
  165. #define L2CAP_CONF_RFC 0x04
  166. #define L2CAP_CONF_FCS 0x05
  167. #define L2CAP_CONF_EFS 0x06
  168. #define L2CAP_CONF_EWS 0x07
  169. #define L2CAP_CONF_MAX_SIZE 22
  170. #define L2CAP_MODE_BASIC 0x00
  171. #define L2CAP_MODE_RETRANS 0x01
  172. #define L2CAP_MODE_FLOWCTL 0x02
  173. #define L2CAP_MODE_ERTM 0x03
  174. #define L2CAP_MODE_STREAMING 0x04
  175. #define L2CAP_SERVTYPE_NOTRAFFIC 0x00
  176. #define L2CAP_SERVTYPE_BESTEFFORT 0x01
  177. #define L2CAP_SERVTYPE_GUARANTEED 0x02
  178. typedef struct {
  179. uint16_t dcid;
  180. uint16_t scid;
  181. } __attribute__ ((packed)) l2cap_disconn_req;
  182. #define L2CAP_DISCONN_REQ_SIZE 4
  183. typedef struct {
  184. uint16_t dcid;
  185. uint16_t scid;
  186. } __attribute__ ((packed)) l2cap_disconn_rsp;
  187. #define L2CAP_DISCONN_RSP_SIZE 4
  188. typedef struct {
  189. uint16_t type;
  190. } __attribute__ ((packed)) l2cap_info_req;
  191. #define L2CAP_INFO_REQ_SIZE 2
  192. typedef struct {
  193. uint16_t type;
  194. uint16_t result;
  195. uint8_t data[0];
  196. } __attribute__ ((packed)) l2cap_info_rsp;
  197. #define L2CAP_INFO_RSP_SIZE 4
  198. /* info type */
  199. #define L2CAP_IT_CL_MTU 0x0001
  200. #define L2CAP_IT_FEAT_MASK 0x0002
  201. /* info result */
  202. #define L2CAP_IR_SUCCESS 0x0000
  203. #define L2CAP_IR_NOTSUPP 0x0001
  204. typedef struct {
  205. uint16_t psm;
  206. uint16_t scid;
  207. uint8_t id;
  208. } __attribute__ ((packed)) l2cap_create_req;
  209. #define L2CAP_CREATE_REQ_SIZE 5
  210. typedef struct {
  211. uint16_t dcid;
  212. uint16_t scid;
  213. uint16_t result;
  214. uint16_t status;
  215. } __attribute__ ((packed)) l2cap_create_rsp;
  216. #define L2CAP_CREATE_RSP_SIZE 8
  217. typedef struct {
  218. uint16_t icid;
  219. uint8_t id;
  220. } __attribute__ ((packed)) l2cap_move_req;
  221. #define L2CAP_MOVE_REQ_SIZE 3
  222. typedef struct {
  223. uint16_t icid;
  224. uint16_t result;
  225. } __attribute__ ((packed)) l2cap_move_rsp;
  226. #define L2CAP_MOVE_RSP_SIZE 4
  227. typedef struct {
  228. uint16_t icid;
  229. uint16_t result;
  230. } __attribute__ ((packed)) l2cap_move_cfm;
  231. #define L2CAP_MOVE_CFM_SIZE 4
  232. typedef struct {
  233. uint16_t icid;
  234. } __attribute__ ((packed)) l2cap_move_cfm_rsp;
  235. #define L2CAP_MOVE_CFM_RSP_SIZE 2
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif /* __L2CAP_H */