-
Notifications
You must be signed in to change notification settings - Fork 1
/
csf.h
470 lines (402 loc) · 13.7 KB
/
csf.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/******************************************************************************
@file csf.h
@brief Collector Specific Functions API
Group: WCS LPC
$Target Device: DEVICES $
******************************************************************************
$License: BSD3 2016 $
******************************************************************************
$Release Name: PACKAGE NAME $
$Release Date: PACKAGE RELEASE DATE $
*****************************************************************************/
#ifndef CSF_H
#define CSF_H
/******************************************************************************
Includes
*****************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "llc.h"
#include "cllc.h"
#include "smsgs.h"
#ifndef __unix__
#include "cui.h"
#else
#include "csf_linux.h"
#endif
#ifdef FEATURE_SECURE_COMMISSIONING
#include "sm_ti154.h"
#endif
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************
Constants
*****************************************************************************/
/*! CSF Events - Key Event */
#define CSF_KEY_EVENT 0x0001
#define COLLECTOR_UI_INPUT_EVT 0x0002
#define COLLECTOR_SENSOR_ACTION_EVT 0x0004
#define CSF_INVALID_SHORT_ADDR 0xFFFF
#define CSF_INVALID_SUBID 0xFFFF
#define SENSOR_ACTION_TOGGLE 0
#define SENSOR_ACTION_SET_RPT_INT 1
#define SENSOR_ACTION_DISASSOC 2
#define SENSOR_ACTION_DEVICE_TYPE_REQ 3
/******************************************************************************
Typedefs
*****************************************************************************/
/******************************************************************************
Function Prototypes
*****************************************************************************/
/*!
* @brief The application calls this function during initialization.
*
* @param sem - pointer to semaphore used by MAC API
*/
extern void Csf_init(void *sem);
/*!
* @brief The application must call this function periodically to
* process any events that this module needs to process.
*/
extern void Csf_processEvents(void);
#ifdef USE_DMM
/*!
* @brief Key event handler function
*
* @param keysPressed - keys that are pressed
*/
extern void Csf_processKeyChange(uint8_t keysPressed);
#endif
/*!
* @brief The application calls this function to retrieve the stored
* network information. The stored network information was saved
* after starting a network.
* <BR>
* NOTE: If the "fh" is true you will need to free the
* pInfo->info.fhNetInfo.fhInfo.bcNumChans and
* pInfo->info.fhNetInfo.fhInfo.pUnicastChans buffers through
* Csf_free().
*
* @param pInfo - pointer to network information structure
*
* @return True if the network information is available
*/
extern bool Csf_getNetworkInformation(Llc_netInfo_t *pInfo);
/*!
* @brief The application calls this function to indicate that it has
* started or restored the device in a network.
*
* The information will be saved and used to determine if a
* network was already started and should be restored instead
* of started.
*
* @param restored - true if restored in network
* @param pNetworkInfo - network information structure
*/
extern void Csf_networkUpdate(bool restored, Llc_netInfo_t *pNetworkInfo);
/*!
* @brief The application calls this function to indicate that a device
* has joined the network.
*
* The information will be saved.
*
* @param pDevInfo - pointer to the device information
* @param capInfo - capability information of the joining device.
*
* @return ApiMac_assocStatus_success, ApiMac_assocStatus_panAtCapacity,
* or ApiMac_assocStatus_panAccessDenied
*/
extern ApiMac_assocStatus_t Csf_deviceUpdate(
ApiMac_deviceDescriptor_t *pDevInfo,
ApiMac_capabilityInfo_t *pCapInfo);
/*!
* @brief The application calls this function to indicate that a device
* is no longer active in the network. This function will be
* called when the device doesn't respond to the tracking request.
*
* The information will be saved.
*
* @param pDevInfo - pointer to the device information
* @param timeout - true if not active because of tracking timeout.
* meaning that the device didn't respond to the tracking request
* within the timeout period.
*/
extern void Csf_deviceNotActiveUpdate(ApiMac_deviceDescriptor_t *pDevInfo,
bool timeout);
/*!
* @brief The application calls this function to indicate that a device
* has responded to a Config Request.
*
* The information will be saved.
*
* @param pSrcAddr - short address of the device that sent the message
* @param rssi - the received packet's signal strength
* @param pMsg - pointer to the Config Response message
*/
extern void Csf_deviceConfigUpdate(ApiMac_sAddr_t *pSrcAddr, int8_t rssi,
Smsgs_configRspMsg_t *pMsg);
/*!
* @brief The application calls this function to indicate that a device
* has reported sensor data.
*
* The information will be saved.
*
* @param pSrcAddr - short address of the device that sent the message
* @param rssi - the received packet's signal strength
* @param pMsg - pointer to the Sensor Data message
*/
extern void Csf_deviceSensorDataUpdate(ApiMac_sAddr_t *pSrcAddr, int8_t rssi,
Smsgs_sensorMsg_t *pMsg);
/*!
* @brief The application calls this function to indicate that a device
* has been disassociated.
*
* @param shortAddr - short address of the device that has been disassociated
*/
#ifndef __unix__
extern void Csf_deviceDisassocUpdate(uint16_t shortAddr);
#endif
#if defined(DEVICE_TYPE_MSG) && !defined(__unix__)
/*!
* @brief The application calls this function to print out the reported
* device type
*
* @param deviceFamilyID - the integer ID of the device family
* @param deviceTypeID - the integer ID of the board/device
*/
extern void Csf_deviceSensorDeviceTypeResponseUpdate(uint8_t deviceFamilyID, uint8_t deviceTypeID);
#endif /* DEVICE_TYPE_MSG */
/*!
* @brief The application calls this function to indicate that a device
* set a Toggle LED Response message.
*
* @param pSrcAddr - short address of the device that sent the message
* @param ledState - 0 is off, 1 is on
*/
extern void Csf_toggleResponseReceived(ApiMac_sAddr_t *pSrcAddr, bool ledState);
/*!
* @brief The application calls this function to indicate that a device
* set a Toggle LED Response message.
*
* @param pSrcAddr - short address of the device that sent the message
* @param ledState - 0 is off, 1 is on
*/
extern void Csf_toggleResponseReceived(ApiMac_sAddr_t *pSrcAddr, bool ledState);
/*!
* @brief The application calls this function to blink o idenify LED.
*
* @param identifyTime - time in seconds to identify for
*/
#ifndef __unix__
extern void Csf_identifyLED(uint16_t identifyTime);
#endif
/*!
* @brief The application calls this function to indicate that the
* Coordinator's state has changed.
*
* @param state - new state
*/
extern void Csf_stateChangeUpdate(Cllc_states_t state);
/*!
* @brief Initialize the tracking clock.
*/
extern void Csf_initializeTrackingClock(void);
/*!
* @brief Initialize the identify clock.
*/
extern void Csf_initializeIdentifyClock(void);
/*!
* @brief set the tracking clock.
*
* @param trackingTime - set timer this value (in msec)
*/
extern void Csf_setTrackingClock(uint32_t trackingTime);
/*!
* @brief Initialize the broadcast clock.
*/
extern void Csf_initializeBroadcastClock(void);
/*!
* @brief set the broadcast cmd clock.
*
* @param broadcast time - set timer this value (in msec)
*/
extern void Csf_setBroadcastClock(uint32_t trackingTime);
/*!
* @brief Initialize the trickle timer clock
*/
extern void Csf_initializeTrickleClock(void);
/*!
* @brief Initialize the clock setting join permit duration
*/
extern void Csf_initializeJoinPermitClock(void);
/*!
* @brief Initialize the clock setting config request delay
*/
extern void Csf_initializeConfigClock(void);
/*!
* @brief Set trickle clock
*
* @param trickleTime - duration of trickle timer( in msec)
* @param frameType - type of Async frame
*/
extern void Csf_setTrickleClock(uint32_t trickleTime, uint8_t frameType);
/*!
* @brief Set Join Permit clock
*
* @param joinDuration - duration for which join permit is TRUE( in msec)
*/
extern void Csf_setJoinPermitClock(uint32_t joinDuration);
/*!
* @brief Set Config request delay clock
*
* @param delay - duration config request event is set( in msec)
*/
extern void Csf_setConfigClock(uint32_t delay);
/*!
* @brief Read the number of device list items stored
*
* @return number of entries in the device list
*/
extern uint16_t Csf_getNumDeviceListEntries(void);
/*!
* @brief Find the short address from a given extended address
*
* @param pExtAddr - extended address
*
* @return CSF_INVALID_SHORT_ADDR if not found, otherwise the short address
*/
extern uint16_t Csf_getDeviceShort(ApiMac_sAddrExt_t *pExtAddr);
/*!
* @brief Find entry in device list from an address
*
* @param pDevAddr - device address
* @param pItem - place to put the device information
*
* @return true if found, false if not
*/
extern bool Csf_getDevice(ApiMac_sAddr_t *pDevAddr, Llc_deviceListItem_t *pItem);
/*!
* @brief Find entry in device list
*
* @param devIndex - Device number (not address)
* @param pItem - place to put the device information
*
* @return true if found, false if not
*/
extern bool Csf_getDeviceItem(uint16_t devIndex, Llc_deviceListItem_t *pItem);
/*!
* @brief Find entry in device list
*
* @param size - number of bytes to allocate from heap
*
* @return true if found, false if not
*/
extern void *Csf_malloc(uint16_t size);
/*!
* @brief Csf implementation for memory de-allocation
*
* @param ptr - a valid pointer to the memory to free
*/
extern void Csf_free(void *ptr);
/*!
* @brief Update the Frame Counter
*
* @param pDevAddr - pointer to device's address. If this pointer
* is NULL, it means that this is the frame counter
* for this device.
* @param frameCntr - valur of frame counter
*/
extern void Csf_updateFrameCounter(ApiMac_sAddr_t *pDevAddr,
uint32_t frameCntr);
/*!
* @brief Get the Frame Counter
*
* @param pDevAddr - pointer to device's address. If this pointer
* is NULL, it means that this is the frame counter
* for this device.
* @param pFrameCntr - pointer to place to put the frame counter
*
* @return true if the frame counter existed, false if not.
*/
extern bool Csf_getFrameCounter(ApiMac_sAddr_t *pDevAddr,
uint32_t *pFrameCntr);
/*!
* @brief Delete an entry from the device list
*
* @param pAddr - address to remove from device list.
*/
extern void Csf_removeDeviceListItem(ApiMac_sAddrExt_t *pAddr);
/*!
* @brief Assert Indication
*
* @param reason - Reason for Assert
* 2 - HAL/ICALL
* 3 - MAC
* 4 - TIRTOS
*/
extern void Csf_assertInd(uint8_t reason);
/*!
* @brief Clear all the NV Items
*/
extern void Csf_clearAllNVItems(void);
/*!
* @brief Check if config timer is active
*
* @return true if active, false if not active
*/
extern bool Csf_isConfigTimerActive(void);
/*!
* @brief Check if tracking timer is active
*
* @return true if active, false if not active
*/
extern bool Csf_isTrackingTimerActive(void);
/*!
* @brief Handles printing that the orphaned device joined back
*
* @return none
*/
extern void Csf_IndicateOrphanReJoin(uint16_t shortAddr);
/*!
* @brief The application calls this function to open the network.
*/
extern void Csf_openNwk(void);
/*!
* @brief The application calls this function to close the network.
*/
extern void Csf_closeNwk(void);
#ifdef FEATURE_SECURE_COMMISSIONING
/*!
* @brief The application calls this function to get a passkey.
*
* @param passkeyAction - passkey entry request or timeout.
*/
extern void Csf_SmPasskeyEntry(SM_passkeyEntry_t passkeyAction);
#endif //FEATURE_SECURE_COMMISSIONING
/*!
* @brief The application calls this function to disassociate from a sensor.
*/
extern int Csf_sendDisassociateMsg(uint16_t deviceShortAddr);
/*!
* @brief The application calls this function to get device ext. address.
*/
extern int Csf_getDeviceExtAdd(uint16_t deviceShortAddr, ApiMac_sAddrExt_t * extAddr);
#ifdef USE_DMM
/*!
* @brief Initialize the provisioning clock.
*/
extern void Csf_initializeProvisioningClock(void);
/*!
* @brief set the provisioning clock.
*
* @param provision - true to set/start provisioning timeout clock,
* false to set disassociation delay.
*/
extern void Csf_setProvisioningClock(bool provision);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CSF_H */