[6319] | 1 | /** @file wlan_mac_dcf.h |
---|
| 2 | * @brief Distributed Coordination Function |
---|
| 3 | * |
---|
| 4 | * This contains code to implement the 802.11 DCF. |
---|
| 5 | * |
---|
| 6 | * @copyright Copyright 2013-2019, Mango Communications. All rights reserved. |
---|
| 7 | * Distributed under the Mango Communications Reference Design License |
---|
| 8 | * See LICENSE.txt included in the design archive or |
---|
| 9 | * at http://mangocomm.com/802.11/license |
---|
| 10 | * |
---|
| 11 | * This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11) |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | /*************************** Constant Definitions ****************************/ |
---|
| 16 | #ifndef WLAN_MAC_DCF_H_ |
---|
| 17 | #define WLAN_MAC_DCF_H_ |
---|
| 18 | |
---|
| 19 | #include "xil_types.h" |
---|
| 20 | |
---|
| 21 | //Forward declarations |
---|
| 22 | struct phy_rx_details_t; |
---|
| 23 | enum phy_samp_rate_t; |
---|
| 24 | struct beacon_txrx_configure_t; |
---|
| 25 | |
---|
| 26 | #define PKT_BUF_INVALID 0xFF |
---|
| 27 | #define MAX_NUM_PENDING_TX_PKT_BUFS 5 |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | //----------------------------------------------- |
---|
| 31 | // MAC Timing Structure |
---|
| 32 | typedef struct mac_timing{ |
---|
| 33 | u16 t_slot; |
---|
| 34 | u16 t_sifs; |
---|
| 35 | u16 t_difs; |
---|
| 36 | u16 t_eifs; |
---|
| 37 | u16 t_phy_rx_start_dly; |
---|
| 38 | u16 t_timeout; |
---|
| 39 | } mac_timing; |
---|
| 40 | |
---|
| 41 | //----------------------------------------------- |
---|
| 42 | // CW Update Reasons |
---|
| 43 | #define DCF_CW_UPDATE_MPDU_TX_ERR 0 |
---|
| 44 | #define DCF_CW_UPDATE_MPDU_RX_ACK 1 |
---|
| 45 | #define DCF_CW_UPDATE_BCAST_TX 2 |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | //----------------------------------------------- |
---|
| 49 | // Reason codes for generating a random number of slots |
---|
| 50 | // See: rand_num_slots() |
---|
| 51 | // |
---|
| 52 | #define RAND_SLOT_REASON_STANDARD_ACCESS 0 |
---|
| 53 | #define RAND_SLOT_REASON_IBSS_BEACON 1 |
---|
| 54 | |
---|
| 55 | //----------------------------------------------- |
---|
| 56 | // According to 10.21.1 of 802.11-2012, the timestamp value of |
---|
| 57 | // transmitted beacons and probe responses shall be set to the |
---|
| 58 | // time of the data symbol containing the first bit of the timestamp |
---|
| 59 | // This is a rate-specific value. For this release, we will hardcode |
---|
| 60 | // the value for the default MCS 0, NONHT (aka 6 Mbps) rate. This |
---|
| 61 | // needs to be changed for beacons & probe responses sent at a different |
---|
| 62 | // rate |
---|
| 63 | #define T_TIMESTAMP_FIELD_OFFSET 52 |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | //----------------------------------------------- |
---|
| 67 | // WLAN Exp low parameter defines (DCF) |
---|
| 68 | // NOTE: Need to make sure that these values do not conflict with any of the LOW PARAM |
---|
| 69 | // callback defines |
---|
| 70 | // |
---|
| 71 | #define LOW_PARAM_DCF_RTS_THRESH 0x10000001 |
---|
| 72 | #define LOW_PARAM_DCF_DOT11SHORTRETRY 0x10000002 |
---|
| 73 | #define LOW_PARAM_DCF_DOT11LONGRETRY 0x10000003 |
---|
| 74 | #define LOW_PARAM_DCF_CW_EXP_MIN 0x10000005 |
---|
| 75 | #define LOW_PARAM_DCF_CW_EXP_MAX 0x10000006 |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | /*********************** Global Structure Definitions ************************/ |
---|
| 80 | |
---|
| 81 | typedef enum rx_finish_state_t{ |
---|
| 82 | RX_FINISH_SEND_NONE, |
---|
| 83 | RX_FINISH_SEND_A, |
---|
| 84 | RX_FINISH_SEND_B |
---|
| 85 | } rx_finish_state_t; |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | typedef enum tx_pending_state_t{ |
---|
| 89 | TX_PENDING_NONE, |
---|
| 90 | TX_PENDING_A, |
---|
| 91 | TX_PENDING_B |
---|
| 92 | } tx_pending_state_t; |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | typedef enum tx_wait_state_t{ |
---|
| 96 | TX_WAIT_NONE, |
---|
| 97 | TX_WAIT_ACK, |
---|
| 98 | TX_WAIT_CTS |
---|
| 99 | } tx_wait_state_t; |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | typedef enum tx_mode_t{ |
---|
| 103 | TX_MODE_SHORT, |
---|
| 104 | TX_MODE_LONG |
---|
| 105 | } tx_mode_t; |
---|
| 106 | |
---|
| 107 | /*************************** Function Prototypes *****************************/ |
---|
| 108 | int main(); |
---|
| 109 | |
---|
| 110 | u32 frame_receive(u8 rx_pkt_buf, struct phy_rx_details_t* phy_details); |
---|
| 111 | void handle_mcast_buffer_enable(u32 enable); |
---|
| 112 | void update_tx_pkt_buf_lists(); |
---|
| 113 | void handle_sample_rate_change(enum phy_samp_rate_t phy_samp_rate); |
---|
| 114 | void update_dtim_count(); |
---|
| 115 | void update_tu_target(u8 recompute); |
---|
| 116 | void handle_mactime_change(s64 time_delta_usec); |
---|
| 117 | void configure_beacon_txrx(struct beacon_txrx_configure_t* beacon_txrx_configure); |
---|
| 118 | void frame_transmit_general(u8 pkt_buf); |
---|
| 119 | |
---|
| 120 | #define DTIM_MCAST_RETURN_PAUSED 0x00000001 |
---|
| 121 | u32 frame_transmit_dtim_mcast(u8 pkt_buf, u8 resume); |
---|
| 122 | int handle_tx_pkt_buf_ready(u8 pkt_buf); |
---|
| 123 | |
---|
| 124 | #define POLL_TX_PKT_BUF_LIST_RETURN_ERROR 0x80000000 |
---|
| 125 | #define POLL_TX_PKT_BUF_LIST_RETURN_TRANSMITTED 0x00000001 |
---|
| 126 | #define POLL_TX_PKT_BUF_LIST_RETURN_PAUSED 0x00000002 |
---|
| 127 | #define POLL_TX_PKT_BUF_LIST_RETURN_MORE_DATA 0x00000004 |
---|
| 128 | u32 poll_tx_pkt_buf_list(pkt_buf_group_t pkt_buf_group); |
---|
| 129 | |
---|
| 130 | void increment_src(u16* src_ptr); |
---|
| 131 | void increment_lrc(u16* lrc_ptr); |
---|
| 132 | |
---|
| 133 | void poll_tbtt_and_send_beacon(); |
---|
| 134 | |
---|
| 135 | #define SEND_BEACON_RETURN_DTIM 0x00000001 |
---|
| 136 | #define SEND_BEACON_RETURN_CANCELLED 0x00000002 |
---|
| 137 | u32 send_beacon(u8 tx_pkt_buf); |
---|
| 138 | |
---|
| 139 | void reset_cw(); |
---|
| 140 | void reset_ssrc(); |
---|
| 141 | void reset_slrc(); |
---|
| 142 | |
---|
| 143 | u32 rand_num_slots(u8 reason); |
---|
| 144 | |
---|
| 145 | void wlan_mac_dcf_hw_start_backoff(u16 num_slots); |
---|
| 146 | |
---|
| 147 | #endif /* WLAN_MAC_DCF_H_ */ |
---|