summaryrefslogtreecommitdiff
path: root/cesar/cp2/msg
diff options
context:
space:
mode:
authorlaranjeiro2008-06-23 15:34:43 +0000
committerlaranjeiro2008-06-23 15:34:43 +0000
commit813d26bfc115e78a9a878e078e04717bb0b28d9f (patch)
treec8f594882b401e6701cc3535b1cc58be8dbd054a /cesar/cp2/msg
parent8fad2c0754e549328ba986eaf23191b2b146dcc8 (diff)
cp2/msg: Wrote and tested the MSG functions.
* Tested the mme_tx_init * Tested the mme_tx_init_encrpypted * Replace the blk allocation for the mme_rx_t and mme_tx_t by slab allocations. * Add function to initialise the mme_rx_t and mme_tx_t objects. * Added the destructors for mme_rx_t and mme_tx_t. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2413 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/msg')
-rw-r--r--cesar/cp2/msg/Module2
-rw-r--r--cesar/cp2/msg/inc/context.h28
-rw-r--r--cesar/cp2/msg/inc/msg.h52
-rw-r--r--cesar/cp2/msg/msg.h18
-rw-r--r--cesar/cp2/msg/src/mme.c108
-rw-r--r--cesar/cp2/msg/src/msg.c253
-rw-r--r--cesar/cp2/msg/test/Makefile11
-rw-r--r--cesar/cp2/msg/test/overide/cp2/inc/context.h34
-rw-r--r--cesar/cp2/msg/test/src/cp_cl_interface_stub.c32
-rw-r--r--cesar/cp2/msg/test/src/interface_stub.c27
-rw-r--r--cesar/cp2/msg/test/src/sta_mgr_stub.c44
-rw-r--r--cesar/cp2/msg/test/src/test-msg-read-header.c20
-rw-r--r--cesar/cp2/msg/test/src/test-msg.c229
13 files changed, 839 insertions, 19 deletions
diff --git a/cesar/cp2/msg/Module b/cesar/cp2/msg/Module
index fad069366c..e8dc3bae01 100644
--- a/cesar/cp2/msg/Module
+++ b/cesar/cp2/msg/Module
@@ -1 +1 @@
-SOURCES := msg.c
+SOURCES := msg.c mme.c
diff --git a/cesar/cp2/msg/inc/context.h b/cesar/cp2/msg/inc/context.h
new file mode 100644
index 0000000000..2e77e61552
--- /dev/null
+++ b/cesar/cp2/msg/inc/context.h
@@ -0,0 +1,28 @@
+#ifndef cp2_msg_inc_context_h
+#define cp2_msg_inc_context_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp2/msg/inc/msg.h
+ * \brief MSG context.
+ * \ingroup cp2_msg
+ *
+ */
+#include "lib/slab.h"
+
+/** Message context. */
+struct cp_msg_t
+{
+ /** Slab cache for the MME TX. */
+ slab_cache_t mme_tx_slab_cache;
+ /** Slab cache for the MME RX. */
+ slab_cache_t mme_rx_slab_cache;
+};
+typedef struct cp_msg_t cp_msg_t;
+
+#endif /* cp2_msg_inc_context_h */
diff --git a/cesar/cp2/msg/inc/msg.h b/cesar/cp2/msg/inc/msg.h
new file mode 100644
index 0000000000..b95e7fea74
--- /dev/null
+++ b/cesar/cp2/msg/inc/msg.h
@@ -0,0 +1,52 @@
+#ifndef cp2_msg_inc_msg_h
+#define cp2_msg_inc_msg_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp2/msg/inc/msg.h
+ * \brief Private function headers.
+ * \ingroup cp2_msg
+ */
+#include "cp2/mme.h"
+
+/**
+ * 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);
+
+/**
+ * Function to init the mme rx t messages.
+ * \param ctx the module context.
+ * \return the mme rx message initialised.
+ */
+cp_mme_tx_t *
+cp_msg_mme_tx_init (cp_t *ctx);
+
+/**
+ * Function destructor for the MME RX messages.
+ * \param ctx the module context.
+ * \param msg the message context.
+ */
+void
+cp_msg_mme_rx_destructor (cp_mme_rx_t *mme);
+
+/**
+ * Function destructor for the MME TX messages.
+ * \param ctx the module context.
+ * \param msg the message context.
+ */
+void
+cp_msg_mme_tx_destructor (cp_mme_tx_t *mme);
+
+#endif /* cp2_msg_inc_msg_h */
diff --git a/cesar/cp2/msg/msg.h b/cesar/cp2/msg/msg.h
index 4d1e6412a9..ed3f30965b 100644
--- a/cesar/cp2/msg/msg.h
+++ b/cesar/cp2/msg/msg.h
@@ -31,13 +31,21 @@
BEGIN_DECLS
/**
- * Initialise the msg module.
+ * Initialise the MSG module.
* \param ctx control plane context
*/
void
cp_msg_init (cp_t *ctx);
/**
+ * Uninitialise the MSG module.
+ * \param ctx control plane context
+ */
+void
+cp_msg_uninit (cp_t *ctx);
+
+
+/**
* Examine message type and post an event to the FSM.
* \param ctx control plane context
* \param mme received MME
@@ -54,6 +62,7 @@ cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme);
* Initialise a MME handle for a new message to be transmitted.
* \param ctx control plane context
* \param peer peer information
+ * \param mmtype the MME MMTYPE.
* \return the newly created message
*
* This function:
@@ -63,12 +72,13 @@ cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme);
* - writes the MME header.
*/
cp_mme_tx_t *
-cp_msg_mme_init (cp_t *ctx, cp_mme_peer_t *peer);
+cp_msg_mme_init (cp_t *ctx, cp_mme_peer_t *peer, uint mmtype);
/**
* Initialise a MME handle for a new encrypted message to be transmitted.
* \param ctx control plane context
* \param peer peer information
+ * \param mmtype the MME MMType.
* \param pid protocol identifier
* \param peks payload encryption key select
* \param prun protocol run information
@@ -79,6 +89,7 @@ cp_msg_mme_init (cp_t *ctx, cp_mme_peer_t *peer);
*/
cp_mme_tx_t *
cp_msg_mme_init_encrypted (cp_t *ctx, cp_mme_peer_t *peer,
+ uint mmtype,
cp_mme_peks_t peks,
const cp_secu_protocol_run_t *prun);
@@ -95,6 +106,7 @@ 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 the module context.
* \param mme the MME received.
* \param length the MME length.
* \param tei the source TEI (0xFF if coming from the HLE).
@@ -102,7 +114,7 @@ cp_msg_mme_send (cp_t *ctx, cp_mme_tx_t *mme);
* \return cp_mme_rx_t object associated.
*/
cp_mme_rx_t *
-cp_msg_mme_read_header (u8 *mme, uint length, cp_tei_t tei,
+cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
uint *fmi);
END_DECLS
diff --git a/cesar/cp2/msg/src/mme.c b/cesar/cp2/msg/src/mme.c
new file mode 100644
index 0000000000..9736d08e45
--- /dev/null
+++ b/cesar/cp2/msg/src/mme.c
@@ -0,0 +1,108 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp2/msg/src/mme.c
+ * \brief Function to init and destroy the MME messages.
+ * \ingroup cp2_msg
+ *
+ */
+#include "common/std.h"
+
+#include "common/defs/ethernet.h"
+#include "lib/slab.h"
+
+#include "interface/interface.h"
+#include "cp2/msg/inc/msg.h"
+
+#include "cp2/inc/context.h"
+
+/**
+ * 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;
+}
+
+/**
+ * Function to init the mme rx t messages.
+ * \param ctx the module context.
+ * \return the mme rx message initialised.
+ */
+cp_mme_tx_t *
+cp_msg_mme_tx_init (cp_t *ctx)
+{
+ cp_mme_tx_t *mme;
+
+ dbg_assert (ctx);
+ mme = slab_alloc (&ctx->msg.mme_tx_slab_cache);
+ memset (mme, 0, sizeof (cp_mme_tx_t));
+
+ mme->cp = ctx;
+ return mme;
+}
+
+/**
+ * Function destructor for the MME RX messages.
+ * \param ctx the module context.
+ * \param msg the message context.
+ */
+void
+cp_msg_mme_rx_destructor (cp_mme_rx_t *mme)
+{
+ blk_t *blk;
+
+ dbg_assert (mme);
+
+ if (mme->p_mme)
+ interface_mme_recv_done (mme->cp->interface, mme->cl_data);
+
+ while (mme->p_frag)
+ {
+ blk = mme->p_frag;
+ mme->p_frag = blk->next;
+ blk_release (blk);
+ }
+}
+
+/**
+ * Function destructor for the MME TX messages.
+ * \param msg the message context.
+ */
+void
+cp_msg_mme_tx_destructor (cp_mme_tx_t *mme)
+{
+ dbg_assert (mme);
+
+ if (mme->p_mme)
+ cp_cl_interf_add_buffer_tx (mme->cp, mme->p_mme);
+}
+
diff --git a/cesar/cp2/msg/src/msg.c b/cesar/cp2/msg/src/msg.c
index 2e3aa70446..265a4c17f9 100644
--- a/cesar/cp2/msg/src/msg.c
+++ b/cesar/cp2/msg/src/msg.c
@@ -20,9 +20,252 @@
#include "cp2/cp.h"
#include "cp2/msg/msg.h"
+#include "cp2/cl_interf/cl_interf.h"
+#include "cp2/sta/mgr/sta_mgr.h"
+#include "cp2/sta/mgr/sta_own_data.h"
+
+#include "cp2/msg/inc/msg.h"
+#include "cp2/inc/context.h"
+
+/**
+ * Initialise the MSG module.
+ * \param ctx control plane context
+ */
+void
+cp_msg_init (cp_t *ctx)
+{
+ dbg_assert (ctx);
+
+ slab_cache_init (&ctx->msg.mme_tx_slab_cache, "MME TX",
+ sizeof (cp_mme_tx_t),
+ (slab_object_destructor_t) cp_msg_mme_tx_destructor);
+
+ slab_cache_init (&ctx->msg.mme_rx_slab_cache, "MME RX",
+ sizeof (cp_mme_rx_t),
+ (slab_object_destructor_t) cp_msg_mme_rx_destructor);
+}
+
+/**
+ * Uninitialise the MSG module.
+ * \param ctx control plane context
+ */
+void
+cp_msg_uninit (cp_t *ctx)
+{
+ dbg_assert (ctx);
+
+ slab_cache_uninit (&ctx->msg.mme_tx_slab_cache);
+ slab_cache_uninit (&ctx->msg.mme_rx_slab_cache);
+}
+
+/**
+ * Examine message type and post an event to the FSM.
+ * \param ctx control plane context
+ * \param mme received MME
+ *
+ * This function looks up the message type and translates it to a FSM event,
+ * while checking the encryption is compliant with the message type.
+ *
+ * It also extracts and checks payload from encrypted messages.
+ */
+void
+cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme);
+
+/**
+ * Initialise a MME handle for a new message to be transmitted.
+ * \param ctx control plane context
+ * \param peer peer information
+ * \param mmtype the MME MMTYPE.
+ * \return the newly created message
+ *
+ * This function:
+ *
+ * - gets a buffer for MME transmission,
+ * - encapsulates the MME in a CC_RELAY.REQ if necessary,
+ * - writes the MME header.
+ */
+cp_mme_tx_t *
+cp_msg_mme_init (cp_t *ctx, cp_mme_peer_t *peer, uint mmtype)
+{
+ cp_mme_tx_t *msg;
+ cp_sta_own_data_t *own_data;
+ u64 data;
+
+ dbg_assert (ctx);
+ dbg_assert (peer);
+
+ // Allocate the new message.
+ msg = cp_msg_mme_tx_init (ctx);
+ dbg_assert (msg);
+
+ // Get a buffer.
+ msg->p_mme = cp_cl_interf_get_buffer_tx (ctx);
+ msg->peer = *peer;
+
+ // Get the station own data.
+ own_data = cp_sta_mgr_get_sta_own_data (ctx);
+
+ // Initialise the bitstream context and fill the MME header.
+ bitstream_init (&msg->bitstream, msg->p_mme,
+ peer->vlan_tag ? HPAV_MME_HEADER_LEN_WITH_VLAN :
+ HPAV_MME_HEADER,
+ BITSTREAM_WRITE);
+
+ // Store the Destination Mac address.
+ bitstream_access (&msg->bitstream, &peer->mac,
+ BYTES_SIZE_TO_BITS (ETH_MAC_ADDRESS_SIZE));
+
+ // Store the source mac address.
+ data = cp_sta_own_data_get_mac_address (own_data);
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (ETH_MAC_ADDRESS_SIZE));
+
+ // Vlan tag.
+ if (peer->vlan_tag)
+ bitstream_access (&msg->bitstream, &peer->vlan_tag,
+ BYTES_SIZE_TO_BITS(ETH_VLAN_TAG_SIZE));
+
+ // MTYPE.
+ data = swap16(HPAV_MTYPE_MME);
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_MTYPE_SIZE));
+
+ // MMV
+ data = HPAV_MMV;
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_MMV_SIZE));
+
+ //MMTYPE.
+ bitstream_access (&msg->bitstream, &mmtype,
+ BYTES_SIZE_TO_BITS (HPAV_MMTYPE_SIZE));
+
+ return msg;
+}
+
+/**
+ * Initialise a MME handle for a new encrypted message to be transmitted.
+ * \param ctx control plane context
+ * \param peer peer information
+ * \param mmtype the MME MMType.
+ * \param pid protocol identifier
+ * \param peks payload encryption key select
+ * \param prun protocol run information
+ * \return the newly created message
+ *
+ * This does the same as cp_msg_mme_init(), but also encapsulate the MME in a
+ * CM_ENCRYPTED_PAYLOAD.IND.
+ */
+cp_mme_tx_t *
+cp_msg_mme_init_encrypted (cp_t *ctx, cp_mme_peer_t *peer,
+ uint mmtype,
+ cp_mme_peks_t peks,
+ const cp_secu_protocol_run_t *prun)
+{
+ cp_mme_tx_t *msg;
+ cp_sta_own_data_t *own_data;
+ u64 data;
+
+ dbg_assert (ctx);
+ dbg_assert (peer);
+ dbg_assert (prun);
+
+ // Initialise the message context.
+ msg = cp_msg_mme_tx_init (ctx);
+ dbg_assert (msg);
+
+ // Get a buffer
+ msg->p_mme = cp_cl_interf_get_buffer_tx (ctx);
+ msg->peer = *peer;
+ msg->peks = peks;
+ msg->prun = *prun;
+
+ own_data = cp_sta_mgr_get_sta_own_data (ctx);
+ // Initialise the bitstream context.
+ bitstream_init (&msg->bitstream, msg->p_mme,
+ peer->vlan_tag ? 2 * HPAV_MME_HEADER_LEN_WITH_VLAN :
+ 2 * HPAV_MME_HEADER, BITSTREAM_WRITE);
+
+ // Store the ODA.
+ bitstream_access (&msg->bitstream, &msg->peer.mac,
+ BYTES_SIZE_TO_BITS (ETH_MAC_ADDRESS_SIZE));
+
+ // Store the OSA.
+ data = cp_sta_own_data_get_mac_address (own_data);
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (ETH_MAC_ADDRESS_SIZE));
+
+ // Vlan tag.
+ if (peer->vlan_tag)
+ bitstream_access (&msg->bitstream, &peer->vlan_tag,
+ BYTES_SIZE_TO_BITS(ETH_VLAN_TAG_SIZE));
+
+ // MTYPE.
+ data = swap16(HPAV_MTYPE_MME);
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_MTYPE_SIZE));
+
+ // MMV
+ data = HPAV_MMV;
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_MMV_SIZE));
+
+ //MMTYPE.
+ data = CM_ENCRYPTED_PAYLOAD_IND;
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_MMTYPE_SIZE));
+
+ // FMI = 0.
+ data = 0;
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_FMI_SIZE));
+
+ // The payload
+ // Store the ODA.
+ bitstream_access (&msg->bitstream, &msg->peer.mac,
+ BYTES_SIZE_TO_BITS (ETH_MAC_ADDRESS_SIZE));
+
+ // Store the OSA.
+ data = cp_sta_own_data_get_mac_address (own_data);
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (ETH_MAC_ADDRESS_SIZE));
+
+ // Vlan tag.
+ if (peer->vlan_tag)
+ bitstream_access (&msg->bitstream, &peer->vlan_tag,
+ BYTES_SIZE_TO_BITS(ETH_VLAN_TAG_SIZE));
+
+ // MTYPE.
+ data = swap16(HPAV_MTYPE_MME);
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_MTYPE_SIZE));
+
+ // MMV
+ data = HPAV_MMV;
+ bitstream_access (&msg->bitstream, &data,
+ BYTES_SIZE_TO_BITS (HPAV_MMV_SIZE));
+
+ //MMTYPE.
+ bitstream_access (&msg->bitstream, &mmtype,
+ BYTES_SIZE_TO_BITS (HPAV_MMTYPE_SIZE));
+
+ return msg;
+}
+
+/**
+ * Finalise and send a MME.
+ * \param ctx control plane context
+ * \param mme MME handle
+ *
+ * If the MME is encapsulated, write any pending footer, then send the
+ * message.
+ */
+void
+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 the module context.
* \param mme the MME received.
* \param length the MME length.
* \param tei the source TEI (0xFF if coming from the HLE).
@@ -30,7 +273,7 @@
* \return cp_mme_rx_t object associated.
*/
cp_mme_rx_t *
-cp_msg_mme_read_header (u8 *mme, uint length, cp_tei_t tei,
+cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
uint *fmi)
{
cp_mme_rx_t *mme_rx;
@@ -38,6 +281,7 @@ cp_msg_mme_read_header (u8 *mme, uint length, cp_tei_t tei,
uint mtype;
uint mmv;
+ dbg_assert (ctx);
dbg_assert (mme);
if (read_u16_from_word (mme + 12) == swap16 (HPAV_MTYPE_MME))
@@ -45,10 +289,7 @@ cp_msg_mme_read_header (u8 *mme, uint length, cp_tei_t tei,
else
vlantag_present = true;
- mme_rx = blk_alloc ();
- mme_rx->p_mme = mme;
- mme_rx->length = length;
- mme_rx->peer.tei = tei;
+ mme_rx = cp_msg_mme_rx_init (ctx, mme, length, tei);
bitstream_init (&mme_rx->bitstream, mme + ETH_MAC_ADDRESS_SIZE,
length, BITSTREAM_READ);
@@ -67,7 +308,7 @@ cp_msg_mme_read_header (u8 *mme, uint length, cp_tei_t tei,
// Verify some data.
if ((mmv != HPAV_MMV1) || (swap16(mtype) != HPAV_MTYPE_MME))
{
- blk_release (mme_rx);
+ slab_release (mme_rx);
mme_rx = NULL;
}
diff --git a/cesar/cp2/msg/test/Makefile b/cesar/cp2/msg/test/Makefile
index d052661e53..137db80e9a 100644
--- a/cesar/cp2/msg/test/Makefile
+++ b/cesar/cp2/msg/test/Makefile
@@ -1,8 +1,15 @@
BASE = ../../..
-HOST_PROGRAMS = test-msg-read-header
+INCLUDES = cp2/msg/test/overide/
-test-msg-read-header_SOURCES = test-msg-read-header.c
+HOST_PROGRAMS = test-msg-read-header test-msg
+
+test-msg-read-header_SOURCES = test-msg-read-header.c interface_stub.c \
+ cp_cl_interface_stub.c sta_mgr_stub.c
test-msg-read-header_MODULES = lib cp2/msg
+test-msg_SOURCES = test-msg.c interface_stub.c cp_cl_interface_stub.c \
+ sta_mgr_stub.c
+test-msg_MODULES = lib cp2/msg
+
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp2/msg/test/overide/cp2/inc/context.h b/cesar/cp2/msg/test/overide/cp2/inc/context.h
new file mode 100644
index 0000000000..fc07d7919d
--- /dev/null
+++ b/cesar/cp2/msg/test/overide/cp2/inc/context.h
@@ -0,0 +1,34 @@
+#ifndef overide_cp2_inc_context_h
+#define overide_cp2_inc_context_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file overide/cp2/inc/context.h
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+
+#include "cp2/msg/inc/context.h"
+#include "cl/cl.h"
+
+struct cp_t
+{
+ /** MSG context. */
+ cp_msg_t msg;
+
+ /** Interface context. */
+ interface_t *interface;
+
+ /** Convergence layer context. */
+ cl_t *cl;
+};
+
+#endif /* overide_cp2_inc_context_h */
diff --git a/cesar/cp2/msg/test/src/cp_cl_interface_stub.c b/cesar/cp2/msg/test/src/cp_cl_interface_stub.c
new file mode 100644
index 0000000000..a3664facb5
--- /dev/null
+++ b/cesar/cp2/msg/test/src/cp_cl_interface_stub.c
@@ -0,0 +1,32 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/cp_cl_interface_stub.c
+ * \brief CL interface stub functions.
+ * \ingroup cp2_msg
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "cp2/cp.h"
+
+static u8 buffer[2048] __attribute__((aligned(2048)));
+
+u8 *
+cp_cl_interf_get_buffer_tx (cp_t *ctx)
+{
+ dbg_assert (ctx);
+ return buffer;
+}
+
+void
+cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer)
+{
+}
+
diff --git a/cesar/cp2/msg/test/src/interface_stub.c b/cesar/cp2/msg/test/src/interface_stub.c
new file mode 100644
index 0000000000..904b3f1ecb
--- /dev/null
+++ b/cesar/cp2/msg/test/src/interface_stub.c
@@ -0,0 +1,27 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/interface_stub.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "cp2/cp.h"
+
+/**
+ * Inform the Data plane when the MME as been processed by the CP.
+ * \param ctx the interface context
+ * \param mme_recv the cl data (as a void pointer).
+ */
+void
+interface_mme_recv_done (interface_t *ctx, void *mme_recv)
+{
+}
diff --git a/cesar/cp2/msg/test/src/sta_mgr_stub.c b/cesar/cp2/msg/test/src/sta_mgr_stub.c
new file mode 100644
index 0000000000..a44a30393b
--- /dev/null
+++ b/cesar/cp2/msg/test/src/sta_mgr_stub.c
@@ -0,0 +1,44 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/sta_mgr_stub.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "cp2/sta/mgr/sta_own_data.h"
+
+static cp_sta_own_data_t own;
+
+/**
+ * Returns a reference on our own station data.
+ * \param ctx the module context.
+ * \return A reference on the sta own data. Do not release It it not a block.
+ */
+cp_sta_own_data_t *
+cp_sta_mgr_get_sta_own_data (cp_t *ctx)
+{
+ dbg_assert (ctx);
+
+ return (cp_sta_own_data_t *) &own;
+}
+
+/**
+ * Get the station mac address.
+ * \param ctx the module context.
+ * \return Get the station Mac address.
+ *
+ */
+mac_t
+cp_sta_own_data_get_mac_address (cp_sta_own_data_t *ctx)
+{
+ return 0x123456789ABCull;
+}
diff --git a/cesar/cp2/msg/test/src/test-msg-read-header.c b/cesar/cp2/msg/test/src/test-msg-read-header.c
index 88d6ecba63..484a148f46 100644
--- a/cesar/cp2/msg/test/src/test-msg-read-header.c
+++ b/cesar/cp2/msg/test/src/test-msg-read-header.c
@@ -22,6 +22,8 @@
#include "cp2/cp.h"
#include "cp2/msg/msg.h"
+#include "cp2/inc/context.h"
+
/**
* Test the msg_read header function with a MME containing a VLAN Tag.
* \param test the test object.
@@ -29,6 +31,7 @@
void
test_case_msg_read_header_mme_without_vlan (test_t test)
{
+ cp_t cp;
bitstream_t bitstream;
u8 buffer[256] __attribute__((aligned(256)));
uint fmi;
@@ -36,6 +39,8 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
u64 data;
+ cp_msg_init (&cp);
+
test_case_begin (test, "TEST 1");
bitstream_init (&bitstream, buffer, 23, BITSTREAM_WRITE);
@@ -55,7 +60,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_begin (test, "Read a MME with vlan")
{
@@ -70,7 +75,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
test_fail_if (fmi != 0x432, "wrong FMI value");
}
test_end;
- blk_release (mme);
+ slab_release (mme);
test_case_begin (test, "TEST 2");
@@ -89,7 +94,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_begin (test, "Read a MME without vlan")
{
@@ -104,7 +109,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
test_fail_if (fmi != 0x432, "wrong FMI value");
}
test_end;
- blk_release (mme);
+ slab_release (mme);
test_case_begin (test, "TEST 3");
@@ -123,7 +128,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_begin (test, "Read a MME without vlan")
{
@@ -148,13 +153,15 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (buffer, 92, 0x1, &fmi);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_begin (test, "Read a MME without vlan")
{
test_fail_if (mme != NULL, "Shall be null");
}
test_end;
+
+ cp_msg_uninit (&cp);
}
int
@@ -173,6 +180,5 @@ main (void)
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/src/test-msg.c b/cesar/cp2/msg/test/src/test-msg.c
new file mode 100644
index 0000000000..2a591b25f7
--- /dev/null
+++ b/cesar/cp2/msg/test/src/test-msg.c
@@ -0,0 +1,229 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/test-msg.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "common/defs/homeplugAV.h"
+
+#include "lib/test.h"
+#include "lib/swap.h"
+#include "lib/bitstream.h"
+
+#include "cp2/cp.h"
+#include "cp2/msg/msg.h"
+
+#include "cp2/inc/context.h"
+#include "cp2/msg/inc/msg.h"
+
+void
+test_case_msg_messages_init (test_t test)
+{
+ cp_t cp;
+ cp_mme_rx_t *mme_rx;
+ cp_mme_tx_t *mme_tx;
+ u8 buffer[10];
+
+ cp_msg_init (&cp);
+
+ test_case_begin (test, "MSG Message");
+
+ mme_rx = cp_msg_mme_rx_init (&cp, buffer, 70, 0xA);
+ test_begin (test, "MME rx init")
+ {
+ test_fail_if (mme_rx == NULL, "MSG message shall not be null");
+ test_fail_if (mme_rx->p_mme != buffer, "Wrong buffer address");
+ test_fail_if (mme_rx->length != 70, "Wrong length");
+ test_fail_if (mme_rx->peer.tei != 0xA, "Wrong TEI");
+ test_fail_if (mme_rx->cp != &cp, "Wrong CP context");
+ }
+ test_end;
+ slab_release (mme_rx);
+
+ mme_tx = cp_msg_mme_tx_init (&cp);
+ test_begin (test, "MME rx init")
+ {
+ test_fail_if (mme_tx == NULL, "MSG message shall not be null");
+ test_fail_if (mme_tx->cp != &cp, "Wrong CP context");
+ }
+ test_end;
+ slab_release (mme_tx);
+
+ cp_msg_uninit (&cp);
+}
+
+void
+test_case_msg_mme_tx_init (test_t test)
+{
+ cp_t cp;
+ cp_mme_tx_t *mme;
+ cp_mme_peer_t peer;
+ bitstream_t bitstream;
+ u64 data;
+
+ cp_msg_init (&cp);
+
+ test_case_begin (test, "Get a MME TX context");
+
+ peer.mac = 0x123456789ABCull;
+ peer.vlan_tag = 0xAB;
+ peer.tei = 0xA;
+ peer.all_sta = false;
+ mme = cp_msg_mme_init (&cp, &peer, 0xb0);
+ // Close the MME bitstream.
+ bitstream_finalise (&mme->bitstream);
+
+ bitstream_init (&bitstream, mme->p_mme, HPAV_MME_HEADER_LEN_WITH_VLAN,
+ BITSTREAM_READ);
+ test_begin (test, "Verify")
+ {
+ test_fail_if (mme->p_mme == NULL, "buffer shall not be NULL");
+ test_fail_if (mme->peer.mac != peer.mac, "Wrong MAC @");
+ test_fail_if (mme->peer.vlan_tag != peer.vlan_tag, "Wrong VLAN tag");
+ test_fail_if (mme->peer.all_sta != peer.all_sta, "Wrong STA Flag");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != peer.mac, "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != 0x123456789ABCull,
+ "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 32);
+ test_fail_if (data != peer.vlan_tag, "Wrong VLAN TAG");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (swap16(data) != HPAV_MTYPE_MME, "Wrong Mtype");
+
+ bitstream_access (&bitstream, &data, 8);
+ test_fail_if (data != HPAV_MMV, "Wrong MMV");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != 0xb0, "Wrong MMTYPE");
+ }
+ test_end;
+
+ bitstream_finalise (&bitstream);
+ slab_release (mme);
+
+ cp_msg_uninit (&cp);
+}
+
+void
+test_case_msg_mme_tx_init_enc (test_t test)
+{
+ cp_t cp;
+ cp_mme_tx_t *mme;
+ cp_mme_peer_t peer;
+ cp_secu_protocol_run_t prun;
+ bitstream_t bitstream;
+ u64 data;
+
+ cp_msg_init (&cp);
+
+ test_case_begin (test, "Get a MME TX enc context");
+
+ peer.mac = 0x123456789ABCull;
+ peer.vlan_tag = 0xAB;
+ peer.tei = 0xA;
+ peer.all_sta = false;
+
+ prun.pid = 2;
+ prun.pmn = 2;
+ prun.my_nonce = 0x3;
+ prun.your_nonce = 0x4;
+
+ mme = cp_msg_mme_init_encrypted (&cp, &peer, 0xb0, 2, &prun);
+ // Close the MME bitstream.
+ bitstream_finalise (&mme->bitstream);
+
+ bitstream_init (&bitstream, mme->p_mme, 2*HPAV_MME_HEADER_LEN_WITH_VLAN,
+ BITSTREAM_READ);
+ test_begin (test, "Verify")
+ {
+ test_fail_if (mme->p_mme == NULL, "buffer shall not be NULL");
+ test_fail_if (mme->peer.mac != peer.mac, "Wrong MAC @");
+ test_fail_if (mme->peer.vlan_tag != peer.vlan_tag, "Wrong VLAN tag");
+ test_fail_if (mme->peer.all_sta != peer.all_sta, "Wrong STA Flag");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != peer.mac, "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != 0x123456789ABCull,
+ "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 32);
+ test_fail_if (data != peer.vlan_tag, "Wrong VLAN TAG");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (swap16(data) != HPAV_MTYPE_MME, "Wrong Mtype");
+
+ bitstream_access (&bitstream, &data, 8);
+ test_fail_if (data != HPAV_MMV, "Wrong MMV");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != CM_ENCRYPTED_PAYLOAD_IND, "Wrong MMTYPE");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != 0, "Wrong FMI");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != peer.mac, "enc: Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != 0x123456789ABCull,
+ "enc: Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 32);
+ test_fail_if (data != peer.vlan_tag, "enc: Wrong VLAN TAG");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (swap16(data) != HPAV_MTYPE_MME, "enc: Wrong Mtype");
+
+ bitstream_access (&bitstream, &data, 8);
+ test_fail_if (data != HPAV_MMV, "enc: Wrong MMV");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != 0xb0, "enc: Wrong MMTYPE");
+
+ }
+ test_end;
+
+ bitstream_finalise (&bitstream);
+ slab_release (mme);
+
+ cp_msg_uninit (&cp);
+}
+
+
+int
+main (void)
+{
+ test_t test;
+ test_init (test, 0, NULL);
+
+ test_case_msg_messages_init (test);
+ test_case_msg_mme_tx_init (test);
+ test_case_msg_mme_tx_init_enc (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);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}