-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathncp-callback-stubs.c
executable file
·395 lines (351 loc) · 14.7 KB
/
ncp-callback-stubs.c
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
// This file is generated by Simplicity Studio. Please do not edit manually.
//
//
#include PLATFORM_HEADER
#include CONFIGURATION_HEADER
#include EMBER_AF_API_EMBER_TYPES
#include "app/util/ezsp/ezsp-enum.h"
#include "app/util/ezsp/ezsp-frame-utilities.h"
#include EMBER_AF_API_HAL
#include EMBER_AF_API_SIM_EEPROM
#include EMBER_AF_API_ZIGBEE_PRO
#include EMBER_AF_API_STACK
void emberAfCounterHandler(EmberCounterType type, EmberCounterInfo info)
{
}
/** @brief NCP Application hook callback for green power messages.
*
* This function is called by the application hook plugin to allow
* user to take an action gpd message is received. The return code
* true indicate the user handled the message and false allows the
* stack to handle it.
*
* @param status Ver.: always
* @param gpdLink Ver.: always
* @param sequenceNumber Ver.: always
* @param *addr Ver.: always
* @param gpdfSecurityLevel Ver.: always
* @param gpdfSecurityKeyType Ver.: always
* @param autoCommissioning Ver.: always
* @param rxAfterTx Ver.: always
* @param gpdSecurityFrameCounter Ver.: always
* @param gpdCommandId Ver.: always
* @param mic Ver.: always
* @param proxyTableIndex Ver.: always
* @param gpdCommandPayloadLength Ver.: always
* @param *gpdCommandPayload Ver.: always
*/
bool emberAfNcpGpepIncomingMessageHandler(GP_PARAMS)
{
// return false so that stack will handle it, return true
// if the message has been handled by user.
return false;
}
void emberDebugHandler(EmberMessageBuffer message)
{
}
/** @brief Called when emberTrustCenterJoinHandler is called from the stack.
*
* The NCP will perform initial processing based on the current
* ::EZSP_TRUST_CENTER_POLICY value and will pass this callback to the
* NCP application. Implementations of this callback should return the
* ::EmberJoinDecision value that will dictate the behavior of the trust center
* in response to the new device joining or rejoining to the network.
*
* See documentation on the stack emberTrustCenterJoinHandler callback
* for more information.
*
* @param newNodeId The node ID of the device wishing to join.
* @param newNodeEui64 The EUI64 of the device wishing to join.
* @param status The ::EmberUpdateDevice status indicating whether the
* device is joining/rejoining or leaving, and whether the join/rejoin is
* secure (using network encryption) or a trust center rejoin.
* @param parentOfNewNode The node ID of the parent of device wishing to join.
* @param decisionId The ::EzspDecisionId that the NCP is currently using
* as set by the HOST application.
* @param joinDecision The current ::EmberJoinDecision that the NCP has chosen
* based on the ::EzspDecisionId for the ::EZSP_TRUST_CENTER_POLICY as set by the
* HOST application. Implementations of this callback may want to return a
* different value based on their desired security.
*
* @return An ::EmberJoinDecision value that will dictate the behavior of the
* trust center in response to the new device joining or rejoining to
* the network.
*/
EmberJoinDecision emberAfPluginEzspSecurityTrustCenterJoinCallback(EmberNodeId newNodeId,
const EmberEUI64 newNodeEui64,
EmberDeviceUpdate status,
EmberNodeId parentOfNewNode,
EzspDecisionId decisionId,
EmberJoinDecision joinDecision)
{
return joinDecision;
}
/**
* @brief Called whenever the radio is powered on.
*/
void halRadioPowerUpHandler(void)
{
}
/**
* @brief Called whenever the radio is powered off.
*/
void halRadioPowerDownHandler(void)
{
}
/** @brief Called in each iteration of the main application loop.
*
* This function is called in each iteration of the main application loop and
* can be used to perform periodic functions. The frequency with which this
* function is called depends on how quickly the main loop runs. If the
* application blocks at any time during the main loop, this function will not
* be called until execution resumes.
*/
void emberAfMainTickCallback(void)
{
}
void emberSetOrGetEzspTokenCommandHandler(bool isSet)
{
appendInt8u(EMBER_INVALID_CALL);
}
/** @brief The Simulated EEPROM callback function, implemented by the
* application.
*
* @param status An ::EmberStatus error code indicating one of the conditions
* described below.
*
* This callback will report an EmberStatus of
* ::EMBER_SIM_EEPROM_ERASE_PAGE_GREEN whenever a token is set and a page needs
* to be erased. If the main application loop does not periodically
* call halSimEepromErasePage(), it is best to then erase a page in
* response to ::EMBER_SIM_EEPROM_ERASE_PAGE_GREEN.
*
* This callback will report an EmberStatus of ::EMBER_SIM_EEPROM_ERASE_PAGE_RED
* when the pages <i>must</i> be erased to prevent data loss.
* halSimEepromErasePage() needs to be called until it returns 0 to indicate
* there are no more pages that need to be erased. Ignoring
* this indication and not erasing the pages will cause dropping the new data
* trying to be written.
*
* This callback will report an EmberStatus of ::EMBER_SIM_EEPROM_FULL when
* the new data cannot be written due to unerased pages. <b>Not erasing
* pages regularly, not erasing in response to
* ::EMBER_SIM_EEPROM_ERASE_PAGE_GREEN, or not erasing in response to
* ::EMBER_SIM_EEPROM_ERASE_PAGE_RED will cause
* ::EMBER_SIM_EEPROM_FULL and the new data will be lost!.</b> Any future
* write attempts will be lost as well.
*
* This callback will report an EmberStatus of ::EMBER_SIM_EEPROM_REPAIRING
* when the Simulated EEPROM needs to repair itself. While there's nothing
* for an app to do when the SimEE is going to repair itself (SimEE has to
* be fully functional for the rest of the system to work), alert the
* application to the fact that repairing is occurring. There are debugging
* scenarios where an app might want to know that repairing is happening;
* such as monitoring frequency.
* @note Common situations will trigger an expected repair, such as using
* a new chip or changing token definitions.
*
* If the callback ever reports the status ::EMBER_ERR_FLASH_WRITE_INHIBITED or
* ::EMBER_ERR_FLASH_VERIFY_FAILED, a catastrophic failure has occurred in
* flash writing, meaning either the address being written is not empty or the
* write itself has failed. If ::EMBER_ERR_FLASH_WRITE_INHIBITED is
* encountered, the function ::halInternalSimEeRepair(false) should be called
* and the chip should then be reset to allow proper initialization to recover.
* If ::EMBER_ERR_FLASH_VERIFY_FAILED is encountered the Simulated EEPROM (and
* tokens) on the specific chip with this error should not be trusted anymore.
*
*/
void halSimEepromCallback(EmberStatus status)
{
switch (status) {
case EMBER_SIM_EEPROM_ERASE_PAGE_GREEN:
//SimEE is asking for one page to be erased.
halSimEepromErasePage();
break;
case EMBER_SIM_EEPROM_ERASE_PAGE_RED:
case EMBER_SIM_EEPROM_FULL:
{ //SimEE says we're out of room! Erase all pages now or data
//currently being written will be dropped.
if(halSimEepromPagesRemainingToBeErased() > 0) {
//If there is at least one HW page to erase, loop over ErasePage until
//all HW pages are erased. Without this explicit check before
//ErasePage, when halSimEepromErasePage() returns 0 the code wont
//know if a page was actually erased or not and properly break out.
while(halSimEepromErasePage()) {
}
// A fresh virtual page now exists to use
break;
}
//If there are still pages to erase, then we have a situation where page
//rotation is stuck because live tokens still exist in the
//page we want to erase. In this case we must do a repair to
//get all live tokens into one virtual page. [BugzId:14392]
//This bug pertains to SimEE2.
//Fall into...
}
case EMBER_ERR_FLASH_WRITE_INHIBITED:
case EMBER_ERR_FLASH_VERIFY_FAILED:
{ //Something went wrong while writing a token. There is stale data and the
//token the app expected to write did not get written. Also there may
//now be "stray" data written in the flash that could inhibit future token
//writes. To deal with stray/stale data, we must repair the Simulated
//EEPROM. Because the expected token write failed and will not be retried,
//it is best to reset the chip and let normal boot sequences take over.
//Since halInternalSimEeRepair() could potentially result in another write
//failure, we use a simple semaphore to prevent recursion.
static bool repairActive = false;
if(!repairActive) {
repairActive = true;
halInternalSimEeRepair(false);
switch (status) {
case EMBER_SIM_EEPROM_ERASE_PAGE_RED:
case EMBER_SIM_EEPROM_FULL:
//Don't reboot - return to let SimEE code retry the token write
//[BugzId:14392]
break;
case EMBER_ERR_FLASH_VERIFY_FAILED:
//[[WBB350FIXME -It would be nice to have a unified, ]]
//[[ platform independent reboot mechanism]]
#if defined (CORTEXM3)
halInternalSysReset(RESET_FLASH_VERIFY);
#else
assert(0);
#endif
break;
case EMBER_ERR_FLASH_WRITE_INHIBITED:
#if defined (CORTEXM3)
halInternalSysReset(RESET_FLASH_INHIBIT);
#else
assert(0);
#endif
break;
default:
assert(0);
break;
}
repairActive = false;
}
break;
}
case EMBER_SIM_EEPROM_REPAIRING:
// While there's nothing for an app to do when the SimEE is going to
// repair itself (SimEE has to be fully functional for the rest of the
// system to work), alert the application to the fact that repairing
// is occurring. There are debugging scenarios where an app might want
// to know that repairing is happening; such as monitoring frequency.
// NOTE: Common situations will trigger an expected repair, such as
// using an erased chip or changing token definitions.
break;
default:
// this condition indicates an unexpected problem.
assert(0);
break;
}
}
void emberOrphanNotificationHandler(EmberEUI64 longId)
{
return;
}
EmberStatus emberPanIdConflictHandler(int8_t conflictCount)
{
return EMBER_SUCCESS;
}
/**@brief Invoked by the EmberZNet stack to filter out incoming
* application MAC passthrough messages. If this returns true for a message
* the complete message will be passed to emberMacPassthroughMessageHandler()
* with a type of EMBER_MAC_PASSTHROUGH_APPLICATION.
*
* Note that this callback may be invoked in ISR context and should execute as
* quickly as possible.
*
* Note that this callback may be called more than once per incoming message.
* Therefore, the callback code should not depend on being called only once,
* and should return the same value each time it is called with a given header.
*
* If the application includes this callback, it must define
* EMBER_APPLICATION_HAS_MAC_PASSTHROUGH_FILTER_HANDLER in its
* CONFIGURATION_HEADER.
*
* @param macHeader A pointer to the initial portion of the
* incoming MAC header. This contains the MAC frame control and
* addressing fields. Subsequent MAC fields, and the MAC payload,
* may not be present.
* @return true if the messages is an application MAC passthrough message.
*/
bool emberMacPassthroughFilterHandler(uint8_t *macHeader)
{
return false;
}
/** @brief Intercepts an incoming packet from the stack and hands off to a plugin
* for further processing
*
* @param packetType The type of packet and the target stack layer. See
* ::EmberZigbeePacketType.
* @param packetBuffer The ::EmberMessageBuffer containing the packet.
* @parma index The starting index of the relevant packet data. The plugin\
* will receive a flat copy of the packet starting from this index.
* @param data Auxiliary data pointer
*
* @return See ::EmberPacketAction
*/
EmberPacketAction emberPacketHandoffIncoming(EmberZigbeePacketType packetType,
EmberMessageBuffer packetBuffer,
uint8_t index,
void *data)
{
return EMBER_ACCEPT_PACKET;
}
/** @brief Intercepts an outgoing packet from the stack and hands off to a plugin
* for further processing
*
* @param packetType The type of packet and the source stack layer. See
* ::EmberZigbeePacketType.
* @param packetBuffer The ::EmberMessageBuffer containing the packet.
* @param index The starting index of the relevant packet data. The plugin\
* will receive a flat copy of the packet starting from this index.
* @param data Auxiliary data pointer
*
* @return See ::EmberPacketAction
*/
EmberPacketAction emberPacketHandoffOutgoing(EmberZigbeePacketType packetType,
EmberMessageBuffer packetBuffer,
uint8_t index,
void *data)
{
return EMBER_ACCEPT_PACKET;
}
/** @brief Allows the application to manage idling the MCU.
*
* @return True if the application is managing idling the MCU, false otherwise.
* If this function returns false, the stack will manage idling the MCU.
*/
bool emberRtosIdleHandler(uint32_t *idleTimeMs)
{
return false;
}
/** @brief Requests the application to wake up the stack task.
*/
void emberRtosStackWakeupIsrHandler(void)
{
}
/** @brief The radio calibration callback function.
*
* The Voltage Controlled Oscillator (VCO) can drift with
* temperature changes. During every call to ::emberTick(), the stack will
* check to see if the VCO has drifted. If the VCO has drifted, the stack
* will call ::emberRadioNeedsCalibratingHandler() to inform the application
* that it should perform calibration of the current channel as soon as
* possible. Calibration can take up to 150 ms. The default callback function
* implementation provided here performs calibration immediately. The
* application can define its own callback by defining
* ::EMBER_APPLICATION_HAS_CUSTOM_RADIO_CALIBRATION_CALLBACK in its
* CONFIGURATION_HEADER. It can then failsafe any critical processes or
* peripherals before calling ::emberCalibrateCurrentChannel(). The
* application must call ::emberCalibrateCurrentChannel() in
* response to this callback to maintain expected radio performance.
*/
void emberRadioNeedsCalibratingHandler(void)
{
// TODO: Failsafe any critical processes or peripherals.
emberCalibrateCurrentChannel();
}