Skip to content

Commit d2fadef

Browse files
silabs-borislrzr
authored andcommitted
UIC-3222: Refactor Get All Users Checksum
Now the attribute ALL_USERS_CHECKSUM is defined at the end of the User interview if device support it Add command to force the refresh of the checksum
1 parent df32187 commit d2fadef

File tree

8 files changed

+442
-90
lines changed

8 files changed

+442
-90
lines changed

applications/zpc/components/zcl_cluster_servers/src/user_credential_cluster_server.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,25 @@ sl_status_t uuic_association_set(dotdot_unid_t unid,
548548
destination_credential_slot);
549549
}
550550

551+
sl_status_t get_all_users_checksum(dotdot_unid_t unid,
552+
dotdot_endpoint_id_t endpoint,
553+
uic_mqtt_dotdot_callback_call_type_t call_type)
554+
{
555+
attribute_store_node_t endpoint_node
556+
= attribute_store_network_helper_get_endpoint_node(unid, endpoint);
557+
558+
// Now that we know that the command is supported, return here if it is
559+
// a support check type of call.
560+
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
561+
return zwave_command_class_user_credential_supports(endpoint_node,
562+
ALL_USERS_CHECKSUM_GET)
563+
? SL_STATUS_OK
564+
: SL_STATUS_FAIL;
565+
}
566+
567+
return zwave_command_class_user_credential_get_all_users_checksum(endpoint_node);
568+
}
569+
551570
sl_status_t get_user_checksum(dotdot_unid_t unid,
552571
dotdot_endpoint_id_t endpoint,
553572
uic_mqtt_dotdot_callback_call_type_t call_type,
@@ -1048,7 +1067,7 @@ void on_user_credential_message(sl_log_level_t log_level,
10481067
nlohmann::json payload;
10491068
payload["level"] = log_level;
10501069
payload["message"] = message;
1051-
1070+
10521071
std::string payload_str = payload.dump();
10531072
uic_mqtt_publish("ucl/Event", payload_str.c_str(), payload_str.length(), true);
10541073
}
@@ -1113,5 +1132,8 @@ sl_status_t user_credential_cluster_server_init()
11131132
// Credential Checksum
11141133
uic_mqtt_dotdot_user_credential_get_credential_checksum_callback_set(
11151134
&get_credential_checksum);
1135+
// All Users Checksum
1136+
uic_mqtt_dotdot_user_credential_get_all_users_checksum_callback_set(
1137+
&get_all_users_checksum);
11161138
return SL_STATUS_OK;
11171139
}

applications/zpc/components/zcl_cluster_servers/test/user_credential_cluster_server_test.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626
#include "attribute_store_defined_attribute_types.h"
2727
#include "zwave_command_class_association_types.h"
2828
#include "zap-types.h"
29+
#include "zwave_command_class_version_types.h"
2930

3031
// ZPC Components
3132
#include "zpc_attribute_store_type_registration.h"
@@ -48,6 +49,9 @@ extern "C" {
4849
// Attribute macro, shortening those long defines for attribute types:
4950
#define ATTRIBUTE(type) ATTRIBUTE_COMMAND_CLASS_USER_CREDENTIAL_##type
5051

52+
// Useful definitions
53+
attribute_store::attribute cpp_endpoint_node;
54+
5155
// Header declarations
5256
void mock_deletion_user_mqtt_topic(user_credential_user_unique_id_t user_id);
5357
void mock_deletion_cred_mqtt_topic(user_credential_user_unique_id_t user_id,
@@ -86,6 +90,7 @@ uic_mqtt_dotdot_user_credential_credential_learn_stop_callback_t credential_lear
8690
uic_mqtt_dotdot_user_credential_credential_association_callback_t credential_association_command = NULL;
8791
uic_mqtt_dotdot_user_credential_get_user_checksum_callback_t get_user_checksum_command = NULL;
8892
uic_mqtt_dotdot_user_credential_get_credential_checksum_callback_t get_credential_checksum_command = NULL;
93+
uic_mqtt_dotdot_user_credential_get_all_users_checksum_callback_t get_all_users_checksum_command = NULL;
8994
// clang-format on
9095

9196
// Stub functions for intercepting callback registration.
@@ -210,6 +215,15 @@ void uic_mqtt_dotdot_user_credential_get_credential_checksum_callback_set_stub(
210215
get_credential_checksum_command = callback;
211216
}
212217

218+
void uic_mqtt_dotdot_user_credential_get_all_users_checksum_callback_set_stub(
219+
const uic_mqtt_dotdot_user_credential_get_all_users_checksum_callback_t
220+
callback,
221+
int cmock_num_calls)
222+
{
223+
get_all_users_checksum_command = callback;
224+
}
225+
226+
213227
/// Setup the test suite (called once before all test_xxx functions are called)
214228
void suiteSetUp()
215229
{
@@ -293,6 +307,7 @@ void setUp()
293307
uic_mqtt_dotdot_user_credential_get_user_checksum_callback_set_Stub(&uic_mqtt_dotdot_user_credential_get_user_checksum_callback_set_stub);
294308
// Credential checksum
295309
uic_mqtt_dotdot_user_credential_get_credential_checksum_callback_set_Stub(&uic_mqtt_dotdot_user_credential_get_credential_checksum_callback_set_stub);
310+
uic_mqtt_dotdot_user_credential_get_all_users_checksum_callback_set_Stub(&uic_mqtt_dotdot_user_credential_get_all_users_checksum_callback_set_stub);
296311
// clang-format on
297312

298313
// Run the component init
@@ -303,6 +318,17 @@ void setUp()
303318
setup_user_capabilities();
304319
// Need to call this after init() to have the mqtt callback initialized
305320
setup_cred_capabilities();
321+
322+
// Setup helper
323+
cpp_endpoint_node = attribute_store::attribute(endpoint_id_node);
324+
}
325+
326+
void set_version(zwave_cc_version_t version)
327+
{
328+
// Set the version
329+
cpp_endpoint_node
330+
.emplace_node(ATTRIBUTE(VERSION))
331+
.set_reported(version);
306332
}
307333

308334
/////////////////////////////////////////////////////////////////////////
@@ -2352,6 +2378,57 @@ void test_user_credential_cluster_test_credential_checksum_happy_case()
23522378
"Checksum node reported value should be not defined");
23532379
}
23542380

