l2cap.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2000-2002 Maxim Krasnyansky <maxk@qualcomm.com>
  7. * Copyright (C) 2003-2011 Marcel Holtmann <marcel@holtmann.org>
  8. *
  9. *
  10. */
  11. #ifndef __L2CAP_H
  12. #define __L2CAP_H
  13. /* L2CAP command codes */
  14. #define L2CAP_COMMAND_REJ 0x01
  15. #define L2CAP_CONN_REQ 0x02
  16. #define L2CAP_CONN_RSP 0x03
  17. #define L2CAP_CONF_REQ 0x04
  18. #define L2CAP_CONF_RSP 0x05
  19. #define L2CAP_DISCONN_REQ 0x06
  20. #define L2CAP_DISCONN_RSP 0x07
  21. #define L2CAP_ECHO_REQ 0x08
  22. #define L2CAP_ECHO_RSP 0x09
  23. #define L2CAP_INFO_REQ 0x0a
  24. #define L2CAP_INFO_RSP 0x0b
  25. #define L2CAP_CREATE_REQ 0x0c
  26. #define L2CAP_CREATE_RSP 0x0d
  27. #define L2CAP_MOVE_REQ 0x0e
  28. #define L2CAP_MOVE_RSP 0x0f
  29. #define L2CAP_MOVE_CFM 0x10
  30. #define L2CAP_MOVE_CFM_RSP 0x11
  31. /* L2CAP extended feature mask */
  32. #define L2CAP_FEAT_FLOWCTL 0x00000001
  33. #define L2CAP_FEAT_RETRANS 0x00000002
  34. #define L2CAP_FEAT_BIDIR_QOS 0x00000004
  35. #define L2CAP_FEAT_ERTM 0x00000008
  36. #define L2CAP_FEAT_STREAMING 0x00000010
  37. #define L2CAP_FEAT_FCS 0x00000020
  38. #define L2CAP_FEAT_EXT_FLOW 0x00000040
  39. #define L2CAP_FEAT_FIXED_CHAN 0x00000080
  40. #define L2CAP_FEAT_EXT_WINDOW 0x00000100
  41. #define L2CAP_FEAT_UCD 0x00000200
  42. /* L2CAP Control Field bit masks */
  43. #define L2CAP_CTRL_SAR_MASK 0xC000
  44. #define L2CAP_CTRL_REQSEQ_MASK 0x3F00
  45. #define L2CAP_CTRL_TXSEQ_MASK 0x007E
  46. #define L2CAP_CTRL_SUPERVISE_MASK 0x000C
  47. #define L2CAP_CTRL_RETRANS 0x0080
  48. #define L2CAP_CTRL_FINAL 0x0080
  49. #define L2CAP_CTRL_POLL 0x0010
  50. #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */
  51. #define L2CAP_CTRL_TXSEQ_SHIFT 1
  52. #define L2CAP_CTRL_SUPER_SHIFT 2
  53. #define L2CAP_CTRL_REQSEQ_SHIFT 8
  54. #define L2CAP_CTRL_SAR_SHIFT 14
  55. #define L2CAP_EXT_CTRL_TXSEQ_MASK 0xFFFC0000
  56. #define L2CAP_EXT_CTRL_SAR_MASK 0x00030000
  57. #define L2CAP_EXT_CTRL_SUPERVISE_MASK 0x00030000
  58. #define L2CAP_EXT_CTRL_REQSEQ_MASK 0x0000FFFC
  59. #define L2CAP_EXT_CTRL_POLL 0x00040000
  60. #define L2CAP_EXT_CTRL_FINAL 0x00000002
  61. #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */
  62. #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2
  63. #define L2CAP_EXT_CTRL_SAR_SHIFT 16
  64. #define L2CAP_EXT_CTRL_SUPER_SHIFT 16
  65. #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18
  66. /* L2CAP Supervisory Function */
  67. #define L2CAP_SUPER_RR 0x00
  68. #define L2CAP_SUPER_REJ 0x01
  69. #define L2CAP_SUPER_RNR 0x02
  70. #define L2CAP_SUPER_SREJ 0x03
  71. /* L2CAP Segmentation and Reassembly */
  72. #define L2CAP_SAR_UNSEGMENTED 0x00
  73. #define L2CAP_SAR_START 0x01
  74. #define L2CAP_SAR_END 0x02
  75. #define L2CAP_SAR_CONTINUE 0x03
  76. #define L2CAP_SDULEN_SIZE 2
  77. /* L2CAP fixed channels */
  78. #define L2CAP_FC_L2CAP 0x02
  79. #define L2CAP_FC_CONNLESS 0x04
  80. #define L2CAP_FC_A2MP 0x08
  81. /* L2CAP structures */
  82. typedef struct {
  83. uint16_t len;
  84. uint16_t cid;
  85. } __attribute__ ((packed)) l2cap_hdr;
  86. #define L2CAP_HDR_SIZE 4
  87. typedef struct {
  88. uint8_t code;
  89. uint8_t ident;
  90. uint16_t len;
  91. } __attribute__ ((packed)) l2cap_cmd_hdr;
  92. #define L2CAP_CMD_HDR_SIZE 4
  93. typedef struct {
  94. uint16_t reason;
  95. } __attribute__ ((packed)) l2cap_cmd_rej;
  96. #define L2CAP_CMD_REJ_SIZE 2
  97. typedef struct {
  98. uint16_t psm;
  99. uint16_t scid;
  100. } __attribute__ ((packed)) l2cap_conn_req;
  101. #define L2CAP_CONN_REQ_SIZE 4
  102. typedef struct {
  103. uint16_t dcid;
  104. uint16_t scid;
  105. uint16_t result;
  106. uint16_t status;
  107. } __attribute__ ((packed)) l2cap_conn_rsp;
  108. #define L2CAP_CONN_RSP_SIZE 8
  109. /* connect result */
  110. #define L2CAP_CR_SUCCESS 0x0000
  111. #define L2CAP_CR_PEND 0x0001
  112. #define L2CAP_CR_BAD_PSM 0x0002
  113. #define L2CAP_CR_SEC_BLOCK 0x0003
  114. #define L2CAP_CR_NO_MEM 0x0004
  115. /* connect status */
  116. #define L2CAP_CS_NO_INFO 0x0000
  117. #define L2CAP_CS_AUTHEN_PEND 0x0001
  118. #define L2CAP_CS_AUTHOR_PEND 0x0002
  119. typedef struct {
  120. uint16_t dcid;
  121. uint16_t flags;
  122. uint8_t data[0];
  123. } __attribute__ ((packed)) l2cap_conf_req;
  124. #define L2CAP_CONF_REQ_SIZE 4
  125. typedef struct {
  126. uint16_t scid;
  127. uint16_t flags;
  128. uint16_t result;
  129. uint8_t data[0];
  130. } __attribute__ ((packed)) l2cap_conf_rsp;
  131. #define L2CAP_CONF_RSP_SIZE 6
  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. #define L2CAP_CONF_PENDING 0x0004
  137. #define L2CAP_CONF_EFS_REJECT 0x0005
  138. typedef struct {
  139. uint8_t type;
  140. uint8_t len;
  141. uint8_t val[0];
  142. } __attribute__ ((packed)) l2cap_conf_opt;
  143. #define L2CAP_CONF_OPT_SIZE 2
  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_EFS 0x06
  150. #define L2CAP_CONF_EWS 0x07
  151. #define L2CAP_CONF_MAX_SIZE 22
  152. #define L2CAP_MODE_BASIC 0x00
  153. #define L2CAP_MODE_RETRANS 0x01
  154. #define L2CAP_MODE_FLOWCTL 0x02
  155. #define L2CAP_MODE_ERTM 0x03
  156. #define L2CAP_MODE_STREAMING 0x04
  157. #define L2CAP_SERVTYPE_NOTRAFFIC 0x00
  158. #define L2CAP_SERVTYPE_BESTEFFORT 0x01
  159. #define L2CAP_SERVTYPE_GUARANTEED 0x02
  160. typedef struct {
  161. uint16_t dcid;
  162. uint16_t scid;
  163. } __attribute__ ((packed)) l2cap_disconn_req;
  164. #define L2CAP_DISCONN_REQ_SIZE 4
  165. typedef struct {
  166. uint16_t dcid;
  167. uint16_t scid;
  168. } __attribute__ ((packed)) l2cap_disconn_rsp;
  169. #define L2CAP_DISCONN_RSP_SIZE 4
  170. typedef struct {
  171. uint16_t type;
  172. } __attribute__ ((packed)) l2cap_info_req;
  173. #define L2CAP_INFO_REQ_SIZE 2
  174. typedef struct {
  175. uint16_t type;
  176. uint16_t result;
  177. uint8_t data[0];
  178. } __attribute__ ((packed)) l2cap_info_rsp;
  179. #define L2CAP_INFO_RSP_SIZE 4
  180. /* info type */
  181. #define L2CAP_IT_CL_MTU 0x0001
  182. #define L2CAP_IT_FEAT_MASK 0x0002
  183. /* info result */
  184. #define L2CAP_IR_SUCCESS 0x0000
  185. #define L2CAP_IR_NOTSUPP 0x0001
  186. typedef struct {
  187. uint16_t psm;
  188. uint16_t scid;
  189. uint8_t id;
  190. } __attribute__ ((packed)) l2cap_create_req;
  191. #define L2CAP_CREATE_REQ_SIZE 5
  192. typedef struct {
  193. uint16_t dcid;
  194. uint16_t scid;
  195. uint16_t result;
  196. uint16_t status;
  197. } __attribute__ ((packed)) l2cap_create_rsp;
  198. #define L2CAP_CREATE_RSP_SIZE 8
  199. typedef struct {
  200. uint16_t icid;
  201. uint8_t id;
  202. } __attribute__ ((packed)) l2cap_move_req;
  203. #define L2CAP_MOVE_REQ_SIZE 3
  204. typedef struct {
  205. uint16_t icid;
  206. uint16_t result;
  207. } __attribute__ ((packed)) l2cap_move_rsp;
  208. #define L2CAP_MOVE_RSP_SIZE 4
  209. typedef struct {
  210. uint16_t icid;
  211. uint16_t result;
  212. } __attribute__ ((packed)) l2cap_move_cfm;
  213. #define L2CAP_MOVE_CFM_SIZE 4
  214. typedef struct {
  215. uint16_t icid;
  216. } __attribute__ ((packed)) l2cap_move_cfm_rsp;
  217. #define L2CAP_MOVE_CFM_RSP_SIZE 2
  218. #endif /* __L2CAP_H */