summaryrefslogtreecommitdiff
path: root/cesar/cp2/cl_interf
diff options
context:
space:
mode:
authorlaranjeiro2008-06-26 16:28:45 +0000
committerlaranjeiro2008-06-26 16:28:45 +0000
commit42818524d2caa8c82bf06a6a5b344771eeafe55a (patch)
treef73dee10acd6412207718bcccad37de2ee6e0fe6 /cesar/cp2/cl_interf
parentd4a6e2e05f6391712de8140abd1a43f333070841 (diff)
cp2/cl_interf: Fix the unit tests, add the cl_interf to the nightly builds.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2460 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/cl_interf')
-rw-r--r--cesar/cp2/cl_interf/src/cl_interf.c7
-rw-r--r--cesar/cp2/cl_interf/test/Makefile3
-rw-r--r--cesar/cp2/cl_interf/test/src/test-cl-interf.c88
3 files changed, 94 insertions, 4 deletions
diff --git a/cesar/cp2/cl_interf/src/cl_interf.c b/cesar/cp2/cl_interf/src/cl_interf.c
index ee80988d25..d7a3e3d5ae 100644
--- a/cesar/cp2/cl_interf/src/cl_interf.c
+++ b/cesar/cp2/cl_interf/src/cl_interf.c
@@ -108,7 +108,7 @@ cp_cl_interf_process_mme (cp_t *ctx)
msg = cyg_mbox_get (ctx->cl_interf.mailbox_handle);
dbg_check (msg);
- mme = cp_msg_mme_read_header (msg->buffer, msg->length,
+ mme = cp_msg_mme_read_header (ctx, msg->buffer, msg->length,
msg->mfs->common.tei, &fmi);
// MME is not formatted correctly.
@@ -159,7 +159,7 @@ cp_cl_interf_process_mme (cp_t *ctx)
// Release data.
if (msg->mfs)
blk_release (msg->mfs);
- blk_release (msg);
+ slab_release (msg);
}
/**
@@ -205,7 +205,8 @@ cp_cl_interf_mme_send (cp_t *ctx, cp_mme_tx_t * mme)
cp_sta_get_tei (sta_current));
// Provide it to the interface.
- interface_mme_send (ctx->interface, mme->p_mme, mme->full_len, mfs);
+ interface_mme_send (ctx->interface, mme->p_mme,
+ mme->length, mfs);
sta_next = cp_net_get_next_sta (net, sta_current);
blk_release (sta_current);
diff --git a/cesar/cp2/cl_interf/test/Makefile b/cesar/cp2/cl_interf/test/Makefile
index 42e29806f0..1589ec8770 100644
--- a/cesar/cp2/cl_interf/test/Makefile
+++ b/cesar/cp2/cl_interf/test/Makefile
@@ -5,6 +5,7 @@ ECOS = y
TARGET_PROGRAMS = test-cl-interf
test-cl-interf_SOURCES = test-cl-interf.c cl_stub.c
-test-cl-interf_MODULES = lib cp2/cl_interf cp2/sta/mgr mac/common cp2/msg
+test-cl-interf_MODULES = lib cp2/cl_interf cp2/sta/mgr mac/common \
+ cp2/secu
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp2/cl_interf/test/src/test-cl-interf.c b/cesar/cp2/cl_interf/test/src/test-cl-interf.c
index 62d8addbbf..2a73494b34 100644
--- a/cesar/cp2/cl_interf/test/src/test-cl-interf.c
+++ b/cesar/cp2/cl_interf/test/src/test-cl-interf.c
@@ -16,14 +16,17 @@
*/
#include "common/std.h"
#include "common/defs/homeplugAV.h"
+#include "common/defs/ethernet.h"
#include "lib/test.h"
#include "lib/swap.h"
+#include "lib/read_word.h"
#include "mac/common/store.h"
#include "cp2/cp.h"
#include "cp2/cl_interf/cl_interf.h"
+#include "cp2/msg/msg.h"
#include "cp2/inc/context.h"
#include "cp2/cl_interf/inc/context.h"
@@ -397,6 +400,90 @@ interface_mme_recv_done (interface_t *ctx, void *mme_recv)
}
/**
+ * Function to init the mme rx t messages.
+ * \param ctx the module context.
+ * \param mme the MME received.
+ * \param length the MME length.
+ * \param tei the source TEI.
+ * \return the mme rx message initialised.
+ */
+cp_mme_rx_t *
+cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei)
+{
+ cp_mme_rx_t *mme_rx;
+
+ dbg_assert (ctx);
+ dbg_assert (mme);
+ dbg_assert (length >= ETH_PACKET_MIN_SIZE
+ && length <= ETH_PACKET_MAX_SIZE);
+
+ // Allocate the MME with the slab allocator.
+ mme_rx = slab_alloc (&ctx->msg.mme_rx_slab_cache);
+
+ dbg_assert (mme_rx);
+ memset (mme_rx, 0, sizeof (cp_mme_rx_t));
+ mme_rx->p_mme = mme;
+ mme_rx->length = length;
+ mme_rx->peer.tei = tei;
+ mme_rx->cp = ctx;
+
+ return mme_rx;
+}
+
+/**
+ * Read the header of a received MME and return the MME context.
+ * \param ctx the module 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, uint length, cp_tei_t tei,
+ uint *fmi)
+{
+ cp_mme_rx_t *mme_rx;
+ bool vlantag_present;
+ uint mtype;
+ uint mmv;
+
+ dbg_assert (ctx);
+ dbg_assert (mme);
+
+ if (read_u16_from_word (mme + 12) == swap16 (HPAV_MTYPE_MME))
+ vlantag_present = false;
+ else
+ vlantag_present = true;
+
+ mme_rx = cp_msg_mme_rx_init (ctx, mme, length, 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))
+ {
+ slab_release (mme_rx);
+ mme_rx = NULL;
+ }
+
+ return mme_rx;
+}
+
+
+/**
* Examine message type and post an event to the FSM.
* \param ctx control plane context
* \param mme received MME
@@ -411,3 +498,4 @@ cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme)
{
dispatch_mme_rx = mme;
}
+