Skip to content

Commit 306e06c

Browse files
committed
SiliconLabsGH-23: Use v1 frame when using version 1.
Bug-SiliconLabs: UIC-3072 Signed-off-by: Thomas du Boisrouvray <[email protected]> Forwarded-SiliconLabs: thdubois/UIC-3072/c4/develop (cherry picked from commit 66c6bb11ab1bbeeed1307ff9316efcc70b89a476)
1 parent 89085ff commit 306e06c

File tree

1 file changed

+80
-8
lines changed

1 file changed

+80
-8
lines changed

applications/zpc/components/zwave_command_classes/src/zwave_command_class_user_code.c

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,38 @@ static bool is_mucr_supported(attribute_store_node_t endpoint_node)
326326
static sl_status_t zwave_command_class_user_code_number_get(
327327
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
328328
{
329-
(void)node; // unused.
329+
attribute_store_node_t endpoint_node
330+
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE_ENDPOINT_ID);
331+
attribute_store_node_t version_node
332+
= attribute_store_get_first_child_by_type(endpoint_node,
333+
ATTRIBUTE(VERSION));
334+
// We need to check the version of the supporting node:
335+
zwave_cc_version_t supporting_node_version = 0;
336+
attribute_store_get_reported(version_node,
337+
&supporting_node_version,
338+
sizeof(supporting_node_version));
339+
340+
if (supporting_node_version == 0) {
341+
// Wait to know the supporting node version
342+
*frame_length = 0;
343+
return SL_STATUS_IS_WAITING;
344+
}
345+
346+
if (supporting_node_version == 1) {
347+
ZW_USERS_NUMBER_GET_FRAME *get_frame
348+
= (ZW_USERS_NUMBER_GET_FRAME *)frame;
349+
get_frame->cmdClass = COMMAND_CLASS_USER_CODE;
350+
get_frame->cmd = USERS_NUMBER_GET;
351+
*frame_length = sizeof(ZW_USERS_NUMBER_GET_FRAME);
352+
}
353+
else {
330354
// This is a static payload.
331355
ZW_USERS_NUMBER_GET_V2_FRAME *get_frame
332356
= (ZW_USERS_NUMBER_GET_V2_FRAME *)frame;
333357
get_frame->cmdClass = COMMAND_CLASS_USER_CODE_V2;
334358
get_frame->cmd = USERS_NUMBER_GET_V2;
335359
*frame_length = sizeof(ZW_USERS_NUMBER_GET_V2_FRAME);
360+
}
336361
return SL_STATUS_OK;
337362
}
338363

@@ -378,8 +403,8 @@ static sl_status_t zwave_command_class_user_code_get(
378403
*frame_length = 0;
379404
return SL_STATUS_ALREADY_EXISTS;
380405
}
381-
frame[0] = COMMAND_CLASS_USER_CODE_V2;
382-
frame[1] = USER_CODE_GET_V2;
406+
frame[0] = COMMAND_CLASS_USER_CODE;
407+
frame[1] = USER_CODE_GET;
383408
frame[2] = (uint8_t)user_id;
384409
*frame_length = 3;
385410
return SL_STATUS_OK;
@@ -540,7 +565,30 @@ static sl_status_t zwave_command_class_user_code_admin_code_get(
540565
static sl_status_t zwave_command_class_user_code_keypad_mode_get(
541566
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
542567
{
543-
(void)node; // unused.
568+
attribute_store_node_t endpoint_node
569+
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE_ENDPOINT_ID);
570+
attribute_store_node_t version_node
571+
= attribute_store_get_first_child_by_type(endpoint_node,
572+
ATTRIBUTE(VERSION));
573+
// We need to check the version of the supporting node:
574+
zwave_cc_version_t supporting_node_version = 0;
575+
attribute_store_get_reported(version_node,
576+
&supporting_node_version,
577+
sizeof(supporting_node_version));
578+
579+
if (supporting_node_version == 0) {
580+
// Wait to know the supporting node version
581+
*frame_length = 0;
582+
return SL_STATUS_IS_WAITING;
583+
}
584+
585+
if (supporting_node_version == 1) {
586+
sl_log_warning(LOG_TAG, "Keypad Mode attribute found for v1 node. Deleting");
587+
attribute_store_delete_node(node);
588+
*frame_length = 0;
589+
return SL_STATUS_ALREADY_EXISTS;
590+
}
591+
544592
zwave_minimum_frame_t *get_frame = (zwave_minimum_frame_t *)frame;
545593
get_frame->command_class = COMMAND_CLASS_USER_CODE_V2;
546594
get_frame->command = USER_CODE_KEYPAD_MODE_GET_V2;
@@ -560,6 +608,30 @@ static sl_status_t zwave_command_class_user_code_keypad_mode_get(
560608
static sl_status_t zwave_command_class_user_code_keypad_mode_set(
561609
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
562610
{
611+
attribute_store_node_t endpoint_node
612+
= attribute_store_get_first_parent_with_type(node, ATTRIBUTE_ENDPOINT_ID);
613+
attribute_store_node_t version_node
614+
= attribute_store_get_first_child_by_type(endpoint_node,
615+
ATTRIBUTE(VERSION));
616+
// We need to check the version of the supporting node:
617+
zwave_cc_version_t supporting_node_version = 0;
618+
attribute_store_get_reported(version_node,
619+
&supporting_node_version,
620+
sizeof(supporting_node_version));
621+
622+
if (supporting_node_version == 0) {
623+
// Wait to know the supporting node version
624+
*frame_length = 0;
625+
return SL_STATUS_IS_WAITING;
626+
}
627+
628+
if (supporting_node_version == 1) {
629+
sl_log_warning(LOG_TAG, "Keypad mode attribute found for v1 node. Deleting");
630+
attribute_store_delete_node(node);
631+
*frame_length = 0;
632+
return SL_STATUS_ALREADY_EXISTS;
633+
}
634+
563635
ZW_USER_CODE_KEYPAD_MODE_SET_V2_FRAME *set_frame
564636
= (ZW_USER_CODE_KEYPAD_MODE_SET_V2_FRAME *)frame;
565637
set_frame->cmdClass = COMMAND_CLASS_USER_CODE_V2;
@@ -653,8 +725,8 @@ static sl_status_t zwave_command_class_user_code_set(
653725
&user_id_status,
654726
sizeof(user_id_status));
655727

656-
frame[0] = COMMAND_CLASS_USER_CODE_V2;
657-
frame[1] = USER_CODE_SET_V2;
728+
frame[0] = COMMAND_CLASS_USER_CODE;
729+
frame[1] = USER_CODE_SET;
658730
frame[2] = (uint8_t)user_id;
659731
frame[3] = user_id_status;
660732
if (user_id_status == 0) {
@@ -788,8 +860,8 @@ static sl_status_t zwave_command_class_user_code_delete_all(
788860
if (supporting_node_version == 1) {
789861
ZW_USER_CODE_SET_4BYTE_FRAME *set_frame
790862
= (ZW_USER_CODE_SET_4BYTE_FRAME *)frame;
791-
set_frame->cmdClass = COMMAND_CLASS_USER_CODE_V2;
792-
set_frame->cmd = USER_CODE_SET_V2;
863+
set_frame->cmdClass = COMMAND_CLASS_USER_CODE;
864+
set_frame->cmd = USER_CODE_SET;
793865
set_frame->userIdentifier = 0;
794866
set_frame->userIdStatus = 0;
795867
set_frame->userCode1 = 0;

0 commit comments

Comments
 (0)