Skip to content

Commit cb377ac

Browse files
silabs-borislrzr
authored andcommitted
uic: zpc: UIC-3274: CRC16 Encapsulation
[Philippe Coval] Took over change and fixed typos Origin: projects/UIC/repos/uic/pull-requests/2851/overview Thanks-to: Aydogan Ersoz <Aydogan.Ersoz@silabs.com> cherry picked from commit 86dd2bba208fc85f256b451a8b7cb9d9b4acea98) Last-update: 2025-01-10 Forwarded: #11 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent 1e7012a commit cb377ac

17 files changed

+1647
-18
lines changed

applications/zpc/components/zpc_attribute_store/include/attribute_store_defined_attribute_types.h

+4
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,10 @@ DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_CONFIGURATION_PARAMETERS_TO_DISCOVER,
561561
/// zwave_cc_version_t
562562
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_CRC16_VERSION,
563563
((COMMAND_CLASS_CRC_16_ENCAP << 8) | 0x01))
564+
// Flag to disable CRC16 response if necessary (default is enabled)
565+
// Should not be used (unless with some faulty devices)
566+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_CRC16_DISABLE_CRC16,
567+
((COMMAND_CLASS_CRC_16_ENCAP << 8) | 0x02))
564568

565569
/////////////////////////////////////////////////
566570
// Device Reset Locally Command Class

applications/zpc/components/zpc_attribute_store/include/zwave_utils.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "zwave_command_class_wake_up_types.h"
3333
#include "attribute_store_defined_attribute_types.h"
3434

35+
#include "attribute_store.h"
36+
3537
/**
3638
* @ingroup zpc_utils
3739
* @{
@@ -214,12 +216,22 @@ zwave_cc_version_t
214216
zwave_endpoint_id_t endpoint_id);
215217

216218
/**
219+
* @brief Get endpoint node associated with the ZWave NodeID and Endpoint ID
220+
*
221+
* @param node_id The Z-Wave NodeID for which we want to find the endpoint
222+
* @param endpoint_id The Z-Wave Endpoint ID for which we want to find the endpoint
223+
*
224+
* @returns The attribute store node associated with the endpoint.
225+
*/
226+
attribute_store_node_t zwave_get_endpoint_node(zwave_node_id_t node_id,
227+
zwave_endpoint_id_t endpoint_id);
228+
/**
217229
* @brief Verify if we registered a node as supporting S2.
218230
*
219231
* @param node_id The NodeID that supports S2.
220232
* @returns True if the node has been registered to support S2, false otherwise
221233
*/
222-
bool zwave_security_validation_is_node_s2_capable(zwave_node_id_t node_id);
234+
bool zwave_security_validation_is_node_s2_capable(zwave_node_id_t node_id);
223235

