summaryrefslogtreecommitdiff
path: root/cp/beacon/inc/beacons_ctx.h
blob: 41594b7d84dbea3cef70f484b6866feb582611e6 (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
#ifndef cp_beacon_inc_beacons_ctx_h
#define cp_beacon_inc_beacons_ctx_h
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp/beacon/inc/beacons_ctx.h
 * \brief   beacon modules. 
 * \ingroup cp_beacon
 *
 * « long description »
 */

#include "lib/trace.h"
#include "hal/phy/phy.h"

#include "interface/interface.h"

#include "cp/station/station.h"
#include "cp/secu/inc/secu_types.h"
#include "cp/secu/secu.h"

#include "cp/beacon/inc/trace.h"
#include "cp/beacon/inc/bentry.h"
#include "hal/timer/timer.h"
#include "mac/pbproc/pbproc.h"

#define CP_BEACON_K 6 // 2^7 when the shift operator is use.

#define CP_BEACON_DEFAULT_SCHEDULE_TIME 12
#define CP_BEACON_DEFAULT_BP_WIDTH (CP_BEACON_DEFAULT_SCHEDULE_TIME*1000000/4)


enum regions_type_t
{
    CP_REGION_RESERVED,
    CP_REGION_SHARED_CSMA, 
    CP_REGION_LOCAL_CSMA,
    CP_REGION_STAYOUT,
    CP_REGION_PROTECTED,
    CP_REGION_BEACON
};

struct cp_beacon_desc_alloc_t
{
    ca_schedule_t *ca_sched;
    uint next_alloc;
};

struct cp_beacon_payload_t
{
    /** Beacon payload. */
    u8 beacon_mpdu_payload [8];
    u8 nbe;
    /** First bentry. */
    u8 bmis[119];
    /** Frame control. */
    pbproc_rx_beacon_params_t fc;
};

struct cp_beacon_desc_t
{
    /** Not use. */
    u8 *next;
    /** Beacon payload. */
    cp_beacon_payload_t *payload;
    /** Beacon nid first four bytes. */
    uint nid_msb;
};

struct cp_pw_line_t
{
    /** Beacon period width. */
    uint bp_ntb;

    /** pw line time between two zero crosses. */
    uint pwzc_ntb;

    /** Array containing the previous value of the register */
    uint date_ntb[2];

    /** Detection done */
    u8 detection;
};

struct cp_beacon_common_t
{
    /** Estimated date. */
    uint btse_ntb[4];
    /** Data common to each beacon containing the BPSTO and the four BTOs. */
    pbproc_tx_beacon_params_t bto_bpsto; 
    /** Count the number of beacon saw or generated. */
    uint beacon_nb;
    /** beacon period estimated in Time Allocation Unit. */
    uint bp_tau[4];
    /** last beacon period computed. */
    uint per_ntb;
    /** Last central beacon received. */
    cp_beacon_desc_t *last_beacon;
    /** MFS use to send the beacons */
    mfs_tx_t *mfs;
    /** Last becon period start date. */
    ca_beacon_period_t last_bp;
};

struct cp_beacon_t
{
    /** station context plane context. */
    cp_sta_t *sta;

    /** The phy context */
    phy_t *phy;

    /** PW line properties. */
    cp_pw_line_t pwl;

    /** Security layer context. */
    cp_secu_t *secu;

    /** CCo context. */
    cp_cco_t *cco;

    /** CA layer context. */
    ca_t *ca;

    /** Mac store context. */
    mac_store_t *mac_store;

    /** Pbproc context. */
    pbproc_t *pbproc;

    /** Interface  the interface context. */
    interface_t *interface;

    /** Central beacon data. */
    cp_beacon_common_t cbeacon;

    /** Proxy beacon data. */
    //cp_proxy_beaocn_t pbeacon;
    
    /** Discover beacon data. */
    cp_beacon_common_t dbeacon;

    /** bentries data. */
    cp_bentries_data_t bentries_data;
    /** Hybrid mode. */
    u8 hm;
    /** Last sta requested to send a discover beacon. */
    u8 last_sta;
    /** Schedule index. */
    uint schedule_index;
    /** Pbproc Activated. */
    bool pbproc_activated;
    /** Awake value to program the timer in ticks. */
    uint awake_time;
    /** API timer context. */
    hal_timer_t *timer;
    /** API timer context. */
    hal_timer_instance_t instance;

    /** user data provide on the function callback for the CP. */
    void *cp_user_data;
    /** Function to call to add the event. */
    cp_beacon_timer_cb_t cp_cb;

    /** Trace system. */
#if CONFIG_TRACE
    /** cp_beacon Trace */
    trace_buffer_t trace;
#endif /* !CONFIG_TRACE */
};

#endif /* cp_beacon_inc_beacons_ctx_h */