Skip to content

Commit d9c3225

Browse files
silabs-aydoganerzr
authored andcommitted
uic: zpc: Pull request #2913: SWPROT-8900 zpc bulk changes for s2v2
Merge in UIC/uic from feature/UIC-3590-zpc-bulk-changes-for-s2v2 to develop (cherry picked from commit 7cbdd551af3ab85e87662a67b3864c464532b961) Last-Update: 2025-01-31 Forwarded: #11 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent b2a79ce commit d9c3225

File tree

45 files changed

+1606
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1606
-267
lines changed

applications/zpc/components/ucl_mqtt/src/zpc_node_state.cpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static sl_status_t ucl_node_state_discover_neighbors_command(
4949
dotdot_endpoint_id_t endpoint,
5050
uic_mqtt_dotdot_callback_call_type_t callback_type)
5151
{
52-
if (true == is_zpc_unid(unid)) {
52+
if (is_zpc_unid(unid)) {
5353
return SL_STATUS_NOT_SUPPORTED;
5454
}
5555

@@ -90,7 +90,7 @@ static sl_status_t ucl_node_state_remove_offline_command(
9090
dotdot_endpoint_id_t endpoint,
9191
uic_mqtt_dotdot_callback_call_type_t callback_type)
9292
{
93-
if (true == is_zpc_unid(unid)) {
93+
if (is_zpc_unid(unid)) {
9494
return SL_STATUS_NOT_SUPPORTED;
9595
}
9696

@@ -132,7 +132,7 @@ static sl_status_t ucl_node_state_interview_command(
132132
dotdot_endpoint_id_t endpoint,
133133
uic_mqtt_dotdot_callback_call_type_t callback_type)
134134
{
135-
if (true == is_zpc_unid(unid)) {
135+
if (is_zpc_unid(unid)) {
136136
return SL_STATUS_NOT_SUPPORTED;
137137
}
138138

@@ -170,7 +170,7 @@ static sl_status_t ucl_node_state_discover_security_command(
170170
dotdot_endpoint_id_t endpoint,
171171
uic_mqtt_dotdot_callback_call_type_t callback_type)
172172
{
173-
if (true == is_zpc_unid(unid)) {
173+
if (is_zpc_unid(unid)) {
174174
return SL_STATUS_NOT_SUPPORTED;
175175
}
176176

@@ -199,6 +199,48 @@ static sl_status_t ucl_node_state_discover_security_command(
199199
: SL_STATUS_NOT_SUPPORTED;
200200
}
201201

202+
/**
203+
* @brief Performs an enable NLS operation for a Unid/Endpoint
204+
*
205+
* @param unid UNID of the node to attempt to enable NLS
206+
* @param endpoint Endpoint of the node. The State topic does not support
207+
* endpoints so this variable will be ignored.
208+
* is performed on a NodeID level, as all endpoints share the same radio.
209+
* @param callback_type Dotdot MQTT Callback type
210+
*
211+
* @returns SL_STATUS_OK/SL_STATUS_FAIL to indicate support if callback_type is set to UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK
212+
* sl_status_t code indicating the outcome of applying the command if callback_type is set to UIC_MQTT_DOTDOT_CALLBACK_TYPE_NORMAL
213+
*/
214+
static sl_status_t ucl_node_state_enable_nls_command(
215+
const dotdot_unid_t unid,
216+
dotdot_endpoint_id_t endpoint,
217+
uic_mqtt_dotdot_callback_call_type_t callback_type)
218+
{
219+
if (is_zpc_unid(unid)) {
220+
return SL_STATUS_NOT_SUPPORTED;
221+
}
222+
223+
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == callback_type) {
224+
// Enable NLS always supported unless the node is offline/unavailable
225+
NodeStateNetworkStatus network_status = unify_attribute_store_node_state_get_status(
226+
attribute_store_network_helper_get_node_id_node(unid)
227+
);
228+
229+
sl_status_t support = SL_STATUS_OK;
230+
if ((network_status == ZCL_NODE_STATE_NETWORK_STATUS_OFFLINE)
231+
|| (network_status == ZCL_NODE_STATE_NETWORK_STATUS_UNAVAILABLE)) {
232+
support = SL_STATUS_FAIL;
233+
}
234+
return support;
235+
}
236+
237+
zwave_node_id_t node_id = 0x00;
238+
if (SL_STATUS_OK == zwave_unid_to_node_id(unid, &node_id)) {
239+
return zwave_store_nls_state(node_id, true, DESIRED_ATTRIBUTE);
240+
}
241+
return SL_STATUS_OK;
242+
}
243+
202244
///////////////////////////////////////////////////////////////////////////////
203245
// Init function shared with the component.
204246
//////////////////////////////////////////////////////////////////////////////
@@ -216,5 +258,8 @@ sl_status_t zpc_node_state_init()
216258
uic_mqtt_dotdot_state_discover_security_callback_set(
217259
&ucl_node_state_discover_security_command);
218260

261+
uic_mqtt_dotdot_state_enable_nls_callback_set(
262+
&ucl_node_state_enable_nls_command);
263+
219264
return SL_STATUS_OK;
220265
}

applications/zpc/components/ucl_mqtt/test/zpc_node_state_test.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ static uic_mqtt_dotdot_state_interview_callback_t interview_command = NULL;
4848
static uic_mqtt_dotdot_state_discover_security_callback_t
4949
discover_security_command
5050
= NULL;
51+
static uic_mqtt_dotdot_state_enable_nls_callback_t
52+
enable_nls_command
53+
= NULL;
5154

5255
// Stub functions
5356
static void uic_mqtt_dotdot_state_remove_offline_callback_set_stub(
@@ -78,6 +81,13 @@ static void uic_mqtt_dotdot_state_discover_security_callback_set_stub(
7881
discover_security_command = callback;
7982
}
8083

84+
static void uic_mqtt_dotdot_state_enable_nls_callback_set_stub(
85+
const uic_mqtt_dotdot_state_enable_nls_callback_t callback,
86+
int cmock_num_calls)
87+
{
88+
enable_nls_command = callback;
89+
}
90+
8191
/// Setup the test suite (called once before all test_xxx functions are called)
8292
void suiteSetUp()
8393
{
@@ -102,6 +112,7 @@ void setUp()
102112
discover_neighbors_command = NULL;
103113
interview_command = NULL;
104114
discover_security_command = NULL;
115+
enable_nls_command = NULL;
105116

106117
// Always respond with HomeID / NodeID from the simulated network
107118
zwave_network_management_get_node_id_IgnoreAndReturn(zpc_node_id);
@@ -123,6 +134,9 @@ void setUp()
123134
uic_mqtt_dotdot_state_discover_security_callback_set_Stub(
124135
uic_mqtt_dotdot_state_discover_security_callback_set_stub);
125136

137+
uic_mqtt_dotdot_state_enable_nls_callback_set_Stub(
138+
uic_mqtt_dotdot_state_enable_nls_callback_set_stub);
139+
126140
// Call init
127141
TEST_ASSERT_EQUAL(SL_STATUS_OK, zpc_node_state_init());
128142

@@ -131,6 +145,7 @@ void setUp()
131145
TEST_ASSERT_NOT_NULL(discover_neighbors_command);
132146
TEST_ASSERT_NOT_NULL(interview_command);
133147
TEST_ASSERT_NOT_NULL(discover_security_command);
148+
TEST_ASSERT_NOT_NULL(enable_nls_command);
134149
}
135150

136151
/// Called after each and every test

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_GENERIC_DEVICE_CLASS, 0x0104)
107107
DEFINE_ATTRIBUTE(ATTRIBUTE_ZWAVE_SPECIFIC_DEVICE_CLASS, 0x0105)
108108
///< This represent a zwave_key_protocol_combination_t
109109
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)
110114

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

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "zwave_keyset_definitions.h"
3131
#include "zwave_command_class_version_types.h"
3232
#include "zwave_command_class_wake_up_types.h"
33+
#include "attribute_store_defined_attribute_types.h"
3334

3435
/**
3536
* @ingroup zpc_utils
@@ -45,6 +46,66 @@
4546
extern "C" {
4647
#endif
4748

49+
/**
50+
* @brief Returns whether a node supports Network Layer Security (NLS)
51+
*
52+
* It will search for the node in the Attribute store and deduct its NLS support
53+
* from the ATTRIBUTE_ZWAVE_NLS_SUPPORT
54+
* attribute stored under the NodeID.
55+
*
56+
* @param node_id The NodeID for which the NLS support is requested
57+
* @param value_state The value state to look for
58+
*
59+
* @returns
60+
* - true if the node/endpoint supports NLS
61+
* - false if the node/endpoint does not support NLS
62+
*/
63+
bool zwave_get_nls_support(zwave_node_id_t node_id, attribute_store_node_value_state_t value_state);
64+
65+
/**
66+
* @brief Returns whether a node has Network Layer Security (NLS) enabled
67+
*
68+
* It will search for the node in the Attribute store and deduct its NLS state
69+
* from the ATTRIBUTE_ZWAVE_NLS_STATE
70+
* attribute stored under the NodeID.
71+
*
72+
* @param node_id The NodeID for which the NLS state is requested
73+
* @param value_state The value state to look for
74+
*
75+
* @returns
76+
* - true if the node/endpoint has NLS enabled
77+
* - false if the node/endpoint has NLS disabled
78+
*/
79+
bool zwave_get_nls_state(zwave_node_id_t node_id, attribute_store_node_value_state_t value_state);
80+
81+
/**
82+
* @brief Stores Network Layer Security (NLS) support for a NodeID in the attribute store.
83+
*
84+
* @param node_id The NodeID for which the NLS support
85+
* must be saved in the attribute store
86+
* @param is_nls_supported NLS support
87+
* @param value_state The value state to store
88+
*
89+
* @returns SL_STATUS_OK on success, any other code if not successful.
90+
*/
91+
sl_status_t zwave_store_nls_support(zwave_node_id_t node_id,
92+
bool is_nls_supported,
93+
attribute_store_node_value_state_t value_state);
94+
95+
/**
96+
* @brief Stores Network Layer Security (NLS) state for a NodeID in the attribute store.
97+
*
98+
* @param node_id The NodeID for which the NLS state
99+
* must be saved in the attribute store
100+
* @param is_nls_enabled NLS state
101+
* @param value_state The value state to store
102+
*
103+
* @returns SL_STATUS_OK on success, any other code if not successful.
104+
*/
105+
sl_status_t zwave_store_nls_state(zwave_node_id_t node_id,
106+
bool is_nls_enabled,
107+
attribute_store_node_value_state_t value_state);
108+
48109
/**
49110
* @brief Returns the operating mode of a node
50111
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ static const std::vector<attribute_schema_t> attribute_schema = {
6161
{ATTRIBUTE_ZWAVE_GENERIC_DEVICE_CLASS, "Generic Device Class", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
6262
{ATTRIBUTE_ZWAVE_SPECIFIC_DEVICE_CLASS, "Specific Device Class", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
6363
{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},
6466
/////////////////////////////////////////////////////////////////////
6567
// Generic Z-Wave attributes
6668
/////////////////////////////////////////////////////////////////////

applications/zpc/components/zpc_attribute_store/src/zwave_utils.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,109 @@
2727
#include "sl_log.h"
2828
#define LOG_TAG "zwave_utils"
2929

30+
bool zwave_get_nls_support(zwave_node_id_t node_id, attribute_store_node_value_state_t value_state)
31+
{
32+
attribute_store_node_t node_id_node
33+
= attribute_store_network_helper_get_zwave_node_id_node(node_id);
34+
35+
attribute_store_node_t node
36+
= attribute_store_get_first_child_by_type(node_id_node,
37+
ATTRIBUTE_ZWAVE_NLS_SUPPORT);
38+
39+
if (node == ATTRIBUTE_STORE_INVALID_NODE) {
40+
return false;
41+
}
42+
43+
uint8_t nls_supported = 0;
44+
if (SL_STATUS_OK
45+
!= attribute_store_read_value(node,
46+
value_state,
47+
&nls_supported,
48+
sizeof(nls_supported))) {
49+
return false;
50+
}
51+
52+
return (bool)nls_supported;
53+
}
54+
55+
bool zwave_get_nls_state(zwave_node_id_t node_id,
56+
attribute_store_node_value_state_t value_state)
57+
{
58+
attribute_store_node_t node_id_node
59+
= attribute_store_network_helper_get_zwave_node_id_node(node_id);
60+
61+
attribute_store_node_t node
62+
= attribute_store_get_first_child_by_type(node_id_node,
63+
ATTRIBUTE_ZWAVE_NLS_STATE);
64+
65+
if (node == ATTRIBUTE_STORE_INVALID_NODE) {
66+
return false;
67+
}
68+
69+
uint8_t nls_enabled = 0;
70+
if (SL_STATUS_OK
71+
!= attribute_store_read_value(node,
72+
value_state,
73+
&nls_enabled,
74+
sizeof(nls_enabled))) {
75+
return false;
76+
}
77+
78+
return (bool)nls_enabled;
79+
}
80+
81+
sl_status_t zwave_store_nls_support(zwave_node_id_t node_id,
82+
bool is_nls_supported,
83+
attribute_store_node_value_state_t value_state)
84+
{
85+
uint8_t value = (uint8_t)is_nls_supported;
86+
87+
attribute_store_node_t node_id_node
88+
= attribute_store_network_helper_get_zwave_node_id_node(node_id);
89+
90+
attribute_store_node_t node
91+
= attribute_store_get_first_child_by_type(node_id_node,
92+
ATTRIBUTE_ZWAVE_NLS_SUPPORT);
93+
94+
if (node == ATTRIBUTE_STORE_INVALID_NODE) {
95+
node = attribute_store_add_node(ATTRIBUTE_ZWAVE_NLS_SUPPORT, node_id_node);
96+
}
97+
98+
if (value_state == DESIRED_ATTRIBUTE) {
99+
return attribute_store_set_desired(node, &value, sizeof(value));
100+
} else if (value_state == REPORTED_ATTRIBUTE) {
101+
return attribute_store_set_reported(node, &value, sizeof(value));
102+
} else {
103+
return SL_STATUS_NOT_SUPPORTED;
104+
}
105+
}
106+
107+
sl_status_t zwave_store_nls_state(zwave_node_id_t node_id,
108+
bool is_nls_enabled,
109+
attribute_store_node_value_state_t value_state)
110+
{
111+
uint8_t value = (uint8_t)is_nls_enabled;
112+
113+
attribute_store_node_t node_id_node
114+
= attribute_store_network_helper_get_zwave_node_id_node(node_id);
115+
116+
attribute_store_node_t node
117+
= attribute_store_get_first_child_by_type(node_id_node,
118+
ATTRIBUTE_ZWAVE_NLS_STATE);
119+
120+
if (node == ATTRIBUTE_STORE_INVALID_NODE) {
121+
node = attribute_store_add_node(ATTRIBUTE_ZWAVE_NLS_STATE, node_id_node);
122+
}
123+
124+
if (value_state == DESIRED_ATTRIBUTE) {
125+
return attribute_store_set_desired(node, &value, sizeof(value));
126+
} else if (value_state == REPORTED_ATTRIBUTE) {
127+
return attribute_store_set_reported(node, &value, sizeof(value));
128+
} else {
129+
return SL_STATUS_NOT_SUPPORTED;
130+
}
131+
}
132+
30133
zwave_operating_mode_t zwave_get_operating_mode(zwave_node_id_t node_id)
31134
{
32135
attribute_store_node_t node_id_node

applications/zpc/components/zpc_rust/src/rust_command_handlers/zwave_command_classes/zwave_command_class_firmware_update/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ where
7878
is_first_follow_up: false,
7979
group_id: 0,
8080
is_test_frame: false,
81+
is_protocol_frame: false,
8182
ignore_incoming_frames_back_off: false,
8283
rf_power: zwave_tx_sys::rf_power_level_t::NORMAL_POWER,
8384
},
@@ -971,6 +972,7 @@ fn handle_fwu_md_get(
971972
is_first_follow_up: false,
972973
group_id: 0,
973974
is_test_frame: false,
975+
is_protocol_frame: false,
974976
ignore_incoming_frames_back_off: false,
975977
rf_power: zwave_tx_sys::rf_power_level_t::NORMAL_POWER,
976978
},

0 commit comments

Comments
 (0)