1 | /** @file wlan_exp_node_sta.c |
---|
2 | * @brief Station WLAN Experiment |
---|
3 | * |
---|
4 | * This contains code for the 802.11 Station's WLAN experiment interface. |
---|
5 | * |
---|
6 | * @copyright Copyright 2014-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 | /***************************** Include Files *********************************/ |
---|
16 | #include "wlan_mac_high_sw_config.h" |
---|
17 | |
---|
18 | #if WLAN_SW_CONFIG_ENABLE_WLAN_EXP |
---|
19 | |
---|
20 | #include "wlan_exp_common.h" |
---|
21 | #include "wlan_exp_node.h" |
---|
22 | #include "wlan_exp_node_ibss.h" |
---|
23 | #include "wlan_platform_high.h" |
---|
24 | |
---|
25 | // Xilinx includes |
---|
26 | #include <xparameters.h> |
---|
27 | #include <xil_io.h> |
---|
28 | |
---|
29 | // Library includes |
---|
30 | #include "string.h" |
---|
31 | #include "stdlib.h" |
---|
32 | |
---|
33 | // WLAN includes |
---|
34 | #include "wlan_mac_event_log.h" |
---|
35 | #include "wlan_mac_network_info.h" |
---|
36 | #include "wlan_mac_ltg.h" |
---|
37 | #include "wlan_mac_ibss.h" |
---|
38 | #include "wlan_mac_station_info.h" |
---|
39 | #include "wlan_mac_high.h" |
---|
40 | #include "wlan_mac_queue.h" |
---|
41 | #include "wlan_mac_common.h" |
---|
42 | |
---|
43 | /*************************** Constant Definitions ****************************/ |
---|
44 | |
---|
45 | |
---|
46 | /*********************** Global Variable Definitions *************************/ |
---|
47 | extern tx_params_t default_unicast_data_tx_params; |
---|
48 | extern network_info_t* active_network_info; |
---|
49 | extern u32 max_queue_size; |
---|
50 | |
---|
51 | extern function_ptr_t wlan_exp_purge_all_wireless_tx_queue_callback; |
---|
52 | |
---|
53 | |
---|
54 | /*************************** Variable Definitions ****************************/ |
---|
55 | |
---|
56 | |
---|
57 | /*************************** Functions Prototypes ****************************/ |
---|
58 | |
---|
59 | |
---|
60 | /******************************** Functions **********************************/ |
---|
61 | |
---|
62 | |
---|
63 | /*****************************************************************************/ |
---|
64 | /** |
---|
65 | * Process Node Commands |
---|
66 | * |
---|
67 | * This function is part of the Ethernet processing system and will process the |
---|
68 | * various node related commands. |
---|
69 | * |
---|
70 | * @return int - Status of the command: |
---|
71 | * NO_RESP_SENT - No response has been sent |
---|
72 | * RESP_SENT - A response has been sent |
---|
73 | * |
---|
74 | * @note See on-line documentation for more information about the Ethernet |
---|
75 | * packet structure: www.warpproject.org |
---|
76 | * |
---|
77 | *****************************************************************************/ |
---|
78 | int process_wlan_exp_app_cmd(cmd_resp_hdr_t* cmd_hdr, eth_tx_queue_buffer_t* eth_tx_queue_buffer) { |
---|
79 | |
---|
80 | // |
---|
81 | // IMPORTANT ENDIAN NOTES: |
---|
82 | // - command |
---|
83 | // - header - Already endian swapped by the framework (safe to access directly) |
---|
84 | // - args - Must be endian swapped as necessary by code (framework does not know the contents of the command) |
---|
85 | // - response |
---|
86 | // - header - Will be endian swapped by the framework (safe to write directly) |
---|
87 | // - args - Must be endian swapped as necessary by code (framework does not know the contents of the response) |
---|
88 | // |
---|
89 | // Standard variables |
---|
90 | u32 resp_sent = NO_RESP_SENT; |
---|
91 | |
---|
92 | u32 cmd_id = CMD_TO_CMDID(cmd_hdr->cmd); |
---|
93 | |
---|
94 | // Segment 0 length includes a fully formed command response header |
---|
95 | // because one was created with default values suitable for a responseless |
---|
96 | // acknowledgment. |
---|
97 | cmd_resp_hdr_t* resp_hdr = (cmd_resp_hdr_t*)(eth_tx_queue_buffer->seg0 |
---|
98 | + eth_tx_queue_buffer->seg0_len |
---|
99 | - sizeof(cmd_resp_hdr_t)); |
---|
100 | |
---|
101 | u32* cmd_args_32 = (u32*)((u8*)cmd_hdr + sizeof(cmd_resp_hdr_t)); |
---|
102 | |
---|
103 | switch(cmd_id){ |
---|
104 | |
---|
105 | //----------------------------------------------------------------------------- |
---|
106 | // WLAN Exp Node Commands that must be implemented in child classes |
---|
107 | //----------------------------------------------------------------------------- |
---|
108 | |
---|
109 | //--------------------------------------------------------------------- |
---|
110 | case CMDID_NODE_RESET_STATE: { |
---|
111 | // NODE_RESET_STATE Packet Format: |
---|
112 | // - cmd_args_32[0] - Flags |
---|
113 | // [0] - NODE_RESET_LOG |
---|
114 | // [1] - NODE_RESET_TXRX_COUNTS |
---|
115 | // [2] - NODE_RESET_LTG |
---|
116 | // [3] - NODE_RESET_TX_DATA_QUEUE |
---|
117 | // [4] - NODE_RESET_ASSOCIATIONS |
---|
118 | // [5] - NODE_RESET_BSS_INFO |
---|
119 | // |
---|
120 | interrupt_state_t prev_interrupt_state; |
---|
121 | u32 status = CMD_PARAM_SUCCESS; |
---|
122 | u32 flags = Xil_Ntohl(cmd_args_32[0]); |
---|
123 | |
---|
124 | // Disable interrupts so no packets interrupt the reset |
---|
125 | prev_interrupt_state = wlan_platform_intc_stop(); |
---|
126 | #if WLAN_SW_CONFIG_ENABLE_LOGGING |
---|
127 | // Configure the LOG based on the flag bits |
---|
128 | if (flags & CMD_PARAM_NODE_RESET_FLAG_LOG) { |
---|
129 | wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_event_log, "Reset log\n"); |
---|
130 | event_log_reset(); |
---|
131 | } |
---|
132 | #endif //WLAN_SW_CONFIG_ENABLE_LOGGING |
---|
133 | if (flags & CMD_PARAM_NODE_RESET_FLAG_TXRX_COUNTS) { |
---|
134 | wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_counts, "Reseting Counts\n"); |
---|
135 | #if WLAN_SW_CONFIG_ENABLE_TXRX_COUNTS |
---|
136 | txrx_counts_zero_all(); |
---|
137 | #endif |
---|
138 | } |
---|
139 | |
---|
140 | #if WLAN_SW_CONFIG_ENABLE_LTG |
---|
141 | if (flags & CMD_PARAM_NODE_RESET_FLAG_LTG) { |
---|
142 | status = ltg_sched_remove(LTG_REMOVE_ALL); |
---|
143 | |
---|
144 | if (status != 0) { |
---|
145 | wlan_exp_printf(WLAN_EXP_PRINT_ERROR, print_type_ltg, "Failed to remove all LTGs\n"); |
---|
146 | status = CMD_PARAM_ERROR + CMD_PARAM_LTG_ERROR; |
---|
147 | } else { |
---|
148 | wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_ltg, "Removing All LTGs\n"); |
---|
149 | } |
---|
150 | } |
---|
151 | #endif //WLAN_SW_CONFIG_ENABLE_LTG |
---|
152 | |
---|
153 | if (flags & CMD_PARAM_NODE_RESET_FLAG_TX_DATA_QUEUE) { |
---|
154 | wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_queue, "Purging all data transmit queues\n"); |
---|
155 | wlan_exp_purge_all_wireless_tx_queue_callback(); |
---|
156 | } |
---|
157 | |
---|
158 | if (flags & CMD_PARAM_NODE_RESET_FLAG_BSS) { |
---|
159 | wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Resetting BSS\n"); |
---|
160 | |
---|
161 | // Set "active_bss_info" to NULL |
---|
162 | configure_bss(NULL, 0); |
---|
163 | } |
---|
164 | |
---|
165 | if (flags & CMD_PARAM_NODE_RESET_FLAG_NETWORK_LIST) { |
---|
166 | wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Resetting Network List\n"); |
---|
167 | wlan_mac_high_reset_network_list(); |
---|
168 | } |
---|
169 | |
---|
170 | // Call MAC specific reset with the flags |
---|
171 | |
---|
172 | // Re-enable interrupts |
---|
173 | wlan_platform_intc_set_state(prev_interrupt_state); |
---|
174 | |
---|
175 | // Send response of success |
---|
176 | wlan_exp_add_u32_resp_arg(eth_tx_queue_buffer, resp_hdr, status); |
---|
177 | } |
---|
178 | break; |
---|
179 | |
---|
180 | |
---|
181 | //----------------------------------------------------------------------------- |
---|
182 | // IBSS Specific Commands |
---|
183 | //----------------------------------------------------------------------------- |
---|
184 | |
---|
185 | |
---|
186 | //--------------------------------------------------------------------- |
---|
187 | default: { |
---|
188 | wlan_exp_printf(WLAN_EXP_PRINT_ERROR, print_type_node, "Unknown node command: 0x%x\n", cmd_id); |
---|
189 | } |
---|
190 | break; |
---|
191 | } |
---|
192 | |
---|
193 | return resp_sent; |
---|
194 | } |
---|
195 | |
---|
196 | /*****************************************************************************/ |
---|
197 | /** |
---|
198 | * Used by wlan_exp_cmd_add_association_callback in wlan_exp_node.c |
---|
199 | * |
---|
200 | * @param mac_addr - Pointer to MAC address association that will be added |
---|
201 | * |
---|
202 | * @return None |
---|
203 | * |
---|
204 | *****************************************************************************/ |
---|
205 | void wlan_exp_ibss_tx_cmd_add_association(u8* mac_addr) { |
---|
206 | station_info_t* station_info = NULL; |
---|
207 | if (active_network_info != NULL) { |
---|
208 | wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Adding association for: "); |
---|
209 | wlan_exp_print_mac_address(WLAN_EXP_PRINT_INFO, mac_addr); wlan_exp_printf(WLAN_EXP_PRINT_INFO, NULL, "\n"); |
---|
210 | |
---|
211 | // Add station info |
---|
212 | // - Set ht_capable argument to the HT_CAPABLE capability of the BSS. Given that the node does not know |
---|
213 | // the HT capabilities of the new station, it is reasonable to assume that they are the same as the BSS. |
---|
214 | // |
---|
215 | station_info = network_info_add_member(active_network_info, mac_addr, max_queue_size); |
---|
216 | |
---|
217 | if(station_info){ |
---|
218 | if(active_network_info->bss_config.ht_capable){ |
---|
219 | station_info->capabilities |= STATION_INFO_CAPABILITIES_HT_CAPABLE; |
---|
220 | } else { |
---|
221 | station_info->capabilities &= ~STATION_INFO_CAPABILITIES_HT_CAPABLE; |
---|
222 | } |
---|
223 | } |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | #endif |
---|