summaryrefslogtreecommitdiff
path: root/cesar/cp
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-08-26 17:24:52 +0200
committerThierry Carré2011-10-20 10:37:47 +0200
commit04e96dbe7bc52e60918267087f2582b578d5d763 (patch)
treee08746e17c56b7e35e3edfcca1c38a1f7f633c1f /cesar/cp
parent382a27ccbe8d62d6013b5e7863b434dc049f6d81 (diff)
cesar/cp/msg: handle correctly fragmented message information, refs #2689
Diffstat (limited to 'cesar/cp')
-rw-r--r--cesar/cp/cl_interf/inc/cl_interf.h24
-rw-r--r--cesar/cp/cl_interf/src/cl_interf.c148
-rw-r--r--cesar/cp/cl_interf/test/src/test-cl-interf.c276
-rw-r--r--cesar/cp/mme.h6
-rw-r--r--cesar/cp/msg/msg.h6
-rw-r--r--cesar/cp/msg/src/msg.c49
-rw-r--r--cesar/cp/msg/test/src/cc_discover_list.c222
-rw-r--r--cesar/cp/msg/test/src/relay.c34
-rw-r--r--cesar/cp/sta/mgr/sta.h8
9 files changed, 374 insertions, 399 deletions
diff --git a/cesar/cp/cl_interf/inc/cl_interf.h b/cesar/cp/cl_interf/inc/cl_interf.h
index 7124498582..78e27c8a38 100644
--- a/cesar/cp/cl_interf/inc/cl_interf.h
+++ b/cesar/cp/cl_interf/inc/cl_interf.h
@@ -15,6 +15,23 @@
#include "cp/cp.h"
#include "mac/common/mfs.h"
+enum cp_cl_interf_rx_mme_frag_result_t
+{
+ /* Fragment received is OK, the transaction can continue. */
+ CP_CL_INTERF_RX_MME_FRAG_OK,
+ /* Fragment is invalid, it is dropped. */
+ CP_CL_INTERF_RX_MME_FRAG_NOK,
+ /* Fragment FMSN is wrong. */
+ CP_CL_INTERF_RX_MME_FRAG_FMSN_NOK,
+ /* Fragment is duplicated one. */
+ CP_CL_INTERF_RX_MME_FRAG_DUPLICATED,
+ /* Fragment is valid and all fragments have been received. */
+ CP_CL_INTERF_RX_MME_FRAG_ENDED,
+ CP_CL_INTERF_RX_MME_FRAG_NB
+};
+typedef enum cp_cl_interf_rx_mme_frag_result_t
+cp_cl_interf_rx_mme_frag_result_t;
+
/**
* Receive a MME from the PWL or the HLE.
* \param cp the module context.
@@ -37,10 +54,11 @@ cp_cl_interf_rx_mme (void *cp, cp_tei_t tei,
* \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.
+ * \param hard_enc the hardware encryption status.
+ * \return a status enum.
*/
-bool
+cp_cl_interf_rx_mme_frag_result_t
cp_cl_interf_rx_mme_frag (cp_t *ctx, cp_tei_t tei, u8 *mme, uint length,
- uint fmi);
+ uint fmi, bool hard_enc);
#endif /* cp_cl_interf_inc_cl_interf_h */
diff --git a/cesar/cp/cl_interf/src/cl_interf.c b/cesar/cp/cl_interf/src/cl_interf.c
index cf4a2d2936..8b2011cc6a 100644
--- a/cesar/cp/cl_interf/src/cl_interf.c
+++ b/cesar/cp/cl_interf/src/cl_interf.c
@@ -181,46 +181,31 @@ cp_cl_interf_process_mme (cp_t *ctx)
* http://standards.ieee.org/develop/regauth/oui/oui.txt */
if (mme->mmtype < VS_MIN)
{
- bool last_mme;
- uint ssn;
cp_sta_t *sta;
cp_net_t *net;
+ cp_cl_interf_rx_mme_frag_result_t result;
net = cp_sta_mgr_get_our_avln (ctx);
sta = cp_sta_mgr_sta_get_assoc (ctx, net, msg->tei);
- ssn = sta->reassembly_ctx.last_seg_ssn;
-
- last_mme = cp_cl_interf_rx_mme_frag (ctx, msg->tei,
- msg->buffer, msg->length,
- fmi);
+ result = cp_cl_interf_rx_mme_frag (ctx, msg->tei,
+ msg->buffer, msg->length,
+ fmi, msg->hard_encrypt);
interface_mme_recv_done (ctx->interface, msg->buffer,
msg->cl_data);
mme->p_mme = NULL;
- if (last_mme)
+ if (result == CP_CL_INTERF_RX_MME_FRAG_ENDED)
{
- mme->p_frag = (blk_t *)sta->reassembly_ctx.head;
- mme->p_frag_current = mme->p_frag_current;
+ mme->p_frag = mme->p_frag_current =
+ (blk_t *)sta->reassembly_ctx.head;
mme->encrypt = sta->reassembly_ctx.encrypt;
-
memset (&sta->reassembly_ctx, 0,
sizeof (cp_sta_reassembly_ctx_t));
cp_msg_dispatch (ctx, mme);
}
else
- {
- /* Store the encrypt information. If SSN is 0 then it
- * takes the hardware encryption of the MSG, otherwise
- * it shall be false if the status is false. */
- if (ssn == 0)
- sta->reassembly_ctx.encrypt = msg->hard_encrypt;
- else
- sta->reassembly_ctx.encrypt &= msg->hard_encrypt;
-
slab_release (mme);
- }
-
slab_release (sta);
}
else
@@ -367,81 +352,106 @@ cp_cl_interf_rx_mme (void *cp, cp_tei_t tei,
}
}
-
-/**
- * Copy the Fragmented MME into blocks.
- * \param ctx the cp module context.
- * \param tei the station source TEI.
- * \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.
- */
-bool
+cp_cl_interf_rx_mme_frag_result_t
cp_cl_interf_rx_mme_frag (cp_t *ctx, cp_tei_t tei, u8 *mme, uint length,
- uint fmi)
+ uint fmi, bool hard_enc)
{
uint fmi_frag_nbs;
uint fmi_frag_nb;
- uint fmi_frag_ssn;
+ uint fmi_frag_fmsn;
+ bitstream_t bitstream;
cp_net_t *net;
cp_sta_t *sta;
cp_sta_reassembly_ctx_blk_t *head;
cp_sta_reassembly_ctx_blk_t *tail;
blk_t *blk_tail;
- bitstream_t bitstream;
+
uint nb_blk;
cp_sta_reassembly_ctx_blk_t *current;
uint offset;
uint rest;
-
+ cp_cl_interf_rx_mme_frag_result_t res = CP_CL_INTERF_RX_MME_FRAG_NB;
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_access (&bitstream, &fmi_frag_fmsn, 8);
bitstream_finalise (&bitstream);
net = cp_sta_mgr_get_our_avln (ctx);
sta = cp_sta_mgr_sta_get_assoc (ctx, net, tei);
-
dbg_assert (sta);
- 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_tail);
- tail = (cp_sta_reassembly_ctx_blk_t *) blk_tail;
- tail->next = NULL;
-
- for (current = head, offset = 0;
- offset < length && current != NULL;
- offset += BLK_SIZE, current = current->next)
+ /* First reception of a fragment or the next one. */
+ if (!sta->reassembly_ctx.receiving_msg
+ || (sta->reassembly_ctx.receiving_msg
+ && sta->reassembly_ctx.nb_frags == fmi_frag_nbs
+ && sta->reassembly_ctx.last_seg_nb + 1 == fmi_frag_nb
+ && sta->reassembly_ctx.fmsn == fmi_frag_fmsn)
+ )
{
- 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);
- }
+ sta->reassembly_ctx.receiving_msg = true;
+ sta->reassembly_ctx.nb_frags = fmi_frag_nbs;
+ sta->reassembly_ctx.last_seg_nb = fmi_frag_nb;
+ sta->reassembly_ctx.fmsn = fmi_frag_fmsn;
+ 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_tail);
+ tail = (cp_sta_reassembly_ctx_blk_t *) blk_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_nb;
+ bitstream_memcpy (current->data, mme + offset,
+ (rest > BLK_SIZE) ? BLK_SIZE : rest);
+ }
- // Chain the blocks.
- if (sta->reassembly_ctx.tail)
- {
- sta->reassembly_ctx.tail->next = head;
- sta->reassembly_ctx.tail = tail;
+ // Chain the blocks.
+ if (sta->reassembly_ctx.tail)
+ {
+ sta->reassembly_ctx.encrypt &= hard_enc;
+ sta->reassembly_ctx.tail->next = head;
+ sta->reassembly_ctx.tail = tail;
+ }
+ else
+ {
+ sta->reassembly_ctx.encrypt = hard_enc;
+ sta->reassembly_ctx.head = head;
+ sta->reassembly_ctx.tail = tail;
+ }
+ /* Create the answer. */
+ if (sta->reassembly_ctx.nb_frags == fmi_frag_nb)
+ res = CP_CL_INTERF_RX_MME_FRAG_ENDED;
+ else
+ res = CP_CL_INTERF_RX_MME_FRAG_OK;
}
+ /* Handle all others cases of error. */
else
{
- sta->reassembly_ctx.head = head;
- sta->reassembly_ctx.tail = tail;
+ /* Segment has already been received. */
+ if (sta->reassembly_ctx.last_seg_nb >= fmi_frag_nb)
+ res = CP_CL_INTERF_RX_MME_FRAG_DUPLICATED;
+ /* Transaction number does not match. */
+ else if (sta->reassembly_ctx.fmsn != fmi_frag_fmsn)
+ res = CP_CL_INTERF_RX_MME_FRAG_FMSN_NOK;
+ /* Segment received is ahead. */
+ else if (sta->reassembly_ctx.last_seg_nb < fmi_frag_nb)
+ {
+ res = CP_CL_INTERF_RX_MME_FRAG_NOK;
+ /* Release all fragments. */
+ blk_release_desc_range ((blk_t*) sta->reassembly_ctx.head,
+ (blk_t*) sta->reassembly_ctx.tail);
+ sta->reassembly_ctx.receiving_msg = false;
+ sta->reassembly_ctx.head = sta->reassembly_ctx.tail = NULL;
+ }
}
slab_release (sta);
-
- if (fmi_frag_nb == fmi_frag_nbs)
- return true;
- else
- return false;
+ return res;
}
diff --git a/cesar/cp/cl_interf/test/src/test-cl-interf.c b/cesar/cp/cl_interf/test/src/test-cl-interf.c
index 3218c32f2f..f7bf0dcdd9 100644
--- a/cesar/cp/cl_interf/test/src/test-cl-interf.c
+++ b/cesar/cp/cl_interf/test/src/test-cl-interf.c
@@ -78,195 +78,143 @@ test_case_cl_interf_receive_mme (test_t test)
}
void
+test_case_cl_intef_process_mme_create_mme (cp_t *cp, cp_sta_t *sta,
+ uint fmi_nb_frags,
+ uint fmi_nb,
+ uint fmi_fmsn)
+{
+ u8 buffer[ETH_PACKET_MAX_SIZE];
+ bitstream_t stream;
+ bitstream_write_init (&stream, buffer, ETH_PACKET_MAX_SIZE);
+ /* Store header. */
+ bitstream_write_large (&stream, cp_sta_own_data_get_mac_address (cp),
+ 48);
+ bitstream_write_large (&stream, cp_sta_get_mac_address (sta), 48);
+ bitstream_write (&stream, swap16(HPAV_MTYPE_MME), 16);
+ bitstream_write (&stream, 1, 8);
+ bitstream_write (&stream, 0x3245, 16);
+ bitstream_write (&stream, fmi_nb_frags, 4);
+ bitstream_write (&stream, fmi_nb, 4);
+ bitstream_write (&stream, fmi_fmsn, 8);
+ bitstream_finalise (&stream);
+ cp_cl_interf_rx_mme (cp, cp_sta_get_tei (sta), buffer,
+ ETH_PACKET_MAX_SIZE, NULL, true);
+}
+
+void
+test_case_cl_intef_process_verify (test_t t, cp_sta_t *sta, bool receiving_msg,
+ uint last_seg_nb, uint nb_frags, uint fmsn,
+ bool encrypt)
+{
+ test_within (t);
+ test_fail_unless (sta->reassembly_ctx.receiving_msg == receiving_msg);
+ test_fail_unless (sta->reassembly_ctx.last_seg_nb == last_seg_nb);
+ test_fail_unless (sta->reassembly_ctx.nb_frags == nb_frags);
+ test_fail_unless (sta->reassembly_ctx.fmsn == fmsn);
+ test_fail_unless (sta->reassembly_ctx.encrypt == encrypt);
+ if (receiving_msg)
+ {
+ test_fail_unless (sta->reassembly_ctx.head);
+ /* Verify sequence of segmented messages. */
+ uint ssn = 0;
+ cp_sta_reassembly_ctx_blk_t *reassembly_ctx;
+ for (reassembly_ctx = sta->reassembly_ctx.head;
+ reassembly_ctx;
+ reassembly_ctx = reassembly_ctx->next)
+ {
+ test_fail_unless (reassembly_ctx->ssn == ssn);
+ if (reassembly_ctx->length < BLK_SIZE)
+ ssn++;
+ }
+ }
+ else
+ test_fail_unless (!sta->reassembly_ctx.head);
+}
+
+void
test_case_cl_intef_process_mme (test_t test)
{
cp_t cp;
- bitstream_t bitstream;
- u8 buffer[ETH_PACKET_MAX_SIZE], buffer2[ETH_PACKET_MAX_SIZE];
- void *cl_data = INVALID_PTR;
- test_case_begin (test, "Process the MME");
test_cl_interf_init (&cp);
cp_sta_own_data_set_mac_address (&cp, 0x123456789abcull);
- test_begin (test, "Process a non Fragmented MME")
+ test_case_begin (test, "Fragmented MME");
+ /* Create the station to simulate the MME reception. */
+ cp_net_t *net = cp_sta_mgr_add_avln (&cp, 1, 1);
+ cp_sta_t *sta = cp_sta_mgr_sta_add (&cp, net, 1, 1);
+ cp_sta_mgr_set_our_avln (&cp, net);
+ test_begin (test, "3 segments received ok")
{
- bitstream_write_init (&bitstream, buffer, 23);
- bitstream_write_large (&bitstream, 0x123456789abcull, 48);
- bitstream_write_large (&bitstream, 0x3456789ABCDEull, 48);
- bitstream_write (&bitstream, 0x12, 32);
- bitstream_write (&bitstream, swap16(HPAV_MTYPE_MME), 16);
- bitstream_write (&bitstream, 1, 8);
- bitstream_write (&bitstream, 0x3245, 16);
- bitstream_write (&bitstream, 0, 16);
- bitstream_finalise (&bitstream);
dispatch_mme_rx = NULL;
- /* MME not encrypted. */
- cp_cl_interf_rx_mme (&cp, 1, buffer, 1200, cl_data, false);
- cp_cl_interf_process_mme (&cp);
- test_fail_if (dispatch_mme_rx->encrypt != false);
- 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");
-
- if (dispatch_mme_rx)
- slab_release (dispatch_mme_rx);
-
- /* MME Encrypted. */
- cp_cl_interf_rx_mme (&cp, 1, buffer, 1200, cl_data, true);
+ uint i;
+ for (i = 0; i < 2; i++)
+ {
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, i, 1);
+ cp_cl_interf_process_mme (&cp);
+ test_case_cl_intef_process_verify (test, sta, true, i, 2, 1, true);
+ }
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, 2, 1);
cp_cl_interf_process_mme (&cp);
-
- test_fail_if (dispatch_mme_rx->encrypt != true);
- 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");
-
- if (dispatch_mme_rx)
- slab_release (dispatch_mme_rx);
-
-
- cp_cl_interf_uninit (&cp);
+ test_case_cl_intef_process_verify (test, sta, false, 0, 0, 0, false);
+ while (dispatch_mme_rx->p_frag)
+ {
+ dispatch_mme_rx->p_frag_current = dispatch_mme_rx->p_frag->next;
+ blk_release_desc (dispatch_mme_rx->p_frag);
+ dispatch_mme_rx->p_frag = dispatch_mme_rx->p_frag_current;
+ }
+ slab_release (dispatch_mme_rx);
+ dispatch_mme_rx = NULL;
}
test_end;
-
- test_begin (test, "Process a fragmented MME")
+ test_begin (test, "Following segment mismatch")
{
- bitstream_write_init (&bitstream, buffer, 23);
- bitstream_write_large (&bitstream, 0x123456789ABCull, 48);
- bitstream_write_large (&bitstream, 0x3456789ABCDEull, 48);
- bitstream_write (&bitstream, 0x12, 32);
- bitstream_write (&bitstream, swap16(HPAV_MTYPE_MME), 16);
- bitstream_write (&bitstream, 1, 8);
- bitstream_write (&bitstream, 0x3245, 16);
- /* 2 frags. */
- bitstream_write (&bitstream, 1, 4);
- /* 1st frag. */
- bitstream_write (&bitstream, 0, 4);
- /* SSN. */
- bitstream_write (&bitstream, 1, 4);
- bitstream_finalise (&bitstream);
-
- bitstream_write_init (&bitstream, buffer2, 23);
- bitstream_write_large (&bitstream, 0x123456789ABCull, 48);
- bitstream_write_large (&bitstream, 0x3456789ABCDEull, 48);
- bitstream_write (&bitstream, 0x12, 32);
- bitstream_write (&bitstream, swap16(HPAV_MTYPE_MME), 16);
- bitstream_write (&bitstream, 1, 8);
- bitstream_write (&bitstream, 0x3245, 16);
- /* 2 frags. */
- bitstream_write (&bitstream, 1, 4);
- /* 2sd frag. */
- bitstream_write (&bitstream, 1, 4);
- /* SSN. */
- bitstream_write (&bitstream, 1, 4);
- bitstream_finalise (&bitstream);
-
dispatch_mme_rx = NULL;
- cp_net_t *net = cp_sta_mgr_add_avln (&cp, 1, 1);
- cp_sta_mgr_set_our_avln (&cp, net);
- cp_sta_t *sta = cp_sta_mgr_sta_add (&cp, net, 1, 1);
-
- cp_sta_own_data_set_mac_address (&cp, 0x123456789ABCull);
-
- cp_cl_interf_rx_mme (&cp, 1, buffer, 1200, cl_data, false);
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, 0, 1);
cp_cl_interf_process_mme (&cp);
- cp_cl_interf_rx_mme (&cp, 1, buffer2, 1200, cl_data, false);
+ test_case_cl_intef_process_verify (test, sta, true, 0, 2, 1, true);
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, 2, 1);
cp_cl_interf_process_mme (&cp);
-
- test_fail_if (dispatch_mme_rx->encrypt != false);
- 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");
-
- if (dispatch_mme_rx->p_frag)
- {
- blk_t *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;
- }
- }
-
- if (dispatch_mme_rx)
- slab_release (dispatch_mme_rx);
-
-
- /* First MME not encrypt the second one is encrypted. */
- cp_cl_interf_rx_mme (&cp, 1, buffer, 1200, cl_data, false);
+ test_case_cl_intef_process_verify (test, sta, false, 0, 2, 1, true);
+ test_fail_unless (!dispatch_mme_rx);
+ }
+ test_end;
+ test_begin (test, "Next segment nb frags mismatch")
+ {
+ dispatch_mme_rx = NULL;
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, 0, 1);
cp_cl_interf_process_mme (&cp);
- cp_cl_interf_rx_mme (&cp, 1, buffer2, 1200, cl_data, true);
+ test_case_cl_intef_process_verify (test, sta, true, 0, 2, 1, true);
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 3, 1, 1);
cp_cl_interf_process_mme (&cp);
-
- test_fail_if (dispatch_mme_rx->encrypt != false);
- 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");
-
- if (dispatch_mme_rx->p_frag)
- {
- blk_t *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;
- }
- }
-
- if (dispatch_mme_rx)
- slab_release (dispatch_mme_rx);
-
- /* All MMEs are encrypt. */
- cp_cl_interf_rx_mme (&cp, 1, buffer, 1200, cl_data, true);
+ test_case_cl_intef_process_verify (test, sta, false, 0, 2, 1, true);
+ test_fail_unless (!dispatch_mme_rx);
+ }
+ test_end;
+ test_begin (test, "Next segment fmsn mismatch")
+ {
+ dispatch_mme_rx = NULL;
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, 0, 1);
cp_cl_interf_process_mme (&cp);
- cp_cl_interf_rx_mme (&cp, 1, buffer2, 1200, cl_data, true);
+ test_case_cl_intef_process_verify (test, sta, true, 0, 2, 1, true);
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, 1, 2);
cp_cl_interf_process_mme (&cp);
-
- test_fail_if (dispatch_mme_rx->encrypt != true);
- 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");
-
- if (dispatch_mme_rx->p_frag)
- {
- blk_t *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;
- }
- }
-
- if (dispatch_mme_rx)
- slab_release (dispatch_mme_rx);
- /* Release the station. */
- cp_sta_mgr_sta_remove (&cp, sta);
- slab_release (sta);
+ test_case_cl_intef_process_verify (test, sta, true, 0, 2, 1, true);
+ test_fail_unless (!dispatch_mme_rx);
}
test_end;
- test_begin (test, "VS specific MMV 0")
+ test_begin (test, "Segment received twice")
{
- bitstream_write_init (&bitstream, buffer, 23);
- bitstream_write_large (&bitstream, 0x123456789ABCull, 48);
- bitstream_write_large (&bitstream, 0x3456789ABCDEull, 48);
- bitstream_write (&bitstream, swap16(HPAV_MTYPE_MME), 16);
- bitstream_write (&bitstream, HPAV_MMV0, 8);
- bitstream_write (&bitstream, VS_ETH_STATS, 16);
- bitstream_write (&bitstream, SPC_OUI, OUI_SIZE_BITS);
- bitstream_finalise (&bitstream);
dispatch_mme_rx = NULL;
- cp_cl_interf_rx_mme (&cp, 1, buffer, 60, false, false);
- cp_cl_interf_process_mme (&cp);
+ uint i;
+ for (i = 0; i < 2; i++)
+ {
+ test_case_cl_intef_process_mme_create_mme (&cp, sta, 2, 0, 1);
+ cp_cl_interf_process_mme (&cp);
+ test_case_cl_intef_process_verify (test, sta, true, 0, 2, 1, true);
+ }
test_fail_unless (!dispatch_mme_rx);
}
test_end;
+ slab_release (sta);
test_cl_interf_uninit (&cp);
}
diff --git a/cesar/cp/mme.h b/cesar/cp/mme.h
index c8d96e5dca..9d338dbb7c 100644
--- a/cesar/cp/mme.h
+++ b/cesar/cp/mme.h
@@ -449,9 +449,9 @@ struct cp_mme_tx_t
/* FMI number of fragments. */
uint fmi_nbfrag;
/* FMI Fn mi. */
- uint fmi_fnmi;
- /* Fragment ssn. */
- uint fmi_ssn;
+ uint fmi_nb;
+ /* Fragment Messager Sequence Number. */
+ uint fmi_fmsn;
};
typedef struct cp_mme_tx_t cp_mme_tx_t;
diff --git a/cesar/cp/msg/msg.h b/cesar/cp/msg/msg.h
index 0e4c6f0a5a..c4d3b48ccb 100644
--- a/cesar/cp/msg/msg.h
+++ b/cesar/cp/msg/msg.h
@@ -122,8 +122,8 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
* \param peer peer information
* \param mmtype the MME MMTYPE.
* \param fmi_nbFrag The number of fragments.
- * \param fmi_fnmi the number of the fragment.
- * \param fmi_ssn the sequence number of the fragment.
+ * \param fmi_nb the number of the fragment.
+ * \param fmi_fmsn the sequence number of the fragment.
* \return the newly created message
*
* This function:
@@ -134,7 +134,7 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
*/
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_fnmi, uint fmi_ssn);
+ uint fmi_nbFrag, uint fmi_nb, uint fmi_fmsn);
/**
* Finalise and send a MME.
diff --git a/cesar/cp/msg/src/msg.c b/cesar/cp/msg/src/msg.c
index 045e905510..6a42ce4c81 100644
--- a/cesar/cp/msg/src/msg.c
+++ b/cesar/cp/msg/src/msg.c
@@ -291,7 +291,7 @@ cp_msg_mme_length (cp_mme_tx_t *mme)
{
uint length;
- if (mme->fmi_ssn)
+ if (mme->fmi_nb)
{
length = mme->peer.vlan_tag ? HPAV_MME_HEADER_LEN_WITH_VLAN :
HPAV_MME_HEADER;
@@ -699,12 +699,15 @@ cp_msg_mme_init_encrypted (cp_t *ctx, cp_mme_peer_t *peer,
* \param bs the bitstream.
* \param dpeer the destination peer.
* \param final_peer the final destination peer.
+ * \param fmi_nbFrag the number of fragments.
+ * \param fmi_nb the fragment number.
+ * \param fmi_fmsn the transaction number.
*/
void
cp_msg_mme_write_relay_header (cp_t *ctx, bitstream_t *bs,
cp_mme_peer_t dpeer,
cp_mme_peer_t final_peer,
- uint fmi_nbFrag, uint fmi_fnmi, uint fmi_ssn)
+ uint fmi_nbFrag, uint fmi_nb, uint fmi_fmsn)
{
dbg_assert (ctx);
dbg_assert (bs);
@@ -728,8 +731,8 @@ cp_msg_mme_write_relay_header (cp_t *ctx, bitstream_t *bs,
bitstream_write (bs, CC_RELAY_REQ,
BYTES_SIZE_TO_BITS (HPAV_MMTYPE_SIZE));
bitstream_write (bs, fmi_nbFrag, 4);
- bitstream_write (bs, fmi_fnmi, 4);
- bitstream_write (bs, fmi_ssn, 8);
+ bitstream_write (bs, fmi_nb, 4);
+ bitstream_write (bs, fmi_fmsn, 8);
/* Store the beginning of the CC RELAY MME.*/
bitstream_write_large (bs, final_peer.mac, 48);
@@ -780,8 +783,8 @@ cp_msg_mme_write_relay (cp_t *ctx, bitstream_t *bs, cp_mme_tx_t *msg)
cp_msg_mme_write_relay_header (ctx, bs, msg->peer,
msg->final_peer,
msg->fmi_nbfrag,
- msg->fmi_fnmi,
- msg->fmi_ssn);
+ msg->fmi_nb,
+ msg->fmi_fmsn);
slab_release (fdestpco);
}
}
@@ -803,7 +806,7 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
{
cp_msg_mme_write_relay_header (ctx, bs, msg->peer,
msg->final_peer, msg->fmi_nbfrag,
- msg->fmi_fnmi, msg->fmi_ssn);
+ msg->fmi_nb, msg->fmi_fmsn);
}
else
{
@@ -824,38 +827,21 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
bitstream_write (bs, mmtype,
BYTES_SIZE_TO_BITS (HPAV_MMTYPE_SIZE));
bitstream_write (bs, msg->fmi_nbfrag, 4);
- bitstream_write (bs, msg->fmi_fnmi, 4);
- bitstream_write (bs, msg->fmi_ssn, 8);
+ bitstream_write (bs, msg->fmi_nb, 4);
+ bitstream_write (bs, msg->fmi_fmsn, 8);
if (mmtype >= VS_MIN && mmtype <= VS_MAX)
bitstream_write (bs, SPC_OUI, OUI_SIZE_BITS);
}
-/**
- * Initialise a MME handle for a new message fragment to be transmitted.
- * \param ctx control plane context
- * \param peer peer information
- * \param mmtype the MME MMTYPE.
- * \param fmi_nbFrag The number of fragments.
- * \param fmi_fnmi the number of the fragment.
- * \param fmi_ssn the sequence number of the fragment.
- * \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_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_fnmi, uint fmi_ssn)
+ uint fmi_nbFrag, uint fmi_nb, uint fmi_fmsn)
{
cp_mme_tx_t *msg;
dbg_assert (ctx);
dbg_assert (peer);
- dbg_assert (fmi_fnmi <= fmi_nbFrag);
- dbg_assert (fmi_ssn <= fmi_nbFrag);
+ dbg_assert (fmi_nb <= fmi_nbFrag);
// Allocate the new message.
msg = cp_msg_mme_tx_init (ctx);
@@ -868,8 +854,8 @@ cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
msg->peks = CP_MME_PEKS_SPC_NOT_EMBEDDED;
msg->fmi_nbfrag = fmi_nbFrag;
- msg->fmi_fnmi = fmi_fnmi;
- msg->fmi_ssn = fmi_ssn;
+ msg->fmi_nb = fmi_nb;
+ msg->fmi_fmsn = fmi_fmsn;
msg->mmtype = mmtype;
// Initialise the bitstream context and fill the MME header.
@@ -1346,8 +1332,7 @@ cp_msg_mme_tx_change_buffer (bitstream_t *bs, cp_mme_tx_t *mme)
bitstream_t header_bs;
bitstream_write_init (&header_bs, mme->p_mme, ETH_PACKET_MAX_SIZE);
- mme->fmi_fnmi++;
- mme->fmi_ssn++;
+ mme->fmi_nb++;
cp_msg_mme_write_frag_header (mme->cp, mme, &header_bs,
mme->mmtype);
diff --git a/cesar/cp/msg/test/src/cc_discover_list.c b/cesar/cp/msg/test/src/cc_discover_list.c
index bc131dc30c..4e98b90444 100644
--- a/cesar/cp/msg/test/src/cc_discover_list.c
+++ b/cesar/cp/msg/test/src/cc_discover_list.c
@@ -25,66 +25,100 @@
static u8 buffer[2][2048];
static uint buffer_index = 0;
+struct test_cc_discover_list_t
+{
+ cp_t cp;
+ mac_config_t mac_config;
+};
+typedef struct test_cc_discover_list_t test_cc_discover_list_t;
+
+static void
+test_cc_discover_list_init (test_cc_discover_list_t *ctx)
+{
+ memset (ctx, 0, sizeof (test_cc_discover_list_t));
+ cp_msg_init (&ctx->cp);
+ cp_sta_mgr_init (&ctx->cp);
+ ctx->cp.mac_config = &ctx->mac_config;
+ cp_sta_own_data_set_mac_address (
+ &ctx->cp, MAC_ADDRESS (0x00, 0x13, 0xd7, 0x00, 0x00, 0x01));
+};
+
+static void
+test_cc_discover_list_uninit (test_cc_discover_list_t *ctx)
+{
+ cp_sta_mgr_uninit (&ctx->cp);
+ cp_msg_uninit (&ctx->cp);
+}
+
+void
+test_check_mme_header (test_t test, bitstream_t *s, u8 *buffer, mac_t dmac,
+ mac_t smac, u32 vlantag, cp_mmtype_t mmtype,
+ uint fmi_nbfrags, uint fmi_nb, uint fmi_fmsn)
+{
+ test_within (test);
+ bitstream_read_init (s, buffer, ETH_PACKET_MAX_SIZE);
+ test_fail_unless (bitstream_read_large (s, 48) == dmac);
+ test_fail_unless (bitstream_read_large (s, 48) == smac);
+ if (vlantag)
+ test_fail_unless (bitstream_read (s, 32) == vlantag);
+ test_fail_unless (bitstream_read (s, 16) == swap16(HPAV_MTYPE_MME));
+ test_fail_unless (bitstream_read (s, 8) == HPAV_MMV);
+ test_fail_unless (bitstream_read (s, 16) == mmtype);
+ test_fail_unless (bitstream_read (s, 4) == fmi_nbfrags);
+ test_fail_unless (bitstream_read (s, 4) == fmi_nb);
+ test_fail_unless (bitstream_read (s, 8) == fmi_fmsn);
+}
+
static void
test_change_buffer (bitstream_t *bs, u8 *buffer)
{
uint header = 19;
- bitstream_set_buffer (bs, buffer + header,
- ETH_PACKET_MAX_SIZE - header);
+ bitstream_set_buffer (bs, buffer + header, ETH_PACKET_MAX_SIZE - header);
}
void
test_case__cc_discover_list_req (test_t test)
{
- cp_t cp;
- memset (&cp, 0, sizeof (cp_t));
-
+ test_cc_discover_list_t ctx;
+ test_cc_discover_list_init (&ctx);
test_case_begin (test, "CC_DISCOVER_LIST.REQ");
-
test_begin (test, "send a discover_list.req")
{
- u8 *buffer_current = buffer[buffer_index];
+ bitstream_t s;
cp_mme_peer_t peer;
- cp_msg_init (&cp);
-
/* configure the Peer. */
peer.mac = 0x23456789ABCDull;
peer.vlan_tag = 0x0;
peer.tei = 0xA;
-
- cp_msg_cc_discover_list_req_send (&cp, &peer);
-
- test_fail_if (*(buffer_current + 19) != 0);
- }
- test_end;
-
- test_begin (test, "received a discover_list.req")
- {
+ /* Launch the test. */
+ cp_msg_cc_discover_list_req_send (&ctx.cp, &peer);
+ test_check_mme_header (test, &s, buffer[0], peer.mac,
+ cp_sta_own_data_get_mac_address (&ctx.cp),
+ peer.vlan_tag, CC_DISCOVER_LIST_REQ, 0, 0, 0);
+ test_fail_unless (bitstream_read (&s, 32) == 0);
+ bitstream_finalise (&s);
+ /* Read it with the correct function. */
cp_mme_rx_t mme;
- bool res;
-
mme.length = 60;
- mme.p_mme = buffer[buffer_index - 1];
- bitstream_read_init (&mme.bitstream, mme.p_mme + 19, 60);
-
- res = cp_msg_cc_discover_list_req_receive (&cp, &mme);
-
- test_fail_if (res != true);
+ mme.p_mme = buffer[0];
+ test_check_mme_header (test, &mme.bitstream, buffer[0], peer.mac,
+ cp_sta_own_data_get_mac_address (&ctx.cp),
+ peer.vlan_tag, CC_DISCOVER_LIST_REQ, 0, 0, 0);
+ test_fail_unless (cp_msg_cc_discover_list_req_receive (&ctx.cp, &mme));
}
test_end;
+ test_cc_discover_list_uninit (&ctx);
}
void
test_case__cc_discover_list_cnf_send (test_t test)
{
test_case_begin (test, "CC_DISCOVER_LIST.CNF");
-
test_begin (test, "Simple discover list")
{
- mac_config_t mc;
- cp_t cp;
- cp.mac_config = &mc;
- mac_config_init (&mc);
+ test_cc_discover_list_t ctx;
+ test_cc_discover_list_init (&ctx);
+ buffer_index = 0;
uint nb_sta = 10;
uint nb_net = 2;
uint i;
@@ -94,7 +128,6 @@ test_case__cc_discover_list_cnf_send (test_t test)
cp_mme_peer_t peer;
cp_msg_cc_discover_list_ctx_t disc_ctx;
bitstream_t bitstream;
- u8 *buffer_first = buffer[buffer_index];
cp_net_t *net;
cp_sta_t *sta;
@@ -138,47 +171,38 @@ test_case__cc_discover_list_cnf_send (test_t test)
nets[i].offset = 0;
}
- cp_msg_init (&cp);
- cp_sta_mgr_init (&cp);
-
/* Add the peer station to the station manager to avoid a relay MME
* call init function. */
- net = cp_sta_mgr_add_avln (&cp, 1, 1);
- sta = cp_sta_mgr_sta_add (&cp, net, peer.tei, peer.mac);
+ net = cp_sta_mgr_add_avln (&ctx.cp, 1, 1);
+ sta = cp_sta_mgr_sta_add (&ctx.cp, net, peer.tei, peer.mac);
slab_release (sta);
- mme = cp_msg_cc_discover_list_cnf_send_begin (&cp, &peer, nb_sta,
+ mme = cp_msg_cc_discover_list_cnf_send_begin (&ctx.cp, &peer, nb_sta,
nb_net, &disc_ctx);
- cp_msg_cc_discover_list_cnf_send_stations_begin (&cp, mme,
+ cp_msg_cc_discover_list_cnf_send_stations_begin (&ctx.cp, mme,
&disc_ctx);
for (i = 0; i < nb_sta; i++)
- cp_msg_cc_discover_list_cnf_send_station (&cp, mme, &stas[i]);
- cp_msg_cc_discover_list_cnf_send_net_begin (&cp, mme, &disc_ctx);
+ cp_msg_cc_discover_list_cnf_send_station (&ctx.cp, mme, &stas[i]);
+ cp_msg_cc_discover_list_cnf_send_net_begin (&ctx.cp, mme, &disc_ctx);
for (i = 0; i < nb_net; i++)
- cp_msg_cc_discover_list_cnf_send_net (&cp, mme, &nets[i]);
- cp_msg_cc_discover_list_cnf_send_end (&cp, mme);
+ cp_msg_cc_discover_list_cnf_send_net (&ctx.cp, mme, &nets[i]);
+ cp_msg_cc_discover_list_cnf_send_end (&ctx.cp, mme);
/* Verify. */
- test_fail_if (*(buffer_first + 19) != nb_sta);
- test_fail_if (*(buffer_first + 140) != nb_net);
-
- bitstream_read_init (&bitstream, buffer_first + 20,
- ETH_PACKET_MAX_SIZE - 20);
+ test_check_mme_header (test, &bitstream, buffer[0], peer.mac,
+ cp_sta_own_data_get_mac_address (&ctx.cp),
+ peer.vlan_tag, CC_DISCOVER_LIST_CNF, 0, 0, 0);
+ test_fail_unless (bitstream_read (&bitstream, 8) == nb_sta);
for ( i = 0; i < nb_sta; i++)
{
- uint unused;
memset (&sta_read, 0, sizeof (cp_msg_cc_discover_list_sta_t));
-
bitstream_access (&bitstream, &sta_read.mac_addr, 48);
bitstream_access (&bitstream, &sta_read.tei, 8);
bitstream_access (&bitstream, &sta_read.same_network, 8);
bitstream_access (&bitstream, &sta_read.snid, 4);
bitstream_access (&bitstream, &sta_read.access, 4);
-
/* reserved */
- unused = 0;
- bitstream_access (&bitstream, &unused, 1);
-
+ bitstream_read (&bitstream, 1);
/* Continue */
bitstream_access (&bitstream, &sta_read.cco_cap, 2);
bitstream_access (&bitstream, &sta_read.proxy_cap, 1);
@@ -189,19 +213,14 @@ test_case__cc_discover_list_cnf_send (test_t test)
bitstream_access (&bitstream, &sta_read.signal_level, 8);
bitstream_access (&bitstream, &sta_read.average_ble, 8);
- test_fail_if (memcmp (&sta_read, &stas[i],
- sizeof (cp_msg_cc_discover_list_sta_t))
- != 0);
+ test_fail_unless (memcmp (&sta_read, &stas[i],
+ sizeof (cp_msg_cc_discover_list_sta_t))
+ == 0);
}
- bitstream_finalise (&bitstream);
-
-
- bitstream_read_init (&bitstream, buffer_first + 141,
- ETH_PACKET_MAX_SIZE - 141);
+ test_fail_unless (bitstream_read (&bitstream, 8) == nb_net);
for ( i = 0; i < nb_net; i++)
{
memset (&net_read, 0, sizeof (cp_msg_cc_discover_list_net_t));
-
bitstream_access (&bitstream, &net_read.nid, 56);
bitstream_access (&bitstream, &net_read.snid, 4);
bitstream_access (&bitstream, &net_read.access, 4);
@@ -209,21 +228,20 @@ test_case__cc_discover_list_cnf_send (test_t test)
bitstream_access (&bitstream, &net_read.numslots, 8);
bitstream_access (&bitstream, &net_read.coordinated_status, 8);
bitstream_access (&bitstream, &net_read.offset, 16);
-
- test_fail_if (memcmp (&net_read, &nets[i],
- sizeof (cp_msg_cc_discover_list_net_t))
- != 0);
+ test_fail_unless (memcmp (&net_read, &nets[i],
+ sizeof (cp_msg_cc_discover_list_net_t))
+ == 0);
}
bitstream_finalise (&bitstream);
-
- cp_msg_uninit (&cp);
- cp_sta_mgr_uninit (&cp);
+ test_cc_discover_list_uninit (&ctx);
}
test_end;
test_begin (test, "Complex discover list")
{
- cp_t cp;
+ test_cc_discover_list_t ctx;
+ test_cc_discover_list_init (&ctx);
+ buffer_index = 0;
uint nb_sta = 150;
uint nb_net = 2;
uint i;
@@ -233,9 +251,6 @@ test_case__cc_discover_list_cnf_send (test_t test)
cp_mme_peer_t peer;
cp_msg_cc_discover_list_ctx_t disc_ctx;
bitstream_t bitstream;
- u8 *buffer_first = buffer[buffer_index];
- u8 *buffer_second = buffer [(buffer_index + 1) % 2];
-
cp_msg_cc_discover_list_net_t net_read;
cp_msg_cc_discover_list_sta_t sta_read;
@@ -277,44 +292,35 @@ test_case__cc_discover_list_cnf_send (test_t test)
nets[i].offset = 0;
}
- cp_msg_init (&cp);
-
- mme = cp_msg_cc_discover_list_cnf_send_begin (&cp, &peer, nb_sta,
+ mme = cp_msg_cc_discover_list_cnf_send_begin (&ctx.cp, &peer, nb_sta,
nb_net, &disc_ctx);
- cp_msg_cc_discover_list_cnf_send_stations_begin (&cp, mme,
+ cp_msg_cc_discover_list_cnf_send_stations_begin (&ctx.cp, mme,
&disc_ctx);
for (i = 0; i < nb_sta; i++)
- cp_msg_cc_discover_list_cnf_send_station (&cp, mme, &stas[i]);
- cp_msg_cc_discover_list_cnf_send_net_begin (&cp, mme, &disc_ctx);
+ cp_msg_cc_discover_list_cnf_send_station (&ctx.cp, mme, &stas[i]);
+ cp_msg_cc_discover_list_cnf_send_net_begin (&ctx.cp, mme, &disc_ctx);
for (i = 0; i < nb_net; i++)
- cp_msg_cc_discover_list_cnf_send_net (&cp, mme, &nets[i]);
- cp_msg_cc_discover_list_cnf_send_end (&cp, mme);
+ cp_msg_cc_discover_list_cnf_send_net (&ctx.cp, mme, &nets[i]);
+ cp_msg_cc_discover_list_cnf_send_end (&ctx.cp, mme);
/* Verify. */
- test_fail_if (*(buffer_first + 19) != nb_sta);
- test_fail_if (*(buffer_second + 321) != nb_net);
-
- bitstream_read_init (&bitstream, buffer_first + 20,
- ETH_PACKET_MAX_SIZE - 20);
-
+ test_check_mme_header (test, &bitstream, buffer[0], peer.mac,
+ cp_sta_own_data_get_mac_address (&ctx.cp),
+ peer.vlan_tag, CC_DISCOVER_LIST_CNF, 1, 0, 0);
+ test_fail_unless (bitstream_read (&bitstream, 8) == nb_sta);
bitstream_init_buffer_cb (
&bitstream,
- (bitstream_buffer_cb_t) test_change_buffer, buffer_second);
+ (bitstream_buffer_cb_t) test_change_buffer, buffer[1]);
for ( i = 0; i < nb_sta; i++)
{
- uint unused;
memset (&sta_read, 0, sizeof (cp_msg_cc_discover_list_sta_t));
-
bitstream_access (&bitstream, &sta_read.mac_addr, 48);
bitstream_access (&bitstream, &sta_read.tei, 8);
bitstream_access (&bitstream, &sta_read.same_network, 8);
bitstream_access (&bitstream, &sta_read.snid, 4);
bitstream_access (&bitstream, &sta_read.access, 4);
-
/* reserved */
- unused = 0;
- bitstream_access (&bitstream, &unused, 1);
-
+ bitstream_read (&bitstream, 1);
/* Continue */
bitstream_access (&bitstream, &sta_read.cco_cap, 2);
bitstream_access (&bitstream, &sta_read.proxy_cap, 1);
@@ -325,18 +331,14 @@ test_case__cc_discover_list_cnf_send (test_t test)
bitstream_access (&bitstream, &sta_read.signal_level, 8);
bitstream_access (&bitstream, &sta_read.average_ble, 8);
- test_fail_if (memcmp (&sta_read, &stas[i],
- sizeof (cp_msg_cc_discover_list_sta_t))
- != 0);
+ test_fail_unless (memcmp (&sta_read, &stas[i],
+ sizeof (cp_msg_cc_discover_list_sta_t))
+ == 0);
}
- bitstream_finalise (&bitstream);
-
- bitstream_read_init (&bitstream, buffer_second + 322,
- ETH_PACKET_MAX_SIZE - 322);
+ test_fail_unless (bitstream_read (&bitstream, 8) == nb_net);
for ( i = 0; i < nb_net; i++)
{
memset (&net_read, 0, sizeof (cp_msg_cc_discover_list_net_t));
-
bitstream_access (&bitstream, &net_read.nid, 56);
bitstream_access (&bitstream, &net_read.snid, 4);
bitstream_access (&bitstream, &net_read.access, 4);
@@ -344,14 +346,17 @@ test_case__cc_discover_list_cnf_send (test_t test)
bitstream_access (&bitstream, &net_read.numslots, 8);
bitstream_access (&bitstream, &net_read.coordinated_status, 8);
bitstream_access (&bitstream, &net_read.offset, 16);
-
- test_fail_if (memcmp (&net_read, &nets[i],
- sizeof (cp_msg_cc_discover_list_net_t))
- != 0);
+ test_fail_unless (memcmp (&net_read, &nets[i],
+ sizeof (cp_msg_cc_discover_list_net_t))
+ == 0);
}
bitstream_finalise (&bitstream);
+ /* check the header of the second MME. */
+ test_check_mme_header (test, &bitstream, buffer[1], peer.mac,
+ cp_sta_own_data_get_mac_address (&ctx.cp),
+ peer.vlan_tag, CC_DISCOVER_LIST_CNF, 1, 1, 0);
- cp_msg_uninit (&cp);
+ test_cc_discover_list_uninit (&ctx);
}
test_end;
}
@@ -642,6 +647,7 @@ main (int argc, char **argv)
{
test_t test;
test_init (test, argc, argv);
+ test_suite_begin (test, "CC DISCOVER LIST");
test_case__cc_discover_list_req (test);
test_case__cc_discover_list_cnf_send (test);
test_case__cc_discover_list_cnf_recv (test);
diff --git a/cesar/cp/msg/test/src/relay.c b/cesar/cp/msg/test/src/relay.c
index e0b9a35727..bf2dc7607f 100644
--- a/cesar/cp/msg/test/src/relay.c
+++ b/cesar/cp/msg/test/src/relay.c
@@ -48,9 +48,9 @@ struct mme_header_t
mac_t osa;
uint vlan;
cp_mmtype_t mmtype;
- uint fmi_inf;
- uint fmi_mi;
- uint fmi_ssn;
+ uint fmi_nbfrag;
+ uint fmi_nb;
+ uint fmi_fmsn;
};
typedef struct mme_header_t mme_header_t;
@@ -76,9 +76,9 @@ test_read_header (test_t test, bitstream_t *stream, mme_header_t *expected,
bitstream_access (stream, &mtype, 16);
bitstream_access (stream, &mmv, 8);
bitstream_access (stream, &header_read.mmtype, 16);
- bitstream_access (stream, &header_read.fmi_inf, 4);
- bitstream_access (stream, &header_read.fmi_mi, 4);
- bitstream_access (stream, &header_read.fmi_ssn, 8);
+ bitstream_access (stream, &header_read.fmi_nbfrag, 4);
+ bitstream_access (stream, &header_read.fmi_nb, 4);
+ bitstream_access (stream, &header_read.fmi_fmsn, 8);
test_begin (test, "Header")
{
@@ -87,9 +87,9 @@ test_read_header (test_t test, bitstream_t *stream, mme_header_t *expected,
test_fail_if (mtype != swap16(HPAV_MTYPE_MME));
test_fail_if (mmv != HPAV_MMV);
test_fail_if (header_read.mmtype != expected->mmtype);
- test_fail_if (header_read.fmi_inf != expected->fmi_inf);
- test_fail_if (header_read.fmi_mi != expected->fmi_mi);
- test_fail_if (header_read.fmi_ssn != expected->fmi_ssn);
+ test_fail_if (header_read.fmi_nbfrag != expected->fmi_nbfrag);
+ test_fail_if (header_read.fmi_nb != expected->fmi_nb);
+ test_fail_if (header_read.fmi_fmsn != expected->fmi_fmsn);
}
test_end;
}
@@ -821,19 +821,21 @@ test_case_msg_mme_change_buffer_tx (test_t test)
test_this_test_init ();
- mme = cp_msg_mme_init_frag (&cp, &peer, CC_SET_TEI_MAP_REQ, 1, 0, 0);
+ mme = cp_msg_mme_init_frag (&cp, &peer, CC_SET_TEI_MAP_REQ, 1, 0, 1);
test_fail_unless (mme->relay == true);
mme->bitstream.data_bits = 0;
mme->bitstream.data = NULL;
cp_msg_mme_tx_change_buffer (&mme->bitstream, mme);
+ /* TX buffer is changed, fmi_nb is incremented in
+ * cp_msg_mme_tx_change_buffer */
memset (&expected, 0, sizeof (mme_header_t));
expected.oda = PCO_MAC;
expected.osa = OWN_MAC;
expected.mmtype = CC_RELAY_REQ;
- expected.fmi_inf = 1;
- expected.fmi_mi = 1;
- expected.fmi_ssn = 1;
+ expected.fmi_nbfrag = 1;
+ expected.fmi_nb = 1;
+ expected.fmi_fmsn = 1;
test_fail_unless (mme->relay == true);
@@ -852,9 +854,9 @@ test_case_msg_mme_change_buffer_tx (test_t test)
expected.oda = STA_MAC;
expected.osa = OWN_MAC;
expected.mmtype = mme->mmtype;
- expected.fmi_inf = 1;
- expected.fmi_mi = 1;
- expected.fmi_ssn = 1;
+ expected.fmi_nbfrag = 1;
+ expected.fmi_nb = 1;
+ expected.fmi_fmsn = 1;
test_read_header (test, &bs, &expected, false);
test_fail_unless (bitstream_read (&bs, 32) == 0);
diff --git a/cesar/cp/sta/mgr/sta.h b/cesar/cp/sta/mgr/sta.h
index 648db088ea..cb52df22b2 100644
--- a/cesar/cp/sta/mgr/sta.h
+++ b/cesar/cp/sta/mgr/sta.h
@@ -46,8 +46,14 @@ typedef struct cp_sta_reassembly_ctx_blk_t cp_sta_reassembly_ctx_blk_t;
/** Reassembly context. */
struct cp_sta_reassembly_ctx_t
{
+ /** Message is being received. */
+ bool receiving_msg;
/** Last segment received. */
- uint last_seg_ssn;
+ uint last_seg_nb;
+ /** Number of fragments. */
+ uint nb_frags;
+ /** Transaction sequence number. */
+ uint fmsn;
/** Encrypted by the hardware. */
bool encrypt;
/** MME fragment head. */