summaryrefslogtreecommitdiff
path: root/cp/beacon/beacons.h
blob: 80b572b10f6dcee4f54b143e9adb88c3112c0e7b (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
#ifndef cp_beacon_beacons_h
#define cp_beacon_beacons_h
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/beacon/beacons.h
 * \brief   CP Beacon module 
 * \ingroup cp_beacon 
 *
 */
#include <cyg/kernel/kapi.h>
#include <cyg/hal/hal_arch.h>

#include "cp/beacon/forward.h"

#include "interface/interface.h"
#include "mac/ca/ca.h"
#include "mac/pbproc/pbproc.h"
#include "mac/common/store.h"
#include "hal/phy/phy.h"
#include "hal/timer/timer.h"
#include "cp/station/station.h"
#include "cp/secu/secu.h"
#include "cp/cco/cco.h"

/** Call back used when the timer calls the beacon modules.
 * This will be use to provide the data to the CP.
 * The CP shall keep the event to request the beacon to process by calling the
 * right function. 
 *
 * \param  user_data  the data registered in the callback.
 */
typedef void (*cp_beacon_timer_cb_t) (void *user_data);

enum cp_beacon_type
{
    CP_BEACON_CENTRAL_BEACON,
    CP_BEACON_DISCOVER_BEACON,
    CP_BEACON_PROXY_BACON
};

/**
 * Init the beacons module.
 *
 * \param  interface  the interface context.
 * \param  phy  the phy context.
 * \param  sta  the station context.
 * \param  secu  the control plane security layer context.
 * \param  ca  the Channel Access context.
 * \param  mac_store mac_store.
 * \param  pbproc  pbproc.
 * \param  cco  the cco context.
 * \param  timer   the hal timer context to program the instance.
 * \param  user_data  the CP user_data to be provided with the call back.
 * \param  cb  the function to call back when the module is awake by the
 * timer.
 * \return  the beacon context.
 */
cp_beacon_t *
cp_beacon_init(interface_t *interface, phy_t *phy, cp_sta_t *sta,
               sec_t /*cp_secu_t*/ *secu, ca_t *ca,
               pbproc_t *pbproc, mac_store_t *mac_store, cp_cco_t *cco,
               hal_timer_t *timer, void *user_data, cp_beacon_timer_cb_t cb);

/**
 * Uninit the beacon module
 *
 * \param  ctx the beacon module.
 */
void
cp_beacon_uninit(cp_beacon_t *ctx);

/**
 * Create the default schedule for the CA to be able to listen the PWL on the
 * POND procedure.
 * This will create four beacon periods of a duration corresponding to
 * CP_BEACON_DEFAULT_SCHEDULE_TIME / 4.
 *
 * \param  ctx  the cp beacon context
 */
void
cp_beacon_create_default_schedule (cp_beacon_t *ctx);

/**
 * Compute the AC line frequency from the PRATIC register
 *
 * \param  ctx beacon context. 
 */
void
cp_beacon_acl_frequency_detection (cp_beacon_t *ctx);

/**
 * Compute the next BTS, the four next BTOs and the BP in Time Allocation
 * Unit to provide the data to the generated beacon.
 *
 * \param  ctx  the beacon context.
 * \param  common  the common part of the beacons structure.
 */
void
cp_beacon_estimate_bts_bto_bp (cp_beacon_t *ctx, cp_beacon_common_t *common);

/**
 * Send a beacon when the STA is acting as a CCo.
 *
 * \param  ctx  the beacon module context
 * \param  beacon_type beacon type
 */
void
cp_beacon_cco_send_beacon (cp_beacon_t *ctx, uint beacon_type);


/**
 * Generate the central beacon when the STA acts as a CCo.
 *
 * \param  ctx  the beacon context.
 */
extern inline void
cp_beacon_cco_send_central_beacon (cp_beacon_t *ctx)
{
    dbg_assert (ctx);
    cp_beacon_cco_send_beacon (ctx, CP_BEACON_CENTRAL_BEACON);
}

/**
 * Generate the discover beacon when the STA acts as a UCCo.
 *
 * \param  ctx  the beacon context.
 */
extern inline void
cp_beacon_cco_send_discover_beacon (cp_beacon_t *ctx)
{
    dbg_assert (ctx);
    cp_beacon_cco_send_beacon (ctx, CP_BEACON_DISCOVER_BEACON);
}

/**
 * Process the received beacon or countdown the counters if the beacon as
 * not been received.
 *
 * \param  ctx  the beacon context.
 * \param  beacon  the beacon received.
 */
void
cp_beacon_process (cp_beacon_t *ctx, cp_beacon_desc_t *beacon);

/**
 * Set the value of the Encryption change key countdown.
 * It allows the CCo to insert the bentry corresponding in the central beacon.
 * Each time the countdown goes to 0 the snid is changed.
 *
 * \param  ctx  the beacon context.
 * \param  kccd  the countdown value in a range from 1 to 62.
 * \param  kbc  the key being change boolean
 * \param  new_eks  the new eks to set.
 */
void
cp_beacon_set_encryption_key_change_countdown (cp_beacon_t *ctx, u8 kccd, bool kbc,
                                               u8 new_eks);

/**
 * Set the value of the Handover countdown.
 * It allows the CCo to insert the bentry corresponding in the central beacon.
 * Each time the countdown goes to 0 the snid is changed.
 *
 * \param  ctx  the beacon context.
 * \param  hcd  the countdown value in a range from 1 to 62.
 * \param  new_tei new CCo tei 
 */
void
cp_beacon_set_handover_countdown (cp_beacon_t *ctx, u8 hcd, u8 new_tei);

/**
 * Set the value of the Hybrid Mode countdown.
 * It allows the CCo to insert the bentry corresponding in the central beacon.
 * Each time the countdown goes to 0 the snid is changed.
 *
 * \param  ctx  the beacon context.
 * \param  hmccd  the countdown value in a range from 1 to 62.
 * \param  newhm new hybrid mode value 
 */
void
cp_beacon_set_change_hm_countdown (cp_beacon_t *ctx, u8 hmccd, u8 newhm);

/**
 * Set the value of the snid countdown.
 * It allows the CCo to insert the bentry corresponding in the central beacon.
 * Each time the countdown goes to 0 the snid is changed.
 *
 * \param  ctx  the beacon context.
 * \param  sccd  the countdown value in a range from 1 to 62.
 * \param  new_snid new snid value 
 */
void
cp_beacon_set_snid_countdown (cp_beacon_t *ctx, u8 sccd, u8 new_snid);

#endif /* cp_beacon_beacons_h */