1 /** 2 **************************************************************************************** 3 * 4 * @file l2cc_task.h 5 * 6 * @brief Header file - L2CCTASK. 7 * 8 * Copyright (C) RivieraWaves 2009-2016 9 * 10 * 11 **************************************************************************************** 12 */ 13 14 #ifndef L2CC_TASK_H_ 15 #define L2CC_TASK_H_ 16 17 /** 18 **************************************************************************************** 19 * @addtogroup L2CCTASK Task 20 * @ingroup L2CC 21 * @brief Handles ALL messages to/from L2CC block. 22 * 23 * The L2CC task is responsible for L2CAP attribute and security block handling. 24 * 25 * @{ 26 **************************************************************************************** 27 */ 28 29 /* 30 * INCLUDE FILES 31 **************************************************************************************** 32 */ 33 #include "rwip_task.h" // Task definitions 34 //#include "compiler.h" 35 #include "ble_arch.h" 36 #include <stdbool.h> 37 38 /* 39 * MACRO DEFINITIONS 40 **************************************************************************************** 41 */ 42 43 /// Number of L2CC Deprecated messages 44 #define L2CC_NB_DEPRECATED_MSG (4) 45 46 /* 47 * STATES 48 **************************************************************************************** 49 */ 50 51 /* 52 * MESSAGES 53 **************************************************************************************** 54 */ 55 56 /// Message API of the L2CC task 57 enum l2cc_msg_id 58 { 59 /// L2CAP Operation completed event 60 L2CC_CMP_EVT = TASK_FIRST_MSG(TASK_ID_L2CC) + L2CC_NB_DEPRECATED_MSG, //a04 61 62 /* ************* LE Credit Based API ************* */ 63 /// LE credit based connection request 64 L2CC_LECB_CONNECT_CMD, 65 /// LE credit based connection request indication 66 L2CC_LECB_CONNECT_REQ_IND, 67 /// LE credit based connection request confirmation 68 L2CC_LECB_CONNECT_CFM, 69 /// LE credit based connection indication 70 L2CC_LECB_CONNECT_IND, 71 /// LE credit based disconnect request 72 L2CC_LECB_DISCONNECT_CMD, 73 /// LE credit based disconnect indication 74 L2CC_LECB_DISCONNECT_IND, 75 /// LE credit based credit addition 76 L2CC_LECB_ADD_CMD, 77 /// LE credit based credit addition indication 78 L2CC_LECB_ADD_IND, 79 80 /// Send data over an LE Credit Based Connection 81 L2CC_LECB_SDU_SEND_CMD, 82 /// Inform that a data packet has been received from a LE Credit Based connection. 83 L2CC_LECB_SDU_RECV_IND, 84 85 86 /* ******************* Debug API ******************* */ 87 /// Send Debug PDU data 88 L2CC_DBG_PDU_SEND_CMD, //0xa0f 89 /// Debug PDU data received 90 L2CC_DBG_PDU_RECV_IND, 91 92 93 /* **************** PDU Internal API ****************** */ 94 /// Send Legacy PDU data 95 L2CC_PDU_SEND_CMD, //0xa11 96 /// Legacy PDU data received 97 L2CC_PDU_RECV_IND, 98 99 /// Timeout indication for a transaction on signaling channel 100 L2CC_SIGNALING_TRANS_TO_IND, 101 }; 102 103 104 /// request operation type - application interface 105 enum l2cc_operation 106 { 107 /* Operation Flags */ 108 /* No Operation (if nothing has been requested) */ 109 /* ************************************************ */ 110 /// No operation 111 L2CC_NO_OP = 0x00, 112 113 /* LE Credit Based */ 114 /* ************************************************ */ 115 /// LE credit based connection request 116 L2CC_LECB_CONNECT, 117 /// LE credit based disconnection request 118 L2CC_LECB_DISCONNECT, 119 /// LE credit addition request 120 L2CC_LECB_CREDIT_ADD, 121 /// Send SDU 122 L2CC_LECB_SDU_SEND, 123 124 /* Debug PDU Transmission (internal) */ 125 /* ************************************************ */ 126 /// Send a Debug PDU 127 L2CC_DBG_PDU_SEND, 128 129 /* PDU Transmission (internal) */ 130 /* ************************************************ */ 131 /// Send internal LE Legacy PDU 132 L2CC_PDU_SEND, 133 }; 134 135 136 /// Default L2Cap SDU definition 137 struct l2cc_sdu 138 { 139 /// Channel Identifier 140 uint16_t cid; 141 /// Number of credit used 142 uint16_t credit; 143 /// SDU Data length 144 uint16_t length; 145 /// data 146 uint8_t data[__ARRAY_EMPTY]; 147 }; 148 149 150 /// Operation completed event 151 struct l2cc_cmp_evt 152 { 153 /// L2CC request type (@see enum l2cc_operation) 154 uint8_t operation; 155 /// Status of request. 156 uint8_t status; 157 /// Channel ID 158 uint16_t cid; 159 /// Number of peer credit used - only relevant for LECB 160 uint16_t credit; 161 }; 162 163 /// LE credit based connection request 164 struct l2cc_lecb_connect_cmd 165 { 166 /// L2CC request type: 167 /// - L2CC_LECB_CONNECT: LE credit connection 168 uint8_t operation; 169 /// parameter used for internal usage 170 uint8_t pkt_id; 171 /// LE Protocol/Service Multiplexer 172 uint16_t le_psm; 173 /// Local Channel identifier (0: automatically allocate a free channel) 174 uint16_t local_cid; 175 /// Credit allocated for the LE Credit Based Connection 176 /// Shall be at least: floor(((SDU + 2) + (MPS - 1)) / MPS) + 1 177 /// To be sure that 1 SDU can be fully received without requesting credits to application 178 uint16_t local_credit; 179 /// Maximum SDU size - Shall not exceed device MTU 180 uint16_t local_mtu; 181 /// Maximum Packet size - Shall not exceed device MPS 182 uint16_t local_mps; 183 }; 184 185 /// LE credit based connection request indication 186 struct l2cc_lecb_connect_req_ind 187 { 188 /// LE Protocol/Service Multiplexer 189 uint16_t le_psm; 190 /// Peer Channel identifier 191 uint16_t peer_cid; 192 /// Maximum SDU size 193 uint16_t peer_mtu; 194 /// Maximum Packet size 195 uint16_t peer_mps; 196 }; 197 198 /// LE credit based connection request confirmation 199 struct l2cc_lecb_connect_cfm 200 { 201 /// LE Protocol/Service Multiplexer 202 uint16_t le_psm; 203 /// Peer Channel identifier 204 uint16_t peer_cid; 205 /// True to accept the incoming connection, False else 206 bool accept; 207 /// Local Channel identifier (0: automatically allocate a free channel) 208 uint16_t local_cid; 209 /// Credit allocated for the LE Credit Based Connection 210 /// Shall be at least: floor(((SDU + 2) + (MPS - 1)) / MPS) + 1 211 /// To be sure that 1 SDU can be fully received without requesting credits to application 212 uint16_t local_credit; 213 /// Maximum SDU size - Shall not exceed device MTU 214 uint16_t local_mtu; 215 /// Maximum Packet size - Shall not exceed device MPS 216 uint16_t local_mps; 217 }; 218 219 /// LE credit based connection indication 220 struct l2cc_lecb_connect_ind 221 { 222 /// Status 223 uint8_t status; 224 /// LE Protocol/Service Multiplexer 225 uint16_t le_psm; 226 /// Local Channel identifier 227 uint16_t local_cid; 228 /// Peer Channel identifier 229 uint16_t peer_cid; 230 /// Destination Credit for the LE Credit Based Connection 231 uint16_t peer_credit; 232 /// Maximum SDU size 233 uint16_t peer_mtu; 234 /// Maximum Packet size 235 uint16_t peer_mps; 236 }; 237 238 /// LE credit based disconnect request 239 struct l2cc_lecb_disconnect_cmd 240 { 241 /// L2CC request type: 242 /// - L2CC_LECB_DISCONNECT: LE credit disconnection 243 uint8_t operation; 244 /// parameter used for internal usage 245 uint8_t pkt_id; 246 /// Peer Channel identifier 247 uint16_t peer_cid; 248 }; 249 250 /// LE credit based disconnect indication 251 struct l2cc_lecb_disconnect_ind 252 { 253 /// LE Protocol/Service Multiplexer 254 uint16_t le_psm; 255 /// Local Channel identifier 256 uint16_t local_cid; 257 /// Peer Channel identifier 258 uint16_t peer_cid; 259 /// Reason 260 uint8_t reason; 261 }; 262 263 /// LE credit based credit addition 264 struct l2cc_lecb_add_cmd 265 { 266 /// L2CC request type: 267 /// - L2CC_LECB_CREDIT_ADD: LE credit addition 268 uint8_t operation; 269 /// parameter used for internal usage 270 uint8_t pkt_id; 271 /// Local Channel identifier 272 uint16_t local_cid; 273 /// Credit added locally for channel identifier 274 uint16_t credit; 275 }; 276 277 ///LE credit based credit addition indication 278 struct l2cc_lecb_add_ind 279 { 280 /// Peer Channel identifier 281 uint16_t peer_cid; 282 /// Destination added credit (relative value) 283 uint16_t peer_added_credit; 284 }; 285 286 /// Send data over an LE Credit Based Connection 287 struct l2cc_lecb_sdu_send_cmd 288 { 289 /// L2CC request type (@see enum l2cc_operation): 290 /// - L2CC_LECB_SDU_SEND: Send a SDU 291 uint8_t operation; 292 /// offset value information - for internal use only 293 uint16_t offset; 294 /// SDU information 295 struct l2cc_sdu sdu; 296 }; 297 298 /// Inform that a data packet has been received from a LE Credit Based connection. 299 struct l2cc_lecb_sdu_recv_ind 300 { 301 /// Status information 302 uint8_t status; 303 /// offset value information 304 uint16_t offset; 305 /// SDU information 306 struct l2cc_sdu sdu; 307 }; 308 309 310 /// @} L2CCTASK 311 312 #endif // L2CC_TASK_H_ 313