summaryrefslogtreecommitdiff
path: root/cesar/cp/beacon/inc/bentry.h
blob: d8c0cef81539998c81b8733182dfaeb65b82baee (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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#ifndef cp_beacon_inc_bentry_h
#define cp_beacon_inc_bentry_h
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/beacon/inc/bentry.h
 * \brief   bentry private functions. 
 * \ingroup cp_beacon
 *
 */

#include "cp/beacon/beacons.h"
#include "mac/pbproc/pbproc.h"

#include "cp/beacon/inc/bentries_structs.h"
#include "cp/beacon/inc/beacons_work.h"

#define CP_BENRTY_MAX_SAI_DATA_VALUE 4095
#define CP_BENRTY_MAX_SAI_DATA_VALUE_TCK MAC_ATU_TO_TCK(4095)
#define CP_BENTRY_MAX_SAI_MAX_NS 63

enum cp_bentry_header_t
{
    CP_BENTRY_NON_PERSISTENT_SCHEDULE,
    CP_BENTRY_PERSISTENT_SCHEDULE,
    CP_BENTRY_REGIONS,
    CP_BENTRY_MAC_ADDRESS,
    CP_BENTRY_DISCOVER,
    CP_BENTRY_DISCOVER_INFO,
    CP_BENTRY_BEACON_PERIOD_START_OFFSET,
    CP_BENTRY_ENCRYPTION_KEY_CHANGE,
    CP_BENTRY_CCO_HANDOVER,
    CP_BENTRY_BEACON_RELOCATION,
    CP_BENTRY_AC_LINE_SYNC_COUNTDOWN,
    CP_BENTRY_CHANGE_NUMSLOTS,
    CP_BENTRY_CHANGE_HM,
    CP_BENTRY_CHANGE_SNID,
    CP_BENTRY_VENDOR=0xFF
};

enum cp_bentry_regions_type_t
{
    CP_BENTRY_REGIONS_RSVD,
    CP_BENTRY_REGIONS_SHARED_CSMA,
    CP_BENTRY_REGIONS_LOCAL_CSMA,
    CP_BENTRY_REGIONS_STAYOUT,
    CP_BENTRY_REGIONS_PROTECTED,
    CP_BENTRY_REGIONS_BEACON
};

struct cp_bentries_data_t
{
    /** Non persistent Preview schedule countdown. */
    u8 pscd;
    /** Non persistent current schedule countdown. */
    u8 cscd;
    /** Key change countdown. */
    u8 kccd;
    /** Handover countdown. */
    u8 hcd;
    /** Relocation countdown. */
    u8 rcd;
    /** AC line countdown. */
    u8 aclcd;
    /** Change numslot. */
    u8 nsccd;
    /** Change Hibryd mode countdown. */
    u8 hmccd;
    /** Change snid countdown. */
    u8 sccd;


    /** New TEI CCo. */
    u8 nctei;
    /** New Hybrid Mode. */
    u8 newHm;
    /** New SNID. */
    u8 newSNID;
    /** Discover info list. */
    uint discover_info;
};

/**
 * Fill the bentry header
 *
 * \param  bentry_header_addr  the bentry address.
 * \param  type  the type of bentry.
 * \param  length  the bentry length in bytes.
 *
 * \return the address to store the rest of the bentry.
 */
u8 *
cp_bentry_header_fill (u8 *bentry_header_addr, uint type, uint length);

/**
 * Create the non persistent schedule bentry for the beacon period.
 *
 * \param  ctx  the cp_beacon_context. 
 * \param  bentry_addr  the address to store the data in the beacon payload.
 * \param  sched  the ca schedule to fill the next schedule.
 * \return  the next address to store the next bentry.
 */
u8 *
cp_bentry_non_persistent_schedule(cp_beacon_t *ctx, u8 *bentry_addr,
                              cp_beacon_desc_alloc_t *sched);


/**
 * Create the schedules when the STA is UCCo to be correspond to the current
 * schedule of the CCo.
 * The schedule provided are non persistent, it is on vailable if the STA is
 * not associated with the CCo and the CCo is a UCCo.
 *
 * \param  ctx  the cp beacon module context
 * \param  bentry_addr  the bentry addr
 * \return  the address of the next bentry. 
 */
u8 *
cp_bentry_default_schedule (cp_beacon_t *ctx, u8 *bentry_addr);

/**
 * Create the schedule bentry for the beacon period.
 *
 * \param  ctx  the cp_beacon_context. 
 * \param  bentry_addr  the address to store the data in the beacon payload.
 * \param  sched  the ca schedule to fill the next schedule.
 * \return  the next address to store the next bentry.
 */
u8 *
cp_bentry_persistent_schedule(cp_beacon_t *ctx, u8 *bentry_addr,
                              cp_beacon_desc_alloc_t *sched);

/**
 * Create the regions for the beacons.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry_addr  the bentry address.
 */
u8 *
cp_bentry_regions (cp_beacon_t *ctx, u8 *bentry_addr);

/**
 * Store the mac address of the station in the beacon bentry
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry_addr  the bentry addr.
 * \return  the next address to store the next bentry.
 */
u8 *
cp_bentry_mac_address(cp_beacon_t *ctx, u8 *bentry_addr);

/**
 * Store the tei of the next sta which shall send a discover beacon.
 *
 * \param  ctx  the cp_beacon context.
 * \param  bentry_addr  the bentry addr
 * \param  tei  the sta tei to request a discover beacon.
 * \return  the next address to store the next bentry.
 */
u8 *
cp_bentry_discover(cp_beacon_t *ctx, u8 *bentry_addr, u8 tei);

/**
 * Store the discover list in the bentry.
 *
 * \param  ctx  the cp_beacon context.
 * \param  bentry_addr  the bentry addr
 * \return  the next address to store the next bentry.* \param  ctx
 */
u8 *
cp_bentry_discover_info(cp_beacon_t *ctx, u8 *bentry_addr);

/**
 * BPSTO always present in CSMA only mode and for discover beacons.
 * This bentry data is stamped by the CA.
 * The address of the first byte of the BPSTO is stored in bpsto camp of the
 * structure common.
 *
 * \param  ctx  the cp_beacon context.
 * \param  common  common data of all beacons.
 * \param  bentry_addr  the bentry addr
 * \return  the next address to store the next bentry.
 */
u8 *
cp_bentry_bpsto (cp_beacon_t *ctx, cp_beacon_common_t *common, u8 *bentry_addr);

/**
 * Encryption key change.
 *
 * \param  ctx  the cp_beacon context.
 * \param  bentry_addr  the bentry addr
 * \return  the next address to store the next bentry. 
 */
u8 *
cp_bentry_encryption_key_change (cp_beacon_t *ctx, u8 *bentry_addr);

/**
 * Handover. Add a the bentry when the CCo will change.
 *
 * \param  ctx  the cp_beacon context.
 * \param  bentry_addr  the bentry addr
 * \param  new_cco_tei  the new cco tei.
 * \return  the next address to store the next bentry. 
 */
u8 *
cp_bentry_handover(cp_beacon_t *ctx, u8 *bentry_addr, u8 new_cco_tei);

/**
 * Chnage hybrid mode
 *
 * \param  ctx  the cp_beacon context.
 * \param  bentry_addr the bentry addr
 * \return  the next address to store the next bentry.
 */
u8 *
cp_bentry_change_hm (cp_beacon_t *ctx, u8 *bentry_addr);

/**
 * Chnage The snid.
 *
 * \param  ctx  the cp_beacon context.
 * \param  bentry_addr the bentry addr
 * \return  the next address to store the next bentry.
 */
u8 *
cp_bentry_change_snid (cp_beacon_t *ctx, u8 *bentry_addr);

/**
 * Process the persistent schedule bentry
 * 
 * \param  ctx  the cp_beacon context.
 * \param  bentry  the bentry to process.
 * \param  sched  the current schedule to program
 */
u8 *
cp_bentry_persistent_schedule_process (cp_beacon_t *ctx, u8 *bentry,
                                       cp_beacon_desc_alloc_t *sched);

/**
 * Process the non persistent schedule bentry
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 * \param  sched  the shedule to program
 */
u8 *
cp_bentry_non_persistent_schedule_process (cp_beacon_t *ctx, u8 *bentry,
                                           cp_beacon_desc_alloc_t *sched);

/**
 * Process a bentry regions.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process, the bentry payload, it does not contain the
 * bentry header and the bentry length.
 */
u8 *
cp_bentry_regions_process (cp_beacon_t *ctx, u8 *bentry);

/**
 * Process a mac address bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process only the payload, the bentry header and the
 * length are not provided.
 * \param  mac  the mac address buffer to copy it into
 */
u8 *
cp_bentry_mac_address_process (cp_beacon_t *ctx, u8 *bentry, mac_t *mac);

/**
 * Process a discover bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 * \param  central_beacon  the central beacon received.
 */
u8 *
cp_bentry_discover_process (cp_beacon_t *ctx, u8 *bentry,
                            cp_beacon_desc_t *central_beacon);

/**
 * Process a discover info bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_discover_info_process (cp_beacon_t *ctx, u8 *bentry);

/**
 * Process a beacon period start offset bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process, the bentry payload, it does not contain the
 * bentry header and the bentry length.
 * \param  bpsto  the beacon period start time offset to be filled.
 */
u8 *
cp_bentry_bpsto_process (cp_beacon_t *ctx, u8 *bentry, uint *bpsto);

/**
 * Process the encryption key change bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_encryption_key_change_process (cp_beacon_t *ctx, u8 *bentry);

/**
 * Process the Handover in progress bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_handover_process (cp_beacon_t *ctx, u8 *bentry);

/**
 * Process the beacon relocation bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_beacon_relocation_process (cp_beacon_t *ctx, u8 *bentry);

/**
 * Process the AC Line synchronization bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_ac_line_sync_countdown_process (cp_beacon_t *ctx, u8 *bentry);
            
/**
 * Process the bentry change num slots.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_change_num_slots_process (cp_beacon_t *ctx, u8 *bentry);
               
/**
 * Process the change Hybrid Mode bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_change_hm_process (cp_beacon_t *ctx, u8 *bentry);
   
/**
 * Process the change snid bentry.
 *
 *\param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_change_snid_process (cp_beacon_t *ctx, u8 *bentry);
               
/**
 * Proces the vendor specific bentry.
 *
 * \param  ctx  the cp_beacon context
 * \param  bentry to process
 */
u8 *
cp_bentry_vendor_specific_process (cp_beacon_t *ctx, u8 *bentry);

#endif /* cp_beacon_inc_bentry_h */