summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/stub/libmme
diff options
context:
space:
mode:
authorCeline Buret2009-12-24 16:44:46 +0100
committerCeline Buret2009-12-24 16:44:46 +0100
commit35a21ba6a0683bca9cfb46e7d900cb6c491a3ffd (patch)
treec1be30086a4e9a0da72a218dee3f9bedbdf5cdfe /cleopatre/devkit/tests/stub/libmme
parent9da19d641a857668ef37361db9dca63d91926bce (diff)
cleo/appli/eoc/online[eoc]: clean code and makefile
cleo/appli/libspid[eoc]: adapt makefile cle/appli/libmme[eoc]: adapt makefile cleo/devkit/tests/online[eoc]: clean and re-organize cleo/devkit/tests/stub[eoc]: create Refs #812. Clean online daemon code. Remove useless include files.Rename functions and defines. Big clean in unitary tests. Creation of a stub directory, which needs to be more generic. Big clean in functional tests makefiles.
Diffstat (limited to 'cleopatre/devkit/tests/stub/libmme')
-rw-r--r--cleopatre/devkit/tests/stub/libmme/src/mme.c326
1 files changed, 326 insertions, 0 deletions
diff --git a/cleopatre/devkit/tests/stub/libmme/src/mme.c b/cleopatre/devkit/tests/stub/libmme/src/mme.c
new file mode 100644
index 0000000000..8282fa4ff2
--- /dev/null
+++ b/cleopatre/devkit/tests/stub/libmme/src/mme.c
@@ -0,0 +1,326 @@
+/* Cleopatre-EoC project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/stub/libmme/src/mme.c
+ * \brief Stub functions for some libmme functions used in online daemon
+ * \ingroup cleopatre - libmme
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <linux/if_ether.h>
+
+#include "libmme.h"
+
+/**
+ * Pull (get) data from beginning of MME payload. MME data head and length are updated
+ * If there is not enough data to pull, an error is returned and the remaining payload length is returned.
+ *
+ * \param ctx MME context where to get data
+ * \param data buffer where to get data from the beginning of MME payload
+ * \param length length of data to pull
+ * \param result_length length of data pulled; if there is not enough data into the MME to fit the length, the remaining data length is returned
+ * \return error type (MME_SUCCESS if success)
+ * \return MME_ERROR_NOT_INIT: context not initialized
+ */
+mme_error_t mme_pull (mme_ctx_t *ctx, void *data, unsigned int length, unsigned int *result_length)
+{
+ /* protect from null pointers */
+ if (ctx == NULL || data == NULL || result_length == NULL)
+ return MME_ERROR_GEN;
+ /* check if ctx has been inititalized */
+ if (ctx->status == MME_STATUS_INIT)
+ return MME_ERROR_NOT_INIT;
+
+ /* check if it is demanded more data than we have in payload */
+ if (length > ctx->tail - ctx->head)
+ {
+ *result_length = ctx->tail - ctx->head;
+ return MME_ERROR_ENOUGH;
+ }
+
+ *result_length = length;
+
+ memcpy(data, (unsigned char *)(ctx->buffer + ctx->head), length);
+
+ ctx->head += length;
+
+ return MME_SUCCESS;
+}
+
+
+/**
+ * Create a MME message context. This context is used to build the MME message step by step.
+ * The provided buffer must be enough large to contain all the final payload.
+ * The MME payload can be bigger than an ethernet payload, as the fragmentation is managed by the 'send' function.
+ *
+ * \param ctx MME context to fill with init value
+ * \param mmtype type of MME message (must be in official type list)
+ * \param buffer the buffer to put the payload
+ * \param length the buffer length
+ * \return error type (MME_SUCCESS if success)
+ */
+mme_error_t mme_init (mme_ctx_t *ctx, const mme_type_t mmtype, unsigned char *buffer, const unsigned int length)
+{
+ /* protect from null pointers */
+ if (ctx == NULL || buffer == NULL)
+ return MME_ERROR_GEN;
+
+ ctx->buffer = buffer;
+ ctx->mmtype = mmtype;
+ ctx->length = length;
+ ctx->head = 0;
+ ctx->tail = 0;
+
+ ctx->status = MME_STATUS_OK;
+
+ return MME_SUCCESS;
+}
+
+
+/**
+ * Send fake MME by filling buffer: confirm_ctx->buffer
+ *
+ * \param ctx MME context to send
+ * \param type transaction type
+ * \param iface selected communication interface
+ * \param dest destination MAC address in binary format (6 bytes)
+ * \param confirm_ctx MME context given to put the received MME answer packet. A adapted buffer must have been provided.
+ * \return error type (MME_SUCCESS if success)
+ * \return MME_ERROR_NOT_INIT: context not initialized
+ */
+mme_error_t mme_send (mme_ctx_t *ctx, mme_send_type_t type, unsigned char *iface, unsigned char *dest, mme_ctx_t *confirm_ctx)
+{
+ static int test_number = 0;
+ static int iteration_number = -1;
+ char increase_iter_num = 0;
+ unsigned char mac[6] = {0xAA, 0xBB, 0xCC, 0x12, 0x34, 0x56};
+ unsigned char mac1[6] = {0xDD, 0xEE, 0xFF, 0x78, 0x90, 0x99};
+ unsigned char mac2[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
+ unsigned char model_number[64] = "SPiDCOMmodem1";
+ unsigned char software_version[64] = "eoc-alpha0-1";
+ unsigned char wrong_model_number[64] = "WrongModelNumber";
+ unsigned char wrong_software_version[64] = "WrongSWVersion";
+
+ /* protect from null pointers */
+ if (ctx == NULL || confirm_ctx == NULL ||iface == NULL || dest == NULL)
+ return MME_ERROR_GEN;
+
+ /* check if ctx has been inititalized */
+ if (ctx->status == MME_STATUS_INIT)
+ return MME_ERROR_NOT_INIT;
+
+ /* get_device_info function test */
+ if ((test_number == 0) && (iteration_number == -1) && (ctx->mmtype == (MME_TYPE_VS_EOC_GET_DEVICE_INFO | MME_TYPE_REQ)))
+ {
+ test_number = 4;
+ }
+
+ /* get_link_info function test */
+ if ((test_number == 0) && (iteration_number == -1) && (ctx->mmtype == (MME_TYPE_CM_NW_STATS | MME_TYPE_REQ)))
+ {
+ test_number = 5;
+ }
+
+ /* VS_EOC_GET_TOPO - all correct fields has correct value */
+ if ((test_number == 0) && (iteration_number == -1))
+ {
+ confirm_ctx->buffer[0] = 0x00; /* result */
+ confirm_ctx->buffer[1] = 0x03; /* number of STAs */
+ memcpy(confirm_ctx->buffer + 2, mac, 6); /* MAC address of STA0 */
+ confirm_ctx->buffer[8] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[9] = 0x14; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 10, mac1, 6); /* MAC address of STA1 */
+ confirm_ctx->buffer[16] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[17] = 0x09; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 18, mac2, 6); /* MAC address of STA2 */
+ confirm_ctx->buffer[24] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[25] = 0x05; /* STA-CCo attenuation */
+ }
+
+ /* CM_NW_STATS - all correct fields has correct value */
+ if ((test_number == 0) && (iteration_number == 0))
+ {
+ confirm_ctx->buffer[0] = 0x03; /* number of STAs */
+ memcpy(confirm_ctx->buffer + 1, mac, 6); /* MAC address of STA0 */
+ confirm_ctx->buffer[7] = 0x32; /* Tx average PHY data rate for STA0 */
+ confirm_ctx->buffer[8] = 0x33; /* Rx average PHY data rate for STA0 */
+ memcpy(confirm_ctx->buffer + 9, mac1, 6); /* MAC address of STA1 */
+ confirm_ctx->buffer[15] = 0x34; /* Tx average PHY data rate for STA1 */
+ confirm_ctx->buffer[16] = 0x35; /* Rx average PHY data rate for STA1 */
+ memcpy(confirm_ctx->buffer + 17, mac2, 6); /* MAC address of STA2 */
+ confirm_ctx->buffer[23] = 0x36; /* Tx average PHY data rate for STA2 */
+ confirm_ctx->buffer[24] = 0x37; /* Rx average PHY data rate for STA2 */
+
+ increase_iter_num = 1;
+ }
+
+ /* VS_EOC_GET_DEVICE_INFO with correct parameters and result */
+ if ((test_number == 0) && (iteration_number == 1))
+ {
+ confirm_ctx->buffer[0] = 0x00; /* result */
+ memcpy(confirm_ctx->buffer + 1, model_number, 64); /* model_number */
+ memcpy(confirm_ctx->buffer + 65, software_version, 64); /* software_version */
+ confirm_ctx->buffer[129] = 0x0A; /* downstream_attenuation */
+ confirm_ctx->buffer[130] = 0x04; /* port amount */
+
+ increase_iter_num = 1;
+ }
+
+ /* VS_EOC_GET_DEVICE_INFO with incorrect parameters and result */
+ if ((test_number == 0) && (iteration_number == 2))
+ {
+ confirm_ctx->buffer[0] = 0x01; /* result */
+ memcpy(confirm_ctx->buffer + 1, wrong_model_number, 64); /* model_number */
+ memcpy(confirm_ctx->buffer + 65, wrong_software_version, 64); /* software_version */
+ confirm_ctx->buffer[129] = 0; /* downstream_attenuation */
+ confirm_ctx->buffer[130] = 0; /* port amount */
+
+ increase_iter_num = 1;
+ }
+
+ /* VS_EOC_GET_DEVICE_INFO with correct parameters and wrong result */
+ if ((test_number == 0) && (iteration_number == 3))
+ {
+
+ confirm_ctx->buffer[0] = 0x01; /* result */
+ memcpy(confirm_ctx->buffer + 1, model_number, 64); /* model_number */
+ memcpy(confirm_ctx->buffer + 65, software_version, 64); /* software_version */
+ confirm_ctx->buffer[129] = 0x0A; /* downstream_attenuation */
+ confirm_ctx->buffer[130] = 0x04; /* port amount */
+
+ increase_iter_num = 1;
+ }
+
+ /* VS_EOC_GET_TOPO - wrong result */
+ if ((test_number == 1) && (iteration_number == -1))
+ {
+ confirm_ctx->buffer[0] = 0x01; /* result */
+ confirm_ctx->buffer[1] = 0x03; /* number of STAs */
+ memcpy(confirm_ctx->buffer + 2, mac, 6); /* MAC address of STA0 */
+ confirm_ctx->buffer[8] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[9] = 0x14; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 10, mac1, 6); /* MAC address of STA1 */
+ confirm_ctx->buffer[16] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[17] = 0x09; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 18, mac2, 6); /* MAC address of STA2 */
+ confirm_ctx->buffer[24] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[25] = 0x05; /* STA-CCo attenuation */
+
+ /* quit the test VS_EOC_GET_DEVICE_INFO will not be tested */
+ iteration_number = 3;
+ increase_iter_num = 1;
+ }
+
+ /* VS_EOC_GET_TOPO - number of STAs is smaller than received data */
+ if ((test_number == 2) && (iteration_number == -1))
+ {
+ confirm_ctx->buffer[0] = 0x00; /* result */
+ confirm_ctx->buffer[1] = 0x01; /* number of STAs */
+ memcpy(confirm_ctx->buffer + 2, mac, 6); /* MAC address of STA0 */
+ confirm_ctx->buffer[8] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[9] = 0x14; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 10, mac1, 6); /* MAC address of STA1 */
+ confirm_ctx->buffer[16] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[17] = 0x09; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 18, mac2, 6); /* MAC address of STA2 */
+ confirm_ctx->buffer[24] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[25] = 0x05; /* STA-CCo attenuation */
+
+ iteration_number = 3;
+ increase_iter_num = 1;
+ }
+
+ /* VS_EOC_GET_TOPO - number of STAs is greater than received data */
+ if ((test_number == 3) && (iteration_number == -1))
+ {
+ confirm_ctx->buffer[0] = 0x00; /* result */
+ confirm_ctx->buffer[1] = 0x05; /* number of STAs */
+ memcpy(confirm_ctx->buffer + 2, mac, 6); /* MAC address of STA0 */
+ confirm_ctx->buffer[8] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[9] = 0x14; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 10, mac1, 6); /* MAC address of STA1 */
+ confirm_ctx->buffer[16] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[17] = 0x09; /* STA-CCo attenuation */
+ memcpy(confirm_ctx->buffer + 18, mac2, 6); /* MAC address of STA2 */
+ confirm_ctx->buffer[24] = 0x01; /* STA allowed / not allowed */
+ confirm_ctx->buffer[25] = 0x05; /* STA-CCo attenuation */
+ }
+
+ /* CM_NW_STATS - all correct fields has correct value */
+ if ((test_number == 3) && (iteration_number == 0))
+ {
+ confirm_ctx->buffer[0] = 0x03; /* number of STAs */
+ memcpy(confirm_ctx->buffer + 1, mac, 6); /* MAC address of STA0 */
+ confirm_ctx->buffer[7] = 0x32; /* Tx average PHY data rate for STA0 */
+ confirm_ctx->buffer[8] = 0x33; /* Rx average PHY data rate for STA0 */
+ memcpy(confirm_ctx->buffer + 9, mac1, 6); /* MAC address of STA1 */
+ confirm_ctx->buffer[15] = 0x34; /* Tx average PHY data rate for STA1 */
+ confirm_ctx->buffer[16] = 0x35; /* Rx average PHY data rate for STA1 */
+ memcpy(confirm_ctx->buffer + 17, mac2, 6); /* MAC address of STA2 */
+ confirm_ctx->buffer[23] = 0x36; /* Tx average PHY data rate for STA2 */
+ confirm_ctx->buffer[24] = 0x37; /* Rx average PHY data rate for STA2 */
+
+ iteration_number = 3;
+ increase_iter_num = 1;
+ }
+
+ /* VS_EOC_GET_DEVICE_INFO - all correct fields has correct value */
+ if ((test_number == 4) && (iteration_number == -1))
+ {
+ confirm_ctx->buffer[0] = 0x00; /* result */
+ memcpy(confirm_ctx->buffer + 1, model_number, 64); /* model_number */
+ memcpy(confirm_ctx->buffer + 65, software_version, 64); /* software_version */
+ confirm_ctx->buffer[129] = 0x0A; /* downstream_attenuation */
+ confirm_ctx->buffer[130] = 0x04; /* port amount */
+
+ /* quit the test */
+ iteration_number = 3;
+ increase_iter_num = 1;
+ }
+
+ /* CM_NW_STATS - correct parameters, correct result */
+ if ((test_number == 5) && (iteration_number == -1))
+ {
+ confirm_ctx->buffer[0] = 0x03; /* number of STAs */
+ memcpy(confirm_ctx->buffer + 1, mac, 6); /* MAC address of STA0 */
+ confirm_ctx->buffer[7] = 0x1E; /* Tx average PHY data rate for STA0 */
+ confirm_ctx->buffer[8] = 0x28; /* Rx average PHY data rate for STA0 */
+ memcpy(confirm_ctx->buffer + 9, mac1, 6); /* MAC address of STA1 */
+ confirm_ctx->buffer[15] = 0x1E; /* Tx average PHY data rate for STA1 */
+ confirm_ctx->buffer[16] = 0x28; /* Rx average PHY data rate for STA1 */
+ memcpy(confirm_ctx->buffer + 17, mac2, 6); /* MAC address of STA2 */
+ confirm_ctx->buffer[23] = 0x1E; /* Tx average PHY data rate for STA2 */
+ confirm_ctx->buffer[24] = 0x28; /* Rx average PHY data rate for STA2 */
+
+ /* quit the test */
+ iteration_number = 3;
+ increase_iter_num = 1;
+ }
+
+ confirm_ctx->tail = ETH_DATA_LEN;
+
+ if (increase_iter_num == 1)
+ {
+ iteration_number++;
+ increase_iter_num = 0;
+ }
+
+ if (iteration_number == -1)
+ {
+ iteration_number = 0;
+ }
+
+ if (iteration_number == 4)
+ {
+ test_number++;
+ iteration_number = -1;
+ }
+
+ return MME_SUCCESS;
+}