From 256a2f8ac0c5fdfadd9efcd3774301ccbad3390c Mon Sep 17 00:00:00 2001 From: laranjeiro Date: Wed, 27 Feb 2008 08:46:23 +0000 Subject: Added the interface module with its sub module e.g sniffer. Tested in unit tests. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1470 017c9cb6-072f-447c-8318-d5b54f68fe89 --- interface/sniffer/Module | 1 + interface/sniffer/inc/context.h | 42 +++++ interface/sniffer/sniffer.h | 196 ++++++++++++++++++++ interface/sniffer/src/sniffer.c | 215 ++++++++++++++++++++++ interface/sniffer/test/Makefile | 9 + interface/sniffer/test/src/test-sniffer.c | 294 ++++++++++++++++++++++++++++++ 6 files changed, 757 insertions(+) create mode 100644 interface/sniffer/Module create mode 100644 interface/sniffer/inc/context.h create mode 100644 interface/sniffer/sniffer.h create mode 100644 interface/sniffer/src/sniffer.c create mode 100644 interface/sniffer/test/Makefile create mode 100644 interface/sniffer/test/src/test-sniffer.c (limited to 'interface/sniffer') diff --git a/interface/sniffer/Module b/interface/sniffer/Module new file mode 100644 index 0000000000..059889da76 --- /dev/null +++ b/interface/sniffer/Module @@ -0,0 +1 @@ +SOURCES=sniffer.c diff --git a/interface/sniffer/inc/context.h b/interface/sniffer/inc/context.h new file mode 100644 index 0000000000..254250881e --- /dev/null +++ b/interface/sniffer/inc/context.h @@ -0,0 +1,42 @@ +#ifndef interface_sniffer_inc_context_h +#define interface_sniffer_inc_context_h +/* Cesar project {{{ + * + * Copyright (C) 2008 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file interface/sniffer/inc/context.h + * \brief Context of the sniffer. + * \ingroup inteface_sniffer + * + */ + +#define SNIFFER_REG__SNIFF_MME_TX 0, 0 +#define SNIFFER_REG__SNIFF_MME_RX 1, 1 +#define SNIFFER_REG__SNIFF_BEACON_TX 2, 2 +#define SNIFFER_REG__SNIFF_BEACON_RX 3, 3 + +#define SNIFFER_MME 1 +#define SNIFFER_BEACON 0 + +struct interface_sniffer_t +{ + /** Sniff the beacon send. */ + bool sniff_beacon_tx; + /** Sniff the beacon on reception. */ + bool sniff_beacon_rx; + /** Sniff the MME on TX. */ + bool sniff_mme_tx; + /** Sniff the MME on RX. */ + bool sniff_mme_rx; + + /** Call this function when it needs to post a message for the HLE. */ + interface_sniffer_send_message_cb_t send_func; + /** data to provide on function callback. */ + void *send_user_data; +}; + +#endif /* interface_sniffer_inc_context_h */ diff --git a/interface/sniffer/sniffer.h b/interface/sniffer/sniffer.h new file mode 100644 index 0000000000..9c74647c7b --- /dev/null +++ b/interface/sniffer/sniffer.h @@ -0,0 +1,196 @@ +#ifndef interface_sniffer_sniffer_h +#define interface_sniffer_sniffer_h +/* Cesar project {{{ + * + * Copyright (C) 2008 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file interface/sniffer/sniffer.h + * \brief Sniffer public functions. + * \ingroup interface_sniffer + * + */ + +#include "mac/common/pb.h" +#include "interface/interface_module.h" + + +/** Send a message to the interface. This message shall be send to the linux driver. + * \param user_data  the data provided in the function registration + * \param message  the message to send. + * \param length  the message length + */ +typedef void (*interface_sniffer_send_message_cb_t) (void *user_data, + uint *message, uint length); + + +/** Forward declaration. */ +typedef struct interface_sniffer_t interface_sniffer_t; + + +/** Initialise the sniffer and all the callback of the sniffer. + * \param cb the function to call when the sniffer needs to send a message. + * \param user_data the data to provide on each function callback provided. + */ +interface_sniffer_t* +interface_sniffer_init (interface_sniffer_send_message_cb_t cb, void *user_data); + + +/** Uninitalise the sniffer. + * \param ctx the sniffer context. + */ +void +interface_sniffer_uninit (interface_sniffer_t *ctx); + +/** Configure the sniffer. + * \param ctx the sniffer context + * \param data the data to configure the sniffer. + */ +void +interface_sniffer_configure (interface_sniffer_t *ctx, uint data); + + +/** Copy a MME to the buffer and request the interface to send the MME. + * \param ctx the sniffer context. + * \param mme the MME buffer + * \param length the MME length + * \param buffer the destination buffer. + * \param tx the MME way (TX/RX) + * \param encrypted if the MME has been encrypted or not. + */ +void +interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length, + u8 *buffer, bool tx, bool encrypted); + +/** Copy a MME to the buffer and request the interface to send the MME. + * \param ctx the sniffer context. + * \param mme the MME buffer + * \param length the MME length + * \param buffer the destination buffer. + * \param encrypted if the MME has been encrypted or not. + */ +extern inline void +interface_sniffer_copy_mme_tx (interface_sniffer_t *ctx, u8 *mme, uint length, + u8 *buffer, bool encrypted) +{ + interface_sniffer_copy_mme (ctx, mme, length, buffer, true, encrypted); +} + +/** Copy a MME to the buffer and request the interface to send the MME. + * \param ctx the sniffer context. + * \param mme the MME buffer + * \param length the MME length + * \param buffer the destination buffer. + * \param encrypted if the MME has been encrypted or not. + */ +extern inline void +interface_sniffer_copy_mme_rx (interface_sniffer_t *ctx, u8 *mme, uint length, + u8 *buffer, bool encrypted) +{ + interface_sniffer_copy_mme (ctx, mme, length, buffer, false, encrypted); +} + +/** Copy a beacon to the buffer and request the interface to send the copied beacon. + * Encapsulate the beacon in a MME. + * \param ctx the sniffer context. + * \param beacon the beacon + * \param buffer the destination buffer. + * \param tx the beacon way (TX/RX) + * \param mac_address the station mac address to fill the OSA ODA in the + * MME. + */ +void +interface_sniffer_copy_beacon (interface_sniffer_t *ctx, pb_beacon_t *beacon, + u8 *buffer, bool tx, mac_t mac_address); + +/** Copy a beacon to the buffer and request the interface to send the copied beacon. + * Encapsulate the beacon in a MME. + * \param ctx the sniffer context. + * \param beacon the beacon + * \param buffer the destination buffer. + * \param mac_address the station mac address to fill the OSA ODA in the + * MME. + */ +extern inline void +interface_sniffer_copy_beacon_tx (interface_sniffer_t *ctx, pb_beacon_t *beacon, + u8 *buffer, mac_t mac_address) +{ + interface_sniffer_copy_beacon (ctx, beacon, buffer, true, mac_address); +} + +/** Copy a beacon to the buffer and request the interface to send the copied beacon. + * Encapsulate the beacon in a MME. + * \param ctx the sniffer context. + * \param beacon the beacon + * \param buffer the destination buffer. + * \param mac_address the station mac address to fill the OSA ODA in the + * MME. + */ +extern inline void +interface_sniffer_copy_beacon_rx (interface_sniffer_t *ctx, pb_beacon_t *beacon, + u8 *buffer, mac_t mac_address) +{ + interface_sniffer_copy_beacon (ctx, beacon, buffer, false, mac_address); +} + +/** Provides the MME sniff status. + * \param ctx the sniffer context. + * \param tx the way. + * \return the MME sniff status. + */ +bool +interface_sniffer_mme_status (interface_sniffer_t *ctx, bool tx); + + +/** Provides the MME sniff status. + * \param ctx the sniffer context. + * \return the MME sniff status. + */ +extern inline bool +interface_sniffer_mme_status_tx (interface_sniffer_t *ctx) +{ + return interface_sniffer_mme_status(ctx, true); +} + +/** Provides the MME sniff status. + * \param ctx the sniffer context. + * \return the MME sniff status. + */ +extern inline bool +interface_sniffer_mme_status_rx (interface_sniffer_t *ctx) +{ + return interface_sniffer_mme_status(ctx, false); +} + +/** Provides the beacon sniff status. + * \param ctx the sniffer context. + * \param tx the way. + * \return the beacon sniff status. + */ +bool +interface_sniffer_beacon_status (interface_sniffer_t *ctx, bool tx); + +/** Provides the beacon sniff status. + * \param ctx the sniffer context. + * \return the beacon sniff status. + */ +extern inline bool +interface_sniffer_beacon_status_tx (interface_sniffer_t *ctx) +{ + return interface_sniffer_beacon_status (ctx, true); +} + +/** Provides the beacon sniff status. + * \param ctx the sniffer context. + * \return the beacon sniff status. + */ +extern inline bool +interface_sniffer_beacon_status_rx (interface_sniffer_t *ctx) +{ + return interface_sniffer_beacon_status (ctx, false); +} + +#endif /* interface_sniffer_sniffer_h */ diff --git a/interface/sniffer/src/sniffer.c b/interface/sniffer/src/sniffer.c new file mode 100644 index 0000000000..68ee831402 --- /dev/null +++ b/interface/sniffer/src/sniffer.c @@ -0,0 +1,215 @@ +/* Cesar project {{{ + * + * Copyright (C) 2008 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file interface/sniffer/src/sniffer.c + * \brief Sniffer source functions. + * \ingroup interface_sniffer + * + * « long description » + */ +#include "common/std.h" +#include "common/defs/ethernet.h" +#include "common/defs/homeplugAV.h" + +#include "lib/bitstream.h" +#include "hal/hle/ipmbox.h" +#include "string.h" + +#include "mac/pbproc/pbproc.h" + +#include "interface/sniffer/sniffer.h" +#include "interface/sniffer/inc/context.h" + +/* Static declaration. */ +static interface_sniffer_t sniffer_global; + +/** Initialise the sniffer and all the callback of the sniffer. + * \param cb the function to call when the sniffer needs to send a message. + * \param user_data the data to provide on each function callback provided. + */ +interface_sniffer_t* +interface_sniffer_init (interface_sniffer_send_message_cb_t cb, void *user_data) +{ + dbg_assert (cb); + + sniffer_global.sniff_beacon_tx = false; + sniffer_global.sniff_beacon_rx = false; + sniffer_global.sniff_mme_tx = false; + sniffer_global.sniff_mme_rx = false; + + sniffer_global.send_func = cb; + sniffer_global.send_user_data = user_data; + + return &sniffer_global; +} + + +/** Uninitalise the sniffer. + * \param ctx the sniffer context. + */ +void +interface_sniffer_uninit (interface_sniffer_t *ctx) +{ + dbg_assert (ctx); +} + +/** Configure the sniffer. + * \param ctx the sniffer context + * \param data the data to configure the sniffer. + */ +void +interface_sniffer_configure (interface_sniffer_t *ctx, uint data) +{ + dbg_assert (ctx); + dbg_assert (data); + + ctx->sniff_mme_tx = BF_GET(SNIFFER_REG__SNIFF_MME_TX, data); + ctx->sniff_mme_rx = BF_GET(SNIFFER_REG__SNIFF_MME_RX, data); + ctx->sniff_beacon_tx = BF_GET(SNIFFER_REG__SNIFF_BEACON_TX, data); + ctx->sniff_beacon_rx = BF_GET(SNIFFER_REG__SNIFF_BEACON_RX, data); +} + + +/** Copy a MME to the buffer and request the interface to send the MME. + * \param ctx the sniffer context. + * \param mme the MME buffer + * \param length the MME length + * \param buffer the destination buffer. + * \param tx the MME way (TX/RX) + */ +void +interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length, + u8 *buffer, bool tx, bool encrypted) +{ + uint word[2]; + + dbg_assert (ctx); + dbg_assert (mme); + dbg_assert (ETH_PACKET_MIN_SIZE <= length && length <= + ETH_PACKET_MAX_SIZE); + dbg_assert (buffer); + dbg_assert (ctx->send_func); + + memcpy (buffer, mme, length); + + word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, INTERFACE_MODULE_SNIFFER), + (MSG_LENGTH, 1), (PARAM_SNIFFER_WAY, tx), + (PARAM_SNIFFER_EKC, encrypted), + (PARAM_SNIFFER_TYPE, SNIFFER_MME), + (PARAM_SNIFFER_LENGTH, length)); + + word[1] = (uint)buffer; + + + /** Request the interface to send the message to the linux driver. */ + (*ctx->send_func) (ctx->send_user_data, word, 2); +} + +/** Copy a beacon to the buffer and request the interface to send the copied beacon. + * Encapsulate the beacon in a MME. + * \param ctx the sniffer context. + * \param beacon the beacon + * \param buffer the destination buffer. + * \param tx the beacon way (TX/RX) + * \param mac_address the station mac address to fill the OSA ODA in the + * MME. + */ +void +interface_sniffer_copy_beacon (interface_sniffer_t *ctx, pb_beacon_t *beacon, + u8 *buffer, bool tx, mac_t mac_address) +{ + bitstream_t bitstream; + uint data; + uint length; + uint word[2]; + + dbg_assert (ctx); + dbg_assert (buffer); + dbg_assert (beacon); + + length = 136 + sizeof (pbproc_rx_beacon_params_t); + + // Fill the buffer header. + bitstream_init (&bitstream, buffer, 25, BITSTREAM_WRITE); + bitstream_access (&bitstream, &mac_address, 48); + bitstream_access (&bitstream, &mac_address, 48); + + /** Inserting the VLAN TAG. */ + data = 0; + bitstream_access (&bitstream, &data, 32); + + /** Inserting the MTYPE. */ + data = ((HPAV_MTYPE_MME & 0xFF) << 8) | (HPAV_MTYPE_MME >> 8); + bitstream_access (&bitstream, &data, 16); + + /** Inserting the MMV. */ + data = 0x0; + bitstream_access (&bitstream, &data, 8); + + /** Inserting the MMTYPE. */ + data = 0xA036; + bitstream_access (&bitstream, &data, 16); + + /** Inserting the module type. */ + data = INTERFACE_MODULE_SNIFFER; + bitstream_access (&bitstream, &data, 8); + + /** Inserting data type i.e. beacon == 0 */ + data = 0; + bitstream_access (&bitstream, &data, 8); + + /** Inserting length. */ + bitstream_access (&bitstream, &length, 16); + bitstream_finalise (&bitstream); + + word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, INTERFACE_MODULE_SNIFFER), + (MSG_LENGTH, 1), (PARAM_SNIFFER_WAY, tx), + (PARAM_SNIFFER_EKC, false), + (PARAM_SNIFFER_TYPE, SNIFFER_BEACON), + (PARAM_SNIFFER_LENGTH, length)); + + word[1] = (uint)buffer; + + + /** Request the interface to send the message to the linux driver. */ + (*ctx->send_func) (ctx->send_user_data, word, 2); +} + + +/** Provides the MME sniff status. + * \param ctx the sniffer context. + * \param tx the way. + * \return the MME sniff status. + */ +bool +interface_sniffer_mme_status (interface_sniffer_t *ctx, bool tx) +{ + dbg_assert (ctx); + + if (tx) + return ctx->sniff_mme_tx; + else + return ctx->sniff_mme_rx; +} + +/** Provides the beacon sniff status. + * \param ctx the sniffer context. + * \param tx the way. + * \return the beacon sniff status. + */ +bool +interface_sniffer_beacon_status (interface_sniffer_t *ctx, bool tx) +{ + dbg_assert (ctx); + + if (tx) + return ctx->sniff_mme_tx; + else + return ctx->sniff_mme_rx; +} + diff --git a/interface/sniffer/test/Makefile b/interface/sniffer/test/Makefile new file mode 100644 index 0000000000..1fee49b3e5 --- /dev/null +++ b/interface/sniffer/test/Makefile @@ -0,0 +1,9 @@ +BASE = ../../.. + +DEFS = -DINTERFACE_MODULE_SNIFFER=6 + +HOST_PROGRAMS = test-sniffer +test-sniffer_SOURCES = test-sniffer.c +test-sniffer_MODULES = lib interface/sniffer + +include $(BASE)/common/make/top.mk diff --git a/interface/sniffer/test/src/test-sniffer.c b/interface/sniffer/test/src/test-sniffer.c new file mode 100644 index 0000000000..dabb36366a --- /dev/null +++ b/interface/sniffer/test/src/test-sniffer.c @@ -0,0 +1,294 @@ +/* Cesar project {{{ + * + * Copyright (C) 2008 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file interface/sniffer/test/src/test-sniffer.c + * \brief testing sniffer. + * \ingroup interface_sniffer + * + */ +#include "common/std.h" +#include "lib/test.h" +#include "lib/read_word.h" +#include "lib/bitstream.h" + +#include "interface/sniffer/sniffer.h" +#include "interface/sniffer/inc/context.h" + +#include + +uint ipmbox_msg[2]; + +void test_sniffer_send_message (void *user_data, uint *message, uint length) +{ + memcpy (ipmbox_msg, message, 2*sizeof(uint)); +} + +int +main (void) +{ + test_t test; + interface_sniffer_t *sniffer; + u8 data[10]; + u8 mme[1500]; + u8 copy_mme[1500]; + uint i; + pb_beacon_t *beacon; + + /** Data to process the ipmbox message. */ + uint type; + uint data_tx; + uint data_length; + uint data_type; + uint data_ekc; + u8 *msg; + uint msg_len; + bitstream_t bitstream; + + /** Process the MME beacon data. */ + mac_t oda; + mac_t osa; + uint vlan; + uint mtype; + uint mmv; + uint mmtype; + uint module; + uint mme_data_type; + uint mme_data_length; + + test_init (test, 0, NULL); + + + test_case_begin (test, "Sniffer init"); + sniffer = interface_sniffer_init (test_sniffer_send_message, NULL); + + test_begin (test, "sniffer init") + { + test_fail_if (sniffer->sniff_beacon_tx != false, "Error, sniffer should be unactivated"); + test_fail_if (sniffer->sniff_beacon_rx != false, "Error, sniffer should be unactivated"); + test_fail_if (sniffer->sniff_mme_tx != false, "Error, sniffer should be unactivated"); + test_fail_if (sniffer->sniff_mme_rx != false, "Error, sniffer should be unactivated"); + test_fail_if (sniffer->send_func == NULL, "Error, send function not filled"); + } + test_end; + + test_case_begin (test, "Activating the sniffer."); + + data[0] = 0xF; + interface_sniffer_configure (sniffer, read_u8_from_word(data)); + test_begin (test, "All sniffer part") + { + test_fail_if (sniffer->sniff_beacon_tx != true, "Error, beacon TX's sniffer should be activated"); + test_fail_if (sniffer->sniff_beacon_rx != true, "Error, beacon RX's sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_tx != true, "Error, MME TX's sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_rx != true, "Error, MME RX's sniffer should be activated"); + } + test_end; + + data[0] = 0xE; + interface_sniffer_configure (sniffer, read_u8_from_word(data)); + test_begin (test, "Unactivate the sniffer on MME TX") + { + test_fail_if (sniffer->sniff_beacon_tx != true, "Error, beacon TX's sniffer should be activated"); + test_fail_if (sniffer->sniff_beacon_rx != true, "Error, beacon RX's sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_tx != false , "Error, MME TX's sniffer should be unactivated"); + test_fail_if (sniffer->sniff_mme_rx != true, "Error, MME RX's sniffer should be activated"); + } + test_end; + + interface_sniffer_configure (sniffer, 0xD); + test_begin (test, "Unactivate the sniff MME on RX") + { + test_fail_if (sniffer->sniff_beacon_tx != true, "Error, beacon TX's sniffer should be activated"); + test_fail_if (sniffer->sniff_beacon_rx != true, "Error, beacon RX's sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_tx != true , "Error, MME TX's sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_rx != false , "Error, MME RX's sniffer should be unactivated"); + } + test_end; + + data[0] = 0xB; + interface_sniffer_configure (sniffer, read_u8_from_word(data)); + test_begin (test, "Unactivate the sniff becon on rx") + { + test_fail_if (sniffer->sniff_beacon_tx != false, "Error, sniffer should be unactivated"); + test_fail_if (sniffer->sniff_beacon_rx != true, "Error, sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_tx != true , "Error, sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_rx != true, "Error, sniffer should be activated"); + } + test_end; + + data[0] = 0x7; + interface_sniffer_configure (sniffer, read_u8_from_word(data)); + test_begin (test, "Unactivate the sniff becon on tx") + { + test_fail_if (sniffer->sniff_beacon_tx != true, "Error, sniffer should be activated"); + test_fail_if (sniffer->sniff_beacon_rx != false, "Error, sniffer should be unactivated"); + test_fail_if (sniffer->sniff_mme_tx != true , "Error, sniffer should be activated"); + test_fail_if (sniffer->sniff_mme_rx != true, "Error, sniffer should be activated"); + } + test_end; + + + test_case_begin (test, "Copy a MME"); + + for (i = 0; i < 1500; i++) + { + mme[i] = i; + } + + interface_sniffer_copy_mme_tx (sniffer, mme, 1500, copy_mme, false); + + bitstream_init (&bitstream, ipmbox_msg, sizeof (uint), BITSTREAM_READ); + bitstream_access (&bitstream, &type, 8); + bitstream_access (&bitstream, &msg_len, 4); + bitstream_access (&bitstream, &data_tx, 1); + bitstream_access (&bitstream, &data_ekc, 1); + bitstream_access (&bitstream, &data_type, 3); + bitstream_access (&bitstream, &data_length, 12); + bitstream_finalise (&bitstream); + + msg = (u8 *) ipmbox_msg[1]; + + test_begin (test, "Verify message posted in the IPMBOX") + { + test_fail_if (type != INTERFACE_SNIFFER, "Error on message type"); + test_fail_if (msg_len != 1, "Error on message length"); + test_fail_if (data_ekc != false, "Error on message encryption"); + test_fail_if (data_tx != true, "Error on message way"); + test_fail_if (data_type != 1, "Error on message data type"); + test_fail_if (data_length != 1500, "Error on message data length"); + + for (i = 0; i < data_length; i++) + { + test_fail_if (msg[i] != (u8)i, "Error, mme_copy at index %d is not equal to %d", i, (u8)i); + } + } + test_end; + + interface_sniffer_copy_mme_rx (sniffer, mme, 1500, copy_mme, true); + + bitstream_init (&bitstream, ipmbox_msg, sizeof (uint), BITSTREAM_READ); + bitstream_access (&bitstream, &type, 8); + bitstream_access (&bitstream, &msg_len, 4); + bitstream_access (&bitstream, &data_tx, 1); + bitstream_access (&bitstream, &data_ekc, 1); + bitstream_access (&bitstream, &data_type, 3); + bitstream_access (&bitstream, &data_length, 12); + bitstream_finalise (&bitstream); + + msg = (u8 *) ipmbox_msg[1]; + + test_begin (test, "Verify message posted in the IPMBOX") + { + test_fail_if (type != INTERFACE_SNIFFER, "Error on message type"); + test_fail_if (msg_len != 1, "Error on message length"); + test_fail_if (data_ekc != true, "Error on message encryption"); + test_fail_if (data_tx != false, "Error on message way"); + test_fail_if (data_type != 1, "Error on message data type"); + test_fail_if (data_length != 1500, "Error on message data length"); + + for (i = 0; i < data_length; i++) + { + test_fail_if (msg[i] != (u8)i, "Error, mme_copy at index %d is not equal to %d", i, (u8)i); + } + } + test_end; + + + test_case_begin (test, "Beacon SNIFF"); + + beacon = (pb_beacon_t *)blk_alloc_desc (); + memcpy (&beacon->first_data_word, mme, 4); + memcpy (beacon->data, mme, 136); + + interface_sniffer_copy_beacon_tx (sniffer, beacon, copy_mme, + 0x123456789abcull); + + bitstream_init (&bitstream, ipmbox_msg, sizeof (uint), BITSTREAM_READ); + bitstream_access (&bitstream, &type, 8); + bitstream_access (&bitstream, &msg_len, 4); + bitstream_access (&bitstream, &data_tx, 1); + bitstream_access (&bitstream, &data_ekc, 1); + bitstream_access (&bitstream, &data_type, 3); + bitstream_access (&bitstream, &data_length, 11); + bitstream_finalise (&bitstream); + + msg = (u8*)ipmbox_msg[1]; + bitstream_init (&bitstream, msg, 25, BITSTREAM_READ); + bitstream_access (&bitstream, &oda, 48); + bitstream_access (&bitstream, &osa, 48); + bitstream_access (&bitstream, &vlan, 32); + bitstream_access (&bitstream, &mtype, 16); + bitstream_access (&bitstream, &mmv, 8); + bitstream_access (&bitstream, &mmtype, 16); + bitstream_access (&bitstream, &module, 8); + bitstream_access (&bitstream, &mme_data_type, 8); + bitstream_access (&bitstream, &mme_data_length, 16); + bitstream_finalise (&bitstream); + + test_begin (test, "verify beacon data") + { + test_fail_if (oda != 0x123456789abcull, "Error on message ODA OSA"); + test_fail_if (osa != 0x123456789abcull, "Error on message ODA OSA"); + test_fail_if (vlan != 0, "Error on message vlan"); + test_fail_if (mtype != 0xE188 , "Error on MTYPE"); + test_fail_if (mmv != 0, "Error on message MMV"); + test_fail_if (mmtype != 0xA036, "Error on message MMTYPE"); + test_fail_if (mme_data_type != 0 , "Error on message data type"); + test_fail_if (mme_data_length != 160 , "Error on message data length"); + } + test_end; + + + test_begin (test, "verify beacon data") + { + test_fail_if (type != INTERFACE_SNIFFER, "Error on message type"); + test_fail_if (msg_len != 1, "Error on message length"); + test_fail_if (data_tx != true , "Error on message way"); + test_fail_if (data_ekc != false, "Error on message encryption"); + test_fail_if (data_type != 0, "Error on message data type"); + test_fail_if (data_length != 160 , "Error on message data length"); + + for (i = 25; i < data_length; i++) + { + test_fail_if (msg[i] != (u8)i, "Error, mme_copy at index %d is not equal to %d", i, (u8)i); + } + } + test_end; + + interface_sniffer_copy_beacon_rx (sniffer, beacon, copy_mme, + 0x123456789abcull); + + bitstream_init (&bitstream, ipmbox_msg, sizeof (uint), BITSTREAM_READ); + bitstream_access (&bitstream, &type, 8); + bitstream_access (&bitstream, &msg_len, 4); + bitstream_access (&bitstream, &data_tx, 1); + bitstream_access (&bitstream, &data_ekc, 1); + bitstream_access (&bitstream, &data_type, 3); + bitstream_access (&bitstream, &data_length, 11); + bitstream_finalise (&bitstream); + + test_begin (test, "verify beacon data") + { + test_fail_if (type != INTERFACE_SNIFFER, "Error on message type"); + test_fail_if (msg_len != 1, "Error on message length"); + test_fail_if (data_tx != false, "Error on message way"); + test_fail_if (data_ekc != false, "Error on message encryption"); + test_fail_if (data_type != 0, "Error on message data type"); + test_fail_if (data_length != 160 , "Error on message data length"); + + for (i = 25; i < data_length; i++) + { + test_fail_if (msg[i] != (u8)i, "Error, mme_copy at index %d is not equal to %d", i, (u8)i); + } + } + test_end; + + + test_result (test); + return test_nb_failed (test) == 0 ? 0 : 1; +} -- cgit v1.2.3