Compare commits
1 Commits
9907a27ab7
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 626f33a15e |
@@ -244,6 +244,63 @@ int CheckCommUnitExcl(GateWayPara GateWay, uint8_t *CommUnitMac)
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
/*****************************************************************************************
|
||||||
|
* 函数名称: RegPayloadValid
|
||||||
|
* 功能描述: 注册请求payload合法性校验,拦截频偏串台误解调的乱码帧,避免乱码设备占用注册表
|
||||||
|
* 参 数: GateWay, 网关句柄
|
||||||
|
CUHeader, 注册帧头
|
||||||
|
PayLoad, 注册负载数据
|
||||||
|
* 返 回 值: 合法返回true, 非法返回false
|
||||||
|
*****************************************************************************************/
|
||||||
|
static bool RegPayloadValid(GateWayPara GateWay, CommUnitFrameHeader CUHeader, uint8_t *PayLoad)
|
||||||
|
{
|
||||||
|
uint8_t SensorN = PayLoad[0];
|
||||||
|
int i, j;
|
||||||
|
bool MacEmpty;
|
||||||
|
|
||||||
|
/*空注册无意义*/
|
||||||
|
if(SensorN == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*payload长度必须容纳N个传感器条目(每条目6字节)*/
|
||||||
|
if(CUHeader->PayloadLen < (uint16_t)(SensorN * 6 + 1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*通讯单元自身MAC不能为全0/全FF*/
|
||||||
|
MacEmpty = true;
|
||||||
|
for(i = 0; i < 6; i++) {
|
||||||
|
if(CUHeader->DevMac[i] != 0x00 && CUHeader->DevMac[i] != 0xFF) { MacEmpty = false; break; }
|
||||||
|
}
|
||||||
|
if(MacEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*注册帧GWMac若非空(全0/全FF视为未填)则必须与本网关匹配*/
|
||||||
|
MacEmpty = true;
|
||||||
|
for(i = 0; i < 6; i++) {
|
||||||
|
if(CUHeader->GWMac[i] != 0x00 && CUHeader->GWMac[i] != 0xFF) { MacEmpty = false; break; }
|
||||||
|
}
|
||||||
|
if(!MacEmpty && memcmp(CUHeader->GWMac, GateWay->ConfigPara.GwMac, 6) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*逐传感器: 类型必须在已知类型表内且非保留(数据长度>0), MAC非全0/全FF且不等于网关MAC*/
|
||||||
|
for(j = 0; j < SensorN; j++) {
|
||||||
|
uint16_t RegType = PayLoad[(j*6)+1] | (PayLoad[(j*6)+2] << 8);
|
||||||
|
if(RegType == 0x0000 || RegType >= sizeof(SensorTypeDataLen)/sizeof(SensorTypeDataLen[0])
|
||||||
|
|| SensorTypeDataLen[RegType] == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
MacEmpty = true;
|
||||||
|
for(i = 0; i < 6; i++) {
|
||||||
|
uint8_t mac = PayLoad[(j*6)+1+i];
|
||||||
|
if(mac != 0x00 && mac != 0xFF) { MacEmpty = false; break; }
|
||||||
|
}
|
||||||
|
if(MacEmpty || memcmp(&PayLoad[(j*6)+1], GateWay->ConfigPara.GwMac, 6) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************************
|
/*****************************************************************************************
|
||||||
* 函数名称: CommUnitSendCmd
|
* 函数名称: CommUnitSendCmd
|
||||||
* 功能描述: 网关下发通讯单元指令函数
|
* 功能描述: 网关下发通讯单元指令函数
|
||||||
@@ -611,6 +668,12 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData
|
|||||||
if(PayLoad[0] > SENSOR_NUM_MAX) {
|
if(PayLoad[0] > SENSOR_NUM_MAX) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
/*串台防护: 校验注册payload合法性, 拦截频偏误解调的乱码帧*/
|
||||||
|
if(!RegPayloadValid(GateWay, CUHeader, PayLoad)) {
|
||||||
|
MAIN_DBG_LOG("\r\nReg rejected: invalid payload (cross-band interference?) Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n",
|
||||||
|
CUHeader->DevMac[0], CUHeader->DevMac[1], CUHeader->DevMac[2], CUHeader->DevMac[3], CUHeader->DevMac[4], CUHeader->DevMac[5]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// if(CUHeader->PayloadLen < 2)
|
// if(CUHeader->PayloadLen < 2)
|
||||||
// return -1;
|
// return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user