summaryrefslogtreecommitdiff
path: root/cesar
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
parent89328e8cc096f8c9f340a3eb8910d06748a3e572 (diff)
cesar, cleopatre, common: new ipmbox design, closes #848
Diffstat (limited to 'cesar')
-rw-r--r--cesar/bsu/stub/src/bsu.c9
-rw-r--r--cesar/bufmgr/Module (renamed from cesar/hle/Module)2
-rw-r--r--cesar/bufmgr/bufmgr.h96
-rw-r--r--cesar/bufmgr/inc/context.h69
-rw-r--r--cesar/bufmgr/inc/trace.h56
-rw-r--r--cesar/bufmgr/src/bufmgr.c180
-rw-r--r--cesar/bufmgr/src/trace.c42
-rw-r--r--cesar/bufmgr/stub/Module1
-rw-r--r--cesar/bufmgr/stub/src/bufmgr.c76
-rw-r--r--cesar/bufmgr/test/utest/Config1
-rw-r--r--cesar/bufmgr/test/utest/Makefile11
-rw-r--r--cesar/bufmgr/test/utest/inc/scenario_defs.h84
-rw-r--r--cesar/bufmgr/test/utest/inc/test_bufmgr.h20
-rw-r--r--cesar/bufmgr/test/utest/src/bufmgr.c260
-rw-r--r--cesar/bufmgr/test/utest/src/ipmbox.c48
-rw-r--r--cesar/bufmgr/test/utest/src/scenario_defs.c90
-rw-r--r--cesar/ce/fcall/src/fcall.c2
-rw-r--r--cesar/ce/rx/test/src/test_rx.c6
-rw-r--r--cesar/cl/Module5
-rw-r--r--cesar/cl/cl.h311
-rw-r--r--cesar/cl/inc/cl.h49
-rw-r--r--cesar/cl/inc/context.h98
-rw-r--r--cesar/cl/inc/receive.h74
-rw-r--r--cesar/cl/inc/send.h42
-rw-r--r--cesar/cl/inc/trace.h3
-rw-r--r--cesar/cl/mbx/Module1
-rw-r--r--cesar/cl/mbx/inc/mbx.h32
-rw-r--r--cesar/cl/mbx/mbx.h73
-rw-r--r--cesar/cl/mbx/src/mbx.c92
-rw-r--r--cesar/cl/mbx/stub/Module1
-rw-r--r--cesar/cl/mbx/stub/src/mbx.c45
-rw-r--r--cesar/cl/src/brg_rx.c7
-rw-r--r--cesar/cl/src/cl.c969
-rw-r--r--cesar/cl/src/cl_mactotei.c5
-rw-r--r--cesar/cl/src/receive.c107
-rw-r--r--cesar/cl/src/send.c455
-rw-r--r--cesar/cl/src/trace.c4
-rw-r--r--cesar/cl/stub/src/cl.c132
-rw-r--r--cesar/cl/test/bridge_table/Makefile2
-rw-r--r--cesar/cl/test/data_rate/Makefile2
-rw-r--r--cesar/cl/test/functional/Makefile.mk8
-rw-r--r--cesar/cl/test/functional/host-Makefile12
-rw-r--r--cesar/cl/test/functional/sparc-Makefile12
-rw-r--r--cesar/cl/test/functional/src/cl.c115
-rw-r--r--cesar/cl/test/utest/Makefile11
-rw-r--r--cesar/cl/test/utest/src/brg_rx.c1
-rw-r--r--cesar/cl/test/utest/src/hle_tools.c37
-rw-r--r--cesar/cl/test/utest/src/misc.c2
-rw-r--r--cesar/cl/test/utest/src/receive.c125
-rw-r--r--cesar/cl/test/utest/src/send.c6
-rw-r--r--cesar/cl/test/utest/src/test.c52
-rw-r--r--cesar/cl/test/utest/test.h18
-rw-r--r--cesar/cp/cl_interf/cl_interf.h9
-rw-r--r--cesar/cp/cl_interf/doc/cl-interf.xmi1
-rw-r--r--cesar/cp/cl_interf/inc/cl_interf.h2
-rw-r--r--cesar/cp/cl_interf/inc/cl_interf_msg.h5
-rw-r--r--cesar/cp/cl_interf/inc/context.h5
-rw-r--r--cesar/cp/cl_interf/src/cl_interf.c62
-rw-r--r--cesar/cp/cl_interf/test/Makefile3
-rw-r--r--cesar/cp/cl_interf/test/override/cp/inc/context.h1
-rw-r--r--cesar/cp/cl_interf/test/src/test-cl-interf.c52
-rw-r--r--cesar/cp/cp.h2
-rw-r--r--cesar/cp/doc/mme_tx.msc1
-rw-r--r--cesar/cp/inc/context.h4
-rw-r--r--cesar/cp/mme.h2
-rw-r--r--cesar/cp/msg/inc/msg.h4
-rw-r--r--cesar/cp/msg/msg.h3
-rw-r--r--cesar/cp/msg/src/mme.c12
-rw-r--r--cesar/cp/msg/src/msg.c4
-rw-r--r--cesar/cp/msg/stub/src/msg.c4
-rw-r--r--cesar/cp/msg/test/Makefile40
-rw-r--r--cesar/cp/msg/test/overide/cp/inc/context.h4
-rw-r--r--cesar/cp/msg/test/src/cc_discover_list.c5
-rw-r--r--cesar/cp/msg/test/src/cp_cl_interface_stub.c5
-rw-r--r--cesar/cp/msg/test/src/interface_stub.c27
-rw-r--r--cesar/cp/msg/test/src/mme_frag.c5
-rw-r--r--cesar/cp/msg/test/src/msg.c12
-rw-r--r--cesar/cp/msg/test/src/msg_cc.c108
-rw-r--r--cesar/cp/msg/test/src/msg_cm.c56
-rw-r--r--cesar/cp/msg/test/src/msg_vs.c53
-rw-r--r--cesar/cp/msg/test/src/relay.c3
-rw-r--r--cesar/cp/msg/test/src/test-msg-read-header.c30
-rw-r--r--cesar/cp/src/cp.c7
-rw-r--r--cesar/cp/sta/action/test/utest/Makefile3
-rw-r--r--cesar/cp/sta/core/stub/src/sta_core.c12
-rw-r--r--cesar/cp/sta/mgr/test/Makefile2
-rw-r--r--cesar/hal/Module4
-rw-r--r--cesar/hal/hle/Module1
-rw-r--r--cesar/hal/hle/defs.h73
-rw-r--r--cesar/hal/hle/forward.h19
-rw-r--r--cesar/hal/hle/inc/hal_ipmbox.h130
-rw-r--r--cesar/hal/hle/inc/ipmbox.h105
-rw-r--r--cesar/hal/hle/inc/reg_ipmbox.h91
-rw-r--r--cesar/hal/hle/ipmbox.h71
-rw-r--r--cesar/hal/hle/maximus/inc/maximus_defs.h19
-rw-r--r--cesar/hal/hle/maximus/inc/maximus_interrupts.h20
-rw-r--r--cesar/hal/hle/maximus/inc/maximus_ipmbox_ctx.h70
-rw-r--r--cesar/hal/hle/maximus/src/maximus_ipmbox.c337
-rw-r--r--cesar/hal/hle/maximus/test/inc/test_maximus_hle.h42
-rw-r--r--cesar/hal/hle/maximus/test/src/test_maximus_hle.c67
-rw-r--r--cesar/hal/hle/maximus/test/src/test_maximus_ipmbox.c394
-rw-r--r--cesar/hal/hle/src/hal_ipmbox.c83
-rw-r--r--cesar/hal/hle/src/ipmbox.c216
-rw-r--r--cesar/hal/hle/test/Makefile15
-rw-r--r--cesar/hal/hle/test/src/hal_hle_hal_ipmbox.c260
-rw-r--r--cesar/hal/hle/test/src/hal_hle_ipmbox.c328
-rw-r--r--cesar/hal/ipmbox/Module2
-rw-r--r--cesar/hal/ipmbox/doc/claudia_ipmbox.odt (renamed from cesar/hal/hle/doc/claudia_ipmbox.odt)bin200409 -> 200409 bytes
-rw-r--r--cesar/hal/ipmbox/inc/ecos.h50
-rw-r--r--cesar/hal/ipmbox/inc/ipmbox.h48
-rw-r--r--cesar/hal/ipmbox/inc/regs.h19
-rw-r--r--cesar/hal/ipmbox/ipmbox.h133
-rw-r--r--cesar/hal/ipmbox/maximus/Module (renamed from cesar/hal/hle/maximus/Module)0
-rw-r--r--cesar/hal/ipmbox/maximus/inc/maximus_ether.h (renamed from cesar/hal/hle/maximus/inc/maximus_ether.h)24
-rw-r--r--cesar/hal/ipmbox/maximus/inc/maximus_interrupts.h22
-rw-r--r--cesar/hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h108
-rw-r--r--cesar/hal/ipmbox/maximus/src/maximus_ether.c (renamed from cesar/hal/hle/maximus/src/maximus_ether.c)269
-rw-r--r--cesar/hal/ipmbox/maximus/src/maximus_ipmbox.c508
-rw-r--r--cesar/hal/ipmbox/maximus/test/Config (renamed from cesar/hal/hle/maximus/test/Config)0
-rw-r--r--cesar/hal/ipmbox/maximus/test/Makefile (renamed from cesar/hal/hle/maximus/test/Makefile)4
-rw-r--r--cesar/hal/ipmbox/maximus/test/src/test_maximus_ether.c (renamed from cesar/hal/hle/maximus/test/src/test_maximus_ether.c)291
-rw-r--r--cesar/hal/ipmbox/maximus/test/src/test_maximus_ipmbox.c337
-rw-r--r--cesar/hal/ipmbox/src/ipmbox.c411
-rw-r--r--cesar/hal/ipmbox/stub/Module1
-rw-r--r--cesar/hal/ipmbox/stub/src/ipmbox.c117
-rw-r--r--cesar/hal/ipmbox/test/Config1
-rw-r--r--cesar/hal/ipmbox/test/Makefile10
-rw-r--r--cesar/hal/ipmbox/test/override/hal/ipmbox/inc/ecos.h58
-rw-r--r--cesar/hal/ipmbox/test/override/hal/ipmbox/inc/regs.h21
-rw-r--r--cesar/hal/ipmbox/test/src/ipmbox.c502
-rw-r--r--cesar/hal/phy/maximus/test/src/test_phy_access.c29
-rw-r--r--cesar/hal/phy/maximus/test/src/test_phy_ctrl.c89
-rw-r--r--cesar/hal/phy/maximus/test/src/test_tmdma.c4
-rw-r--r--cesar/hal/phy/soft/bridgedma/src/bridgedma.c3
-rw-r--r--cesar/hal/phy/test/phy/sparc-Makefile3
-rw-r--r--cesar/hal/phy/test/phy/src/dataplane_stub.c63
-rw-r--r--cesar/hal/phy/test/phy/src/test_phy.c32
-rwxr-xr-xcesar/hle/doc/cesar_hle.odtbin105764 -> 0 bytes
-rw-r--r--cesar/hle/hle.h96
-rw-r--r--cesar/hle/inc/context.h62
-rw-r--r--cesar/hle/inc/trace.h75
-rw-r--r--cesar/hle/src/hle.c360
-rw-r--r--cesar/hle/src/trace.c72
-rw-r--r--cesar/hle/test/Makefile19
-rw-r--r--cesar/hle/test/src/hle_recv_from_arm.c336
-rw-r--r--cesar/hle/test/src/hle_send_to_arm.c108
-rw-r--r--cesar/hle/test/src/interface-send.c101
-rw-r--r--cesar/hle/test/src/ipmbox.c38
-rw-r--r--cesar/hle/tools/inc/context.h2
-rw-r--r--cesar/hle/tools/inc/debug_dump.h5
-rw-r--r--cesar/hle/tools/inc/rpc.h1
-rw-r--r--cesar/hle/tools/src/debug_dump.c52
-rw-r--r--cesar/hle/tools/src/rpc.c23
-rw-r--r--cesar/hle/tools/src/tools.c33
-rw-r--r--cesar/hle/tools/test/utest/inc/scenario_defs.h15
-rw-r--r--cesar/hle/tools/test/utest/src/scenario_defs.c12
-rw-r--r--cesar/hle/tools/test/utest/src/test_hle_tools.c31
-rw-r--r--cesar/hle/tools/tools.h28
-rw-r--r--cesar/host/test/src/test_netclock.c95
-rw-r--r--cesar/host/test/src/test_sci.c5
-rw-r--r--cesar/interface/fcall/defs.h6
-rw-r--r--cesar/interface/fcall/inc/context.h39
-rw-r--r--cesar/interface/fcall/interface_fcall.h21
-rw-r--r--cesar/interface/fcall/src/interface_fcall.c70
-rw-r--r--cesar/interface/fcall/test/Makefile4
-rw-r--r--cesar/interface/fcall/test/src/bufmgr_stub.c28
-rw-r--r--cesar/interface/fcall/test/src/test_interface_fcall.c204
-rw-r--r--cesar/interface/inc/context.h23
-rw-r--r--cesar/interface/inc/interface.h37
-rw-r--r--cesar/interface/interface.h49
-rw-r--r--cesar/interface/sniffer/inc/context.h11
-rw-r--r--cesar/interface/sniffer/mmtype.h2
-rw-r--r--cesar/interface/sniffer/sniffer.h59
-rw-r--r--cesar/interface/sniffer/src/sniffer.c75
-rw-r--r--cesar/interface/sniffer/test/Makefile5
-rw-r--r--cesar/interface/sniffer/test/src/bufmgr_stub.c28
-rw-r--r--cesar/interface/sniffer/test/src/test-sniffer.c24
-rw-r--r--cesar/interface/src/interface.c320
-rw-r--r--cesar/interface/stub/src/interface.c73
-rw-r--r--cesar/interface/test/Makefile.mk9
-rw-r--r--cesar/interface/test/sparc-Makefile14
-rw-r--r--cesar/interface/test/src/bufmgr_stub.c34
-rw-r--r--cesar/interface/test/src/sar_stub.c3
-rw-r--r--cesar/interface/test/src/test-interface.c127
-rw-r--r--cesar/interface/test/synth-Makefile13
-rw-r--r--cesar/mac/pbproc/test/int/sparc-Makefile4
-rw-r--r--cesar/mac/pbproc/test/int/src/dataplane_stub.c63
-rw-r--r--cesar/mac/pbproc/test/int/src/test_pbproc.c18
-rw-r--r--cesar/mac/sar/inc/sar.h9
-rw-r--r--cesar/mac/sar/inc/sar_context.h57
-rw-r--r--cesar/mac/sar/inc/sar_job_mfs.h2
-rw-r--r--cesar/mac/sar/sar.h159
-rw-r--r--cesar/mac/sar/src/sar.c328
-rw-r--r--cesar/mac/sar/src/sar_expiration.c4
-rw-r--r--cesar/mac/sar/stub/src/sar.c80
-rw-r--r--cesar/mac/sar/test/functional/Makefile.mk17
-rw-r--r--cesar/mac/sar/test/functional/src/bufmgr_stub.c81
-rw-r--r--cesar/mac/sar/test/functional/src/test_functions.c113
-rw-r--r--cesar/mac/sar/test/functional/test_functions.h13
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/Makefile6
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/activate.c17
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/bufmgr_stub.c69
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/misc.c64
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/reassembly.c70
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/sar_call_back_ul.c44
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/segmentation.c26
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/stats.c7
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/tests.c27
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/tests.h21
-rw-r--r--cesar/maximus/common/types/ethernet_types.h11
-rw-r--r--cesar/maximus/common/types/sci_types.h4
-rw-r--r--cesar/maximus/ethernet/inc/EtherSciMsgTest.h1
-rw-r--r--cesar/maximus/ethernet/src/EtherSciMsg.cpp11
-rw-r--r--cesar/maximus/ethernet/src/EtherSciMsgTest.cpp4
-rw-r--r--cesar/maximus/prototest/fcall/Makefile3
-rw-r--r--cesar/maximus/prototest/fcall/inc/syscall.h1
-rw-r--r--cesar/maximus/prototest/fcall/src/test_fcall.c93
-rw-r--r--cesar/maximus/prototest/integration/Makefile2
-rw-r--r--cesar/maximus/prototest/integration/src/cl_stub.c44
-rw-r--r--cesar/maximus/prototest/integration/src/test_integration.c1
-rw-r--r--cesar/maximus/python/lib/cesar/sta_cesar.py8
-rw-r--r--cesar/maximus/python/lib/proto/maximus_proto.py4
-rw-r--r--cesar/maximus/python/maximus/ethernet/__init__.py2
-rw-r--r--cesar/maximus/python/maximus/ethernet/buffer.py23
-rw-r--r--cesar/maximus/python/maximus/ethernet/create.py6
-rw-r--r--cesar/maximus/python/maximus/ethernet/sniffer.py60
-rw-r--r--cesar/maximus/python/maximus/macframe/msdu.py7
-rw-r--r--cesar/maximus/python/maximus/mme/mme.py19
-rw-r--r--cesar/maximus/python/maximus/simu/rx.py6
-rw-r--r--cesar/maximus/python/maximus/station/sta.py99
-rw-r--r--cesar/maximus/python/py/test_ether.py105
-rw-r--r--cesar/maximus/python/src/interface_module.cpp20
-rw-r--r--cesar/maximus/python/test/test_ethernet.py179
-rw-r--r--cesar/maximus/python/test/test_interface.py4
-rw-r--r--cesar/maximus/python/test/test_lib_cesar.py8
-rw-r--r--cesar/maximus/python/test/test_station.py8
-rw-r--r--cesar/maximus/python/tools/csi/csicore.py15
-rw-r--r--cesar/maximus/python/tools/csi/csifilter.py4
-rw-r--r--cesar/maximus/stationtest/Makefile6
-rw-r--r--cesar/maximus/stationtest/src/test_ether.c170
-rw-r--r--cesar/maximus/stationtest/src/test_lib_cesar.c123
-rw-r--r--cesar/maximus/stationtest/src/test_station.c123
-rwxr-xr-xcesar/maximus/test/test.sh22
-rwxr-xr-xcesar/maximus/test/test_python.sh53
-rw-r--r--cesar/projects/plc/Makefile3
-rw-r--r--cesar/station/src/station.c26
-rw-r--r--cesar/station/station.h10
-rw-r--r--cesar/test_general/dataplane/inc/context.h3
-rw-r--r--cesar/test_general/dataplane/inc/trace_dump.h2
-rw-r--r--cesar/test_general/dataplane/maximus-Makefile2
-rw-r--r--cesar/test_general/dataplane/sparc-Config1
-rw-r--r--cesar/test_general/dataplane/sparc-Makefile2
-rw-r--r--cesar/test_general/dataplane/src/test_dataplane.c24
-rw-r--r--cesar/test_general/dataplane/src/trace_dump.c5
-rw-r--r--cesar/test_general/station/common/src/station.c2
-rw-r--r--cesar/test_general/station/compliance/Makefile.mk4
-rw-r--r--cesar/test_general/station/fcall/src/sta_mgr.c2
-rw-r--r--cesar/test_general/station/maximus/Makefile4
-rw-r--r--cesar/test_general/station/scenario/Makefile5
-rw-r--r--cesar/test_general/station/scenario/py/sc15_hide.py2
-rw-r--r--cesar/test_general/station/scenario/py/scenario_init.py11
-rw-r--r--cesar/test_general/station/tonemap/common-define.mk4
-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
265 files changed, 6800 insertions, 8898 deletions
diff --git a/cesar/bsu/stub/src/bsu.c b/cesar/bsu/stub/src/bsu.c
index af23873e84..1d7e231c5d 100644
--- a/cesar/bsu/stub/src/bsu.c
+++ b/cesar/bsu/stub/src/bsu.c
@@ -82,3 +82,12 @@ bsu_update_tracking (bsu_t *ctx, u8 tei, mac_t mac_addr_track)
void
bsu_update_tracking (bsu_t *ctx, u8 tei, mac_t mac_addr_track)
{}
+
+void
+bsu_init_beacon_cb (bsu_beacon_processed_t cb, void *cb_ud)
+ __attribute__((weak));
+
+void
+bsu_init_beacon_cb (bsu_beacon_processed_t cb, void *cb_ud)
+{
+}
diff --git a/cesar/hle/Module b/cesar/bufmgr/Module
index d835eb2d0a..7054f922ce 100644
--- a/cesar/hle/Module
+++ b/cesar/bufmgr/Module
@@ -1,4 +1,4 @@
-SOURCES := hle.c
+SOURCES := bufmgr.c
ifeq ($(CONFIG_TRACE),y)
SOURCES += trace.c
endif
diff --git a/cesar/bufmgr/bufmgr.h b/cesar/bufmgr/bufmgr.h
new file mode 100644
index 0000000000..b4cf912fd0
--- /dev/null
+++ b/cesar/bufmgr/bufmgr.h
@@ -0,0 +1,96 @@
+#ifndef bufmgr_bufmgr_h
+#define bufmgr_bufmgr_h
+
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bufmgr/bufmgr.h
+ * \brief Public interfaces for buffer manager.
+ * \ingroup bufmgr
+ *
+ * The buffer manager is responsible for passing empty buffers coming from
+ * Linux to other cesar components and returning used buffers from those
+ * components to Linux.
+ *
+ * Buffer manager is responsible for informing clients after a try get that
+ * new buffers are available. For that, clients must register.
+ */
+#include "hal/ipmbox/ipmbox.h"
+
+/* Forward declaration. */
+typedef struct bufmgr_t bufmgr_t;
+
+/**
+ * Callback prototype.
+ * \param user_data the user_data to give with the callback
+ */
+typedef void (*bufmgr_callback_t) (void *user_data);
+
+BEGIN_DECLS
+
+/**
+ * Get a buffer from the buffer manager.
+ * \param ctx module context
+ * \return a buffer, NULL if none available
+ */
+u8 *
+bufmgr_get (bufmgr_t *ctx);
+
+/**
+ * Get a buffer from the buffer manager and wait it for a certain delay or
+ * until it gets it.
+ * \param ctx module context
+ * \param delay_ms delay of wait in ms, 0 if client wants to wait forever
+ * \return a buffer, NULL if no buffer available and the delay expired
+ */
+u8 *
+bufmgr_get_wait (bufmgr_t *ctx, uint delay_rtc);
+
+/**
+ * Give back a buffer.
+ * \param ctx module context
+ * \param buffer buffer to return
+ */
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer);
+
+/**
+ * Give the buffer to buffer manager to keep it.
+ * \param ctx module context
+ * \param buffer buffer to return
+ */
+void
+bufmgr_keep_buffer (bufmgr_t *ctx, u8 *buffer);
+
+/**
+ * Register a client to the buffer manager.
+ * \param ctx module context
+ * \param cb the callback to call
+ * \param user_data the user data to provide
+ */
+void
+bufmgr_client_register (bufmgr_t *ctx, bufmgr_callback_t cb, void *user_data);
+
+/**
+ * Initialise the module.
+ * \param ipmbox the ipmbox context
+ * \return buffer manager context
+ */
+bufmgr_t *
+bufmgr_init (ipmbox_t *ipmbox);
+
+/**
+ * Uninitialise the module.
+ * \param ctx module context
+ */
+void
+bufmgr_uninit (bufmgr_t *ctx);
+
+END_DECLS
+
+#endif /* bufmgr_bufmgr_h */
diff --git a/cesar/bufmgr/inc/context.h b/cesar/bufmgr/inc/context.h
new file mode 100644
index 0000000000..1f2d59e75c
--- /dev/null
+++ b/cesar/bufmgr/inc/context.h
@@ -0,0 +1,69 @@
+#ifndef bufmgr_inc_context_h
+#define bufmgr_inc_context_h
+
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bufmgr/inc/context.h
+ * \brief Buffer manager context structure definition.
+ * \ingroup bufmgr
+ */
+#include "common/ipmbox/protocol.h"
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/arch/sem.h"
+
+#include "bufmgr/inc/trace.h"
+
+/* Size of the local buffer list. */
+#define BUFMGR_BUFFER_LIST_SIZE \
+ (IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF / 2)
+
+/* Number of required local buffers in local list.
+ * The list is bigger to store empty buffers received from the PLC to the CP.
+ * Those buffers are empty buffers given by linux and must be kept in the
+ * buffer manager. */
+#define BUFMGR_BUFFER_LIST_NB (BUFMGR_BUFFER_LIST_SIZE / 2)
+
+/* Number of buffer reserved for blocking clients. */
+#define BUFMGR_RESERVED_BUFFER_NB 4
+
+/* Number of registered clients. */
+#define BUFMGR_CLIENT_NB 5
+
+/* Client callback. */
+struct bufmgr_client_t
+{
+ /** Callback. */
+ bufmgr_callback_t cb;
+ /** User data. */
+ void *user_data;
+};
+typedef struct bufmgr_client_t bufmgr_client_t;
+
+/* Context structure. */
+struct bufmgr_t
+{
+ /* IPMbox context. */
+ ipmbox_t *ipmbox;
+ /** Table of client callback. */
+ bufmgr_client_t client[BUFMGR_CLIENT_NB];
+ /** Number of clients registered. */
+ uint client_nb;
+ /** List of buffers. */
+ u32 buffers [BUFMGR_BUFFER_LIST_SIZE];
+ /** Number of available buffers. */
+ uint buffers_nb;
+ /** Semaphore for reserved buffers. */
+ hal_arch_sem_t sem;
+#if CONFIG_TRACE
+ /** Buffer Manager Trace */
+ trace_buffer_t trace;
+#endif
+};
+
+#endif /*bufmgr_inc_context_h*/
diff --git a/cesar/bufmgr/inc/trace.h b/cesar/bufmgr/inc/trace.h
new file mode 100644
index 0000000000..bb9600eb92
--- /dev/null
+++ b/cesar/bufmgr/inc/trace.h
@@ -0,0 +1,56 @@
+#ifndef bufmgr_inc_trace_h
+#define bufmgr_inc_trace_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cesar/bufmgr/inc/trace.h
+ * \brief Buffer manager traces.
+ * \ingroup bufmgr
+ */
+
+#include "lib/trace.h"
+
+/** Shortcut for tracing inside buffer manager . */
+#define BUFMGR_TRACE(id, args...) \
+ TRACE_FAST_SHORT (BUFMGR_TRACE_, &ctx->trace, id, ## args)
+
+#if CONFIG_TRACE
+
+enum
+{
+ BUFMGR_TRACE_BUFFER_GET,
+ BUFMGR_TRACE_BUFFER_GET_WAIT,
+ BUFMGR_TRACE_BUFFER_GIVE_BACK,
+ BUFMGR_TRACE_BUFFER_NEW,
+ BUFMGR_TRACE_BUFFER_KEEP,
+};
+
+/**
+ * Initialize the trace system
+ * \param ctx the bufmgr context.
+ */
+void
+bufmgr_trace_init (bufmgr_t *ctx);
+
+/**
+ * Uninitialise the trace system
+ * \param ctx the bufmgr context
+ */
+void
+bufmgr_trace_uninit (bufmgr_t *ctx);
+
+END_DECLS
+
+#else /* !CONFIG_TRACE */
+
+#define bufmgr_trace_init(ctx) ((void) 0)
+#define bufmgr_trace_uninit(ctx) ((void) 0)
+
+#endif /* !CONFIG_TRACE */
+
+#endif /* bufmgr_inc_trace_h */
diff --git a/cesar/bufmgr/src/bufmgr.c b/cesar/bufmgr/src/bufmgr.c
new file mode 100644
index 0000000000..73ff9d8e7b
--- /dev/null
+++ b/cesar/bufmgr/src/bufmgr.c
@@ -0,0 +1,180 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bufmgr/src/bufmgr.c
+ * \brief Buffer Manager
+ * \ingroup bufmgr
+ */
+#include "common/std.h"
+
+#include "common/ipmbox/msg.h"
+
+#include "hal/ipmbox/ipmbox.h"
+
+#include "bufmgr/bufmgr.h"
+#include "bufmgr/inc/context.h"
+#include "bufmgr/inc/trace.h"
+
+static bufmgr_t bufmgr_global;
+
+/**
+ * Fill buffer cache table.
+ * \param ctx module context
+ *
+ * Must be called DSR locked.
+ */
+PRIVATE inline void
+bufmgr_fill_cache (bufmgr_t *ctx)
+{
+ /* This is OK as DSR is locked. */
+ uint reserved_buf_nb = hal_arch_sem_peek (&ctx->sem);
+ uint missing_reserved_buffers = BUFMGR_RESERVED_BUFFER_NB
+ - reserved_buf_nb;
+ if (ctx->buffers_nb < BUFMGR_BUFFER_LIST_NB)
+ {
+ uint nb_got = ipmbox_empty_buf_get (
+ ctx->ipmbox, &ctx->buffers[ctx->buffers_nb],
+ BUFMGR_BUFFER_LIST_NB - ctx->buffers_nb);
+ ctx->buffers_nb += nb_got;
+ }
+ /* Try to convert cached buffers into reserved buffers. */
+ missing_reserved_buffers =
+ MIN (missing_reserved_buffers, ctx->buffers_nb - reserved_buf_nb);
+ for ( ; missing_reserved_buffers; missing_reserved_buffers--)
+ hal_arch_sem_post (&ctx->sem);
+}
+
+u8 *
+bufmgr_get (bufmgr_t *ctx)
+{
+ dbg_claim (ctx);
+ u8 *buffer = NULL;
+ arch_dsr_lock ();
+ if (ctx->buffers_nb <= BUFMGR_RESERVED_BUFFER_NB)
+ bufmgr_fill_cache (ctx);
+ /* Give a buffer is possible. */
+ if (ctx->buffers_nb > BUFMGR_RESERVED_BUFFER_NB)
+ {
+ buffer = (u8 *) ctx->buffers[ctx->buffers_nb - 1];
+ ctx->buffers_nb--;
+ }
+ BUFMGR_TRACE (BUFFER_GET, buffer);
+ arch_dsr_unlock ();
+ return buffer;
+}
+
+static inline u8 *
+bufmgr_reserved_get (bufmgr_t *ctx)
+{
+ u8 *buffer = NULL;
+ arch_dsr_lock ();
+ buffer = (u8 *) ctx->buffers[ctx->buffers_nb - 1];
+ ctx->buffers_nb--;
+ arch_dsr_unlock ();
+ return buffer;
+}
+
+u8 *
+bufmgr_get_wait (bufmgr_t *ctx, uint delay_rtc)
+{
+ u8 *buffer = NULL;
+ do
+ {
+ buffer = bufmgr_get (ctx);
+ if (buffer)
+ break;
+ if (delay_rtc)
+ {
+ if (hal_arch_sem_timed_wait (&ctx->sem, delay_rtc))
+ buffer = bufmgr_reserved_get (ctx);
+ break;
+ }
+ else
+ {
+ hal_arch_sem_wait (&ctx->sem);
+ buffer = bufmgr_reserved_get (ctx);
+ }
+ } while (!buffer);
+ BUFMGR_TRACE (BUFFER_GET_WAIT, buffer, delay_rtc);
+ return buffer;
+}
+
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer)
+{
+ dbg_claim (ctx);
+ dbg_claim (buffer);
+ BUFMGR_TRACE (BUFFER_GIVE_BACK, buffer);
+ ipmbox_msg_empty_buf_t msg = { .buffer_addr = (u32) buffer };
+ ipmbox_tx_empty_buf (ctx->ipmbox, (u32 *) &msg,
+ IPMBOX_MSG_EMPTY_BUF_WORDS);
+}
+
+void
+bufmgr_keep_buffer (bufmgr_t *ctx, u8 *buffer)
+{
+ dbg_claim (ctx);
+ dbg_claim (buffer);
+ arch_dsr_lock ();
+ BUFMGR_TRACE (BUFFER_KEEP, buffer);
+ dbg_assert (ctx->buffers_nb < BUFMGR_BUFFER_LIST_SIZE);
+ ctx->buffers[ctx->buffers_nb] = (u32) buffer;
+ ctx->buffers_nb++;
+ if (hal_arch_sem_peek (&ctx->sem) < BUFMGR_RESERVED_BUFFER_NB)
+ hal_arch_sem_post (&ctx->sem);
+ arch_dsr_unlock ();
+}
+
+/**
+ * Call each client that has asked to be recalled on a lack of buffers.
+ * \param ctx module context
+ */
+static void
+bufmgr_handle_new_buf (bufmgr_t *ctx)
+{
+ uint i;
+ bufmgr_fill_cache (ctx);
+ /* Call each registered client's callback. */
+ for (i = 0; i < ctx->client_nb; i++)
+ ctx->client[i].cb (ctx->client[i].user_data);
+ BUFMGR_TRACE (BUFFER_NEW);
+}
+
+void
+bufmgr_client_register (bufmgr_t *ctx, bufmgr_callback_t cb, void *user_data)
+{
+ dbg_assert (ctx);
+ dbg_assert (cb);
+ dbg_assert (ctx->client_nb < BUFMGR_CLIENT_NB);
+ ctx->client[ctx->client_nb].cb = cb;
+ ctx->client[ctx->client_nb].user_data = user_data;
+ ctx->client_nb++;
+}
+
+bufmgr_t *
+bufmgr_init (ipmbox_t *ipmbox)
+{
+ bufmgr_t *ctx = &bufmgr_global;
+ ctx->ipmbox = ipmbox;
+ ctx->client_nb = 0;
+ ctx->buffers_nb = 0;
+ hal_arch_sem_init (&ctx->sem, 0);
+ /* Register a callback for empty_buf IT. */
+ ipmbox_register_empty_buf_cb (ipmbox, ctx,
+ (ipmbox_empty_buf_cb_t) bufmgr_handle_new_buf);
+ bufmgr_trace_init (ctx);
+ return ctx;
+}
+
+void
+bufmgr_uninit (bufmgr_t *ctx)
+{
+ dbg_assert (ctx);
+ ctx->client_nb = 0;
+ ctx->buffers_nb = 0;
+}
diff --git a/cesar/bufmgr/src/trace.c b/cesar/bufmgr/src/trace.c
new file mode 100644
index 0000000000..54b3f549ad
--- /dev/null
+++ b/cesar/bufmgr/src/trace.c
@@ -0,0 +1,42 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bufmgr/src/trace.c
+ * \brief Buffer manager traces.
+ * \ingroup bufmgr
+ */
+#include "common/std.h"
+#include "bufmgr/bufmgr.h"
+#include "bufmgr/inc/trace.h"
+#include "bufmgr/inc/context.h"
+
+void
+bufmgr_trace_init (bufmgr_t *ctx)
+{
+ static trace_namespace_t namespace;
+ static const trace_event_id_t event_ids[] =
+ {
+ TRACE_EVENT (BUFMGR_TRACE_BUFFER_GET, "Buffer get %x"),
+ TRACE_EVENT (BUFMGR_TRACE_BUFFER_GET_WAIT,
+ "Buffer get wait %x delay_rtc %d"),
+ TRACE_EVENT (BUFMGR_TRACE_BUFFER_GIVE_BACK,
+ "Buffer give back %x"),
+ TRACE_EVENT (BUFMGR_TRACE_BUFFER_NEW, "new buffers"),
+ TRACE_EVENT (BUFMGR_TRACE_BUFFER_KEEP, "Buffer keep %x"),
+ };
+ dbg_assert (ctx);
+ trace_namespace_init (&namespace, event_ids, COUNT (event_ids));
+ trace_buffer_add (&ctx->trace, "bufmgr", 8, 4, true, &namespace);
+}
+
+void
+bufmgr_trace_uninit (bufmgr_t *ctx)
+{
+ dbg_assert (ctx);
+ trace_buffer_remove (&ctx->trace);
+}
diff --git a/cesar/bufmgr/stub/Module b/cesar/bufmgr/stub/Module
new file mode 100644
index 0000000000..d4846f1daf
--- /dev/null
+++ b/cesar/bufmgr/stub/Module
@@ -0,0 +1 @@
+SOURCES := bufmgr.c \ No newline at end of file
diff --git a/cesar/bufmgr/stub/src/bufmgr.c b/cesar/bufmgr/stub/src/bufmgr.c
new file mode 100644
index 0000000000..fd61d8725d
--- /dev/null
+++ b/cesar/bufmgr/stub/src/bufmgr.c
@@ -0,0 +1,76 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bufmgr/stub/src/bufmgr.c
+ * \brief Buffer Manager stub functions
+ * \ingroup bufmgr_stub
+ */
+#include "common/std.h"
+
+#include "bufmgr/bufmgr.h"
+
+u8*
+bufmgr_get (bufmgr_t *ctx) __attribute__((weak));
+
+u8*
+bufmgr_get (bufmgr_t *ctx)
+{
+ return NULL;
+}
+
+u8*
+bufmgr_get_wait (bufmgr_t *ctx, uint delay_rtc) __attribute__((weak));
+
+u8*
+bufmgr_get_wait (bufmgr_t *ctx, uint delay_rtc)
+{
+ return NULL;
+}
+
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer) __attribute__((weak));
+
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer)
+{
+}
+
+void
+bufmgr_client_register (bufmgr_t *ctx, bufmgr_callback_t cb,
+ void *user_data) __attribute__((weak));
+
+void
+bufmgr_client_register (bufmgr_t *ctx, bufmgr_callback_t cb,
+ void *user_data)
+{
+}
+
+bufmgr_t*
+bufmgr_init (ipmbox_t *ipmbox) __attribute__((weak));
+
+bufmgr_t*
+bufmgr_init (ipmbox_t *ipmbox)
+{
+ return NULL;
+}
+
+void
+bufmgr_uninit (bufmgr_t *ctx) __attribute__((weak));
+
+void
+bufmgr_uninit (bufmgr_t *ctx)
+{
+}
+
+void
+bufmgr_keep_buffer (bufmgr_t *ctx, u8 *buffer) __attribute__((weak));
+
+void
+bufmgr_keep_buffer (bufmgr_t *ctx, u8 *buffer)
+{
+}
diff --git a/cesar/bufmgr/test/utest/Config b/cesar/bufmgr/test/utest/Config
new file mode 100644
index 0000000000..dbdade324f
--- /dev/null
+++ b/cesar/bufmgr/test/utest/Config
@@ -0,0 +1 @@
+CONFIG_DEBUG_FATAL_CATCH=y
diff --git a/cesar/bufmgr/test/utest/Makefile b/cesar/bufmgr/test/utest/Makefile
new file mode 100644
index 0000000000..e3ece7526e
--- /dev/null
+++ b/cesar/bufmgr/test/utest/Makefile
@@ -0,0 +1,11 @@
+BASE = ../../..
+
+INCLUDES = bufmgr bufmgr/test/utest
+
+DEFS=-DNO_PRIVATE
+
+HOST_PROGRAMS = test_bufmgr
+test_bufmgr_SOURCES = bufmgr.c ipmbox.c scenario_defs.c
+test_bufmgr_MODULES = lib lib/scenario bufmgr
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/bufmgr/test/utest/inc/scenario_defs.h b/cesar/bufmgr/test/utest/inc/scenario_defs.h
new file mode 100644
index 0000000000..eb80cd6984
--- /dev/null
+++ b/cesar/bufmgr/test/utest/inc/scenario_defs.h
@@ -0,0 +1,84 @@
+#ifndef inc_scenario_defs_h
+#define inc_scenario_defs_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/scenario_defs.h
+ * \brief Scenario entries definition.
+ * \ingroup test
+ */
+#include "bufmgr/bufmgr.h"
+
+/* Scenario globals. */
+#define SCENARIO_DEFS_GLOBALS \
+ bufmgr_t *bufmgr;
+
+/* Scenario actions. */
+#define SCENARIO_DEFS_ACTIONS \
+ bufmgr_fill_cache, \
+ bufmgr_get, \
+ bufmgr_get_wait, \
+ bufmgr_give_back, \
+ bufmgr_keep_buffer
+
+typedef struct
+{
+ uint ipmbox_buf_available;
+} scenario_action_bufmgr_fill_cache_t;
+
+void
+scenario_action_bufmgr_fill_cache_cb (scenario_globals_t *globals,
+ scenario_params_t *params);
+
+typedef struct
+{
+ u8 *buf_expected;
+} scenario_action_bufmgr_get_t;
+
+void
+scenario_action_bufmgr_get_cb (scenario_globals_t *globals,
+ scenario_params_t *params);
+
+typedef scenario_action_bufmgr_get_t scenario_action_bufmgr_get_wait_t;
+
+void
+scenario_action_bufmgr_get_wait_cb (scenario_globals_t *globals,
+ scenario_params_t *params);
+
+typedef struct
+{
+ u8 *buffer;
+} scenario_action_bufmgr_keep_buffer_t;
+
+void
+scenario_action_bufmgr_keep_buffer_cb(scenario_globals_t *globals,
+ scenario_params_t *params);
+
+typedef scenario_empty_t scenario_action_bufmgr_give_back_t;
+
+void
+scenario_action_bufmgr_give_back_cb (scenario_globals_t *globals,
+ scenario_params_t *params);
+
+/* Scenario events. */
+#define SCENARIO_DEFS_EVENTS \
+ ipmbox_empty_buf_get, \
+ ipmbox_tx_empty_buf
+
+typedef struct
+{
+ uint nb_req;
+ uint nb_return;
+} scenario_event_ipmbox_empty_buf_get_t;
+
+typedef struct
+{
+ uint length;
+} scenario_event_ipmbox_tx_empty_buf_t;
+
+#endif /* inc_scenario_defs_h */
diff --git a/cesar/bufmgr/test/utest/inc/test_bufmgr.h b/cesar/bufmgr/test/utest/inc/test_bufmgr.h
new file mode 100644
index 0000000000..50a16da254
--- /dev/null
+++ b/cesar/bufmgr/test/utest/inc/test_bufmgr.h
@@ -0,0 +1,20 @@
+#ifndef inc_test_bufmgr_h
+#define inc_test_bufmgr_h
+
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file inc/test_bufmgr.h
+ * \brief Buffer manager unitary test private data
+ * \ingroup test
+ */
+
+/* Define a fake buffer address for tests. */
+#define BUFMGR_TEST_FAKE_BUFFER_ADDRESS 0x42
+
+#endif /* inc_test_bufmgr_h */
diff --git a/cesar/bufmgr/test/utest/src/bufmgr.c b/cesar/bufmgr/test/utest/src/bufmgr.c
new file mode 100644
index 0000000000..3274fa0ebe
--- /dev/null
+++ b/cesar/bufmgr/test/utest/src/bufmgr.c
@@ -0,0 +1,260 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bufmgr/test/utest/src/bufmgr.c
+ * \brief Buffer Manager unitary test
+ * \ingroup bufmgr_test
+ */
+#include "common/std.h"
+
+#include "lib/test.h"
+#include "lib/scenario/scenario.h"
+#include "lib/blk.h"
+#include "lib/rnd.h"
+
+#include "bufmgr/bufmgr.h"
+#include "bufmgr/inc/context.h"
+
+#include "inc/test_bufmgr.h"
+
+void
+bufmgr_fill_cache_test_case (test_t t)
+{
+ test_case_begin (t, "Fill cache buffer");
+ test_begin (t, "all cases.")
+ {
+ bufmgr_t *bufmgr = bufmgr_init (NULL);
+ uint i, j;
+ scenario_globals_t globals = {
+ .bufmgr = bufmgr
+ };
+ for (i = 0; i < BUFMGR_BUFFER_LIST_SIZE; i++)
+ {
+ for (j = 0; j < BUFMGR_BUFFER_LIST_SIZE; j++)
+ {
+
+ bufmgr->sem = MIN (i, (uint) BUFMGR_RESERVED_BUFFER_NB);
+ bufmgr->buffers_nb = i;
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (bufmgr_fill_cache,
+ .ipmbox_buf_available = j),
+ SCENARIO_EVENT_COND (i < BUFMGR_BUFFER_LIST_NB,
+ ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB - i,
+ .nb_return =
+ MIN (BUFMGR_BUFFER_LIST_NB - i, j)),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ }
+ }
+ bufmgr_uninit (bufmgr);
+ }
+ test_end;
+}
+
+void
+bufmgr_get_test_case (test_t t)
+{
+ test_case_begin (t, "Get buffer");
+ test_begin (t, "all cases.")
+ {
+ bufmgr_t *bufmgr = bufmgr_init (NULL);
+ scenario_globals_t globals = {
+ .bufmgr = bufmgr
+ };
+ bufmgr->sem = bufmgr->buffers_nb = 0;
+ scenario_entry_t entries[] = {
+ /* No buffers. */
+ SCENARIO_ACTION (bufmgr_get,
+ .buf_expected = NULL),
+ SCENARIO_EVENT (ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB,
+ .nb_return = 0),
+ /* Get only buffers for reserved list. */
+ SCENARIO_ACTION (bufmgr_get,
+ .buf_expected = NULL),
+ SCENARIO_EVENT (ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB,
+ .nb_return = BUFMGR_RESERVED_BUFFER_NB),
+ /* Get a buffer. */
+ SCENARIO_ACTION (bufmgr_get,
+ .buf_expected = (u8*) BUFMGR_TEST_FAKE_BUFFER_ADDRESS),
+ SCENARIO_EVENT (ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB
+ - BUFMGR_RESERVED_BUFFER_NB,
+ .nb_return = 1),
+ /* Only reserved buffers available. */
+ SCENARIO_ACTION (bufmgr_get,
+ .buf_expected = NULL),
+ SCENARIO_EVENT (ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB
+ - BUFMGR_RESERVED_BUFFER_NB,
+ .nb_return = 0),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ bufmgr_uninit (bufmgr);
+ }
+ test_end;
+}
+
+void
+bufmgr_get_wait_test_case (test_t t)
+{
+ test_case_begin (t, "Wait to get buffer");
+ test_begin (t, "all cases.")
+ {
+ bufmgr_t *bufmgr = bufmgr_init (NULL);
+ scenario_globals_t globals = {
+ .bufmgr = bufmgr
+ };
+ bufmgr->sem = bufmgr->buffers_nb = 0;
+ scenario_entry_t entries[] = {
+ /* No buffers. */
+ SCENARIO_ACTION (bufmgr_get_wait,
+ .buf_expected = NULL),
+ SCENARIO_EVENT (ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB,
+ .nb_return = 0),
+ /* Get a buffer from reserved list. */
+ SCENARIO_ACTION (bufmgr_get_wait,
+ .buf_expected =
+ (u8*) BUFMGR_TEST_FAKE_BUFFER_ADDRESS),
+ SCENARIO_EVENT (ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB,
+ .nb_return = BUFMGR_RESERVED_BUFFER_NB),
+ /* Get a buffer from cached list. */
+ SCENARIO_ACTION (bufmgr_get_wait,
+ .buf_expected = (u8*) BUFMGR_TEST_FAKE_BUFFER_ADDRESS),
+ SCENARIO_EVENT (ipmbox_empty_buf_get,
+ .nb_req = BUFMGR_BUFFER_LIST_NB
+ - BUFMGR_RESERVED_BUFFER_NB + 1,
+ .nb_return = 2),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (bufmgr->sem == BUFMGR_RESERVED_BUFFER_NB - 1);
+ bufmgr_uninit (bufmgr);
+ }
+ test_end;
+}
+
+void
+bufmgr_give_back_test_case (test_t t)
+{
+ test_case_begin (t, "Give back an empty buffer");
+ bufmgr_t *bufmgr;
+ /* Context init. */
+ bufmgr = bufmgr_init (NULL);
+ test_begin (t, "Nominal")
+ {
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (bufmgr_give_back),
+ SCENARIO_EVENT (ipmbox_tx_empty_buf, .length = 1),
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .bufmgr = bufmgr
+ };
+ scenario_run (t, entries, &globals);
+ } test_end;
+ test_begin (t, "Keep buffer, to not give back to linux")
+ {
+ bufmgr->buffers_nb = BUFMGR_BUFFER_LIST_NB;
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (bufmgr_keep_buffer,
+ .buffer = (u8*) BUFMGR_TEST_FAKE_BUFFER_ADDRESS),
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .bufmgr = bufmgr
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (bufmgr->buffers_nb == BUFMGR_BUFFER_LIST_NB + 1);
+ /* Get a buffer. */
+ scenario_entry_t entries_get_buffer[] = {
+ SCENARIO_ACTION (bufmgr_get_wait,
+ .buf_expected =
+ (u8*) BUFMGR_TEST_FAKE_BUFFER_ADDRESS),
+ SCENARIO_END
+ };
+ scenario_run (t, entries_get_buffer, &globals);
+ test_fail_unless (bufmgr->buffers_nb == BUFMGR_BUFFER_LIST_NB);
+ } test_end;
+ bufmgr_uninit (bufmgr);
+}
+
+void
+bufmgr_callback_test_case (test_t t)
+{
+ test_case_begin (t, "Register callbacks");
+ test_begin (t, "Register callback.")
+ {
+ lib_rnd_t rand;
+ lib_rnd_init (&rand, 0x12afe);
+ bufmgr_client_t client[BUFMGR_CLIENT_NB];
+ bufmgr_t *bufmgr;
+ bufmgr = bufmgr_init (NULL);
+ test_fail_unless (!bufmgr->client_nb);
+ uint i;
+ for (i = 0; i < BUFMGR_CLIENT_NB; i++)
+ {
+ client[i].cb = INVALID_PTR + i;
+ client[i].user_data = INVALID_PTR + i + 1;
+ bufmgr_client_register (bufmgr, client[i].cb,
+ client[i].user_data);
+ }
+ /* Add a new one... */
+ dbg_fatal_try_begin
+ {
+ bufmgr_client_register (bufmgr, (void*)0x42, (void*)0x43);
+ test_fail_unless (false);
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ test_verbose_print (fatal_message);
+ test_fail_unless (true);
+ }
+ dbg_fatal_try_end;
+ /* Check values. */
+ for (i = 0; i < BUFMGR_CLIENT_NB; i++)
+ {
+ test_fail_unless (bufmgr->client[i].cb == client[i].cb);
+ test_fail_unless (bufmgr->client[i].user_data ==
+ client[i].user_data);
+ }
+ bufmgr_uninit (bufmgr);
+ } test_end;
+}
+
+void
+bufmger_test_suite (test_t t)
+{
+ test_suite_begin (t, "buffer manager");
+ bufmgr_fill_cache_test_case (t);
+ bufmgr_get_test_case (t);
+ bufmgr_get_wait_test_case (t);
+ bufmgr_give_back_test_case (t);
+ bufmgr_callback_test_case (t);
+ test_case_begin (t, "memory");
+ test_begin (t, "memory")
+ {
+ test_fail_unless (blk_check_memory ());
+ } test_end;
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t t;
+ test_init (t, argc, argv);
+ bufmger_test_suite (t);
+ test_result (t);
+ return test_nb_failed (t) == 0 ? 0 : 1;
+}
diff --git a/cesar/bufmgr/test/utest/src/ipmbox.c b/cesar/bufmgr/test/utest/src/ipmbox.c
new file mode 100644
index 0000000000..bae1c46f2c
--- /dev/null
+++ b/cesar/bufmgr/test/utest/src/ipmbox.c
@@ -0,0 +1,48 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file bufmgr/test/utest/src/ipmbox.c
+ * \brief Override IPMbox functions.
+ * \ingroup bufmgr_test
+ */
+#include "common/std.h"
+
+#include "lib/test.h"
+#include "lib/scenario/scenario.h"
+
+#include "hal/ipmbox/ipmbox.h"
+
+#include "inc/test_bufmgr.h"
+
+uint
+ipmbox_empty_buf_get (ipmbox_t *ctx, u32 *msg_buf, uint nb)
+{
+ scenario_event (ipmbox_empty_buf_get, params);
+ test_fail_unless (nb == params->nb_req);
+ if (params->nb_return)
+ {
+ *msg_buf = (u32) BUFMGR_TEST_FAKE_BUFFER_ADDRESS;
+ }
+ else
+ *msg_buf = (u32) NULL;
+ return params->nb_return;
+}
+
+void
+ipmbox_tx_empty_buf (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ scenario_event (ipmbox_tx_empty_buf, params);
+ test_fail_unless (*first_msg == BUFMGR_TEST_FAKE_BUFFER_ADDRESS);
+ test_fail_unless (length == params->length);
+}
+
+void
+ipmbox_register_empty_buf_cb (ipmbox_t *ctx, void *user_data,
+ ipmbox_empty_buf_cb_t empty_buf_cb)
+{
+}
diff --git a/cesar/bufmgr/test/utest/src/scenario_defs.c b/cesar/bufmgr/test/utest/src/scenario_defs.c
new file mode 100644
index 0000000000..c2b0cad991
--- /dev/null
+++ b/cesar/bufmgr/test/utest/src/scenario_defs.c
@@ -0,0 +1,90 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/scenario_defs.c
+ * \brief Scenario actions.
+ * \ingroup test
+ */
+#include "common/std.h"
+
+#include "lib/test.h"
+#include "lib/scenario/scenario.h"
+
+#include "bufmgr/bufmgr.h"
+#include "bufmgr/inc/context.h"
+
+#include "inc/test_bufmgr.h"
+
+void
+bufmgr_fill_cache (bufmgr_t *ctx);
+
+void
+scenario_action_bufmgr_fill_cache_cb (scenario_globals_t *globals,
+ scenario_params_t *params)
+{
+ test_within (scenario.t);
+ bufmgr_t *ctx = globals->bufmgr;
+ scenario_action_bufmgr_fill_cache_t *p =
+ &params->action_bufmgr_fill_cache;
+ uint buffers_init_nb = ctx->buffers_nb;
+ uint reserved_buf_init_nb = ctx->sem;
+ uint ipmbox_buf_available = p->ipmbox_buf_available;
+ uint reserved_buf_added =
+ MIN (BUFMGR_RESERVED_BUFFER_NB - reserved_buf_init_nb,
+ ipmbox_buf_available);
+ uint buffers_end_nb = buffers_init_nb;
+ if (buffers_init_nb < BUFMGR_BUFFER_LIST_NB)
+ {
+ buffers_end_nb +=
+ MIN ((uint) BUFMGR_BUFFER_LIST_NB - buffers_init_nb,
+ ipmbox_buf_available);
+ }
+ bufmgr_fill_cache (ctx);
+ test_fail_unless (ctx->sem == reserved_buf_init_nb + reserved_buf_added);
+ test_fail_unless (ctx->buffers_nb == buffers_end_nb);
+}
+
+void
+scenario_action_bufmgr_get_cb (scenario_globals_t *globals,
+ scenario_params_t *params)
+{
+ test_within (scenario.t);
+ bufmgr_t *ctx = globals->bufmgr;
+ scenario_action_bufmgr_get_t *p = &params->action_bufmgr_get;
+ u8 *buf = bufmgr_get (ctx);
+ test_fail_unless (buf == p->buf_expected);
+}
+
+void
+scenario_action_bufmgr_get_wait_cb (scenario_globals_t *globals,
+ scenario_params_t *params)
+{
+ test_within (scenario.t);
+ bufmgr_t *ctx = globals->bufmgr;
+ scenario_action_bufmgr_get_wait_t *p = &params->action_bufmgr_get_wait;
+ u8 *buf = bufmgr_get_wait (ctx, 10);
+ test_fail_unless (buf == p->buf_expected);
+}
+
+void
+scenario_action_bufmgr_keep_buffer_cb (scenario_globals_t *globals,
+ scenario_params_t *params)
+{
+ bufmgr_t *ctx = globals->bufmgr;
+ scenario_action_bufmgr_keep_buffer_t *p =
+ &params->action_bufmgr_keep_buffer;
+ bufmgr_keep_buffer (ctx, p->buffer);
+}
+
+void
+scenario_action_bufmgr_give_back_cb (scenario_globals_t *globals,
+ scenario_params_t *params)
+{
+ bufmgr_t *ctx = globals->bufmgr;
+ bufmgr_give_back (ctx, (u8 *) BUFMGR_TEST_FAKE_BUFFER_ADDRESS);
+}
diff --git a/cesar/ce/fcall/src/fcall.c b/cesar/ce/fcall/src/fcall.c
index c606afd53b..590a4633d9 100644
--- a/cesar/ce/fcall/src/fcall.c
+++ b/cesar/ce/fcall/src/fcall.c
@@ -16,6 +16,8 @@
#include "config/fcall/mme.h"
#if CONFIG_FCALL_MME
# include "interface/inc/context.h"
+# include "interface/fcall/inc/context.h"
+# include "cesar/station/station.h"
#else
# include "host/station/station.h"
#endif
diff --git a/cesar/ce/rx/test/src/test_rx.c b/cesar/ce/rx/test/src/test_rx.c
index f01deb8e65..159b106ed5 100644
--- a/cesar/ce/rx/test/src/test_rx.c
+++ b/cesar/ce/rx/test/src/test_rx.c
@@ -124,7 +124,7 @@ void
test_rx_ce_suite (test_t t)
{
mac_store_t *mac_store = mac_store_init ();
- sar_t *sar = sar_init (mac_store, NULL, NULL, 0x1);
+ sar_t *sar = sar_init (mac_store, NULL, NULL, NULL, 0x1);
pbproc_t *pbproc = (pbproc_t *) t;
mac_config_t mac_config;
@@ -147,7 +147,7 @@ test_ce_rx_measure_suite (test_t t)
rx_params.preamble_ntb = 0;
rx_params.beacon_period_start_ntb = 42;
mac_store_t *mac_store = mac_store_init ();
- sar_t *sar = sar_init (mac_store, NULL, NULL, 0x1);
+ sar_t *sar = sar_init (mac_store, NULL, NULL, NULL, 0x1);
pbproc_t *pbproc = (pbproc_t *) t;
mac_config_t mac_config;
@@ -302,7 +302,7 @@ test_ce_rx_get_snr (test_t t)
{
const uint tei = 1;
mac_store_t *mac_store = mac_store_init ();
- sar_t *sar = sar_init (mac_store, NULL, NULL, 0x1);
+ sar_t *sar = sar_init (mac_store, NULL, NULL, NULL, 0x1);
pbproc_t *pbproc = (pbproc_t *) t;
mac_config_t mac_config;
u16 ber = 0x42;
diff --git a/cesar/cl/Module b/cesar/cl/Module
index 13768e9721..f0762629ec 100644
--- a/cesar/cl/Module
+++ b/cesar/cl/Module
@@ -1,4 +1,7 @@
-SOURCES := cl.c cl_mactotei.c bridge_table.c data_rate.c brg_rx.c
+SOURCES := cl.c cl_mactotei.c bridge_table.c data_rate.c brg_rx.c send.c \
+ receive.c
ifeq ($(CONFIG_TRACE),y)
SOURCES += trace.c
endif
+
+MODULES := cl/mbx
diff --git a/cesar/cl/cl.h b/cesar/cl/cl.h
index 931092cb2f..c4e604b979 100644
--- a/cesar/cl/cl.h
+++ b/cesar/cl/cl.h
@@ -14,332 +14,101 @@
* \ingroup cl
*
*/
-
-#include "mac/common/mfs.h"
+#include "common/defs/igmp.h"
+#include "bufmgr/bufmgr.h"
+#include "hal/ipmbox/ipmbox.h"
+#include "mac/common/config.h"
#include "mac/common/store.h"
-#include "lib/utils.h"
#include "mac/sar/sar.h"
-#include "common/defs/igmp.h"
+#include "cl/mbx/mbx.h"
#if MODULE_INCLUDED (cl)
# include "config/cl.h"
#else
-# define CONFIG_CL_DATARATE 0
+# define CONFIG_CL_DATA_RATE 0
#endif
/** forward declaration. */
typedef struct cl_t cl_t;
-typedef struct cl_send_t cl_send_t;
-
-/**
- * Callback use to inform the upper layer when a data had been sent over the
- * PLC.
- *
- * \param user the user data
- * \param buffer the buffer use to send the data over the PLC.
- */
-typedef void
-(*cl_data_send_done_cb_t) (void *user, u8 *buffer);
-
-/**
- * Callback to provide a received data to the upper layer coming from the SAR.
- *
- * \param user the user data
- * \param buffer the buffer containing the data
- * \param length the data length in the buffer.
- */
-typedef void
-(*cl_data_recv_cb_t) (void *user, u8 *buffer, uint length);
-
-/**
- * Provides a MME buffer to the CP.
- *
- * \param user_data the layer data.
- * \param buffer the buffer to provide.
- */
-typedef void
-(*cl_mme_buffer_add_cb_t) (void *user_data, u8 *buffer);
-
-/**
- * Call back to use when the CL needs to send a MME to the upper layer.
- *
- * \param ul_data the upper layer data provided on the registration.
- * \param buffer the buffer containing the MME.
- * \param length the length of the MME
- */
-typedef void
-(*cl_mme_ul_send_done_cb_t) (void *ul_data, u8 *buffer, uint length);
-
-/**
- * Callback definition used by the CL when the CP had processed the MME
- * in the buffer. This will return the buffer to the upper layer.
- *
- * \param user_data the upper layer user data
- * \param buffer the buffer containing the MME.
- */
-typedef void
-(*cl_mme_ul_recv_done_cb_t) (void *user_data, u8 *buffer);
-
-/**
- * Use this callback to provide a received MME to the CP.
- *
- * \param user user data
- * \param tei the station's source TEI.
- * \param buffer the buffer containing the MME.
- * \param length the MME length
- * \param mme_recv private data for the cl_mme.
- * \param encryption inform if the MF has been encrypted or not when it
- * arrives from the PWL.
- */
-typedef void
-(*cl_mme_recv_cb_t) (void *user, uint tei, u8 *buffer,
- uint length, bool mme_recv, bool encryption);
BEGIN_DECLS
/**
* Init the Convergence Layer and return a pointer on the CL context.
- *
* \param mac_store the mac store.
* \param sar the sar context.
* \param mac_config the mac config.
+ * \param ipmbox context.
+ * \param bufmgr context.
* \return the convergence layer context.
*/
cl_t *
-cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config);
+cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config,
+ ipmbox_t *ipmbox, bufmgr_t *bufmgr);
/**
* Uninit the Convergence layer context.
- *
* \param ctx the convergence layer context
*/
void
cl_uninit (cl_t *ctx);
/**
- * Initialize the CL to call the Upper layer once the CP ends processing the
- * MME.
- * Used each time the CP needs to send an MME to the upper layer.
- *
- * \param ctx the CL context
- * \param cb the upper layer callback to use to send an MME.
- * \param user the user data to provide with the callback
- */
-void
-cl_mme_ul_init_send_done (cl_t *ctx, cl_mme_ul_recv_done_cb_t cb,
- void *user);
-
-/**
- * Init the function call when an MME is received from the SAR or the HLE.
- * The CP registers its callback to allow the CL to call it each time a MME
- * is received from the PLC or the HLE.
- *
- * \param ctx the CL ctx
- * \param mme_recv_cb
- * \param user the user data
+ * Clean data send link.
+ * \param ctx CL context.
*/
void
-cl_mme_recv_init (cl_t *ctx, cl_mme_recv_cb_t mme_recv_cb, void *user);
+cl_data_send_link_clear (cl_t *ctx);
/**
- * Initialize the CL to send MMEs to the Upper layer considered as data.
- * Used each time the CP needs to send an MME to the upper layer.
- *
- * \param ctx the CL context
- * \param cb the upper layer callback to use to send an MME.
- * \param user the user data to provide with the callback
+ * Get the access to the igmp data in the cl context.
+ * \param cl the CL context.
+ * \return the pointer to the igmp data.
*/
-void
-cl_mme_init_ul_as_data (cl_t *ctx, cl_mme_ul_send_done_cb_t cb, void *user);
-
+igmp_groups_t *
+cl_get_igmp_groups (cl_t *cl);
/**
- * Initialize the CP call back to get a buffer.
- *
- * \param cl the cl context
- * \param cb the call back function
- * \param user_data the user data.
+ * Update the igmp groups based on the mactotei table.
+ * \param cl the CL context.
*/
void
-cl_mme_init_buffer_add_cb (cl_t *cl, cl_mme_buffer_add_cb_t cb,
- void *user_data);
+cl_update_igmp_groups (cl_t *ctx);
/**
- * Send a MME from the CP to the Upper layer or to the PWL.
- *
- * \param ctx the cl context.
- * \param buffer the buffer containing the data to send.
- * \param length the length of the MME.
- * \param tei the destination tei.
- *
- * The TEI can take the following values:
- * * MAC_TEI_BCAST
- * * MAC_TEI_UNASSOCIATED
- * * MAC_TEI_MIN to MAC_TEI_MAX
- * * MAC_TEI_FOREIGN
+ * Send an MME from the CP to the PLC or to linux if TEI is foreign.
+ * \param ctx the CL context
+ * \param buffer the buffer containing the MME
+ * \param length the length of the MME
+ * \param tei the destination TEI (MAC_TEI_FOREIGN for linux)
*/
void
cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei);
/**
- * Callback called by the sar when a MME as been sent over the PWL.
- *
- * \param ctx the cl context.
- * \param buffer the buffer used.
- * \param cl_data the data provided to the SAR on the send.
- */
-void
-cl_mme_sar_send_done (cl_t *ctx, u8 *buffer, void *cl_data);
-
-/**
- * Receives an MME from the SAR or the upper layer.
- * This function is called each time the SAR or the HLE has an MME to send to
- * the CP. It is used by the inline function.
- * When the MFS is NULL the MME received comes from the HLE. Otherwise the MME
- * comes from the SAR.
- *
- * \param ctx the cl context
- * \param buffer the MME buffer
- * \param length the MME length
- * \param mfs the MFS used by the reassembly process.
- * \param encryption if the mac frame comes from the SAR if returns the
- * state of the encryption.
+ * Compute the data rate on the station.
+ * \param ctx the module context
+ * \param mfs the mfs to use
+ * \param length the payload length
*/
void
-cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs,
- bool encryption);
+cl_compute_datarate_on_sta_ (cl_t *ctx, mfs_t *mfs, uint length);
-/**
- * Receives an MME from the Upper layer.
- * It will provide this MME to the Control Plane to be processed.
- *
- * \param ctx the cl context
- * \param buffer the MME buffer
- * \param length the MME length
- */
extern inline void
-cl_mme_ul_send (cl_t *ctx, u8 *buffer, uint length)
+cl_compute_datarate_on_sta (cl_t *ctx, mfs_t *mfs, uint length)
{
- cl_mme_recv (ctx, buffer, length, NULL, false);
-}
-
-/**
- * Receives an MME from the SAR.
- * It will provide this MME to the Control Plane to be processed.
- *
- * \param ctx the cl context
- * \param buffer the MME buffer
- * \param length the MME length
- * \param mfs the MFS used by the reassembly process.
- * \param encryption boolean informing if the MF was encrypted or not.
- */
-extern inline void
-cl_mme_sar_recv (cl_t *ctx, u8 *buffer, uint length,
- mfs_rx_t *mfs, bool encryption)
-{
- cl_mme_recv (ctx, buffer, length, mfs, encryption);
+#if CONFIG_CL_DATA_RATE
+ cl_compute_datarate_on_sta_ (ctx, mfs, length);
+#endif
}
/**
- * The CP inform the CL that the buffer containing previously a received MME can
- * be use again to store another MME if necessary.
- *
- * \param ctx the CL context
- * \param buffer the buffer gived back.
- * \param mme_recv the data provided on the previous callback.
- */
-void
-cl_mme_recv_done (cl_t *ctx, u8 *buffer, bool mme_recv);
-
-/**
- * Initialize the callback to inform the upper layer when a data had been sent
- * over the PWL.
- *
- * \param cl the CL context
- * \param cb the callback to call once the data had been sent
- * \param user the user data to provide with the callback call
- */
-void
-cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user);
-
-/**
- * The SAR inform the CL that the data previously provided had been sent over
- * the PLC.
- *
- * \param ctx the CL context.
- * \param buffer the buffer containing the MME
- * \param cl_data the data provided to the SAR on the msdu add.
- */
-void
-cl_data_send_done (cl_t *ctx, u8 *buffer, void *cl_data);
-
-/**
- * Send a data from the upper layer to the SAR, this data should be sent over
- * the PWL.
- *
- * \param ctx the CL context.
- * \param buffer the buffer containing the data to send
- * \param length the data length
- * \param tag the upper layer tag.
- * \param arrival_time_ntb arrival time ntb.
- */
-void
-cl_data_send (cl_t *ctx, u8 *buffer, uint length, uint tag,
- u32 arrival_time_ntb);
-
-/**
- * Initialize the callback to receive the data from the PLC to the upper layer.
- *
- * \param cl the CL context
- * \param cb the function callback to call
- * \param user the user data to provide on the callback.
+ * For some users which needs mbx.
+ * \param ctx the module context.
+ * \return cl_mbx context.
*/
-void
-cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user);
-
-/**
- * Called by the SAR each time it has a data to provide to the CL.
- *
- * \param ctx the CL context
- * \param buffer the buffer containing the data to send to the Upper layer.
- * \param length the data length in the buffer
- * \param mfs the mfs used to receive the data.
- */
-void
-cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs);
-
-/**
- * Provides a buffer to the CP.
- *
- * \param cl the CL context
- * \param buffer the buffer to reassembly some data
- */
-void
-cl_mme_buffer_add (cl_t *cl, u8 *buffer);
-
-/**
- * Provides a buffer to the SAR to reassembly data
- *
- * \param cl the CL context
- * \param buffer the buffer to reassembly some data
- */
-void
-cl_data_buffer_add (cl_t *cl, u8 *buffer);
-
-/**
- * Update the igmp groups based on the mactotei table.
- * \param cl the CL context.
- */
-void
-cl_update_igmp_groups (cl_t *ctx);
-
-/**
- * Get the access to the igmp data in the cl context.
- * \param cl the CL context.
- * \return the pointer to the igmp data.
- */
-igmp_groups_t *
-cl_get_igmp_groups (cl_t *cl);
+cl_mbx_t*
+cl_mbx_get (cl_t *ctx);
END_DECLS
diff --git a/cesar/cl/inc/cl.h b/cesar/cl/inc/cl.h
deleted file mode 100644
index 9a4f76e8cc..0000000000
--- a/cesar/cl/inc/cl.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef CL_INC_CL_H_
-#define CL_INC_CL_H_
-
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file cl/inc/cl.h
- * \brief private function for the CL
- * \ingroup cl/inc
- *
- */
-
-#include "cl/cl_mactotei.h"
-#include "cl/inc/context.h"
-
-BEGIN_DECLS
-
-/**
- * Init the MME module of the CL.
- * \param ctx the MME context.
- */
-void
-cl_mme_init (cl_mme_t *ctx);
-
-/**
- * Find a mac address in the table using a dichotomy search
- * \param cl the convergence layer context.
- * \param mac the mac address to find
- * \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);
-
-/**
- * Clear link cache.
- * \param ctx the module context.
- */
-void
-cl_data_send_link_clear (cl_t *ctx);
-
-END_DECLS
-
-#endif /*CL_INC_CL_H_*/
diff --git a/cesar/cl/inc/context.h b/cesar/cl/inc/context.h
index 9372864dea..afc24cd739 100644
--- a/cesar/cl/inc/context.h
+++ b/cesar/cl/inc/context.h
@@ -14,85 +14,18 @@
* \ingroup cl
*
*/
-#include "common/defs/ethernet.h"
-
-#include "lib/slab.h"
#include "lib/seq_check.h"
#include "mac/common/mfs.h"
-#include "mac/common/store.h"
-#include "mac/common/config.h"
-#include "mac/sar/sar.h"
#include "cl/cl_mactotei.h"
#include "cl/brg_rx.h"
-#include "cl/inc/bridge_table.h" // bridge_table_context_t
-
+#include "cl/inc/bridge_table.h"
#include "cl/inc/trace.h"
-#include "common/defs/igmp.h"
+#include "cl/mbx/inc/mbx.h"
/** Define the delay at the one the data inside the cl_data_send_link_t are
* considered expired. */
#define CL_DATA_SEND_EXCEED_TIME_MS 100
-/** data tx structure. */
-struct cl_data_tx_t
-{
- /** the callback function to use once the data hab been sent. */
- cl_data_send_done_cb_t cb;
- /** user data to provide with the callback. */
- void *user;
-};
-typedef struct cl_data_tx_t cl_data_tx_t;
-
-/** data tx structure. */
-struct cl_data_rx_t
-{
- /** callback to call the upperlayer once the CL receives a data. */
- cl_data_recv_cb_t cb;
- /** user value to provide with the function callback. */
- void *user;
-};
-typedef struct cl_data_rx_t cl_data_rx_t;
-
-/** MME tx structure to the upper layer*/
-struct cl_mme_tx_t
-{
- /** function to call when a mme is for the driver */
- cl_data_recv_cb_t cb;
- /** user data */
- void *user;
-};
-typedef struct cl_mme_tx_t cl_mme_tx_t;
-
-struct cl_send_t
-{
- /** The CL context. */
- cl_t *cl;
- /** The buffer to give back. */
- u8 *buffer;
- /** MME if the buffer contains a MME. */
- bool mme;
-};
-
-/** cl mme context */
-struct cl_mme_t
-{
- /** The Call back to inform the upper layer when a MME has been processed
- * */
- cl_mme_ul_recv_done_cb_t ul_mme_recv_done;
- void *ul_mme_recv_done_user_data;
-
- /** Callback to use to add a buffer to the CP. */
- cl_mme_buffer_add_cb_t mme_buffer_add_cb;
- /** The user data to provide with the bellow callback. */
- void *mme_buffer_add_user_data;
-
- /** Callback to call on each reception of MME. */
- cl_mme_recv_cb_t mme_recv_cb;
- /** Data to proved with the callback*/
- void *mme_recv_user_data;
-};
-typedef struct cl_mme_t cl_mme_t;
-
/** Keep DATA about last data SEND. This should help the CL to use
* previous MFS to send the new Frame if it is for the same destination Mac
* Address. The date inside it is only set if it the current time is exceed
@@ -120,31 +53,18 @@ struct cl_t
/** Mac store reference. */
mac_store_t *mac_store;
- /** MME module to use to send or receive the MME to the CP. */
- cl_mme_t mme;
+ /** IPMBox context. */
+ ipmbox_t *ipmbox;
+
+ /** buffer manager context. */
+ bufmgr_t *bufmgr;
/** mactotei table to send data over the PLC. */
cl_mactotei_table_t *mactotei;
- /** send data context. */
- cl_data_tx_t data_tx;
-
- /** recevie data context. */
- cl_data_rx_t data_rx;
-
- /** When a MME is send as data to the local tei */
- cl_mme_tx_t mme_ul_send;
-
- /** MME buffer to provide to the SAR */
- u8 static_mme_buffer [ETH_PACKET_MAX_SIZE];
- u8 *mme_buffer;
-
/** The mac config */
mac_config_t *mac_config;
- /** Slab allocator. */
- slab_cache_t slab_buffer_handler;
-
/** The bridge table module context. */
bridge_table_context_t bridge_table;
@@ -157,6 +77,9 @@ struct cl_t
/** RX bridge Table. */
cl_brg_rx_t *brg_rx;
+ /** MBX context. */
+ cl_mbx_t *mbx;
+
/** Tracing system */
#if CONFIG_TRACE
/** cl Trace */
@@ -164,6 +87,7 @@ struct cl_t
#endif /* !CONFIG_TRACE */
#if CONFIG_SEQ_CHECK
lib_seq_check_t seq_check_rx_ctx;
+ lib_seq_check_t seq_check_tx_ctx;
#endif
};
diff --git a/cesar/cl/inc/receive.h b/cesar/cl/inc/receive.h
new file mode 100644
index 0000000000..bbf2911128
--- /dev/null
+++ b/cesar/cl/inc/receive.h
@@ -0,0 +1,74 @@
+#ifndef cl_inc_receive_h
+#define cl_inc_receive_h
+
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/inc/receive.h
+ * \brief Functions to handle data coming into the CL
+ * \ingroup cl
+ */
+#include "cl/cl.h"
+
+BEGIN_DECLS
+
+/**
+ * Called by the SAR each time it has a data to provide to the CL.
+ * \param ctx the CL context
+ * \param buffer the buffer containing the data to send to the Upper layer.
+ * \param length the data length in the buffer
+ * \param mfs the mfs used to receive the data.
+ */
+void
+cl_sar_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs);
+
+/**
+ * Receives an MME from the SAR.
+ * \param ctx the cl context
+ * \param buffer the MME buffer
+ * \param length the MME length
+ * \param mfs the MFS used by the reassembly process.
+ * \param encryption if the mac frame comes from the SAR if returns the
+ * state of the encryption.
+ */
+void
+cl_sar_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs,
+ bool encryption);
+
+/**
+ * Process DATA messages given by upper layer.
+ * \param ctx CL context.
+ * \param msg_buffer buffer containing the messages
+ * \param nb_words total message size (in words)
+ */
+void
+cl_ipmbox_data_recv (cl_t *ctx, u32 *msg_buffer, uint nb_words);
+
+/**
+ * Process MBX messages given by IPMbox.
+ * \param ctx CL context.
+ * \param msg_buffer buffer containing the messages
+ * \param nb_words total length of the messages (in words)
+ */
+void
+cl_ipmbox_mbx_recv (cl_t *ctx, u32 *msg_buffer, uint nb_words);
+
+/**
+ * Callback when the lib sequencer detect a wrong sequencing.
+ * \param user user data
+ * \param vlan the VLAN id
+ * \param seq_expected the sequence number expected
+ * \param seq_actual the actual sequence number found in the packet
+ */
+void
+cl_lib_seq_check_rx_cb (void *user, uint vlan, uint seq_expected,
+ uint seq_actual);
+
+END_DECLS
+
+#endif /* cl_inc_receive_h */
diff --git a/cesar/cl/inc/send.h b/cesar/cl/inc/send.h
new file mode 100644
index 0000000000..8219d22b4e
--- /dev/null
+++ b/cesar/cl/inc/send.h
@@ -0,0 +1,42 @@
+#ifndef cl_inc_send_h
+#define cl_inc_send_h
+
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/inc/send.h
+ * \brief Functions to handle data going out of the CL
+ * \ingroup cl
+ */
+#include "cl/cl.h"
+
+/**
+ * Send a data from the upper layer to the SAR, this data should be sent over
+ * the PWL.
+ * \param ctx the CL context.
+ * \param buffer the buffer containing the data to send
+ * \param length the data length
+ * \param tag the upper layer tag.
+ * \param arrival_time_ntb arrival time ntb.
+ */
+void
+cl_data_send (cl_t *ctx, u8 *buffer, uint length, uint tag,
+ u32 arrival_time_ntb);
+
+/**
+ * Callback when the lib sequencer detect a wrong sequencing.
+ * \param user user data
+ * \param vlan the VLAN id
+ * \param seq_expected the sequence number expected
+ * \param seq_actual the actual sequence number found in the packet
+ */
+void
+cl_lib_seq_check_tx_cb (void *user, uint vlan, uint seq_expected,
+ uint seq_actual);
+
+#endif /* cl_inc_send_h */
diff --git a/cesar/cl/inc/trace.h b/cesar/cl/inc/trace.h
index 7192677e7c..8c9cb6a07f 100644
--- a/cesar/cl/inc/trace.h
+++ b/cesar/cl/inc/trace.h
@@ -47,7 +47,8 @@ enum
CL_TRACE_DATA_RECV,
CL_TRACE_DATA_BUFFER_ADD,
CL_TRACE_BRIDGE_ADD,
- CL_TRACE_SEQ_CHECK,
+ CL_TRACE_SEQ_CHECK_TX,
+ CL_TRACE_SEQ_CHECK_RX,
};
BEGIN_DECLS
diff --git a/cesar/cl/mbx/Module b/cesar/cl/mbx/Module
new file mode 100644
index 0000000000..541b7d4a9b
--- /dev/null
+++ b/cesar/cl/mbx/Module
@@ -0,0 +1 @@
+SOURCES := mbx.c
diff --git a/cesar/cl/mbx/inc/mbx.h b/cesar/cl/mbx/inc/mbx.h
new file mode 100644
index 0000000000..bedf6c4ba6
--- /dev/null
+++ b/cesar/cl/mbx/inc/mbx.h
@@ -0,0 +1,32 @@
+#ifndef cl_mbx_inc_mbx_h
+#define cl_mbx_inc_mbx_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/mbx/inc/mbx.h
+ * \brief CL MBX context.
+ * \ingroup cl_mbx
+ */
+#include "cl/mbx/mbx.h"
+#include "hle/tools/tools.h"
+
+struct cl_mbx_t
+{
+#if HLE_TOOLS
+ /* HLE tools. */
+ hle_tools_t *hle_tools;
+#endif
+ /** Callback for MME processing. */
+ cl_mme_callback_t cb;
+ /** The MME user data. */
+ void *user_data;
+ /** Ipmbox context. */
+ ipmbox_t *ipmbox;
+};
+
+#endif /* cl_mbx_inc_mbx_h */
diff --git a/cesar/cl/mbx/mbx.h b/cesar/cl/mbx/mbx.h
new file mode 100644
index 0000000000..cc830a5c33
--- /dev/null
+++ b/cesar/cl/mbx/mbx.h
@@ -0,0 +1,73 @@
+#ifndef cl_mbx_mbx_h
+#define cl_mbx_mbx_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/mbx/mbx.h
+ * \brief MBX Handler.
+ * \ingroup cl_mbx
+ */
+#include "hal/ipmbox/ipmbox.h"
+
+/**
+ * Use this callback to provide a received MME to the CP.
+ * \param user user data
+ * \param tei the station's source TEI
+ * \param buffer the buffer containing the MME
+ * \param length the MME length
+ * \param encryption inform if the MF has been encrypted or not when it
+ * arrives from the PWL
+ */
+typedef void
+(*cl_mme_callback_t) (void *user, uint tei, u8 *buffer,
+ uint length, bool encryption);
+
+/** Forward declaration */
+typedef struct cl_mbx_t cl_mbx_t;
+
+BEGIN_DECLS
+
+/**
+ * Initialise the cl mbx handler.
+ * \param ipmbox context
+ * \param cb the callback
+ * \param user_data the user data
+ * \return the cl_mbx context
+ */
+cl_mbx_t*
+cl_mbx_init (ipmbox_t *ipmbox);
+
+/**
+ * Uninitialise the context.
+ * \param ctx the module context
+ */
+void
+cl_mbx_uninit (cl_mbx_t* ctx);
+
+/**
+ * Register the callback to be called on MME reception.
+ * \param ctx the module context
+ * \param cb the callback
+ * \param user_data the user data
+ */
+void
+cl_mbx_callback_register (cl_mbx_t *ctx, cl_mme_callback_t cb,
+ void *user_data);
+
+/**
+ * send a message through the MBX queue.
+ * \param ctx the module context
+ * \param buffer the buffer containing the data
+ * \param length the length of the payload
+ */
+void
+cl_mbx_ipmbox_send (cl_mbx_t *ctx, u8 *buffer, uint length);
+
+END_DECLS
+
+#endif /* cl_mbx_mbx_h */
diff --git a/cesar/cl/mbx/src/mbx.c b/cesar/cl/mbx/src/mbx.c
new file mode 100644
index 0000000000..d0439b0893
--- /dev/null
+++ b/cesar/cl/mbx/src/mbx.c
@@ -0,0 +1,92 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/mbx/src/mbx.c
+ * \brief MbX Handler.
+ * \ingroup cl_mbx
+ */
+#include "common/std.h"
+
+#include "common/ipmbox/protocol.h"
+
+#include "mac/common/defs.h"
+
+#include "hal/ipmbox/ipmbox.h"
+
+#include "cl/mbx/mbx.h"
+#include "cl/mbx/inc/mbx.h"
+
+void
+cl_mbx_ipmbox_mbx_recv (cl_mbx_t *ctx, u32 *msg_buffer, uint nb_words)
+{
+ /* Check parameters. */
+ dbg_claim (ctx);
+ dbg_claim (msg_buffer);
+ dbg_claim (nb_words && nb_words <= IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX);
+
+ ipmbox_msg_mbx_t *msg = (ipmbox_msg_mbx_t *) msg_buffer;
+ ipmbox_msg_mbx_t *msg_end = msg + nb_words / IPMBOX_MSG_MBX_WORDS;
+ for ( ; msg != msg_end; msg++)
+ {
+ u32 type = ipmbox_msg_get_mbx_type (msg->header);
+ switch (type)
+ {
+ case IPMBOX_MSG_MBX_TYPE_MME_PRIV:
+ ctx->cb (ctx->user_data, MAC_TEI_FOREIGN,
+ (u8 *) msg->buffer_addr,
+ ipmbox_msg_get_mme_priv_length (msg->header),
+ false);
+ break;
+ default:
+ hle_tools_msg_recv (ctx->hle_tools, msg);
+ break;
+ }
+ }
+}
+
+cl_mbx_t*
+cl_mbx_init (ipmbox_t *ipmbox)
+{
+ static cl_mbx_t cl_mbx_global;
+ cl_mbx_t *ctx = &cl_mbx_global;
+ ctx->cb = 0;
+ ctx->user_data = 0;
+ ctx->ipmbox = ipmbox;
+ ipmbox_register_rx_mbx_cb (
+ ipmbox, ctx, (ipmbox_rx_cb_t) cl_mbx_ipmbox_mbx_recv);
+#if HLE_TOOLS
+ /* Initialise hle tools. */
+ ctx->hle_tools = hle_tools_init (ipmbox);
+#endif
+ return ctx;
+}
+
+void
+cl_mbx_uninit (cl_mbx_t* ctx)
+{
+}
+
+void
+cl_mbx_callback_register (cl_mbx_t *ctx, cl_mme_callback_t cb,
+ void *user_data)
+{
+ dbg_assert (ctx);
+ dbg_assert (cb);
+ ctx->cb = cb;
+ ctx->user_data = user_data;
+}
+
+void
+cl_mbx_ipmbox_send (cl_mbx_t *ctx, u8 *buffer, uint length)
+{
+ ipmbox_msg_mbx_t msg;
+ msg.header = ipmbox_msg_create_header_mme_priv (length);
+ msg.buffer_addr = (u32) buffer;
+ ipmbox_tx_mbx (ctx->ipmbox, (u32 *) &msg, IPMBOX_MSG_MBX_WORDS);
+}
+
diff --git a/cesar/cl/mbx/stub/Module b/cesar/cl/mbx/stub/Module
new file mode 100644
index 0000000000..541b7d4a9b
--- /dev/null
+++ b/cesar/cl/mbx/stub/Module
@@ -0,0 +1 @@
+SOURCES := mbx.c
diff --git a/cesar/cl/mbx/stub/src/mbx.c b/cesar/cl/mbx/stub/src/mbx.c
new file mode 100644
index 0000000000..eed26ba44b
--- /dev/null
+++ b/cesar/cl/mbx/stub/src/mbx.c
@@ -0,0 +1,45 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/mbx.c
+ * \brief CL MBX queue handler stub
+ * \ingroup cl_mbx
+ */
+#include "common/std.h"
+#include "cl/mbx/mbx.h"
+
+cl_mbx_t*
+cl_mbx_init (ipmbox_t *ipmbox)__attribute__((weak));
+
+void
+cl_mbx_uninit (cl_mbx_t* ctx)__attribute__((weak));
+
+void
+cl_mbx_callback_register (cl_mbx_t *ctx, cl_mme_callback_t cb,
+ void *user_data)__attribute__((weak));
+
+void
+cl_mbx_ipmbox_send (cl_mbx_t *ctx, u8 *buffer, uint length)
+ __attribute__((weak));
+
+
+cl_mbx_t*
+cl_mbx_init (ipmbox_t *ipmbox)
+{
+ return INVALID_PTR;
+}
+
+void
+cl_mbx_uninit (cl_mbx_t* ctx){}
+
+void
+cl_mbx_callback_register (cl_mbx_t *ctx, cl_mme_callback_t cb,
+ void *user_data){}
+
+void
+cl_mbx_ipmbox_send (cl_mbx_t *ctx, u8 *buffer, uint length){}
diff --git a/cesar/cl/src/brg_rx.c b/cesar/cl/src/brg_rx.c
index 8770635465..c35626698e 100644
--- a/cesar/cl/src/brg_rx.c
+++ b/cesar/cl/src/brg_rx.c
@@ -11,11 +11,12 @@
* \ingroup cl
*/
#include "common/std.h"
-#include "cl/cl.h"
-#include "cl/brg_rx.h"
+
#include "hal/arch/arch.h"
-#include "cl/inc/cl.h"
+#include "cl/cl.h"
+#include "cl/brg_rx.h"
+#include "cl/inc/context.h"
void
cl_brg_rx_add (cl_t *ctx, mac_t smac, uint tei)
diff --git a/cesar/cl/src/cl.c b/cesar/cl/src/cl.c
index d72b10c583..374a0cfaae 100644
--- a/cesar/cl/src/cl.c
+++ b/cesar/cl/src/cl.c
@@ -13,338 +13,88 @@
*/
#include "common/std.h"
-#include "common/defs/ethernet.h"
-#include "lib/bitstream.h"
+
#include "lib/seq_check.h"
+#include "hal/arch/arch.h"
+#include "hal/gpio/gpio.h"
+
#include "cl/cl.h"
-#include "cl/data_rate.h"
-#include "mac/sar/sar.h"
-#include "mac/pbproc/pbproc.h"
-#include "mac/common/timings.h"
+#include "cl/cl_mactotei.h"
+#include "cl/bridge_table.h"
#include "cl/inc/context.h"
-#include "cl/inc/cl.h"
#include "cl/inc/trace.h"
-#include "cl/bridge_table.h" // bridge_table_*
-
-#include "mac/common/ntb.h"
-#include "mac/sar/sar.h"
-
-#include <string.h>
-
-#include "mac/common/store.h"
-
-#include "hal/arch/arch.h"
-#include "hal/gpio/gpio.h"
+#include "cl/inc/send.h"
+#include "cl/inc/receive.h"
+#include "config/cl.h"
static struct cl_t cl_global;
-/**
- * Callback when the lib sequencer detect a wrong sequencing.
- * \param user user data
- * \param vlan the VLAN id
- * \param seq_expected the sequence number expected
- * \param seq_actual the actual sequence number found in the packet
- */
-void
-cl_lib_seq_check_cb (void *user, uint vlan, uint seq_expected,
- uint seq_actual);
-
-void
-cl_lib_seq_check_cb (void *user, uint vlan, uint seq_expected,
- uint seq_actual)
-{
- dbg_assert (user);
- trace_do (cl_t *ctx = (cl_t *) user);
- CL_TRACE (SEQ_CHECK, vlan, seq_expected, seq_actual);
-}
-
-/**
- * Search for the lid in the classifier
- *
- * \param ctx CL context
- * \param tei the tei found previously by the mactotei table.
- * \param tag tag provided by the upper layer.
- * \param bcast true if the link is a broadcast one, false otherwise.
- * \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 *ctx, uint tei, uint tag,
- bool *bcast, bool *acs,
- bool *drop)
-{
- static uint lid_table[] = { 1, 0, 0, 1, 2, 2, 3, 3 };
- uint lid;
- dbg_assert (ctx);
- dbg_assert (bcast);
- dbg_assert (acs);
- dbg_assert (drop);
- dbg_assert (tag < COUNT (lid_table));
- if (tei == MAC_TEI_BCAST)
- *bcast = true;
- else
- *bcast = false;
- *acs = false;
- *drop = false;
- lid = lid_table[tag];
- CL_TRACE (CLASSIFIER, phy_date (), tei, *bcast, *acs, *drop, lid);
- /** TODO fill the classifier */
- return lid;
-}
-
-/**
- * Compute the data rate for a station based on the TEI.
- * \param ctx CL context.
- * \param mfs the MFS used for the transmission or reception.
- * \param length the data length.
- */
-PRIVATE void
-cl_compute_datarate_on_sta (cl_t *ctx, mfs_t *mfs, uint length)
-{
-#if CONFIG_CL_DATA_RATE
- if (MAC_TEI_IS_STA (mfs->common.tei))
- {
- sta_t *sta = mac_store_sta_get (ctx->mac_store, mfs->common.tei);
- if (sta)
- {
- data_rate_update_info (
- mfs->common.tx ? &sta->tx_data_rate : &sta->rx_data_rate,
- length);
- blk_release (sta);
- }
- }
-#endif
-}
-
-/**
- * Send a data once the TEI has been find.
- *
- * \param ctx the cl context.
- * \param buffer the buffer containing the data to send.
- * \param length the buffer data length.
- * \param tei the TEI found from the cl_mactotei list.
- * \param tag the tag provided by the upper layer.
- * \param cl_data opaque type.
- * \param arrival_time_ntb the arrival time in NTB.
- * \param dmac the final destination mac address.
- * \param smac the source mac address.
- */
-static void
-cl_data_send_with_tei (cl_t *ctx, u8 *buffer, uint length, uint tei,
- uint tag, cl_send_t *cl_data, u32 arrival_time_ntb,
- mac_t dmac, mac_t smac)
-{
- uint lid;
- bool bcast;
- bool acs;
- bool drop;
- mfs_tx_t *mfs;
-
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
- dbg_assert (tei);
-
- /* Get some data from the classifier. */
- lid = cl_classifer_get_lid (ctx, tei, tag, &bcast, &acs, &drop);
-
- if (MAC_LID_IS_PLID (lid))
- {
- bool added;
-
- /* Create the MFS if it does not exits. */
- mfs = mac_store_mfs_add_tx (ctx->mac_store, bcast, false, lid, tei,
- &added);
-
- if (added)
- sar_mfs_add (ctx->sar, (mfs_t *)mfs);
- }
- else
- {
- /* try to get the mfs from the store. */
- mfs = mac_store_mfs_get_tx (ctx->mac_store, bcast, false, lid, tei);
- }
-
- if (!drop && !acs && mfs)
- {
- CL_TRACE (DATA_SEND, phy_date (), buffer, length, mfs->common.tei,
- mfs->common.lid, mfs->common.bcast);
- ctx->data_send_link.mfs = mfs;
- ctx->data_send_link.last_update_date_ntb = arrival_time_ntb;
- ctx->data_send_link.dmac = dmac;
- ctx->data_send_link.smac = smac;
- ctx->data_send_link.tag = tag;
- sar_msdu_add (ctx->sar, buffer, length, mfs, cl_data,
- arrival_time_ntb);
- cl_compute_datarate_on_sta (ctx, PARENT_OF (mfs_t, tx, mfs), length);
- }
- else
- {
- CL_TRACE (DATA_SEND_DROP, phy_date (), ctx->mac_config->authenticated,
- buffer, length);
- dbg_assert (ctx->data_tx.cb);
- (*ctx->data_tx.cb) (ctx->data_tx.user, buffer);
- /* Release the MFS */
- if (mfs)
- blk_release (mfs);
- }
-}
-
-/** Initialise the cl_send object.
- * \param cl the cl context.
- * \param buffer the buffer
- * \param mme if the buffer contains a MME.
- * \return a cl data object.
- *
- * This object is used to hold reference to the buffer. Once this object is
- * destroyed, it will release the associated buffer. This is useful for
- * multiple unicast where the same buffer is sent several time to the SAR
- * layer.
- */
-static cl_send_t *
-cl_send_init (cl_t *ctx, u8 *buffer, bool mme)
-{
- cl_send_t *cl_data;
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- cl_data = slab_alloc (&ctx->slab_buffer_handler);
-
- cl_data->cl = ctx;
- cl_data->buffer = buffer;
- cl_data->mme = mme;
- return cl_data;
-}
-
-/**
- * Gives back the buffer to the CP or the HLE.
- * \param object destructed object
- *
- * This is the destructor of cl_send_t objects.
- */
-static void
-cl_send_release (void *object)
-{
- cl_send_t *cl_data;
- cl_t *ctx;
- dbg_assert (object);
-
- cl_data = object;
- ctx = cl_data->cl;
-
- if (cl_data->mme)
- {
- cl_mme_buffer_add (cl_data->cl, cl_data->buffer);
- CL_TRACE (MME_SEND_DONE, phy_date (), cl_data->buffer);
- }
- else
- {
- dbg_assert (ctx->data_tx.cb);
- (*ctx->data_tx.cb) (ctx->data_tx.user, cl_data->buffer);
- CL_TRACE (DATA_SEND_DONE, phy_date (), cl_data->buffer);
- }
-}
-
-/**
- * Init the Convergence Layer and return a pointer on the CL context.
- *
- * \param mac_store the mac store.
- * \param sar the sar context.
- * \param mac_config the mac config.
- * \return the convergence layer context.
- */
cl_t *
-cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config)
+cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config,
+ ipmbox_t *ipmbox, bufmgr_t *bufmgr)
{
cl_t *ctx;
- dbg_assert (mac_store);
- dbg_assert (sar);
+ /* Check parameters. */
dbg_assert (mac_config);
ctx = &cl_global;
+ /* Initialize MAC store. */
cl_global.mac_store = mac_store;
- /* Initialize the SAR */
- cl_global.sar = sar;
- cl_global.mme_buffer = ARCH_CPU_TO_UNCACHEABLE(cl_global.static_mme_buffer);
-
- // MME part
- 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,(sar_reassembly_done_cb_t) cl_mme_recv);
+ /* Initialize IPMbox. */
+ cl_global.ipmbox = ipmbox;
+ ipmbox_register_rx_data_cb (
+ ipmbox, &cl_global, (ipmbox_rx_cb_t) cl_ipmbox_data_recv);
- sar_mme_buffer_add (cl_global.sar, cl_global.mme_buffer);
+ /* Initialise Mbx cl sub module. */
+ cl_global.mbx = cl_mbx_init (ipmbox);
- // Data TX part
- sar_init_data_context (cl_global.sar, &cl_global);
- sar_init_segmentation_data_cb (cl_global.sar,
- (sar_segmentation_done_cb_t) cl_data_send_done);
+ /* Initialize buffer manager. */
+ cl_global.bufmgr = bufmgr;
- // DATA RX part
- sar_init_reassembly_data_cb (cl_global.sar, (sar_reassembly_done_cb_t)cl_data_recv);
-
- /* init the mme */
- cl_mme_init (&cl_global.mme);
+ /* Initialize SAR */
+ cl_global.sar = sar;
+ sar_init_reassembly_callbacks (cl_global.sar,
+ (sar_reassembly_cb_t) cl_sar_data_recv,
+ (sar_reassembly_cb_t) cl_sar_mme_recv,
+ &cl_global);
- /* init the cl_mactotei table */
+ /* Initialize the cl_mactotei table */
cl_global.mactotei = NULL;
- /* init the cl mme buffer to null */
- cl_global.mme_ul_send.cb = NULL;
- cl_global.mme_ul_send.user = NULL;
-
- /* add the mac_config */
+ /* Add the mac_config */
cl_global.mac_config = mac_config;
/* Initialize the trace system. */
cl_trace_init (ctx);
- /* Initialise the slab cache. */
- slab_cache_init (&ctx->slab_buffer_handler,
- "CL cache", sizeof (cl_send_t), cl_send_release);
-
/* Initialize the local bridge table module. */
bridge_table_init (ctx);
ctx->brg_rx = NULL;
- /* Initialise the data link. */
+ /* Initialize the data link. */
ctx->data_send_link.mfs = NULL;
CL_TRACE (INIT, phy_date ());
- /* Initialise packet sequence check. */
- lib_seq_check_init (&ctx->seq_check_rx_ctx, cl_lib_seq_check_cb, ctx);
+ /* Initialize packet sequence check. */
+ lib_seq_check_init (&ctx->seq_check_rx_ctx, cl_lib_seq_check_rx_cb, ctx);
+ lib_seq_check_init (&ctx->seq_check_tx_ctx, cl_lib_seq_check_tx_cb, ctx);
- /* Debug leds. */
+ /* Debug LEDs. */
GPIO_SETUP (LED_CL_RX, GPIO_DIRECTION_OUT);
GPIO_SET (LED_CL_RX, 0);
GPIO_SETUP (LED_CL_TX, GPIO_DIRECTION_OUT);
GPIO_SET (LED_CL_TX, 0);
-
return &cl_global;
}
/**
- * Init the MME module of the CL
- *
- * \param ctx the mme context.
- */
-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;
-}
-
-/**
* Uninit the Convergence layer context.
*
* \param ctx the convergence layer context
@@ -356,13 +106,9 @@ void cl_uninit (cl_t *ctx)
CL_TRACE (UNINIT, phy_date ());
if (ctx->mactotei)
- {
cl_mactotei_release_table (ctx);
- }
- cl_brg_rx_release (ctx);
- /* Uninitialise the slab cache. */
- slab_cache_uninit (&ctx->slab_buffer_handler);
+ cl_brg_rx_release (ctx);
/* De-initialize the local bridge table module. */
bridge_table_deinit (ctx);
@@ -370,626 +116,6 @@ void cl_uninit (cl_t *ctx)
cl_trace_uninit(ctx);
}
-/**
- * Initialize the CL to call the Upper layer once the CP ends processing the
- * MME.
- * Used each time the CP needs to send an MME to the upper layer.
- *
- * \param ctx the CL context
- * \param cb the upper layer callback to use to send an MME.
- * \param user the user data to provide with the callback
- */
-void cl_mme_ul_init_send_done (cl_t *ctx, cl_mme_ul_recv_done_cb_t cb,
- void *user)
-{
- dbg_assert (ctx);
- dbg_assert (cb);
-
- ctx->mme.ul_mme_recv_done = cb;
- ctx->mme.ul_mme_recv_done_user_data = user;
-}
-
-/**
- * Init the function call when an MME is received from the SAR or the HLE.
- * The CP registers its callback to allow the CL to call it each time a MME
- * is received from the PLC or the HLE.
- *
- * \param ctx the CL ctx
- * \param mme_recv_cb
- * \param user_data the user data
- */
-void cl_mme_recv_init (cl_t *ctx, cl_mme_recv_cb_t mme_recv_cb, void
-*user_data)
-{
- dbg_assert (ctx);
- dbg_assert (mme_recv_cb);
-
- ctx->mme.mme_recv_cb = mme_recv_cb;
- ctx->mme.mme_recv_user_data = user_data;
-}
-
-/**
- * Initialize the CL to send MMEs to the Upper layer considered as data.
- * Used each time the CP needs to send an MME to the upper layer.
- *
- * \param ctx the CL context
- * \param cb the upper layer callback to use to send an MME.
- * \param user the user data to provide with the callback
- */
-void cl_mme_init_ul_as_data (cl_t *ctx, cl_mme_ul_send_done_cb_t cb,
- void *user)
-{
- dbg_assert (ctx);
- dbg_assert (cb);
-
- ctx->mme_ul_send.cb = cb;
- ctx->mme_ul_send.user = user;
-}
-
-/**
- * Initialize the CP call back to get a buffer.
- *
- * \param cl the cl context
- * \param cb the call back function
- * \param user_data the user data.
- */
-void cl_mme_init_buffer_add_cb (cl_t *cl, cl_mme_buffer_add_cb_t cb,
- void *user_data)
-{
- dbg_assert (cl);
- dbg_assert (cb);
-
- cl->mme.mme_buffer_add_cb = cb;
- cl->mme.mme_buffer_add_user_data = user_data;
-}
-
-/**
- * Sends a packet to the SAR.
- * \param ctx the CL context.
- * \param buffer the buffer length.
- * \param length the buffer length.
- * \param tei the destination TEI.
- * \param mme true if the message comes from the CP, false otherwise.
- * \param arrival_time_ntb the arrival time in NTB.
- */
-static void
-cl_send_unicast (cl_t *ctx, u8 *buffer, uint length, uint tei,
- bool mme, u32 arrival_time_ntb)
-{
- cl_send_t *cl_data;
- mfs_tx_t *mfs;
- bool added;
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
- dbg_assert (MAC_TEI_FOREIGN != tei);
-
- if (mme && ((MAC_TEI_IS_STA (tei)) || (MAC_TEI_BCAST == tei)))
- {
- /* Allocate the buffer handler. */
- cl_data = cl_send_init (ctx, buffer, mme);
-
- mfs = mac_store_mfs_add_tx (ctx->mac_store,
- tei == MAC_TEI_BCAST ? true : false,
- true /* mme */,
- MAC_LID_NONE,
- tei,
- &added);
-
- if (added)
- sar_mfs_add (ctx->sar, (mfs_t *) mfs);
-
- CL_TRACE (MME_SEND_UNICAST, phy_date (), length, buffer, tei);
- sar_msdu_add (ctx->sar, buffer, length,
- mfs, cl_data, arrival_time_ntb);
-
- blk_release (mfs);
- }
- else
- /* FIXME to be implemented for the DATA too. */
- dbg_assert_default ();
-}
-
-/**
- * Sends a packet to the SAR.
- * \param ctx the CL context.
- * \param buffer the buffer length.
- * \param length the buffer length.
- * \param tei the destination TEI.
- * \param mme true if the message comes from the CP, false otherwise.
- * \param tag the tag provided by the upper layer.
- * \param arrival_time_ntb the arrival time NTB.
- * \param group_id the group id for data multiunicast.
- */
-static void
-cl_send_multiunicast (cl_t *ctx, u8 *buffer, uint length, bool mme, uint tag,
- u32 arrival_time_ntb, uint group_id)
-{
- cl_send_t *cl_data;
- uint i;
- sta_t *sta;
- mfs_tx_t *mfs;
- bool added;
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
-
- /* Allocate the buffer handler. */
- cl_data = cl_send_init (ctx, buffer, mme);
-
- if (mme)
- {
- for ( i = MAC_TEI_STA_MIN; i < MAC_TEI_STA_NB; i++)
- {
- sta = mac_store_sta_get (ctx->mac_store, i);
-
- if (sta && sta->multi_unicast_receiver)
- {
- mfs = mac_store_mfs_add_tx (ctx->mac_store,
- false /* MME */,
- true /* MME */,
- MAC_LID_NONE,
- i,
- &added);
- if (added)
- sar_mfs_add (ctx->sar, (mfs_t *) mfs);
-
- CL_TRACE (MME_SEND_MULTIUNICAST, phy_date (), length, buffer,
- i);
- slab_addref (cl_data);
- sar_msdu_add (ctx->sar, buffer, length,
- mfs, cl_data, arrival_time_ntb);
-
- blk_release (mfs);
- blk_release (sta);
- }
- }
- }
- else
- {
- for (i = 0; i < ctx->groups.nb_actual_members[group_id]; i++)
- {
- uint lid;
- bool bcast;
- bool acs;
- bool drop;
- uint tei = ctx->groups.member_tei[group_id][i];
- dbg_assert (MAC_TEI_IS_STA (tei));
-
- /* Get some data from the classifier. */
- lid = cl_classifer_get_lid (ctx, tei, tag, &bcast, &acs, &drop);
-
- if (MAC_LID_IS_PLID (lid))
- {
- /* Create the MFS if it does not exits. */
- mfs = mac_store_mfs_add_tx (ctx->mac_store, bcast, false, lid,
- tei, &added);
- if (added)
- sar_mfs_add (ctx->sar, (mfs_t *)mfs);
- }
- else
- {
- /* try to get the mfs from the store. */
- mfs = mac_store_mfs_get_tx (ctx->mac_store, bcast, false, lid,
- tei);
- }
-
- if (!drop && !acs && mfs)
- {
- CL_TRACE (DATA_SEND, phy_date (), buffer, length,
- mfs->common.tei, mfs->common.lid, mfs->common.bcast);
- slab_addref (cl_data);
- sar_msdu_add (ctx->sar, buffer, length, mfs, cl_data,
- arrival_time_ntb);
- cl_compute_datarate_on_sta (
- ctx, PARENT_OF (mfs_t, tx, mfs), length);
- }
- else
- {
- CL_TRACE (DATA_SEND_MULTI_FAILED, phy_date (), drop, acs,
- mfs, tei, group_id);
- }
- if (mfs)
- blk_release (mfs);
- }
- }
- slab_release (cl_data);
-}
-
-/**
- * Prepare the CL to send a Frame.
- * \param ctx the cl context.
- * \param buffer the Ethernet frame to send.
- * \param length the Ethernet frame length.
- * \param tag the tag for the classifier.
- * \param arrrival_time_ntb arrival time in the High layers.
- * \param dmac the destination mac address.
- * \param smac the source mac address.
- */
-static void
-cl_data_send_prepare (cl_t *ctx, u8 *buffer, uint length, uint tag,
- u32 arrival_time_ntb, mac_t dmac, mac_t smac)
-{
- /* The source MAC address should not be not be a multicast, a zero address
- * nor a broadcast one (note that checking multicast address also checks
- * for broadcast). Linux, in bridging mode, handle this problem and reject
- * any of those packets (see net/bridge/br_input.c:127 (in
- * br_handle_frame). */
- dbg_assert (smac != MAC_ZERO);
- dbg_assert (!mac_is_multicast (smac));
- /* Add the source MAC address to the local bridge table if not our MAC
- * address. */
- dbg_assert (ctx->mac_config);
- if (ctx->mac_config->sta_mac_address != smac)
- bridge_table_add (ctx, smac);
-
- /* Data are forbidden if not authenticated. */
- if (!ctx->mac_config->authenticated)
- {
- (*ctx->data_tx.cb) (ctx->data_tx.user, buffer);
- CL_TRACE (DATA_SEND_DROP, phy_date (), ctx->mac_config->authenticated,
- buffer, length);
- return;
- }
-
- /* Get the TEI from the mactotei table. */
- uint tei;
- uint group;
- tei = cl_mactotei_table_find_tei_and_tag_from_mac (ctx, dmac, &group);
- dbg_assert (tei != ctx->mac_config->tei);
-
- if (tei == MAC_TEI_BCAST)
- {
- if (ctx->groups.nb_actual_members[group] > 1)
- {
- cl_send_multiunicast (ctx, buffer, length, 0, tag, arrival_time_ntb,
- group);
- return;
- }
- else
- tei = ctx->groups.member_tei[group][0];
- }
-
- /* If the TEI is not found the packet is send as broadcast. */
- cl_data_send_with_tei (ctx, buffer, length,
- tei == MAC_TEI_UNASSOCIATED ? MAC_TEI_BCAST: tei,
- tag, NULL, arrival_time_ntb, dmac, smac);
-}
-
-void
-cl_data_send (cl_t *ctx, u8 *buffer, uint length, uint tag,
- u32 arrival_time_ntb)
-{
- mac_t smac, dmac;
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
- bitstream_direct_read_macs (buffer, &dmac, &smac);
- if (ctx->data_send_link.mfs
- && ctx->data_send_link.mfs->fsm_state != MFS_FSM_CMD_RELEASE
- && dmac == ctx->data_send_link.dmac
- && smac == ctx->data_send_link.smac
- && tag == ctx->data_send_link.tag
- && ctx->mac_config->authenticated
- && less_mod2p32 (arrival_time_ntb,
- ctx->data_send_link.last_update_date_ntb
- + MAC_MS_TO_TCK (CL_DATA_SEND_EXCEED_TIME_MS)))
- {
- CL_TRACE (DATA_SEND, phy_date (), buffer, length,
- ctx->data_send_link.mfs->common.tei,
- ctx->data_send_link.mfs->common.lid,
- ctx->data_send_link.mfs->common.bcast);
- sar_msdu_add (ctx->sar, buffer, length,
- ctx->data_send_link.mfs, NULL,
- arrival_time_ntb);
- cl_compute_datarate_on_sta (
- ctx, PARENT_OF (mfs_t, tx, ctx->data_send_link.mfs), length);
- }
- else
- {
- /* Release the MFS's reference. */
- if (ctx->data_send_link.mfs)
- {
- blk_release (ctx->data_send_link.mfs);
- ctx->data_send_link.mfs = NULL;
- }
- cl_data_send_prepare (ctx, buffer, length, tag,
- arrival_time_ntb, dmac, smac);
- }
-}
-
-/**
- * Send an MME from the CP to the PLC via the SAR MME way.
- *
- * \param ctx the CL context
- * \param buffer the buffer containing the MME
- * \param length the length of the MME
- * \param mfs the MFS use for the SAR if the MME should be send over the PLC
- */
-void
-cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && length <= ETH_PACKET_MAX_SIZE);
- dbg_assert (ctx->sar);
-
-
- /* Unicast or broadcast neighbour.
- * Unicast is allowed even if the station is not associated.
- * The broadcast is only allowed if the station is associated. */
- if (((MAC_TEI_IS_STA (tei)
- || (tei == MAC_TEI_BCAST)))
- && (MAC_TEI_IS_STA(ctx->mac_config->tei)))
- {
- cl_send_unicast (ctx, buffer, length,
- tei,
- true /* MME */,
- mac_ntb());
- }
- /* Handle the unassociated unicast with temporary MFS. */
- else if (MAC_TEI_IS_STA (tei)
- && (ctx->mac_config->tei == MAC_TEI_UNASSOCIATED))
- {
- mfs_tx_t *mfs;
- cl_send_t *cl_data;
-
- mfs = &mac_store_mfs_unassociated_add (
- ctx->mac_store, true /* tx */, false /* unicast */,
- true /* mme */, MAC_LID_NONE, tei)->tx;
-
- dbg_assert (ctx->sar);
- sar_mfs_add (ctx->sar, (mfs_t *) mfs);
-
- cl_data = cl_send_init (ctx, buffer, true /* MME. */);
-
- CL_TRACE (MME_SEND_UNASSOC_UNICAST, phy_date (), length, buffer,
- mfs->common.tei);
- sar_msdu_add (ctx->sar, buffer, length,
- mfs, cl_data, mac_ntb());
- blk_release (mfs);
- }
- /* It the destination TEI is broadcast and our station is not
- * associated, disallow to send a broadcast packet as a multi unicast.*/
- else if (tei == MAC_TEI_MULTI_UNICAST)
- {
- dbg_assert (ctx->mac_config->tei);
- cl_send_multiunicast (ctx, buffer, length, true /* MME */, 1,
- mac_ntb(), 0);
- }
- /* the destination is not associated or associated and our station
- * can or not be associated */
- else if ((tei == MAC_TEI_UNASSOCIATED)
- || (tei == MAC_TEI_BCAST))
- {
- mfs_tx_t *mfs;
- cl_send_t *cl_data;
-
- mfs = &mac_store_mfs_unassociated_add (
- ctx->mac_store, true /* tx */, true /* bcast */,
- true /* mme */, MAC_LID_NONE, MAC_TEI_BCAST)->tx;
-
- /* Quick hack to send the CC_ASSOC.CNF before the
- * CC_SET_TEI_MAP.IND. */
- mfs->cap = 3;
-
- dbg_assert (ctx->sar);
- sar_mfs_add (ctx->sar, (mfs_t *) mfs);
-
- cl_data = cl_send_init (ctx, buffer, true /* MME. */);
-
- CL_TRACE (MME_SEND_TO_UNASSOC, phy_date (), length, buffer,
- mfs->common.tei);
- sar_msdu_add (ctx->sar, buffer, length,
- mfs, cl_data, mac_ntb());
-
- blk_release (mfs);
- }
- else
- {
- CL_TRACE (MME_SEND_TO_DRIVER, phy_date (), length, buffer);
- dbg_assert (ctx->mme_ul_send.cb);
- (*ctx->mme_ul_send.cb) (ctx->mme_ul_send.user, buffer, length);
- }
-}
-
-/**
- * Callback called by the sar when a MME as been sent over the PWL.
- *
- * \param ctx the cl context.
- * \param buffer the buffer used.
- * \param cl_data the data provided to the SAR on the send.
- */
-void cl_mme_sar_send_done (cl_t *ctx, u8 *buffer, void *cl_data)
-{
- cl_send_t *data;
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (cl_data);
-
- data = cl_data;
-
- slab_release (data);
-
- /* Debug info. */
- GPIO_TOGGLE (LED_CL_TX);
-}
-
-void cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs, bool
- encryption)
-{
- dbg_assert (ctx);
-
- dbg_assert (ctx->mme.mme_recv_cb);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
-
- (*ctx->mme.mme_recv_cb) (ctx->mme.mme_recv_user_data,
- mfs ? mfs->common.tei : MAC_TEI_FOREIGN,
- buffer, length, mfs ? true : false, encryption);
-
- CL_TRACE (MME_RECV, phy_date (), length, buffer, mfs ? true : false);
-
- /* Debug info. */
- GPIO_TOGGLE (LED_CL_RX);
-}
-
-void cl_mme_recv_done (cl_t *ctx, u8* buffer, bool mme_recv)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- CL_TRACE (MME_RECV_DONE, phy_date (), buffer, mme_recv);
-
- if (mme_recv)
- {
- dbg_assert (ctx->sar);
- sar_mme_buffer_add (ctx->sar, buffer);
- }
- else
- {
- dbg_assert (ctx->mme.ul_mme_recv_done);
-
- (*ctx->mme.ul_mme_recv_done) (ctx->mme.ul_mme_recv_done_user_data,
- buffer);
- }
-}
-
-
-
-
-/**
- * Initialize the callback to inform the upper layer when a data had been sent
- * over the PLC.
- *
- * \param cl the CL context
- * \param cb the callback to call once the data had been sent
- * \param user the user data to provide with the callback call
- */
-void cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user)
-{
- dbg_assert (cl);
- dbg_assert (cb);
-
- cl->data_tx.cb = cb;
- cl->data_tx.user = user;
-}
-
-
-/**
- * The SAR inform the CL that the data previously provided had been sent over
- * the PLC.
- *
- * \param ctx the CL context.
- * \param buffer the buffer containing the MME
- * \param cl_data the data provided to the SAR on the msdu add.
- */
-void cl_data_send_done (cl_t *ctx, u8 *buffer, void *cl_data)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- if (!cl_data)
- {
- /* Give back to upper layer. */
- dbg_assert (ctx->data_tx.cb);
- (*ctx->data_tx.cb) (ctx->data_tx.user, buffer);
- CL_TRACE (DATA_SEND_DONE, phy_date (), buffer);
- }
- else
- slab_release (cl_data);
-
- /* Debug info. */
- GPIO_TOGGLE (LED_CL_TX);
-}
-
-/**
- * Initialize the callback to receive the data from the PLC.
- *
- * \param cl the CL context
- * \param cb the function callback to call
- * \param user the user data to provide on the callback.
- */
-void cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user)
-{
- dbg_assert (cl);
- dbg_assert (cb);
-
- cl->data_rx.cb = cb;
- cl->data_rx.user = user;
-}
-
-/**
- * Called by the SAR each time it has a data to provide to the CL.
- *
- * \param ctx the CL context
- * \param buffer the buffer containing the data to send to the Upper layer.
- * \param length the data length in the buffer
- * \param mfs the mfs used to receive the data.
- */
-void cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
- dbg_assert (mfs);
-
- /* Check sequence number of throughput. */
- lib_seq_check_packet (&ctx->seq_check_rx_ctx, buffer, length);
-
- dbg_assert (ctx->data_rx.cb);
-
- mac_t smac, dmac;
- bitstream_direct_read_macs (buffer, &dmac, &smac);
- CL_TRACE (DATA_RECV, phy_date (), buffer, TRACE_U64 (dmac),
- TRACE_U64 (smac), length);
- (*ctx->data_rx.cb) (ctx->data_rx.user, buffer, length);
- cl_brg_rx_add (ctx, smac, mfs->common.tei);
- /* update data rate informations associated to the RX
- * from the associated sta to the local sta */
- cl_compute_datarate_on_sta (ctx, PARENT_OF (mfs_t, rx, mfs), length);
- /* Debug info. */
- GPIO_TOGGLE (LED_CL_RX);
-}
-
-/**
- * Provides a buffer to the CP.
- *
- * \param ctx the CL context
- * \param buffer the buffer to reassembly some data
- */
-void cl_mme_buffer_add (cl_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- CL_TRACE (MME_BUFFER_ADD, phy_date (), buffer);
- dbg_assert (ctx->mme.mme_buffer_add_cb);
- (*ctx->mme.mme_buffer_add_cb) (ctx->mme.mme_buffer_add_user_data, buffer);
-}
-
-/**
- * Provides a buffer to the SAR to reassembly data
- *
- * \param ctx the CL context
- * \param buffer the buffer to reassembly some data
- */
-void cl_data_buffer_add (cl_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- CL_TRACE (DATA_BUFFER_ADD, phy_date (), buffer);
-
- sar_data_buffer_add (ctx->sar, buffer);
-}
-
void
cl_data_send_link_clear (cl_t *ctx)
{
@@ -1034,3 +160,28 @@ cl_update_igmp_groups (cl_t *ctx)
ctx->groups.member_tei[g][0] = MAC_TEI_BCAST;
}
}
+
+#if CONFIG_CL_DATA_RATE
+void
+cl_compute_datarate_on_sta_ (cl_t *ctx, mfs_t *mfs, uint length)
+{
+ if (MAC_TEI_IS_STA (mfs->common.tei))
+ {
+ sta_t *sta = mac_store_sta_get (ctx->mac_store, mfs->common.tei);
+ if (sta)
+ {
+ data_rate_update_info (
+ mfs->common.tx ? &sta->tx_data_rate : &sta->rx_data_rate,
+ length);
+ blk_release (sta);
+ }
+ }
+}
+#endif
+
+cl_mbx_t*
+cl_mbx_get (cl_t *ctx)
+{
+ dbg_assert (ctx);
+ return ctx->mbx;
+}
diff --git a/cesar/cl/src/cl_mactotei.c b/cesar/cl/src/cl_mactotei.c
index 38dae1f1e3..fb3253c2a0 100644
--- a/cesar/cl/src/cl_mactotei.c
+++ b/cesar/cl/src/cl_mactotei.c
@@ -11,11 +11,12 @@
* \ingroup cl
*/
#include "common/std.h"
-#include "cl/cl_mactotei.h"
-#include "cl/inc/cl.h"
#include "mac/common/defs.h"
+#include "cl/cl_mactotei.h"
+#include "cl/inc/context.h"
+
/**
* Set a TEI and a tag in an extra information field.
* \param tei TEI to set.
diff --git a/cesar/cl/src/receive.c b/cesar/cl/src/receive.c
new file mode 100644
index 0000000000..3a6f5e74c1
--- /dev/null
+++ b/cesar/cl/src/receive.c
@@ -0,0 +1,107 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/src/receive.c
+ * \brief Functions to handle data coming into the CL
+ * \ingroup cl
+ */
+#include "common/std.h"
+#include "common/defs/ethernet.h"
+
+#include "common/ipmbox/msg.h"
+#include "common/ipmbox/protocol.h"
+
+#include "lib/bitstream.h"
+#include "lib/seq_check.h"
+
+#include "mac/common/ntb.h"
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/gpio/gpio.h"
+
+#include "hle/tools/tools.h"
+
+#include "cl/cl.h"
+#include "cl/data_rate.h"
+#include "cl/bridge_table.h"
+
+#include "cl/inc/trace.h"
+#include "cl/inc/context.h"
+#include "cl/inc/send.h"
+#include "cl/inc/receive.h"
+#include "config/cl.h"
+
+void
+cl_sar_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
+{
+ dbg_claim (ctx);
+ dbg_claim (buffer);
+ dbg_claim (mfs);
+
+ /* Check sequence number of throughput. */
+ lib_seq_check_packet (&ctx->seq_check_rx_ctx, buffer, length);
+
+ mac_t smac, dmac;
+ bitstream_direct_read_macs (buffer, &dmac, &smac);
+ CL_TRACE (DATA_RECV, phy_date (), buffer, TRACE_U64 (dmac),
+ TRACE_U64 (smac), length);
+
+ /* Create IPMbox message. */
+ ipmbox_msg_data_t msg;
+ msg.header = ipmbox_msg_create_header_data (length, 0);
+ msg.buffer_addr = (u32) buffer;
+ ipmbox_tx_data (ctx->ipmbox, (u32 *) &msg, IPMBOX_MSG_DATA_WORDS);
+
+ cl_brg_rx_add (ctx, smac, mfs->common.tei);
+
+ /* update data rate informations associated to the RX
+ * from the associated sta to the local sta */
+ cl_compute_datarate_on_sta (ctx, PARENT_OF (mfs_t, rx, mfs), length);
+ /* Debug info. */
+ GPIO_TOGGLE (LED_CL_RX);
+}
+
+void
+cl_sar_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs,
+ bool encryption)
+{
+ dbg_claim (ctx);
+ dbg_claim (mfs);
+ dbg_claim (buffer);
+ (*ctx->mbx->cb) (ctx->mbx->user_data, mfs->common.tei,
+ buffer, length, encryption);
+ CL_TRACE (MME_RECV, phy_date (), length, buffer, true);
+ /* Debug info. */
+ GPIO_TOGGLE (LED_CL_RX);
+}
+
+void
+cl_ipmbox_data_recv (cl_t *ctx, u32 *msg_buffer, uint nb_words)
+{
+ /* Check parameters. */
+ dbg_claim (msg_buffer);
+ dbg_claim (nb_words);
+
+ ipmbox_msg_data_t *msg = (ipmbox_msg_data_t *) msg_buffer;
+ ipmbox_msg_data_t *msg_end = msg + nb_words / IPMBOX_MSG_DATA_WORDS;
+ for ( ; msg != msg_end; msg++)
+ {
+ u32 length = ipmbox_msg_get_data_length (msg->header);
+ u32 vlan_prio = ipmbox_msg_get_data_prio_tag (msg->header);
+ cl_data_send (ctx, (u8 *) msg->buffer_addr, length, vlan_prio,
+ mac_ntb ());
+ }
+}
+
+void
+cl_lib_seq_check_rx_cb (void *user, uint vlan, uint seq_expected,
+ uint seq_actual)
+{
+ dbg_assert (user);
+ trace_do (cl_t *ctx = (cl_t *) user);
+ CL_TRACE (SEQ_CHECK_RX, vlan, seq_expected, seq_actual);
+}
diff --git a/cesar/cl/src/send.c b/cesar/cl/src/send.c
new file mode 100644
index 0000000000..b43e7df8d3
--- /dev/null
+++ b/cesar/cl/src/send.c
@@ -0,0 +1,455 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/src/send.c
+ * \brief Functions to handle data going out of the CL
+ * \ingroup cl
+ */
+#include "common/std.h"
+#include "common/defs/ethernet.h"
+
+#include "common/ipmbox/msg.h"
+
+#include "lib/utils.h"
+#include "lib/bitstream.h"
+#include "lib/seq_check.h"
+
+#include "mac/common/timings.h"
+#include "mac/common/ntb.h"
+
+#include "cl/cl.h"
+#include "cl/data_rate.h"
+#include "cl/bridge_table.h"
+
+#include "cl/inc/context.h"
+#include "cl/inc/trace.h"
+#include "cl/inc/send.h"
+#include "config/cl.h"
+
+/**
+ * Search for the lid in the classifier
+ * \param ctx CL context
+ * \param tei the tei found previously by the mactotei table.
+ * \param tag tag provided by the upper layer.
+ * \param bcast true if the link is a broadcast one, false otherwise.
+ * \param acs put true if the link should be process by the ACS
+ * \param drop put true if the data should be drop.
+ */
+PRIVATE uint
+cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
+ bool *bcast, bool *acs,
+ bool *drop)
+{
+ static uint lid_table[] = { 1, 0, 0, 1, 2, 2, 3, 3 };
+ uint lid;
+ dbg_assert (ctx);
+ dbg_assert (bcast);
+ dbg_assert (acs);
+ dbg_assert (drop);
+ dbg_assert (tag < COUNT (lid_table));
+ if (tei == MAC_TEI_BCAST)
+ *bcast = true;
+ else
+ *bcast = false;
+ *acs = false;
+ *drop = false;
+ lid = lid_table[tag];
+ CL_TRACE (CLASSIFIER, phy_date (), tei, *bcast, *acs, *drop, lid);
+ /** TODO fill the classifier */
+ return lid;
+}
+
+/**
+ * Sends a packet to the SAR.
+ * \param ctx the CL context.
+ * \param buffer the buffer length.
+ * \param length the buffer length.
+ * \param tei the destination TEI.
+ * \param mme true if the message comes from the CP, false otherwise.
+ * \param tag the tag provided by the upper layer.
+ * \param arrival_time_ntb the arrival time NTB.
+ * \param group_id the group id for data multiunicast.
+ */
+static void
+cl_send_multiunicast (cl_t *ctx, u8 *buffer, uint length, bool mme, uint tag,
+ u32 arrival_time_ntb, uint group_id)
+{
+ uint i;
+ sta_t *sta;
+ mfs_tx_t *mfs;
+ bool added;
+ dbg_claim (ctx);
+ dbg_claim (buffer);
+
+ if (mme)
+ {
+ for ( i = MAC_TEI_STA_MIN; i < MAC_TEI_STA_NB; i++)
+ {
+ sta = mac_store_sta_get (ctx->mac_store, i);
+
+ if (sta && sta->multi_unicast_receiver)
+ {
+ mfs = mac_store_mfs_add_tx (ctx->mac_store,
+ false /* MME */,
+ true /* MME */,
+ MAC_LID_NONE,
+ i,
+ &added);
+ if (added)
+ sar_mfs_add (ctx->sar, (mfs_t *) mfs);
+
+ CL_TRACE (MME_SEND_MULTIUNICAST, phy_date (), length, buffer,
+ i);
+ sar_msdu_add (ctx->sar, buffer, length, mfs,
+ arrival_time_ntb);
+ blk_release (mfs);
+ blk_release (sta);
+ }
+ }
+ /* The buffer is no more used, be aware the SAR is polling the bridge
+ * DMA, that why it can release the buffer here. */
+ bufmgr_keep_buffer (ctx->bufmgr, buffer);
+ }
+ else
+ {
+ for (i = 0; i < ctx->groups.nb_actual_members[group_id]; i++)
+ {
+ uint lid;
+ bool bcast;
+ bool acs;
+ bool drop;
+ uint tei = ctx->groups.member_tei[group_id][i];
+ dbg_assert (MAC_TEI_IS_STA (tei));
+
+ /* Get some data from the classifier. */
+ lid = cl_classifer_get_lid (ctx, tei, tag, &bcast, &acs, &drop);
+
+ if (MAC_LID_IS_PLID (lid))
+ {
+ /* Create the MFS if it does not exits. */
+ mfs = mac_store_mfs_add_tx (ctx->mac_store, bcast, false, lid,
+ tei, &added);
+ if (added)
+ sar_mfs_add (ctx->sar, (mfs_t *)mfs);
+ }
+ else
+ {
+ /* try to get the mfs from the store. */
+ mfs = mac_store_mfs_get_tx (ctx->mac_store, bcast, false, lid,
+ tei);
+ }
+
+ if (!drop && !acs && mfs)
+ {
+ CL_TRACE (DATA_SEND, phy_date (), buffer, length,
+ mfs->common.tei, mfs->common.lid,
+ mfs->common.bcast);
+ sar_msdu_add (ctx->sar, buffer, length, mfs,
+ arrival_time_ntb);
+ /* update data rate informations associated to the TX
+ * from the local sta to the associated sta */
+ cl_compute_datarate_on_sta (ctx, PARENT_OF (mfs_t, tx, mfs),
+ length);
+ }
+ else
+ {
+ CL_TRACE (DATA_SEND_MULTI_FAILED, phy_date (), drop, acs,
+ mfs, tei, group_id);
+ }
+ if (mfs)
+ blk_release (mfs);
+ }
+ /* The buffer is no more used, be aware the SAR is polling the bridge
+ * DMA, that why it can release the buffer here. */
+ bufmgr_give_back (ctx->bufmgr, buffer);
+ }
+}
+
+/**
+ * Send a data once the TEI has been find.
+ *
+ * \param ctx the cl context.
+ * \param buffer the buffer containing the data to send.
+ * \param length the buffer data length.
+ * \param tei the TEI found from the cl_mactotei list.
+ * \param tag the tag provided by the upper layer.
+ * \param arrival_time_ntb the arrival time in NTB.
+ * \param dmac the final destination mac address.
+ * \param smac the source mac address.
+ */
+static void
+cl_data_send_with_tei (cl_t *ctx, u8 *buffer, uint length, uint tei,
+ uint tag, u32 arrival_time_ntb, mac_t dmac, mac_t smac)
+{
+ uint lid;
+ bool bcast;
+ bool acs;
+ bool drop;
+ mfs_tx_t *mfs;
+
+ dbg_assert (ctx);
+ dbg_assert (buffer);
+ dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
+ && (length <= ETH_PACKET_MAX_SIZE));
+ dbg_assert (tei);
+
+ /* Get some data from the classifier. */
+ lid = cl_classifer_get_lid (ctx, tei, tag, &bcast, &acs, &drop);
+
+ if (MAC_LID_IS_PLID (lid))
+ {
+ bool added;
+
+ /* Create the MFS if it does not exits. */
+ mfs = mac_store_mfs_add_tx (ctx->mac_store, bcast, false, lid, tei,
+ &added);
+
+ if (added)
+ sar_mfs_add (ctx->sar, (mfs_t *)mfs);
+ }
+ else
+ {
+ /* try to get the mfs from the store. */
+ mfs = mac_store_mfs_get_tx (ctx->mac_store, bcast, false, lid, tei);
+ }
+
+ if (!drop && !acs && mfs)
+ {
+ CL_TRACE (DATA_SEND, phy_date (), buffer, length, mfs->common.tei,
+ mfs->common.lid, mfs->common.bcast);
+ ctx->data_send_link.mfs = mfs;
+ ctx->data_send_link.last_update_date_ntb = arrival_time_ntb;
+ ctx->data_send_link.dmac = dmac;
+ ctx->data_send_link.smac = smac;
+ ctx->data_send_link.tag = tag;
+ sar_msdu_add (ctx->sar, buffer, length, mfs, arrival_time_ntb);
+ /* update data rate informations associated to the TX
+ * from the local sta to the associated sta */
+ cl_compute_datarate_on_sta (ctx, PARENT_OF (mfs_t, tx, mfs),
+ length);
+ }
+ else
+ {
+ CL_TRACE (DATA_SEND_DROP, phy_date (), ctx->mac_config->authenticated,
+ buffer, length);
+ /* Release the MFS */
+ if (mfs)
+ blk_release (mfs);
+ }
+ /* SAR ends using the buffer it can be given back.
+ * BRGDMA is polled by the SAR thats why it the buffer can be given
+ * back to the buffer manager. */
+ bufmgr_give_back (ctx->bufmgr, buffer);
+}
+
+/**
+ * Prepare the CL to send a Frame.
+ * \param ctx the cl context.
+ * \param buffer the Ethernet frame to send.
+ * \param length the Ethernet frame length.
+ * \param tag the tag for the classifier.
+ * \param arrrival_time_ntb arrival time in the High layers.
+ * \param dmac the destination mac address.
+ * \param smac the source mac address.
+ */
+static void
+cl_data_send_prepare (cl_t *ctx, u8 *buffer, uint length, uint tag,
+ u32 arrival_time_ntb, mac_t dmac, mac_t smac)
+{
+ /* The source MAC address should not be not be a multicast, a zero address
+ * nor a broadcast one (note that checking multicast address also checks
+ * for broadcast). Linux, in bridging mode, handle this problem and reject
+ * any of those packets (see net/bridge/br_input.c:127 (in
+ * br_handle_frame). */
+ dbg_claim (smac != MAC_ZERO);
+ dbg_claim (!mac_is_multicast (smac));
+ /* Add the source MAC address to the local bridge table if not our MAC
+ * address. */
+ dbg_claim (ctx->mac_config);
+ if (ctx->mac_config->sta_mac_address != smac)
+ bridge_table_add (ctx, smac);
+
+ /* Data are forbidden if not authenticated. */
+ if (!ctx->mac_config->authenticated)
+ {
+ CL_TRACE (DATA_SEND_DROP, phy_date (), ctx->mac_config->authenticated,
+ buffer, length);
+ bufmgr_give_back (ctx->bufmgr, buffer);
+ return;
+ }
+
+ /* Get the TEI from the mactotei table. */
+ uint tei;
+ uint group;
+ tei = cl_mactotei_table_find_tei_and_tag_from_mac (ctx, dmac, &group);
+ dbg_assert (tei != ctx->mac_config->tei);
+
+ if (tei == MAC_TEI_BCAST)
+ {
+ if (ctx->groups.nb_actual_members[group] > 1)
+ {
+ cl_send_multiunicast (ctx, buffer, length, 0, tag, arrival_time_ntb,
+ group);
+ return;
+ }
+ else
+ tei = ctx->groups.member_tei[group][0];
+ }
+
+ /* If the TEI is not found the packet is send as broadcast. */
+ cl_data_send_with_tei (ctx, buffer, length,
+ tei == MAC_TEI_UNASSOCIATED ? MAC_TEI_BCAST: tei,
+ tag, arrival_time_ntb, dmac, smac);
+}
+
+void
+cl_data_send (cl_t *ctx, u8 *buffer, uint length, uint tag,
+ u32 arrival_time_ntb)
+{
+ mac_t smac, dmac;
+ dbg_claim (ctx);
+ dbg_claim (buffer);
+ dbg_claim (length >= ETH_PACKET_MIN_SIZE_ALLOWED
+ && length <= ETH_PACKET_MAX_SIZE);
+ /* Check sequence number of throughput. */
+ lib_seq_check_packet (&ctx->seq_check_tx_ctx, buffer, length);
+ /* Get macs. */
+ bitstream_direct_read_macs (buffer, &dmac, &smac);
+ if (ctx->data_send_link.mfs
+ && ctx->data_send_link.mfs->fsm_state != MFS_FSM_CMD_RELEASE
+ && dmac == ctx->data_send_link.dmac
+ && smac == ctx->data_send_link.smac
+ && tag == ctx->data_send_link.tag
+ && ctx->mac_config->authenticated
+ && less_mod2p32 (arrival_time_ntb,
+ ctx->data_send_link.last_update_date_ntb
+ + MAC_MS_TO_TCK (CL_DATA_SEND_EXCEED_TIME_MS)))
+ {
+ CL_TRACE (DATA_SEND, phy_date (), buffer, length,
+ ctx->data_send_link.mfs->common.tei,
+ ctx->data_send_link.mfs->common.lid,
+ ctx->data_send_link.mfs->common.bcast);
+ sar_msdu_add (ctx->sar, buffer, length, ctx->data_send_link.mfs,
+ arrival_time_ntb);
+ /* update data rate informations associated to the TX
+ * from the local sta to the associated sta */
+ cl_compute_datarate_on_sta (
+ ctx, PARENT_OF (mfs_t, tx, ctx->data_send_link.mfs), length);
+ /* SAR ends using the buffer it can be given back.
+ * BRGDMA is polled by the SAR thats why it the buffer can be given
+ * back to the buffer manager. */
+ bufmgr_give_back (ctx->bufmgr, buffer);
+ }
+ else
+ {
+ /* Release the MFS's reference. */
+ if (ctx->data_send_link.mfs)
+ {
+ blk_release (ctx->data_send_link.mfs);
+ ctx->data_send_link.mfs = NULL;
+ }
+ cl_data_send_prepare (ctx, buffer, length, tag,
+ arrival_time_ntb, dmac, smac);
+ }
+}
+
+void
+cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei)
+{
+ dbg_claim (ctx);
+ dbg_claim (buffer);
+ dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
+ && length <= ETH_PACKET_MAX_SIZE);
+
+ /* Unicast or broadcast neighbour.
+ * Unicast is allowed even if the station is not associated.
+ * The broadcast is only allowed if the station is associated. */
+ if (((MAC_TEI_IS_STA (tei) || (tei == MAC_TEI_BCAST)))
+ && (MAC_TEI_IS_STA(ctx->mac_config->tei)))
+ {
+ mfs_tx_t *mfs;
+ bool added;
+ mfs = mac_store_mfs_add_tx (ctx->mac_store,
+ tei == MAC_TEI_BCAST ? true : false,
+ true /* mme */,
+ MAC_LID_NONE,
+ tei,
+ &added);
+
+ if (added)
+ sar_mfs_add (ctx->sar, (mfs_t *) mfs);
+ CL_TRACE (MME_SEND_UNICAST, phy_date (), length, buffer, tei);
+ sar_msdu_add (ctx->sar, buffer, length, mfs, mac_ntb ());
+ bufmgr_keep_buffer (ctx->bufmgr, buffer);
+ blk_release (mfs);
+ }
+ /* Handle the unassociated unicast with temporary MFS. */
+ else if (MAC_TEI_IS_STA (tei)
+ && (ctx->mac_config->tei == MAC_TEI_UNASSOCIATED))
+ {
+ mfs_tx_t *mfs;
+
+ mfs = &mac_store_mfs_unassociated_add (
+ ctx->mac_store, true /* tx */, false /* unicast */,
+ true /* mme */, MAC_LID_NONE, tei)->tx;
+
+ dbg_assert (ctx->sar);
+ sar_mfs_add (ctx->sar, (mfs_t *) mfs);
+
+ CL_TRACE (MME_SEND_UNASSOC_UNICAST, phy_date (), length, buffer,
+ mfs->common.tei);
+ sar_msdu_add (ctx->sar, buffer, length, mfs, mac_ntb());
+ bufmgr_keep_buffer (ctx->bufmgr, buffer);
+ blk_release (mfs);
+ }
+ /* It the destination TEI is broadcast and our station is not
+ * associated, disallow to send a broadcast packet as a multi unicast.*/
+ else if (tei == MAC_TEI_MULTI_UNICAST)
+ {
+ dbg_assert (ctx->mac_config->tei);
+ cl_send_multiunicast (ctx, buffer, length, true /* MME */, 1,
+ mac_ntb(), 0);
+ }
+ /* the destination is not associated or associated and our station
+ * can or not be associated */
+ else if ((tei == MAC_TEI_UNASSOCIATED) || (tei == MAC_TEI_BCAST))
+ {
+ mfs_tx_t *mfs;
+
+ mfs = &mac_store_mfs_unassociated_add (
+ ctx->mac_store, true /* tx */, true /* bcast */,
+ true /* mme */, MAC_LID_NONE, MAC_TEI_BCAST)->tx;
+
+ /* Quick hack to send the CC_ASSOC.CNF before the
+ * CC_SET_TEI_MAP.IND. */
+ mfs->cap = 3;
+
+ dbg_assert (ctx->sar);
+ sar_mfs_add (ctx->sar, (mfs_t *) mfs);
+
+ CL_TRACE (MME_SEND_TO_UNASSOC, phy_date (), length, buffer,
+ mfs->common.tei);
+ sar_msdu_add (ctx->sar, buffer, length, mfs, mac_ntb());
+ bufmgr_keep_buffer (ctx->bufmgr, buffer);
+ blk_release (mfs);
+ }
+ else
+ {
+ CL_TRACE (MME_SEND_TO_DRIVER, phy_date (), length, buffer);
+ cl_mbx_ipmbox_send (ctx->mbx, buffer, length);
+ }
+}
+
+void
+cl_lib_seq_check_tx_cb (void *user, uint vlan, uint seq_expected,
+ uint seq_actual)
+{
+ dbg_assert (user);
+ trace_do (cl_t *ctx = (cl_t *) user);
+ CL_TRACE (SEQ_CHECK_TX, vlan, seq_expected, seq_actual);
+}
diff --git a/cesar/cl/src/trace.c b/cesar/cl/src/trace.c
index 758caa7561..acf2cc28cb 100644
--- a/cesar/cl/src/trace.c
+++ b/cesar/cl/src/trace.c
@@ -52,7 +52,9 @@ cl_trace_init (cl_t *ctx)
TRACE_EVENT (CL_TRACE_DATA_RECV, "CL_DATA_RECV buffer @ : %x, destination : %m, source : %m, length : %d", TIMESTAMP),
TRACE_EVENT (CL_TRACE_DATA_BUFFER_ADD, "CL_DATA_BUFFER_ADD buffer @ : %x", TIMESTAMP),
TRACE_EVENT (CL_TRACE_BRIDGE_ADD, "Bridging MAC %m"),
- TRACE_EVENT (CL_TRACE_SEQ_CHECK, "[SeqCheck] input from PLC: "
+ TRACE_EVENT (CL_TRACE_SEQ_CHECK_RX, "[SeqCheck] input from PLC: "
+ "[%02d] expected=%04X, actual=%04X"),
+ TRACE_EVENT (CL_TRACE_SEQ_CHECK_TX, "[SeqCheck] input from Eth: "
"[%02d] expected=%04X, actual=%04X"),
};
dbg_assert (ctx);
diff --git a/cesar/cl/stub/src/cl.c b/cesar/cl/stub/src/cl.c
index a4dc8a2954..8ab2f215c8 100644
--- a/cesar/cl/stub/src/cl.c
+++ b/cesar/cl/stub/src/cl.c
@@ -17,124 +17,72 @@
#include "common/defs/igmp.h"
cl_t *
-cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config) __attribute__((weak));
-
-void
-cl_uninit (cl_t *ctx) __attribute__((weak));
-
-void
-cl_mme_ul_init_send_done (cl_t *ctx, cl_mme_ul_recv_done_cb_t cb,
- void *user) __attribute__((weak));
-
-void
-cl_mme_recv_init (cl_t *ctx, cl_mme_recv_cb_t mme_recv_cb, void *user) __attribute__((weak));
-
-void
-cl_mme_init_ul_as_data (cl_t *ctx, cl_mme_ul_send_done_cb_t cb, void *user) __attribute__((weak));
-
-void
-cl_mme_init_buffer_add_cb (cl_t *cl, cl_mme_buffer_add_cb_t cb,
- void *user_data) __attribute__((weak));
-
-void
-cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei) __attribute__((weak));
-
-void
-cl_mme_sar_send_done (cl_t *ctx, u8 *buffer, void *cl_data) __attribute__((weak));
-
-void
-cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs,
- bool encryption) __attribute__((weak));
-
-void
-cl_mme_recv_done (cl_t *ctx, u8 *buffer, bool mme_recv) __attribute__((weak));
-
-void
-cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user) __attribute__((weak));
-
-void
-cl_data_send_done (cl_t *ctx, u8 *buffer, void *cl_data) __attribute__((weak));
-
-void
-cl_data_send (cl_t *ctx, u8 *buffer, uint length, uint tag, u32 av_time) __attribute__((weak));
-
-void
-cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user) __attribute__((weak));
-
-void
-cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs) __attribute__((weak));
-
-void
-cl_mme_buffer_add (cl_t *cl, u8 *buffer) __attribute__((weak));
-
-void
-cl_data_buffer_add (cl_t *cl, u8 *buffer) __attribute__((weak));
-
+cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config,
+ ipmbox_t *ipmbox, bufmgr_t *bufmgr) __attribute__((weak));
cl_t *
-cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config)
+cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config,
+ ipmbox_t *ipmbox, bufmgr_t *bufmgr)
{
return NULL;
}
void
-cl_uninit (cl_t *ctx) {}
-
-void
-cl_mme_ul_init_send_done (cl_t *ctx, cl_mme_ul_recv_done_cb_t cb,
- void *user) {}
-
-void
-cl_mme_recv_init (cl_t *ctx, cl_mme_recv_cb_t mme_recv_cb, void *user) {}
-
-void
-cl_mme_init_ul_as_data (cl_t *ctx, cl_mme_ul_send_done_cb_t cb, void *user) {}
-
-void
-cl_mme_init_buffer_add_cb (cl_t *cl, cl_mme_buffer_add_cb_t cb,
- void *user_data) {}
+cl_uninit (cl_t *ctx) __attribute__((weak));
void
-cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei) {}
+cl_uninit (cl_t *ctx)
+{
+}
void
-cl_mme_sar_send_done (cl_t *ctx, u8 *buffer, void *cl_data) {}
+cl_data_send_link_clear (cl_t *ctx) __attribute__((weak));
void
-cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs,
- bool encryption) {}
+cl_data_send_link_clear (cl_t *ctx)
+{
+}
-void
-cl_mme_recv_done (cl_t *ctx, u8 *buffer, bool mme_recv) {}
+igmp_groups_t *
+cl_get_igmp_groups (cl_t *cl) __attribute__((weak));
-void
-cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user) {}
+igmp_groups_t *
+cl_get_igmp_groups (cl_t *cl)
+{
+ return NULL;
+}
void
-cl_data_send_done (cl_t *ctx, u8 *buffer, void *cl_data) {}
+cl_update_igmp_groups (cl_t *ctx) __attribute__((weak));
void
-cl_data_send (cl_t *ctx, u8 *buffer, uint length, uint tag, u32 av_time) {}
+cl_update_igmp_groups (cl_t *ctx)
+{
+}
void
-cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user) {}
+cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei)
+__attribute__((weak));
void
-cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs) {}
+cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei)
+{
+}
void
-cl_mme_buffer_add (cl_t *cl, u8 *buffer) {}
+cl_compute_datarate_on_sta (cl_t *ctx, mfs_t *mfs, uint length)
+__attribute__((weak));
void
-cl_data_buffer_add (cl_t *cl, u8 *buffer) {}
+cl_compute_datarate_on_sta (cl_t *ctx, mfs_t *mfs, uint length)
+{
+}
-void
-cl_update_igmp_groups (cl_t *cl)__attribute__((weak));
-void
-cl_update_igmp_groups (cl_t *cl) {}
+cl_mbx_t*
+cl_mbx_get (cl_t *ctx) __attribute__((weak));
-void
-cl_data_send_link_clear (cl_t *cl)__attribute__((weak));
-void
-cl_data_send_link_clear (cl_t *cl)
-{ }
+cl_mbx_t*
+cl_mbx_get (cl_t *ctx)
+{
+ return NULL;
+}
diff --git a/cesar/cl/test/bridge_table/Makefile b/cesar/cl/test/bridge_table/Makefile
index 57bb69919f..2a2de34cc1 100644
--- a/cesar/cl/test/bridge_table/Makefile
+++ b/cesar/cl/test/bridge_table/Makefile
@@ -3,7 +3,7 @@ BASE = ../../..
HOST_PROGRAMS = test_bridge_table
test_bridge_table_SOURCES = test_bridge_table.c
-test_bridge_table_MODULES = lib cl
+test_bridge_table_MODULES = lib cl hal/ipmbox/stub
# Overrides source of the cl module.
cl_MODULE_SOURCES = bridge_table.c
diff --git a/cesar/cl/test/data_rate/Makefile b/cesar/cl/test/data_rate/Makefile
index 5420f7fb4f..3156b1d874 100644
--- a/cesar/cl/test/data_rate/Makefile
+++ b/cesar/cl/test/data_rate/Makefile
@@ -6,7 +6,7 @@ INCLUDES = cl/test/data_rate/override
HOST_PROGRAMS = data_rate
data_rate_SOURCES = data_rate_test.c
-data_rate_MODULES = lib cl
+data_rate_MODULES = lib cl hal/ipmbox/stub
# Overrides source of the cl module.
cl_MODULE_SOURCES = data_rate.c
diff --git a/cesar/cl/test/functional/Makefile.mk b/cesar/cl/test/functional/Makefile.mk
new file mode 100644
index 0000000000..f9f0c6c89b
--- /dev/null
+++ b/cesar/cl/test/functional/Makefile.mk
@@ -0,0 +1,8 @@
+BASE = ../../..
+ECOS = y
+TARGET_PROGRAMS = cl
+cl_SOURCES = cl.c
+cl_MODULES = lib cl mac/common hal/arch \
+ mac/sar/stub bufmgr/stub hal/ipmbox/stub
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/cl/test/functional/host-Makefile b/cesar/cl/test/functional/host-Makefile
index 8368f15a8e..bd68478cff 100644
--- a/cesar/cl/test/functional/host-Makefile
+++ b/cesar/cl/test/functional/host-Makefile
@@ -1,12 +1,2 @@
-BASE = ../../..
-
-ECOS = y
VARIANT= host
-
-TARGET_PROGRAMS = cl
-
-cl_SOURCES = cl.c
-cl_MODULES = lib cl mac/common \
- mac/sar/stub
-
-include $(BASE)/common/make/top.mk
+include Makefile.mk
diff --git a/cesar/cl/test/functional/sparc-Makefile b/cesar/cl/test/functional/sparc-Makefile
index 702c58fcce..8d92a345d7 100644
--- a/cesar/cl/test/functional/sparc-Makefile
+++ b/cesar/cl/test/functional/sparc-Makefile
@@ -1,13 +1,3 @@
-BASE = ../../..
-
-ECOS = y
TARGET = sparc
VARIANT= sparc
-
-TARGET_PROGRAMS = cl
-
-cl_SOURCES = cl.c
-cl_MODULES = lib cl mac/common hal \
- mac/sar/stub
-
-include $(BASE)/common/make/top.mk
+include Makefile.mk
diff --git a/cesar/cl/test/functional/src/cl.c b/cesar/cl/test/functional/src/cl.c
index dd8bfd2628..8c679a6494 100644
--- a/cesar/cl/test/functional/src/cl.c
+++ b/cesar/cl/test/functional/src/cl.c
@@ -19,9 +19,13 @@
#include "mac/common/store.h"
#include "mac/common/ntb.h"
+#include "bufmgr/bufmgr.h"
+#include "hal/ipmbox/ipmbox.h"
#include "cl/cl.h"
#include "cl/cl_mactotei.h"
+#include "cl/inc/send.h"
+#include "cl/inc/receive.h"
#include <cyg/kernel/kapi.h>
#include <cyg/hal/hal_arch.h>
@@ -43,44 +47,13 @@ struct cl_test_t
mac_config_t mac_config;
/** MFS Sent. */
mfs_tx_t *mfs;
- /** Data receive callback test boolean */
- bool data_recv_cb;
- /** MME receive callback test boolean */
- bool mme_recv_cb;
- /** MME buffer add callback buffer pointer */
- u8 *cl_mme_buffer;
- /** DATA buffer add callback buffer pointer */
- u8 *cl_data_buffer;
+ /** Data transmitted? */
+ bool data_transmitted;
+ /** MME transmitted? */
+ bool mme_transmitted;
};
typedef struct cl_test_t cl_test_t;
-/* Callbacks. */
-void
-cl_data_send_done_cb (void *user, u8 *buffer)
-{
-}
-
-void
-cl_data_recv_cb (void *user, u8 *buffer, uint length)
-{
- cl_test_t *cl = (cl_test_t*) user;
- cl->data_recv_cb = true;
-}
-
-void
-cl_mme_recv_cb (void *user, u8 *buffer, uint length)
-{
- cl_test_t *cl = (cl_test_t*) user;
- cl->mme_recv_cb = true;
-}
-
-void
-cl_mme_buffer_add_cb (void *user_data, u8 *buffer)
-{
- cl_test_t *cl = (cl_test_t*) user_data;
- cl->cl_mme_buffer = buffer;
-}
-
/* TEST Functions */
void
cl_test_init (cl_test_t *test)
@@ -89,11 +62,8 @@ cl_test_init (cl_test_t *test)
test->mac_store = mac_store_init ();
mac_config_init (&test->mac_config);
mac_ntb_init (&test->mac_config);
- test->cl = cl_init (test->mac_store, (sar_t*) test, &test->mac_config);
- cl_data_send_done_init (test->cl, cl_data_send_done_cb, test);
- cl_data_recv_init (test->cl, cl_data_recv_cb, test);
- cl_mme_init_buffer_add_cb (test->cl, cl_mme_buffer_add_cb, test);
- cl_mme_init_ul_as_data (test->cl, cl_mme_recv_cb, test);
+ test->cl = cl_init (test->mac_store, (sar_t*) test, &test->mac_config,
+ (ipmbox_t*) test, INVALID_PTR);
}
void
@@ -173,35 +143,9 @@ cl_data_rx_recv (test_t test)
cl_test_t t;
cl_test_init (&t);
mfs_rx_init (&mfs, false, false, 1, 1);
- t.data_recv_cb = false;
- cl_data_recv (t.cl, buffer, 106, &mfs);
- test_fail_unless (t.data_recv_cb == true);
- cl_test_uninit (&t);
- }
- test_end;
-}
-
-void
-cl_buffers (test_t test)
-{
- test_case_begin (test, "CL buffers add");
- test_begin (test, "MME buffer")
- {
- cl_test_t t;
- cl_test_init (&t);
- t.cl_mme_buffer = NULL;
- cl_mme_buffer_add (t.cl, buffer);
- test_fail_unless (t.cl_mme_buffer == buffer);
- cl_test_uninit (&t);
- }
- test_end;
- test_begin (test, "Data buffer")
- {
- cl_test_t t;
- cl_test_init (&t);
- t.cl_data_buffer = NULL;
- cl_data_buffer_add (t.cl, buffer);
- test_fail_unless (t.cl_data_buffer == buffer);
+ t.data_transmitted = false;
+ cl_sar_data_recv (t.cl, buffer, 106, &mfs);
+ test_fail_unless (t.data_transmitted == true);
cl_test_uninit (&t);
}
test_end;
@@ -256,10 +200,10 @@ cl_mme_tx_send (test_t test)
bitstream_direct_write_large (buffer, 48, 0x123456789ABCull, 48);
t.mac_config.tei = 1;
t.mac_config.authenticated = true;
- /* Add the address to the mac_to_tei table. */
+ t.mme_transmitted = false;
cl_mme_send (t.cl, buffer, 106, MAC_TEI_FOREIGN);
test_fail_unless (t.mfs == NULL);
- test_fail_unless (t.mme_recv_cb == true);
+ test_fail_unless (t.mme_transmitted == true);
cl_test_uninit (&t);
}
test_end;
@@ -274,7 +218,6 @@ cyg_user_start (cyg_addrword_t addr)
cl_data_tx_send (test);
cl_data_rx_recv (test);
- cl_buffers (test);
cl_mme_tx_send (test);
test_case_begin (test, "Memory");
@@ -292,10 +235,9 @@ cyg_user_start (cyg_addrword_t addr)
}
/* Stubs. */
-
void
sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length,
- mfs_tx_t *mfs, void *user_data, u32 arrival_time_ntb)
+ mfs_tx_t *mfs, u32 arrival_time_ntb)
{
cl_test_t *t = (cl_test_t*) ctx;
dbg_assert (ctx);
@@ -303,8 +245,6 @@ sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length,
dbg_assert (buffer);
dbg_assert (length);
t->mfs = mfs;
- /* Simulate the end of the segmentation. */
- cl_data_send_done (t->cl, buffer, user_data);
}
@@ -315,14 +255,21 @@ sar_mfs_add (sar_t *ctx, mfs_t *mfs)
}
void
-sar_buffer_add (sar_t *ctx, u8 *buffer, bool data)
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length)
{
- cl_test_t *t = (cl_test_t*) ctx;
- dbg_assert (ctx);
- dbg_assert (buffer);
+ cl_test_t *t = (cl_test_t *) ctx;
+ t->data_transmitted = true;
+}
- if (data)
- t->cl_data_buffer = buffer;
- else
- t->cl_mme_buffer = buffer;
+void
+ipmbox_tx_mbx (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ cl_test_t *t = (cl_test_t *) ctx;
+ t->mme_transmitted = true;
+}
+
+void
+ipmbox_register_rx_cb (ipmbox_t *ctx, void *user_data,
+ ipmbox_rx_cb_t rx_cb_data, ipmbox_rx_cb_t rx_cb_mbx)
+{
}
diff --git a/cesar/cl/test/utest/Makefile b/cesar/cl/test/utest/Makefile
index c68a702408..53c607d8bb 100644
--- a/cesar/cl/test/utest/Makefile
+++ b/cesar/cl/test/utest/Makefile
@@ -1,10 +1,13 @@
BASE = ../../..
DEFS = -DNO_PRIVATE
-HOST_PROGRAMS = cl
+HOST_PROGRAMS = test_cl
-cl_SOURCES = cl.c test.c send.c receive.c misc.c brg_rx.c
-cl_MODULES = lib cl mac/common \
- mac/sar/stub
+test_cl_SOURCES = cl.c test.c send.c receive.c misc.c brg_rx.c \
+ hle_tools.c
+test_cl_MODULES = lib cl mac/common \
+ mac/sar/stub bufmgr/stub hal/ipmbox/stub hle/tools
+
+hle_tools_MODULE_SOURCES =
include $(BASE)/common/make/top.mk
diff --git a/cesar/cl/test/utest/src/brg_rx.c b/cesar/cl/test/utest/src/brg_rx.c
index 11a73ab49d..a32c81ed14 100644
--- a/cesar/cl/test/utest/src/brg_rx.c
+++ b/cesar/cl/test/utest/src/brg_rx.c
@@ -16,7 +16,6 @@
#include "mac/common/timings.h"
#include "cl/test/utest/test.h"
#include "cl/inc/context.h"
-#include "cl/inc/cl.h"
void
cl_test_brg_rx (test_t test)
diff --git a/cesar/cl/test/utest/src/hle_tools.c b/cesar/cl/test/utest/src/hle_tools.c
new file mode 100644
index 0000000000..d136b0780a
--- /dev/null
+++ b/cesar/cl/test/utest/src/hle_tools.c
@@ -0,0 +1,37 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/hle_tools.c
+ * \brief Stub hle tools.
+ * \ingroup cl
+ */
+#include "common/std.h"
+#include "hle/tools/tools.h"
+
+#include "cl/test/utest/test.h"
+#include "config/hle.h"
+
+hle_tools_t *
+hle_tools_init (ipmbox_t *ipmbox)
+{
+ static hle_tools_test_t hle_tools;
+ hle_tools.msg = NULL;
+ return (hle_tools_t *) &hle_tools;
+}
+
+void
+hle_tools_uninit (hle_tools_t *ctx)
+{
+}
+
+void
+hle_tools_msg_recv (hle_tools_t *ctx, const ipmbox_msg_mbx_t *msg)
+{
+ hle_tools_test_t *t = (hle_tools_test_t*) ctx;
+ t->msg = (ipmbox_msg_mbx_t*) msg;
+}
diff --git a/cesar/cl/test/utest/src/misc.c b/cesar/cl/test/utest/src/misc.c
index dda06ac235..0032ecaa73 100644
--- a/cesar/cl/test/utest/src/misc.c
+++ b/cesar/cl/test/utest/src/misc.c
@@ -15,7 +15,7 @@
#include "cl/test/utest/test.h"
#include "cl/cl_mactotei.h"
#include <stdio.h>
-#include "cl/inc/cl.h"
+#include "cl/inc/context.h"
uint
cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
diff --git a/cesar/cl/test/utest/src/receive.c b/cesar/cl/test/utest/src/receive.c
index 0706ab5462..a6478c96db 100644
--- a/cesar/cl/test/utest/src/receive.c
+++ b/cesar/cl/test/utest/src/receive.c
@@ -11,10 +11,30 @@
* \ingroup cl
*
*/
+#include <string.h>
+
#include "common/std.h"
#include "common/defs/ethernet.h"
+
+#include "common/ipmbox/msg.h"
+
#include "lib/test.h"
+
+#include "cl/cl_mactotei.h"
+
#include "cl/test/utest/test.h"
+#include "cl/inc/receive.h"
+#include "cl/mbx/mbx.h"
+
+void
+cl_sar_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs);
+
+void
+cl_sar_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs,
+ bool encryption);
+
+void
+cl_mbx_ipmbox_mbx_recv (cl_mbx_t *ctx, u32 *msg_buffer, uint nb_words);
void
test_cl__recv_from_sar (test_t test, cl_test_t *t, bool data, u8 *buffer,
@@ -28,27 +48,26 @@ test_cl__recv_from_sar (test_t test, cl_test_t *t, bool data, u8 *buffer,
mfs = mac_store_mfs_add_rx (t->mac_store, false, false,
1, 1, &added);
dbg_assert (added);
- cl_data_recv (t->cl, buffer, length, mfs);
+ cl_sar_data_recv (t->cl, buffer, length, mfs);
}
else
{
mfs = mac_store_mfs_add_rx (t->mac_store, false, true,
MAC_LID_NONE, 1, &added);
dbg_assert (added);
- cl_mme_sar_recv (t->cl, buffer, length, mfs, true);
+ cl_sar_mme_recv (t->cl, buffer, length, mfs, true);
+ test_fail_unless (t->pwl_recv.stei == 1);
+ test_fail_unless (t->pwl_recv.nek_enc == true);
}
- test_fail_unless (t->pwl_recv.stei == data ? 0: 1);
test_fail_unless (t->pwl_recv.buffer == buffer);
test_fail_unless (t->pwl_recv.length == length);
- test_fail_unless (t->pwl_recv.from_sar == true);
- test_fail_unless (t->pwl_recv.nek_enc == data ? false : true);
mac_store_mfs_remove (t->mac_store, PARENT_OF (mfs_t, rx, mfs));
dbg_check (mac_store_sta_remove (t->mac_store, 1));
blk_release (mfs);
}
void
-test_case__cl_mme_recv (test_t test)
+test_case__cl_sar_mme_recv (test_t test)
{
u8 buffer[ETH_PACKET_MAX_SIZE];
cl_test_t t;
@@ -62,21 +81,11 @@ test_case__cl_mme_recv (test_t test)
test_cl__recv_from_sar (test, &t, false, buffer, length);
}
test_end;
- test_begin (test, "From Upper Layer")
- {
- cl_mme_ul_send (t.cl, buffer, length);
- test_fail_unless (t.pwl_recv.stei == MAC_TEI_FOREIGN);
- test_fail_unless (t.pwl_recv.buffer == buffer);
- test_fail_unless (t.pwl_recv.length == length);
- test_fail_unless (t.pwl_recv.from_sar == false);
- test_fail_unless (t.pwl_recv.nek_enc == false);
- }
- test_end;
cl_test_uninit (&t);
}
void
-test_case__cl_data_recv (test_t test)
+test_case__cl_sar_data_recv (test_t test)
{
u8 buffer[ETH_PACKET_MAX_SIZE];
cl_test_t t;
@@ -94,10 +103,88 @@ test_case__cl_data_recv (test_t test)
}
void
+test_case__cl_ipmbox_data_recv (test_t test)
+{
+ u8 buffer[2][ETH_PACKET_MAX_SIZE];
+ cl_test_t t;
+ uint length[] = {500, 512};
+ uint tag[] = {0, 1};
+ uint lid[] = {1, 0};
+ mac_t dmac = 0x123456789abcull;
+ ipmbox_msg_mbx_t msg_buffer[2];
+ cl_test_init (&t, 0x9999432);
+ uint i;
+ for (i = 0; i < COUNT(buffer); i++)
+ {
+ cl_test_prepare_buffer (&t, buffer[i], length[i], dmac, tag[i]);
+ msg_buffer[i].header =
+ ipmbox_msg_create_header_data (length[i], tag[i]);
+ msg_buffer[i].buffer_addr = (u32) buffer[i];
+ }
+ memset (&t.sar, 0, sizeof (sar_test_t));
+ /* Add the dmac into the mac 2 tei table. */
+ cl_mactotei_blk_t *table = cl_mactotei_new ();
+ cl_mactotei_addr_add (table, dmac, 1, 1);
+ cl_mactotei_use_table (t.cl, table);
+ /* Run the test. */
+ test_case_begin (test, "Receive DATA");
+ test_begin (test, "From IPMBox")
+ {
+ cl_ipmbox_data_recv (t.cl, (u32 *) msg_buffer, 4);
+ test_fail_unless (t.sar.nb == 2);
+ for (i = 0; i < COUNT(buffer); i++)
+ {
+ test_fail_unless (t.sar.buffer[i] == buffer[i]);
+ test_fail_unless (t.sar.length[i] == length[i]);
+ test_fail_unless (t.sar.mfs[i]);
+ test_fail_unless (t.sar.mfs[i]->common.lid == lid[i]);
+ mac_store_mfs_remove (t.mac_store,
+ PARENT_OF (mfs_t, tx, t.sar.mfs[i]));
+ }
+ }
+ test_end;
+ /* Remove the station from the mac store. TEI is 1 as used int the mac2tei
+ * table entry, set above. */
+ dbg_check (mac_store_sta_remove (t.mac_store, 1));
+ cl_test_uninit (&t);
+}
+
+void
+test_case__cl_ipmbox_mbx_recv (test_t test)
+{
+ test_case_begin (test, "RECEIVE MBOX");
+ test_begin (test, "From IPMBox")
+ {
+ cl_test_t ctx;
+ cl_test_init (&ctx, 1646);
+ ipmbox_msg_mbx_t msgs[2];
+ msgs[0].header = ipmbox_msg_create_header_mme_priv (60);
+ msgs[0].buffer_addr = 0x42;
+ msgs[1].header = ipmbox_msg_create_header_debug_dump (61);
+ msgs[1].buffer_addr = 0x43;
+ cl_mbx_ipmbox_mbx_recv (ctx.mbx, (u32 *) msgs,
+ IPMBOX_MSG_MBX_WORDS * 2);
+ /* Check MME is sent to interface. */
+ test_fail_unless (ctx.pwl_recv.stei == MAC_TEI_FOREIGN);
+ test_fail_unless (ctx.pwl_recv.buffer == (u8 *) 0x42);
+ test_fail_unless (ctx.pwl_recv.length == 60);
+ test_fail_unless (ctx.pwl_recv.nek_enc == false);
+ /* Check debug dump is sent to hle tools. */
+ test_fail_unless (ctx.hle_tools->msg == &msgs[1]);
+ test_fail_unless (ctx.hle_tools->msg->header == msgs[1].header);
+ test_fail_unless (ctx.hle_tools->msg->buffer_addr == 0x43);
+ cl_test_uninit (&ctx);
+ }
+ test_end;
+}
+
+void
cl_test_suite_receive (test_t test)
{
test_suite_begin (test, "CL receive");
- test_case__cl_mme_recv (test);
- test_case__cl_data_recv (test);
+ test_case__cl_sar_mme_recv (test);
+ test_case__cl_sar_data_recv (test);
+ test_case__cl_ipmbox_data_recv (test);
+ test_case__cl_ipmbox_mbx_recv (test);
}
diff --git a/cesar/cl/test/utest/src/send.c b/cesar/cl/test/utest/src/send.c
index 48408675cf..d465f4ed3b 100644
--- a/cesar/cl/test/utest/src/send.c
+++ b/cesar/cl/test/utest/src/send.c
@@ -16,7 +16,7 @@
#include "mac/common/timings.h"
#include "cl/test/utest/test.h"
#include "cl/inc/context.h"
-#include "cl/inc/cl.h"
+#include "cl/inc/send.h"
uint
cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
@@ -25,7 +25,7 @@ cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
void
sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length,
- mfs_tx_t *mfs, void *user_data, u32 arrival_time_ntb)
+ mfs_tx_t *mfs, u32 arrival_time_ntb)
{
sar_test_t *t = (sar_test_t*) ctx;
dbg_assert (ctx);
@@ -35,8 +35,6 @@ sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length,
t->length[t->nb] = length;
t->mfs[t->nb] = mfs;
t->nb++;
- if (user_data)
- slab_release (user_data);
}
void
diff --git a/cesar/cl/test/utest/src/test.c b/cesar/cl/test/utest/src/test.c
index 57df690e01..7d97ef41cf 100644
--- a/cesar/cl/test/utest/src/test.c
+++ b/cesar/cl/test/utest/src/test.c
@@ -16,40 +16,32 @@
#include "cl/test/utest/test.h"
#include "cl/cl_mactotei.h"
#include "mac/common/ntb.h"
-
-static void
-cl_test_buffer_ul_add (void *user_data, u8 *buffer)
-{ }
+#include "common/ipmbox/msg.h"
+#include "hle/tools/tools.h"
+#include "cl/mbx/mbx.h"
+#include "cl/inc/context.h"
void
-cl_test_mme_ul_send_done_cb (void *ul_data, u8 *buffer, uint length)
-{ }
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ dbg_assert (ctx);
+ cl_test_recv_t *test_ctx = (cl_test_recv_t*) ctx;
+ test_ctx->buffer = (u8 *) first_msg[1];
+ test_ctx->length = ipmbox_msg_get_data_length (first_msg[0]);
+}
static void
cl_test_init_mme_recv_cp (void *user, uint tei, u8 *buffer, uint length,
- bool from_sar, bool encryption)
+ bool encryption)
{
cl_test_recv_t *ctx = (cl_test_recv_t*) user;
dbg_assert (user);
ctx->stei = tei;
ctx->buffer = buffer;
ctx->length = length;
- ctx->from_sar = from_sar;
ctx->nek_enc = encryption;
}
-static void
-cl_test_init_data_recv (void *user, u8 *buffer, uint length)
-{
- cl_test_recv_t *ctx = (cl_test_recv_t*) user;
- dbg_assert (user);
- ctx->stei = 0;
- ctx->buffer = buffer;
- ctx->length = length;
- ctx->from_sar = true;
- ctx->nek_enc = false;
-}
-
static int
cl_trace_buffer_dbg_dump_callback (void *user, const char *text,
uint text_size)
@@ -57,11 +49,6 @@ cl_trace_buffer_dbg_dump_callback (void *user, const char *text,
return 0;
}
-static void
-cl_data_send_done_cb (void *user, u8 *buffer)
-{
-}
-
void
cl_test_init (cl_test_t *ctx, u32 seed)
{
@@ -72,13 +59,14 @@ cl_test_init (cl_test_t *ctx, u32 seed)
ctx->mac_config.authenticated = true;
ctx->mac_config.tei = 0xfe;
ctx->mac_config.sta_mac_address = 0xfeffffd71300ull;
- ctx->cl = cl_init (ctx->mac_store, (sar_t*) &ctx->sar, &ctx->mac_config);
- cl_mme_init_buffer_add_cb (ctx->cl, cl_test_buffer_ul_add, INVALID_PTR);
- cl_mme_init_ul_as_data (ctx->cl, cl_test_mme_ul_send_done_cb,
- INVALID_PTR);
- cl_data_send_done_init (ctx->cl, cl_data_send_done_cb, ctx);
- cl_mme_recv_init (ctx->cl, cl_test_init_mme_recv_cp, &ctx->pwl_recv);
- cl_data_recv_init (ctx->cl, cl_test_init_data_recv, &ctx->pwl_recv);
+ ctx->cl = cl_init (ctx->mac_store, (sar_t*) &ctx->sar, &ctx->mac_config,
+ (ipmbox_t *) &ctx->pwl_recv, (bufmgr_t*) &ctx->bufmgr);
+ /* Done by cl_init, it is done to get the global hle_tools context
+ * address. */
+ ctx->hle_tools = (hle_tools_test_t *) hle_tools_init (INVALID_PTR);
+ ctx->mbx = ctx->cl->mbx;
+ cl_mbx_callback_register (ctx->mbx, cl_test_init_mme_recv_cp,
+ &ctx->pwl_recv);
lib_rnd_init (&ctx->rnd, seed);
}
diff --git a/cesar/cl/test/utest/test.h b/cesar/cl/test/utest/test.h
index 6e444d0faa..f20fd1ee0e 100644
--- a/cesar/cl/test/utest/test.h
+++ b/cesar/cl/test/utest/test.h
@@ -15,6 +15,8 @@
#include "cl/cl.h"
#include "lib/rnd.h"
+#include "common/ipmbox/msg.h"
+#include "cl/mbx/mbx.h"
#define TEST_BUFFER_MAX_NB 4
@@ -41,13 +43,17 @@ struct cl_test_recv_t
u8 *buffer;
/** length */
uint length;
- /** From SAR ? */
- bool from_sar;
/** NEK Encrypted ?*/
bool nek_enc;
};
typedef struct cl_test_recv_t cl_test_recv_t;
+struct hle_tools_test_t
+{
+ ipmbox_msg_mbx_t *msg;
+};
+typedef struct hle_tools_test_t hle_tools_test_t;
+
struct cl_test_t
{
/** CL context. */
@@ -62,6 +68,14 @@ struct cl_test_t
sar_test_t sar;
/** PWL receive MME or DATA. */
cl_test_recv_t pwl_recv;
+ /** Ipmbox context. */
+ void *ipmbox;
+ /** Buffer manager context. */
+ void *bufmgr;
+ /** Hle tools stubbed context. */
+ hle_tools_test_t *hle_tools;
+ /** Mbox context. */
+ cl_mbx_t *mbx;
};
typedef struct cl_test_t cl_test_t;
diff --git a/cesar/cp/cl_interf/cl_interf.h b/cesar/cp/cl_interf/cl_interf.h
index 084b86f462..e8ac46140a 100644
--- a/cesar/cp/cl_interf/cl_interf.h
+++ b/cesar/cp/cl_interf/cl_interf.h
@@ -71,15 +71,6 @@ void
cp_cl_interf_mme_send (cp_t *ctx, cp_mme_tx_t * mme);
/**
- * Add a buffer to the circular list.
- * \param ctx the module context.
- * \param buffer The buffer received.
- *
- */
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer);
-
-/**
* Remove all oldest MME received.
* \param ctx the module context.
*
diff --git a/cesar/cp/cl_interf/doc/cl-interf.xmi b/cesar/cp/cl_interf/doc/cl-interf.xmi
index c91ba065ad..bfa3e16ad3 100644
--- a/cesar/cp/cl_interf/doc/cl-interf.xmi
+++ b/cesar/cp/cl_interf/doc/cl-interf.xmi
@@ -100,7 +100,6 @@ Lock if until no buffers are available." isSpecification="false" isLeaf="false"
<UML:Attribute comment="The MME length." isSpecification="false" visibility="public" xmi.id="8JaeJ943Z31Y" type="YAORIYtJmMqR" name="length" />
<UML:Attribute comment="The MFS used to receive the MME from the PWL only, NULL if coming from the HLE." isSpecification="false" visibility="public" xmi.id="BmlhEa9J6S9Y" type="n5sZ4X1cfP1w" name="mfs" />
<UML:Attribute comment="Indicate if the MME was received as encrypted or not." isSpecification="false" visibility="public" xmi.id="PZFMGE6MXh0o" type="oLPdEMH2zWqt" name="hard_encrypt" />
- <UML:Attribute comment="Data used by the CL." isSpecification="false" visibility="public" xmi.id="jCCDbeeeRbPU" type="Lz9qKEoylkrp" name="cl_data" />
</UML:Classifier.feature>
</UML:Class>
<UML:Class isSpecification="false" isLeaf="false" visibility="public" namespace="Logical View" xmi.id="2eC8WeevFgVX" isRoot="false" isAbstract="false" name="cp_sta_reassembly_t" >
diff --git a/cesar/cp/cl_interf/inc/cl_interf.h b/cesar/cp/cl_interf/inc/cl_interf.h
index 78e27c8a38..88148c9cb3 100644
--- a/cesar/cp/cl_interf/inc/cl_interf.h
+++ b/cesar/cp/cl_interf/inc/cl_interf.h
@@ -44,7 +44,7 @@ cp_cl_interf_rx_mme_frag_result_t;
*/
void
cp_cl_interf_rx_mme (void *cp, cp_tei_t tei,
- u8 * buffer, uint length, bool cl_data,
+ u8 * buffer, uint length,
bool hardware_encrypt);
/**
diff --git a/cesar/cp/cl_interf/inc/cl_interf_msg.h b/cesar/cp/cl_interf/inc/cl_interf_msg.h
index 984c19b77a..9eb8d3fd3e 100644
--- a/cesar/cp/cl_interf/inc/cl_interf_msg.h
+++ b/cesar/cp/cl_interf/inc/cl_interf_msg.h
@@ -40,11 +40,6 @@ struct cp_cl_interf_msg_t
* Indicate if the MME was received as encrypted or not.
*/
bool hard_encrypt;
-
- /**
- * Data used by the CL.
- */
- bool cl_data;
};
typedef struct cp_cl_interf_msg_t cp_cl_interf_msg_t;
diff --git a/cesar/cp/cl_interf/inc/context.h b/cesar/cp/cl_interf/inc/context.h
index e498b5bea0..c5a5ba4db5 100644
--- a/cesar/cp/cl_interf/inc/context.h
+++ b/cesar/cp/cl_interf/inc/context.h
@@ -19,11 +19,6 @@
struct cp_cl_interf_t
{
/**
- * Buffers mailbox.
- */
- mbox_t buffers_mbox;
-
- /**
* The mailbox to insert the received messages.
*/
mbox_t mme_rx_mbox;
diff --git a/cesar/cp/cl_interf/src/cl_interf.c b/cesar/cp/cl_interf/src/cl_interf.c
index b6e7dff023..810466e4cd 100644
--- a/cesar/cp/cl_interf/src/cl_interf.c
+++ b/cesar/cp/cl_interf/src/cl_interf.c
@@ -16,6 +16,8 @@
#include "lib/blk.h"
+#include "mac/common/timings.h"
+
#include "cp/cp.h"
#include "cp/defs.h"
@@ -30,8 +32,8 @@
#include "cp/cl_interf/inc/cl_interf.h"
#include "cp/cl_interf/inc/cl_interf_msg.h"
-/** The time in eCos ticks to wait before continuing the process. */
-#define CP_CL_INTERF_MBOX_GET_WAIT_ECOS_TICKS 1
+/** The time in ms to wait before continuing the process. */
+#define CP_CL_INTERF_MBOX_GET_WAIT_MS 10
/**
* Initialise the module.
@@ -43,17 +45,12 @@ cp_cl_interf_init (cp_t *ctx)
{
dbg_assert (ctx);
- // Initialise the circular list.
- mbox_init (&ctx->cl_interf.buffers_mbox);
-
// Create the mailbox.
mbox_init(&ctx->cl_interf.mme_rx_mbox);
// Initialise the call backs.
interface_callback_init (ctx->interface,
cp_cl_interf_rx_mme,
- (interface_mme_buffer_add_cb_t)
- cp_cl_interf_add_buffer_tx,
ctx);
// Initialise the cache.
@@ -88,15 +85,6 @@ cp_cl_interf_uninit (cp_t *ctx)
// Delete the mailbox.
mbox_uninit (&ctx->cl_interf.mme_rx_mbox);
- while (mbox_peek (&ctx->cl_interf.buffers_mbox))
- {
- node = mbox_get (&ctx->cl_interf.buffers_mbox);
- /*TODO give it back to the linux driver. */
- }
-
- // Delete the mailbox.
- mbox_uninit (&ctx->cl_interf.buffers_mbox);
-
// Uninitialise the slab alloc.
slab_cache_uninit (&ctx->cl_interf.msg_slab);
}
@@ -153,7 +141,7 @@ cp_cl_interf_process_mme (cp_t *ctx)
msg = PARENT_OF (cp_cl_interf_msg_t, node, node);
mme = cp_msg_mme_read_header (
- ctx, msg->buffer, msg->length, msg->tei, &fmi, msg->cl_data);
+ ctx, msg->buffer, msg->length, msg->tei, &fmi);
CP_TRACE (CL_INTERF_PROCESS_MME, phy_date (), msg->buffer, msg->length,
msg->tei, fmi);
@@ -208,8 +196,10 @@ cp_cl_interf_process_mme (cp_t *ctx)
msg->buffer, msg->length,
fmi, msg->hard_encrypt);
- interface_mme_recv_done (ctx->interface, msg->buffer,
- msg->cl_data);
+ if (msg->tei == MAC_TEI_FOREIGN)
+ bufmgr_give_back (ctx->bufmgr, msg->buffer);
+ else
+ bufmgr_keep_buffer (ctx->bufmgr, msg->buffer);
mme->p_mme = NULL;
if (result == CP_CL_INTERF_RX_MME_FRAG_ENDED)
@@ -258,11 +248,15 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
u8 *buffer;
dbg_assert (ctx);
+ uint wait_rtc =
+ cp_sta_core_ms_to_cyg_tick (ctx, CP_CL_INTERF_MBOX_GET_WAIT_MS);
for (buffer = NULL; buffer == NULL;)
{
- buffer = (u8 *) mbox_timed_get (&ctx->cl_interf.buffers_mbox,
- CP_CL_INTERF_MBOX_GET_WAIT_ECOS_TICKS);
- cp_sta_core_checkpoint (ctx);
+ buffer = bufmgr_get_wait (ctx->bufmgr, wait_rtc);
+ if (buffer)
+ break;
+ else
+ cp_sta_core_checkpoint (ctx);
}
CP_TRACE (CL_INTERF_GET_BUFFER_TX, phy_date (), buffer);
@@ -289,22 +283,6 @@ cp_cl_interf_mme_send (cp_t *ctx, cp_mme_tx_t * mme)
}
/**
- * Add a buffer to the circular list.
- * \param ctx the module context.
- * \param buffer The buffer received.
- *
- */
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- mbox_put (&ctx->cl_interf.buffers_mbox, (mbox_node_t *) buffer);
- CP_TRACE (CL_INTERF_BUFFER_ADD, buffer);
-}
-
-/**
* Remove all oldest MME received.
* \param ctx the module context.
*
@@ -319,13 +297,11 @@ cp_cl_interf_garbage_collector (cp_t *ctx){}
* \param tei station's source TEI.
* \param buffer The MME buffer containing the MME.
* \param length The MME length.
- * \param cl-data The CL data.
* \param hardware_encrypt Indicate if the MME was Phy encrypted or not.
*
*/
void
-cp_cl_interf_rx_mme (void *cp, cp_tei_t tei,
- u8 * buffer, uint length, bool cl_data,
+cp_cl_interf_rx_mme (void *cp, cp_tei_t tei, u8 *buffer, uint length,
bool hardware_encrypt)
{
cp_cl_interf_msg_t *msg;
@@ -349,7 +325,6 @@ cp_cl_interf_rx_mme (void *cp, cp_tei_t tei,
msg->tei = tei;
msg->buffer = buffer;
msg->length = length;
- msg->cl_data = cl_data;
msg->hard_encrypt = hardware_encrypt;
CP_TRACE (CL_INTERF_MME_RX, phy_date (), buffer, length);
@@ -363,7 +338,8 @@ cp_cl_interf_rx_mme (void *cp, cp_tei_t tei,
/* The MME is not for this station. */
else
{
- interface_mme_recv_done (ctx->interface, buffer, cl_data);
+ /* Buffer is never from MAC_TEI_FOREIGN. */
+ bufmgr_keep_buffer (ctx->bufmgr, buffer);
CP_TRACE (CL_INTERF_MME_RX_DROP, phy_date (), buffer, length,
TRACE_U64 (mac));
}
diff --git a/cesar/cp/cl_interf/test/Makefile b/cesar/cp/cl_interf/test/Makefile
index 6ba1ed3365..237af7bfc7 100644
--- a/cesar/cp/cl_interf/test/Makefile
+++ b/cesar/cp/cl_interf/test/Makefile
@@ -8,6 +8,7 @@ test-cl-interf_SOURCES = test-cl-interf.c test.c
test-cl-interf_MODULES = lib cp/cl_interf cp/sta/mgr mac/common \
cp/secu cp/fsm/stub cp/cco/action/stub \
cp/sta/core/stub mac/sar/stub cl/stub \
- bsu/stub cp/msg/stub
+ bsu/stub cp/msg/stub hle/tools hal/ipmbox/stub \
+ bufmgr/stub cp/sta/core/stub
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp/cl_interf/test/override/cp/inc/context.h b/cesar/cp/cl_interf/test/override/cp/inc/context.h
index ba949c05d3..c22f6c513e 100644
--- a/cesar/cp/cl_interf/test/override/cp/inc/context.h
+++ b/cesar/cp/cl_interf/test/override/cp/inc/context.h
@@ -44,6 +44,7 @@ struct cp_t
sar_t *sar;
lib_rnd_t rnd;
void *bsu;
+ void *bufmgr;
};
#endif /* overide_cp_inc_context_h */
diff --git a/cesar/cp/cl_interf/test/src/test-cl-interf.c b/cesar/cp/cl_interf/test/src/test-cl-interf.c
index d22969127b..46c6a39274 100644
--- a/cesar/cp/cl_interf/test/src/test-cl-interf.c
+++ b/cesar/cp/cl_interf/test/src/test-cl-interf.c
@@ -39,9 +39,6 @@ test_case_cl_interf_init (test_t test)
cp_cl_interf_init (&cp);
test_begin (test, "verify")
{
- test_fail_if (mbox_peek (&cp.cl_interf.buffers_mbox) !=
- 0,
- "Wrong number of slots for the TX buffer list");
test_fail_if (mbox_peek (&cp.cl_interf.mme_rx_mbox) != 0,
"Wrong number of messages in the mailbox.");
}
@@ -53,13 +50,12 @@ void
test_case_cl_interf_receive_mme (test_t test)
{
u8 buffer[ETH_PACKET_MAX_SIZE];
- void *cl_data = INVALID_PTR;
cp_t cp;
test_case_begin (test, "Receive MME");
test_cl_interf_init (&cp);
bitstream_direct_write_large (buffer, 0, 0x123456789abcull, 48);
cp_sta_own_data_set_mac_address (&cp, 0x123456789abcull);
- cp_cl_interf_rx_mme (&cp, 23, buffer, 1200, cl_data, true);
+ cp_cl_interf_rx_mme (&cp, 23, buffer, 1200, true);
test_begin (test, "Verify.")
{
mbox_node_t *node = mbox_get (&cp.cl_interf.mme_rx_mbox);
@@ -98,7 +94,7 @@ test_case_cl_intef_process_mme_create_mme (cp_t *cp, cp_sta_t *sta,
bitstream_write (&stream, fmi_fmsn, 8);
bitstream_finalise (&stream);
cp_cl_interf_rx_mme (cp, cp_sta_get_tei (sta), buffer,
- ETH_PACKET_MAX_SIZE, NULL, true);
+ ETH_PACKET_MAX_SIZE, true);
}
void
@@ -219,24 +215,6 @@ test_case_cl_intef_process_mme (test_t test)
}
void
-test_case_cl_interf_add_and_get_tx_buffer (test_t test)
-{
- cp_t cp;
- u8 *mme;
- u8 buffer[ETH_PACKET_MAX_SIZE];
- test_case_begin (test, "Get a TX buffer");
- cp_cl_interf_init (&cp);
- cp_cl_interf_add_buffer_tx (&cp, buffer);
- mme = cp_cl_interf_get_buffer_tx (&cp);
- test_begin (test, "Verify")
- {
- test_fail_if (mme != buffer, "Buffer shall not be null");
- }
- test_end;
- cp_cl_interf_uninit (&cp);
-}
-
-void
test_case_cl_interf_send_mme (test_t test)
{
test_case_begin (test, "cl interf send");
@@ -273,7 +251,7 @@ test_case_cl_interf_mme_rx_update_sta_expired_date_run (
bitstream_write (&stream, 0, 4);
bitstream_finalise (&stream);
dispatch_mme_rx = NULL;
- cp_cl_interf_rx_mme (cp, 1, buffer, 60, INVALID_PTR, true);
+ cp_cl_interf_rx_mme (cp, 1, buffer, 60, true);
cp_cl_interf_process_mme (cp);
test_fail_unless (dispatch_mme_rx);
slab_release (dispatch_mme_rx);
@@ -351,7 +329,6 @@ main (int argc, char **argv)
test_case_cl_interf_init (test);
test_case_cl_interf_receive_mme (test);
test_case_cl_intef_process_mme (test);
- test_case_cl_interf_add_and_get_tx_buffer (test);
test_case_cl_interf_send_mme (test);
test_case_cl_interf_mme_rx_update_sta_expired_date (test);
@@ -370,13 +347,11 @@ main (int argc, char **argv)
* Initialise the callbacks functions.
* \param ctx the interface context.
* \param mme_recv_cb the function to call on reception of a MME.
- * \param buffer_add_cb the function to call on buffer reception.
- * \param beacon_add_cb the function to call on beacon reception
* \param user_data the data to provide on each callback function.
*/
void
interface_callback_init (interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb,
- interface_mme_buffer_add_cb_t buffer_add_cb, void *user_data)
+ void *user_data)
{
}
@@ -393,27 +368,15 @@ interface_mme_send (interface_t *ctx, u8* buffer, uint length, uint tei)
}
/**
- * Inform the Data plane when the MME as been processed by the CP.
- * \param ctx the interface context
- * \param mme_recv the cl data (as a void pointer).
- */
-void
-interface_mme_recv_done (interface_t *ctx, u8 *buffer, bool mme_recv)
-{
-}
-
-/**
* Function to init the mme rx t messages.
* \param ctx the module context.
* \param mme the MME received.
* \param length the MME length.
* \param tei the source TEI.
- * \param cl_data specific data provided by CL for the CL.
* \return the mme rx message initialised.
*/
cp_mme_rx_t *
-cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- bool cl_data)
+cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei)
{
cp_mme_rx_t *mme_rx;
@@ -431,7 +394,6 @@ cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
mme_rx->length = length;
mme_rx->peer.tei = tei;
mme_rx->cp = ctx;
- mme_rx->cl_data = cl_data;
return mme_rx;
}
@@ -447,7 +409,7 @@ cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
*/
cp_mme_rx_t *
cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- uint *fmi, bool cl_data)
+ uint *fmi)
{
cp_mme_rx_t *mme_rx;
bool vlantag_present;
@@ -462,7 +424,7 @@ cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
else
vlantag_present = true;
- mme_rx = cp_msg_mme_rx_init (ctx, mme, length, tei, cl_data);
+ mme_rx = cp_msg_mme_rx_init (ctx, mme, length, tei);
bitstream_init (&mme_rx->bitstream, mme + ETH_MAC_ADDRESS_SIZE,
length, BITSTREAM_READ);
diff --git a/cesar/cp/cp.h b/cesar/cp/cp.h
index d20fb5504d..8e58531d85 100644
--- a/cesar/cp/cp.h
+++ b/cesar/cp/cp.h
@@ -47,7 +47,7 @@ cp_t *
cp_init (bsu_t *bsu, bsu_aclf_t* aclf, mac_config_t * mac_config,
interface_t * interface, hal_timer_t *hal_timer, pbproc_t *pbproc,
mac_store_t *mac_store, sar_t *sar, cl_t *cl, ce_rx_t *ce_rx,
- u32 seed);
+ bufmgr_t *bufmgr, u32 seed);
/**
* Initialise the control plane context.
diff --git a/cesar/cp/doc/mme_tx.msc b/cesar/cp/doc/mme_tx.msc
index 02e22e555a..f2a7490a2f 100644
--- a/cesar/cp/doc/mme_tx.msc
+++ b/cesar/cp/doc/mme_tx.msc
@@ -13,7 +13,6 @@ cp_cl_interf << interface;
cp_msg << cp_cl_interf;
client << cp_msg;
... [label = "The message is sent to the dataplane for the Linux or the PLC"];
-interface -> cp_cl_interf [label = "cp_cl_interf_add_buffer_tx (ctx, buffer)"];
interface << cp_cl_interf;
... [label = "A new buffer to send the message is provided"];
}
diff --git a/cesar/cp/inc/context.h b/cesar/cp/inc/context.h
index 828bee4b9e..0c9d697dd7 100644
--- a/cesar/cp/inc/context.h
+++ b/cesar/cp/inc/context.h
@@ -39,6 +39,7 @@
#include "ce/rx/rx.h"
#include "bsu/beacon/beacon.h"
#include "bsu/aclf/aclf.h"
+#include "bufmgr/bufmgr.h"
/* Private interfaces. */
#include "cp/inc/trace.h"
@@ -167,6 +168,9 @@ struct cp_t
/** Context of the aclf. */
bsu_aclf_t *bsu_aclf;
+
+ /** Context of the buffer manager. */
+ bufmgr_t *bufmgr;
};
#endif /* cp_inc_cp_h */
diff --git a/cesar/cp/mme.h b/cesar/cp/mme.h
index 5db831e6f4..b8af81153c 100644
--- a/cesar/cp/mme.h
+++ b/cesar/cp/mme.h
@@ -408,8 +408,6 @@ struct cp_mme_rx_t
cp_secu_protocol_run_t prun;
/** Bitstream context. */
bitstream_t bitstream;
- /** Data used by the CL. */
- bool cl_data;
/** CP context used by the destructor of the MME_rx_t message. */
cp_t *cp;
/** IV or UUID. */
diff --git a/cesar/cp/msg/inc/msg.h b/cesar/cp/msg/inc/msg.h
index 5eabd44494..766e2244f8 100644
--- a/cesar/cp/msg/inc/msg.h
+++ b/cesar/cp/msg/inc/msg.h
@@ -23,12 +23,10 @@
* \param mme the MME received.
* \param length the MME length.
* \param tei the source TEI.
- * \param cl_data specific data provided by CL for the CL.
* \return the mme rx message initialised.
*/
cp_mme_rx_t *
-cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- bool cl_data);
+cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei);
/**
* Function to init the mme rx t messages.
diff --git a/cesar/cp/msg/msg.h b/cesar/cp/msg/msg.h
index 0cab91342e..433eb390ed 100644
--- a/cesar/cp/msg/msg.h
+++ b/cesar/cp/msg/msg.h
@@ -175,14 +175,13 @@ cp_msg_mme_read_header_initialised (cp_mme_rx_t *mme, uint *fmi,
* \param length the MME length.
* \param tei the source TEI (0xFF if coming from the HLE).
* \param fmi the FMI data.
- * \param cl_data the data provided by the CL for the CL.
* \return cp_mme_rx_t object associated.
*
* If the MME is not correct the MME will be dropped.
*/
cp_mme_rx_t *
cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- uint *fmi, bool cl_data);
+ uint *fmi);
/**
* Read an encrypted header and decrypt the payload.
diff --git a/cesar/cp/msg/src/mme.c b/cesar/cp/msg/src/mme.c
index 638b1c4b8a..a5743aac21 100644
--- a/cesar/cp/msg/src/mme.c
+++ b/cesar/cp/msg/src/mme.c
@@ -24,8 +24,7 @@
cp_mme_rx_t *
-cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- bool cl_data)
+cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei)
{
cp_mme_rx_t *mme_rx;
@@ -43,7 +42,6 @@ cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
mme_rx->peer.tei = tei;
mme_rx->cp = ctx;
mme_rx->peks = CP_MME_PEKS_SPC_NOT_EMBEDDED;
- mme_rx->cl_data = cl_data;
return mme_rx;
}
@@ -80,8 +78,10 @@ cp_msg_mme_rx_destructor (cp_mme_rx_t *mme)
if (mme->p_mme)
{
- interface_mme_recv_done (mme->cp->interface, mme->p_mme,
- mme->cl_data);
+ if (mme->peer.tei == MAC_TEI_FOREIGN)
+ bufmgr_give_back (mme->cp->bufmgr, mme->p_mme);
+ else
+ bufmgr_keep_buffer (mme->cp->bufmgr, mme->p_mme);
mme->p_mme = NULL;
}
@@ -104,6 +104,6 @@ cp_msg_mme_tx_destructor (cp_mme_tx_t *mme)
dbg_assert (mme);
if (mme->p_mme)
- cp_cl_interf_add_buffer_tx (mme->cp, mme->p_mme);
+ bufmgr_keep_buffer (mme->cp->bufmgr, mme->p_mme);
}
diff --git a/cesar/cp/msg/src/msg.c b/cesar/cp/msg/src/msg.c
index 5d32afdff5..043d109b89 100644
--- a/cesar/cp/msg/src/msg.c
+++ b/cesar/cp/msg/src/msg.c
@@ -1106,7 +1106,7 @@ cp_msg_mme_read_header_initialised (cp_mme_rx_t *mme, uint *fmi,
cp_mme_rx_t *
cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- uint *fmi, bool cl_data)
+ uint *fmi)
{
cp_mme_rx_t *mme_rx;
bool vlantag_present;
@@ -1124,7 +1124,7 @@ cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
if (length >= (vlantag_present ? HPAV_MME_HEADER_LEN_WITH_VLAN :
HPAV_MME_HEADER))
{
- mme_rx = cp_msg_mme_rx_init (ctx, mme, length, tei, cl_data);
+ mme_rx = cp_msg_mme_rx_init (ctx, mme, length, tei);
bitstream_init (&mme_rx->bitstream, mme + ETH_MAC_ADDRESS_SIZE,
length - ETH_MAC_ADDRESS_SIZE, BITSTREAM_READ);
diff --git a/cesar/cp/msg/stub/src/msg.c b/cesar/cp/msg/stub/src/msg.c
index 41c9c687e3..c8e34093f8 100644
--- a/cesar/cp/msg/stub/src/msg.c
+++ b/cesar/cp/msg/stub/src/msg.c
@@ -86,11 +86,11 @@ cp_msg_mme_send (cp_t *ctx, cp_mme_tx_t *mme) {}
cp_mme_rx_t *
cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- uint *fmi, bool cl_data) __attribute__((weak));
+ uint *fmi) __attribute__((weak));
cp_mme_rx_t *
cp_msg_mme_read_header (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei,
- uint *fmi, bool cl_data)
+ uint *fmi)
{
return NULL;
}
diff --git a/cesar/cp/msg/test/Makefile b/cesar/cp/msg/test/Makefile
index e17ad4959c..f46fcdca1a 100644
--- a/cesar/cp/msg/test/Makefile
+++ b/cesar/cp/msg/test/Makefile
@@ -8,59 +8,59 @@ HOST_PROGRAMS = test-msg-read-header test-msg-cc test-msg-cm \
test_drv_msg test_cc_discover_list test_frag_mme \
relay test_vs_msg test_allowed_mme msg
-test-msg-read-header_SOURCES = test-msg-read-header.c interface_stub.c \
+test-msg-read-header_SOURCES = test-msg-read-header.c \
cp_cl_interface_stub.c misc_stub.c
test-msg-read-header_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr \
cp/fsm/stub cp/sta/core/stub cp/cco/action/stub \
- mac/sar/stub cl/stub bsu/stub
+ mac/sar/stub cl/stub bsu/stub bufmgr/stub
-test-msg-cc_SOURCES = msg_cc.c interface_stub.c misc_stub.c
+test-msg-cc_SOURCES = msg_cc.c misc_stub.c
test-msg-cc_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr cp/fsm/stub \
cp/sta/core/stub cp/cco/action/stub mac/sar/stub \
- cl/stub bsu/stub
+ cl/stub bsu/stub bufmgr/stub
-test-msg-cm_SOURCES = msg_cm.c interface_stub.c misc_stub.c
+test-msg-cm_SOURCES = msg_cm.c misc_stub.c
test-msg-cm_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr cp/fsm/stub \
cp/sta/core/stub cp/cco/action/stub mac/sar/stub \
- cl/stub bsu/stub
+ cl/stub bsu/stub bufmgr/stub
-test_frag_mme_SOURCES = mme_frag.c interface_stub.c misc_stub.c
+test_frag_mme_SOURCES = mme_frag.c misc_stub.c
test_frag_mme_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr \
cp/fsm/stub cp/sta/core/stub cp/cco/action/stub \
- mac/sar/stub cl/stub bsu/stub
+ mac/sar/stub cl/stub bsu/stub bufmgr/stub
-test_drv_msg_SOURCES = msg_drv.c interface_stub.c \
+test_drv_msg_SOURCES = msg_drv.c \
cp_cl_interface_stub.c misc_stub.c
test_drv_msg_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr cp/fsm/stub \
cp/sta/core/stub cp/cco/action/stub mac/sar/stub \
- cl/stub bsu/stub
+ cl/stub bsu/stub bufmgr/stub
-test_cc_discover_list_SOURCES = cc_discover_list.c interface_stub.c misc_stub.c
+test_cc_discover_list_SOURCES = cc_discover_list.c misc_stub.c
test_cc_discover_list_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr \
cp/fsm/stub cp/sta/core/stub cp/cco/action/stub \
- cl/stub bsu/stub mac/sar/stub
+ cl/stub bsu/stub mac/sar/stub bufmgr/stub
-relay_SOURCES = relay.c interface_stub.c misc_stub.c
+relay_SOURCES = relay.c misc_stub.c
relay_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr \
cp/fsm/stub cp/sta/core/stub cp/cco/action/stub \
- cl/stub bsu/stub mac/sar/stub
+ cl/stub bsu/stub mac/sar/stub bufmgr/stub
-test_vs_msg_SOURCES = msg_vs.c interface_stub.c misc_stub.c \
+test_vs_msg_SOURCES = msg_vs.c misc_stub.c \
mac_sar_interface_stub.c cp_cl_interface_vs_stub.c
test_vs_msg_MODULES = lib cp/msg cp/secu mac/common cp/sta/mgr \
cp/fsm/stub cp/sta/core/stub cp/cco/action/stub \
- cl/stub bsu/stub mac/sar/stub
+ cl/stub bsu/stub mac/sar/stub bufmgr/stub
-test_allowed_mme_SOURCES = test_msg_allowed_mme.c interface_stub.c \
+test_allowed_mme_SOURCES = test_msg_allowed_mme.c \
cp_cl_interface_stub.c misc_stub.c
test_allowed_mme_MODULES = lib cp/msg cp/sta/mgr cp/sta/core/stub \
cp/fsm/stub cp/secu mac/common mac/sar/stub \
- cp/cco/action/stub cl/stub bsu/stub
+ cp/cco/action/stub cl/stub bsu/stub bufmgr/stub
-msg_SOURCES = msg.c interface_stub.c cp_cl_interface_stub.c misc_stub.c
+msg_SOURCES = msg.c cp_cl_interface_stub.c misc_stub.c
msg_MODULES = lib cp/msg cp/sta/mgr \
cp/sta/core/stub \
cp/fsm/stub cp/secu mac/common mac/sar/stub \
- cp/cco/action/stub cl/stub bsu/stub
+ cp/cco/action/stub cl/stub bsu/stub bufmgr/stub
include $(BASE)/common/make/top.mk
diff --git a/cesar/cp/msg/test/overide/cp/inc/context.h b/cesar/cp/msg/test/overide/cp/inc/context.h
index 480019b7f4..250877009e 100644
--- a/cesar/cp/msg/test/overide/cp/inc/context.h
+++ b/cesar/cp/msg/test/overide/cp/inc/context.h
@@ -27,6 +27,7 @@
#include "mac/common/config.h"
#include "mac/common/store.h"
#include "bsu/aclf/aclf.h"
+#include "bufmgr/bufmgr.h"
struct cp_t
{
@@ -59,6 +60,9 @@ struct cp_t
/** SAR context. */
sar_t *sar;
+
+ /** Buffer manager context. */
+ bufmgr_t *bufmgr;
};
#endif /* overide_cp_inc_context_h */
diff --git a/cesar/cp/msg/test/src/cc_discover_list.c b/cesar/cp/msg/test/src/cc_discover_list.c
index 6268082da5..603f669f95 100644
--- a/cesar/cp/msg/test/src/cc_discover_list.c
+++ b/cesar/cp/msg/test/src/cc_discover_list.c
@@ -673,11 +673,6 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
return the_buffer;
}
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer)
-{
-}
-
/**
* Send a MME over the PWL or the HLE.
* \param ctx the module context.
diff --git a/cesar/cp/msg/test/src/cp_cl_interface_stub.c b/cesar/cp/msg/test/src/cp_cl_interface_stub.c
index 52a5333246..7b8643aae0 100644
--- a/cesar/cp/msg/test/src/cp_cl_interface_stub.c
+++ b/cesar/cp/msg/test/src/cp_cl_interface_stub.c
@@ -26,11 +26,6 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
return buffer;
}
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer)
-{
-}
-
/**
* Send a MME over the PWL or the HLE.
* \param ctx the module context.
diff --git a/cesar/cp/msg/test/src/interface_stub.c b/cesar/cp/msg/test/src/interface_stub.c
deleted file mode 100644
index 68d5683537..0000000000
--- a/cesar/cp/msg/test/src/interface_stub.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file src/interface_stub.c
- * \brief « brief description »
- * \ingroup « module »
- *
- * « long description »
- */
-#include "common/std.h"
-
-#include "cp/cp.h"
-
-/**
- * Inform the Data plane when the MME as been processed by the CP.
- * \param ctx the interface context
- * \param mme_recv the cl data (as a void pointer).
- */
-void
-interface_mme_recv_done (interface_t *ctx, void *mme_recv)
-{
-}
diff --git a/cesar/cp/msg/test/src/mme_frag.c b/cesar/cp/msg/test/src/mme_frag.c
index 4379f5f800..83710c465f 100644
--- a/cesar/cp/msg/test/src/mme_frag.c
+++ b/cesar/cp/msg/test/src/mme_frag.c
@@ -313,11 +313,6 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
return buffer;
}
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer)
-{
-}
-
/**
* Send a MME over the PWL or the HLE.
* \param ctx the module context.
diff --git a/cesar/cp/msg/test/src/msg.c b/cesar/cp/msg/test/src/msg.c
index 265699ce27..99671088e4 100644
--- a/cesar/cp/msg/test/src/msg.c
+++ b/cesar/cp/msg/test/src/msg.c
@@ -75,7 +75,7 @@ test_case_msg_dispatch (test_t test)
/* process the test. */
cp_sta_own_data_set_mac_address (&cp, 1);
mme = cp_msg_mme_read_header (&cp, buffer, 75, MAC_TEI_UNASSOCIATED,
- &fmi, false);
+ &fmi);
fsm_post = false;
cp_msg_dispatch (&cp, mme);
@@ -121,7 +121,7 @@ test_case_msg_dispatch (test_t test)
/* process the test. */
cp_sta_own_data_set_mac_address (&cp, 1);
mme = cp_msg_mme_read_header (&cp, buffer, 75, MAC_TEI_UNASSOCIATED,
- &fmi, false);
+ &fmi);
fsm_post = false;
cp_msg_dispatch (&cp, mme);
@@ -171,7 +171,7 @@ test_case_msg_dispatch (test_t test)
/* process the test. */
cp_sta_own_data_set_mac_address (&cp, 1);
mme = cp_msg_mme_read_header (&cp, buffer, 75, MAC_TEI_UNASSOCIATED,
- &fmi, false);
+ &fmi);
fsm_post = false;
cp_msg_dispatch (&cp, mme);
@@ -221,7 +221,7 @@ test_case_msg_dispatch (test_t test)
/* process the test. */
cp_sta_own_data_set_mac_address (&cp, 1);
mme = cp_msg_mme_read_header (&cp, buffer, 75, MAC_TEI_UNASSOCIATED,
- &fmi, false);
+ &fmi);
fsm_post = false;
cp_msg_dispatch (&cp, mme);
@@ -263,7 +263,7 @@ test_case_msg_dispatch (test_t test)
/* process the test. */
cp_sta_own_data_set_mac_address (&cp, 1);
mme = cp_msg_mme_read_header (&cp, buffer, 60, MAC_TEI_UNASSOCIATED,
- &fmi, false);
+ &fmi);
fsm_post = false;
cp_msg_dispatch (&cp, mme);
@@ -300,7 +300,7 @@ test_case_msg_dispatch (test_t test)
/* process the test. */
cp_sta_own_data_set_mac_address (&cp, 1);
mme = cp_msg_mme_read_header (&cp, buffer, 60, MAC_TEI_UNASSOCIATED,
- &fmi, false);
+ &fmi);
fsm_post = false;
cp_msg_dispatch (&cp, mme);
diff --git a/cesar/cp/msg/test/src/msg_cc.c b/cesar/cp/msg/test/src/msg_cc.c
index c0a381e79f..b4d4ec8a7b 100644
--- a/cesar/cp/msg/test/src/msg_cc.c
+++ b/cesar/cp/msg/test/src/msg_cc.c
@@ -156,8 +156,7 @@ test_case_msg_cc_who_ru (test_t test)
test_case_begin (test, "CC_WHO_RU.REQ : Receive");
test_begin (test, "Verify")
{
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_who_ru_req_receive (&cp, mme, &data);
test_fail_unless (res == true);
@@ -172,8 +171,7 @@ test_case_msg_cc_who_ru (test_t test)
{
bitstream_direct_write_large (buffer, 19*8, nid << 2, 56);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xa, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xa, (uint*) &data);
res = cp_msg_cc_who_ru_req_receive (&cp, mme, &data);
test_fail_unless (res == false);
@@ -184,8 +182,7 @@ test_case_msg_cc_who_ru (test_t test)
test_begin (test, "who ru no more bits available.")
{
- mme = cp_msg_mme_read_header (&cp, buffer, 19, 0xa, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 19, 0xa, (uint*) &data);
res = cp_msg_cc_who_ru_req_receive (&cp, mme, &data);
test_fail_unless (res == false);
@@ -229,8 +226,7 @@ test_case_msg_cc_who_ru (test_t test)
cp_sta_own_data_set_cco_status (&cp, true);
memset (&cnf, 0, sizeof (cp_msg_cc_who_ru_cnf_t));
- mme = cp_msg_mme_read_header (&cp, buffer, 96, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 96, 0xA, (uint*) &data);
res = cp_msg_cc_who_ru_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == true);
@@ -249,8 +245,7 @@ test_case_msg_cc_who_ru (test_t test)
memset (&cnf, 0, sizeof (cp_msg_cc_who_ru_cnf_t));
bitstream_direct_write_large (buffer, 19*8, nid << 2, 56);
- mme = cp_msg_mme_read_header (&cp, buffer, 96, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 96, 0xA, (uint*) &data);
res = cp_msg_cc_who_ru_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == false);
test_fail_unless (mme->mmtype == CC_WHO_RU_CNF);
@@ -268,8 +263,7 @@ test_case_msg_cc_who_ru (test_t test)
memset (&cnf, 0, sizeof (cp_msg_cc_who_ru_cnf_t));
bitstream_direct_write_large (buffer, 26*8, MAC_ZERO, 48);
- mme = cp_msg_mme_read_header (&cp, buffer, 120, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 120, 0xA, (uint*) &data);
res = cp_msg_cc_who_ru_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == false);
test_fail_unless (mme->mmtype == CC_WHO_RU_CNF);
@@ -286,8 +280,7 @@ test_case_msg_cc_who_ru (test_t test)
memset (&cnf, 0, sizeof (cp_msg_cc_who_ru_cnf_t));
bitstream_direct_write (buffer, 40*8, 128, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 120, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 120, 0xA, (uint*) &data);
res = cp_msg_cc_who_ru_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == false);
test_fail_unless (mme->mmtype == CC_WHO_RU_CNF);
@@ -377,8 +370,7 @@ test_case_msg_cc_assoc (test_t test)
test_begin (test, "Verify")
{
memset (&req, 0, sizeof (cp_msg_cc_assoc_req_t));
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_req_receive (&cp, mme, &req);
test_fail_unless (res == true);
@@ -396,8 +388,7 @@ test_case_msg_cc_assoc (test_t test)
memset (&req, 0, sizeof (cp_msg_cc_assoc_req_t));
bitstream_direct_write (buffer, 19*8, CP_MSG_CC_ASSOC_REQ_TYPE_NB, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_req_receive (&cp, mme, &req);
test_fail_unless (res == false);
@@ -417,8 +408,7 @@ test_case_msg_cc_assoc (test_t test)
memset (&req, 0, sizeof (cp_msg_cc_assoc_req_t));
bitstream_direct_write_large (buffer, 20*8, nid << 2, 56);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_req_receive (&cp, mme, &req);
test_fail_unless (res == false);
@@ -438,8 +428,7 @@ test_case_msg_cc_assoc (test_t test)
memset (&req, 0, sizeof (cp_msg_cc_assoc_req_t));
bitstream_direct_write (buffer, 27*8, CP_CCO_LEVEL_MAX + 1, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_req_receive (&cp, mme, &req);
test_fail_unless (res == false);
@@ -459,8 +448,7 @@ test_case_msg_cc_assoc (test_t test)
memset (&req, 0, sizeof (cp_msg_cc_assoc_req_t));
bitstream_direct_write (buffer, 28*8, CP_PCO_CAP_MAX + 1, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_req_receive (&cp, mme, &req);
test_fail_unless (res == false);
@@ -516,8 +504,7 @@ test_case_msg_cc_assoc (test_t test)
test_begin (test, "Verify")
{
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == true);
@@ -536,8 +523,7 @@ test_case_msg_cc_assoc (test_t test)
{
bitstream_direct_write (buffer, 19*8, CP_MSG_CC_ASSOC_CNF_RESULT_NB, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == false);
@@ -559,8 +545,7 @@ test_case_msg_cc_assoc (test_t test)
{
bitstream_direct_write_large (buffer, 20*8, nid << 2, 56);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == false);
@@ -580,8 +565,7 @@ test_case_msg_cc_assoc (test_t test)
{
bitstream_direct_write (buffer, 28*8, MAC_TEI_UNASSOCIATED, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == false);
@@ -601,8 +585,7 @@ test_case_msg_cc_assoc (test_t test)
{
bitstream_direct_write (buffer, 29*8, 0, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_assoc_cnf_receive (&cp, mme, &cnf);
test_fail_unless (res == false);
@@ -681,8 +664,7 @@ test_case_msg_cc_leave (test_t test)
test_begin (test, "Verify")
{
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_leave_req_receive (&cp, mme, &reason);
test_fail_unless (res == true);
@@ -698,8 +680,7 @@ test_case_msg_cc_leave (test_t test)
{
bitstream_direct_write (buffer, 19*8, CP_MSG_CC_LEAVE_REQ_REASON_NB,
8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_leave_req_receive (&cp, mme, &reason);
test_fail_unless (res == false);
@@ -735,8 +716,7 @@ test_case_msg_cc_leave (test_t test)
test_begin (test, "Verify")
{
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_leave_ind_receive (&cp, mme, &reason, &nid);
test_fail_unless (res == true);
@@ -750,8 +730,7 @@ test_case_msg_cc_leave (test_t test)
test_begin (test, "Wrong reason")
{
bitstream_direct_write (buffer, 19*8, CP_MSG_CC_LEAVE_IND_REASON_NB, 8);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_leave_ind_receive (&cp, mme, &reason, &nid);
test_fail_unless (res == false);
@@ -768,8 +747,7 @@ test_case_msg_cc_leave (test_t test)
test_begin (test, "Wrong nid")
{
bitstream_direct_write_large (buffer, 20*8, nid << 2, 56);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_leave_ind_receive (&cp, mme, &reason, &nid);
test_fail_unless (res == false);
@@ -872,8 +850,7 @@ test_case_msg_cc_set_tei_map (test_t test)
test_begin (test, "Verify")
{
bool res;
- mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_set_tei_map_ind_receive_begin (&cp, mme_rx, &mode,
&nb_sta);
test_fail_unless (res == true);
@@ -906,8 +883,7 @@ test_case_msg_cc_set_tei_map (test_t test)
bitstream_direct_write (buffer, 19*8,
CP_MSG_CC_SET_TEI_MAP_IND_MODE_NB, 8);
- mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_set_tei_map_ind_receive_begin (&cp, mme_rx, &mode,
&nb_sta);
test_fail_unless (res == false);
@@ -927,8 +903,7 @@ test_case_msg_cc_set_tei_map (test_t test)
bitstream_direct_write (buffer, 21*8, MAC_TEI_UNASSOCIATED, 8);
- mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_set_tei_map_ind_receive_begin (&cp, mme_rx, &mode,
&nb_sta);
test_fail_unless (res == true);
@@ -960,8 +935,7 @@ test_case_msg_cc_set_tei_map (test_t test)
bitstream_direct_write_large (buffer, 22*8, MAC_ZERO, 48);
- mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_set_tei_map_ind_receive_begin (&cp, mme_rx, &mode,
&nb_sta);
test_fail_unless (res == true);
@@ -994,8 +968,7 @@ test_case_msg_cc_set_tei_map (test_t test)
bitstream_direct_write (buffer, 28*8,
CP_MSG_CC_SET_TEI_MAP_IND_STATUS_NB, 8);
- mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data,
- false);
+ mme_rx = cp_msg_mme_read_header (&cp, buffer, 60, 0xA, (uint*) &data);
res = cp_msg_cc_set_tei_map_ind_receive_begin (&cp, mme_rx, &mode,
&nb_sta);
test_fail_unless (res == true);
@@ -1082,7 +1055,7 @@ test_case_msg_cc_handover (test_t test)
test_fail_unless (data == CP_MSG_CC_HANDOVER_REQ_REASON_CCO_SELECTION);
bitstream_finalise (&stream);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi);
test_fail_unless (mme->mmtype == CC_HANDOVER_REQ);
data = cp_msg_cc_handover_req_receive (&cp, mme, &soft_hard, &reason);
slab_release (mme);
@@ -1116,14 +1089,14 @@ test_case_msg_cc_handover (test_t test)
buffer[19] = 0x2;
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi);
data = cp_msg_cc_handover_req_receive (&cp, mme, &soft_hard, &reason);
test_fail_unless (data == false);
slab_release (mme);
buffer[19] = 0x1;
buffer[20] = 0x3;
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi);
data = cp_msg_cc_handover_req_receive (&cp, mme, &soft_hard, &reason);
test_fail_unless (data == false);
slab_release (mme);
@@ -1182,7 +1155,7 @@ test_case_msg_cc_handover (test_t test)
test_fail_unless (data == CP_MSG_CC_HANDOVER_CNF_RESULT_ACCEPT);
bitstream_finalise (&stream);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi);
test_fail_unless (mme->mmtype == CC_HANDOVER_CNF);
cp_msg_cc_handover_cnf_receive (&cp, mme, &result);
slab_release (mme);
@@ -1202,7 +1175,7 @@ test_case_msg_cc_handover (test_t test)
dbg_fatal_try_end;
buffer[19] = 3;
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi);
data = cp_msg_cc_handover_cnf_receive (&cp, mme, &result);
slab_release (mme);
@@ -1313,7 +1286,7 @@ test_case_msg_cc_handover (test_t test)
}
bitstream_finalise (&stream);
- mme_rx = cp_msg_mme_read_header (&cp, buffer, 1518, 1, &fmi, false);
+ mme_rx = cp_msg_mme_read_header (&cp, buffer, 1518, 1, &fmi);
test_fail_unless (mme_rx->mmtype == CC_HANDOVER_INFO_IND);
data = cp_msg_cc_handover_info_ind_receive_begin (&cp, mme_rx,
@@ -1343,7 +1316,7 @@ test_case_msg_cc_handover (test_t test)
/* Try corrupted values. */
/* Change the TEI to 0. */
bitstream_direct_write (buffer, 176, 0, 8);
- mme_rx = cp_msg_mme_read_header (&cp, buffer, 1518, 1, &fmi, false);
+ mme_rx = cp_msg_mme_read_header (&cp, buffer, 1518, 1, &fmi);
test_fail_unless (mme_rx->mmtype == CC_HANDOVER_INFO_IND);
data = cp_msg_cc_handover_info_ind_receive_begin (&cp, mme_rx,
@@ -1406,7 +1379,7 @@ test_case_msg_cc_handover (test_t test)
for (i = 19; i < 60; i++)
test_fail_unless (buffer[i] == 0);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 2, &fmi);
res = cp_msg_cc_handover_info_rsp_receive (&cp, mme);
test_fail_unless (res == true);
slab_release (mme);
@@ -1470,7 +1443,7 @@ test_case_msg_cc_cco_appoint (test_t test)
test_fail_unless (bitstream_read_large (&stream, 48) == 0);
bitstream_finalise (&stream);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0x1, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0x1, &fmi);
test_fail_unless (mme);
test_fail_unless (mme->mmtype == CC_CCO_APPOINT_REQ);
res = cp_msg_cc_cco_appoint_req_receive (&cp, mme, &req_type,
@@ -1489,7 +1462,7 @@ test_case_msg_cc_cco_appoint (test_t test)
test_fail_unless (bitstream_read_large (&stream, 48) == 0x12);
bitstream_finalise (&stream);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0x1, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0x1, &fmi);
test_fail_unless (mme);
test_fail_unless (mme->mmtype == CC_CCO_APPOINT_REQ);
res = cp_msg_cc_cco_appoint_req_receive (&cp, mme, &req_type,
@@ -1592,7 +1565,7 @@ test_case_msg_cc_cco_appoint (test_t test)
== CP_MSG_CC_CCO_APPOINT_CNF_RES_SUCCESS_UAP_STA_ACCEPT);
bitstream_finalise (&stream);
- mme = cp_msg_mme_read_header (&cp, buffer, 60, 0x1, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 60, 0x1, &fmi);
test_fail_unless (mme);
test_fail_unless (mme->mmtype == CC_CCO_APPOINT_CNF);
res = cp_msg_cc_cco_appoint_cnf_receive (&cp, mme, &result);
@@ -1660,11 +1633,6 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
return buffer;
}
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer)
-{
-}
-
/**
* Send a MME over the PWL or the HLE.
* \param ctx the module context.
diff --git a/cesar/cp/msg/test/src/msg_cm.c b/cesar/cp/msg/test/src/msg_cm.c
index b02aa031c3..dc937df855 100644
--- a/cesar/cp/msg/test/src/msg_cm.c
+++ b/cesar/cp/msg/test/src/msg_cm.c
@@ -95,8 +95,7 @@ test_case_cm_set_key_req_run (test_t t,
cp_msg_cm_set_key_req_send (ctx, &peer, peks, &prun_input,
&key_req_input);
memset (&key_req_output, 0, sizeof (cp_msg_cm_set_key_req_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
if (peks != CP_MME_PEKS_NONE)
{
ok = cp_msg_mme_read_header_enc (&cp, msg);
@@ -140,8 +139,7 @@ test_case_cm_set_key_cnf_run (test_t t,
cp_msg_cm_set_key_cnf_send (ctx, &peer, peks, &prun_input,
&key_cnf_input);
memset (&key_cnf_output, 0, sizeof (cp_msg_cm_set_key_cnf_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_mme_read_header_enc (&cp, msg);
test_fail_unless (ok == true);
ok = cp_msg_cm_set_key_cnf_receive (&cp, msg, &key_cnf_output);
@@ -338,8 +336,7 @@ test_case_cm_get_key (test_t test)
{
memset (&data, 0, sizeof (cp_msg_cm_get_key_req_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_mme_read_header_enc (&cp, msg);
test_fail_unless (ok == true);
@@ -365,8 +362,7 @@ test_case_cm_get_key (test_t test)
memset (&data, 0, sizeof (cp_msg_cm_get_key_req_t));
bitstream_direct_write (buffer, 19 * 8, 2, 8);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
bitstream_finalise (&msg->bitstream);
bitstream_read_init (&msg->bitstream, buffer + 19, 420 - 19);
@@ -392,8 +388,7 @@ test_case_cm_get_key (test_t test)
memset (&data, 0, sizeof (cp_msg_cm_get_key_req_t));
bitstream_direct_write (buffer, 20 * 8, CP_MSG_KEY_NB, 8);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_req_receive (&cp, msg, &data);
test_fail_unless (ok == false);
@@ -415,8 +410,7 @@ test_case_cm_get_key (test_t test)
memset (&data, 0, sizeof (cp_msg_cm_get_key_req_t));
bitstream_direct_write_large (buffer, 21 * 8, nid << 2, 56);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_req_receive (&cp, msg, &data);
test_fail_unless (ok == false);
@@ -459,8 +453,7 @@ test_case_cm_get_key (test_t test)
test_begin (test, "Key refused")
{
memset (&cnf, 0, sizeof (cp_msg_cm_get_key_cnf_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == true);
test_fail_unless (cnf.result ==
@@ -496,8 +489,7 @@ test_case_cm_get_key (test_t test)
test_begin (test, "Verify encrypted payload")
{
memset (&cnf, 0, sizeof (cp_msg_cm_get_key_cnf_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_mme_read_header_enc (&cp, msg);
test_fail_unless (ok == true);
@@ -530,8 +522,7 @@ test_case_cm_get_key (test_t test)
test_begin (test, "Verify encrypted payload")
{
memset (&cnf, 0, sizeof (cp_msg_cm_get_key_cnf_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == true);
@@ -558,8 +549,7 @@ test_case_cm_get_key (test_t test)
bitstream_direct_write (buffer, 19 * 8, CP_MSG_CM_GET_KEY_CNF_RESULT_NB,
8);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == false);
@@ -589,8 +579,7 @@ test_case_cm_get_key (test_t test)
bitstream_direct_write (buffer, 20 * 8, CP_MSG_KEY_NB,
8);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == false);
@@ -620,8 +609,7 @@ test_case_cm_get_key (test_t test)
memset (&cnf, 0, sizeof (cp_msg_cm_get_key_cnf_t));
bitstream_direct_write_large (buffer, 29 * 8, nid << 2, 56);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == false);
@@ -662,8 +650,7 @@ test_case_cm_get_key (test_t test)
/* Overwrite EKS. */
bitstream_direct_write (buffer, 36 * 8, CP_MME_PEKS_TEK_MAX, 8);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == true);
@@ -701,8 +688,7 @@ test_case_cm_get_key (test_t test)
cp_msg_cm_get_key_cnf_send (&cp, &peer, CP_MME_PEKS_NONE, &prun, &cnf);
memset (&cnf, 0, sizeof (cp_msg_cm_get_key_cnf_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == true);
@@ -737,8 +723,7 @@ test_case_cm_get_key (test_t test)
cp_msg_cm_get_key_cnf_send (&cp, &peer, CP_MME_PEKS_NONE, &prun, &cnf);
memset (&cnf, 0, sizeof (cp_msg_cm_get_key_cnf_t));
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == true);
@@ -775,8 +760,7 @@ test_case_cm_get_key (test_t test)
/* Overwrite EKS. */
bitstream_direct_write (buffer, 36 * 8, MAC_EKS_CLEAR, 8);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
test_fail_unless (ok == true);
@@ -803,8 +787,7 @@ test_case_cm_get_key (test_t test)
{
/* Overwrite EKS in the received MME. */
bitstream_direct_write (buffer, 36 * 8, MAC_EKS_MAX + 1, 8);
- msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi,
- false);
+ msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi);
ok = cp_msg_cm_get_key_cnf_receive (&cp, msg, &cnf);
/* Decode should failed. */
@@ -3587,11 +3570,6 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
return buffer;
}
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer)
-{
-}
-
/**
* Send a MME over the PWL or the HLE.
* \param ctx the module context.
diff --git a/cesar/cp/msg/test/src/msg_vs.c b/cesar/cp/msg/test/src/msg_vs.c
index ba0a1ee3bb..2231272931 100644
--- a/cesar/cp/msg/test/src/msg_vs.c
+++ b/cesar/cp/msg/test/src/msg_vs.c
@@ -510,7 +510,7 @@ test_case_msg_vs_get_tonemap (test_t test)
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (bitstream_read (&rx_mme->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
test_fail_unless (rx_mme != NULL);
@@ -531,7 +531,7 @@ test_case_msg_vs_get_tonemap (test_t test)
bitstream_direct_write_large (first_mme, 152, MAC_ZERO, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_TONEMAP_REQ);
data = cp_msg_vs_get_tonemap_req_receive (&cp, rx_mme, &mac_addr, &tmi,
&int_id, &dir);
@@ -545,7 +545,7 @@ test_case_msg_vs_get_tonemap (test_t test)
bitstream_direct_write_large (first_mme, 152, MAC_BROADCAST, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_TONEMAP_REQ);
data = cp_msg_vs_get_tonemap_req_receive (&cp, rx_mme, &mac_addr, &tmi,
&int_id, &dir);
@@ -561,7 +561,7 @@ test_case_msg_vs_get_tonemap (test_t test)
CP_MSG_VS_GET_TONEMAP_TMI_RSVD_MAX, 8);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_TONEMAP_REQ);
data = cp_msg_vs_get_tonemap_req_receive (&cp, rx_mme, &mac_addr,
&tmi, &int_id, &dir);
@@ -578,7 +578,7 @@ test_case_msg_vs_get_tonemap (test_t test)
CP_MSG_VS_GET_TONEMAP_REQ_DIRECTION_NB, 8);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_TONEMAP_REQ);
data = cp_msg_vs_get_tonemap_req_receive (&cp, rx_mme, &mac_addr,
&tmi, &int_id, &dir);
@@ -844,7 +844,7 @@ test_case_msg_vs_get_snr (test_t test)
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SNR_REQ);
test_fail_unless (bitstream_read (&rx_mme->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
@@ -865,7 +865,7 @@ test_case_msg_vs_get_snr (test_t test)
bitstream_direct_write_large (first_mme, 152, MAC_ZERO, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SNR_REQ);
data = cp_msg_vs_get_snr_req_receive (&cp, rx_mme, &mac_addr,
&tm_int_i, &int_id,
@@ -880,7 +880,7 @@ test_case_msg_vs_get_snr (test_t test)
bitstream_direct_write_large (first_mme, 152, MAC_BROADCAST, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SNR_REQ);
data = cp_msg_vs_get_snr_req_receive (&cp, rx_mme, &mac_addr,
&tm_int_i, &int_id,
@@ -897,7 +897,7 @@ test_case_msg_vs_get_snr (test_t test)
CP_MSG_VS_GET_SNR_REQ_INT_RSVD_MAX , 8);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SNR_REQ);
data = cp_msg_vs_get_snr_req_receive (&cp, rx_mme, &mac_addr,
&tm_int_i, &int_id,
@@ -915,7 +915,7 @@ test_case_msg_vs_get_snr (test_t test)
CP_MSG_VS_GET_SNR_REQ_CARRIER_GR_NB, 8);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SNR_REQ);
data = cp_msg_vs_get_snr_req_receive (&cp, rx_mme, &mac_addr,
&tm_int_i, &int_id,
@@ -1060,7 +1060,7 @@ test_case_msg_vs_get_spectrum (test_t test)
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SPECTRUM_REQ);
test_fail_unless (bitstream_read (&rx_mme->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
@@ -1079,7 +1079,7 @@ test_case_msg_vs_get_spectrum (test_t test)
bitstream_direct_write_large (first_mme, 152, MAC_ZERO, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SPECTRUM_REQ);
data = cp_msg_vs_get_spectrum_req_receive (&cp, rx_mme, &mac_addr,
&carrier_gr);
@@ -1093,7 +1093,7 @@ test_case_msg_vs_get_spectrum (test_t test)
bitstream_direct_write_large (first_mme, 152, MAC_BROADCAST, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SPECTRUM_REQ);
data = cp_msg_vs_get_spectrum_req_receive (&cp, rx_mme, &mac_addr,
&carrier_gr);
@@ -1109,7 +1109,7 @@ test_case_msg_vs_get_spectrum (test_t test)
CP_MSG_VS_GET_SPECTRUM_REQ_CARRIER_GR_RSVD_MAX, 8);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_SPECTRUM_REQ);
data = cp_msg_vs_get_spectrum_req_receive (&cp, rx_mme, &mac_addr,
&carrier_gr);
@@ -1242,7 +1242,7 @@ test_case_msg_vs_get_link_stats (test_t test)
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_LINK_STATS_REQ);
test_fail_unless (bitstream_read (&rx_mme->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
@@ -1269,7 +1269,7 @@ test_case_msg_vs_get_link_stats (test_t test)
CP_MSG_VS_GET_LINK_STATS_REQ_REQTYPE_NB, 8);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_LINK_STATS_REQ);
data = cp_msg_vs_get_link_stats_req_receive (&cp, rx_mme, &rx_data);
@@ -1288,7 +1288,7 @@ test_case_msg_vs_get_link_stats (test_t test)
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_LINK_STATS_REQ);
data = cp_msg_vs_get_link_stats_req_receive (&cp, rx_mme, &rx_data);
@@ -1306,7 +1306,7 @@ test_case_msg_vs_get_link_stats (test_t test)
CP_MSG_VS_GET_LINK_STATS_REQ_MGMTFLAG_NB, 8);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_LINK_STATS_REQ);
data = cp_msg_vs_get_link_stats_req_receive (&cp, rx_mme, &rx_data);
@@ -1323,7 +1323,7 @@ test_case_msg_vs_get_link_stats (test_t test)
bitstream_direct_write_large (first_mme, 248, MAC_ZERO, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_LINK_STATS_REQ);
data = cp_msg_vs_get_link_stats_req_receive (&cp, rx_mme, &rx_data);
@@ -1337,7 +1337,7 @@ test_case_msg_vs_get_link_stats (test_t test)
bitstream_direct_write_large (first_mme, 248, MAC_BROADCAST, 48);
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_LINK_STATS_REQ);
data = cp_msg_vs_get_link_stats_req_receive (&cp, rx_mme, &rx_data);
@@ -1482,7 +1482,7 @@ test_case_msg_vs_get_stats (test_t test)
/* Receive MME */
rx_mme = cp_msg_mme_read_header (&cp, first_mme, ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
test_fail_unless (rx_mme->mmtype == VS_GET_STATS_REQ);
test_fail_unless (bitstream_read (&rx_mme->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
@@ -1624,7 +1624,7 @@ test_case_msg_vs_get_ce_stats_req_receive_test_case (test_t test,
/* Receive MME. */
rx_mme = cp_msg_mme_read_header (&cp, GET_BUFFER(0), ETH_PACKET_MAX_SIZE,
- peer.tei, &fmi, false);
+ peer.tei, &fmi);
dbg_assert (rx_mme->mmtype == VS_GET_CE_STATS_REQ);
test_fail_unless (bitstream_read (&rx_mme->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
@@ -1885,7 +1885,7 @@ test_case_msg_vs_get_pb_stats (test_t test)
/* Receive MME. */
rx_mme = cp_msg_mme_read_header (&cp, GET_BUFFER(0),
ETH_PACKET_MAX_SIZE, peer.tei,
- &fmi, false);
+ &fmi);
dbg_assert (rx_mme->mmtype == VS_GET_PB_STATS_REQ);
test_fail_unless (bitstream_read (&rx_mme->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
@@ -2099,7 +2099,7 @@ test_case_msg_vs_get_mactotei (test_t test)
uint fmi;
mme_rx = cp_msg_mme_read_header (&cp, GET_BUFFER(0),
ETH_PACKET_MIN_SIZE, peer.tei,
- &fmi, false);
+ &fmi);
dbg_assert (mme_rx->mmtype == VS_GET_MACTOTEI_REQ);
test_fail_unless (bitstream_read (&mme_rx->bitstream, OUI_SIZE_BITS)
== SPC_OUI);
@@ -2221,11 +2221,6 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
return all_buffer[buffer_idx];
}
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 *buffer)
-{
-}
-
/**
* Send a MME over the PWL or the HLE.
* \param ctx the module context.
diff --git a/cesar/cp/msg/test/src/relay.c b/cesar/cp/msg/test/src/relay.c
index f17fb26773..59217e958f 100644
--- a/cesar/cp/msg/test/src/relay.c
+++ b/cesar/cp/msg/test/src/relay.c
@@ -907,6 +907,3 @@ cp_cl_interf_get_buffer_tx (cp_t *ctx)
void
cp_cl_interf_mme_send (cp_t *ctx, cp_mme_tx_t * mme) {}
-
-void
-cp_cl_interf_add_buffer_tx (cp_t *ctx, u8 * buffer) {}
diff --git a/cesar/cp/msg/test/src/test-msg-read-header.c b/cesar/cp/msg/test/src/test-msg-read-header.c
index d16b5caa2c..2d0728ae64 100644
--- a/cesar/cp/msg/test/src/test-msg-read-header.c
+++ b/cesar/cp/msg/test/src/test-msg-read-header.c
@@ -149,7 +149,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_fail_unless (mme != NULL);
test_fail_if (mme->p_mme != buffer, "Wrong buffer address");
@@ -183,7 +183,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_fail_if (mme->p_mme != buffer, "Wrong buffer address");
test_fail_if (mme->length != 92, "Wrong length");
@@ -214,7 +214,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_begin (test, "Read a MME without vlan")
{
@@ -239,7 +239,7 @@ test_case_msg_read_header_mme_without_vlan (test_t test)
bitstream_access (&bitstream, &data, 16);
bitstream_finalise (&bitstream);
- mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi, true);
+ mme = cp_msg_mme_read_header (&cp, buffer, 92, 0x1, &fmi);
test_begin (test, "Read a MME without vlan")
{
@@ -263,7 +263,7 @@ test_case_msg_allowed_mme_sta_unassociated_common (uint mmtype)
/* Configure the test. */
cp_msg_init (&cp);
cp_sta_mgr_init (&cp);
- mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED, false);
+ mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED);
mme->peer.mac = mac;
mme->peer.tei = MAC_TEI_UNASSOCIATED;
mme->mmtype = mmtype;
@@ -306,7 +306,7 @@ test_case_msg_allowed_mme_sta_associated_common (uint mmtype)
cp_sta_own_data_set_tei (&cp, 1);
- mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED, false);
+ mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED);
mme->peer.mac = mac;
mme->peer.tei = 254;
mme->length = 60;
@@ -350,7 +350,7 @@ test_case_msg_allowed_mme_sta_auth_common (uint mmtype, bool enc)
cp_sta_own_data_set_tei (&cp, 1);
cp_sta_own_data_set_authenticated_status (&cp, true);
- mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED, false);
+ mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED);
mme->peer.mac = mac;
mme->peer.tei = 254;
mme->mmtype = mmtype;
@@ -382,7 +382,7 @@ test_case_msg_allowed_mme_from_h1 (uint mmtype)
/* Configure the test. */
cp_msg_init (&cp);
- mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED, false);
+ mme = cp_msg_mme_rx_init (&cp, buffer, 60, MAC_TEI_UNASSOCIATED);
mme->peer.mac = mac;
mme->peer.tei = MAC_TEI_FOREIGN;
mme->mmtype = mmtype;
@@ -633,8 +633,7 @@ test_case_msg_cm_get_key_req(test_t test)
net = cp_sta_mgr_add_avln (&ctx, 9, 0x84e35a5cb6b02ull);
cp_sta_mgr_set_our_avln (&ctx, net);
mme = cp_msg_mme_read_header (
- &ctx, ((u8*) cm_get_key_req_intellon) + 6, length, 1, &fmi,
- false);
+ &ctx, ((u8*) cm_get_key_req_intellon) + 6, length, 1, &fmi);
result = cp_msg_dispatch__read_enc_header (&ctx, mme);
test_fail_unless (result == true);
@@ -687,7 +686,7 @@ test_case_msg_cm_get_key_req(test_t test)
net = cp_sta_mgr_add_avln (&ctx, 9, 0x84e35a5cb6b02ull);
cp_sta_mgr_set_our_avln (&ctx, net);
mme = cp_msg_mme_read_header (&ctx, ((u8*) cm_get_key_req_spc300) + 6,
- length, 1, &fmi, false);
+ length, 1, &fmi);
result = cp_msg_dispatch__read_enc_header (&ctx, mme);
test_fail_unless (result == true);
@@ -730,7 +729,7 @@ test_case_mme_too_short (test_t test)
cp_msg_init (&cp);
- mme = cp_msg_mme_read_header (&cp, buffer, 15, 1, &fmi, false);
+ mme = cp_msg_mme_read_header (&cp, buffer, 15, 1, &fmi);
test_fail_unless (mme == NULL);
cp_msg_uninit (&cp);
@@ -757,8 +756,7 @@ test_case_mme_too_short (test_t test)
cp_msg_init (&cp);
- mme = cp_msg_mme_read_header (&cp, buffer, HPAV_MME_HEADER, 1, &fmi,
- true);
+ mme = cp_msg_mme_read_header (&cp, buffer, HPAV_MME_HEADER, 1, &fmi);
test_fail_unless (mme != NULL);
slab_release (mme);
@@ -788,7 +786,7 @@ test_case_mme_too_short (test_t test)
cp_msg_init (&cp);
mme = cp_msg_mme_read_header (
- &cp, buffer, HPAV_MME_HEADER_LEN_WITH_VLAN, 1, &fmi, true);
+ &cp, buffer, HPAV_MME_HEADER_LEN_WITH_VLAN, 1, &fmi);
test_fail_unless (mme != NULL);
slab_release (mme);
@@ -834,7 +832,7 @@ test_case_mme_encrypted_payload (test_t test)
cp_msg_mme_send (&cp, tx);
buffer = cp_cl_interf_get_buffer_tx (&cp);
- rx = cp_msg_mme_read_header (&cp, buffer, 75, peer.tei, &fmi, true);
+ rx = cp_msg_mme_read_header (&cp, buffer, 75, peer.tei, &fmi);
test_fail_unless (rx != NULL);
fsm_post = false;
diff --git a/cesar/cp/src/cp.c b/cesar/cp/src/cp.c
index 7cdf39b7c9..45c001d716 100644
--- a/cesar/cp/src/cp.c
+++ b/cesar/cp/src/cp.c
@@ -30,6 +30,7 @@ static cp_t cp_global;
* \param sar the SAR context.
* \param cl the CL context.
* \param ce_rx the CE in RX context.
+ * \param bufmgr the buffer manager context.
* \param seed the seed to initialise the random generator.
* \return The control plane context.
*
@@ -38,7 +39,7 @@ cp_t *
cp_init (bsu_t *bsu, bsu_aclf_t* aclf, mac_config_t * mac_config,
interface_t * interface, hal_timer_t *hal_timer, pbproc_t *pbproc,
mac_store_t *mac_store, sar_t *sar, cl_t *cl, ce_rx_t *ce_rx,
- u32 seed)
+ bufmgr_t *bufmgr, u32 seed)
{
dbg_assert (mac_config);
dbg_assert (interface);
@@ -47,6 +48,7 @@ cp_init (bsu_t *bsu, bsu_aclf_t* aclf, mac_config_t * mac_config,
dbg_assert (sar);
dbg_assert (cl);
dbg_assert (ce_rx);
+ dbg_assert (bufmgr);
cp_global.mac_config = mac_config;
cp_global.interface = interface;
@@ -61,6 +63,9 @@ cp_init (bsu_t *bsu, bsu_aclf_t* aclf, mac_config_t * mac_config,
cp_global.bsu = bsu;
cp_global.bsu_aclf = aclf;
+ /** Initialise buffer manager. */
+ cp_global.bufmgr = bufmgr;
+
/* Init the random generator. */
lib_rnd_init (&cp_global.rnd, seed ^ 0x87543571);
diff --git a/cesar/cp/sta/action/test/utest/Makefile b/cesar/cp/sta/action/test/utest/Makefile
index c27b78ee83..9efa946f33 100644
--- a/cesar/cp/sta/action/test/utest/Makefile
+++ b/cesar/cp/sta/action/test/utest/Makefile
@@ -12,7 +12,8 @@ test_sta_action_SOURCES = test_sta_action.c assoc.c drv.c info.c key.c \
test_sta_action_MODULES = lib lib/scenario cp/sta/action cp/sta/mgr \
cp/fsm/stub cp/secu mac/common cl/stub cl \
cp/cco/action/stub cp/beacon/stub cp/msg/stub \
- ce/stub mac/sar/stub cp/av/cco/bw/stub bsu/stub
+ ce/stub mac/sar/stub cp/av/cco/bw/stub bsu/stub \
+ hal/ipmbox/stub
cp_fsm_MODULE_SOURCES = tables.c
# For bridging MME tests.
diff --git a/cesar/cp/sta/core/stub/src/sta_core.c b/cesar/cp/sta/core/stub/src/sta_core.c
index 27ae963bf2..4a65890d78 100644
--- a/cesar/cp/sta/core/stub/src/sta_core.c
+++ b/cesar/cp/sta/core/stub/src/sta_core.c
@@ -19,6 +19,10 @@
#include "cp/sta/core/core.h"
#include "cp/sta/core/defs.h"
+#if !(defined (ECOS) && ECOS)
+typedef int cyg_tick_count_t;
+#endif
+
/**
* initialisation of station core.
*
@@ -173,3 +177,11 @@ cp_sta_core_checkpoint (cp_t *ctx)
{
}
+cyg_tick_count_t
+cp_sta_core_ms_to_cyg_tick (cp_t *ctx, const uint ms) __attribute__((weak));
+
+cyg_tick_count_t
+cp_sta_core_ms_to_cyg_tick (cp_t *ctx, const uint ms)
+{
+ return ms * 1000;
+}
diff --git a/cesar/cp/sta/mgr/test/Makefile b/cesar/cp/sta/mgr/test/Makefile
index ead5152c67..33aac4cf7f 100644
--- a/cesar/cp/sta/mgr/test/Makefile
+++ b/cesar/cp/sta/mgr/test/Makefile
@@ -7,7 +7,7 @@ test_sta_mgr_SOURCES = core_stub.c net_test.c sar_stub.c sta_mgr.c \
sta-test.c station_test.c test_sta_mgr.c
test_sta_mgr_MODULES = lib cp/sta/mgr mac/common cp/fsm/stub \
cp/cco/action/stub bsu/stub cp/msg/stub \
- cl cl/stub
+ cl cl/stub hal/ipmbox/stub
cl_MODULE_SOURCES = cl_mactotei.c brg_rx.c
diff --git a/cesar/hal/Module b/cesar/hal/Module
index c57ce1b3cb..c9cdc9f5ec 100644
--- a/cesar/hal/Module
+++ b/cesar/hal/Module
@@ -1,8 +1,8 @@
ifeq ($($(BUILD_TYPE_VAR)),)
MODULES := hal/timer hal/watchdog \
- hal/phy/maximus hal/hle/maximus hal/leon/maximus \
+ hal/phy/maximus hal/ipmbox/maximus hal/leon/maximus \
hal/phy/soft/bridgedma
else
MODULES := hal/timer hal/watchdog hal/arch \
- hal/phy hal/hle hal/leon hal/boot_params hal/mem
+ hal/phy hal/ipmbox hal/leon hal/boot_params hal/mem
endif
diff --git a/cesar/hal/hle/Module b/cesar/hal/hle/Module
deleted file mode 100644
index e3d78156f4..0000000000
--- a/cesar/hal/hle/Module
+++ /dev/null
@@ -1 +0,0 @@
-SOURCES := hal_ipmbox.c ipmbox.c
diff --git a/cesar/hal/hle/defs.h b/cesar/hal/hle/defs.h
deleted file mode 100644
index c70d1573bc..0000000000
--- a/cesar/hal/hle/defs.h
+++ /dev/null
@@ -1,73 +0,0 @@
-#ifndef hal_hle_defs_h
-#define hal_hle_defs_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/defs.h
- * \brief HAL HLE types and defines.
- * \ingroup hal_hle
- */
-
-#define IPMBOX_REG__MSG_TYPE 7, 0 /* 8 bits. */
-#define IPMBOX_REG__MSG_LENGTH 11, 8 /* 4 bits. */
-
-#define IPMBOX_REG__PARAM_MSG_TYPE 12, 12 /* 1 bit. */
-#define IPMBOX_REG__PARAM_MSG_LENGTH 23, 13 /* 11 bits. */
-#define IPMBOX_REG__PARAM_MSG_PRIO 26, 24 /* 3 bits */
-
-#define IPMBOX_REG__PARAM_BUFFER_TYPE 14, 12 /* 3 bits. */
-
-/* Still in the header message. */
-#define IPMBOX_REG__PARAM_INTERFACE_TYPE 19, 12 /* 8 bits. */
-#define IPMBOX_REG__PARAM_INTERFACE_LENGTH 30, 20 /* 11 bits. */
-
-#define IPMBOX_REG__PARAM_RPC_FORWARD_LENGTH 24, 12
-#define IPMBOX_REG__PARAM_RPC_REVERSE_LENGTH_KB 27, 25
-#define IPMBOX_REG__PARAM_RPC_MORE_DATA 25, 25
-#define IPMBOX_REG__PARAM_RPC_COOKIE 31, 28
-
-#define IPMBOX_REG__PARAM_DEBUG_DUMP_LENGTH 27, 12 /* 16 bits. */
-
-/** Message header (32 bits). */
-struct ipmbox_msg_hdr_t
-{
- BITFIELDS_WORD(
- /** Message type. */
- u32 type:8;,
- /** Number of parameter words (32 bits) following the header. */
- u32 length:4;,
- /** Optional parameters. */
- u32 param:20;)
-};
-typedef struct ipmbox_msg_hdr_t ipmbox_msg_hdr_t;
-
-/** Message types. */
-enum hle_msg_type_t
-{
- HLE_MSG_TYPE_DATA = 0x00, /*< Data or MME message type. */
- HLE_MSG_TYPE_BUFFER_ADD = 0x01, /*< Buffer alloc message type. */
- HLE_MSG_TYPE_SEND_DONE = 0x02, /*< Buffer dealloc message type. */
- HLE_MSG_TYPE_INTERFACE = 0x03, /*< Interface message type. */
- HLE_MSG_TYPE_BASE_NB, /*< Number of defined base message types. */
- HLE_MSG_TYPE_RPC = 0x30, /*< Remote procedure call message type. */
- HLE_MSG_TYPE_DEBUG_DUMP = 0x40, /*< Debug dump message type. */
- HLE_MSG_TYPE_NONE = 0xff /*< Invalid message type. */
- };
-typedef enum hle_msg_type_t hle_msg_type_t;
-
-/** Buffer allocation type. */
-enum hle_buffer_alloc_type_t
-{
- HLE_BUFFER_ALLOC_DATA,
- HLE_BUFFER_ALLOC_MME,
- HLE_BUFFER_ALLOC_INTERFACE,
- HLE_BUFFER_ALLOC_NB
-};
-typedef enum hle_buffer_alloc_type_t hle_buffer_alloc_type_t;
-
-#endif /* hal_hle_defs_h */
diff --git a/cesar/hal/hle/forward.h b/cesar/hal/hle/forward.h
deleted file mode 100644
index 93aac0bf24..0000000000
--- a/cesar/hal/hle/forward.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef hal_hle_forward_h
-#define hal_hle_forward_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/forward.h
- * \brief HAL HLE ipmbox context forward declaration.
- * \ingroup hal_hle
- */
-
-/* Forward declaration. */
-typedef struct ipmbox_t ipmbox_t;
-
-#endif /* hal_hle_forward_h */
diff --git a/cesar/hal/hle/inc/hal_ipmbox.h b/cesar/hal/hle/inc/hal_ipmbox.h
deleted file mode 100644
index a04367a78b..0000000000
--- a/cesar/hal/hle/inc/hal_ipmbox.h
+++ /dev/null
@@ -1,130 +0,0 @@
-#ifndef hal_ipmbox_h
-#define hal_ipmbox_h
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/inc/hal_ipmbox.h
- * \brief HAL HLE hal layer.
- * \ingroup hal_hle
- */
-#include "hal/hle/inc/reg_ipmbox.h"
-
-#define A2L_HEAD (*(volatile u32 *) A2L_HEAD_ADDR)
-#define A2L_TAIL (*(volatile u32 *) A2L_TAIL_ADDR)
-#define L2A_HEAD (*(volatile u32 *) L2A_HEAD_ADDR)
-#define L2A_TAIL (*(volatile u32 *) L2A_TAIL_ADDR)
-#define A2L_IT (*(volatile u32 *) A2L_IT_ADDR)
-#define L2A_IT (*(volatile u32 *) L2A_IT_ADDR)
-#define A2L_IT_MASK (*(volatile u32 *) A2L_IT_MASK_ADDR)
-
-/**
- * Enable the Leon to Arm Acknowledge Interrupt.
- */
-extern inline void
-L2Aa_it_enable (void)
-{
- A2L_IT_MASK &= ~A2LA_EN_MASK;
-}
-
-/**
- * Enable the Arm to Leon Trigger Interrupt.
- */
-extern inline void
-A2Lt_it_enable (void)
-{
- A2L_IT_MASK &= ~A2LT_EN_MASK;
-}
-
-/**
- * Disable the Leon to Arm Acknowledge Interrupt.
- */
-extern inline void
-L2Aa_it_disable (void)
-{
- A2L_IT_MASK |= A2LA_EN_MASK;
-}
-
-/**
- * Disable the Arm to Leon Trigger Interrupt.
- */
-extern inline void
-A2Lt_it_disable (void)
-{
- A2L_IT_MASK |= A2LT_EN_MASK;
-}
-
-/**
- * Clear the Arm to Leon Interrupt.
- */
-extern inline void
-clr_A2Lt_interrupt (void)
-{
- A2L_IT = A2LT_MASK;
-}
-
-/**
- * Set the Arm to Leon acknowledge Interrupt.
- */
-extern inline void
-clr_L2Aa_interrupt (void)
-{
- A2L_IT = A2LA_MASK;
-}
-
-/**
- * Read the Arm to Leon Interrupt.
- */
-extern inline bool
-get_A2Lt_interrupt (void)
-{
- return (A2L_IT & A2LT_MASK) ? true : false;
-}
-
-/**
- * Set the Leon to Arm Interrupt.
- */
-extern inline void
-set_L2At_interrupt (void)
-{
- L2A_IT |= L2AT_MASK;
-}
-
-/**
- * Set the Leon to Arm acknowledge Interrupt.
- */
-extern inline void
-set_A2La_interrupt (void)
-{
- L2A_IT |= L2AA_MASK;
-}
-
-/**
- * Copy message to the ring buffer, update pointers and trigger interrupt.
- *
- * \param message pointer to the message
- * \param size message size in words
- */
-void
-halmbx_copy_to_ring (u32 *message, uint size);
-
-/**
- * Copy message from the ring buffer, update pointers and trigger interrupt.
- *
- * \param message pointer to the message
- * \param size max message size in words
- */
-void
-halmbx_copy_from_ring (u32 *message, uint size);
-
-/**
- * Initialize the HAL layer.
- */
-void
-halmbx_init (void);
-
-#endif /* hal_ipmbox_h */
diff --git a/cesar/hal/hle/inc/ipmbox.h b/cesar/hal/hle/inc/ipmbox.h
deleted file mode 100644
index 7ad0518a85..0000000000
--- a/cesar/hal/hle/inc/ipmbox.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef ipmbox_h
-#define ipmbox_h
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file ipmbox.h
- * \brief HAL HLE mailbox layer.
- * \ingroup hal_hle
- *
- * this file provide all structures and defines needed for unit test or normal mode.
- */
-#include "hal/hle/ipmbox.h" // for 'ipmbox_rx_cb_t'
-
-#ifndef HAL_HLE_IPMBOX_UNIT_TEST
-
-#include <cyg/hal/drv_api.h>
-#include <cyg/hal/hal_intr.h>
-
-/* eCos function is dawn too slow, use HAL_INTERRUPT_ACKNOWLEDGE instead of
- * cyg_drv_interrupt_acknowledge. */
-#define ipmbox_interrupt_acknowledge HAL_INTERRUPT_ACKNOWLEDGE
-
-/* We need this undocumented eCos function for budget. */
-extern void cyg_interrupt_post_dsr (CYG_ADDRWORD intr_obj);
-
-#else
-
-//eCos stub only for unit tests
-#define CYGNUM_HAL_INTERRUPT_GIC2_14 14
-#define CYG_ISR_HANDLED 1
-#define CYG_ISR_CALL_DSR 2
-
-typedef unsigned int cyg_interrupt;
-typedef unsigned int cyg_handle_t;
-typedef unsigned int cyg_vector_t;
-typedef unsigned int cyg_priority_t;
-typedef unsigned int cyg_addrword_t;
-typedef unsigned int cyg_uint32;
-typedef unsigned int cyg_ucount32;
-typedef unsigned int cyg_ISR_t(cyg_vector_t vector, cyg_addrword_t data);
-typedef void cyg_DSR_t(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);
-
-static inline void
-cyg_drv_interrupt_mask (cyg_vector_t vector)
-{
-}
-
-static inline void
-cyg_drv_interrupt_acknowledge (cyg_vector_t vector)
-{
-}
-
-static inline void
-cyg_drv_interrupt_unmask (cyg_vector_t vector)
-{
-}
-
-#define ipmbox_interrupt_mask cyg_drv_interrupt_mask
-#define ipmbox_interrupt_acknowledge cyg_drv_interrupt_acknowledge
-#define ipmbox_interrupt_unmask cyg_drv_interrupt_unmask
-
-static inline void
-cyg_drv_interrupt_attach (cyg_handle_t handle)
-{
-}
-
-static inline void
-cyg_drv_interrupt_create (cyg_vector_t vector,
- cyg_priority_t priority,
- cyg_addrword_t data,
- cyg_ISR_t *isr,
- cyg_DSR_t *dsr,
- cyg_handle_t *handle,
- cyg_interrupt *intr)
-{
-}
-
-extern bool dsr_posted;
-
-static inline void
-cyg_interrupt_post_dsr (u32 intr_obj)
-{
- dsr_posted = true;
-}
-
-//declaration of "static" functions
-cyg_uint32 mailbox_rx_isr (cyg_vector_t vector, cyg_addrword_t data);
-void mailbox_rx_dsr (cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);
-
-#endif
-
-/** Context structure definition */
-struct ipmbox_t {
- void *rx_cb_user_data;
- ipmbox_rx_cb_t rx_cb;
- cyg_interrupt rx_it;
- cyg_handle_t rx_it_handle;
-};
-
-#endif /* ipmbox_h */
diff --git a/cesar/hal/hle/inc/reg_ipmbox.h b/cesar/hal/hle/inc/reg_ipmbox.h
deleted file mode 100644
index fa968257ed..0000000000
--- a/cesar/hal/hle/inc/reg_ipmbox.h
+++ /dev/null
@@ -1,91 +0,0 @@
-#ifndef reg_ipmbox_h
-#define reg_ipmbox_h
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file reg_ipmbox.h
- * \brief HAL HLE mailboxes registers
- * \ingroup hal_hle
- *
- * This file defines all registers needed for mailboxes managements
- */
-
-/** Arm to Leon ring mask. */
-#define A2L_RING_MASK (A2L_RING_SIZE - 1)
-/** Leon to Arm ring mask. */
-#define L2A_RING_MASK (L2A_RING_SIZE - 1)
-
-/** Arm to Leon ring size in words. */
-#define A2L_RING_WORDS (A2L_RING_SIZE / 4)
-/** Leon to Arm ring size in words. */
-#define L2A_RING_WORDS (L2A_RING_SIZE / 4)
-
-/** Compute used words in Arm to Leon ring. */
-#define A2L_RING_USED_WORDS(head, tail) \
- ((((u32) (tail) - (u32) (head)) & A2L_RING_MASK) / 4)
-/** Compute used words in Leon to Arm ring. */
-#define L2A_RING_USED_WORDS(head, tail) \
- ((((u32) (tail) - (u32) (head)) & L2A_RING_MASK) / 4)
-
-/** HAL Acces declaration */
-#ifndef HAL_HLE_IPMBOX_UNIT_TEST
-
-#define SDRAM_WITHOUT_CACHE (0x40000000)
-#define A2L_RING_SIZE (0x1000)
-#define L2A_RING_SIZE (A2L_RING_SIZE)
-
-#define MAILBOX_REG_BASE_ADDR (0xB4000000)
-#define A2L_HEAD_ADDR (MAILBOX_REG_BASE_ADDR + 0x14)
-#define A2L_TAIL_ADDR (MAILBOX_REG_BASE_ADDR + 0x10)
-#define L2A_HEAD_ADDR (MAILBOX_REG_BASE_ADDR + 0x1C)
-#define L2A_TAIL_ADDR (MAILBOX_REG_BASE_ADDR + 0x18)
-#define A2L_IT_ADDR (MAILBOX_REG_BASE_ADDR + 0x00)
-#define L2A_IT_ADDR (MAILBOX_REG_BASE_ADDR + 0x08)
-#define A2L_IT_MASK_ADDR (MAILBOX_REG_BASE_ADDR + 0x04)
-
-#define A2LT_EN_MASK (0x00000001)
-#define A2LA_EN_MASK (0x00000002)
-#define A2LT_MASK (0x00000001)
-#define A2LA_MASK (0x00000002)
-#define L2AT_MASK (0x00000001)
-#define L2AA_MASK (0x00000002)
-
-#else /* !HAL_HLE_IPMBOX_UNIT_TEST */
-
-#define A2L_RING_SIZE (0x1000)
-#define L2A_RING_SIZE (A2L_RING_SIZE)
-extern u32 A2L_ring[A2L_RING_WORDS];
-extern u32 L2A_ring[L2A_RING_WORDS];
-#define A2L_RING_BASE_ADDR ((u32)&A2L_ring[0])
-#define L2A_RING_BASE_ADDR ((u32)&L2A_ring[0])
-
-extern u32 utest_A2L_head;
-extern u32 utest_A2L_tail;
-extern u32 utest_L2A_head;
-extern u32 utest_L2A_tail;
-extern u32 utest_A2L_it;
-extern u32 utest_L2A_it;
-extern u32 utest_A2L_it_mask;
-#define A2L_HEAD_ADDR ((u32)&utest_A2L_head)
-#define A2L_TAIL_ADDR ((u32)&utest_A2L_tail)
-#define L2A_HEAD_ADDR ((u32)&utest_L2A_head)
-#define L2A_TAIL_ADDR ((u32)&utest_L2A_tail)
-#define A2L_IT_ADDR ((u32)&utest_A2L_it)
-#define L2A_IT_ADDR ((u32)&utest_L2A_it)
-#define A2L_IT_MASK_ADDR ((u32)&utest_A2L_it_mask)
-
-#define A2LT_EN_MASK (0x00000001)
-#define A2LA_EN_MASK (0x00000002)
-#define A2LT_MASK (0x00000001)
-#define A2LA_MASK (0x00000002)
-#define L2AT_MASK (0x00000001)
-#define L2AA_MASK (0x00000002)
-
-#endif /* !HAL_HLE_IPMBOX_UNIT_TEST */
-
-#endif /* reg_ipmbox_h */
diff --git a/cesar/hal/hle/ipmbox.h b/cesar/hal/hle/ipmbox.h
deleted file mode 100644
index 4106c009b9..0000000000
--- a/cesar/hal/hle/ipmbox.h
+++ /dev/null
@@ -1,71 +0,0 @@
-#ifndef hal_hle_ipmbox_h
-#define hal_hle_ipmbox_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/ipmbox.h
- * \brief HAL HLE public interface.
- * \ingroup hal_hle
- */
-#include "hal/hle/forward.h" // for 'ipmbox_t'
-
-/**
- * RX DSR callback function.
- * \param user_data user data
- * \param first_msg pointer to the first received message header
- * \param length total length (in word) of received messages
- */
-typedef void (*ipmbox_rx_cb_t) (void *user_data, u32 *first_msg, uint length);
-
-BEGIN_DECLS
-
-/**
- * Initialise the HAL HLE.
- * \param user_data user data passed to any callback
- * \param rx_cb RX DSR callback, callback used when an Ethernet packet is received
- * \return the newly created context
- */
-ipmbox_t *
-ipmbox_init (void *user_data, ipmbox_rx_cb_t rx_cb);
-
-/**
- * Activate ipmbox interruptions.
- * \param ctx ipmbox context
- * \param activation indicates if interruptions are activated or deactivated
- */
-void
-ipmbox_activate (ipmbox_t *ctx, bool activation);
-
-/**
- * Uninitialise the HAL HLE.
- * \param ctx ipmbox context
- */
-void
-ipmbox_uninit (ipmbox_t *ctx);
-
-/**
- * Transmit a message to mailbox.
- * \param ctx ipmbox context
- * \param first_msg pointer to the first message header
- * \param length total length (in word) of messages to transmit
- */
-void
-ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length);
-
-/**
- * Receive message from mailbox, interrupts locked.
- * \param ctx ipmbox context
- * \param first_msg pointer to store first received message address
- * \return total length (in word) of received messages
- */
-uint
-ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg);
-
-END_DECLS
-
-#endif /* hal_hle_ipmbox_h */
diff --git a/cesar/hal/hle/maximus/inc/maximus_defs.h b/cesar/hal/hle/maximus/inc/maximus_defs.h
deleted file mode 100644
index 69fa3de7e3..0000000000
--- a/cesar/hal/hle/maximus/inc/maximus_defs.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef hal_hle_maximus_inc_maximus_defs_h
-#define hal_hle_maximus_inc_maximus_defs_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/maximus/inc/maximus_defs.h
- * \brief HAL HLE declarations for Maximus.
- * \ingroup hal_hle_maximus
- */
-
-/** Max size of Maximus mailbox. */
-#define MAXIMUS_HLE_MAILBOX_MAX_SIZE 1024
-
-#endif /* hal_hle_maximus_inc_maximus_defs_h */
diff --git a/cesar/hal/hle/maximus/inc/maximus_interrupts.h b/cesar/hal/hle/maximus/inc/maximus_interrupts.h
deleted file mode 100644
index 8b51d00aab..0000000000
--- a/cesar/hal/hle/maximus/inc/maximus_interrupts.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef hal_hle_maximus_inc_maximus_interrupts_h
-#define hal_hle_maximus_inc_maximus_interrupts_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/maximus/inc/maximus_interrupts.h
- * \brief HAL interrupt register definition for Maximus.
- * \ingroup hal_hle_maximus
- */
-
-#define HAL_HLE_INTERRUPT_IPMBOX 7
-
-#define HAL_HLE_INTERRUPT_PRIORITY 1 /* is it the right value? */
-
-#endif /* hal_hle_maximus_inc_maximus_interrupts_h */
diff --git a/cesar/hal/hle/maximus/inc/maximus_ipmbox_ctx.h b/cesar/hal/hle/maximus/inc/maximus_ipmbox_ctx.h
deleted file mode 100644
index 417fde63de..0000000000
--- a/cesar/hal/hle/maximus/inc/maximus_ipmbox_ctx.h
+++ /dev/null
@@ -1,70 +0,0 @@
-#ifndef hal_hle_maximus_inc_maximus_ipmbox_context_h
-#define hal_hle_maximus_inc_maximus_ipmbox_context_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/maximus/inc/maximus_ipmbox_context.h
- * \brief HAL HLE ipmbox context for Maximus.
- * \ingroup hal_hle_maximus
- */
-#include "hal/hle/ipmbox.h" // for 'ipmbox_rx_cb_t', 'ipmbox_tx_cb_t', and 'ipmbox_deferred_cb_t'
-#include "hal/hle/maximus/inc/maximus_defs.h" // for 'MAXIMUS_HLE_MAILBOX_MAX_SIZE'
-#include "maximus/common/types/sci_types.h" // for 'SCI_MSG_MAX_SIZE'
-#include <stdint.h> // for 'u32'
-#ifdef ECOS
-#include <cyg/hal/drv_api.h>
-#endif /* ECOS */
-
-/** HLE mailbox structure for Maximus */
-struct maximus_hle_mailbox_t
-{
- /** Total length (in word) of messages. */
- uint length;
- /** Mailbox. */
- u32 mailbox[MAXIMUS_HLE_MAILBOX_MAX_SIZE];
-};
-typedef struct maximus_hle_mailbox_t maximus_hle_mailbox_t;
-
-struct maximus_hle_buffer_t
-{
- /** Pointer to next allocated buffer. */
- struct maximus_hle_buffer_t *next;
- /** Buffer id.*/
- u32 id;
- /** Pointer to data. */
- u32 *data;
-};
-typedef struct maximus_hle_buffer_t maximus_hle_buffer_t;
-
-/** HLE ipmbox context structure for Maximus */
-struct ipmbox_t
-{
- /** HLE reception mailbox structure. */
- maximus_hle_mailbox_t rx;
- /** Pointer to first element in linked list of allocated buffers. */
- maximus_hle_buffer_t *first_buffer;
- /** Pointer to last element in linked list of allocated buffers. */
- maximus_hle_buffer_t *last_buffer;
- /** User data passed to any callback. */
- void *user_data;
- /** RX DSR callback. */
- ipmbox_rx_cb_t rx_cb;
-#ifdef ECOS
- /** ipmbox interrupt descriptor for eCos: relates to RX and TX */
- cyg_interrupt ipmbox_interrupt;
- /** ipmbox interrupt handle */
- cyg_handle_t ipmbox_interrupt_handle;
-#endif /* ECOS */
- /** For ether messages. */
- unsigned char buffer[SCI_MSG_MAX_SIZE];
- /** Set to true to enable assertions on WARNING messages. */
- bool warning_assert;
-};
-/* Forward declaration in hal/hle/forward.h. */
-
-#endif /* hal_hle_maximus_inc_maximus_ipmbox_context_h */
diff --git a/cesar/hal/hle/maximus/src/maximus_ipmbox.c b/cesar/hal/hle/maximus/src/maximus_ipmbox.c
deleted file mode 100644
index 5f66c4bb1e..0000000000
--- a/cesar/hal/hle/maximus/src/maximus_ipmbox.c
+++ /dev/null
@@ -1,337 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/maximus/src/maximus_ipmbox.c
- * \brief HAL HLE functions for Maximus.
- * \ingroup hal_hle_maximus
- */
-
-#include "common/std.h"
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...' and 'ipmbox_msg_hdr_t'
-#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h"
-#include "hal/hle/maximus/inc/maximus_ether.h" // for 'maximus_ether_recv()'
-#include "hal/hle/maximus/inc/maximus_defs.h" // for 'MAXIMUS_MAILBOX_MAX_SIZE'
-#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX' and 'HAL_HLE_INTERRUPT_PRIORITY'
-#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
-#include "host/station/station.h" // for 'station_log()'
-#include "ecos/packages/hal/maximus/arch/current/include/hal_host_intr.h"
-#include <string.h> // for 'memset'
-#include <stdlib.h> // for 'free'
-#include <errno.h>
-
-#include "interface/sniffer/mmtype.h"
-#include "common/defs/homeplugAV.h"
-
-#ifdef ECOS
-static cyg_uint32 _ipmbox_ecos_isr(cyg_vector_t vector, cyg_addrword_t data)
-{
- cyg_drv_interrupt_mask(HAL_HLE_INTERRUPT_IPMBOX);
- cyg_drv_interrupt_acknowledge(HAL_HLE_INTERRUPT_IPMBOX);
- return CYG_ISR_CALL_DSR; // cause DSR to be run
-}
-
-static void _ipmbox_ecos_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
-{
- /* nothing to do except calling the hle dsr */
- ipmbox_t *ctx = (ipmbox_t *)data;
- dbg_assert_ptr(ctx);
- dbg_assert_ptr(ctx->rx_cb);
- dbg_assert_ptr(ctx->user_data);
- if ((NULL != ctx)
- && (NULL != ctx->rx_cb)
- && (NULL != ctx->user_data))
- {
- (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
- // reset total length of messages
- ctx->rx.length = 0;
- }
- cyg_drv_interrupt_unmask(HAL_HLE_INTERRUPT_IPMBOX);
- return;
-}
-#endif /* ECOS */
-
-/**
- * Initialise the HAL HLE.
- * \param user_data user data passed to any callback
- * \param rx_cb RX DSR callback, callback used when an Ethernet packet is received
- * \return the newly created context
- * set errno to:
- * - EINVAL if user_data or rx_cb are null
- */
-ipmbox_t *
-ipmbox_init (void *user_data, ipmbox_rx_cb_t rx_cb)
-{
- static ipmbox_t ctx;
- static maximus_hle_buffer_t first_buffer;
-
- dbg_assert_ptr(user_data);
- dbg_assert_ptr(rx_cb);
- if ((NULL == user_data)
- || (NULL == rx_cb))
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
- memset(&ctx, '\0', sizeof(ipmbox_t));
- ctx.user_data = user_data;
- ctx.rx_cb = rx_cb;
-
- // initialize linked list of allocated buffers
- ctx.first_buffer = &first_buffer;
- ctx.first_buffer->next = NULL;
- ctx.first_buffer->id = 0;
- ctx.first_buffer->data = NULL;
- ctx.last_buffer = ctx.first_buffer;
-
- // register ether_recv to the sci layer
- sci_register_callback(my_station.sci, SCI_MSG_TYPE_ETHERNET, maximus_ether_recv, &ctx);
-
-#ifdef ECOS
- // register the ipmbox ISR and DSR into eCos
- cyg_drv_interrupt_create(HAL_HLE_INTERRUPT_IPMBOX,
- HAL_HLE_INTERRUPT_PRIORITY,
- (cyg_addrword_t)&ctx,
- _ipmbox_ecos_isr,
- _ipmbox_ecos_dsr,
- &ctx.ipmbox_interrupt_handle,
- &ctx.ipmbox_interrupt);
- cyg_drv_interrupt_attach(ctx.ipmbox_interrupt_handle);
- cyg_drv_interrupt_mask(HAL_HLE_INTERRUPT_IPMBOX);
-#endif /* ECOS */
- }
-
- return &ctx;
-}
-
-/**
- * Activate ipmbox interruptions.
- * \param ctx ipmbox context
- * \param activation indicates if interruptions are activated or deactivated
- * set errno to:
- * - EINVAL if ctx is NULL
- */
-void
-ipmbox_activate (ipmbox_t *ctx, bool activation)
-{
- dbg_assert_ptr(ctx);
- if (NULL == ctx)
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
-#ifdef ECOS
- if (activation)
- {
- cyg_drv_interrupt_unmask(HAL_HLE_INTERRUPT_IPMBOX);
- }
- else
- {
- cyg_drv_interrupt_mask(HAL_HLE_INTERRUPT_IPMBOX);
- }
-#endif /* ECOS */
- }
-}
-
-/**
- * Uninitialise the HAL HLE.
- * \param ctx ipmbox context
- * set errno to:
- * - EINVAL if ctx is NULL
- */
-void
-ipmbox_uninit (ipmbox_t *ctx)
-{
- dbg_assert_ptr(ctx);
- if (NULL == ctx)
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
- // release allocated buffers
- maximus_hle_buffer_t *current_buffer = ctx->first_buffer->next;
- maximus_hle_buffer_t *next_buffer = NULL;
- while (NULL != current_buffer)
- {
- next_buffer = current_buffer->next;
- free(current_buffer->data);
- free(current_buffer);
- current_buffer = next_buffer;
- }
-
- // reset ipmbox context
- memset(ctx, '\0', sizeof(ipmbox_t));
- }
-}
-
-/**
- * Transmit an Ethernet packet.
- * \param ctx ipmbox context
- * \param first_msg pointer to the first received message header
- * \param length total length (in word) of messages to transmit
- * set errno to:
- * - EINVAL if ctx or first_msg are null, if length is incorrect, or if first_msg values are incorrect
- */
-void
-ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
-{
- dbg_assert_ptr(ctx);
- dbg_assert_ptr(first_msg);
- dbg_assert(2 == length);
- if ((NULL == ctx)
- || (NULL == first_msg)
- || (2 != length))
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
- ipmbox_msg_hdr_t hdr = *(ipmbox_msg_hdr_t *)first_msg;
- dbg_assert(HLE_MSG_TYPE_BASE_NB > hdr.type);
- dbg_assert(1 == hdr.length);
- if ((HLE_MSG_TYPE_BASE_NB <= hdr.type)
- || (1 != hdr.length))
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
- if ((HLE_MSG_TYPE_DATA == hdr.type)
- || (HLE_MSG_TYPE_INTERFACE == hdr.type))
- {
- // to send message
- u8 type = ETHERNET_TYPE_NONE;
- u8 flags = ETHERNET_FLAG_NONE;
- uint data_length = 0;
- u32 data = 0;
-
- // to release buffer
- bool found = false;
- maximus_hle_buffer_t *current_buffer = ctx->first_buffer;
- maximus_hle_buffer_t *previous_buffer = current_buffer;
-
- if (HLE_MSG_TYPE_DATA == hdr.type)
- {
- // get type (1 bit): DATA or MME type
- // 0: DATA type
- // 1: MME type
- if (0 == (u8)(hdr.param & 0x00001))
- {
- type = ETHERNET_TYPE_DATA;
- }
- else // (1 == (u8)(hdr.param & 0x001))
- {
- type = ETHERNET_TYPE_MME;
- }
-
- // get DATA or MME length (11 bits): length of data into DATA or MME buffer
- data_length = (uint)((hdr.param & 0x00FFE) >> 1);
-
- // get buffer pointer (32 bits): pointer to DATA or MME buffer
- data = *(first_msg + 1);
- }
-
- else // (HLE_MSG_TYPE_INTERFACE == hdr.type)
- {
- int data_index = 1;
-
- // get data length (11 bits): length of data into buffer
- data_length = (uint)((hdr.param & 0x7FF00) >> 8);
-
- // get buffer pointer (32 bits): pointer to buffer
- data = *(first_msg + data_index);
- type = ETHERNET_TYPE_SNIFFER;
- }
-
- // send DATA, MME or SNIFFER (sniffed Beacon or MME) to Maximus
- if (0 != maximus_ether_send(ctx, type, flags, data_length, (u32 *)data))
- {
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- dbg_assert_print(false, "errno = %d when transmitting an Ethernet or a sniffed packet", errno);
- }
-
- // check that this pointer is still allocated
- while ((NULL != current_buffer->next) && !found)
- {
- previous_buffer = current_buffer;
- current_buffer = current_buffer->next;
- found = (data == (u32)current_buffer->data); // pointer to buffer to release
- }
- dbg_assert(found);
- if (!found)
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- else
- {
- // for BUFFER RELEASED message
- u32 id = current_buffer->id;
-
- // before deallocating buffer, link previous to next,
- // and update last buffer if needed
- previous_buffer->next = current_buffer->next;
- if (current_buffer == ctx->last_buffer)
- {
- ctx->last_buffer = previous_buffer;
- }
- free(current_buffer->data);
- free(current_buffer);
-
- // send BUFFER RELEASED to Maximus
- if (0 != maximus_ether_send(ctx, ETHERNET_TYPE_BUFFER_RELEASED, ETHERNET_FLAG_NONE, sizeof(u32), &id))
- {
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- dbg_assert_print(false, "errno = %d when transmitting an Ethernet packet", errno);
- }
- }
- }
- else if (HLE_MSG_TYPE_SEND_DONE == hdr.type)
- {
- // get buffer pointer (32 bits): pointer to buffer to release
- u32 *data = (u32 *)(*(first_msg + 1));
-
- // deallocate buffer
- dbg_assert_ptr(data);
- if (NULL != data)
- {
- free(data);
- }
- else
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- }
- }
- else // (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
- {
- errno = EINVAL;
- station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
- "%s: errno = %d", __FUNCTION__, errno);
- dbg_assert_print(false, "errno = %d because cannot transmit an Ethernet packet of type BUFFER_ADD", errno);
- }
- }
- }
-}
diff --git a/cesar/hal/hle/maximus/test/inc/test_maximus_hle.h b/cesar/hal/hle/maximus/test/inc/test_maximus_hle.h
deleted file mode 100644
index a2999d606c..0000000000
--- a/cesar/hal/hle/maximus/test/inc/test_maximus_hle.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef hal_hle_maximus_test_inc_test_maximus_hle_h
-#define hal_hle_maximus_test_inc_test_maximus_hle_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/maximus/test/inc/test_maximus_hle.h
- * \brief test header for Maximus.
- * \ingroup hal_hle_maximus
- */
-
-#include "host/fwd.h" // for 'station_ctx_t'
-
-/**
- * RX DSR callback function.
- * \param user_data user data
- * \param first_msg pointer to the first received message header
- * \param length total length (in word) of received messages
- * \return true if a DSR is requested
- */
-void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length);
-
-/**
- * Open pipe or socket.
- * \param station pointer to the station context
- * \return file descriptor for pipe or socket
- */
-int
-maximus_ether_open (station_ctx_t *station);
-
-/**
- * Close pipe.
- * \param fd file descriptor for pipe or socket
- */
-void
-maximus_ether_close (int fd);
-
-#endif /* hal_hle_maximus_test_inc_test_maximus_hle_h */
diff --git a/cesar/hal/hle/maximus/test/src/test_maximus_hle.c b/cesar/hal/hle/maximus/test/src/test_maximus_hle.c
deleted file mode 100644
index 4e88254d34..0000000000
--- a/cesar/hal/hle/maximus/test/src/test_maximus_hle.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/maximus/test/src/test_maximus_hle.c
- * \brief HAL HLE main test function for Maximus.
- * \ingroup hal_hle_maximus
- */
-
-#include "common/std.h"
-#include "lib/test.h"
-#include "host/station/station.h" // for 'station_ctx_t'
-#include <unistd.h> // for 'open()' and 'close()'
-#include <fcntl.h> // for 'open()' and 'close()'
-
-void ipmbox_test_suite (test_t t);
-void ether_test_suite (test_t t);
-
-uint32_t maximus_pending_isrs;
-station_ctx_t my_station;
-
-void
-ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
-{
- int *my_data = (int *)user_data;
- *my_data = 987654321;
- return;
-}
-
-int
-maximus_ether_open (station_ctx_t *station)
-{
- int fd;
-
- #ifdef STATION_SOCK
- fd = station->sock_pair_fd;
- #else /* STATION_SOCK */
- fd = open(station->pipe_out_name, O_RDONLY);
- #endif /* STATION_SOCK */
-
- return fd;
-}
-
-void
-maximus_ether_close (int fd)
-{
- #ifndef STATION_SOCK
- close(fd);
- #endif /* !STATION_SOCK */
-}
-
-int
-main (int argc, char **argv)
-{
- test_t t;
- test_init(t, argc, argv);
-
- ether_test_suite(t);
- ipmbox_test_suite(t);
-
- test_result(t);
- return test_nb_failed(t) == 0 ? 0 : 1;
-}
diff --git a/cesar/hal/hle/maximus/test/src/test_maximus_ipmbox.c b/cesar/hal/hle/maximus/test/src/test_maximus_ipmbox.c
deleted file mode 100644
index 98ae2f38ea..0000000000
--- a/cesar/hal/hle/maximus/test/src/test_maximus_ipmbox.c
+++ /dev/null
@@ -1,394 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/maximus/test/src/test_maximus_ipmbox.c
- * \brief HAL HLE ipmbox test functions for Maximus.
- * \ingroup hal_hle_maximus
- */
-
-#include "common/std.h"
-#include "lib/test.h"
-#include "hal/hle/maximus/test/inc/test_maximus_hle.h"
-#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...' and 'ipmbox_msg_hdr_t'
-#include "host/station/station.h" // for 'station_ctx_t'
-#include "host/fwd.h" // for 'sci_msg_t'
-#include "maximus/common/types/ethernet_types.h" // for 'ether_msg_hdr_t'
-#include <stdio.h> // for 'printf'
-#include <string.h> // for 'memset'
-#include <unistd.h> // for 'read'
-#include <fcntl.h> // for 'read'
-#include <stdlib.h> // for 'malloc'
-#include <errno.h>
-
-extern uint32_t maximus_pending_isrs; // used in 'station.c'
-extern station_ctx_t my_station;
-ipmbox_t *ctx;
-
-void ipmbox_init_test_case(test_t t)
-{
- int user_data = 123456789;
-
- printf("init\n");
- test_case_begin(t, "init");
-
- test_begin(t, "init")
- {
- ctx = ipmbox_init ((void *)&user_data, &ipmbox_rx_cb);
- test_fail_unless ((EINVAL != errno)
- && (NULL != ctx)
- && (user_data == *((int *)ctx->user_data))
- && (&ipmbox_rx_cb == ctx->rx_cb)
- && (NULL != ctx->first_buffer)
- && (NULL == ctx->first_buffer->next)
- && (0 == ctx->first_buffer->id)
- && (NULL == ctx->first_buffer->data)
- && (ctx->last_buffer == ctx->first_buffer)
- && (0 == ctx->rx.length));
- ctx->warning_assert = true;
- } test_end;
-
- test_begin(t, "rx cb")
- {
- (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
- test_fail_unless (987654321 == *((int *)ctx->user_data));
- } test_end;
-
- maximus_pending_isrs = 0;
- ctx->rx.length = 0;
-
- return;
-}
-
-void ipmbox_activate_test_case(test_t t)
-{
- printf("activate\n");
- test_case_begin(t, "activate");
-
- test_begin(t, "NULL ipmbox")
- {
- dbg_fatal_try_begin
- {
- ipmbox_activate (NULL, false);
- test_fail_unless (EINVAL == errno);
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("NULL ipmbox\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
-
- // reset errno
- errno = 0;
- } test_end;
-
- test_begin(t, "activate")
- {
- ipmbox_activate (ctx, true);
- test_fail_unless (EINVAL != errno);
- } test_end;
-
- return;
-}
-
-void ipmbox_uninit_test_case(test_t t)
-{
- printf("uninit\n");
- test_case_begin(t, "uninit");
-
- test_begin(t, "uninit")
- {
- ipmbox_uninit(ctx);
- test_fail_unless (EINVAL != errno);
- } test_end;
-
- return;
-}
-
-void ipmbox_tx_test_case(test_t t)
-{
- // ethernet frame data
- int frame_length = 1200;
- u8 frame[1200];
- memset(frame, '\0', frame_length); // init frame
-
- // mailbox msg
- ipmbox_msg_hdr_t hdr;
- u32 mailbox[3];
- uint length = 2; // init length
- hdr.type = HLE_MSG_TYPE_NONE; // init hdr type
- hdr.length = 1; // init hdr length
- hdr.param = 0; // init hdr param
- memset(mailbox, '\0', 3 * sizeof(u32)); // init mailbox
-
- printf("tx\n");
- test_case_begin(t, "tx");
-
- test_begin(t, "tx none")
- {
- dbg_fatal_try_begin
- {
- // set mailbox
- memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
-
- ipmbox_tx (ctx, mailbox, length);
- test_fail_unless (EINVAL == errno);
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("tx none\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
-
- // reset errno
- errno = 0;
- } test_end;
-
- for (hdr.type = HLE_MSG_TYPE_DATA; hdr.type < HLE_MSG_TYPE_BASE_NB; hdr.type++)
- {
- /* Fill sci data. */
-
- // hle type data or hle type interface
- if ((HLE_MSG_TYPE_DATA == hdr.type) || (HLE_MSG_TYPE_INTERFACE == hdr.type))
- {
- int i;
- maximus_hle_buffer_t *second_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
- second_buffer->next = NULL;
- second_buffer->id = 32;
- second_buffer->data = (u32 *)malloc(frame_length);
- for (i=0; i<frame_length; i++)
- {
- frame[i] = (u8)i;
- *((u8*)second_buffer->data+i) = frame[i];
- }
- ctx->first_buffer->next = second_buffer;
-
- if (HLE_MSG_TYPE_DATA == hdr.type)
- {
- // set hdr param
- hdr.param = frame_length << 1;
- }
- else // (HLE_MSG_TYPE_INTERFACE == hdr.type)
- {
- // set hdr length
- hdr.length = 1;
-
- // set hdr param
- hdr.param = frame_length << 8; // data length
- hdr.param |= 1; // module type
- }
-
- // set mailbox
- memcpy(&mailbox[0], &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
- mailbox[1] = (u32)second_buffer->data; // set data
-
- test_begin(t, "tx data or interface")
- {
- ipmbox_tx (ctx, mailbox, length);
- test_fail_unless (EINVAL != errno);
- } test_end;
- }
-
- // hle type buffer add
- else if (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
- {
- // set mailbox
- memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
-
- test_begin(t, "tx buffer add")
- {
- dbg_fatal_try_begin
- {
- // set mailbox
- memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
-
- ipmbox_tx(ctx, mailbox, length);
- test_fail_unless (EINVAL == errno);
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("tx buffer add\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
-
- // reset errno
- errno = 0;
- } test_end;
- }
-
- // hle type send done
- else if (HLE_MSG_TYPE_SEND_DONE == hdr.type)
- {
- test_begin(t, "tx send done")
- {
- // allocate buffer
- u32 *data = (u32 *)malloc(1500);
-
- // set mailbox
- memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
- mailbox[1] = (u32)data;
-
- ipmbox_tx(ctx, mailbox, length);
- test_fail_unless (EINVAL != errno);
- } test_end;
- }
-
- /* Check results. */
-
- // hle type data
- if (HLE_MSG_TYPE_DATA == hdr.type)
- {
- // check that the correct ether message has been sent to Maximus
- test_begin(t, "ether message DATA")
- {
- unsigned char buffer[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
- ether_msg_hdr_t *ether_hdr;
- int fd_in = -1;
-
- // open pipe or socket
- fd_in = maximus_ether_open(&my_station);
-
- // read sci and ether headers
- memset(buffer, '\0', SCI_MSG_MAX_SIZE);
- test_fail_unless ((-1 != fd_in)
- && (sizeof(sci_msg_hdr_t) == read(fd_in, buffer, sizeof(sci_msg_hdr_t)))
- && (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
-
- // set sci and ether headers pointers
- sci_hdr = (sci_msg_hdr_t *)buffer;
- ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
-
- // check ether header
- test_fail_unless ((ETHERNET_TYPE_DATA == ether_hdr->type)
- && (ETHERNET_FLAG_NONE == ether_hdr->flags));
-
- // read the remaining part of message
- test_fail_unless (frame_length == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
-
- // check ether data
- test_fail_unless (0 == memcmp(frame, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
-
- // close pipe
- maximus_ether_close(fd_in);
- } test_end;
- }
-
- // hle type buffer add
- else if (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
- {
- // nothing to check
- }
-
- // hle type send done
- else if (HLE_MSG_TYPE_SEND_DONE == hdr.type)
- {
- // check that the allocated buffer has been released
- test_begin(t, "SEND DONE")
- {
- test_fail_unless (NULL == (u32 *)ctx->rx.mailbox[1]);
- } test_end;
- }
-
- // hle type interface
- else // HLE_MSG_TYPE_INTERFACE
- {
- // check that the correct ether message has been sent to Maximus
- test_begin(t, "ether message SNIFFER")
- {
- unsigned char buffer[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
- ether_msg_hdr_t *ether_hdr;
- int fd_in = -1;
-
- // open pipe or socket
- fd_in = maximus_ether_open(&my_station);
-
- // read sci and ether headers
- memset(buffer, '\0', SCI_MSG_MAX_SIZE);
- test_fail_unless ((-1 != fd_in)
- && (sizeof(sci_msg_hdr_t) == read(fd_in, buffer, sizeof(sci_msg_hdr_t)))
- && (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
-
- // set sci and ether headers pointers
- sci_hdr = (sci_msg_hdr_t *)buffer;
- ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
-
- // check ether header
- test_fail_unless ((ETHERNET_TYPE_SNIFFER == ether_hdr->type)
- && (ETHERNET_FLAG_MAX == ether_hdr->flags));
-
- // read the remaining part of message
- test_fail_unless (frame_length == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
-
- // check ether data
- test_fail_unless (0 == memcmp(frame, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
-
- // close pipe
- maximus_ether_close(fd_in);
- } test_end;
- }
-
- // hle type data or hle type interface
- if ((HLE_MSG_TYPE_DATA == hdr.type) || (HLE_MSG_TYPE_INTERFACE == hdr.type))
- {
- test_begin(t, "ether message BUFFER RELEASED")
- {
- unsigned char buffer[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
- ether_msg_hdr_t *ether_hdr;
- int fd_in = -1;
-
- // open pipe or socket
- fd_in = maximus_ether_open(&my_station);
-
- // read sci and ether headers
- memset(buffer, '\0', SCI_MSG_MAX_SIZE);
- test_fail_unless ((-1 != fd_in)
- && (sizeof(sci_msg_hdr_t) == read(fd_in, buffer, sizeof(sci_msg_hdr_t)))
- && (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
-
- // set sci and ether headers pointers
- sci_hdr = (sci_msg_hdr_t *)buffer;
- ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
-
- // check ether header
- test_fail_unless ((ETHERNET_TYPE_BUFFER_RELEASED == ether_hdr->type)
- && (ETHERNET_FLAG_NONE == ether_hdr->flags));
-
- // read the remaining part of message
- test_fail_unless (sizeof(u32) == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), sizeof(u32)));
-
- // check ether data
- test_fail_unless (32 == *(buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t)));
-
- // close pipe
- maximus_ether_close(fd_in);
- } test_end;
- }
- }
-}
-
-void ipmbox_test_suite(test_t t)
-{
- // reset errno
- errno = 0;
-
- station_init (&my_station);
- station_log_set_level(&my_station, STATION_LOG_DEBUG);
- station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
-
- test_suite_begin(t, "ipmbox");
- ipmbox_init_test_case(t);
- ipmbox_activate_test_case(t);
- ipmbox_tx_test_case(t);
- ipmbox_uninit_test_case(t);
-
- station_down (&my_station);
-}
diff --git a/cesar/hal/hle/src/hal_ipmbox.c b/cesar/hal/hle/src/hal_ipmbox.c
deleted file mode 100644
index f9d5ee9d11..0000000000
--- a/cesar/hal/hle/src/hal_ipmbox.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/src/hal_ipmbox.c
- * \brief HAL HLE hal layer.
- * \ingroup hal_hle
- *
- * this layer provide all Hardware Abstraction:
- * registers, Gidel memory, interrupts.
- */
-
-#include "common/std.h"
-
-#include "hal/hle/inc/hal_ipmbox.h"
-
-/** Hardware pointers definition */
-static volatile u32 *A2L_ptr;
-static volatile u32 *L2A_ptr;
-
-void
-halmbx_copy_to_ring (u32 *message, uint size)
-{
- dbg_assert (message);
- dbg_assert (size);
- dbg_assert (L2A_RING_WORDS - L2A_RING_USED_WORDS (L2A_HEAD, L2A_TAIL)
- > size);
- /* Copy the message into the mailbox ring. */
- volatile u32 *tail = (volatile u32 *) L2A_TAIL;
- volatile u32 *end = L2A_ptr + L2A_RING_WORDS;
- while (size--)
- {
- *tail++ = *message++;
- /* Ring roll over. */
- if (tail == end)
- tail = L2A_ptr;
- }
- /* Update the TAIL pointer. */
- L2A_TAIL = (u32) tail;
- /* Trigger interrupt. */
- set_L2At_interrupt ();
-}
-
-void
-halmbx_copy_from_ring (u32 *message, uint size)
-{
- dbg_assert (message);
- dbg_assert (size);
- /* Copy the message from the mailbox ring. */
- volatile u32 *head = (volatile u32 *) A2L_HEAD;
- volatile u32 *end = A2L_ptr + A2L_RING_WORDS;
- while (size--)
- {
- *message++ = *head++;
- /* Ring roll over. */
- if (head == end)
- head = A2L_ptr;
- }
- /* Update the HEAD pointer. */
- A2L_HEAD = (u32) head;
- /* Trigger acknowledge interrupt. */
- set_A2La_interrupt ();
-}
-
-void
-halmbx_init (void)
-{
- //ARM Mailboxes registers already configure
- //so just find the corresponding ring_base_addr
- u32 A2L_ring_base_addr = A2L_TAIL & ~A2L_RING_MASK;
- A2L_HEAD = A2L_ring_base_addr;
- u32 L2A_ring_base_addr = L2A_HEAD & ~L2A_RING_MASK;
- L2A_TAIL = L2A_ring_base_addr;
-
- /* Initialize ring pointers. */
- A2L_ptr = (u32*) A2L_ring_base_addr;
- L2A_ptr = (u32*) L2A_ring_base_addr;
-}
-
diff --git a/cesar/hal/hle/src/ipmbox.c b/cesar/hal/hle/src/ipmbox.c
deleted file mode 100644
index 5cb0bad35e..0000000000
--- a/cesar/hal/hle/src/ipmbox.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/src/ipmbox.c
- * \brief HAL HLE mailbox layer.
- * \ingroup hal_hle
- *
- * this layer provide all mechanisms to manage mailboxes.
- */
-
-#include "common/std.h"
-
-#include "hal/hle/inc/hal_ipmbox.h"
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/inc/ipmbox.h"
-#include "hal/hle/defs.h"
-#include "hal/arch/arch.h"
-
-/** Rx Mailbox interrupt number */
-#define MAILBOX_RX_IT_NUM CYGNUM_HAL_INTERRUPT_GIC2_14
-
-/** RX budget. Number of words which can be handled in one execution.
- * Warning: this works if all messages have the same size because input
- * mailbox will be cut without analysis. */
-#define MAILBOX_RX_BUDGET 128
-
-/** Global context variable */
-static ipmbox_t context;
-/** Ipmbox Rx buffer */
-static u32 rx_msgs[A2L_RING_WORDS];
-
-/**
- * Activate ipmbox interruptions.
- * \param ctx ipmbox context
- * \param activation indicates if interruptions are activated or deactivated
- */
-void ipmbox_activate (ipmbox_t *ctx, bool activation)
-{
- if(activation)
- {
- //Unmask receive interrupt.
- A2Lt_it_enable();
- }
- else
- {
- //Mask receive interrupt.
- A2Lt_it_disable();
- }
-}
-
-/**
- * Transmit a message to mailbox.
- * \param ctx ipmbox context
- * \param first_msg pointer to the first received message header
- * \param length total length (in word) of messages to transmit
- */
-void
-ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
-{
- /* Check args. */
- dbg_assert (ctx);
- dbg_assert (first_msg);
- dbg_assert (length != 0);
- /* Copy messages to the ring buffer, lock DSR to prevent mailbox
- * corruption. */
- arch_dsr_lock ();
- halmbx_copy_to_ring (first_msg, length);
- arch_dsr_unlock ();
-}
-
-/**
- * Mailbox receive ISR handler function.
- * \param vector interrupt vector number
- * \param data user interrupt arguments
- * \return isr status and if DSR is needed
- */
-cyg_uint32 mailbox_rx_isr (cyg_vector_t vector, cyg_addrword_t data)
-{
- //Block this interrupt from occurring until the DSR completes.
- A2Lt_it_disable ();
- //Acknowledge interrupt (because of shared child interrupt).
- ipmbox_interrupt_acknowledge (MAILBOX_RX_IT_NUM);
-
- //Tell the kernel that chained interrupt processing is done and the DSR needs to be executed next.
- return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
-}
-
-/**
- * Mailbox receive DSR handler function.
- * \param vector interrupt vector number
- * \param count ?
- * \param data user interrupt arguments
- */
-void mailbox_rx_dsr (cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
-{
- ipmbox_t *ctx = (ipmbox_t*) data;
- uint budget = MAILBOX_RX_BUDGET;
- uint size;
-
- do
- {
- /* Clear interrupt. */
- clr_A2Lt_interrupt ();
-
- /* Try to slurp all RX queue. */
- size = A2L_RING_USED_WORDS (A2L_HEAD, A2L_TAIL);
- if (size)
- {
- /* Check and update budget. */
- if (budget == 0)
- {
- /* Ask to be executed again, do not activate interrupts. */
- cyg_interrupt_post_dsr (ctx->rx_it_handle);
- return;
- }
- if (size > budget)
- size = budget;
- budget -= size;
- /* Copy messages out of mailbox, because callback can not handle
- * circular buffers. */
- halmbx_copy_from_ring (rx_msgs, size);
- /* Send all received messages to the upper layer. */
- ctx->rx_cb (ctx->rx_cb_user_data, rx_msgs, size);
- }
- } while (size);
-
- /* Allow this interrupt to occur again. */
- A2Lt_it_enable ();
-}
-
-uint
-ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg)
-{
- uint size;
- /* Only if interrupt set. */
- if (get_A2Lt_interrupt ())
- {
- /* Clear interrupt. */
- clr_A2Lt_interrupt ();
- /* Try to slurp all RX queue. */
- size = A2L_RING_USED_WORDS (A2L_HEAD, A2L_TAIL);
- if (size)
- {
- /* Copy messages out of mailbox, because callback can not handle
- * circular buffers. */
- halmbx_copy_from_ring (rx_msgs, size);
- /* Return received messages. */
- *first_msg = rx_msgs;
- return size;
- }
- }
- /* Nothing. */
- return 0;
-}
-
-/**
- * Uninitialise the HAL HLE.
- * \param ctx ipmbox context
- */
-void ipmbox_uninit (ipmbox_t *ctx)
-{
- //Stop all mailbox interrupts.
- L2Aa_it_disable();
- A2Lt_it_disable();
-
- /* Mask. */
- cyg_drv_interrupt_mask (MAILBOX_RX_IT_NUM);
-}
-
-/**
- * Initialise the HAL HLE.
- * \param user_data user data passed to any callback
- * \param rx_cb RX DSR callback, callback used when an Ethernet packet is received
- * \return the newly created context
- */
-ipmbox_t * ipmbox_init (void *user_data, ipmbox_rx_cb_t rx_cb)
-{
- ipmbox_t *ctx = &context;
-
- //Check args.
- dbg_assert(rx_cb);
-
- //Store user informations.
- ctx->rx_cb_user_data = user_data;
- ctx->rx_cb = rx_cb;
-
- //Stop all mailbox interrupts.
- L2Aa_it_disable();
- A2Lt_it_disable();
-
- //Create interrupt for Rx messages.
- cyg_drv_interrupt_create (MAILBOX_RX_IT_NUM,
- 0,
- (cyg_addrword_t) ctx,
- &mailbox_rx_isr,
- &mailbox_rx_dsr,
- &ctx->rx_it_handle,
- &ctx->rx_it);
-
- //Initialize Hardware.
- halmbx_init();
-
- //Attach this interrupt.
- cyg_drv_interrupt_attach (ctx->rx_it_handle);
-
- /* Unmask. */
- cyg_drv_interrupt_unmask (MAILBOX_RX_IT_NUM);
-
- return ctx;
-}
-
diff --git a/cesar/hal/hle/test/Makefile b/cesar/hal/hle/test/Makefile
deleted file mode 100644
index 1331a7223f..0000000000
--- a/cesar/hal/hle/test/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-BASE = ../../..
-
-DEFS = -DHAL_HLE_IPMBOX_UNIT_TEST
-
-#ECOS = y
-#TARGET_PROGRAMS = hal_hle_hal_ipmbox hal_hle_ipmbox
-HOST_PROGRAMS = hal_hle_hal_ipmbox hal_hle_ipmbox
-
-hal_hle_hal_ipmbox_SOURCES = hal_hle_hal_ipmbox.c
-hal_hle_hal_ipmbox_MODULES = lib hal/hle
-
-hal_hle_ipmbox_SOURCES = hal_hle_ipmbox.c
-hal_hle_ipmbox_MODULES = lib hal/hle
-
-include $(BASE)/common/make/top.mk
diff --git a/cesar/hal/hle/test/src/hal_hle_hal_ipmbox.c b/cesar/hal/hle/test/src/hal_hle_hal_ipmbox.c
deleted file mode 100644
index bb7d6a74df..0000000000
--- a/cesar/hal/hle/test/src/hal_hle_hal_ipmbox.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/test/hal_hle_hal_ipmbox.c
- * \brief HAL HLE unit test to test the hal hle access register.
- * \ingroup hal_hle
- *
- * This file will tests all registers access so mask/unmask a bit in a
- * register set/clear a bit in a register...
- * But also status in the ring, copy from/to the ring...
- */
-#include "common/std.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "lib/test.h"
-
-#include "hal/hle/inc/hal_ipmbox.h"
-#include "hal/hle/inc/reg_ipmbox.h"
-
-u32 A2L_ring[A2L_RING_WORDS] __attribute__ ((aligned (A2L_RING_SIZE)));
-u32 L2A_ring[L2A_RING_WORDS] __attribute__ ((aligned (L2A_RING_SIZE)));
-
-u32 utest_A2L_head;
-u32 utest_A2L_tail;
-u32 utest_L2A_head;
-u32 utest_L2A_tail;
-u32 utest_A2L_it;
-u32 utest_L2A_it;
-u32 utest_A2L_it_mask;
-
-bool dsr_posted;
-
-void test_halmbx_init(test_t test)
-{
- test_begin (test, "halmbx_init test")
- {
- utest_A2L_tail = (u32) A2L_ring;
- utest_L2A_head = (u32) L2A_ring;
- utest_A2L_head = 0xDEADBEEF;
- utest_L2A_tail = 0xDEADBEEF;
- halmbx_init();
- test_fail_if(utest_A2L_head != A2L_RING_BASE_ADDR, "Error checking init");
- test_fail_if(utest_L2A_tail != L2A_RING_BASE_ADDR, "Error checking init");
- }
- test_end;
-}
-
-void test_set_L2At_interrupt(test_t test)
-{
- test_begin (test, "set_L2At_interrupt test")
- {
- utest_L2A_it = 0;
- set_L2At_interrupt();
- test_fail_if(utest_L2A_it != 0x01, "L2A trigger not set");
- utest_L2A_it = 3;
- set_L2At_interrupt();
- test_fail_if(utest_L2A_it != 0x03, "L2A trigger not set");
- }
- test_end;
-}
-
-void test_set_A2La_interrupt(test_t test)
-{
- test_begin (test, "set_A2La_interrupt test")
- {
- utest_L2A_it = 0;
- set_A2La_interrupt();
- test_fail_if(utest_L2A_it != 0x02, "A2L acknowledge not set");
- utest_L2A_it = 3;
- set_A2La_interrupt();
- test_fail_if(utest_L2A_it != 0x03, "A2L acknowledge not set");
- }
- test_end;
-}
-
-void test_clr_A2Lt_interrupt(test_t test)
-{
- test_begin (test, "clear_A2Lt_interrupt test")
- {
- utest_A2L_it = 1;
- clr_A2Lt_interrupt();
- test_fail_if(utest_A2L_it != 0x01, "A2L trigger not set");
- utest_A2L_it = 2;
- clr_A2Lt_interrupt();
- test_fail_if(utest_A2L_it != 0x01, "A2L trigger not set");
- }
- test_end;
-}
-
-void test_clr_L2Aa_interrupt(test_t test)
-{
- test_begin (test, "clear_L2Aa_interrupt test")
- {
- utest_A2L_it = 2;
- clr_L2Aa_interrupt();
- test_fail_if(utest_A2L_it != 0x02, "L2A acknowledge not set");
- utest_A2L_it = 1;
- clr_L2Aa_interrupt();
- test_fail_if(utest_A2L_it != 0x02, "L2A acknowledge not set");
- }
- test_end;
-}
-
-void test_L2Aa_it_enable(test_t test)
-{
- test_begin (test, " test_L2Aa_it_enable test")
- {
- utest_A2L_it_mask = 2;
- L2Aa_it_enable();
- test_fail_if(utest_A2L_it_mask != 0x00, "L2A acknowledge not enable");
- utest_A2L_it_mask = 1;
- L2Aa_it_enable();
- test_fail_if(utest_A2L_it_mask != 0x01, "L2A acknowledge not enable");
- }
- test_end;
-}
-
-void test_A2Lt_it_enable(test_t test)
-{
- test_begin (test, " test_A2Lt_it_enable test")
- {
- utest_A2L_it_mask = 1;
- A2Lt_it_enable();
- test_fail_if(utest_A2L_it_mask != 0x00, "A2L trigger not enable");
- utest_A2L_it_mask = 2;
- A2Lt_it_enable();
- test_fail_if(utest_A2L_it_mask != 0x02, "A2L trigger not enable");
- }
- test_end;
-}
-
-void test_L2Aa_it_disable(test_t test)
-{
- test_begin (test, " test_L2Aa_it_disable test")
- {
- utest_A2L_it_mask = 0;
- L2Aa_it_disable();
- test_fail_if(utest_A2L_it_mask != 0x02, "L2A acknowledge not disable");
- utest_A2L_it_mask = 3;
- L2Aa_it_disable();
- test_fail_if(utest_A2L_it_mask != 0x03, "L2A acknowledge not disable");
- }
- test_end;
-}
-
-void test_A2Lt_it_disable(test_t test)
-{
- test_begin (test, " test_A2Lt_it_disable test")
- {
- utest_A2L_it_mask = 0;
- A2Lt_it_disable();
- test_fail_if(utest_A2L_it_mask != 0x01, "A2L trigger not disable");
- utest_A2L_it_mask = 3;
- A2Lt_it_disable();
- test_fail_if(utest_A2L_it_mask != 0x03, "A2L trigger not disable");
- }
- test_end;
-}
-
-void test_halmbx_copy_to_ring(test_t test)
-{
- u32 *result;
- u32 msg[] = {0x12345678, 0xFEDCBA98};
-
- test_begin (test, "halmbx_copy_to_ring test")
- {
- //Init HAL to fill the vector
- utest_A2L_head = A2L_RING_BASE_ADDR;
- utest_L2A_tail = L2A_RING_BASE_ADDR;
-
- //Check function
- utest_L2A_tail = L2A_RING_BASE_ADDR + 0x4;
- utest_L2A_head = L2A_RING_BASE_ADDR + 0x4;
- halmbx_copy_to_ring(msg, COUNT(msg));
- result = (u32*)utest_L2A_head;
- test_fail_if(*result++ != msg[0], "Error with copy result");
- test_fail_if(*result != msg[1], "Error with copy result");
- test_fail_if(utest_L2A_tail != (L2A_RING_BASE_ADDR + 0xC), "Error with update");
-
- utest_L2A_tail = L2A_RING_BASE_ADDR + L2A_RING_SIZE - 4;
- utest_L2A_head = L2A_RING_BASE_ADDR + L2A_RING_SIZE - 4;
- halmbx_copy_to_ring(msg, COUNT(msg));
- result = (u32*)utest_L2A_head;
- test_fail_if(*result != msg[0], "Error with rollover copy result");
- result = (u32*)L2A_RING_BASE_ADDR;
- test_fail_if(*result != msg[1], "Error with rollover copy result");
- test_fail_if(utest_L2A_tail != (L2A_RING_BASE_ADDR + 0x4), "Error with rollover update");
- }
- test_end;
-}
-
-void test_halmbx_copy_from_ring(test_t test)
-{
- u32 *ptr;
- u32 msg_origin[] = {0x87654321, 0x89ABCDEF};
- u32 msg[2];
-
- test_begin (test, "halmbx_copy_from_ring test")
- {
- //Init HAL to fill the vector
- utest_A2L_head = A2L_RING_BASE_ADDR;
- utest_L2A_tail = L2A_RING_BASE_ADDR;
-
- //Check function
- utest_A2L_tail = A2L_RING_BASE_ADDR + 0x4;
- utest_A2L_head = A2L_RING_BASE_ADDR + 0x4;
- ptr = (u32*)utest_A2L_head;
- *ptr = msg_origin[0];
- *(ptr+1) = msg_origin[1];
- halmbx_copy_from_ring(msg, COUNT(msg_origin));
- test_fail_if(msg_origin[0] != msg[0], "Error with copy result");
- test_fail_if(msg_origin[1] != msg[1], "Error with copy result");
- test_fail_if(utest_A2L_head != (A2L_RING_BASE_ADDR + 0xC), "Error with update");
-
- utest_A2L_tail = A2L_RING_BASE_ADDR + A2L_RING_SIZE - 4;
- utest_A2L_head = A2L_RING_BASE_ADDR + A2L_RING_SIZE - 4;
- ptr = (u32*)utest_A2L_head;
- *ptr = msg_origin[0];
- ptr = (u32*)A2L_RING_BASE_ADDR;
- *ptr = msg_origin[1];
- halmbx_copy_from_ring(msg, COUNT(msg_origin));
- test_fail_if(msg_origin[0] != msg[0], "Error with rollover copy result");
- test_fail_if(msg_origin[1] != msg[1], "Error with rollover copy result");
- test_fail_if(utest_A2L_head != (A2L_RING_BASE_ADDR + 0x4), "Error with rollover update");
- }
- test_end;
-}
-
-int main (void)
-{
- test_t test;
-
- test_init (test, 0, NULL);
-
- test_halmbx_init(test);
-
- test_set_L2At_interrupt(test);
- test_set_A2La_interrupt(test);
- test_clr_A2Lt_interrupt(test);
- test_clr_L2Aa_interrupt(test);
- test_L2Aa_it_enable(test);
- test_A2Lt_it_enable(test);
- test_L2Aa_it_disable(test);
- test_A2Lt_it_disable(test);
-
- test_halmbx_copy_to_ring(test);
- test_halmbx_copy_from_ring(test);
-
- test_result (test);
- return test_nb_failed (test) == 0 ? 0 : 1;
-}
-
diff --git a/cesar/hal/hle/test/src/hal_hle_ipmbox.c b/cesar/hal/hle/test/src/hal_hle_ipmbox.c
deleted file mode 100644
index 77f71f14f9..0000000000
--- a/cesar/hal/hle/test/src/hal_hle_ipmbox.c
+++ /dev/null
@@ -1,328 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hal/hle/test/src/hal_hle_ipmbox.c
- * \brief HAL HLE unit test to test the ipmbox mechanisms.
- * \ingroup hal_hle
- *
- * This file will tests all ipmbox functions
- */
-#include "common/std.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "lib/test.h"
-
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/inc/ipmbox.h"
-#include "hal/hle/inc/reg_ipmbox.h"
-
-test_t test;
-
-u32 A2L_ring[A2L_RING_WORDS] __attribute__ ((aligned (A2L_RING_SIZE)));
-u32 L2A_ring[L2A_RING_WORDS] __attribute__ ((aligned (L2A_RING_SIZE)));
-
-u32 utest_A2L_head;
-u32 utest_A2L_tail;
-u32 utest_L2A_head;
-u32 utest_L2A_tail;
-u32 utest_A2L_it;
-u32 utest_L2A_it;
-u32 utest_A2L_it_mask;
-
-ipmbox_t *ctx;
-
-bool dsr_posted;
-
-void my_callback(void *user_data, u32 *first_msg, uint length)
-{
-}
-
-void test_ipmbox_init(void)
-{
- test_begin (test, "ipmbox_init test")
- {
- u32 user_data;
- ipmbox_rx_cb_t rx_cb = &my_callback;
- utest_A2L_tail = (u32) A2L_ring;
- utest_L2A_head = (u32) L2A_ring;
- utest_A2L_it_mask = 0;
-
- ctx = ipmbox_init((void*)&user_data, rx_cb);
-
- test_fail_if(utest_A2L_it_mask != 0x3, "Error init disable interrupts");
- test_fail_if(utest_A2L_head != A2L_RING_BASE_ADDR, "Error init ring ptr");
- test_fail_if(utest_L2A_tail != L2A_RING_BASE_ADDR, "Error init ring ptr");
- test_fail_if(ctx->rx_cb_user_data != (void*)&user_data, "Error init with ctx");
- test_fail_if(ctx->rx_cb != rx_cb, "Error init with ctx");
- }
- test_end;
-}
-
-void test_ipmbox_uninit(void)
-{
- test_begin (test, "ipmbox_uninit test")
- {
- utest_A2L_it_mask = 0;
- ipmbox_uninit(ctx);
- test_fail_if(utest_A2L_it_mask != 0x3, "Error uninit ipmbox");
- }
- test_end;
-}
-
-void test_ipmbox_activate(void)
-{
- test_begin (test, "ipmbox_activate test")
- {
- utest_A2L_it_mask = 1;
- ipmbox_activate(ctx, 1);
- test_fail_if(utest_A2L_it_mask != 0x0, "Error activate ipmbox");
- ipmbox_activate(ctx, 0);
- test_fail_if(utest_A2L_it_mask != 0x1, "Error deactivate ipmbox");
- }
- test_end;
-}
-
-void
-test_ipmbox_tx (void)
-{
- uint n;
- u32 msg[2];
- test_case_begin (test, "tx");
- ctx = ipmbox_init (NULL, my_callback);
- n = 0;
- test_begin (test, "tx ok")
- {
- while (n < L2A_RING_WORDS - 2)
- {
- msg[0] = n++;
- msg[1] = n++;
- ipmbox_tx (ctx, msg, 2);
- }
- } test_end;
- test_begin (test, "check mailbox")
- {
- for (n = 0; n < L2A_RING_WORDS - 2; n++)
- test_fail_unless (L2A_ring[n] == n);
- } test_end;
-}
-
-u32 msg_origin[] = {0x332201AA, 0x12345678,
- 0x332201BB, 0x89ABCDEF,
- 0x554401CC, 0x23456781,
- 0x554401DD, 0x34567812,
- 0x776601EE, 0x45678123,
- 0x776601FF, 0x67812345,
- 0x99880100, 0x78123456,
- 0x99880111, 0x81234567,
- 0xBBAA0122, 0xFEDCBA98};
-
-void rx_cb_first(void *user_data, u32 *first_msg, uint length)
-{
- test_begin (test, "first ipmbox_dsr test")
- {
- uint i;
- test_fail_if(utest_A2L_head != A2L_RING_BASE_ADDR+(length*sizeof(u32)), "Error dsr size msg");
- for(i=0;i<length;i++)
- {
- test_fail_if(*(first_msg+i) != msg_origin[i], "Error dsr rx msg");
- }
- test_fail_if(*(first_msg+17) == msg_origin[17], "Error dsr overflow");
- }
- test_end;
-}
-
-void test_ipmbox_irq(void)
-{
- u32 user_data;
- ipmbox_rx_cb_t rx_cb = &rx_cb_first;
- test_begin (test, "ipmbox_isr test")
- {
- test_fail_if(mailbox_rx_isr(14, 0) != 0x3, "Error isr ipmbox");
- }
- test_end;
-
- //DSR tests
- ctx = ipmbox_init((void*)&user_data, rx_cb);
-
- //first one
- utest_A2L_head = A2L_RING_BASE_ADDR;
- utest_A2L_tail = A2L_RING_BASE_ADDR;
- memcpy((char*)utest_A2L_head, (char*)msg_origin, 0x10);
- utest_A2L_tail = A2L_RING_BASE_ADDR + 0x10;
- mailbox_rx_dsr(14, 0, (cyg_addrword_t)ctx);
-
- //second one
- utest_A2L_head = A2L_RING_BASE_ADDR;
- utest_A2L_tail = A2L_RING_BASE_ADDR;
- memcpy((char*)utest_A2L_head, (char*)msg_origin, 0x40);
- utest_A2L_tail = A2L_RING_BASE_ADDR + 0x40;
- mailbox_rx_dsr(14, 0, (cyg_addrword_t)ctx);
-}
-
-void
-rx_cb_budget (void *user_data, u32 *first_msg, uint length)
-{
- uint i;
- test_within (test);
- /* expectp points to an array containing (length, base) pairs, ended by a
- * zero. */
- uint **expectp = user_data;
- uint expect_length = (*expectp)[0];
- uint expect_base = (*expectp)[1];
- test_fail_unless (expect_length != 0);
- test_fail_unless (length == expect_length);
- for (i = 0; i < expect_length; i++)
- test_fail_unless (first_msg[i] == i + expect_base);
- (*expectp) += 2;
-}
-
-void
-test_ipmbox_budget (void)
-{
- uint i;
- uint *expectp = NULL;
- test_case_begin (test, "budget");
- ctx = ipmbox_init (&expectp, rx_cb_budget);
- utest_A2L_head = A2L_RING_BASE_ADDR;
- utest_A2L_tail = A2L_RING_BASE_ADDR;
- /* Just for fun, a very small message. */
- test_begin (test, "tiny")
- {
- uint expect[] = { 12, 0, 0 };
- expectp = expect;
- for (i = 0; i < 12; i++)
- A2L_ring[i] = i;
- utest_A2L_tail += 12 * 4;
- dsr_posted = false;
- mailbox_rx_dsr (14, 0, (uint) ctx);
- test_fail_if (dsr_posted);
- } test_end;
- /* A small message which should not trigger budget. */
- test_begin (test, "small")
- {
- uint expect[] = { 100, 12, 0 };
- expectp = expect;
- for (i = 12; i < 100 + 12; i++)
- A2L_ring[i] = i;
- utest_A2L_tail += 100 * 4;
- dsr_posted = false;
- mailbox_rx_dsr (14, 0, (uint) ctx);
- test_fail_unless (*expectp == 0);
- test_fail_if (dsr_posted);
- } test_end;
- /* A medium message which should not trigger budget. */
- test_begin (test, "medium")
- {
- uint expect[] = { 128, 112, 0 };
- expectp = expect;
- for (i = 112; i < 128 + 112; i++)
- A2L_ring[i] = i;
- utest_A2L_tail += 128 * 4;
- dsr_posted = false;
- mailbox_rx_dsr (14, 0, (uint) ctx);
- test_fail_unless (*expectp == 0);
- test_fail_if (dsr_posted);
- } test_end;
- /* A large message to trigger budget. */
- test_begin (test, "large")
- {
- uint expect[] = { 128, 240, 128, 368, 0 };
- expectp = expect;
- for (i = 240; i < 256 + 240; i++)
- A2L_ring[i] = i;
- utest_A2L_tail += 256 * 4;
- dsr_posted = false;
- mailbox_rx_dsr (14, 0, (uint) ctx);
- test_fail_unless (dsr_posted);
- dsr_posted = false;
- mailbox_rx_dsr (14, 0, (uint) ctx);
- test_fail_unless (*expectp == 0);
- test_fail_if (dsr_posted);
- } test_end;
-}
-
-void
-test_ipmbox_sync (void)
-{
- uint i, j;
- test_case_begin (test, "sync");
- ctx = ipmbox_init (NULL, my_callback); /* Callback not used. */
- utest_A2L_head = A2L_RING_BASE_ADDR;
- utest_A2L_tail = A2L_RING_BASE_ADDR;
- /* Read with roll-over. */
- test_begin (test, "rollover")
- {
- /* Fill mailbox with a roll-over. */
- utest_A2L_head += A2L_RING_SIZE * 3 / 4;
- utest_A2L_tail = utest_A2L_head;
- for (i = 0, j = A2L_RING_WORDS * 3 / 4;
- i < A2L_RING_WORDS / 4;
- i++, j++)
- A2L_ring[j] = i;
- for (j = 0;
- i < A2L_RING_WORDS / 2;
- i++, j++)
- A2L_ring[j] = i;
- utest_A2L_tail += A2L_RING_SIZE / 2;
- /* Set interrupt. */
- utest_A2L_it = A2LT_MASK;
- /* Read everything. */
- const u32 *rx_msg = NULL;
- uint rx_msg_length;
- rx_msg_length = ipmbox_rx_sync (ctx, &rx_msg);
- /* Check result. */
- test_fail_unless (rx_msg_length == A2L_RING_WORDS / 2);
- test_fail_unless (rx_msg);
- for (i = 0; i < rx_msg_length; i++)
- test_fail_unless (rx_msg[i] == i);
- } test_end;
- /* No interrupt. */
- test_begin (test, "no interrupt")
- {
- /* Read everything. */
- const u32 *rx_msg = NULL;
- uint rx_msg_length;
- rx_msg_length = ipmbox_rx_sync (ctx, &rx_msg);
- /* Check result. */
- test_fail_unless (rx_msg_length == 0);
- test_fail_unless (rx_msg == NULL);
- } test_end;
- /* Nothing to read. */
- test_begin (test, "nothing to read")
- {
- /* Set interrupt. */
- utest_A2L_it = A2LT_MASK;
- /* Read everything. */
- const u32 *rx_msg = NULL;
- uint rx_msg_length;
- rx_msg_length = ipmbox_rx_sync (ctx, &rx_msg);
- /* Check result. */
- test_fail_unless (rx_msg_length == 0);
- test_fail_unless (rx_msg == NULL);
- } test_end;
-}
-
-int main (int argc, char **argv)
-{
- test_init (test, argc, argv);
-
- test_ipmbox_init();
- test_ipmbox_activate();
- test_ipmbox_tx();
- test_ipmbox_irq();
- test_ipmbox_budget();
- test_ipmbox_sync();
- test_ipmbox_uninit();
-
- test_result (test);
- return test_nb_failed (test) == 0 ? 0 : 1;
-}
-
diff --git a/cesar/hal/ipmbox/Module b/cesar/hal/ipmbox/Module
new file mode 100644
index 0000000000..e00d0e596f
--- /dev/null
+++ b/cesar/hal/ipmbox/Module
@@ -0,0 +1,2 @@
+SOURCES := ipmbox.c
+MODULES := ../common/ipmbox
diff --git a/cesar/hal/hle/doc/claudia_ipmbox.odt b/cesar/hal/ipmbox/doc/claudia_ipmbox.odt
index 095ab88ce1..095ab88ce1 100644
--- a/cesar/hal/hle/doc/claudia_ipmbox.odt
+++ b/cesar/hal/ipmbox/doc/claudia_ipmbox.odt
Binary files differ
diff --git a/cesar/hal/ipmbox/inc/ecos.h b/cesar/hal/ipmbox/inc/ecos.h
new file mode 100644
index 0000000000..d30f0d16ec
--- /dev/null
+++ b/cesar/hal/ipmbox/inc/ecos.h
@@ -0,0 +1,50 @@
+#ifndef hal_ipmbox_inc_ipmbox_ecos_h
+#define hal_ipmbox_inc_ipmbox_ecos_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/inc/ipmbox_ecos.h
+ * \brief HAL IPMBox eCos management data.
+ * \ingroup hal_ipmbox
+ */
+#if defined (ECOS) && ECOS
+#include <cyg/hal/drv_api.h>
+#include <cyg/hal/hal_intr.h>
+#include "hal/leon/itc2.h"
+
+/* eCos function is dawn too slow, use HAL_INTERRUPT_ACKNOWLEDGE instead of
+ * cyg_drv_interrupt_acknowledge. */
+# define ipmbox_interrupt_acknowledge HAL_INTERRUPT_ACKNOWLEDGE
+
+/** Rx IPMBox DATA and MBX interrupt number. */
+# define IPMBOX_RX_IT_NUM CYGNUM_HAL_INTERRUPT_GIC2_14
+/** Rx Empty buf interrupt number. */
+# define IPMBOX_EMPTY_BUF_IT_NUM CYGNUM_HAL_INTERRUPT_GIC2_13
+
+/* We need this undocumented eCos function for budget. */
+extern void cyg_interrupt_post_dsr (CYG_ADDRWORD intr_obj);
+
+/* eCos interrupt management structure. */
+typedef struct ipmbox_ecos_t
+{
+ cyg_interrupt rx_it;
+ cyg_handle_t rx_it_handle;
+ cyg_interrupt empty_buf_it;
+ cyg_handle_t empty_buf_it_handle;
+} ipmbox_ecos_t;
+
+#else /* ! eCos */
+
+/** Rx IPMBox DATA and MBX interrupt number. */
+# define IPMBOX_RX_IT_NUM 0
+/** Rx Empty buf interrupt number. */
+# define IPMBOX_EMPTY_BUF_IT_NUM 1
+
+#endif
+
+#endif /* hal_ipmbox_inc_ipmbox_ecos_h */
diff --git a/cesar/hal/ipmbox/inc/ipmbox.h b/cesar/hal/ipmbox/inc/ipmbox.h
new file mode 100644
index 0000000000..5d45127b7d
--- /dev/null
+++ b/cesar/hal/ipmbox/inc/ipmbox.h
@@ -0,0 +1,48 @@
+#ifndef hal_ipmbox_inc_ipmbox_h
+#define hal_ipmbox_inc_ipmbox_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/inc/ipmbox.h
+ * \brief HAL IPMBox private data.
+ * \ingroup hal_ipmbox
+ *
+ * This file defines IPMBox context structure.
+ */
+#include "common/ipmbox/queue.h"
+#include "common/ipmbox/registers.h"
+
+#include "hal/ipmbox/inc/ecos.h"
+
+/** RX DATA budget. Number of words which can be handled in one
+ * execution. */
+#define IPMBOX_RX_DATA_BUDGET 128
+
+/** Context structure definition */
+struct ipmbox_t {
+ /** Queues, by types & directions. */
+ ipmbox_queue_t queue[IPMBOX_QUEUE_TYPE_NB][IPMBOX_QUEUE_DIRECTION_NB];
+ /** IPMBox registers. */
+ volatile ipmbox_registers_t *regs;
+ /** RX DATA user data. */
+ void *rx_cb_data_user_data;
+ /** RX MBX user data. */
+ void *rx_cb_mbx_user_data;
+ /** RX DATA DSR callback. */
+ ipmbox_rx_cb_t rx_cb_data;
+ /** RX MBX DSR callback. */
+ ipmbox_rx_cb_t rx_cb_mbx;
+ /* Empty buffer user data callback. */
+ void *empty_buf_cb_user_data;
+ /* Empty buffer DSR callback. */
+ ipmbox_empty_buf_cb_t empty_buf_cb;
+ /* eCos context. */
+ ipmbox_ecos_t ecos;
+};
+
+#endif /* hal_ipmbox_inc_ipmbox_h */
diff --git a/cesar/hal/ipmbox/inc/regs.h b/cesar/hal/ipmbox/inc/regs.h
new file mode 100644
index 0000000000..ae14059ccb
--- /dev/null
+++ b/cesar/hal/ipmbox/inc/regs.h
@@ -0,0 +1,19 @@
+#ifndef hal_ipmbox_inc_ipmbox_regs_h
+#define hal_ipmbox_inc_ipmbox_regs_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/inc/ipmbox_regs.h
+ * \brief HAL IPMBox registers base address.
+ * \ingroup hal_ipmbox
+ */
+
+/* IPMBox registers base address. */
+#define IPMBOX_REG_BASE_ADDR (0xB4000000)
+
+#endif /* hal_ipmbox_inc_ipmbox_regs_h */
diff --git a/cesar/hal/ipmbox/ipmbox.h b/cesar/hal/ipmbox/ipmbox.h
new file mode 100644
index 0000000000..509a3e1a15
--- /dev/null
+++ b/cesar/hal/ipmbox/ipmbox.h
@@ -0,0 +1,133 @@
+#ifndef hal_ipmbox_ipmbox_h
+#define hal_ipmbox_ipmbox_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/ipmbox.h
+ * \brief HAL IPMbox public interface.
+ * \ingroup hal_ipmbox
+ */
+#include "common/ipmbox/queue.h"
+
+/* Context forward declaration. */
+typedef struct ipmbox_t ipmbox_t;
+
+/**
+ * RX DSR callback function.
+ * \param user_data user data
+ * \param first_msg pointer to the first received message header
+ * \param length total length (in word) of received messages
+ */
+typedef void (*ipmbox_rx_cb_t) (void *user_data, u32 *first_msg, uint length);
+
+/**
+ * Empty buf DSR callback function.
+ * \param user_data user data
+ */
+typedef void (*ipmbox_empty_buf_cb_t) (void *user_data);
+
+BEGIN_DECLS
+
+/**
+ * Initialise the HAL HLE.
+ * \return the newly created context
+ */
+ipmbox_t *
+ipmbox_init (void);
+
+/**
+ * Uninitialise the HAL HLE.
+ * \param ctx ipmbox context
+ */
+void
+ipmbox_uninit (ipmbox_t *ctx);
+
+/**
+ * Activate ipmbox interruptions.
+ * \param ctx ipmbox context
+ * \param activation indicates if interruptions are activated or deactivated
+ */
+void
+ipmbox_activate (ipmbox_t *ctx, bool activation);
+
+/**
+ * Register callbacks for DATA queue.
+ * \param ctx ipmbox context
+ * \param user_data the user_data
+ * \param rx_cb_data callback to handle DATA.
+ */
+void
+ipmbox_register_rx_data_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_rx_cb_t rx_cb_data);
+
+/**
+ * Register callbacks for MBX queue.
+ * \param ctx ipmbox context
+ * \param user_data the user_data
+ * \param rx_cb_mbx callback to handle MBox.
+ */
+void
+ipmbox_register_rx_mbx_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_rx_cb_t rx_cb_mbx);
+
+/**
+ * Register callbacks for empty buf queue.
+ * \param ctx ipmbox context
+ * \param user_data the user_data
+ * \param rx_cb_empty_buf callback to handle empty buffers.
+ */
+void
+ipmbox_register_empty_buf_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_empty_buf_cb_t empty_buf_cb);
+
+/** Transmit a message to DATA queue.
+ * \param ctx ipmbox context
+ * \param first_msg pointer to the first message header
+ * \param length total length (in word) of messages to transmit
+ */
+void
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length);
+
+/** Transmit a message to EMPTY_BUF queue.
+ * \param ctx ipmbox context
+ * \param first_msg pointer to the first message header
+ * \param length total length (in word) of messages to transmit
+ */
+void
+ipmbox_tx_empty_buf (ipmbox_t *ctx, u32 *first_msg, uint length);
+
+/** Transmit a message to MBX queue.
+ * \param ctx ipmbox context
+ * \param first_msg pointer to the first message header
+ * \param length total length (in word) of messages to transmit
+ */
+void
+ipmbox_tx_mbx (ipmbox_t *ctx, u32 *first_msg, uint length);
+
+/**
+ * Get nb empty buffers from the empty buf queue.
+ * \param ctx ipmbox context
+ * \param msg_buf destination array for the messages
+ * \param nb number of elements of msg_buf.
+ * \return number of copied element in msg_buf.
+ */
+uint
+ipmbox_empty_buf_get (ipmbox_t *ctx, u32 *msg_buf, uint nb);
+
+/**
+ * Receive message from mailbox, interrupts locked.
+ * \param ctx ipmbox context
+ * \param first_msg pointer to store first received message address
+ * \return total length (in word) of received messages
+ */
+uint
+ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg);
+
+END_DECLS
+
+#endif /* hal_ipmbox_ipmbox_h */
diff --git a/cesar/hal/hle/maximus/Module b/cesar/hal/ipmbox/maximus/Module
index 8b80d1ba66..8b80d1ba66 100644
--- a/cesar/hal/hle/maximus/Module
+++ b/cesar/hal/ipmbox/maximus/Module
diff --git a/cesar/hal/hle/maximus/inc/maximus_ether.h b/cesar/hal/ipmbox/maximus/inc/maximus_ether.h
index 007ede58d6..fa8df3d8c3 100644
--- a/cesar/hal/hle/maximus/inc/maximus_ether.h
+++ b/cesar/hal/ipmbox/maximus/inc/maximus_ether.h
@@ -1,5 +1,5 @@
-#ifndef hal_hle_maximus_inc_maximus_ether_h
-#define hal_hle_maximus_inc_maximus_ether_h
+#ifndef hal_ipmbox_maximus_inc_maximus_ether_h
+#define hal_ipmbox_maximus_inc_maximus_ether_h
/* Cesar project {{{
*
* Copyright (C) 2007 Spidcom
@@ -8,20 +8,19 @@
*
* }}} */
/**
- * \file hal/hle/maximus/inc/maximus_ether.h
- * \brief HAL HLE declarations for Maximus.
- * \ingroup hal_hle_maximus
+ * \file hal/ipmbox/maximus/inc/maximus_ether.h
+ * \brief HAL IPMBox declarations for Maximus.
+ * \ingroup hal_ipmbox_maximus
*/
-#include "hal/hle/forward.h" // for 'ipmbox_t'
#include "host/fwd.h" // for 'sci_msg_t'
-#include "hal/hle/ipmbox.h" // for 'ipmbox_msg_data_t'
+#include "hal/ipmbox/ipmbox.h"
/**
* Fill a blank ether header
* \param ctx current ipmbox context
* \param msg pointer to sci message to fill header
- * \param type type of message (DATA, MME, DATA_BUFFER_ADD, MME_BUFFER_ADD, BUFFER_RELEASED, or SNIFFER)
+ * \param type type of message (DATA, MME, BUFFER_ADD, or BUFFER_RELEASED)
* \param flags not used
* \return 0 if ok, -1 if it fails with errno =
* - EINVAL if ctx or msg are NULL, or if arguments are out-of-range
@@ -49,17 +48,18 @@ int maximus_ether_recv (sci_msg_t *msg, void *ipmbox);
*/
int maximus_ether_recv_invalid (ipmbox_t *ctx, sci_msg_t *msg);
int maximus_ether_recv_data (ipmbox_t *ctx, sci_msg_t *msg);
-int maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg);
+int maximus_ether_recv_mbx (ipmbox_t *ctx, sci_msg_t *msg);
+int maximus_ether_recv_empty_buf (ipmbox_t *ctx, sci_msg_t *msg);
/**
- * Send an Ether SCI message of type DATA, MME, BUFFER_RELEASED, or SNIFFER to Maximus.
+ * Send an Ether SCI message of type DATA, MME, or BUFFER_RELEASED to Maximus.
* \param ctx ipmbox current context
- * \param type type of message (DATA, MME, BUFFER_RELEASED, or SNIFFER)
+ * \param type type of message (DATA, MME, or BUFFER_RELEASED)
* \param flags not used
* \param data_length sci message data length to send
* \param data pointer to sci message data to send
* \return 0 if ok, -1 if it fails with errno =
- * - EINVAL if ctx or data are null, or if data length equals 0
+ * - EINVAL if ctx or data are null, or of data length equals 0
* if 'sci_send()' fails, it sets errno
*/
int maximus_ether_send (ipmbox_t *ctx, u8 type, u8 flags, uint data_length, u32 *data);
diff --git a/cesar/hal/ipmbox/maximus/inc/maximus_interrupts.h b/cesar/hal/ipmbox/maximus/inc/maximus_interrupts.h
new file mode 100644
index 0000000000..89685202d7
--- /dev/null
+++ b/cesar/hal/ipmbox/maximus/inc/maximus_interrupts.h
@@ -0,0 +1,22 @@
+#ifndef hal_ipmbox_maximus_inc_maximus_interrupts_h
+#define hal_ipmbox_maximus_inc_maximus_interrupts_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/maximus/inc/maximus_interrupts.h
+ * \brief HAL interrupt register definition for Maximus.
+ * \ingroup hal_ipmbox_maximus
+ */
+
+#define HAL_IPMBOX_RX_INTERRUPT 7
+
+#define HAL_IPMBOX_BUF_INTERRUPT 8
+
+#define HAL_IPMBOX_INTERRUPT_PRIORITY 1 /* is it the right value? */
+
+#endif /* hal_ipmbox_maximus_inc_maximus_interrupts_h */
diff --git a/cesar/hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h b/cesar/hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h
new file mode 100644
index 0000000000..54103eff29
--- /dev/null
+++ b/cesar/hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h
@@ -0,0 +1,108 @@
+#ifndef hal_ipmbox_maximus_inc_maximus_ipmbox_context_h
+#define hal_ipmbox_maximus_inc_maximus_ipmbox_context_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/maximus/inc/maximus_ipmbox_context.h
+ * \brief HAL ipmbox context for Maximus.
+ * \ingroup hal_ipmbox_maximus
+ */
+#include "hal/ipmbox/ipmbox.h" // for 'ipmbox_rx_cb_t', 'ipmbox_empty_buf_cb_t'
+#include "maximus/common/types/sci_types.h" // for 'SCI_MSG_MAX_SIZE'
+#include "common/ipmbox/protocol.h"
+#include <stdint.h> // for 'u32'
+#ifdef ECOS
+#include <cyg/hal/drv_api.h>
+#endif /* ECOS */
+
+/** Data queue structure for Maximus. */
+struct maximus_queue_data_t
+{
+ /** Total length (in word) of messages. */
+ uint length;
+ /** Mailbox. */
+ u32 mailbox[IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_DATA];
+};
+typedef struct maximus_queue_data_t maximus_queue_data_t;
+
+/** Mailbox queue structure for Maximus. */
+struct maximus_queue_mbx_t
+{
+ /** Total length (in word) of messages. */
+ uint length;
+ /** Mailbox. */
+ u32 mailbox[IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX];
+};
+typedef struct maximus_queue_mbx_t maximus_queue_mbx_t;
+
+/** Empty Buffer queue structure for Maximus. */
+struct maximus_queue_empty_buf_t
+{
+ /** Total length (in word) of messages. */
+ uint length;
+ /** Mailbox. */
+ u32 mailbox[IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF];
+};
+typedef struct maximus_queue_empty_buf_t maximus_queue_empty_buf_t;
+
+struct maximus_ipmbox_buffer_t
+{
+ /** Pointer to next allocated buffer. */
+ struct maximus_ipmbox_buffer_t *next;
+ /** Buffer id.*/
+ u32 id;
+ /** Pointer to data. */
+ u32 *data;
+};
+typedef struct maximus_ipmbox_buffer_t maximus_ipmbox_buffer_t;
+
+/** Ipmbox context structure for Maximus. */
+struct ipmbox_t
+{
+ /** Data reception queue structure. */
+ maximus_queue_data_t rx_data;
+ /** Mailbox reception queue structure. */
+ maximus_queue_mbx_t rx_mbx;
+ /** Empty buffer reception queue structure. */
+ maximus_queue_empty_buf_t rx_empty_buf;
+ /** Pointer to first element in linked list of allocated buffers. */
+ maximus_ipmbox_buffer_t *first_buffer;
+ /** Pointer to last element in linked list of allocated buffers. */
+ maximus_ipmbox_buffer_t *last_buffer;
+ /** User data passed to rx data callback. */
+ void *rx_data_user_data;
+ /** User data passed to rx mbx callback. */
+ void *rx_mbx_user_data;
+ /** User data passed to empty buffer callback. */
+ void *buf_user_data;
+ /** RX DSR callbacks. */
+ ipmbox_rx_cb_t rx_cb_data;
+ ipmbox_rx_cb_t rx_cb_mbx;
+ /** Pointer to current DSR callback. */
+ ipmbox_rx_cb_t rx_cb_current;
+ /** Empty buffer DSR callback. */
+ ipmbox_empty_buf_cb_t empty_buf_cb;
+#ifdef ECOS
+ /** Ipmbox interrupt descriptor for eCos: relates to RX data and RX
+ * mailbox. */
+ cyg_interrupt ipmbox_rx_interrupt;
+ /** Ipmbox interrupt handle for RX data and RX mailbox. */
+ cyg_handle_t ipmbox_rx_interrupt_handle;
+ /** Ipmbox interrupt descriptor for eCos: relates to empty buffer. */
+ cyg_interrupt ipmbox_buf_interrupt;
+ /** Ipmbox interrupt handle for empty buffer. */
+ cyg_handle_t ipmbox_buf_interrupt_handle;
+#endif /* ECOS */
+ /** For ether messages. */
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+ /** Set to true to enable assertions on WARNING messages. */
+ bool warning_assert;
+};
+/* Forward declaration in hal/ipmbox/forward.h. */
+
+#endif /* hal_ipmbox_maximus_inc_maximus_ipmbox_context_h */
diff --git a/cesar/hal/hle/maximus/src/maximus_ether.c b/cesar/hal/ipmbox/maximus/src/maximus_ether.c
index 137f02a0ec..29cfbbf87b 100644
--- a/cesar/hal/hle/maximus/src/maximus_ether.c
+++ b/cesar/hal/ipmbox/maximus/src/maximus_ether.c
@@ -6,48 +6,34 @@
*
* }}} */
/**
- * \file hal/hle/maximus/src/maximus_ether.c
+ * \file hal/ipmbox/maximus/src/maximus_ether.c
* \brief HAL HLE functions for Maximus.
* \ingroup hal_hle_maximus
*/
#include "common/std.h"
-#include "hal/hle/maximus/inc/maximus_ether.h"
-#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h"
-#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...' and 'ipmbox_msg_hdr_t'
+#include "hal/ipmbox/maximus/inc/maximus_ether.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h"
#include "host/fwd.h" // for 'sci_msg_t' and 'ether_msg_hdr_t'
#include "host/station/station.h" // for 'station_log()'
#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
-#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
+#include "hal/ipmbox/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
+#include "common/ipmbox/msg.h"
#include "ecos/packages/hal/maximus/arch/current/include/hal_host_intr.h"
#include "common/defs/ethernet.h" // for 'ETH_PACKET_MAX_SIZE' and 'ETH_PACKET_MIN_SIZE'
-#include "interface/sniffer/defs.h" // for 'SNIFFER_BEACON' and 'SNIFFER_MME'
#include <stdlib.h> // for 'malloc'
#include <errno.h>
-#include "interface/sniffer/mmtype.h" // for 'VS_SNIFFER_REQ'
#include "common/defs/homeplugAV.h" // for 'HPAV_MTYPE_MME' and 'HPAV_M(M)TYPE_OFFSET'
#include "lib/swap.h" // for 'swap16()'
typedef int (*maximus_ether_recv_function)(ipmbox_t *ctx, sci_msg_t *msg);
-maximus_ether_recv_function maximus_ether_function_array[ETHERNET_TYPE_NB] = { &maximus_ether_recv_invalid, // none
- &maximus_ether_recv_data, // data
- &maximus_ether_recv_data, // mme
- &maximus_ether_recv_buffer_add, // data buffer add
- &maximus_ether_recv_buffer_add, // mme buffer add
- &maximus_ether_recv_buffer_add, // interface buffer add
- &maximus_ether_recv_invalid, // buffer released
- &maximus_ether_recv_invalid }; // sniffer
+maximus_ether_recv_function maximus_ether_function_array[ETHERNET_TYPE_NB] = { &maximus_ether_recv_invalid, // (0) none
+ &maximus_ether_recv_data, // (1) data
+ &maximus_ether_recv_mbx, // (2) mme
+ &maximus_ether_recv_empty_buf, // (3) buffer add
+ &maximus_ether_recv_invalid }; // (4) buffer released
-/**
- * Fill a blank ether header
- * \param ctx current ipmbox context
- * \param msg pointer to sci message to fill header
- * \param type type of message (DATA, MME, DATA_BUFFER_ADD, MME_BUFFER_ADD, INTERFACE_BUFFER_ADD, BUFFER_RELEASED, or SNIFFER)
- * \param flags not used
- * \return 0 if ok, -1 if it fails with errno =
- * - EINVAL if ctx or msg are NULL, or if arguments are out-of-range
- */
int
maximus_ether_fill_hdr(ipmbox_t *ctx, sci_msg_t *msg, u8 type, u8 flags)
{
@@ -88,18 +74,9 @@ maximus_ether_fill_hdr(ipmbox_t *ctx, sci_msg_t *msg, u8 type, u8 flags)
}
}
- return ret;
+ return ret;
}
-/**
- * Process ether message received by the sci layer.
- * This function must be registred to SCI layer with SCI_MSG_TYPE_ETHERNET type.
- * \param msg message to process
- * \param ipmbox ipmbox current context
- * \return 0 if ok, -1 if it fails with errno =
- * - EINVAL if msg or ctx are NULL
- * - EPROTO if msg->hdr.ether is null, or if msg->hdr.ether values are out-of-range
- */
int
maximus_ether_recv (sci_msg_t *msg, void *ipmbox)
{
@@ -117,7 +94,7 @@ maximus_ether_recv (sci_msg_t *msg, void *ipmbox)
}
else
{
- // set ipmbox context
+ // set ipmbox context
ctx = (ipmbox_t *)ipmbox;
// set header pointer in case of not already done
@@ -153,18 +130,9 @@ maximus_ether_recv (sci_msg_t *msg, void *ipmbox)
}
}
- return ret;
+ return ret;
}
-/**
- * Process ether message received by the sci layer, depending on the ether header type.
- * \param ctx ipmbox current context
- * \param msg message to process
- * \return 0 if ok, -1 if it fails with errno =
- * - EINVAL if ctx, msg, msg->sci_hdr or ctx->rx_cb are null
- * - EPROTO if msg->hdr.ether->type is incorrect, or if msg->hdr.ether values are out-of-range
- */
-
int
maximus_ether_recv_invalid (ipmbox_t *ctx, sci_msg_t *msg)
{
@@ -199,57 +167,87 @@ maximus_ether_recv_data (ipmbox_t *ctx, sci_msg_t *msg)
}
else
{
- ipmbox_msg_hdr_t hdr;
+ ipmbox_msg_data_t msg_data;
u8 *data;
- int len = msg->length;
- uint mtype;
- uint mmtype;
-
- // set hdr length
- hdr.length = 1;
-
- // get data
- data = (u8 *)malloc(2048);
- memset(data, 0, 2048);
- memcpy(data, msg->data_begin, msg->length);
-
- mtype = swap16(bitstream_direct_read (data,
- (HPAV_MME_HEADER - 7) * 8,
- 16));
- mmtype = bitstream_direct_read (data,
- HPAV_MMTYPE_OFFSET * 8,
- 16);
- if ((mtype == HPAV_MTYPE_MME)
- && (ETHERNET_TYPE_MME == msg->hdr.ether->type)
- && (VS_SNIFFER_REQ == mmtype))
+ unsigned int msg_len = (unsigned int) msg->length;
+
+ // Get data from sci message.
+ data = (u8 *) calloc (2048, sizeof (u8));
+ memcpy (data, msg->data_begin, msg->length);
+ msg_data.buffer_addr = (u32) data;
+
+ if (msg->length != sci_msg_pop(msg, msg->length))
{
- // set hdr type
- hdr.type = HLE_MSG_TYPE_INTERFACE;
-
- // set hdr param
- // DATA length (11 bits): length of data into DATA buffer
- // module type (8 bits): 1 for module sniffer
- hdr.param = msg->length << 8;
- hdr.param |= 1;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ dbg_assert_print(false, "errno = %d when poping SCI message", errno);
}
else
{
- // set hdr type
- hdr.type = HLE_MSG_TYPE_DATA;
-
- // set hdr param
- // DATA length (11 bits): length of data into DATA buffer
- // type (1 bit):
- // 0 for DATA type
- // 1 for MME type
- hdr.param = msg->length << 1;
- if (ETHERNET_TYPE_MME == msg->hdr.ether->type)
+ msg_data.header = ipmbox_msg_create_header_data (msg_len, 0 /* vlan prio */);
+
+ if (IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_DATA <= ctx->rx_data.length + 2)
{
- hdr.param |= 1;
+ errno = ENOSPC;
+ station_log(&my_station, STATION_LOG_WARNING, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d because data queue is full", __FUNCTION__, errno);
+ dbg_assert_print(!ctx->warning_assert, "errno = %d because data queue is full", errno);
+ // reset total length of messages
+ ctx->rx_data.length = 0;
}
+
+ /* Update data queue. */
+ // set hdr
+ memcpy(&ctx->rx_data.mailbox[ctx->rx_data.length], &msg_data, sizeof(ipmbox_msg_data_t));
+ // update total length of messages
+ ctx->rx_data.length += 2;
+
+ /* set callback for DSR */
+ ctx->rx_cb_current = ctx->rx_cb_data;
+ // raise interruption
+ maximus_pending_isrs |= (1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ ret = 0;
}
+ }
+
+ return ret;
+}
+
+int
+maximus_ether_recv_mbx (ipmbox_t *ctx, sci_msg_t *msg)
+{
+ int ret = -1;
- if (len != sci_msg_pop(msg, len))
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
+ dbg_assert_ptr(msg->hdr.ether);
+ dbg_assert_ptr(msg->sci_hdr);
+ dbg_assert((ETH_PACKET_MIN_SIZE_ALLOWED <= msg->length) && (ETH_PACKET_MAX_SIZE >= msg->length));
+ dbg_assert_ptr(msg->data_begin);
+ if((NULL == ctx)
+ || (NULL == msg)
+ || (NULL == msg->hdr.ether)
+ || (NULL == msg->sci_hdr)
+ || ((ETH_PACKET_MIN_SIZE_ALLOWED > msg->length) || (ETH_PACKET_MAX_SIZE < msg->length))
+ || (NULL == msg->data_begin))
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ ipmbox_msg_mbx_t msg_mbx;
+ unsigned int msg_len = (unsigned int) msg->length;
+ u8 *mme;
+
+ // Get MME from sci message.
+ mme = (u8 *) calloc (2048, sizeof (u8));
+ memcpy (mme, msg->data_begin, msg->length);
+ msg_mbx.buffer_addr = (u32) mme;
+
+ if (msg->length != sci_msg_pop(msg, msg->length))
{
station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
"%s: errno = %d", __FUNCTION__, errno);
@@ -257,26 +255,29 @@ maximus_ether_recv_data (ipmbox_t *ctx, sci_msg_t *msg)
}
else
{
- if (MAXIMUS_HLE_MAILBOX_MAX_SIZE <= ctx->rx.length + hdr.length + 1)
+ msg_mbx.header = ipmbox_msg_create_header_mme_priv (msg_len);
+
+ if (IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX <= ctx->rx_mbx.length + 2)
{
errno = ENOSPC;
station_log(&my_station, STATION_LOG_WARNING, STATION_LOGTYPE_ETHER,
- "%s: errno = %d because mailbox is full", __FUNCTION__, errno);
- dbg_assert_print(!ctx->warning_assert, "errno = %d because mailbox is full", errno);
+ "%s: errno = %d because mailbox queue is full", __FUNCTION__, errno);
+ dbg_assert_print(!ctx->warning_assert, "errno = %d because mailbox queue is full", errno);
// reset total length of messages
- ctx->rx.length = 0;
+ ctx->rx_mbx.length = 0;
}
- /* Update mailbox. */
+ /* Update mailbox queue. */
// set hdr
- memcpy(&ctx->rx.mailbox[ctx->rx.length], &hdr, sizeof(ipmbox_msg_hdr_t));
- // set buffer pointer (32 bits): pointer to DATA buffer
- ctx->rx.mailbox[ctx->rx.length + 1] = (u32)data;
+ memcpy (&ctx->rx_mbx.mailbox[ctx->rx_mbx.length], &msg_mbx,
+ sizeof (ipmbox_msg_mbx_t));
// update total length of messages
- ctx->rx.length += hdr.length + 1;
+ ctx->rx_mbx.length += 2;
+ /* set callback for DSR */
+ ctx->rx_cb_current = ctx->rx_cb_mbx;
// raise interruption
- maximus_pending_isrs |= (1 << HAL_HLE_INTERRUPT_IPMBOX);
+ maximus_pending_isrs |= (1 << HAL_IPMBOX_RX_INTERRUPT);
ret = 0;
}
@@ -286,7 +287,7 @@ maximus_ether_recv_data (ipmbox_t *ctx, sci_msg_t *msg)
}
int
-maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
+maximus_ether_recv_empty_buf (ipmbox_t *ctx, sci_msg_t *msg)
{
int ret = -1;
@@ -309,31 +310,10 @@ maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
}
else
{
- ipmbox_msg_hdr_t hdr;
+ ipmbox_msg_empty_buf_t msg_empty_buf;
u32 buffer_nb; // number of buffers to be allocated
uint i;
- // set hdr type
- hdr.type = HLE_MSG_TYPE_BUFFER_ADD;
-
- // set hdr length
- hdr.length = 1;
-
- // set hdr param
- // alloc type (3 bits):
- // 0 for DATA buffer allocation
- // 1 for MME buffer allocation
- // 2 for INTERFACE buffer allocation
- hdr.param = 0;
- if (ETHERNET_TYPE_MME_BUFFER_ADD == msg->hdr.ether->type)
- {
- hdr.param = 1;
- }
- if (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == msg->hdr.ether->type)
- {
- hdr.param = 2;
- }
-
// get requested buffer nb
memcpy(&buffer_nb, msg->data_begin, sizeof(u32));
if ((int)sizeof(u32) != sci_msg_pop(msg, sizeof(u32)))
@@ -344,21 +324,22 @@ maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
}
else
{
- if (MAXIMUS_HLE_MAILBOX_MAX_SIZE <= ctx->rx.length + (hdr.length + 1) * buffer_nb)
+ if (IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF <= \
+ ctx->rx_empty_buf.length + buffer_nb)
{
errno = ENOSPC;
station_log(&my_station, STATION_LOG_WARNING, STATION_LOGTYPE_ETHER,
- "%s: errno = %d because mailbox is full", __FUNCTION__, errno);
- dbg_assert_print(!ctx->warning_assert, "errno = %d because mailbox is full", errno);
+ "%s: errno = %d because empty buffer queue is full", __FUNCTION__, errno);
+ dbg_assert_print(!ctx->warning_assert, "errno = %d because empty buffer queue is full", errno);
// reset total length of messages
- ctx->rx.length = 0;
+ ctx->rx_empty_buf.length = 0;
}
- /* Update mailbox. */
- for (i = ctx->rx.length; i < ctx->rx.length + (hdr.length + 1) * buffer_nb; i += hdr.length + 1)
+ /* Update empty buffer queue. */
+ for (i = ctx->rx_empty_buf.length; i < ctx->rx_empty_buf.length + buffer_nb; i ++)
{
u32 buffer_id;
- maximus_hle_buffer_t *buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
+ maximus_ipmbox_buffer_t *buffer = (maximus_ipmbox_buffer_t *)malloc(sizeof(maximus_ipmbox_buffer_t));
// get buffer id
memcpy(&buffer_id, msg->data_begin, sizeof(u32));
@@ -370,23 +351,22 @@ maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
}
else
{
- // set hdr
- memcpy(&ctx->rx.mailbox[i], &hdr, sizeof(ipmbox_msg_hdr_t));
-
// set buffer pointer (32 bits): pointer to allocated buffer
ctx->last_buffer->next = buffer;
ctx->last_buffer = buffer;
ctx->last_buffer->next = NULL;
ctx->last_buffer->id = buffer_id;
- ctx->last_buffer->data = (u32 *)malloc(2048);
- ctx->rx.mailbox[i+1] = (u32)ctx->last_buffer->data;
+ ctx->last_buffer->data = (u32 *) calloc (2048, sizeof (u8));
+ msg_empty_buf.buffer_addr = (u32)ctx->last_buffer->data;
+ memcpy (&ctx->rx_empty_buf.mailbox[i], &msg_empty_buf,
+ sizeof (ipmbox_msg_empty_buf_t));
}
}
// update total length of messages
- ctx->rx.length += (hdr.length + 1) * buffer_nb;
+ ctx->rx_empty_buf.length += buffer_nb;
// raise interruption
- maximus_pending_isrs |= (1 << HAL_HLE_INTERRUPT_IPMBOX);
+ maximus_pending_isrs |= (1 << HAL_IPMBOX_BUF_INTERRUPT);
ret = 0;
}
@@ -395,17 +375,6 @@ maximus_ether_recv_buffer_add (ipmbox_t *ctx, sci_msg_t *msg)
return ret;
}
-/**
- * Send an Ether SCI message of type DATA, MME, BUFFER_RELEASED, or SNIFFER to Maximus.
- * \param ctx ipmbox current context
- * \param type type of message (DATA, MME, BUFFER_RELEASED, or SNIFFER)
- * \param flags not used
- * \param data_length sci message data length to send
- * \param data pointer to sci message data to send
- * \return 0 if ok, -1 if it fails with errno =
- * - EINVAL if ctx or data are null, or of data length equals 0
- * if 'sci_send()' fails, it sets errno
- */
int
maximus_ether_send (ipmbox_t *ctx, u8 type, u8 flags, uint data_length, u32 *data)
{
@@ -414,18 +383,14 @@ maximus_ether_send (ipmbox_t *ctx, u8 type, u8 flags, uint data_length, u32 *dat
dbg_assert_ptr(ctx);
dbg_assert((ETHERNET_TYPE_NB > type)
&& (ETHERNET_TYPE_NONE < type)
- && (ETHERNET_TYPE_DATA_BUFFER_ADD != type)
- && (ETHERNET_TYPE_MME_BUFFER_ADD != type)
- && (ETHERNET_TYPE_INTERFACE_BUFFER_ADD != type));
+ && (ETHERNET_TYPE_BUFFER_ADD != type));
dbg_assert(ETHERNET_FLAG_MAX >= flags);
dbg_assert(0 != data_length);
dbg_assert_ptr(data);
if ( (NULL == ctx)
|| (ETHERNET_TYPE_NB <= type)
|| (ETHERNET_TYPE_NONE >= type)
- || (ETHERNET_TYPE_DATA_BUFFER_ADD == type)
- || (ETHERNET_TYPE_MME_BUFFER_ADD == type)
- || (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == type)
+ || (ETHERNET_TYPE_BUFFER_ADD == type)
|| (ETHERNET_FLAG_MAX < flags)
|| (0 == data_length)
|| (NULL == data) )
@@ -454,7 +419,7 @@ maximus_ether_send (ipmbox_t *ctx, u8 type, u8 flags, uint data_length, u32 *dat
{
station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
"%s: errno = %d", __FUNCTION__, errno);
- dbg_assert_print(false, "errno = %d when pushing SCI message", errno);
+ dbg_assert_print(false, "errno = %d when pushing SCI message", errno);
}
else
{
diff --git a/cesar/hal/ipmbox/maximus/src/maximus_ipmbox.c b/cesar/hal/ipmbox/maximus/src/maximus_ipmbox.c
new file mode 100644
index 0000000000..5e5b5e92c5
--- /dev/null
+++ b/cesar/hal/ipmbox/maximus/src/maximus_ipmbox.c
@@ -0,0 +1,508 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/maximus/src/maximus_ipmbox.c
+ * \brief HAL IPMBox functions for Maximus.
+ * \ingroup hal_ipmbox_maximus
+ */
+
+#include "common/std.h"
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h"
+#include "hal/ipmbox/maximus/inc/maximus_ether.h" // for 'maximus_ether_recv()'
+#include "hal/ipmbox/maximus/inc/maximus_interrupts.h" // for 'HAL_IPMBOX_INTERRUPT_IPMBOX' and 'HAL_IPMBOX_INTERRUPT_PRIORITY'
+#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
+#include "host/station/station.h" // for 'station_log()'
+#include "common/ipmbox/msg.h"
+#include "ecos/packages/hal/maximus/arch/current/include/hal_host_intr.h"
+#include <string.h> // for 'memset'
+#include <stdlib.h> // for 'free'
+#include <errno.h>
+
+#include "interface/sniffer/mmtype.h"
+#include "common/defs/homeplugAV.h"
+
+#ifdef ECOS
+static cyg_uint32 _ipmbox_ecos_rx_isr(cyg_vector_t vector, cyg_addrword_t data)
+{
+ cyg_drv_interrupt_mask(HAL_IPMBOX_RX_INTERRUPT);
+ cyg_drv_interrupt_acknowledge(HAL_IPMBOX_RX_INTERRUPT);
+ return CYG_ISR_CALL_DSR; // cause DSR to be run
+}
+
+static cyg_uint32 _ipmbox_ecos_buf_isr(cyg_vector_t vector, cyg_addrword_t data)
+{
+ cyg_drv_interrupt_mask(HAL_IPMBOX_BUF_INTERRUPT);
+ cyg_drv_interrupt_acknowledge(HAL_IPMBOX_BUF_INTERRUPT);
+ return CYG_ISR_CALL_DSR; // cause DSR to be run
+}
+
+static void _ipmbox_ecos_buf_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
+{
+ /* nothing to do except calling the ipmbox dsr */
+ ipmbox_t *ctx = (ipmbox_t *)data;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(ctx->empty_buf_cb);
+ dbg_assert_ptr(ctx->buf_user_data);
+ if ((NULL != ctx)
+ && (NULL != ctx->empty_buf_cb)
+ && (NULL != ctx->buf_user_data))
+ {
+ (*ctx->empty_buf_cb)(ctx->buf_user_data);
+ }
+ /* HAL_IPMBOX_BUF_INTERRUPT will be unmasked in ipmbox_empty_buf_get */
+ return;
+}
+
+static void _ipmbox_ecos_rx_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
+{
+ /* Only one thing to do: calling the appropriate ipmbox dsr. */
+ ipmbox_t *ctx = (ipmbox_t *) data;
+ dbg_assert_ptr (ctx);
+ dbg_assert_ptr (ctx->rx_cb_data);
+ dbg_assert_ptr (ctx->rx_cb_mbx);
+ dbg_assert_ptr (ctx->rx_cb_current);
+ dbg_assert_ptr (ctx->rx_data_user_data);
+ dbg_assert_ptr (ctx->rx_mbx_user_data);
+ dbg_assert ((ctx->rx_cb_current == ctx->rx_cb_mbx)
+ || (ctx->rx_cb_current == ctx->rx_cb_data));
+
+ if ((NULL != ctx)
+ && (NULL != ctx->rx_cb_data)
+ && (NULL != ctx->rx_cb_mbx)
+ && (NULL != ctx->rx_cb_current)
+ && (NULL != ctx->rx_data_user_data)
+ && (NULL != ctx->rx_mbx_user_data))
+ {
+ if (ctx->rx_cb_current == ctx->rx_cb_mbx)
+ {
+ (*ctx->rx_cb_mbx) (ctx->rx_mbx_user_data, ctx->rx_mbx.mailbox,
+ ctx->rx_mbx.length);
+ /* Reset total length of messages. */
+ ctx->rx_mbx.length = 0;
+ }
+ else if (ctx->rx_cb_current == ctx->rx_cb_data)
+ {
+ (*ctx->rx_cb_data) (ctx->rx_data_user_data, ctx->rx_data.mailbox,
+ ctx->rx_data.length);
+ /* Reset total length of messages. */
+ ctx->rx_data.length = 0;
+ }
+
+ ctx->rx_cb_current = NULL;
+ }
+ cyg_drv_interrupt_unmask(HAL_IPMBOX_RX_INTERRUPT);
+ return;
+}
+#endif /* ECOS */
+
+ipmbox_t *
+ipmbox_init (void)
+{
+ static ipmbox_t ctx;
+ static maximus_ipmbox_buffer_t first_buffer;
+
+ memset(&ctx, '\0', sizeof(ipmbox_t));
+
+ // initialize linked list of allocated buffers
+ ctx.first_buffer = &first_buffer;
+ ctx.first_buffer->next = NULL;
+ ctx.first_buffer->id = 0;
+ ctx.first_buffer->data = NULL;
+ ctx.last_buffer = ctx.first_buffer;
+
+ // register ether_recv to the sci layer
+ sci_register_callback(my_station.sci, SCI_MSG_TYPE_ETHERNET, maximus_ether_recv, &ctx);
+
+#ifdef ECOS
+ // Register the ipmbox RX_ISR and DSR into eCos.
+ cyg_drv_interrupt_create(HAL_IPMBOX_RX_INTERRUPT,
+ HAL_IPMBOX_INTERRUPT_PRIORITY,
+ (cyg_addrword_t)&ctx,
+ _ipmbox_ecos_rx_isr,
+ _ipmbox_ecos_rx_dsr,
+ &ctx.ipmbox_rx_interrupt_handle,
+ &ctx.ipmbox_rx_interrupt);
+ cyg_drv_interrupt_attach(ctx.ipmbox_rx_interrupt_handle);
+ cyg_drv_interrupt_mask(HAL_IPMBOX_RX_INTERRUPT);
+
+ // Register the ipmbox empty buffer ISR and DSR into eCos.
+ cyg_drv_interrupt_create(HAL_IPMBOX_BUF_INTERRUPT,
+ HAL_IPMBOX_INTERRUPT_PRIORITY,
+ (cyg_addrword_t)&ctx,
+ _ipmbox_ecos_buf_isr,
+ _ipmbox_ecos_buf_dsr,
+ &ctx.ipmbox_buf_interrupt_handle,
+ &ctx.ipmbox_buf_interrupt);
+ cyg_drv_interrupt_attach(ctx.ipmbox_buf_interrupt_handle);
+ cyg_drv_interrupt_mask(HAL_IPMBOX_BUF_INTERRUPT);
+#endif /* ECOS */
+
+ return &ctx;
+}
+
+void
+ipmbox_register_rx_data_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_rx_cb_t rx_cb_data)
+{
+ dbg_assert (ctx);
+ dbg_assert (rx_cb_data);
+ ctx->rx_data_user_data = data_user_data;
+ ctx->rx_cb_data = rx_cb_data;
+}
+
+void
+ipmbox_register_rx_mbx_cb (ipmbox_t *ctx, void *user_data,
+ ipmbox_rx_cb_t rx_cb_mbx)
+{
+ dbg_assert (ctx);
+ dbg_assert (rx_cb_mbx);
+ ctx->rx_mbx_user_data = user_data;
+ ctx->rx_cb_mbx = rx_cb_mbx;
+}
+
+void
+ipmbox_register_empty_buf_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_empty_buf_cb_t empty_buf_cb)
+{
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(data_user_data);
+ dbg_assert_ptr(empty_buf_cb);
+
+ if ((NULL == ctx)
+ || (NULL == data_user_data)
+ || (NULL == empty_buf_cb))
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ ctx->buf_user_data = data_user_data;
+ ctx->empty_buf_cb = empty_buf_cb;
+ }
+}
+
+/**
+ * Activate ipmbox interruptions.
+ * \param ctx ipmbox context
+ * \param activation indicates if interruptions are activated or deactivated
+ * set errno to:
+ * - EINVAL if ctx is NULL
+ */
+void
+ipmbox_activate (ipmbox_t *ctx, bool activation)
+{
+ dbg_assert_ptr(ctx);
+ if (NULL == ctx)
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+#ifdef ECOS
+ if (activation)
+ {
+ cyg_drv_interrupt_unmask(HAL_IPMBOX_RX_INTERRUPT);
+ /* HAL_IPMBOX_BUF_INTERRUPT will be unmasked in ipmbox_empty_buf_get */
+ }
+ else
+ {
+ cyg_drv_interrupt_mask(HAL_IPMBOX_RX_INTERRUPT);
+ cyg_drv_interrupt_mask(HAL_IPMBOX_BUF_INTERRUPT);
+ }
+#endif /* ECOS */
+ }
+}
+
+/**
+ * Uninitialise the HAL IPMBOX.
+ * \param ctx ipmbox context
+ * set errno to:
+ * - EINVAL if ctx is NULL
+ */
+void
+ipmbox_uninit (ipmbox_t *ctx)
+{
+ dbg_assert_ptr(ctx);
+ if (NULL == ctx)
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ // release allocated buffers
+ maximus_ipmbox_buffer_t *current_buffer = ctx->first_buffer->next;
+ maximus_ipmbox_buffer_t *next_buffer = NULL;
+ while (NULL != current_buffer)
+ {
+ next_buffer = current_buffer->next;
+ free(current_buffer->data);
+ free(current_buffer);
+ current_buffer = next_buffer;
+ }
+
+ // reset ipmbox context
+ memset(ctx, '\0', sizeof(ipmbox_t));
+ }
+}
+
+void
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(first_msg);
+ dbg_assert(2 == length); /* TODO: length always 2 ? */
+ if ((NULL == ctx)
+ || (NULL == first_msg)
+ || (2 != length)) /* TODO */
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ ipmbox_msg_data_t msg_data;
+ // to release buffer
+ bool found = false;
+ /* TODO : mme tag ?*/
+
+ // get buffer pointer
+ memcpy (&msg_data, first_msg, sizeof (ipmbox_msg_data_t));
+
+ maximus_ipmbox_buffer_t *current_buffer = ctx->first_buffer;
+ maximus_ipmbox_buffer_t *previous_buffer = current_buffer;
+
+ // send DATA to Maximus
+ if (0 != maximus_ether_send (ctx, ETHERNET_TYPE_DATA, ETHERNET_FLAG_NONE,
+ ipmbox_msg_get_data_length (msg_data.header),
+ (u32 *) msg_data.buffer_addr))
+ {
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ dbg_assert_print(false, "errno = %d when transmitting an Ethernet packet", errno);
+ }
+
+ // check that this pointer is still allocated
+ while ((NULL != current_buffer->next) && !found)
+ {
+ previous_buffer = current_buffer;
+ current_buffer = current_buffer->next;
+ // pointer to buffer to release
+ found = (msg_data.buffer_addr == (u32) current_buffer->data);
+ }
+ dbg_assert(found);
+ if (!found)
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ // for BUFFER RELEASED message
+ u32 id = current_buffer->id;
+
+ // before deallocating buffer, link previous to next,
+ // and update last buffer if needed
+ previous_buffer->next = current_buffer->next;
+ if (current_buffer == ctx->last_buffer)
+ {
+ ctx->last_buffer = previous_buffer;
+ }
+ free(current_buffer->data);
+ free(current_buffer);
+
+ // send BUFFER RELEASED to Maximus
+ if (0 != maximus_ether_send(ctx, ETHERNET_TYPE_BUFFER_RELEASED,
+ ETHERNET_FLAG_NONE, sizeof(u32), &id))
+ {
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ dbg_assert_print(false, "errno = %d when transmitting an Ethernet packet", errno);
+ }
+ }
+ }
+}
+
+void
+ipmbox_tx_empty_buf (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(first_msg);
+ dbg_assert(IPMBOX_MSG_EMPTY_BUF_WORDS == length);
+ if ((NULL == ctx)
+ || (NULL == first_msg)
+ || (IPMBOX_MSG_EMPTY_BUF_WORDS != length))
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ ipmbox_msg_empty_buf_t msg_empty_buf;
+ memcpy (&msg_empty_buf, first_msg, sizeof (ipmbox_msg_empty_buf_t));
+
+ /* Deallocate buffer. */
+ dbg_assert (msg_empty_buf.buffer_addr);
+ if (0 != msg_empty_buf.buffer_addr)
+ {
+ free ((u32 *) msg_empty_buf.buffer_addr);
+ }
+ else
+ {
+ errno = EINVAL;
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ }
+}
+
+void
+ipmbox_tx_mbx (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(first_msg);
+ dbg_assert(2 == length); /* TODO: length always 2 ? */
+ if ((NULL == ctx)
+ || (NULL == first_msg)
+ || (2 != length)) /* TODO */
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ ipmbox_msg_mbx_t msg_mbx;
+ // to release buffer
+ bool found = false;
+
+ // get buffer pointer
+ memcpy (&msg_mbx, first_msg, sizeof (ipmbox_msg_mbx_t));
+ dbg_assert (ipmbox_msg_get_mbx_type (msg_mbx.header) == \
+ IPMBOX_MSG_MBX_TYPE_MME_PRIV); /* TODO : DBG DUMP message ?*/
+ maximus_ipmbox_buffer_t *current_buffer = ctx->first_buffer;
+ maximus_ipmbox_buffer_t *previous_buffer = current_buffer;
+
+ // send MME to Maximus
+ if (0 != maximus_ether_send (ctx, ETHERNET_TYPE_MME, ETHERNET_FLAG_NONE,
+ ipmbox_msg_get_mme_priv_length (msg_mbx.header),
+ (u32 *) msg_mbx.buffer_addr))
+ {
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ dbg_assert_print(false, "errno = %d when transmitting an Ethernet packet", errno);
+ }
+
+ // check that this pointer is still allocated
+ while ((NULL != current_buffer->next) && !found)
+ {
+ previous_buffer = current_buffer;
+ current_buffer = current_buffer->next;
+ // pointer to buffer to release
+ found = (msg_mbx.buffer_addr == (u32) current_buffer->data);
+ }
+ dbg_assert(found);
+ if (!found)
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ // for BUFFER RELEASED message
+ u32 id = current_buffer->id;
+
+ // before deallocating buffer, link previous to next,
+ // and update last buffer if needed
+ previous_buffer->next = current_buffer->next;
+ if (current_buffer == ctx->last_buffer)
+ {
+ ctx->last_buffer = previous_buffer;
+ }
+ free(current_buffer->data);
+ free(current_buffer);
+
+ // send BUFFER RELEASED to Maximus
+ if (0 != maximus_ether_send(ctx, ETHERNET_TYPE_BUFFER_RELEASED,
+ ETHERNET_FLAG_NONE, sizeof(u32), &id))
+ {
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ dbg_assert_print(false, "errno = %d when transmitting an Ethernet packet", errno);
+ }
+ }
+ }
+}
+
+/**
+ * Get nb empty buffers from the empty buf queue.
+ * \param ctx ipmbox context
+ * \param msg_buf destination array for the messages
+ * \param nb number of elements of msg_buf.
+ * \return number of copied element in msg_buf.
+ */
+uint
+ipmbox_empty_buf_get (ipmbox_t *ctx, u32 *msg_buf, uint nb_requested)
+{
+ uint nb_copied = nb_requested;
+
+ dbg_assert_ptr (ctx);
+ dbg_assert_ptr (msg_buf);
+ dbg_assert (nb_requested <= IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF);
+ if ((NULL == ctx)
+ || (NULL == msg_buf)
+ || (nb_requested > IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF))
+ {
+ errno = EINVAL;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: errno = %d", __FUNCTION__, errno);
+ }
+ else
+ {
+ uint i;
+
+ if (nb_requested > ctx->rx_empty_buf.length)
+ {
+ nb_copied = ctx->rx_empty_buf.length;
+#ifdef ECOS
+ /* Cesar needs more buffers.
+ * => Unmask IT to warn Cesar when new buffers are available. */
+ cyg_drv_interrupt_unmask (HAL_IPMBOX_BUF_INTERRUPT);
+#endif /* ECOS */
+ }
+
+ memcpy (msg_buf, ctx->rx_empty_buf.mailbox, nb_copied * sizeof (u32));
+
+ /* Move elements that were not copied into the beginning of the mailbox array. */
+ for (i = 0; i < (ctx->rx_empty_buf.length - nb_copied) ; i++)
+ {
+ ctx->rx_empty_buf.mailbox[i] = ctx->rx_empty_buf.mailbox[nb_copied + i];
+ }
+
+ // decrement total length of messages
+ ctx->rx_empty_buf.length -= nb_copied;
+ }
+
+ return nb_copied;
+}
+
+uint
+ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg)
+{
+ dbg_assert_print (0, "NOT IMPLEMENTED");
+}
diff --git a/cesar/hal/hle/maximus/test/Config b/cesar/hal/ipmbox/maximus/test/Config
index 5077dbafd3..5077dbafd3 100644
--- a/cesar/hal/hle/maximus/test/Config
+++ b/cesar/hal/ipmbox/maximus/test/Config
diff --git a/cesar/hal/hle/maximus/test/Makefile b/cesar/hal/ipmbox/maximus/test/Makefile
index 1829c194d9..f4e0b01309 100644
--- a/cesar/hal/hle/maximus/test/Makefile
+++ b/cesar/hal/ipmbox/maximus/test/Makefile
@@ -2,7 +2,7 @@ BASE = ../../../..
EXTRA_HOST_CFLAGS+= -DUNIT_TEST
HOST_PROGRAMS = test_maximus_hle
test_maximus_hle_SOURCES = test_maximus_hle.c test_maximus_ipmbox.c test_maximus_ether.c
-test_maximus_hle_MODULES = lib hal/hle/maximus host
-INCLUDES = hal/hle/maximus/test/inc
+test_maximus_hle_MODULES = lib hal/ipmbox/maximus host
+INCLUDES = hal/ipmbox/maximus/test/inc
include $(BASE)/common/make/top.mk
diff --git a/cesar/hal/hle/maximus/test/src/test_maximus_ether.c b/cesar/hal/ipmbox/maximus/test/src/test_maximus_ether.c
index 992beb7af0..266eb94700 100644
--- a/cesar/hal/hle/maximus/test/src/test_maximus_ether.c
+++ b/cesar/hal/ipmbox/maximus/test/src/test_maximus_ether.c
@@ -6,24 +6,22 @@
*
* }}} */
/**
- * \file hal/hle/maximus/test/src/test_maximus_ipmbox.c
- * \brief HAL HLE ipmbox test functions for Maximus.
- * \ingroup hal_hle_maximus
+ * \file hal/ipmbox/maximus/test/src/test_maximus_ipmbox.c
+ * \brief HAL ipmbox test functions for Maximus.
+ * \ingroup hal_ipmbox_maximus
*/
#include "common/std.h"
#include "lib/test.h"
-#include "hal/hle/maximus/test/inc/test_maximus_hle.h"
-#include "hal/hle/maximus/inc/maximus_ether.h"
-#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h"
-#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/forward.h" // for 'ipmbox_t'
-#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...'
+#include "hal/ipmbox/maximus/test/inc/test_maximus_hle.h"
+#include "hal/ipmbox/maximus/inc/maximus_ether.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h"
+#include "hal/ipmbox/maximus/inc/maximus_interrupts.h"
+#include "hal/ipmbox/ipmbox.h"
#include "host/station/station.h" // for 'station_ctx_t'
#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
-#include "interface/sniffer/mmtype.h" // for 'VS_SNIFFER_REQ'
#include "common/defs/homeplugAV.h" // for 'HPAV_MTYPE_MME' and 'HPAV_M(M)TYPE_OFFSET'
+#include "common/ipmbox/msg.h"
#include "lib/swap.h" // for 'swap16()'
#include <stdio.h> // for 'printf'
#include <string.h> // for 'memset'
@@ -38,7 +36,6 @@ ipmbox_t *ctx;
void maximus_ether_fill_hdr_test_case(test_t t)
{
- printf("fill hdr\n");
test_case_begin(t, "fill hdr");
sci_msg_t msg;
@@ -52,7 +49,7 @@ void maximus_ether_fill_hdr_test_case(test_t t)
test_fail_unless ((0 == sci_msg_init(&msg, buffer, SCI_MSG_MAX_SIZE))
&& (EINVAL != errno));
msg.length = 0;
- } test_end;
+ } test_end;
test_begin(t, "fill hdr")
{
@@ -111,7 +108,6 @@ void maximus_ether_recv_test_case(test_t t)
sci_msg_t msg;
unsigned char buffer[SCI_MSG_MAX_SIZE];
- printf("recv\n");
test_case_begin(t, "recv");
test_begin(t, "sci init")
@@ -120,7 +116,7 @@ void maximus_ether_recv_test_case(test_t t)
test_fail_unless ((0 == sci_msg_init(&msg, buffer, SCI_MSG_MAX_SIZE))
&& (EINVAL != errno));
msg.length = 0;
- } test_end;
+ } test_end;
test_begin(t, "NULL msg")
{
@@ -158,11 +154,10 @@ void maximus_ether_recv_test_case(test_t t)
test_begin(t, "recv")
{
- u32 buf_nb = 1;
u32 buf_id = 1;
- u32 total_buf_nb = buf_nb;
- maximus_hle_buffer_t *first_buffer = NULL;
- maximus_hle_buffer_t *current_buffer = NULL;
+ u32 total_buf_nb = 10;
+ maximus_ipmbox_buffer_t *first_buffer = NULL;
+ maximus_ipmbox_buffer_t *current_buffer = NULL;
// ether header
ether_msg_hdr_t ether_hdr;
@@ -183,68 +178,31 @@ void maximus_ether_recv_test_case(test_t t)
ether_hdr.flags = ETHERNET_FLAG_NONE;
ether_hdr.reserved = 0;
- for (ether_hdr.type = ETHERNET_TYPE_DATA; ether_hdr.type < ETHERNET_TYPE_BUFFER_RELEASED; ether_hdr.type++)
+ for (ether_hdr.type = ETHERNET_TYPE_DATA;
+ ether_hdr.type < ETHERNET_TYPE_BUFFER_RELEASED;
+ ether_hdr.type++)
{
/* Fill sci data. */
// ether type data or mme
- if ((ETHERNET_TYPE_DATA == ether_hdr.type) || (ETHERNET_TYPE_MME == ether_hdr.type))
+ if ((ETHERNET_TYPE_DATA == ether_hdr.type)
+ || (ETHERNET_TYPE_MME == ether_hdr.type))
{
uint i;
for (i=0; i<data_length; i++)
{
data[i] = (u8)i;
}
- if (ETHERNET_TYPE_MME == ether_hdr.type)
- {
- u16 mtype = swap16(HPAV_MTYPE_MME);
- u16 mmtype = VS_SNIFFER_REQ;
- memcpy(data + HPAV_MTYPE_OFFSET, &mtype, sizeof(u16));
- memcpy(data + HPAV_MMTYPE_OFFSET, &mmtype, sizeof(u16));
- }
-
test_fail_unless (((int)data_length == sci_msg_push(&msg, data_length))
&& (EINVAL != errno)
&& (ENOSPC != errno));
memcpy(msg.data_begin, data, data_length);
}
- // ether type data buffer add
- else if (ETHERNET_TYPE_DATA_BUFFER_ADD == ether_hdr.type)
- {
- test_fail_unless (((int)sizeof(u32) == sci_msg_push(&msg, sizeof(u32)))
- && (EINVAL != errno)
- && (ENOSPC != errno));
- memcpy(msg.data_begin, &buf_nb, sizeof(u32));
- test_fail_unless (((int)sizeof(u32) == sci_msg_push(&msg, sizeof(u32)))
- && (EINVAL != errno)
- && (ENOSPC != errno));
- memcpy(msg.data_begin, &buf_id, sizeof(u32));
- }
-
- // ether type mme buffer add
- else if (ETHERNET_TYPE_MME_BUFFER_ADD == ether_hdr.type)
- {
- buf_nb = 10;
- for (buf_id = total_buf_nb + buf_nb; buf_id > total_buf_nb; buf_id--)
- {
- test_fail_unless (((int)sizeof(u32) == sci_msg_push(&msg, sizeof(u32)))
- && (EINVAL != errno)
- && (ENOSPC != errno));
- memcpy(msg.data_begin, &buf_id, sizeof(u32));
- }
- test_fail_unless (((int)sizeof(u32) == sci_msg_push(&msg, sizeof(u32)))
- && (EINVAL != errno)
- && (ENOSPC != errno));
- memcpy(msg.data_begin, &buf_nb, sizeof(u32));
- total_buf_nb += buf_nb;
- }
-
- // ether type interface buffer add
- else // (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == ether_hdr.type)
+ // ether type buffer add
+ else if (ETHERNET_TYPE_BUFFER_ADD == ether_hdr.type)
{
- buf_nb = 2;
- for (buf_id = total_buf_nb + buf_nb; buf_id > total_buf_nb; buf_id--)
+ for (buf_id = total_buf_nb; buf_id > 0; buf_id--)
{
test_fail_unless (((int)sizeof(u32) == sci_msg_push(&msg, sizeof(u32)))
&& (EINVAL != errno)
@@ -254,8 +212,7 @@ void maximus_ether_recv_test_case(test_t t)
test_fail_unless (((int)sizeof(u32) == sci_msg_push(&msg, sizeof(u32)))
&& (EINVAL != errno)
&& (ENOSPC != errno));
- memcpy(msg.data_begin, &buf_nb, sizeof(u32));
- total_buf_nb += buf_nb;
+ memcpy(msg.data_begin, &total_buf_nb, sizeof(u32));
}
// fill ether header
@@ -288,82 +245,77 @@ void maximus_ether_recv_test_case(test_t t)
/* Check results. */
// test ether type data or mme
- if ((ETHERNET_TYPE_DATA == ether_hdr.type) || (ETHERNET_TYPE_MME == ether_hdr.type))
+ if (ETHERNET_TYPE_DATA == ether_hdr.type)
{
- u32 hdr = 0; // ipmbox msg hdr
- if (ETHERNET_TYPE_MME == ether_hdr.type)
- {
- hdr = (data_length << 20) | (1 << 12) | (1 << 8) | HLE_MSG_TYPE_INTERFACE;
- }
- else
- {
- hdr = (data_length << 13) | (1 << 8) | HLE_MSG_TYPE_DATA;
- }
+ ipmbox_msg_data_t msg_data;
+ msg_data.header = ipmbox_msg_create_header_data (data_length, 0);
- test_begin(t, "ether type data or mme")
+ test_begin(t, "ether type data")
{
- test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
- && (2 == ctx->rx.length)
- && (ctx->rx.mailbox[0] == hdr)
- && (0 == memcmp((u8 *)ctx->rx.mailbox[1], data, data_length)));
- (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
- maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
- ctx->rx.length = 0;
+ test_fail_unless ((maximus_pending_isrs & (1 << HAL_IPMBOX_RX_INTERRUPT))
+ && (2 == ctx->rx_data.length)
+ && (ctx->rx_data.mailbox[0] == msg_data.header)
+ && (0 == memcmp ((u8 *) ctx->rx_data.mailbox[1], data,
+ data_length)));
+ (*ctx->rx_cb_data) (ctx->rx_data_user_data, ctx->rx_data.mailbox,
+ ctx->rx_data.length);
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+ ctx->rx_data.length = 0;
// release allocated buffer
- test_fail_unless (NULL != (u32 *)ctx->rx.mailbox[1]);
- free((u32 *)ctx->rx.mailbox[1]);
+ test_fail_unless (NULL != (u32 *)ctx->rx_data.mailbox[1]);
+ free((u32 *)ctx->rx_data.mailbox[1]);
} test_end;
}
- // test ether type data buffer add
- else if (ETHERNET_TYPE_DATA_BUFFER_ADD == ether_hdr.type)
+ else if (ETHERNET_TYPE_MME == ether_hdr.type)
{
- test_begin(t, "ether type data buffer add")
+ ipmbox_msg_mbx_t msg_mbx;
+ msg_mbx.header = ipmbox_msg_create_header_mme_priv (data_length);
+
+ test_begin(t, "ether type mme")
{
- u32 mailbox[2 * buf_nb];
- mailbox[0] = (1 << 8) | HLE_MSG_TYPE_BUFFER_ADD; // ipmbox msg hdr
- mailbox[1] = (u32)ctx->last_buffer->data; // ipmbox msg data
- first_buffer = ctx->first_buffer->next;
- current_buffer = first_buffer;
+ test_fail_unless ((maximus_pending_isrs & (1 << HAL_IPMBOX_RX_INTERRUPT))
+ && (2 == ctx->rx_mbx.length)
+ && (ctx->rx_mbx.mailbox[0] == msg_mbx.header)
+ && (0 == memcmp ((u8 *) ctx->rx_mbx.mailbox[1], data,
+ data_length)));
+ (*ctx->rx_cb_mbx) (ctx->rx_mbx_user_data, ctx->rx_mbx.mailbox,
+ ctx->rx_mbx.length);
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+ ctx->rx_mbx.length = 0;
- test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
- && (2 * buf_nb == ctx->rx.length)
- && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * buf_nb * sizeof(u32)))
- && (NULL == current_buffer->next)
- && (total_buf_nb == current_buffer->id)
- && (NULL != current_buffer->data));
- (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
- maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
- ctx->rx.length = 0;
+ // release allocated buffer
+ test_fail_unless (NULL != (u32 *)ctx->rx_mbx.mailbox[1]);
+ free((u32 *)ctx->rx_mbx.mailbox[1]);
} test_end;
}
- // test ether type mme buffer add
- else if (ETHERNET_TYPE_MME_BUFFER_ADD == ether_hdr.type)
+ // test ether type buffer add
+ else if (ETHERNET_TYPE_BUFFER_ADD == ether_hdr.type)
{
- test_begin(t, "ether type mme buffer add")
+ uint i;
+
+ test_begin(t, "ether type buffer add")
{
- uint i;
- u32 mailbox[2 * buf_nb];
- u32 hdr = (1 << 12) | (1 << 8) | HLE_MSG_TYPE_BUFFER_ADD; // ipmbox msg hdr
- first_buffer = current_buffer->next;
+ ipmbox_msg_empty_buf_t expected_msg[total_buf_nb];
+ first_buffer = ctx->first_buffer->next;
current_buffer = first_buffer;
- for (i=0; i<2*buf_nb; i+=2)
+ for (i=0; i<total_buf_nb; i++)
{
- mailbox[i] = hdr;
- mailbox[i+1] = (u32)current_buffer->data; // ipmbox msg data
+ expected_msg[i].buffer_addr = (u32) current_buffer->data;
current_buffer = current_buffer->next;
}
// check mailbox contents
- test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
- && (2 * buf_nb == ctx->rx.length)
- && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * buf_nb * sizeof(u32))));
+ test_fail_unless ((maximus_pending_isrs & (1 << HAL_IPMBOX_BUF_INTERRUPT))
+ && (total_buf_nb == ctx->rx_empty_buf.length)
+ && (0 == memcmp (ctx->rx_empty_buf.mailbox,
+ expected_msg, total_buf_nb * sizeof (u32))));
// check list of the 10 allocated buffers
current_buffer = first_buffer;
- for (i=total_buf_nb-buf_nb+1; i<total_buf_nb; i++)
+ for (i=1; i<total_buf_nb; i++)
{
test_fail_unless ((NULL != current_buffer->next)
&& (i == current_buffer->id)
@@ -374,58 +326,42 @@ void maximus_ether_recv_test_case(test_t t)
&& (total_buf_nb == current_buffer->id)
&& (NULL != current_buffer->data));
- // call rx_cb
- (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
- maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
- ctx->rx.length = 0;
+ (*ctx->empty_buf_cb)(ctx->buf_user_data);
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_BUF_INTERRUPT);
+ test_fail_unless (ctx->rx_empty_buf.length != 0);
} test_end;
- }
- // test ether type interface buffer add
- else // (ETHERNET_TYPE_INTERFACE_BUFFER_ADD == ether_hdr.type)
- {
- test_begin(t, "ether type interface buffer add")
+ test_begin (t, "empty buf get")
{
- uint i;
- u32 mailbox[2 * buf_nb];
- u32 hdr = (2 << 12) | (1 << 8) | HLE_MSG_TYPE_BUFFER_ADD; // ipmbox msg hdr
- first_buffer = current_buffer->next;
+ uint nb_requested = 4;
+ u32 msg_buf[IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF];
+ test_fail_unless (ipmbox_empty_buf_get (ctx, msg_buf, nb_requested) \
+ == nb_requested);
+ test_fail_unless (ctx->rx_empty_buf.length == total_buf_nb - nb_requested);
current_buffer = first_buffer;
- for (i=0; i<2*buf_nb; i+=2)
+ for (i = 0; i < nb_requested; i++)
{
- mailbox[i] = hdr;
- mailbox[i+1] = (u32)current_buffer->data; // ipmbox msg data
+ test_fail_unless ((u32) current_buffer->data == msg_buf[i]);
current_buffer = current_buffer->next;
}
- // check mailbox contents
- test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
- && (2 * buf_nb == ctx->rx.length)
- && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * buf_nb * sizeof(u32))));
-
- // check list of the 2 allocated buffers
- current_buffer = first_buffer;
- for (i=total_buf_nb-buf_nb+1; i<total_buf_nb; i++)
+ uint remaining_length = ctx->rx_empty_buf.length;
+ nb_requested = 22;
+ test_fail_unless (ipmbox_empty_buf_get (ctx, msg_buf, nb_requested) \
+ == remaining_length);
+ for (i = 0; i < remaining_length; i++)
{
- test_fail_unless ((NULL != current_buffer->next)
- && (i == current_buffer->id)
- && (NULL != current_buffer->data));
+ test_fail_unless ((u32) current_buffer->data == msg_buf[i]);
current_buffer = current_buffer->next;
}
- test_fail_unless ((NULL == current_buffer->next)
- && (total_buf_nb == current_buffer->id)
- && (NULL != current_buffer->data));
- // call rx_cb
- (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
- maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
- ctx->rx.length = 0;
+ test_fail_unless (ctx->rx_empty_buf.length == 0);
} test_end;
test_begin(t, "release allocated buffers")
{
uint rls_buf_nb = 0;
- maximus_hle_buffer_t *next_buffer = NULL;
+ maximus_ipmbox_buffer_t *next_buffer = NULL;
current_buffer = ctx->first_buffer->next;
while (NULL != current_buffer)
{
@@ -435,6 +371,7 @@ void maximus_ether_recv_test_case(test_t t)
current_buffer = next_buffer;
rls_buf_nb++;
}
+ ctx->first_buffer->next = NULL;
test_fail_unless (total_buf_nb == rls_buf_nb);
} test_end;
}
@@ -491,32 +428,6 @@ void maximus_ether_recv_test_case(test_t t)
// reset errno
errno = 0;
} test_end;
-
- // test ether type sniffer
- ether_hdr.type = ETHERNET_TYPE_SNIFFER;
-
- // fill ether header
- test_fail_unless (((int)sizeof(ether_msg_hdr_t) == sci_msg_push(&msg, sizeof(ether_msg_hdr_t)))
- && (EINVAL != errno)
- && (ENOSPC != errno));
- memcpy(msg.data_begin, &ether_hdr, sizeof(ether_msg_hdr_t));
-
- test_begin(t, "ether type sniffer")
- {
- dbg_fatal_try_begin
- {
- test_fail_unless ((0 > (maximus_ether_recv(&msg, ctx)))
- && (EINVAL == errno));
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("ether type sniffer\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
-
- // reset errno
- errno = 0;
- } test_end;
} test_end;
}
@@ -533,7 +444,6 @@ void maximus_ether_send_test_case(test_t t)
// initialize data
memset(data, '\0', data_length);
- printf("send\n");
test_case_begin(t, "send");
test_begin(t, "send incorrect flags")
@@ -594,10 +504,9 @@ void maximus_ether_send_test_case(test_t t)
for (type = ETHERNET_TYPE_NONE; type < ETHERNET_TYPE_NB; type++)
{
- // ether type none, data buffer add, or mme buffer add
+ // ether type none, or buffer add
if ((ETHERNET_TYPE_NONE == type)
- || (ETHERNET_TYPE_DATA_BUFFER_ADD == type)
- || (ETHERNET_TYPE_MME_BUFFER_ADD == type))
+ || (ETHERNET_TYPE_BUFFER_ADD == type))
{
test_begin(t, "send invalid")
{
@@ -620,13 +529,11 @@ void maximus_ether_send_test_case(test_t t)
// ether type data, mme, buffer released, or sniffer
else if ((ETHERNET_TYPE_DATA == type)
|| (ETHERNET_TYPE_MME == type)
- || (ETHERNET_TYPE_BUFFER_RELEASED == type)
- || (ETHERNET_TYPE_SNIFFER == type))
+ || (ETHERNET_TYPE_BUFFER_RELEASED == type))
{
// ether type data, mme, or sniffer
if ((ETHERNET_TYPE_DATA == type)
- || (ETHERNET_TYPE_MME == type)
- || (ETHERNET_TYPE_SNIFFER == type))
+ || (ETHERNET_TYPE_MME == type))
{
// set data
int i;
@@ -660,7 +567,6 @@ void maximus_ether_send_test_case(test_t t)
test_begin(t, "ether message")
{
unsigned char buffer[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
ether_msg_hdr_t *ether_hdr;
int fd_in = -1;
@@ -674,7 +580,6 @@ void maximus_ether_send_test_case(test_t t)
&& (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
// set sci and ether headers pointers
- sci_hdr = (sci_msg_hdr_t *)buffer;
ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
// check ether header
@@ -696,7 +601,8 @@ void maximus_ether_send_test_case(test_t t)
void ether_test_suite(test_t t)
{
- int user_data = 1234567890;
+ int rx_user_data = 0x12345678;
+ int buf_user_data = 0xFFFFFFFF;
// reset errno
errno = 0;
@@ -705,9 +611,11 @@ void ether_test_suite(test_t t)
station_log_set_level(&my_station, STATION_LOG_DEBUG);
station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
- ctx = ipmbox_init ((void*)&user_data,
- &ipmbox_rx_cb);
+ ctx = ipmbox_init ();
ctx->warning_assert = true;
+ ipmbox_register_rx_data_cb (ctx, (void *) &rx_user_data, &rx_cb_data);
+ ipmbox_register_rx_mbx_cb (ctx, (void *) &rx_user_data, &rx_cb_mbx);
+ ipmbox_register_empty_buf_cb (ctx, (void *) &buf_user_data, &empty_buf_cb);
ipmbox_activate (ctx, true);
test_suite_begin(t, "ether");
@@ -715,5 +623,6 @@ void ether_test_suite(test_t t)
maximus_ether_recv_test_case(t);
maximus_ether_send_test_case(t);
+ ipmbox_uninit (ctx);
station_down (&my_station);
}
diff --git a/cesar/hal/ipmbox/maximus/test/src/test_maximus_ipmbox.c b/cesar/hal/ipmbox/maximus/test/src/test_maximus_ipmbox.c
new file mode 100644
index 0000000000..1b56f7c524
--- /dev/null
+++ b/cesar/hal/ipmbox/maximus/test/src/test_maximus_ipmbox.c
@@ -0,0 +1,337 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/maximus/test/src/test_maximus_ipmbox.c
+ * \brief HAL ipmbox test functions for Maximus.
+ * \ingroup hal_ipmbox_maximus
+ */
+
+#include "common/std.h"
+#include "lib/test.h"
+#include "hal/ipmbox/maximus/test/inc/test_maximus_hle.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
+#include "hal/ipmbox/ipmbox.h"
+#include "host/station/station.h" // for 'station_ctx_t'
+#include "host/fwd.h" // for 'sci_msg_t'
+#include "maximus/common/types/ethernet_types.h" // for 'ether_msg_hdr_t'
+#include "common/ipmbox/msg.h"
+#include <stdio.h> // for 'printf'
+#include <string.h> // for 'memset'
+#include <unistd.h> // for 'read'
+#include <fcntl.h> // for 'read'
+#include <stdlib.h> // for 'malloc'
+#include <errno.h>
+
+extern uint32_t maximus_pending_isrs; // used in 'station.c'
+extern station_ctx_t my_station;
+ipmbox_t *ctx;
+
+static void
+test_buffer_released (test_t t, u32 buffer_id)
+{
+ test_begin(t, "ether message BUFFER RELEASED")
+ {
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+ ether_msg_hdr_t *ether_hdr;
+ int fd_in = -1;
+
+ // open pipe or socket
+ fd_in = maximus_ether_open(&my_station);
+
+ // read sci and ether headers
+ memset(buffer, '\0', SCI_MSG_MAX_SIZE);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, buffer, sizeof(sci_msg_hdr_t)))
+ && (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
+
+ // set sci and ether headers pointers
+ ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
+
+ // check ether header
+ test_fail_unless ((ETHERNET_TYPE_BUFFER_RELEASED == ether_hdr->type)
+ && (ETHERNET_FLAG_NONE == ether_hdr->flags));
+
+ // read the remaining part of message
+ test_fail_unless (sizeof(u32) == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), sizeof(u32)));
+
+ // check ether data
+ test_fail_unless (buffer_id == *(buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t)));
+
+ // close pipe
+ maximus_ether_close(fd_in);
+ } test_end;
+}
+
+static void
+test_ether_msg (test_t t, u8 *frame, int frame_length, u8 ether_type)
+{
+ // check that the correct ether message has been sent to Maximus
+ test_begin(t, "ether message")
+ {
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+ ether_msg_hdr_t *ether_hdr;
+ int fd_in = -1;
+
+ // open pipe or socket
+ fd_in = maximus_ether_open(&my_station);
+
+ // read sci and ether headers
+ memset(buffer, '\0', SCI_MSG_MAX_SIZE);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, buffer, sizeof(sci_msg_hdr_t)))
+ && (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
+
+ // set sci and ether headers pointers
+ ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
+
+ // check ether header
+ test_fail_unless ((ether_type == ether_hdr->type)
+ && (ETHERNET_FLAG_NONE == ether_hdr->flags));
+
+ // read the remaining part of message
+ test_fail_unless (frame_length == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
+
+ // check ether data
+ test_fail_unless (0 == memcmp(frame, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
+
+ // close pipe
+ maximus_ether_close(fd_in);
+ } test_end;
+}
+
+void ipmbox_init_test_case(test_t t)
+{
+ test_case_begin(t, "init");
+
+ test_begin(t, "init")
+ {
+ ctx = ipmbox_init ();
+ test_fail_unless ((EINVAL != errno)
+ && (NULL != ctx)
+ && (NULL != ctx->first_buffer)
+ && (NULL == ctx->first_buffer->next)
+ && (0 == ctx->first_buffer->id)
+ && (NULL == ctx->first_buffer->data)
+ && (ctx->last_buffer == ctx->first_buffer)
+ && (0 == ctx->rx_data.length)
+ && (0 == ctx->rx_mbx.length)
+ && (0 == ctx->rx_empty_buf.length));
+ ctx->warning_assert = true;
+ } test_end;
+
+ maximus_pending_isrs = 0;
+
+ return;
+}
+
+void
+ipmbox_register_rx_cb_test_case (test_t t)
+{
+ test_case_begin (t, "register rx cb");
+
+ test_begin(t, "register rx cb")
+ {
+ int rx_user_data = 42;
+
+ ipmbox_register_rx_data_cb (ctx, (void *) &rx_user_data,
+ &rx_cb_data);
+ ipmbox_register_rx_mbx_cb (ctx, (void *) &rx_user_data,
+ &rx_cb_mbx);
+ test_fail_unless (ctx->rx_cb_data != NULL);
+ test_fail_unless (ctx->rx_cb_mbx != NULL);
+ test_fail_unless (*(int *) ctx->rx_data_user_data == 42);
+ /* Check that the correct callback is registered. */
+ (*ctx->rx_cb_data) ((void *) &rx_user_data, NULL, 0);
+ test_fail_unless (rx_user_data == RX_CB_DATA_USER_DATA);
+ /* Check that the correct callback is registered. */
+ (*ctx->rx_cb_mbx) ((void *) &rx_user_data, NULL, 0);
+ test_fail_unless (rx_user_data == RX_CB_MBX_USER_DATA);
+ } test_end;
+}
+
+void
+ipmbox_register_empty_buf_cb_test_case (test_t t)
+{
+ test_case_begin (t, "register empty buf cb");
+
+ test_begin(t, "register empty buf cb")
+ {
+ int buf_user_data = 24;
+
+ ipmbox_register_empty_buf_cb (ctx, (void *) &buf_user_data,
+ &empty_buf_cb);
+ test_fail_unless (ctx->empty_buf_cb != NULL);
+ test_fail_unless (*(int *) ctx->buf_user_data == 24);
+ /* Check that the correct callback is registered. */
+ (*ctx->empty_buf_cb) ((void *) &buf_user_data);
+ test_fail_unless (buf_user_data == EMPTY_BUF_CB_USER_DATA);
+ } test_end;
+}
+
+void ipmbox_activate_test_case(test_t t)
+{
+ test_case_begin(t, "activate");
+
+ test_begin(t, "NULL ipmbox")
+ {
+ dbg_fatal_try_begin
+ {
+ ipmbox_activate (NULL, false);
+ test_fail_unless (EINVAL == errno);
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("NULL ipmbox\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+
+ test_begin(t, "activate")
+ {
+ ipmbox_activate (ctx, true);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+
+ return;
+}
+
+void ipmbox_uninit_test_case(test_t t)
+{
+ test_case_begin(t, "uninit");
+
+ test_begin(t, "uninit")
+ {
+ ipmbox_uninit(ctx);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+
+ return;
+}
+
+void ipmbox_tx_data_test_case(test_t t)
+{
+ test_case_begin(t, "tx data");
+
+ // ethernet frame data
+ int frame_length = 1200;
+ u8 frame[1200];
+ memset(frame, '\0', frame_length); // init frame
+
+ // mailbox msg
+ ipmbox_msg_data_t msg_data;
+ int i;
+
+ maximus_ipmbox_buffer_t *second_buffer = (maximus_ipmbox_buffer_t *) \
+ calloc (1, sizeof (maximus_ipmbox_buffer_t));
+ second_buffer->next = NULL;
+ second_buffer->id = 32;
+ second_buffer->data = (u32 *) calloc (frame_length, sizeof(u8));
+ for (i=0; i<frame_length; i++)
+ {
+ frame[i] = (u8)i;
+ *((u8*)second_buffer->data+i) = frame[i];
+ }
+ ctx->first_buffer->next = second_buffer;
+
+ // fill data message to send
+ msg_data.header = ipmbox_msg_create_header_data (frame_length, 0);
+ msg_data.buffer_addr = (u32) second_buffer->data;
+
+ test_begin(t, "tx data")
+ {
+ ipmbox_tx_data (ctx, (u32 *) &msg_data, 2);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+
+ /* Check results. */
+ test_ether_msg (t, frame, frame_length, ETHERNET_TYPE_DATA);
+ test_buffer_released (t, second_buffer->id);
+}
+
+void ipmbox_tx_mbx_test_case(test_t t)
+{
+ test_case_begin(t, "tx mbx");
+
+ // ethernet frame data
+ int frame_length = 1200;
+ u8 frame[1200];
+ memset(frame, '\0', frame_length); // init frame
+
+ // mailbox msg
+ ipmbox_msg_mbx_t msg_mbx;
+ int i;
+
+ maximus_ipmbox_buffer_t *second_buffer = (maximus_ipmbox_buffer_t *) \
+ calloc (1, sizeof (maximus_ipmbox_buffer_t));
+ second_buffer->next = NULL;
+ second_buffer->id = 32;
+ second_buffer->data = (u32 *) calloc (frame_length, sizeof(u8));
+ for (i=0; i<frame_length; i++)
+ {
+ frame[i] = (u8)i;
+ *((u8*)second_buffer->data+i) = frame[i];
+ }
+ ctx->first_buffer->next = second_buffer;
+
+ // fill mailbox message to send
+ msg_mbx.header = ipmbox_msg_create_header_mme_priv (frame_length);
+ msg_mbx.buffer_addr = (u32) second_buffer->data;
+
+ test_begin(t, "tx mme")
+ {
+ ipmbox_tx_mbx (ctx, (u32 *) &msg_mbx, 2);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+
+ /* Check results. */
+ test_ether_msg (t, frame, frame_length, ETHERNET_TYPE_MME);
+ test_buffer_released (t, second_buffer->id);
+}
+
+void ipmbox_tx_empty_buf_test_case(test_t t)
+{
+ test_case_begin(t, "tx empty buf");
+
+ test_begin(t, "tx empty buf")
+ {
+ // allocate buffer
+ u32 *data = (u32 *) malloc (1500);
+
+ /* Fill empty buffer message to send. */
+ ipmbox_msg_empty_buf_t empty_buf_msg;
+ empty_buf_msg.buffer_addr = (u32) data;
+
+ ipmbox_tx_empty_buf (ctx, (u32 *) &empty_buf_msg, 1);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+}
+
+void ipmbox_test_suite(test_t t)
+{
+ // reset errno
+ errno = 0;
+
+ station_init (&my_station);
+ station_log_set_level(&my_station, STATION_LOG_DEBUG);
+ station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
+
+ test_suite_begin(t, "ipmbox");
+ ipmbox_init_test_case(t);
+ ipmbox_register_rx_cb_test_case(t);
+ ipmbox_register_empty_buf_cb_test_case(t);
+ ipmbox_activate_test_case(t);
+ ipmbox_tx_data_test_case(t);
+ ipmbox_tx_empty_buf_test_case(t);
+ ipmbox_tx_mbx_test_case(t);
+ ipmbox_uninit_test_case(t);
+
+ station_down (&my_station);
+}
diff --git a/cesar/hal/ipmbox/src/ipmbox.c b/cesar/hal/ipmbox/src/ipmbox.c
new file mode 100644
index 0000000000..e3d84f3bd8
--- /dev/null
+++ b/cesar/hal/ipmbox/src/ipmbox.c
@@ -0,0 +1,411 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/src/ipmbox.c
+ * \brief HAL mailbox layer.
+ * \ingroup hal_ipmbox
+ *
+ * this layer provide all mechanisms to manage mailboxes.
+ */
+#include "common/std.h"
+
+#include "common/ipmbox/protocol.h"
+
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/ipmbox/inc/ipmbox.h"
+#include "hal/ipmbox/inc/regs.h"
+#include "hal/ipmbox/inc/ecos.h"
+#include "hal/arch/arch.h"
+
+/** RX message buffer size. It must be equal to the max of data budget
+ * or MBX queue size. */
+#define IPMBOX_RX_MSG_BUFFER_SIZE \
+ (IPMBOX_RX_DATA_BUDGET > IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX \
+ ? IPMBOX_RX_DATA_BUDGET : IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX)
+
+/** Global context variable. */
+static ipmbox_t ipmbox_global;
+/** Ipmbox RX buffer. */
+static u32 rx_msgs[IPMBOX_RX_MSG_BUFFER_SIZE];
+
+/**
+ * Transmit a message to mailbox.
+ * \param ctx ipmbox context
+ * \param queue the queue to add the message to.
+ * \param first_msg pointer to the first message header
+ * \param length total length (in word) of messages to transmit
+ */
+PRIVATE inline void
+ipmbox_tx (ipmbox_t *ctx, ipmbox_queue_t *queue, u32 *first_msg, uint length)
+{
+ /* Copy messages to the ring buffer and warn the ARM.
+ * Lock DSR to prevent mailbox corruption. */
+ arch_dsr_lock ();
+ dbg_assert (ipmbox_queue_get_free_space (queue) >= length);
+ ipmbox_queue_copy_to (queue, first_msg, length);
+ ctx->regs->l2a_it = IPMBOX_L2A_IT;
+ arch_dsr_unlock ();
+}
+
+void
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ ipmbox_tx (ctx, &ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A],
+ first_msg, length);
+}
+
+void
+ipmbox_tx_empty_buf (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ ipmbox_tx (ctx, &ctx->queue[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_L2A],
+ first_msg, length);
+}
+
+void
+ipmbox_tx_mbx (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ ipmbox_tx (ctx, &ctx->queue[IPMBOX_QUEUE_MBX][IPMBOX_L2A],
+ first_msg, length);
+}
+
+uint
+ipmbox_empty_buf_get (ipmbox_t *ctx, u32 *msg_buf, uint nb)
+{
+ dbg_claim (ctx);
+ dbg_claim (msg_buf);
+ dbg_claim (nb);
+ ipmbox_queue_t *queue = &ctx->queue[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_A2L];
+ /* Lock DSR because threads can call this function. */
+ arch_dsr_lock ();
+ /* Clear interruption. */
+ ctx->regs->a2l_it = IPMBOX_A2L_IT_ACK;
+ uint size = ipmbox_queue_get_used_space (queue);
+ /* We need to unmask the interruption to be aware of new buffers. */
+ if (size < nb)
+ ctx->regs->a2l_it_mask &= ~IPMBOX_A2L_IT_ACK;
+ uint nb_elements = MIN (size, nb);
+ if (size)
+ ipmbox_queue_copy_from (queue, msg_buf, nb_elements);
+ /* Unlock DSR. */
+ arch_dsr_unlock ();
+ return nb_elements;
+}
+
+/**
+ * IPMBox receive ISR handler function for empty buffers.
+ * \param vector interrupt vector number
+ * \param data user interrupt arguments
+ * \return isr status and if DSR is needed
+ */
+cyg_uint32
+ipmbox_empty_buf_isr (cyg_vector_t vector, cyg_addrword_t data)
+{
+ /* Get context. */
+ ipmbox_t *ctx = (ipmbox_t *) data;
+ dbg_claim (ctx);
+ /* Block this interrupt from occurring until the DSR completes. */
+ ctx->regs->a2l_it_mask = IPMBOX_A2L_IT_ACK;
+ /* Acknowledge interrupt (because of shared child interrupt). */
+ ipmbox_interrupt_acknowledge (IPMBOX_EMPTY_BUF_IT_NUM);
+ /* Tell the kernel that chained interrupt processing is done and the DSR
+ * needs to be executed next. */
+ return (CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
+}
+
+/**
+ * IPMBox receive DSR handler function.
+ * \param vector interrupt vector number
+ * \param count ?
+ * \param data user interrupt arguments
+ */
+void
+ipmbox_empty_buf_dsr (cyg_vector_t vector, cyg_ucount32 count,
+ cyg_addrword_t data)
+{
+ ipmbox_t *ctx = (ipmbox_t*) data;
+ dbg_claim (ctx);
+ /* Send all received messages to the upper layer. */
+ ctx->empty_buf_cb (ctx->empty_buf_cb_user_data);
+}
+
+/**
+ * IPMBox receive ISR handler function.
+ * \param vector interrupt vector number
+ * \param data user interrupt arguments
+ * \return isr status and if DSR is needed
+ */
+cyg_uint32
+ipmbox_rx_isr (cyg_vector_t vector, cyg_addrword_t data)
+{
+ /* Get context. */
+ ipmbox_t *ctx = (ipmbox_t *) data;
+ dbg_claim (ctx);
+ /* Block this interrupt from occurring until the DSR completes. */
+ ctx->regs->a2l_it_mask |= IPMBOX_A2L_IT;
+ /* Acknowledge interrupt (because of shared child interrupt). */
+ ipmbox_interrupt_acknowledge (IPMBOX_RX_IT_NUM);
+ /* Tell the kernel that chained interrupt processing is done and the DSR
+ * needs to be executed next. */
+ return (CYG_ISR_HANDLED | CYG_ISR_CALL_DSR);
+}
+
+/**
+ * IPMBox receive DSR handler function.
+ * \param vector interrupt vector number
+ * \param count ?
+ * \param data user interrupt arguments
+ */
+void
+ipmbox_rx_dsr (cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
+{
+ ipmbox_t *ctx = (ipmbox_t*) data;
+ uint budget_data = IPMBOX_RX_DATA_BUDGET;
+ uint size;
+ bool call_dsr = false;
+ ipmbox_queue_t *queue_data = &ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L];
+ ipmbox_queue_t *queue_mbx = &ctx->queue[IPMBOX_QUEUE_MBX][IPMBOX_A2L];
+ /* Check parameters. */
+ dbg_claim (ctx->rx_cb_data);
+ dbg_claim (ctx->rx_cb_mbx);
+ /* Process DATA queue. */
+ do
+ {
+ size = ipmbox_queue_get_used_space (queue_data);
+ if (size)
+ {
+ /* Check and update budget_data. */
+ if (budget_data == 0)
+ {
+ call_dsr = true;
+ break;
+ }
+ if (size > budget_data)
+ size = budget_data;
+ budget_data -= size;
+ /* Copy messages out of mailbox, because callback can not handle
+ * circular buffers. */
+ ipmbox_queue_copy_from (queue_data, rx_msgs, size);
+ /* Send all received messages to the upper layer. */
+ ctx->rx_cb_data (ctx->rx_cb_data_user_data, rx_msgs, size);
+ }
+ }
+ while (size);
+
+ /* Process MBX queue. */
+ do
+ {
+ /* Clear interrupt. We can do this for the IT because before leaving
+ * this function, the DATA queue size is checked. */
+ ctx->regs->a2l_it = IPMBOX_A2L_IT;
+ size = ipmbox_queue_get_used_space (queue_mbx);
+ if (size)
+ {
+ /* Copy messages out of mailbox, because callback can not handle
+ * circular buffers. */
+ ipmbox_queue_copy_from (queue_mbx, rx_msgs, size);
+ /* Send all received messages to the upper layer. */
+ ctx->rx_cb_mbx (ctx->rx_cb_mbx_user_data, rx_msgs, size);
+ }
+ }
+ while (size);
+
+ /* Check DATA QUEUE used space to avoid IT enabling. */
+ if (ipmbox_queue_get_used_space (queue_data))
+ call_dsr = true;
+
+ if (call_dsr)
+ /* Ask to be executed again, do not activate interrupts. */
+ cyg_interrupt_post_dsr (ctx->ecos.rx_it_handle);
+ else
+ /* Allow this interrupt to occur again. */
+ ctx->regs->a2l_it_mask &= ~IPMBOX_A2L_IT;
+}
+
+uint
+ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg)
+{
+ uint size;
+ /* Only if interrupt set. */
+ if (ctx->regs->a2l_it & IPMBOX_A2L_IT)
+ {
+ ipmbox_queue_t *queue = &ctx->queue[IPMBOX_QUEUE_MBX][IPMBOX_A2L];
+ /* Clear interrupt. */
+ ctx->regs->a2l_it = IPMBOX_A2L_IT;
+ size = ipmbox_queue_get_used_space (queue);
+ if (size)
+ {
+ /* Copy messages out of mailbox, because callback can not handle
+ * circular buffers. */
+ ipmbox_queue_copy_from (queue, rx_msgs, size);
+ /* Return received messages. */
+ *first_msg = rx_msgs;
+ return size;
+ }
+ }
+ /* Nothing. */
+ return 0;
+}
+
+ipmbox_t *
+ipmbox_init (void)
+{
+ ipmbox_t *ctx = &ipmbox_global;
+
+ /* Map IPMBox registers. */
+ ctx->regs = (ipmbox_registers_t *) IPMBOX_REG_BASE_ADDR;
+ /* Map init_info structure. */
+ ipmbox_protocol_init_t *init_info = (ipmbox_protocol_init_t *)
+ ctx->regs->l2a_head;
+ /* Check version number. */
+ dbg_assert (init_info->version == IPMBOX_PROTOCOL_VERSION);
+ /* Check queues' sizes. */
+ dbg_assert (init_info->queue_size[IPMBOX_QUEUE_DATA][IPMBOX_A2L]
+ == IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_DATA);
+ dbg_assert (init_info->queue_size[IPMBOX_QUEUE_DATA][IPMBOX_L2A]
+ == IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_DATA);
+ dbg_assert (init_info->queue_size[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_A2L]
+ == IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF);
+ dbg_assert (init_info->queue_size[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_L2A]
+ == IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_EMPTY_BUF);
+ dbg_assert (init_info->queue_size[IPMBOX_QUEUE_MBX][IPMBOX_A2L]
+ == IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX);
+ dbg_assert (init_info->queue_size[IPMBOX_QUEUE_MBX][IPMBOX_L2A]
+ == IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_MBX);
+ /* Initialize DATA queues. */
+ /* Sizes. */
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].size =
+ init_info->queue_size[IPMBOX_QUEUE_DATA][IPMBOX_A2L];
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].size =
+ init_info->queue_size[IPMBOX_QUEUE_DATA][IPMBOX_L2A];
+ /* Queue pointers. */
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].ptr =
+ (ipmbox_queue_ptr_t *) &ctx->regs->a2l_tail;
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].ptr =
+ (ipmbox_queue_ptr_t *) &ctx->regs->l2a_tail;
+ /* Base pointers. */
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].base_ptr =
+ (u32*) ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].ptr->tail
+ - ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].size + 1;
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].base_ptr =
+ (u32*) ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].ptr->head;
+ /* End pointers. */
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].end_ptr =
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].base_ptr
+ + ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].size;
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].end_ptr =
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].base_ptr
+ + ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].size;
+ /* Get shared memory base address. */
+ volatile ipmbox_queue_ptr_t *shared_mem_ptr_zone = init_info->shared_mem;
+ /* Initialize other queues. */
+ uint i, j;
+ for (i = IPMBOX_QUEUE_MBX; i < IPMBOX_QUEUE_DATA; i++)
+ {
+ for (j = IPMBOX_A2L; j < IPMBOX_QUEUE_DIRECTION_NB; j++)
+ {
+ ctx->queue[i][j].ptr = shared_mem_ptr_zone;
+ shared_mem_ptr_zone++;
+ ctx->queue[i][j].base_ptr = (u32*) ctx->queue[i][j].ptr->head;
+ ctx->queue[i][j].size = init_info->queue_size[i][j];
+ ctx->queue[i][j].end_ptr = ctx->queue[i][j].base_ptr
+ + ctx->queue[i][j].size;
+ }
+ }
+ /* Reset the tail pointers for DATA queue. */
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].ptr->head =
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].ptr->tail;
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].ptr->tail =
+ ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].ptr->head;
+ /* Reset others queues. */
+ for (i = IPMBOX_QUEUE_MBX; i < IPMBOX_QUEUE_DATA; i++)
+ for (j = IPMBOX_A2L; j < IPMBOX_QUEUE_DIRECTION_NB; j++)
+ ctx->queue[i][j].ptr->tail = ctx->queue[i][j].ptr->head;
+ /* Stop all mailbox interrupts. */
+ ctx->regs->a2l_it_mask = (IPMBOX_A2L_IT | IPMBOX_A2L_IT_ACK);
+ /* Create interrupt for Rx messages. */
+ cyg_drv_interrupt_create (IPMBOX_RX_IT_NUM,
+ 0,
+ (cyg_addrword_t) ctx,
+ &ipmbox_rx_isr,
+ &ipmbox_rx_dsr,
+ &ctx->ecos.rx_it_handle,
+ &ctx->ecos.rx_it);
+ /* Attach this interrupt. */
+ cyg_drv_interrupt_attach (ctx->ecos.rx_it_handle);
+ /* Create interrupt for Empty buffers messages. */
+ cyg_drv_interrupt_create (IPMBOX_EMPTY_BUF_IT_NUM,
+ 0,
+ (cyg_addrword_t) ctx,
+ &ipmbox_empty_buf_isr,
+ &ipmbox_empty_buf_dsr,
+ &ctx->ecos.empty_buf_it_handle,
+ &ctx->ecos.empty_buf_it);
+ /* Attach this interrupt. */
+ cyg_drv_interrupt_attach (ctx->ecos.empty_buf_it_handle);
+ /* Unmask. */
+ cyg_drv_interrupt_unmask (IPMBOX_RX_IT_NUM);
+ cyg_drv_interrupt_unmask (IPMBOX_EMPTY_BUF_IT_NUM);
+ return ctx;
+}
+
+void
+ipmbox_uninit (ipmbox_t *ctx)
+{
+ /* Stop all mailbox interrupts. */
+ ctx->regs->a2l_it_mask = (IPMBOX_A2L_IT | IPMBOX_A2L_IT_ACK);
+ /* Mask. */
+ cyg_drv_interrupt_mask (IPMBOX_RX_IT_NUM);
+}
+
+void
+ipmbox_activate (ipmbox_t *ctx, bool activation)
+{
+ dbg_assert (ctx);
+ dbg_assert (ctx->rx_cb_mbx);
+ dbg_assert (ctx->rx_cb_data);
+ if (activation)
+ {
+ /* Enable the Arm to Leon Trigger Interrupt. */
+ ctx->regs->a2l_it_mask &= ~IPMBOX_A2L_IT;
+ }
+ else
+ {
+ /* Disable the Arm to Leon Trigger and Ack Interrupt. */
+ ctx->regs->a2l_it_mask |= (IPMBOX_A2L_IT | IPMBOX_A2L_IT_ACK);
+ }
+}
+
+void
+ipmbox_register_rx_data_cb (ipmbox_t *ctx, void *user_data,
+ ipmbox_rx_cb_t rx_cb_data)
+{
+ dbg_assert (ctx);
+ dbg_assert (rx_cb_data);
+ ctx->rx_cb_data = rx_cb_data;
+ ctx->rx_cb_data_user_data = user_data;
+}
+
+void
+ipmbox_register_rx_mbx_cb (ipmbox_t *ctx, void *user_data,
+ ipmbox_rx_cb_t rx_cb_mbx)
+{
+ dbg_assert (ctx);
+ dbg_assert (rx_cb_mbx);
+ ctx->rx_cb_mbx = rx_cb_mbx;
+ ctx->rx_cb_mbx_user_data = user_data;
+}
+
+void
+ipmbox_register_empty_buf_cb (ipmbox_t *ctx, void *user_data,
+ ipmbox_empty_buf_cb_t empty_buf_cb)
+{
+ dbg_assert (ctx);
+ dbg_assert (empty_buf_cb);
+ ctx->empty_buf_cb = empty_buf_cb;
+ ctx->empty_buf_cb_user_data = user_data;
+}
diff --git a/cesar/hal/ipmbox/stub/Module b/cesar/hal/ipmbox/stub/Module
new file mode 100644
index 0000000000..2a248a2de2
--- /dev/null
+++ b/cesar/hal/ipmbox/stub/Module
@@ -0,0 +1 @@
+SOURCES := ipmbox.c \ No newline at end of file
diff --git a/cesar/hal/ipmbox/stub/src/ipmbox.c b/cesar/hal/ipmbox/stub/src/ipmbox.c
new file mode 100644
index 0000000000..e1b221fb5f
--- /dev/null
+++ b/cesar/hal/ipmbox/stub/src/ipmbox.c
@@ -0,0 +1,117 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/stub/src/ipmbox.c
+ * \brief HAL IPMbox stub functions.
+ * \ingroup hal_ipmbox_stub
+ */
+#include "hal/ipmbox/ipmbox.h"
+
+ipmbox_t *
+ipmbox_init (void) __attribute__((weak));
+
+ipmbox_t *
+ipmbox_init (void)
+{
+ return NULL;
+}
+
+void
+ipmbox_uninit (ipmbox_t *ctx) __attribute__((weak));
+
+void
+ipmbox_uninit (ipmbox_t *ctx)
+{
+}
+
+void
+ipmbox_activate (ipmbox_t *ctx, bool activation) __attribute__((weak));
+
+void
+ipmbox_activate (ipmbox_t *ctx, bool activation)
+{
+}
+
+void
+ipmbox_register_rx_data_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_rx_cb_t rx_cb_data) __attribute__((weak));
+
+void
+ipmbox_register_rx_data_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_rx_cb_t rx_cb_data)
+{
+}
+
+void
+ipmbox_register_rx_mbx_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_rx_cb_t rx_cb_mbx) __attribute__((weak));
+
+void
+ipmbox_register_rx_mbx_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_rx_cb_t rx_cb_mbx)
+{
+}
+
+
+void
+ipmbox_register_empty_buf_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_empty_buf_cb_t empty_buf_cb)
+ __attribute__((weak));
+
+void
+ipmbox_register_empty_buf_cb (ipmbox_t *ctx, void *data_user_data,
+ ipmbox_empty_buf_cb_t empty_buf_cb)
+{
+}
+
+void
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length)
+ __attribute__((weak));
+
+void
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+}
+
+void
+ipmbox_tx_empty_buf (ipmbox_t *ctx, u32 *first_msg, uint length)
+ __attribute__((weak));
+
+void
+ipmbox_tx_empty_buf (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+}
+
+void
+ipmbox_tx_mbx (ipmbox_t *ctx, u32 *first_msg, uint length)
+ __attribute__((weak));
+
+void
+ipmbox_tx_mbx (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+}
+
+uint
+ipmbox_empty_buf_get (ipmbox_t *ctx, u32 *msg_buf, uint nb)
+ __attribute__((weak));
+
+uint
+ipmbox_empty_buf_get (ipmbox_t *ctx, u32 *msg_buf, uint nb)
+{
+ return 0;
+}
+
+uint
+ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg)
+ __attribute__((weak));
+
+uint
+ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg)
+{
+ return 0;
+}
diff --git a/cesar/hal/ipmbox/test/Config b/cesar/hal/ipmbox/test/Config
new file mode 100644
index 0000000000..dbdade324f
--- /dev/null
+++ b/cesar/hal/ipmbox/test/Config
@@ -0,0 +1 @@
+CONFIG_DEBUG_FATAL_CATCH=y
diff --git a/cesar/hal/ipmbox/test/Makefile b/cesar/hal/ipmbox/test/Makefile
new file mode 100644
index 0000000000..4820f10f9b
--- /dev/null
+++ b/cesar/hal/ipmbox/test/Makefile
@@ -0,0 +1,10 @@
+BASE = ../../..
+
+INCLUDES = hal/ipmbox/test/override/
+
+HOST_PROGRAMS = test_ipmbox
+
+test_ipmbox_SOURCES = ipmbox.c
+test_ipmbox_MODULES = lib hal/ipmbox ../common/ipmbox
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/hal/ipmbox/test/override/hal/ipmbox/inc/ecos.h b/cesar/hal/ipmbox/test/override/hal/ipmbox/inc/ecos.h
new file mode 100644
index 0000000000..82271c3c82
--- /dev/null
+++ b/cesar/hal/ipmbox/test/override/hal/ipmbox/inc/ecos.h
@@ -0,0 +1,58 @@
+#ifndef hal_ipmbox_inc_ipmbox_ecos_h
+#define hal_ipmbox_inc_ipmbox_ecos_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file override/hal/ipmbox/inc/ipmbox_ecos.h
+ * \brief HAL IPMBox eCos management data.
+ * \ingroup hal_ipmbox_test
+ */
+
+/* eCos stubs. */
+
+#define CYG_ISR_HANDLED 1
+#define CYG_ISR_CALL_DSR 1
+
+#define CYGNUM_HAL_INTERRUPT_GIC2_14 0x42
+#define CYGNUM_HAL_INTERRUPT_GIC2_13 0x42
+
+/* Types. */
+typedef unsigned long CYG_ADDRWORD;
+typedef unsigned long cyg_uint32;
+typedef unsigned long cyg_vector_t;
+typedef unsigned long cyg_addrword_t;
+typedef unsigned long cyg_ucount32;
+
+typedef struct ipmbox_ecos_t
+{
+ int rx_it;
+ int rx_it_handle;
+ int empty_buf_it;
+ int empty_buf_it_handle;
+} ipmbox_ecos_t;
+
+/* Functions. */
+#define ipmbox_interrupt_acknowledge(param) ((void) 0)
+
+#define cyg_drv_interrupt_create(...) ((void) 0)
+
+#define cyg_drv_interrupt_attach(...) ((void) 0)
+
+#define cyg_drv_interrupt_unmask(...) ((void) 0)
+
+#define cyg_drv_interrupt_mask(...) ((void) 0)
+
+extern bool dsr_posted;
+
+extern inline void
+cyg_interrupt_post_dsr (CYG_ADDRWORD intr_obj)
+{
+ dsr_posted = true;
+}
+
+#endif /* hal_ipmbox_inc_ipmbox_ecos_h */
diff --git a/cesar/hal/ipmbox/test/override/hal/ipmbox/inc/regs.h b/cesar/hal/ipmbox/test/override/hal/ipmbox/inc/regs.h
new file mode 100644
index 0000000000..ba5fd0bdc4
--- /dev/null
+++ b/cesar/hal/ipmbox/test/override/hal/ipmbox/inc/regs.h
@@ -0,0 +1,21 @@
+#ifndef hal_ipmbox_inc_ipmbox_regs_h
+#define hal_ipmbox_inc_ipmbox_regs_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file override/hal/ipmbox/inc/ipmbox_regs.h
+ * \brief HAL IPMBox registers base address.
+ * \ingroup hal_ipmbox_test
+ */
+
+extern ipmbox_registers_t regs;
+
+/* IPMBox registers base address. */
+#define IPMBOX_REG_BASE_ADDR (&regs)
+
+#endif /* hal_ipmbox_inc_ipmbox_regs_h */
diff --git a/cesar/hal/ipmbox/test/src/ipmbox.c b/cesar/hal/ipmbox/test/src/ipmbox.c
new file mode 100644
index 0000000000..d9ed882751
--- /dev/null
+++ b/cesar/hal/ipmbox/test/src/ipmbox.c
@@ -0,0 +1,502 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/ipmbox/test/src/ipmbox.c
+ * \brief HAL HLE unit test to test the ipmbox mechanisms.
+ * \ingroup hal_ipmbox
+ *
+ * This file will tests all ipmbox functions
+ */
+#include "common/std.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "lib/test.h"
+#include "lib/blk.h"
+
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/ipmbox/inc/ipmbox.h"
+#include "hal/ipmbox/inc/regs.h"
+
+#include "common/ipmbox/protocol.h"
+
+bool dsr_posted;
+bool data_cb_called;
+bool mbx_cb_called;
+bool empty_buf_cb_called;
+
+/* Shared memory size (in 32 bits words). */
+#define SHARED_MEM_SIZE (IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_DATA \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_EMPTY_BUF \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_MBX \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_DATA \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF \
+ + 8)
+
+/* Shared memory offsets. */
+#define SHMEM_PTR_ZONE 0
+#define SHMEM_A2L_MBX_QUEUE_BASE (SHMEM_PTR_ZONE + 8)
+#define SHMEM_L2A_MBX_QUEUE_BASE (SHMEM_A2L_MBX_QUEUE_BASE \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX)
+#define SHMEM_A2L_EMPTY_BUF_QUEUE_BASE (SHMEM_L2A_MBX_QUEUE_BASE \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_MBX)
+#define SHMEM_L2A_EMPTY_BUF_QUEUE_BASE (SHMEM_A2L_EMPTY_BUF_QUEUE_BASE \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF)
+#define SHMEM_A2L_DATA_QUEUE_BASE (SHMEM_L2A_EMPTY_BUF_QUEUE_BASE \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_EMPTY_BUF)
+#define SHMEM_L2A_DATA_QUEUE_BASE (SHMEM_A2L_DATA_QUEUE_BASE \
+ + IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_DATA)
+
+uint qsize [][IPMBOX_QUEUE_DIRECTION_NB] = {
+ {IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX, IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_MBX},
+ {IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF,
+ IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_EMPTY_BUF},
+ {IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_DATA,
+ IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_DATA}
+ };
+
+/* Fake hardware registers. */
+ipmbox_registers_t regs;
+
+/* Fake shared memory between LEON and ARM. */
+u32 shared_mem[SHARED_MEM_SIZE];
+
+/* Prototype declarations. */
+void
+ipmbox_rx_dsr (cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);
+
+void
+ipmbox_empty_buf_dsr (cyg_vector_t vector, cyg_ucount32 count,
+ cyg_addrword_t data);
+
+/* Callbacks test stub. */
+void
+ipmbox_test_data_cb (void *user_data, u32 *first_msg, uint length)
+{
+ data_cb_called = true;
+}
+
+void
+ipmbox_test_mbx_cb (void *user_data, u32 *first_msg, uint length)
+{
+ mbx_cb_called = true;
+}
+
+void
+ipmbox_test_empty_buf_cb (void *user_data)
+{
+ empty_buf_cb_called = true;
+}
+
+ipmbox_t *
+ipmbox_test_init (void)
+{
+ /* Init fake regs. */
+ regs.a2l_tail = (u32) &shared_mem[SHMEM_A2L_DATA_QUEUE_BASE
+ + qsize[IPMBOX_QUEUE_DATA][IPMBOX_A2L] - 1];
+ regs.a2l_head = (u32) INVALID_PTR;
+ regs.l2a_head = (u32) &shared_mem[SHMEM_L2A_DATA_QUEUE_BASE];
+ regs.l2a_tail = (u32) INVALID_PTR;
+ regs.a2l_it = 0;
+ regs.a2l_it_mask = 0;
+ regs.l2a_it = 0;
+ regs.l2a_it_mask = 0;
+ /* Init pointer in the shared memory ptr zone. */
+ u32 shmem_queue_base [] = {
+ SHMEM_A2L_MBX_QUEUE_BASE,
+ SHMEM_L2A_MBX_QUEUE_BASE,
+ SHMEM_A2L_EMPTY_BUF_QUEUE_BASE,
+ SHMEM_L2A_EMPTY_BUF_QUEUE_BASE,
+ };
+ ipmbox_queue_ptr_t *queue =
+ (ipmbox_queue_ptr_t*) &shared_mem[SHMEM_PTR_ZONE];
+ uint i;
+ for (i = 0; i < COUNT (shmem_queue_base); i++)
+ {
+ queue->head = (u32) &shared_mem[shmem_queue_base[i]];
+ queue->tail = (u32) INVALID_PTR;
+ queue++;
+ }
+ /* Initialise init info zone inside DATA L2A. */
+ ipmbox_protocol_init_t *init = (ipmbox_protocol_init_t*) regs.l2a_head;
+ init->version = IPMBOX_PROTOCOL_VERSION;
+ init->shared_mem = (ipmbox_queue_ptr_t*) shared_mem;
+ uint j;
+ for (i = 0; i < COUNT (qsize); i++)
+ for (j = 0; j < COUNT (qsize[i]); j++)
+ init->queue_size[i][j] = qsize[i][j];
+ ipmbox_t *ctx = ipmbox_init ();
+ /* Initialise callbacks. */
+ ipmbox_register_rx_data_cb (ctx, INVALID_PTR, ipmbox_test_data_cb);
+ ipmbox_register_rx_mbx_cb (ctx, INVALID_PTR, ipmbox_test_mbx_cb);
+ ipmbox_register_empty_buf_cb (ctx, INVALID_PTR, ipmbox_test_empty_buf_cb);
+ return ctx;
+}
+
+void
+ipmbox_init_test_case (test_t t)
+{
+ ipmbox_t *ctx = ipmbox_test_init ();
+ test_case_begin (t, "init/uninit/(de)activate");
+ test_begin (t, "init")
+ {
+ test_fail_unless (ctx->regs == IPMBOX_REG_BASE_ADDR);
+ /* Check mapping of queues' pointers. */
+ test_fail_unless (ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L].ptr
+ == (ipmbox_queue_ptr_t*) &ctx->regs->a2l_tail);
+ test_fail_unless (ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_L2A].ptr
+ == (ipmbox_queue_ptr_t*) &ctx->regs->l2a_tail);
+ test_fail_unless (
+ ctx->queue[IPMBOX_QUEUE_MBX][IPMBOX_A2L].ptr
+ == (ipmbox_queue_ptr_t*) &shared_mem[SHMEM_PTR_ZONE]);
+ test_fail_unless (
+ ctx->queue[IPMBOX_QUEUE_MBX][IPMBOX_L2A].ptr
+ == (ipmbox_queue_ptr_t*) &shared_mem[SHMEM_PTR_ZONE + 2]);
+ test_fail_unless (
+ ctx->queue[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_A2L].ptr
+ == (ipmbox_queue_ptr_t*) &shared_mem[SHMEM_PTR_ZONE + 4]);
+ test_fail_unless (
+ ctx->queue[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_L2A].ptr
+ == (ipmbox_queue_ptr_t*) &shared_mem[SHMEM_PTR_ZONE + 6]);
+
+ u32 shmem_queue_base [][IPMBOX_QUEUE_DIRECTION_NB] = {
+ {SHMEM_A2L_MBX_QUEUE_BASE, SHMEM_L2A_MBX_QUEUE_BASE},
+ {SHMEM_A2L_EMPTY_BUF_QUEUE_BASE, SHMEM_L2A_EMPTY_BUF_QUEUE_BASE},
+ {SHMEM_A2L_DATA_QUEUE_BASE, SHMEM_L2A_DATA_QUEUE_BASE}
+ };
+ uint i, j;
+ for (i = 0; i < COUNT (shmem_queue_base); i++)
+ {
+ for (j = 0; j < COUNT (shmem_queue_base[i]); j++)
+ {
+ test_fail_unless (ctx->queue[i][j].ptr->head
+ == ctx->queue[i][j].ptr->tail);
+ test_fail_unless (ctx->queue[i][j].base_ptr
+ == &shared_mem[shmem_queue_base[i][j]]);
+ test_fail_unless (ctx->queue[i][j].size == qsize[i][j]);
+ test_fail_unless (ctx->queue[i][j].end_ptr
+ == ctx->queue[i][j].base_ptr + qsize[i][j]);
+ }
+ }
+ /* Check registers. */
+ test_fail_unless (ctx->regs->a2l_it == 0);
+ test_fail_unless (ctx->regs->l2a_it == 0);
+ test_fail_unless (ctx->regs->a2l_it_mask
+ == (IPMBOX_A2L_IT | IPMBOX_A2L_IT_ACK));
+ test_fail_unless (ctx->regs->l2a_it_mask == 0);
+ }
+ test_end;
+ test_begin (t, "(de)activate")
+ {
+ ipmbox_activate (ctx, true);
+ test_fail_unless (ctx->regs->a2l_it_mask == IPMBOX_A2L_IT_ACK);
+ ipmbox_activate (ctx, false);
+ test_fail_unless (ctx->regs->a2l_it_mask
+ == (IPMBOX_A2L_IT | IPMBOX_A2L_IT_ACK));
+ }
+ test_end;
+ test_begin (t, "uninit")
+ {
+ ctx->regs->a2l_it_mask = 0;
+ ipmbox_uninit (ctx);
+ test_fail_unless (ctx->regs->a2l_it_mask
+ == (IPMBOX_A2L_IT | IPMBOX_A2L_IT_ACK));
+ }
+ test_end;
+}
+
+void
+ipmbox_callback_register_test_case (test_t t)
+{
+ test_case_begin (t, "Register callbacks");
+ test_begin (t, "all")
+ {
+ ipmbox_t *ctx = ipmbox_test_init ();
+ ipmbox_register_rx_data_cb (ctx, INVALID_PTR, ipmbox_test_data_cb);
+ ipmbox_register_rx_mbx_cb (ctx, INVALID_PTR, ipmbox_test_mbx_cb);
+ ipmbox_register_empty_buf_cb (
+ ctx, INVALID_PTR + 1, ipmbox_test_empty_buf_cb);
+ test_fail_unless (ctx->rx_cb_data_user_data == INVALID_PTR);
+ test_fail_unless (ctx->rx_cb_mbx_user_data == INVALID_PTR);
+ test_fail_unless (ctx->rx_cb_data == ipmbox_test_data_cb);
+ test_fail_unless (ctx->rx_cb_mbx == ipmbox_test_mbx_cb);
+ test_fail_unless (ctx->empty_buf_cb_user_data == INVALID_PTR + 1);
+ test_fail_unless (ctx->empty_buf_cb == ipmbox_test_empty_buf_cb);
+ ipmbox_uninit (ctx);
+ }
+ test_end;
+}
+
+void
+ipmbox_tx_test_case (test_t t)
+{
+ test_case_begin (t, "Tx to Arm");
+ test_begin (t, "DATA/MBX/EMPTY_BUF")
+ {
+ ipmbox_t *ctx = ipmbox_test_init ();
+ u32 msg[2];
+ /* First call each tx function and check after each call the IT is
+ * raised. */
+ ctx->regs->l2a_it = 0;
+ msg[0] = 0x42;
+ msg[1] = 0x43;
+ ipmbox_tx_data (ctx, msg, 2);
+ test_fail_unless (ctx->regs->l2a_it == IPMBOX_L2A_IT);
+ ctx->regs->l2a_it = 0;
+ msg[0] = 0x44;
+ msg[1] = 0x45;
+ ipmbox_tx_mbx (ctx, msg, 2);
+ test_fail_unless (ctx->regs->l2a_it == IPMBOX_L2A_IT);
+ ctx->regs->l2a_it = 0;
+ msg[0] = 0x46;
+ msg[1] = 0x47;
+ ipmbox_tx_empty_buf (ctx, msg, 2);
+ test_fail_unless (ctx->regs->l2a_it == IPMBOX_L2A_IT);
+ ctx->regs->l2a_it = 0;
+ /* Check the message is stored in each queue. */
+ test_fail_unless (shared_mem[SHMEM_L2A_DATA_QUEUE_BASE] == 0x42);
+ test_fail_unless (shared_mem[SHMEM_L2A_DATA_QUEUE_BASE + 1] == 0x43);
+ test_fail_unless (shared_mem[SHMEM_L2A_MBX_QUEUE_BASE] == 0x44);
+ test_fail_unless (shared_mem[SHMEM_L2A_MBX_QUEUE_BASE + 1] == 0x45);
+ test_fail_unless (shared_mem[SHMEM_L2A_EMPTY_BUF_QUEUE_BASE] == 0x46);
+ test_fail_unless (shared_mem[SHMEM_L2A_EMPTY_BUF_QUEUE_BASE + 1] == 0x47);
+ /* Test the assert. */
+ dbg_fatal_try_begin
+ {
+ ipmbox_tx_data (
+ ctx, msg, IPMBOX_PROTOCOL_QUEUE_SIZE_L2A_DATA + 1);
+ test_fail_unless (false);
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ test_verbose_print (fatal_message);
+ test_fail_unless (true);
+ }
+ dbg_fatal_try_end;
+ ipmbox_uninit (ctx);
+ }
+ test_end;
+}
+
+void
+ipmbox_empty_buf_get_test_case (test_t t)
+{
+ ipmbox_t *ctx = ipmbox_test_init ();
+ u32 buffs[10];
+ ipmbox_queue_copy_to (&ctx->queue[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_A2L],
+ buffs, 10);
+ ctx->regs->a2l_it = 0;
+ test_case_begin (t, "Empty buf get");
+ test_begin (t, "buffers available")
+ {
+ uint nb_got;
+ nb_got = ipmbox_empty_buf_get (ctx, buffs, 5);
+ test_fail_unless (ctx->regs->a2l_it == IPMBOX_A2L_IT_ACK);
+ test_fail_unless (nb_got == 5);
+ test_fail_unless (ctx->regs->a2l_it_mask & IPMBOX_A2L_IT_ACK);
+ }
+ test_end;
+ test_begin (t, "not enough buffers")
+ {
+ uint nb_got;
+ nb_got = ipmbox_empty_buf_get (ctx, buffs, 6);
+ test_fail_unless (nb_got == 5);
+ test_fail_unless ((ctx->regs->a2l_it_mask & IPMBOX_A2L_IT_ACK) == 0);
+ }
+ test_end;
+ test_begin (t, "no buffers")
+ {
+ uint nb_got;
+ ctx->regs->a2l_it_mask = IPMBOX_A2L_IT_ACK;
+ nb_got = ipmbox_empty_buf_get (ctx, buffs, 6);
+ test_fail_unless (nb_got == 0);
+ test_fail_unless ((ctx->regs->a2l_it_mask & IPMBOX_A2L_IT_ACK) == 0);
+ }
+ test_end;
+ test_begin (t, "just enough buffers")
+ {
+ uint nb_got;
+ ipmbox_queue_copy_to (&ctx->queue[IPMBOX_QUEUE_EMPTY_BUF][IPMBOX_A2L],
+ buffs, 10);
+ ctx->regs->a2l_it_mask = IPMBOX_A2L_IT_ACK;
+ nb_got = ipmbox_empty_buf_get (ctx, buffs, 10);
+ test_fail_unless (nb_got == 10);
+ test_fail_unless ((ctx->regs->a2l_it_mask & IPMBOX_A2L_IT_ACK));
+ }
+ test_end;
+ ipmbox_uninit (ctx);
+}
+
+void
+ipmbox_rx_sync_test_case (test_t t)
+{
+ ipmbox_t *ctx = ipmbox_test_init ();
+ test_case_begin (t, "RX sync");
+ test_begin (t, "Nothing to do")
+ {
+ u32 *first_msg = NULL;
+ uint nb_msg;
+ /* IT not set. */
+ ctx->regs->a2l_it = 0;
+ nb_msg = ipmbox_rx_sync (ctx, (const u32**) &first_msg);
+ test_fail_unless (!nb_msg);
+ test_fail_unless (!first_msg);
+ /* IT set. */
+ ctx->regs->a2l_it = -1;
+ nb_msg = ipmbox_rx_sync (ctx, (const u32**) &first_msg);
+ test_fail_unless (ctx->regs->a2l_it == IPMBOX_A2L_IT);
+ test_fail_unless (!nb_msg);
+ test_fail_unless (!first_msg);
+ }
+ test_end;
+ test_begin (t, "Messages to process")
+ {
+ ipmbox_queue_copy_to (&ctx->queue[IPMBOX_QUEUE_MBX][IPMBOX_A2L],
+ &shared_mem[SHMEM_A2L_EMPTY_BUF_QUEUE_BASE],
+ 10);
+ u32 *first_msg = NULL;
+ uint nb_msg;
+ ctx->regs->a2l_it = IPMBOX_A2L_IT;
+ nb_msg = ipmbox_rx_sync (ctx, (const u32**) &first_msg);
+ test_fail_unless (ctx->regs->a2l_it == IPMBOX_A2L_IT);
+ test_fail_unless (nb_msg == 10);
+ test_fail_unless (first_msg);
+ }
+ test_end;
+ ipmbox_uninit (ctx);
+}
+
+void
+ipmbox_rx_irq_test_case (test_t t)
+{
+ ipmbox_t *ctx = ipmbox_test_init ();
+ test_case_begin (t, "RX IRQ");
+ test_begin (t, "Really no work (data/mbx)")
+ {
+ data_cb_called = false;
+ mbx_cb_called = false;
+ dsr_posted = false;
+ ctx->regs->l2a_it = 0;
+ ctx->regs->a2l_it = 0;
+ ctx->regs->a2l_it_mask = IPMBOX_A2L_IT;
+ ipmbox_rx_dsr (0, 0, (cyg_addrword_t) ctx);
+ test_fail_unless (!ctx->regs->l2a_it);
+ test_fail_unless (!data_cb_called);
+ test_fail_unless (!mbx_cb_called);
+ test_fail_unless (!dsr_posted);
+ test_fail_unless ((ctx->regs->a2l_it_mask & IPMBOX_A2L_IT) == 0);
+ }
+ test_end;
+ test_begin (t, "Only MBX")
+ {
+ /* store some MBX messages. */
+ ipmbox_queue_copy_to (&ctx->queue[IPMBOX_QUEUE_MBX][IPMBOX_A2L],
+ &shared_mem[SHMEM_A2L_EMPTY_BUF_QUEUE_BASE],
+ IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_MBX / 2);
+ data_cb_called = false;
+ mbx_cb_called = false;
+ dsr_posted = false;
+ ctx->regs->l2a_it = 0;
+ ctx->regs->a2l_it = 0;
+ ctx->regs->a2l_it_mask = IPMBOX_A2L_IT;
+ ipmbox_rx_dsr (0, 0, (cyg_addrword_t) ctx);
+ test_fail_unless (!ctx->regs->l2a_it);
+ test_fail_unless (!data_cb_called);
+ test_fail_unless (mbx_cb_called);
+ test_fail_unless (!dsr_posted);
+ test_fail_unless ((ctx->regs->a2l_it_mask & IPMBOX_A2L_IT) == 0);
+ }
+ test_end;
+ test_begin (t, "DATA <= BUDGET")
+ {
+ /* store some DATA messages. */
+ ipmbox_queue_copy_to (&ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L],
+ &shared_mem[SHMEM_A2L_EMPTY_BUF_QUEUE_BASE],
+ IPMBOX_RX_DATA_BUDGET);
+ data_cb_called = false;
+ mbx_cb_called = false;
+ dsr_posted = false;
+ ctx->regs->l2a_it = 0;
+ ctx->regs->a2l_it = 0;
+ ctx->regs->a2l_it_mask = IPMBOX_A2L_IT;
+ ipmbox_rx_dsr (0, 0, (cyg_addrword_t) ctx);
+ test_fail_unless (ctx->regs->l2a_it == 0);
+ test_fail_unless (data_cb_called);
+ test_fail_unless (!mbx_cb_called);
+ test_fail_unless (!dsr_posted);
+ test_fail_unless ((ctx->regs->a2l_it_mask & IPMBOX_A2L_IT) == 0);
+ }
+ test_end;
+ test_begin (t, "DATA > BUDGET")
+ {
+ /* store some DATA messages. */
+ ipmbox_queue_copy_to (&ctx->queue[IPMBOX_QUEUE_DATA][IPMBOX_A2L],
+ &shared_mem[SHMEM_A2L_EMPTY_BUF_QUEUE_BASE],
+ IPMBOX_RX_DATA_BUDGET + 1);
+ data_cb_called = false;
+ mbx_cb_called = false;
+ dsr_posted = false;
+ ctx->regs->l2a_it = 0;
+ ctx->regs->a2l_it = 0;
+ ctx->regs->a2l_it_mask = IPMBOX_A2L_IT;
+ ipmbox_rx_dsr (0, 0, (cyg_addrword_t) ctx);
+ test_fail_unless (ctx->regs->l2a_it == 0);
+ test_fail_unless (data_cb_called);
+ test_fail_unless (!mbx_cb_called);
+ test_fail_unless (dsr_posted);
+ test_fail_unless ((ctx->regs->a2l_it_mask & IPMBOX_A2L_IT));
+ }
+ test_end;
+ ipmbox_uninit (ctx);
+}
+
+void
+ipmbox_empty_buf_irq_test_case (test_t t)
+{
+ test_case_begin (t, "Empty buf IRQ");
+ test_begin (t, "Call the callback")
+ {
+ ipmbox_t *ctx = ipmbox_test_init ();
+ empty_buf_cb_called = false;
+ ipmbox_empty_buf_dsr (0, 0, (cyg_addrword_t) ctx);
+ test_fail_unless (empty_buf_cb_called);
+ ipmbox_uninit (ctx);
+ }
+ test_end;
+}
+
+void
+ipmbox_test_suite (test_t t)
+{
+ test_suite_begin (t, "IPMBox");
+ ipmbox_init_test_case (t);
+ ipmbox_callback_register_test_case (t);
+ ipmbox_tx_test_case (t);
+ ipmbox_empty_buf_get_test_case (t);
+ ipmbox_rx_sync_test_case (t);
+ ipmbox_rx_irq_test_case (t);
+ ipmbox_empty_buf_irq_test_case (t);
+ test_case_begin (t, "memory");
+ test_begin (t, "memory")
+ {
+ test_fail_unless (blk_check_memory ());
+ } test_end;
+}
+
+int main (int argc, char **argv)
+{
+ test_t t;
+ test_init (t, argc, argv);
+ ipmbox_test_suite (t);
+ test_result (t);
+ return test_nb_failed (t) == 0 ? 0 : 1;
+}
+
diff --git a/cesar/hal/phy/maximus/test/src/test_phy_access.c b/cesar/hal/phy/maximus/test/src/test_phy_access.c
index e0fb33faf0..6bd9b5a166 100644
--- a/cesar/hal/phy/maximus/test/src/test_phy_access.c
+++ b/cesar/hal/phy/maximus/test/src/test_phy_access.c
@@ -56,7 +56,7 @@ void phy_access_backoff_start_test_case(test_t t)
netclock_msg_hdr_t *netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -94,7 +94,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -112,7 +111,7 @@ void phy_access_backoff_start_test_case(test_t t)
netclock_msg_hdr_t *netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -143,7 +142,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -154,7 +152,7 @@ void phy_access_backoff_start_test_case(test_t t)
netclock_msg_hdr_t *netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe
@@ -192,7 +190,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -208,7 +205,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_begin(t, "phy message for PRS0")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
uint8_t prs0 = 1;
@@ -221,8 +217,7 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless ((-1 != fd_in)
&& ((int)(sizeof(sci_msg_hdr_t)+sizeof(phy_msg_hdr_t)) == read(fd_in, data, sizeof(sci_msg_hdr_t)+sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -246,7 +241,7 @@ void phy_access_backoff_start_test_case(test_t t)
sci_msg_hdr_t *sci_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -285,7 +280,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -305,7 +299,7 @@ void phy_access_backoff_start_test_case(test_t t)
netclock_msg_hdr_t *netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -336,7 +330,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
// reset slot count netclock id (because callback will not be called)
@@ -360,7 +353,7 @@ void phy_access_backoff_start_test_case(test_t t)
sci_msg_hdr_t *sci_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -399,7 +392,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -415,7 +407,6 @@ void phy_access_backoff_start_test_case(test_t t)
test_begin(t, "phy message for PRS1")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
uint8_t prs1 = 1;
@@ -428,8 +419,7 @@ void phy_access_backoff_start_test_case(test_t t)
test_fail_unless ((-1 != fd_in)
&& ((int)(sizeof(sci_msg_hdr_t)+sizeof(phy_msg_hdr_t)) == read(fd_in, data, sizeof(sci_msg_hdr_t)+sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -753,7 +743,7 @@ void phy_access_timer_program_test_case(test_t t)
netclock_msg_hdr_t *netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -787,7 +777,6 @@ void phy_access_timer_program_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
diff --git a/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c b/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c
index 96b1382faf..57c933b309 100644
--- a/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c
+++ b/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c
@@ -758,7 +758,7 @@ void maximus_phy_recv_test_case(test_t t)
unsigned char data[256];
netclock_msg_hdr_t *netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -792,7 +792,6 @@ void maximus_phy_recv_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
// reset netclock id
@@ -1609,7 +1608,6 @@ void phy_tx_frame_test_case(test_t t)
test_begin(t, "tonemask phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -1622,8 +1620,7 @@ void phy_tx_frame_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -1680,7 +1677,7 @@ void phy_tx_frame_test_case(test_t t)
netclock_msg_hdr_t netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -1716,7 +1713,6 @@ void phy_tx_frame_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -1804,7 +1800,7 @@ void phy_tx_frame_test_case(test_t t)
int fd_in = -1;
uint duration_in_ticks;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// set preamble transimission time
@@ -1844,7 +1840,6 @@ void phy_tx_frame_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -1891,7 +1886,6 @@ void phy_tx_frame_test_case(test_t t)
test_begin(t, "first phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -1904,8 +1898,7 @@ void phy_tx_frame_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -1925,7 +1918,7 @@ void phy_tx_frame_test_case(test_t t)
uint fc_duration = MAC_FC_AV_TCK; // in AV mode
uint duration_in_ticks;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// calculate frame control transimission time
@@ -1978,7 +1971,6 @@ void phy_tx_frame_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -1993,7 +1985,6 @@ void phy_tx_frame_test_case(test_t t)
test_begin(t, "second phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -2006,8 +1997,7 @@ void phy_tx_frame_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -2034,7 +2024,7 @@ void phy_tx_frame_test_case(test_t t)
uint symbol_nb;
uint duration_in_ticks;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// calculate MPDU payload transimission time
@@ -2085,7 +2075,6 @@ void phy_tx_frame_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -2151,8 +2140,7 @@ void phy_tx_frame_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -2209,7 +2197,6 @@ void phy_tx_frame_test_case(test_t t)
{
// for phy message
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -2230,8 +2217,7 @@ void phy_tx_frame_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -2291,7 +2277,7 @@ void phy_tx_frame_test_case(test_t t)
netclock_msg_hdr_t netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -2320,7 +2306,6 @@ void phy_tx_frame_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
// reset next tx frame netclock id (because callback will not be called)
@@ -2361,7 +2346,7 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
netclock_msg_hdr_t netclock_hdr;
int fd_in = -1;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// open pipe or socket
@@ -2397,7 +2382,6 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -2439,7 +2423,7 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
int fd_in = -1;
uint duration_in_ticks;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// set preamble transimission time
@@ -2479,7 +2463,6 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -2494,7 +2477,6 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
test_begin(t, "first phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -2507,8 +2489,7 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -2528,7 +2509,7 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
uint fc_duration = MAC_FC_AV_TCK; // in AV mode
uint duration_in_ticks;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// calculate frame control transimission time
@@ -2581,7 +2562,6 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -2596,7 +2576,6 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
test_begin(t, "second phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -2609,8 +2588,7 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -2637,7 +2615,7 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
uint symbol_nb;
uint duration_in_ticks;
- netclock_callback_t reference, *found_callback;
+ netclock_callback_t reference;
set_node_t *found_node;
// calculate MPDU payload transimission time
@@ -2688,7 +2666,6 @@ void maximus_phy_tx_frame_sound_test_case(test_t t)
test_fail_unless((found_node = set_find(&my_station.netclock->callback_set, &reference.node)) != NULL);
// remove it from callback set
- found_callback = PARENT_OF(netclock_callback_t, node, found_node);
set_remove(&my_station.netclock->callback_set, found_node);
} test_end;
@@ -2842,7 +2819,6 @@ void maximus_phy_send_test_case(test_t t)
for (msg_counter = 0; msg_counter < msg_nb; msg_counter++)
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -2860,8 +2836,7 @@ void maximus_phy_send_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -2898,7 +2873,6 @@ void maximus_phy_send_test_case(test_t t)
test_begin(t, "tonemap phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -2911,8 +2885,7 @@ void maximus_phy_send_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -2942,7 +2915,6 @@ void maximus_phy_send_test_case(test_t t)
test_begin(t, "rx phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -2955,8 +2927,7 @@ void maximus_phy_send_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -3232,7 +3203,6 @@ void phy_rx_prepare_test_case(test_t t)
test_begin(t, "rx phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -3245,8 +3215,7 @@ void phy_rx_prepare_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -3285,7 +3254,6 @@ void phy_rx_prepare_test_case(test_t t)
test_begin(t, "rx phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -3298,8 +3266,7 @@ void phy_rx_prepare_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -3338,7 +3305,6 @@ void phy_rx_prepare_test_case(test_t t)
test_begin(t, "rx phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -3351,8 +3317,7 @@ void phy_rx_prepare_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -3406,7 +3371,6 @@ void phy_rx_prepare_sound_test_case(test_t t)
test_begin(t, "rx phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -3419,8 +3383,7 @@ void phy_rx_prepare_sound_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
@@ -3462,7 +3425,6 @@ void phy_rx_prepare_sound_test_case(test_t t)
test_begin(t, "rx phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -3475,8 +3437,7 @@ void phy_rx_prepare_sound_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
diff --git a/cesar/hal/phy/maximus/test/src/test_tmdma.c b/cesar/hal/phy/maximus/test/src/test_tmdma.c
index 58e33257da..02bad76ffd 100644
--- a/cesar/hal/phy/maximus/test/src/test_tmdma.c
+++ b/cesar/hal/phy/maximus/test/src/test_tmdma.c
@@ -49,7 +49,6 @@ void phy_set_tonemask_test_case(test_t t)
test_begin(t, "tonemask phy message")
{
unsigned char data[SCI_MSG_MAX_SIZE];
- sci_msg_hdr_t *sci_hdr;
phy_msg_hdr_t *phy_hdr;
int fd_in = -1;
@@ -62,8 +61,7 @@ void phy_set_tonemask_test_case(test_t t)
&& (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
&& (sizeof(phy_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(phy_msg_hdr_t))));
- // set sci and phy headers pointers
- sci_hdr = (sci_msg_hdr_t *)(data);
+ /* Set phy header pointer. */
phy_hdr = (phy_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
// check phy header
diff --git a/cesar/hal/phy/soft/bridgedma/src/bridgedma.c b/cesar/hal/phy/soft/bridgedma/src/bridgedma.c
index b93a2cda42..d263588c11 100644
--- a/cesar/hal/phy/soft/bridgedma/src/bridgedma.c
+++ b/cesar/hal/phy/soft/bridgedma/src/bridgedma.c
@@ -127,7 +127,7 @@ static uint _pb_data_add(
static int
_job_process(phy_bridgedma_t *ctx, phy_bridgedma_job_t *job)
{
- unsigned char * mac_ptr, *data_ptr;
+ unsigned char *data_ptr;
blk_t *pb_current;
unsigned long icv_final, icv_compare;
@@ -148,7 +148,6 @@ _job_process(phy_bridgedma_t *ctx, phy_bridgedma_job_t *job)
pb_current = job->first_pb_desc;
data_ptr = pb_current->data + job->first_pb_offset;
- mac_ptr = job->data_addr;
if(job->direction == 0)
{
diff --git a/cesar/hal/phy/test/phy/sparc-Makefile b/cesar/hal/phy/test/phy/sparc-Makefile
index dd3fb6636d..17920522d0 100644
--- a/cesar/hal/phy/test/phy/sparc-Makefile
+++ b/cesar/hal/phy/test/phy/sparc-Makefile
@@ -11,8 +11,7 @@ DEFS = -DTEST_PHY_SIMU=0
TARGET_PROGRAMS = test_phy
test_phy_SOURCES = test_phy.c basic.c clk_sync.c access.c data.c gen.c mem.c \
burst.c dataplane_stub.c common.c
-test_phy_MODULES = lib hal/phy mac/common interface host hal/hle hle hal/arch
-mac_common_MODULES_SOURCES = tonemask.c
+test_phy_MODULES = lib hal mac/common interface host bufmgr cl/mbx
VARIANT = sparc
include $(BASE)/common/make/top.mk
diff --git a/cesar/hal/phy/test/phy/src/dataplane_stub.c b/cesar/hal/phy/test/phy/src/dataplane_stub.c
index 00acf68efb..ad0cea68ac 100644
--- a/cesar/hal/phy/test/phy/src/dataplane_stub.c
+++ b/cesar/hal/phy/test/phy/src/dataplane_stub.c
@@ -12,76 +12,37 @@
*/
#include "common/std.h"
+#include "mac/sar/sar.h"
#include "cl/cl.h"
void
-cl_data_buffer_add (cl_t *cl, u8 *buffer)
-{
-}
-
-void
-cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user)
-{
-}
-
-void
-cl_data_send (cl_t *cl, u8 *buffer, uint length, uint tag,
- u32 arrival_time_ntb)
-{
-}
-
-void
-cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user)
-{
-}
-
-void
-cl_mme_buffer_add (cl_t *cl, u8 *buffer)
-{
-}
-
-void
-cl_mme_init_buffer_add_cb (cl_t *cl, cl_mme_buffer_add_cb_t cb, void *user_data)
-{
-}
-
-void
-cl_mme_init_ul_as_data (cl_t *ctx, cl_mme_ul_send_done_cb_t cb, void *user)
+sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs, void *bto_bpsto)
{
}
void
-cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs, bool encryption)
+sar_init_beacon_cb (sar_t *sar, void *user_data, sar_beacon_cb_t uf)
{
}
-void
-cl_mme_recv_done (cl_t *ctx, u8 *buffer, bool mme_recv)
+cl_t*
+cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config,
+ ipmbox_t *ipmbox, bufmgr_t *bufmgr)
{
+ return (cl_t *) ipmbox;
}
-void
-cl_mme_recv_init (cl_t *ctx, cl_mme_recv_cb_t mme_recv_cb, void *user)
+cl_mbx_t*
+cl_mbx_get (cl_t *ctx)
{
+ return cl_mbx_init ((ipmbox_t *)ctx);
}
void
cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei)
-{
-}
-
-void
-cl_mme_ul_init_send_done (cl_t *ctx, cl_mme_ul_recv_done_cb_t cb, void *user)
-{
-}
-
-void
-sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs, void *bto_bpsto)
-{
-}
+{}
void
-sar_init_beacon_cb (sar_t *sar, void *user_data, sar_beacon_cb_t uf)
+cl_ipmbox_data_recv (cl_t *ctx, u32 *msg_buffer, uint nb_words)
{
}
-
diff --git a/cesar/hal/phy/test/phy/src/test_phy.c b/cesar/hal/phy/test/phy/src/test_phy.c
index 66481da416..aca71a72d3 100644
--- a/cesar/hal/phy/test/phy/src/test_phy.c
+++ b/cesar/hal/phy/test/phy/src/test_phy.c
@@ -44,9 +44,9 @@
#include "config/fcall/mme.h"
#if CONFIG_FCALL_MME
-# include "hle/hle.h"
# include "interface/interface.h"
# include "interface/inc/context.h"
+# include "interface/fcall/inc/context.h"
# include "common/defs/spidcom.h"
#endif
@@ -632,20 +632,16 @@ cp_mme_recv (void *user_data,
uint tei,
u8 *buffer,
uint length,
- bool mme_recv,
bool encryption)
{
- interface_mme_recv_done (user_data, buffer, mme_recv);
-}
-
-void
-cp_mme_buffer_add (void *user_data, u8 *buffer)
-{
- /* nothing to do */
+ bufmgr_give_back (user_data, buffer);
}
#endif /* CONFIG_FCALL_MME */
+void
+cl_ipmbox_data_recv (void *ctx, u32 *msg_buffer, uint nb_words);
+
/** Entry point. */
void
cyg_user_start (void)
@@ -656,14 +652,16 @@ cyg_user_start (void)
mac_config.ntb_offset_tck = 0;
mac_config.sta_mac_address = SPC_OUI;
mac_ntb_init (&mac_config);
- hle_t *hle = hle_init (INVALID_PTR);
- interface_t *interface = interface_init (hle, INVALID_PTR, INVALID_PTR,
- &mac_config);
- interface_callback_init (interface,
- cp_mme_recv,
- cp_mme_buffer_add,
- interface);
- hle_activate (hle, true);
+ ipmbox_t *ipmbox = ipmbox_init ();
+ bufmgr_t *bufmgr = bufmgr_init (ipmbox);
+ cl_t *cl = cl_init (INVALID_PTR, INVALID_PTR, &mac_config,
+ ipmbox, bufmgr);
+ interface_t *interface =
+ interface_init (cl, cl_mbx_get (cl), INVALID_PTR,
+ &mac_config, bufmgr);
+ interface_callback_init (interface, cp_mme_recv, interface);
+ ipmbox_register_rx_data_cb (ipmbox, cl_ipmbox_data_recv, INVALID_PTR);
+ ipmbox_activate (ipmbox, true);
fcall = interface->fcall->fcall_ctx;
#else /* !CONFIG_FCALL_MME */
fcall = my_station.fcall;
diff --git a/cesar/hle/doc/cesar_hle.odt b/cesar/hle/doc/cesar_hle.odt
deleted file mode 100755
index ff51613097..0000000000
--- a/cesar/hle/doc/cesar_hle.odt
+++ /dev/null
Binary files differ
diff --git a/cesar/hle/hle.h b/cesar/hle/hle.h
deleted file mode 100644
index 48cfad2ebe..0000000000
--- a/cesar/hle/hle.h
+++ /dev/null
@@ -1,96 +0,0 @@
-#ifndef HLE_H_
-#define HLE_H_
-
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hle.h
- * \brief Public functions
- * \ingroup hle
- *
- * High Entity Layer to receive Ethernet packets to the STA and provide data
- * from the STA.
- */
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h"
-#include "cl/cl.h"
-
-/**
- * Provide a Interface buffer to the interface.
- *
- * \param user_data the interface user data.
- * \param buffer the buffer.
- */
-typedef void (*hle_interface_buffer_add_cb_t) (void *user_data, u8 *buffer);
-
-/**
- * Provide the MME interfaces to the interface.
- *
- * \param user_data the interface user data.
- * \param buffer the buffer containing the MME.
- */
-typedef void (*hle_interface_mme_recv_cb_t) (void *user_data, u8 *buffer);
-
-/** forward declaration */
-typedef struct hle_t hle_t;
-
-/**
- * Initialise the interface to add an Interface buffer.
- * \param ctx the hle context.
- * \param buffer_cb the function to call on interface buffer reception.
- * \param mme_cb the function to call on interface specific MME reception.
- * \param user_data the user_data to provide on function call.
- */
-void
-hle_init_interface_cb (hle_t *ctx, hle_interface_buffer_add_cb_t buffer_cb,
- hle_interface_mme_recv_cb_t mme_cb,
- void *user_data);
-
-/**
- * Initialize the HLE.
- * \param cl the convergence layer context.
- * \return the hle context
- */
-hle_t *
-hle_init (cl_t *cl);
-
-/**
- * Uninitialise the HLE.
- * \param hle the hle context.
- */
-void
-hle_uninit (hle_t *hle);
-
-/**
- * Called by the Convergence layer or the interface module when the buffer has been used.
- * This allows the HLE to know which buffer is newly available to be used or
- * give it back to the ARM. (the buffer is borrowed by the linux).
- * \param hle the hle context.
- * \param buffer the buffer used to send the data.
- */
-void
-hle_send_done (hle_t *hle, u8 *buffer);
-
-/**
- * Activate the HLE to receive messages from the IPMbox.
- * \param ctx the HLE context.
- * \param active boolean to active or deactivate the reception of messages.
- */
-void
-hle_activate (hle_t *ctx, bool active);
-
-/**
- * Send a packet to the ipmbox.
- * \param ctx the hle context.
- * \param msg the message address to post the message in the ipmbox.
- * \param length the length of the message in words.
- */
-void
-hle_ipmbox_send (hle_t *ctx, u32 *msg, uint length);
-
-#endif /*HLE_H_*/
diff --git a/cesar/hle/inc/context.h b/cesar/hle/inc/context.h
deleted file mode 100644
index 8681744177..0000000000
--- a/cesar/hle/inc/context.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef hle_inc_context_h
-#define hle_inc_context_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hle/inc/context.h
- * \brief HLE context.
- * \ingroup hle
- *
- */
-
-#include "lib/trace.h"
-#include "lib/seq_check.h"
-
-#include "cl/cl.h"
-
-#include "hal/hle/ipmbox.h"
-
-#if MODULE_INCLUDED (hle_tools)
-# define HLE_TOOLS 1
-# include "hle/tools/tools.h"
-#else
-# define HLE_TOOLS 0
-#endif
-
-struct hle_t
-{
- /** CL context */
- cl_t *cl;
-
- /** ipmbox context */
- ipmbox_t *ipmbox;
-
-#if HLE_TOOLS
- /** HLE tools context. */
- hle_tools_t *hle_tools;
-#endif
-
- /** Interface buffer add callback. */
- hle_interface_buffer_add_cb_t interface_buffer_add_cb;
- /** Interface mme receive callback. */
- hle_interface_mme_recv_cb_t interface_mme_recv_cb;
- /** interface user data. */
- void *interface_user_data;
-
-#if CONFIG_TRACE
- /** HLE Trace */
- trace_buffer_t trace;
-#endif /* !CONFIG_TRACE */
-#if CONFIG_SEQ_CHECK
- /** Sequence check. */
- lib_seq_check_t seq_in;
- lib_seq_check_t seq_out;
-#endif
-};
-
-#endif /* hle_inc_context_h */
diff --git a/cesar/hle/inc/trace.h b/cesar/hle/inc/trace.h
deleted file mode 100644
index 185b9be4d9..0000000000
--- a/cesar/hle/inc/trace.h
+++ /dev/null
@@ -1,75 +0,0 @@
-#ifndef hle_inc_trace_h
-#define hle_inc_trace_h
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hle/inc/trace.h
- * \brief trace system for the HLE.
- * \ingroup hle
- *
- */
-
-#include "lib/trace.h"
-
-/** Shortcut for tracing inside the HLE. */
-#define HLE_TRACE(id, args...)\
- TRACE_FAST_SHORT(HLE_TRACE_, &ctx->trace, id, ## args)
-
-#if CONFIG_TRACE
-
-enum
-{
- HLE_TRACE_INIT,
- HLE_TRACE_UNINIT,
- HLE_TRACE_DATA_SEND,
- HLE_TRACE_DATA_SEND_DONE,
- HLE_TRACE_DATA_BUFFER_ADD,
- HLE_TRACE_DATA_RECV,
- HLE_TRACE_MME_BUFFER_ADD,
- HLE_TRACE_MME_SEND,
- HLE_TRACE_MME_RECV,
- HLE_TRACE_IPMBOX,
- HLE_TRACE_DROPPED,
- HLE_TRACE_SEQ_CHECK_IN,
- HLE_TRACE_SEQ_CHECK_OUT,
-};
-
-BEGIN_DECLS
-
-/**
- * Initialize the trace buffer
- * \param ctx the hle context.
- */
-void
-hle_trace_init (hle_t *ctx);
-
-/**
- * Uninit the trace buffer
- * \param ctx the hle context
- */
-void
-hle_trace_uninit (hle_t *ctx);
-
-/**
- * Print the trace buffers
- * \param ctx the hle context
- */
-void
-hle_trace_print (hle_t *ctx);
-
-END_DECLS
-
-#else /* !CONFIG_TRACE */
-
-#define hle_trace_init(ctx) ((void) 0)
-#define hle_trace_uninit(ctx) ((void) 0)
-#define hle_trace_print(ctx) ((void) 0)
-
-#endif /* !CONFIG_TRACE */
-
-#endif /* hle_inc_trace_h */
diff --git a/cesar/hle/src/hle.c b/cesar/hle/src/hle.c
deleted file mode 100644
index c324365518..0000000000
--- a/cesar/hle/src/hle.c
+++ /dev/null
@@ -1,360 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hle.c
- * \brief function of the HLE
- * \ingroup hle
- *
- */
-#include "common/std.h"
-#include "common/defs/ethernet.h"
-#include "hal/hle/defs.h"
-#include "hal/hle/ipmbox.h"
-#include "hle/hle.h"
-#include "cl/cl.h"
-#include "hle/inc/context.h"
-#include "hle/inc/trace.h"
-#include "mac/common/ntb.h"
-#include "lib/seq_check.h"
-
-#include "common/module.h"
-
-/** Hle global context */
-static hle_t hle_global;
-
-/**
- * Callback when the lib sequencer detect a wrong sequencing, input from
- * Linux.
- * \param user user data
- * \param vlan the VLAN id
- * \param seq_expected the sequence number expected
- * \param seq_actual the actual sequence number found in the packet
- */
-void
-hle_lib_seq_check_cb_in (void *user, uint vlan, uint seq_expected,
- uint seq_actual);
-
-/**
- * Callback when the lib sequencer detect a wrong sequencing, output to
- * Linux.
- * \param user user data
- * \param vlan the VLAN id
- * \param seq_expected the sequence number expected
- * \param seq_actual the actual sequence number found in the packet
- */
-void
-hle_lib_seq_check_cb_out (void *user, uint vlan, uint seq_expected,
- uint seq_actual);
-
-void
-hle_lib_seq_check_cb_in (void *user, uint vlan, uint seq_expected,
- uint seq_actual)
-{
- dbg_assert (user);
- trace_do (hle_t *ctx = (hle_t *) user);
- HLE_TRACE (SEQ_CHECK_IN, vlan, seq_expected, seq_actual);
-}
-
-void
-hle_lib_seq_check_cb_out (void *user, uint vlan, uint seq_expected,
- uint seq_actual)
-{
- dbg_assert (user);
- trace_do (hle_t *ctx = (hle_t *) user);
- HLE_TRACE (SEQ_CHECK_OUT, vlan, seq_expected, seq_actual);
-}
-
-/**
- * Send a data to the Convergence Layer to be sent over the PWL.
- * \param hle the hle context.
- * \param buffer the buffer containing the data to send.
- * \param length the data length
- * \param tag the priority tag provided by the upper layer.
- * \param arrival_time_ntb arrival time in the station in NTB.
- */
-static inline void
-hle_data_send (hle_t *ctx, u8 *buffer, uint length, uint tag,
- u32 arrival_time_ntb)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (length <= ETH_PACKET_MAX_SIZE);
-
- /* Check sequence. */
- lib_seq_check_packet (&ctx->seq_in, buffer, length);
-
- if (length < ETH_PACKET_MIN_SIZE_ALLOWED)
- {
- hle_send_done (ctx, buffer);
- HLE_TRACE (DROPPED, phy_date (), 1, length, buffer);
- }
- else
- {
- HLE_TRACE (DATA_SEND, phy_date (), length, buffer);
- cl_data_send (ctx->cl, buffer, length, tag, arrival_time_ntb);
- }
-}
-
-/**
- * Receives a data from the Convergence layer.
- * \param hle the hle context.
- * \param buffer the buffer used to receive the data
- * \param length the length of the data received.
- */
-inline void
-hle_data_recv (hle_t *ctx, u8 *buffer, uint length)
-{
- uint word[2];
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
- /* Tracing data. */
- HLE_TRACE (DATA_RECV, phy_date (), length, buffer);
-
- /* Check sequence. */
- lib_seq_check_packet (&ctx->seq_out, buffer, length);
-
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_DATA),
- (MSG_LENGTH, 1), (PARAM_MSG_TYPE, 0),
- (PARAM_MSG_LENGTH, length));
- word[1] = (uint) buffer;
- ipmbox_tx (ctx->ipmbox, word, 2);
-}
-
-/**
- * Provides a buffer to the CL in order to receive new MMEs from the CP.
- * \param hle the hle context.
- * \param buffer the buffer to provide to the CL.
- */
-static inline void
-hle_data_buffer_add (hle_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (ctx->cl);
- /* Tracing data. */
- HLE_TRACE (DATA_BUFFER_ADD, phy_date (), buffer);
- cl_data_buffer_add (ctx->cl, buffer);
-}
-
-/**
- * Send a MME to the Convergence Layer to be provide to the CP.
- * \param hle the hle context.
- * \param buffer the buffer containing the data to send.
- * \param length the data length
- */
-static inline void
-hle_mme_send (hle_t *ctx, u8 *buffer, uint length)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (length <= ETH_PACKET_MAX_SIZE);
- dbg_assert (ctx->cl);
- if (length < ETH_PACKET_MIN_SIZE_ALLOWED)
- {
- hle_send_done (ctx, buffer);
- HLE_TRACE (DROPPED, phy_date (), 0, length, buffer);
- }
- else
- {
- HLE_TRACE (MME_SEND, phy_date (), length, buffer);
- cl_mme_ul_send (ctx->cl, buffer, length);
- }
-}
-
-/**
- * Receives a MME from the Convergence layer.
- * \param hle the hle context.
- * \param buffer the buffer used to receive the data
- * \param length the length of the data received.
- */
-inline void
-hle_mme_recv (hle_t *ctx, u8 *buffer, uint length)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE)
- && (length <= ETH_PACKET_MAX_SIZE));
- uint word[2];
- /* Tracing data. */
- HLE_TRACE (MME_RECV, phy_date (), length, buffer);
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_DATA),
- (MSG_LENGTH, 1), (PARAM_MSG_TYPE, 1),
- (PARAM_MSG_LENGTH, length));
- word[1] = (uint) buffer;
- ipmbox_tx (ctx->ipmbox, word, 2);
-}
-
-/**
- * Provides a buffer to the CL in order to receive new MMEs from the CP.
- * \param hle the hle context.
- * \param buffer the buffer to provide to the CL.
- */
-static inline void
-hle_mme_buffer_add (hle_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (ctx->cl);
- /* Tracing data. */
- HLE_TRACE (MME_BUFFER_ADD, phy_date (), buffer);
- cl_mme_buffer_add (ctx->cl, buffer);
-}
-
-/**
- * Receives a message from the Linux.
- *
- * \param ctx the hle context.
- * \param msg_buffer the pointer of the buffer containing the messages to read
- * \param length the length of the messages in words.
- */
-void
-hle_ipmbox_recv (hle_t *ctx, u32 *msg_buffer, uint length)
-{
- dbg_assert (msg_buffer);
- dbg_assert (ctx);
- u32 *m, *mend;
- m = msg_buffer;
- mend = msg_buffer + length;
- uint msg, msg_length, type, data_length, data_type;
- while (m != mend)
- {
- msg = m[0];
- msg_length = 1 + BF_GET (IPMBOX_REG__MSG_LENGTH, msg);
- type = BF_GET (IPMBOX_REG__MSG_TYPE, msg);
- switch (type)
- {
- case HLE_MSG_TYPE_DATA /* Data type */:
- data_type = BF_GET(IPMBOX_REG__PARAM_MSG_TYPE, msg); /* data type MME or DATA */
- data_length = BF_GET (IPMBOX_REG__PARAM_MSG_LENGTH, msg);
- if (data_type == 0) /* Data */
- {
- uint tag = BF_GET (IPMBOX_REG__PARAM_MSG_PRIO, msg);
- hle_data_send (ctx, (u8 *) m[1], data_length, tag,
- mac_ntb ());
- }
- else
- hle_mme_send (ctx, (u8 *) m[1], data_length);
- break;
- case HLE_MSG_TYPE_BUFFER_ADD /* Buffer ADD */ :
- data_type = BF_GET (IPMBOX_REG__PARAM_BUFFER_TYPE, msg);
- switch (data_type)
- {
- case HLE_BUFFER_ALLOC_MME:
- hle_mme_buffer_add (ctx, (u8 *) m[1]);
- break;
- case HLE_BUFFER_ALLOC_DATA:
- hle_data_buffer_add (ctx, (u8 *) m[1]);
- break;
- case HLE_BUFFER_ALLOC_INTERFACE:
- (*ctx->interface_buffer_add_cb)
- (ctx->interface_user_data, (u8 *) m[1]);
- break;
- }
- break;
- case HLE_MSG_TYPE_INTERFACE:
- (*ctx->interface_mme_recv_cb)
- (ctx->interface_user_data, (u8 *) m[1]);
- break;
-#if HLE_TOOLS
- case HLE_MSG_TYPE_RPC:
- case HLE_MSG_TYPE_DEBUG_DUMP:
- hle_tools_recv_msg (ctx->hle_tools, m, msg_length);
- break;
-#endif
- }
- m += msg_length;
- }
-}
-
-hle_t *
-hle_init (cl_t *cl)
-{
- hle_t *ctx;
- dbg_assert (cl);
- ctx = &hle_global;
- hle_global.cl = cl;
- /** Initialize the CL data call backs. */
- cl_data_recv_init (cl, (cl_data_recv_cb_t) hle_data_recv, &hle_global);
- cl_data_send_done_init (cl, (cl_data_send_done_cb_t) hle_send_done,
- &hle_global);
- /** Initialize the CL MMEs call backs. */
- cl_mme_init_ul_as_data (cl, (cl_mme_ul_send_done_cb_t) hle_mme_recv,
- &hle_global);
- cl_mme_ul_init_send_done (cl,
- (cl_mme_ul_recv_done_cb_t) hle_send_done, &hle_global);
- /** Initialize the ipmbox */
- hle_global.ipmbox = ipmbox_init (&hle_global,
- (ipmbox_rx_cb_t) hle_ipmbox_recv);
- /** Initialize the trace system. */
- hle_trace_init (&hle_global);
- /* Initialize tools if enabled. */
-#if HLE_TOOLS
- hle_global.hle_tools = hle_tools_init (hle_global.ipmbox);
-#endif
- /* Tracing */
- HLE_TRACE (INIT, phy_date ());
- /* Sequence check initialization. */
- lib_seq_check_init (&ctx->seq_in, hle_lib_seq_check_cb_in, &hle_global);
- lib_seq_check_init (&ctx->seq_out, hle_lib_seq_check_cb_out, &hle_global);
- return &hle_global;
-}
-
-void
-hle_uninit (hle_t *ctx)
-{
- dbg_assert (ctx);
- /* tracing data */
- HLE_TRACE (UNINIT, phy_date ());
- hle_trace_uninit (ctx);
-}
-
-void
-hle_init_interface_cb (hle_t *ctx, hle_interface_buffer_add_cb_t buffer_cb,
- hle_interface_mme_recv_cb_t mme_cb,
- void *user_data)
-{
- dbg_assert (ctx);
- dbg_assert (buffer_cb);
- dbg_assert (mme_cb);
- ctx->interface_buffer_add_cb = buffer_cb;
- ctx->interface_mme_recv_cb = mme_cb;
- ctx->interface_user_data = user_data;
-}
-
-void
-hle_send_done (hle_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (ctx->ipmbox);
- uint word[2];
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_SEND_DONE),
- (MSG_LENGTH, 1));
- word[1] = (uint) buffer;
- ipmbox_tx (ctx->ipmbox, word, 2);
-}
-
-void
-hle_activate (hle_t *ctx, bool active)
-{
- dbg_assert (ctx);
- ipmbox_activate (ctx->ipmbox, active);
- /* Trace system. */
- HLE_TRACE (IPMBOX, phy_date (), active);
-}
-
-void
-hle_ipmbox_send (hle_t *ctx, u32 *msg, uint length)
-{
- dbg_assert (ctx);
- dbg_assert (msg);
- dbg_assert (length);
- ipmbox_tx (ctx->ipmbox, msg, length);
-}
diff --git a/cesar/hle/src/trace.c b/cesar/hle/src/trace.c
deleted file mode 100644
index 630d4500e2..0000000000
--- a/cesar/hle/src/trace.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hle/src/trace.c
- * \brief trace buffer for the HLE
- * \ingroup hle
- *
- */
-#include "common/std.h"
-
-#include "hle/hle.h"
-#include "hle/inc/context.h"
-#include "hle/inc/trace.h"
-
-/**
- * Initialize the trace buffer
- * \param ctx the hle context.
- */
-void
-hle_trace_init (hle_t *ctx)
-{
- static trace_namespace_t namespace;
- static const trace_event_id_t event_ids[] =
- {
- TRACE_EVENT (HLE_TRACE_INIT, "HLE_INIT", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_UNINIT, "HLE_UNINIT", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_DATA_SEND, "HLE_DATA_SEND length : %d, buffer @ : %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_DATA_SEND_DONE, "HLE_DATA_SEND_DONE buffer @ : %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_DATA_BUFFER_ADD, "HLE_DATA_BUFFER_ADD buffer @ : %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_DATA_RECV, "HLE_DATA_RECV length : %d, buffer @ : %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_MME_BUFFER_ADD, "HLE_MME_BUFFER_ADD buffer @ : %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_MME_SEND, "HLE_MME_SEND length : %d, buffer @ : %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_MME_RECV, "HLE_MME_RECV length : %d, buffer @ : %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_IPMBOX, "HLE_IPMBOX_ACTIVATE avctive : %d", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_DROPPED, "HLE_MSG DROPPED data: %d, length: %d, buffer: %x", TIMESTAMP),
- TRACE_EVENT (HLE_TRACE_SEQ_CHECK_IN, "[SeqCheck] input from linux: "
- "[%02d] expected=%04X, actual=%04X"),
- TRACE_EVENT (HLE_TRACE_SEQ_CHECK_OUT, "[SeqCheck] output to linux: "
- "[%02d] expected=%04X, actual=%04X"),
- };
- dbg_assert (ctx);
- trace_namespace_init (&namespace, event_ids, COUNT (event_ids));
- trace_buffer_add (&ctx->trace, "hle", 8, 4, true, &namespace);
-}
-
-/**
- * Uninit the trace buffer
- * \param ctx the hle context
- */
-void
-hle_trace_uninit (hle_t *ctx)
-{
- dbg_assert (ctx);
- trace_buffer_remove (&ctx->trace);
-}
-
-/**
- * Print the trace buffers
- * \param ctx the hle context
- */
-void
-hle_trace_print (hle_t *ctx)
-{
- dbg_assert(ctx);
- trace_buffer_dbg_dump(&ctx->trace);
-}
-
diff --git a/cesar/hle/test/Makefile b/cesar/hle/test/Makefile
deleted file mode 100644
index 5de79d0da7..0000000000
--- a/cesar/hle/test/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-BASE = ../..
-
-HOST_PROGRAMS = hle_recv_from_arm hle_send_to_arm interface_send
-
-hle_recv_from_arm_SOURCES = hle_recv_from_arm.c ipmbox.c
-hle_recv_from_arm_MODULES = lib hle mac/common \
- cl/stub
-
-hle_send_to_arm_SOURCES = hle_send_to_arm.c
-hle_send_to_arm_MODULES = lib hle mac/common \
- cl/stub
-
-interface_send_SOURCES = interface-send.c
-interface_send_MODULES = lib hle mac/common \
- cl/stub
-
-VARIANT = host
-
-include $(BASE)/common/make/top.mk
diff --git a/cesar/hle/test/src/hle_recv_from_arm.c b/cesar/hle/test/src/hle_recv_from_arm.c
deleted file mode 100644
index 46d0018f9a..0000000000
--- a/cesar/hle/test/src/hle_recv_from_arm.c
+++ /dev/null
@@ -1,336 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file test/hle_recv.c
- * \brief unit test to test the hle when it sends a data to the CL.
- * \ingroup hle
- *
- * « long description »
- */
-#include "common/std.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "lib/test.h"
-#include "lib/blk.h"
-#include "lib/trace.h"
-#include "lib/bitstream.h"
-
-#include "cl/cl.h"
-
-#include "hle/hle.h"
-#include "lib/test.h"
-
-#include "hle/inc/trace.h"
-#include "hle/inc/context.h"
-
-#include "mac/common/ntb.h"
-
-void
-hle_ipmbox_recv (hle_t *ctx, u32 *msg_buffer, uint length);
-
-unsigned int packet1 []__attribute__((aligned(2048))) =
-{ 0xa1b2c3d4, 0x00040002, 0x00000000, 0x00000000,
- 0x0000ffff, 0x00000001, 0x46973299, 0x0007c33e,
- 0x00000042, 0x00000042, 0x12005452, 0x00080235,
- 0x4c205227, 0x00450008, 0x4e043400, 0x06400040,
- 0x000a1917, 0x79cb0f02, 0x1b04d547, 0x6b285000,
- 0x0000babc, 0x02800000, 0x396bf0fa, 0x04020000,
- 0x0301b405, 0x01010003, 0x00000204};
-unsigned int packet1_len = 106;
-
-unsigned int packet2[] = { 0xa1b2c3d4, 0x00040002, 0x00000000, 0x00000000,
- 0x0000ffff, 0x00000001, 0x469732d4, 0x0000da24, 0x0000005d,
- 0x0000005d, 0x12005452, 0x00080235, 0x4c205227, 0x00450008,
- 0x09064f00, 0x06400040, 0x000a901c, 0x000a0f02, 0x01040202,
- 0x46d6bd01, 0x0d0071cf, 0x185072c5, 0x4b65b0f9, 0x00000000,
- 0x53ff2300, 0x0071424d, 0x18000000, 0x0000c807, 0x00000000,
- 0x00000000, 0x00010000, 0x0000feff, 0x00000a01, 0x00000000 };
-unsigned int packet2_len = 133;
-
-static uint cl_data_length;
-static u8 *cl_data_buffer;
-static uint cl_data_tag;
-
-static uint cl_mme_length;
-static u8 *cl_mme_buffer;
-
-static u8 *buffers;
-
-void
-cl_data_send (cl_t *cl, u8 *buffer, uint length, uint tag, u32 av_time)
-{
- cl_data_length = length;
- cl_data_buffer = buffer;
- cl_data_tag = tag;
-}
-
-void
-cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs,
- bool encrypted)
-{
- cl_mme_length = length;
- cl_mme_buffer = buffer;
-}
-
-void
-cl_data_buffer_add (cl_t *cl, u8 *buffer)
-{
- buffers = buffer;
-}
-
-void
-cl_mme_buffer_add (cl_t *cl, u8 *buffer)
-{
- buffers = buffer;
-}
-
-void
-cp_interface_buffer_add (void *user_data, u8 *buffer)
-{
- buffers = buffer;
-}
-
-void
-hle_interface_mme_recv_cb (void *user_data, u8 *buffer)
-{
- buffers = buffer;
-}
-
-void
-test_case__hle_recv_data_send_to_cl (test_t test)
-{
- test_case_begin (test, "Data received from the HLE");
-
- test_begin (test, "data")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = 0x30d4100;
- msg[1] = (uint) packet1;
-
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless (cl_data_length == packet1_len);
- test_fail_unless (cl_data_tag == 3);
- test_fail_unless ((uint *) cl_data_buffer == packet1);
- }
- test_end;
-
- test_begin (test, "data too short")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_DATA),
- (MSG_LENGTH, 1), (PARAM_MSG_TYPE, 0),
- (PARAM_MSG_LENGTH, ETH_PACKET_MIN_SIZE_ALLOWED));
-
- msg[1] = (uint) packet1;
-
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless (cl_data_length == ETH_PACKET_MIN_SIZE_ALLOWED);
- test_fail_unless ((uint *) cl_data_buffer == packet1);
-
- msg[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_DATA),
- (MSG_LENGTH, 1), (PARAM_MSG_TYPE, 0),
- (PARAM_MSG_LENGTH, ETH_PACKET_MIN_SIZE_ALLOWED - 1));
-
- msg[1] = (uint) packet1;
-
- cl_data_length = 0;
- cl_data_buffer = NULL;
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless (cl_data_length == 0);
- test_fail_unless (cl_data_buffer == NULL);
- }
- test_end;
-
- test_begin (test, "MME")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = 0x30d5100;
- msg[1] = (uint) packet1;
-
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless (cl_mme_length == packet1_len);
- test_fail_unless ((uint *) cl_mme_buffer == packet1);
- }
- test_end;
-
- test_begin (test, "MME too short")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_DATA),
- (MSG_LENGTH, 1), (PARAM_MSG_TYPE, 1),
- (PARAM_MSG_LENGTH, ETH_PACKET_MIN_SIZE_ALLOWED));
-
- msg[1] = (uint) packet1;
-
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless (cl_mme_length == ETH_PACKET_MIN_SIZE_ALLOWED);
- test_fail_unless ((uint *) cl_mme_buffer == packet1);
-
- msg[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_DATA),
- (MSG_LENGTH, 1), (PARAM_MSG_TYPE, 1),
- (PARAM_MSG_LENGTH, ETH_PACKET_MIN_SIZE_ALLOWED - 1));
-
- msg[1] = (uint) packet1;
-
- cl_mme_length = 0;
- cl_mme_buffer = NULL;
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless (cl_mme_length == 0);
- test_fail_unless (cl_mme_buffer == NULL);
- }
- test_end;
-}
-
-void
-test_case__hle_recv_buffer (test_t test)
-{
- test_case_begin (test, "buffer received from the HLE");
-
- test_begin (test, "data")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = 0x101;
- msg[1] = (uint) packet1;
-
- buffers = NULL;
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless ((uint *) buffers == packet1);
- }
- test_end;
-
- test_begin (test, "MME")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = 0x1101;
- msg[1] = (uint) packet1;
-
- buffers = NULL;
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless ((uint *) buffers == packet1);
- }
- test_end;
-
- test_begin (test, "MME")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = 0x2101;
- msg[1] = (uint) packet1;
-
- hle->interface_buffer_add_cb = cp_interface_buffer_add;
- buffers = NULL;
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless ((uint *) buffers == packet1);
- }
- test_end;
-}
-
-void
-test_case__hle_recv_interface_msg_type (test_t test)
-{
- test_case_begin (test, "Interface message received from the HLE");
-
- test_begin (test, "message")
- {
- hle_t *hle;
- uint cl;
- uint msg[2];
-
- /* Configure the test. */
- hle = hle_init ((cl_t *) &cl);
-
- msg[0] = 0x6A103;
- msg[1] = (uint) packet1;
-
- buffers = NULL;
- hle->interface_mme_recv_cb = hle_interface_mme_recv_cb;
- hle_ipmbox_recv (hle, msg, 2);
-
- test_fail_unless ((uint *) buffers == packet1);
- }
- test_end;
-}
-
-
-int main (void)
-{
- uint mac_config = 0;
- test_t test;
-
- test_init (test, 0, NULL);
-
- mac_ntb_init ((mac_config_t *) &mac_config);
-
- test_case__hle_recv_data_send_to_cl (test);
- test_case__hle_recv_buffer (test);
- test_case__hle_recv_interface_msg_type (test);
-
- test_begin (test, "Memory test")
- {
- test_fail_if (blk_check_memory() == false, "Memory not freed");
- }
- test_end;
-
- test_result (test);
- return test_nb_failed (test) == 0 ? 0 : 1;
-}
-
-
diff --git a/cesar/hle/test/src/hle_send_to_arm.c b/cesar/hle/test/src/hle_send_to_arm.c
deleted file mode 100644
index aeb5d32377..0000000000
--- a/cesar/hle/test/src/hle_send_to_arm.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file test/hle_recv.c
- * \brief unit test to test the hle when it sents a data to the CL.
- * \ingroup hle
- *
- * « long description »
- */
-#include "common/std.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "lib/test.h"
-#include "lib/blk.h"
-#include "lib/trace.h"
-
-#include "cl/cl.h"
-
-#include "hle/hle.h"
-#include "lib/test.h"
-
-#include "hle/inc/trace.h"
-#include "mac/common/ntb.h"
-
-unsigned int packet1 []__attribute__((aligned(2048))) =
-{ 0xa1b2c3d4, 0x00040002, 0x00000000, 0x00000000,
- 0x0000ffff, 0x00000001, 0x46973299, 0x0007c33e,
- 0x00000042, 0x00000042, 0x12005452, 0x00080235,
- 0x4c205227, 0x00450008, 0x4e043400, 0x06400040,
- 0x000a1917, 0x79cb0f02, 0x1b04d547, 0x6b285000,
- 0x0000babc, 0x02800000, 0x396bf0fa, 0x04020000,
- 0x0301b405, 0x01010003, 0x00000204};
-unsigned int packet1_len = 106;
-
-void
-hle_ipmbox_recv (hle_t *ctx, u32 *msg_buffer, uint length);
-
-void
-hle_data_recv (hle_t *ctx, u8 *buffer, uint length);
-
-void
-hle_mme_recv (hle_t *ctx, u8 *buffer, uint length);
-
-test_t test;
-static bool data_sent;
-
-int main (void)
-{
- hle_t *hle;
- uint cl;
- mac_config_t mac_config;
-
- test_init(test, 0, NULL);
- mac_ntb_init (&mac_config);
- trace_init ();
-
- test_case_begin (test, "Send to cleopatre");
-
- test_begin (test, "Good frame")
- {
- // The function cl_init has been overided.
- hle = hle_init ((cl_t *) &cl);
-
- data_sent = false;
- hle_data_recv(hle, (u8 *) packet1, packet1_len);
- test_fail_unless (data_sent == true);
- data_sent = false;
- hle_mme_recv(hle, (u8 *) packet1, packet1_len);
- test_fail_unless (data_sent == true);
-
- hle_uninit (hle);
- }
- test_end;
-
- test_begin (test, "Memory test")
- {
- test_fail_if (blk_check_memory() == false, "Memory not freed");
- }
- test_end;
-
- test_result (test);
- return test_nb_failed (test) == 0 ? 0 : 1;
-}
-
-ipmbox_t *ipmbox_init (void *user_data, ipmbox_rx_cb_t rx_cb)
-{
- return user_data;
-}
-
-void ipmbox_tx (ipmbox_t *ctx, u32 *msg_buffer, uint length)
-{
- data_sent = true;
-}
-
-void
-ipmbox_activate (ipmbox_t *ctx, bool activation)
-{
-
-}
-
diff --git a/cesar/hle/test/src/interface-send.c b/cesar/hle/test/src/interface-send.c
deleted file mode 100644
index 581ae4a2b7..0000000000
--- a/cesar/hle/test/src/interface-send.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2008 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file hle/test/src/interface-send.c
- * \brief Test the hle_send function.
- * \ingroup hle
- *
- * « long description »
- */
-#include "common/std.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "lib/test.h"
-#include "lib/blk.h"
-#include "lib/trace.h"
-
-#include "cl/cl.h"
-
-#include "hle/hle.h"
-#include "lib/test.h"
-
-#include "hle/inc/trace.h"
-#include "mac/common/ntb.h"
-
-test_t test;
-bool test_ipmbox_tx;
-bool test_ipmbox_activate;
-
-void
-interface_buffer_work_add (void *user_data, u8 *buffer)
-{
-}
-
-ipmbox_t *ipmbox_init (void *user_data, ipmbox_rx_cb_t rx_cb)
-{
- return user_data;
-}
-
-void ipmbox_tx (ipmbox_t *ctx, u32 *msg_buffer, uint length)
-{
- test_case_begin (test, "IPMbox tx");
-
- test_begin (test, "sending data")
- {
- test_fail_if (length != 3, "Wrong length");
- }
- test_end;
-}
-
-void
-ipmbox_activate (ipmbox_t *ctx, bool activation)
-{
- test_ipmbox_activate = true;
-}
-
-
-int main (void)
-{
- hle_t *hle;
- cl_t *cl;
- mac_config_t mac_config;
-
- uint word [3];
-
- test_init (test, 0, NULL);
-
- cl = blk_alloc ();
- hle = hle_init (cl);
- mac_ntb_init (&mac_config);
-
- test_ipmbox_activate = false;
-
- hle_activate (hle, true);
- hle_ipmbox_send (hle, word, 3);
-
- test_begin (test, "HLE activate")
- {
- test_fail_if (test_ipmbox_activate != true, "HLE activate not called");
- }
- test_end;
-
- blk_release (cl);
-
- test_begin (test, "Memory test")
- {
- test_fail_if (blk_check_memory() == false, "Memory not freed");
- }
- test_end;
-
- test_result (test);
- return test_nb_failed (test) == 0 ? 0 : 1;
-}
-
diff --git a/cesar/hle/test/src/ipmbox.c b/cesar/hle/test/src/ipmbox.c
deleted file mode 100644
index 6f03bafed6..0000000000
--- a/cesar/hle/test/src/ipmbox.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Cesar project {{{
- *
- * Copyright (C) 2007 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file test/hle_recv.c
- * \brief unit test to test the hle when it sends a data to the CL.
- * \ingroup hle
- *
- * « long description »
- */
-
-#include "common/std.h"
-
-#include "lib/blk.h"
-#include "hal/hle/forward.h"
-#include "hal/hle/ipmbox.h"
-
-
-ipmbox_t *ipmbox_init (void *user_data, ipmbox_rx_cb_t rx_cb)
-{
- return user_data;
-}
-
-void ipmbox_tx (ipmbox_t *ctx, u32 *msg_buffer, uint length)
-{
-
-}
-
-void
-ipmbox_activate (ipmbox_t *ctx, bool activation)
-{
-
-}
-
diff --git a/cesar/hle/tools/inc/context.h b/cesar/hle/tools/inc/context.h
index 50eab7cbcb..9343b7455a 100644
--- a/cesar/hle/tools/inc/context.h
+++ b/cesar/hle/tools/inc/context.h
@@ -13,7 +13,7 @@
* \ingroup hle
*/
-#include "hal/hle/forward.h"
+#include "hal/ipmbox/ipmbox.h"
/** HLE tools context. */
struct hle_tools_t
diff --git a/cesar/hle/tools/inc/debug_dump.h b/cesar/hle/tools/inc/debug_dump.h
index 7321072a7b..42589a16e9 100644
--- a/cesar/hle/tools/inc/debug_dump.h
+++ b/cesar/hle/tools/inc/debug_dump.h
@@ -12,6 +12,7 @@
* \brief Handle debug dump over mailbox.
* \ingroup hle
*/
+#include "hle/tools/tools.h"
BEGIN_DECLS
@@ -24,12 +25,12 @@ hle_tools_debug_dump_init (hle_tools_t *ctx);
/**
* Send back a dump buffer.
- * \param ipmbox ipmbox context
+ * \param ctx HLE tools context
* \param buffer buffer to be sent back
* \param buffer_length buffer used length
*/
void
-hle_tools_debug_dump_send_buffer (ipmbox_t *ipmbox,
+hle_tools_debug_dump_send_buffer (hle_tools_t *ctx,
u32 *buffer, uint buffer_length);
END_DECLS
diff --git a/cesar/hle/tools/inc/rpc.h b/cesar/hle/tools/inc/rpc.h
index 9513ca4fcc..81fdc47599 100644
--- a/cesar/hle/tools/inc/rpc.h
+++ b/cesar/hle/tools/inc/rpc.h
@@ -12,6 +12,7 @@
* \brief HLE Remote Procedure Call.
* \ingroup hle
*/
+#include "hle/tools/tools.h"
BEGIN_DECLS
diff --git a/cesar/hle/tools/src/debug_dump.c b/cesar/hle/tools/src/debug_dump.c
index 3a747e728c..9dfd4842a9 100644
--- a/cesar/hle/tools/src/debug_dump.c
+++ b/cesar/hle/tools/src/debug_dump.c
@@ -18,25 +18,21 @@
* filled and sent back to ARM side.
*/
#include "common/std.h"
+
#include "hle/tools/tools.h"
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h"
#include "inc/context.h"
-#include "inc/debug_dump.h"
void
-hle_tools_debug_dump_send_buffer (ipmbox_t *ipmbox,
+hle_tools_debug_dump_send_buffer (hle_tools_t *ctx,
u32 *buffer, uint buffer_length)
{
+ dbg_assert (ctx);
dbg_assert (buffer);
- u32 msg[2];
- msg[0] = BF_FILL (IPMBOX_REG,
- (MSG_TYPE, HLE_MSG_TYPE_DEBUG_DUMP),
- (MSG_LENGTH, COUNT (msg) - 1),
- (PARAM_DEBUG_DUMP_LENGTH, buffer_length));
- msg[1] = (u32) buffer;
- ipmbox_tx (ipmbox, msg, COUNT (msg));
+ ipmbox_msg_mbx_t msg;
+ msg.header = ipmbox_msg_create_header_debug_dump (buffer_length);
+ msg.buffer_addr = (u32) buffer;
+ ipmbox_tx_mbx (ctx->ipmbox, (u32 *) &msg, IPMBOX_MSG_MBX_WORDS);
}
/**
@@ -50,9 +46,9 @@ int
hle_tools_dump (void *user, const char *text, uint text_size)
{
const u32 *msg_buffer;
- uint msg_buffer_length;
- const u32 *m, *mend;
- uint msg, msg_length, type;
+ uint msg_nb;
+ ipmbox_msg_mbx_t *m, *m_end;
+ uint type;
u32 *buffer;
uint buffer_length;
uint dump, dumped;
@@ -66,23 +62,21 @@ hle_tools_dump (void *user, const char *text, uint text_size)
while (text_size || end_of_dump)
{
/* Get mailbox content. */
- msg_buffer = NULL;
- msg_buffer_length = ipmbox_rx_sync (ctx->ipmbox, &msg_buffer);
- m = msg_buffer;
- mend = msg_buffer + msg_buffer_length;
+ msg_nb = ipmbox_rx_sync (ctx->ipmbox, &msg_buffer)
+ / IPMBOX_MSG_MBX_WORDS;
+ m = (ipmbox_msg_mbx_t *) msg_buffer;
+ m_end = m + msg_nb;
/* Read messages. */
- while (m != mend)
+ for ( ; m != m_end; m++)
{
- msg = m[0];
- msg_length = 1 + BF_GET (IPMBOX_REG__MSG_LENGTH, msg);
- type = BF_GET (IPMBOX_REG__MSG_TYPE, msg);
+ type = ipmbox_msg_get_mbx_type (m->header);
switch (type)
{
- case HLE_MSG_TYPE_DEBUG_DUMP:
+ case IPMBOX_MSG_MBX_TYPE_DEBUG_DUMP:
/* Dump buffer. */
buffer_length =
- BF_GET (IPMBOX_REG__PARAM_DEBUG_DUMP_LENGTH, msg);
- buffer = (u32 *) m[1];
+ ipmbox_msg_get_debug_dump_length (m->header);
+ buffer = (u32 *) m->buffer_addr;
/* Fill it, little endian. */
dumped = dump = MIN (text_size, buffer_length);
for (; dump >= 4; dump -= 4)
@@ -103,18 +97,16 @@ hle_tools_dump (void *user, const char *text, uint text_size)
*buffer++ = w;
text_size -= dumped;
/* Send back message. */
- hle_tools_debug_dump_send_buffer (ctx->ipmbox, (u32 *) m[1],
- dumped);
+ hle_tools_debug_dump_send_buffer (
+ ctx, (u32 *) m->buffer_addr, dumped);
/* Clear end_of_dump flag, it was sent. */
end_of_dump = false;
break;
default:
/* Forward to general tools. */
- hle_tools_recv_msg (ctx, m, msg_length);
+ hle_tools_msg_recv (ctx, m);
break;
}
- /* Message length + the message header. */
- m += msg_length;
}
}
return sent;
diff --git a/cesar/hle/tools/src/rpc.c b/cesar/hle/tools/src/rpc.c
index 78f0b434d5..c35a7c23d7 100644
--- a/cesar/hle/tools/src/rpc.c
+++ b/cesar/hle/tools/src/rpc.c
@@ -11,12 +11,10 @@
* \ingroup hle
*/
#include "common/std.h"
-#include "hle/tools/tools.h"
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h"
-#include "inc/context.h"
-#include "inc/rpc.h"
+#include "hle/tools/tools.h"
+#include "hle/tools/inc/context.h"
+#include "hle/tools/inc/rpc.h"
/**
* Send RPC response.
@@ -32,20 +30,15 @@ hle_tools_rpc_send (hle_tools_t *ctx, uint length, bool more_data,
{
dbg_assert (ctx);
dbg_assert (buffer);
- u32 msg[2];
- msg[0] = BF_FILL (IPMBOX_REG,
- (MSG_TYPE, HLE_MSG_TYPE_RPC),
- (MSG_LENGTH, COUNT (msg) - 1),
- (PARAM_RPC_FORWARD_LENGTH, length),
- (PARAM_RPC_MORE_DATA, more_data),
- (PARAM_RPC_COOKIE, cookie));
- msg[1] = (u32) buffer;
- ipmbox_tx (ctx->ipmbox, msg, COUNT (msg));
+ ipmbox_msg_mbx_t msg;
+ msg.header = ipmbox_msg_create_header_rpc_l2a (length, more_data, cookie);
+ msg.buffer_addr = (u32) buffer;
+ ipmbox_tx_mbx (ctx->ipmbox, (u32 *) &msg, IPMBOX_MSG_MBX_WORDS);
}
void
hle_tools_rpc_recv (hle_tools_t *ctx, uint forward_length,
- uint reverse_length, uint cookie, u32 *buffer)
+ uint reverse_length_kb, uint cookie, u32 *buffer)
{
dbg_assert (ctx);
dbg_assert (buffer);
diff --git a/cesar/hle/tools/src/tools.c b/cesar/hle/tools/src/tools.c
index ac6bd1776d..8a8f1abb65 100644
--- a/cesar/hle/tools/src/tools.c
+++ b/cesar/hle/tools/src/tools.c
@@ -11,12 +11,14 @@
* \ingroup hle
*/
#include "common/std.h"
+
#include "hle/tools/tools.h"
+#include "hle/tools/inc/debug_dump.h"
+#include "hle/tools/inc/rpc.h"
+#include "hle/tools/inc/context.h"
+#include "config/hle.h"
-#include "hal/hle/defs.h"
-#include "inc/context.h"
-#include "inc/debug_dump.h"
-#include "inc/rpc.h"
+#include "config/hle/tools.h"
/** Global context. */
hle_tools_t hle_tools_global;
@@ -33,26 +35,26 @@ hle_tools_init (ipmbox_t *ipmbox)
}
void
-hle_tools_recv_msg (hle_tools_t *ctx, const u32 *msg, uint length)
+hle_tools_msg_recv (hle_tools_t *ctx, const ipmbox_msg_mbx_t *msg)
{
dbg_assert (ctx);
- dbg_assert (msg && length);
- hle_msg_type_t type = BF_GET (IPMBOX_REG__MSG_TYPE, msg[0]);
+ dbg_assert (msg);
+ uint type = ipmbox_msg_get_mbx_type (msg->header);
switch (type)
{
#if CONFIG_HLE_TOOLS_DEBUG_DUMP
- case HLE_MSG_TYPE_DEBUG_DUMP:
- /* Nothing to dump. */
- hle_tools_debug_dump_send_buffer (ctx->ipmbox, (u32 *) msg[1], 0);
+ case IPMBOX_MSG_MBX_TYPE_DEBUG_DUMP:
+ hle_tools_debug_dump_send_buffer (
+ ctx, (u32 *) msg->buffer_addr, 0);
break;
#endif
#if CONFIG_HLE_TOOLS_RPC
- case HLE_MSG_TYPE_RPC:
+ case IPMBOX_MSG_MBX_TYPE_RPC:
hle_tools_rpc_recv (
- ctx,
- BF_GET (IPMBOX_REG__PARAM_RPC_FORWARD_LENGTH, msg[0]),
- BF_GET (IPMBOX_REG__PARAM_RPC_REVERSE_LENGTH_KB, msg[0]) * 1024,
- BF_GET (IPMBOX_REG__PARAM_RPC_COOKIE, msg[0]), (u32 *) msg[1]);
+ ctx, ipmbox_msg_get_rpc_forward_length (msg->header),
+ ipmbox_msg_get_rpc_a2l_reverse_length_kb (msg->header),
+ ipmbox_msg_get_rpc_cookie (msg->header),
+ (u32 *) msg->buffer_addr);
break;
#endif
default:
@@ -60,4 +62,3 @@ hle_tools_recv_msg (hle_tools_t *ctx, const u32 *msg, uint length)
break;
}
}
-
diff --git a/cesar/hle/tools/test/utest/inc/scenario_defs.h b/cesar/hle/tools/test/utest/inc/scenario_defs.h
index 39f7578abe..83d151d6b7 100644
--- a/cesar/hle/tools/test/utest/inc/scenario_defs.h
+++ b/cesar/hle/tools/test/utest/inc/scenario_defs.h
@@ -13,7 +13,7 @@
* \ingroup test
*/
-#include "hal/hle/ipmbox.h"
+#include "hal/ipmbox/ipmbox.h"
#include "hle/tools/tools.h"
/* Scenario globals. */
@@ -30,7 +30,7 @@ struct scenario_ipmbox_buffer_t
/* Scenario actions. */
#define SCENARIO_DEFS_ACTIONS \
hle_tools_dump, \
- hle_tools_recv_msg
+ hle_tools_msg_recv
typedef struct
{
@@ -43,19 +43,22 @@ void
scenario_action_hle_tools_dump_cb (scenario_globals_t *globals,
scenario_params_t *params);
-typedef struct scenario_ipmbox_buffer_t scenario_action_hle_tools_recv_msg_t;
+typedef struct
+{
+ ipmbox_msg_mbx_t msg;
+} scenario_action_hle_tools_msg_recv_t;
void
-scenario_action_hle_tools_recv_msg_cb (scenario_globals_t *globals,
+scenario_action_hle_tools_msg_recv_cb (scenario_globals_t *globals,
scenario_params_t *params);
/* Scenario events. */
#define SCENARIO_DEFS_EVENTS \
ipmbox_rx_sync, \
- ipmbox_tx
+ ipmbox_tx_mbx
typedef struct scenario_ipmbox_buffer_t scenario_event_ipmbox_rx_sync_t;
-typedef struct scenario_ipmbox_buffer_t scenario_event_ipmbox_tx_t;
+typedef struct scenario_ipmbox_buffer_t scenario_event_ipmbox_tx_mbx_t;
#endif /* inc_scenario_defs_h */
diff --git a/cesar/hle/tools/test/utest/src/scenario_defs.c b/cesar/hle/tools/test/utest/src/scenario_defs.c
index dce387fac6..03255be607 100644
--- a/cesar/hle/tools/test/utest/src/scenario_defs.c
+++ b/cesar/hle/tools/test/utest/src/scenario_defs.c
@@ -30,12 +30,12 @@ scenario_action_hle_tools_dump_cb (scenario_globals_t *globals,
}
void
-scenario_action_hle_tools_recv_msg_cb (scenario_globals_t *globals,
+scenario_action_hle_tools_msg_recv_cb (scenario_globals_t *globals,
scenario_params_t *params)
{
- scenario_action_hle_tools_recv_msg_t *p =
- &params->action_hle_tools_recv_msg;
- hle_tools_recv_msg (globals->hle_tools, p->buffer, p->length);
+ scenario_action_hle_tools_msg_recv_t *p =
+ &params->action_hle_tools_msg_recv;
+ hle_tools_msg_recv (globals->hle_tools, &p->msg);
}
uint
@@ -48,9 +48,9 @@ ipmbox_rx_sync (ipmbox_t *ctx, const u32 **first_msg)
}
void
-ipmbox_tx (ipmbox_t *ctx, u32 *first_msg, uint length)
+ipmbox_tx_mbx (ipmbox_t *ctx, u32 *first_msg, uint length)
{
- scenario_event (ipmbox_tx, params, globals);
+ scenario_event (ipmbox_tx_mbx, params, globals);
test_fail_unless (ctx == globals->ipmbox);
test_fail_unless (length == params->length);
uint i;
diff --git a/cesar/hle/tools/test/utest/src/test_hle_tools.c b/cesar/hle/tools/test/utest/src/test_hle_tools.c
index 0194aca435..f20af58310 100644
--- a/cesar/hle/tools/test/utest/src/test_hle_tools.c
+++ b/cesar/hle/tools/test/utest/src/test_hle_tools.c
@@ -32,15 +32,15 @@ dump_test (test_t t, const char *sdump, const char *s1, const char *s2,
SCENARIO_ACTION (hle_tools_dump, .text = sdump, .text_size = sdumpl,
.sent = sdumpl),
SCENARIO_EVENT (ipmbox_rx_sync,
- .buffer = { 0x10140, (u32) buffer1, 0x10140,
+ .buffer = { 0x1001, (u32) buffer1, 0x1001,
(u32) buffer2 }, .length = !s2 || two_step ? 2 : 4),
- SCENARIO_EVENT (ipmbox_tx, .buffer = { 0x140 | s1l << 12,
+ SCENARIO_EVENT (ipmbox_tx_mbx, .buffer = { 0x1 | s1l << 8,
(u32) buffer1, }, .length = 2),
SCENARIO_EVENT_COND (two_step, ipmbox_rx_sync,
- .buffer = { 0x10140, (u32) buffer2 },
+ .buffer = { 0x1001, (u32) buffer2 },
.length = 2),
- SCENARIO_EVENT_COND (s2, ipmbox_tx,
- .buffer = { 0x140 | s2l << 12, (u32) buffer2, },
+ SCENARIO_EVENT_COND (s2, ipmbox_tx_mbx,
+ .buffer = { 0x1 | s2l << 8, (u32) buffer2, },
.length = 2),
SCENARIO_END
};
@@ -108,9 +108,8 @@ recv_msg_test_suite (test_t t)
test_begin (t, "drop")
{
scenario_entry_t entries[] = {
- SCENARIO_ACTION (hle_tools_recv_msg,
- .buffer = { 0x1d0, 0x12345678 },
- .length = 2),
+ SCENARIO_ACTION (hle_tools_msg_recv,
+ .msg = { 0x1d0, 0x12345678 }),
SCENARIO_END
};
scenario_globals_t globals = {
@@ -124,10 +123,9 @@ recv_msg_test_suite (test_t t)
{
char buffer[16];
scenario_entry_t entries[] = {
- SCENARIO_ACTION (hle_tools_recv_msg,
- .buffer = { 0x10140, (u32) buffer },
- .length = 2),
- SCENARIO_EVENT (ipmbox_tx, .buffer = { 0x140, (u32) buffer },
+ SCENARIO_ACTION (hle_tools_msg_recv,
+ .msg = { 0x1001, (u32) buffer }),
+ SCENARIO_EVENT (ipmbox_tx_mbx, .buffer = { 0x1, (u32) buffer },
.length = 2),
SCENARIO_END
};
@@ -150,11 +148,10 @@ rpc_test_suite (test_t t)
{
char buffer[1024] = "fatal\n";
scenario_entry_t entries[] = {
- SCENARIO_ACTION (hle_tools_recv_msg,
- .buffer = { 0x32006130, (u32) buffer },
- .length = 2),
- SCENARIO_EVENT (ipmbox_tx,
- .buffer = { 0x30000130, (u32) buffer },
+ SCENARIO_ACTION (hle_tools_msg_recv,
+ .msg = { 0x3200602, (u32) buffer }),
+ SCENARIO_EVENT (ipmbox_tx_mbx,
+ .buffer = { 0x3000002, (u32) buffer },
.length = 2),
SCENARIO_END
};
diff --git a/cesar/hle/tools/tools.h b/cesar/hle/tools/tools.h
index a585e0fd5d..058c9cea8e 100644
--- a/cesar/hle/tools/tools.h
+++ b/cesar/hle/tools/tools.h
@@ -12,10 +12,18 @@
* \brief HLE tools.
* \ingroup hle
*/
+#include "common/module.h"
-#include "hal/hle/forward.h"
+#if MODULE_INCLUDED (hle_tools)
+# define HLE_TOOLS 1
+#else
+# define HLE_TOOLS 0
+#endif
-#include "config/hle/tools.h"
+#if HLE_TOOLS
+
+# include "hal/ipmbox/ipmbox.h"
+# include "common/ipmbox/msg.h"
/* Forward declaration. */
typedef struct hle_tools_t hle_tools_t;
@@ -31,14 +39,20 @@ hle_tools_t *
hle_tools_init (ipmbox_t *ipmbox);
/**
- * Handle one message received from mailbox.
- * \param ctx HLE tools context
- * \param msg message to handle
- * \param length message length
+ * Process mbx hle tools message.
+ * \param ctx module context
+ * \param msg the message to process
*/
void
-hle_tools_recv_msg (hle_tools_t *ctx, const u32 *msg, uint length);
+hle_tools_msg_recv (hle_tools_t *ctx, const ipmbox_msg_mbx_t *msg);
END_DECLS
+#else /* !HLE_TOOLS */
+
+# define hle_tools_init(ipmbox) ((void) 0)
+# define hle_tools_msg_recv(ctx, msg) ((void) 0)
+
+#endif /* !HLE_TOOLS */
+
#endif /* hle_tools_tools_h */
diff --git a/cesar/host/test/src/test_netclock.c b/cesar/host/test/src/test_netclock.c
index 4ccabcccb8..b892f40ae2 100644
--- a/cesar/host/test/src/test_netclock.c
+++ b/cesar/host/test/src/test_netclock.c
@@ -22,40 +22,6 @@
#include <stdio.h>
extern char dump_buffer[];
-//void netclock_new_test_case(test_t t)
-//{
-// netclock_ctx_t *netclock;
-// station_ctx_t *station;
-//
-// test_case_begin(t, "new");
-// station = station_new();
-//
-// test_begin(t, "station = NULL")
-// {
-// test_fail_unless(
-// (netclock_new(NULL) == NULL)
-// && (errno == EINVAL)
-// );
-// } test_end;
-//
-// test_begin(t, "check new")
-// {
-// test_fail_unless(
-// ((netclock = netclock_new(station)) != NULL)
-// && (netclock->station == station)
-// );
-// } test_end;
-//
-// netclock_free(netclock);
-// station_free(station);
-// return;
-//}
-//
-//void netclock_free_test_case(test_t t)
-//{
-// return
-//}
-
void netclock_init_test_case(test_t t)
{
netclock_ctx_t netclock;
@@ -95,7 +61,6 @@ void netclock_init_test_case(test_t t)
&& (netclock.current_id == 1)
&& (netclock.sci->msg_callback[SCI_MSG_TYPE_NETWORK_CLOCK].function == netclock_recv)
&& (netclock.sci->msg_callback[SCI_MSG_TYPE_NETWORK_CLOCK].data == &netclock)
-// && (set_empty(&netclock.callback_set))
);
} test_end;
@@ -324,37 +289,6 @@ void netclock_schedule_test_case(test_t t)
);
} test_end;
-// test_begin(t, "full registring table")
-// {
-// int i;
-// netclock.callback_nb = NETCLOCK_CALLBACK_MAX_NB;
-// test_fail_unless(
-// (netclock_schedule(&netclock, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data) < 0)
-// && (errno == ENOSPC)
-// );
-// netclock.callback_nb = 1;
-//
-// for(i = 0; i < NETCLOCK_CALLBACK_TABLE_SIZE; i++)
-// {
-// netclock.callback_table[i].function = _fake_schedule;
-// }
-// test_fail_unless(
-// (netclock_schedule(&netclock, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data) < 0)
-// && (errno == ENOSPC)
-// );
-// } test_end;
-//
-// test_begin(t, "one free slot")
-// {
-// netclock.callback_table[NETCLOCK_CALLBACK_TABLE_SIZE / 2].function = NULL;
-// netclock.callback_nb = NETCLOCK_CALLBACK_TABLE_SIZE - 1;
-// test_fail_unless(
-// (netclock_schedule(&netclock, NETWORK_CLOCK_TYPE_PHY, 0x1234567890abcdefULL, _test_schedule, data) > 0)
-// && (netclock.callback_table[NETCLOCK_CALLBACK_TABLE_SIZE / 2].function == _test_schedule)
-// && (netclock.callback_nb == NETCLOCK_CALLBACK_TABLE_SIZE)
-// );
-// } test_end;
-
station_down(&station);
#ifndef STATION_SOCK
close(fd_in);
@@ -372,7 +306,9 @@ void netclock_unschedule_test_case(test_t t)
int fd_in;
int len;
unsigned char buffer[1024];
-
+ netclock_id_t id1 = 0x1233;
+ netclock_id_t id2 = 0x1234;
+
test_case_begin(t, "unschedule");
station_init(&station);
@@ -388,24 +324,23 @@ void netclock_unschedule_test_case(test_t t)
// reset errno
errno = 0;
} test_end
-
+
test_begin(t, "check unschedule")
{
netclock_callback_t callback1, callback2, cb_ref;
- callback1.id = 0x1233;
- callback1.function = _fake_schedule;
+ callback1.id = id1;
+ callback1.function = &_fake_schedule;
set_node_init(&callback1.node);
- set_insert(&netclock.callback_set, &callback1.node);
- callback2.id = 0x1234;
- callback2.function = _test_schedule;
+ set_insert (&netclock.callback_set, &callback1.node);
+ callback2.id = id2;
+ callback2.function = &_test_schedule;
set_node_init(&callback2.node);
- set_insert(&netclock.callback_set, &callback2.node);
+ set_insert (&netclock.callback_set, &callback2.node);
netclock.callback_nb = 2;
+ cb_ref.id = id1;
set_node_init(&cb_ref.node);
- cb_ref.id = callback2.id;
-
test_fail_unless(
- (netclock_unschedule(&netclock, 0x1234) >= 0)
+ (netclock_unschedule (&netclock, id1) >= 0)
&& (set_find(&netclock.callback_set, &cb_ref.node) == NULL)
&& (netclock.callback_nb == 1)
);
@@ -426,7 +361,7 @@ void netclock_unschedule_test_case(test_t t)
nclock_hdr = (netclock_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
test_fail_unless(
(nclock_hdr->type == NETWORK_CLOCK_TYPE_REMOVE)
- && (ntohs(nclock_hdr->id) == 0x1234)
+ && (ntohs (nclock_hdr->id) == id1)
);
} test_end;
@@ -434,7 +369,7 @@ void netclock_unschedule_test_case(test_t t)
test_begin(t, "id not exist")
{
test_fail_unless(
- (netclock_unschedule(&netclock, 0x1234) < 0)
+ (netclock_unschedule (&netclock, id1) < 0)
&& (errno == ENOENT)
&& (netclock.callback_nb == 1)
);
@@ -550,8 +485,6 @@ void netclock_recv_test_case(test_t t)
void netclock_test_suite(test_t t)
{
test_suite_begin(t, "netclock");
- //netclock_new_test_case(t);
- //netclock_free_test_case(t);
netclock_init_test_case(t);
netclock_fill_hdr_test_case(t);
netclock_schedule_test_case(t);
diff --git a/cesar/host/test/src/test_sci.c b/cesar/host/test/src/test_sci.c
index 8ffc1d06a3..833f710f6c 100644
--- a/cesar/host/test/src/test_sci.c
+++ b/cesar/host/test/src/test_sci.c
@@ -130,9 +130,7 @@ void sci_fill_hdr_test_case(test_t t)
sci_ctx_t sci;
sci_msg_t msg;
unsigned char buffer[128];
- unsigned short previous_msg_id;
-
-
+
test_case_begin(t, "fill_hdr");
test_begin(t, "init msg")
@@ -193,7 +191,6 @@ void sci_fill_hdr_test_case(test_t t)
&& (EINVAL != errno)
&& (ENOSPC != errno)
);
- previous_msg_id = sci.current_msg_id;
test_fail_unless(
(sci_fill_hdr(&sci, &msg, SCI_MSG_TYPE_SYSTEM, 0xaa55) >= 0)
&& ((unsigned char *)msg.sci_hdr == msg.data_begin)
diff --git a/cesar/interface/fcall/defs.h b/cesar/interface/fcall/defs.h
index 781491110d..59e93cb0ef 100644
--- a/cesar/interface/fcall/defs.h
+++ b/cesar/interface/fcall/defs.h
@@ -14,7 +14,9 @@
*
* « long description »
*/
-
-#define INTERFACE_FCALL_MMTYPE 0xA006 /* VS_FCALL.IND */
+ /* VS_FCALL BASE */
+#define INTERFACE_FCALL_MMTYPE 0xA004
+/* VS_FCALL.IND */
+#define INTERFACE_FCALL_MMTYPE_IND 0xA006
#endif /* interface_fcall_defs_h */
diff --git a/cesar/interface/fcall/inc/context.h b/cesar/interface/fcall/inc/context.h
index dcb2e31970..8e2854cef8 100644
--- a/cesar/interface/fcall/inc/context.h
+++ b/cesar/interface/fcall/inc/context.h
@@ -15,30 +15,25 @@
*/
#include "host/fcall/fcall.h"
#include "lib/bitstream.h"
-#include "mac/common/config.h" /** for mac_config_t */
-typedef void (*interface_fcall_send_message_cb_t) (void *user_data, uint *message, uint length);
+#include "interface/fcall/interface_fcall.h"
-typedef void (*interface_fcall_send_done_message_cb_t) (void *user_data, u8 *message);
-
-/** Get a buffer to send answer.
- * \param user_data the user data previously registered.
- * \return buffer the buffer provided.
- */
-typedef u8 *
-(*interface_fcall_get_buffer_cb_t) (void *user_data);
-
-typedef struct interface_fcall_t
+struct interface_fcall_t
{
- fcall_ctx_t *fcall_ctx; /** pointer to fcall context */
- probe_ctx_t *probe_ctx; /** pointer to probe context */
- interface_fcall_send_message_cb_t send_cb; /** callback function to call when interface fcall module needs to send a message */
- interface_fcall_send_done_message_cb_t send_done_cb; /** callback function to call when interface fcall module needs to release a buffer */
- interface_fcall_get_buffer_cb_t buffer_get_cb; /** interface_fcall_get_buffer call back */
- void *user_data; /** data to provide on callback function */
- bitstream_t bitstream_ctx; /** bitstream context */
- mac_config_t *mac_config; /** contains sta mac address = ODA of the received MME */
- mac_t osa; /** OSA of the received MME */
-} interface_fcall_t;
+ /** pointer to fcall context */
+ fcall_ctx_t *fcall_ctx;
+ /** pointer to probe context */
+ probe_ctx_t *probe_ctx;
+ /** bitstream context */
+ bitstream_t bitstream_ctx;
+ /** mac configuration structure. */
+ mac_config_t *mac_config;
+ /** Convergence layer context. */
+ cl_mbx_t *cl_mbx;
+ /** Buffer manager. */
+ bufmgr_t *bufmgr;
+ /** Source mac address of the received MME */
+ mac_t osa;
+};
#endif /* interface_fcall_inc_context_h */
diff --git a/cesar/interface/fcall/interface_fcall.h b/cesar/interface/fcall/interface_fcall.h
index bc51ea43a7..61d556a5e0 100644
--- a/cesar/interface/fcall/interface_fcall.h
+++ b/cesar/interface/fcall/interface_fcall.h
@@ -13,22 +13,21 @@
* \ingroup interface/fcall
*
*/
-#include "interface/fcall/inc/context.h"
+#include "cl/mbx/mbx.h"
+#include "bufmgr/bufmgr.h"
+#include "mac/common/config.h"
+
+typedef struct interface_fcall_t interface_fcall_t;
/**
- * initialise the interface fcall module and the callback functions
- * \param send_cb the function to call when the interface fcall needs to send an INTERFACE message
- * \param send_done_cb the function to call when the interface fcall needs to send a SEND DONE message
- * \param buffer_get_cb the function to call back to get a buffer.
- * \param user_data the data to provide on callback function
+ * Initialise the interface fcall module and the callback functions.
+ * \param cl_mbx the convergence layer to send MME to linux
* \param mac_config the mac_config
+ * \param bufmgr the buffer manager context
*/
interface_fcall_t*
-interface_fcall_init (interface_fcall_send_message_cb_t send_cb,
- interface_fcall_send_done_message_cb_t send_done_cb,
- interface_fcall_get_buffer_cb_t buffer_get_cb,
- void *user_data,
- mac_config_t *mac_config);
+interface_fcall_init (cl_mbx_t *cl_mbx, mac_config_t *mac_config,
+ bufmgr_t *bufmgr);
/**
* uninitalise the interface fcall module
diff --git a/cesar/interface/fcall/src/interface_fcall.c b/cesar/interface/fcall/src/interface_fcall.c
index eb4ee08eec..18663dce32 100644
--- a/cesar/interface/fcall/src/interface_fcall.c
+++ b/cesar/interface/fcall/src/interface_fcall.c
@@ -21,8 +21,7 @@
#include "common/defs/ethernet.h" /* for ETH_MAC_ADDRESS_SIZE,
ETH_PACKET_MIN_SIZE and ETH_PACKET_MAX_SIZE */
#include "common/defs/homeplugAV.h" // for 'HPAV_MTYPE_MME' and 'HPAV_MMV'
-#include "hal/hle/defs.h"
-#include "lib/utils.h"
+#include "common/ipmbox/msg.h"
#include "lib/swap.h" // for 'swap16()'
#include <errno.h>
@@ -34,20 +33,9 @@
# define diag_printf(arg, ...) ((void) 0)
#endif
-/**
- * initialise the interface fcall module and the callback functions
- * \param send_cb the function to call when the interface fcall needs to send an INTERFACE message
- * \param send_done_cb the function to call when the interface fcall needs to send a SEND DONE message
- * \param buffer_get_cb the function to call back to get a buffer.
- * \param user_data the data to provide on callback function
- * \param mac_config the mac_config
- */
interface_fcall_t*
-interface_fcall_init (interface_fcall_send_message_cb_t send_cb,
- interface_fcall_send_done_message_cb_t send_done_cb,
- interface_fcall_get_buffer_cb_t buffer_get_cb,
- void *user_data,
- mac_config_t *mac_config)
+interface_fcall_init (cl_mbx_t *cl_mbx, mac_config_t *mac_config,
+ bufmgr_t *bufmgr)
{
static interface_fcall_t ctx;
static fcall_ctx_t fcall_ctx;
@@ -55,29 +43,15 @@ interface_fcall_init (interface_fcall_send_message_cb_t send_cb,
static sci_ctx_t sci_ctx;
- dbg_assert_ptr(send_cb);
- dbg_assert_ptr(send_done_cb);
- dbg_assert_ptr(buffer_get_cb);
- dbg_assert_ptr(user_data);
- dbg_assert_ptr (mac_config);
- if ((NULL == send_cb)
- || (NULL == send_done_cb)
- || (NULL == user_data)
- || (NULL == buffer_get_cb)
- || (NULL == mac_config))
- {
- errno = EINVAL;
- return NULL;
- }
-
+ dbg_assert (cl_mbx);
+ dbg_assert (bufmgr);
+ dbg_assert (mac_config);
memset(&ctx, '\0', sizeof(interface_fcall_t));
ctx.fcall_ctx = &fcall_ctx;
ctx.probe_ctx = &probe_ctx;
- ctx.send_cb = send_cb;
- ctx.send_done_cb = send_done_cb;
- ctx.buffer_get_cb = buffer_get_cb;
- ctx.user_data = user_data;
ctx.mac_config = mac_config;
+ ctx.bufmgr = bufmgr;
+ ctx.cl_mbx = cl_mbx;
if (sci_init(&sci_ctx, NULL) < 0)
{
@@ -211,12 +185,7 @@ interface_fcall_mme_recv (void *data, u8 *mme)
}
/** To free buffer allocated by the driver. */
- dbg_assert_ptr(ctx->send_done_cb);
- if (NULL != ctx->send_done_cb)
- {
- (*ctx->send_done_cb)(ctx->user_data, mme);
- diag_printf("interface_fcall_mme_recv: SEND DONE\n");
- }
+ bufmgr_give_back (ctx->bufmgr, mme);
}
/**
@@ -229,7 +198,6 @@ interface_fcall_mme_send (void *data, sci_msg_t *msg)
{
interface_fcall_t *ctx = NULL;
uint field = 0, length = 0;
- uint word[2];
u8 *buffer = NULL;
dbg_assert_ptr(data);
@@ -244,7 +212,7 @@ interface_fcall_mme_send (void *data, sci_msg_t *msg)
ctx = (interface_fcall_t*)data;
/** Get a buffer. */
- buffer = (*ctx->buffer_get_cb) (ctx->user_data);
+ buffer = bufmgr_get_wait (ctx->bufmgr, 0);
memset(buffer, '\0', SCI_MSG_MAX_SIZE);
/** Copy message. */
@@ -270,7 +238,7 @@ interface_fcall_mme_send (void *data, sci_msg_t *msg)
bitstream_access (&ctx->bitstream_ctx, &field, 8);
/* Inserting the MMTYPE (LITTLE-ENDIAN). */
- field = INTERFACE_FCALL_MMTYPE;
+ field = INTERFACE_FCALL_MMTYPE_IND;
bitstream_access (&ctx->bitstream_ctx, &field, 16);
/* Inserting the FMI (LITTLE-ENDIAN). */
@@ -290,18 +258,6 @@ interface_fcall_mme_send (void *data, sci_msg_t *msg)
bitstream_access (&ctx->bitstream_ctx, &length, 16);
bitstream_finalise (&ctx->bitstream_ctx);
-
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
- (MSG_LENGTH, 1),
- (PARAM_INTERFACE_TYPE, INTERFACE_MODULE_FCALL),
- (PARAM_INTERFACE_LENGTH, msg->length + INTERFACE_FCALL_PAYLOAD_OFFSET));
- word[1] = (uint)buffer;
-
- /** Request the interface to send the message to the linux driver. */
- dbg_assert_ptr(ctx->send_cb);
- if (NULL != ctx->send_cb)
- {
- (*ctx->send_cb)(ctx->user_data, word, 2);
- diag_printf("interface_fcall_mme_send: TX\n");
- }
+ cl_mbx_ipmbox_send (
+ ctx->cl_mbx, buffer, msg->length + INTERFACE_FCALL_PAYLOAD_OFFSET);
}
diff --git a/cesar/interface/fcall/test/Makefile b/cesar/interface/fcall/test/Makefile
index bc4b3281a3..239e4fb319 100644
--- a/cesar/interface/fcall/test/Makefile
+++ b/cesar/interface/fcall/test/Makefile
@@ -1,7 +1,7 @@
BASE = ../../..
DEFS += -DUNIT_TEST
HOST_PROGRAMS = test_interface_fcall
-test_interface_fcall_SOURCES = test_interface_fcall.c
-test_interface_fcall_MODULES = lib interface/fcall host
+test_interface_fcall_SOURCES = test_interface_fcall.c bufmgr_stub.c
+test_interface_fcall_MODULES = lib interface/fcall host cl/stub cl/mbx/stub
include $(BASE)/common/make/top.mk
diff --git a/cesar/interface/fcall/test/src/bufmgr_stub.c b/cesar/interface/fcall/test/src/bufmgr_stub.c
new file mode 100644
index 0000000000..5f8e5e3c42
--- /dev/null
+++ b/cesar/interface/fcall/test/src/bufmgr_stub.c
@@ -0,0 +1,28 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/bufmgr_stub.c
+ * \brief Buffer manager stub.
+ * \ingroup interface
+ */
+#include "common/std.h"
+#include "bufmgr/bufmgr.h"
+
+#include "common/defs/ethernet.h"
+
+static u8 buffer[ETH_PACKET_MAX_SIZE];
+
+u8*
+bufmgr_get_wait (bufmgr_t *ctx, uint delay_ms)
+{
+ return buffer;
+}
+
+void
+bufmgr_give_back (bufmgr_t *bufmgr, u8 *buffer)
+{ }
diff --git a/cesar/interface/fcall/test/src/test_interface_fcall.c b/cesar/interface/fcall/test/src/test_interface_fcall.c
index 048e72f293..f4d27942b4 100644
--- a/cesar/interface/fcall/test/src/test_interface_fcall.c
+++ b/cesar/interface/fcall/test/src/test_interface_fcall.c
@@ -15,11 +15,14 @@
#include "host/fcall/fcall.h"
#include "interface/fcall/interface_fcall.h"
#include "interface/fcall/inc/interface_fcall.h"
+#include "interface/fcall/inc/context.h"
#include "interface/forward.h"
-#include "lib/swap.h" // for 'swap16()'
-#include "common/defs/ethernet.h" /* for ETH_MAC_ADDRESS_SIZE */
-#include <stdio.h> // for 'printf'
-#include <malloc.h>
+
+#include "lib/swap.h"
+
+#include "common/defs/ethernet.h"
+
+#include <stdio.h>
#include <errno.h>
u32 maximus_pending_isrs;
@@ -30,76 +33,6 @@ u16 probe_len = sizeof(u16);
mac_config_t mac_config;
mac_t sta_mac_address = 0x123456789ABCLL;
-void
-interface_fcall_send_message_cb (void *user_data, uint *message, uint length)
-{
- static int test_nb = 1;
- u8 *data;
- dbg_assert_ptr(user_data);
- dbg_assert_ptr(message);
- dbg_assert(2 == length);
- data = (u8*)(*(message + 1));
- if (1 == test_nb)
- {
- test_nb++;
- dbg_assert_print (!memcmp (data + ETH_MAC_ADDRESS_SIZE, &sta_mac_address, ETH_MAC_ADDRESS_SIZE),
- "OSA");
- dbg_assert_print((0 == memcmp(data + INTERFACE_FCALL_PAYLOAD_OFFSET + sizeof(struct fcall_msg_hdr), fcall_test, strlen(fcall_test) + 1)),
- "registered send function");
- }
- else if (2 == test_nb)
- {
- u16 probe_len = ntohs(sizeof(u16));
- u8 index = INTERFACE_FCALL_PAYLOAD_OFFSET + sizeof(struct fcall_msg_hdr);
- test_nb++;
- dbg_assert_print (!memcmp (data + ETH_MAC_ADDRESS_SIZE, &sta_mac_address, ETH_MAC_ADDRESS_SIZE),
- "OSA");
- dbg_assert_print((0 == memcmp(data + index, "probe", strlen("probe") + 1)),
- "registered probe");
- index += strlen("probe") + 1;
- dbg_assert_print((0 == memcmp(data + index, "probe_test", strlen("probe_test") + 1)),
- "registered probe");
- index += strlen("probe_test") + 1;
- dbg_assert_print((0 == memcmp(data + index, &probe_len, sizeof(u16))),
- "registered probe");
- index += sizeof(u16);
- dbg_assert_print((0 == memcmp(data + index, &probe_test, sizeof(u16))),
- "registered probe");
- dbg_assert(0x1234 == probe_test);
- }
- else if (3 == test_nb)
- {
- u8 index = INTERFACE_FCALL_PAYLOAD_OFFSET + sizeof(struct fcall_msg_hdr);
- test_nb++;
- dbg_assert_print (!memcmp (data + ETH_MAC_ADDRESS_SIZE, &sta_mac_address, ETH_MAC_ADDRESS_SIZE),
- "OSA");
- dbg_assert_print((0 == memcmp(data + index, "probe", strlen("probe") + 1)),
- "registered probe");
- index += strlen("probe") + 1;
- dbg_assert_print((0 == memcmp(data + index, "probe_test", strlen("probe_test") + 1)),
- "registered probe");
- //dbg_assert(0x5678 == probe_test);
- }
- free(data);
- return;
-}
-
-void
-interface_fcall_send_done_message_cb (void *user_data, u8 *message)
-{
- dbg_assert_ptr(user_data);
- dbg_assert_ptr(message);
- free(message);
- return;
-}
-
-u8 *
-interface_fcall_buffer_get_cb (void *user_data)
-{
- u8 *buffer = malloc(SCI_MSG_MAX_SIZE);
- return buffer;
-}
-
int host_fcall_test (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
return 0;
@@ -108,123 +41,16 @@ int host_fcall_test (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg,
void
interface_fcall_init_test_case(test_t t)
{
- int user_data = 123;
memset (&mac_config, 0, sizeof (mac_config_t));
mac_config.sta_mac_address = sta_mac_address;
-
- test_case_begin(t, "init");
-
- test_begin(t, "NULL send cb")
- {
- dbg_fatal_try_begin
- {
- test_fail_unless(
- (NULL == interface_fcall_init(NULL,
- &interface_fcall_send_done_message_cb,
- &interface_fcall_buffer_get_cb,
- (void*)&user_data,
- &mac_config))
- );
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("init with NULL send cb\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
- } test_end;
-
- test_begin(t, "NULL send done cb")
- {
- dbg_fatal_try_begin
- {
- test_fail_unless(
- (NULL == interface_fcall_init(interface_fcall_send_message_cb,
- NULL,
- &interface_fcall_buffer_get_cb,
- (void*)&user_data,
- &mac_config))
- );
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("init with NULL send done cb\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
- } test_end;
-
- test_begin(t, "NULL buffer get cb")
- {
- dbg_fatal_try_begin
- {
- test_fail_unless(
- (NULL == interface_fcall_init(interface_fcall_send_message_cb,
- &interface_fcall_send_done_message_cb,
- NULL,
- (void*)&user_data,
- &mac_config))
- );
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("init with NULL buffer get cb\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
- } test_end;
-
- test_begin(t, "NULL user data")
- {
- dbg_fatal_try_begin
- {
- test_fail_unless(
- (NULL == interface_fcall_init(&interface_fcall_send_message_cb,
- &interface_fcall_send_done_message_cb,
- &interface_fcall_buffer_get_cb,
- NULL,
- &mac_config))
- );
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("init with NULL user data\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
- } test_end;
-
- test_begin(t, "NULL mac config")
- {
- dbg_fatal_try_begin
- {
- test_fail_unless(
- (NULL == interface_fcall_init(&interface_fcall_send_message_cb,
- &interface_fcall_send_done_message_cb,
- &interface_fcall_buffer_get_cb,
- (void*)&user_data,
- NULL))
- );
- }
- dbg_fatal_try_catch (const char *fatal_message)
- {
- printf("init with NULL user data\n%s\n", fatal_message);
- }
- dbg_fatal_try_end;
- } test_end;
-
test_begin(t, "check init")
{
- ctx = interface_fcall_init(&interface_fcall_send_message_cb,
- &interface_fcall_send_done_message_cb,
- &interface_fcall_buffer_get_cb,
- (void*)&user_data,
- &mac_config);
+ ctx = interface_fcall_init (INVALID_PTR, &mac_config, INVALID_PTR);
test_fail_unless(
(NULL != ctx)
&& (EINVAL != errno)
&& (ctx->fcall_ctx != NULL)
&& (ctx->probe_ctx != NULL)
- && (ctx->send_cb == &interface_fcall_send_message_cb)
- && (ctx->send_done_cb == &interface_fcall_send_done_message_cb)
- && (ctx->buffer_get_cb == &interface_fcall_buffer_get_cb)
- && (ctx->user_data == &user_data)
&& !memcmp (ctx->mac_config, &mac_config, sizeof (mac_config_t))
);
} test_end;
@@ -234,7 +60,7 @@ void
interface_fcall_mme_recv_test_case(test_t t)
{
struct fcall_msg_hdr fcall_hdr;
- u8 *mme = malloc(SCI_MSG_MAX_SIZE);
+ u8 mme[SCI_MSG_MAX_SIZE];
test_case_begin(t, "mme recv");
@@ -246,7 +72,7 @@ interface_fcall_mme_recv_test_case(test_t t)
}
dbg_fatal_try_catch (const char *fatal_message)
{
- printf("mme recv with NULL data\n%s\n", fatal_message);
+ test_verbose_print (fatal_message);
}
dbg_fatal_try_end;
} test_end;
@@ -259,7 +85,7 @@ interface_fcall_mme_recv_test_case(test_t t)
}
dbg_fatal_try_catch (const char *fatal_message)
{
- printf("mme recv with NULL mme\n%s\n", fatal_message);
+ test_verbose_print (fatal_message);
}
dbg_fatal_try_end;
} test_end;
@@ -282,7 +108,6 @@ interface_fcall_mme_recv_test_case(test_t t)
(errno != EINVAL)
);
- mme = malloc(SCI_MSG_MAX_SIZE);
length = swap16(sizeof(struct fcall_msg_hdr) + strlen("probe") + 1 + strlen("probe_test") + 1 + sizeof(u16));
probe_register(ctx->probe_ctx, "probe_test", sizeof(u16), &probe_test);
fcall_hdr.param_nb = 1;
@@ -295,7 +120,6 @@ interface_fcall_mme_recv_test_case(test_t t)
(errno != EINVAL)
);
- mme = malloc(SCI_MSG_MAX_SIZE);
length = swap16(sizeof(struct fcall_msg_hdr) + strlen("probe") + 1 + strlen("probe_test") + 1 + 2 * sizeof(u16) );
probe_register(ctx->probe_ctx, "probe_test", sizeof(u16), &probe_test);
fcall_hdr.param_nb = 1;
@@ -328,7 +152,7 @@ interface_fcall_mme_send_test_case(test_t t)
}
dbg_fatal_try_catch (const char *fatal_message)
{
- printf("mme send with NULL data\n%s\n", fatal_message);
+ test_verbose_print (fatal_message);
}
dbg_fatal_try_end;
} test_end;
@@ -341,7 +165,7 @@ interface_fcall_mme_send_test_case(test_t t)
}
dbg_fatal_try_catch (const char *fatal_message)
{
- printf("mme send with NULL msg\n%s\n", fatal_message);
+ test_verbose_print (fatal_message);
}
dbg_fatal_try_end;
} test_end;
@@ -378,7 +202,7 @@ interface_fcall_uninit_test_case(test_t t)
}
dbg_fatal_try_catch (const char *fatal_message)
{
- printf("uninit with NULL ctx\n%s\n", fatal_message);
+ test_verbose_print (fatal_message);
}
dbg_fatal_try_end;
} test_end;
diff --git a/cesar/interface/inc/context.h b/cesar/interface/inc/context.h
index 86de8b5a73..899057aea8 100644
--- a/cesar/interface/inc/context.h
+++ b/cesar/interface/inc/context.h
@@ -9,20 +9,22 @@
* }}} */
/**
* \file interface/inc/context.h
- * \brief Interface context.
+ * \brief Interface context.
* \ingroup interface
*
*/
#include <cyg/kernel/kapi.h>
#include <cyg/hal/hal_arch.h>
-#include "hle/hle.h"
+
+#include "common/defs/priority.h"
+
#include "lib/mbox.h"
+
#include "mac/common/config.h"
+#include "bufmgr/bufmgr.h"
#include "interface/interface.h"
-#include "common/defs/priority.h"
-
/** module includes. */
#include "config/interface.h"
#if CONFIG_INTERFACE_SNIFFER
@@ -34,13 +36,14 @@
struct interface_t
{
- /** cl context. */
+ /** CL context. */
cl_t *cl;
+ /** cl mbx context. */
+ cl_mbx_t *cl_mbx;
/** sar context. */
sar_t *sar;
- /** hle context. */
- hle_t *hle;
-
+ /** buffer manager context. */
+ bufmgr_t *bufmgr;
#if CONFIG_INTERFACE_SNIFFER
/** sniffer context. */
interface_sniffer_t *sniffer;
@@ -57,12 +60,8 @@ struct interface_t
/* callbacks functions. */
/** Callback to call on MME reception. */
interface_mme_recv_cb_t mme_recv_cb;
- /** Callback on buffer add. */
- interface_mme_buffer_add_cb_t buffer_add_cb;
/** Interface MME user data. */
void *interface_mme_user_data;
- /** Buffer mailbox. */
- mbox_t buffers_mbox;
/** Thread. */
cyg_thread thread;
diff --git a/cesar/interface/inc/interface.h b/cesar/interface/inc/interface.h
index bee22e4bfa..614f220cf6 100644
--- a/cesar/interface/inc/interface.h
+++ b/cesar/interface/inc/interface.h
@@ -9,7 +9,7 @@
* }}} */
/**
* \file interface/inc/interface.h
- * \brief Interface private functions.
+ * \brief Interface private functions.
* \ingroup interface
*
*/
@@ -19,41 +19,6 @@
#include "interface/defs-mmtype.h"
/**
- * The buffer shall be provided to the CP.
- * \param ctx the interface context.
- * \param buffer the buffer to add.
- */
-void
-interface_buffer_add (interface_t *ctx, u8 *buffer);
-
-/**
- * Add a buffer to its own list.
- * \param ctx the interface context.
- * \param buffer the buffer to add
- */
-void
-interface_buffer_work_add (interface_t *ctx, u8 *buffer);
-
-/**
- * Receive a data from the HLE.
- * \param ctx the interface context.
- * \param buffer the Message received.
- *
- * This will be use by the Fcall module in the interface. It can be use by
- * anything in the future.
- */
-void
-interface_hle_recv (interface_t *ctx, u8 *buffer);
-
-/**
- * Get a buffer from the list.
- * \param ctx the interface context.
- * \return the buffer to use, NULL if no buffer is available.
- */
-u8*
-interface_buffer_work_get (interface_t *ctx);
-
-/**
* Interface process, function used by the interface thread to process
* received MMEs.
*
diff --git a/cesar/interface/interface.h b/cesar/interface/interface.h
index 6179bfaa43..4163dfb03f 100644
--- a/cesar/interface/interface.h
+++ b/cesar/interface/interface.h
@@ -15,9 +15,8 @@
* The interface module allows the communication between Actors and
* the Data plane.
*/
-
-#include "hle/hle.h"
#include "cl/cl.h"
+#include "cl/mbx/mbx.h"
#include "mac/sar/sar.h"
#include "bsu/bsu.h"
@@ -30,35 +29,27 @@
* \param tei the station's source TEI.
* \param buffer the buffer containing the MME.
* \param length the MME length
- * \param mme_data data use by the CL.
* \param encrypted inform if the packet comes from the PWL if it has been
* crypted.
*/
typedef void
(*interface_mme_recv_cb_t) (void *user_data, uint tei, u8 *buffer,
- uint length, bool mme_recv, bool encryption);
-
-/**
- * Function to call when the interface receives a empty buffer.
- * \param user_data the data registered by the actor in the init function.
- * \param buffer the buffer to add.
- */
-typedef void
-(*interface_mme_buffer_add_cb_t) (void *user_data, u8 *buffer);
+ uint length, bool encryption);
BEGIN_DECLS
/**
* Initialise the interface module.
- * \param hle the hle context.
* \param cl the cl context.
+ * \param mbx the mbx context.
* \param sar the sar context.
* \param mac_config the mac config context.
+ * \param bufmgr the buffer manager context.
* \return the interface module context.
*/
interface_t*
-interface_init (hle_t *hle, cl_t *cl, sar_t *sar, mac_config_t
- *mac_config);
+interface_init (cl_t *cl, cl_mbx_t *mbx, sar_t *sar, mac_config_t *mac_config,
+ bufmgr_t *bufmgr);
/**
* Interface uninit.
@@ -71,36 +62,23 @@ interface_uninit (interface_t *ctx);
* Initialise the callbacks functions.
* \param ctx the interface context.
* \param mme_recv_cb the function to call on reception of a MME.
- * \param buffer_add_cb the function to call on buffer reception.
- * \param beacon_add_cb the function to call on beacon reception
* \param user_data the data to provide on each callback function.
*/
void
-interface_callback_init (interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb,
- interface_mme_buffer_add_cb_t buffer_add_cb, void *user_data);
+interface_callback_init (
+ interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb, void *user_data);
/** Receives an MME from the PWL or the HLE.
* \param ctx the interface context
* \param tei the station's source TEI.
* \param buffer the buffer containing the MME.
* \param length the MME length
- * \param mme_data data use by the CL.
* \param encrypted inform if the packet comes from the PWL if it has been
* crypted.
*/
void
interface_mme_recv (interface_t *ctx, uint tei, u8 *buffer, uint length,
- bool mme_data, bool encrypted);
-
-
-/**
- * Inform the Data plane when the MME as been processed by the CP.
- * \param ctx the interface context
- * \param buffer the buffer to give back.
- * \param mme_recv the cl data (as a void pointer).
- */
-void
-interface_mme_recv_done (interface_t *ctx, u8 *buffer, bool mme_recv);
+ bool encrypted);
/** Provides a MME to send to the CL. This MME can be send as a MME or a data.
* \param ctx the interface context.
@@ -119,15 +97,6 @@ interface_mme_send (interface_t *ctx, u8* buffer, uint length, uint tei);
void
interface_beacon (interface_t *ctx, bsu_beacon_t *beacon);
-/**
- * Sends a message to the IPMbox
- * \param ctx the interface context
- * \param data the message to post in the ipmbox.
- * \param length the length of the data in bytes.
- */
-void
-interface_hle_send (interface_t *ctx, uint *data, uint length);
-
END_DECLS
#endif /* interface_interface_h */
diff --git a/cesar/interface/sniffer/inc/context.h b/cesar/interface/sniffer/inc/context.h
index e5e31243b7..5ac9623842 100644
--- a/cesar/interface/sniffer/inc/context.h
+++ b/cesar/interface/sniffer/inc/context.h
@@ -10,7 +10,7 @@
/**
* \file interface/sniffer/inc/context.h
* \brief Context of the sniffer.
- * \ingroup inteface_sniffer
+ * \ingroup interface_sniffer
*
*/
@@ -28,11 +28,10 @@ struct interface_sniffer_t
bool sniff_mme_rx;
/** Mac config context. */
mac_config_t *mac_config;
-
- /** Call this function when it needs to post a message for the HLE. */
- interface_sniffer_send_message_cb_t send_func;
- /** data to provide on function callback. */
- void *send_user_data;
+ /** Convergence layer mbx context. */
+ cl_mbx_t *cl_mbx;
+ /** buffer manager context. */
+ bufmgr_t *bufmgr;
/** Destination mac address. */
mac_t da;
diff --git a/cesar/interface/sniffer/mmtype.h b/cesar/interface/sniffer/mmtype.h
index ed01c47c08..aa8a7bdf1f 100644
--- a/cesar/interface/sniffer/mmtype.h
+++ b/cesar/interface/sniffer/mmtype.h
@@ -17,4 +17,6 @@
#define VS_SNIFFER_CNF 0xA02D
#define VS_SNIFFER_IND 0xA02E
+#define INTERFACE_SNIFFER_MMTYPE VS_SNIFFER_REQ
+
#endif /* interface_sniffer_mmtype_h */
diff --git a/cesar/interface/sniffer/sniffer.h b/cesar/interface/sniffer/sniffer.h
index a95216fbe7..dd6a7af01a 100644
--- a/cesar/interface/sniffer/sniffer.h
+++ b/cesar/interface/sniffer/sniffer.h
@@ -13,18 +13,13 @@
* \ingroup interface_sniffer
*
*/
-#include "common/defs/ethernet.h"
-#include "common/defs/homeplugAV.h"
-
#include "hal/arch/arch.h"
-#include "lib/bitstream.h"
-#include "hal/hle/defs.h"
-#include "string.h"
-
-#include "mac/pbproc/pbproc.h"
-#include "mac/common/pb.h"
#include "interface/sniffer/mmtype.h"
#include "bsu/beacon/beacon.h"
+#include "cl/mbx/mbx.h"
+#include "bufmgr/bufmgr.h"
+
+#include <string.h>
#define INTERFACE_BEACON_SIZE 136
@@ -42,31 +37,21 @@ enum interface_sniffer_cnf_result_t
INTERFACE_SNIFFER_CNF_RESULT_NB
};
-/** Send a message to the interface. This message shall be send to the linux driver.
- * \param user_data the data provided in the function registration
- * \param message the message to send.
- * \param length the message length
- */
-typedef void (*interface_sniffer_send_message_cb_t) (void *user_data,
- uint *message, uint length);
-
-
/** Forward declaration. */
typedef struct interface_sniffer_t interface_sniffer_t;
BEGIN_DECLS
/** 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.
+ * \param cl_mbx the convergence layer to send MME to linux.
+ * \param bufmgr the buffer manager context.
* \param mac_config the mac_config.
*/
interface_sniffer_t*
-interface_sniffer_init (interface_sniffer_send_message_cb_t cb, void *user_data,
+interface_sniffer_init (cl_mbx_t *cl_mbx, bufmgr_t *bufmgr,
mac_config_t *mac_config);
-
-/** Uninitalise the sniffer.
+/** Uninitialise the sniffer.
* \param ctx the sniffer context.
*/
void
@@ -76,77 +61,69 @@ interface_sniffer_uninit (interface_sniffer_t *ctx);
* \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)
* \param encrypted if the MME has been encrypted or not.
*/
void
interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
- u8 *buffer, bool tx, bool encrypted);
+ bool tx, bool encrypted);
/** 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 encrypted if the MME has been encrypted or not.
*/
extern inline void
interface_sniffer_copy_mme_tx (interface_sniffer_t *ctx, u8 *mme, uint length,
- u8 *buffer, bool encrypted)
+ bool encrypted)
{
- interface_sniffer_copy_mme (ctx, mme, length, buffer, true, encrypted);
+ interface_sniffer_copy_mme (ctx, mme, length, true, encrypted);
}
/** 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 encrypted if the MME has been encrypted or not.
*/
extern inline void
interface_sniffer_copy_mme_rx (interface_sniffer_t *ctx, u8 *mme, uint length,
- u8 *buffer, bool encrypted)
+ bool encrypted)
{
- interface_sniffer_copy_mme (ctx, mme, length, buffer, false, encrypted);
+ interface_sniffer_copy_mme (ctx, mme, length, false, encrypted);
}
/** 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)
*/
void
interface_sniffer_copy_beacon (
- interface_sniffer_t *ctx, bsu_beacon_t *beacon, u8 *buffer, bool tx);
+ interface_sniffer_t *ctx, bsu_beacon_t *beacon, bool tx);
/** 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.
*/
extern inline void
-interface_sniffer_copy_beacon_tx (
- interface_sniffer_t *ctx, bsu_beacon_t *beacon, u8 *buffer)
+interface_sniffer_copy_beacon_tx (interface_sniffer_t *ctx, bsu_beacon_t *beacon)
{
- interface_sniffer_copy_beacon (ctx, beacon, buffer, true);
+ interface_sniffer_copy_beacon (ctx, beacon, true);
}
/** 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.
*/
extern inline void
-interface_sniffer_copy_beacon_rx (
- interface_sniffer_t *ctx, bsu_beacon_t *beacon, u8 *buffer)
+interface_sniffer_copy_beacon_rx (interface_sniffer_t *ctx, bsu_beacon_t *beacon)
{
- interface_sniffer_copy_beacon (ctx, beacon, buffer, false);
+ interface_sniffer_copy_beacon (ctx, beacon, false);
}
/** Provides the MME sniff status.
diff --git a/cesar/interface/sniffer/src/sniffer.c b/cesar/interface/sniffer/src/sniffer.c
index ce7afc47ae..1d4c96d29b 100644
--- a/cesar/interface/sniffer/src/sniffer.c
+++ b/cesar/interface/sniffer/src/sniffer.c
@@ -9,15 +9,12 @@
* \file interface/sniffer/src/sniffer.c
* \brief Sniffer source functions.
* \ingroup interface_sniffer
- *
- * « long description »
*/
#include "common/std.h"
#include "common/defs/spidcom.h"
+#include "common/defs/homeplugAV.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"
@@ -45,20 +42,15 @@ interface_sniffer_configure (interface_sniffer_t *ctx, uint data)
}
interface_sniffer_t*
-interface_sniffer_init (interface_sniffer_send_message_cb_t cb, void *user_data,
- mac_config_t *mac_config)
+interface_sniffer_init (cl_mbx_t *cl_mbx, bufmgr_t *bufmgr, mac_config_t *mac_config)
{
- 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;
sniffer_global.mac_config = mac_config;
-
+ sniffer_global.cl_mbx = cl_mbx;
+ sniffer_global.bufmgr = bufmgr;
return &sniffer_global;
}
@@ -71,29 +63,24 @@ interface_sniffer_uninit (interface_sniffer_t *ctx)
dbg_assert (ctx);
}
-/** 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)
+ bool tx, bool encrypted)
{
bitstream_t bitstream;
uint header_length;
uint embedded_length;
uint offset;
- uint word[2];
+ u8 *buffer;
dbg_assert (ctx);
dbg_assert (mme);
dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
&& (length <= ETH_PACKET_MAX_SIZE));
- dbg_assert (buffer);
- dbg_assert (ctx->send_func);
+
+ buffer = bufmgr_get (ctx->bufmgr);
+ if (!buffer)
+ return;
/* Compute the header size. */
if (ctx->vlan_tag == 0)
@@ -107,7 +94,6 @@ interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
embedded_length = ETH_PACKET_MAX_SIZE - header_length;
else
embedded_length = length;
-
/* Create the header of the MME. */
bitstream_write_init (&bitstream, buffer, header_length);
bitstream_write_large (&bitstream, ctx->da, 48);
@@ -119,34 +105,32 @@ interface_sniffer_copy_mme (interface_sniffer_t *ctx, u8 *mme, uint length,
bitstream_write (&bitstream, VS_SNIFFER_IND, 16);
bitstream_write (&bitstream, 0, 16);
bitstream_write (&bitstream, SPC_OUI, OUI_SIZE_BITS);
-
bitstream_write (&bitstream, INTERFACE_SNIFFER_TYPE_MME, 8);
/* 0 for TX, 1 for RX. */
bitstream_write (&bitstream, !tx, 8);
offset = bitstream_finalise (&bitstream) / 8;
bitstream_memcpy (buffer + offset, mme, embedded_length);
-
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
- (MSG_LENGTH, 1),
- (PARAM_INTERFACE_TYPE, INTERFACE_MODULE_SNIFFER),
- (PARAM_INTERFACE_LENGTH, length + offset));
-
- word[1] = (uint)buffer;
-
-
- /** Request the interface to send the message to the linux driver. */
- (*ctx->send_func) (ctx->send_user_data, word, 2);
+ /* Send the MME through the CL. */
+ cl_mbx_ipmbox_send (ctx->cl_mbx, buffer, length + offset);
}
void
interface_sniffer_copy_beacon (
- interface_sniffer_t *ctx, bsu_beacon_t *beacon, u8 *buffer, bool tx)
+ interface_sniffer_t *ctx, bsu_beacon_t *beacon, bool tx)
{
bitstream_t bitstream;
uint length;
- uint word[2];
+ u8 *buffer;
+
+ dbg_assert (ctx);
+ dbg_assert (beacon);
+
+ buffer = bufmgr_get (ctx->bufmgr);
+ if (!buffer)
+ return;
+
length = INTERFACE_BEACON_SIZE + sizeof (pbproc_rx_beacon_params_t);
- // Fill the buffer header.
+ /* Fill the buffer header. */
bitstream_init (&bitstream, buffer,
length + HPAV_MME_HEADER + INTERFACE_MME_HEADER_SIZE +
OUI_SIZE,
@@ -166,17 +150,8 @@ interface_sniffer_copy_beacon (
bitstream_write_large (&bitstream, beacon->vf.nid, 54);
bsu_beacon_write_bitstream_initialised_no_nid (beacon, &bitstream, buffer);
bitstream_finalise (&bitstream);
-
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
- (MSG_LENGTH, 1),
- (PARAM_INTERFACE_TYPE, INTERFACE_MODULE_SNIFFER),
- (PARAM_INTERFACE_LENGTH, length));
-
- word[1] = (uint)buffer;
-
-
- /** Request the interface to send the message to the linux driver. */
- (*ctx->send_func) (ctx->send_user_data, word, 2);
+ /* Send the MME through the CL. */
+ cl_mbx_ipmbox_send (ctx->cl_mbx, buffer, length);
}
diff --git a/cesar/interface/sniffer/test/Makefile b/cesar/interface/sniffer/test/Makefile
index fa382ea15e..29ad8b482b 100644
--- a/cesar/interface/sniffer/test/Makefile
+++ b/cesar/interface/sniffer/test/Makefile
@@ -1,7 +1,8 @@
BASE = ../../..
HOST_PROGRAMS = test-sniffer
-test-sniffer_SOURCES = test-sniffer.c
-test-sniffer_MODULES = lib interface/sniffer bsu/beacon
+test-sniffer_SOURCES = test-sniffer.c bufmgr_stub.c
+test-sniffer_MODULES = lib interface/sniffer bsu/beacon cl/stub \
+ cl/mbx/stub
include $(BASE)/common/make/top.mk
diff --git a/cesar/interface/sniffer/test/src/bufmgr_stub.c b/cesar/interface/sniffer/test/src/bufmgr_stub.c
new file mode 100644
index 0000000000..5c54c696ae
--- /dev/null
+++ b/cesar/interface/sniffer/test/src/bufmgr_stub.c
@@ -0,0 +1,28 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/bufmgr_stub.c
+ * \brief Buffer manager stub.
+ * \ingroup interface
+ */
+#include "common/std.h"
+#include "bufmgr/bufmgr.h"
+
+#include "common/defs/ethernet.h"
+
+static u8 buffer[ETH_PACKET_MAX_SIZE];
+
+u8*
+bufmgr_get (bufmgr_t *ctx)
+{
+ return buffer;
+}
+
+void
+bufmgr_give_back (bufmgr_t *bufmgr, u8 *buffer)
+{ }
diff --git a/cesar/interface/sniffer/test/src/test-sniffer.c b/cesar/interface/sniffer/test/src/test-sniffer.c
index 96ae5054f0..0ca5ba446f 100644
--- a/cesar/interface/sniffer/test/src/test-sniffer.c
+++ b/cesar/interface/sniffer/test/src/test-sniffer.c
@@ -16,6 +16,7 @@
#include "lib/bitstream.h"
#include "lib/swap.h"
#include "common/defs/spidcom.h"
+#include "common/defs/homeplugAV.h"
#include "interface/sniffer/sniffer.h"
#include "interface/sniffer/inc/context.h"
@@ -25,18 +26,11 @@ void
interface_sniffer_configure (interface_sniffer_t *ctx, uint data);
u8 request[1518];
-u8 answer [1518];
#define STA_MAC_ADDR 0x12345678ABCull
#define OSA1 0x23456789ABCDull
#define OSA2 0x3456789ABCDEull
-void
-test_interface_sniffer_send_message_cb (void *user_data, uint *message,
- uint length)
-{}
-
-
static void
test_sniffer_prepare_request (mac_t osa, uint req, uint vlan)
{
@@ -66,6 +60,7 @@ test_sniffer_read_answer (mac_t *oda, uint *res, uint *status,
dbg_assert (res);
dbg_assert (status);
dbg_assert (da);
+ u8 *answer = bufmgr_get (INVALID_PTR);
*oda = bitstream_direct_read_large (answer, 0, 48);
if (swap16(bitstream_direct_read (answer, 96, 16)) == HPAV_MTYPE_MME)
@@ -101,6 +96,7 @@ test_sniffer_configure (test_t test)
mac_t da;
uint result;
uint status;
+ u8 *answer = bufmgr_get (INVALID_PTR);
memset (&sniffer, 0, sizeof (interface_sniffer_t));
memset (&mac_config, 0, sizeof (mac_config_t));
@@ -356,12 +352,12 @@ test_sniffer_mme (test_t test)
{
interface_sniffer_t *sniffer;
mac_config_t mac_config;
+ u8 *answer = bufmgr_get (INVALID_PTR);
memset (&mac_config, 0, sizeof (mac_config_t));
mac_config.sta_mac_address = STA_MAC_ADDR;
- sniffer = interface_sniffer_init (test_interface_sniffer_send_message_cb,
- NULL, &mac_config);
+ sniffer = interface_sniffer_init (INVALID_PTR, INVALID_PTR, &mac_config);
test_case_begin (test, "Sniff MME");
@@ -384,7 +380,7 @@ test_sniffer_mme (test_t test)
length = bitstream_finalise (&stream) / 8;
memset (answer, 0, 1518);
- interface_sniffer_copy_mme_tx (sniffer, request, 60, answer, false);
+ interface_sniffer_copy_mme_tx (sniffer, request, 60, false);
bitstream_read_init (&stream, answer, ETH_PACKET_MAX_SIZE);
test_fail_unless (bitstream_read_large (&stream, 48) == sniffer->da);
@@ -402,7 +398,7 @@ test_sniffer_mme (test_t test)
test_fail_unless (memcmp (request, answer + 24, length) == 0);
memset (answer, 0, 1518);
- interface_sniffer_copy_mme_rx (sniffer, request, 60, answer, false);
+ interface_sniffer_copy_mme_rx (sniffer, request, 60, false);
bitstream_read_init (&stream, answer, ETH_PACKET_MAX_SIZE);
test_fail_unless (bitstream_read_large (&stream, 48) == sniffer->da);
@@ -534,16 +530,16 @@ test_sniffer_beacon_tx_rx (test_t test, bool tx)
mac_config_t mac_config;
memset (&mac_config, 0, sizeof (mac_config_t));
mac_config.sta_mac_address = STA_MAC_ADDR;
- sniffer = interface_sniffer_init (test_interface_sniffer_send_message_cb,
- NULL, &mac_config);
+ sniffer = interface_sniffer_init (INVALID_PTR, INVALID_PTR, &mac_config);
sniffer->da = OSA1;
pb_beacon_t *phy_beacon;
bsu_beacon_t beacon;
bitstream_t stream;
uint i;
test_sniffer_beacon_create (&beacon);
+ u8 *answer = bufmgr_get (INVALID_PTR);
memset (answer, 0, 1518);
- interface_sniffer_copy_beacon (sniffer, &beacon, answer, tx);
+ interface_sniffer_copy_beacon (sniffer, &beacon, tx);
bitstream_read_init (&stream, answer, 175);
test_fail_unless (OSA1 == bitstream_read_large (&stream, 48));
test_fail_unless (STA_MAC_ADDR == bitstream_read_large (&stream, 48));
diff --git a/cesar/interface/src/interface.c b/cesar/interface/src/interface.c
index 43bc1383a1..7df70dbc3e 100644
--- a/cesar/interface/src/interface.c
+++ b/cesar/interface/src/interface.c
@@ -13,9 +13,11 @@
*/
#include "common/std.h"
#include "common/defs/ethernet.h"
+#include "common/defs/priority.h"
#include "lib/swap.h"
-#include "hle/hle.h"
+#include "hal/arch/sem.h"
+
#include "interface/interface.h"
#include "interface/sniffer/mmtype.h"
#include "interface/fcall/defs.h"
@@ -24,8 +26,6 @@
#include "interface/inc/context.h"
#include "interface/inc/mme_process.h"
-#include "common/defs/priority.h"
-
#if CONFIG_INTERFACE_SNIFFER
# include "interface/sniffer/sniffer.h"
#endif
@@ -57,79 +57,38 @@ interface_thread_process (cyg_addrword_t data)
}
#endif
-#if CONFIG_INTERFACE_FCALL
-
-/**
- * Called by the interface fcall module when the buffer has been used.
- * This allows the HLE to know which buffer is newly available to be used or
- * give it back to the ARM. (the buffer is borrowed by the linux).
- *
- * \param ctx the interface context.
- * \param buffer the buffer used to send the data.
- */
-static void
-interface_hle_send_done (interface_t *ctx, u8 *buffer);
-
-#endif
-
-
-/**
- * Initialise the interface module.
- * \param hle the hle context.
- * \param cl the cl context.
- * \param sar the sar context.
- * \param mac_config the mac config context.
- * \return the interface module context.
- */
interface_t*
-interface_init (hle_t *hle, cl_t *cl, sar_t *sar, mac_config_t
- *mac_config)
+interface_init (cl_t *cl, cl_mbx_t *mbx, sar_t *sar, mac_config_t *mac_config,
+ bufmgr_t *bufmgr)
{
- dbg_assert (hle);
- dbg_assert (cl);
+ dbg_assert (mbx);
dbg_assert (sar);
dbg_assert (mac_config);
- interface_global.hle = hle;
interface_global.cl = cl;
+ interface_global.cl_mbx = mbx;
interface_global.sar = sar;
interface_global.mac_config = mac_config;
+ interface_global.bufmgr = bufmgr;
#if CONFIG_INTERFACE_SNIFFER
- interface_global.sniffer = interface_sniffer_init
- ((interface_sniffer_send_message_cb_t) interface_hle_send,
- &interface_global, mac_config);
+ interface_global.sniffer =
+ interface_sniffer_init (mbx, bufmgr, mac_config);
#endif /* CONFIG_INTERFACE_SNIFFER */
#if CONFIG_INTERFACE_FCALL
- interface_global.fcall = interface_fcall_init
- ((interface_fcall_send_message_cb_t) interface_hle_send,
- (interface_fcall_send_done_message_cb_t) interface_hle_send_done,
- (interface_fcall_get_buffer_cb_t) interface_buffer_work_get,
- &interface_global, mac_config);
+ interface_global.fcall =
+ interface_fcall_init (mbx, mac_config, bufmgr);
#endif /* CONFIG_INTERFACE_FCALL */
- mbox_init (&interface_global.buffers_mbox);
-
- // Integrate the HLE.
- hle_init_interface_cb (hle,
- (hle_interface_buffer_add_cb_t) interface_buffer_work_add,
- (hle_interface_mme_recv_cb_t) interface_hle_recv,
- &interface_global);
-
- // Integrate the CL.
- cl_mme_init_buffer_add_cb (cl,
- (cl_mme_buffer_add_cb_t) interface_buffer_add,
- &interface_global);
- cl_mme_recv_init (cl,(cl_mme_recv_cb_t) interface_mme_recv,
- &interface_global);
-
+ /* Integrate the CL MBX. */
+ cl_mbx_callback_register (mbx, (cl_mme_callback_t) interface_mme_recv,
+ &interface_global);
- // Create the mailbox.
+ /* Create the mailbox. */
mbox_init (&interface_global.mailbox);
#ifndef INTERFACE_UNIT_TEST
- // Create the interface thread.
cyg_thread_create(INTERFACE_THREAD_PRIORITY, &interface_thread_process,
(cyg_addrword_t) &interface_global,
"INTERFACE",
@@ -151,9 +110,7 @@ void
interface_uninit (interface_t *ctx)
{
dbg_assert (ctx);
-
mbox_uninit (&ctx->mailbox);
-
#ifndef INTERFACE_UNIT_TEST
cyg_thread_suspend (ctx->thread_handle);
#endif
@@ -165,71 +122,57 @@ interface_uninit (interface_t *ctx)
#endif /* CONFIG_INTERFACE_FCALL */
}
-/**
- * Initialise the callbacks functions.
- * \param ctx the interface context.
- * \param mme_recv_cb the function to call on reception of a MME.
- * \param buffer_add_cb the function to call on buffer reception.
- * \param beacon_add_cb the function to call on beacon reception
- * \param user_data the data to provide on each callback function.
- */
void
-interface_callback_init (interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb,
- interface_mme_buffer_add_cb_t buffer_add_cb, void *user_data)
+interface_callback_init (
+ interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb, void *user_data)
{
dbg_assert (ctx);
dbg_assert (mme_recv_cb);
- dbg_assert (buffer_add_cb);
-
ctx->mme_recv_cb = mme_recv_cb;
- ctx->buffer_add_cb = buffer_add_cb;
ctx->interface_mme_user_data = user_data;
}
-/** Receives an MME from the PWL or the HLE.
- * \param ctx the interface context
- * \param tei the station's source TEI.
- * \param buffer the buffer containing the MME.
- * \param length the MME length
- * \param mme_data data use by the CL.
- * \param encrypted inform if the packet comes from the PWL if it has been
- * crypted.
- */
void
interface_mme_recv (interface_t *ctx, uint tei, u8 *buffer, uint length,
- bool mme_data, bool encrypted)
+ bool encrypted)
{
dbg_assert (ctx);
dbg_assert (buffer);
dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
&& (length <= ETH_PACKET_MAX_SIZE));
-
#if CONFIG_INTERFACE_SNIFFER
if (interface_sniffer_mme_status_rx(ctx->sniffer))
{
- u8 *copy_buffer = interface_buffer_work_get (ctx);
-
- if (copy_buffer)
- {
- interface_sniffer_copy_mme_rx (ctx->sniffer, buffer, length,
- copy_buffer, encrypted);
- }
+ interface_sniffer_copy_mme_rx (ctx->sniffer, buffer, length,
+ encrypted);
}
#endif /* CONFIG_INTERFACE_SNIFFER */
-
- // Call the actor callback.
- dbg_assert (ctx->mme_recv_cb);
- (*ctx->mme_recv_cb) (ctx->interface_mme_user_data, tei, buffer,
- length, mme_data, encrypted);
-}
-
-void
-interface_mme_recv_done (interface_t *ctx, u8 *buffer, bool mme_recv)
-{
- dbg_assert (ctx);
- dbg_assert (ctx->cl);
-
- cl_mme_recv_done (ctx->cl, buffer, mme_recv);
+ /* Filter Interface MMType. */
+ uint ether_type, mmtype_bits_offset, mmtype_base;
+ /* Get the Ethernet type first to detect the VLAN. */
+ ether_type = bitstream_direct_read (
+ buffer, BYTES_SIZE_TO_BITS (HPAV_MTYPE_OFFSET),
+ BYTES_SIZE_TO_BITS (HPAV_MTYPE_SIZE));
+ mmtype_bits_offset = BYTES_SIZE_TO_BITS (HPAV_MMTYPE_OFFSET);
+ /* If the Ether type is an HPAV MME, there is no VLAN tag. */
+ if (swap16 (ether_type) != HPAV_MTYPE_MME)
+ mmtype_bits_offset = BYTES_SIZE_TO_BITS (HPAV_VLANTAG_SIZE);
+ /* Get the MME Type and convert it into the MME Type base. */
+ mmtype_base = bitstream_direct_read (
+ buffer, mmtype_bits_offset, BYTES_SIZE_TO_BITS (HPAV_MMTYPE_SIZE))
+ & ~0x3;
+ /* If MMTYPE is interface FCALL or Sniffer. */
+ if (mmtype_base == INTERFACE_FCALL_MMTYPE
+ || mmtype_base == INTERFACE_SNIFFER_MMTYPE)
+ {
+ mbox_put (&ctx->mailbox, (mbox_node_t *) buffer);
+ }
+ else
+ {
+ dbg_assert (ctx->mme_recv_cb);
+ (*ctx->mme_recv_cb) (ctx->interface_mme_user_data, tei, buffer,
+ length, encrypted);
+ }
}
/** Provides a MME to send to the CL. This MME can be send as a MME or a data.
@@ -245,21 +188,11 @@ interface_mme_send (interface_t *ctx, u8* buffer, uint length, uint tei)
dbg_assert (buffer);
dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
&& (length <= ETH_PACKET_MAX_SIZE));
-
#if CONFIG_INTERFACE_SNIFFER
if (interface_sniffer_mme_status_tx (ctx->sniffer))
- {
- u8 *copy_buffer = interface_buffer_work_get (ctx);
-
- if (copy_buffer)
- {
- interface_sniffer_copy_mme_tx (ctx->sniffer, buffer, length,
- copy_buffer, false);
- }
- }
+ interface_sniffer_copy_mme_tx (
+ ctx->sniffer, buffer, length, false);
#endif /* CONFIG_INTERFACE_SNIFFER */
-
- dbg_assert (ctx->cl);
cl_mme_send (ctx->cl, buffer, length, tei);
}
@@ -273,153 +206,42 @@ interface_beacon (interface_t *ctx, bsu_beacon_t *beacon)
if (beacon->params.direction == BSU_BEACON_DIRECTION_TO_PLC
&& interface_sniffer_beacon_status_tx (ctx->sniffer))
{
- u8 *buffer = interface_buffer_work_get (ctx);
- if (buffer)
- interface_sniffer_copy_beacon_tx (
- ctx->sniffer, beacon, buffer);
+ interface_sniffer_copy_beacon_tx (ctx->sniffer, beacon);
}
else if (beacon->params.direction == BSU_BEACON_DIRECTION_FROM_PLC
&& interface_sniffer_beacon_status_rx (ctx->sniffer))
{
- u8 *buffer = interface_buffer_work_get (ctx);
- if (buffer)
- interface_sniffer_copy_beacon_rx (
- ctx->sniffer, beacon, buffer);
+ interface_sniffer_copy_beacon_rx (ctx->sniffer, beacon);
}
#endif /* CONFIG_INTERFACE_SNIFFER */
}
-/**
- * Sends a message to the IPMbox
- * \param ctx the interface context
- * \param data the message to post in the ipmbox.
- * \param length the length of the data in bytes.
- */
-void
-interface_hle_send (interface_t *ctx, uint *data, uint length)
-{
- dbg_assert (ctx);
- dbg_assert (data);
- dbg_assert (length);
-
- hle_ipmbox_send (ctx->hle, data, length);
-}
-
-#if CONFIG_INTERFACE_FCALL
-
-/**
- * Called by the interface fcall module when the buffer has been used.
- * This allows the HLE to know which buffer is newly available to be used or
- * give it back to the ARM. (the buffer is borrowed by the linux).
- *
- * \param ctx the interface context.
- * \param buffer the buffer used to send the data.
- */
-static void
-interface_hle_send_done (interface_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (ctx->hle);
-
- hle_send_done (ctx->hle, buffer);
-}
-
-#endif /* CONFIG_INTERFACE_FCALL */
-
-/**
- * Add a buffer to the registered actor.
- * \param ctx the interface context.
- * \param buffer the buffer to add.
- */
-void
-interface_buffer_add (interface_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
- dbg_assert (ctx->buffer_add_cb);
-
- (*ctx->buffer_add_cb) (ctx->interface_mme_user_data, buffer);
-}
-
-/**
- * Add a buffer to its own list.
- * \param ctx the interface context.
- * \param buffer the buffer to add.
- */
-void
-interface_buffer_work_add (interface_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- dbg_assert (ctx->buffer_add_cb);
-
- mbox_put (&ctx->buffers_mbox, (mbox_node_t *) buffer);
-}
-
-/**
- * Get a buffer from the list.
- * \param ctx the interface context.
- * \return the buffer to use, NULL if no buffer is available.
- */
-u8*
-interface_buffer_work_get (interface_t *ctx)
-{
- u8 *buffer;
- dbg_assert (ctx);
-
- buffer = (u8*) mbox_try_get (&ctx->buffers_mbox);
-
- return buffer;
-}
-
-/**
- * Receive a data from the HLE.
- * \param ctx the interface context.
- * \param buffer the Message received.
- *
- * This will be use by the Fcall module in the interface. It can be use by
- * anything in the future.
- */
-void
-interface_hle_recv (interface_t *ctx, u8 *buffer)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- mbox_put (&ctx->mailbox, (mbox_node_t *) buffer);
-}
-
static inline bool
interface_read_mme (interface_t *ctx, u8 *mme, uint *mmtype)
{
bitstream_t stream;
- mac_t oda = 0;
- mac_t osa = 0;
- uint vlantag = 0;
uint mtype = 0;
uint mmv = 0;
uint fmi = 0;
- uint offset = 0;
bitstream_read_init (&stream, mme, ETH_PACKET_MAX_SIZE);
- oda = bitstream_read_large (&stream, 48);
- osa = bitstream_read_large (&stream, 48);
+ bitstream_skip (&stream, 48);
+ bitstream_skip (&stream, 48);
if (bitstream_direct_read (mme, 96, 16) != swap16(HPAV_MTYPE_MME))
- vlantag = bitstream_read (&stream, 32);
+ bitstream_skip (&stream, 32);
mtype = swap16(bitstream_read (&stream, 16));
mmv = bitstream_read (&stream, 8);
*mmtype = bitstream_read (&stream, 16);
fmi = bitstream_read (&stream, 16);
- offset = bitstream_finalise (&stream);
+ bitstream_finalise (&stream);
- if ((mtype == HPAV_MTYPE_MME)
- && (mmv == HPAV_MMV)
- && ((*mmtype == VS_SNIFFER_REQ)
- || (*mmtype == INTERFACE_FCALL_MMTYPE)))
+ if (mtype == HPAV_MTYPE_MME
+ && mmv == HPAV_MMV
+ && (*mmtype == VS_SNIFFER_REQ
+ || *mmtype == INTERFACE_FCALL_MMTYPE_IND)
+ && fmi == 0)
return true;
return false;
}
@@ -441,30 +263,16 @@ interface_process (interface_t *ctx)
// Configure the interface sniffer sub module.
case VS_SNIFFER_REQ:
{
- u8 *ans = interface_buffer_work_get (ctx);
+ u8 *ans = bufmgr_get_wait (ctx->bufmgr, 0);
interface_sniffer_configure_and_respond (ctx->sniffer, buffer,
ans);
- uint word[2];
- /* Give back the current buffer. */
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE,
- HLE_MSG_TYPE_SEND_DONE),
- (MSG_LENGTH, 1));
- word[1] = (uint) buffer;
- interface_hle_send (ctx, word, 2);
- /* Send the CNF MME. */
- word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE,
- HLE_MSG_TYPE_INTERFACE),
- (MSG_LENGTH, 1),
- (PARAM_INTERFACE_TYPE,
- INTERFACE_MODULE_SNIFFER),
- (PARAM_INTERFACE_LENGTH, 60));
- word[1] = (uint) ans;
- interface_hle_send (ctx, word, 2);
+ bufmgr_give_back (ctx->bufmgr, buffer);
+ cl_mme_send (ctx->cl, ans, 60, MAC_TEI_FOREIGN);
}
break;
#endif /* CONFIG_INTERFACE_SNIFFER */
#if CONFIG_INTERFACE_FCALL
- case INTERFACE_FCALL_MMTYPE:
+ case INTERFACE_FCALL_MMTYPE_IND:
interface_fcall_mme_recv (ctx->fcall, buffer);
break;
#endif /* CONFIG_INTERFACE_FCALL */
diff --git a/cesar/interface/stub/src/interface.c b/cesar/interface/stub/src/interface.c
index 3337f491cb..2756ce7716 100644
--- a/cesar/interface/stub/src/interface.c
+++ b/cesar/interface/stub/src/interface.c
@@ -15,71 +15,60 @@
#include "interface/interface.h"
interface_t*
-interface_init (hle_t *hle, cl_t *cl, sar_t *sar, mac_config_t
- *mac_config)__attribute__((weak));
-
-void
-interface_uninit (interface_t *ctx)__attribute__((weak));
-
-void
-interface_callback_init (interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb,
- interface_mme_buffer_add_cb_t buffer_add_cb, void *user_data)__attribute__((weak));
-
-void
-interface_mme_recv (interface_t *ctx, uint tei, u8 *buffer, uint length,
- bool mme_data, bool encrypted)__attribute__((weak));
-
-
-void
-interface_mme_recv_done (interface_t *ctx, u8 *buffer, bool mme_recv)__attribute__((weak));
-
-void
-interface_mme_send (interface_t *ctx, u8* buffer, uint length, uint tei)__attribute__((weak));
-
-void
-interface_beacon (interface_t *ctx, bsu_beacon_t *beacon)__attribute__((weak));
-
-void
-interface_hle_send (interface_t *ctx, uint *data, uint length)__attribute__((weak));
+interface_init (cl_t *cl, cl_mbx_t *mbx, sar_t *sar, mac_config_t *mac_config,
+ bufmgr_t *bufmgr) __attribute__((weak));
interface_t*
-interface_init (hle_t *hle, cl_t *cl, sar_t *sar, mac_config_t
- *mac_config)
+interface_init (cl_t *cl, cl_mbx_t *mbx, sar_t *sar, mac_config_t *mac_config,
+ bufmgr_t *bufmgr)
{
return NULL;
}
void
-interface_uninit (interface_t *ctx){}
+interface_uninit (interface_t *ctx) __attribute__((weak));
void
-interface_callback_init (interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb,
- interface_mme_buffer_add_cb_t buffer_add_cb, void *user_data){}
+interface_uninit (interface_t *ctx)
+{
+}
void
-interface_mme_recv (interface_t *ctx, uint tei, u8 *buffer, uint length,
- bool mme_data, bool encrypted){}
-
+interface_callback_init (
+ interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb, void *user_data)
+__attribute__((weak));
void
-interface_mme_recv_done (interface_t *ctx, u8 *buffer, bool mme_recv){}
+interface_callback_init (
+ interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb, void *user_data)
+{
+}
void
-interface_mme_send (interface_t *ctx, u8* buffer, uint length, uint tei){}
+interface_mme_recv (interface_t *ctx, uint tei, u8 *buffer, uint length,
+ bool encrypted) __attribute__((weak));
void
-interface_beacon_prepare (interface_t *ctx, pb_beacon_t *beacon,
- mfs_tx_t *beacon_mfs, void *bto_bpsto){}
+interface_mme_recv (interface_t *ctx, uint tei, u8 *buffer, uint length,
+ bool encrypted)
+{
+}
-void interface_beacon_add (interface_t *ctx, bsu_beacon_t *beacon){}
+void
+interface_mme_send (interface_t *ctx, u8* buffer, uint length, uint tei)
+__attribute__((weak));
void
-interface_hle_send (interface_t *ctx, uint *data, uint length){}
+interface_mme_send (interface_t *ctx, u8* buffer, uint length, uint tei)
+{
+}
void
interface_beacon (interface_t *ctx, bsu_beacon_t *beacon)
-{}
+__attribute__((weak));
void
-bsu_init_beacon_cb (bsu_beacon_processed_t cb, void *cb_ud){}
+interface_beacon (interface_t *ctx, bsu_beacon_t *beacon)
+{
+}
diff --git a/cesar/interface/test/Makefile.mk b/cesar/interface/test/Makefile.mk
new file mode 100644
index 0000000000..a6c059816b
--- /dev/null
+++ b/cesar/interface/test/Makefile.mk
@@ -0,0 +1,9 @@
+BASE = ../..
+DEFS= -DINTERFACE_UNIT_TEST=1
+ECOS = y
+
+TARGET_PROGRAMS = test-interface
+test-interface_SOURCES = sar_stub.c test-interface.c bufmgr_stub.c
+test-interface_MODULES = lib interface host bsu/beacon\
+ cl/stub cl/mbx/stub \
+ $(SPARC_MODULES) $(SYNTH_MODULES)
diff --git a/cesar/interface/test/sparc-Makefile b/cesar/interface/test/sparc-Makefile
index 5cd45a282a..e322180778 100644
--- a/cesar/interface/test/sparc-Makefile
+++ b/cesar/interface/test/sparc-Makefile
@@ -1,15 +1,5 @@
-BASE = ../..
-
TARGET = sparc
-
-DEFS = -DINTERFACE_UNIT_TEST=1
-ECOS = y
-
-TARGET_PROGRAMS = test-interface
-test-interface_SOURCES = sar_stub.c test-interface.c
-test-interface_MODULES = lib interface host \
- cl/stub hal bsu/beacon
-
-
+SPARC_MODULES = hal
VARIANT = sparc
+include Makefile.mk
include $(BASE)/common/make/top.mk
diff --git a/cesar/interface/test/src/bufmgr_stub.c b/cesar/interface/test/src/bufmgr_stub.c
new file mode 100644
index 0000000000..da7958c992
--- /dev/null
+++ b/cesar/interface/test/src/bufmgr_stub.c
@@ -0,0 +1,34 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/bufmgr_stub.c
+ * \brief Buffer manager stub.
+ * \ingroup interface
+ */
+#include "common/std.h"
+#include "bufmgr/bufmgr.h"
+
+#include "common/defs/ethernet.h"
+
+static u8 buffer[ETH_PACKET_MAX_SIZE];
+
+u8*
+bufmgr_get (bufmgr_t *ctx)
+{
+ return buffer;
+}
+
+u8*
+bufmgr_get_wait (bufmgr_t *ctx, uint delay_rtc)
+{
+ return buffer;
+}
+
+void
+bufmgr_give_back (bufmgr_t *bufmgr, u8 *buffer)
+{ }
diff --git a/cesar/interface/test/src/sar_stub.c b/cesar/interface/test/src/sar_stub.c
index 41584542f9..15f13268a1 100644
--- a/cesar/interface/test/src/sar_stub.c
+++ b/cesar/interface/test/src/sar_stub.c
@@ -23,7 +23,8 @@ struct sar_t
static sar_t sar_global;
sar_t *
-sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed)
+sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca,
+ bufmgr_t *bufmgr, u32 seed)
{
return &sar_global;
}
diff --git a/cesar/interface/test/src/test-interface.c b/cesar/interface/test/src/test-interface.c
index d45cc5424f..b8d43fdf43 100644
--- a/cesar/interface/test/src/test-interface.c
+++ b/cesar/interface/test/src/test-interface.c
@@ -14,8 +14,9 @@
#include "common/std.h"
#include "common/defs/spidcom.h"
#include "lib/test.h"
+#include "lib/swap.h"
-#include "hal/hle/ipmbox.h"
+#include "hal/ipmbox/ipmbox.h"
#include "cl/cl.h"
#include "mac/sar/sar.h"
#include "interface/interface.h"
@@ -38,21 +39,15 @@
interface_t *interface;
-bool test_buffer_add;
bool test_copy;
bool test_mme_recv;
bool test_beacon_add;
u8 request [1518];
-u8 answer [1518];
-
-
-void
-test_interface_mme_buffer_add (void *user_data, u8 *buffer);
void
test_interface_mme_recv (void *user_data, uint tei, u8 *buffer,
- uint length, bool mme_recv, bool encrypted);
+ uint length, bool encrypted);
void
test_interface_beacon_add(void *user_data, pb_beacon_t *beacon);
@@ -168,6 +163,7 @@ test_sniffer_read_answer (mac_t *oda, uint *res, uint *status,
dbg_assert (status);
dbg_assert (da);
+ u8 *answer = bufmgr_get (INVALID_PTR);
mmtype = bitstream_direct_read (answer, 120, 16);
if ((mmtype == VS_SNIFFER_CNF)
@@ -204,8 +200,7 @@ test_configure_sniffer (test_t test)
for (i = 0; i < 0xF; i++)
{
test_sniffer_prepare_request (OSA1, i);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
test_sniffer_read_answer (&oda, &res, &status, &da);
@@ -227,8 +222,7 @@ test_configure_sniffer (test_t test)
mac_t da;
test_sniffer_prepare_request (OSA2, 0x1);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
test_sniffer_read_answer (&oda, &res, &status, &da);
@@ -248,8 +242,7 @@ test_configure_sniffer (test_t test)
mac_t da;
test_sniffer_prepare_request (OSA2, 0x0);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
test_sniffer_read_answer (&oda, &res, &status, &da);
@@ -269,8 +262,7 @@ test_configure_sniffer (test_t test)
mac_t da;
test_sniffer_prepare_request (OSA2, 0x1);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
test_sniffer_read_answer (&oda, &res, &status, &da);
@@ -284,33 +276,6 @@ test_configure_sniffer (test_t test)
}
void
-test_adding_buffers (test_t test)
-{
- test_case_begin (test, "Adding buffers");
-
- test_begin (test, "Add buffer to Control Plane")
- {
- test_buffer_add = false;
- interface_buffer_add (interface, request);
-
- test_fail_unless (test_buffer_add == true);
- }
- test_end;
-
- test_begin (test, "Add buffer to interface")
- {
- u8 *buffer = NULL;
- interface_buffer_work_add (interface, request);
-
- buffer = interface_buffer_work_get (interface);
- test_fail_unless (buffer != NULL);
- test_fail_unless (buffer == request);
- }
- test_end;
-
-}
-
-void
test_copy_mme (test_t test)
{
test_suite_begin (test, "Copy MME");
@@ -323,13 +288,11 @@ test_copy_mme (test_t test)
uint length;
test_sniffer_prepare_request (OSA1, 0);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
test_sniffer_prepare_request (OSA1, 3);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
/* Prepare the MME to be sniffed. */
@@ -345,14 +308,13 @@ test_copy_mme (test_t test)
bitstream_write_large (&stream, 0x123456789ABCDull, 56);
length = bitstream_finalise (&stream) / 8;
+ u8 *answer = bufmgr_get (INVALID_PTR);
memset (answer, 0, 1518);
- interface_buffer_work_add (interface, answer);
interface_mme_send (interface, request, 60, 0x10);
test_fail_unless (memcmp (request, answer + 24, length) == 0);
memset (answer, 0, 1518);
- interface_buffer_work_add (interface, answer);
- interface_mme_recv (interface, 0x10, request, 60, true, false);
+ interface_mme_recv (interface, 0x10, request, 60, false);
test_fail_unless (memcmp (request, answer + 24, length) == 0);
}
test_end;
@@ -373,18 +335,15 @@ test_copy_beacon (test_t test)
beacon->params.direction = BSU_BEACON_DIRECTION_TO_PLC;
test_create_beacon (beacon);
test_sniffer_prepare_request (OSA1, 0);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
test_sniffer_prepare_request (OSA1, 0xC);
- interface_hle_recv (interface, request);
- interface_buffer_work_add (interface, answer);
+ mbox_put (&interface->mailbox, (mbox_node_t *) request);
interface_process (interface);
-
+ u8 *answer = bufmgr_get (INVALID_PTR);
memset (answer, 0, 1518);
- interface_buffer_work_add (interface, answer);
interface_beacon (interface, beacon);
bitstream_read_init (&stream, answer, 175);
@@ -416,7 +375,6 @@ test_copy_beacon (test_t test)
bitstream_finalise (&stream);
memset (answer, 0, 1518);
- interface_buffer_work_add (interface, answer);
beacon->params.direction = BSU_BEACON_DIRECTION_FROM_PLC;
interface_beacon (interface, beacon);
@@ -457,28 +415,24 @@ int
main (void)
{
test_t test;
- cl_t *cl;
+ cl_mbx_t *mbx;
sar_t *sar;
- hle_t *hle;
mac_config_t mac_config;
test_init (test, 0, NULL);
- cl = cl_init(NULL, NULL, NULL);
- sar = sar_init (NULL, NULL, NULL, 0x2);
- hle = blk_alloc ();
+ mbx = cl_mbx_init (NULL);
+ sar = sar_init (NULL, NULL, NULL, NULL, 0x2);
mac_config.sta_mac_address = STA_MAC_ADDR;
- interface = interface_init (hle, cl, sar, &mac_config);
- interface_callback_init (interface, test_interface_mme_recv,
- test_interface_mme_buffer_add, cl);
+ interface = interface_init (
+ INVALID_PTR, mbx, sar, &mac_config, INVALID_PTR);
+ interface_callback_init (interface, test_interface_mme_recv, mbx);
test_configure_sniffer (test);
- test_adding_buffers (test);
test_copy_mme (test);
test_copy_beacon (test);
interface_uninit (interface);
- blk_release (hle);
test_result (test);
#ifndef __sparc__
@@ -487,32 +441,9 @@ main (void)
return test_nb_failed (test) == 0 ? 0 : 1;
}
-/**
- * Initialise the interface to add an Interface buffer.
- *
- * \param ctx the hle context.
- * \param buffer_cb the function to call on interface buffer reception.
- * \param mme_cb the function to call on interface mme.
- * \param user_data the user_data to provide on function call.
- */
-void
-hle_init_interface_cb (hle_t *ctx, hle_interface_buffer_add_cb_t buffer_cb,
- hle_interface_mme_recv_cb_t mme_cb, void *user_data)
-{
-}
-
-
-void
-test_interface_mme_buffer_add (void *user_data, u8 *buffer)
-{
- dbg_assert (buffer);
- test_buffer_add = true;
-}
-
-
void
test_interface_mme_recv (void *user_data, uint tei, u8 *buffer,
- uint length, bool mme_recv, bool encryption)
+ uint length, bool encryption)
{
dbg_assert (buffer);
@@ -527,19 +458,9 @@ test_interface_beacon_add(void *user_data, pb_beacon_t *beacon)
test_beacon_add = true;
}
-void
-hle_ipmbox_send (hle_t *ctx, u32 *msg, uint length)
-{
- test_copy = true;
-}
-
-void
-hle_send_done (hle_t *ctx, u8 *buffer)
-{
-}
-
cl_t *
-cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config)
+cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config,
+ ipmbox_t *ipmbox, bufmgr_t *bufmgr)
{
return (cl_t *) 0x12345678;
}
diff --git a/cesar/interface/test/synth-Makefile b/cesar/interface/test/synth-Makefile
index 652c36ded8..32b9b8e86f 100644
--- a/cesar/interface/test/synth-Makefile
+++ b/cesar/interface/test/synth-Makefile
@@ -1,14 +1,3 @@
-BASE = ../..
-
-ECOS = y
-
-DEFS= -DINTERFACE_UNIT_TEST=1
-
-TARGET_PROGRAMS = test-interface
-test-interface_SOURCES = sar_stub.c test-interface.c
-test-interface_MODULES = lib interface host \
- cl/stub bsu/beacon
-
VARIANT = synth
-
+include Makefile.mk
include $(BASE)/common/make/top.mk
diff --git a/cesar/mac/pbproc/test/int/sparc-Makefile b/cesar/mac/pbproc/test/int/sparc-Makefile
index 6152f8e490..552b052293 100644
--- a/cesar/mac/pbproc/test/int/sparc-Makefile
+++ b/cesar/mac/pbproc/test/int/sparc-Makefile
@@ -9,8 +9,8 @@ TARGET_OPTIMIZE = -Os
TARGET_PROGRAMS = test_pbproc
test_pbproc_SOURCES = test_pbproc.c get_seg.c add_seg.c prepare_beacon.c \
dataplane_stub.c
-test_pbproc_MODULES = lib hal hle interface host \
- mac/pbproc mac/ca mac/common \
+test_pbproc_MODULES = lib hal hle/tools interface host \
+ mac/pbproc mac/ca mac/common cl/stub bufmgr \
mac/ca/test/fcall mac/common/test/fcall
VARIANT = sparc
diff --git a/cesar/mac/pbproc/test/int/src/dataplane_stub.c b/cesar/mac/pbproc/test/int/src/dataplane_stub.c
index 00acf68efb..9e9668be00 100644
--- a/cesar/mac/pbproc/test/int/src/dataplane_stub.c
+++ b/cesar/mac/pbproc/test/int/src/dataplane_stub.c
@@ -12,76 +12,27 @@
*/
#include "common/std.h"
-#include "cl/cl.h"
+#include "mac/sar/sar.h"
-void
-cl_data_buffer_add (cl_t *cl, u8 *buffer)
-{
-}
-
-void
-cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user)
-{
-}
-
-void
-cl_data_send (cl_t *cl, u8 *buffer, uint length, uint tag,
- u32 arrival_time_ntb)
-{
-}
-
-void
-cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user)
-{
-}
-
-void
-cl_mme_buffer_add (cl_t *cl, u8 *buffer)
-{
-}
-
-void
-cl_mme_init_buffer_add_cb (cl_t *cl, cl_mme_buffer_add_cb_t cb, void *user_data)
-{
-}
-
-void
-cl_mme_init_ul_as_data (cl_t *ctx, cl_mme_ul_send_done_cb_t cb, void *user)
-{
-}
-
-void
-cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs, bool encryption)
-{
-}
-
-void
-cl_mme_recv_done (cl_t *ctx, u8 *buffer, bool mme_recv)
-{
-}
-
-void
-cl_mme_recv_init (cl_t *ctx, cl_mme_recv_cb_t mme_recv_cb, void *user)
-{
-}
+#include "cl/mbx/mbx.h"
void
-cl_mme_send (cl_t *ctx, u8 *buffer, uint length, uint tei)
+sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs, void *bto_bpsto)
{
}
void
-cl_mme_ul_init_send_done (cl_t *ctx, cl_mme_ul_recv_done_cb_t cb, void *user)
+sar_init_beacon_cb (sar_t *sar, void *user_data, sar_beacon_cb_t uf)
{
}
void
-sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs, void *bto_bpsto)
+cl_mbx_callback_register (cl_mbx_t *ctx, cl_mme_callback_t cb,
+ void *user_data)
{
}
void
-sar_init_beacon_cb (sar_t *sar, void *user_data, sar_beacon_cb_t uf)
+cl_mbx_ipmbox_send (cl_mbx_t *ctx, u8 *buffer, uint length)
{
}
-
diff --git a/cesar/mac/pbproc/test/int/src/test_pbproc.c b/cesar/mac/pbproc/test/int/src/test_pbproc.c
index 546d7f6aa7..624c71d0c4 100644
--- a/cesar/mac/pbproc/test/int/src/test_pbproc.c
+++ b/cesar/mac/pbproc/test/int/src/test_pbproc.c
@@ -25,9 +25,9 @@
#include "config/fcall/mme.h"
#if CONFIG_FCALL_MME
-# include "hle/hle.h"
# include "interface/interface.h"
# include "interface/inc/context.h"
+# include "interface/fcall/inc/context.h"
# include "common/defs/spidcom.h"
# include "mac/common/ntb.h"
#endif
@@ -439,10 +439,9 @@ cp_mme_recv (void *user_data,
uint tei,
u8 *buffer,
uint length,
- bool mme_recv,
bool encryption)
{
- interface_mme_recv_done (user_data, buffer, mme_recv);
+ bufmgr_give_back (user_data, buffer);
}
void
@@ -461,14 +460,11 @@ cyg_user_start (void)
#if CONFIG_FCALL_MME
test_pbproc_global.config.sta_mac_address = SPC_OUI;
mac_ntb_init (&test_pbproc_global.config);
- hle_t *hle = hle_init (INVALID_PTR);
- interface_t *interface = interface_init (hle, INVALID_PTR, INVALID_PTR,
- &test_pbproc_global.config);
- interface_callback_init (interface,
- cp_mme_recv,
- cp_mme_buffer_add,
- interface);
- hle_activate (hle, true);
+ interface_t *interface = interface_init (INVALID_PTR, INVALID_PTR,
+ INVALID_PTR,
+ &test_pbproc_global.config,
+ INVALID_PTR);
+ interface_callback_init (interface, cp_mme_recv, interface);
fcall = interface->fcall->fcall_ctx;
#else /* !CONFIG_FCALL_MME */
fcall = my_station.fcall;
diff --git a/cesar/mac/sar/inc/sar.h b/cesar/mac/sar/inc/sar.h
index c40f7c0e13..1c47c33fc0 100644
--- a/cesar/mac/sar/inc/sar.h
+++ b/cesar/mac/sar/inc/sar.h
@@ -56,15 +56,14 @@ sar_rx_mpdu_process (sar_t *ctx, sar_mpdu_t * rx);
/**
* Provide the next reassembly job to the bridge DMA.
- * \param sar_ctx the SAR context.
- * \param ctx the reassembly context to transmit the data.
+ * \param ctx the SAR context.
*
* It only provided the job to the bridge DMA if a reassembly buffer is
* available. It will loop to provide a maximum of jobs to the bridge DMA
* until it has available buffers and jobs.
*/
void
-sar_rx_upper_layer_transmit_data (sar_t *sar_ctx, sar_reassembly_ctx_t *ctx);
+sar_rx_upper_layer_transmit_data (sar_t *ctx);
/**
* Create the job descriptor and allocate the PB to store the MSDU.
@@ -108,7 +107,6 @@ sar_bridge_dma_free_head (sar_t *ctx);
* Process the MFS to reconstitute Mac Frames.
* \param ctx the SAR context
* \param mfs the MFS to process.
- * \param rea_ctx the reassembly context.
*
* Process the contiguous PB list in the MFS and reconstitute all possibles
* Mac Frames the sub list contains. If PBs are missing to reassembly the next
@@ -116,8 +114,7 @@ sar_bridge_dma_free_head (sar_t *ctx);
* the PBs are expired.
*/
void
-sar_rx_mfs_process (sar_t *ctx, mfs_rx_t * mfs,
- sar_reassembly_ctx_t *rea_ctx);
+sar_rx_mfs_process (sar_t *ctx, mfs_rx_t * mfs);
END_DECLS
diff --git a/cesar/mac/sar/inc/sar_context.h b/cesar/mac/sar/inc/sar_context.h
index ea6f9d5599..eb8997304c 100644
--- a/cesar/mac/sar/inc/sar_context.h
+++ b/cesar/mac/sar/inc/sar_context.h
@@ -19,6 +19,7 @@
#include "lib/rnd.h"
#include "lib/seq_check.h"
#include "hal/phy/bridgedma.h"
+#include "bufmgr/bufmgr.h"
#ifdef STATION_H_
#include "hal/phy/forward.h"
@@ -58,29 +59,11 @@ struct sar_msdu_t
u8 *buffer_address;
/** the associated MFS */
mfs_tx_t *mfs;
- /** User data. */
- void *user_data;
/** Arrival time in NTB. */
u32 arrival_ntb;
};
typedef struct sar_msdu_t sar_msdu_t;
-struct sar_buffer_t
-{
- /** Next pointer. */
- struct sar_buffer_t *next;
-};
-typedef struct sar_buffer_t sar_buffer_t;
-
-struct sar_buffer_list_t
-{
- /** List head. */
- sar_buffer_t *head;
- /** List tail. */
- sar_buffer_t *tail;
-};
-typedef struct sar_buffer_list_t sar_buffer_list_t;
-
struct sar_bridgedma_pending_list_t
{
/* list head. */
@@ -92,16 +75,17 @@ typedef struct sar_bridgedma_pending_list_t sar_bridgedma_pending_list_t;
struct sar_reassembly_ctx_t
{
- /** SAR reassembly done callback function. */
- sar_reassembly_done_cb_t sar_rea_done;
+ /** SAR reassembly callback DATA function. */
+ sar_reassembly_cb_t data_cb;
+ /** SAR reassembly callback MME function. */
+ sar_reassembly_cb_t mme_cb;
+ /** SAR reassembly user data callback. */
+ void *user_data;
/** SAR job pending list. */
sar_bridgedma_pending_list_t jobs_pending_list;
- /** SAR buffer list containing reassembly buffers. */
- sar_buffer_list_t buffer_list;
};
typedef struct sar_reassembly_ctx_t sar_reassembly_ctx_t;
-#if CONFIG_STATS
/**
* Statistics gathered by the SAR module.
*/
@@ -118,7 +102,6 @@ struct sar_stats_t
u32 pb_pool_not_filled;
};
typedef struct sar_stats_t sar_stats_t;
-#endif
struct sar_pb_stats_t
{
@@ -142,25 +125,12 @@ struct sar_t
mac_store_t *mac_store;
/** Channel access. */
ca_t *ca;
- /** inform the upper layer when a job had been bridged
- * Initialized in sar_segmentation_init_mme_cb */
- sar_segmentation_done_cb_t sar_seg_data_done_cb;
-
- /** inform the upper layer when a job had been bridged
- * Initialized in sar_segmentation_init_data_cb*/
- sar_segmentation_done_cb_t sar_seg_msg_done_cb;
-
/** Call back pointer for measurement data
* Data initialized in the sar_init_measurement_cb */
sar_measurement_cb_t sar_measurement;
- /** SAR context for the DATA reassembly
- * sar_init_reassembly_data_cb */
- sar_reassembly_ctx_t data_ctx;
-
- /** SAR context for the MME reassembly
- * sar_init_reassembly_mme_cb */
- sar_reassembly_ctx_t mme_ctx;
+ /** SAR context for reassembly */
+ sar_reassembly_ctx_t reassembly;
/** beacon function call back */
void *beacon_user_data;
@@ -186,15 +156,12 @@ struct sar_t
/** Pb proc call back to provide pbs */
pbproc_t *pbproc_ctx;
+ /** Buffer manager. */
+ bufmgr_t *bufmgr;
+
/** Channel estimation ctx */
void *ul_ce_ctx;
- /** data context */
- void *ul_data_ctx;
-
- /** message context */
- void *ul_msg_ctx;
-
/** Tracing system */
#if CONFIG_TRACE
/** SAR Trace */
diff --git a/cesar/mac/sar/inc/sar_job_mfs.h b/cesar/mac/sar/inc/sar_job_mfs.h
index 83e5fa0389..75a9a2b375 100644
--- a/cesar/mac/sar/inc/sar_job_mfs.h
+++ b/cesar/mac/sar/inc/sar_job_mfs.h
@@ -33,8 +33,6 @@ struct sar_job_mfs_t
u32 pb_quantity;
/** Last PB taken. */
bool pb_last_taken;
- /** User data to give back on TX message. */
- void *user_data;
};
typedef struct sar_job_mfs_t sar_job_mfs_t;
diff --git a/cesar/mac/sar/sar.h b/cesar/mac/sar/sar.h
index 6939f84b76..65cb462e70 100644
--- a/cesar/mac/sar/sar.h
+++ b/cesar/mac/sar/sar.h
@@ -19,6 +19,7 @@
#include "mac/pbproc/pbproc.h"
#include "mac/sar/sar_mfs_expiration_cb.h"
#include "mac/sar/sar_mf.h"
+#include "bufmgr/bufmgr.h"
/* forward declaration */
typedef struct sar_t sar_t;
@@ -41,33 +42,16 @@ typedef void
u32 ber_sum);
/**
- * Segmentation job done for the segmentation module, it send a data to inform
- * the upper layer that a job had been processed.
- *
- * \param user upper layer context
- * \param buffer the buffer which is no more used.
- * \param user_data data provided by the upper layer on the MSDU add.
- *
- * The MFS reference is given to the CL it do not make a addref on it.
+ * Provide a new frame to the upper layer.
+ * \param user_data the data store by the init callback
+ * \param buffer the buffer containing the new frame.
+ * \param length the message length in the buffer.
+ * \param mfs the MFS used to reassembly.
+ * \param encrypted encryption information on the medium.
*/
typedef void
-(*sar_segmentation_done_cb_t) (void *user, u8* buffer, void *user_data);
-
-/**
- * Inform the upper layer that the buffer given in parameter is not used anymore.
- *
- * \param user upper layer context pointer
- * \param buffer the buffer which is no more used.
- * \param length the length of the buffer.
- * \param mfs the MFS used to reassembly the packet.
- * \param encrypted true if the MF has been encrypted, false otherwise. This
- * is only valid for the MME, the DATA are dropped if it is not encrypted.
- *
- * The MFS reference is given to the CL it do not make a addref on it.
- */
-typedef void
-(*sar_reassembly_done_cb_t) (void *user, u8* buffer,
- uint length, mfs_rx_t *mfs, bool encrypted);
+(*sar_reassembly_cb_t) (
+ void *user, u8* buffer, uint length, mfs_rx_t *mfs, bool encrypted);
/**
* Provides the beacon to the Control Plane
@@ -87,10 +71,12 @@ BEGIN_DECLS
* \param mac_store the mac store
* \param pbproc the PBProc context.
* \param ca the Channel Access context.
+ * \param bufmgr the buffer manager context.
* \return the SAR context.
*/
sar_t *
-sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed);
+sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca,
+ bufmgr_t *bufmgr, u32 seed);
/**
* Release all the data used in the sar.
@@ -100,26 +86,6 @@ void
sar_uninit (sar_t *ctx);
/**
- * Initialise the SAR callback for DATA reception.
- * \param ctx the SAR context
- * \param user the upper layer data context.
- *
- * This should be called once the reassembly process has been done.
- */
-void
-sar_init_data_context (sar_t *ctx, void *user);
-
-/**
- * Initialise the SAR callback for MME reception.
- * \param ctx the SAR context
- * \param user the upper layer MSG context.
- *
- * This should be called once the reassembly process has been done.
- */
-void
-sar_init_mme_context (sar_t *ctx, void *user);
-
-/**
* Initialise the SAR callback for Measure reception.
* \param ctx the SAR context
* \param user the upper layer MSG context.
@@ -132,34 +98,6 @@ void
sar_init_measure_context (sar_t *ctx, void *user);
/**
- * Initialise the SAR with the function to call to inform when the MME is
- * provided to the PB Processing layer.
- * \param ctx the SAR context
- * \param sar_seg_done the function to call.
- *
- * When the callback is called the MME is still not sent by the PBProc but
- * only provided to it. The PBProc has for job to sent it when it have the
- * possibility on the medium.
- */
-void
-sar_init_segmentation_mme_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_mme_seg_done);
-
-/**
- * Initialise the SAR with the function to call to inform when the DATA is
- * provided to the PB Processing layer.
- * \param ctx the SAR context
- * \param sar_seg_done the function to call.
- *
- * When the callback is called the DATA is still not sent by the PBProc but
- * only provided to it. The PBProc has for job to sent it when it have the
- * possibility on the medium.
- */
-void
-sar_init_segmentation_data_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_data_seg_done);
-
-/**
* Initialize the callback to send the measurement contained in the PBs.
* \param ctx the SAR context
* \param sar_measurement the function to call.
@@ -169,73 +107,16 @@ sar_init_measurement_cb (sar_t *ctx,
sar_measurement_cb_t sar_measurement);
/**
- * Add a buffer address to the SAR to bridge pending jobs.
- * \param ctx the SAR context to add a buffer
- * \param buffer_addr the buffer address to add to the SAR in order to bridge
- * the pending jobs.
- * \param data if it is a data buffer.
- */
-void
-sar_buffer_add (sar_t *ctx, u8* buffer_addr, bool data);
-
-/**
- * Add a buffer address to the SAR to bridge pending jobs.
- * \param ctx the SAR context to add a buffer
- * \param buffer_addr the buffer address to add to the SAR in order to bridge
- * the pending jobs.
- */
-extern inline void
-sar_data_buffer_add (sar_t *ctx, u8* buffer_addr)
-{
- sar_buffer_add (ctx, buffer_addr, true);
-}
-
-/**
- * Add a buffer address to the SAR to bridge pending jobs.
- * \param ctx the SAR context to add a buffer
- * \param buffer_addr the buffer address to add to the SAR in order to bridge
- * the pending jobs.
- */
-extern inline void
-sar_mme_buffer_add (sar_t *ctx, u8* buffer_addr)
-{
- sar_buffer_add (ctx, buffer_addr, false);
-}
-
-/**
* Initialise the SAR to call the function on each new frame available.
* \param ctx the SAR context
- * \param sar_rea_done function to call.
- * \param data a boolean to indicate if it is a DATA stream or MME.
+ * \param data_cb callback for DATA.
+ * \param mme_cb callback for MME.
+ * \param user_data a user data provided with the callbacks.
*/
void
-sar_init_reassembly_ul (sar_t *ctx,
- sar_reassembly_done_cb_t sar_rea_done,
- bool data);
-
-/**
- * Initialise the SAR to call the function on each new MME available.
- * \param ctx the SAR context
- * \param sar_mme_reassembly_done function to call.
- */
-extern inline void
-sar_init_reassembly_mme_cb (sar_t *ctx,
- sar_reassembly_done_cb_t sar_mme_reassembly_done)
-{
- sar_init_reassembly_ul (ctx, sar_mme_reassembly_done, false);
-}
-
-/**
- * Initialise the SAR to call the function on each new DATA available.
- * \param ctx the SAR context
- * \param sar_data_reassembly_done function to call.
- */
-extern inline void
-sar_init_reassembly_data_cb (sar_t *ctx,
- sar_reassembly_done_cb_t sar_data_reassembly_done)
-{
- sar_init_reassembly_ul (ctx, sar_data_reassembly_done, true);
-}
+sar_init_reassembly_callbacks (
+ sar_t *ctx, sar_reassembly_cb_t data_cb,
+ sar_reassembly_cb_t mme_cb, void *user_data);
/**
* Add a received MPDU RX to be processed.
@@ -253,15 +134,13 @@ sar_mpdu_add (void *user, pbproc_rx_desc_t *rx_desc);
* \param buffer the buffer containing the Mac Frame.
* \param length the length of the Mac Frame.
* \param mfs the MFS to stock the PB generated
- * \param user_data opaque object.
* \param arrival_time_ntb the arrival time of the MSDU in the station.
*
* user_data is an opaque object given back once the segmentation is done.
*/
void
sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length,
- mfs_tx_t *mfs, void *user_data,
- u32 arrival_time_ntb);
+ mfs_tx_t *mfs, u32 arrival_time_ntb);
/**
* Add an MFS to the SAR expiration mechanism.
diff --git a/cesar/mac/sar/src/sar.c b/cesar/mac/sar/src/sar.c
index 2712444a98..7a5986b0ee 100644
--- a/cesar/mac/sar/src/sar.c
+++ b/cesar/mac/sar/src/sar.c
@@ -487,8 +487,33 @@ sar_job_mfs_fill (sar_job_mfs_t *job, bool tx)
job->pb_last_taken = false;
}
+/**
+ * Callback called by buffer manager when new buffers are available.
+ * \param ctx SAR context
+ *
+ * This function does not need to lock DSR because it is only called in the
+ * buffer manager DSR context.
+ */
+PRIVATE void
+sar_buffer_available (sar_t *ctx)
+{
+ if (ctx->activate)
+ {
+ /* If there is RX pending JOB provide the head to the bridge DMA. */
+ sar_rx_upper_layer_transmit_data (ctx);
+ phy_bridgedma_stopped (ctx->bridgedma_ctx);
+ sar_bridge_dma_free_head (ctx);
+ }
+ if (ctx->pbs_missing_for_pbproc)
+ {
+ /* Refill the PB pool if missing block were registered. */
+ sar_pb_pool_refill (ctx, 0);
+ }
+}
+
sar_t *
-sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed)
+sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca,
+ bufmgr_t *bufmgr, u32 seed)
{
sar_t *ctx;
dbg_assert (mac_store);
@@ -497,9 +522,12 @@ sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed)
memset (&sar_global, 0, sizeof (sar_t));
sar_global.ca = ca;
sar_global.mac_store = mac_store;
+ /* Buffer manager. */
+ sar_global.bufmgr = bufmgr;
+ bufmgr_client_register (
+ bufmgr, (bufmgr_callback_t) sar_buffer_available, &sar_global);
/* reassembly */
- sar_reassembly_init (&sar_global.data_ctx);
- sar_reassembly_init (&sar_global.mme_ctx);
+ sar_reassembly_init (&sar_global.reassembly);
/* pbproc */
sar_global.pbproc_ctx = pbproc;
pbproc_init_cb (pbproc, &sar_global, sar_mpdu_add, sar_beacon_add);
@@ -535,51 +563,14 @@ sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed)
return &sar_global;
}
-/**
- * Call uper layer to give back the buffer and MFS.
- * \param ctx the sar context.
- * \param buffer the buffer containing the frame.
- * \param mfs the MFS to used.
- * \param user_data opaque object to give back to the upper layer.
- */
-static inline void
-sar_tx_done (sar_t *ctx, u8 *buffer, mfs_tx_t *mfs, void *user_data)
-{
- dbg_assert (ctx);
- dbg_assert (buffer);
-
- if (mfs->common.mme)
- ctx->sar_seg_msg_done_cb (ctx->ul_msg_ctx, buffer,
- user_data);
- else
- ctx->sar_seg_data_done_cb (ctx->ul_data_ctx, buffer,
- user_data);
-}
-
void
sar_reassembly_init (sar_reassembly_ctx_t *ctx)
{
dbg_assert (ctx);
-
- ctx->sar_rea_done = NULL;
+ ctx->data_cb = NULL;
+ ctx->mme_cb = NULL;
+ ctx->user_data = NULL;
slist_init (ctx->jobs_pending_list., bare);
- slist_init (ctx->buffer_list., bare);
-}
-
-void
-sar_init_data_context (sar_t *ctx, void *user)
-{
- dbg_assert (ctx);
-
- ctx->ul_data_ctx = user;
-}
-
-void
-sar_init_mme_context (sar_t *ctx, void *user)
-{
- dbg_assert (ctx);
-
- ctx->ul_msg_ctx = user;
}
void
@@ -591,39 +582,16 @@ sar_init_measure_context (sar_t *ctx, void *user)
}
void
-sar_init_segmentation_mme_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_seg_done)
+sar_init_reassembly_callbacks (
+ sar_t *ctx, sar_reassembly_cb_t data_cb,
+ sar_reassembly_cb_t mme_cb, void *user_data)
{
dbg_assert (ctx);
-
- ctx->sar_seg_msg_done_cb = sar_seg_done;
-}
-
-void
-sar_init_segmentation_data_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_seg_done)
-{
- dbg_assert (ctx);
-
- ctx->sar_seg_data_done_cb = sar_seg_done;
-}
-
-void
-sar_init_reassembly_ul (sar_t *ctx,
- sar_reassembly_done_cb_t sar_rea_done, bool data)
-{
- dbg_assert (ctx);
-
- if (data)
- {
- dbg_assert (ctx->ul_data_ctx);
- ctx->data_ctx.sar_rea_done = sar_rea_done;
- }
- else
- {
- dbg_assert (ctx->ul_msg_ctx);
- ctx->mme_ctx.sar_rea_done = sar_rea_done;
- }
+ dbg_assert (data_cb);
+ dbg_assert (mme_cb);
+ ctx->reassembly.user_data = user_data;
+ ctx->reassembly.data_cb = data_cb;
+ ctx->reassembly.mme_cb = mme_cb;
}
void
@@ -675,32 +643,6 @@ sar_mpdu_release_content (sar_t *ctx, sar_mpdu_t *mpdu)
}
void
-sar_buffer_add (sar_t *ctx, u8* buffer_addr, bool data)
-{
- sar_reassembly_ctx_t *rea_ctx;
- if (data)
- rea_ctx = &ctx->data_ctx;
- else
- rea_ctx = &ctx->mme_ctx;
-
- /* Lock DSR because this function can be called in DSR or task context. */
- arch_dsr_lock ();
- slist_push_back (rea_ctx->buffer_list., (sar_buffer_t*) buffer_addr,
- bare);
- if (ctx->activate)
- {
- /* If there is RX pending JOB provide the head to the bridge DMA. */
- sar_rx_upper_layer_transmit_data (ctx, rea_ctx);
- phy_bridgedma_stopped (ctx->bridgedma_ctx);
- sar_bridge_dma_free_head (ctx);
- }
- if (ctx->pbs_missing_for_pbproc)
- /* Refill the PB pool if missing block were registered. */
- sar_pb_pool_refill (ctx, 0);
- arch_dsr_unlock ();
-}
-
-void
sar_mpdu_add (void *user, pbproc_rx_desc_t *rx_desc)
{
sar_t *ctx;
@@ -783,12 +725,11 @@ sar_msdu_add__mfs_mme_plid_in_release (sar_t *ctx, mfs_tx_t *mfs)
* \param ctx the sar context.
* \param buffer the buffer containing the frame.
* \param mfs the MFS to use.
- * \param user_data opaque object to give back to the upper layer.
* \param arrival_time_ntb the arrival NTB date.
*/
inline void
sar_msdu_add__send_frame (sar_t *ctx, u8 *buffer, u16 length, mfs_tx_t *mfs,
- void *user_data, u32 arrival_time_ntb)
+ u32 arrival_time_ntb)
{
sar_msdu_t msdu;
@@ -800,7 +741,6 @@ sar_msdu_add__send_frame (sar_t *ctx, u8 *buffer, u16 length, mfs_tx_t *mfs,
msdu.length = length;
msdu.mfs = mfs;
msdu.buffer_address = buffer;
- msdu.user_data = user_data;
msdu.arrival_ntb = arrival_time_ntb;
SAR_TRACE (TX, phy_date (), buffer, length, mfs->common.tei,
mfs->common.lid, arrival_time_ntb);
@@ -819,13 +759,13 @@ sar_msdu_add__send_frame (sar_t *ctx, u8 *buffer, u16 length, mfs_tx_t *mfs,
void
sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length, mfs_tx_t *mfs,
- void *user_data, u32 arrival_time_ntb)
+ u32 arrival_time_ntb)
{
- dbg_assert (ctx);
- dbg_assert (mfs);
- dbg_assert (mfs->common.tx);
- dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
- && (length <= ETH_PACKET_MAX_SIZE));
+ dbg_claim (ctx);
+ dbg_claim (mfs);
+ dbg_claim (mfs->common.tx);
+ dbg_claim (length >= ETH_PACKET_MIN_SIZE_ALLOWED
+ && length <= ETH_PACKET_MAX_SIZE);
/* Link statistics. */
mfs->stats.num_msdus ++;
@@ -845,18 +785,16 @@ sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length, mfs_tx_t *mfs,
else
{
SAR_TRACE (MSDU_DROPPED_MFS_RELEASE, buffer, mfs);
- sar_tx_done (ctx, buffer, mfs, user_data);
return;
}
}
sar_msdu_add__send_frame (ctx, buffer, length, mfs,
- user_data, arrival_time_ntb);
+ arrival_time_ntb);
}
else
{
SAR_TRACE (MSDU_DROPPED, buffer);
- sar_tx_done (ctx, buffer, mfs, user_data);
}
}
@@ -910,12 +848,10 @@ static void
sar_bridge_dma_free_head_rx (sar_t *ctx, sar_job_mfs_t *job)
{
bool sta_auth, encrypted;
- sar_reassembly_done_cb_t sar_rea_done;
- void *ul_ctx;
sta_t *sta;
- dbg_assert (ctx);
- dbg_assert (job);
+ dbg_claim (ctx);
+ dbg_claim (job);
#if CONFIG_SAR_BRG_JOB_ERROR
dbg_assert (job->job.mf_header1 != 0xdeaddead);
@@ -949,9 +885,9 @@ sar_bridge_dma_free_head_rx (sar_t *ctx, sar_job_mfs_t *job)
sta_auth |= pb->header.spc_encrypted;
}
}
-
- sar_rea_done = ctx->mme_ctx.sar_rea_done;
- ul_ctx = ctx->ul_msg_ctx;
+ ctx->reassembly.mme_cb (
+ ctx->reassembly.user_data, job->job.data_addr,
+ job->job.data_len, &job->mfs->rx, encrypted);
}
else
{
@@ -959,14 +895,10 @@ sar_bridge_dma_free_head_rx (sar_t *ctx, sar_job_mfs_t *job)
* already been dropped in the rx_mpdu_process function. */
encrypted = true;
sta_auth = true;
-
- sar_rea_done = ctx->data_ctx.sar_rea_done;
- ul_ctx = ctx->ul_data_ctx;
+ ctx->reassembly.data_cb (
+ ctx->reassembly.user_data, job->job.data_addr,
+ job->job.data_len, &job->mfs->rx, encrypted);
}
- dbg_assert (sar_rea_done);
- (*sar_rea_done) (ul_ctx, job->job.data_addr, job->job.data_len,
- (mfs_rx_t *) job->mfs, encrypted);
-
SAR_TRACE (BRIDGE_RX,
((pb_t*) job->job.first_pb_desc)->header.ssn,
job->job.first_pb_offset,
@@ -986,11 +918,8 @@ sar_bridge_dma_free_head_rx (sar_t *ctx, sar_job_mfs_t *job)
}
else
{
- /* Link stats. */
job->mfs->rx.stats.num_icv_fails ++;
- /* Keep the buffer for another reassembly. */
- sar_buffer_add (ctx, job->job.data_addr,
- !((mfs_rx_t *) job->mfs)->common.mme);
+ bufmgr_keep_buffer (ctx->bufmgr, job->job.data_addr);
}
/* Release the PBs in the job. */
@@ -1007,8 +936,8 @@ static void
sar_bridge_dma_free_head_tx (sar_t *ctx, sar_job_mfs_t *job)
{
mfs_tx_t *local_mfs;
- dbg_assert (ctx);
- dbg_assert (job);
+ dbg_claim (ctx);
+ dbg_claim (job);
local_mfs = &job->mfs->tx;
uint pb_quantity = job->pb_quantity;
@@ -1033,7 +962,6 @@ sar_bridge_dma_free_head_tx (sar_t *ctx, sar_job_mfs_t *job)
pbproc_mfs_provide (&job->mfs->tx, pb_quantity);
if (job->mfs->tx.fsm_state != MFS_FSM_CMD_RELEASE)
ca_mfs_update (ctx->ca, &job->mfs->tx);
- sar_tx_done (ctx, job->job.data_addr, &job->mfs->tx, job->user_data);
}
/**
@@ -1046,25 +974,11 @@ sar_bridge_dma_free_header_not_activate (sar_t *ctx, sar_job_mfs_t *job)
{
dbg_assert (ctx);
dbg_assert (job);
-
/* Release the PBs in the job. */
blk_release_desc_range_nb ((blk_t *) job->job.first_pb_desc,
job->pb_quantity);
-
- if (job->mfs->common.tx)
- {
- /* If TX give back the buffer. Data addr pointer can stay in a unknown
- * state, on each TX this pointer is correctly intialised. */
- if (job->job.data_addr)
- sar_tx_done (ctx, job->job.data_addr, &job->mfs->tx,
- job->user_data);
- }
- else
- {
- /* Keep the reassembly buffer. */
- if (job->job.data_addr)
- sar_buffer_add (ctx, job->job.data_addr, !job->mfs->common.mme);
- }
+ if (job->job.direction && job->job.data_addr)
+ bufmgr_keep_buffer (ctx->bufmgr, job->job.data_addr);
}
void
@@ -1072,7 +986,7 @@ sar_bridge_dma_free_head (sar_t *ctx)
{
sar_job_mfs_t *job;
sar_job_mfs_t *jobs;
- dbg_assert (ctx);
+ dbg_claim (ctx);
/* Get the ended list of jobs from the bridge DMA. */
jobs =
PARENT_OF_OR_NULL (
@@ -1121,8 +1035,7 @@ sar_pb_pool_refill (sar_t *ctx, uint pb_nb)
pb_t *tail = NULL;
blk_t *blk_tail;
- dbg_assert (ctx);
- dbg_assert (ctx->pbproc_ctx);
+ dbg_claim (ctx);
pb_nb += ctx->pbs_missing_for_pbproc;
if (pb_nb)
{
@@ -1135,8 +1048,10 @@ sar_pb_pool_refill (sar_t *ctx, uint pb_nb)
tail = (pb_t*) blk_tail;
pbproc_rx_segment_refill (ctx->pbproc_ctx, head, tail, allocate);
}
+#if CONFIG_STATS
else
ctx->stats.pb_pool_not_filled++;
+#endif
}
}
@@ -1144,18 +1059,12 @@ sar_pb_pool_refill (sar_t *ctx, uint pb_nb)
* Try to extract MF from the PBs present in the MFS.
* \param ctx the SAR context.
* \param mfs the MFS to use.
- * \param opsf_ssn The ssn of the oldest pending PB received.
*/
void
-sar_mac_frame_reconstitute (sar_t *ctx, mfs_rx_t *mfs,
- sar_reassembly_ctx_t *rea_ctx)
+sar_mac_frame_reconstitute (sar_t *ctx, mfs_rx_t *mfs)
{
- dbg_assert (ctx);
- dbg_assert (mfs);
- dbg_assert (rea_ctx);
-
sar_rx_mfs_ssn_min_update (ctx, mfs);
- sar_rx_mfs_process (ctx, mfs, rea_ctx);
+ sar_rx_mfs_process (ctx, mfs);
blk_release (mfs);
}
@@ -1189,14 +1098,13 @@ sar_reassembly_run (sar_t *ctx, sar_mpdu_t *rx)
if (rx->rx.mfs)
{
sar_expiration_mfs_update_ntb (ctx, rx->rx.mfs, rx->arrival_ntb);
- sar_mac_frame_reconstitute (ctx, &rx->rx.mfs->rx, &ctx->data_ctx);
+ sar_mac_frame_reconstitute (ctx, &rx->rx.mfs->rx);
}
if (rx->rx.mfs_mme)
{
sar_expiration_mfs_update_ntb (ctx, rx->rx.mfs_mme,
rx->arrival_ntb);
- sar_mac_frame_reconstitute (ctx, &rx->rx.mfs_mme->rx,
- &ctx->mme_ctx);
+ sar_mac_frame_reconstitute (ctx, &rx->rx.mfs_mme->rx);
}
}
}
@@ -1717,59 +1625,73 @@ sar_rx_mfs_detect_and_reconstitute_mf (sar_t *ctx, mfs_rx_t *mfs)
return job;
}
+/**
+ * Queue jobs in the pending list.
+ * \param ctx the module context.
+ * \param jobs the jobs to queue.
+ */
+static inline void
+sar_rx_mfs_process__queue_jobs (sar_t *ctx, sar_job_mfs_t *jobs)
+{
+ if (jobs->next)
+ slist_push_back_range (ctx->reassembly.jobs_pending_list., jobs,
+ jobs->next, bare);
+ else
+ slist_push_back (ctx->reassembly.jobs_pending_list., jobs, bare);
+}
+
void
-sar_rx_mfs_process (sar_t *ctx, mfs_rx_t * mfs, sar_reassembly_ctx_t *rea_ctx)
+sar_rx_mfs_process (sar_t *ctx, mfs_rx_t * mfs)
{
sar_job_mfs_t *job;
dbg_assert (mfs);
- dbg_assert (rea_ctx);
-
- while ((job = sar_rx_mfs_detect_and_reconstitute_mf (ctx, mfs)))
+ /* No pending jobs. */
+ if (slist_empty (ctx->reassembly.jobs_pending_list., bare))
{
- if (!slist_empty (rea_ctx->buffer_list., bare))
+ while ((job = sar_rx_mfs_detect_and_reconstitute_mf (ctx, mfs)))
{
- u8 *buffer =
- (u8*) slist_pop_front (rea_ctx->buffer_list., bare);
- job->job.data_addr = buffer;
- /* Workaround for maria bug #905 */
- if (job->job.next)
+ u8 *buffer = bufmgr_get (ctx->bufmgr);
+ if (buffer)
{
- job->job.next->data_addr = buffer + job->job.data_len;
- phy_bridgedma_start (
- ctx->bridgedma_ctx, &job->job, job->job.next);
+ job->job.data_addr = buffer;
+ /* Workaround for maria bug #905 */
+ if (job->job.next)
+ {
+ job->job.next->data_addr = buffer + job->job.data_len;
+ phy_bridgedma_start (
+ ctx->bridgedma_ctx, &job->job, job->job.next);
+ }
+ else
+ phy_bridgedma_start (
+ ctx->bridgedma_ctx, &job->job, &job->job);
}
else
- phy_bridgedma_start (
- ctx->bridgedma_ctx, &job->job, &job->job);
- }
- else
- {
- if (job->next)
- slist_push_back_range (rea_ctx->jobs_pending_list., job,
- job->next, bare);
- else
- slist_push_back (rea_ctx->jobs_pending_list., job, bare);
+ {
+ /* No more buffers available. */
+ sar_rx_mfs_process__queue_jobs (ctx, job);
+ break;
+ }
}
}
+ /* No more buffer available. */
+ while ((job = sar_rx_mfs_detect_and_reconstitute_mf (ctx, mfs)))
+ sar_rx_mfs_process__queue_jobs (ctx, job);
}
void
-sar_rx_upper_layer_transmit_data (sar_t *sar_ctx, sar_reassembly_ctx_t *ctx)
+sar_rx_upper_layer_transmit_data (sar_t *ctx)
{
sar_job_mfs_t *job_head = NULL;
sar_job_mfs_t *job_tail = NULL;
sar_job_mfs_t *job_current;
u8 *buffer;
- dbg_assert (sar_ctx);
dbg_assert (ctx);
-
/* Get the head of the list. */
- job_current = ctx->jobs_pending_list.head;
- while (job_current && !slist_empty(ctx->buffer_list., bare))
+ job_current = ctx->reassembly.jobs_pending_list.head;
+ while (job_current && (buffer = bufmgr_get (ctx->bufmgr)))
{
if (job_head == NULL)
job_head = job_current;
- buffer = (u8*) slist_pop_front (ctx->buffer_list., bare);
job_current->job.data_addr = buffer;
/* Work around maria:#905 */
if (job_current->job.crc_store == false)
@@ -1782,15 +1704,14 @@ sar_rx_upper_layer_transmit_data (sar_t *sar_ctx, sar_reassembly_ctx_t *ctx)
job_tail = job_current;
job_current = job_current->next;
}
-
/* No more buffers available or no more job to unchain. */
if (job_head)
{
/* Unchain the jobs from the list. */
- slist_slice (ctx->jobs_pending_list., job_tail, bare);
+ slist_slice (ctx->reassembly.jobs_pending_list., job_tail, bare);
job_tail->next = NULL;
/* Provide the jobs to the bridgedma list. */
- phy_bridgedma_start (sar_ctx->bridgedma_ctx, &job_head->job,
+ phy_bridgedma_start (ctx->bridgedma_ctx, &job_head->job,
&job_tail->job);
}
}
@@ -1806,7 +1727,6 @@ sar_tx_mac_framing (sar_t *ctx, sar_msdu_t *md_data)
&& (md_data->length <= ETH_PACKET_MAX_SIZE));
/* initialise the job descriptor. */
ctx->job_tx->mfs = (mfs_t *) md_data->mfs;
- ctx->job_tx->user_data = md_data->user_data;
ctx->job_tx->pb_last_taken = false;
/* Take the last PB from the MFS if possible. */
if ((ctx->job_tx->job.first_pb_desc =
@@ -2046,20 +1966,19 @@ sar_cleanup__mfs_remove (mac_store_t *mac_store, mfs_t *mfs, void *ctx)
/**
* Release the pending jobs present in the list.
* \param ctx the SAR context.
- * \param rctx the reassembly context to process.
*/
static inline void
-sar_cleanup_pending_jobs (sar_t *ctx, sar_reassembly_ctx_t *rctx)
+sar_cleanup_pending_jobs (sar_t *ctx)
{
sar_job_mfs_t *job;
- while (!slist_empty (rctx->jobs_pending_list., bare))
+ while (!slist_empty (ctx->reassembly.jobs_pending_list., bare))
{
- job = slist_pop_front (rctx->jobs_pending_list., bare);
+ job = slist_pop_front (ctx->reassembly.jobs_pending_list., bare);
/* BUG Maria:#905, for the second job, there is nothing to do. */
if (job->job.direction && job->job.crc_store == false)
{
sar_job_mfs_t *j_next =
- slist_pop_front (rctx->jobs_pending_list., bare);
+ slist_pop_front (ctx->reassembly.jobs_pending_list., bare);
blk_release (j_next);
}
sar_bridge_dma_free_header_not_activate (ctx, job);
@@ -2079,15 +1998,12 @@ sar_cleanup (sar_t *ctx)
{
uint i;
dbg_assert (ctx);
- sar_cleanup_pending_jobs (ctx, &ctx->data_ctx);
- sar_cleanup_pending_jobs (ctx, &ctx->mme_ctx);
+ sar_cleanup_pending_jobs (ctx);
/* Remove all the stations from the store. */
for (i = MAC_TEI_STA_MIN; i <= MAC_TEI_STA_MAX; i++)
sar_sta_remove (ctx, i);
/* Remove the others MFS. */
- mac_store_mfs_travel (ctx->mac_store,
- sar_cleanup__mfs_remove,
- ctx);
+ mac_store_mfs_travel (ctx->mac_store, sar_cleanup__mfs_remove, ctx);
}
void
diff --git a/cesar/mac/sar/src/sar_expiration.c b/cesar/mac/sar/src/sar_expiration.c
index 744f4e88b8..b6ff95eb2e 100644
--- a/cesar/mac/sar/src/sar_expiration.c
+++ b/cesar/mac/sar/src/sar_expiration.c
@@ -40,8 +40,8 @@
void
sar_expiration_mfs_update_ntb (sar_t *ctx, mfs_t *mfs, u32 arrival_ntb)
{
- dbg_assert (ctx);
- dbg_assert (mfs);
+ dbg_claim (ctx);
+ dbg_claim (mfs);
if (mfs->common.tx)
mfs->common.expiration_ntb = arrival_ntb
+ MAC_MS_TO_TCK (MFS_TX_ACTIVITY_DELAY_MS);
diff --git a/cesar/mac/sar/stub/src/sar.c b/cesar/mac/sar/stub/src/sar.c
index 49112f34ec..b63652b27c 100644
--- a/cesar/mac/sar/stub/src/sar.c
+++ b/cesar/mac/sar/stub/src/sar.c
@@ -17,46 +17,25 @@
#include "mac/sar/sar_pb_stats.h"
sar_t *
-sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed) __attribute__((weak));
+sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca,
+ bufmgr_t *bufmgr, u32 seed) __attribute__((weak));
void
sar_uninit (sar_t *ctx) __attribute__((weak));
void
-sar_init_data_context (sar_t *ctx, void *user) __attribute__((weak));
-
-void
-sar_init_mme_context (sar_t *ctx, void *user) __attribute__((weak));
-
-void
sar_init_measure_context (sar_t *ctx, void *user) __attribute__((weak));
void
-sar_init_segmentation_mme_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_mme_seg_done) __attribute__((weak));
-
-void
-sar_init_segmentation_data_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_data_seg_done) __attribute__((weak));
-
-void
sar_init_measurement_cb (sar_t *ctx,
sar_measurement_cb_t sar_measurement) __attribute__((weak));
void
-sar_buffer_add (sar_t *ctx, u8* buffer_addr, bool data) __attribute__((weak));
-
-void
-sar_init_reassembly_ul (sar_t *ctx,
- sar_reassembly_done_cb_t sar_rea_done,
- bool data) __attribute__((weak));
-
-void
sar_mpdu_add (void *user, pbproc_rx_desc_t *rx_desc) __attribute__((weak));
void
sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length,
- mfs_tx_t *mfs, void *user_data, u32 av_time) __attribute__((weak));
+ mfs_tx_t *mfs, u32 arrival_time_ntb) __attribute__((weak));
void
sar_mfs_add (sar_t *ctx, mfs_t *mfs) __attribute__((weak));
@@ -79,14 +58,6 @@ void
sar_sta_remove (sar_t *ctx, u8 tei) __attribute__((weak));
-void
-sar_mme_buffer_add (sar_t *ctx, u8* buffer_addr) __attribute__((weak));
-
-
-void
-sar_data_buffer_add (sar_t *ctx, u8* buffer_addr) __attribute__((weak));
-
-
void sar_mfs_add (sar_t *ctx, mfs_t *mfs) __attribute__((weak));
void
@@ -104,7 +75,8 @@ void
sar_read_pb_stats_end (sar_t *ctx) __attribute__((weak));
sar_t *
-sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed)
+sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca,
+ bufmgr_t *bufmgr, u32 seed)
{
return NULL;
}
@@ -113,40 +85,18 @@ void
sar_uninit (sar_t *ctx) {}
void
-sar_init_data_context (sar_t *ctx, void *user) {}
-
-void
-sar_init_mme_context (sar_t *ctx, void *user) {}
-
-void
sar_init_measure_context (sar_t *ctx, void *user) {}
void
-sar_init_segmentation_mme_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_mme_seg_done) {}
-
-void
-sar_init_segmentation_data_cb (sar_t *ctx,
- sar_segmentation_done_cb_t sar_data_seg_done) {}
-
-void
sar_init_measurement_cb (sar_t *ctx,
sar_measurement_cb_t sar_measurement) {}
void
-sar_buffer_add (sar_t *ctx, u8* buffer_addr, bool data){}
-
-void
-sar_init_reassembly_ul (sar_t *ctx,
- sar_reassembly_done_cb_t sar_rea_done,
- bool data) {}
-
-void
sar_mpdu_add (void *user, pbproc_rx_desc_t *rx_desc) {}
void
sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length,
- mfs_tx_t *mfs, void *user_data, u32 av_time) {}
+ mfs_tx_t *mfs, u32 arrival_time_ntb) {}
void
sar_mfs_add (sar_t *ctx, mfs_t *mfs) { }
@@ -168,13 +118,6 @@ sar_beacon_send (sar_t *sar, pb_beacon_t *beacon, mfs_tx_t *beacon_mfs,
void
sar_sta_remove (sar_t *ctx, u8 tei) {}
-
-void
-sar_mme_buffer_add (sar_t *ctx, u8* buffer_addr) {}
-
-void
-sar_data_buffer_add (sar_t *ctx, u8* buffer_addr) {}
-
void
sar_cleanup (sar_t *ctx) {}
@@ -190,3 +133,14 @@ sar_read_pb_stats_entry (sar_t *ctx, uint index)
{
return NULL;
}
+
+void
+sar_init_reassembly_callbacks (
+ sar_t *ctx, sar_reassembly_cb_t data_cb,
+ sar_reassembly_cb_t mme_cb, void *user_data) __attribute__((weak));
+
+void
+sar_init_reassembly_callbacks (
+ sar_t *ctx, sar_reassembly_cb_t data_cb,
+ sar_reassembly_cb_t mme_cb, void *user_data)
+{ }
diff --git a/cesar/mac/sar/test/functional/Makefile.mk b/cesar/mac/sar/test/functional/Makefile.mk
index 878fd59386..827134c6b5 100644
--- a/cesar/mac/sar/test/functional/Makefile.mk
+++ b/cesar/mac/sar/test/functional/Makefile.mk
@@ -2,38 +2,41 @@ TARGET_PROGRAMS = sar_rx_perf sar_rx_perf_huge_mpdu \
sar_rx_perf_huge_mpdu_1518 sar_tx_perf \
sar_tx_rx sar_rx_tx sar_tx_out_in_rx
-sar_rx_perf_SOURCES = sar_rx_perf.c pbproc_stub.c ca_stub.c test_functions.c
+sar_rx_perf_SOURCES = sar_rx_perf.c pbproc_stub.c ca_stub.c test_functions.c \
+ bufmgr_stub.c
sar_rx_perf_MODULES = hal/arch lib mac/common mac/sar mac/pbproc \
$(HOST_MODULES) $(SPARC_MODULES)
sar_rx_perf_huge_mpdu_SOURCES = sar_rx_perf_huge_mpdu.c pbproc_stub.c \
- ca_stub.c test_functions.c
+ ca_stub.c test_functions.c bufmgr_stub.c
sar_rx_perf_huge_mpdu_MODULES = hal/arch lib mac/common mac/sar \
mac/pbproc \
$(HOST_MODULES) $(SPARC_MODULES)
sar_rx_perf_huge_mpdu_1518_SOURCES = sar_rx_perf_huge_mpdu_1518.c \
- pbproc_stub.c ca_stub.c test_functions.c
+ pbproc_stub.c ca_stub.c test_functions.c \
+ bufmgr_stub.c
sar_rx_perf_huge_mpdu_1518_MODULES = hal/arch lib mac/common mac/sar \
mac/pbproc \
$(HOST_MODULES) $(SPARC_MODULES)
-sar_tx_perf_SOURCES = sar_tx_perf.c pbproc_stub.c ca_stub.c test_functions.c
+sar_tx_perf_SOURCES = sar_tx_perf.c pbproc_stub.c ca_stub.c test_functions.c \
+ bufmgr_stub.c
sar_tx_perf_MODULES = hal/arch lib mac/common mac/sar mac/pbproc \
$(HOST_MODULES) $(SPARC_MODULES)
sar_tx_rx_SOURCES = sar_tx_rx.c pbproc_stub.c ca_stub.c \
- test_functions.c
+ bufmgr_stub.c test_functions.c
sar_tx_rx_MODULES = hal/arch lib mac/common mac/sar mac/pbproc \
$(HOST_MODULES) $(SPARC_MODULES)
sar_rx_tx_SOURCES = sar_rx_tx.c pbproc_stub.c ca_stub.c \
- test_functions.c
+ bufmgr_stub.c test_functions.c
sar_rx_tx_MODULES = hal/arch lib mac/common mac/sar mac/pbproc \
$(HOST_MODULES) $(SPARC_MODULES)
sar_tx_out_in_rx_SOURCES = sar_tx_out_in_rx.c pbproc_stub.c ca_stub.c \
- test_functions.c
+ bufmgr_stub.c test_functions.c
sar_tx_out_in_rx_MODULES = hal/arch lib mac/common mac/sar mac/pbproc \
$(HOST_MODULES) $(SPARC_MODULES)
diff --git a/cesar/mac/sar/test/functional/src/bufmgr_stub.c b/cesar/mac/sar/test/functional/src/bufmgr_stub.c
new file mode 100644
index 0000000000..ec3d8da577
--- /dev/null
+++ b/cesar/mac/sar/test/functional/src/bufmgr_stub.c
@@ -0,0 +1,81 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file unit_test/ecos/src/bufmgr_stub.c
+ * \brief Buffer manager stub functions
+ * \ingroup mac_sar_test
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "common/defs/ethernet.h"
+
+#include "hal/arch/arch.h"
+
+#include "bufmgr/bufmgr.h"
+
+#include "mac/sar/test/functional/test_functions.h"
+
+#include <string.h>
+
+
+/* Variables needed by the test. */
+#ifdef __sparc__
+static u8 buffer[SAR_TEST_BUFFER_NB][2048] __attribute__ ((section(".private")));
+#else
+static u8 buffer[SAR_TEST_BUFFER_NB][2048];
+#endif
+
+u8*
+bufmgr_get (bufmgr_t *ctx)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ if (bufmgr->free_buffer_nb)
+ {
+ u8 *buffer_to_give = buffer[bufmgr->free_buffer_nb - 1];
+ bufmgr->free_buffer_nb--;
+ return ARCH_CPU_TO_UNCACHEABLE (buffer_to_give);
+ }
+ return NULL;
+}
+
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ bufmgr->free_buffer_nb++;
+ dbg_assert (bufmgr->free_buffer_nb <= SAR_TEST_BUFFER_NB);
+ bufmgr->nb_given_back++;
+}
+
+void
+bufmgr_keep_buffer (bufmgr_t *ctx, u8 *buffer)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ bufmgr->free_buffer_nb++;
+ dbg_assert (bufmgr->free_buffer_nb <= SAR_TEST_BUFFER_NB);
+ bufmgr->nb_given_back++;
+}
+
+bufmgr_t *
+bufmgr_init (ipmbox_t *ctx)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ uint i;
+ for (i = 0; i < SAR_TEST_BUFFER_NB; i++)
+ bufmgr->buffer[i] = buffer[i];
+ bufmgr->nb_given_back = 0;
+ bufmgr->free_buffer_nb = SAR_TEST_BUFFER_NB;
+ return (bufmgr_t *) ctx;
+}
+
+void
+bufmgr_client_register (bufmgr_t *ctx, bufmgr_callback_t cb, void *user_data)
+{
+}
diff --git a/cesar/mac/sar/test/functional/src/test_functions.c b/cesar/mac/sar/test/functional/src/test_functions.c
index dc44faeeff..74ccbc2916 100644
--- a/cesar/mac/sar/test/functional/src/test_functions.c
+++ b/cesar/mac/sar/test/functional/src/test_functions.c
@@ -35,18 +35,6 @@
#include "hal/phy/soft/bridgedma/bridgedma_crc.h"
#include <string.h>
-#define BUFFERS_MAX 100
-
-/* Variables needed by the test. */
-#ifdef __sparc__
-static u8 buffers[BUFFERS_MAX][2048] __attribute__ ((section(".private")));
-#else
-static u8 buffers[BUFFERS_MAX][2048];
-#endif
-
-static uint nb_frames_tx;
-static uint nb_frames_rx;
-
/* Stubbed Functions. */
void
ce_measurements (void *data, pbproc_rx_params_t *rx_params,
@@ -58,38 +46,25 @@ ce_measurements (void *data, pbproc_rx_params_t *rx_params,
}
static void
-sar_test_segmentation_done__do_nothing (void *user,
- u8* buffer,
- void *user_data)
-{
- nb_frames_tx++;
-}
-
-static void
sar_reassembly_done__do_nothing (void *user, u8* buffer, uint length,
mfs_rx_t *mfs, bool encrypted)
{
- nb_frames_rx++;
+ sar_test_ctx_t *ctx = user;
+ ctx->nb_frames_rx++;
+ bufmgr_give_back ((bufmgr_t*) &ctx->bufmgr, buffer);
}
/*-- End stubbed functions. --*/
-u8*
-sar_test_get_buffer (uint buffer_nb)
-{
- dbg_assert (buffer_nb < BUFFERS_MAX);
- return ARCH_CPU_TO_UNCACHEABLE (buffers[buffer_nb]);
-}
-
uint
-sar_test_rx_frames (void)
+sar_test_rx_frames (sar_test_ctx_t *ctx)
{
- return nb_frames_rx;
+ return ctx->nb_frames_rx;
}
uint
-sar_test_tx_frames (void)
+sar_test_tx_frames (sar_test_ctx_t *ctx)
{
- return nb_frames_tx;
+ return ctx->nb_frames_tx;
}
void
@@ -103,25 +78,21 @@ sar_test_init (sar_test_ctx_t *test_ctx)
/* Initialise the store. */
test_ctx->mac_store = mac_store_init ();
+ /* Initialise the fake buffer manager. */
+ bufmgr_init ((ipmbox_t *) &test_ctx->bufmgr);
+
/* Initialise the SAR. */
test_ctx->sar = sar_init (test_ctx->mac_store, INVALID_PTR, INVALID_PTR,
- 2);
+ (bufmgr_t *) &test_ctx->bufmgr, 2);
/* CE. */
sar_init_measure_context (test_ctx->sar, INVALID_PTR);
sar_init_measurement_cb (test_ctx->sar, ce_measurements);
- sar_init_data_context (test_ctx->sar, INVALID_PTR);
- sar_init_segmentation_data_cb (test_ctx->sar,
- sar_test_segmentation_done__do_nothing);
- sar_init_mme_context (test_ctx->sar, INVALID_PTR);
- sar_init_segmentation_mme_cb (test_ctx->sar,
- sar_test_segmentation_done__do_nothing);
- sar_init_reassembly_data_cb (test_ctx->sar,
- sar_reassembly_done__do_nothing);
- sar_init_reassembly_mme_cb (test_ctx->sar,
- sar_reassembly_done__do_nothing);
-
- nb_frames_tx = 0;
- nb_frames_rx = 0;
+ sar_init_reassembly_callbacks (test_ctx->sar,
+ sar_reassembly_done__do_nothing,
+ sar_reassembly_done__do_nothing,
+ test_ctx);
+ test_ctx->nb_frames_rx = 0;
+ test_ctx->nb_frames_tx = 0;
}
void
@@ -152,17 +123,8 @@ test_mpdu_reception (sar_test_ctx_t *ctx, pb_t *pb_head, pb_t *pb_tail,
mfs_rx_t *mfs;
bool added;
pbproc_rx_desc_t *sar_mpdu;
- uint i;
- u8 *buffer;
/* Activate the SAR. */
sar_activate (ctx->sar, true);
- /* Provide the buffer to the SAR. */
- for (i = 0; i < COUNT (buffers); i++)
- {
- buffer = ARCH_CPU_TO_UNCACHEABLE (buffers[i]);
- memset (buffer, 0x0, ETH_PACKET_MAX_SIZE);
- sar_data_buffer_add (ctx->sar, buffer);
- }
/* Prepare the MPDU for the SAR. */
sar_mpdu = (pbproc_rx_desc_t*) blk_alloc_desc ();
sar_mpdu->rx->params.tei = 1;
@@ -203,7 +165,6 @@ test_simulate_mpdu_reception (sar_test_ctx_t *ctx, uint eth_frame_nb,
crc_t crc_ctx;
u32 enc_tab[256];
u32 crc;
- u8 *buffer;
blk_t *pb_first, *pb_last;
pb_t *pb_current;
uint pb_nb;
@@ -211,7 +172,7 @@ test_simulate_mpdu_reception (sar_test_ctx_t *ctx, uint eth_frame_nb,
uint i, j;
bitstream_t stream;
- dbg_assert (eth_frame_nb <= BUFFERS_MAX);
+ dbg_assert (eth_frame_nb <= SAR_TEST_BUFFER_NB);
/* Compute PB number. */
pb_nb = (eth_frame_nb * (eth_frame_len + 6) + BLK_SIZE - 1) / BLK_SIZE;
@@ -245,15 +206,16 @@ test_simulate_mpdu_reception (sar_test_ctx_t *ctx, uint eth_frame_nb,
crc_ctx.table.t32 = enc_tab;
crc_init(&crc_ctx);
- buffer = buffers[0];
- memset (buffer, 0xff, 2048);
+ u8 *buffer_internal = bufmgr_get ((bufmgr_t *) &ctx->bufmgr);
+ memset (buffer_internal, 0xff, 2048);
/* Request the Leon processor to write all the data buffered. */
arch_write_buffer_flush ();
crc = crc_compute_begin (&crc_ctx);
- crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc, buffer,
+ crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc, buffer_internal,
eth_frame_len);
crc = crc_compute_end (&crc_ctx, crc);
+ bufmgr_give_back ((bufmgr_t *) &ctx->bufmgr, buffer_internal);
/* Store a Full size Ethernet Packet in it. */
pb_current = (pb_t*) pb_first;
@@ -285,7 +247,6 @@ void
test_simulate_mpdu_reception_check (sar_test_ctx_t *ctx, test_t test,
uint frames_nb, uint frames_len)
{
- u8 *buffer;
dbg_assert (ctx);
test_case_begin (test, "Verify reassembly");
@@ -293,14 +254,16 @@ test_simulate_mpdu_reception_check (sar_test_ctx_t *ctx, test_t test,
test_begin (test, "Sar reassembly")
{
uint i, j;
- test_fail_unless (frames_nb == sar_test_rx_frames ());
+ test_fail_unless (frames_nb == sar_test_rx_frames (ctx));
for (j = 0; j < frames_nb; j++)
{
- buffer = sar_test_get_buffer (j);
for (i = 0; i < frames_len; i++)
+ {
+ u8 *buffer = ctx->bufmgr.buffer[SAR_TEST_BUFFER_NB - 1 - j];
test_fail_unless (bitstream_direct_read (buffer, i*8, 8)
== 0xFF);
+ }
}
}
test_end;
@@ -335,7 +298,7 @@ sar_test_rx_multiple_frames (uint frames_nb, uint frames_len)
#endif
}
-static void
+void
test_simulate_msdu_emission (sar_test_ctx_t *ctx,
uint frames_nb, uint frames_len)
{
@@ -353,16 +316,20 @@ test_simulate_msdu_emission (sar_test_ctx_t *ctx,
if (added)
sar_mfs_add (ctx->sar, (mfs_t*) mfs);
- /* Get the buffer. */
- buffer = sar_test_get_buffer (0);
- memset (buffer, 0xff, 2048);
-
+ ctx->bufmgr.nb_given_back = 0;
/* Disallow the SAR to expire MFS. */
for (i = 0; i < frames_nb; i++)
- sar_msdu_add (ctx->sar, buffer, frames_len, mfs, INVALID_PTR,
- mac_ntb());
+ {
+ /* Get the buffer. */
+ buffer = bufmgr_get ((bufmgr_t *) &ctx->bufmgr);
+ memset (buffer, 0xff, 2048);
+ sar_msdu_add (ctx->sar, buffer, frames_len, mfs, mac_ntb());
+ bufmgr_give_back ((bufmgr_t *) &ctx->bufmgr, buffer);
+ }
blk_release (mfs);
+ /* Store number of frames given back to bufmgr. */
+ ctx->nb_frames_tx = ctx->bufmgr.nb_given_back;
}
void
@@ -373,7 +340,6 @@ test_simulate_msdu_emission_check (sar_test_ctx_t *ctx, test_t test,
crc_t crc_ctx;
u32 enc_tab[256];
u32 crc;
- u8 *buffer;
pb_t *pb_current;
bitstream_t stream;
uint i;
@@ -391,7 +357,7 @@ test_simulate_msdu_emission_check (sar_test_ctx_t *ctx, test_t test,
crc_ctx.table.t32 = enc_tab;
crc_init(&crc_ctx);
- buffer = buffers[0];
+ u8 *buffer = bufmgr_get ((bufmgr_t *) &ctx->bufmgr);
memset (buffer, 0xff, 2048);
/* Request the Leon processor to write all the data buffered. */
arch_write_buffer_flush ();
@@ -400,10 +366,11 @@ test_simulate_msdu_emission_check (sar_test_ctx_t *ctx, test_t test,
crc = bridgedma_crc_compute_continue_block (&crc_ctx, crc, buffer,
frames_len);
crc = crc_compute_end (&crc_ctx, crc);
+ bufmgr_give_back ((bufmgr_t *) &ctx->bufmgr, buffer);
test_begin (test, "Sar")
{
- test_fail_unless (frames_nb == sar_test_tx_frames ());
+ test_fail_unless (frames_nb == sar_test_tx_frames (ctx));
pb_current = mfs->head;
bitstream_read_init (&stream, pb_current->data, BLK_SIZE);
diff --git a/cesar/mac/sar/test/functional/test_functions.h b/cesar/mac/sar/test/functional/test_functions.h
index 3e50cde1ce..39885f8f0b 100644
--- a/cesar/mac/sar/test/functional/test_functions.h
+++ b/cesar/mac/sar/test/functional/test_functions.h
@@ -15,11 +15,24 @@
#include "mac/sar/sar.h"
#include "hal/phy/soft/bridgedma/inc/bridgedma.h"
+#define SAR_TEST_BUFFER_NB 100
+
+struct sar_test_bufmgr_t
+{
+ u8 *buffer[SAR_TEST_BUFFER_NB];
+ uint free_buffer_nb;
+ uint nb_given_back;
+};
+typedef struct sar_test_bufmgr_t sar_test_bufmgr_t;
+
struct sar_test_ctx_t
{
sar_t *sar;
mac_store_t *mac_store;
mac_config_t mac_config;
+ sar_test_bufmgr_t bufmgr;
+ uint nb_frames_rx;
+ uint nb_frames_tx;
};
typedef struct sar_test_ctx_t sar_test_ctx_t;
diff --git a/cesar/mac/sar/test/unit_test/ecos/Makefile b/cesar/mac/sar/test/unit_test/ecos/Makefile
index c9955b49f1..bc38433081 100644
--- a/cesar/mac/sar/test/unit_test/ecos/Makefile
+++ b/cesar/mac/sar/test/unit_test/ecos/Makefile
@@ -3,7 +3,7 @@ BASE = ../../../../../
INCLUDES = mac/sar/test/unit_test/ecos/override
ECOS = y
-DEFS = -DSAR_UNIT_TEST=1
+DEFS = -DSAR_UNIT_TEST=1 -DNO_PRIVATE
TARGET_PROGRAMS = sar sar_pbproc_override
@@ -12,14 +12,14 @@ sar_SOURCES = sar.c activate.c mfs_ssn_resize.c \
reassembly_measurement.c expiration.c sar_call_back_ul.c \
sar_remove_sta.c segmentation.c detect_mf.c \
get_associated_mfs.c sar_tx_job_desc_create.c misc.c stats.c \
- sar_pb_stats.c ca_stub.c pbproc_stub.c tests.c
+ sar_pb_stats.c ca_stub.c pbproc_stub.c tests.c bufmgr_stub.c
sar_MODULES = lib mac/sar mac/common mac/pbproc hal/phy/soft/bridgedma \
mac/sar/test/unit_test/ecos/override/ce/rx
sar_pbproc_override_SOURCES = sar_pbproc_override.c \
sar_pbproc_override_sar_tx_mfs_extract.c \
sar_pbproc_override_mfs.c \
- ca_stub.c pbproc_stub.c tests.c
+ ca_stub.c pbproc_stub.c tests.c bufmgr_stub.c
sar_pbproc_override_MODULES = lib mac/sar mac/common hal/phy/soft/bridgedma \
mac/sar/test/unit_test/ecos/override/ce/rx
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/activate.c b/cesar/mac/sar/test/unit_test/ecos/src/activate.c
index 5656f75a8e..90a5265af3 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/activate.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/activate.c
@@ -45,7 +45,6 @@ test_case__sar_activate (test_t test)
sar_job_mfs_t *jobs[nb_jobs];
uint i;
mfs_t *mfs;
- u8 buffer[1];
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
/* Create some jobs. */
@@ -77,7 +76,6 @@ test_case__sar_activate (test_t test)
pb_t *last;
jobs[i] = sar_job_mfs_create_rx ();
- jobs[i]->job.data_addr = buffer;
/* Get the MFS. */
jobs[i]->mfs = (mfs_t *) mac_store_mfs_add_rx (t.mac_store,
@@ -96,7 +94,7 @@ test_case__sar_activate (test_t test)
/* Configure the job. */
jobs[i]->job.first_pb_desc = (blk_t *) jobs[i]->mfs->rx.head;
}
- jobs[i]->job.data_addr = buffer;
+ jobs[i]->job.data_addr = bufmgr_get ((bufmgr_t *) &t.bufmgr);
jobs[i]->pb_quantity = 4;
}
@@ -115,7 +113,6 @@ test_case__sar_activate (test_t test)
memset (&t.rea_done, 0, sizeof (struct
sar_test_reassembly_complete_t));
sar_bridge_dma_free_head (t.sar);
- test_fail_unless (t.rea_done.buffer == NULL);
test_fail_unless (t.rea_done.length == 0);
/* Remove the first station and MFSs. */
@@ -207,9 +204,8 @@ test_case__sar_dissociate (test_t test)
sar_mfs_add (t.sar, mfs);
blk_release (mfs);
- sar_reassembly_ctx_t *rctx[] = {&t.sar->data_ctx, &t.sar->mme_ctx};
uint i;
- for (i = 0; i < COUNT (rctx); i++)
+ for (i = 0; i < 2; i++)
{
/* Get the MFS. */
mfs = (mfs_t *) mac_store_mfs_add_rx (t.mac_store,
@@ -230,7 +226,7 @@ test_case__sar_dissociate (test_t test)
job->mfs = mfs;
blk_addref (mfs);
/* Add it to DATA reassembly context. */
- slist_push_back (rctx[i]->jobs_pending_list., job, bare);
+ slist_push_back (t.sar->reassembly.jobs_pending_list., job, bare);
/* Now create the two job for the workaround of maria:#905. */
job = sar_job_mfs_create_rx ();
/* Add some PBs into the job. */
@@ -243,7 +239,7 @@ test_case__sar_dissociate (test_t test)
/* Create the next job. */
job->next = sar_job_mfs_create_rx ();
/* Add to the list. */
- slist_push_back_range (rctx[i]->jobs_pending_list., job,
+ slist_push_back_range (t.sar->reassembly.jobs_pending_list., job,
job->next, bare);
blk_release (mfs);
}
@@ -260,9 +256,8 @@ test_case__sar_dissociate (test_t test)
test_fail_if (mfs != NULL);
/* Reassembly list must be empty. */
- for (i = 0; i < COUNT (rctx); i++)
- test_fail_unless (
- slist_empty (rctx[i]->jobs_pending_list., bare));
+ test_fail_unless (
+ slist_empty (t.sar->reassembly.jobs_pending_list., bare));
/* Uninitialise the test. */
sar_test_uninit (&t);
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/bufmgr_stub.c b/cesar/mac/sar/test/unit_test/ecos/src/bufmgr_stub.c
new file mode 100644
index 0000000000..031ea87b2d
--- /dev/null
+++ b/cesar/mac/sar/test/unit_test/ecos/src/bufmgr_stub.c
@@ -0,0 +1,69 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file unit_test/ecos/src/bufmgr_stub.c
+ * \brief Buffer manager stub functions
+ * \ingroup mac_sar_test
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "common/defs/ethernet.h"
+
+#include "bufmgr/bufmgr.h"
+
+#include "mac/sar/test/unit_test/ecos/tests.h"
+
+static u8 buffer[SAR_TEST_BUFFER_NB][ETH_PACKET_MAX_SIZE];
+
+u8*
+bufmgr_get (bufmgr_t *ctx)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ if (bufmgr->free_buffer_nb)
+ {
+ u8 *buffer_to_give = buffer[bufmgr->free_buffer_nb - 1];
+ bufmgr->free_buffer_nb--;
+ return buffer_to_give;
+ }
+ return NULL;
+}
+
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ bufmgr->free_buffer_nb++;
+ dbg_assert (bufmgr->free_buffer_nb <= SAR_TEST_BUFFER_NB);
+}
+
+void
+bufmgr_keep_buffer (bufmgr_t *ctx, u8 *buffer)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ bufmgr->free_buffer_nb++;
+ dbg_assert (bufmgr->free_buffer_nb <= SAR_TEST_BUFFER_NB);
+}
+
+
+bufmgr_t *
+bufmgr_init (ipmbox_t *ctx)
+{
+ struct sar_test_bufmgr_t *bufmgr = (struct sar_test_bufmgr_t *) ctx;
+ uint i;
+ for (i = 0; i < SAR_TEST_BUFFER_NB; i++)
+ bufmgr->buffer[i] = buffer[i];
+ return (bufmgr_t *) ctx;
+}
+
+void
+bufmgr_client_register (bufmgr_t *ctx, bufmgr_callback_t cb,
+ void *user_data)
+{
+}
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 389bd15ccd..10b5e49917 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/misc.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/misc.c
@@ -93,10 +93,7 @@ test_case_misc__cleanup_pending_jobs_add_rx_simulate_missing_pb (
sar_mf_header (pb_first, 0, &sar_mf);
job = sar_rx_mfs_detect_and_reconstitute_mf__create_job (
t->sar, mfs, &sar_mf, pb_first->next->next);
- if (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);
+ slist_push_back (t->sar->reassembly.jobs_pending_list., job, bare);
blk_release (mfs);
}
@@ -121,10 +118,7 @@ test_case_misc__add_pending_jobs_add_one_rx (sar_test_t *t, bool data)
sar_mf_header (pb_first, 0, &sar_mf);
job = sar_rx_mfs_detect_and_reconstitute_mf__create_job (
t->sar, mfs, &sar_mf, pb_first->next->next);
- if (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);
+ slist_push_back (t->sar->reassembly.jobs_pending_list., job, bare);
/* Release the reference on the last PB which is duplicated. */
blk_release_desc (&mfs->head->blk);
mfs->head = NULL;
@@ -154,9 +148,7 @@ test_case_misc__cleanup_pending_jobs (test_t test)
sar_activate (t.sar, false);
sar_cleanup (t.sar);
test_fail_unless (
- slist_empty (t.sar->data_ctx.jobs_pending_list., bare) == true);
- test_fail_unless (
- slist_empty (t.sar->mme_ctx.jobs_pending_list., bare) == true);
+ slist_empty (t.sar->reassembly.jobs_pending_list., bare));
sar_activate (t.sar, true);
test_case_misc__cleanup_pending_jobs_add_rx_simulate_missing_pb (
&t, true);
@@ -165,60 +157,13 @@ test_case_misc__cleanup_pending_jobs (test_t test)
sar_activate (t.sar, false);
sar_cleanup (t.sar);
test_fail_unless (
- slist_empty (t.sar->data_ctx.jobs_pending_list., bare) == true);
- test_fail_unless (
- slist_empty (t.sar->mme_ctx.jobs_pending_list., bare) == true);
+ slist_empty (t.sar->reassembly.jobs_pending_list., bare));
sar_test_uninit (&t);
}
test_end;
}
void
-test_misc_buffer_add (sar_test_t *t)
-{
- static u8 buffer[ETH_PACKET_MAX_SIZE];
- /* DATA. */
- test_case_misc__add_pending_jobs_add_rx (t, true);
- sar_buffer_add (t->sar, buffer, true);
- sar_buffer_add (t->sar, buffer, true);
- /* MME. */
- test_case_misc__add_pending_jobs_add_rx (t, false);
- sar_buffer_add (t->sar, buffer, false);
- sar_buffer_add (t->sar, buffer, false);
-}
-
-void
-test_misc_buffer_add_result (sar_test_t *t, test_t test, bool expected_result)
-{
- test_begin (test, "SAR not activate/Activate")
- {
- test_misc_buffer_add (t);
- test_fail_unless (
- slist_empty (t->sar->data_ctx.jobs_pending_list., bare)
- == expected_result);
- test_fail_unless (
- slist_empty (t->sar->mme_ctx.jobs_pending_list., bare)
- == expected_result);
- }
- test_end;
-}
-
-void
-test_case_misc__buffer_add (test_t test)
-{
- sar_test_t t;
- sar_test_init (&t, INVALID_PTR, INVALID_PTR);
- test_case_begin (test, "Buffer add");
- sar_activate (t.sar, false);
- test_misc_buffer_add_result (&t, test, false);
- sar_cleanup (t.sar);
- sar_activate (t.sar, true);
- test_misc_buffer_add_result (&t, test, true);
- sar_cleanup (t.sar);
- sar_test_uninit (&t);
-}
-
-void
test_case_misc__chandata_add_sta__process (test_t test, sar_test_t *t, u8 tei)
{
pbproc_rx_desc_t *desc = (pbproc_rx_desc_t *) blk_alloc_desc ();
@@ -300,7 +245,6 @@ test_suite_misc (test_t test)
test_suite_begin (test, "Misc");
test_case_misc__exhausted_memory (test);
test_case_misc__cleanup_pending_jobs (test);
- test_case_misc__buffer_add (test);
test_case_misc__chandata_add_sta (test);
test_case_misc__pb136 (test);
}
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 322d532152..06dedfd8af 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/reassembly.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/reassembly.c
@@ -39,6 +39,9 @@
#include "config/blk.h"
void
+sar_buffer_available (sar_t *ctx);
+
+void
test_case_brodcast (test_t test)
{
test_case_begin (test, "Broadcast links Full MPDU");
@@ -430,6 +433,8 @@ test_case_example (test_t test)
pb_t *mfs_pb_last;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* Do not give a buffer. */
+ t.bufmgr.free_buffer_nb = 0;
/* Create MFS and PB list. */
mfs = blk_alloc ();
mfs->head = (pb_t*) blk_alloc_desc_range (COUNT(pb_ssn_list),
@@ -480,14 +485,14 @@ test_case_example (test_t test)
/* Set the SSN min in the MFS. */
mfs->ssn_min = 8;
- sar_rx_mfs_process (t.sar, mfs, &t.sar->data_ctx);
+ sar_rx_mfs_process (t.sar, mfs);
/* The MFS head should point to PB with SSN 9. */
test_fail_unless (mfs->head != NULL);
test_fail_unless (mfs->head->header.ssn == 9);
/* Only one job should have been reassembled. */
- job = slist_pop_front (t.sar->data_ctx.jobs_pending_list., bare);
+ job = slist_pop_front (t.sar->reassembly.jobs_pending_list., bare);
test_fail_unless (job != NULL);
test_fail_unless (job->job.data_len == 1512);
test_fail_unless (((pb_t*) job->job.first_pb_desc)->header.ssn == 0);
@@ -499,7 +504,7 @@ test_case_example (test_t test)
/* Try to get the next job, normally the pointer should be null. */
test_fail_unless (
- slist_empty (t.sar->data_ctx.jobs_pending_list., bare));
+ slist_empty (t.sar->reassembly.jobs_pending_list., bare));
while (mfs->head)
mfs->head = sar_pb_release (mfs->head);
blk_release (mfs);
@@ -526,6 +531,8 @@ test_case_example (test_t test)
pb_t *mfs_pb_last;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* Do not give a buffer. */
+ t.bufmgr.free_buffer_nb = 0;
/* Create MFS and PB list. */
mfs = blk_alloc ();
mfs->head = (pb_t*) blk_alloc_desc_range (COUNT(pb_ssn_list),
@@ -568,14 +575,14 @@ test_case_example (test_t test)
/* Set the SSN min in the MFS. */
mfs->ssn_min = 6;
- sar_rx_mfs_process (t.sar, mfs, &t.sar->data_ctx);
+ sar_rx_mfs_process (t.sar, mfs);
/* The MFS head should point to PB with SSN 5 and the tail to SSN 5. */
test_fail_unless (mfs->head != NULL);
test_fail_unless (mfs->head->header.ssn == 5);
/* Only one job should have been reassembled. */
- job = slist_pop_front (t.sar->data_ctx.jobs_pending_list., bare);
+ job = slist_pop_front (t.sar->reassembly.jobs_pending_list., bare);
test_fail_unless (job != NULL);
test_fail_unless (job->job.data_len == 1512);
test_fail_unless (((pb_t*) job->job.first_pb_desc)->header.ssn == 0);
@@ -587,7 +594,7 @@ test_case_example (test_t test)
/* Try to get the next job, normally the pointer should be null. */
test_fail_unless (
- slist_empty (t.sar->data_ctx.jobs_pending_list., bare));
+ slist_empty (t.sar->reassembly.jobs_pending_list., bare));
while (mfs->head)
mfs->head = sar_pb_release (mfs->head);
blk_release (mfs);
@@ -609,6 +616,8 @@ test_case_example (test_t test)
sar_job_mfs_t *job;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* Do not give a buffer. */
+ t.bufmgr.free_buffer_nb = 0;
/* Initialise the PBs. */
for (i = 0; i < COUNT (pb_ssn_list); i++)
{
@@ -643,7 +652,7 @@ test_case_example (test_t test)
mfs->head = pb_list[2];
mfs->head->next = pb_list[3];
- sar_rx_mfs_process (t.sar, mfs, &t.sar->data_ctx);
+ sar_rx_mfs_process (t.sar, mfs);
/* The MFS should not change. */
test_fail_unless (mfs->head != NULL);
@@ -651,7 +660,7 @@ test_case_example (test_t test)
/* No job should be created. */
test_fail_unless (
- slist_empty (t.sar->data_ctx.jobs_pending_list., bare));
+ slist_empty (t.sar->reassembly.jobs_pending_list., bare));
/* Chain the new PBs. */
mfs->head = pb_list[0];
pb_list[0]->next = pb_list[1];
@@ -660,13 +669,13 @@ test_case_example (test_t test)
/* All the PB have been received so the SSN min is 4. */
mfs->ssn_min = pb_list[3]->header.ssn + 1;
- sar_rx_mfs_process (t.sar, mfs, &t.sar->data_ctx);
+ sar_rx_mfs_process (t.sar, mfs);
/* The MFS head should point to PB with SSN 5 and the tail to SSN 5. */
test_fail_unless (mfs->head == NULL);
/* Only one job should have been reassembled. */
- job = slist_pop_front (t.sar->data_ctx.jobs_pending_list., bare);
+ job = slist_pop_front (t.sar->reassembly.jobs_pending_list., bare);
test_fail_unless (job != NULL);
test_fail_unless (job->job.data_len == 940);
test_fail_unless (((pb_t*) job->job.first_pb_desc)->header.ssn == 0);
@@ -677,7 +686,7 @@ test_case_example (test_t test)
blk_release (job);
/* Try to get the next job, normally the pointer should not be null. */
- job = slist_pop_front (t.sar->data_ctx.jobs_pending_list., bare);
+ job = slist_pop_front (t.sar->reassembly.jobs_pending_list., bare);
test_fail_unless (job != NULL);
test_fail_unless (job->job.data_len == 960);
test_fail_unless (((pb_t*) job->job.first_pb_desc)->header.ssn == 1);
@@ -704,6 +713,8 @@ test_case_example (test_t test)
pb_t *pb_current;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* Do not give a buffer. */
+ t.bufmgr.free_buffer_nb = 0;
/* Initialize the PB list already in the MFS. */
mfs = blk_alloc ();
mfs_rx_init (mfs, false, false, 1, 1);
@@ -757,6 +768,8 @@ test_case_reassembly_one_pb_opsf (test_t test)
pbproc_rx_desc_t *desc = (pbproc_rx_desc_t *) blk_alloc_desc ();
sar_mpdu_t *mpdu = PARENT_OF (sar_mpdu_t, rx, desc->rx);
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* Do not give a buffer. */
+ t.bufmgr.free_buffer_nb = 0;
sar_test_mpdu_default_fill (mpdu, 1, 1);
/* Create a list of PBs with Ethernet frames inside. */
sar_test_data_create (&pb_first, &pb_last, 6, 0, 0x493, false);
@@ -774,7 +787,7 @@ test_case_reassembly_one_pb_opsf (test_t test)
pb_first->header.opsf = true;
sar_reassembly_run (t.sar, mpdu);
/* Verify... */
- job = slist_pop_front (t.sar->data_ctx.jobs_pending_list., bare);
+ job = slist_pop_front (t.sar->reassembly.jobs_pending_list., bare);
test_fail_unless (job);
test_fail_unless (job->job.data_len == 1518);
blk_release_desc_range_nb (job->job.first_pb_desc, job->pb_quantity);
@@ -804,6 +817,8 @@ test_case_reassembly_severals_pb_groups (test_t test)
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* Do not give a buffer. */
+ t.bufmgr.free_buffer_nb = 0;
/* Configure the rx params. */
sar_test_mpdu_default_fill (&rx, 1, 1);
/* 4 time the Same PBs. */
@@ -848,7 +863,6 @@ test_case_reassembly (test_t test)
uint offset;
mfs_rx_t *mfs;
bool added;
- u8 buffer[ETH_PACKET_MAX_SIZE];
pbproc_rx_desc_t *rx_desc;
pb_t *pb_current;
uint ssn;
@@ -930,13 +944,9 @@ test_case_reassembly (test_t test)
}
bitstream_finalise (&stream);
- /* Add the buffer to the SAR. */
- sar_data_buffer_add (t.sar, buffer);
-
/* Add the MPDU to the SAR. */
sar_mpdu_add (t.sar, rx_desc);
- test_fail_unless (t.rea_done.buffer == buffer);
test_fail_unless (t.rea_done.length == 60);
test_fail_unless (t.rea_done.mfs == mfs);
@@ -958,7 +968,6 @@ test_case_reassembly (test_t test)
sar_test_t t;
pb_t *pb;
sar_mpdu_t mpdu;
- u8 buffer[256];
uint i;
bitstream_t stream;
@@ -976,14 +985,12 @@ test_case_reassembly (test_t test)
SAR_MF_TYPE_DATA, SAR_MF_MFH_SIZE);
/* Add the MPDU to the SAR. */
- t.rea_done.buffer = INVALID_PTR;
t.rea_done.length = 0xdeaddead;
t.rea_done.mfs = INVALID_PTR;
t.rea_done.encrypted = false;
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);
@@ -1008,10 +1015,8 @@ test_case_reassembly (test_t test)
bitstream_finalise (&stream);
/* Add the MPDU to the SAR. */
- sar_data_buffer_add (t.sar, buffer);
sar_reassembly_run (t.sar, &mpdu);
sar_bridge_dma_free_head (t.sar);
- test_fail_unless (t.rea_done.buffer == buffer);
test_fail_unless (t.rea_done.length == 60);
test_fail_unless (t.rea_done.mfs == &mpdu.rx.mfs->rx);
test_fail_unless (t.rea_done.encrypted == true);
@@ -1030,13 +1035,14 @@ test_case_reassembly (test_t test)
pb_t *pb_first, *pb_last;
pb_t *pb_first2, *pb_last2;
sar_mpdu_t mpdu;
- u8 buffer[1518];
uint pb_nb = 200;
uint i;
u32 buff_ssn = 0;
u32 tmp;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
sar_activate (t.sar, true);
+ /* Fake that there is no buffer available. */
+ t.bufmgr.free_buffer_nb = 0;
/* Create the MPDU. */
sar_test_mpdu_default_fill (&mpdu, 1, 1);
sar_test_create_data_pb_list_mixed_up (pb_nb, 0, &pb_first, &pb_last,
@@ -1047,7 +1053,6 @@ test_case_reassembly (test_t test)
sar_test_create_data_pb_duplicate_store_crc_false (
&pb_first2, &pb_last2, pb_first, pb_last, pb_nb);
/* Add the MPDU to the SAR. */
- t.rea_done.buffer = INVALID_PTR;
t.rea_done.length = 0xdeaddead;
t.rea_done.mfs = INVALID_PTR;
t.rea_done.encrypted = false;
@@ -1056,20 +1061,22 @@ test_case_reassembly (test_t test)
mpdu.rx.pb_first = pb_first2;
mpdu.rx.pb_last = pb_last2;
mpdu.rx.pb_nb = pb_nb;
+ /* Process the first frame. */
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);
+ /* Fake that there is one buffer available. */
+ t.bufmgr.free_buffer_nb = 1;
for (i = 0; i < (pb_nb * BLK_SIZE) / 1518; i++)
{
+ /* Process the following frames. */
+ sar_buffer_available (t.sar);
/* Add the MPDU to the SAR. */
- sar_data_buffer_add (t.sar, buffer);
- test_fail_unless (t.rea_done.buffer == buffer);
test_fail_unless (t.rea_done.length == 1518);
test_fail_unless (t.rea_done.mfs == &mpdu.rx.mfs->rx);
test_fail_unless (t.rea_done.encrypted == true);
- tmp = bitstream_direct_read (buffer, 0, 32);
+ tmp = bitstream_direct_read (t.bufmgr.buffer[0], 0, 32);
test_fail_unless (buff_ssn <= tmp);
test_fail_unless (i <= tmp);
buff_ssn = tmp;
@@ -1087,6 +1094,8 @@ test_case_reassembly_encrypted (test_t test)
{
sar_test_t t;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
+ /* Do not give a buffer. */
+ t.bufmgr.free_buffer_nb = 0;
uint pb_nb = 1;
pb_t *pb;
sar_mpdu_t mpdu;
@@ -1112,7 +1121,6 @@ test_case_reassembly_exhausted_memory (test_t test)
test_case_begin (test, "Exhausted memory");
test_begin (test, "1 frame")
{
- u8 skbuf[ETH_PACKET_MAX_SIZE];
blk_t *head, *tail;
sar_test_t t;
sar_mpdu_t mpdu;
@@ -1120,12 +1128,10 @@ test_case_reassembly_exhausted_memory (test_t test)
/* 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);
- sar_data_buffer_add (t.sar, skbuf);
uint i;
for (i = 0; i < 2; i++)
{
/* Create an MPDU */
- sar_data_buffer_add (t.sar, skbuf);
memset (&mpdu, 0, sizeof (sar_mpdu_t));
sar_test_mpdu_data_create (&mpdu, 6, 0, 0x43, false);
if (i)
@@ -1143,7 +1149,6 @@ test_case_reassembly_exhausted_memory (test_t test)
sar_test_reassembly_done_init (&t);
sar_reassembly_run (t.sar, &mpdu);
sar_bridge_dma_free_head (t.sar);
- 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);
@@ -1189,7 +1194,6 @@ test_case_reassembly_exhausted_memory (test_t test)
sar_test_reassembly_done_init (&t);
sar_reassembly_run (t.sar, &mpdu);
sar_bridge_dma_free_head (t.sar);
- 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);
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/sar_call_back_ul.c b/cesar/mac/sar/test/unit_test/ecos/src/sar_call_back_ul.c
index 0387ffb091..78f0d07241 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/sar_call_back_ul.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/sar_call_back_ul.c
@@ -29,37 +29,26 @@ sar_job_mfs_t*
sar_job_mfs_create_rx (void);
void
+sar_buffer_available (sar_t *ctx);
+
+void
test_case_sar_ul (test_t test)
{
sar_test_t t;
- u8 *buffer = INVALID_PTR;
- void *data = INVALID_PTR;
sar_test_init (&t, INVALID_PTR, INVALID_PTR);
test_begin(test, "sar_call_back_cl")
{
- t.sar->sar_seg_data_done_cb (&t, buffer, data);
- t.sar->data_ctx.sar_rea_done (&t, buffer, 123, INVALID_PTR, true);
-
- test_fail_unless (t.seg_done.buffer == buffer);
- test_fail_unless (t.seg_done.data == data);
+ u8 *buffer = bufmgr_get (t.sar->bufmgr);
+ t.sar->reassembly.data_cb (&t, buffer, 123, INVALID_PTR, true);
- test_fail_unless (t.rea_done.buffer == buffer);
test_fail_unless (t.rea_done.length == 123);
test_fail_unless (t.rea_done.mfs == INVALID_PTR);
test_fail_unless (t.rea_done.encrypted == true);
}
test_end;
- test_begin(test, "sar_call_back_cl")
- {
- t.sar->sar_seg_msg_done_cb (&t, buffer, data);
- test_fail_unless (t.seg_done.buffer == buffer);
- test_fail_unless (t.seg_done.data == data);
- }
- test_end;
-
test_begin(test, "sar_beacon_call_back")
{
uint beacon;
@@ -89,7 +78,6 @@ test_case_rx_upper_layer_transmit_data (test_t test)
test_begin (test, "No buffers, with buffers, only buffers.")
{
sar_test_t t;
- u8 buffer[2][256];
sar_job_mfs_t *job;
uint i;
@@ -113,17 +101,23 @@ test_case_rx_upper_layer_transmit_data (test_t test)
job->job.data_addr = NULL;
job->mfs = blk_alloc ();
job->pb_quantity = 1;
- slist_push_back (t.sar->data_ctx.jobs_pending_list., job, bare);
+ slist_push_back (t.sar->reassembly.jobs_pending_list., job, bare);
}
job = INVALID_PTR;
+ /* Fake that there are not any buffers available. */
+ t.bufmgr.free_buffer_nb = 0;
+
/* Start the test. */
- sar_rx_upper_layer_transmit_data (t.sar, &t.sar->data_ctx);
+ sar_buffer_available (t.sar);
+
+ test_fail_unless (!slist_empty (t.sar->reassembly.jobs_pending_list.,
+ bare));
/* Test. */
for (i = 0; i < 2; i++)
{
- job = slist_pop_front (t.sar->data_ctx.jobs_pending_list., bare);
+ job = slist_pop_front (t.sar->reassembly.jobs_pending_list., bare);
test_fail_unless (job->job.first_pb_offset == 0);
test_fail_unless (job->job.data_len == 20);
test_fail_unless (job->job.header_len == 2);
@@ -141,10 +135,14 @@ test_case_rx_upper_layer_transmit_data (test_t test)
job->job.first_pb_offset = 10;
job->mfs = blk_alloc ();
mfs_rx_init (&job->mfs->rx, false, false, 1, 1);
- slist_push_back (t.sar->data_ctx.jobs_pending_list., job, bare);
- sar_data_buffer_add (t.sar, buffer[0]);
+ slist_push_back (t.sar->reassembly.jobs_pending_list., job, bare);
+
+ /* Fake that buffers are now available. */
+ t.bufmgr.free_buffer_nb = 1;
+
+ /* Continue test. */
+ sar_buffer_available (t.sar);
- test_fail_unless (t.rea_done.buffer = job->job.data_addr);
test_fail_unless (t.rea_done.length = job->job.data_len);
test_fail_unless (t.rea_done.mfs = (mfs_rx_t*) job->mfs);
sar_test_uninit (&t);
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c b/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c
index 3cfa678fb2..bc7faf91e8 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c
@@ -35,7 +35,7 @@ void
test_case_segmentation_seg_nb (test_t test)
{
sar_test_t t;
- u8 buffer[2048];
+ u8 *buffer = NULL;
uint list[4];
uint i;
pbproc_t pbproc;
@@ -61,7 +61,9 @@ test_case_segmentation_seg_nb (test_t test)
for (i = 0; i < 4; i++)
{
/* Add a MSDU to the SAR. */
- sar_msdu_add (t.sar, buffer, list[i], mfs, NULL, 123);
+ buffer = bufmgr_get (t.sar->bufmgr);
+ sar_msdu_add (t.sar, buffer, list[i], mfs, 123);
+ bufmgr_give_back (t.sar->bufmgr, buffer);
test_fail_unless (mfs->pending_seg_nb == 0, "i: %d",i);
switch (i)
{
@@ -125,7 +127,7 @@ test_case_segmentation (test_t test)
pb_t *mfs_pb_first;
mfs_tx_t *mfs;
bool added;
- u8 buffer[ETH_PACKET_MAX_SIZE];
+ u8 *buffer;
sar_mf_t sar_mf;
sar_test_t t;
@@ -163,7 +165,9 @@ test_case_segmentation (test_t test)
mfs->last_seg_offset = offset;
/* Add the MSDU to process. */
- sar_msdu_add (t.sar, buffer, 60, mfs, INVALID_PTR, mac_ntb());
+ buffer = bufmgr_get (t.sar->bufmgr);
+ sar_msdu_add (t.sar, buffer, 60, mfs, mac_ntb());
+ bufmgr_give_back (t.sar->bufmgr, buffer);
/* Check the data. */
test_fail_unless (mfs->head != NULL);
@@ -213,7 +217,7 @@ void
test_case_segmentation_mfs_release (test_t test)
{
sar_test_t t;
- u8 buffer[256];
+ u8 *buffer;
uint length = 60;
mfs_tx_t *mfs, *mfs_store;
uint i;
@@ -232,8 +236,9 @@ test_case_segmentation_mfs_release (test_t test)
dbg_assert (added);
mfs->fsm_state = MFS_FSM_CMD_RELEASE;
sar_mfs_add (t.sar, PARENT_OF (mfs_t, tx, mfs));
- sar_msdu_add (t.sar, buffer, length, mfs, INVALID_PTR,
- mac_ntb());
+ buffer = bufmgr_get (t.sar->bufmgr);
+ sar_msdu_add (t.sar, buffer, length, mfs, mac_ntb());
+ bufmgr_give_back (t.sar->bufmgr, buffer);
mfs_store = mac_store_mfs_get_tx (t.mac_store, false,
i == MAC_LID_NONE, i, 1);
if (MAC_LID_IS_PLID(i) || i == MAC_LID_NONE)
@@ -262,13 +267,14 @@ void
test_case_segmentation_em_max_pb_allowed_test (test_t test, sar_test_t ctx,
mfs_tx_t *mfs)
{
- u8 buffer[ETH_PACKET_MIN_SIZE_ALLOWED];
- memset (buffer, 0xff, ETH_PACKET_MIN_SIZE_ALLOWED);
+ u8 *buffer = NULL;
test_within (test);
+ buffer = bufmgr_get (ctx.sar->bufmgr);
sar_msdu_add (ctx.sar, buffer, ETH_PACKET_MIN_SIZE_ALLOWED, mfs,
- NULL, 0x0);
+ 0x0);
sar_bridge_dma_free_head (ctx.sar);
test_fail_unless (mfs->seg_nb == MAC_SAR_EM_MAX_PB_ALLOWED + 1);
+ bufmgr_give_back (ctx.sar->bufmgr, buffer);
}
void
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/stats.c b/cesar/mac/sar/test/unit_test/ecos/src/stats.c
index ea9dd0cfa0..8d78d37679 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/stats.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/stats.c
@@ -37,7 +37,7 @@ test_case_sar_stats_tx (test_t test)
test_begin (test, "Stats")
{
sar_test_t t;
- u8 buffer[256];
+ u8 *buffer = NULL;
uint length = 60;
mfs_tx_t *mfs;
bool added;
@@ -53,7 +53,10 @@ test_case_sar_stats_tx (test_t test)
sar_mfs_add (t.sar, PARENT_OF (mfs_t, tx, mfs));
/* Create the MSDU and give it to the SAR for the test. */
for (i = 0; i < nb_msdus; i++)
- sar_msdu_add (t.sar, buffer, length, mfs, INVALID_PTR, 0x0);
+ {
+ buffer = bufmgr_get (t.sar->bufmgr);
+ sar_msdu_add (t.sar, buffer, length, mfs, 0x0);
+ }
/* Verify the stats are correct and correspond to the test values. */
test_fail_unless (mfs->stats.num_msdus == nb_msdus);
test_fail_unless (mfs->stats.octets == nb_msdus * length);
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/tests.c b/cesar/mac/sar/test/unit_test/ecos/src/tests.c
index e99c1042da..2186f60df2 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/tests.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/tests.c
@@ -17,6 +17,7 @@
#include "lib/crc.h"
#include "lib/stats.h"
#include "string.h"
+#include "bufmgr/bufmgr.h"
#include "mac/common/ntb.h"
#include "mac/sar/inc/sar_context.h"
#include "mac/sar/test/unit_test/ecos/tests.h"
@@ -36,19 +37,8 @@ phy_date (void)
}
void
-sar_test_segmentation_done (void *user_data, u8 *buffer, void *data)
-{
- sar_test_t *t = user_data;
- dbg_assert (user_data);
-
- t->seg_done.buffer = buffer;
- t->seg_done.data = data;
-}
-
-void
sar_test_reassembly_done_init (sar_test_t *test)
{
- test->rea_done.buffer = INVALID_PTR;
test->rea_done.length = 0xdeaddead;
test->rea_done.mfs = INVALID_PTR;
test->rea_done.encrypted = false;
@@ -61,7 +51,7 @@ sar_test_reassembly_done (void *user, u8* buffer,
sar_test_t *t = user;
dbg_assert (user);
- t->rea_done.buffer = buffer;
+ bufmgr_give_back (t->sar->bufmgr, buffer);
t->rea_done.length = length;
t->rea_done.mfs = mfs;
t->rea_done.encrypted = encrypted;
@@ -94,17 +84,16 @@ sar_test_init (sar_test_t *t, void *phy, void *pbproc)
phy_global = t->phy;
mac_ntb_init (&t->mac_config);
lib_stats_init ();
- t->sar = sar_init (t->mac_store, pbproc, INVALID_PTR, 123);
+ t->sar = sar_init (t->mac_store, pbproc, INVALID_PTR, INVALID_PTR, 123);
t->ce = ce_rx_init (t->mac_store, t->sar, pbproc, &t->mac_config);
sar_init_measure_context (t->sar, t->ce);
sar_init_measurement_cb (t->sar, ce_measurements);
- sar_init_data_context (t->sar, t);
- sar_init_mme_context (t->sar, t);
- sar_init_segmentation_data_cb (t->sar, sar_test_segmentation_done);
- sar_init_segmentation_mme_cb (t->sar, sar_test_segmentation_done);
- sar_init_reassembly_data_cb (t->sar, sar_test_reassembly_done);
- sar_init_reassembly_mme_cb (t->sar, sar_test_reassembly_done);
+ sar_init_reassembly_callbacks (t->sar, sar_test_reassembly_done,
+ sar_test_reassembly_done, t);
sar_init_beacon_cb (t->sar, t, sar_test_beacon_receive);
+ t->sar->bufmgr = (bufmgr_t *) &t->bufmgr;
+ bufmgr_init ((ipmbox_t *)&t->bufmgr);
+ t->bufmgr.free_buffer_nb = SAR_TEST_BUFFER_NB;
}
static int
diff --git a/cesar/mac/sar/test/unit_test/ecos/tests.h b/cesar/mac/sar/test/unit_test/ecos/tests.h
index 24acb1a25e..436c994599 100644
--- a/cesar/mac/sar/test/unit_test/ecos/tests.h
+++ b/cesar/mac/sar/test/unit_test/ecos/tests.h
@@ -12,10 +12,14 @@
* \brief Library tests
* \ingroup mac_sar
*/
+#include "common/defs/ethernet.h"
#include "mac/sar/inc/sar_context.h"
#include "lib/bitstream.h"
#include "ce/rx/rx.h"
+/* Number of stubbed buffers. */
+#define SAR_TEST_BUFFER_NB 10
+
struct sar_test_bitstream_change_data_t
{
/* current PB. */
@@ -26,15 +30,8 @@ struct sar_test_bitstream_change_data_t
typedef struct sar_test_bitstream_change_data_t
sar_test_bitstream_change_data_t;
-struct sar_test_segmentation_complete_t
-{
- u8 *buffer;
- void *data;
-};
-
struct sar_test_reassembly_complete_t
{
- u8 *buffer;
uint length;
mfs_rx_t *mfs;
bool encrypted;
@@ -46,6 +43,12 @@ struct sar_test_beacon_recv_t
pbproc_rx_beacon_params_t *params;
};
+struct sar_test_bufmgr_t
+{
+ u8 *buffer[SAR_TEST_BUFFER_NB];
+ uint free_buffer_nb;
+};
+
struct sar_test_t
{
/* SAR context. */
@@ -58,12 +61,12 @@ struct sar_test_t
void *phy;
/* Ce context. */
ce_rx_t *ce;
- /* Segmentation done context. */
- struct sar_test_segmentation_complete_t seg_done;
/* Reassembly done context. */
struct sar_test_reassembly_complete_t rea_done;
/* Beacon reception context. */
struct sar_test_beacon_recv_t beacon_recv;
+ /* Buffer manager stub context. */
+ struct sar_test_bufmgr_t bufmgr;
};
typedef struct sar_test_t sar_test_t;
diff --git a/cesar/maximus/common/types/ethernet_types.h b/cesar/maximus/common/types/ethernet_types.h
index 62525203dc..78e25a996d 100644
--- a/cesar/maximus/common/types/ethernet_types.h
+++ b/cesar/maximus/common/types/ethernet_types.h
@@ -60,18 +60,11 @@ enum Ethernet_Type
ETHERNET_TYPE_MME = 0x02, // Ether SCI msg data contain the MSDU (MME)
/* HLE_MSG_TYPE_BUFFER_ADD > Buffer alloc message type. */
- ETHERNET_TYPE_DATA_BUFFER_ADD = 0x03, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
- // and IDs of each buffer to allocate (uint32_t)
- ETHERNET_TYPE_MME_BUFFER_ADD = 0x04, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
- // and IDs of each buffer to allocate (uint32_t)
- ETHERNET_TYPE_INTERFACE_BUFFER_ADD = 0x05, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
+ ETHERNET_TYPE_BUFFER_ADD = 0x03, // Ether SCI msg data contain the number of buffers to allocate (uint32_t)
// and IDs of each buffer to allocate (uint32_t)
/* HLE_MSG_TYPE_SEND_DONE > Buffer dealloc message type. */
- ETHERNET_TYPE_BUFFER_RELEASED = 0x06, // Ether SCI msg data contain the ID of released buffer (uint32_t)
-
- /* HLE_MSG_TYPE_INTERFACE > Interface message type. */
- ETHERNET_TYPE_SNIFFER = 0x07, // Ether SCI msg data contain a sniffed packet
+ ETHERNET_TYPE_BUFFER_RELEASED = 0x04, // Ether SCI msg data contain the ID of released buffer (uint32_t)
ETHERNET_TYPE_NB
};
diff --git a/cesar/maximus/common/types/sci_types.h b/cesar/maximus/common/types/sci_types.h
index 7e5e957947..81e7b6b1f1 100644
--- a/cesar/maximus/common/types/sci_types.h
+++ b/cesar/maximus/common/types/sci_types.h
@@ -34,7 +34,7 @@ The original location of this file is /home/buret/eclipse/maximus/common/types/s
#include <stdint.h> // for 'uint8_t', 'uint16_t' and 'uint32_t' types
#define SCI_MSG_MAGIC "MAXI"
-#define SCI_MSG_VERSION 0x02
+#define SCI_MSG_VERSION 0x03
#define SCI_MSG_ID_STATION 0x8000
#define SCI_MSG_ID_MASK 0x7fff
#define SCI_MSG_MAX_SIZE 16384
@@ -67,7 +67,7 @@ enum Sci_Msg_Status
struct Sci_Msg_Header
{
uint32_t magic_id; /* 1st field is magic id (32 bits): always “MAXI” */
- uint8_t version; /* 2nd field is version (8 bits): message protocol version; always 0x02 */
+ uint8_t version; /* 2nd field is version (8 bits): message protocol version */
uint8_t type; /* 3rd field is type (8): message type; Sci_Msg_Type */
uint16_t length; /* 4th field is length (16 bits): message length without header */
uint16_t station_id; /* 5th field is station id (16 bits): source or destination station id; in general, the process id of the simulated station */
diff --git a/cesar/maximus/ethernet/inc/EtherSciMsgTest.h b/cesar/maximus/ethernet/inc/EtherSciMsgTest.h
index 75c2782205..64bc494a7d 100644
--- a/cesar/maximus/ethernet/inc/EtherSciMsgTest.h
+++ b/cesar/maximus/ethernet/inc/EtherSciMsgTest.h
@@ -44,7 +44,6 @@ protected:
void returnSpecializedSciMsgHeaderTest (void);
void setSpecializedSciMsgHeaderTest (void);
void setSpecializedSciMsgTypeTest (void);
- void setSnifferTypeTest (void);
void setFlagsTest (void);
private:
diff --git a/cesar/maximus/ethernet/src/EtherSciMsg.cpp b/cesar/maximus/ethernet/src/EtherSciMsg.cpp
index bd71133113..d65f45ec55 100644
--- a/cesar/maximus/ethernet/src/EtherSciMsg.cpp
+++ b/cesar/maximus/ethernet/src/EtherSciMsg.cpp
@@ -219,20 +219,11 @@ void EtherSciMsg::displaySpecializedSciMsgType ( int log_level ) const
clog << logger(log_level) << "\ttype = ETHERNET_TYPE_MME" << endl;
break;
case 3:
- clog << logger(log_level) << "\ttype = ETHERNET_TYPE_DATA_BUFFER_ADD" << endl;
+ clog << logger(log_level) << "\ttype = ETHERNET_TYPE_BUFFER_ADD" << endl;
break;
case 4:
- clog << logger(log_level) << "\ttype = ETHERNET_TYPE_MME_BUFFER_ADD" << endl;
- break;
- case 5:
- clog << logger(log_level) << "\ttype = ETHERNET_TYPE_INTERFACE_BUFFER_ADD" << endl;
- break;
- case 6:
clog << logger(log_level) << "\ttype = ETHERNET_TYPE_BUFFER_RELEASED" << endl;
break;
- case 7:
- clog << logger(log_level) << "\ttype = ETHERNET_TYPE_SNIFFER" << endl;
- break;
default:
clog << logger(log_level) << "\ttype = unknown!" << endl;
break;
diff --git a/cesar/maximus/ethernet/src/EtherSciMsgTest.cpp b/cesar/maximus/ethernet/src/EtherSciMsgTest.cpp
index 1e58307f5d..ecc9b61c36 100644
--- a/cesar/maximus/ethernet/src/EtherSciMsgTest.cpp
+++ b/cesar/maximus/ethernet/src/EtherSciMsgTest.cpp
@@ -34,7 +34,7 @@ void EtherSciMsgTest::setUp (void)
Ethernet_Header header;
header.version = ETHERNET_VERSION;
- header.type = ETHERNET_TYPE_SNIFFER;
+ header.type = ETHERNET_TYPE_BUFFER_ADD;
header.flags = ETHERNET_FLAG_NONE;
header.reserved = 0x12;
mpEtherSciMsg->setSpecializedSciMsgHeader(header);
@@ -190,7 +190,7 @@ void EtherSciMsgTest::setSpecializedSciMsgHeaderTest (void)
logTest();
CPPUNIT_ASSERT_MESSAGE("setSpecializedSciMsgHeader failed",
- ETHERNET_TYPE_SNIFFER == mpEtherSciMsg->getSpecializedSciMsgHeader().type);
+ ETHERNET_TYPE_BUFFER_ADD == mpEtherSciMsg->getSpecializedSciMsgHeader().type);
}
diff --git a/cesar/maximus/prototest/fcall/Makefile b/cesar/maximus/prototest/fcall/Makefile
index ab86aa762c..aa345c6eef 100644
--- a/cesar/maximus/prototest/fcall/Makefile
+++ b/cesar/maximus/prototest/fcall/Makefile
@@ -5,6 +5,7 @@ ECOS = y
TARGET_PROGRAMS = test_fcall
test_fcall_SOURCES = test_fcall.c
-test_fcall_MODULES = lib interface host
+test_fcall_MODULES = lib host interface/fcall \
+ bufmgr/stub cl/mbx/stub
include $(BASE)/common/make/top.mk
diff --git a/cesar/maximus/prototest/fcall/inc/syscall.h b/cesar/maximus/prototest/fcall/inc/syscall.h
index 72b5548855..0e4d28d233 100644
--- a/cesar/maximus/prototest/fcall/inc/syscall.h
+++ b/cesar/maximus/prototest/fcall/inc/syscall.h
@@ -15,6 +15,7 @@
* Redefinition of Linux System Calls
*/
#include "ecos/packages/hal/synth/arch/current/include/hal_io.h"
+#include <errno.h>
/** flags redefinition */
diff --git a/cesar/maximus/prototest/fcall/src/test_fcall.c b/cesar/maximus/prototest/fcall/src/test_fcall.c
index 878170d44d..08fe906c6d 100644
--- a/cesar/maximus/prototest/fcall/src/test_fcall.c
+++ b/cesar/maximus/prototest/fcall/src/test_fcall.c
@@ -15,14 +15,14 @@
#include <cyg/infra/diag.h>
#include <cyg/kernel/kapi.h>
#include <stdlib.h>
-#include <errno.h>
#include "common/std.h"
+#include "common/defs/ethernet.h"
#include "interface/fcall/interface_fcall.h"
+#include "interface/fcall/inc/context.h"
#include "interface/fcall/inc/interface_fcall.h"
#include "lib/swap.h" // for 'swap16()' and 'swap32()'
#include "lib/read_word.h" // for 'read_u16_from_word()'
#include "maximus/prototest/fcall/inc/syscall.h"
-#include "common/defs/ethernet.h"
#define MY_THREAD_STACK_SIZE (8192 / sizeof(int))
@@ -68,53 +68,6 @@ void my_thread(cyg_addrword_t index)
}
}
-void
-my_interface_hle_send (void *user_data, uint *message, uint length)
-{
- int len = 0, data_length = 0;
- u8 *data = NULL;
-
- dbg_assert_ptr(user_data);
- dbg_assert_ptr(message);
- dbg_assert(2 == length);
-
- diag_write_string("=> interface_hle_send\n");
- data = (u8 *)message[1];
- data_length = swap16(read_u16_from_word(data + INTERFACE_FCALL_PAYLOAD_OFFSET - sizeof(u16))) + INTERFACE_FCALL_PAYLOAD_OFFSET;
- if ((len = write(proto_out_fd, data, data_length)) < 0)
- {
- diag_write_string("error when writing proto out file\n");
- return;
- }
- dbg_assert(len == data_length);
- diag_printf("WRITE len = %d - data length = %d\n", len, data_length);
- diag_write_string("END interface_hle_send\n");
-
- free(data);
- return;
-}
-
-void
-my_interface_hle_send_done (void *user_data, u8 *message)
-{
- dbg_assert_ptr(user_data);
- dbg_assert_ptr(message);
-
- diag_write_string("=> interface_hle_send_done\n");
- free(message);
- diag_write_string("END interface_hle_send_done\n");
-
- return;
-}
-
-u8 *
-my_interface_fcall_get_buffer_cb (void *user_data)
-{
- u8 *buffer;
- buffer = malloc(SCI_MSG_MAX_SIZE);
- return buffer;
-}
-
typedef struct my_struct
{
int i1;
@@ -304,14 +257,9 @@ my_function5 (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *
void
cyg_user_start(void)
{
- int user_data = 123;
memset (&mac_config, 0, sizeof (mac_config_t));
- ctx = interface_fcall_init (&my_interface_hle_send,
- &my_interface_hle_send_done,
- &my_interface_fcall_get_buffer_cb,
- &user_data,
- &mac_config);
+ ctx = interface_fcall_init (INVALID_PTR, &mac_config, INVALID_PTR);
fcall_register(ctx->fcall_ctx, "function_1", (void*)&my_function1, NULL);
fcall_register(ctx->fcall_ctx, "function_2", (void*)&my_function2, NULL);
@@ -363,3 +311,38 @@ cyg_user_start(void)
return;
}
+
+void
+cl_mbx_ipmbox_send (cl_mbx_t *ctx, u8 *buffer, uint length)
+{
+ int len = 0;
+ dbg_assert_ptr (buffer);
+ diag_write_string("=> cl_mbx_ipmbox_send\n");
+ if ((len = write (proto_out_fd, buffer, length)) < 0)
+ {
+ diag_write_string("error when writing proto out file\n");
+ return;
+ }
+ dbg_assert(len == length);
+ diag_printf("WRITE len = %d - data length = %d\n", len, length);
+ diag_write_string("END cl_mbx_ipmbox_send\n");
+ free (buffer);
+}
+
+void
+bufmgr_give_back (bufmgr_t *ctx, u8 *buffer)
+{
+ dbg_assert_ptr (buffer);
+
+ diag_write_string("=> bufmgr_give_back\n");
+ free (buffer);
+ diag_write_string("END bufmgr_give_back\n");
+}
+
+u8*
+bufmgr_get_wait (bufmgr_t *ctx, uint delay_rtc)
+{
+ u8 *buffer;
+ buffer = malloc(SCI_MSG_MAX_SIZE);
+ return buffer;
+}
diff --git a/cesar/maximus/prototest/integration/Makefile b/cesar/maximus/prototest/integration/Makefile
index 716d75895a..440c19a932 100644
--- a/cesar/maximus/prototest/integration/Makefile
+++ b/cesar/maximus/prototest/integration/Makefile
@@ -7,6 +7,6 @@ TARGET = sparc
TARGET_PROGRAMS = test_integration
test_integration_SOURCES = test_integration.c cl_stub.c
-test_integration_MODULES = lib hal/phy interface hal/hle hle mac host
+test_integration_MODULES = lib hal/phy hal/ipmbox mac host
include $(BASE)/common/make/top.mk
diff --git a/cesar/maximus/prototest/integration/src/cl_stub.c b/cesar/maximus/prototest/integration/src/cl_stub.c
index 9b65288d2f..c55ac6a5fe 100644
--- a/cesar/maximus/prototest/integration/src/cl_stub.c
+++ b/cesar/maximus/prototest/integration/src/cl_stub.c
@@ -28,35 +28,10 @@ void cl_uninit (cl_t *ctx)
{
}
-void cl_mme_ul_init_send_done (cl_t *ctx, cl_mme_ul_recv_done_cb_t cb,
- void *user)
-{
- dbg_assert (ctx);
- dbg_assert (cb);
-
- ctx->mme.ul_mme_recv_done = cb;
- ctx->mme.ul_mme_recv_done_user_data = user;
-}
-
void cl_mme_recv_init (cl_t *ctx, cl_mme_recv_cb_t mme_recv_cb, void *user)
{
}
-void cl_mme_init_ul_as_data (cl_t *ctx, cl_mme_ul_send_done_cb_t cb,
- void *user)
-{
-}
-
-void cl_mme_init_buffer_add_cb (cl_t *cl, cl_mme_buffer_add_cb_t cb,
- void *user_data)
-{
-}
-
-
-void cl_mme_send_as_mme (cl_t *ctx, u8 *buffer, uint length, mfs_tx_t *mfs)
-{
-}
-
void cl_mme_send_as_data (cl_t *ctx, u8 *buffer, uint length)
{
}
@@ -70,19 +45,6 @@ void cl_mme_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs, bool
{
}
-void cl_mme_recv_done (cl_t *ctx, cl_mme_recv_t *mme_recv)
-{
-}
-
-void cl_data_send_done_init (cl_t *cl, cl_data_send_done_cb_t cb, void *user)
-{
- dbg_assert (cl);
- dbg_assert (cb);
-
- cl->data_tx.cb = cb;
- cl->data_tx.user = user;
-}
-
void cl_data_send_done (cl_t *ctx, u8 *buffer)
{
}
@@ -93,12 +55,6 @@ void cl_data_send (cl_t *cl, u8 *buffer, uint length)
dbg_assert (buffer);
}
-void cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user)
-{
- dbg_assert (cl);
- dbg_assert (cb);
-}
-
void cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
{
}
diff --git a/cesar/maximus/prototest/integration/src/test_integration.c b/cesar/maximus/prototest/integration/src/test_integration.c
index 87c79e92cc..2078d7b783 100644
--- a/cesar/maximus/prototest/integration/src/test_integration.c
+++ b/cesar/maximus/prototest/integration/src/test_integration.c
@@ -16,7 +16,6 @@
#include <cyg/kernel/kapi.h>
#include <errno.h>
#include "common/std.h"
-#include "hle/hle.h"
#include "interface/interface.h"
#include "interface/inc/context.h"
#include "interface/fcall/interface_fcall.h"
diff --git a/cesar/maximus/python/lib/cesar/sta_cesar.py b/cesar/maximus/python/lib/cesar/sta_cesar.py
index b6fae30390..7f7e2a7d5f 100644
--- a/cesar/maximus/python/lib/cesar/sta_cesar.py
+++ b/cesar/maximus/python/lib/cesar/sta_cesar.py
@@ -9,9 +9,7 @@ def STACesar(maximus,\
seed = 0xFFFFFFFF,\
debug = False,\
name = None,\
- data_buffer_nb=0,\
- mme_buffer_nb=1,\
- interface_buffer_nb=0,\
+ buffer_nb=1,\
config_mode = 'MME',\
config = Config()):
"""This function creates a STA object with the given arguments,
@@ -23,8 +21,6 @@ def STACesar(maximus,\
seed = seed,\
debug = debug,\
name = name,\
- data_buffer_nb=data_buffer_nb,\
- mme_buffer_nb=mme_buffer_nb,\
- interface_buffer_nb=3,\
+ buffer_nb=buffer_nb + 3,\
config_mode = config_mode,\
config = config)
diff --git a/cesar/maximus/python/lib/proto/maximus_proto.py b/cesar/maximus/python/lib/proto/maximus_proto.py
index 98b9a9ebdd..1cfbc8ce27 100644
--- a/cesar/maximus/python/lib/proto/maximus_proto.py
+++ b/cesar/maximus/python/lib/proto/maximus_proto.py
@@ -334,11 +334,11 @@ class MaximusProto:
else:
os.write(self.write_file, msdu.get())
- def set_msdu_rx(self, user_cb, create_eth_function, create_mme_function, create_buffer_function, create_sniffer_function):
+ def set_msdu_rx(self, user_cb, create_eth_function, create_mme_function, create_buffer_function):
"""XXX"""
self.msdu_recv_cb = user_cb
- def set_msdu_rx_catch_all (self, user_cb, create_eth_function, create_mme_function, create_buffer_function, create_sniffer_function):
+ def set_msdu_rx_catch_all (self, user_cb, create_eth_function, create_mme_function, create_buffer_function):
"""XXX"""
self.msdu_recv_catch_all_cb = user_cb
diff --git a/cesar/maximus/python/maximus/ethernet/__init__.py b/cesar/maximus/python/maximus/ethernet/__init__.py
index fa21730e37..b0040e745a 100644
--- a/cesar/maximus/python/maximus/ethernet/__init__.py
+++ b/cesar/maximus/python/maximus/ethernet/__init__.py
@@ -4,7 +4,7 @@
#__all__ = ["buffer", "create", "eth", "scapy"]
-from buffer import alloc_data_buffer, alloc_mme_buffer, alloc_interface_buffer, realloc_buffer, get_buffer_dict
+from buffer import alloc_buffer, realloc_buffer, get_buffer_dict
from eth import Eth
from scapy import *
from maximus.macframe.msdu import MSDU_TYPES
diff --git a/cesar/maximus/python/maximus/ethernet/buffer.py b/cesar/maximus/python/maximus/ethernet/buffer.py
index 3b99058ef5..75a9ef0192 100644
--- a/cesar/maximus/python/maximus/ethernet/buffer.py
+++ b/cesar/maximus/python/maximus/ethernet/buffer.py
@@ -38,9 +38,7 @@ class Buffer(MSDU):
def set_type(self, type):
"""This function sets the Buffer object type.
The Buffer type can be a Python integer (u8)
- or a Python string equals to 'ETHERNET_TYPE_DATA_BUFFER_ADD',
- 'ETHERNET_TYPE_MME_BUFFER_ADD',
- 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',
+ or a Python string equals to 'ETHERNET_TYPE_BUFFER_ADD'
or 'ETHERNET_TYPE_BUFFER_RELEASED'.
"""
self.__type = 0
@@ -138,10 +136,8 @@ class Buffer(MSDU):
def get_type(self):
"""This function returns the Buffer object type into a Python string.
"""
- return MSDU_TYPES[self.get_ether_type()] # 'ETHERNET_TYPE_DATA_BUFFER_ADD',
- # 'ETHERNET_TYPE_MME_BUFFER_ADD',
- # 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',
- # or 'ETHERNET_TYPE_BUFFER_RELEASED'
+ return MSDU_TYPES[self.get_ether_type()] # 'ETHERNET_TYPE_BUFFER_ADD'
+ # or 'ETHERNET_TYPE_BUFFER_RELEASED'.
def get_buffer_nb(self):
"""This function gets the number of buffers to allocate.
@@ -171,17 +167,8 @@ class Buffer(MSDU):
raise Error("Maximus object not set")
return self.__class__.__maximus
-
-def alloc_data_buffer(maximus, station, buffer_nb=1):
- buffer = Buffer(type='ETHERNET_TYPE_DATA_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
- buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
-
-def alloc_mme_buffer(maximus, station, buffer_nb=1):
- buffer = Buffer(type='ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
- buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
-
-def alloc_interface_buffer(maximus, station, buffer_nb=1):
- buffer = Buffer(type='ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
+def alloc_buffer(maximus, station, buffer_nb=1):
+ buffer = Buffer(type='ETHERNET_TYPE_BUFFER_ADD', buffer_nb=buffer_nb, maximus=maximus)
buffer.sendnrecv(maximus, station, count=0) # recv(maximus, count=0) to set creation functions
def realloc_buffer(auto):
diff --git a/cesar/maximus/python/maximus/ethernet/create.py b/cesar/maximus/python/maximus/ethernet/create.py
index edbb700df9..557375fea4 100644
--- a/cesar/maximus/python/maximus/ethernet/create.py
+++ b/cesar/maximus/python/maximus/ethernet/create.py
@@ -4,7 +4,6 @@
from maximus.ethernet.buffer import Buffer
from maximus.ethernet.eth import Eth
-from maximus.ethernet.sniffer import Sniffer
def create_eth():
"""This function creates and returns a new Eth object.
@@ -15,8 +14,3 @@ def create_buffer():
"""This function creates and returns a new Buffer object.
"""
return Buffer('ETHERNET_TYPE_BUFFER_RELEASED')
-
-def create_sniffer():
- """This function creates and returns a new Sniffer object.
- """
- return Sniffer()
diff --git a/cesar/maximus/python/maximus/ethernet/sniffer.py b/cesar/maximus/python/maximus/ethernet/sniffer.py
deleted file mode 100644
index 61140be067..0000000000
--- a/cesar/maximus/python/maximus/ethernet/sniffer.py
+++ /dev/null
@@ -1,60 +0,0 @@
-#! usr/bin/env python
-
-#print __name__
-
-from maximus.macframe.msdu import MSDU_TYPES, MSDU
-from maximus.utils.exception import Error, OutOfRangeError
-from maximus.utils.format import *
-
-class Sniffer(MSDU):
- """The Sniffer object is composed of the following field:
- packet - a Python string
- """
-
- def __init__(self):
- self.__packet = None
-
- def set_msdu_attr(self, payload):
- """This function sets the MSDU attributes from the received Ethernet Frame.
- """
- if type(payload) is not str:
- raise TypeError("Packet")
- else:
- self.__packet = payload
-
- def sendnrecv(self, maximus, station, file=None, timeout=None, filter=None, count=1):
- raise Error("Cannot call this function for a sniffed Ethernet Frame")
-
- def send(self, maximus, station, file=None):
- raise Error("Cannot call this function for a sniffed Ethernet Frame")
-
- def get(self):
- """This function returns the sniffed packet into a string.
- """
- return self.__packet
-
- def get_ether_type(self):
- """This function returns the Sniffer object type into a Python integer (u8).
- """
- ether_type = None
- for i in range (0,len(MSDU_TYPES)):
- if MSDU_TYPES[i] == self.get_type():
- ether_type = i
- return ether_type # 7
-
- def get_type(self):
- """This function returns the Sniffer object type into a Python string.
- """
- return 'ETHERNET_TYPE_SNIFFER'
-
- def display(self):
- """This function displays the sniffed Ethernet Frame.
- """
- print "display the sniffed Ethernet Frame"
- print "packet =",
- if self.get() is not None:
- for c in self.get():
- print hex(ntoh8(c)),
- print
- else:
- print self.get()
diff --git a/cesar/maximus/python/maximus/macframe/msdu.py b/cesar/maximus/python/maximus/macframe/msdu.py
index 60ddcf9502..c2307fb71c 100644
--- a/cesar/maximus/python/maximus/macframe/msdu.py
+++ b/cesar/maximus/python/maximus/macframe/msdu.py
@@ -13,11 +13,8 @@ MAX_SIZE_OF_MSDU = 1518 # in octets
MSDU_TYPES = ['ETHERNET_TYPE_NONE',\
'ETHERNET_TYPE_DATA',\
'ETHERNET_TYPE_MME',\
- 'ETHERNET_TYPE_DATA_BUFFER_ADD',\
- 'ETHERNET_TYPE_MME_BUFFER_ADD',\
- 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD',\
- 'ETHERNET_TYPE_BUFFER_RELEASED',\
- 'ETHERNET_TYPE_SNIFFER']
+ 'ETHERNET_TYPE_BUFFER_ADD',\
+ 'ETHERNET_TYPE_BUFFER_RELEASED']
class MSDU:
diff --git a/cesar/maximus/python/maximus/mme/mme.py b/cesar/maximus/python/maximus/mme/mme.py
index 567383ffb0..d0323b660d 100644
--- a/cesar/maximus/python/maximus/mme/mme.py
+++ b/cesar/maximus/python/maximus/mme/mme.py
@@ -1,15 +1,12 @@
#! usr/bin/env python
-#print __name__
-VS_SNIFFER_REQ=0xA02C
-
from maximus.mme.mmentry import MAX_SIZE_OF_MMENTRY, MMEntry
-from maximus.mme.mmheader import MMHeader, MIN_SIZE_OF_MMHEADER, MAX_SIZE_OF_MMHEADER,\
- SIZE_OF_ODA, SIZE_OF_OSA,\
- SIZE_OF_VLANTAG, MIN_VALUE_OF_VLANTAG, MAX_VALUE_OF_VLANTAG
+from maximus.mme.mmheader import MMHeader, MIN_SIZE_OF_MMHEADER, \
+ MAX_SIZE_OF_MMHEADER, SIZE_OF_ODA, SIZE_OF_OSA, SIZE_OF_VLANTAG, \
+ MIN_VALUE_OF_VLANTAG, MAX_VALUE_OF_VLANTAG, SIZE_OF_MMTYPE, SIZE_OF_FMI
from maximus.macframe.msdu import MIN_SIZE_OF_MSDU_ALLOWED, MSDU_TYPES, MSDU
from maximus.utils.exception import OutOfRangeError
-from maximus.utils.format import ntoh32
+from maximus.utils.format import ntoh32, hptoh16
# Define an empty MME structure for Maximus
class MMEStruct:
@@ -101,6 +98,14 @@ class MME(MSDU):
"""
return self.__mmentry
+ def get_mmtype (self):
+ """Get the MM Type.
+ This function returns the MM Type as a Python integer.
+ """
+ return hptoh16 (self.get_mmheader ()
+ [MIN_SIZE_OF_MMHEADER - SIZE_OF_FMI - SIZE_OF_MMTYPE:\
+ MIN_SIZE_OF_MMHEADER - SIZE_OF_FMI])
+
def get(self):
"""This function returns the MME into a string.
"""
diff --git a/cesar/maximus/python/maximus/simu/rx.py b/cesar/maximus/python/maximus/simu/rx.py
index 7468d91059..76af2dbd8a 100644
--- a/cesar/maximus/python/maximus/simu/rx.py
+++ b/cesar/maximus/python/maximus/simu/rx.py
@@ -2,7 +2,7 @@
#print __name__
-from maximus.ethernet.create import create_eth, create_buffer, create_sniffer
+from maximus.ethernet.create import create_eth, create_buffer
from maximus.macframe.create import create_pb
from maximus.mme.create import create_mme
@@ -49,10 +49,10 @@ class Rx:
if cb_catch_all is None:
self.__cb = GenericCallback(cb, self)
self.__maximus.set_mpdu_rx(self.__cb, create_pb)
- self.__maximus.set_msdu_rx(self.__cb, create_eth, create_mme, create_buffer, create_sniffer)
+ self.__maximus.set_msdu_rx(self.__cb, create_eth, create_mme, create_buffer)
else:
self.__cb_catch_all = GenericCallback (cb_catch_all)
- self.__maximus.set_msdu_rx_catch_all (self.__cb_catch_all, create_eth, create_mme, create_buffer, create_sniffer)
+ self.__maximus.set_msdu_rx_catch_all (self.__cb_catch_all, create_eth, create_mme, create_buffer)
def recv(self, timeout=None):
"""This function only returns when the response defined by user is received,
diff --git a/cesar/maximus/python/maximus/station/sta.py b/cesar/maximus/python/maximus/station/sta.py
index 0ebd563451..047606788b 100644
--- a/cesar/maximus/python/maximus/station/sta.py
+++ b/cesar/maximus/python/maximus/station/sta.py
@@ -3,12 +3,11 @@
#print __name__
from maximus.station.config import *
-from maximus.ethernet.buffer import alloc_data_buffer, alloc_mme_buffer, alloc_interface_buffer
+from maximus.ethernet.buffer import alloc_buffer
from maximus.macframe.msdu import MSDU_TYPES
from maximus.macframe.mpdu import MPDU_TYPES
from maximus.mme import *
from maximus.mme.mmentry import MAX_SIZE_OF_MMENTRY
-from maximus.mme.mmheader import MIN_SIZE_OF_MMHEADER, SIZE_OF_MMTYPE, SIZE_OF_FMI
from maximus.utils.exception import Error, OutOfRangeError
from maximus.utils.format import *
@@ -50,14 +49,12 @@ def data_pad (data, length):
def mme_filter(rsp):
if rsp.get_type() is MSDU_TYPES[2]: # ETHERNET_TYPE_MME
# Check that received MME is an answer to a driver MME sent to the station
- mmtype = hptoh16(rsp.get_mmheader()[MIN_SIZE_OF_MMHEADER - SIZE_OF_FMI - SIZE_OF_MMTYPE:MIN_SIZE_OF_MMHEADER - SIZE_OF_FMI])
+ mmtype = rsp.get_mmtype ()
if mmtype >= DRV_MIN and mmtype <= DRV_MAX:
return True
else:
return False
- elif rsp.get_type() is MSDU_TYPES[6]: # ETHERNET_TYPE_BUFFER_RELEASED
- return False
- elif rsp.get_type() is MSDU_TYPES[7]: # ETHERNET_TYPE_SNIFFER
+ elif rsp.get_type() is MSDU_TYPES[4]: # ETHERNET_TYPE_BUFFER_RELEASED
return False
elif rsp.get_type() is MPDU_TYPES[3]: # PHY_TYPE_MPDU_PAYLOAD
return False
@@ -70,9 +67,7 @@ class STA:
maximus - a Maximus object
station - a Sta object
name - a Python string
- data_buffer_nb - a Python integer
- mme_buffer_nb - a Python integer
- interface_buffer_nb - a Python integer
+ buffer_nb - a Python integer
mme_config - a Python boolean
mac_address - a Python tuple of 6 Python integers
cco_preference - a Python boolean
@@ -92,9 +87,7 @@ class STA:
seed=0xFFFFFFFF,\
debug=False,\
name=None,\
- data_buffer_nb=0,\
- mme_buffer_nb=1,\
- interface_buffer_nb=0,\
+ buffer_nb=1,\
config_mode=CONFIG_MODES[0],\
config=Config()):
"""Initialize the STA with following attributes:
@@ -103,9 +96,7 @@ class STA:
seed - a Python integer
debug - a Python boolean
name - a Python string
- data_buffer_nb - a Python integer
- mme_buffer_nb - a Python integer
- interface_buffer_nb - a Python integer
+ buffer_nb - a Python integer
config_mode - a Python string
config - a Python Config object
"""
@@ -126,9 +117,7 @@ class STA:
# Set station configuration
if not self.__proto:
- self.set_data_buffer_nb(data_buffer_nb)
- self.set_mme_buffer_nb(mme_buffer_nb)
- self.set_interface_buffer_nb(interface_buffer_nb)
+ self.set_buffer_nb(buffer_nb)
self.set_config_mode(config_mode)
self.set_config(config)
@@ -211,53 +200,21 @@ class STA:
if self.get_name() is not None:
self.get().set_name(name)
- def set_data_buffer_nb(self, data_buffer_nb):
- """Set the number of data buffers to allocate into the station.
- The number of data buffers must be a Python integer.
+ def set_buffer_nb(self, buffer_nb):
+ """Set the number of buffers to allocate into the station.
+ The number of buffers must be a Python integer.
"""
- if type(data_buffer_nb) is int:
- if data_buffer_nb >= 0:
- self.__data_buffer_nb = data_buffer_nb
+ if type(buffer_nb) is int:
+ if buffer_nb >= 0:
+ self.__buffer_nb = buffer_nb
else:
- raise OutOfRangeError("Number of data buffers")
+ raise OutOfRangeError("Number of buffers")
else:
raise TypeError
- # Allocate data buffers
- if data_buffer_nb > 0:
- alloc_data_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=data_buffer_nb)
-
- def set_mme_buffer_nb(self, mme_buffer_nb):
- """Set the number of MME buffers to allocate into the station.
- The number of MME buffers must be a Python integer.
- """
- if type(mme_buffer_nb) is int:
- if mme_buffer_nb >= 0:
- self.__mme_buffer_nb = mme_buffer_nb
- else:
- raise OutOfRangeError("Number of MME buffers")
- else:
- raise TypeError
-
- # Allocate MME buffers
- if mme_buffer_nb > 0:
- alloc_mme_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=mme_buffer_nb)
-
- def set_interface_buffer_nb(self, interface_buffer_nb):
- """Set the number of interface buffers to allocate into the station.
- The number of interface buffers must be a Python integer.
- """
- if type(interface_buffer_nb) is int:
- if interface_buffer_nb >= 0:
- self.__interface_buffer_nb = interface_buffer_nb
- else:
- raise OutOfRangeError("Number of interface buffers")
- else:
- raise TypeError
-
- # Allocate interface buffers
- if interface_buffer_nb > 0:
- alloc_interface_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=interface_buffer_nb)
+ # Allocate buffers
+ if buffer_nb > 0:
+ alloc_buffer(maximus=self.__get_maximus(), station=self.get(), buffer_nb=buffer_nb)
def set_config_mode(self, config_mode):
"""Set the configuration mode.
@@ -557,23 +514,11 @@ class STA:
"""
return self.__name
- def get_data_buffer_nb(self):
- """Get the number of data buffers allocated into the station.
- The number of data buffers is a Python integer.
- """
- return self.__data_buffer_nb
-
- def get_mme_buffer_nb(self):
- """Get the number of MME buffers allocated into the station.
- The number of MME buffers is a Python integer.
- """
- return self.__mme_buffer_nb
-
- def get_interface_buffer_nb(self):
- """Get the number of interface buffers allocated into the station.
- The number of interface buffers is a Python integer.
+ def get_buffer_nb(self):
+ """Get the number of buffers allocated into the station.
+ The number of buffers is a Python integer.
"""
- return self.__interface_buffer_nb
+ return self.__buffer_nb
def get_config_mode(self):
"""Get the configuration mode.
@@ -1086,7 +1031,7 @@ class STA:
def __check_cnf(self, rsp, name):
"""Check the MME response validity.
"""
- mmtype = hptoh16(rsp[0].get_mmheader()[MIN_SIZE_OF_MMHEADER - SIZE_OF_FMI - SIZE_OF_MMTYPE:MIN_SIZE_OF_MMHEADER - SIZE_OF_FMI])
+ mmtype = rsp[0].get_mmtype ()
if mmtype == name + MME_TYPES['CNF']:
result = hptoh8(rsp[0].get_mmentry()[0])
if result == FAILURE:
diff --git a/cesar/maximus/python/py/test_ether.py b/cesar/maximus/python/py/test_ether.py
index dee71f231d..ddfa204074 100644
--- a/cesar/maximus/python/py/test_ether.py
+++ b/cesar/maximus/python/py/test_ether.py
@@ -15,6 +15,9 @@ from maximus.macframe.msdu import MIN_SIZE_OF_MSDU
from maximus.simu.rx import * # for 'recv()' function
from struct import pack
+# Constants to check argument validity
+HPAV_MMTYPE_OFFSET = 15 # in octets
+
m = Maximus()
m.init(sys.argv)
@@ -48,6 +51,10 @@ type = 0x4F50
# MME config
mmheader = 'MMHeader 19 octets!'
mmentry = '--- This is the Management Message Entry ---'
+expected_mmheader = mmheader[0:HPAV_MMTYPE_OFFSET] + \
+ htohp8 (hptoh8 (mmheader[HPAV_MMTYPE_OFFSET]) + 1) + \
+ mmheader[HPAV_MMTYPE_OFFSET + 1:]
+expected_mmentry = '\0'
# Send an Ethernet Frame asynchronously
frame1 = Eth()
@@ -57,12 +64,12 @@ frame1.vlantag = vlantag
frame1.type = type
msdu1 = 'This is the Ethernet payload'
frame1.payload = msdu1
-alloc_data_buffer(m, sta1, buffer_nb=2)
+alloc_buffer(m, sta1, buffer_nb=1)
frame1.send(m, sta1)
-rsp1 = recv(m, count=4)
+rsp1 = recv(m, count=2)
# Test the 1st received MSDU (Eth) object
-i = 0
+i = 0 # the second received frame is the BUFFER RELEASED message
if rsp1[i].dst != dst:
print "dst1 =", rsp1[i].dst
raise Error("dst1")
@@ -80,15 +87,6 @@ if str(rsp1[i].payload) != msdu1:
print "msdu1 =", str(rsp1[i].payload)
raise Error("msdu1")
-# Test the 2nd received MSDU (MME) object
-i = 2 # i = 2 because the second received frame is the BUFFER RELEASED message
-if rsp1[i].get_mmheader() != 'ABCDEFGHIJKL' + pack('!I', vlantag) + 'OPThis ':
- print "mmheader1 =", rsp1[i].get_mmheader()
- raise Error("mmheader1")
-if rsp1[i].get_mmentry() != 'is the Ethernet payload':
- print "mmentry1 =", rsp1[i].get_mmentry()
- raise Error("mmentry1")
-
m.wait(100000)
# Send an Ethernet Frame synchronously
@@ -99,11 +97,11 @@ frame2.vlantag = vlantag
frame2.type = type
msdu2 = 'This is the Ethernet payload'
frame2.payload = msdu2
-alloc_data_buffer(m, sta1, buffer_nb=2)
-rsp2 = frame2.sendnrecv(m, sta1, count=4)
+alloc_buffer(m, sta1, buffer_nb=1)
+rsp2 = frame2.sendnrecv(m, sta1, count=2)
# Test the 1st received MSDU (Eth) object
-i = 0
+i = 0 # the second received frame is the BUFFER RELEASED message
if rsp2[i].dst != dst:
print "dst2 =", rsp2[i].dst
raise Error("dst2")
@@ -120,44 +118,20 @@ if str(rsp2[i].payload) != msdu2:
print "msdu2 =", str(rsp2[i].payload)
raise Error("msdu2")
-# Test the 2nd received MSDU (MME) object
-i = 2 # i = 2 because the second received frame is the BUFFER RELEASED message
-if rsp2[i].get_mmheader() != 'ABCDEFGHIJKL' + pack('!I', vlantag) + 'OPThis ':
- print "mmheader2 =", rsp2[i].get_mmheader()
- raise Error("mmheader2")
-if rsp2[i].get_mmentry() != 'is the Ethernet payload':
- print "mmentry2 =", rsp2[i].get_mmentry()
- raise Error("mmentry2")
-
m.wait(100000)
# Send an MME asynchronously
mme3 = MME(MMHeader=mmheader, MMEntry=mmentry)
-alloc_data_buffer(m, sta1, buffer_nb=2)
+alloc_buffer(m, sta1, buffer_nb=1)
mme3.send(m, sta1)
-rsp3 = recv(m, count=4)
+rsp3 = recv(m, count=2)
-# Test the 1st received MSDU (Eth) object
-i = 0
-if rsp3[i].dst != '4d:4d:48:65:61:64': # 'MMHead'
- print "dst3 =", rsp3[i].dst
- raise Error("dst3")
-if rsp3[i].src != '65:72:20:31:39:20': # 'er 19 '
- print "src3 =", rsp3[i].src
- raise Error("src3")
-if rsp3[i].type != 0x6F63: # 'oc'
- print "type3 =", hex(rsp3[i].type)
- raise Error("type3")
-if str(rsp3[i].payload) != 'tets!--- This is the Management Message Entry ---':
- print "msdu3 =", str(rsp3[i].payload)
- raise Error("msdu3")
-
-# Test the 2nd received MSDU (MME) object
-i = 2 # i = 2 because the second received frame is the BUFFER RELEASED message
-if rsp3[i].get_mmheader() != mmheader:
+# Test the 1st received MSDU (MME) object
+i = 0 # the second received frame is the BUFFER RELEASED message
+if rsp3[i].get_mmheader() != expected_mmheader:
print "mmheader3 =", rsp3[i].get_mmheader()
- raise Error("mmheader3")
-if rsp3[i].get_mmentry() != mmentry:
+ raise Error("mmheader")
+if rsp3[i].get_mmentry() != expected_mmentry:
print "mmentry3 =", rsp3[i].get_mmentry()
raise Error("mmentry3")
@@ -165,49 +139,20 @@ m.wait(100000)
# Send an MME synchronously
mme4 = MME(MMHeader=mmheader, MMEntry=mmentry)
-alloc_data_buffer(m, sta1, buffer_nb=2)
-rsp4 = mme4.sendnrecv(m, sta1, count=4)
+alloc_buffer(m, sta1, buffer_nb=1)
+rsp4 = mme4.sendnrecv(m, sta1, count=2)
# Test the 1st received MSDU (Eth) object
-i = 0
-if rsp4[i].dst != '4d:4d:48:65:61:64': # 'MMHead'
- print "dst4 =", rsp4[i].dst
- raise Error("dst4")
-if rsp4[i].src != '65:72:20:31:39:20': # 'er 19 '
- print "src4 =", rsp4[i].src
- raise Error("src4")
-if rsp4[i].type != 0x6F63: # 'oc'
- print "type4 =", hex(rsp4[i].type)
- raise Error("type4")
-if str(rsp4[i].payload) != 'tets!--- This is the Management Message Entry ---':
- print "msdu4 =", str(rsp4[i].payload)
- raise Error("msdu4")
-
-# Test the 2nd received MSDU (MME) object
-i = 2 # i = 2 because the second received frame is the BUFFER RELEASED message
-if rsp4[i].get_mmheader() != mmheader:
+i = 0 # the second received frame is the BUFFER RELEASED message
+if rsp4[i].get_mmheader() != expected_mmheader:
print "mmheader4 =", rsp4[i].get_mmheader()
raise Error("mmheader4")
-if rsp4[i].get_mmentry() != mmentry:
+if rsp4[i].get_mmentry() != expected_mmentry:
print "mmentry4 =", rsp4[i].get_mmentry()
raise Error("mmentry4")
m.wait(100000)
-# Test the sniffed received MSDU (Sniffer) object
-alloc_interface_buffer(m, sta1)
-snif = recv(m, count=2)[0] # the second received frame is the BUFFER RELEASED message
-snif.display()
-if snif.get()[0:48] != "This is a sniffed packet coming from the station":
- print "packet =", snif.get()
- raise Error("packet")
-if snif.get_ether_type() != 7:
- print "ether type =", snif.get_ether_type()
- raise Error("ether type")
-if snif.get_type() != 'ETHERNET_TYPE_SNIFFER':
- print "type =", snif.get_type()
- raise Error("type")
-
# Uninit ether
fcall2 = m.create_fcall('uninit_ether')
fcall2.send(sta1)
diff --git a/cesar/maximus/python/src/interface_module.cpp b/cesar/maximus/python/src/interface_module.cpp
index 5503a36a45..877a6f7f87 100644
--- a/cesar/maximus/python/src/interface_module.cpp
+++ b/cesar/maximus/python/src/interface_module.cpp
@@ -59,7 +59,6 @@ typedef struct rx_param_ether
object create_eth;
object create_mme;
object create_buffer;
- object create_sniffer;
object cb;
object catch_all_cb;
bool activated;
@@ -171,8 +170,7 @@ void recv_ether_cb ( EtherSciMsg & ether )
logFunction();
if ( (ETHERNET_TYPE_DATA == ether.getSpecializedSciMsgType())
- || (ETHERNET_TYPE_MME == ether.getSpecializedSciMsgType())
- || (ETHERNET_TYPE_SNIFFER == ether.getSpecializedSciMsgType()) )
+ || (ETHERNET_TYPE_MME == ether.getSpecializedSciMsgType()))
{
// Log the received Ether SCI message
log_ether(ether);
@@ -185,7 +183,7 @@ void recv_ether_cb ( EtherSciMsg & ether )
// Get Ethernet SCI message attributes
string payload((char *)ether.getSpecializedSciMsgData(), ether.getSpecializedSciMsgDataLength());
- // Create a new MSDU Python object (Eth, MME, Buffer or Sniffer)
+ // Create a new MSDU Python object (Eth, MME, or Buffer)
object rx_msdu;
if (ETHERNET_TYPE_DATA == ether.getSpecializedSciMsgType())
{
@@ -199,14 +197,10 @@ void recv_ether_cb ( EtherSciMsg & ether )
{
rx_msdu = ether_rx_param.create_buffer();
}
- else if (ETHERNET_TYPE_SNIFFER == ether.getSpecializedSciMsgType())
- {
- rx_msdu = ether_rx_param.create_sniffer();
- }
else
{
errno = ENOMSG;
- Error e(__PRETTY_FUNCTION__, "receive an Ether SCI message with a bad type (should be DATA, MME, BUFFER_RELEASED or SNIFFER)", errno);
+ Error e(__PRETTY_FUNCTION__, "receive an Ether SCI message with a bad type (should be DATA, MME or BUFFER_RELEASED)", errno);
e.display();
throw e;
}
@@ -541,8 +535,7 @@ void set_ether_rx_catch_all ( Maximus & m,
object user_cb,
object create_eth_function,
object create_mme_function,
- object create_buffer_function,
- object create_sniffer_function )
+ object create_buffer_function )
{
ether_rx_param.catch_all_cb = user_cb;
ether_rx_param.catch_all_activated = true;
@@ -551,7 +544,6 @@ void set_ether_rx_catch_all ( Maximus & m,
ether_rx_param.create_eth = create_eth_function;
ether_rx_param.create_mme = create_mme_function;
ether_rx_param.create_buffer = create_buffer_function;
- ether_rx_param.create_sniffer = create_sniffer_function;
ether_rx_param.is_create_set = true;
}
}
@@ -565,8 +557,7 @@ void set_ether_rx ( Maximus & m,
object user_cb,
object create_eth_function,
object create_mme_function,
- object create_buffer_function,
- object create_sniffer_function )
+ object create_buffer_function )
{
ether_rx_param.cb = user_cb;
ether_rx_param.activated = true;
@@ -575,7 +566,6 @@ void set_ether_rx ( Maximus & m,
ether_rx_param.create_eth = create_eth_function;
ether_rx_param.create_mme = create_mme_function;
ether_rx_param.create_buffer = create_buffer_function;
- ether_rx_param.create_sniffer = create_sniffer_function;
ether_rx_param.is_create_set = true;
}
}
diff --git a/cesar/maximus/python/test/test_ethernet.py b/cesar/maximus/python/test/test_ethernet.py
index 9a7762c5f0..d74c265718 100644
--- a/cesar/maximus/python/test/test_ethernet.py
+++ b/cesar/maximus/python/test/test_ethernet.py
@@ -6,10 +6,9 @@ import sys, startup
from maximus.ethernet import *
from maximus.ethernet.buffer import Buffer
-from maximus.ethernet.create import create_eth, create_buffer, create_sniffer
+from maximus.ethernet.create import create_eth, create_buffer
from maximus.ethernet.eth import MIN_SIZE_OF_HEADER, MAX_SIZE_OF_HEADER
from maximus.mme.mmheader import MIN_SIZE_OF_MMHEADER
-from maximus.ethernet.sniffer import Sniffer
from maximus.macframe.msdu import MIN_SIZE_OF_MSDU
from maximus.simu.rx import * # for 'recv()' function
from maximus.utils.exception import Error, OutOfRangeError
@@ -61,11 +60,11 @@ if h != (65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 8, 0, 69, 0, 0, 20, 0,
raise Error('Ethernet IP frame payload')
# Send the Ethernet frame asynchronously
-alloc_data_buffer(m, staRx, buffer_nb=2)
+alloc_buffer(m, staRx, buffer_nb=2)
f.send(m, staRx)
# Send the Ethernet frame synchronously
-alloc_data_buffer(m, staRx, buffer_nb=2)
+alloc_buffer(m, staRx, buffer_nb=2)
rsp = f.sendnrecv(m, staRx)
# Uninit ether
@@ -160,7 +159,6 @@ doctest.testmod(buffer)
doctest.testmod(create)
doctest.testmod(eth)
doctest.testmod(scapy)
-doctest.testmod(sniffer)
# UNIT TEST
@@ -204,39 +202,13 @@ class TestEthFunctions(unittest.TestCase):
# Disable the automatic buffer allocation
realloc_buffer(False)
- alloc_data_buffer(self.m, sta, buffer_nb=2)
- rsp = self.eth.sendnrecv(self.m, sta, count=4)
-
- # 1st received frame is the Ethernet frame
- self.assertEqual(rsp[0].dst, 'ff:ff:ff:ff:ff:ff')
- self.assertEqual(rsp[0].src, '00:00:00:00:00:00')
- self.assertEqual(rsp[0].type, 0)
-
- # 2nd and 4th received frames are BUFFER RELEASED messages
- self.assertEqual(rsp[1].get_ether_type(), 6)
- self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
- self.assertEqual(rsp[3].get_ether_type(), 6)
- self.assertEqual(rsp[3].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
- self.assertEqual(len(rsp[1].get_buffer_dict()), length)
+ alloc_buffer(self.m, sta, buffer_nb=2)
# Enable the automatic buffer allocation
realloc_buffer(True)
- alloc_data_buffer(self.m, sta, buffer_nb=2)
+ alloc_buffer(self.m, sta, buffer_nb=2)
length = len(none_buffer.get_buffer_dict())
- rsp = self.eth.sendnrecv(self.m, sta, count=4)
-
- # 1st received frame is the Ethernet frame
- self.assertEqual(rsp[0].dst, 'ff:ff:ff:ff:ff:ff')
- self.assertEqual(rsp[0].src, '00:00:00:00:00:00')
- self.assertEqual(rsp[0].type, 0)
-
- # 3rd and 4th received frames are BUFFER RELEASED messages
- self.assertEqual(rsp[2].get_ether_type(), 6)
- self.assertEqual(rsp[2].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
- self.assertEqual(rsp[3].get_ether_type(), 6)
- self.assertEqual(rsp[3].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
- self.assertEqual(len(rsp[3].get_buffer_dict()), length)
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
@@ -244,7 +216,7 @@ class TestEthFunctions(unittest.TestCase):
def test_send(self):
sta = self.m.create_sta()
self.m.create_fcall('init_ether').send(sta)
- alloc_data_buffer(self.m, sta, buffer_nb=2)
+ alloc_buffer(self.m, sta, buffer_nb=2)
self.eth.send(self.m, sta)
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
@@ -290,136 +262,93 @@ suite = unittest.TestLoader().loadTestsFromTestCase(TestEthFunctions)
class TestBufferFunctions(unittest.TestCase):
def setUp(self):
- self.data_buffer = Buffer('ETHERNET_TYPE_DATA_BUFFER_ADD')
- self.assertEqual(self.data_buffer.get_ether_type(), 3)
- self.assertEqual(self.data_buffer.get_type(), 'ETHERNET_TYPE_DATA_BUFFER_ADD')
- self.assertEqual(self.data_buffer.get_buffer_nb(), 1)
- self.mme_buffer = Buffer('ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=2)
- self.assertEqual(self.mme_buffer.get_ether_type(), 4)
- self.assertEqual(self.mme_buffer.get_type(), 'ETHERNET_TYPE_MME_BUFFER_ADD')
- self.assertEqual(self.mme_buffer.get_buffer_nb(), 2)
- self.interface_buffer = Buffer('ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=3)
- self.assertEqual(self.interface_buffer.get_ether_type(), 5)
- self.assertEqual(self.interface_buffer.get_type(), 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD')
- self.assertEqual(self.interface_buffer.get_buffer_nb(), 3)
+ self.buffers = Buffer('ETHERNET_TYPE_BUFFER_ADD', buffer_nb=8)
+ self.assertEqual(self.buffers.get_ether_type(), 3)
+ self.assertEqual(self.buffers.get_type(), 'ETHERNET_TYPE_BUFFER_ADD')
+ self.assertEqual(self.buffers.get_buffer_nb(), 8)
self.m = m
def tearDown(self):
pass
def test_set_type(self):
- self.data_buffer.set_type('ETHERNET_TYPE_BUFFER_RELEASED')
- self.assertEqual(self.data_buffer.get_ether_type(), 6)
- self.assertEqual(self.data_buffer.get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ self.buffers.set_type('ETHERNET_TYPE_BUFFER_RELEASED')
+ self.assertEqual(self.buffers.get_ether_type(), 4)
+ self.assertEqual(self.buffers.get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
try:
- self.mme_buffer.set_type('ETHERNET_TYPE_MME')
+ self.buffers.set_type('ETHERNET_TYPE_MME')
except OutOfRangeError:
- self.assertEqual(self.mme_buffer.get_ether_type(), 0)
- self.assertEqual(self.mme_buffer.get_type(), 'ETHERNET_TYPE_NONE')
+ self.assertEqual(self.buffers.get_ether_type(), 0)
+ self.assertEqual(self.buffers.get_type(), 'ETHERNET_TYPE_NONE')
def test_set_buffer_nb(self):
- self.data_buffer.set_buffer_nb(123)
- self.assertEqual(self.data_buffer.get_buffer_nb(), 123)
+ self.buffers.set_buffer_nb(123)
+ self.assertEqual(self.buffers.get_buffer_nb(), 123)
try:
- self.mme_buffer.set_buffer_nb(-123)
+ self.buffers.set_buffer_nb(-123)
except OutOfRangeError:
- self.assertEqual(self.mme_buffer.get_buffer_nb(), 0)
+ self.assertEqual(self.buffers.get_buffer_nb(), 0)
def test_set_buffer_realloc(self):
- self.assertEqual(self.data_buffer.get_buffer_realloc(), False)
- self.data_buffer.set_buffer_realloc(True)
- self.assertEqual(self.data_buffer.get_buffer_realloc(), True)
- self.data_buffer.set_buffer_realloc(False)
+ self.assertEqual(self.buffers.get_buffer_realloc(), False)
+ self.buffers.set_buffer_realloc(True)
+ self.assertEqual(self.buffers.get_buffer_realloc(), True)
+ self.buffers.set_buffer_realloc(False)
def test_realloc(self):
sta = self.m.create_sta()
self.m.create_fcall('init_ether').send(sta)
realloc_buffer(True)
buffer_id = 123
- self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_DATA_BUFFER_ADD'
- self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
- buffer_id = 456
- self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_MME_BUFFER_ADD'
- self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
- buffer_id = 789
- self.interface_buffer.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_INTERFACE_BUFFER_ADD'
- self.interface_buffer.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
- rsp = recv(self.m, count=2)
- self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
- self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ self.buffers.get_buffer_dict()[buffer_id] = 'ETHERNET_TYPE_BUFFER_ADD'
+ self.buffers.realloc(station_id=sta.get_station_id(), payload=pack('I', buffer_id))
realloc_buffer(False)
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
def test_set_msdu_attr(self):
id = 123
- self.assert_(self.data_buffer.get_buffer_dict().has_key(id))
- self.data_buffer.set_msdu_attr(pack('I', id))
- self.assert_(not self.data_buffer.get_buffer_dict().has_key(id))
+ self.assert_(self.buffers.get_buffer_dict().has_key(id))
+ self.buffers.set_msdu_attr(pack('I', id))
+ self.assert_(not self.buffers.get_buffer_dict().has_key(id))
def test_sendnrecv(self):
sta = self.m.create_sta()
self.m.create_fcall('init_ether').send(sta)
- interface_buffer = Buffer('ETHERNET_TYPE_INTERFACE_BUFFER_ADD', buffer_nb=2)
- rsp = interface_buffer.sendnrecv(self.m, sta, count=2)
- self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
- self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ buffers = Buffer('ETHERNET_TYPE_BUFFER_ADD', buffer_nb=2)
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
def test_send(self):
sta = self.m.create_sta()
self.m.create_fcall('init_ether').send(sta)
- mme_buffer = Buffer('ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=10)
- mme_buffer.send(self.m, sta)
+ buffers = Buffer('ETHERNET_TYPE_BUFFER_ADD', buffer_nb=10)
+ buffers.send(self.m, sta)
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
def test_get(self):
- mme_buffer = Buffer('ETHERNET_TYPE_MME_BUFFER_ADD', buffer_nb=3)
- buf = mme_buffer.get()
- res = pack('I', mme_buffer.get_buffer_nb())
+ buffers = Buffer('ETHERNET_TYPE_BUFFER_ADD', buffer_nb=3)
+ buf = buffers.get()
+ res = pack('I', buffers.get_buffer_nb())
for i in range (0, 3):
- res += pack('I', mme_buffer.get_buffer_id() - 2 + i)
+ res += pack('I', buffers.get_buffer_id() - 2 + i)
self.assertEqual(buf, res)
def test_create_buffer(self):
self.assertNotEqual(create_buffer(), None)
- def test_alloc_data_buffer(self):
- sta = self.m.create_sta()
- self.m.create_fcall('init_ether').send(sta)
- alloc_data_buffer(self.m, sta)
- self.m.create_fcall('uninit_ether').send(sta)
- sta.remove()
-
- def test_alloc_mme_buffer(self):
+ def test_alloc_buffer(self):
sta = self.m.create_sta()
self.m.create_fcall('init_ether').send(sta)
- alloc_mme_buffer(self.m, sta)
- self.m.create_fcall('uninit_ether').send(sta)
- sta.remove()
-
- def test_alloc_interface_buffer(self):
- sta = self.m.create_sta()
- self.m.create_fcall('init_ether').send(sta)
- realloc_buffer(True)
- alloc_interface_buffer(self.m, sta)
- rsp = recv(self.m, count=2)
- self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
- self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
- realloc_buffer(False)
- alloc_interface_buffer(self.m, sta)
- rsp = recv(self.m, count=2)
- self.assertEqual(rsp[0].get_type(), 'ETHERNET_TYPE_SNIFFER')
- self.assertEqual(rsp[1].get_type(), 'ETHERNET_TYPE_BUFFER_RELEASED')
+ alloc_buffer(self.m, sta)
self.m.create_fcall('uninit_ether').send(sta)
sta.remove()
def test_realloc_buffer(self):
- self.assertEqual(self.interface_buffer.get_buffer_realloc(), False)
+ self.assertEqual(self.buffers.get_buffer_realloc(), False)
realloc_buffer(True)
- self.assertEqual(self.interface_buffer.get_buffer_realloc(), True)
+ self.assertEqual(self.buffers.get_buffer_realloc(), True)
realloc_buffer(False)
def test_get_buffer_dict(self):
@@ -427,39 +356,11 @@ class TestBufferFunctions(unittest.TestCase):
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestBufferFunctions))
-class TestSnifferFunctions(unittest.TestCase):
-
- def setUp(self):
- self.sniffer = Sniffer()
- self.assertEqual(self.sniffer.get(), None)
- self.assertEqual(self.sniffer.get_ether_type(), 7)
- self.assertEqual(self.sniffer.get_type(), 'ETHERNET_TYPE_SNIFFER')
- self.m = m
-
- def tearDown(self):
- pass
-
- def test_set_msdu_attr(self):
- payload = "This is the sniffed packed"
- self.sniffer.set_msdu_attr(payload)
- self.assertEqual(self.sniffer.get(), payload)
-
- def test_display(self):
- self.sniffer.display()
- self.sniffer.set_msdu_attr("ABCD")
- self.sniffer.display()
-
- def test_create_sniffer(self):
- self.assertNotEqual(create_sniffer(), None)
-
-suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSnifferFunctions))
-
try:
suite.addTest(doctest.DocTestSuite(buffer))
suite.addTest(doctest.DocTestSuite(create))
suite.addTest(doctest.DocTestSuite(eth))
suite.addTest(doctest.DocTestSuite(scapy))
- suite.addTest(doctest.DocTestSuite(sniffer))
except ValueError:
print "has no tests"
diff --git a/cesar/maximus/python/test/test_interface.py b/cesar/maximus/python/test/test_interface.py
index 61685e1ef6..9ceec866e8 100644
--- a/cesar/maximus/python/test/test_interface.py
+++ b/cesar/maximus/python/test/test_interface.py
@@ -130,9 +130,7 @@ class TestInterfaceFunctions(unittest.TestCase):
pass
def create_fc3():
pass
- def create_fc4():
- pass
- self.m.set_msdu_rx(cb, create_fc1, create_fc2, create_fc3, create_fc4)
+ self.m.set_msdu_rx(cb, create_fc1, create_fc2, create_fc3)
def test_wait(self):
self.m.wait()
diff --git a/cesar/maximus/python/test/test_lib_cesar.py b/cesar/maximus/python/test/test_lib_cesar.py
index 3a7aa85990..50bf765c65 100644
--- a/cesar/maximus/python/test/test_lib_cesar.py
+++ b/cesar/maximus/python/test/test_lib_cesar.py
@@ -78,10 +78,10 @@ class TestSTACesarFunctions(unittest.TestCase):
self.station.set_name(name)
self.assertEqual(self.station.get_name(), name)
- def test_set_mme_buffer_nb(self):
- mme_buffer_nb = 4
- self.station.set_mme_buffer_nb(mme_buffer_nb)
- self.assertEqual(self.station.get_mme_buffer_nb(), mme_buffer_nb)
+ def test_set_buffer_nb(self):
+ buffer_nb = 4
+ self.station.set_buffer_nb(buffer_nb)
+ self.assertEqual(self.station.get_buffer_nb(), buffer_nb)
def test_set_config_mode(self):
config_mode = 'fcall_process_drv'
diff --git a/cesar/maximus/python/test/test_station.py b/cesar/maximus/python/test/test_station.py
index 7c61d88ff7..edf4c293d3 100644
--- a/cesar/maximus/python/test/test_station.py
+++ b/cesar/maximus/python/test/test_station.py
@@ -142,10 +142,10 @@ class TestSTAFunctions(unittest.TestCase):
self.station.set_name(name)
self.assertEqual(self.station.get_name(), name)
- def test_set_mme_buffer_nb(self):
- mme_buffer_nb = 4
- self.station.set_mme_buffer_nb(mme_buffer_nb)
- self.assertEqual(self.station.get_mme_buffer_nb(), mme_buffer_nb)
+ def test_set_buffer_nb(self):
+ buffer_nb = 4
+ self.station.set_buffer_nb(buffer_nb)
+ self.assertEqual(self.station.get_buffer_nb(), buffer_nb)
def test_set_config_mode(self):
config_mode = 'fcall_process_drv'
diff --git a/cesar/maximus/python/tools/csi/csicore.py b/cesar/maximus/python/tools/csi/csicore.py
index f3665011b2..3ef640d10e 100644
--- a/cesar/maximus/python/tools/csi/csicore.py
+++ b/cesar/maximus/python/tools/csi/csicore.py
@@ -40,7 +40,8 @@ class csiCore:
frame.src = NULL_MAC_ADDRESS[0:17 - len(frame.src)] + frame.src
frame.dst = NULL_MAC_ADDRESS[0:17 - len(frame.dst)] + frame.dst
self.__frames_recv.append (frame)
- elif frame.get_type() is 'ETHERNET_TYPE_SNIFFER':
+ elif frame.get_type() is 'ETHERNET_TYPE_MME' \
+ and frame.get_mmtype () == 0xa02e:
self.sniffed_packets.append (frame)
return True
@@ -222,8 +223,7 @@ class csiCore:
raise Exception ('No station or already running')
cesar = STACesar (self.__maximus, config=station.get_config(),
- mme_buffer_nb=1, data_buffer_nb=16,
- debug=station.get_debug(),
+ buffer_nb=10, debug=station.get_debug(),
config_mode="MME", seed=random.randint(0, 9999),
name=station.get_manufacturer_hfid ())
station.set_sta_cesar (cesar)
@@ -244,18 +244,11 @@ class csiCore:
print avln.get_ahfid () + " : This AVLN do not have any Station"
for i in range (0, avln.get_nb_sta()):
sta = avln.get_sta (i)
-
if sta == None:
raise Exception ('Wrong index, no sta')
-
if sta.get_delay_ms():
self.__maximus.wait (ms_to_tck (sta.get_delay_ms()))
-
- cesar = STACesar (self.__maximus, config=sta.get_config(),
- mme_buffer_nb=1, data_buffer_nb=16, debug=sta.get_debug(),
- config_mode="MME", seed=random.randint(0, 9999),
- name=sta.get_manufacturer_hfid (), executable=sta.get_executable())
- sta.set_sta_cesar (cesar)
+ self.process_sta_start (sta)
def process_avln_stop (self, avln):
"""Stop all the station in the AVLN."""
diff --git a/cesar/maximus/python/tools/csi/csifilter.py b/cesar/maximus/python/tools/csi/csifilter.py
index f94b2958c5..7cf3c601be 100644
--- a/cesar/maximus/python/tools/csi/csifilter.py
+++ b/cesar/maximus/python/tools/csi/csifilter.py
@@ -23,9 +23,9 @@ def frame_filter_mpdu (msdu):
return False
def frame_filter_sniffer (msdu):
- if msdu.get_type() is 'ETHERNET_TYPE_SNIFFER':
+ if msdu.get_type() is 'ETHERNET_TYPE_MME' \
+ and msdu.get_mmtype () & ~3 == 0xa02c:
# The received object is an Sniffer packet
return True
else:
return False
-
diff --git a/cesar/maximus/stationtest/Makefile b/cesar/maximus/stationtest/Makefile
index 5f019274d0..e2fdd5661b 100644
--- a/cesar/maximus/stationtest/Makefile
+++ b/cesar/maximus/stationtest/Makefile
@@ -26,21 +26,21 @@ test_cb_SOURCES = test_cb.c
test_cb_MODULES = lib host
test_ether_SOURCES = test_ether.c
-test_ether_MODULES = lib host hal/hle/maximus
+test_ether_MODULES = lib host hal/ipmbox/maximus
test_false_alarm_SOURCES = test_false_alarm.c
test_false_alarm_MODULES = lib host hal/phy/maximus
cp_beacon_MODULE_SOURCES = beacons.c bentry.c
test_lib_cesar_SOURCES = test_lib_cesar.c
-test_lib_cesar_MODULES = lib host hal/hle/maximus hal/phy/maximus/dur/maximus interface
+test_lib_cesar_MODULES = lib host hal/ipmbox/maximus hal/phy/maximus/dur/maximus
test_send_SOURCES = test_send.c
test_send_MODULES = lib host hal/phy/maximus
cp_beacon_MODULE_SOURCES = beacons.c bentry.c
test_station_SOURCES = test_station.c
-test_station_MODULES = lib host hal/hle/maximus hal/phy/maximus/dur/maximus interface
+test_station_MODULES = lib host hal/ipmbox/maximus hal/phy/maximus/dur/maximus
test_tx_rx_SOURCES = test_tx_rx.c
test_tx_rx_MODULES = lib host hal/phy/maximus
diff --git a/cesar/maximus/stationtest/src/test_ether.c b/cesar/maximus/stationtest/src/test_ether.c
index 665f504c4a..d73de63f26 100644
--- a/cesar/maximus/stationtest/src/test_ether.c
+++ b/cesar/maximus/stationtest/src/test_ether.c
@@ -16,79 +16,127 @@
#include <errno.h>
#include "common/std.h"
#include "host/station/station.h"
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...' and 'ipmbox_msg_hdr_t'
-#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
-#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
+#include "hal/ipmbox/maximus/inc/maximus_interrupts.h" // for 'HAL_IPMBOX_..._INTERRUPT'
#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
+#include "common/ipmbox/msg.h"
+#include "common/defs/homeplugAV.h"
#include <stdlib.h> // for 'malloc()'
+#define RESULT_SUCCESS 0x00
+#define CM_SET_KEY_REQ_MMTYPE 0x6008
+
+/* DRV_STA_....CNF MMENTRY only contains 1 byte: Result */
+#define DRV_STA_CNF_LEN (HPAV_MME_HEADER + 1)
+
+/* CM_SET_KEY.CNF MMENTRY contains:
+ - 1 byte: Result
+ - 4 bytes: My Nonce
+ - 4 bytes: Your Nonce
+ - 1 byte: PID
+ - 2 bytes: PRN
+ - 1 byte: PMN
+ - 1 byte: CCo Capability
+ => 14 bytes in total */
+#define CM_SET_KEY_CNF_LEN (HPAV_MME_HEADER + 14)
+
extern station_ctx_t my_station;
ipmbox_t * ctx;
int user_data = 123;
-void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
+void
+rx_cb_mbx (void *user_data, u32 *first_msg, uint length)
{
- diag_write_string("=> ipmbox_rx_cb\n");
-
// Reset IT
- maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
- ipmbox_msg_hdr_t *hdr = (ipmbox_msg_hdr_t *)&ctx->rx.mailbox[0];
- if (HLE_MSG_TYPE_DATA == hdr->type)
+ ipmbox_msg_mbx_t *msg_mbx = (ipmbox_msg_mbx_t *) ctx->rx_mbx.mailbox;
+
+ /* When receiving an Ether SCI message of type MME REQ from Maximus,
+ * send the answer (an Ether SCI message of type MME CNF)
+ * with an Ether SCI message of type BUFFER_RELEASED. */
+
+ // REQ data length
+ uint data_length = ipmbox_msg_get_mme_priv_length (msg_mbx->header);
+
+ // REQ data
+ u32 buffer_addr;
+ if (1 != ipmbox_empty_buf_get (ctx, &buffer_addr, 1))
+ {
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: cannot get empty buf", __FUNCTION__);
+ }
+ memcpy ((u32 *) buffer_addr, (u32 *) msg_mbx->buffer_addr, data_length);
+
+ // CNF data
+ char *cnf_data = (char *) buffer_addr;
+ *(cnf_data + HPAV_MMTYPE_OFFSET) = *(cnf_data + HPAV_MMTYPE_OFFSET) + 1; // REQ => CNF
+ *(cnf_data + HPAV_MME_HEADER) = RESULT_SUCCESS;
+
+ // CNF data length
+ uint cnf_data_length = 0;
+ u16 mmtype = (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET + 1) << 8)\
+ | (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET));
+ if (CM_SET_KEY_REQ_MMTYPE == mmtype)
+ {
+ cnf_data_length = CM_SET_KEY_CNF_LEN;
+ }
+ else /* mmtype = DRV_STA_....REQ */
{
- /* When receiving an Ether SCI message of type DATA or MME from Maximus,
- * answer by sending a first Ether SCI message of type DATA,
- * with an Ether SCI message of type BUFFER_RELEASED,
- * and a second one of type MME,
- * with an Ether SCI message of type BUFFER_RELEASED. */
-
- uint data_length = (uint)(hdr->param >> 1);
- memcpy(ctx->first_buffer->next->data, (u32 *)ctx->rx.mailbox[1], data_length);
- memcpy(ctx->first_buffer->next->next->data, (u32 *)ctx->rx.mailbox[1], data_length);
-
- // Release allocated buffer
- hdr->type = HLE_MSG_TYPE_SEND_DONE;
- ipmbox_tx (ctx, ctx->rx.mailbox, 2);
-
- hdr->type = HLE_MSG_TYPE_DATA;
- hdr->param &= 0xFFE;
- ctx->rx.mailbox[1] = (u32)ctx->first_buffer->next->data;
- ipmbox_tx (ctx, ctx->rx.mailbox, ctx->rx.length);
-
- hdr->param |= 0x001;
- ctx->rx.mailbox[1] = (u32)ctx->first_buffer->next->data;
- ipmbox_tx (ctx, ctx->rx.mailbox, ctx->rx.length);
+ cnf_data_length = DRV_STA_CNF_LEN;
}
- else if (HLE_MSG_TYPE_BUFFER_ADD == hdr->type)
+
+ // Tx
+ msg_mbx->header = ipmbox_msg_create_header_mme_priv (cnf_data_length);
+ msg_mbx->buffer_addr = buffer_addr;
+ ipmbox_tx_mbx (ctx, (u32 *) msg_mbx, 2);
+
+ return;
+}
+
+
+void
+rx_cb_data (void *user_data, u32 *first_msg, uint length)
+{
+ // Reset IT
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ ipmbox_msg_data_t *msg_data = (ipmbox_msg_data_t *) ctx->rx_data.mailbox;
+
+ /* When receiving an Ether SCI message of type DATA from Maximus,
+ * answer by sending an Ether SCI message of type DATA,
+ * with an Ether SCI message of type BUFFER_RELEASED. */
+
+ // data length
+ uint data_length = ipmbox_msg_get_data_length (msg_data->header);
+
+ // data
+ u32 buffer_addr;
+ if (1 != ipmbox_empty_buf_get (ctx, &buffer_addr, 1))
{
- if (2 == hdr->param)
- {
- /* When receiving an Ether SCI message of type INTERFACE_BUFFER_ADD from Maximus,
- * answer by sending an Ether SCI message of type SNIFFER,
- * with an Ether SCI message of type BUFFER_RELEASED. */
-
- uint data_length = 64;
- char * p_data = malloc(data_length);
- memset(p_data, '\0', data_length);
- strcpy(p_data, "This is a sniffed packet coming from the station");
-
- maximus_hle_buffer_t *p_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
- u32 id = ctx->last_buffer->id;
- ctx->last_buffer->next = p_buffer;
- ctx->last_buffer = p_buffer;
- ctx->last_buffer->next = NULL;
- ctx->last_buffer->id = id;
- ctx->last_buffer->data = (u32 *)p_data;
-
- hdr->type = HLE_MSG_TYPE_INTERFACE;
- hdr->length = 1;
- hdr->param = ((data_length << 8) & 0x7FF00) | 0x00001;
- ctx->rx.mailbox[1] = (u32)p_data;
- ipmbox_tx (ctx, ctx->rx.mailbox, 2);
- }
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: cannot get empty buf", __FUNCTION__);
}
+ memcpy ((u32 *) buffer_addr, (u32 *) msg_data->buffer_addr, data_length);
+
+ // Tx
+ msg_data->buffer_addr = buffer_addr;
+ ipmbox_tx_data (ctx, (u32 *) msg_data, 2);
+
+ return;
+}
+
+
+void
+empty_buf_cb (void *user_data)
+{
+ // Reset IT
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_BUF_INTERRUPT);
+
+ /* When receiving an Ether SCI message of type BUFFER_ADD from Maximus,
+ * do nothing: just keep the allocated buffer for future Tx DATA / MME. */
return;
}
@@ -99,7 +147,11 @@ int init_ether (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void
diag_write_string("=> init_ether\n");
// Initialize the HAL HLE ipmbox
- ctx = ipmbox_init ((void *)&user_data, &ipmbox_rx_cb);
+ ctx = ipmbox_init ();
+ ipmbox_register_rx_data_cb (ctx, (void *) &user_data, &rx_cb_data);
+ ipmbox_register_rx_mbx_cb (ctx, (void *) &user_data, &rx_cb_mbx);
+ ipmbox_register_empty_buf_cb (ctx, (void *) &user_data,
+ &empty_buf_cb);
// Enable assertions on warnings
ctx->warning_assert = true;
diff --git a/cesar/maximus/stationtest/src/test_lib_cesar.c b/cesar/maximus/stationtest/src/test_lib_cesar.c
index dbe3a8007c..d7f5740597 100644
--- a/cesar/maximus/stationtest/src/test_lib_cesar.c
+++ b/cesar/maximus/stationtest/src/test_lib_cesar.c
@@ -15,11 +15,12 @@
#include "common/defs/homeplugAV.h"
#include "host/station/station.h" // for 'station_ctx_t'
#include "hal/phy/maximus/dur/maximus/inc/maximus_phy_dur.h" // for 'maximus_phy_dur_init()'
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...' and 'ipmbox_msg_hdr_t'
-#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
-#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
+#include "hal/ipmbox/maximus/inc/maximus_interrupts.h" // for 'HAL_IPMBOX_..._INTERRUPT'
#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
+#include "common/ipmbox/msg.h"
+#include "common/defs/homeplugAV.h"
#define RESULT_SUCCESS 0x00
#define CM_SET_KEY_REQ_MMTYPE 0x6008
@@ -42,56 +43,80 @@ extern station_ctx_t my_station;
ipmbox_t *ctx;
int user_data = 123;
-void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
+void
+rx_cb_mbx (void *user_data, u32 *first_msg, uint length)
{
// Reset IT
- maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ ipmbox_msg_mbx_t *msg_mbx = (ipmbox_msg_mbx_t *) ctx->rx_mbx.mailbox;
+
+ /* When receiving an Ether SCI message of type MME REQ from Maximus,
+ * send the answer (an Ether SCI message of type MME CNF)
+ * with an Ether SCI message of type BUFFER_RELEASED. */
- ipmbox_msg_hdr_t *hdr = (ipmbox_msg_hdr_t *)&ctx->rx.mailbox[0];
- if (HLE_MSG_TYPE_DATA == hdr->type)
+ // REQ data length
+ uint data_length = ipmbox_msg_get_mme_priv_length (msg_mbx->header);
+
+ // REQ data
+ u32 buffer_addr;
+ if (1 != ipmbox_empty_buf_get (ctx, &buffer_addr, 1))
+ {
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: cannot get empty buf", __FUNCTION__);
+ }
+ memcpy ((u32 *) buffer_addr, (u32 *) msg_mbx->buffer_addr, data_length);
+
+ // CNF data
+ char *cnf_data = (char *) buffer_addr;
+ *(cnf_data + HPAV_MMTYPE_OFFSET) = *(cnf_data + HPAV_MMTYPE_OFFSET) + 1; // REQ => CNF
+ *(cnf_data + HPAV_MME_HEADER) = RESULT_SUCCESS;
+
+ // CNF data length
+ uint cnf_data_length = 0;
+ u16 mmtype = (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET + 1) << 8)\
+ | (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET));
+ if (CM_SET_KEY_REQ_MMTYPE == mmtype)
{
- /* When receiving an Ether SCI message of type MME REQ from Maximus,
- * send the answer (an Ether SCI message of type MME CNF). */
-
- // REQ data length
- uint data_length = (uint)(hdr->param >> 1);
-
- // REQ data
- memcpy(ctx->first_buffer->next->data, (u32 *)ctx->rx.mailbox[1], data_length);
-
- // CNF data
- char *cnf_data = (char *)ctx->first_buffer->next->data;
- *(cnf_data + HPAV_MMTYPE_OFFSET) = *(cnf_data + HPAV_MMTYPE_OFFSET) + 1; // REQ => CNF
- *(cnf_data + HPAV_MME_HEADER) = RESULT_SUCCESS;
-
- // CNF data length
- uint cnf_data_length = 0;
- u16 mmtype = (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET + 1) << 8)\
- | (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET));
- if (CM_SET_KEY_REQ_MMTYPE == mmtype)
- {
- cnf_data_length = CM_SET_KEY_CNF_LEN;
- }
- else /* mmtype = DRV_STA_....REQ */
- {
- cnf_data_length = DRV_STA_CNF_LEN;
- }
-
- // Release allocated buffer
- hdr->type = HLE_MSG_TYPE_SEND_DONE;
- ipmbox_tx (ctx, ctx->rx.mailbox, 2);
-
- // Tx
- hdr->type = HLE_MSG_TYPE_DATA;
- hdr->param = cnf_data_length << 8;
- hdr->param |= 0x001;
- ctx->rx.mailbox[1] = (u32)ctx->first_buffer->next->data;
- ipmbox_tx (ctx, ctx->rx.mailbox, ctx->rx.length);
+ cnf_data_length = CM_SET_KEY_CNF_LEN;
}
+ else /* mmtype = DRV_STA_....REQ */
+ {
+ cnf_data_length = DRV_STA_CNF_LEN;
+ }
+
+ // Tx
+ msg_mbx->header = ipmbox_msg_create_header_mme_priv (cnf_data_length);
+ msg_mbx->buffer_addr = buffer_addr;
+ ipmbox_tx_mbx (ctx, (u32 *) msg_mbx, 2);
return;
}
+void
+rx_cb_data (void *user_data, u32 *first_msg, uint length)
+{
+ // Reset IT
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ /* In this test, we should not receive an Ether SCI message of type DATA
+ * from Maximus. */
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: rx cb data should not be called", __FUNCTION__);
+
+ return;
+}
+
+void
+empty_buf_cb (void *user_data)
+{
+ // Reset IT
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_BUF_INTERRUPT);
+
+ /* When receiving an Ether SCI message of type BUFFER_ADD from Maximus,
+ * do nothing: just keep the allocated buffer for future Tx DATA / MME. */
+}
+
int uninit_ether (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
// Uninitialize the HAL HLE ipmbox
@@ -111,8 +136,12 @@ int main (void)
maximus_phy_dur_init(&my_station);
- // Initialize the HAL HLE ipmbox
- ctx = ipmbox_init ((void *)&user_data, &ipmbox_rx_cb);
+ // Initialize the HAL ipmbox
+ ctx = ipmbox_init ();
+ ipmbox_register_rx_data_cb (ctx, (void *) &user_data, &rx_cb_data);
+ ipmbox_register_rx_mbx_cb (ctx, (void *) &user_data, &rx_cb_mbx);
+ ipmbox_register_empty_buf_cb (ctx, (void *) &user_data,
+ &empty_buf_cb);
// Enable assertions on warnings
ctx->warning_assert = true;
diff --git a/cesar/maximus/stationtest/src/test_station.c b/cesar/maximus/stationtest/src/test_station.c
index 9f15f1812c..f780ae17f0 100644
--- a/cesar/maximus/stationtest/src/test_station.c
+++ b/cesar/maximus/stationtest/src/test_station.c
@@ -14,11 +14,12 @@
#include "common/std.h"
#include "common/defs/homeplugAV.h"
#include "host/station/station.h" // for 'station_ctx_t'
-#include "hal/hle/ipmbox.h"
-#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...' and 'ipmbox_msg_hdr_t'
-#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
-#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
+#include "hal/ipmbox/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
+#include "common/ipmbox/msg.h"
+#include "common/defs/homeplugAV.h"
#include <cyg/infra/diag.h>
#include <stdio.h>
@@ -43,56 +44,80 @@ extern station_ctx_t my_station;
ipmbox_t *ctx;
int user_data = 123;
-void ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
+void
+rx_cb_mbx (void *user_data, u32 *first_msg, uint length)
{
// Reset IT
- maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ ipmbox_msg_mbx_t *msg_mbx = (ipmbox_msg_mbx_t *) ctx->rx_mbx.mailbox;
+
+ /* When receiving an Ether SCI message of type MME REQ from Maximus,
+ * send the answer (an Ether SCI message of type MME CNF)
+ * with an Ether SCI message of type BUFFER_RELEASED. */
- ipmbox_msg_hdr_t *hdr = (ipmbox_msg_hdr_t *)&ctx->rx.mailbox[0];
- if (HLE_MSG_TYPE_DATA == hdr->type)
+ // REQ data length
+ uint data_length = ipmbox_msg_get_mme_priv_length (msg_mbx->header);
+
+ // REQ data
+ u32 buffer_addr;
+ if (1 != ipmbox_empty_buf_get (ctx, &buffer_addr, 1))
+ {
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: cannot get empty buf", __FUNCTION__);
+ }
+ memcpy ((u32 *) buffer_addr, (u32 *) msg_mbx->buffer_addr, data_length);
+
+ // CNF data
+ char *cnf_data = (char *) buffer_addr;
+ *(cnf_data + HPAV_MMTYPE_OFFSET) = *(cnf_data + HPAV_MMTYPE_OFFSET) + 1; // REQ => CNF
+ *(cnf_data + HPAV_MME_HEADER) = RESULT_SUCCESS;
+
+ // CNF data length
+ uint cnf_data_length = 0;
+ u16 mmtype = (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET + 1) << 8)\
+ | (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET));
+ if (CM_SET_KEY_REQ_MMTYPE == mmtype)
{
- /* When receiving an Ether SCI message of type MME REQ from Maximus,
- * send the answer (an Ether SCI message of type MME CNF). */
-
- // REQ data length
- uint data_length = (uint)(hdr->param >> 1);
-
- // REQ data
- memcpy(ctx->first_buffer->next->data, (u32 *)ctx->rx.mailbox[1], data_length);
-
- // CNF data
- char *cnf_data = (char *)ctx->first_buffer->next->data;
- *(cnf_data + HPAV_MMTYPE_OFFSET) = *(cnf_data + HPAV_MMTYPE_OFFSET) + 1; // REQ => CNF
- *(cnf_data + HPAV_MME_HEADER) = RESULT_SUCCESS;
-
- // CNF data length
- uint cnf_data_length = 0;
- u16 mmtype = (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET + 1) << 8)\
- | (u16)(*(cnf_data + HPAV_MMTYPE_OFFSET));
- if (CM_SET_KEY_REQ_MMTYPE == mmtype)
- {
- cnf_data_length = CM_SET_KEY_CNF_LEN;
- }
- else /* mmtype = DRV_STA_....REQ */
- {
- cnf_data_length = DRV_STA_CNF_LEN;
- }
-
- // Release allocated buffer
- hdr->type = HLE_MSG_TYPE_SEND_DONE;
- ipmbox_tx (ctx, ctx->rx.mailbox, 2);
-
- // Tx
- hdr->type = HLE_MSG_TYPE_DATA;
- hdr->param = cnf_data_length << 8;
- hdr->param |= 0x001;
- ctx->rx.mailbox[1] = (u32)ctx->first_buffer->next->data;
- ipmbox_tx (ctx, ctx->rx.mailbox, ctx->rx.length);
+ cnf_data_length = CM_SET_KEY_CNF_LEN;
}
+ else /* mmtype = DRV_STA_....REQ */
+ {
+ cnf_data_length = DRV_STA_CNF_LEN;
+ }
+
+ // Tx
+ msg_mbx->header = ipmbox_msg_create_header_mme_priv (cnf_data_length);
+ msg_mbx->buffer_addr = buffer_addr;
+ ipmbox_tx_mbx (ctx, (u32 *) msg_mbx, 2);
return;
}
+void
+rx_cb_data (void *user_data, u32 *first_msg, uint length)
+{
+ // Reset IT
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ /* In this test, we should not receive an Ether SCI message of type DATA
+ * from Maximus. */
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: rx cb data should not be called", __FUNCTION__);
+
+ return;
+}
+
+void
+empty_buf_cb (void *user_data)
+{
+ // Reset IT
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_BUF_INTERRUPT);
+
+ /* When receiving an Ether SCI message of type BUFFER_ADD from Maximus,
+ * do nothing: just keep the allocated buffer for future Tx DATA / MME. */
+}
+
int uninit_ether (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
// Uninitialize the HAL HLE ipmbox
@@ -110,8 +135,12 @@ int main (void)
station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
my_station.pipe_log_fd = 1;
- // Initialize the HAL HLE ipmbox
- ctx = ipmbox_init ((void *)&user_data, &ipmbox_rx_cb);
+ // Initialize the HAL ipmbox
+ ctx = ipmbox_init ();
+ ipmbox_register_rx_data_cb (ctx, (void *) &user_data, &rx_cb_data);
+ ipmbox_register_rx_mbx_cb (ctx, (void *) &user_data, &rx_cb_mbx);
+ ipmbox_register_empty_buf_cb (ctx, (void *) &user_data,
+ &empty_buf_cb);
// Enable assertions on warnings
ctx->warning_assert = true;
diff --git a/cesar/maximus/test/test.sh b/cesar/maximus/test/test.sh
index cb9230c473..c2891ff1fa 100755
--- a/cesar/maximus/test/test.sh
+++ b/cesar/maximus/test/test.sh
@@ -1,6 +1,6 @@
#! /bin/bash
-WORKSPACE='/home/buret/workspace/maximus'
+WORKSPACE='/home/buret/spidcom/workspace/eoc/cesar'
echo
echo "*** HAL Leon Timer Maximus tests ***"
@@ -10,9 +10,9 @@ make clean; make
obj/test_maximus_timer
echo
-echo "*** HAL HLE Maximus tests ***"
+echo "*** HAL IPMBox Maximus tests ***"
echo
-cd $WORKSPACE/hal/hle/maximus/test
+cd $WORKSPACE/hal/ipmbox/maximus/test
make clean; make
obj/test_maximus_hle
@@ -24,20 +24,6 @@ make clean; make
obj/test_phy_maximus
echo
-echo "*** HAL PHY tests ***"
-echo
-cd $WORKSPACE/hal/phy/test/phy
-make clean; make
-obj/host_test_phy -e obj/test_phy.elf -d false -t 2500000000
-
-echo
-echo "*** SAR tests ***"
-echo
-cd $WORKSPACE/mac/sar/test/maximus_test
-make clean; make
-obj/Maximus_sar -e obj/Sta_sar.elf -d false -t 2500000000
-
-echo
echo "*** Compile stations executables ***"
echo
cd $WORKSPACE/maximus/stationtest
@@ -82,4 +68,4 @@ echo
echo "=> Python tests"
echo
cd $WORKSPACE/maximus/test
-test_python.sh
+./test_python.sh
diff --git a/cesar/maximus/test/test_python.sh b/cesar/maximus/test/test_python.sh
index 099a1ccd20..f1a9c9983a 100755
--- a/cesar/maximus/test/test_python.sh
+++ b/cesar/maximus/test/test_python.sh
@@ -1,6 +1,6 @@
#! /bin/bash
-WORKSPACE='/home/buret/workspace/maximus'
+WORKSPACE='/home/buret/spidcom/workspace/eoc/cesar'
echo
echo "*** Compile stations executables ***"
@@ -41,54 +41,3 @@ python py/test_send_noise.py -e ../stationtest/obj/test_send.elf -d false -t 250
python py/test_tx_rx.py -e ../stationtest/obj/test_tx_rx.elf -d false -t 2500000000
python py/test_ether.py -e ../stationtest/obj/test_ether.elf -d false -t 2500000000
python py/test_false_alarm.py -e ../stationtest/obj/test_false_alarm.elf -d false -t 2500000000
-
-echo
-echo "*** PB proc tests ***"
-echo
-cd $WORKSPACE/mac/pbproc/test/maximus
-make clean; make
-python py/host_test_pbproc.py -e obj/test_pbproc.elf -d false -t 2500000000
-python py/test_coll.py -e obj/test_pbproc.elf -d false -t 2500000000
-
-echo
-echo "*** CE tests ***"
-echo
-cd $WORKSPACE/ce/test/rx/maximus
-make clean; make
-python send_noise.py -e obj/test_rx.elf -d false -t 2500000000
-
-echo
-echo "*** CL - SAR - PB proc tests ***"
-echo
-cd $WORKSPACE/test_general/maximus/integration/cl-sar-pbproc
-make clean; make
-python test1.py -e obj/cl-sar-pbproc.elf -d false -t 2500000000
-
-echo
-echo "*** HLE - CL - SAR - PB proc tests ***"
-echo
-cd $WORKSPACE/test_general/maximus/integration/hle-cl-sar-pbproc
-make clean; make
-python test1.py -e obj/hle-cl-sar-pbproc.elf -d false -t 2500000000
-
-echo
-echo "*** IPMBOX - HLE - CL - SAR - PB proc tests ***"
-echo
-cd $WORKSPACE/test_general/maximus/integration/ipmbox-hle-cl-sar-pbproc
-make clean; make
-python test1.py -e obj/ipmbox-hle-cl-sar-pbproc.elf -d false -t 2500000000
-python test2.py -e obj/ipmbox-hle-cl-sar-pbproc.elf -d false -t 2500000000
-
-echo
-echo "*** SAR - PB proc tests ***"
-echo
-cd $WORKSPACE/test_general/maximus/integration/sar-pbproc
-make clean; make
-python test1.py -e obj/sar-pbproc.elf -d false -t 2500000000
-
-echo
-echo "*** INTERFACE - DP tests ***"
-echo
-cd $WORKSPACE/test_general/maximus/integration/interface-dp
-make clean; make
-python test1.py -d false -t 2500000000
diff --git a/cesar/projects/plc/Makefile b/cesar/projects/plc/Makefile
index cc6b140c53..26a0dfb050 100644
--- a/cesar/projects/plc/Makefile
+++ b/cesar/projects/plc/Makefile
@@ -7,7 +7,8 @@ TARGET_OPTIMIZE = -Os
TARGET_PROGRAMS = plc
plc_SOURCES = plc.c
-plc_MODULES = lib hal mac cl hle interface cp cp/av ce station bsu hle/tools
+plc_MODULES = lib hal mac cl interface cp cp/av ce station bsu hle/tools \
+ bufmgr
# Add support for Fcalls.
plc_MODULES += host ce/fcall
diff --git a/cesar/station/src/station.c b/cesar/station/src/station.c
index bc1bd10f8f..a730d137bc 100644
--- a/cesar/station/src/station.c
+++ b/cesar/station/src/station.c
@@ -64,6 +64,9 @@ cesar_init (void)
seed = phy_seed ();
cesar.mac_config.seed = seed;
+ /* Initialise Ipmbox. */
+ cesar.ipmbox = ipmbox_init ();
+
/* Initialise the PBproc. */
cesar.pbproc = pbproc_init (&cesar.mac_config,
cesar.mac_store);
@@ -71,22 +74,22 @@ cesar_init (void)
/* Initialise the mac ntb. */
mac_ntb_init (&cesar.mac_config);
+ /* Initialise the buffer manager. */
+ cesar.bufmgr = bufmgr_init (cesar.ipmbox);
+
/* Initialise the SAR. */
cesar.sar = sar_init (cesar.mac_store, cesar.pbproc,
- pbproc_get_ca(cesar.pbproc), seed);
+ pbproc_get_ca(cesar.pbproc),
+ cesar.bufmgr, seed);
/* Initialise the CL. */
cesar.cl = cl_init (cesar.mac_store, cesar.sar,
- &cesar.mac_config);
-
- /* Initialise the HLE. */
- cesar.hle = hle_init (cesar.cl);
+ &cesar.mac_config, cesar.ipmbox, cesar.bufmgr);
/* Initialise the interface. */
- cesar.interface = interface_init(cesar.hle,
- cesar.cl,
- cesar.sar,
- &cesar.mac_config);
+ cesar.interface = interface_init(cesar.cl, cl_mbx_get (cesar.cl),
+ cesar.sar, &cesar.mac_config,
+ cesar.bufmgr);
/* Initialise the hal timer. */
cesar.hal_timer = hal_timer_init ();
@@ -107,10 +110,10 @@ cesar_init (void)
cesar.cp = cp_init (cesar.bsu, cesar.bsu_aclf, &cesar.mac_config,
cesar.interface, cesar.hal_timer, cesar.pbproc,
cesar.mac_store, cesar.sar, cesar.cl, cesar.ce_rx,
- seed);
+ cesar.bufmgr, seed);
// start HLE...
- hle_activate(cesar.hle, true);
+ ipmbox_activate(cesar.ipmbox, true);
init_exec (INIT_LIST_CE);
@@ -127,7 +130,6 @@ cesar_uninit (cesar_t *ctx)
cp_uninit (ctx->cp);
interface_uninit(ctx->interface);
- hle_uninit (ctx->hle);
cl_uninit (ctx->cl);
sar_uninit (ctx->sar);
pbproc_uninit (ctx->pbproc);
diff --git a/cesar/station/station.h b/cesar/station/station.h
index 612554f06e..3b58396d38 100644
--- a/cesar/station/station.h
+++ b/cesar/station/station.h
@@ -17,7 +17,6 @@
#include "mac/pbproc/pbproc.h"
#include "mac/sar/sar.h"
#include "cl/cl.h"
-#include "hle/hle.h"
#include "interface/interface.h"
#include "cp/cp.h"
#include "hal/timer/timer.h"
@@ -33,6 +32,12 @@ struct cesar_t
/** Mac config. */
mac_config_t mac_config;
+ /** Ipmbox. */
+ ipmbox_t *ipmbox;
+
+ /** Buffer manager. */
+ bufmgr_t *bufmgr;
+
/** PBProc. */
pbproc_t *pbproc;
@@ -42,9 +47,6 @@ struct cesar_t
/** CL. */
cl_t *cl;
- /** HLE */
- hle_t *hle;
-
/** Interface. */
interface_t *interface;
diff --git a/cesar/test_general/dataplane/inc/context.h b/cesar/test_general/dataplane/inc/context.h
index bae9b0c753..4307bfe168 100644
--- a/cesar/test_general/dataplane/inc/context.h
+++ b/cesar/test_general/dataplane/inc/context.h
@@ -20,7 +20,6 @@
#include "mac/pbproc/pbproc.h"
#include "mac/sar/sar.h"
#include "cl/cl.h"
-#include "hle/hle.h"
#include "mac/ca/test/fcall/beacon_period.h"
#include "mac/common/test/fcall/set_tonemap.h"
@@ -62,8 +61,6 @@ struct test_dataplane_t
sar_t *sar;
/** CL context. */
cl_t *cl;
- /** HLE context. */
- hle_t *hle;
/** Timer context. */
hal_timer_t *hal_timer;
diff --git a/cesar/test_general/dataplane/inc/trace_dump.h b/cesar/test_general/dataplane/inc/trace_dump.h
index 7635079caa..60395e7d6f 100644
--- a/cesar/test_general/dataplane/inc/trace_dump.h
+++ b/cesar/test_general/dataplane/inc/trace_dump.h
@@ -19,7 +19,7 @@ struct test_dataplane_msg_trace_dump_t
/** Bundle name. */
char name[64];
/** Trace what? */
- bool all, phy, ca, pbproc, sar, cl, hle;
+ bool all, phy, ca, pbproc, sar, cl;
};
typedef struct test_dataplane_msg_trace_dump_t
test_dataplane_msg_trace_dump_t;
diff --git a/cesar/test_general/dataplane/maximus-Makefile b/cesar/test_general/dataplane/maximus-Makefile
index d2a72ad4af..d0c7ca88f7 100644
--- a/cesar/test_general/dataplane/maximus-Makefile
+++ b/cesar/test_general/dataplane/maximus-Makefile
@@ -4,7 +4,7 @@ ECOS = y
TARGET_PROGRAMS = test_dataplane
test_dataplane_SOURCES = test_dataplane.c trace_dump.c
-test_dataplane_MODULES = lib hal mac cl hle \
+test_dataplane_MODULES = lib hal mac cl bufmgr \
host \
mac/ca/test/fcall mac/common/test/fcall
diff --git a/cesar/test_general/dataplane/sparc-Config b/cesar/test_general/dataplane/sparc-Config
index 591f8be235..6a841f1ab9 100644
--- a/cesar/test_general/dataplane/sparc-Config
+++ b/cesar/test_general/dataplane/sparc-Config
@@ -2,3 +2,4 @@ CONFIG_DEBUG_CLAIM = n
CONFIG_TRACE = y
CONFIG_TRACE_ON_FATAL = y
CONFIG_STATS = n
+CONFIG_ARCH_ILRAM_PRIO = 0
diff --git a/cesar/test_general/dataplane/sparc-Makefile b/cesar/test_general/dataplane/sparc-Makefile
index a50ddac283..8e4668ff09 100644
--- a/cesar/test_general/dataplane/sparc-Makefile
+++ b/cesar/test_general/dataplane/sparc-Makefile
@@ -8,7 +8,7 @@ TARGET_OPTIMIZE = -Os
TARGET_PROGRAMS = test_dataplane
test_dataplane_SOURCES = test_dataplane.c trace_dump.c
-test_dataplane_MODULES = lib hal mac cl hle \
+test_dataplane_MODULES = lib hal mac cl bufmgr bsu \
host interface \
mac/ca/test/fcall mac/common/test/fcall
diff --git a/cesar/test_general/dataplane/src/test_dataplane.c b/cesar/test_general/dataplane/src/test_dataplane.c
index fd881ba315..23ec012570 100644
--- a/cesar/test_general/dataplane/src/test_dataplane.c
+++ b/cesar/test_general/dataplane/src/test_dataplane.c
@@ -30,6 +30,7 @@ static test_dataplane_t test_dataplane_global;
#if CONFIG_FCALL_MME
# include "interface/interface.h"
# include "interface/inc/context.h"
+# include "interface/fcall/inc/context.h"
# include "common/defs/spidcom.h"
#endif
@@ -41,10 +42,9 @@ cp_mme_recv (void *user_data,
uint tei,
u8 *buffer,
uint length,
- bool mme_recv,
bool encryption)
{
- interface_mme_recv_done (user_data, buffer, mme_recv);
+ bufmgr_give_back (user_data, buffer);
}
/* Stub. */
@@ -173,21 +173,23 @@ test_dataplane_init (test_dataplane_t *ctx)
ctx->store = mac_store_init ();
ctx->pbproc = pbproc_init (&ctx->config, ctx->store);
mac_ntb_init (&ctx->config);
- ctx->sar = sar_init (ctx->store, ctx->pbproc, pbproc_get_ca
- (ctx->pbproc), ctx->config.seed);
+ ipmbox_t *ipmbox = ipmbox_init ();
+ bufmgr_t *bufmgr = bufmgr_init (ipmbox);
+ ctx->sar = sar_init (
+ ctx->store, ctx->pbproc, pbproc_get_ca (ctx->pbproc),
+ bufmgr, ctx->config.seed);
sar_init_measure_context (ctx->sar, ctx);
sar_init_measurement_cb (ctx->sar, ce_measurements);
- ctx->cl = cl_init (ctx->store, ctx->sar, &ctx->config);
- ctx->hle = hle_init (ctx->cl);
+ ctx->cl = cl_init (ctx->store, ctx->sar, &ctx->config, ipmbox, bufmgr);
ctx->hal_timer = hal_timer_init ();
/* Fcall. */
fcall_ctx_t *fcall;
#if CONFIG_FCALL_MME
ctx->config.sta_mac_address = SPC_OUI;
- interface_t *interface = interface_init (ctx->hle, ctx->cl, ctx->sar,
- &ctx->config);
- interface_callback_init (interface, cp_mme_recv, cp_mme_buffer_add,
- interface);
+ interface_t *interface =
+ interface_init (ctx->cl, cl_mbx_get (ctx->cl), ctx->sar,
+ &ctx->config, bufmgr);
+ interface_callback_init (interface, cp_mme_recv, interface);
fcall = interface->fcall->fcall_ctx;
#else /* !CONFIG_FCALL_MME */
fcall = my_station.fcall;
@@ -205,7 +207,7 @@ test_dataplane_init (test_dataplane_t *ctx)
ctx);
fcall_register (fcall, "add_mac", test_dataplane_add_mac_fcall, ctx);
/* Activate data plane (but not PBProc). */
- hle_activate (ctx->hle, true);
+ ipmbox_activate (ipmbox, true);
sar_activate (ctx->sar, true);
/* Test thread. */
cyg_thread_create (TEST_DATAPLANE_PRIORITY, &test_dataplane_thread,
diff --git a/cesar/test_general/dataplane/src/trace_dump.c b/cesar/test_general/dataplane/src/trace_dump.c
index 8ab9735af1..92e2c67c71 100644
--- a/cesar/test_general/dataplane/src/trace_dump.c
+++ b/cesar/test_general/dataplane/src/trace_dump.c
@@ -70,9 +70,6 @@ test_dataplane_trace_dump (test_dataplane_t *ctx, test_dataplane_msg_t *msg)
if (m->cl)
trace_buffer_dump (trace_buffer_get ("cl"),
trace_buffer_dbg_dump_callback, NULL);
- if (m->hle)
- trace_buffer_dump (trace_buffer_get ("hle"),
- trace_buffer_dbg_dump_callback, NULL);
trace_bundle_stop (trace_buffer_dbg_dump_callback, NULL);
}
#endif /* CONFIG_TRACE */
@@ -114,8 +111,6 @@ test_dataplane_trace_dump_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
m->sar = false;
if (!fcall_param_bind_helper ("cl", m->cl))
m->cl = false;
- if (!fcall_param_bind_helper ("hle", m->hle))
- m->hle = false;
}
/* Message accepted, will return later. */
fcall_param_set_async (*param, 1);
diff --git a/cesar/test_general/station/common/src/station.c b/cesar/test_general/station/common/src/station.c
index 7a21f3d4d3..d4d39111aa 100644
--- a/cesar/test_general/station/common/src/station.c
+++ b/cesar/test_general/station/common/src/station.c
@@ -19,7 +19,6 @@
#include "station/station.h"
#include "cp/cp.h"
-#include "hle/hle.h"
#include "cl/cl.h"
#include "mac/sar/sar.h"
#include "mac/pbproc/pbproc.h"
@@ -33,6 +32,7 @@
* module. **/
#if CONFIG_FCALL_MME
#include "interface/inc/context.h"
+#include "interface/fcall/inc/context.h"
#endif
#include "cl/inc/context.h"
#include "mac/pbproc/inc/context.h"
diff --git a/cesar/test_general/station/compliance/Makefile.mk b/cesar/test_general/station/compliance/Makefile.mk
index 2e457b34a4..1697afda62 100644
--- a/cesar/test_general/station/compliance/Makefile.mk
+++ b/cesar/test_general/station/compliance/Makefile.mk
@@ -1,8 +1,8 @@
TARGET_PROGRAMS= station
station_SOURCES =
-station_MODULES = lib mac/common mac cl hle interface cp hal station \
- host ce cp/av bsu \
+station_MODULES = lib mac/common mac cl interface cp hal station \
+ host ce cp/av bsu bufmgr \
test_general/station/fcall \
test_general/station/common \
$(BOARD_MODULES)
diff --git a/cesar/test_general/station/fcall/src/sta_mgr.c b/cesar/test_general/station/fcall/src/sta_mgr.c
index 1c877d48ed..e08c59ddec 100644
--- a/cesar/test_general/station/fcall/src/sta_mgr.c
+++ b/cesar/test_general/station/fcall/src/sta_mgr.c
@@ -40,7 +40,6 @@ fc_sta_mgr_get_unassoc_sta (fcall_ctx_t *fcall, fcall_param_t **param,
uint numDisSta;
uint numDisNet;
uint tei;
- mac_t mac_address;
uint is_cco;
uint pco_glid;
@@ -65,7 +64,6 @@ fc_sta_mgr_get_unassoc_sta (fcall_ctx_t *fcall, fcall_param_t **param,
numDisSta = sta->numDisSta;
numDisNet = sta->numDisNet;
tei = cp_sta_get_tei (sta);
- mac_address = cp_sta_get_mac_address (sta);
is_cco = cp_sta_get_cco_status (sta);
pco_glid = cp_sta_get_pco_glid (sta);
diff --git a/cesar/test_general/station/maximus/Makefile b/cesar/test_general/station/maximus/Makefile
index 82ceb3d3fc..363a11ed78 100644
--- a/cesar/test_general/station/maximus/Makefile
+++ b/cesar/test_general/station/maximus/Makefile
@@ -7,8 +7,8 @@ INCLUDES = test_general/station/common/override/
TARGET_PROGRAMS= sta_maximus
sta_maximus_SOURCES =
-sta_maximus_MODULES = lib mac/common mac cl hle interface cp hal station host \
- cp/av bsu \
+sta_maximus_MODULES = lib mac/common mac cl interface cp hal station host \
+ cp/av bsu bufmgr \
test_general/station/fcall \
test_general/station/common ce/stub
diff --git a/cesar/test_general/station/scenario/Makefile b/cesar/test_general/station/scenario/Makefile
index 952e5a3d3e..f174bc4bdb 100644
--- a/cesar/test_general/station/scenario/Makefile
+++ b/cesar/test_general/station/scenario/Makefile
@@ -4,8 +4,9 @@ ECOS = y
TARGET_PROGRAMS= test_scenario
test_scenario_SOURCES =
-test_scenario_MODULES = lib mac/common mac cl hle interface cp hal station \
- host cp/av bsu \
+test_scenario_MODULES = lib mac cl interface cp hal station \
+ host cp/av bsu hal/ipmbox/maximus \
+ bufmgr \
test_general/station/fcall \
test_general/station/common ce/stub
diff --git a/cesar/test_general/station/scenario/py/sc15_hide.py b/cesar/test_general/station/scenario/py/sc15_hide.py
index 700c7860a5..a7fee4e15c 100644
--- a/cesar/test_general/station/scenario/py/sc15_hide.py
+++ b/cesar/test_general/station/scenario/py/sc15_hide.py
@@ -97,7 +97,7 @@ class TestAssociationAuthentication (unittest.TestCase):
scammer.CC_SET_TEI_MAP_IND_station (tei = 2, mac = sta0_mac,
status = 0),
], 0)
- ok = protocol.protocol_exchange_check (rsp)
+ ok = protocol.protocol_exchange_check (self.csi.sniffed_packets)
self.failUnless (ok)
if __name__ == '__main__':
diff --git a/cesar/test_general/station/scenario/py/scenario_init.py b/cesar/test_general/station/scenario/py/scenario_init.py
index 838eb7522f..40c333b58f 100644
--- a/cesar/test_general/station/scenario/py/scenario_init.py
+++ b/cesar/test_general/station/scenario/py/scenario_init.py
@@ -91,11 +91,12 @@ def sniffer (maximus, sta, mme_tx = False, mme_rx = False, beacon_tx = False,
mmemax = MME ()
mmemax.set_msdu_attr (str (sniffer))
rsp = mmemax.sendnrecv (maximus, sta.get_sta_cesar().get(),
- count = 1, filter = frame_filter_sniffer,
+ count = 2, filter = frame_filter_sniffer,
timeout = sec_to_tck (1))
- m = Ether (rsp[0].get ())
- if m.mmtype == scammer.HPAV_MMTYPES['VS_SNIFFER_CNF']:
- return m.result == scammer.HPAV_RESULT['success']
+ for i in rsp:
+ m = Ether (i.get ())
+ if m.mmtype == scammer.HPAV_MMTYPES['VS_SNIFFER_CNF']:
+ return m.result == scammer.HPAV_RESULT['success']
return False
class HPAVProtocol:
@@ -172,7 +173,7 @@ class HPAVProtocol:
% (m1.pid, m2.pid)
if not pmn_ok:
print "PMN wrong, expected %d git %d" \
- % (m1.pmn. m2.pmn)
+ % (m1.pmn, m2.pmn)
return peks_ok and pid_ok and pmn_ok
def __protocol_exchange_check_mmes (self, m1, m2):
diff --git a/cesar/test_general/station/tonemap/common-define.mk b/cesar/test_general/station/tonemap/common-define.mk
index 0a56708007..cbae98997f 100644
--- a/cesar/test_general/station/tonemap/common-define.mk
+++ b/cesar/test_general/station/tonemap/common-define.mk
@@ -3,7 +3,7 @@ BASE = ../../..
# Common modules.
tonemap_modules_common = ce \
- lib mac/common mac cl hle interface cp hal station \
- cp/av bsu \
+ lib mac/common mac cl interface cp hal station \
+ cp/av bsu bufmgr \
test_general/station/fcall \
test_general/station/common host
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));
}