summaryrefslogtreecommitdiff
path: root/mac/pbproc/test/maximus/src/add_beacon_period.c
blob: 21f15509252b3187d977ee4a17bc58b6dcff2b2f (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
92
93
94
95
96
97
98
99
100
101
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/add_beacon_period.c
 * \brief   Add beacon period fcall.
 * \ingroup test
 */
#include "common/std.h"

#include "host/fcall.h"
#include "mac/common/mfs.h"
#include "mac/common/store.h"
#include "mac/common/timings.h"

#include "inc/test_pbproc.h"
#include "inc/add_beacon_period.h"
#include "inc/context.h"

static int
test_pbproc_add_beacon_period_fcall (fcall_ctx_t *fcall,
                                     fcall_param_t **param, sci_msg_t **msg,
                                     void *data);

void
test_pbproc_add_beacon_period_init (test_pbproc_t *ctx)
{
    dbg_assert (ctx);
    fcall_register (my_station.fcall, "add_beacon_period",
                    test_pbproc_add_beacon_period_fcall, ctx);
}

static void
test_pbproc_add_beacon_period (test_pbproc_t *ctx, u32 start_date, uint glid,
                               mac_coexistence_mode_t coex,
                               uint beacon_period_tck)
{
    dbg_assert (ctx);
    /* Get and fill schedule. */
    uint schedule_index = ctx->beacon_periods_nb == 0 ? 0 :
        ((ctx->beacon_periods[ctx->beacon_periods_nb - 1].schedule_index + 1)
         % (TEST_PBPROC_NB_BEACON_PERIOD + 1));
    ca_schedule_t *sched = ca_alloc_get_schedule (ctx->ca, schedule_index);
    sched->coexistence_mode = coex;
    sched->nek_switch = 0;
    sched->allocations_nb = 1;
    sched->allocations[0].end_offset_tck = beacon_period_tck
        ? beacon_period_tck : MAC_MS_TO_TCK (1000) / 50;
    sched->allocations[0].glid = glid;
    /* Update the beacon period table. */
    if (ctx->beacon_periods_nb == TEST_PBPROC_NB_BEACON_PERIOD)
    {
        uint i;
        for (i = 0; i < TEST_PBPROC_NB_BEACON_PERIOD - 1; i++)
            ctx->beacon_periods[i] = ctx->beacon_periods[i + 1];
        ctx->beacon_periods_nb--;
    }
    ctx->beacon_periods[ctx->beacon_periods_nb].start_date = start_date;
    ctx->beacon_periods[ctx->beacon_periods_nb].schedule_index =
        schedule_index;
    ctx->beacon_periods_nb++;
    /* Use the new one. */
    ca_alloc_update_beacon_periods (ctx->ca, ctx->beacon_periods,
                                    ctx->beacon_periods_nb);
}

static int
test_pbproc_add_beacon_period_fcall (fcall_ctx_t *fcall,
                                     fcall_param_t **param, sci_msg_t **msg,
                                     void *data)
{
    dbg_assert (fcall);
    dbg_assert (param && *param);
    dbg_assert (msg && *msg);
    test_pbproc_t *ctx = (void *) data;
    dbg_assert (ctx);
    /* Read message. */
    u32 start_date;
    uint glid;
    uint beacon_period_tck;
    mac_coexistence_mode_t coex;
    if (!test_pbproc_fcall_bind_long ("start_date", start_date))
        return -1;
    if (!test_pbproc_fcall_bind_long ("glid", glid))
        return -1;
    if (!test_pbproc_fcall_bind_long ("coex", coex))
        coex = MAC_COEXISTENCE_AV_ONLY_MODE;
    if (!test_pbproc_fcall_bind_long ("beacon_period_tck", beacon_period_tck))
        beacon_period_tck = 0;
    /* Add beacon period. */
    test_pbproc_add_beacon_period (ctx, start_date, glid, coex,
                                   beacon_period_tck);
    /* Return. */
    fcall_param_reset (*param);
    return 0;
}