Skip to content

Commit 1835543

Browse files
silabs-tuDrzr
authored andcommitted
NCP Soft-Reset Status Notification from Z/IP GW to Z/IP Clients
Motivation: In some cases, the application layer (like z-ware) really care about the NCP controller's soft reset status report. Especially, the "failed soft-reset status" MUST be sent back to zware, so the user can press the hard reset button the whole system. - We send the 'soft-reset status report' to the unsolicited destinations (remote IPs + Ports), z-ware must always listen on the unsolicited destination. - Since there are no specific comamnd in the Z/IP Packet Command class to notify the health check status of the NCP Controller, we implemented a custom COMMAND_ZIP_CONTROLLER_STATUS_REPORT (0x04) with the payload is status bytes (RESET_OK: 0x00; RESET_FAIL: 0xFF) - So, this new command also requires z-ware (zip clients) must understand and support our custom frame Fixes: #<ZGW-3450> Signed-off-by: silabs-tuD <[email protected]>
1 parent 5105c4a commit 1835543

File tree

7 files changed

+113
-6
lines changed

7 files changed

+113
-6
lines changed

src/CC_NetworkManagement.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,20 @@ static int set_conn_to_unsol2(zwave_connection_t* c)
375375
}
376376
}
377377

378+
/**
379+
* Set up the connection to be the unsolicited destinations (#1 or #2)
380+
*/
381+
bool setup_unsolicited_connection(zwave_connection_t *conn, uint8_t dest_id)
382+
{
383+
bool ret = false;
384+
if(dest_id == 1) {
385+
ret = set_conn_to_unsol1(conn);
386+
} else if(dest_id == 2) {
387+
ret = set_conn_to_unsol2(conn);
388+
}
389+
return ret;
390+
}
391+
378392
static uint8_t set_unsolicited_as_nm_dest()
379393
{
380394
nms.seq = random_rand() & 0xFF;

src/CC_NetworkManagement.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,11 @@ void extend_middleware_probe_timeout(void);
674674
*/
675675
void send_to_both_unsoc_dest(const uint8_t * frame, uint16_t len, ZW_SendDataAppl_Callback_t cbFunc);
676676

677+
/**
678+
* Set up the connection to be the unsolicited destinations (#1 or #2)
679+
*/
680+
bool setup_unsolicited_connection(zwave_connection_t *conn, uint8_t dest_id);
681+
677682
/* Internal entry function used by the CC_NetworkManagement_queue, this function
678683
* the same as NetworkManagementCommandHandler but it will not put the command
679684
* back in the queue.

src/ZW_classcmd_ex.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,11 @@ typedef struct _ZW_EXTENDED_NODE_ADD_STATUS_1BYTE_FRAME_
12151215
#define COMMAND_CLASS_NO_OPERATION_LR 0x04
12161216

12171217

1218-
// Soft Reset Status
1219-
#define COMMAND_ZIP_SOFT_RESET_REPORT 0x04
1218+
// NCP Controller Status
1219+
// We defined a new command (COMMAND_ZIP_CONTROLLER_STATUS_REPORT-0x04) in the COMMAND_CLASS_ZIP (0x23)
1220+
#define COMMAND_ZIP_CONTROLLER_STATUS_REPORT 0x04
1221+
// Currently, we define for the NCP controller's Soft Reset Status only.
1222+
// Later, we can extend it for other controller status reports like NCP Controller Health Check.
12201223
#define STATUS_SOFT_RESET_OK 0x0
12211224
#define STATUS_SOFT_RESET_FAIL 0xFF
12221225

src/ZW_udp_server.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ void ZW_BackupRxConnection(struct uip_udp_conn* new_conn)
508508

509509
void ZW_SendResetReportZIP(uint8_t status)
510510
{
511-
const u8_t reset_rpt_frm[] = {COMMAND_CLASS_ZIP, COMMAND_ZIP_SOFT_RESET_REPORT, status};
511+
const u8_t reset_rpt_frm[] = {COMMAND_CLASS_ZIP, COMMAND_ZIP_CONTROLLER_STATUS_REPORT, status};
512512
struct udp_rx_bk_t *cbk;
513513

514514
LOG_PRINTF("ZW_SendResetReportZIP! items: %u\n", list_length(udp_rx_conn_list));
@@ -522,6 +522,37 @@ void ZW_SendResetReportZIP(uint8_t status)
522522
}
523523
}
524524

525+
/**
526+
* Send NCP Controller Status Report to the given connection.
527+
* We've used the form of Z/IP Command Class (0x23), with a new custom COMMAND_ZIP_CONTROLLER_STATUS_REPORT (0x04).
528+
* And the payload is the status bytes:
529+
* #define STATUS_SOFT_RESET_OK 0x0
530+
* #define STATUS_SOFT_RESET_FAIL 0xFF
531+
* Note: Currently, this function is only used to send "NCP Controller's Soft Reset Status" via unsolicited destinations.
532+
* The frame format is of our custom Z/IP command as below:
533+
* +---+---+---+---+---+---+---+---+
534+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | Bit
535+
* +---+---+---+---+---+---+---+---+
536+
* | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | COMMAND_CLASS_ZIP (0x23)
537+
* +---+---+---+---+---+---+---+---+
538+
* | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | COMMAND_ZIP_CONTROLLER_STATUS_REPORT (0x04)
539+
* +---+---+---+---+---+---+---+---+
540+
* | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | STATUS_SOFT_RESET_OK (0x00) or STATUS_SOFT_RESET_FAIL (0xFF)
541+
* +---+---+---+---+---+---+---+---+
542+
*/
543+
void ZW_SendNCPControllerStatusZIP(zwave_connection_t *c, uint8_t status)
544+
{
545+
const u8_t controller_status_frame[] = {COMMAND_CLASS_ZIP, COMMAND_ZIP_CONTROLLER_STATUS_REPORT, status};
546+
547+
if (c) {
548+
struct uip_udp_conn conn = c->conn;
549+
DBG_PRINTF("ZW_SendNCPControllerStatusZIP => sending ncp cotroller status from local to remote address\n");
550+
uip_udp_print_conn(&conn);
551+
LOG_PRINTF("Sending Command_Class_ZIP (0x%2.2x), COMMAND_ZIP_CONTROLLER_STATUS_REPORT (0x%2.2x), status (0x%2.2x) to Unsolicited Destinations\n", controller_status_frame[0], controller_status_frame[1], controller_status_frame[2]);
552+
udp_send_wrap(&conn, &controller_status_frame, sizeof(controller_status_frame), NULL, NULL);
553+
}
554+
}
555+
525556

526557
void
527558
ZW_SendDataZIP(zwave_connection_t *c, const void *dataptr, u16_t datalen, void

src/ZW_udp_server.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,27 @@ void ZW_SendResetReportZIP(uint8_t status);
234234
*/
235235
void ZW_BackupRxConnInit(void);
236236

237+
238+
/**
239+
* Send NCP Controller Status Report to the given connection.
240+
* We've used the form of Z/IP Command Class (0x23), with a new custom COMMAND_ZIP_CONTROLLER_STATUS_REPORT (0x04).
241+
* And the payload is the status bytes:
242+
* #define STATUS_SOFT_RESET_OK 0x0
243+
* #define STATUS_SOFT_RESET_FAIL 0xFF
244+
* Note: Currently, this function is only used to send "NCP Controller's Soft Reset Status" via unsolicited destinations.
245+
* The frame format is of our custom Z/IP command as below:
246+
* +---+---+---+---+---+---+---+---+
247+
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | Bit
248+
* +---+---+---+---+---+---+---+---+
249+
* | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | COMMAND_CLASS_ZIP (0x23)
250+
* +---+---+---+---+---+---+---+---+
251+
* | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | COMMAND_ZIP_CONTROLLER_STATUS_REPORT (0x04)
252+
* +---+---+---+---+---+---+---+---+
253+
* | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | STATUS_SOFT_RESET_OK (0x00) or STATUS_SOFT_RESET_FAIL (0xFF)
254+
* +---+---+---+---+---+---+---+---+
255+
*/
256+
void ZW_SendNCPControllerStatusZIP(zwave_connection_t *c, uint8_t status);
257+
237258
/**
238259
* This process handles all Z/ZIP UDP communication.
239260
*/

src/transport/ZW_SendDataAppl.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "node_queue.h"
1717
#include "S2_wrap.h"
1818
#include "S2_multicast_auto.h"
19-
#include<stdlib.h>
19+
#include <stdlib.h>
2020
#include "ZW_transport_api.h"
2121
#include "ZIP_Router_logging.h"
2222
#include "zgw_crc.h"
@@ -25,6 +25,8 @@
2525
#include "ZW_classcmd_ex.h"
2626
#include "ZW_ZIPApplication.h"
2727
#include "zip_router_config.h"
28+
#include "ZW_classcmd.h"
29+
#include "CC_NetworkManagement.h"
2830
/*
2931
* SendData Hierarchy, each, level wraps the previous. A higher level call MUST only call lower level calls.
3032
*
@@ -701,7 +703,30 @@ void ZW_SendDataAppl_FrameRX_Notify(const ts_param_t *c, const uint8_t* frame, u
701703
}
702704
}
703705

706+
/**
707+
* Notify the NCP controller status via unsolicited destination(s) (#1 and #2).
708+
* @param status Status code defined in ZW_classcmd_ex.h
709+
*/
710+
void notify_ncp_controller_status_via_unsolicited_dest(uint8_t status)
711+
{
712+
// unsolicited connections
713+
zwave_connection_t uconn;
714+
memset(&uconn, 0, sizeof(zwave_connection_t));
715+
716+
DBG_PRINTF("Notify NCP soft reset status(%d) via unsolicited dest\n", status);
717+
if (uip_is_addr_unspecified(&cfg.unsolicited_dest)
718+
&& uip_is_addr_unspecified(&cfg.unsolicited_dest2)) {
719+
ERR_PRINTF("No Unsolicited Destinations configured\n");
720+
return;
721+
}
704722

723+
// Send the report to both unsolicited destinations (#1 and #2)
724+
for (int i = 0; i < 2; i++) {
725+
if(setup_unsolicited_connection(&uconn, i+1)) {
726+
ZW_SendNCPControllerStatusZIP(&uconn, status);
727+
}
728+
}
729+
}
705730

706731
PROCESS_THREAD(ZW_SendDataAppl_process, ev, data)
707732
{
@@ -740,10 +765,12 @@ PROCESS_THREAD(ZW_SendDataAppl_process, ev, data)
740765
if (ZW_SoftResetWithCheck()) {
741766
DBG_PRINTF("Soft reset successful!\n");
742767
process_post(&ZW_SendDataAppl_process, SEND_EVENT_SEND_NEXT_LL, NULL);
743-
ZW_SendResetReportZIP(STATUS_SOFT_RESET_OK);
768+
//ZW_SendResetReportZIP(STATUS_SOFT_RESET_OK);
769+
notify_ncp_controller_status_via_unsolicited_dest(STATUS_SOFT_RESET_OK);
744770
} else {
745771
ERR_PRINTF("Soft reset failed\n");
746-
ZW_SendResetReportZIP(STATUS_SOFT_RESET_FAIL);
772+
//ZW_SendResetReportZIP(STATUS_SOFT_RESET_FAIL);
773+
notify_ncp_controller_status_via_unsolicited_dest(STATUS_SOFT_RESET_FAIL);
747774
}
748775
}
749776
}

src/transport/ZW_SendDataAppl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ security_scheme_t highest_scheme(uint8_t scheme_mask);
224224
void ZW_SendDataAppl_FrameRX_Notify(const ts_param_t *p, const uint8_t* frame, uint16_t length);
225225

226226

227+
/**
228+
* Notify the NCP controller status via unsolicited destination(s) (#1 and #2)
229+
* @param status Status code defined in ZW_classcmd_ex.h
230+
*/
231+
void notify_ncp_controller_status_via_unsolicited_dest(uint8_t status);
232+
227233
/** @} */
228234

229235
#endif /* ZW_SENDDATAAPPL_H_ */

0 commit comments

Comments
 (0)