Skip to content

Commit 45e1f10

Browse files
silabs-aydoganerzr
authored andcommitted
SWPROT-9320 Controller NLS state storage (#54)
Merge in UIC/uic from task/ayersoz/SWPROT-9320-controller-nls-state-storage to z-wave/main (cherry picked from commit 7a63883eb991f0f8cbbb663df8802be0764ec6e5) Last-Update: 2025-03-05 Forwarded: #54 Relate-to: #50 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent c2a04c8 commit 45e1f10

File tree

7 files changed

+54
-7
lines changed

7 files changed

+54
-7
lines changed

applications/zpc/components/zpc_attribute_store/include/attribute_store_defined_attribute_types.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_FAILING_NODE_PING_INTERVAL, 0x0017)
9393
///< Used by poll engine to request of for polling of the attributer
9494
DEFINE_ATTRIBUTE(ATTRIBUTE_POLL_ENGINE_MARK, 0x0018)
9595

96+
///< This represents whether a Z-Wave node supports NLS.
97+
DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_NLS_SUPPORT, 0x0019)
98+
///< This represents whether a Z-Wave node has NLS enabled.
99+
DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_NLS_STATE, 0x0020)
100+
96101
// Generic endpoint attributes, should be attached under endpoints
97102
// Suggested range 0x100..0x1FF (using Z-Wave Protocol CC identifier)
98103
/** This represents the list of supported command classes (NIF) for a node */
@@ -107,10 +112,6 @@ DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_GENERIC_DEVICE_CLASS, 0x0104)
107112
DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_SPECIFIC_DEVICE_CLASS, 0x0105)
108113
///< This represent a zwave_key_protocol_combination_t
109114
DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_KEY_AND_PROTOCOL_TO_DISCOVER, 0x0106)
110-
/** This represents whether a Z-Wave node/endpoint supports NLS. */
111-
DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_NLS_SUPPORT, 0x0107)
112-
/** This represents whether a Z-Wave node/endpoint has NLS enabled. */
113-
DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_NLS_STATE, 0x0108)
114115

115116
// Generic attributes that can be placed anywhere under an endpoint.
116117
/** This indicates if more reports are expected to "complete" the value of an attribute */

