summaryrefslogtreecommitdiff
path: root/cesar/cp/cco/action/inc/cco_action.h
blob: d960a533cdc5fb617e9a22dd3a9505c68bc7a351 (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
114
115
#ifndef cp_cco_inc_cco_action_h
#define cp_cco_inc_cco_action_h
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/cco/inc/cco_action.h
 * \brief   CCo private functions.
 * \ingroup cp_cco
 *
 */
#include "lib/set.h"
#include "lib/rnd.h"

#include "cp/msg/msg.h"
#include "cp/sta/core/core.h"
#include "cp/sta/core/defs.h"
#include "cp/cco/action/cco_action.h"

#define CP_CCO_ACTION_TEI_FLAGS_ROW 8
#define CP_CCO_ACTION_TEI_FLAGS_ROW_SIZE_BITS 32 /* 32 bits. */

/* Conversion of minutes to eCos ticks. */
#define MIN_TO_RTC(val) (val * 100)

/* Return the next EKS value from the previous one. */
#define CP_CCO_ACTION_EKS_NEXT(val) \
    (((val) + 1 > MAC_EKS_MAX) ? MAC_EKS_MIN : val + 1)

/* Timeout value for the EKS exchange MME. */
#define CP_CCO_ACTION_EKS_TIMEOUT_MS 1000

struct cp_cco_action_t
{
    /** TEI in use. */
    uint tei_flags [CP_CCO_ACTION_TEI_FLAGS_ROW];

    /** Event to change the neks. */
    cp_sta_core_timed_event_def_t nek_change;
    /** EKS timeout. */
    cp_sta_core_timed_event_def_t eks_timer;
    /** EKS value to change. */
    uint eks_current;
    /** The new NEK. */
    cp_key_t nek_new;
    /** Station's TEI with the one the transaction as started. */
    cp_mme_peer_t eks_sta_current_peer;
    /** EKS protocol run. */
    cp_secu_protocol_run_t eks_prun;

    /** heap for the CCo selection process. */
    heap_t selection_heap;
};

BEGIN_DECLS

/**
 * Search for an available TEI in the AVLN list.
 * \param  ctx  the module context.
 * \return  return the TEI found.
 *
 *  Get the AVLN from the station manager (our AVLN). Lookup in the station
 * a hole of TEIs. It no hole is found and no more STAs are available
 * it means that all the TEIs are used in the AVLN. \Warn The TEI = 0
 * is reserved and 255 too
 */
cp_tei_t
cp_cco_action_tei_compute (cp_t *ctx);

/**
 * Return true if the left node is lesser than the right node.
 * \param  left  The left node.
 * \param  right  The right node.
 * \return  true if left is lesser than right.
 *
 *  This function shall compare the expiration lease of the stations
 */
bool
cp_cco_action_tei_lease_less (set_node_t * left, set_node_t * right);


/**
 * Removes a station from the CCo selection procedure.
 * \param  ctx  the module context.
 * \param  sta  the station to remove.
 *
 * This function shall remove a station from the CCO selection procedure. It
 * shall be called when the station refuse to become the New CCo or a timeout
 * on the handover procedure.
 */
void
cp_cco_action_cco_selection__sta_remove (cp_t *ctx, cp_sta_t *sta);

/**
 * Clear the selection context.
 * \param  ctx  the module context.
 */
void
cp_cco_action_cco_selection__clear (cp_t *ctx);

/**
 * Selects the Next CCo on the AVLN.
 * \param  ctx  the module context.
 * \return  the station elected or NULL.
 */
cp_sta_t *
cp_cco_action_cco_selection__selection (cp_t *ctx);

END_DECLS

#endif /* cp_cco_inc_cco_action_h */