Skip to content

Commit fe344dc

Browse files
committed
fix(cc): Fix central_scene handler on frame without cmd
Adding determinist test as well as suggested in related review. Origin: SiliconLabsSoftware#115 Relate-to: SiliconLabsSoftware#110 (comment) Relate-to: SiliconLabsSoftware#111 (comment) Thanks-to: Laudin Molina Troconis <[email protected]> Relate-to: SiliconLabsSoftware/z-wave-engine-application-layer#10 Signed-off-by: Philippe Coval <[email protected]>
1 parent e134e44 commit fe344dc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ static sl_status_t zwave_command_class_central_scene_control_handler(
554554
const uint8_t *frame,
555555
uint16_t frame_length)
556556
{
557-
if (frame_length < COMMAND_INDEX) {
557+
if (frame_length <= COMMAND_INDEX) { // Should contain at least class and cmd
558558
return SL_STATUS_NOT_SUPPORTED;
559559
}
560560

@@ -793,4 +793,4 @@ sl_status_t zwave_command_class_central_scene_init()
793793
zwave_command_handler_register_handler(handler);
794794

795795
return SL_STATUS_OK;
796-
}
796+
}

applications/zpc/components/zwave_command_classes/test/zwave_command_class_central_scene_test.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,17 @@ void test_zwave_command_class_central_scene_configuration_set_no_slow_refresh()
346346
void test_zwave_command_class_central_scene_frame_too_short()
347347
{
348348
TEST_ASSERT_NOT_NULL(central_scene_handler.control_handler);
349-
const uint8_t incoming_frame[] = {COMMAND_CLASS_CENTRAL_SCENE_V3};
350-
351-
TEST_ASSERT_EQUAL(
352-
SL_STATUS_NOT_SUPPORTED,
353-
central_scene_handler.control_handler(&connection_info,
349+
const uint8_t incoming_frame[] = {
350+
COMMAND_CLASS_CENTRAL_SCENE_V3,
351+
CENTRAL_SCENE_NOTIFICATION_V3 // Padding with deterministic valid cmd if overflow
352+
};
353+
354+
TEST_ASSERT_EQUAL(SL_STATUS_NOT_SUPPORTED,
355+
central_scene_handler.control_handler(
356+
&connection_info,
354357
incoming_frame,
355-
sizeof(incoming_frame)));
358+
sizeof(incoming_frame) - 1 // remove padding
359+
));
356360
}
357361

358362
void test_zwave_command_class_central_scene_frame_wrong_command_class()
@@ -963,4 +967,4 @@ void test_zwave_command_class_central_scene_notification_return_scene_to_idle()
963967
TEST_ASSERT_NOT_NULL(return_scene_to_idle);
964968
return_scene_to_idle(endpoint_id_node);
965969
verify_attribute_store_data_notification(0, 0);
966-
}
970+
}

0 commit comments

Comments
 (0)