2381+
2382+
void test_user_credential_cluster_test_all_users_checksum_happy_case()
2383+
{
2384+
set_version(1);
2385+
2386+
// Command not supported yet (default user capabilities SUPPORT_ALL_USERS_CHECKSUM set to 0)
2387+
TEST_ASSERT_EQUAL_MESSAGE(
2388+
SL_STATUS_FAIL,
2389+
get_all_users_checksum_command(supporting_node_unid,
2390+
endpoint_id,
2391+
UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK),
2392+
"Not supported yet since we are missing the capability");
2393+
2394+
cpp_endpoint_node.child_by_type(ATTRIBUTE(SUPPORT_ALL_USERS_CHECKSUM))
2395+
.set_reported<uint8_t>(1);
2396+
2397+
TEST_ASSERT_EQUAL_MESSAGE(
2398+
SL_STATUS_OK,
2399+
get_all_users_checksum_command(supporting_node_unid,
2400+
endpoint_id,
2401+
UIC_MQTT_DOTDOT_CALLBACK_TYPE_NORMAL),
2402+
"Should be able to setup attribute store for get_all_users_checksum");
2403+
2404+
auto checksum_node
2405+
= cpp_endpoint_node.child_by_type(ATTRIBUTE(ALL_USERS_CHECKSUM));
2406+
2407+
TEST_ASSERT_TRUE_MESSAGE(
2408+
checksum_node.is_valid(),
2409+
"All users checksum node should exists");
2410+
2411+
checksum_node.set_desired<uint16_t>(1312);
2412+
checksum_node.set_reported<uint16_t>(12);
2413+
2414+
// Try a second time to see if we clear the attributes
2415+
TEST_ASSERT_EQUAL_MESSAGE(
2416+
SL_STATUS_OK,
2417+
get_all_users_checksum_command(supporting_node_unid,
2418+
endpoint_id,
2419+
UIC_MQTT_DOTDOT_CALLBACK_TYPE_NORMAL),
2420+
"Should be able to setup attribute store for get_all_users_checksum");
2421+
2422+
TEST_ASSERT_FALSE_MESSAGE(
2423+
checksum_node.desired_exists(),
2424+
"Checksum node desired value should NOT exists");
2425+
2426+
TEST_ASSERT_FALSE_MESSAGE(
2427+
checksum_node.reported_exists(),
2428+
"Checksum node reported value should NOT exists");
2429+
}
2430+
2431+
23552432
///////////////////////////////////////////////////
23562433
// Support tests
23572434
///////////////////////////////////////////////////

applications/zpc/components/zwave_command_classes/src/private/user_credential/user_credential_user_capabilities.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ user_capabilities::user_capabilities(attribute_store::attribute endpoint_node) {
4141
this->support_user_schedule
4242
= endpoint_node.child_by_type(ATTRIBUTE(SUPPORT_USER_SCHEDULE))
4343
.reported<uint8_t>();
44-
this->support_all_user_checksum
44+
this->support_all_users_checksum
4545
= endpoint_node.child_by_type(ATTRIBUTE(SUPPORT_ALL_USERS_CHECKSUM))
4646
.reported<uint8_t>();
4747
this->support_by_user_checksum
@@ -54,6 +54,7 @@ user_capabilities::user_capabilities(attribute_store::attribute endpoint_node) {
5454
sl_log_error(LOG_TAG,
5555
"Something was wrong getting user capabilities : %s",
5656
e.what());
57+
attribute_store_log();
5758
this->is_data_valid = false;
5859
}
5960
}
@@ -116,4 +117,9 @@ bool user_capabilities::is_credential_rule_supported(
116117
return (supported_credential_rules_bitmask & (1 << credential_rule));
117118
}
118119

120+
bool user_capabilities::is_all_users_checksum_supported() const
121+
{
122+
return support_all_users_checksum;
123+
}
124+
119125
} // namespace user_credential

applications/zpc/components/zwave_command_classes/src/private/user_credential/user_credential_user_capabilities.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class user_capabilities
7979
bool
8080
is_credential_rule_supported(user_credential_rule_t credential_rule) const;
8181

82+
/**
83+
* @brief Check if all users checksum is supported
84+
* @return true All users checksum is supported
85+
* @return false All users checksum is not supported
86+
*/
87+
bool is_all_users_checksum_supported() const;
88+
8289
private:
8390
// Maximum number of users that can be stored in the device
8491
uint16_t max_user_count = 0;
@@ -91,7 +98,7 @@ class user_capabilities
9198
// Device support for scheduling users
9299
uint8_t support_user_schedule = 0;
93100
// Device support for getting the checksum of all users
94-
uint8_t support_all_user_checksum = 0;
101+
uint8_t support_all_users_checksum = 0;
95102
// Device support for getting the checksum of a specific user
96103
uint8_t support_by_user_checksum = 0;
97104

0 commit comments

Comments
 (0)