summaryrefslogtreecommitdiff
path: root/cesar/tools/sniffer_phy
diff options
context:
space:
mode:
authorIPMbox Team2012-02-03 14:32:28 +0100
committerNicolas Schodet2012-02-20 10:08:46 +0100
commit3ed571f9d933e5c5dadef650c07e20e8aad06213 (patch)
tree761bfe80d4660605e00f52afb8532d9a2ef847b6 /cesar/tools/sniffer_phy
parent89328e8cc096f8c9f340a3eb8910d06748a3e572 (diff)
cesar, cleopatre, common: new ipmbox design, closes #848
Diffstat (limited to 'cesar/tools/sniffer_phy')
-rw-r--r--cesar/tools/sniffer_phy/Makefile3
-rw-r--r--cesar/tools/sniffer_phy/inc/lhle.h20
-rw-r--r--cesar/tools/sniffer_phy/src/lhle.c155
3 files changed, 84 insertions, 94 deletions
diff --git a/cesar/tools/sniffer_phy/Makefile b/cesar/tools/sniffer_phy/Makefile
index 0ea6da7fb2..367a4f4305 100644
--- a/cesar/tools/sniffer_phy/Makefile
+++ b/cesar/tools/sniffer_phy/Makefile
@@ -11,7 +11,8 @@ test_mme_MODULES = lib
TARGET_PROGRAMS = sniffer_phy
sniffer_phy_SOURCES = sniffer_phy.c lhle.c lowlevel.c mme.c
-sniffer_phy_MODULES = lib hal/phy mac/common hal/hle hle hal/arch
+sniffer_phy_MODULES = lib hal/phy mac/common hal/ipmbox hal/arch \
+ hle/tools
mac_common_MODULES_SOURCES = tonemask.c
include $(BASE)/common/make/top.mk
diff --git a/cesar/tools/sniffer_phy/inc/lhle.h b/cesar/tools/sniffer_phy/inc/lhle.h
index c6cd47f39e..67fba522f2 100644
--- a/cesar/tools/sniffer_phy/inc/lhle.h
+++ b/cesar/tools/sniffer_phy/inc/lhle.h
@@ -12,29 +12,19 @@
* \brief Sniffer light HLE.
* \ingroup sniffer_phy
*/
-#include "hal/hle/ipmbox.h"
+#include "hal/ipmbox/ipmbox.h"
+#include "hle/tools/tools.h"
#include "inc/forward.h"
-/** Free buffer. */
-struct lhle_free_buffer_t
-{
- /** Pointer to buffer. */
- u8 *buffer;
- /** Pointer to next free buffer. */
- struct lhle_free_buffer_t *next;
-};
-typedef struct lhle_free_buffer_t lhle_free_buffer_t;
-
/** Light HLE context. */
struct lhle_t
{
/** IPMBox context. */
ipmbox_t *ipmbox;
- /** Head of free buffers list. */
- lhle_free_buffer_t *free_head;
- /** Tail of free buffers list. */
- lhle_free_buffer_t *free_tail;
+#if HLE_TOOLS
+ hle_tools_t *tools;
+#endif
};
typedef struct lhle_t lhle_t;
diff --git a/cesar/tools/sniffer_phy/src/lhle.c b/cesar/tools/sniffer_phy/src/lhle.c
index a07429f79e..1913b6b2ef 100644
--- a/cesar/tools/sniffer_phy/src/lhle.c
+++ b/cesar/tools/sniffer_phy/src/lhle.c
@@ -12,8 +12,6 @@
*
* Handle messages from/to Linux.
*
- * Any buffer added is used to feed the free buffer list.
- *
* When a buffer is received, it is handled to the MME layer for analysis.
* The buffer is send back to Linux as soon as the buffer has been handled.
*
@@ -21,32 +19,13 @@
*/
#include "common/std.h"
-#include "hal/hle/defs.h"
+#include "common/ipmbox/msg.h"
#include "common/defs/ethernet.h"
#include "lib/slist.h"
#include "inc/context.h"
/**
- * Give back message to upper layer.
- * \param ctx sniffer context
- * \param buffer buffer to be given back
- */
-static void
-lhle_done (sniffer_phy_t *ctx, u8 *buffer)
-{
- u32 msg[2];
- dbg_assert (ctx);
- dbg_assert (buffer);
- /* Compose message. */
- msg[0] = BF_FILL (IPMBOX_REG,
- (MSG_TYPE, HLE_MSG_TYPE_SEND_DONE),
- (MSG_LENGTH, 1));
- msg[1] = (u32) buffer;
- ipmbox_tx (ctx->lhle.ipmbox, msg, COUNT (msg));
-}
-
-/**
* Receive a frame from upper layers.
* \param ctx sniffer context
* \param buffer buffer containing the frame
@@ -63,110 +42,130 @@ lhle_receive (sniffer_phy_t *ctx, u8 *buffer, uint length)
{
mme_handle (ctx, buffer, length);
}
- lhle_done (ctx, buffer);
+ ipmbox_msg_empty_buf_t msg = { .buffer_addr = (u32) buffer };
+ ipmbox_tx_empty_buf (ctx->lhle.ipmbox, (u32 *) &msg, 1);
}
/**
- * Add an empty buffer.
+ * Receive messages from upper layers.
* \param ctx sniffer context
- * \param buffer buffer to add
+ * \param first_msg pointer to first message
+ * \param length length of messages buffer
*/
static void
-lhle_buffer_add (sniffer_phy_t *ctx, u8 *buffer)
+lhle_ipmbox_recv_mbx (void *user_data, u32 *first_msg, uint length)
{
+ sniffer_phy_t *ctx = user_data;
+ ipmbox_msg_mbx_t *m, *mend;
dbg_assert (ctx);
- dbg_assert (buffer);
- /* Add an element to the free list. */
- lhle_free_buffer_t *new_buffer = (void *) buffer;
- new_buffer->buffer = buffer;
- slist_push_back (ctx->lhle.free_, new_buffer);
+ dbg_assert (first_msg);
+ /* Read all messages. */
+ m = (ipmbox_msg_mbx_t *) first_msg;
+ mend = (ipmbox_msg_mbx_t *) (first_msg + length);
+ while (m != mend)
+ {
+ switch (ipmbox_msg_get_mbx_type (m->header))
+ {
+ case IPMBOX_MSG_MBX_TYPE_MME_PRIV:
+ /* This contains the sniffer MME. */
+ lhle_receive (
+ ctx, (u8 *) m->buffer_addr,
+ ipmbox_msg_get_mme_priv_length (m->header));
+ break;
+ case IPMBOX_MSG_MBX_TYPE_RPC:
+ case IPMBOX_MSG_MBX_TYPE_DEBUG_DUMP:
+ /* All hle/tools. */
+ hle_tools_msg_recv (ctx->lhle.tools, m);
+ break;
+ default:
+ /* Unsupported, ignore. */
+ break;
+ }
+ /* Go on with next message. */
+ m++;
+ }
}
/**
- * Receive messages from upper layers.
+ * Receive data from upper layers.
* \param ctx sniffer context
* \param first_msg pointer to first message
* \param length length of messages buffer
*/
static void
-lhle_ipmbox_recv (void *user_data, u32 *first_msg, uint length)
+lhle_ipmbox_recv_data (void *user_data, u32 *first_msg, uint length)
{
sniffer_phy_t *ctx = user_data;
- u32 *m, *mend;
- u32 msg;
- u8 *buffer;
+ ipmbox_msg_data_t *m, *mend;
dbg_assert (ctx);
dbg_assert (first_msg);
/* Read all messages. */
- m = first_msg;
- mend = first_msg + length;
+ m = (ipmbox_msg_data_t *) first_msg;
+ mend = (ipmbox_msg_data_t *) (first_msg + length);
while (m != mend)
{
- msg = m[0];
- buffer = (u8 *) m[1];
- switch (BF_GET (IPMBOX_REG__MSG_TYPE, msg))
- {
- /* Only use MME. */
- case HLE_MSG_TYPE_DATA:
- if (BF_GET (IPMBOX_REG__PARAM_MSG_TYPE, msg))
- lhle_receive (
- ctx, buffer,
- BF_GET (IPMBOX_REG__PARAM_MSG_LENGTH, msg));
- else
- lhle_done (ctx, buffer);
- break;
- /* This contains the sniffer MME. */
- case HLE_MSG_TYPE_INTERFACE:
- lhle_receive (
- ctx, buffer,
- BF_GET (IPMBOX_REG__PARAM_INTERFACE_LENGTH, msg));
- break;
- /* Take any buffer, I do not care about their type. */
- case HLE_MSG_TYPE_BUFFER_ADD:
- lhle_buffer_add (ctx, buffer);
- break;
- }
+ /* Return this buffer, unused. */
+ ipmbox_msg_empty_buf_t rsp = { .buffer_addr = m->buffer_addr };
+ ipmbox_tx_empty_buf (ctx->lhle.ipmbox, (u32 *) &rsp, 1);
/* Go on with next message. */
- m += BF_GET (IPMBOX_REG__MSG_LENGTH, msg) + 1;
+ m++;
}
}
+/**
+ * Empty buf DSR callback function.
+ * \param user_data user data
+ */
+void
+lhle_ipmbox_empty_buf (void *user_data)
+{
+ /* Do not care. */
+}
+
void
lhle_init (sniffer_phy_t *ctx)
{
- /* Initialise context. */
- slist_init (ctx->lhle.free_);
/* Initialise and activate IPMBox. */
- ctx->lhle.ipmbox = ipmbox_init (ctx, lhle_ipmbox_recv);
+ ctx->lhle.ipmbox = ipmbox_init ();
+ ipmbox_register_rx_data_cb (ctx->lhle.ipmbox, ctx, lhle_ipmbox_recv_data);
+ ipmbox_register_rx_mbx_cb (ctx->lhle.ipmbox, ctx, lhle_ipmbox_recv_mbx);
+ ipmbox_register_empty_buf_cb (ctx->lhle.ipmbox, ctx,
+ lhle_ipmbox_empty_buf);
ipmbox_activate (ctx->lhle.ipmbox, true);
+#if HLE_TOOLS
+ /* Initialise hle/tools. */
+ ctx->lhle.tools = hle_tools_init (ctx->lhle.ipmbox);
+#endif
}
u8 *
lhle_buffer_get (sniffer_phy_t *ctx)
{
+ u32 empty_buff_addr;
dbg_assert (ctx);
- /* Return an element from the free list. */
- if (slist_empty (ctx->lhle.free_))
- return NULL;
+ /* Return an element from the empty buffer queue. */
+ if (ipmbox_empty_buf_get (ctx->lhle.ipmbox, &empty_buff_addr, 1))
+ {
+ return (u8 *) empty_buff_addr;
+ }
else
- return slist_pop_front (ctx->lhle.free_)->buffer;
+ {
+ return NULL;
+ }
}
void
lhle_send (sniffer_phy_t *ctx, u8 *buffer, uint length)
{
- u32 msg[2];
+ ipmbox_msg_mbx_t msg;
dbg_assert (ctx);
dbg_assert (buffer);
dbg_assert (length >= ETH_PACKET_MIN_SIZE_ALLOWED
&& length <= ETH_PACKET_MAX_SIZE);
/* Compose message. */
- msg[0] = BF_FILL (IPMBOX_REG,
- (MSG_TYPE, HLE_MSG_TYPE_DATA),
- (MSG_LENGTH, 1),
- (PARAM_MSG_TYPE, 1), /* MME. */
- (PARAM_MSG_LENGTH, length));
- msg[1] = (u32) buffer;
- ipmbox_tx (ctx->lhle.ipmbox, msg, COUNT (msg));
+ msg.header = ipmbox_msg_create_header_mme_priv (length);
+ msg.buffer_addr = (u32) buffer;
+ ipmbox_tx_mbx (ctx->lhle.ipmbox, (u32 *) &msg,
+ sizeof (ipmbox_msg_mbx_t) / sizeof (u32));
}