Skip to content

Commit 2cd1a90

Browse files
silabs-borislrzr
authored andcommitted
UIC-3222: Use zwave_command_class_user_credential_supports API for commands
1 parent b58a3da commit 2cd1a90

File tree

7 files changed

+142
-127
lines changed

7 files changed

+142
-127
lines changed

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

Lines changed: 81 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,9 @@ static sl_status_t
138138
// Now that we know that the command is supported, return here if it is
139139
// a support check type of call.
140140
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
141-
attribute_store_node_t user_count_node
142-
= attribute_store_get_first_child_by_type(endpoint_node,
143-
ATTRIBUTE(NUMBER_OF_USERS));
144-
145-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
146-
: SL_STATUS_FAIL;
141+
return zwave_command_class_user_credential_supports(endpoint_node, USER_SET)
142+
? SL_STATUS_OK
143+
: SL_STATUS_FAIL;
147144
}
148145

149146
return zwave_command_class_user_credential_add_new_user(
@@ -175,12 +172,9 @@ static sl_status_t
175172
// Now that we know that the command is supported, return here if it is
176173
// a support check type of call.
177174
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
178-
attribute_store_node_t user_count_node
179-
= attribute_store_get_first_child_by_type(endpoint_node,
180-
ATTRIBUTE(NUMBER_OF_USERS));
181-
182-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
183-
: SL_STATUS_FAIL;
175+
return zwave_command_class_user_credential_supports(endpoint_node, USER_SET)
176+
? SL_STATUS_OK
177+
: SL_STATUS_FAIL;
184178
}
185179

186180
return zwave_command_class_user_credential_modify_user(
@@ -208,12 +202,9 @@ static sl_status_t
208202
// Now that we know that the command is supported, return here if it is
209203
// a support check type of call.
210204
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
211-
attribute_store_node_t user_count_node
212-
= attribute_store_get_first_child_by_type(endpoint_node,
213-
ATTRIBUTE(NUMBER_OF_USERS));
214-
215-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
216-
: SL_STATUS_FAIL;
205+
return zwave_command_class_user_credential_supports(endpoint_node, USER_SET)
206+
? SL_STATUS_OK
207+
: SL_STATUS_FAIL;
217208
}
218209

219210
return zwave_command_class_user_credential_delete_user(endpoint_node,
@@ -235,12 +226,10 @@ static sl_status_t
235226
// Now that we know that the command is supported, return here if it is
236227
// a support check type of call.
237228
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
238-
attribute_store_node_t user_count_node
239-
= attribute_store_get_first_child_by_type(endpoint_node,
240-
ATTRIBUTE(NUMBER_OF_USERS));
241-
242-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
243-
: SL_STATUS_FAIL;
229+
return zwave_command_class_user_credential_supports(endpoint_node,
230+
CREDENTIAL_SET)
231+
? SL_STATUS_OK
232+
: SL_STATUS_FAIL;
244233
}
245234

246235
return zwave_command_class_user_credential_add_new_credential(
@@ -266,11 +255,10 @@ static sl_status_t
266255
// Now that we know that the command is supported, return here if it is
267256
// a support check type of call.
268257
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
269-
attribute_store_node_t user_count_node
270-
= attribute_store_get_first_child_by_type(endpoint_node,
271-
ATTRIBUTE(NUMBER_OF_USERS));
272-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
273-
: SL_STATUS_FAIL;
258+
return zwave_command_class_user_credential_supports(endpoint_node,
259+
CREDENTIAL_SET)
260+
? SL_STATUS_OK
261+
: SL_STATUS_FAIL;
274262
}
275263
return zwave_command_class_user_credential_modify_credential(
276264
endpoint_node,
@@ -294,12 +282,10 @@ static sl_status_t
294282
// Now that we know that the command is supported, return here if it is
295283
// a support check type of call.
296284
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
297-
attribute_store_node_t user_count_node
298-
= attribute_store_get_first_child_by_type(endpoint_node,
299-
ATTRIBUTE(NUMBER_OF_USERS));
300-
301-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
302-
: SL_STATUS_FAIL;
285+
return zwave_command_class_user_credential_supports(endpoint_node,
286+
CREDENTIAL_SET)
287+
? SL_STATUS_OK
288+
: SL_STATUS_FAIL;
303289
}
304290

