summaryrefslogtreecommitdiff
path: root/cesar/bsu/beacon/beacon.h
blob: dbaa5eb7856ebedca455a4b379bf12d95ebb032f (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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#ifndef bsu_beacon_h
#define bsu_beacon_h
/* Cesar project {{{
 *
 * Copyright (C) 2010 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bsu/beacon/beacon.h
 * \brief   Beacon library
 * \ingroup bsu_beacon
 *
 * Functions to read and write beacons.
 */
#include "lib/bitstream.h"
#include "bsu/beacon/defs.h"
#include "bsu/beacon/inc/region.h"
#include "bsu/beacon/inc/schedule.h"
#include "bsu/beacon/inc/misc.h"
#include "mac/common/pb.h"
#include "mac/pbproc/pbproc.h"

/** Number of schedules information kept from the beacon. */
#define BSU_BEACON_SCHEDULES_NB 3

enum bsu_beacon_direction_t
{
    BSU_BEACON_DIRECTION_TO_PLC,
    BSU_BEACON_DIRECTION_FROM_PLC,
    BSU_BEACON_DIRECTION_NB
};
typedef enum bsu_beacon_direction_t bsu_beacon_direction_t;

/** BSU computed parameters. */
struct bsu_beacon_params_t
{
    /** Pbproc RX parameters. */
    pbproc_rx_beacon_params_t rx_parameters;
    /** Direction */
    bsu_beacon_direction_t direction;
    /** Frequency error. */
    s32 frequency_error;
    /** Tick offset, difference between the NTB and PHY Date clock. */
    u32 ntb_offset_tck;
    /** Frequency error is valid. */
    bool frequency_error_valid;
};
typedef struct bsu_beacon_params_t bsu_beacon_params_t;

enum bsu_beacon_type_t
{
    BSU_BEACON_TYPE_CENTRAL,
    BSU_BEACON_TYPE_DISCOVER,
    BSU_BEACON_TYPE_PROXY,
    BSU_BEACON_TYPE_NB
};
typedef enum bsu_beacon_type_t bsu_beacon_type_t;

enum bsu_beacon_region_type_t
{
    BSU_BEACON_REGION_RESERVED,
    BSU_BEACON_REGION_SHARED_CSMA,
    BSU_BEACON_REGION_LOCAL_CSMA,
    BSU_BEACON_REGION_STAYOUT,
    BSU_BEACON_REGION_PROTECTED,
    BSU_BEACON_REGION_BEACON,
    BSU_BEACON_REGION_NB
};
typedef enum bsu_beacon_region_type_t bsu_beacon_region_type_t;

struct bsu_beacon_variant_fields_t
{
    /** Network Identifier. */
    u64 nid;
    /** Hybrid mode. */
    u8 hm;
    /** Source TEI. */
    u8 stei;
    /** Beacon type. */
    bsu_beacon_type_t bt;
    /** Non-Coordinating Networks Reported. */
    bool ncnr;
    /** Network Power Saving Mode. */
    bool npsm;
    /** Number of beacon slots. */
    u8 numslots;
    /** Beacon slot usage. */
    u8 slotusage;
    /** Slot identifier. */
    u8 slotid;
    /** AC Line Synchronization Status. */
    u8 aclsss;
    /** Handover in Progress. */
    bool hoip;
    /** RTS Broadcast Flag. */
    bool rtsbf;
    /** Network Mode. */
    mac_network_mode_t nm;
    /** CCo Capability. */
    u8 ccocap;
};
typedef struct bsu_beacon_variant_fields_t bsu_beacon_variant_fields_t;

/** Beacon Management information. */
struct bsu_beacon_bmi_t
{
    /** Number of beacon entries. */
    u32 nbe;
    /** Region beacon entry. */
    bsu_beacon_bmi_region_t region;
    /** Persistent schedule. */
    bsu_beacon_bmi_persistent_schedule_t ps;
    /** Non persistent schedule. */
    bsu_beacon_bmi_non_persistent_schedule_t nps;
    /** Discover bentry. */
    bsu_beacon_bmi_discover_t discover;
    /** Beacon period start time offset. */
    bsu_beacon_bmi_bpsto_t bpsto;
    /** Discover info bentry. */
    bsu_beacon_bmi_discover_info_t discover_info;
    /** Encryption key change. */
    bsu_beacon_bmi_eks_t eks;
    /** CCo Handover. */
    bsu_beacon_bmi_handover_t handover;
    /** Beacon relocation. */
    bsu_beacon_bmi_relocation_t relocation;
    /** AC Line synchronization countdown. */
    bsu_beacon_bmi_aclsc_t aclsc;
    /** Change number of slots. */
    bsu_beacon_bmi_change_num_slot_t cns;
    /** Change hybrid mode. */
    bsu_beacon_bmi_change_hybrid_mode_t change_hm;
    /** Change SNID. */
    bsu_beacon_bmi_change_snid_t change_snid;
    /** Mac Address. */
    bsu_beacon_bmi_mac_address_t mac_address;
};
typedef struct bsu_beacon_bmi_t bsu_beacon_bmi_t;

/** beacon description structure. */
struct bsu_beacon_t
{
    /** Next pointer, usefull to chain beacons in a list if necessary.*/
    struct bsu_beacon_t *next;
    /** Data are valid for the beacon period starting at this date. */
    u32 beacon_period_start_date;
    /** Variant fields. */
    bsu_beacon_variant_fields_t vf;
    /** Beacon Management Information. */
    bsu_beacon_bmi_t bmis;
    /** Parameters received with the beacon in the frame control. */
    bsu_beacon_params_t params;
};
typedef struct bsu_beacon_t bsu_beacon_t;

/** Schedule description for the AVLN. */
struct bsu_beacon_schedules_t
{
    /** Network mode. */
    mac_network_mode_t nm;
    /** Persistent schedule. */
    bsu_beacon_bmi_persistent_schedule_t ps;
    /** Non persistent schedule. */
    bsu_beacon_bmi_non_persistent_schedule_t nps;
    /** Beacon period start time offset. */
    bsu_beacon_bmi_bpsto_t bpsto;
    /** SNID change beacon entry. */
    bsu_beacon_bmi_change_snid_t snid;
    /** EKS change beacon entry. */
    bsu_beacon_bmi_eks_t eks;
    /** Change hybrid mode. */
    bsu_beacon_bmi_change_hybrid_mode_t hm;
};
typedef struct bsu_beacon_schedules_t bsu_beacon_schedules_t;

BEGIN_DECLS

/**
 * When the bitstream is initialised it will fill the phy beacon with the
 * bitstream.
 * \param  beacon  the bsu_beacon containing the data.
 * \param  stream  the bitstream to use.
 * \param  data  the start address where the beacon is written down.
 * \return  the offset to store the BSPTO when network mode is CSMA_ONLY.
 *
 * phy_beacon is necessary to store a part of the NID in the phy_beacon
 * header.
 * \warn client is responsible for initialising and finalising the bitstream.
 * The NID is not embedded with this function, client is responsible to store
 * it with the bitstream.
 */
uint
bsu_beacon_write_bitstream_initialised_no_nid (
    bsu_beacon_t *beacon, bitstream_t *stream, u8 *data);

/**
 * When the bitstream is initialised it will fill the phy beacon with the
 * bitstream.
 * \param  beacon  the bsu_beacon containing the data.
 * \param  stream  the bitstream to use.
 * \param  pbbeacon  the physical beacon to write in.
 * \return  the offset to store the BSPTO when network mode is CSMA_ONLY.
 *
 * phy_beacon is necessary to store a part of the NID in the phy_beacon
 * header.
 */
uint
bsu_beacon_write_bitstream_initialised (
    bsu_beacon_t *beacon, bitstream_t *stream, pb_beacon_t *pbbeacon);

/**
 * Write a beacon to be sent on the medium
 * \param  beacon  the beacon containing the data to store.
 * \param  type  the beacon type to send.
 * \param  mac_config  the mac config object.
 * \param  params  the TX beacon params containing the BPSTO and BTO.
 * \return  a beacon ready to send over the medium.
 */
pb_beacon_t*
bsu_beacon_write (bsu_beacon_t *beacon, bsu_beacon_type_t type,
                  mac_config_t *mac_config,
                  pbproc_tx_beacon_params_t *params);

/**
 * Read the whole beacon and store the data into the beacon structure.
 * \param  pbbeacon  the beacon received from the medium.
 * \param  beacon  the structure to store the data.
 * \return  true on success false otherwise.
 */
bool
bsu_beacon_read (pb_beacon_t *pbbeacon, bsu_beacon_t *beacon);

/**
 * Decrease the countdown values of the beacon.
 * \param  beacon  the beacon structure to decrease the values.
 */
void
bsu_beacon_countdown (bsu_beacon_t *beacon);

END_DECLS

#endif /* bsu_beacon_h */