summaryrefslogtreecommitdiff
path: root/cp/interf/src/interf_cl_layer.c
blob: 2e116d09fb9987c6627998fd4982742e100e4dde (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
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */

#include "common/std.h"
#include "cp/interf/inc/interf_cl_layer.h"

static cl_t *interf_cl_ctx = NULL;
static mac_store_t *interf_mac_store_ctx = NULL;

void interf_cl_layer_init (void)
{
    u8 *buf;
    int i;
    // get the mac store context
    interf_mac_store_ctx = mac_store_init ();
    // get the cl context
    interf_cl_ctx = cl_init (interf_mac_store_ctx);
    // register the receive callback at the cl
    cl_mme_recv_init (interf_cl_ctx, interf_receive, NULL);
    // transmit some buffer to the cl
    for(i=0 ; i<3 ; i++)
    {
        buf = (u8 *) interf_give_buf();
        cl_mme_recv_done (interf_cl_ctx, buf);        
    }
}

void interf_cl_layer_add_buf (msg_mme_t *msg)
{
    dbg_assert(interf_mac_store_ctx);
    dbg_assert (interf_cl_ctx);
    dbg_assert ( !msg_check_wrong_mme_const_values (msg));

}

void 
interf_cl_layer_send_buf (
                        const msg_mme_t *msg, 
                        const uint length, 
                        const msg_param_t msg_param,
                        const tei_t tei
                        )
{
    mfs_tx_t *mfs_tx;
    bool added;
    
    dbg_assert(interf_mac_store_ctx);
    dbg_assert (interf_cl_ctx);
    dbg_assert ( !msg_check_wrong_mme_const_values (msg));
    
    // Retrieve the TX MFS.
    mfs_tx = mac_store_mfs_get_tx (interf_mac_store_ctx,
                                    msg_param.mnbf, 
                                    true, 
                                    MAC_LID_NONE,
                                    tei
                                    );
    if( ! mfs_tx)
    {
        mfs_tx = mac_store_mfs_add_tx (interf_mac_store_ctx,
                                        msg_param.mnbf, 
                                        true, 
                                        MAC_LID_NONE,
                                        tei,
                                        &added
                                        );
        dbg_assert(added);
    }
    // Send the MME to the PLC
    cl_mme_send (interf_cl_ctx,
                (u8 *) msg,
                length, 
                mfs_tx,
                interf_release_buf, 
                (void *) msg
                );

}