summaryrefslogtreecommitdiff
path: root/cesar/maximus/stationtest/src/test_station.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/stationtest/src/test_station.c')
-rw-r--r--cesar/maximus/stationtest/src/test_station.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/cesar/maximus/stationtest/src/test_station.c b/cesar/maximus/stationtest/src/test_station.c
new file mode 100644
index 0000000000..73fe7fcb54
--- /dev/null
+++ b/cesar/maximus/stationtest/src/test_station.c
@@ -0,0 +1,91 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file test_station.c
+ * \brief station executable used for the test station program
+ * \ingroup
+ */
+
+#include "common/std.h"
+#include "host/station.h" // for 'station_ctx_t'
+#include "cp/beacon/beacons.h" // for 'cp_sta_t'
+#include "cp/station/maximus/inc/maximus_cp_station.h" // for 'maximus_cp_station_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 "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
+
+cp_sta_t cp_sta_global;
+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)
+{
+ // Reset IT
+ maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+
+ ipmbox_msg_hdr_t *hdr = (ipmbox_msg_hdr_t *)&ctx->rx.mailbox[0];
+ if (HLE_MSG_TYPE_DATA == hdr->type)
+ {
+ /* When receiving an Ether SCI message of type MME REQ from Maximus,
+ * send the answer (an Ether SCI message of type MME CNF). */
+
+ uint data_length = (uint)(hdr->param >> 1);
+ memcpy(ctx->first_buffer->next->data, (u32 *)ctx->rx.mailbox[1], data_length);
+ char *data = (char *)ctx->first_buffer->next->data;
+ *(data + 15) = *(data + 15) + 1; // REQ => CNF
+ *(data + 19) = 0x01; // Success
+ memset(data + 20, '\0', data_length - 20);
+
+ // 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 |= 0x001;
+ ctx->rx.mailbox[1] = (u32)ctx->first_buffer->next->data;
+ ipmbox_tx (ctx, ctx->rx.mailbox, ctx->rx.length);
+ }
+
+ return;
+}
+
+int uninit_ether (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
+{
+ // Uninitialize the HAL HLE ipmbox
+ ipmbox_uninit (ctx);
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+int main (void)
+{
+ station_log_set_level(&my_station, STATION_LOG_WARNING);
+ station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
+ my_station.pipe_log_fd = 1;
+
+ maximus_cp_station_init(&my_station);
+
+ // Initialize the HAL HLE ipmbox
+ ctx = ipmbox_init ((void *)&user_data, &ipmbox_rx_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);
+
+ return 0;
+}