From 65b04fc6cb5c481911ee48d23bb2225cabb99f48 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Wed, 18 Apr 2012 21:16:27 +0200 Subject: [PATCH] Added verification of control field --- mbus/mbus-protocol.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index c6916f9..368ca7f 100644 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -265,9 +265,11 @@ mbus_frame_type(mbus_frame *frame) // // Possible checks: // -// 1) Start/stop bytes -// 2) length field and actual data size -// 3) checksum +// 1) frame type +// 2) Start/stop bytes +// 3) control field +// 4) length field and actual data size +// 5) checksum // //------------------------------------------------------------------------------ int @@ -289,6 +291,17 @@ mbus_frame_verify(mbus_frame *frame) 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; @@ -302,6 +315,18 @@ mbus_frame_verify(mbus_frame *frame) 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) { snprintf(error_str, sizeof(error_str), "Frame length 1 != 2");