summaryrefslogtreecommitdiff
path: root/cesar/cp2/msg
diff options
context:
space:
mode:
authorlaranjeiro2008-06-11 13:24:55 +0000
committerlaranjeiro2008-06-11 13:24:55 +0000
commit5d991fc1ceeffda433661529913e265a4d5cd887 (patch)
treefbe4f69375c815bf4e46d7b383b30971fb274849 /cesar/cp2/msg
parent1868b7c506071efb98dd3d3e95d5ce44f886015c (diff)
cp2/msg: Tested the Msg read header function.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2282 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/msg')
-rw-r--r--cesar/cp2/msg/Module2
-rw-r--r--cesar/cp2/msg/msg.h7
-rw-r--r--cesar/cp2/msg/src/msg.c76
-rw-r--r--cesar/cp2/msg/test/Makefile8
-rw-r--r--cesar/cp2/msg/test/doc/Makefile20
-rw-r--r--cesar/cp2/msg/test/doc/read-header.txt69
-rw-r--r--cesar/cp2/msg/test/src/test-msg-read-header.c178
-rw-r--r--cesar/cp2/msg/test/utest/Makefile7
-rw-r--r--cesar/cp2/msg/test/utest/src/test_msg.c28
9 files changed, 357 insertions, 38 deletions
diff --git a/cesar/cp2/msg/Module b/cesar/cp2/msg/Module
index b7aa509ead..fad069366c 100644
--- a/cesar/cp2/msg/Module
+++ b/cesar/cp2/msg/Module
@@ -1 +1 @@
-SOURCES :=
+SOURCES := msg.c
diff --git a/cesar/cp2/msg/msg.h b/cesar/cp2/msg/msg.h
index bf1d4f4c3f..4d1e6412a9 100644
--- a/cesar/cp2/msg/msg.h
+++ b/cesar/cp2/msg/msg.h
@@ -95,12 +95,15 @@ cp_msg_mme_send (cp_t *ctx, cp_mme_tx_t *mme);
/**
* Read the header of a received MME and return the MME context.
- * \param ctx control plane context.
* \param mme the MME received.
+ * \param length the MME length.
+ * \param tei the source TEI (0xFF if coming from the HLE).
+ * \param fmi the FMI data.
* \return cp_mme_rx_t object associated.
*/
cp_mme_rx_t *
-cp_msg_mme_read_header (cp_t *ctx, u8 *mme);
+cp_msg_mme_read_header (u8 *mme, uint length, cp_tei_t tei,
+ uint *fmi);
END_DECLS
diff --git a/cesar/cp2/msg/src/msg.c b/cesar/cp2/msg/src/msg.c
new file mode 100644
index 0000000000..2e3aa70446
--- /dev/null
+++ b/cesar/cp2/msg/src/msg.c
@@ -0,0 +1,76 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp2/msg/src/msg.c
+ * \brief MSG functions.
+ * \ingroup cp2_msg
+ *
+ */
+#include "common/std.h"
+#include "lib/read_word.h"
+#include "lib/swap.h"
+
+#include "common/defs/homeplugAV.h"
+#include "common/defs/ethernet.h"
+
+#include "cp2/cp.h"
+#include "cp2/msg/msg.h"
+
+/**
+ * Read the header of a received MME and return the MME context.
+ * \param mme the MME received.
+ * \param length the MME length.
+ * \param tei the source TEI (0xFF if coming from the HLE).
+ * \param fmi the FMI data.
+ * \return cp_mme_rx_t object associated.
+ */
+cp_mme_rx_t *
+cp_msg_mme_read_header (u8 *mme, uint length, cp_tei_t tei,
+ uint *fmi)
+{
+ cp_mme_rx_t *mme_rx;
+ bool vlantag_present;
+ uint mtype;
+ uint mmv;
+
+ dbg_assert (mme);
+
+ if (read_u16_from_word (mme + 12) == swap16 (HPAV_MTYPE_MME))
+ vlantag_present = false;
+ else
+ vlantag_present = true;
+
+ mme_rx = blk_alloc ();
+ mme_rx->p_mme = mme;
+ mme_rx->length = length;
+ mme_rx->peer.tei = tei;
+
+ bitstream_init (&mme_rx->bitstream, mme + ETH_MAC_ADDRESS_SIZE,
+ length, BITSTREAM_READ);
+ bitstream_access (&mme_rx->bitstream, &mme_rx->peer.mac,
+ BYTES_SIZE_TO_BITS(ETH_MAC_ADDRESS_SIZE));
+ if (vlantag_present)
+ bitstream_access (&mme_rx->bitstream, &mme_rx->peer.vlan_tag, 32);
+ else
+ mme_rx->peer.vlan_tag = 0;
+
+ bitstream_access (&mme_rx->bitstream, &mtype, 16);
+ bitstream_access (&mme_rx->bitstream, &mmv, 8);
+ bitstream_access (&mme_rx->bitstream, &mme_rx->mmtype, 16);
+ bitstream_access (&mme_rx->bitstream, fmi, 16);
+
+ // Verify some data.
+ if ((mmv != HPAV_MMV1) || (swap16(mtype) != HPAV_MTYPE_MME))
+ {
+ blk_release (mme_rx);
+ mme_rx = NULL;
+ }
+
+ return mme_rx;
+}
+
diff --git a/cesar/cp2/msg/test/Makefile b/cesar/cp2/msg/test/Makefile
new file mode 100644
index 0000000000..d052661e53
--- /dev/null
+++ b/cesar/cp2/msg/test/Makefile
@@ -0,0 +1,8 @@
+BASE = ../../..
+
+HOST_PROGRAMS = test-msg-read-header
+
+test-msg-read-header_SOURCES = test-msg-read-header.c
+test-msg-read-header_MODULES = lib cp2/msg
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/cp2/msg/test/doc/Makefile b/cesar/cp2/msg/test/doc/Makefile
new file mode 100644
index 0000000000..50006394a5
--- /dev/null
+++ b/cesar/cp2/msg/test/doc/Makefile
@@ -0,0 +1,20 @@
+PAGES = read-header.txt
+
+ODT=$(PAGES:%.txt=%.odt)
+HTML=$(PAGES:%.txt=%.html)
+
+all: $(ODT) $(HTML)
+
+odt: $(ODT)
+
+html: $(HTML)
+
+%.odt: %.txt
+ rst2odt.py $< $@
+
+%.html: %.txt
+ rst2html $< $@
+
+clean:
+ rm -f $(ODT)
+ rm -f $(HTML)
diff --git a/cesar/cp2/msg/test/doc/read-header.txt b/cesar/cp2/msg/test/doc/read-header.txt
new file mode 100644
index 0000000000..482609d42b
--- /dev/null
+++ b/cesar/cp2/msg/test/doc/read-header.txt
@@ -0,0 +1,69 @@
+MSG read MME header
+===================
+
+ MME used for the test with :
+
+* a length of 92 bytes.
+* TEI = 1
+
++-------+-------------------+-----------------+
+|Name | Value | length (bytes) |
++-------+-------------------+-----------------+
+|oda | 12:34:56:78:9A:BC | 6 |
++-------+-------------------+-----------------+
+|osa | 34:56:78:9A:BC:DE | 6 |
++-------+-------------------+-----------------+
+|[vlan] | 0x12 | 4 |
++-------+-------------------+-----------------+
+|Mtype | 0x88E1 | 2 |
++-------+-------------------+-----------------+
+|MMV | 0x1 | 1 |
++-------+-------------------+-----------------+
+|MMTYPE | 0x3245 | 2 |
++-------+-------------------+-----------------+
+|FMI | 0x432 | 2 |
++-------+-------------------+-----------------+
+
+Test 1 : Read a MME with a VLAN tag.
+------------------------------------
+
+The result shall be the following one.
+
+The MME rx object returned shall not be NULL and shall contain:
+
+* p_mme = buffer address containing the MME.
+* mmtype = 0x3245
+* length = 92.
+* peer
+
+ * mac = 34:56:78:9A:BC:DE
+ * vlan = 0x12
+ * tei = 1 (provided in argument).
+ * all_sta = false.
+
+Test 2 : Read a MME without a VLAN tag.
+---------------------------------------
+
+The result shall be the following one.
+
+The MME rx object returned shall not be NULL and shall contain:
+
+* p_mme = buffer address containing the MME.
+* mmtype = 0x3245
+* length = 92.
+* peer
+
+ * mac = 34:56:78:9A:BC:DE
+ * vlan = 0
+ * tei = 1 (provided in argument).
+ * all_sta = false.
+
+Test 3 : Read a MME with the MMV equal to 0
+-------------------------------------------
+
+The returned value shall be NULL.
+
+Test 4 : Read the MME with MType different of 0x88E1
+----------------------------------------------------
+
+The returned value shall be NULL.
diff --git a/cesar/cp2/msg/test/src/test-msg-read-header.c b/cesar/cp2/msg/test/src/test-msg-read-header.c
new file mode 100644
index 0000000000..88d6ecba63
--- /dev/null
+++ b/cesar/cp2/msg/test/src/test-msg-read-header.c
@@ -0,0 +1,178 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file test/src/test-msg.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * http://pessac/cesar/trac/wiki/UT-CPM1-MSG-MSG
+ */
+#include "common/std.h"
+#include "common/defs/homeplugAV.h"
+
+#include "lib/bitstream.h"
+#include "lib/test.h"
+#include "lib/swap.h"
+
+#include "cp2/cp.h"
+#include "cp2/msg/msg.h"
+
+/**
+ * Test the msg_read header function with a MME containing a VLAN Tag.
+ * \param test the test object.
+ */
+void
+test_case_msg_read_header_mme_without_vlan (test_t test)
+{
+ bitstream_t bitstream;
+ u8 buffer[256] __attribute__((aligned(256)));
+ uint fmi;
+ cp_mme_rx_t *mme;
+
+ u64 data;
+
+ test_case_begin (test, "TEST 1");
+
+ bitstream_init (&bitstream, buffer, 23, BITSTREAM_WRITE);
+ data = 0x123456789ABCull;
+ bitstream_access (&bitstream, &data, 48);
+ data = 0x3456789ABCDEull;
+ bitstream_access (&bitstream, &data, 48);
+ data = 0x12;
+ bitstream_access (&bitstream, &data, 32);
+ data = swap16(HPAV_MTYPE_MME);
+ bitstream_access (&bitstream, &data, 16);
+ data = 1;
+ bitstream_access (&bitstream, &data, 8);
+ data = 0x3245;
+ bitstream_access (&bitstream, &data, 16);
+ data = 0x432;
+ bitstream_access (&bitstream, &data, 16);
+ bitstream_finalise (&bitstream);
+
+ mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+
+ test_begin (test, "Read a MME with vlan")
+ {
+ test_fail_if (mme->p_mme != buffer, "Wrong buffer address");
+ test_fail_if (mme->length != 92, "Wrong length");
+ test_fail_if (mme->mmtype != 0x3245, "Wrong MMTYPE");
+ test_fail_if (mme->peer.mac != 0x3456789ABCDEull,
+ "Wrong mac address");
+ test_fail_if (mme->peer.tei != 1, "wrong TEI");
+ test_fail_if (mme->peer.vlan_tag != 0x12, "Wrong VLAN tag");
+ test_fail_if (mme->peer.all_sta != false, "all_sta shall be false");
+ test_fail_if (fmi != 0x432, "wrong FMI value");
+ }
+ test_end;
+ blk_release (mme);
+
+ test_case_begin (test, "TEST 2");
+
+ bitstream_init (&bitstream, buffer, 19, BITSTREAM_WRITE);
+ data = 0x123456789ABCull;
+ bitstream_access (&bitstream, &data, 48);
+ data = 0x3456789ABCDEull;
+ bitstream_access (&bitstream, &data, 48);
+ data = swap16(HPAV_MTYPE_MME);
+ bitstream_access (&bitstream, &data, 16);
+ data = 1;
+ bitstream_access (&bitstream, &data, 8);
+ data = 0x3245;
+ bitstream_access (&bitstream, &data, 16);
+ data = 0x432;
+ bitstream_access (&bitstream, &data, 16);
+ bitstream_finalise (&bitstream);
+
+ mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+
+ test_begin (test, "Read a MME without vlan")
+ {
+ test_fail_if (mme->p_mme != buffer, "Wrong buffer address");
+ test_fail_if (mme->length != 92, "Wrong length");
+ test_fail_if (mme->mmtype != 0x3245, "Wrong MMTYPE");
+ test_fail_if (mme->peer.mac != 0x3456789ABCDEull,
+ "Wrong mac address");
+ test_fail_if (mme->peer.tei != 1, "wrong TEI");
+ test_fail_if (mme->peer.vlan_tag != 0, "Wrong VLAN tag");
+ test_fail_if (mme->peer.all_sta != false, "all_sta shall be false");
+ test_fail_if (fmi != 0x432, "wrong FMI value");
+ }
+ test_end;
+ blk_release (mme);
+
+ test_case_begin (test, "TEST 3");
+
+ bitstream_init (&bitstream, buffer, 23, BITSTREAM_WRITE);
+ data = 0x123456789ABCull;
+ bitstream_access (&bitstream, &data, 48);
+ data = 0x3456789ABCDEull;
+ bitstream_access (&bitstream, &data, 48);
+ data = swap16(HPAV_MTYPE_MME);
+ bitstream_access (&bitstream, &data, 16);
+ data = 0;
+ bitstream_access (&bitstream, &data, 8);
+ data = 0x3245;
+ bitstream_access (&bitstream, &data, 16);
+ data = 0x432;
+ bitstream_access (&bitstream, &data, 16);
+ bitstream_finalise (&bitstream);
+
+ mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+
+ test_begin (test, "Read a MME without vlan")
+ {
+ test_fail_if (mme != NULL, "Shall be null");
+ }
+ test_end;
+
+ test_case_begin (test, "TEST 4");
+
+ bitstream_init (&bitstream, buffer, 23, BITSTREAM_WRITE);
+ data = 0x123456789ABCull;
+ bitstream_access (&bitstream, &data, 48);
+ data = 0x3456789ABCDEull;
+ bitstream_access (&bitstream, &data, 48);
+ data = swap16(HPAV_MTYPE_MME + 1);
+ bitstream_access (&bitstream, &data, 16);
+ data = 1;
+ bitstream_access (&bitstream, &data, 8);
+ data = 0x3245;
+ bitstream_access (&bitstream, &data, 16);
+ data = 0x432;
+ bitstream_access (&bitstream, &data, 16);
+ bitstream_finalise (&bitstream);
+
+ mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+
+ test_begin (test, "Read a MME without vlan")
+ {
+ test_fail_if (mme != NULL, "Shall be null");
+ }
+ test_end;
+}
+
+int
+main (void)
+{
+ test_t test;
+ test_init (test, 0, NULL);
+
+ test_case_msg_read_header_mme_without_vlan (test);
+
+ test_case_begin (test, "Memory allocation");
+ test_begin (test, "memory leaks")
+ {
+ test_fail_if (blk_check_memory () != true, "Memory leaks");
+ }
+ test_end;
+
+ test_result (test);
+// HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}
diff --git a/cesar/cp2/msg/test/utest/Makefile b/cesar/cp2/msg/test/utest/Makefile
deleted file mode 100644
index 9bd73cb5d6..0000000000
--- a/cesar/cp2/msg/test/utest/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-BASE = ../../../..
-
-HOST_PROGRAMS = test_msg
-test_msg_SOURCES = test_msg.c
-test_msg_MODULES = lib cp2/msg
-
-include $(BASE)/common/make/top.mk
diff --git a/cesar/cp2/msg/test/utest/src/test_msg.c b/cesar/cp2/msg/test/utest/src/test_msg.c
deleted file mode 100644
index 63018c27b0..0000000000
--- a/cesar/cp2/msg/test/utest/src/test_msg.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file src/test_msg.c
- * \brief Test msg module.
- * \ingroup test
- */
-#include "common/std.h"
-
-#include "lib/test.h"
-
-/* For the moment, only test headers compilation. */
-#include "cp2/msg/msg.h"
-
-int
-main (int argc, char **argv)
-{
- test_t t;
- test_init (t, argc, argv);
- test_result (t);
- return test_nb_failed (t) == 0 ? 0 : 1;
-}
-