Skip to content

Commit f138c88

Browse files
Milind Dumbarerzr
authored andcommitted
ZGW-3393: Check node id base type when wrong source node id is received
[Philippe Coval] This change was reverted in 7.18.3, it looks like it is not the source of the flaky test on sapi, Let's add it back for next release. Forwarded: #20 Signed-off-by: Philippe Coval <[email protected]>
1 parent 3cf4851 commit f138c88

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/serialapi/Serialapi.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ static void ( *cbFuncZWReplaceFailedNode ) ( BYTE txStatus );
180180
static VOID_CALLBACKFUNC(cbFuncZWSendSUCID)(BYTE, TX_STATUS_TYPE*);
181181
/** @} */
182182

183+
static bool is_nodeid_basetype_8();
183184
const char* zw_lib_names[] = {
184185
"Unknown",
185186
"Static controller",
@@ -962,6 +963,12 @@ static void Dispatch( BYTE *pData , uint16_t len)
962963
source_node = (pData[IDX_DATA + (j++)]) << 8; //j is (1 in LR)
963964
}
964965
source_node |= pData[IDX_DATA + (j++)]; //j is 1 (2 in LR)
966+
if(nodemask_nodeid_is_invalid(source_node)) {
967+
if(is_nodeid_basetype_8() && lr_enabled) {
968+
SER_PRINTF("Invalid node id: %d received because Long Range is enabled and Nodeid base type is 8. Setting it to 16", source_node);
969+
SerialAPI_EnableLR();
970+
}
971+
}
965972
// Rename variable 'len' that hides/shadows function parameter
966973
uint8_t length = pData[ IDX_DATA + (j++) ]; //j is 2 (3 in LR)
967974
if (DetectBufferOverflow(length) || (IDX_DATA + j + length) > len) // Stop processing if the length is larger than the buffer.
@@ -1317,6 +1324,8 @@ static void Dispatch( BYTE *pData , uint16_t len)
13171324
break;
13181325

13191326
case FUNC_ID_SERIALAPI_STARTED:
1327+
1328+
lr_enabled = 0;
13201329
/* ZW->HOST: bWakeupReason | bWatchdogStarted | deviceOptionMask | */
13211330
/* nodeType_generic | nodeType_specific | cmdClassLength | cmdClass[] */
13221331
// Do not issue the callback if the packet size is larger than our buffer.
@@ -1754,13 +1763,14 @@ void MemoryGetID( BYTE *pHomeID, uint16_t *pNodeID )
17541763
pHomeID[ 2 ] = buffer[ IDX_DATA + (j++) ];
17551764
pHomeID[ 3 ] = buffer[ IDX_DATA + (j++) ];
17561765
if (lr_enabled && (byLen == 8)) {
1757-
WRN_PRINTF("Short frame for Long range enabled in FUNC_ID_MEMORY_GET_ID");
1758-
}
1759-
1760-
if (lr_enabled && (byLen == 9)) {
1761-
*pNodeID = buffer[ IDX_DATA + (j++) ] << 8;
1766+
WRN_PRINTF("Short frame for Long range enabled in FUNC_ID_MEMORY_GET_ID");
1767+
*pNodeID = 0;
1768+
} else {
1769+
if (lr_enabled && (byLen == 9)) {
1770+
*pNodeID = buffer[ IDX_DATA + (j++) ] << 8;
1771+
}
1772+
*pNodeID |= buffer[ IDX_DATA + (j++) ];
17621773
}
1763-
*pNodeID |= buffer[ IDX_DATA + (j++) ];
17641774
if((*pNodeID < 1) ||
17651775
((*pNodeID > ZW_CLASSIC_MAX_NODES) && (*pNodeID < ZW_LR_MIN_NODE_ID)) ||
17661776
(*pNodeID > ZW_LR_MAX_NODE_ID)) {
@@ -2711,6 +2721,18 @@ void SerialAPI_ApplicationNodeInformation( BYTE listening, APPL_NODE_TYPE nodeTy
27112721
SendFrame(FUNC_ID_SERIAL_API_APPL_NODE_INFORMATION, buffer, idx );
27122722
}
27132723

2724+
static bool is_nodeid_basetype_8()
2725+
{
2726+
BYTE buff[9]; /* FUNC_ID_MEMORY_GET_ID returns max 9 bytes*/
2727+
idx = 0;
2728+
byLen = 0;
2729+
SendFrameWithResponse( FUNC_ID_MEMORY_GET_ID,0, 0, buff, &byLen );
2730+
if (byLen == 8) {
2731+
return true;
2732+
} else {
2733+
return false;
2734+
}
2735+
}
27142736
/**
27152737
* @brief Sets the nodeid type for the serial api
27162738
*

0 commit comments

Comments
 (0)