summaryrefslogtreecommitdiff
path: root/cesar/maximus/stationtest/src/test_station.c
blob: 73fe7fcb54a899b6fec6d33ad9ec0b1bd479c287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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;
}