summaryrefslogtreecommitdiff
path: root/cesar/maximus/stationtest/src/test_log.c
diff options
context:
space:
mode:
authorCeline Buret2012-01-13 16:27:58 +0100
committerCeline Buret2012-04-12 14:26:53 +0200
commite50c8cfc7de9e375c8d0ce4a1820860a52cb1e8f (patch)
tree5d1e21c3b5a63e0d8a43cd7dacfb726ad0355c2b /cesar/maximus/stationtest/src/test_log.c
parentea8a5d730db3d1e20b35d20e7163f1427831e564 (diff)
cesar/{host,maximus}: warn user if log is truncated, refs #43
Until now, log was truncated silently if its length reached the max log length. With this commit, user is informed when the station log is too big and truncated.
Diffstat (limited to 'cesar/maximus/stationtest/src/test_log.c')
-rw-r--r--cesar/maximus/stationtest/src/test_log.c193
1 files changed, 193 insertions, 0 deletions
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;
+}