summaryrefslogtreecommitdiff
path: root/cesar/cp2/cl_interf/src/cl_interf_old.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp2/cl_interf/src/cl_interf_old.c')
-rw-r--r--cesar/cp2/cl_interf/src/cl_interf_old.c216
1 files changed, 216 insertions, 0 deletions
diff --git a/cesar/cp2/cl_interf/src/cl_interf_old.c b/cesar/cp2/cl_interf/src/cl_interf_old.c
new file mode 100644
index 0000000000..60a580bfd8
--- /dev/null
+++ b/cesar/cp2/cl_interf/src/cl_interf_old.c
@@ -0,0 +1,216 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp2\cl_interf\src\cl_interf.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+
+#include "common/std.h"
+#include "cp2/mme.h"
+#include "cp2/cl_interf/cl_interf.h"
+
+
+
+// mbox for incomming msg
+static cyg_handle_t m_incoming_mbox_handle;
+static cyg_mbox m_incoming_mbox;
+static cp_t *m_cp_ctx = NULL;
+
+/**
+ * initialisation of cp_cl_interf module.
+ *
+ * \param ctx the cp context
+ *
+ * register callbacks in DP/CL module,
+ * clear buffers etc.
+ *
+ */
+void
+cp_cl_interf_init(cp_t *ctx)
+{
+ cyg_mbox_create( & m_incoming_mbox_handle, & m_incoming_mbox);
+ m_cp_ctx = ctx;
+}
+
+/**
+ * callback for Rx MME.
+ *
+ * \param ctx the cp context
+ * \param payload the mme itself
+ * \param payload_size size of the payload
+ * \param mfs the receiving mfs
+ * \param hardware_encrypted set to true if the mme was hardwarely encrypted
+ *
+ * !!! this function is executed in the CL context !!!
+ * 1) push the message in the MMEs fifo
+ * 2) set the flag to unlock the station core
+ */
+void
+cp_cl_interf_rx_mme(
+ void *user,
+ mfs_rx_t *mfs,
+ u8 *buffer,
+ uint length,
+ cl_mme_recv_t *mme_recv,
+ bool encryption
+ )
+{
+ cp_mme_rx_t *cp_mme_rx = NULL;
+
+ dbg_assert(msf);
+ dbg_assert(buffer);
+ dbg_assert(mme_recv);
+
+ // TODO change the malloc with the slab allocator
+ cp_mme_rx = malloc(sizeof(cp_mme_rx_t));
+ dbg_assert(cp_mme_rx);
+
+
+ cp_mme_rx->p_mme = buffer;
+ cp_mme_rx->p_frag = NULL;
+ cp_mme_rx->length = length;
+ cp_mme_rx->mfs = mfs;
+ cp_mme_rx->hw_encrypted = encryption;
+
+ #if DEBUG
+ dbg_assert(cyg_mbox_tryput(m_incoming_mbox_handle, (void *) cp_mme_rx));
+ #else
+ cyg_mbox_put (m_incoming_mbox_handle, (void *) cp_mme_rx);
+ #endif
+ // set the event flag for the station
+ // TODO use the station's module API
+ cyg_flag_setbits (&station_flag, STATION_FLAG_MSG_RCV);
+}
+
+/**
+ * return the last received and completed mme.
+ *
+ * \param ctx the cp context
+ * \return mme_rx_t the mme context (for unit test purpose only)
+ *
+ * 1) get the last MME from the MMEs fifo
+ * 2) read the MME's header and store it in a newly allocated MME Tx context
+ * 3) check the ODA, and the MME constants
+ * 4) if it is a fragment from a bigger MME
+ * - update the MME context
+ * - copy the payload in 512 byte blocs
+ * 5) if the message is completed, call the msg_dispatch function
+ */
+cp_mme_rx_t *
+cp_cl_interf_give_last_mme(cp_t *ctx)
+{
+ u16 tmp;
+ bool check_mme_ok = true;
+ cp_mme_rx_t *cp_mme_rx = NULL;
+ // 1) get the last MME from the MMEs fifo
+ if(cp_mme_rx = cyg_mbox_tryget (m_incoming_mbox_handle)) != NULL )
+ {
+ // 2) read the MME's header and store it in a newly allocated MME Tx context
+ bitstream_init(cp_mme_rx->bitstream, cp_mme_rx->p_mme, cp_mme_rx->length, read);
+
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.oda, 48);
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.osa, 48);
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.m_type, 16);
+ // check if this is the expected m_type
+ if(cp_mme_rx->header.m_type != MSG_MTYPE_IEEE_ETHERTYPE)
+ {
+ // if not, we have a vlan tag
+ // so, read and compute the vlan tag
+ cp_mme_rx->header.v_lan_tag = cp_mme_rx->header.m_type << 0xFF;
+ bitstream_access(cp_mme_rx->bitstream, &tmp, 16);
+ cp_mme_rx->header.v_lan_tag |= tmp;
+ // and read the ethertype
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.m_type, 16);
+ }
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.mmv, 8);
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.mm_type, 16);
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.nf_mi, 4);
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.fn_mi, 4);
+ bitstream_access(cp_mme_rx->bitstream, &cp_mme_rx->header.fmsn, 8);
+ // 3) check the ODA, and the MME constants
+ if(cp_mme_rx->header.oda != cp_sta_own_data_get_mac_address(NULL))
+ check_mme_ok = false;
+ if(cp_mme_rx->header.m_type != MSG_MTYPE_IEEE_ETHERTYPE)
+ check_mme_ok = false;
+ if(cp_mme_rx->header.mmv != MSG_MM_VERSION)
+ check_mme_ok = false;
+ if(check_mme_ok == false)
+ {
+ // then release the MME and forget it
+ // TODO
+ }
+ else
+ {
+ // check if the message is complete
+ if(cp_mme_rx->header.nf_mi == cp_mme_rx->header.fn_mi)
+ {
+ // yes, so call the msg_dispatch function
+ cp_msg_dispatch(ctx, cp_mme_rx);
+ }
+ else
+ {
+ // no, so store the message
+ // TODO
+ }
+ }
+ }
+ return cp_mme_rx;
+}
+
+
+/**
+ * return the Tx MME buffer.
+ *
+ * \param ctx the cp context
+ * \return mme_rx_t the mme context
+ *
+ * !!! This function must be thread-safe !!!
+ * If the Tx buffer is available, return it.
+ * else, wait for it.
+ * It can be called either from CP or CE thread, and the Tx buffer is given
+ * from the CL environnement.
+ */
+mme_tx_t *
+cp_cl_interf_give_tx_buffer(cp_t *ctx);
+
+/**
+ * will send the MME buffer to the DP.
+ *
+ * \param ctx the cp context
+ * \param mme the mme to send and it context
+ *
+ * Must retreive the MFS and send the message through this MFS.
+ * if necessary, will pad the message to the minimum MME size
+ */
+void
+cp_cl_interf_mme_send(cp_t *ctx, mme_tx_t *mme);
+
+/**
+ * callback used by the CL to give back the Tx buffer.
+ *
+ * \param ctx the cp context
+ * \param buffer the buffer
+ *
+ * * !!! this function is executed in the CL context
+ */
+void
+cp_cl_interf_receive_tx_buffer(cp_t *ctx, u8 * buffer);
+
+/**
+ * this function will remove expired block of fragmented mme.
+ *
+ * \param ctx the cp context
+ *
+ * it is called periodicly, and will check all the currently stored MME
+ * fragments. If necessary, release it.
+ */
+void
+cp_cl_interf_garbage_collector(cp_t *ctx);