summaryrefslogtreecommitdiff
path: root/cp/conn/src/conn.c
blob: febf31b80672d20c0b067ff87cae0cf6abb09aeb (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
109
110
111
112
113
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/conn/src/conn.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */

#include "common/std.h"
#include "cp/conn/inc/conn_defs.h"
#include "cp/conn/inc/conn_priv.h"
#include "lib/swap.h"
#include <string.h>

static conn_data_t conn_data[MAX_NB_CONN];

/****************** private functions ************************/

u16
cp_conn_cid_2_index(u16 cid)
{
    tei_t tei;
    u8 llid; 
    u16 index;
    
    llid = cid & 0xFF;
    tei = cid >> 8;
    index = (llid - MAC_LLID_MIN) * MAC_TEI_STA_NB + tei - 1;
    dbg_assert(index < COUNT(conn_data));
    return index;
}

u16
cp_conn_get_new_conn_index(void)
{
    tei_t tei;
    u8 llid;
    u16 index;
    
    tei = cp_station_get_tei(NULL);
    for(llid = MAC_LLID_MIN ; llid < MAC_LLID_MAX ; llid ++)
    {
        index = (llid - MAC_LLID_MIN) * MAC_TEI_STA_NB + tei - 1;
        if(conn_data[index].conn_status == CONN_FREE)
        {            
            return index;
        }
    }
    // all connexion are used !!!
    dbg_assert(0);
    return 0;
}


/****************** public functions ************************/

void
cp_conn_init(void)
{
    u32 i;
    for(i=0 ; i < COUNT(conn_data) ; i++)
    {
        conn_data[i].conn_status = CONN_FREE;
        conn_data[i].connexion = NULL;
        conn_data[i].req_id = 0;
    }
}

bool
cp_conn_is_multicast(mac_address_t ad)
{
    
}

void
cp_conn_create_init(mac_address_t osa, 
                    mac_address_t oda, 
                    u16 req_id, 
                    cspec_t cspec, 
                    classifier_rules_t classifier_rules)
{
    u16 index;
    
    // check if the connection is compliant with the current network mode (5.2.3.1)
    // TODO
    // do the connection admission control procedure (7.8.3)
    if(cspec.cinfo_fw.mac_service_type != CONN_CONTENTION_BASED)
    {
        // TODO
    }
    index = cp_conn_get_new_conn_index();
    if(index)
    { // create the new connection
        // record the CSPEC
        conn_data[index].connexion = blk_alloc_zero();
        memcpy(&conn_data[index].connexion->con_info.cspec, &cspec, sizeof(cspec));
        // record the connection info
        memcpy(conn_data[index].connexion->con_info.init, osa, sizeof(mac_address_t));
        memcpy(conn_data[index].connexion->con_info.term, oda, sizeof(mac_address_t));        
        memcpy(&conn_data[index].connexion->rules, &classifier_rules, sizeof(classifier_rules_t));        
        conn_data[index].req_id = req_id;
        // send the connexion request to the other station(s)
        conn_data[index].conn_status = CONN_WAIT;

    }
}