Skip to content

Commit a52bb3b

Browse files
silabs-borislrzr
authored andcommitted
UIC-3222: Credential Learn fix
Allow to add an credential that is already in the node tree Check desired or reported value of CREDENTIAL_LEARN_OPERATION_TYPE to avoid issues with supervision Send status to mqtt
1 parent 295475b commit a52bb3b

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

applications/zpc/components/zwave_command_classes/src/zwave_command_class_user_credential.cpp

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -686,26 +686,17 @@ sl_status_t zwave_command_class_user_credential_credential_handle_report(
686686

687687
switch (credential_report_type) {
688688
case credential_report_type_t::CREDENTIAL_ADDED:
689-
if (!is_credential_available(endpoint_node,
690-
credential_type,
691-
credential_slot)) {
692-
sl_log_error(LOG_TAG,
693-
"Credential already exists. Can't add credential Type "
694-
"%d, Slot %d (User %d)",
695-
credential_type,
696-
credential_slot,
697-
user_id);
698-
return SL_STATUS_FAIL;
699-
} else {
700-
credential_type_node
701-
= create_or_update_desired_value(user_id_node,
702-
ATTRIBUTE(CREDENTIAL_TYPE),
703-
credential_type);
704-
credential_slot_node
705-
= create_or_update_desired_value(credential_type_node,
706-
ATTRIBUTE(CREDENTIAL_SLOT),
707-
credential_slot);
708-
}
689+
// In case of credential learn, the credential is already present in the
690+
// node tree. So we don't check if the node exists before creating it.
691+
// Only update existing nodes if they are present.
692+
credential_type_node
693+
= create_or_update_desired_value(user_id_node,
694+
ATTRIBUTE(CREDENTIAL_TYPE),
695+
credential_type);
696+
credential_slot_node
697+
= create_or_update_desired_value(credential_type_node,
698+
ATTRIBUTE(CREDENTIAL_SLOT),
699+
credential_slot);
709700
break;
710701
case credential_report_type_t::CREDENTIAL_MODIFIED: {
711702
// Should throw an exception if the credential doesn't exists
@@ -1030,9 +1021,9 @@ sl_status_t zwave_command_class_user_credential_credential_learn_status_report(
10301021
const uint8_t step_remaining = parser.read_byte();
10311022

10321023
sl_log_debug(LOG_TAG,
1033-
"Credential Learn Status Report. Credential Type: %d / "
1024+
"Credential Learn Status Report. Credential Type: %s / "
10341025
"Credential Slot: %d (User %d)",
1035-
credential_type,
1026+
cred_type_get_enum_value_name(credential_type).c_str(),
10361027
credential_slot,
10371028
user_id);
10381029

@@ -1043,10 +1034,12 @@ sl_status_t zwave_command_class_user_credential_credential_learn_status_report(
10431034
{credential_slot, DESIRED_OR_REPORTED_ATTRIBUTE});
10441035

10451036
// Get operation type so we can handle error cases
1037+
// We use desired or reported here since it can be set to reported by the
1038+
// supervision process.
10461039
auto operation_type
10471040
= credential_id_nodes.slot_node
10481041
.child_by_type(ATTRIBUTE(CREDENTIAL_LEARN_OPERATION_TYPE))
1049-
.desired<user_credential_operation_type_t>();
1042+
.desired_or_reported<user_credential_operation_type_t>();
10501043

10511044
// Action based of current learn status
10521045
std::string learn_status_str;
@@ -1065,11 +1058,12 @@ sl_status_t zwave_command_class_user_credential_credential_learn_status_report(
10651058
learn_status_str = "Credential Learn already in progress";
10661059
break;
10671060
case CREDENTIAL_LEARN_REPORT_ENDED_NOT_DUE_TO_TIMEOUT:
1068-
learn_status_str = "Credential Learn ended not due to timeout";
1061+
log_level = SL_LOG_ERROR;
1062+
learn_status_str = "Credential Learn Ended (not due to timeout)";
10691063
need_deletion = (operation_type == USER_CREDENTIAL_OPERATION_TYPE_ADD);
10701064
break;
10711065
case CREDENTIAL_LEARN_REPORT_TIMEOUT:
1072-
log_level = SL_LOG_WARNING;
1066+
log_level = SL_LOG_ERROR;
10731067
learn_status_str = "Credential Learn Timeout";
10741068
need_deletion = (operation_type == USER_CREDENTIAL_OPERATION_TYPE_ADD);
10751069
break;
@@ -1092,17 +1086,16 @@ sl_status_t zwave_command_class_user_credential_credential_learn_status_report(
10921086
log_level = SL_LOG_CRITICAL;
10931087
}
10941088

1095-
sl_log(LOG_TAG,
1096-
log_level,
1097-
"%s for User %d, Credential Type %d, "
1098-
"Credential Slot %d",
1099-
learn_status_str.c_str(),
1100-
user_id,
1101-
credential_type,
1102-
credential_slot);
1089+
auto message = boost::format("Credential Learn Status Report : %1% for "
1090+
"Credential Type %2% (Slot %3%, User %4%)")
1091+
% learn_status_str
1092+
% cred_type_get_enum_value_name(credential_type)
1093+
% credential_slot % user_id;
1094+
send_message_to_mqtt(log_level, message.str());
11031095

11041096
if (need_deletion) {
11051097
credential_id_nodes.slot_node.delete_node();
1098+
return SL_STATUS_OK;
11061099
}
11071100

11081101
// Update nodes

0 commit comments

Comments
 (0)