summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/mac/sar/src/sar.c93
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/detect_mf.c3
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/misc.c3
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/reassembly.c52
4 files changed, 81 insertions, 70 deletions
diff --git a/cesar/mac/sar/src/sar.c b/cesar/mac/sar/src/sar.c
index 87bc0cde29..58e584925f 100644
--- a/cesar/mac/sar/src/sar.c
+++ b/cesar/mac/sar/src/sar.c
@@ -1469,35 +1469,29 @@ sar_rx_mfs_detect_and_reconstitute_mf__possible (sar_t *ctx, mfs_rx_t *mfs,
dbg_assert (mfs);
dbg_assert (pb);
dbg_assert (sar_mf);
-
- /* Does a MF exists in the PB ? */
- if (pb->header.mfbf)
+ dbg_assert (pb->header.mfbf);
+ /* Get the Mac Frame header. */
+ sar_mf_header (pb, pb->header.mfbo, sar_mf);
+ /* Frame is present and the length is correct ? */
+ if ((sar_mf->type != SAR_MF_TYPE_NONE)
+ && sar_mf->header_complete
+ && (sar_mf->length <= ETH_PACKET_MAX_SIZE)
+ && (sar_mf->length >= ETH_PACKET_MIN_SIZE_ALLOWED))
{
- /* Get the Mac Frame header. */
- sar_mf_header (pb, pb->header.mfbo, sar_mf);
-
- /* Frame is present and the length is correct ? */
- if ((sar_mf->type != SAR_MF_TYPE_NONE)
- && sar_mf->header_complete
- && (sar_mf->length <= ETH_PACKET_MAX_SIZE)
- && (sar_mf->length >= ETH_PACKET_MIN_SIZE_ALLOWED))
+ /* Check the MF Type with the MFS type. */
+ if ((sar_mf->type == SAR_MF_TYPE_MME)
+ && (mfs->common.mme == true))
+ return true;
+ else
{
- /* Check the MF Type with the MFS type. */
- if ((sar_mf->type == SAR_MF_TYPE_MME)
- && (mfs->common.mme == true))
+ if ((sar_mf->type == SAR_MF_TYPE_DATA)
+ && (mfs->common.ats == false))
+ return true;
+ else if ((sar_mf->type == SAR_MF_TYPE_DATA_ATS)
+ && (mfs->common.ats == true))
return true;
- else
- {
- if ((sar_mf->type == SAR_MF_TYPE_DATA)
- && (mfs->common.ats == false))
- return true;
- else if ((sar_mf->type == SAR_MF_TYPE_DATA_ATS)
- && (mfs->common.ats == true))
- return true;
- }
}
}
-
return false;
}
@@ -1510,7 +1504,7 @@ sar_rx_mfs_detect_and_reconstitute_mf__possible (sar_t *ctx, mfs_rx_t *mfs,
*
* A MAC Frame is present in the PBs from the MFS's head to pb_mf_ends, the
* function will use the informations read from the MFS's head PB to create a
- * job for the Bridge DMA and provide the PBs contining the MAC Frame to
+ * job for the Bridge DMA and provide the PBs containing the MAC Frame to
* reconstitute.
*/
inline sar_job_mfs_t *
@@ -1519,7 +1513,6 @@ sar_rx_mfs_detect_and_reconstitute_mf__create_job (sar_t *ctx, mfs_rx_t *mfs,
pb_t *pb_mf_ends)
{
sar_job_mfs_t *job;
- sar_mf_t new_mf;
dbg_assert (ctx);
dbg_assert (mfs);
dbg_assert (sar_mf);
@@ -1557,24 +1550,11 @@ sar_rx_mfs_detect_and_reconstitute_mf__create_job (sar_t *ctx, mfs_rx_t *mfs,
#if CONFIG_SAR_BRG_JOB_ERROR
job->job.mf_header1 = 0xdeaddead;
#endif
-
- /* If the pb_mf_ends does not have a MAC Frame start, MFS's head should
- * point to the next PB. */
- if (!pb_mf_ends->header.mfbf)
- mfs->head = pb_mf_ends->next;
- else
- {
- sar_mf_header (pb_mf_ends, pb_mf_ends->header.mfbo, &new_mf);
- if (new_mf.type != SAR_MF_TYPE_NONE)
- {
- mfs->head = pb_mf_ends;
- blk_addref_desc ((blk_t *) pb_mf_ends);
- }
- else
- mfs->head = pb_mf_ends->next;
- }
+ /* Add a reference on the last PB without trying to check if another mac
+ * Frame is present, the parent will do it in the next loop. */
+ blk_addref_desc (&pb_mf_ends->blk);
blk_addref ((blk_t *) mfs);
-
+ mfs->head = pb_mf_ends;
return job;
}
@@ -1596,8 +1576,8 @@ sar_rx_mfs_detect_and_reconstitute_mf (sar_t *ctx, mfs_rx_t *mfs)
while (mfs->head
&& lesseq_mod2p16 (mfs->head->header.ssn, mfs->ssn_min))
{
- /* Verify type. */
- if (sar_rx_mfs_detect_and_reconstitute_mf__possible (
+ if (mfs->head->header.mfbf
+ && sar_rx_mfs_detect_and_reconstitute_mf__possible (
ctx, mfs, mfs->head, &sar_mf))
{
pb_t *pb_mf_ends;
@@ -1625,16 +1605,15 @@ sar_rx_mfs_detect_and_reconstitute_mf (sar_t *ctx, mfs_rx_t *mfs)
/* Not enough memory available, drop the frame. */
SAR_TRACE (EXHAUSTED_MEMORY, mfs->head->header.ssn,
pb_mf_ends->header.ssn);
- if (pb_mf_ends->header.mfbf)
- blk_addref_desc ((blk_t*) pb_mf_ends);
- blk_release_desc_range ((blk_t*) mfs->head,
- (blk_t*) pb_mf_ends);
+ pb_t *pb = mfs->head;
+ blk_addref_desc (&pb_mf_ends->blk);
mfs->head = pb_mf_ends;
+ blk_release_desc_range (&pb->blk, &pb_mf_ends->blk);
}
}
/* The segments are not contiguous and the missing PBs are outside
* the window. */
- if (less_mod2p16 (pb_mf_ends->header.ssn + 1, mfs->ssn_min))
+ else if (less_mod2p16 (pb_mf_ends->header.ssn + 1, mfs->ssn_min))
{
/* Next PB is outside the window. */
if (mfs->head == pb_mf_ends)
@@ -1656,19 +1635,19 @@ sar_rx_mfs_detect_and_reconstitute_mf (sar_t *ctx, mfs_rx_t *mfs)
/* Stop the loop. */
break;
}
- /* MAC Frame header read from the PB is not complete and the next PB
- * is in the MFS window. If not missing PB will never be received. */
- else if (!sar_mf.header_complete
- && sar_mf.type != SAR_MF_TYPE_NONE
- && (u16) (mfs->head->header.ssn + 1) >= mfs->ssn_min)
+ /* PB have got a MF boundary and the data read in the PB is
+ * incomplete and the next PB is after the SSN min i.e. it can be
+ * receive. */
+ else if (mfs->head->header.mfbf
+ && !sar_mf.header_complete
+ && lesseq_mod2p16 (mfs->ssn_min, mfs->head->header.ssn + 1))
{
job = NULL;
break;
}
- /* Impossible to reassembly the Mac Frame i.e. the PB is corrupt. */
+ /* Impossible to reassembly the Mac Frame. */
else
{
- /* Next PB is outside the window. */
SAR_TRACE (PB_EMPTY, mfs->head->header.ssn,
mfs->head->header.mfbo);
pb_missing += sar_stats_rx_gap_between_pb_ssn_min (
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/detect_mf.c b/cesar/mac/sar/test/unit_test/ecos/src/detect_mf.c
index ffe327ddae..c5ad09052d 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/detect_mf.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/detect_mf.c
@@ -91,6 +91,7 @@ test_case_sar_detect_mf (test_t test)
test_fail_unless (job->pb_quantity == 3);
/* Remove the add ref done by sar_rx_mfs_detect_and_reconstitute_mf. */
+ blk_release_desc (&mfs->head->blk);
blk_release (mfs);
/* Remove the references from this test. */
@@ -272,6 +273,8 @@ test_case_sar_detect_mf_all_pb_offset (test_t test)
/* Release the references. */
if (job->job.next)
blk_release (job->job.next);
+ if (mfs->head)
+ blk_release_desc (&mfs->head->blk);
blk_release (job);
blk_release (mfs);
}
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/misc.c b/cesar/mac/sar/test/unit_test/ecos/src/misc.c
index 1ca9a8556d..1cd7a4d912 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/misc.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/misc.c
@@ -105,6 +105,9 @@ test_case_misc__add_pending_jobs_add_one_rx (sar_test_t *t, bool data)
slist_push_back (t->sar->data_ctx.jobs_pending_list., job, bare);
else
slist_push_back (t->sar->mme_ctx.jobs_pending_list., job, bare);
+ /* Release the reference on the last PB which is duplicated. */
+ blk_release_desc (&mfs->head->blk);
+ mfs->head = NULL;
blk_release (mfs);
}
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/reassembly.c b/cesar/mac/sar/test/unit_test/ecos/src/reassembly.c
index c2fcf91aa2..f9e4edcfbd 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/reassembly.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/reassembly.c
@@ -1133,22 +1133,48 @@ test_case_reassembly_exhausted_memory (test_t test)
sar_test_t t;
sar_mpdu_t mpdu;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
- memset (&mpdu, 0, sizeof (sar_mpdu_t));
/* Change free blocks to realize the test. */
head = blk_alloc_desc_range (CONFIG_BLK_NB - CONFIG_BLK_SLACK, &tail);
test_fail_unless (blk_slack () == false);
- /* Create an MPDU */
- sar_test_mpdu_data_create (&mpdu, 6, 0, 0x43, false);
- sar_activate (t.sar, true);
- mpdu.rx.params.lid = 1;
- mpdu.rx.params.tei = 1;
- sar_test_reassembly_done_init (&t);
- sar_reassembly_run (t.sar, &mpdu);
- test_fail_unless (t.rea_done.buffer == INVALID_PTR);
- test_fail_unless (t.rea_done.length == 0xdeaddead);
- test_fail_unless (t.rea_done.mfs == INVALID_PTR);
- test_fail_unless (t.rea_done.encrypted == false);
- sar_cleanup (t.sar);
+ uint i;
+ for (i = 0; i < 2; i++)
+ {
+ /* Create an MPDU */
+ memset (&mpdu, 0, sizeof (sar_mpdu_t));
+ sar_test_mpdu_data_create (&mpdu, 6, 0, 0x43, false);
+ if (i)
+ {
+ bitstream_direct_write (mpdu.rx.pb_last->data, 488*8,
+ SAR_MF_TYPE_DATA, 2);
+ bitstream_direct_write (mpdu.rx.pb_last->data, 488*8 + 2,
+ 1517, 14);
+ mpdu.rx.pb_last->header.mfbf = true;
+ mpdu.rx.pb_last->header.mfbo = 488;
+ }
+ sar_activate (t.sar, true);
+ mpdu.rx.params.lid = 1;
+ mpdu.rx.params.tei = 1;
+ sar_test_reassembly_done_init (&t);
+ sar_reassembly_run (t.sar, &mpdu);
+ test_fail_unless (t.rea_done.buffer == INVALID_PTR);
+ test_fail_unless (t.rea_done.length == 0xdeaddead);
+ test_fail_unless (t.rea_done.mfs == INVALID_PTR);
+ test_fail_unless (t.rea_done.encrypted == false);
+ mfs_rx_t *mfs = mac_store_mfs_get_rx (t.mac_store, false, false,
+ mpdu.rx.params.lid,
+ mpdu.rx.params.tei);
+ test_fail_unless (mfs);
+ if (i == 0)
+ test_fail_unless (mfs->head == NULL);
+ else
+ {
+ test_fail_unless (mfs->head != NULL);
+ blk_release_desc (&mfs->head->blk);
+ mfs->head = NULL;
+ }
+ blk_release (mfs);
+ sar_cleanup (t.sar);
+ }
sar_test_uninit (&t);
blk_release_desc_range (head, tail);
}