l2cdefs.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 1999-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. #ifndef L2CDEFS_H
  19. #define L2CDEFS_H
  20. /* L2CAP command codes
  21. */
  22. #define L2CAP_CMD_REJECT 0x01
  23. #define L2CAP_CMD_CONN_REQ 0x02
  24. #define L2CAP_CMD_CONN_RSP 0x03
  25. #define L2CAP_CMD_CONFIG_REQ 0x04
  26. #define L2CAP_CMD_CONFIG_RSP 0x05
  27. #define L2CAP_CMD_DISC_REQ 0x06
  28. #define L2CAP_CMD_DISC_RSP 0x07
  29. #define L2CAP_CMD_ECHO_REQ 0x08
  30. #define L2CAP_CMD_ECHO_RSP 0x09
  31. #define L2CAP_CMD_INFO_REQ 0x0A
  32. #define L2CAP_CMD_INFO_RSP 0x0B
  33. #define L2CAP_CMD_AMP_CONN_REQ 0x0C
  34. #define L2CAP_CMD_AMP_CONN_RSP 0x0D
  35. #define L2CAP_CMD_AMP_MOVE_REQ 0x0E
  36. #define L2CAP_CMD_AMP_MOVE_RSP 0x0F
  37. #define L2CAP_CMD_AMP_MOVE_CFM 0x10
  38. #define L2CAP_CMD_AMP_MOVE_CFM_RSP 0x11
  39. #define L2CAP_CMD_BLE_UPDATE_REQ 0x12
  40. #define L2CAP_CMD_BLE_UPDATE_RSP 0x13
  41. #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ 0x14
  42. #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES 0x15
  43. #define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT 0x16
  44. /* Define some packet and header lengths
  45. */
  46. #define L2CAP_PKT_OVERHEAD 4 /* Length and CID */
  47. #define L2CAP_CMD_OVERHEAD 4 /* Cmd code, Id and length */
  48. #define L2CAP_CMD_REJECT_LEN 2 /* Reason (data is optional) */
  49. #define L2CAP_CONN_REQ_LEN 4 /* PSM and source CID */
  50. #define L2CAP_CONN_RSP_LEN 8 /* Dest CID, source CID, reason, status */
  51. #define L2CAP_CONFIG_REQ_LEN 4 /* Dest CID, flags (data is optional) */
  52. #define L2CAP_CONFIG_RSP_LEN 6 /* Dest CID, flags, result,data optional*/
  53. #define L2CAP_DISC_REQ_LEN 4 /* Dest CID, source CID */
  54. #define L2CAP_DISC_RSP_LEN 4 /* Dest CID, source CID */
  55. #define L2CAP_ECHO_REQ_LEN 0 /* Data is optional */
  56. #define L2CAP_ECHO_RSP_LEN 0 /* Data is optional */
  57. #define L2CAP_INFO_REQ_LEN 2 /* Info type */
  58. #define L2CAP_INFO_RSP_LEN 4 /* Info type, result (data is optional) */
  59. #define L2CAP_BCST_OVERHEAD 2 /* Additional broadcast packet overhead */
  60. #define L2CAP_UCD_OVERHEAD 2 /* Additional connectionless packet overhead */
  61. #define L2CAP_AMP_CONN_REQ_LEN 5 /* PSM, CID, and remote controller ID */
  62. #define L2CAP_AMP_MOVE_REQ_LEN 3 /* CID and remote controller ID */
  63. #define L2CAP_AMP_MOVE_RSP_LEN 4 /* CID and result */
  64. #define L2CAP_AMP_MOVE_CFM_LEN 4 /* CID and result */
  65. #define L2CAP_AMP_MOVE_CFM_RSP_LEN 2 /* CID */
  66. #define L2CAP_CMD_BLE_UPD_REQ_LEN 8 /* Min and max interval, latency, tout */
  67. #define L2CAP_CMD_BLE_UPD_RSP_LEN 2 /* Result */
  68. #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_REQ_LEN 10 /* LE_PSM, SCID, MTU, MPS, Init Credit */
  69. #define L2CAP_CMD_BLE_CREDIT_BASED_CONN_RES_LEN 10 /* DCID, MTU, MPS, Init credit, Result */
  70. #define L2CAP_CMD_BLE_FLOW_CTRL_CREDIT_LEN 4 /* CID, Credit */
  71. /* Define the packet boundary flags
  72. */
  73. #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
  74. #define L2CAP_PKT_START_FLUSHABLE 2
  75. #define L2CAP_PKT_START_NON_FLUSHABLE 0
  76. #endif
  77. #define L2CAP_COMPLETE_AMP_PKT 3 /* complete L2CAP packet on AMP HCI */
  78. #define L2CAP_PKT_START 2
  79. #define L2CAP_PKT_CONTINUE 1
  80. #define L2CAP_MASK_FLAG 0x0FFF
  81. #define L2CAP_PKT_TYPE_SHIFT 12
  82. #define L2CAP_PKT_TYPE_MASK 3
  83. /* Define the L2CAP connection result codes
  84. */
  85. #define L2CAP_CONN_OK 0
  86. #define L2CAP_CONN_PENDING 1
  87. #define L2CAP_CONN_NO_PSM 2
  88. #define L2CAP_CONN_SECURITY_BLOCK 3
  89. #define L2CAP_CONN_NO_RESOURCES 4
  90. #define L2CAP_CONN_BAD_CTLR_ID 5 /* AMP related */
  91. #define L2CAP_CONN_TIMEOUT 0xEEEE
  92. #define L2CAP_CONN_AMP_FAILED 254
  93. #define L2CAP_CONN_NO_LINK 255 /* Add a couple of our own for internal use */
  94. #define L2CAP_CONN_CANCEL 256 /* L2CAP connection cancelled */
  95. /* Define L2CAP Move Channel Response result codes
  96. */
  97. #define L2CAP_MOVE_OK 0
  98. #define L2CAP_MOVE_PENDING 1
  99. #define L2CAP_MOVE_CTRL_ID_NOT_SUPPORT 2
  100. #define L2CAP_MOVE_SAME_CTRLR_ID 3
  101. #define L2CAP_MOVE_CONFIG_NOT_SUPPORTED 4
  102. #define L2CAP_MOVE_CHAN_COLLISION 5
  103. #define L2CAP_MOVE_NOT_ALLOWED 6
  104. /* Define L2CAP Move Channel Confirmation result codes
  105. */
  106. #define L2CAP_MOVE_CFM_OK 0
  107. #define L2CAP_MOVE_CFM_REFUSED 1
  108. /* Define the L2CAP command reject reason codes
  109. */
  110. #define L2CAP_CMD_REJ_NOT_UNDERSTOOD 0
  111. #define L2CAP_CMD_REJ_MTU_EXCEEDED 1
  112. #define L2CAP_CMD_REJ_INVALID_CID 2
  113. /* L2CAP Predefined CIDs
  114. */
  115. #define L2CAP_SIGNALLING_CID 1
  116. #define L2CAP_CONNECTIONLESS_CID 2
  117. #define L2CAP_AMP_CID 3
  118. #define L2CAP_ATT_CID 4
  119. #define L2CAP_BLE_SIGNALLING_CID 5
  120. #define L2CAP_SMP_CID 6
  121. #define L2CAP_SMP_BR_CID 7
  122. #define L2CAP_AMP_TEST_CID 0x003F
  123. #define L2CAP_BASE_APPL_CID 0x0040
  124. #define L2CAP_BLE_CONN_MAX_CID 0x007F
  125. /* Fixed Channels mask bits */
  126. /* Signal channel supported (Mandatory) */
  127. #define L2CAP_FIXED_CHNL_SIG_BIT (1 << L2CAP_SIGNALLING_CID)
  128. /* Connectionless reception */
  129. #define L2CAP_FIXED_CHNL_CNCTLESS_BIT (1 << L2CAP_CONNECTIONLESS_CID)
  130. /* AMP Manager supported */
  131. #define L2CAP_FIXED_CHNL_AMP_BIT (1 << L2CAP_AMP_CID)
  132. /* Attribute protocol supported */
  133. #define L2CAP_FIXED_CHNL_ATT_BIT (1 << L2CAP_ATT_CID)
  134. /* BLE Signalling supported */
  135. #define L2CAP_FIXED_CHNL_BLE_SIG_BIT (1 << L2CAP_BLE_SIGNALLING_CID)
  136. /* BLE Security Mgr supported */
  137. #define L2CAP_FIXED_CHNL_SMP_BIT (1 << L2CAP_SMP_CID)
  138. /* Security Mgr over BR supported */
  139. #define L2CAP_FIXED_CHNL_SMP_BR_BIT (1 << L2CAP_SMP_BR_CID)
  140. /* Define the L2CAP configuration result codes
  141. */
  142. #define L2CAP_CFG_OK 0
  143. #define L2CAP_CFG_UNACCEPTABLE_PARAMS 1
  144. #define L2CAP_CFG_FAILED_NO_REASON 2
  145. #define L2CAP_CFG_UNKNOWN_OPTIONS 3
  146. #define L2CAP_CFG_PENDING 4
  147. #define L2CAP_CFG_FLOW_SPEC_REJECTED 5
  148. /* Define the L2CAP configuration option types
  149. */
  150. #define L2CAP_CFG_TYPE_MTU 0x01
  151. #define L2CAP_CFG_TYPE_FLUSH_TOUT 0x02
  152. #define L2CAP_CFG_TYPE_QOS 0x03
  153. #define L2CAP_CFG_TYPE_FCR 0x04
  154. #define L2CAP_CFG_TYPE_FCS 0x05
  155. #define L2CAP_CFG_TYPE_EXT_FLOW 0x06
  156. #define L2CAP_CFG_TYPE_EXT_WIN_SIZE 0x07
  157. #define L2CAP_CFG_MTU_OPTION_LEN 2 /* MTU option length */
  158. #define L2CAP_CFG_FLUSH_OPTION_LEN 2 /* Flush option len */
  159. #define L2CAP_CFG_QOS_OPTION_LEN 22 /* QOS option length */
  160. #define L2CAP_CFG_FCR_OPTION_LEN 9 /* FCR option length */
  161. #define L2CAP_CFG_FCS_OPTION_LEN 1 /* FCR option length */
  162. #define L2CAP_CFG_EXT_FLOW_OPTION_LEN 16 /* Extended Flow Spec */
  163. #define L2CAP_CFG_EXT_WIN_SIZE_LEN 2 /* Ext window size length */
  164. #define L2CAP_CFG_OPTION_OVERHEAD 2 /* Type and length */
  165. /* Configuration Cmd/Rsp Flags mask
  166. */
  167. #define L2CAP_CFG_FLAGS_MASK_CONT 0x0001 /* Flags mask: Continuation */
  168. /* FCS Check Option values
  169. */
  170. #define L2CAP_CFG_FCS_BYPASS 0 /* Bypass the FCS in streaming or ERTM modes */
  171. #define L2CAP_CFG_FCS_USE 1 /* Use the FCS in streaming or ERTM modes [default] */
  172. /* Default values for configuration
  173. */
  174. #define L2CAP_NO_AUTOMATIC_FLUSH 0xFFFF
  175. #define L2CAP_NO_RETRANSMISSION 0x0001
  176. #define L2CAP_DEFAULT_MTU (672)
  177. #define L2CAP_DEFAULT_FLUSH_TO L2CAP_NO_AUTOMATIC_FLUSH
  178. #define L2CAP_DEFAULT_SERV_TYPE 1
  179. #define L2CAP_DEFAULT_TOKEN_RATE 0
  180. #define L2CAP_DEFAULT_BUCKET_SIZE 0
  181. #define L2CAP_DEFAULT_PEAK_BANDWIDTH 0
  182. #define L2CAP_DEFAULT_LATENCY 0xFFFFFFFF
  183. #define L2CAP_DEFAULT_DELAY 0xFFFFFFFF
  184. #define L2CAP_DEFAULT_FCS L2CAP_CFG_FCS_USE
  185. /* Define the L2CAP disconnect result codes
  186. */
  187. #define L2CAP_DISC_OK 0
  188. #define L2CAP_DISC_TIMEOUT 0xEEEE
  189. /* Define the L2CAP info resp result codes
  190. */
  191. #define L2CAP_INFO_RESP_RESULT_SUCCESS 0
  192. #define L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED 1
  193. /* Define the info-type fields of information request & response
  194. */
  195. #define L2CAP_CONNLESS_MTU_INFO_TYPE 0x0001
  196. #define L2CAP_EXTENDED_FEATURES_INFO_TYPE 0x0002 /* Used in Information Req/Response */
  197. #define L2CAP_FIXED_CHANNELS_INFO_TYPE 0x0003 /* Used in AMP */
  198. #define L2CAP_CONNLESS_MTU_INFO_SIZE 2 /* Connectionless MTU size */
  199. #define L2CAP_EXTENDED_FEATURES_ARRAY_SIZE 4 /* Extended features array size */
  200. #define L2CAP_FIXED_CHNL_ARRAY_SIZE 8 /* Fixed channel array size */
  201. /* Extended features mask bits
  202. */
  203. #define L2CAP_EXTFEA_RTRANS 0x00000001 /* Retransmission Mode (Not Supported) */
  204. #define L2CAP_EXTFEA_FC 0x00000002 /* Flow Control Mode (Not Supported) */
  205. #define L2CAP_EXTFEA_QOS 0x00000004
  206. #define L2CAP_EXTFEA_ENH_RETRANS 0x00000008 /* Enhanced retransmission mode */
  207. #define L2CAP_EXTFEA_STREAM_MODE 0x00000010 /* Streaming Mode */
  208. #define L2CAP_EXTFEA_NO_CRC 0x00000020 /* Optional FCS (if set No FCS desired) */
  209. #define L2CAP_EXTFEA_EXT_FLOW_SPEC 0x00000040 /* Extended flow spec */
  210. #define L2CAP_EXTFEA_FIXED_CHNLS 0x00000080 /* Fixed channels */
  211. #define L2CAP_EXTFEA_EXT_WINDOW 0x00000100 /* Extended Window Size */
  212. #define L2CAP_EXTFEA_UCD_RECEPTION 0x00000200 /* Unicast Connectionless Data Reception */
  213. /* Mask for locally supported features used in Information Response (default to none) */
  214. #ifndef L2CAP_EXTFEA_SUPPORTED_MASK
  215. #define L2CAP_EXTFEA_SUPPORTED_MASK 0
  216. #endif
  217. /* Mask for LE supported features used in Information Response (default to none) */
  218. #ifndef L2CAP_BLE_EXTFEA_MASK
  219. #define L2CAP_BLE_EXTFEA_MASK 0
  220. #endif
  221. /* Define a value that tells L2CAP to use the default HCI ACL buffer size */
  222. #define L2CAP_INVALID_ERM_BUF_SIZE 0
  223. /* Define a value that tells L2CAP to use the default MPS */
  224. #define L2CAP_DEFAULT_ERM_MPS 0x0000
  225. #define L2CAP_FCR_OVERHEAD 2 /* Control word */
  226. #define L2CAP_FCS_LEN 2 /* FCS takes 2 bytes */
  227. #define L2CAP_SDU_LEN_OVERHEAD 2 /* SDU length field is 2 bytes */
  228. #define L2CAP_SDU_LEN_OFFSET 2 /* SDU length offset is 2 bytes */
  229. #define L2CAP_EXT_CONTROL_OVERHEAD 4 /* Extended Control Field */
  230. #define L2CAP_MAX_HEADER_FCS (L2CAP_PKT_OVERHEAD + L2CAP_EXT_CONTROL_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN)
  231. /* length(2), channel(2), control(4), SDU length(2) FCS(2) */
  232. /* To optimize this, it must be a multiplum of the L2CAP PDU length AND match the 3DH5 air
  233. * including the l2cap headers in each packet - to match the latter - the -5 is added
  234. */
  235. #define L2CAP_MAX_SDU_LENGTH (8080 + 26 - (L2CAP_MIN_OFFSET + 6))
  236. #define L2CAP_MAX_BUF_SIZE (10240 + 24)
  237. /* Part of L2CAP_MIN_OFFSET that is not part of L2CAP
  238. */
  239. #define L2CAP_OFFSET_WO_L2HDR (L2CAP_MIN_OFFSET-(L2CAP_PKT_OVERHEAD+L2CAP_FCR_OVERHEAD))
  240. /* SAR bits in the control word
  241. */
  242. #define L2CAP_FCR_UNSEG_SDU 0x0000 /* Control word to begin with for unsegmented PDU*/
  243. #define L2CAP_FCR_START_SDU 0x4000 /* ...for Starting PDU of a semented SDU */
  244. #define L2CAP_FCR_END_SDU 0x8000 /* ...for ending PDU of a segmented SDU */
  245. #define L2CAP_FCR_CONT_SDU 0xc000 /* ...for continuation PDU of a segmented SDU */
  246. /* Supervisory frame types
  247. */
  248. #define L2CAP_FCR_SUP_RR 0x0000 /* Supervisory frame - RR */
  249. #define L2CAP_FCR_SUP_REJ 0x0001 /* Supervisory frame - REJ */
  250. #define L2CAP_FCR_SUP_RNR 0x0002 /* Supervisory frame - RNR */
  251. #define L2CAP_FCR_SUP_SREJ 0x0003 /* Supervisory frame - SREJ */
  252. #define L2CAP_FCR_SAR_BITS 0xC000 /* Mask to get the SAR bits from control word */
  253. #define L2CAP_FCR_SAR_BITS_SHIFT 14 /* Bits to shift right to get the SAR bits from ctrl-word */
  254. #define L2CAP_FCR_S_FRAME_BIT 0x0001 /* Mask to check if a PDU is S-frame */
  255. #define L2CAP_FCR_REQ_SEQ_BITS 0x3F00 /* Mask to get the req-seq from control word */
  256. #define L2CAP_FCR_REQ_SEQ_BITS_SHIFT 8 /* Bits to shift right to get the req-seq from ctrl-word */
  257. #define L2CAP_FCR_TX_SEQ_BITS 0x007E /* Mask on get the tx-seq from control word */
  258. #define L2CAP_FCR_TX_SEQ_BITS_SHIFT 1 /* Bits to shift right to get the tx-seq from ctrl-word */
  259. #define L2CAP_FCR_F_BIT 0x0080 /* F-bit in the control word (Sup and I frames) */
  260. #define L2CAP_FCR_P_BIT 0x0010 /* P-bit in the control word (Sup frames only) */
  261. #define L2CAP_FCR_F_BIT_SHIFT 7
  262. #define L2CAP_FCR_P_BIT_SHIFT 4
  263. #define L2CAP_FCR_SEG_BITS 0xC000 /* Mask to get the segmentation bits from ctrl-word */
  264. #define L2CAP_FCR_SUP_SHIFT 2 /* Bits to shift right to get the S-bits from ctrl-word */
  265. #define L2CAP_FCR_SUP_BITS 0x000C /* Mask to get the supervisory bits from ctrl-word */
  266. #define L2CAP_FCR_INIT_CRC 0 /* Initial state of the CRC register */
  267. #define L2CAP_FCR_SEQ_MODULO 0x3F /* Mask for sequence numbers (range 0 - 63) */
  268. #endif