summaryrefslogtreecommitdiff
path: root/cesar/interface/sniffer/src
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/interface/sniffer/src')
-rw-r--r--cesar/interface/sniffer/src/sniffer.c224
1 files changed, 224 insertions, 0 deletions
diff --git a/cesar/interface/sniffer/src/sniffer.c b/cesar/interface/sniffer/src/sniffer.c
new file mode 100644
index 0000000000..057281a0bc
--- /dev/null
+++ b/cesar/interface/sniffer/src/sniffer.c
@@ -0,0 +1,224 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file interface/sniffer/src/sniffer.c
+ * \brief Sniffer source functions.
+ * \ingroup interface_sniffer
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/swap.h"
+
+#include "hal/hle/defs.h"
+
+#include "interface/sniffer/sniffer.h"
+#include "interface/interface_module.h"
+#include "interface/sniffer/inc/context.h"
+
+/* Static declaration. */
+static interface_sniffer_t sniffer_global;
+
+/** Initialise the sniffer and all the callback of the sniffer.
+ * \param cb the function to call when the sniffer needs to send a message.
+ * \param user_data the data to provide on each function callback provided.
+ */
+interface_sniffer_t*
+interface_sniffer_init (interface_sniffer_send_message_cb_t cb, void *user_data)
+{
+ dbg_assert (cb);
+
+ sniffer_global.sniff_beacon_tx = false;
+ sniffer_global.sniff_beacon_rx = false;
+ sniffer_global.sniff_mme_tx = false;
+ sniffer_global.sniff_mme_rx = false;
+
+ sniffer_global.send_func = cb;
+ sniffer_global.send_user_data = user_data;
+
+ return &sniffer_global;
+}
+
+
+/** Uninitalise the sniffer.
+ * \param ctx the sniffer context.
+ */
+void
+interface_sniffer_uninit (interface_sniffer_t *ctx)
+{
+ dbg_assert (ctx);
+}
+
+/** Configure the sniffer.
+ * \param ctx the sniffer context
+ * \param data the data to configure the sniffer.
+ */
+void
+interface_sniffer_configure (interface_sniffer_t *ctx, uint data)
+{
+ dbg_assert (ctx);
+ dbg_assert (data);
+
+ ctx->sniff_mme_tx = BF_GET(SNIFFER_REG__SNIFF_MME_TX, data);
+ ctx->sniff_mme_rx = BF_GET(SNIFFER_REG__SNIFF_MME_RX, data);
+ ctx->sniff_beacon_tx = BF_GET(SNIFFER_REG__SNIFF_BEACON_TX, data);
+ ctx->sniff_beacon_rx = BF_GET(SNIFFER_REG__SNIFF_BEACON_RX, data);
+}
+
+
+/** Copy a MME to the buffer and request the interface to send the MME.
+ * \param ctx the sniffer context.
+ * \param mme the MME buffer
+ * \param length the MME length
+ * \param buffer the destination buffer.
+ * \param tx the MME way (TX/RX)
+ */
+void
+interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
+ u8 *buffer, bool tx, bool encrypted)
+{
+ uint word[3];
+
+ dbg_assert (ctx);
+ dbg_assert (mme);
+ dbg_assert (ETH_PACKET_MIN_SIZE <= length && length <=
+ ETH_PACKET_MAX_SIZE);
+ dbg_assert (buffer);
+ dbg_assert (ctx->send_func);
+
+ bitstream_memcpy (buffer, mme, length);
+
+ word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
+ (MSG_LENGTH, 2),
+ (PARAM_INTERFACE_TYPE, INTERFACE_MODULE_SNIFFER),
+ (PARAM_INTERFACE_LENGTH, length));
+
+ word[1] = BF_FILL (IPMBOX_REG, (PARAM_MODULE_WAY, !tx),
+ (PARAM_MODULE_ENC, encrypted),
+ (PARAM_MODULE_TYPE, SNIFFER_MME));
+
+ word[2] = (uint)buffer;
+
+
+ /** Request the interface to send the message to the linux driver. */
+ (*ctx->send_func) (ctx->send_user_data, word, 3);
+}
+
+/** Copy a beacon to the buffer and request the interface to send the copied beacon.
+ * Encapsulate the beacon in a MME.
+ * \param ctx the sniffer context.
+ * \param beacon the beacon
+ * \param buffer the destination buffer.
+ * \param tx the beacon way (TX/RX)
+ * \param mac_address the station mac address to fill the OSA ODA in the
+ * MME.
+ */
+void
+interface_sniffer_copy_beacon (interface_sniffer_t *ctx, pb_beacon_t *beacon,
+ u8 *buffer, bool tx, mac_t mac_address)
+{
+ bitstream_t bitstream;
+ uint data;
+ uint length;
+ uint word[3];
+
+ dbg_assert (ctx);
+ dbg_assert (buffer);
+ dbg_assert (beacon);
+
+ length = 136 + sizeof (pbproc_rx_beacon_params_t);
+
+ // Fill the buffer header.
+ bitstream_init (&bitstream, buffer, 27, BITSTREAM_WRITE);
+ bitstream_access (&bitstream, &mac_address, 48);
+ bitstream_access (&bitstream, &mac_address, 48);
+
+ /* Inserting the MTYPE. */
+ data = htons(HPAV_MTYPE_MME);
+ bitstream_access (&bitstream, &data, 16);
+
+ /* Inserting the MMV. */
+ data = HPAV_MMV;
+ bitstream_access (&bitstream, &data, 8);
+
+ /* Inserting the MMTYPE. */
+ data = 0xA036;
+ bitstream_access (&bitstream, &data, 16);
+
+ /* Inserting the FMI. */
+ data = 0;
+ bitstream_access (&bitstream, &data, 16);
+
+ /* Inserting the module type. */
+ data = INTERFACE_MODULE_SNIFFER;
+ bitstream_access (&bitstream, &data, 8);
+
+ /* Inserting data type i.e. beacon == 0 */
+ data = 0;
+ bitstream_access (&bitstream, &data, 8);
+
+ /* Inserting length. */
+ bitstream_access (&bitstream, &length, 16);
+
+ /* inserting the first data word of the beacon. */
+ bitstream_access (&bitstream, &beacon->first_data_word, 32);
+ bitstream_finalise (&bitstream);
+
+ /* Make a copy of the full beacon. */
+ bitstream_memcpy (buffer + 27, beacon->data, length - 4);
+
+
+ word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
+ (MSG_LENGTH, 2),
+ (PARAM_INTERFACE_TYPE, INTERFACE_MODULE_SNIFFER),
+ (PARAM_INTERFACE_LENGTH, length));
+
+ word[1] = BF_FILL (IPMBOX_REG, (PARAM_MODULE_WAY, !tx),
+ (PARAM_MODULE_ENC, 0),
+ (PARAM_MODULE_TYPE, SNIFFER_BEACON));
+
+ word[2] = (uint)buffer;
+
+
+ /** Request the interface to send the message to the linux driver. */
+ (*ctx->send_func) (ctx->send_user_data, word, 3);
+}
+
+
+/** Provides the MME sniff status.
+ * \param ctx the sniffer context.
+ * \param tx the way.
+ * \return the MME sniff status.
+ */
+bool
+interface_sniffer_mme_status (interface_sniffer_t *ctx, bool tx)
+{
+ dbg_assert (ctx);
+
+ if (tx)
+ return ctx->sniff_mme_tx;
+ else
+ return ctx->sniff_mme_rx;
+}
+
+/** Provides the beacon sniff status.
+ * \param ctx the sniffer context.
+ * \param tx the way.
+ * \return the beacon sniff status.
+ */
+bool
+interface_sniffer_beacon_status (interface_sniffer_t *ctx, bool tx)
+{
+ dbg_assert (ctx);
+
+ if (tx)
+ return ctx->sniff_beacon_tx;
+ else
+ return ctx->sniff_beacon_rx;
+}
+