From e02f02fa6901218b0af70bf0db2b1338eb3caaa6 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Thu, 22 Jan 2015 17:58:21 +0200 Subject: [PATCH] mpdu: Change the validation function signature What comes in is a frame, and let's set it to uint8_t pointer, which is semantically better than unsigned char. Also, returning the cast pointer instead of a boolean is easier to use as there won't be any need to perform the cast ourselves afterward --- src/mpdu.c | 18 ++++++++++-------- src/mpdu.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/mpdu.c b/src/mpdu.c index 10c179a9..f2637841 100644 --- a/src/mpdu.c +++ b/src/mpdu.c @@ -154,26 +154,28 @@ static bool validate_mgmt_mpdu(const struct mpdu *mpdu, int len, int *offset) return true; } -bool mpdu_validate(const unsigned char *frame, int len) +const struct mpdu *mpdu_validate(const uint8_t *frame, int len) { - struct mpdu *mpdu; + const struct mpdu *mpdu; + bool valid; int offset; if (!frame) - return false; + return NULL; if (len < 2) - return false; + return NULL; offset = 2; - mpdu = (struct mpdu *) frame; + mpdu = (const struct mpdu *) frame; switch (mpdu->fc.type) { case MPDU_TYPE_MANAGEMENT: - return validate_mgmt_mpdu(mpdu, len, &offset); + valid = validate_mgmt_mpdu(mpdu, len, &offset); + break; default: - return false; + return NULL; } - return true; + return valid ? mpdu : NULL; } diff --git a/src/mpdu.h b/src/mpdu.h index 440d3ee4..1407862f 100644 --- a/src/mpdu.h +++ b/src/mpdu.h @@ -251,4 +251,4 @@ struct mpdu { }; } __attribute__ ((packed)); -bool mpdu_validate(const unsigned char *mpdu, int len); +const struct mpdu *mpdu_validate(const uint8_t *frame, int len);