-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_handlers.c
3304 lines (2899 loc) · 119 KB
/
cmd_handlers.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
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file cmd_handlers.c
* @copyright 2022 Silicon Laboratories Inc.
*/
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <AppTimer.h>
#include <SyncEvent.h>
#include <ZAF_Common_interface.h>
#include <ZW_application_transport_interface.h>
#include <Min2Max2.h>
#include <SizeOf.h>
#include <zpal_misc.h>
#include <zpal_watchdog.h>
//#define DEBUGPRINT
#include <DebugPrint.h>
#include "app_node_info.h"
#include "virtual_slave_node_info.h"
#include "cmd_handlers.h"
#include "cmds_management.h"
#include "cmds_proprietary.h"
#include "cmds_security.h"
#include "cmds_rf.h"
#include "SerialAPI.h"
#include "app.h"
#include "serialapi_file.h"
#include "utils.h"
#include "nvm_backup_restore.h"
#include "zaf_protocol_config.h"
#if SUPPORT_ZW_AES_ECB
#include <ZW_aes_api.h>
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
extern bool bTxStatusReportEnabled;
SSyncEventArg1 LearnModeStatusCb = {.uFunctor.pFunction = 0}; // Ensure function pointer is initialized
SSyncEvent SetDefaultCB = {.uFunctor.pFunction = 0}; // Ensure function pointer is initialized
#ifdef ZW_CONTROLLER
static uint8_t addState = 0;
uint8_t funcID_ComplHandler_ZW_NodeManagement;
uint8_t nodeManagement_Func_ID;
#endif
#ifdef ZW_CONTROLLER
static void SetupNodeManagement(const comm_interface_frame_ptr frame, uint8_t funcID_offet)
{
nodeManagement_Func_ID = frame->cmd;
funcID_ComplHandler_ZW_NodeManagement = *(frame->payload + funcID_offet);
set_state_and_notify(stateIdle);
addState = 0;
}
#endif
#if SUPPORT_ZW_INITIATE_SHUTDOWN
/*
This callback function called from protocol just before going into deep sleep (Deep Sleep)
The function itself sends a respond to the host notifying it that the device is ready to go into deep sleep.
*/
static void Initiate_shutdown_cb(void)
{
// 0x1 0x03 0x00 0xd9
const uint8_t status = 0x01;
comm_interface_transmit_frame(FUNC_ID_ZW_INITIATE_SHUTDOWN, RESPONSE, &status, sizeof(status), NULL);
comm_interface_wait_transmit_done();
}
/*
HOST->ZW
ZW-HOST 0x01
*/
ZW_ADD_CMD(FUNC_ID_ZW_INITIATE_SHUTDOWN)
{
AppTimerStopAll();
if (InitiateShutdown(&Initiate_shutdown_cb))
{
set_state_and_notify(stateIdle);
}
else
{
// somthing went wrong we failed to start the graceful shutdown
DoRespond(0);
}
}
#endif
#if SUPPORT_FUNC_ID_CLEAR_TX_TIMERS
static void ClearTxTimers(void)
{
SZwaveCommandPackage CommandPackage = { .eCommandType = EZWAVECOMMANDTYPE_CLEAR_TX_TIMERS };
// Put the package on queue (and DO wait for it, since there is no feedback to serial master)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwCommandQueue(), (uint8_t *)&CommandPackage, 500);
if (EQUEUENOTIFYING_STATUS_SUCCESS != QueueStatus)
{
DPRINT("Warning: Failed to clear Tx timers");
}
}
ZW_ADD_CMD(FUNC_ID_CLEAR_TX_TIMERS)
{
/* HOST->ZW: */
ClearTxTimers();
set_state(stateIdle);
}
#endif /* SUPPORT_FUNC_ID_CLEAR_TX_TIMERS */
#if SUPPORT_FUNC_ID_GET_TX_TIMERS
ZW_ADD_CMD(FUNC_ID_GET_TX_TIMERS)
{
/* HOST->ZW: */
/* ZW->HOST: channel0TxTimer_MSB | channel0TxTimer_Next_MSB | channel0TxTimer_Next_LSB | channel0TxTimerLSB | */
/* channel1TxTimer_MSB | channel1TxTimer_Next_MSB | channel1TxTimer_Next_LSB | channel1TxTimerLSB | */
/* channel2TxTimer_MSB | channel2TxTimer_Next_MSB | channel2TxTimer_Next_LSB | channel2TxTimerLSB | */
/* channel3TxTimer_MSB | channel3TxTimer_Next_MSB | channel3TxTimer_Next_LSB | channel3TxTimerLSB | */
/* channel4TxTimer_MSB | channel4TxTimer_Next_MSB | channel4TxTimer_Next_LSB | channel4TxTimerLSB */
// Copy current Network Statistic counters
const zpal_radio_network_stats_t *sRFStats = ZAF_getNetworkStatistics();
uint8_t i = 0;
// Copy with endian swap
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 0) & 0xff);
DoRespond_workbuf(i);
}
#endif /* SUPPORT_FUNC_ID_GET_TX_TIMERS */
#if SUPPORT_ZW_GET_BACKGROUND_RSSI
static void GetBackgroundRSSI(RSSI_LEVELS *noise_levels)
{
SZwaveCommandPackage cmdPackage = {.eCommandType = EZWAVECOMMANDTYPE_GET_BACKGROUND_RSSI};
__attribute__((unused)) EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwCommandQueue(), (uint8_t *)&cmdPackage, 0);
assert(EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus);
SZwaveCommandStatusPackage cmdStatus = { 0 };
if (GetCommandResponse(&cmdStatus, EZWAVECOMMANDSTATUS_GET_BACKGROUND_RSSI))
{
memcpy((uint8_t *)noise_levels, cmdStatus.Content.GetBackgroundRssiStatus.rssi, sizeof(RSSI_LEVELS));
return;
}
assert(false); // FIXME We should have more intelligent error handling, we shouldnt assert here.
}
ZW_ADD_CMD(FUNC_ID_ZW_GET_BACKGROUND_RSSI)
{
/* HOST->ZW: (no arguments) */
/* ZW->HOST: RES | RSSI Ch0 | RSSI Ch1 | RSSI Ch2 */
GetBackgroundRSSI((RSSI_LEVELS*)&compl_workbuf[0]);
DoRespond_workbuf(sizeof(RSSI_LEVELS));
}
#endif
#if SUPPORT_ZW_CLEAR_NETWORK_STATS
static void ClearNetworkStats(void)
{
SZwaveCommandPackage CommandPackage = {.eCommandType = EZWAVECOMMANDTYPE_CLEAR_NETWORK_STATISTICS};
// Put the package on queue (and dont wait for it)
__attribute__((unused)) EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwCommandQueue(), (uint8_t *)&CommandPackage, 0);
assert(EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus);
}
ZW_ADD_CMD(FUNC_ID_ZW_CLEAR_NETWORK_STATS)
{
/* HOST->ZW: */
/* ZW->HOST: 0x01 */
ClearNetworkStats();
DoRespond(1);
}
#endif /* SUPPORT_ZW_CLEAR_NETWORK_STATS */
#if SUPPORT_ZW_GET_NETWORK_STATS
ZW_ADD_CMD(FUNC_ID_ZW_GET_NETWORK_STATS)
{
/* HOST->ZW: */
/* ZW->HOST: wRFTxFrames_MSB | wRFTxFrames_LSB | */
/* wRFTxLBTBackOffs_MSB | wRFTxLBTBackOffs_LSB | */
/* wRFRxFrames_MSB | wRFRxFrames_LSB */
/* wRFRxLRCErrors_MSB | wRFRxLRCErrors_LSB */
/* wRFRxCRCErrors_MSB | wRFRxCRCErrors_LSB */
/* wRFRxForeignHomeID_MSB | wRFRxForeignHomeID_LSB */
// Copy current Network Statistic counters
const zpal_radio_network_stats_t *sRFStats = ZAF_getNetworkStatistics();
int i = 0;
// Copy with endian swap
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_frames >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_frames >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_lbt_back_offs >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_lbt_back_offs >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_frames >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_frames >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_lrc_errors >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_lrc_errors >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_crc_errors >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_crc_errors >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_foreign_home_id >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->rx_foreign_home_id >> 0) & 0xff);
DoRespond_workbuf((uint8_t)i);
}
#endif /* SUPPORT_ZW_GET_NETWORK_STATS */
#if SUPPORT_ZW_SET_RF_RECEIVE_MODE
uint8_t SetRFReceiveMode(uint8_t mode)
{
SZwaveCommandPackage pCmdPackage = {
.eCommandType = EZWAVECOMMANDTYPE_SET_RF_RECEIVE_MODE,
.uCommandParams.SetRfReceiveMode.mode = mode};
// Put the Command on queue (and dont wait for it, queue must be empty)
__attribute__((unused)) EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwCommandQueue(), (uint8_t *)&pCmdPackage, 0);
assert(EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus);
SZwaveCommandStatusPackage cmdStatus = { 0 };
if (GetCommandResponse(&cmdStatus, EZWAVECOMMANDSTATUS_SET_RF_RECEIVE_MODE))
{
return cmdStatus.Content.SetRFReceiveModeStatus.result;
}
assert(0);
return 0;
}
ZW_ADD_CMD(FUNC_ID_ZW_SET_RF_RECEIVE_MODE)
{
/* HOST->ZW: mode */
/* ZW->HOST: retVal */
const uint8_t retVal = SetRFReceiveMode(frame->payload[0]);
DoRespond(retVal);
}
#endif /* SUPPORT_ZW_SET_RF_RECEIVE_MODE */
#if SUPPORT_ZW_SEND_NODE_INFORMATION
uint8_t funcID_ComplHandler_ZW_SendNodeInformation;
static uint8_t SendNodeInformation(uint16_t destID, uint8_t txOptions, ZW_TX_Callback_t pCallBack)
{
SZwaveTransmitPackage FramePackage = {
.uTransmitParams.NodeInfo.DestNodeId = destID,
.uTransmitParams.NodeInfo.TransmitOptions = txOptions,
.uTransmitParams.NodeInfo.Handle = (ZW_Void_Callback_t)pCallBack,
.eTransmitType = EZWAVETRANSMITTYPE_NODEINFORMATION
};
// Put the package on queue (and dont wait for it)
EQueueNotifyingStatus QueueStatus;
QueueStatus = QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t *)&FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
/*===================== ComplHandler_ZW_SendNodeInformation =============
** Completion handler for ZW_SendNodeInformation
**
**--------------------------------------------------------------------------*/
static void /* RET Nothing */
ZCB_ComplHandler_ZW_SendNodeInformation(
uint8_t txStatus, /* IN Transmit completion status */
__attribute__((unused)) TX_STATUS_TYPE *txStatusReport)
{
compl_workbuf[0] = funcID_ComplHandler_ZW_SendNodeInformation;
compl_workbuf[1] = txStatus;
Request(FUNC_ID_ZW_SEND_NODE_INFORMATION, compl_workbuf, 2);
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_NODE_INFORMATION)
{
/* HOST->ZW: destNode | txOptions | funcID */
/* ZW->HOST: retVal */
uint8_t offset = 0;
node_id_t destNode = (node_id_t)GET_NODEID(&frame->payload[0], offset);
funcID_ComplHandler_ZW_SendNodeInformation = frame->payload[offset + 2];
const uint8_t retVal = SendNodeInformation(destNode, frame->payload[offset + 1], (frame->payload[offset + 2] != 0) ? &ZCB_ComplHandler_ZW_SendNodeInformation : NULL);
DoRespond(retVal);
}
#endif /* SUPPORT_ZW_SEND_NODE_INFORMATION */
#if SUPPORT_ZW_SECURITY_SETUP
ZW_ADD_CMD(FUNC_ID_ZW_SECURITY_SETUP)
{
uint8_t length;
func_id_zw_security_setup(frame_payload_len(frame), frame->payload, compl_workbuf, &length);
DoRespond_workbuf(length);
}
#endif
#if SUPPORT_ZW_SEND_DATA || SUPPORT_ZW_SEND_DATA_BRIDGE
uint8_t funcID_ComplHandler_ZW_SendData;
#endif
#if SUPPORT_ZW_SEND_PROTOCOL_DATA
static struct
{
uint8_t session_id;
uint8_t callback_id;
} nlsEncryptionMetadata = { 0 };
#endif
#if SUPPORT_ZW_SEND_DATA || SUPPORT_ZW_SEND_DATA_EX || SUPPORT_ZW_SEND_DATA_BRIDGE
static void
GenerateTxStatusRequest(
uint8_t cmd,
uint8_t txStatusfuncID,
uint8_t txStatus,
TX_STATUS_TYPE *txStatusReport) /* IN Transmit completion status */
{
uint8_t bIdx = 0;
compl_workbuf[bIdx++] = txStatusfuncID;
compl_workbuf[bIdx++] = txStatus;
if (bTxStatusReportEnabled /* Do HOST want txStatusReport */
&& txStatusReport) /* Check if detailed info is available from protocol */
{
compl_workbuf[bIdx++] = (uint8_t)((((txStatusReport->TransmitTicks / 10) & 0xFFFFFF) >> 8) & 0xFF);
compl_workbuf[bIdx++] = (uint8_t)(((txStatusReport->TransmitTicks / 10) & 0xFFFFFF) & 0xFF);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bRepeaters);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->rssi_values.incoming[0]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->rssi_values.incoming[1]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->rssi_values.incoming[2]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->rssi_values.incoming[3]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->rssi_values.incoming[4]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bACKChannelNo);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bLastTxChannelNo);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bRouteSchemeState);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->pLastUsedRoute[0]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->pLastUsedRoute[1]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->pLastUsedRoute[2]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->pLastUsedRoute[3]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->pLastUsedRoute[4]);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bRouteTries);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bLastFailedLink.from);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bLastFailedLink.to);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bUsedTxpower);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bMeasuredNoiseFloor);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bDestinationAckUsedTxPower);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bDestinationAckMeasuredRSSI);
compl_workbuf[bIdx++] = (uint8_t)(txStatusReport->bDestinationAckMeasuredNoiseFloor);
}
Request(cmd, compl_workbuf, bIdx);
}
#endif
#if SUPPORT_ZW_SEND_DATA
/*====================== ComplHandler_ZW_SendData ========================
** Completion handler for ZW_SendData
**
**--------------------------------------------------------------------------*/
static void /* RET Nothing */
ZCB_ComplHandler_ZW_SendData(
uint8_t txStatus,
TX_STATUS_TYPE *txStatusReport) /* IN Transmit completion status */
{
GenerateTxStatusRequest(FUNC_ID_ZW_SEND_DATA, funcID_ComplHandler_ZW_SendData, txStatus, txStatusReport);
}
static uint8_t SendData(uint16_t nodeID, const uint8_t *pData, uint8_t dataLength, uint8_t txOptions, ZW_TX_Callback_t pCallBack)
{
#ifndef ZW_SECURITY_PROTOCOL
SZwaveTransmitPackage FramePackage = {
.uTransmitParams.SendData.DestNodeId = nodeID,
.uTransmitParams.SendData.FrameConfig.TransmitOptions = txOptions,
.uTransmitParams.SendData.FrameConfig.Handle = pCallBack,
.eTransmitType = EZWAVETRANSMITTYPE_STD,
.uTransmitParams.SendData.FrameConfig.iFrameLength = dataLength,
};
memcpy(FramePackage.uTransmitParams.SendData.FrameConfig.aFrame, pData, dataLength);
#else
SZwaveTransmitPackage FramePackage = {
.uTransmitParams.SendDataEx.DestNodeId = nodeID,
.uTransmitParams.SendDataEx.FrameConfig.TransmitOptions = txOptions,
.uTransmitParams.SendDataEx.FrameConfig.Handle = pCallBack,
.eTransmitType = EZWAVETRANSMITTYPE_EX,
.uTransmitParams.SendDataEx.FrameConfig.iFrameLength = dataLength,
};
memcpy(FramePackage.uTransmitParams.SendDataEx.FrameConfig.aFrame, pData, dataLength);
#endif
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t *)&FramePackage, 0));
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_DATA)
{
/* HOST->ZW: nodeID | dataLength | pData[] | txOptions | funcID */
/* ZW->HOST: RetVal */
/* If RetVal == false -> no callback */
/* If RetVal == true then callback returns with */
/* ZW->HOST: funcID | txStatus | wTransmitTicksMSB | wTransmitTicksLSB | bRepeaters | rssi_values.incoming[0] |
* rssi_values.incoming[1] | rssi_values.incoming[2] | rssi_values.incoming[3] | rssi_values.incoming[4] |
* bRouteSchemeState | repeater0 | repeater1 | repeater2 | repeater3 | routespeed |
* bRouteTries | bLastFailedLink.from | bLastFailedLink.to |
* bUsedTxpower | bMeasuredNoiseFloor | bAckDestinationUsedTxPower | bDestinationAckMeasuredRSSI |
* bDestinationckMeasuredNoiseFloor */
uint8_t offset = 0;
node_id_t nodeId = (node_id_t)GET_NODEID(&frame->payload[0], offset);
uint8_t dataLength = frame->payload[offset + 1];
assert(dataLength <= BUF_SIZE_RX);
dataLength = MIN(dataLength, BUF_SIZE_RX);
const uint8_t * const pSerInData = frame->payload + offset + 2;
funcID_ComplHandler_ZW_SendData = frame->payload[offset + 3 + dataLength];
// Create transmit frame package
const uint8_t retVal = SendData(nodeId, pSerInData, dataLength, frame->payload[offset + 2 + dataLength],
(funcID_ComplHandler_ZW_SendData) ? &ZCB_ComplHandler_ZW_SendData : NULL);
DoRespond(retVal);
}
#endif
#if SUPPORT_ZW_SEND_DATA_EX
uint8_t funcID_ComplHandler_ZW_SendDataEx;
/*====================== ComplHandler_ZW_SendDataEx ========================
** Completion handler for ZW_SendDataEx
**
**--------------------------------------------------------------------------*/
static void /* RET Nothing */
ZCB_ComplHandler_ZW_SendDataEx(
uint8_t txStatus,
TX_STATUS_TYPE *txStatusReport) /* IN Transmit completion status */
{
GenerateTxStatusRequest(FUNC_ID_ZW_SEND_DATA_EX, funcID_ComplHandler_ZW_SendDataEx, txStatus, txStatusReport);
}
static uint8_t SendDataEx(uint16_t nodeID, uint8_t *pData, uint8_t dataLength,
uint8_t txOptions, uint8_t txSecOptions, uint8_t txOptions2, uint8_t secKeyType,
ZW_TX_Callback_t pCallBack)
{
// Create transmit frame package
SZwaveTransmitPackage FramePackage = {
.uTransmitParams.SendDataEx.DestNodeId = nodeID,
.uTransmitParams.SendDataEx.TransmitSecurityOptions = txSecOptions,
.uTransmitParams.SendDataEx.TransmitOptions2 = txOptions2,
.uTransmitParams.SendDataEx.eKeyType = secKeyType,
.uTransmitParams.SendDataEx.FrameConfig.TransmitOptions = txOptions,
.uTransmitParams.SendDataEx.FrameConfig.Handle = pCallBack,
.uTransmitParams.SendDataEx.FrameConfig.iFrameLength = dataLength,
.eTransmitType = EZWAVETRANSMITTYPE_EX
};
memcpy(&FramePackage.uTransmitParams.SendDataEx.FrameConfig.aFrame, pData, dataLength);
// Put the package on queue (and dont wait for it)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t *)&FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_DATA_EX)
{
/* HOST->ZW: nodeID | dataLength | pData[] | txOptions | txSecOptions | securityKey | txOptions2 | funcID */
/* ZW->HOST: RetVal */
/* If "RetVal != 1" -> no callback */
/* If "RetVal == 1" and "funcID != 0" then callback returns with */
/* ZW->HOST: funcID | txStatus | wTransmitTicksMSB | wTransmitTicksLSB | bRepeaters | rssi_values.incoming[0] | */
/* rssi_values.incoming[1] | rssi_values.incoming[2] | rssi_values.incoming[3] | rssi_values.incoming[4] | */
/* bRouteSchemeState | repeater0 | repeater1 | repeater2 | repeater3 | routespeed | */
/* bRouteTries | bLastFailedLink.from | bLastFailedLink.to */
uint8_t offset = 0;
node_id_t nodeId = (node_id_t)GET_NODEID(&frame->payload[0], offset);
uint8_t dataLength;
dataLength = frame->payload[offset + 1];
assert(dataLength <= BUF_SIZE_RX);
dataLength = MIN(dataLength, BUF_SIZE_RX);
funcID_ComplHandler_ZW_SendDataEx = frame->payload[offset + 6 + dataLength];
const uint8_t retVal = SendDataEx(nodeId, &frame->payload[offset + 2], dataLength, frame->payload[offset + 2 + dataLength],
frame->payload[offset + 3 + dataLength], frame->payload[offset + 5 + dataLength],
frame->payload[offset + 4 + dataLength], (funcID_ComplHandler_ZW_SendDataEx != 0) ? ZCB_ComplHandler_ZW_SendDataEx : NULL);
DoRespond(retVal);
}
#endif
#if SUPPORT_ZW_SEND_DATA_MULTI || SUPPORT_ZW_SEND_DATA_MULTI_BRIDGE
uint8_t funcID_ComplHandler_ZW_SendDataMulti;
#endif
#if SUPPORT_ZW_SEND_DATA_MULTI
/*===================== ComplHandler_ZW_SendDataMulti ====================
** Completion handler for ZW_SendDataMulti
**
**--------------------------------------------------------------------------*/
static void /* RET Nothing */
ZCB_ComplHandler_ZW_SendDataMulti(
uint8_t txStatus,
__attribute__((unused)) TX_STATUS_TYPE *txStatusType) /* IN Transmit completion status */
{
compl_workbuf[0] = funcID_ComplHandler_ZW_SendDataMulti;
compl_workbuf[1] = txStatus;
Request(FUNC_ID_ZW_SEND_DATA_MULTI, compl_workbuf, 2);
}
static uint8_t SendDataMulti(uint8_t numberOfNodes, const uint8_t *pNodeList, const uint8_t *pData, uint8_t dataLength, uint8_t txOptions, ZW_TX_Callback_t pCallBack)
{
// Create transmit frame package
SZwaveTransmitPackage FramePackage;
SSendDataMulti *pSendDataMulti = &FramePackage.uTransmitParams.SendDataMulti;
memset(&pSendDataMulti->FrameConfig.aFrame, 0, sizeof(pSendDataMulti->FrameConfig.aFrame));
/* clear the destination node mask */
memset(&pSendDataMulti->NodeMask, 0, sizeof(pSendDataMulti->NodeMask));
/* Set the destination node mask bits */
for (uint8_t i = 0; i < numberOfNodes && i < MAX_GROUP_NODES; i++)
{
ZW_NodeMaskSetBit(pSendDataMulti->NodeMask, pNodeList[i]);
}
assert(dataLength <= BUF_SIZE_RX);
dataLength = MIN(dataLength, BUF_SIZE_RX);
pSendDataMulti->FrameConfig.TransmitOptions = txOptions;
memcpy(&pSendDataMulti->FrameConfig.aFrame, pData, dataLength);
pSendDataMulti->FrameConfig.Handle = pCallBack;
FramePackage.eTransmitType = EZWAVETRANSMITTYPE_MULTI;
FramePackage.uTransmitParams.SendDataMulti.FrameConfig.iFrameLength = dataLength;
// Put the package on queue (and dont wait for it)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t *)&FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_DATA_MULTI)
{
/* numberNodes | pNodeIDList[] | dataLength | pData[] | txOptions | funcId */
// Create transmit frame package
uint8_t numOfNodes = frame->payload[0];
uint8_t tLength = frame->payload[1 + numOfNodes];
uint8_t tOptions = frame->payload[2 + numOfNodes + tLength];
funcID_ComplHandler_ZW_SendDataMulti = frame->payload[3 + numOfNodes + tLength];
const uint8_t retVal = SendDataMulti(numOfNodes, &frame->payload[1], &frame->payload[2 + numOfNodes], tLength, tOptions,
(funcID_ComplHandler_ZW_SendDataMulti != 0) ? &ZCB_ComplHandler_ZW_SendDataMulti : NULL);
DoRespond(retVal);
}
#endif
#if SUPPORT_ZW_SEND_DATA_MULTI_EX
uint8_t funcID_ComplHandler_ZW_SendDataMultiEx;
/*===================== ComplHandler_ZW_SendDataMulti ====================
** Completion handler for ZW_SendDataMulti
**
**--------------------------------------------------------------------------*/
static void
ZCB_ComplHandler_ZW_SendDataMultiEx(
uint8_t txStatus, /* IN Transmit completion status */
__attribute__((unused)) TX_STATUS_TYPE* extendedTxStatus)
{
compl_workbuf[0] = funcID_ComplHandler_ZW_SendDataMultiEx;
compl_workbuf[1] = txStatus;
Request(FUNC_ID_ZW_SEND_DATA_MULTI_EX, compl_workbuf, 2);
}
static uint8_t SendDataMultiEx(uint8_t dataLength, uint8_t *pData, uint8_t txOptions, uint8_t secKeyType, uint8_t groupID, ZW_TX_Callback_t pCallBack)
{
assert(dataLength <= BUF_SIZE_RX);
dataLength = MIN(dataLength, BUF_SIZE_RX);
// Create transmit frame package
SZwaveTransmitPackage FramePackage = {
.uTransmitParams.SendDataMultiEx.FrameConfig.Handle = pCallBack,
.uTransmitParams.SendDataMultiEx.FrameConfig.TransmitOptions = txOptions,
.uTransmitParams.SendDataMultiEx.FrameConfig.iFrameLength = dataLength,
.uTransmitParams.SendDataMultiEx.GroupId = groupID,
.uTransmitParams.SendDataMultiEx.eKeyType = secKeyType,
.eTransmitType = EZWAVETRANSMITTYPE_MULTI_EX
};
memcpy(&FramePackage.uTransmitParams.SendDataMultiEx.FrameConfig.aFrame, pData, dataLength);
// Put the package on queue (and dont wait for it)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t *)&FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_DATA_MULTI_EX)
{
/* dataLength | pData[] | txOptions | securityKey | groupId | funcId */
uint8_t dataLength = frame->payload[0];
funcID_ComplHandler_ZW_SendDataMultiEx = frame->payload[4 + dataLength];
uint8_t tOptions = frame->payload[1 + dataLength];
uint8_t tGID = frame->payload[3 + dataLength];
uint8_t tKey = frame->payload[2 + dataLength];
const uint8_t retVal = SendDataMultiEx(dataLength, &frame->payload[1], tOptions, tKey, tGID, (funcID_ComplHandler_ZW_SendDataMultiEx != 0) ? ZCB_ComplHandler_ZW_SendDataMultiEx : NULL);
DoRespond(retVal);
}
#endif
#if SUPPORT_ZW_SEND_DATA_ABORT
static void SendDataAbort(void)
{
// FIXME - we need to change the implementation of abort
// What makes sense? aborting based on frame context?
// We cant peek into FreeRtos queue...
// We could also reset the queue on abort. and stop any ongoing frame.
SZwaveCommandPackage CommandPackage = { .eCommandType = EZWAVECOMMANDTYPE_SEND_DATA_ABORT };
// Put the package on queue (and DO wait for it, since there is no feedback to serial master)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwCommandQueue(), (uint8_t *)&CommandPackage, 500);
if (EQUEUENOTIFYING_STATUS_SUCCESS != QueueStatus)
{
DPRINT("Warning: Failed to To call ZW_SendDataAbort");
}
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_DATA_ABORT)
{
/* If we are in middle of transmitting an application frame then STOP the transmission as soon as possible. */
SendDataAbort();
set_state_and_notify(stateIdle);
}
#endif
#if SUPPORT_ZW_SEND_DATA_BRIDGE
/*================= ComplHandler_ZW_SendData_Bridge ======================
** Completion handler for ZW_SendData_Bridge
**
**--------------------------------------------------------------------------*/
static void /* RET Nothing */
ZCB_ComplHandler_ZW_SendData_Bridge(
uint8_t txStatus,
TX_STATUS_TYPE *txStatusReport) /* IN Transmit completion status */
{
GenerateTxStatusRequest(FUNC_ID_ZW_SEND_DATA_BRIDGE, funcID_ComplHandler_ZW_SendData, txStatus, txStatusReport);
}
static uint8_t SendDataBridge(uint16_t srcNode, uint16_t destNode, uint8_t dataLength, const uint8_t *pData, uint8_t txOptions, ZW_TX_Callback_t pCallBack)
{
assert(dataLength <= BUF_SIZE_RX);
dataLength = MIN(dataLength, BUF_SIZE_RX);
// Create transmit frame package
SZwaveTransmitPackage FramePackage = {
.uTransmitParams.SendDataBridge.FrameConfig.Handle = pCallBack,
.uTransmitParams.SendDataBridge.FrameConfig.TransmitOptions = txOptions,
.uTransmitParams.SendDataBridge.FrameConfig.iFrameLength = dataLength,
.uTransmitParams.SendDataBridge.DestNodeId = destNode,
.uTransmitParams.SendDataBridge.SourceNodeId = srcNode,
.eTransmitType = EZWAVETRANSMITTYPE_BRIDGE
};
memcpy(&FramePackage.uTransmitParams.SendDataBridge.FrameConfig.aFrame, pData, dataLength);
// Put the package on queue (and dont wait for it)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t *)&FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_DATA_BRIDGE)
{
/* HOST->ZW: srcNodeID | destNodeID | dataLength | pData[] | txOptions | pRoute[4] | funcID */
/* Devkit 6.0x pRoute[4] not used... Use [0,0,0,0] */
uint8_t offset = 0;
node_id_t sourceNodeId;
node_id_t destNodeId;
sourceNodeId = (node_id_t)GET_NODEID(&frame->payload[0], offset);
destNodeId = (node_id_t)GET_NODEID(&frame->payload[1 + offset], offset);
uint8_t dataLength = frame->payload[offset + 2];
funcID_ComplHandler_ZW_SendData = frame->payload[offset + 3 + 1 + 4 + dataLength];
uint8_t tOptions = frame->payload[offset + 3 + dataLength];
const uint8_t retVal = SendDataBridge(sourceNodeId, destNodeId, dataLength, &frame->payload[offset + 3], tOptions,
(funcID_ComplHandler_ZW_SendData != 0) ? &ZCB_ComplHandler_ZW_SendData_Bridge : NULL);
DoRespond(retVal);
}
#endif
#if SUPPORT_ZW_SEND_DATA_MULTI_BRIDGE
/*================ ComplHandler_ZW_SendDataMulti_Bridge ==================
** Completion handler for ZW_SendDataMulti
**
**--------------------------------------------------------------------------*/
static void /* RET Nothing */
ZCB_ComplHandler_ZW_SendDataMulti_Bridge(
uint8_t txStatus, /* IN Transmit completion status */
__attribute__((unused)) TX_STATUS_TYPE* extendedTxStatus)
{
compl_workbuf[0] = funcID_ComplHandler_ZW_SendDataMulti;
compl_workbuf[1] = txStatus;
Request(FUNC_ID_ZW_SEND_DATA_MULTI_BRIDGE, compl_workbuf, 2);
}
static uint8_t SendDataMultiBridge(node_id_t srcNode, uint8_t numOfNodes, uint8_t *pNodeIDList,
uint8_t dataLength, const uint8_t *pData, uint8_t txOptions, ZW_TX_Callback_t pCallBack)
{
// when nodeIdBaseType is 2 then we handle the FramePackage.uTransmitParams.SendDataMultiBridge.NodeMask as node list
// when nodeIdBaseType is 1 then we handle the FramePackage.uTransmitParams.SendDataMultiBridge.NodeMask as node mask
// Create transmit frame package
assert(dataLength <= BUF_SIZE_RX);
dataLength = MIN(dataLength, BUF_SIZE_RX);
SZwaveTransmitPackage FramePackage = {
.uTransmitParams.SendDataMultiBridge.FrameConfig.Handle = pCallBack,
.uTransmitParams.SendDataMultiBridge.FrameConfig.TransmitOptions = txOptions,
.uTransmitParams.SendDataMultiBridge.FrameConfig.iFrameLength = dataLength,
.uTransmitParams.SendDataMultiBridge.SourceNodeId = srcNode,
.eTransmitType = EZWAVETRANSMITTYPE_MULTI_BRIDGE
};
memcpy(&FramePackage.uTransmitParams.SendDataMultiBridge.FrameConfig.aFrame, pData, dataLength);
bool lr_list = false;
bool classic_list = false;
if (SERIAL_API_SETUP_NODEID_BASE_TYPE_16_BIT == nodeIdBaseType) {
/*if nodeIdBaseType 2 then we should check if the list contain lr only nodes or classic only nodes mixed list is not allowed*/
if ((MULTICAST_NODE_LIST_SIZE>>1) < numOfNodes) {
/*maximum allowed nodes are 32 */
numOfNodes = MULTICAST_NODE_LIST_SIZE>>1;
}
for (uint8_t i = 0; i < numOfNodes; i++)
{
node_id_t curNode = (node_id_t) (((node_id_t)pNodeIDList[i<<1] << 8) | // index = i *2
(pNodeIDList[(i<<1) +1] & 0xFF)); // index = (i *2) +1
if ((LOWEST_LONG_RANGE_NODE_ID <= curNode) && (HIGHEST_LONG_RANGE_NODE_ID >= curNode)) {
lr_list = true;
} else {
classic_list = true;
}
if (lr_list && classic_list) {
/* mixed list we bail out*/
return false;
}
}
if (lr_list) {
/*lr nodes are 16-bit and the list is in bytes then we copy 2 * numOfNodes*/
memcpy(FramePackage.uTransmitParams.SendDataMultiBridge.NodeMask, pNodeIDList , numOfNodes * 2);
}
} else {
classic_list = true;
if (MAX_GROUP_NODES < numOfNodes) {
numOfNodes = MAX_GROUP_NODES;
}
}
FramePackage.uTransmitParams.SendDataMultiBridge.lr_nodeid_list = lr_list;
if (classic_list) {
uint8_t tmpNode;
for (uint8_t i = 0; i < numOfNodes; i++)
{
// if the list of classic nodes then the node ID is located in the lsb bytes of the 16-bit nodeID list.
if (SERIAL_API_SETUP_NODEID_BASE_TYPE_16_BIT == nodeIdBaseType) {
tmpNode = pNodeIDList[(i<<1) +1];
} else {
/* Set the destination node mask bits */
tmpNode = pNodeIDList[i];
}
ZW_NodeMaskSetBit(FramePackage.uTransmitParams.SendDataMultiBridge.NodeMask, tmpNode);
}
}
// Put the package on queue (and dont wait for it)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t *)&FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_DATA_MULTI_BRIDGE)
{
/* HOST->ZW: srcNodeID | numberNodes | pNodeIDList[] | dataLength | pData[] | txOptions | funcId */
uint8_t numberNodes;
uint8_t dataLength;
uint8_t txOptions;
uint8_t offset = 0;
node_id_t srcNodeId = (node_id_t)GET_NODEID(&frame->payload[0], offset);
uint8_t nodeid_list_size;
numberNodes = frame->payload[offset + 1];
uint8_t *pNodeList = &frame->payload[offset + 2];
if (nodeIdBaseType == SERIAL_API_SETUP_NODEID_BASE_TYPE_16_BIT) {
nodeid_list_size = numberNodes * 2;
} else {
nodeid_list_size = numberNodes;
}
dataLength = frame->payload[offset + 2 + nodeid_list_size];
txOptions = frame->payload[offset + 2 + 1 + nodeid_list_size + dataLength];
funcID_ComplHandler_ZW_SendDataMulti = frame->payload[offset + 2 + 1 + 1 + nodeid_list_size + dataLength];
uint8_t *pDataBuf = &frame->payload[offset + 3 + nodeid_list_size];
const uint8_t retVal = SendDataMultiBridge(srcNodeId, numberNodes, pNodeList,
dataLength, pDataBuf, txOptions,
(funcID_ComplHandler_ZW_SendDataMulti != 0) ? &ZCB_ComplHandler_ZW_SendDataMulti_Bridge : NULL);
DoRespond(retVal);
}
#endif
#if (defined(SUPPORT_ZW_SEND_PROTOCOL_DATA) && SUPPORT_ZW_SEND_PROTOCOL_DATA )
static void ZCB_ComplHandler_ZW_SendProtocolData(
uint8_t txStatus,
TX_STATUS_TYPE *txStatusReport) /* IN Transmit completion status */
{
GenerateTxStatusRequest(FUNC_ID_ZW_SEND_PROTOCOL_DATA, nlsEncryptionMetadata.session_id, txStatus, txStatusReport);
}
static uint8_t SendProtocolData(node_id_t destNodeID,
uint8_t dataLength,
const uint8_t * const pData,
uint8_t protocolMetadataLength,
const uint8_t * const protocolMetadata,
ZW_TX_Callback_t pCallback)
{
SZwaveTransmitPackage FramePackage = { 0 };
FramePackage.eTransmitType = EZWAVETRANSMITTYPE_NLS;
FramePackage.uTransmitParams.SendProtocolData.DestNodeID = destNodeID;
FramePackage.uTransmitParams.SendProtocolData.FrameConfig.Handle = pCallback;
FramePackage.uTransmitParams.SendProtocolData.FrameConfig.protocolMetadataLength = protocolMetadataLength;
FramePackage.uTransmitParams.SendProtocolData.FrameConfig.FrameLength = dataLength;
assert(dataLength < TX_BUFFER_SIZE);
assert(protocolMetadataLength == PROTOCOL_METADATA_LENGTH);
if (dataLength > TX_BUFFER_SIZE || protocolMetadataLength != PROTOCOL_METADATA_LENGTH)
{
return false;
}
memcpy(&FramePackage.uTransmitParams.SendProtocolData.FrameConfig.aFrame, pData, dataLength);
memcpy(&FramePackage.uTransmitParams.SendProtocolData.FrameConfig.protocolMetadata, protocolMetadata, protocolMetadataLength);
nlsEncryptionMetadata.callback_id = protocolMetadata[PROTOCOL_METADATA_CALLBACK_ID_IDX];
// Put the package on queue (and don't wait for it)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwTxQueue(), (uint8_t*) &FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
ZW_ADD_CMD(FUNC_ID_ZW_SEND_PROTOCOL_DATA)
{
/* HOST->ZW: srcNodeID | destNodeID | dataLength | pData[] | protocolMetadataLength | protocolMetadata[] | sessionID */
uint8_t retVal = 0;
uint8_t index = 1;
node_id_t destNodeID = (node_id_t) GET_NODEID(&frame->payload[0], index);
uint8_t dataLength = frame->payload[index++];
if (dataLength > BUF_SIZE_RX)
{
DoRespond(retVal);
return;
}
const uint8_t * const pData = &frame->payload[index];
index += dataLength;
uint8_t protocolMetadataLength = frame->payload[index++];
assert(protocolMetadataLength == PROTOCOL_METADATA_LENGTH);
const uint8_t * const protocolMetadata = &frame->payload[index];
index += protocolMetadataLength;
nlsEncryptionMetadata.session_id = frame->payload[index];
// Create transmit frame package
retVal = SendProtocolData(destNodeID, dataLength, pData, protocolMetadataLength, protocolMetadata, ZCB_ComplHandler_ZW_SendProtocolData);
DoRespond(retVal);
}
#endif
#if (defined(SUPPORT_ZW_REQUEST_PROTOCOL_CC_ENCRYPTION) && SUPPORT_ZW_REQUEST_PROTOCOL_CC_ENCRYPTION )
static bool ActivateProtocolCallback(uint8_t callbackId, uint8_t tx_status, TX_STATUS_TYPE extended_tx_status)
{
SZwaveCommandPackage FramePackage = { 0 };
FramePackage.eCommandType = EZWAVECOMMANDTYPE_SEND_PROTOCOL_DATA_CB;
FramePackage.uCommandParams.SendProtocolDataCb.callback_id = callbackId;
FramePackage.uCommandParams.SendProtocolDataCb.tx_status = tx_status;
FramePackage.uCommandParams.SendProtocolDataCb.extended_tx_status = extended_tx_status;
//Put the package on queue (and don't wait for it)
EQueueNotifyingStatus QueueStatus = QueueNotifyingSendToBack(ZAF_getZwCommandQueue(), (uint8_t*) &FramePackage, 0);
return (EQUEUENOTIFYING_STATUS_SUCCESS == QueueStatus) ? true : false;
}
ZW_ADD_CMD(FUNC_ID_ZW_REQUEST_PROTOCOL_CC_ENCRYPTION)
{
uint8_t idx = 0;
uint8_t session_id = 0;
volatile uint8_t rpcce_tx_status = TRANSMIT_COMPLETE_FAIL;
TX_STATUS_TYPE extended_tx_status = { 0 };
session_id = frame->payload[idx++];
if (session_id != nlsEncryptionMetadata.session_id)
{
return;
}
rpcce_tx_status = frame->payload[idx++];
memcpy(&extended_tx_status, &frame->payload[idx], sizeof(TX_STATUS_TYPE));
if (rpcce_tx_status == TRANSMIT_COMPLETE_VERIFIED)
{
ActivateProtocolCallback(nlsEncryptionMetadata.callback_id, rpcce_tx_status, extended_tx_status);
}
set_state_and_notify(stateIdle);
}
#endif
#if SUPPORT_MEMORY_GET_ID
ZW_ADD_CMD(FUNC_ID_MEMORY_GET_ID)
{
uint8_t i = 0;
node_id_t node_id;
uint32_t home_id;
node_id = ZAF_GetNodeID();
home_id = ZAF_GetHomeID();
/* */
compl_workbuf[i++] = (uint8_t) ((home_id & 0xff000000) >> 24);
compl_workbuf[i++] = (uint8_t) ((home_id & 0x00ff0000) >> 16);
compl_workbuf[i++] = (uint8_t) ((home_id & 0x0000ff00) >> 8);
compl_workbuf[i++] = (uint8_t) (home_id & 0x000000ff);
if (SERIAL_API_SETUP_NODEID_BASE_TYPE_16_BIT == nodeIdBaseType)
{
// 16 bit nodeID
compl_workbuf[i++] = (uint8_t)(node_id >> 8); // MSB(16bit)
}
compl_workbuf[i++] = (uint8_t)(node_id & 0xFF); // LSB(16bit)/8bit
DoRespond_workbuf(i);
}
#endif
#if SUPPORT_MEMORY_GET_BYTE
ZW_ADD_CMD(FUNC_ID_MEMORY_GET_BYTE)
{
/* offset (MSB) | offset (LSB) */
uint8_t retVal = 0;
if ((FRAME_LENGTH_MIN + 2) < frame->len)
{
uint16_t offset = ((uint16_t)(frame->payload[0] << 8)) + frame->payload[1];
if (! SerialApiNvmReadAppData(offset, &retVal, 1))
{
retVal = 0;
}
}
DoRespond(retVal);
}
#endif
#if SUPPORT_MEMORY_PUT_BYTE
ZW_ADD_CMD(FUNC_ID_MEMORY_PUT_BYTE)
{
uint8_t retVal = 0;
if ((FRAME_LENGTH_MIN + 3) < frame->len)
{
uint16_t offset = ((uint16_t)(frame->payload[0] << 8)) + frame->payload[1];
retVal = SerialApiNvmWriteAppData(offset, &frame->payload[2], 1);
}
DoRespond(retVal);
}
#endif
#if SUPPORT_MEMORY_GET_BUFFER
ZW_ADD_CMD(FUNC_ID_MEMORY_GET_BUFFER)
{
uint8_t dataLength = 0;
dataLength = frame->payload[2];
/* Make sure the length isn't larger than the available buffer size */
if (dataLength > (uint8_t)BUF_SIZE_TX)
{
dataLength = (uint8_t)BUF_SIZE_TX;
}
uint16_t offset = ((uint16_t)(frame->payload[0] << 8)) + frame->payload[1];
if (!SerialApiNvmReadAppData(offset, compl_workbuf, dataLength))
{
dataLength = 0;