Mistake on this page?
Report an issue in GitHub or email us
lctr_api_conn.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief Link layer controller connection interface file.
6  *
7  * Copyright (c) 2013-2019 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019-2020 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 
25 #ifndef LCTR_API_CONN_H
26 #define LCTR_API_CONN_H
27 
28 #include "lctr_api.h"
29 #include "bb_ble_api.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*!
36  * \addtogroup LL_LCTR_API_CONN
37  * \{
38  */
39 
40 /**************************************************************************************************
41  Constants
42 **************************************************************************************************/
43 
44 /*! \brief Data channel PDU length (header + payload + MIC). */
45 #define LCTR_DATA_PDU_LEN(len) ((len) + LL_DATA_HDR_LEN + BB_DATA_PDU_TAILROOM)
46 
47 /*! \brief Maximum data channel PDU length (header + payload + MIC). */
48 #define LCTR_DATA_PDU_MAX_LEN LCTR_DATA_PDU_LEN(BB_DATA_PLD_MAX_LEN)
49 
50 /*! \brief Minimum data channel PDU length (header + payload + MIC). */
51 #define LCTR_DATA_PDU_MIN_LEN LCTR_DATA_PDU_LEN(LL_MAX_DATA_LEN_MIN)
52 
53 /*! \brief Maximum value for maximum Data PDU length (spec limit is 251) */
54 #define LCTR_MAX_DATA_LEN_MAX BB_DATA_PLD_MAX_LEN
55 
56 /*! \brief Maximum handle index (CIS included). */
57 #define LCTR_MAX_HANDLE_INDEX (pLctrRtCfg->maxConn + pLctrRtCfg->maxCis)
58 
59 /*! \brief Connected task messages for \a LCTR_DISP_CONN dispatcher. */
60 enum
61 {
62  /* Broadcast events */
63  LCTR_CONN_MSG_RESET = LCTR_MSG_RESET,
64  /* Receive remote PDU events */
65  _LCTR_CONN_MSG_RX_EVENTS = 10,
66  LCTR_CONN_MSG_RX_CONNECT_IND, /*!< Connect indication received. */
67  LCTR_CONN_MSG_RX_LLCP, /*!< LLCP message received. */
68  LCTR_CONN_MSG_RX_LLCP_UNKNOWN, /*!< Unknown LLCP message received. */
69  LCTR_CONN_MSG_RX_LLCP_INVALID_PARAM, /*!< LLCP message with invalid parameter received. */
70  /* Host/API events */
71  _LCTR_CONN_MSG_API_EVENTS = 20,
72  LCTR_CONN_MSG_API_CONN_UPDATE, /*!< Connection update API event. */
73  LCTR_CONN_MSG_API_CHAN_MAP_UPDATE, /*!< Channel map update API event. */
74  LCTR_CONN_MSG_API_DISCONNECT, /*!< Disconnect API event. */
75  LCTR_CONN_MSG_API_START_ENC, /*!< Start encryption API event. */
76  LCTR_CONN_MSG_API_LTK_REPLY, /*!< LTK reply. */
77  LCTR_CONN_MSG_API_LTK_NEG_REPLY, /*!< LTK negative reply. */
78  LCTR_CONN_MSG_API_REMOTE_FEATURE, /*!< Read remote feature API event. */
79  LCTR_CONN_MSG_API_REMOTE_VERSION, /*!< Read remote version API event. */
80  LCTR_CONN_MSG_API_CONN_PARAM_REPLY, /*!< Remote connection parameter request reply API event. */
81  LCTR_CONN_MSG_API_CONN_PARAM_NEG_REPLY,/*!< Remote connection parameter request negative reply API event. */
82  LCTR_CONN_MSG_API_DATA_LEN_CHANGE, /*!< Data length change API event. */
83  LCTR_CONN_MSG_API_PHY_UPDATE, /*!< PHY update API event. */
84  LCTR_CONN_MSG_API_SET_MIN_USED_CHAN, /*!< Set minimum number of used channels API event. */
85  LCTR_CONN_MSG_API_PER_ADV_SYNC_TRSF, /*!< Periodic advertising sync transfer API event. */
86  LCTR_CONN_MSG_API_REQ_PEER_SCA, /*!< Request peer SCA. */
87  LCTR_CONN_MSG_API_CIS_REQ, /*!< CIS request API event. */
88  LCTR_CONN_MSG_API_CIS_REQ_ACCEPT, /*!< Peer CIS request accept API event. */
89  LCTR_CONN_MSG_API_CIS_REQ_REJECT, /*!< Peer CIS request accept API event. */
90  LCTR_CONN_MSG_API_PWR_CTRL_REQ, /*!< Peer power control request API event. */
91 
92  /* Internal events */
93  _LCTR_CONN_INT_EVENTS = 40,
94  LCTR_CONN_DATA_PENDING, /*!< New data pending. */
95  LCTR_CONN_ARQ_Q_FLUSHED, /*!< ARQ queue transitioned to empty. */
96  LCTR_CONN_MST_ESTABLISH, /*!< Establish connection (master only). */
97  LCTR_CONN_SLV_INIT_STARTUP_LLCP, /*!< Slave initiates startup LLCP procedures(slave only). */
98  _LCTR_CONN_LLCP_EVENTS = 50,
99  LCTR_CONN_LLCP_CONN_UPDATE, /*!< LL initiated connection update procedure. */
100  LCTR_CONN_LLCP_VERSION_EXCH, /*!< LL initiated remote version exchange. */
101  LCTR_CONN_LLCP_FEATURE_EXCH, /*!< LL initiated remote feature exchange. */
102  LCTR_CONN_LLCP_LENGTH_EXCH, /*!< LL initiated data length exchange. */
103  LCTR_CONN_LLCP_PWR_CTRL_REQ, /*!< LL initiated power control request. */
104  LCTR_CONN_LLCP_TERM, /*!< LL initiated termination. */
105  LCTR_CONN_LLCP_PROC_CMPL, /*!< LLCP procedure completed. */
106  LCTR_CONN_LLCP_START_PENDING, /*!< Start pending LLCP procedure. */
107  LCTR_CONN_LLCP_SKIP_CONN_PARAM, /*!< Skip connection parameter exchange. */
108  LCTR_CONN_LLCP_REJECT_CONN_UPD, /*!< Reject a connection update. */
109  _LCTR_CONN_TERM_EVENTS = 70,
110  LCTR_CONN_TERM_SUP_TIMEOUT, /*!< Terminate connection due to supervision timeout. */
111  LCTR_CONN_TERM_MIC_FAILED, /*!< Terminate connection due to MIC failure. */
112  LCTR_CONN_TERM_INST_PASSED, /*!< Terminate connection due to instant passed. */
113  LCTR_CONN_TERM_CIS_LOCAL_RESOURCE, /*!< Terminate CIS connection due to local resource limitation. */
114  LCTR_CONN_TERMINATED, /*!< Connection event terminated. */
115  LCTR_CONN_INIT_CANCELED, /*!< Connection cancelled event. */
116  _LCTR_CONN_TMR_EVENTS = 80,
117  LCTR_CONN_TMR_LLCP_RSP_EXP, /*!< LLCP response timer expired. */
118  LCTR_CONN_TMR_CIS_LLCP_RSP_EXP, /*!< CIS LLCP response timer expired. */
119  LCTR_CONN_TMR_PING_PERIOD_EXP, /*!< LE Ping period timer expired. */
120  LCTR_CONN_TMR_AUTH_PAYLOAD_EXP /*!< Authentication payload timer expired. */
121 };
122 
123 /**************************************************************************************************
124  Data Types
125 **************************************************************************************************/
126 
127 /*! \brief Connection update message. */
128 typedef struct
129 {
130  lctrMsgHdr_t hdr; /*!< Message header. */
131  LlConnSpec_t connSpec; /*!< Updated connection specification. */
133 
134 /*! \brief Disconnect message. */
135 typedef struct
136 {
137  lctrMsgHdr_t hdr; /*!< Message header. */
138  uint8_t reason; /*!< Disconnect reason. */
140 
141 /*! \brief Start encryption message. */
142 typedef struct
143 {
144  lctrMsgHdr_t hdr; /*!< Message header. */
145  uint8_t rand[LL_RAND_LEN]; /*!< Random number. */
146  uint16_t diversifier; /*!< Diversifier. */
147  uint8_t key[LL_KEY_LEN]; /*!< Encryption key. */
149 
150 /*! \brief Remote connection parameter reply message. */
151 typedef struct
152 {
153  lctrMsgHdr_t hdr; /*!< Message header. */
154  uint8_t key[LL_KEY_LEN]; /*!< Encryption key. */
156 
157 /*! \brief Remote connection parameter reply message. */
158 typedef struct
159 {
160  lctrMsgHdr_t hdr; /*!< Message header. */
161  LlConnSpec_t connSpec; /*!< Updated connection specification. */
163 
164 /*! \brief Remote connection parameter negative reply message. */
165 typedef struct
166 {
167  lctrMsgHdr_t hdr; /*!< Message header. */
168  uint8_t reason; /*!< Reason code. */
170 
171 /*! \brief Data length change message. */
172 typedef struct
173 {
174  lctrMsgHdr_t hdr; /*!< Message header. */
175  uint16_t maxTxLen; /*!< Maximum transmit length. */
176  uint16_t maxTxTime; /*!< Maximum transmit time. */
178 
179 /*! \brief PHY update message. */
180 typedef struct
181 {
182  lctrMsgHdr_t hdr; /*!< Message header. */
183  uint8_t allPhys; /*!< All PHYs preferences. */
184  uint8_t txPhys; /*!< Preferred transmitter PHYs. */
185  uint8_t rxPhys; /*!< Preferred receiver PHYs. */
186  uint16_t phyOptions; /*!< PHY options. */
188 
189 /*! \brief Set minimum number of used channels message. */
190 typedef struct
191 {
192  lctrMsgHdr_t hdr; /*!< Message header. */
193  uint8_t phys; /*!< Bitmask for the PHYs. */
194  uint8_t minUsedChan; /*!< Minimum number of used channels. */
196 
197 /*! \brief Periodic advertising sync transfer message. */
198 typedef struct
199 {
200  lctrMsgHdr_t hdr; /*!< Message header. */
201  uint16_t syncSource; /*!< Periodic sync source. */
202  uint16_t syncHandle; /*!< Periodic sync handle. */
203  uint16_t serviceData; /*!< Service data provided by the host. */
205 
206 /*! \brief Set minimum number of used channels message. */
207 typedef struct
208 {
209  lctrMsgHdr_t hdr; /*!< Message header. */
210  uint8_t action; /*!< Action. */
211 } lctrScaReq_t;
212 
213 /*! \brief CIS set CIG test CIS parameters. */
214 typedef struct
215 {
216  lctrMsgHdr_t hdr; /*!< Message header. */
217  uint16_t cisHandle; /*!< CIS handle. */
219 
220 /*! \brief Internal reject CIS request message. */
221 typedef struct
222 {
223  lctrMsgHdr_t hdr; /*!< Message header. */
224  uint8_t reason; /*!< Reject reason. */
226 
227 /*! \brief Disconnect message. */
228 typedef struct
229 {
230  lctrMsgHdr_t hdr; /*!< Message header. */
231  uint8_t reason; /*!< Disconnect reason. */
232  uint16_t cisHandle; /*!< CIS handle. */
233 } lctrCisDisc_t;
234 
235 /*! \brief Internal power control request message. */
236 typedef struct
237 {
238  lctrMsgHdr_t hdr; /*!< Message Header. */
239  int8_t delta; /*!< Delta requested. */
240  uint8_t phy; /*!< PHY requested. */
242 
243 /*! \brief Link layer controller message data. */
244 typedef union
245 {
246  lctrMsgHdr_t hdr; /*!< Message header. */
247  lctrConnEstablish_t connEstablish; /*!< Connection establish message data. */
248  lctrConnUpdate_t connUpd; /*!< Connection update message data. */
249  lctrChanMapUpdate_t chanMapUpd; /*!< Channel map update message data. */
250  lctrDisconnect_t disc; /*!< Disconnect message data. */
251  lctrStartEnc_t startEnc; /*!< Start encryption message data. */
252  lctrLtkReply_t ltkReply; /*!< LTK reply message data. */
253  lctrConnParamReply_t connParamReply; /*!< Remote connection parameter reply message data. */
254  lctrConnParamNegReply_t connParamNegReply;/*!< Remote connection parameter negative reply message data. */
255  lctrDataLengthChange_t dataLenChange; /*!< Data length change message data. */
256  lctrPhyUpdate_t phyUpd; /*!< PHY update message data. */
257  lctrSetMinUsedChan_t setMinUsedChan; /*!< Set minimum number of used channels message data. */
258  lctrPerAdvSyncTrsf_t perAdvSyncTrsf; /*!< Periodic advertising sync transfer data. */
259  lctrScaReq_t scaReq; /*!< Sleep clock accuracy request. */
260  lctrMsgPwrCtrlReq_t pwrCtrlReq; /*!< Power control request. */
261 
262  /* CIS */
263  lctrCreateCis_t createCis; /*!< Create CIS message data. */
264  lctrRejCisReq_t rejCisReq; /*!< Reject CIS request message data. */
265  lctrCisDisc_t cisDisc; /*!< CIS disconnect message data. */
266 } lctrConnMsg_t;
267 
268 /*! \brief Initialize connection context. */
269 typedef void (*LctrInitConnHdlr_t)(uint16_t connHandle);
270 
271 /*! \brief Set transmit flow control. */
272 typedef void (*LctrTxFcHdlr_t)(uint16_t connHandle, uint8_t *pBuf);
273 
274 /*! \brief Transmit PDU complete. */
275 typedef void (*LctrTxPduCompHdlr_t)(uint16_t connHandle);
276 
277 /*! \brief Transmit empty packet acknowledgment, returns TRUE if required. */
278 typedef bool_t (*LctrTxAckHdlr_t)(uint16_t connHandle);
279 
280 /*! \brief Receive process flow control, returns TRUE if retransmission. */
281 typedef bool_t (*LctrRxAckHdlr_t)(uint16_t connHandle);
282 
283 /*! \brief VS receive data handler. */
284 typedef void (*LctrVsRecvHdlr_t)(uint16_t connHandle, uint8_t *pBuf);
285 
286 /*! \brief Connection event complete handler. */
287 typedef void (*LctrCeCompHdlr_t)(uint16_t connHandle);
288 
289 /*! \brief Vendor specific PDU handlers. */
290 typedef struct
291 {
292  LctrInitConnHdlr_t connSetup; /*!< Setup connection context. */
293  LctrInitConnHdlr_t connCleanup; /*!< Cleanup connection context. */
294  LctrTxFcHdlr_t txPduFc; /*!< Set transmit PDU flow control. */
295  LctrTxAckHdlr_t txPduAck; /*!< Tx PDU acknowledge required? */
296  LctrRxAckHdlr_t rxPduAck; /*!< Process a receive PDU acknowledgment. */
297  LctrVsRecvHdlr_t dataRecv; /*!< Receive data buffer handler. */
298  LctrTxPduCompHdlr_t ceSetup; /*!< Setup connection event. */
299  LctrCeCompHdlr_t ceCleanup; /*!< Cleanup connection event. */
301 
302 /**************************************************************************************************
303  Function Declarations
304 **************************************************************************************************/
305 
306 /* Initialization */
307 void LctrSlvConnInit(void);
308 void LctrSlvConnEncInit(void);
309 void LctrMstConnInit(void);
310 void LctrMstConnEncInit(void);
311 void LctrVsConnInit(const LctrVsHandlers_t *pHdlrs);
312 
313 /* Helpers */
314 uint8_t LctrValidateConnSpec(const LlConnSpec_t *pConnSpec);
315 uint8_t LctrValidateModifyScaParam(uint8_t action);
316 bool_t LctrIsProcActPended(uint16_t handle, uint8_t event);
317 
318 /* Status */
319 bool_t LctrIsConnHandleEnabled(uint16_t handle);
320 bool_t LctrIsCisConnHandleEnabled(uint16_t handle);
321 uint8_t LctrGetRole(uint16_t handle);
322 int8_t LctrGetRssi(uint16_t handle);
323 uint8_t lctrSetTxPowerReporting(uint16_t handle, uint8_t enableLocal, uint8_t enableRemote);
324 int8_t LctrGetTxPowerLevel(uint16_t handle);
325 uint64_t LctrGetChannelMap(uint16_t handle);
326 uint64_t LctrGetUsedFeatures(uint16_t handle);
327 uint8_t LctrGetTxPhy(uint16_t handle);
328 uint8_t LctrGetRxPhy(uint16_t handle);
329 void LctrGetPeerMinUsedChan(uint16_t handle, uint8_t *pPeerMinUsedChan);
330 bool_t LctrIsWaitingForReply(uint16_t handle, uint8_t reply);
331 bool_t LctrIsCisEnabled(uint16_t handle);
332 
333 /* Control */
334 void LctrSetTxPowerLevel(uint16_t handle, int8_t level);
335 void LctrSetPhyTxPowerLevel(uint16_t handle, int8_t level, uint8_t phy);
336 int8_t LctrGetPhyTxPowerLevel(uint16_t handle, uint8_t phy);
337 uint32_t LctrGetAuthPayloadTimeout(uint16_t handle);
338 bool_t LctrSetAuthPayloadTimeout(uint16_t handle, uint32_t timeoutMs);
339 void LctrGetEncMode(uint16_t handle, LlEncMode_t *pMode);
340 bool_t LctrSetEncMode(uint16_t handle, const LlEncMode_t *pMode);
341 void LctrSetConnOpFlags(uint16_t handle, uint32_t flags, bool_t enable);
342 uint8_t lctrSetPowerMonitorEnable(uint16_t handle, bool_t enable);
343 
344 
345 /* Data path */
346 void LctrTxAcl(uint8_t *pAclBuf);
347 uint8_t *LctrRxAcl(void);
348 void LctrRxAclComplete(uint8_t numBufs);
349 
350 /*! \} */ /* LL_LCTR_API_CONN */
351 
352 #ifdef __cplusplus
353 };
354 #endif
355 
356 #endif /* LCTR_API_CONN_H */
Data length change message.
void(* LctrTxPduCompHdlr_t)(uint16_t connHandle)
Transmit PDU complete.
Set minimum number of used channels message.
LctrInitConnHdlr_t connCleanup
lctrMsgHdr_t hdr
BLE baseband interface file.
lctrChanMapUpdate_t chanMapUpd
Periodic advertising sync transfer message.
LctrTxPduCompHdlr_t ceSetup
lctrRejCisReq_t rejCisReq
lctrCreateCis_t createCis
LctrRxAckHdlr_t rxPduAck
lctrStartEnc_t startEnc
Encryption mode data structure used in LlGetEncMode() and LlSetEncMode().
Definition: ll_api.h:828
#define LL_RAND_LEN
Definition: ll_defs.h:309
Channel map update message.
Definition: lctr_api.h:117
bool_t(* LctrRxAckHdlr_t)(uint16_t connHandle)
Receive process flow control, returns TRUE if retransmission.
lctrConnParamNegReply_t connParamNegReply
LctrCeCompHdlr_t ceCleanup
lctrMsgHdr_t hdr
lctrMsgHdr_t hdr
Internal reject CIS request message.
lctrMsgHdr_t hdr
lctrConnParamReply_t connParamReply
Remote connection parameter reply message.
void(* LctrInitConnHdlr_t)(uint16_t connHandle)
Initialize connection context.
uint16_t diversifier
LctrTxAckHdlr_t txPduAck
Link layer controller common interface file.
Link layer controller message data.
Vendor specific PDU handlers.
lctrMsgHdr_t hdr
void(* LctrCeCompHdlr_t)(uint16_t connHandle)
Connection event complete handler.
lctrDataLengthChange_t dataLenChange
Connection establish.
Definition: lctr_api.h:149
lctrScaReq_t scaReq
lctrConnUpdate_t connUpd
Start encryption message.
lctrMsgHdr_t hdr
bool_t(* LctrTxAckHdlr_t)(uint16_t connHandle)
Transmit empty packet acknowledgment, returns TRUE if required.
Disconnect message.
Connection update message.
#define LL_KEY_LEN
Definition: ll_defs.h:310
void(* LctrVsRecvHdlr_t)(uint16_t connHandle, uint8_t *pBuf)
VS receive data handler.
void(* LctrTxFcHdlr_t)(uint16_t connHandle, uint8_t *pBuf)
Set transmit flow control.
uint16_t cisHandle
LctrInitConnHdlr_t connSetup
CIS set CIG test CIS parameters.
lctrPhyUpdate_t phyUpd
uint16_t phyOptions
Disconnect message.
Common message structure passed to event handler.
Definition: lctr_api.h:109
lctrMsgHdr_t hdr
lctrMsgHdr_t hdr
lctrLtkReply_t ltkReply
Internal power control request message.
LlConnSpec_t connSpec
lctrMsgHdr_t hdr
uint16_t cisHandle
LctrTxFcHdlr_t txPduFc
lctrSetMinUsedChan_t setMinUsedChan
lctrMsgPwrCtrlReq_t pwrCtrlReq
LctrVsRecvHdlr_t dataRecv
Connection specification (LlCreateConn(), LlConnUpdate() and LlExtCreateConn()).
Definition: ll_api.h:624
lctrConnEstablish_t connEstablish
lctrCisDisc_t cisDisc
lctrDisconnect_t disc
uint8_t action
LlConnSpec_t connSpec
PHY update message.
Set minimum number of used channels message.
Remote connection parameter negative reply message.
lctrPerAdvSyncTrsf_t perAdvSyncTrsf
Remote connection parameter reply message.
lctrMsgHdr_t hdr
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.