summaryrefslogtreecommitdiff
path: root/cesar/cp2/msg/src/mme.c
blob: 9736d08e45dce6263be35d582481cd0b56c7f5da (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
102
103
104
105
106
107
108
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp2/msg/src/mme.c
 * \brief   Function to init and destroy the MME messages.
 * \ingroup cp2_msg
 *
 */
#include "common/std.h"

#include "common/defs/ethernet.h"
#include "lib/slab.h"

#include "interface/interface.h"
#include "cp2/msg/inc/msg.h"

#include "cp2/inc/context.h"

/**
 * Function to init the mme rx t messages.
 * \param  ctx  the module context.
 * \param  mme   the MME received.
 * \param  length  the MME length.
 * \param  tei  the source TEI.
 * \return  the mme rx message initialised.
 */
cp_mme_rx_t *
cp_msg_mme_rx_init (cp_t *ctx, u8 *mme, uint length, cp_tei_t tei)
{
    cp_mme_rx_t *mme_rx;

    dbg_assert (ctx);
    dbg_assert (mme);
    dbg_assert (length >= ETH_PACKET_MIN_SIZE
                && length <= ETH_PACKET_MAX_SIZE);

    // Allocate the MME with the slab allocator.
    mme_rx = slab_alloc (&ctx->msg.mme_rx_slab_cache);

    dbg_assert (mme_rx);
    memset (mme_rx, 0, sizeof (cp_mme_rx_t));
    mme_rx->p_mme = mme;
    mme_rx->length = length;
    mme_rx->peer.tei = tei;
    mme_rx->cp = ctx;

    return mme_rx;
}

/**
 * Function to init the mme rx t messages.
 * \param  ctx the module context.
 * \return  the mme rx message initialised.
 */
cp_mme_tx_t *
cp_msg_mme_tx_init (cp_t *ctx)
{
    cp_mme_tx_t *mme;

    dbg_assert (ctx);
    mme = slab_alloc (&ctx->msg.mme_tx_slab_cache);
    memset (mme, 0, sizeof (cp_mme_tx_t));

    mme->cp = ctx;
    return mme;
}

/**
 * Function destructor for the MME RX messages.
 * \param  ctx  the module context.
 * \param  msg  the message context.
 */
void
cp_msg_mme_rx_destructor (cp_mme_rx_t *mme)
{
    blk_t *blk;

    dbg_assert (mme);

    if (mme->p_mme)
        interface_mme_recv_done (mme->cp->interface, mme->cl_data);

    while (mme->p_frag)
    {
        blk = mme->p_frag;
        mme->p_frag = blk->next;
        blk_release (blk);
    }
}

/**
 * Function destructor for the MME TX messages.
 * \param  msg  the message context.
 */
void
cp_msg_mme_tx_destructor (cp_mme_tx_t *mme)
{
    dbg_assert (mme);

    if (mme->p_mme)
        cp_cl_interf_add_buffer_tx (mme->cp, mme->p_mme);
}