224236
/**
225237
* @brief Sets a node as S2 capable, meaning that we know it supports S2,

applications/zpc/components/zpc_attribute_store/src/zpc_attribute_store_type_registration.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static const std::vector<attribute_schema_t> attribute_schema = {
192192
// Device Reset Locally Command Class attributes
193193
/////////////////////////////////////////////////////////////////////
194194
{ATTRIBUTE_COMMAND_CLASS_CRC16_VERSION, "CRC16 Version", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
195+
{ATTRIBUTE_COMMAND_CLASS_CRC16_DISABLE_CRC16, "Disable CRC16 frames", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
195196
/////////////////////////////////////////////////////////////////////
196197
// Inclusion Controller Command Class attributes
197198
/////////////////////////////////////////////////////////////////////

applications/zpc/components/zpc_attribute_store/src/zwave_utils.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,8 @@ zwave_cc_version_t
359359
zwave_node_id_t node_id,
360360
zwave_endpoint_id_t endpoint_id)
361361
{
362-
unid_t node_unid;
363-
zwave_unid_from_node_id(node_id, node_unid);
364362
attribute_store_node_t endpoint_node
365-
= attribute_store_network_helper_get_endpoint_node(node_unid, endpoint_id);
363+
= zwave_get_endpoint_node(node_id, endpoint_id);
366364

367365
if (endpoint_node == ATTRIBUTE_STORE_INVALID_NODE) {
368366
return 0;
@@ -378,6 +376,16 @@ zwave_cc_version_t
378376
return version;
379377
}
380378

379+
attribute_store_node_t zwave_get_endpoint_node(zwave_node_id_t node_id,
380+
zwave_endpoint_id_t endpoint_id)
381+
{
382+
unid_t node_unid;
383+
zwave_unid_from_node_id(node_id, node_unid);
384+
return attribute_store_network_helper_get_endpoint_node(node_unid,
385+
endpoint_id);
386+
387+
}
388+
381389
bool zwave_security_validation_is_node_s2_capable(zwave_node_id_t node_id)
382390
{
383391
attribute_store_node_t node_id_node

applications/zpc/components/zwave/zwave_transports/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target_link_libraries(
1111
PUBLIC zwave_controller
1212
zwave_tx
1313
zwave_rx
14+
zwave_crc16
1415
zwave_s0
1516
zwave_s2
1617
zwave_api_transport
@@ -21,6 +22,7 @@ target_link_libraries(
2122
zwave_tx_scheme_selector)
2223
install(TARGETS zwave_transports LIBRARY DESTINATION lib)
2324

25+
add_subdirectory(crc16)
2426
add_subdirectory(s0)
2527
add_subdirectory(s2)
2628
add_subdirectory(multi_channel)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Library
2+
add_library(zwave_crc16
3+
src/zwave_crc16_transport.c
4+
)
5+
6+
target_include_directories(zwave_crc16
7+
PUBLIC include
8+
)
9+
10+
target_link_libraries(zwave_crc16
11+
PUBLIC zwave_controller unify
12+
PRIVATE zpc_attribute_store zwave_command_classes
13+
)
14+
15+
if(BUILD_TESTING)
16+
#target_add_mock(zwave_crc16)
17+
add_subdirectory(test)
18+
endif()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/******************************************************************************
2+
* # License
3+
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
4+
******************************************************************************
5+
* The licensor of this software is Silicon Laboratories Inc. Your use of this
6+
* software is governed by the terms of Silicon Labs Master Software License
7+
* Agreement (MSLA) available at
8+
* www.silabs.com/about-us/legal/master-software-license-agreement. This
9+
* software is distributed to you in Source Code format and is governed by the
10+
* sections of the MSLA applicable to Source Code.
11+
*
12+
*****************************************************************************/
13+
14+
/**
15+
* @defgroup zwave_crc16_transport CRC16 Transport
16+
* @ingroup zwave_transports
17+
* @brief Transport for CRC16
18+
*
19+
* @{
20+
*/
21+
22+
#ifndef ZWAVE_CRC_16_TRANSPORT_H
23+
#define ZWAVE_CRC_16_TRANSPORT_H
24+
25+
#include "sl_status.h"
26+
#include "zwave_node_id_definitions.h"
27+
28+
// We allow to encapsulate the maximum minus our encapsulation command overhead
29+
#define CRC_16_ENCAPSULATION_HEADER 2
30+
#define CRC_16_ENCAPSULATION_FOOTER 2
31+
#define CRC_16_ENCAPSULATION_OVERHEAD (CRC_16_ENCAPSULATION_HEADER + CRC_16_ENCAPSULATION_FOOTER)
32+
33+
#define CRC_16_ENCAPSULATED_COMMAND_MAXIMUM_SIZE \
34+
(ZWAVE_MAX_FRAME_SIZE - CRC_16_ENCAPSULATION_OVERHEAD)
35+
36+
typedef struct zwave_crc16_encapsulation_frame {
37+
uint8_t command_class; /* The command class */
38+
uint8_t command; /* The command */
39+
uint8_t encapsulated_command
40+
[CRC_16_ENCAPSULATED_COMMAND_MAXIMUM_SIZE]; /* The checksum will be appended to the command*/
41+
/* Encapsulated command */
42+
} zwave_crc16_encapsulation_frame_t;
43+
44+
#ifdef __cplusplus
45+
extern "C" {
46+
#endif
47+
48+
/**
49+
* @brief Initialize the CRC16 Transport
50+
* *
51+
* @returns SL_STATUS_OK if successful
52+
* @returns SL_STATUS_FAIL if an error occurred
53+
*/
54+
sl_status_t zwave_crc16_transport_init(void);
55+
56+
#ifdef __cplusplus
57+
}
58+
#endif
59+
60+
#endif //ZWAVE_CRC_16_TRANSPORT_H
61+
/** @} end zwave_crc16_transport */

0 commit comments

Comments
 (0)