Added verification of control field

This commit is contained in:
Stefan Wahren
2012-04-18 21:16:27 +02:00
parent 1b69b1b51b
commit 65b04fc6cb

View File

@ -265,9 +265,11 @@ mbus_frame_type(mbus_frame *frame)
// //
// Possible checks: // Possible checks:
// //
// 1) Start/stop bytes // 1) frame type
// 2) length field and actual data size // 2) Start/stop bytes
// 3) checksum // 3) control field
// 4) length field and actual data size
// 5) checksum
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int int
@ -289,6 +291,17 @@ mbus_frame_verify(mbus_frame *frame)
return -1; return -1;
} }
if ((frame->control != MBUS_CONTROL_MASK_SND_NKE) &&
(frame->control != MBUS_CONTROL_MASK_REQ_UD1) &&
(frame->control != MBUS_CONTROL_MASK_REQ_UD1 | MBUS_CONTROL_MASK_FCB) &&
(frame->control != MBUS_CONTROL_MASK_REQ_UD2) &&
(frame->control != MBUS_CONTROL_MASK_REQ_UD2 | MBUS_CONTROL_MASK_FCB))
{
snprintf(error_str, sizeof(error_str), "Unknown Control Code for Short Frame");
return -1;
}
break; break;
@ -302,6 +315,18 @@ mbus_frame_verify(mbus_frame *frame)
return -1; return -1;
} }
if ((frame->control != MBUS_CONTROL_MASK_SND_UD) &&
(frame->control != MBUS_CONTROL_MASK_SND_UD | MBUS_CONTROL_MASK_FCB) &&
(frame->control != MBUS_CONTROL_MASK_RSP_UD) &&
(frame->control != MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_DFC) &&
(frame->control != MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_ACD) &&
(frame->control != MBUS_CONTROL_MASK_RSP_UD | MBUS_CONTROL_MASK_DFC | MBUS_CONTROL_MASK_ACD))
{
snprintf(error_str, sizeof(error_str), "Unknown Control Code for Long/Control Frame");
return -1;
}
if (frame->length1 != frame->length2) if (frame->length1 != frame->length2)
{ {
snprintf(error_str, sizeof(error_str), "Frame length 1 != 2"); snprintf(error_str, sizeof(error_str), "Frame length 1 != 2");