source: ReferenceDesigns/w3_802.11/c/wlan_mac_common_framework/include/wlan_mac_common.h

Last change on this file was 6319, checked in by chunter, 5 years ago

1.8.0 release wlan-mac-se

File size: 9.0 KB
Line 
1/** @file wlan_mac_common.h
2 *  @brief Common Definitions
3 *
4 *  This contains common definitions of required by both the upper and
5 *  lower-level CPUs.
6 *
7 *  @copyright Copyright 2013-2019, Mango Communications. All rights reserved.
8 *          Distributed under the Mango Communications Reference Design License
9 *              See LICENSE.txt included in the design archive or
10 *              at http://mangocomm.com/802.11/license
11 *
12 *  This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11)
13 */
14
15/*************************** Constant Definitions ****************************/
16#ifndef WLAN_MAC_COMMON_H_
17#define WLAN_MAC_COMMON_H_
18
19#include "xil_types.h"
20#include "wlan_common_types.h"
21#include "string.h"
22
23// Forward declarations
24struct wlan_mac_hw_info_t;
25struct station_info_t;
26
27//-----------------------------------------------
28// Common function defines
29//
30#define WLAN_MAX(a, b)                                       (((a) > (b)) ? (a) : (b))
31#define WLAN_MIN(a, b)                                       (((a) < (b)) ? (a) : (b))
32
33#define CALC_MEM_HIGH_ADDR(base, size) ((base) + ((size) - 1))
34#define CALC_MEM_BASE_ADDR(high, size) ((high) - (size) + 1)
35#define CALC_MEM_SIZE(base, high) ((high) - (base) + 1)
36
37#define abs_64(a)                                       (((a) < 0) ? (-1 * a) : (a))
38
39#define sat_add16(a, b)                                 (((a) > (0xFFFF - (b))) ? 0xFFFF : ((a) + (b)))
40#define sat_add32(a, b)                                 (((a) > (0xFFFFFFFF - (b))) ? 0xFFFFFFFF : ((a) + (b)))
41
42#define sat_sub(a, b)                                   (((a) > (b)) ? ((a) - (b)) : 0)
43
44#define wlan_addr_eq(addr1, addr2)                        (memcmp((void*)(addr1), (void*)(addr2), 6)==0)
45#define wlan_addr_mcast(addr)                          ((((u8*)(addr))[0] & 1) == 1)
46
47//-----------------------------------------------
48// Level Print function defines
49//
50#define PRINT_LEVEL                                        PL_ERROR
51
52#define PL_NONE                                            0
53#define PL_ERROR                                           1
54#define PL_WARNING                                         2
55#define PL_VERBOSE                                         3
56
57#define wlan_printf(severity, format, args...) \
58    do { \
59        if (PRINT_LEVEL >= severity){ xil_printf(format, ##args); } \
60    } while(0)
61
62
63//-----------------------------------------------
64// PHY defines
65//
66#define WLAN_PHY_FCS_NBYTES                                4U
67
68#define PHY_MODE_DSSS                                      0x0
69#define PHY_MODE_NONHT                                     0x1       // 11a OFDM
70#define PHY_MODE_HTMF                                      0x2       // 11n OFDM, HT mixed format
71
72//-----------------------------------------------
73// Unique sequence number defines
74//
75#define UNIQUE_SEQ_INVALID                                 0xFFFFFFFFFFFFFFFFULL
76
77
78//-----------------------------------------------
79// WLAN defines
80//
81
82// Reference: http://standards.ieee.org/develop/regauth/tut/macgrp.pdf
83#define MAC_ADDR_MSB_MASK_MCAST                            0x01
84#define MAC_ADDR_MSB_MASK_LOCAL                            0x02
85
86
87//-----------------------------------------------
88// CPU Status defines
89//
90#define CPU_STATUS_INITIALIZED                             0x00000001
91#define CPU_STATUS_EXCEPTION                               0x80000000
92
93
94//-----------------------------------------------
95// Antenna mode defines
96//     NOTE:  These values are enumerated and are *not* written to PHY registers
97//
98#define RX_ANTMODE_SISO_ANTA                               0x0
99#define RX_ANTMODE_SISO_ANTB                               0x1
100#define RX_ANTMODE_SISO_ANTC                               0x2
101#define RX_ANTMODE_SISO_ANTD                               0x3
102#define RX_ANTMODE_SISO_SELDIV_2ANT                        0x4
103#define RX_ANTMODE_SISO_SELDIV_4ANT                        0x5
104
105#define TX_ANTMODE_SISO_ANTA                               0x10
106#define TX_ANTMODE_SISO_ANTB                               0x20
107#define TX_ANTMODE_SISO_ANTC                               0x30
108#define TX_ANTMODE_SISO_ANTD                               0x40
109
110
111//-----------------------------------------------
112// Receive filter defines
113//     NOTE:  These filters allow the user to select the types of received packets to process
114//
115#define RX_FILTER_FCS_GOOD                                 0x1000    ///< Pass only packets with good checksum result
116#define RX_FILTER_FCS_ALL                                  0x2000    ///< Pass packets with any checksum result
117#define RX_FILTER_FCS_MASK                                 0xF000
118#define RX_FILTER_FCS_NOCHANGE                             RX_FILTER_FCS_MASK
119
120#define RX_FILTER_HDR_ADDR_MATCH_MPDU                      0x0001    ///< Pass any unicast-to-me or multicast data or management packet
121#define RX_FILTER_HDR_ALL_MPDU                             0x0002    ///< Pass any data or management packet (no address filter)
122#define RX_FILTER_HDR_ALL                                  0x0003    ///< Pass any packet (no type or address filters)
123#define RX_FILTER_HDR_MASK                                 0x0FFF
124#define RX_FILTER_HDR_NOCHANGE                             RX_FILTER_HDR_MASK
125
126
127//-----------------------------------------------
128// Error defines
129//     Currently, the framework supports error values of 0 - 0xF.  These will
130//     be displayed on the hex display as Ex, where x is the error value.
131//
132#define WLAN_ERROR_CODE_RIGHT_SHIFT                        0
133#define WLAN_ERROR_CODE_INSUFFICIENT_BD_SIZE               1
134#define WLAN_ERROR_CODE_DRAM_NOT_PRESENT                   2
135#define WLAN_ERROR_CODE_CPU_LOW_TX_MUTEX                   3
136#define WLAN_ERROR_CODE_CPU_LOW_RX_MUTEX                   4
137
138
139#define WLAN_ERROR_CPU_STOP                                0x80000000
140
141
142
143//-----------------------------------------------
144// Debug / Monitor defines
145//
146#define ISR_PERF_MON_GPIO_MASK                             0x01
147// #define _ISR_PERF_MON_EN_                                         ///< ISR Performance Monitor Toggle
148
149
150/*********************** Global Structure Definitions ************************/
151
152// Forward declarations
153struct wlan_mac_hw_info_t;
154
155typedef enum userio_input_mask_t{
156    USERIO_INPUT_MASK_PB_0      = 0x00000001,
157    USERIO_INPUT_MASK_PB_1      = 0x00000002,
158    USERIO_INPUT_MASK_PB_2      = 0x00000004,
159    USERIO_INPUT_MASK_PB_3      = 0x00000008,
160    USERIO_INPUT_MASK_SW_0      = 0x00000010,
161    USERIO_INPUT_MASK_SW_1      = 0x00000020,
162    USERIO_INPUT_MASK_SW_2      = 0x00000040,
163    USERIO_INPUT_MASK_SW_3      = 0x00000080,
164} userio_input_mask_t;
165
166//-----------------------------------------------
167// Beacon Tx/Rx Configuration Struct
168//
169typedef enum __attribute__((__packed__)){
170    NEVER_UPDATE,
171    ALWAYS_UPDATE,
172    FUTURE_ONLY_UPDATE,
173} mactime_update_mode_t;
174ASSERT_TYPE_SIZE(mactime_update_mode_t, 1);
175
176
177typedef enum __attribute__((__packed__)){
178    NO_BEACON_TX,
179    AP_BEACON_TX,
180    IBSS_BEACON_TX,
181} beacon_tx_mode_t;
182ASSERT_TYPE_SIZE(beacon_tx_mode_t, 1);
183
184
185typedef struct __attribute__((__packed__)) beacon_txrx_configure_t{
186    // Beacon Rx Configuration Parameters
187    mactime_update_mode_t    ts_update_mode;               // Determines how MAC time is updated on reception of beacons
188    u8                       bssid_match[MAC_ADDR_LEN];    // BSSID of current association for Rx matching
189
190    // Beacon Tx Configuration Parameters
191    u8                       beacon_template_pkt_buf;      // Packet Buffer that contains the the beacon template to transmit
192    u32                      beacon_interval_tu;           // Beacon Interval (in TU)
193    beacon_tx_mode_t         beacon_tx_mode;               // Tx Beacon Mode
194    u8                       dtim_period;                  // DTIM Period (in beacon intervals)
195    u8                       reserved0;
196    u8                       reserved1;
197    u16                      dtim_tag_byte_offset;         // # of bytes into the payload that contains the start of the DTIM tag
198    u16                      reserved2;
199} beacon_txrx_config_t;
200ASSERT_TYPE_SIZE(beacon_txrx_config_t, 20);
201
202
203typedef struct time_hr_min_sec_t{
204    u32 hr;
205    u32 min;
206    u32 sec;
207} time_hr_min_sec_t;
208
209/*************************** Function Prototypes *****************************/
210
211void                    wlan_mac_common_malloc_init();
212int                     wlan_null_callback(void* param);
213int                     wlan_verify_channel(u32 channel);
214void                    init_mac_hw_info();
215time_hr_min_sec_t       wlan_mac_time_to_hr_min_sec(u64 time);
216
217int wlan_create_rts_frame(u8* pkt,
218                          u8* address_ra,
219                          u8* address_ta,
220                          u16 duration);
221
222int wlan_create_cts_frame(u8* pkt,
223                          u8* address_ra,
224                          u16 duration);
225
226int wlan_create_ack_frame(void* pkt,
227                          u8* address_ra);
228
229struct wlan_mac_hw_info_t* get_mac_hw_info();
230u8* get_mac_hw_addr_wlan();
231u8* get_mac_hw_addr_wlan_exp();
232void wlan_assert_print(const char *FilenamePtr, int LineNumber);
233
234#endif   // END WLAN_MAC_COMMON_H_
Note: See TracBrowser for help on using the repository browser.