summaryrefslogtreecommitdiff
path: root/cesar/mac/common/src/mfs.c
blob: a9604b73ea87f414cc91ac61eeb581e6dfd4d0af (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    mac/common/src/mfs.c
 * \brief   MAC frame stream functions.
 * \ingroup mac_common
 */
#include "common/std.h"

#include "mac/common/mfs.h"
#include "mac/common/defs.h"

#include "config/mac/common.h"

static void
mfs_common_init (mfs_common_t *mfs_common, bool tx, bool bcast, bool mme, uint
                 lid, uint tei)
{
    mfs_common->tx = tx;
    mfs_common->bcast = bcast;
    mfs_common->mme = mme;
    mfs_common->ats = false;
    mfs_common->lid = lid;
    mfs_common->tei = tei;
    mfs_common->lid_alias = MAC_LID_NONE;
    mfs_common->unassociated = false;
    /* mfs_common->expiration_heap_node */
    /* mfs_common->expiration_date */
    /* mfs_common->expiration_delay */
    mfs_common->release = false;
}

void
mfs_rx_init (mfs_rx_t *mfs, bool bcast, bool mme, uint lid, uint tei)
{
    dbg_assert_ptr (mfs);
    dbg_assert ((mme && lid == MAC_LID_NONE)
                || (!mme && MAC_LID_IS_XLID (lid)));
    dbg_assert (tei != MAC_TEI_BCAST);
    mfs_common_init (&mfs->common, false, bcast, mme, lid, tei);
    mfs->head = NULL;
    mfs->last_contiguous = NULL;
    mfs->tail = NULL;
    mfs->last_offset_processed = 0;
    mfs->ssn_min = 0;
    mfs->window_size = mme ? 8 : 16;
}

void
mfs_tx_init (mfs_tx_t *mfs, bool bcast, bool mme, uint lid, uint tei)
{
    dbg_assert_ptr (mfs);
    dbg_assert ((mme && lid == MAC_LID_NONE)
                || (!mme && (MAC_LID_IS_XLID (lid)
                             || lid == MAC_LID_SPC_CENTRAL
                             || lid == MAC_LID_DISCOVER)));
    dbg_assert ((bcast && tei == MAC_TEI_BCAST)
                || (!bcast && MAC_TEI_IS_STA (tei))
                || (!bcast && mme && tei == MAC_TEI_UNASSOCIATED));
    mfs_common_init (&mfs->common, true, bcast, mme, lid, tei);
    if(CONFIG_MAC_COMMON_EOC_MFS)
    {
        mfs->cfp = true;
    }
    else
    {
        mfs->cfp = false;
    }
    mfs->burst_count = 0;
    heap_node_init (&mfs->ca_prio_link);
    list_init_node (&mfs->ca_held_link);
    mfs->ca_state = CA_MFS_STATE_UNKNOWN;
    mfs->seg_nb = 0;
    mfs->pending_seg_nb = 0;
    mfs->fsm_state = bcast ? MFS_FSM_CMD_NOP : MFS_FSM_CMD_INIT;
    mfs->min_ssn = 0;
    mfs->window_size = mme ? 8 : 16;
    mfs->window_holes_seg_nb = 0;
    mfs->cap = MAC_LID_IS_PLID (lid) ? lid : 0;
    mfs->dynamic_cap = mme;
    mfs->cap_seg_nb[0] = mfs->cap_seg_nb[1] = mfs->cap_seg_nb[2] =
        mfs->cap_seg_nb[3] = 0;
    mfs->head = NULL;
    dbg_invalid_ptr (mfs->tail);
    mfs->last_seg_offset = 0;
    mfs->next_ssn = 0;
    mfs->beacon = false;
    mfs->pending_jobs = 0;
}