1 /*
2  * Copyright 2019-2023, Cypress Semiconductor Corporation or
3  * an affiliate of Cypress Semiconductor Corporation.  All rights reserved.
4  *
5  * This software, including source code, documentation and related
6  * materials ("Software") is owned by Cypress Semiconductor Corporation
7  * or one of its affiliates ("Cypress") and is protected by and subject to
8  * worldwide patent protection (United States and foreign),
9  * United States copyright laws and international treaty provisions.
10  * Therefore, you may use this Software only as provided in the license
11  * agreement accompanying the software package from which you
12  * obtained this Software ("EULA").
13  * If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
14  * non-transferable license to copy, modify, and compile the Software
15  * source code solely for use in connection with Cypress's
16  * integrated circuit products.  Any reproduction, modification, translation,
17  * compilation, or representation of this Software except as specified
18  * above is prohibited without the express written permission of Cypress.
19  *
20  * Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
23  * reserves the right to make changes to the Software without notice. Cypress
24  * does not assume any liability arising out of the application or use of the
25  * Software or any product or circuit described in the Software. Cypress does
26  * not authorize its products for use in any products where a malfunction or
27  * failure of the Cypress product may reasonably be expected to result in
28  * significant property damage, injury or death ("High Risk Product"). By
29  * including Cypress's product in a High Risk Product, the manufacturer
30  * of such system or application assumes all risk of such use and in doing
31  * so agrees to indemnify Cypress against all liability.
32  */
33 
34 /** @file
35  *
36  *   This file contains L2CAP protocol definitions
37  */
38 
39 #ifndef L2CDEFS_H
40 #define L2CDEFS_H
41 
42 /**
43  * @anchor L2CAP_CMD_CODE
44  * @name L2CAP command codes
45  * @{
46  *
47  * L2CAP command codes.
48  */
49 #define L2CAP_CMD_REJECT                    0x01    /**< Reject Command */
50 #define L2CAP_CMD_CONN_REQ                  0x02    /**< Connection Request Command */
51 #define L2CAP_CMD_CONN_RSP                  0x03    /**< Connection Response */
52 #define L2CAP_CMD_CONFIG_REQ                0x04    /**< Configuration Request */
53 #define L2CAP_CMD_CONFIG_RSP                0x05    /**< Configuration Response */
54 #define L2CAP_CMD_DISC_REQ                  0x06    /**< Disconnect Request */
55 #define L2CAP_CMD_DISC_RSP                  0x07    /**< Disconnect Response */
56 #define L2CAP_CMD_ECHO_REQ                  0x08    /**< Echo Request */
57 #define L2CAP_CMD_ECHO_RSP                  0x09    /**< Echo Response */
58 #define L2CAP_CMD_INFO_REQ                  0x0A    /**< Command Information Request */
59 #define L2CAP_CMD_INFO_RSP                  0x0B    /**< Command Information Response */
60 #define L2CAP_CMD_AMP_CONN_REQ              0x0C    /**< AMP Connection Request */
61 #define L2CAP_CMD_AMP_CONN_RSP              0x0D    /**< AMP Connection Response */
62 #define L2CAP_CMD_AMP_MOVE_REQ              0x0E    /**< AMP Move Request */
63 #define L2CAP_CMD_AMP_MOVE_RSP              0x0F    /**< AMP Move Response */
64 #define L2CAP_CMD_AMP_MOVE_CFM              0x10    /**< AMP Move Confirm */
65 #define L2CAP_CMD_AMP_MOVE_CFM_RSP          0x11    /**< AMP Move Confirm Response */
66 #define L2CAP_CMD_BLE_UPDATE_REQ            0x12    /**< BLE Connection Param Update Request */
67 #define L2CAP_CMD_BLE_UPDATE_RSP            0x13    /**< BLE Connection Param Update Response */
68 #define L2CAP_CMD_LE_COC_CONN_REQ           0x14    /**< LE COC Connection Request */
69 #define L2CAP_CMD_LE_COC_CONN_RSP           0x15    /**< LE COC Connection Response */
70 #define L2CAP_CMD_CRB_CREDITS               0x16    /**< Credits */
71 #define L2CAP_CMD_ECRB_CONNECT_REQ          0x17    /**< Enhanced credit-based connection request       */
72 #define L2CAP_CMD_ECRB_CONNECT_RSP          0x18    /**< Enhanced credit-based connection response      */
73 #define L2CAP_CMD_ECRB_RECONFIG_REQ         0x19    /**< Enhanced credit-based reconfiguration request  */
74 #define L2CAP_CMD_ECRB_RECONFIG_RSP         0x1A    /**< Enhanced credit-based reconfiguration response */
75 /** @} L2CAP_CMD_CODE */
76 
77 /**
78  * @anchor L2CAP_PKT_HEADER_LEN
79  * @name L2CAP command codes
80  * @{
81  *
82  * L2CAP packet and header lengths.
83  */
84 #define L2CAP_PKT_OVERHEAD      4           /**< Length and CID                       */
85 #define L2CAP_CMD_OVERHEAD      4           /**< Cmd code, Id and length              */
86 #define L2CAP_CMD_REJECT_LEN    2           /**< Reason (data is optional)            */
87 #define L2CAP_CONN_REQ_LEN      4           /**< PSM and source CID                   */
88 #define L2CAP_CONN_RSP_LEN      8           /**< Dest CID, source CID, reason, status */
89 #define L2CAP_CONFIG_REQ_LEN    4           /**< Dest CID, flags (data is optional)   */
90 #define L2CAP_CONFIG_RSP_LEN    6           /**< Dest CID, flags, result,data optional*/
91 #define L2CAP_DISC_REQ_LEN      4           /**< Dest CID, source CID                 */
92 #define L2CAP_DISC_RSP_LEN      4           /**< Dest CID, source CID                 */
93 #define L2CAP_ECHO_REQ_LEN      0           /**< Data is optional                     */
94 #define L2CAP_ECHO_RSP_LEN      0           /**< Data is optional                     */
95 #define L2CAP_INFO_REQ_LEN      2           /**< Info type                            */
96 #define L2CAP_INFO_RSP_LEN      4           /**< Info type, result (data is optional) */
97 #define L2CAP_BCST_OVERHEAD     2           /**< Additional broadcast packet overhead */
98 #define L2CAP_UCD_OVERHEAD      2           /**< Additional connectionless packet overhead */
99 
100 #define L2CAP_AMP_CONN_REQ_LEN  5           /**< PSM, CID, and remote controller ID   */
101 #define L2CAP_AMP_MOVE_REQ_LEN  3           /**< CID and remote controller ID         */
102 #define L2CAP_AMP_MOVE_RSP_LEN  4           /**< CID and result                       */
103 #define L2CAP_AMP_MOVE_CFM_LEN  4           /**< CID and result                       */
104 #define L2CAP_AMP_MOVE_CFM_RSP_LEN  2       /**< CID                                  */
105 
106 #define L2CAP_CMD_BLE_UPD_REQ_LEN   8       /**< Min and max interval, latency, tout  */
107 #define L2CAP_CMD_BLE_UPD_RSP_LEN   2       /**< Conn update response length  */
108 
109 #define L2CAP_LE_COC_CONN_REQ_LEN   10      /**< LE_PSM, src CID, MTU, MPS, init credits  */
110 #define L2CAP_LE_COC_CONN_RSP_LEN   10      /**< Dest CID, MTU, MPS, init credits, result */
111 #define L2CAP_CRB_CREDITS_LEN        4      /**< Local CID, connection credits to add                */
112 
113 #define L2CAP_ECRB_BASE_CONN_REQ_LEN 8      /**< LE_PSM, MTU, MPS, init credits */
114 #define L2CAP_ECRB_BASE_CONN_RSP_LEN 8      /**< MTU, MPS, init credits, result */
115 #define L2CAP_ECRB_BASE_RECONFIG_REQ_LEN 4  /**< MTU, MPS */
116 #define L2CAP_ECRB_RECONFIG_RSP_LEN  2      /**< result */
117 #define L2CAP_ECRB_MAX_CONN_REQ_LEN 18      /**< LE_PSM, MTU, MPS, init credits + up to 5 CIDs */
118 #define L2CAP_ECRB_MAX_CONN_RSP_LEN 18      /**< MTU, MPS, init credits, result + up to 5 CIDs */
119 #define L2CAP_ECRB_MAX_RECONFIG_REQ_LEN 14  /**< MTU, MPS + up to 5 CIDs */
120 /** @} L2CAP_PKT_HEADER_LEN */
121 
122 /* Define the packet boundary flags
123 */
124 #define L2CAP_PKT_START_FLUSHABLE       2
125 #define L2CAP_PKT_START_NON_FLUSHABLE   0
126 #define L2CAP_COMPLETE_FLUSHABLE_PKT    3       /* complete flushable L2CAP packet */
127 #define L2CAP_PKT_START                 2
128 #define L2CAP_PKT_CONTINUE              1
129 #define L2CAP_MASK_FLAG            0x0FFF
130 #define L2CAP_PKT_TYPE_SHIFT            12
131 #define L2CAP_PKT_TYPE_MASK             3
132 
133 #define L2CAP_BLE_CONN_MIN_MPS_SIZE           23
134 #define L2CAP_BLE_CONN_MAX_MPS_SIZE           65533
135 #define L2CAP_BLE_CONN_MIN_MTU_SIZE           23
136 #define L2CAP_CRB_CONN_SDU_LEN_FIELD_SIZE     2         /* Applies to LE-COC and ECRB channel types */
137 
138 
139 #define L2CAP_CONN_TIMEOUT           0xEEEE   /**< Connection timeout @note Internal use only */
140 #define L2CAP_CONN_REJECTED          253      /**< Connection reject @note Internal use only */
141 #define L2CAP_CONN_AMP_FAILED        254      /**< Connection failed @note Internal use only */
142 #define L2CAP_CONN_NO_LINK           255      /**< NO Link @note Internal use only */
143 #define L2CAP_CONN_CANCEL            256      /**< L2CAP connection cancelled @note Internal use only */
144 
145 
146 /**
147  * @anchor L2CAP_MOVE_RESULT
148  * @name L2CAP Move Channel Response result codes
149  * @{
150  *
151  * L2CAP Move Channel Response result codes
152  */
153 #define L2CAP_MOVE_OK                   0       /**< OK */
154 #define L2CAP_MOVE_PENDING              1       /**< Pending */
155 #define L2CAP_MOVE_CTRL_ID_NOT_SUPPORT  2       /**< Control ID Not Supprted */
156 #define L2CAP_MOVE_SAME_CTRLR_ID        3       /**< Same Control ID */
157 #define L2CAP_MOVE_CONFIG_NOT_SUPPORTED 4       /**< Configuration Not Supported */
158 #define L2CAP_MOVE_CHAN_COLLISION       5       /**< Channel Collision */
159 #define L2CAP_MOVE_NOT_ALLOWED          6       /**< Not Allowed */
160 /** @} L2CAP_MOVE_RESULT */
161 
162 
163 /* Define L2CAP Move Channel Confirmation result codes
164 */
165 #define L2CAP_MOVE_CFM_OK               0   /**< Channel Move confirm Ok */
166 #define L2CAP_MOVE_CFM_REFUSED          1   /**< Channel Move confirm Refused */
167 
168 
169 /* Define the L2CAP command reject reason codes
170 */
171 #define L2CAP_CMD_REJ_NOT_UNDERSTOOD    0       /**< Command Not Understood */
172 #define L2CAP_CMD_REJ_MTU_EXCEEDED      1       /**< MTU Exceeded */
173 #define L2CAP_CMD_REJ_INVALID_CID       2       /**< Invalid CID */
174 
175 
176 /**
177  * @anchor L2CAP_PREDIFINED_CIDS
178  * @name L2CAP Predefined CIDs
179  * @{
180  *
181  * L2CAP Predefined CIDs
182  */
183 #define L2CAP_SIGNALLING_CID            1           /**< Signalling CID */
184 #define L2CAP_CONNECTIONLESS_CID        2           /**< Connectionless CID */
185 #define L2CAP_AMP_CID                   3           /**< AMP CID */
186 #define L2CAP_ATT_CID                   4           /**< Attribute CID */
187 #define L2CAP_BLE_SIGNALLING_CID        5           /**< BLE Signalling CID */
188 #define L2CAP_SMP_CID                   6           /**< SMP CID */
189 #define L2CAP_SMP_BR_CID                7           /**< SMP BR CID */
190 
191 #define L2CAP_FIRST_FIXED_CHNL          0x04        /**< First fixed channel */
192 #define L2CAP_LAST_FIXED_CHNL           0x3E        /**< Last fixed channel */
193 
194 
195 #define L2CAP_ASSIGNED_NUM_START        0x0020      /**< Channel Assigned Number Start */
196 #define L2CAP_ASSIGNED_NUM_END          0x003E      /**< Channel Assigned Number End */
197 #define L2CAP_AMP_TEST_CID              0x003F      /**< AMP Test CID */
198 #define L2CAP_BASE_APPL_CID             0x0040      /**< Dynamic : Base CID */
199 #define L2CAP_BLE_CONN_MAX_CID          0x007F      /**< Max BLE CID */
200 
201 /** @} L2CAP_PREDIFINED_CIDS */
202 
203 /**
204  * @anchor L2CAP_CHAN_MASK
205  * @name Fixed Channels mask bits
206  * @{
207  *
208  * Fixed Channels mask bits
209  */
210 #define L2CAP_FIXED_CHNL_SIG_BIT        (1 << L2CAP_SIGNALLING_CID)     /**< Signal Channel Supported (Mandatory) */
211 #define L2CAP_FIXED_CHNL_CNCTLESS_BIT   (1 << L2CAP_CONNECTIONLESS_CID) /**< Connectionless Reception             */
212 #define L2CAP_FIXED_CHNL_AMP_BIT        (1 << L2CAP_AMP_CID)            /**< AMP Manager Supported                */
213 #define L2CAP_FIXED_CHNL_ATT_BIT        (1 << L2CAP_ATT_CID)            /**< Attribute protocol Supported         */
214 #define L2CAP_FIXED_CHNL_BLE_SIG_BIT    (1 << L2CAP_BLE_SIGNALLING_CID) /**< BLE Signalling Supported             */
215 #define L2CAP_FIXED_CHNL_SMP_BIT        (1 << L2CAP_SMP_CID)            /**< BLE Security Manager Supported       */
216 #define L2CAP_FIXED_CHNL_SMP_BR_BIT     (1 << L2CAP_SMP_BR_CID)         /**< Security Manager over BR Supported   */
217 /** @} L2CAP_CHAN_MASK */
218 
219 
220 /**
221  * @anchor L2CAP_CONFIG_CODE
222  * @name L2CAP configuration result codes
223  * @{
224  *
225  * L2CAP configuration result codes
226  */
227 #define L2CAP_CFG_OK                    0       /**< Config OK */
228 #define L2CAP_CFG_UNACCEPTABLE_PARAMS   1       /**< Unacceptable Parameters */
229 #define L2CAP_CFG_FAILED_NO_REASON      2       /**< Failed with No reason */
230 #define L2CAP_CFG_UNKNOWN_OPTIONS       3       /**< Config unknown option */
231 #define L2CAP_CFG_PENDING               4       /**< Config pending */
232 #define L2CAP_CFG_FLOW_SPEC_REJECTED    5       /**< spec rejected */
233 /** @} L2CAP_CONFIG_CODE */
234 
235 
236 /**
237  * @anchor L2CAP_CONFIG_TYPE
238  * @name L2CAP configuration option types
239  * @{
240  *
241  * L2CAP configuration option types
242  */
243 #define L2CAP_CFG_TYPE_MTU              0x01        /**< MTU configuration */
244 #define L2CAP_CFG_TYPE_FLUSH_TOUT       0x02        /**< Flush Timeout configuration */
245 #define L2CAP_CFG_TYPE_QOS              0x03        /**< QOS configuration */
246 #define L2CAP_CFG_TYPE_FCR              0x04        /**< Retransmission & FLow Control configuration  */
247 #define L2CAP_CFG_TYPE_FCS              0x05        /**< Frame Check Sequence configuration */
248 #define L2CAP_CFG_TYPE_EXT_FLOW         0x06        /**< Extended Flow Specification configuration */
249 #define L2CAP_CFG_TYPE_EXT_WIN_SIZE     0x07        /**< Extended Windown Size configuration */
250 /** @} L2CAP_CONFIG_TYPE */
251 
252 /**
253  * @anchor L2CAP_CONFIG_TYPE_LEN
254  * @name L2CAP configuration option type lens
255  * @{
256  *
257  * L2CAP configuration option type len
258  */
259 #define L2CAP_CFG_MTU_OPTION_LEN        2           /**< MTU option length    */
260 #define L2CAP_CFG_FLUSH_OPTION_LEN      2           /**< Flush option len     */
261 #define L2CAP_CFG_QOS_OPTION_LEN        22          /**< QOS option length    */
262 #define L2CAP_CFG_FCR_OPTION_LEN        9           /**< FCR option length    */
263 #define L2CAP_CFG_FCS_OPTION_LEN        1           /**< FCR option length    */
264 #define L2CAP_CFG_EXT_FLOW_OPTION_LEN   16          /**< Extended Flow Spec   */
265 #define L2CAP_CFG_EXT_WIN_SIZE_LEN      2           /**< Ext window size length */
266 #define L2CAP_CFG_OPTION_OVERHEAD       2           /**< Type and length      */
267 /** @} L2CAP_CONFIG_TYPE_LEN */
268 
269 /* Configuration Cmd/Rsp Flags mask
270 */
271 #define L2CAP_CFG_FLAGS_MASK_CONT       0x0001      /**< Flags mask: Continuation */
272 
273 /* FCS Check Option values
274 */
275 #define L2CAP_CFG_FCS_BYPASS            0       /**< Bypass the FCS in streaming or ERTM modes */
276 #define L2CAP_CFG_FCS_USE               1       /**< Use the FCS in streaming or ERTM modes [default] */
277 
278 /* Default values for configuration
279 */
280 #define L2CAP_NO_AUTOMATIC_FLUSH        0xFFFF      /**< No Automatic Flush */
281 #define L2CAP_NO_RETRANSMISSION         0x0001      /**< No Retranmission */
282 
283 #define L2CAP_DEFAULT_MTU               (672)                       /**< Default MTU */
284 #define L2CAP_DEFAULT_FLUSH_TO          L2CAP_NO_AUTOMATIC_FLUSH    /**< Default Flush settings */
285 #define L2CAP_DEFAULT_SERV_TYPE         1                           /**< Default service type */
286 #define L2CAP_DEFAULT_TOKEN_RATE        0                           /**< Default Token rate */
287 #define L2CAP_DEFAULT_BUCKET_SIZE       0                           /**< Default Bucket size */
288 #define L2CAP_DEFAULT_PEAK_BANDWIDTH    0                           /**< Default Peak bandwidth */
289 #define L2CAP_DEFAULT_LATENCY           0xFFFFFFFF                  /**< Default Letency */
290 #define L2CAP_DEFAULT_DELAY             0xFFFFFFFF                  /**< Default Delay */
291 #define L2CAP_DEFAULT_FCS               L2CAP_CFG_FCS_USE           /**< Default FCS settings */
292 
293 
294 /* Define the L2CAP disconnect result codes
295 */
296 #define L2CAP_DISC_OK                   0               /**< L2CAP Disconnect Success */
297 #define L2CAP_DISC_TIMEOUT              0xEEEE          /**< L2CAP Disconnection Timeout */
298 
299 /* Define the L2CAP info resp result codes
300 */
301 #define L2CAP_INFO_RESP_RESULT_SUCCESS          0       /**< L2CAP Info response success */
302 #define L2CAP_INFO_RESP_RESULT_NOT_SUPPORTED    1       /**< L2CAP info response result not supported */
303 
304 /* Define the info-type fields of information request & response
305 */
306 #define L2CAP_CONNLESS_MTU_INFO_TYPE      0x0001    /**< Connection less MTU info type */
307 #define L2CAP_EXTENDED_FEATURES_INFO_TYPE 0x0002    /**< Extended feature Info Type. Used in Information Req/Response */
308 #define L2CAP_FIXED_CHANNELS_INFO_TYPE    0x0003    /**< Fix channel Info Type. Used in AMP                      */
309 
310 #define L2CAP_CONNLESS_MTU_INFO_SIZE           2    /**< Connectionless MTU size          */
311 #define L2CAP_EXTENDED_FEATURES_ARRAY_SIZE     4    /**< Extended features array size     */
312 #define L2CAP_FIXED_CHNL_ARRAY_SIZE            8    /**< Fixed channel array size         */
313 
314 /* Extended features mask bits
315 */
316 #define L2CAP_EXTFEA_RTRANS         0x00000001    /**< Retransmission Mode (Not Supported)    */
317 #define L2CAP_EXTFEA_FC             0x00000002    /**< Flow Control Mode   (Not Supported)    */
318 #define L2CAP_EXTFEA_QOS            0x00000004    /**< QOS Mode */
319 #define L2CAP_EXTFEA_ENH_RETRANS    0x00000008    /**< Enhanced retransmission mode           */
320 #define L2CAP_EXTFEA_STREAM_MODE    0x00000010    /**< Streaming Mode                         */
321 #define L2CAP_EXTFEA_NO_CRC         0x00000020    /**< Optional FCS (if set No FCS desired)   */
322 #define L2CAP_EXTFEA_EXT_FLOW_SPEC  0x00000040    /**< Extended flow spec                     */
323 #define L2CAP_EXTFEA_FIXED_CHNLS    0x00000080    /**< Fixed channels                         */
324 #define L2CAP_EXTFEA_EXT_WINDOW     0x00000100    /**< Extended Window Size                   */
325 #define L2CAP_EXTFEA_UCD_RECEPTION  0x00000200    /**< Unicast Connectionless Data Reception  */
326 #define L2CAP_EXTFEA_ECRB_SUPPORTED 0x00000400    /**< Unicast Connectionless Data Reception  */
327 
328 /** Mask for LE supported features used in Information Response (default to none) */
329 #ifndef L2CAP_BLE_EXTFEA_MASK
330 #define L2CAP_BLE_EXTFEA_MASK 0
331 #endif
332 
333 /** Define a value that tells L2CAP to use the default MPS */
334 #define L2CAP_DEFAULT_ERM_MPS           0x0000
335 
336 #define L2CAP_FCR_OVERHEAD         2   /**< Control word                 */
337 #define L2CAP_FCS_LEN              2   /**< FCS takes 2 bytes */
338 #define L2CAP_SDU_LEN_OVERHEAD     2   /**< SDU length field is 2 bytes */
339 #define L2CAP_SDU_LEN_OFFSET       2   /**< SDU length offset is 2 bytes */
340 #define L2CAP_EXT_CONTROL_OVERHEAD 4   /**< Extended Control Field       */
341 #define L2CAP_MAX_HEADER_FCS       (L2CAP_PKT_OVERHEAD + L2CAP_EXT_CONTROL_OVERHEAD + L2CAP_SDU_LEN_OVERHEAD + L2CAP_FCS_LEN)
342                                    /**< length(2), channel(2), control(4), SDU length(2) FCS(2) */
343 /** Part of L2CAP_MINIMUM_OFFSET that is not part of L2CAP */
344 #define L2CAP_OFFSET_WO_L2HDR  (L2CAP_MINIMUM_OFFSET-(L2CAP_PKT_OVERHEAD+L2CAP_FCR_OVERHEAD))
345 
346 /* SAR bits in the control word
347 */
348 #define L2CAP_FCR_UNSEG_SDU    0x0000   /**< Control word to begin with for unsegmented PDU*/
349 #define L2CAP_FCR_START_SDU    0x4000   /**< ..for Starting PDU of a semented SDU */
350 #define L2CAP_FCR_END_SDU      0x8000   /**< ..for ending PDU of a segmented SDU */
351 #define L2CAP_FCR_CONT_SDU     0xc000   /**< ..for continuation PDU of a segmented SDU */
352 
353 /* Supervisory frame types
354 */
355 #define L2CAP_FCR_SUP_RR        0x0000   /**< Supervisory frame - RR                          */
356 #define L2CAP_FCR_SUP_REJ       0x0001   /**< Supervisory frame - REJ                         */
357 #define L2CAP_FCR_SUP_RNR       0x0002   /**< Supervisory frame - RNR                         */
358 #define L2CAP_FCR_SUP_SREJ      0x0003   /**< Supervisory frame - SREJ                        */
359 
360 #define L2CAP_FCR_SAR_BITS           0xC000    /**< Mask to get the SAR bits from control word */
361 #define L2CAP_FCR_SAR_BITS_SHIFT     14        /**< Bits to shift right to get the SAR bits from ctrl-word */
362 
363 #define L2CAP_FCR_S_FRAME_BIT         0x0001   /**< Mask to check if a PDU is S-frame */
364 #define L2CAP_FCR_REQ_SEQ_BITS        0x3F00   /**< Mask to get the req-seq from control word */
365 #define L2CAP_FCR_REQ_SEQ_BITS_SHIFT  8        /**< Bits to shift right to get the req-seq from ctrl-word */
366 #define L2CAP_FCR_TX_SEQ_BITS         0x007E   /**< Mask on get the tx-seq from control word */
367 #define L2CAP_FCR_TX_SEQ_BITS_SHIFT   1        /**< Bits to shift right to get the tx-seq from ctrl-word */
368 
369 #define L2CAP_FCR_F_BIT               0x0080   /**< F-bit in the control word (Sup and I frames)  */
370 #define L2CAP_FCR_P_BIT               0x0010   /**< P-bit in the control word (Sup frames only)   */
371 
372 #define L2CAP_FCR_F_BIT_SHIFT         7
373 #define L2CAP_FCR_P_BIT_SHIFT         4
374 
375 #define L2CAP_FCR_SEG_BITS            0xC000   /**< Mask to get the segmentation bits from ctrl-word */
376 #define L2CAP_FCR_SUP_SHIFT           2        /**< Bits to shift right to get the S-bits from ctrl-word */
377 #define L2CAP_FCR_SUP_BITS            0x000C   /**< Mask to get the supervisory bits from ctrl-word */
378 
379 #define L2CAP_FCR_INIT_CRC            0        /**< Initial state of the CRC register */
380 #define L2CAP_FCR_SEQ_MODULO          0x3F     /**< Mask for sequence numbers (range 0 - 63) */
381 
382 /*************************************************************************************************
383 ** The following definitions are only used for internal testing of ERTM at the application level
384 *************************************************************************************************/
385 /* L2CA_SetupErtmTest() corruption test types */
386 #define L2CAP_FCR_TTYPE_CORR_IFRAME     0       /**< Corrupt one or more I-frames, based on count   */
387 #define L2CAP_FCR_TTYPE_CORR_SFRAME     1       /**< Corrupt an S-frame, (acknowledgement) */
388 #define L2CAP_FCR_TTYPE_STOP_TEST       2       /**< Used when turning off a test */
389 #define L2CAP_FCR_TTYPE_GET_CID         3       /**< Returns RFCOMM cid when '0' is passed in cid argument */
390 
391 /* L2CA_SetupErtmTest() Freq */
392 #define L2CAP_FCR_FREQ_NORMAL           0       /**< A single test is run */
393 #define L2CAP_FCR_FREQ_RANDOM           1       /**< Randomly loses or corrupts a packet */
394 
395  /**
396  * @addtogroup  l2cap
397  *
398  * @{
399  */
400 
401 /**
402  * @anchor L2CAP_CONN_RESULT
403  * @name L2CAP connection result codes
404  * @{
405  *
406  * L2CAP connection result codes.
407  */
408 #define L2CAP_CONN_OK                0     /**< Connection OK */
409 #define L2CAP_CONN_PENDING           1     /**< Connection Pending */
410 #define L2CAP_CONN_NO_PSM            2     /**< Connection NO PSM */
411 #define L2CAP_CONN_SECURITY_BLOCK    3     /**< Connection Security Block */
412 #define L2CAP_CONN_NO_RESOURCES      4     /**< Connection NO Resource */
413 #define L2CAP_CONN_BAD_CTLR_ID       5     /**< Bad Controller ID */
414 
415 /**  @note AMP related */
416 #define L2CAP_BLE_CONN_BAD_AUTHENT      5     /**< BLE Connection Bad Authentication */
417 #define L2CAP_BLE_CONN_BAD_AUTHORIZ     6     /**< BLE Connection Bad Autherization */
418 #define L2CAP_BLE_CONN_BAD_KEY_SIZE     7     /**< BLE Connection Bad key size */
419 #define L2CAP_BLE_CONN_BAD_ENCRYPT      8     /**< BLE Connection Bad Encryption */
420 #define L2CAP_BLE_CONN_INVALID_CID      9     /**< Invalid Source CID */
421 #define L2CAP_BLE_CONN_CID_ALREADY_USED 10    /**< Source CID already allocated */
422 #define L2CAP_BLE_CONN_BAD_PARAMS       11    /**< Bad parameters */
423 /** @note LE COC related */
424 
425 
426 /** @} L2CAP_CONN_RESULT */
427 
428 
429 /*************************************************************************************************
430 ** The following definitions are related to credit-based flow control mode
431 *************************************************************************************************/
432 #define     L2CAP_ECRB_MIN_MTU                  64      /**< ECRB Min MTU */
433 #define     L2CAP_ECRB_MIN_MPS                  64      /**< ECRB Min MPS */
434 
435 /* ECRB Result codes
436 */
437 /**
438  * @anchor L2CAP_ECRB_RESULT
439  * @name L2CAP ECRB Result Code
440  * @{
441  *
442  * L2CAP ECRB Result Code
443  */
444 #define     L2CAP_ECRB_ALL_CONNS_SUCCESSFUL     0x0000      /**< All Connections Successful */
445 #define     L2CAP_ECRB_ALL_CONNS_REFUSED        0x0002      /**< All Connections Refused */
446 #define     L2CAP_ECRB_SOME_CONNS_REFUSED       0x0004      /**< Some Connections Refused */
447 #define     L2CAP_ECRB_INSUFF_AUTHENTICATION    0x0005      /**< Insufficient Authentication */
448 #define     L2CAP_ECRB_INSUFF_AUTHORIZATION     0x0006      /**< Insufficient Autherization */
449 #define     L2CAP_ECRB_INSUFF_KEY_SIZE          0x0007      /**< Insufficient Key size */
450 #define     L2CAP_ECRB_INSUFF_ENCRYPTION        0x0008      /**< Insufficient Encryption */
451 #define     L2CAP_ECRB_INVALID_SOURCE_CID       0x0009      /**< Invalid Source CID */
452 #define     L2CAP_ECRB_SOURCE_CID_IN_USE        0x000A      /**< Source CID in Used */
453 #define     L2CAP_ECRB_UNACCEPTABLE_PARAMS      0x000B      /**< Unacceptable Params */
454 #define     L2CAP_ECRB_INVALID_PARAMS           0x000C      /**< Invalid Params */
455 
456 #define     L2CAP_ECRB_RECONFIG_SUCCESSFUL      0x0000      /**< Reconfiguration Successful */
457 #define     L2CAP_ECRB_RECONFIG_FAIL_BAD_MTU    0x0001      /**< Reconfiguration fail : Bad MTU */
458 #define     L2CAP_ECRB_RECONFIG_FAIL_BAD_MPS    0x0002      /**< Reconfiguration fail : Bad MPS */
459 #define     L2CAP_ECRB_RECONFIG_FAIL_BAD_DCID   0x0003      /**< Reconfiguration fail : Bad DCID */
460 #define     L2CAP_ECRB_RECONFIG_FAIL_OTHER      0x0004      /**< Reconfiguration fail : Other Reason */
461 
462 
463 #define     L2CAP_ECRB_NOT_SUPPORTED_BY_PEER    0xF000      /**< Not Supported by Peer */
464 /** @} L2CAP_ECRB_RESULT */
465 
466 /**@} l2cap*/
467 
468 #endif
469