summaryrefslogtreecommitdiff
path: root/cesar/bsu/bsu.h
blob: b67d2afb95928247333ee1c3ce289fbaf81d1918 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#ifndef bsu_bsu_h
#define bsu_bsu_h
/* Cesar project {{{
 *
 * Copyright (C) 2010 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bsu/bsu.h
 * \brief   Beacon Scheduler Updater
 * \ingroup bsu
 *
 * BSU is responsible for computing the Channel Access schedules and send
 * beacons.
 */
#include "bsu/aclf/aclf.h"
#include "mac/pbproc/pbproc.h"
#include "mac/sar/sar.h"
#include "hal/timer/timer.h"
#include "bsu/beacon/beacon.h"
#include "bsu/beacon/defs.h"

/** Forward declaration. */
typedef struct bsu_t bsu_t;
typedef struct bsu_avln_t bsu_avln_t;
typedef struct bsu_avln_ntb_t bsu_avln_ntb_t;

enum bsu_update_sta_type_t
{
    BSU_UPDATE_STA_TYPE_STA,
    BSU_UPDATE_STA_TYPE_CCO,
    BSU_UPDATE_STA_TYPE_NB
};
typedef enum bsu_update_sta_type_t bsu_update_sta_type_t;

/** Function to call on beacon reception or beacon sending.
 * \param  ctx  upper layer context.
 * \param  beacon  the beacon sent or received.
 * \warn  the upper layer is responsible for releasing the reference on the
 * beacon.
 */
typedef void
(*bsu_beacon_processed_t) (void *ctx, bsu_beacon_t *beacon);

BEGIN_DECLS

/**
 * Initialise the module.
 * \param  aclf  the ACLF module context.
 * \param  mac_config  the mac config structure pointer.
 * \param  phy  the PHY context.
 * \param  mac_store  the mac store database.
 * \param  ca  the channel access context.
 * \param  sar  the SAR context.
 * \param  timer  hal timer to awake the module.
 * \param  pbproc  the pbprocessing context.
 * \return  the context.
 */
bsu_t *
bsu_init (bsu_aclf_t *aclf, mac_config_t *mac_config, phy_t *phy,
          mac_store_t *mac_store, ca_t *ca, sar_t *sar, hal_timer_t *timer,
          pbproc_t *pbproc);

/**
 * Initialise the beacon callback to send to upper layer.
 * \param  ctx  the module context
 * \param  cb  the function to call
 * \param  ul  the upper layer user data
 */
void
bsu_init_beacon_cb (bsu_t *ctx, bsu_beacon_processed_t cb, void *cb_ud);

/**
 * Uninitialise the module.
 * \param  the ctx module.
 */
void
bsu_uninit (bsu_t *ctx);

/**
 * Update the data beacon for the bsu.
 * \param  ctx  the module context.
 * \param  beacon  the beacon data to send a central beacon.
 * \param  sta  true if the station acts as a STA.
 */
void
bsu_update (bsu_t *ctx, bsu_beacon_t *beacon, bsu_update_sta_type_t sta);

/**
 * Update the tracking AVLN's identification.
 * \param  ctx  the module context.
 * \param  nid  the NID to track.
 * \param  snid  the SNID to track.
 * \param  tei  the TEI to track.
 * \param  mac  the CCo's mac address if present, MAC_ZERO otherwise.
 */
void
bsu_track_avln (bsu_t *ctx, u64 nid, u16 snid, u8 tei, mac_t mac);

/**
 * Un-track an AVLN.
 * \param  ctx  the module context.
 */
void
bsu_untrack_avln (bsu_t *ctx);

/**
 * BSU power function
 * \param  ctx  the module context.
 * \param  snid  the snid to be used in schedules during the power one
 * procedure.
 * To be called after the first bsu_update and before bsu_activate.
 */
void
bsu_power_on (bsu_t *ctx, u8 snid);

/**
 * Activates the BSU.
 * \param  ctx  the module context.
 * \param  status  true to activate, false otherwise.
 */
void
bsu_activate (bsu_t *ctx, bool status);

/**
 * Get the current NEK.
 * \param  bsu  bsu context.
 * \return  The current NEK.
 *
 * \note If a NEK change is about to happen (i.e. A new NEK will be used
 * starting from the next beacon period), then there is a period of time where
 * this function returns the next NEK instead of the current one.
 * More exactly, if the function is called after the bsu changed the
 * ctx->nek_switch, but before the next beacon period where the new NEK will
 * actually be used, then the returned NEK is the next one, not the current one.
 * As this function is called by the cp, the behavior seems acceptable.
 */
mac_nek_t *
bsu_nek_get_current (const bsu_t *bsu);

/**
 * Use the provided NEK as both the current and the next one.
 * \param  bsu  bsu context.
 * \param  nek  NEK to use.
 */
void
bsu_nek_use (bsu_t *bsu, mac_nek_t *nek);

/**
 * Set the NEK to use for the upcoming NEK change.
 * \param  ctx  bsu context.
 * \param  nek  NEK to use.
 */
void
bsu_nek_set_next (bsu_t *ctx, mac_nek_t *nek);

/**
 * Update discover info beacon entry.
 * \param  ctx  the module context.
 * \param  discover   the discover info beacon entry.
 */
void
bsu_update_discover_info (bsu_t *ctx, bsu_beacon_bmi_discover_info_t *discover);

/**
 * Update NID and SNID.
 * \param  ctx  the module context.
 * \param  nid   the nid.
 * \param  snid  the snid.
 */
void
bsu_update_nid_snid (bsu_t *ctx, u64 nid, u8 snid);

/**
 * Remove an AVLN.
 * \param  ctx  the module context.
 * \param  nid  the NID of the AVLN.
 * \param  snid  the SNID of the AVLN.
 * \param  mac  the CCo's mac address.
 *
 * The AVLNs are static object do not release it.
 */
void
bsu_avln_remove (bsu_t *ctx, u64 nid, u8 snid, mac_t mac);

/**
 * Update the tracking after a CCo change (Handover case)
 * \param  ctx  the module context.
 * \param  tei  the new CCo's TEI to track.
 * \param  mac_addr_track  the new CCo's Mac address to track.
 */
void
bsu_update_tracking (bsu_t *ctx, u8 tei, mac_t mac_addr_track);

END_DECLS

#endif /* bsu_bsu_h */