l2cap.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2000-2001 Qualcomm Incorporated
  7. * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
  8. * Copyright (C) 2002-2010 Marcel Holtmann <marcel@holtmann.org>
  9. * Copyright (c) 2012 Code Aurora Forum. All rights reserved.
  10. *
  11. *
  12. */
  13. #ifndef __L2CAP_H
  14. #define __L2CAP_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <sys/socket.h>
  19. /* L2CAP defaults */
  20. #define L2CAP_DEFAULT_MTU 672
  21. #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF
  22. /* L2CAP socket address */
  23. struct sockaddr_l2 {
  24. sa_family_t l2_family;
  25. unsigned short l2_psm;
  26. bdaddr_t l2_bdaddr;
  27. unsigned short l2_cid;
  28. uint8_t l2_bdaddr_type;
  29. };
  30. /* L2CAP socket options */
  31. #define L2CAP_OPTIONS 0x01
  32. struct l2cap_options {
  33. uint16_t omtu;
  34. uint16_t imtu;
  35. uint16_t flush_to;
  36. uint8_t mode;
  37. uint8_t fcs;
  38. uint8_t max_tx;
  39. uint16_t txwin_size;
  40. };
  41. #define L2CAP_CONNINFO 0x02
  42. struct l2cap_conninfo {
  43. uint16_t hci_handle;
  44. uint8_t 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. #define L2CAP_CREATE_REQ 0x0c
  66. #define L2CAP_CREATE_RSP 0x0d
  67. #define L2CAP_MOVE_REQ 0x0e
  68. #define L2CAP_MOVE_RSP 0x0f
  69. #define L2CAP_MOVE_CFM 0x10
  70. #define L2CAP_MOVE_CFM_RSP 0x11
  71. /* L2CAP extended feature mask */
  72. #define L2CAP_FEAT_FLOWCTL 0x00000001
  73. #define L2CAP_FEAT_RETRANS 0x00000002
  74. #define L2CAP_FEAT_BIDIR_QOS 0x00000004
  75. #define L2CAP_FEAT_ERTM 0x00000008
  76. #define L2CAP_FEAT_STREAMING 0x00000010
  77. #define L2CAP_FEAT_FCS 0x00000020
  78. #define L2CAP_FEAT_EXT_FLOW 0x00000040
  79. #define L2CAP_FEAT_FIXED_CHAN 0x00000080
  80. #define L2CAP_FEAT_EXT_WINDOW 0x00000100
  81. #define L2CAP_FEAT_UCD 0x00000200
  82. /* L2CAP fixed channels */
  83. #define L2CAP_FC_L2CAP 0x02
  84. #define L2CAP_FC_CONNLESS 0x04
  85. #define L2CAP_FC_A2MP 0x08
  86. /* L2CAP structures */
  87. typedef struct {
  88. uint16_t len;
  89. uint16_t cid;
  90. } __attribute__ ((packed)) l2cap_hdr;
  91. #define L2CAP_HDR_SIZE 4
  92. typedef struct {
  93. uint8_t code;
  94. uint8_t ident;
  95. uint16_t len;
  96. } __attribute__ ((packed)) l2cap_cmd_hdr;
  97. #define L2CAP_CMD_HDR_SIZE 4
  98. typedef struct {
  99. uint16_t reason;
  100. } __attribute__ ((packed)) l2cap_cmd_rej;
  101. #define L2CAP_CMD_REJ_SIZE 2
  102. typedef struct {
  103. uint16_t psm;
  104. uint16_t scid;
  105. } __attribute__ ((packed)) l2cap_conn_req;
  106. #define L2CAP_CONN_REQ_SIZE 4
  107. typedef struct {
  108. uint16_t dcid;
  109. uint16_t scid;
  110. uint16_t result;
  111. uint16_t status;
  112. } __attribute__ ((packed)) l2cap_conn_rsp;
  113. #define L2CAP_CONN_RSP_SIZE 8
  114. /* connect result */
  115. #define L2CAP_CR_SUCCESS 0x0000
  116. #define L2CAP_CR_PEND 0x0001
  117. #define L2CAP_CR_BAD_PSM 0x0002
  118. #define L2CAP_CR_SEC_BLOCK 0x0003
  119. #define L2CAP_CR_NO_MEM 0x0004
  120. /* connect status */
  121. #define L2CAP_CS_NO_INFO 0x0000
  122. #define L2CAP_CS_AUTHEN_PEND 0x0001
  123. #define L2CAP_CS_AUTHOR_PEND 0x0002
  124. typedef struct {
  125. uint16_t dcid;
  126. uint16_t flags;
  127. uint8_t data[0];
  128. } __attribute__ ((packed)) l2cap_conf_req;
  129. #define L2CAP_CONF_REQ_SIZE 4
  130. typedef struct {
  131. uint16_t scid;
  132. uint16_t flags;
  133. uint16_t result;
  134. uint8_t data[0];
  135. } __attribute__ ((packed)) l2cap_conf_rsp;
  136. #define L2CAP_CONF_RSP_SIZE 6
  137. #define L2CAP_CONF_SUCCESS 0x0000
  138. #define L2CAP_CONF_UNACCEPT 0x0001
  139. #define L2CAP_CONF_REJECT 0x0002
  140. #define L2CAP_CONF_UNKNOWN 0x0003
  141. #define L2CAP_CONF_PENDING 0x0004
  142. #define L2CAP_CONF_EFS_REJECT 0x0005
  143. typedef struct {
  144. uint8_t type;
  145. uint8_t len;
  146. uint8_t val[0];
  147. } __attribute__ ((packed)) l2cap_conf_opt;
  148. #define L2CAP_CONF_OPT_SIZE 2
  149. #define L2CAP_CONF_MTU 0x01
  150. #define L2CAP_CONF_FLUSH_TO 0x02
  151. #define L2CAP_CONF_QOS 0x03
  152. #define L2CAP_CONF_RFC 0x04
  153. #define L2CAP_CONF_FCS 0x05
  154. #define L2CAP_CONF_EFS 0x06
  155. #define L2CAP_CONF_EWS 0x07
  156. #define L2CAP_CONF_MAX_SIZE 22
  157. #define L2CAP_MODE_BASIC 0x00
  158. #define L2CAP_MODE_RETRANS 0x01
  159. #define L2CAP_MODE_FLOWCTL 0x02
  160. #define L2CAP_MODE_ERTM 0x03
  161. #define L2CAP_MODE_STREAMING 0x04
  162. #define L2CAP_SERVTYPE_NOTRAFFIC 0x00
  163. #define L2CAP_SERVTYPE_BESTEFFORT 0x01
  164. #define L2CAP_SERVTYPE_GUARANTEED 0x02
  165. typedef struct {
  166. uint16_t dcid;
  167. uint16_t scid;
  168. } __attribute__ ((packed)) l2cap_disconn_req;
  169. #define L2CAP_DISCONN_REQ_SIZE 4
  170. typedef struct {
  171. uint16_t dcid;
  172. uint16_t scid;
  173. } __attribute__ ((packed)) l2cap_disconn_rsp;
  174. #define L2CAP_DISCONN_RSP_SIZE 4
  175. typedef struct {
  176. uint16_t type;
  177. } __attribute__ ((packed)) l2cap_info_req;
  178. #define L2CAP_INFO_REQ_SIZE 2
  179. typedef struct {
  180. uint16_t type;
  181. uint16_t result;
  182. uint8_t data[0];
  183. } __attribute__ ((packed)) l2cap_info_rsp;
  184. #define L2CAP_INFO_RSP_SIZE 4
  185. /* info type */
  186. #define L2CAP_IT_CL_MTU 0x0001
  187. #define L2CAP_IT_FEAT_MASK 0x0002
  188. /* info result */
  189. #define L2CAP_IR_SUCCESS 0x0000
  190. #define L2CAP_IR_NOTSUPP 0x0001
  191. typedef struct {
  192. uint16_t psm;
  193. uint16_t scid;
  194. uint8_t id;
  195. } __attribute__ ((packed)) l2cap_create_req;
  196. #define L2CAP_CREATE_REQ_SIZE 5
  197. typedef struct {
  198. uint16_t dcid;
  199. uint16_t scid;
  200. uint16_t result;
  201. uint16_t status;
  202. } __attribute__ ((packed)) l2cap_create_rsp;
  203. #define L2CAP_CREATE_RSP_SIZE 8
  204. typedef struct {
  205. uint16_t icid;
  206. uint8_t id;
  207. } __attribute__ ((packed)) l2cap_move_req;
  208. #define L2CAP_MOVE_REQ_SIZE 3
  209. typedef struct {
  210. uint16_t icid;
  211. uint16_t result;
  212. } __attribute__ ((packed)) l2cap_move_rsp;
  213. #define L2CAP_MOVE_RSP_SIZE 4
  214. typedef struct {
  215. uint16_t icid;
  216. uint16_t result;
  217. } __attribute__ ((packed)) l2cap_move_cfm;
  218. #define L2CAP_MOVE_CFM_SIZE 4
  219. typedef struct {
  220. uint16_t icid;
  221. } __attribute__ ((packed)) l2cap_move_cfm_rsp;
  222. #define L2CAP_MOVE_CFM_RSP_SIZE 2
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif /* __L2CAP_H */