305291
return zwave_command_class_user_credential_delete_credential(
@@ -320,12 +306,9 @@ static sl_status_t
320306
// Now that we know that the command is supported, return here if it is
321307
// a support check type of call.
322308
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
323-
attribute_store_node_t user_count_node
324-
= attribute_store_get_first_child_by_type(endpoint_node,
325-
ATTRIBUTE(NUMBER_OF_USERS));
326-
327-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
328-
: SL_STATUS_FAIL;
309+
return zwave_command_class_user_credential_supports(endpoint_node, USER_SET)
310+
? SL_STATUS_OK
311+
: SL_STATUS_FAIL;
329312
}
330313

331314
return zwave_command_class_user_credential_delete_all_users(endpoint_node);
@@ -342,12 +325,10 @@ static sl_status_t
342325
// Now that we know that the command is supported, return here if it is
343326
// a support check type of call.
344327
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
345-
attribute_store_node_t user_count_node
346-
= attribute_store_get_first_child_by_type(endpoint_node,
347-
ATTRIBUTE(NUMBER_OF_USERS));
348-
349-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
350-
: SL_STATUS_FAIL;
328+
return zwave_command_class_user_credential_supports(endpoint_node,
329+
CREDENTIAL_SET)
330+
? SL_STATUS_OK
331+
: SL_STATUS_FAIL;
351332
}
352333

353334
return zwave_command_class_user_credential_delete_all_credentials(
@@ -366,12 +347,10 @@ static sl_status_t
366347
// Now that we know that the command is supported, return here if it is
367348
// a support check type of call.
368349
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
369-
attribute_store_node_t user_count_node
370-
= attribute_store_get_first_child_by_type(endpoint_node,
371-
ATTRIBUTE(NUMBER_OF_USERS));
372-
373-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
374-
: SL_STATUS_FAIL;
350+
return zwave_command_class_user_credential_supports(endpoint_node,
351+
CREDENTIAL_SET)
352+
? SL_STATUS_OK
353+
: SL_STATUS_FAIL;
375354
}
376355

