summaryrefslogtreecommitdiff
path: root/cesar/maximus/stationtest
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/stationtest')
-rw-r--r--cesar/maximus/stationtest/Makefile10
-rw-r--r--cesar/maximus/stationtest/src/test_log.c193
2 files changed, 200 insertions, 3 deletions
diff --git a/cesar/maximus/stationtest/Makefile b/cesar/maximus/stationtest/Makefile
index acc4d499f4..40f2f39c5f 100644
--- a/cesar/maximus/stationtest/Makefile
+++ b/cesar/maximus/stationtest/Makefile
@@ -2,9 +2,9 @@ BASE = ../..
ECOS = y
-TARGET_PROGRAMS = exception hello_world one_thread threaddelay \
- stationtest \
- test_cb test_ether test_false_alarm test_lib_cesar test_send test_station test_tx_rx
+TARGET_PROGRAMS = exception hello_world one_thread threaddelay stationtest \
+ test_cb test_ether test_false_alarm test_lib_cesar test_send test_station \
+ test_tx_rx test_log
exception_SOURCES = exception.c
exception_MODULES = lib host
@@ -45,4 +45,8 @@ 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
+cp_beacon_MODULE_SOURCES = beacons.c bentry.c
+test_log_SOURCES = test_log.c
+test_log_MODULES = lib host hal/ipmbox/maximus hal/phy/maximus/dur/maximus
+
include $(BASE)/common/make/top.mk
diff --git a/cesar/maximus/stationtest/src/test_log.c b/cesar/maximus/stationtest/src/test_log.c
new file mode 100644
index 0000000000..1329144d9f
--- /dev/null
+++ b/cesar/maximus/stationtest/src/test_log.c
@@ -0,0 +1,193 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file test_station.c
+ * \brief station executable used for the test station program
+ * \ingroup
+ */
+
+#include "common/std.h"
+#include "common/defs/homeplugAV.h"
+#include "host/station/station.h" /* for 'station_ctx_t' */
+#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 <cyg/infra/diag.h>
+#include <stdio.h>
+
+#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
+rx_cb_mbx (void *user_data, u32 *first_msg, uint length)
+{
+ /* Reset IT. */
+ 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. */
+
+ /* 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;
+ /* REQ => CNF */
+ *(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME)) =
+ *(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME)) + 1;
+ *(cnf_data + HPAV_MME_HEADER) = RESULT_SUCCESS;
+
+ /* CNF data length. */
+ uint cnf_data_length = 0;
+ u16 mmtype = (
+ (u16) (*(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME) + 1) << 8)
+ | (u16) (*(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME))));
+ 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;
+ }
+
+ /* 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 ipmbox. */
+ ipmbox_uninit (ctx);
+
+ /* Now make the return parameter list. */
+ fcall_param_reset (*param);
+
+ return 0;
+}
+
+#define MIN_LEN 2
+#define MAX_LEN STATION_MAX_LOG_SIZE
+#define BIG_LEN (STATION_MAX_LOG_SIZE + 1)
+
+int test_log (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg,
+ void *data)
+{
+ char min[MIN_LEN];
+ memset (min, 'm', MIN_LEN - 1);
+ min[MIN_LEN - 1]='\0';
+
+ char max[MAX_LEN];
+ memset (max, 'm', MAX_LEN - 1);
+ min[MAX_LEN - 1]='\0';
+
+ char big[BIG_LEN];
+ memset (big, 'b', BIG_LEN - 1);
+ big[BIG_LEN - 1]='\0';
+
+ station_log_set_level(&my_station, STATION_LOG_WARNING);
+ station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
+ my_station.pipe_log_fd = 1;
+
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_STATION,
+ "%s", min);
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_STATION,
+ "%s", max);
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_STATION,
+ "%s", big);
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+int main (void)
+{
+ /* 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;
+
+ /* Activate ipmbox interruptions. */
+ ipmbox_activate (ctx, true);
+
+ fcall_register (my_station.fcall, "uninit_ether", (void*) &uninit_ether,
+ NULL);
+ fcall_register(my_station.fcall, "test_log", (void*) &test_log, NULL);
+
+ return 0;
+}