summaryrefslogtreecommitdiff
path: root/cesar/cp2
diff options
context:
space:
mode:
authorlaranjeiro2008-06-12 16:22:36 +0000
committerlaranjeiro2008-06-12 16:22:36 +0000
commit6d4ae7541fedd08505cd766f554bb3d68a3ee442 (patch)
tree40d2fb469aa7c13eb88860cadce715e989212d7f /cesar/cp2
parent19396daa88c615f90f84a8b6fb069c20cd5ba060 (diff)
cl-interf : Ending the test for cl_interf_mme_process.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2314 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2')
-rw-r--r--cesar/cp2/cl_interf/inc/cl_interf.h3
-rw-r--r--cesar/cp2/cl_interf/src/cl_interf.c99
-rw-r--r--cesar/cp2/cl_interf/test/src/test-cl-interf.c140
3 files changed, 194 insertions, 48 deletions
diff --git a/cesar/cp2/cl_interf/inc/cl_interf.h b/cesar/cp2/cl_interf/inc/cl_interf.h
index 2c29652dd1..ea670ab6d8 100644
--- a/cesar/cp2/cl_interf/inc/cl_interf.h
+++ b/cesar/cp2/cl_interf/inc/cl_interf.h
@@ -37,8 +37,9 @@ cp_cl_interf_rx_mme (cp_t *ctx, mfs_rx_t * mfs,
* \param mme the MME to fragment.
* \param length the MME length.
* \param fmi the FMI MME data.
+ * \return true if it was the last message, false otherwise.
*/
-void
+bool
cp_cl_interf_rx_mme_frag (cp_t *ctx, cp_tei_t tei, u8 *mme, uint length,
uint fmi);
diff --git a/cesar/cp2/cl_interf/src/cl_interf.c b/cesar/cp2/cl_interf/src/cl_interf.c
index 99a1d0a4ea..c14697c1dd 100644
--- a/cesar/cp2/cl_interf/src/cl_interf.c
+++ b/cesar/cp2/cl_interf/src/cl_interf.c
@@ -117,14 +117,38 @@ cp_cl_interf_process_mme (cp_t *ctx)
interface_mme_recv_done (ctx->interface, msg->cl_data);
else
{
+ mme->cl_data = msg->cl_data;
// Verify if the MME is a segmented MME.
if (fmi)
{
- cp_cl_interf_rx_mme_frag (ctx, msg->mfs->common.tei,
+ bool last_mme;
+ last_mme = cp_cl_interf_rx_mme_frag (ctx, msg->mfs->common.tei,
msg->buffer, msg->length,
fmi);
interface_mme_recv_done (ctx->interface, msg->cl_data);
+ mme->p_mme = NULL;
+ mme->length += msg->length;
+
+ if (last_mme)
+ {
+ cp_sta_t *sta;
+ cp_net_t *net;
+
+ net = cp_sta_mgr_get_our_avln (ctx);
+ sta = cp_net_get_sta (net, msg->mfs->common.tei);
+ mme->p_frag = (blk_t *)sta->reassembly_ctx.head;
+ sta->reassembly_ctx.head = NULL;
+ sta->reassembly_ctx.tail = NULL;
+ blk_release (sta);
+
+ cp_msg_dispatch (ctx, mme);
+ }
+ else
+ {
+ interface_mme_recv_done (ctx->interface, msg->cl_data);
+ blk_release (mme);
+ }
}
// Normal MME call the MSG dispatcher.
else
@@ -275,8 +299,9 @@ cp_cl_interf_rx_mme (cp_t *ctx, mfs_rx_t * mfs,
* \param mme the MME to fragment.
* \param length the MME length.
* \param fmi the FMI MME data.
+ * \return true if it was the last message, false otherwise.
*/
-void
+bool
cp_cl_interf_rx_mme_frag (cp_t *ctx, cp_tei_t tei, u8 *mme, uint length,
uint fmi)
{
@@ -287,44 +312,58 @@ cp_cl_interf_rx_mme_frag (cp_t *ctx, cp_tei_t tei, u8 *mme, uint length,
cp_sta_t *sta;
cp_sta_reassembly_ctx_blk_t *head;
cp_sta_reassembly_ctx_blk_t *tail;
+ bitstream_t bitstream;
+ uint nb_blk;
+ cp_sta_reassembly_ctx_blk_t *current;
+ uint offset;
+ uint rest;
+
- fmi_frag_nbs = read_u8_from_word ((u8 *) &fmi) >> 4;
- fmi_frag_nb = read_u8_from_word ((u8 *) &fmi) & 0xF;
- fmi_frag_ssn = read_u8_from_word (((u8 *) &fmi) + 1);
+ bitstream_init (&bitstream, &fmi, 16, BITSTREAM_READ);
+ bitstream_access (&bitstream, &fmi_frag_nbs, 4);
+ bitstream_access (&bitstream, &fmi_frag_nb, 4);
+ bitstream_access (&bitstream, &fmi_frag_ssn, 4);
+ bitstream_finalise (&bitstream);
net = cp_sta_mgr_get_our_avln (ctx);
sta = cp_net_get_sta (net, tei);
dbg_assert (sta);
- if (sta->reassembly_ctx.last_seg_ssn != fmi_frag_ssn)
+ sta->reassembly_ctx.last_seg_ssn = fmi_frag_ssn;
+ nb_blk = (length / BLK_SIZE) + 1;
+
+ // Compute the number of blocks.
+ head = (cp_sta_reassembly_ctx_blk_t *)
+ blk_alloc_desc_range (nb_blk, (blk_t **) &tail);
+ tail->next = NULL;
+
+ for (current = head, offset = 0;
+ offset < length && current != NULL;
+ offset += BLK_SIZE, current = current->next)
{
- uint nb_blk;
- cp_sta_reassembly_ctx_blk_t *current;
- uint offset;
- uint rest;
-
- sta->reassembly_ctx.last_seg_ssn = fmi_frag_ssn;
- nb_blk = (length / BLK_SIZE) + 1;
-
- // Compute the number of blocks.
- head = (cp_sta_reassembly_ctx_blk_t *)
- blk_alloc_desc_range (nb_blk, (blk_t **) &tail);
- tail->next = NULL;
-
- for (current = head, offset = 0;
- offset < length && current != NULL;
- offset += BLK_SIZE, current = current->next)
- {
- current->length = ((rest = (length - offset)) > BLK_SIZE)
- ? BLK_SIZE : rest;
- current->ssn = fmi_frag_ssn;
- bitstream_memcpy (current->data, mme + offset,
- (rest > BLK_SIZE) ? BLK_SIZE : rest);
- }
+ current->length = ((rest = (length - offset)) > BLK_SIZE)
+ ? BLK_SIZE : rest;
+ current->ssn = fmi_frag_ssn;
+ bitstream_memcpy (current->data, mme + offset,
+ (rest > BLK_SIZE) ? BLK_SIZE : rest);
+ }
- // Chain the blocks.
+ // Chain the blocks.
+ if (sta->reassembly_ctx.tail)
+ {
sta->reassembly_ctx.tail->next = head;
sta->reassembly_ctx.tail = tail;
}
+ else
+ {
+ sta->reassembly_ctx.head = head;
+ sta->reassembly_ctx.tail = tail;
+ }
+ blk_release (sta);
+
+ if (fmi_frag_nb == fmi_frag_nbs)
+ return true;
+ else
+ return false;
}
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 d722f2c53a..62d8addbbf 100644
--- a/cesar/cp2/cl_interf/test/src/test-cl-interf.c
+++ b/cesar/cp2/cl_interf/test/src/test-cl-interf.c
@@ -15,8 +15,10 @@
* [wiki:UT-CPM1-CL-INTERF]
*/
#include "common/std.h"
+#include "common/defs/homeplugAV.h"
#include "lib/test.h"
+#include "lib/swap.h"
#include "mac/common/store.h"
@@ -31,9 +33,11 @@
#include "cp2/msg/msg.h"
static test_t test;
-static cp_mme_rx_t mme_rx_data;
static bool test_send_mme_without_mfs = false;
+// Use by the msg dispatch stub.
+static cp_mme_rx_t *dispatch_mme_rx;
+
/** Thread context. */
u8 thread_stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];
cyg_handle_t thread_handle;
@@ -65,16 +69,17 @@ void
test_case_cl_interf_receive_mme (void)
{
cp_t cp;
- mfs_rx_t mfs;
+ mfs_rx_t *mfs;
cp_cl_interf_msg_t *msg;
void *cl_data;
u8 buffer[2048] __attribute__((aligned(2048)));
+ mfs = blk_alloc ();
cp_cl_interf_init (&cp);
test_case_begin (test, "Receive MME");
- cp_cl_interf_rx_mme (&cp, &mfs, buffer, 1200, cl_data, true);
+ cp_cl_interf_rx_mme (&cp, mfs, buffer, 1200, cl_data, true);
msg = cyg_mbox_get (cp.cl_interf.mailbox_handle);
test_begin (test, "Verify.")
@@ -82,12 +87,14 @@ test_case_cl_interf_receive_mme (void)
test_fail_if (msg == NULL, "Message shall not be null");
test_fail_if (msg->buffer != buffer, "Wrong MME buffer address");
test_fail_if (msg->length != 1200, "Wrong MME length");
- test_fail_if (msg->mfs != &mfs, "Wrong MFS");
+ test_fail_if (msg->mfs != mfs, "Wrong MFS");
test_fail_if (msg->hard_encrypt != true, "Wrong encryption status");
test_fail_if (msg->cl_data != cl_data, "Wrong data_cl");
}
test_end;
blk_release (msg);
+ blk_release (mfs);
+ blk_release (mfs);
cp_cl_interf_uninit (&cp);
}
@@ -96,43 +103,141 @@ void
test_case_cl_intef_process_mme (void)
{
cp_t cp;
- mfs_rx_t mfs;
+ mfs_rx_t *mfs;
void *cl_data;
u8 buffer[2048] __attribute__((aligned(2048)));
+ u8 buffer2[2048] __attribute__((aligned(2048)));
+ bitstream_t bitstream;
+ u64 data;
+ cp_net_t *net;
+ cp_sta_t *sta;
+ blk_t *current;
cp_cl_interf_init (&cp);
test_case_begin (test, "Process the MME : Test 1");
- cp_cl_interf_rx_mme (&cp, &mfs, buffer, 1200, cl_data, true);
+ mfs = blk_alloc ();
+ cl_data = buffer;
+
+ 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 = 0;
+ bitstream_access (&bitstream, &data, 16);
+ bitstream_finalise (&bitstream);
+
+ cp_cl_interf_rx_mme (&cp, mfs, buffer, 1200, cl_data, true);
cp_cl_interf_process_mme (&cp);
test_begin (test, "Verify")
{
- test_fail_if (mme_rx_data.p_mme != buffer, "Wrong buffer address");
- test_fail_if (mme_rx_data.p_frag != NULL, "frag shall be null");
- test_fail_if (mme_rx_data.length != 1200, "Wrong length");
- test_fail_if (mme_rx_data.cl_data != cl_data, "Wrong cl_data");
+ test_fail_if (dispatch_mme_rx->p_mme != buffer, "Wrong buffer address");
+ test_fail_if (dispatch_mme_rx->p_frag != NULL, "frag shall be null");
+ test_fail_if (dispatch_mme_rx->length != 1200, "Wrong length");
+ test_fail_if (dispatch_mme_rx->cl_data != cl_data, "Wrong cl_data");
}
test_end;
+ blk_release (mfs);
+ blk_release (dispatch_mme_rx);
test_case_begin (test, "Process the MME : Test 2");
- cp_cl_interf_rx_mme (&cp, &mfs, buffer, 1200, cl_data, true);
- cp_cl_interf_rx_mme (&cp, &mfs, buffer, 1200, cl_data, true);
+ cp_sta_mgr_init (&cp);
+ net = cp_sta_mgr_get_our_avln (&cp);
+ sta = cp_net_sta_add (net, 1, 1);
+ blk_release (sta);
+
+ mfs = blk_alloc ();
+ mfs->common.tei = 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 = 1; // 2 frags.
+ bitstream_access (&bitstream, &data, 4);
+ data = 0; // 1st frag.
+ bitstream_access (&bitstream, &data, 4);
+ data = 1; // SSN.
+ bitstream_access (&bitstream, &data, 4);
+ bitstream_finalise (&bitstream);
+
+ cp_cl_interf_rx_mme (&cp, mfs, buffer, 1200, cl_data, true);
+
+ bitstream_init (&bitstream, buffer2, 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 = 1; // 2 frags.
+ bitstream_access (&bitstream, &data, 4);
+ data = 1; // 1st frag.
+ bitstream_access (&bitstream, &data, 4);
+ data = 1; // SSN.
+ bitstream_access (&bitstream, &data, 4);
+ bitstream_finalise (&bitstream);
+
+ cp_cl_interf_rx_mme (&cp, mfs, buffer2, 1200, cl_data, true);
cp_cl_interf_process_mme (&cp);
+ cp_cl_interf_process_mme (&cp);
test_begin (test, "Verify")
{
- test_fail_if (mme_rx_data.p_mme != NULL , "Wrong buffer address");
- test_fail_if (mme_rx_data.p_frag == NULL, "frag shall not be null");
- test_fail_if (mme_rx_data.length != 1200, "Wrong length");
- test_fail_if (mme_rx_data.cl_data != cl_data, "Wrong cl_data");
+ test_fail_if (dispatch_mme_rx->p_mme != NULL , "Wrong buffer address");
+ test_fail_if (dispatch_mme_rx->p_frag == NULL,
+ "frag shall not be null");
+ test_fail_if (dispatch_mme_rx->length != 2400, "Wrong length");
+ test_fail_if (dispatch_mme_rx->cl_data != cl_data, "Wrong cl_data");
}
test_end;
+
+ if (dispatch_mme_rx->p_frag)
+ {
+ current = dispatch_mme_rx->p_frag;
+ dispatch_mme_rx->p_frag = dispatch_mme_rx->p_frag->next;
+ while (current)
+ {
+ blk_release_desc (current);
+ current = dispatch_mme_rx->p_frag;
+ if (dispatch_mme_rx->p_frag)
+ dispatch_mme_rx->p_frag = dispatch_mme_rx->p_frag->next;
+ }
+ }
+
+ cp_sta_mgr_uninit (&cp);
cp_cl_interf_uninit (&cp);
+ blk_release (dispatch_mme_rx);
+ blk_release (mfs);
}
void
@@ -205,7 +310,7 @@ test_cl_interf_thread_entry_point (cyg_addrword_t data)
test_case_cl_interf_init ();
test_case_cl_interf_receive_mme ();
-// test_case_cl_intef_process_mme ();
+ test_case_cl_intef_process_mme ();
test_case_cl_interf_add_and_get_tx_buffer ();
test_case_cl_interf_send_mme ();
@@ -304,4 +409,5 @@ interface_mme_recv_done (interface_t *ctx, void *mme_recv)
void
cp_msg_dispatch (cp_t *ctx, cp_mme_rx_t *mme)
{
+ dispatch_mme_rx = mme;
}