-
Notifications
You must be signed in to change notification settings - Fork 1
/
cllc.h
416 lines (366 loc) · 12.4 KB
/
cllc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/******************************************************************************
@file cllc.h
@brief Coordinator Logical Link Controller
Group: WCS LPC
$Target Device: DEVICES $
******************************************************************************
$License: BSD3 2016 $
******************************************************************************
$Release Name: PACKAGE NAME $
$Release Date: PACKAGE RELEASE DATE $
*****************************************************************************/
#ifndef CLLC_H
#define CLLC_H
/******************************************************************************
Includes
*****************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "llc.h"
#include "api_mac.h"
#include "ti_154stack_config.h"
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************
Constants and definitions
*****************************************************************************/
/*! Event ID - LLC Event for PA Async command */
#define CLLC_PA_EVT 0x0001
/*! Event ID - LLC Event for PC Async command */
#define CLLC_PC_EVT 0x0002
/*! Event ID - LLC Event for Join Permit duration */
#define CLLC_JOIN_EVT 0x0004
/*! Event ID - State change event */
#define CLLC_STATE_CHANGE_EVT 0x0008
/*! Association status */
#define CLLC_ASSOC_STATUS_ALIVE 0x0001
/*!
Coordinator State Values
*/
typedef enum
{
/*! Powered up, not started and waiting for user to start */
Cllc_states_initWaiting,
/*! Starting coordinator, scanning and selecting the best parameters */
Cllc_states_startingCoordinator,
/*!
Powered up, found network information, and restoring device in network
*/
Cllc_states_initRestoringCoordinator,
/*! Device is operating as coordinator */
Cllc_states_started,
/*! Device is restored as coordinator in the network */
Cllc_states_restored,
/*! Joining allowed state has changed to allowed */
Cllc_states_joiningAllowed,
/*! Joining allowed state has changed to not allowed */
Cllc_states_joiningNotAllowed
} Cllc_states_t;
/*!
Coordinator starting State Values
*/
typedef enum
{
/*! Initialized state */
Cllc_coordStates_initialized = 0,
/*! MAC coordinator is performing a active scan */
Cllc_coordStates_scanActive,
/*! active scan confirm received*/
Cllc_coordStates_scanActiveCnf,
/*! Eneergy detect scan confirm received */
Cllc_coordStates_scanEdCnf,
/*! Start confirm received */
Cllc_coordStates_startCnf
} Cllc_coord_states_t;
/*! Building block for association table */
typedef struct
{
/*! Short address of associated device */
uint16_t shortAddr;
/*! capability information */
ApiMac_capabilityInfo_t capInfo;
/*! RSSI */
int8_t rssi;
/*! Device alive status */
uint16_t status;
#ifdef FEATURE_SECURE_COMMISSIONING
uint8_t reCM_status;
uint8_t keyRef_statue;
uint8_t NumOfKeyRefresh;
#endif
#ifdef USE_DMM
uint8_t sensorData;
#endif
} Cllc_associated_devices_t;
/*! Cllc statistics */
typedef struct
{
/*! number of PA Solicit messages received */
uint32_t fhNumPASolicitReceived;
/*! number of PA messages sent */
uint32_t fhNumPASent;
/*! number of PC Solicit messages received */
uint32_t fhNumPANConfigSolicitsReceived;
/*! number of PC messages sent */
uint32_t fhNumPANConfigSent;
uint32_t otherStats;
} Cllc_statistics_t;
/*! Association table */
extern Cllc_associated_devices_t Cllc_associatedDevList[CONFIG_MAX_DEVICES];
/*! Cllc statistics */
extern Cllc_statistics_t Cllc_statistics;
/*! Cllc events flags */
extern uint16_t Cllc_events;
/******************************************************************************
Structures - Building blocks for the Coordinator LLC
*****************************************************************************/
/*!
Coordinator started callback.
*/
typedef void (*Cllc_startedFp_t)(Llc_netInfo_t *pStartedInfo);
/*!
Device joining callback - Indication that a device is joining. pDevInfo
is a pointer to the device's information and capInfo is the device's
capabilities. The application will determine if the device can join by
the return value - ApiMac_assocStatus_t. If this callback is ignored,
callback pointer is NULL, all devices will be allowed to join, assuming
that associate permit is true.
*/
typedef ApiMac_assocStatus_t (*Cllc_deviceJoiningFp_t)(
ApiMac_deviceDescriptor_t *pDevInfo,
ApiMac_capabilityInfo_t *pCapInfo);
/*!
State Changed callback - This indication says that the CLLC's state
has changed.
*/
typedef void (*Cllc_stateChangedFp_t)(Cllc_states_t state);
/*!
Structure containing all the CLLC callbacks (indications).
To receive the callback fill in the structure item with a pointer
to the function that will handle that callback. To ignore a callback
set that function pointer to NULL.
*/
typedef struct _Cllc_callbacks_t
{
/*! Coordinator Started Indication callback */
Cllc_startedFp_t pStartedCb;
/*! Device joining callback */
Cllc_deviceJoiningFp_t pDeviceJoiningCb;
/*! The state has changed callback */
Cllc_stateChangedFp_t pStateChangeCb;
} Cllc_callbacks_t;
/******************************************************************************
Function Prototypes
*****************************************************************************/
/*!
* @brief Initialize this module and update the callback structure.
* <BR>
* This function will take the application's MAC callback
* structure and override some callbacks with its own callbacks.
* The application callbacks that are overridden are saved so that
* they can be chain called when processing the callbacks.
*
* @param pMacCbs - pointer to the API MAC callback structure
* @param pCllcCbs - pointer to the CLLC callback structure
*/
extern void Cllc_init(ApiMac_callbacks_t *pMacCbs, Cllc_callbacks_t *pCllcCbs);
/*!
* @brief Application task processing.
* <BR>
* This function handles the events in CLLC for trickle timer,
* controlling associate permit flag and transitioning between
* various states during operation.
*/
extern void Cllc_process(void);
/*!
* @brief set the PAN ID to form.
*
* @param panId - PAN ID to set
*/
extern void Cllc_setFormingPanId(uint16_t panId);
/*!
* @brief get the PAN ID to form.
*
* @param panId - Pointer to current PAN ID in jdllc
*/
extern void Cllc_getFormingPanId(uint16_t *pPanId);
/*!
* @brief set the channel mask.
*
* @param channelMask - channel mask to set
*/
extern void Cllc_setChanMask(uint8_t *channelMask);
/*!
* @brief get the channel mask.
*
* @param channelMask - Pointer to current channel mask in cllc
*/
extern void Cllc_getChanMask(uint8_t *channelMask);
/*!
* @brief set the async channel mask.
*
* @param asyncChanMask - async channel mask to set
*/
extern void Cllc_setAsyncChanMask(uint8_t *asyncChanMask);
/*!
* @brief get the async channel mask.
*
* @param asyncChanMask - async channel mask to get
*/
extern void Cllc_getAsyncChanMask(uint8_t *asyncChanMask);
#ifdef FEATURE_MAC_SECURITY
/*!
* @brief set the default security key.
*
* @param key - default key to set
*/
extern void Cllc_setDefaultKey(uint8_t *key);
/*!
* @brief get the default security key.
*
* @param key - default key to get
*/
extern void Cllc_getDefaultKey(uint8_t *key);
#endif
/*!
* @brief Set the collector (Full Function Device - FFD) address.
*
* @param addr - Pointer to FFD address to set
*/
extern void Cllc_setFfdShortAddr(uint16_t addr);
/*!
* @brief Get the collector (Full Function Device - FFD) address.
*
* @param addr - FFD address from jdllc
*/
extern void Cllc_getFfdShortAddr(uint16_t *addr);
/*!
* @brief Get the current PHY ID of the sensor device.
*
* @return frequency - Current MAC PHY ID
*/
extern uint8_t Cllc_getFreq(void);
/*!
* @brief Get the current channel of the collector device
*
* @return channel - Current MAC channel
*/
extern uint8_t Cllc_getChan(void);
/*!
* @brief Get the current state of the sensor device.
*
* @return state - Sensor state
*/
extern uint8_t Cllc_getProvState(void);
/*!
* @brief Start a network.
* <BR>
* The application will call this function to start the process
* of making this device a coordinator of a new network.
* <BR>
* This module will automatically determine the best channel(s)
* and PANID, before starting.
*/
extern void Cllc_startNetwork(void);
/*!
* @brief Restore the coodinator in the network.
* <BR>
* The application will call this function to restore the
* coordinator in the network by passing all the network
* information needed to restore the device.
* <BR>
* This module will configure the MAC with all the network
* information then start the coordinator without scanning.
*
* @param pNetworkInfo - network information
* @param numDevices - number of devices in association table
* @param pDevList - list of devices
*/
extern void Cllc_restoreNetwork(Llc_netInfo_t *pNetworkInfo, uint16_t numDevices,
Llc_deviceListItem_t *pDevList);
/*!
* @brief Remove device from the network.
* <BR>
* The application will call this function to remove a device
* from the network by passing the extended address of the
* device.
* <BR>
*
* @param pExtAddr - pointer to extended address of the device
*/
extern void Cllc_removeDevice(ApiMac_sAddrExt_t *pExtAddr);
/*!
* @brief Set Join Permit PIB value.
* <BR>
* The application will call this function to set or clear
* <BR>
*
* @param duration - duration for join permit to be turned on in
* milliseconds.
* 0 sets it Off, 0xFFFFFFFF sets it ON indefinitely
* Any other non zero value sets it on for that duration
*
* @return ApiMac_status_t - ApiMac_status_success for successful
* operation
*/
extern ApiMac_status_t Cllc_setJoinPermit(uint32_t duration);
/*!
* @brief API for app to set disassociation request.
*
* @param shortAddr - short address of device
* @param rxOnIdle -- true or false
*/
extern void Cllc_sendDisassociationRequest(uint16_t shortAddr,bool rxOnIdle);
/*!
* @brief Initialize the MAC Security
*
* @param frameCounter - Initial frame counter
*/
extern void Cllc_securityInit(uint32_t frameCounter, uint8_t *key);
/*!
* @brief Fill in the security structure
*
* @param pSec - pointer to security structure
*/
extern void Cllc_securityFill(ApiMac_sec_t *pSec);
/*!
* @brief Check the security level against expected level
*
* @param pSec - pointer to security structure
*
* @return true is matches expected security level, false if not
*/
extern bool Cllc_securityCheck(ApiMac_sec_t *pSec);
/*!
* @brief Add a device to the MAC security device table.
*
* @param panID - PAN ID
* @param shortAddr - short address of the device
* @param pExtAddr - pointer to the extended address
* @param frameCounter - starting frame counter
*
* @return status returned by ApiMac_secAddDevice()
*/
extern ApiMac_status_t Cllc_addSecDevice(uint16_t panID,
uint16_t shortAddr,
ApiMac_sAddrExt_t *pExtAddr,
uint32_t frameCounter);
/*!
* @brief Find the associated device table entry matching an
* extended address.
*
* @param shortAddr - device's short address
*
* @return pointer to the associated device table entry,
* NULL if not found.
*/
extern Cllc_associated_devices_t *Cllc_findDevice(uint16_t shortAddr);
//*****************************************************************************
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif /* CLLC_H */