summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cl/Module3
-rw-r--r--cl/cl.h10
-rw-r--r--cl/cl_mactotei.h27
-rw-r--r--cl/inc/context.h9
-rw-r--r--cl/inc/trace.h82
-rw-r--r--cl/src/cl.c224
-rw-r--r--cl/src/trace.c92
-rw-r--r--cl/test/src/cl_mactotei_api.c4
-rw-r--r--cl/test/src/cl_mactotei_find.c3
-rw-r--r--cl/test/src/cl_mactotei_heapsort.c3
-rw-r--r--cl/test/src/cl_mme_recv.c2
-rw-r--r--cl/test/src/cl_mme_send_as_data.c6
-rw-r--r--cl/test/src/cl_mme_send_as_mme.c4
-rw-r--r--cl/test/src/cl_recv_data.c6
-rw-r--r--cl/test/src/cl_send_data.c4
15 files changed, 353 insertions, 126 deletions
diff --git a/cl/Module b/cl/Module
index 23345d1c6f..fa85c6b9ab 100644
--- a/cl/Module
+++ b/cl/Module
@@ -1 +1,4 @@
SOURCES := cl.c cl_mactotei.c
+ifeq ($(CONFIG_TRACE),y)
+SOURCES += trace.c
+endif
diff --git a/cl/cl.h b/cl/cl.h
index a1122953a0..5a4dcd02c5 100644
--- a/cl/cl.h
+++ b/cl/cl.h
@@ -170,10 +170,10 @@ void cl_mme_send_as_data (cl_t *ctx, u8 *buffer, uint length);
/**
* Callback called by the sar when a MME as been sent over the PWL.
*
- * \param cl the cl context.
+ * \param ctx the cl context.
* \param buffer the buffer used.
*/
-void cl_mme_sar_send_done (cl_t *cl, u8 *buffer);
+void cl_mme_sar_send_done (cl_t *ctx, u8 *buffer);
/**
* Receives an MME from the SAR or the upper layer.
@@ -187,7 +187,7 @@ void cl_mme_sar_send_done (cl_t *cl, u8 *buffer);
* \param length the MME length
* \param mfs the MFS used in the reassembly process.
*/
-void cl_mme_recv (void *ctx, u8 *buffer, uint length, mfs_rx_t *mfs);
+void cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs);
/**
* Receives an MME from the Upper layer.
@@ -243,7 +243,7 @@ void cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user);
* \param ctx the CL context.
* \param buffer the buffer containing the MME
*/
-void cl_data_send_done (void *ctx, u8 *buffer);
+void cl_data_send_done (cl_t *ctx, u8 *buffer);
/**
* Send a data from the upper layer to the SAR, this data should be sent over
@@ -272,7 +272,7 @@ void cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user);
* \param length the data length in the buffer
* \param mfs the mfs used to receive the data.
*/
-void cl_data_recv (void *ctx, u8 *buffer, uint length, mfs_rx_t *mfs);
+void cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs);
/**
diff --git a/cl/cl_mactotei.h b/cl/cl_mactotei.h
index f60875cf91..4f74b62bf5 100644
--- a/cl/cl_mactotei.h
+++ b/cl/cl_mactotei.h
@@ -59,41 +59,26 @@ void cl_mactotei_addr_add (cl_mactotei_blk_t *table, mac_t mac_addr,
* Sample : cl_mactotei_copy_table_excluding_tag (cl, table, 2), will copy all
* the mac to tei lines of the CL table without those where the tag value is 2.
*
- * \param cl the convergence layer context
+ * \param ctx the convergence layer context
* \param table the mactotei new table to fill
* \param tag the tag to exclude from the copy
*/
-void cl_mactotei_copy_table_excluding_tag (cl_t *cl,
+void cl_mactotei_copy_table_excluding_tag (cl_t *ctx,
cl_mactotei_blk_t *table, u8 tag);
/**
* Request the CL to use the new table and remove the old one.
*
- * \msc
- * CP, CL, CL_MACTOTEI;
- *
- * CP->CL [label = "cl_mactotei_use_table (cl, table)"];
- * CL->CL_MACTOTEI [label = "cl_mactotei_use_table_intern (table)"];
- * CL<<CL_MACTOTEI [label = "done"];
- * CL->CL [label = "cl_mactotei_switch_table (cl, table)"];
- * \endmsc
- *
- * \param cl the CL context
+ * \param ctx the CL context
* \param table the new table to use.
*/
-void cl_mactotei_use_table (cl_t *cl, cl_mactotei_blk_t *table);
+void cl_mactotei_use_table (cl_t *ctx, cl_mactotei_blk_t *table);
/**
* Release the complete table from the memory.
*
- * \msc
- * CL, CL_MACTOTEI;
- *
- * CL->CL_MACTOTEI [label = "cl_mactotei_release_table_intern (table)"];
- * \endmsc
- *
- * \param cl the convergence layer context
+ * \param ctx the convergence layer context
*/
-void cl_mactotei_release_table (cl_t *cl);
+void cl_mactotei_release_table (cl_t *ctx);
#endif /*CL_MACTOTEI_H_*/
diff --git a/cl/inc/context.h b/cl/inc/context.h
index 02db90f2b2..e3b51747b1 100644
--- a/cl/inc/context.h
+++ b/cl/inc/context.h
@@ -21,6 +21,7 @@
#include "mac/sar/sar.h"
#include "cl/inc/cl_mactotei.h"
+#include "cl/inc/trace.h"
/** data tx structure. */
struct cl_data_tx_t
@@ -114,6 +115,14 @@ struct cl_t
/** MME buffer to provide to the SAR */
u8 mme_buffer [2048] __attribute__((aligned(2048)));
+
+ /** Tracing system */
+#if CONFIG_TRACE
+ /** cl Trace */
+ trace_buffer_t trace;
+ /** cl trace namespace */
+ trace_namespace_t trace_namespace;
+#endif /* !CONFIG_TRACE */
};
#endif /* CL_INC_CONTEXT_H_ */
diff --git a/cl/inc/trace.h b/cl/inc/trace.h
new file mode 100644
index 0000000000..a801eb8d32
--- /dev/null
+++ b/cl/inc/trace.h
@@ -0,0 +1,82 @@
+#ifndef cl_inc_trace_h
+#define cl_inc_trace_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/inc/trace.h
+ * \brief Trace system for the Convergence Layer.
+ * \ingroup cl
+ *
+ */
+
+#include "lib/trace.h"
+
+/** Shortcut for tracing */
+#define CL_TRACE(id, args...) \
+ TRACE_FAST_SHORT (CL_TRACE_, &ctx->trace, id, ## args)
+
+#if CONFIG_TRACE
+
+#define CL_ID(id, ord, args) \
+ CL_TRACE_ ## id = TRACE_ID (ord, args)
+
+enum
+{
+ CL_ID (INIT, 1, 0),
+ CL_ID (UNINIT, 2, 0),
+ CL_ID (MME_SEND_AS_MME, 3, 3),
+ CL_ID (MME_SEND_AS_DATA, 4, 2),
+ CL_ID (MME_BUFFER_ADD, 5, 1),
+ CL_ID (MME_RECV, 6, 3),
+ CL_ID (MME_RECV_DONE, 7, 2),
+ CL_ID (MACTOTEI_COPY, 8, 2),
+ CL_ID (MACTOTEI_USE, 9, 1),
+ CL_ID (MACTOTEI_RELEASE, 10, 1),
+ CL_ID (MACTOTEI_FIND_TEI, 11, 3),
+ CL_ID (CLASSIFIER, 12, 5),
+ CL_ID (DATA_SEND, 13, 5),
+ CL_ID (DATA_SEND_DROP, 14, 2),
+ CL_ID (DATA_SEND_DONE, 15, 1),
+ CL_ID (DATA_RECV, 16, 2),
+ CL_ID (DATA_BUFFER_ADD, 17, 1)
+};
+
+BEGIN_DECLS
+
+/**
+ * Initialize the trace buffer
+ * \param ctx the cl context
+ */
+void
+cl_trace_init (cl_t *ctx);
+
+/**
+ * Uninitialize the trace buffer
+ * \param ctx the cl context.
+ */
+void
+cl_trace_uninit(cl_t *ctx);
+
+/**
+ * Print the trace
+ * \param ctx the cl context.
+ */
+void
+cl_trace_print (cl_t *ctx);
+
+END_DECLS
+
+#else /* !CONFIG_TRACE */
+
+#define cl_trace_init(ctx) ((void) 0)
+#define cl_trace_uinit(ctx) ((void) 0)
+#define cl_trace_print(ctx) ((void) 0)
+
+#endif /* CONFIG_TRACE */
+
+#endif /* cl_inc_trace_h */
diff --git a/cl/src/cl.c b/cl/src/cl.c
index e04dcabf28..8e21693915 100644
--- a/cl/src/cl.c
+++ b/cl/src/cl.c
@@ -36,6 +36,13 @@ static struct cl_t cl_global;
*/
cl_t *cl_init (mac_store_t *mac_store, sar_t *sar)
{
+ cl_t *ctx;
+
+ dbg_assert (mac_store);
+ dbg_assert (sar);
+
+ ctx = &cl_global;
+
cl_global.mac_store = mac_store;
/* Initialize the SAR */
@@ -45,16 +52,17 @@ cl_t *cl_init (mac_store_t *mac_store, sar_t *sar)
sar_init_mme_context (cl_global.sar, &cl_global);
sar_init_segmentation_mme_cb (cl_global.sar,
(sar_segmentation_done_cb_t) cl_mme_sar_send_done);
- sar_init_reassembly_mme_cb (cl_global.sar, cl_mme_recv);
+ sar_init_reassembly_mme_cb (cl_global.sar,(sar_reassembly_done_cb_t) cl_mme_recv);
sar_mme_buffer_add (cl_global.sar, cl_global.mme_buffer);
// Data TX part
sar_init_data_context (cl_global.sar, &cl_global);
- sar_init_segmentation_data_cb (cl_global.sar, cl_data_send_done);
+ sar_init_segmentation_data_cb (cl_global.sar,
+ (sar_segmentation_done_cb_t) cl_data_send_done);
// DATA RX part
- sar_init_reassembly_data_cb (cl_global.sar, cl_data_recv);
+ sar_init_reassembly_data_cb (cl_global.sar, (sar_reassembly_done_cb_t)cl_data_recv);
/* Initialize the random generator */
lib_rnd_init (&cl_global.random_generator, 12345678);
@@ -69,6 +77,11 @@ cl_t *cl_init (mac_store_t *mac_store, sar_t *sar)
cl_global.mme_ul_send.cb = NULL;
cl_global.mme_ul_send.user = NULL;
+ /* Initialize the trace system. */
+ cl_trace_init (ctx);
+
+ CL_TRACE (INIT);
+
return &cl_global;
}
@@ -79,6 +92,8 @@ cl_t *cl_init (mac_store_t *mac_store, sar_t *sar)
*/
void cl_mme_init (cl_mme_t *ctx)
{
+ dbg_assert (ctx);
+
ctx->ul_mme_recv_done = NULL;
ctx->ul_mme_recv_done_user_data = NULL;
}
@@ -92,11 +107,15 @@ void cl_uninit (cl_t *ctx)
{
dbg_assert (ctx);
+ CL_TRACE (UNINIT);
+
sar_uninit (ctx->sar);
if (ctx->mactotei)
{
cl_mactotei_release_table (ctx);
}
+
+ cl_trace_uninit(ctx);
}
/**
@@ -191,6 +210,8 @@ void cl_mme_send_as_mme (cl_t *ctx, u8 *buffer, uint length, mfs_tx_t *mfs)
dbg_assert (ctx->sar);
dbg_assert (mfs->common.mme);
+ CL_TRACE (MME_SEND_AS_MME, length, buffer, mfs->common.tei);
+
sar_msdu_add (ctx->sar, buffer, length,
lib_rnd32 (&ctx->random_generator), mfs);
}
@@ -208,6 +229,8 @@ void cl_mme_send_as_data (cl_t *ctx, u8 *buffer, uint length)
dbg_assert (buffer);
dbg_assert (length >= 60 && length <= 1518);
+ CL_TRACE (MME_SEND_AS_DATA, length, buffer);
+
ctx->mme_ul_send.mme_buffer = buffer;
cl_data_send (ctx, buffer, length);
@@ -216,15 +239,16 @@ void cl_mme_send_as_data (cl_t *ctx, u8 *buffer, uint length)
/**
* Callback called by the sar when a MME as been sent over the PWL.
*
- * \param cl the cl context.
+ * \param ctx the cl context.
* \param buffer the buffer used.
*/
-void cl_mme_sar_send_done (cl_t *cl, u8 *buffer)
+void cl_mme_sar_send_done (cl_t *ctx, u8 *buffer)
{
- dbg_assert (cl);
+ dbg_assert (ctx);
dbg_assert (buffer);
- cl_mme_buffer_add (cl, buffer);
+ CL_TRACE (MME_BUFFER_ADD, buffer);
+ cl_mme_buffer_add (ctx, buffer);
}
/**
@@ -240,25 +264,25 @@ void cl_mme_sar_send_done (cl_t *cl, u8 *buffer)
* \param mfs the MFS used in the reassembly process.
* \param sar a boolean informing from which layer comes the MME.
*/
-void cl_mme_recv (void *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
+void cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
{
- cl_t *cl;
dbg_assert (ctx);
- cl = (cl_t *) ctx;
- dbg_assert (cl->mme.mme_recv_cb);
+ dbg_assert (ctx->mme.mme_recv_cb);
dbg_assert (buffer);
dbg_assert (length >= 60 && length <= 1518);
- cl->mme.mme_recv.buffer = buffer;
+ ctx->mme.mme_recv.buffer = buffer;
+
+ CL_TRACE (MME_RECV, length, buffer, ctx->mme.mme_recv.sar);
if (mfs)
- cl->mme.mme_recv.sar = true;
+ ctx->mme.mme_recv.sar = true;
else
- cl->mme.mme_recv.sar = false;
+ ctx->mme.mme_recv.sar = false;
- (*cl->mme.mme_recv_cb) (cl->mme.mme_recv_user_data, mfs, buffer, length,
- &cl->mme.mme_recv);
+ (*ctx->mme.mme_recv_cb) (ctx->mme.mme_recv_user_data, mfs, buffer, length,
+ &ctx->mme.mme_recv);
}
/**
@@ -274,6 +298,8 @@ void cl_mme_recv_done (cl_t *ctx, cl_mme_recv_t *mme_recv)
dbg_assert (mme_recv);
dbg_assert (mme_recv->buffer);
+ CL_TRACE (MME_RECV_DONE, mme_recv->buffer, mme_recv->sar);
+
if (mme_recv->sar)
{
dbg_assert (ctx->sar);
@@ -296,80 +322,71 @@ void cl_mme_recv_done (cl_t *ctx, cl_mme_recv_t *mme_recv)
* Sample : cl_mactotei_copy_table_excluding_tag (cl, table, 2), will copy all
* the mac to tei lines of the CL table without those where the tag value is 2.
*
- * \param cl the convergence layer context
+ * \param ctx the convergence layer context
* \param table the mactotei new table to fill
* \param tag the tag to exclude from the copy
*/
-void cl_mactotei_copy_table_excluding_tag (cl_t *cl,
+void cl_mactotei_copy_table_excluding_tag (cl_t *ctx,
cl_mactotei_blk_t *table, u8 tag)
{
- dbg_assert (cl);
- dbg_assert (cl->mactotei);
+ dbg_assert (ctx);
+ dbg_assert (ctx->mactotei);
dbg_assert (table);
- cl_mactotei_copy (cl->mactotei, table, tag);
+ CL_TRACE (MACTOTEI_COPY, table, tag);
+
+ cl_mactotei_copy (ctx->mactotei, table, tag);
}
/**
* Request the CL to use the new table and remove the old one.
*
- * \msc
- * CP, CL, CL_MACTOTEI;
- *
- * CP->CL [label = "cl_mactotei_use_table (cl, table)"];
- * CL->CL_MACTOTEI [label = "cl_mactotei_use_table_intern (table)"];
- * CL<<CL_MACTOTEI [label = "done"];
- * CL->CL [label = "cl_mactotei_switch_table (cl, table)"];
- * \endmsc
- *
- * \param cl the CL context
+ * \param ctx the CL context
* \param table the new table to use.
*/
-void cl_mactotei_use_table (cl_t *cl, cl_mactotei_blk_t *table)
+void cl_mactotei_use_table (cl_t *ctx, cl_mactotei_blk_t *table)
{
- dbg_assert (cl);
+ dbg_assert (ctx);
dbg_assert (table);
+ CL_TRACE (MACTOTEI_USE, table);
+
/** add the table to the CL context */
- cl_mactotei_switch_table (cl, cl_mactotei_generate_table (table));
+ cl_mactotei_switch_table (ctx, cl_mactotei_generate_table (table));
}
/**
* Swith the old mactotei table with the new one.
*
- * \param cl the convergence layer context
+ * \param ctx the convergence layer context
* \param table the table to switch
*/
-void cl_mactotei_switch_table (cl_t *cl, cl_mactotei_table_t *table)
+void cl_mactotei_switch_table (cl_t *ctx, cl_mactotei_table_t *table)
{
- dbg_assert (cl);
+ dbg_assert (ctx);
dbg_assert (table);
- if (cl->mactotei)
+ if (ctx->mactotei)
{
- cl_mactotei_release_table_intern (cl->mactotei);
+ CL_TRACE (MACTOTEI_RELEASE, ctx->mactotei);
+ cl_mactotei_release_table_intern (ctx->mactotei);
}
- cl->mactotei = table;
+ ctx->mactotei = table;
}
/**
* Release the complete table from the memory.
*
- * \msc
- * CL, CL_MACTOTEI;
- *
- * CL->CL_MACTOTEI [label = "cl_mactotei_release_table_intern (table)"];
- * \endmsc
- *
- * \param cl the convergence layer context
+ * \param ctx the convergence layer context
*/
-void cl_mactotei_release_table (cl_t *cl)
+void cl_mactotei_release_table (cl_t *ctx)
{
- dbg_assert (cl);
- dbg_assert (cl->mactotei);
+ dbg_assert (ctx);
+ dbg_assert (ctx->mactotei);
- cl_mactotei_release_table_intern (cl->mactotei);
- cl->mactotei = NULL;
+ CL_TRACE (MACTOTEI_RELEASE, ctx->mactotei);
+ cl_mactotei_release_table_intern (ctx->mactotei);
+ ctx->mactotei = NULL;
}
/**
@@ -380,44 +397,47 @@ void cl_mactotei_release_table (cl_t *cl)
* \return the tei corresponding to the mac address if known otherwise it
* returns 0xff a broadcast tei (see HPAV section 5.3.1.2)
*/
-uint cl_mactotei_table_find_tei_from_mac (cl_t *cl, mac_t mac)
+uint cl_mactotei_table_find_tei_from_mac (cl_t *ctx, mac_t mac)
{
uint index;
cl_mactotei_t mactotei;
- dbg_assert (cl);
- dbg_assert (cl->mactotei);
+ dbg_assert (ctx);
+ dbg_assert (ctx->mactotei);
- DICHOTOMY_SEARCH (0, cl->mactotei->nb_total, index, mac
- <= cl_mactotei_table_get_mac_at (cl->mactotei, index));
+ DICHOTOMY_SEARCH (0, ctx->mactotei->nb_total, index, mac
+ <= cl_mactotei_table_get_mac_at (ctx->mactotei, index));
- if (index < cl->mactotei->nb_total)
+ if (index < ctx->mactotei->nb_total)
{
- mactotei = cl_mactotei_table_get_mactotei_at (cl->mactotei, index);
+ mactotei = cl_mactotei_table_get_mactotei_at (ctx->mactotei, index);
if (mactotei.mac != mac)
{
+ CL_TRACE (MACTOTEI_FIND_TEI, mac, false, 0xff);
return 0xff;
}
else
{
+ CL_TRACE (MACTOTEI_FIND_TEI, mac, true, mactotei.tei);
return mactotei.tei;
}
}
+ CL_TRACE (MACTOTEI_FIND_TEI, mac, false, 0xff);
return 0xff;
}
/**
* Search for the lid in the classifier
*
- * \param cl CL context
+ * \param ctx CL context
* \param bcast put true if the link is a bcast one, false otherwise.
* \param tei the tei found previously by the mactotei table.
* \param acs put true if the link should be process by the acs
* \param drop put true if the data should be drop.
*/
-uint cl_classifer_get_lid (cl_t *cl, uint tei, bool *bcast, bool *acs,
+uint cl_classifer_get_lid (cl_t *ctx, uint tei, bool *bcast, bool *acs,
bool *drop)
{
if (tei == 0xff)
@@ -432,6 +452,9 @@ uint cl_classifer_get_lid (cl_t *cl, uint tei, bool *bcast, bool *acs,
*acs = false;
*drop = false;
+ CL_TRACE (CLASSIFIER, tei, *bcast, *acs, *drop, 1);
+
+ /** TODO fill the clissifier */
return 1;
}
@@ -456,11 +479,11 @@ void cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user)
* Send a data from the upper layer to the SAR, this data should be sent over
* the PLC.
*
- * \param cl the CL context.
+ * \param ctx the CL context.
* \param buffer the buffer containing the data to send
* \param length the data length
*/
-void cl_data_send (cl_t *cl, u8 *buffer, uint length)
+void cl_data_send (cl_t *ctx, u8 *buffer, uint length)
{
uint tei;
uint lid;
@@ -471,40 +494,47 @@ void cl_data_send (cl_t *cl, u8 *buffer, uint length)
mfs_tx_t *mfs;
- dbg_assert (cl);
+ dbg_assert (ctx);
dbg_assert (buffer);
dbg_assert (length >= 64 && length <= 1518);
- dbg_assert (cl->mactotei);
- dbg_assert (cl->sar);
- dbg_assert (cl->mac_store);
+ dbg_assert (ctx->mactotei);
+ dbg_assert (ctx->sar);
+ dbg_assert (ctx->mac_store);
mac = read_u32_from_word (buffer);
mac = mac << 16;
mac = mac | (read_u32_from_word (buffer + sizeof(u32)) & 0xFFFF);
/* Get the TEI from the mactotei table. */
- tei = cl_mactotei_table_find_tei_from_mac (cl, mac & 0x0000FFFFFFFFFFFFull);
+ tei = cl_mactotei_table_find_tei_from_mac (ctx, mac & 0x0000FFFFFFFFFFFFull);
if (tei != station_get_tei())
{
/* Get some data from the classifier. */
- lid = cl_classifer_get_lid (cl, tei, &bcast, &acs, &drop);
+ lid = cl_classifer_get_lid (ctx, tei, &bcast, &acs, &drop);
/* try to get the mfs from the store. */
- mfs = mac_store_mfs_get_tx (cl->mac_store, bcast, false, lid, tei);
+ mfs = mac_store_mfs_get_tx (ctx->mac_store, bcast, false, lid, tei);
if (!drop && !acs && mfs)
{
- sar_msdu_add (cl->sar, buffer, length, sar_get_ntb(cl->sar), mfs);
+ CL_TRACE (DATA_SEND, buffer, length, mfs->common.tei, mfs->common.lid,
+ mfs->common.bcast);
+ sar_msdu_add (ctx->sar, buffer, length, sar_get_ntb(ctx->sar), mfs);
/* release the mfs */
blk_release (mfs);
}
+ else
+ {
+ CL_TRACE (DATA_SEND_DROP, buffer, length);
+ }
}
else
{
- dbg_assert (cl->mme_ul_send.cb);
- (*cl->mme_ul_send.cb) (cl->mme_ul_send.user, buffer, length);
+ CL_TRACE (DATA_SEND, buffer, length, 0, 0, 0);
+ dbg_assert (ctx->mme_ul_send.cb);
+ (*ctx->mme_ul_send.cb) (ctx->mme_ul_send.user, buffer, length);
}
}
@@ -515,24 +545,23 @@ void cl_data_send (cl_t *cl, u8 *buffer, uint length)
* \param ctx the CL context.
* \param buffer the buffer containing the MME
*/
-void cl_data_send_done (void *ctx, u8 *buffer)
+void cl_data_send_done (cl_t *ctx, u8 *buffer)
{
- cl_t *cl;
dbg_assert (ctx);
dbg_assert (buffer);
- cl = (cl_t *) ctx;
+ CL_TRACE (DATA_SEND_DONE, buffer);
/* Compare the buffer address with the MME buffer address. */
- if (cl->mme_ul_send.mme_buffer == buffer)
+ if (ctx->mme_ul_send.mme_buffer == buffer)
{
- cl_mme_buffer_add(cl, buffer);
- cl->mme_ul_send.mme_buffer = NULL;
+ cl_mme_buffer_add(ctx, buffer);
+ ctx->mme_ul_send.mme_buffer = NULL;
}
else
{
- dbg_assert (cl->data_tx.cb);
- (*cl->data_tx.cb) (cl->data_tx.user, buffer);
+ dbg_assert (ctx->data_tx.cb);
+ (*ctx->data_tx.cb) (ctx->data_tx.user, buffer);
}
}
@@ -560,45 +589,48 @@ void cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user)
* \param length the data length in the buffer
* \param mfs the mfs used to receive the data.
*/
-void cl_data_recv (void *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
+void cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
{
- cl_t *cl;
-
dbg_assert (ctx);
dbg_assert (buffer);
dbg_assert (length >= 64 && length <= 1518);
dbg_assert (mfs);
- cl = (cl_t *) ctx;
- dbg_assert (cl->data_rx.cb);
+ dbg_assert (ctx->data_rx.cb);
- (*cl->data_rx.cb) (cl->data_rx.user, buffer, length);
+ CL_TRACE (DATA_RECV, buffer, length);
+
+ (*ctx->data_rx.cb) (ctx->data_rx.user, buffer, length);
}
/**
* Provides a buffer to the CP.
*
- * \param cl the CL context
+ * \param ctx the CL context
* \param buffer the buffer to reassembly some datas
*/
-void cl_mme_buffer_add (cl_t *cl, u8 *buffer)
+void cl_mme_buffer_add (cl_t *ctx, u8 *buffer)
{
- dbg_assert (cl);
+ dbg_assert (ctx);
dbg_assert (buffer);
-
- (*cl->mme.mme_buffer_add_cb) (cl->mme.mme_buffer_add_user_data, buffer);
+
+ CL_TRACE (MME_BUFFER_ADD, buffer);
+ (*ctx->mme.mme_buffer_add_cb) (ctx->mme.mme_buffer_add_user_data, buffer);
}
/**
* Provides a buffer to the SAR to reassembly data
*
- * \param cl the CL context
+ * \param ctx the CL context
* \param buffer the buffer to reassembly some datas
*/
-void cl_data_buffer_add (cl_t *cl, u8 *buffer)
+void cl_data_buffer_add (cl_t *ctx, u8 *buffer)
{
- dbg_assert (cl);
+ dbg_assert (ctx);
dbg_assert (buffer);
- sar_data_buffer_add (cl->sar, buffer);
+ CL_TRACE (DATA_BUFFER_ADD, buffer);
+
+ sar_data_buffer_add (ctx->sar, buffer);
}
+
diff --git a/cl/src/trace.c b/cl/src/trace.c
new file mode 100644
index 0000000000..12aa6c0175
--- /dev/null
+++ b/cl/src/trace.c
@@ -0,0 +1,92 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/src/trace.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include <string.h>
+#include <stdio.h>
+
+#include "cl/cl.h"
+#include "cl/inc/trace.h"
+
+#include "cl/inc/context.h"
+
+/**
+ * Initialize the trace buffer
+ * \param ctx the cl context
+ */
+void
+cl_trace_init (cl_t *ctx)
+{
+ uint i;
+ dbg_assert (ctx);
+
+ static trace_event_id_t event_ids[] =
+ {
+ TRACE_EVENT (CL_TRACE_INIT, "CL_INIT"),
+ TRACE_EVENT (CL_TRACE_UNINIT, "CL_UNINIT"),
+ TRACE_EVENT (CL_TRACE_MME_SEND_AS_MME, "CL_MME_SEND_AS_MME length : %d, buffer @ : %x, dtei : %d"),
+ TRACE_EVENT (CL_TRACE_MME_SEND_AS_DATA, "CL_MME_SEND_AS_DATA length : %d, buffer @ : %x"),
+ TRACE_EVENT (CL_TRACE_MME_BUFFER_ADD, "CL_MME_BUFFER_ADD buffer @ : %x"),
+ TRACE_EVENT (CL_TRACE_MME_RECV, "CL_MME_RECV length : %d, buffer @ : %x, from sar : %d"),
+ TRACE_EVENT (CL_TRACE_MME_RECV_DONE, "CL_MME_RECV_DONE buffer @ : %x, from sar : %d"),
+ TRACE_EVENT (CL_TRACE_MACTOTEI_COPY, "CL_MACTOTEI_COPY table @ : %x, tag : %d"),
+ TRACE_EVENT (CL_TRACE_MACTOTEI_USE, "CL_MACTOTEI_USE table @ : %x"),
+ TRACE_EVENT (CL_TRACE_MACTOTEI_RELEASE, "CL_MACTOTEI_RELEASE table @ : %x"),
+ TRACE_EVENT (CL_TRACE_MACTOTEI_FIND_TEI, "CL_MACTOTEI_FIND_TEI mac @ : %x, found %d, tei use : %x"),
+ TRACE_EVENT (CL_TRACE_CLASSIFIER, "CL_CLASSIFIER tei : %x, bcast %d, acs : %d, drop : %d, lid : %x"),
+ TRACE_EVENT (CL_TRACE_DATA_SEND, "CL_DATA_SEND buffer @ : %x, length : %d, tei : %x, lid : %x, bcast : %d"),
+ TRACE_EVENT (CL_TRACE_DATA_SEND_DROP, "CL_DATA_SEND_DROP buffer @ : %x, length : %d"),
+ TRACE_EVENT (CL_TRACE_DATA_SEND_DONE, "CL_DATA_SEND_DONE buffer @ : %x"),
+ TRACE_EVENT (CL_TRACE_DATA_RECV, "CL_DATA_RECV buffer @ : %x, length : %d"),
+ TRACE_EVENT (CL_TRACE_DATA_BUFFER_ADD, "CL_DATA_BUFFER_ADD buffer @ : %x")
+ };
+
+ trace_namespace_init (&ctx->trace_namespace);
+
+ for (i = 0; i < COUNT (event_ids); i++)
+ {
+ trace_namespace_register_event_id (&ctx->trace_namespace,
+ &event_ids[i]);
+ }
+
+ trace_buffer_add (&ctx->trace, 8, 4, true, &ctx->trace_namespace);
+}
+
+/**
+ * Uninitialize the trace buffer
+ * \param ctx the cl context.
+ */
+void
+cl_trace_uninit(cl_t *ctx)
+{
+ dbg_assert (ctx);
+
+ trace_buffer_remove (&ctx->trace);
+ trace_namespace_uninit (&ctx->trace_namespace);
+}
+
+/**
+ * Print the trace
+ * \param ctx the cl context.
+ */
+void
+cl_trace_print (cl_t *ctx)
+{
+ dbg_assert (ctx);
+
+ trace_buffer_dbg_dump(&ctx->trace);
+}
+
+
diff --git a/cl/test/src/cl_mactotei_api.c b/cl/test/src/cl_mactotei_api.c
index 34a849fd21..1e668b9328 100644
--- a/cl/test/src/cl_mactotei_api.c
+++ b/cl/test/src/cl_mactotei_api.c
@@ -14,6 +14,8 @@
#include "common/std.h"
#include "lib/test.h"
+#include "lib/trace.h"
+
#include "cl/cl_mactotei.h"
#include "cl/cl.h"
@@ -32,6 +34,7 @@ int main (void)
pbproc_t *pbproc;
mac_config_t *mac_config;
+ trace_init ();
test_init (test, 0, NULL);
mac_store = mac_store_init ();
@@ -228,3 +231,4 @@ int main (void)
test_result (test);
return test_nb_failed (test) == 0 ? 0 : 1;
}
+
diff --git a/cl/test/src/cl_mactotei_find.c b/cl/test/src/cl_mactotei_find.c
index cd3ed15bb4..02143f702e 100644
--- a/cl/test/src/cl_mactotei_find.c
+++ b/cl/test/src/cl_mactotei_find.c
@@ -15,6 +15,8 @@
#include "common/std.h"
#include "lib/test.h"
#include "lib/rnd.h"
+#include "lib/trace.h"
+
#include "cl/cl_mactotei.h"
#include "cl/cl.h"
@@ -35,6 +37,7 @@ int main (void)
mac_config_t *mac_config;
mac_store_t *mac_store;
+ trace_init ();
test_init (test, 0, NULL);
mac_store = mac_store_init ();
mac_config = blk_alloc ();
diff --git a/cl/test/src/cl_mactotei_heapsort.c b/cl/test/src/cl_mactotei_heapsort.c
index 5d9ddb4e1e..1179c3c298 100644
--- a/cl/test/src/cl_mactotei_heapsort.c
+++ b/cl/test/src/cl_mactotei_heapsort.c
@@ -15,6 +15,8 @@
#include "common/std.h"
#include "lib/test.h"
#include "lib/rnd.h"
+#include "lib/trace.h"
+
#include "cl/cl_mactotei.h"
#include "cl/cl.h"
#include "mac/common/store.h"
@@ -37,6 +39,7 @@ int main (void)
mac_config_t *mac_config;
mac_store_t *mac_store;
+ trace_init ();
test_init (test, 0, NULL);
lib_rnd_init (&rnd1, 12345678);
diff --git a/cl/test/src/cl_mme_recv.c b/cl/test/src/cl_mme_recv.c
index 5618384899..a8a289f1f5 100644
--- a/cl/test/src/cl_mme_recv.c
+++ b/cl/test/src/cl_mme_recv.c
@@ -14,6 +14,7 @@
#include "common/std.h"
#include "lib/test.h"
+#include "lib/trace.h"
#include "mac/common/store.h"
#include "mac/pbproc/pbproc.h"
@@ -51,6 +52,7 @@ int main (void)
u8 buffer[2048];
test_init (test, 0, NULL);
+ trace_init ();
mac_store = mac_store_init ();
mac_config = blk_alloc ();
diff --git a/cl/test/src/cl_mme_send_as_data.c b/cl/test/src/cl_mme_send_as_data.c
index d878e5393b..de7fbd3449 100644
--- a/cl/test/src/cl_mme_send_as_data.c
+++ b/cl/test/src/cl_mme_send_as_data.c
@@ -14,6 +14,7 @@
#include "common/std.h"
#include "lib/test.h"
+#include "lib/trace.h"
#include "cl/cl_mactotei.h"
#include "cl/cl.h"
@@ -69,7 +70,7 @@ void cl_test_send_mme_as_data_to_sar (test_t test)
cl = cl_init (mac_store, sar);
cl_mme_init_buffer_add_cb(cl, test_mme_cp_add_buffer, cl);
- sar_init_segmentation_data_cb (sar, cl_data_send_done);
+ sar_init_segmentation_data_cb (sar, (sar_segmentation_done_cb_t) cl_data_send_done);
sar_init_mme_context (sar, cl);
/* create the mfs for the test. */
@@ -129,7 +130,7 @@ void cl_test_send_mme_as_data_to_hle (test_t test)
cl_mme_init_ul_as_data(cl,test_mme_ul_reception_done , cl);
cl_mme_init_buffer_add_cb(cl, test_mme_cp_add_buffer, cl);
- sar_init_segmentation_data_cb (sar, cl_data_send_done);
+ sar_init_segmentation_data_cb (sar, (sar_segmentation_done_cb_t) cl_data_send_done);
sar_init_mme_context (sar, cl);
/* create the mactotei table */
@@ -169,6 +170,7 @@ int main (void)
test_t test;
test_init (test, 0, NULL);
+ trace_init ();
cl_test_send_mme_as_data_to_sar (test);
cl_test_send_mme_as_data_to_hle (test);
diff --git a/cl/test/src/cl_mme_send_as_mme.c b/cl/test/src/cl_mme_send_as_mme.c
index d2146348df..f45e287126 100644
--- a/cl/test/src/cl_mme_send_as_mme.c
+++ b/cl/test/src/cl_mme_send_as_mme.c
@@ -14,12 +14,15 @@
#include "common/std.h"
#include "lib/test.h"
+#include "lib/trace.h"
#include "cl/cl.h"
#include "mac/common/store.h"
#include "mac/sar/sar.h"
#include "mac/pbproc/pbproc.h"
+#include "cl/inc/trace.h"
+
bool test_add_buffer;
@@ -41,6 +44,7 @@ int main (void)
mfs_tx_t *mfs;
bool added;
+ trace_init ();
test_init (test, 0, NULL);
mac_store = mac_store_init ();
diff --git a/cl/test/src/cl_recv_data.c b/cl/test/src/cl_recv_data.c
index 05c9de5c0a..eafe5a2b77 100644
--- a/cl/test/src/cl_recv_data.c
+++ b/cl/test/src/cl_recv_data.c
@@ -14,6 +14,7 @@
#include "common/std.h"
#include "lib/test.h"
+#include "lib/trace.h"
#include "cl/cl.h"
@@ -21,6 +22,8 @@
#include "cl/inc/context.h"
#include "mac/sar/sar.h"
+#include "cl/inc/trace.h"
+
bool bool_data_recv;
void data_recv_cb (void *user, u8 *buffer, uint length)
@@ -39,6 +42,7 @@ int main (void)
mac_config_t *mac_config;
sar_t *sar;
+ trace_init ();
test_init (test, 0, NULL);
mac_store = mac_store_init ();
mac_config = blk_alloc ();
@@ -58,7 +62,7 @@ int main (void)
test_end;
cl_data_buffer_add(cl, buffer);
-
+
cl_uninit (cl);
mac_store_uninit (mac_store);
blk_release (mac_config);
diff --git a/cl/test/src/cl_send_data.c b/cl/test/src/cl_send_data.c
index 907392db00..bc03f5ea39 100644
--- a/cl/test/src/cl_send_data.c
+++ b/cl/test/src/cl_send_data.c
@@ -14,11 +14,13 @@
#include "common/std.h"
#include "lib/test.h"
+#include "lib/trace.h"
#include "mac/pbproc/pbproc.h"
#include "cl/cl.h"
#include "cl/cl_mactotei.h"
+#include "cl/inc/trace.h"
#include <stdio.h>
bool sent_cb_done;
@@ -50,6 +52,7 @@ int main (void)
pbproc_t *pbproc;
mac_config_t *mac_config;
+ trace_init ();
test_init (test, 0, NULL);
mac_store = mac_store_init ();
@@ -99,7 +102,6 @@ int main (void)
test_end;
cl_uninit (cl);
-
mfs = mac_store_mfs_get_tx (mac_store, false, false, 1, 2);
dbg_assert (mfs);