applications/zpc/components/zpc_attribute_store/src/zpc_attribute_store_type_registration.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static const std::vector<attribute_schema_t> attribute_schema = {
5151
{ATTRIBUTE_MULTICAST_GROUP_LIST, "Multicast Group list", ATTRIBUTE_NODE_ID, EMPTY_STORAGE_TYPE},
5252
{ATTRIBUTE_MULTICAST_GROUP, "Multicast Group", ATTRIBUTE_MULTICAST_GROUP_LIST, U8_STORAGE_TYPE},
5353
{ATTRIBUTE_ZWAVE_FAILING_NODE_PING_INTERVAL, "NOP interval", ATTRIBUTE_NODE_ID, UNSIGNED_LONG_STORAGE_TYPE},
54+
{ATTRIBUTE_ZWAVE_NLS_SUPPORT, "NLS support", ATTRIBUTE_NODE_ID, U8_STORAGE_TYPE},
55+
{ATTRIBUTE_ZWAVE_NLS_STATE, "NLS state", ATTRIBUTE_NODE_ID, U8_STORAGE_TYPE},
5456
{ATTRIBUTE_POLL_ENGINE_MARK, "Poll Engine Mark", ATTRIBUTE_STORE_INVALID_ATTRIBUTE_TYPE, UNKNOWN_STORAGE_TYPE},
5557
/////////////////////////////////////////////////////////////////////
5658
// Generic Z-Wave Endpoint ID attributes
@@ -61,8 +63,6 @@ static const std::vector<attribute_schema_t> attribute_schema = {
6163
{ATTRIBUTE_ZWAVE_GENERIC_DEVICE_CLASS, "Generic Device Class", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
6264
{ATTRIBUTE_ZWAVE_SPECIFIC_DEVICE_CLASS, "Specific Device Class", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
6365
{ATTRIBUTE_ZWAVE_KEY_AND_PROTOCOL_TO_DISCOVER, "Network Key / Protocol to probe", ATTRIBUTE_ENDPOINT_ID, BYTE_ARRAY_STORAGE_TYPE},
64-
{ATTRIBUTE_ZWAVE_NLS_SUPPORT, "NLS support", ATTRIBUTE_NODE_ID, U8_STORAGE_TYPE},
65-
{ATTRIBUTE_ZWAVE_NLS_STATE, "NLS state", ATTRIBUTE_NODE_ID, U8_STORAGE_TYPE},
6666
/////////////////////////////////////////////////////////////////////
6767
// Generic Z-Wave attributes
6868
/////////////////////////////////////////////////////////////////////

applications/zpc/components/zwave/zwave_transports/s2/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ if(BUILD_TESTING)
5757
add_mock(libs2_mock ${ZW-LIBS2_PATH}/include/S2.h
5858
${ZW-LIBS2_PATH}/include/s2_inclusion.h
5959
${ZW-LIBS2_PATH}/include/s2_protocol.h)
60+
add_mock(libs2_external_mock ${ZW-LIBS2_PATH}/include/S2_external.h)
6061
target_interface_libraries(libs2_mock zwave_definitions s2crypto aes)
62+
target_interface_libraries(libs2_external_mock zwave_definitions s2crypto aes)
6163
target_compile_definitions(libs2_mock PUBLIC ZIPGW)
64+
target_compile_definitions(libs2_external_mock PUBLIC ZIPGW)
6265
endif()

applications/zpc/components/zwave/zwave_transports/s2/src/zwave_s2_network.c

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "zwave_s2_internal.h"
2323
#include "zwave_s2_keystore_int.h"
2424
#include "zwave_helper_macros.h"
25+
#include "zwapi_protocol_controller.h"
26+
#include "zwave_utils.h"
2527

2628
#define LOG_TAG "zwave_s2_network"
2729

@@ -136,6 +138,22 @@ void zwave_s2_network_init()
136138
// Print out our keys on the console
137139
zwave_s2_log_security_keys(SL_LOG_INFO);
138140
#endif
141+
142+
uint8_t nls_state = 0;
143+
zwave_node_id_t node_id = zwave_network_management_get_node_id();
144+
sl_status_t status = zwapi_get_node_nls(node_id, &nls_state);
145+
if (status != SL_STATUS_OK) {
146+
sl_log_error(LOG_TAG, "Unable to read NLS state for Node ID: %d\n", node_id);
147+
return;
148+
}
149+
150+
sl_log_info(LOG_TAG, "NLS state %s for Node ID: %d\n", nls_state == 1 ? "active" : "not active", node_id);
151+
152+
S2_load_nls_state(s2_ctx, nls_state);
153+
status = zwave_store_nls_state(node_id, nls_state, REPORTED_ATTRIBUTE);
154+
if (status != SL_STATUS_OK) {
155+
sl_log_error(LOG_TAG, "Unable to store NLS state in attribute store for Node ID: %d\n", node_id);
156+
}
139157
}
140158

141159
void zwave_s2_start_learn_mode(zwave_node_id_t node_id)

applications/zpc/components/zwave/zwave_transports/s2/src/zwave_s2_transport.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,23 @@ void S2_notify_nls_state_report(node_t srcNode, uint8_t class_id, bool nls_capab
453453

454454
void S2_save_nls_state(void)
455455
{
456-
// not relevant for ZPC
456+
zwave_node_id_t node_id = zwave_network_management_get_node_id();
457+
458+
sl_status_t status = zwave_store_nls_state(node_id, s2_ctx->nls_state, REPORTED_ATTRIBUTE);
459+
if (status != SL_STATUS_OK) {
460+
sl_log_error(LOG_TAG, "Unable to save NLS state in attribute store for Node ID: %d\n", node_id);
461+
return;
462+
}
463+
464+
if (s2_ctx->nls_state) {
465+
status = zwapi_enable_node_nls(node_id);
466+
if (SL_STATUS_OK != status) {
467+
sl_log_error(LOG_TAG, "Error saving NLS state in the controller NVM for Node ID: %d", node_id);
468+
return;
469+
}
470+
}
471+
472+
sl_log_debug(LOG_TAG, "NLS state saved in the controller NVM for Node ID: %d\n", node_id);
457473
}
458474

459475
sl_status_t compute_next_nls_enabled_node(void)

applications/zpc/components/zwave/zwave_transports/s2/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ target_add_unittest(
4242
zwave_s2_network_test.c
4343
DEPENDS
4444
libs2_mock
45+
libs2_external_mock
4546
zwave_network_management_mock
4647
zwave_api_mock
4748
uic_contiki_stub

applications/zpc/components/zwave/zwave_transports/s2/test/zwave_s2_network_test.c

+8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
#include "S2_mock.h"
1919
#include "s2_inclusion_mock.h"
20+
#include "S2_external_mock.h"
2021
#include "zwave_s2_network.h"
2122
#include "zwave_s2_network_callbacks_mock.h"
2223
#include "sl_log.h"
2324
#include "zwapi_protocol_mem_mock.h"
25+
#include "zwapi_protocol_controller_mock.h"
2426

2527
// Includes from LibS2
2628
#include "s2_protocol.h"
@@ -53,6 +55,7 @@ void setUp()
5355
// Configure our HomeID and NodeID for the test:
5456
zwave_network_management_get_home_id_IgnoreAndReturn(test_home_id);
5557
zwave_network_management_get_node_id_IgnoreAndReturn(test_node_id);
58+
clock_time_IgnoreAndReturn(0);
5659
s2_ctx = &test_ctx;
5760
memset(s2_ctx, 0, sizeof(struct S2));
5861
contiki_test_helper_init();
@@ -74,6 +77,8 @@ static void
7477

7578
void test_s2_network_init()
7679
{
80+
uint8_t nls_state = false;
81+
7782
S2_destroy_Expect(s2_ctx);
7883
s2_inclusion_init_IgnoreAndReturn(true);
7984
s2_inclusion_set_event_handler_StubWithCallback(
@@ -82,6 +87,9 @@ void test_s2_network_init()
8287

8388
zwapi_memory_get_buffer_IgnoreAndReturn(SL_STATUS_OK);
8489

90+
zwapi_get_node_nls_ExpectAndReturn(1, &nls_state, SL_STATUS_OK);
91+
S2_load_nls_state_Ignore();
92+
8593
zwave_s2_network_init();
8694
}
8795

0 commit comments

Comments
 (0)