377356
return zwave_command_class_user_credential_delete_all_credentials_by_type(
@@ -391,12 +370,10 @@ static sl_status_t delete_all_credentials_for_user(
391370
// Now that we know that the command is supported, return here if it is
392371
// a support check type of call.
393372
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
394-
attribute_store_node_t user_count_node
395-
= attribute_store_get_first_child_by_type(endpoint_node,
396-
ATTRIBUTE(NUMBER_OF_USERS));
397-
398-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
399-
: SL_STATUS_FAIL;
373+
return zwave_command_class_user_credential_supports(endpoint_node,
374+
CREDENTIAL_SET)
375+
? SL_STATUS_OK
376+
: SL_STATUS_FAIL;
400377
}
401378

402379
return zwave_command_class_user_credential_delete_all_credentials_for_user(
@@ -417,12 +394,10 @@ static sl_status_t delete_all_credentials_for_user_by_type(
417394
// Now that we know that the command is supported, return here if it is
418395
// a support check type of call.
419396
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
420-
attribute_store_node_t user_count_node
421-
= attribute_store_get_first_child_by_type(endpoint_node,
422-
ATTRIBUTE(NUMBER_OF_USERS));
423-
424-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
425-
: SL_STATUS_FAIL;
397+
return zwave_command_class_user_credential_supports(endpoint_node,
398+
CREDENTIAL_SET)
399+
? SL_STATUS_OK
400+
: SL_STATUS_FAIL;
426401
}
427402

428403
return zwave_command_class_user_credential_delete_all_credentials_for_user_by_type(
@@ -446,12 +421,10 @@ sl_status_t
446421
// Now that we know that the command is supported, return here if it is
447422
// a support check type of call.
448423
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
449-
attribute_store_node_t user_count_node
450-
= attribute_store_get_first_child_by_type(endpoint_node,
451-
ATTRIBUTE(NUMBER_OF_USERS));
452-
453-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
454-
: SL_STATUS_FAIL;
424+
return zwave_command_class_user_credential_supports(endpoint_node,
425+
CREDENTIAL_LEARN_START)
426+
? SL_STATUS_OK
427+
: SL_STATUS_FAIL;
455428
}
456429

457430
return zwave_command_class_user_credential_credential_learn_start_add(
@@ -477,12 +450,10 @@ sl_status_t
477450
// Now that we know that the command is supported, return here if it is
478451
// a support check type of call.
479452
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
480-
attribute_store_node_t user_count_node
481-
= attribute_store_get_first_child_by_type(endpoint_node,
482-
ATTRIBUTE(NUMBER_OF_USERS));
483-
484-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
485-
: SL_STATUS_FAIL;
453+
return zwave_command_class_user_credential_supports(endpoint_node,
454+
CREDENTIAL_LEARN_START)
455+
? SL_STATUS_OK
456+
: SL_STATUS_FAIL;
486457
}
487458

488459
return zwave_command_class_user_credential_credential_learn_start_modify(
@@ -504,12 +475,10 @@ sl_status_t
504475
// Now that we know that the command is supported, return here if it is
505476
// a support check type of call.
506477
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
507-
attribute_store_node_t user_count_node
508-
= attribute_store_get_first_child_by_type(endpoint_node,
509-
ATTRIBUTE(NUMBER_OF_USERS));
510-
511-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
512-
: SL_STATUS_FAIL;
478+
return zwave_command_class_user_credential_supports(endpoint_node,
479+
CREDENTIAL_LEARN_CANCEL)
480+
? SL_STATUS_OK
481+
: SL_STATUS_FAIL;
513482
}
514483

515484
return zwave_command_class_user_credential_credential_learn_stop(
@@ -531,12 +500,11 @@ sl_status_t uuic_association_set(dotdot_unid_t unid,
531500
// Now that we know that the command is supported, return here if it is
532501
// a support check type of call.
533502
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
534-
attribute_store_node_t user_count_node
535-
= attribute_store_get_first_child_by_type(endpoint_node,
536-
ATTRIBUTE(NUMBER_OF_USERS));
537-
538-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
539-
: SL_STATUS_FAIL;
503+
return zwave_command_class_user_credential_supports(
504+
endpoint_node,
505+
USER_CREDENTIAL_ASSOCIATION_SET)
506+
? SL_STATUS_OK
507+
: SL_STATUS_FAIL;
540508
}
541509

542510
return zwave_command_class_user_credential_uuic_association_set(
@@ -548,9 +516,10 @@ sl_status_t uuic_association_set(dotdot_unid_t unid,
548516
destination_credential_slot);
549517
}
550518

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)
519+
sl_status_t
520+
get_all_users_checksum(dotdot_unid_t unid,
521+
dotdot_endpoint_id_t endpoint,
522+
uic_mqtt_dotdot_callback_call_type_t call_type)
554523
{
555524
attribute_store_node_t endpoint_node
556525
= attribute_store_network_helper_get_endpoint_node(unid, endpoint);
@@ -564,7 +533,8 @@ sl_status_t get_all_users_checksum(dotdot_unid_t unid,
564533
: SL_STATUS_FAIL;
565534
}
566535

567-
return zwave_command_class_user_credential_get_all_users_checksum(endpoint_node);
536+
return zwave_command_class_user_credential_get_all_users_checksum(
537+
endpoint_node);
568538
}
569539

570540
sl_status_t get_user_checksum(dotdot_unid_t unid,
@@ -578,12 +548,10 @@ sl_status_t get_user_checksum(dotdot_unid_t unid,
578548
// Now that we know that the command is supported, return here if it is
579549
// a support check type of call.
580550
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
581-
attribute_store_node_t user_count_node
582-
= attribute_store_get_first_child_by_type(endpoint_node,
583-
ATTRIBUTE(NUMBER_OF_USERS));
584-
585-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
586-
: SL_STATUS_FAIL;
551+
return zwave_command_class_user_credential_supports(endpoint_node,
552+
USER_CHECKSUM_GET)
553+
? SL_STATUS_OK
554+
: SL_STATUS_FAIL;
587555
}
588556

589557
return zwave_command_class_user_credential_get_user_checksum(endpoint_node,
@@ -602,12 +570,10 @@ sl_status_t
602570
// Now that we know that the command is supported, return here if it is
603571
// a support check type of call.
604572
if (UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK == call_type) {
605-
attribute_store_node_t user_count_node
606-
= attribute_store_get_first_child_by_type(endpoint_node,
607-
ATTRIBUTE(NUMBER_OF_USERS));
608-
609-
return attribute_store_node_exists(user_count_node) ? SL_STATUS_OK
610-
: SL_STATUS_FAIL;
573+
return zwave_command_class_user_credential_supports(endpoint_node,
574+
CREDENTIAL_CHECKSUM_GET)
575+
? SL_STATUS_OK
576+
: SL_STATUS_FAIL;
611577
}
612578

613579
return zwave_command_class_user_credential_get_credential_checksum(
@@ -1139,11 +1105,14 @@ void on_user_credential_message(sl_log_level_t log_level,
11391105
const std::string message)
11401106
{
11411107
nlohmann::json payload;
1142-
payload["level"] = log_level;
1143-
payload["message"] = message;
1108+
payload["level"] = log_level;
1109+
payload["message"] = message;
11441110

11451111
std::string payload_str = payload.dump();
1146-
uic_mqtt_publish("ucl/Event", payload_str.c_str(), payload_str.length(), true);
1112+
uic_mqtt_publish("ucl/Event",
1113+
payload_str.c_str(),
1114+
payload_str.length(),
1115+
true);
11471116
}
11481117

11491118
///////////////////////////////////////////////////////////////////////////////
@@ -1213,13 +1182,12 @@ sl_status_t user_credential_cluster_server_init()
12131182
uic_mqtt_dotdot_user_credential_set_admin_pin_code_callback_set(
12141183
&admin_pin_code_set);
12151184
uic_mqtt_dotdot_user_credential_deactivate_admin_pin_code_callback_set(
1216-
&admin_pin_code_deactivate);
1185+
&admin_pin_code_deactivate);
12171186

12181187
// Types that can't be mapped with UAM
1219-
attribute_store_register_callback_by_type_and_state(
1220-
&on_admin_pin_code_update,
1221-
ATTRIBUTE(ADMIN_PIN_CODE),
1222-
REPORTED_ATTRIBUTE);
1188+
attribute_store_register_callback_by_type_and_state(&on_admin_pin_code_update,
1189+
ATTRIBUTE(ADMIN_PIN_CODE),
1190+
REPORTED_ATTRIBUTE);
12231191

12241192
return SL_STATUS_OK;
12251193
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ credential_capabilities::credential_capabilities(
3838
= endpoint_node.child_by_type(ATTRIBUTE(SUPPORT_ADMIN_PIN_CODE))
3939
.reported<uint8_t>();
4040
this->admin_code_deactivation_support
41-
= endpoint_node.child_by_type(ATTRIBUTE(SUPPORT_ADMIN_PIN_CODE_DEACTIVATION))
41+
= endpoint_node
42+
.child_by_type(ATTRIBUTE(SUPPORT_ADMIN_PIN_CODE_DEACTIVATION))
4243
.reported<uint8_t>();
4344

4445
this->is_data_valid = true;
@@ -49,15 +50,15 @@ credential_capabilities::credential_capabilities(
4950
}
5051
}
5152

52-
bool credential_capabilities::has_credential_checksum_support() const
53+
bool credential_capabilities::is_credential_checksum_supported() const
5354
{
5455
return is_data_valid && credential_checksum_support > 0;
5556
}
56-
bool credential_capabilities::has_admin_code_support() const
57+
bool credential_capabilities::is_admin_code_supported() const
5758
{
5859
return is_data_valid && admin_code_support > 0;
5960
}
60-
bool credential_capabilities::has_admin_code_deactivation_support() const
61+
bool credential_capabilities::is_admin_code_deactivation_supported() const
6162
{
6263
return is_data_valid && admin_code_deactivation_support > 0;
6364
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class credential_capabilities
2727
const attribute_store::attribute &endpoint_node);
2828
~credential_capabilities() = default;
2929

30-
bool has_credential_checksum_support() const;
31-
bool has_admin_code_support() const;
32-
bool has_admin_code_deactivation_support() const;
30+
bool is_credential_checksum_supported() const;
31+
bool is_admin_code_supported() const;
32+
bool is_admin_code_deactivation_supported() const;
3333

3434
private:
3535
uint8_t credential_checksum_support = 0;

0 commit comments

Comments
 (0)