source: ReferenceDesigns/w3_802.11/c/wlan_mac_high_sta/wlan_exp_node_sta.c

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

1.8.0 release wlan-mac-se

File size: 14.0 KB
Line 
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 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/***************************** Include Files *********************************/
16#include "wlan_mac_high_sw_config.h"
17
18#if WLAN_SW_CONFIG_ENABLE_WLAN_EXP
19
20#include "wlan_platform_common.h"
21#include "wlan_platform_high.h"
22#include "wlan_exp_common.h"
23#include "wlan_exp_node.h"
24#include "wlan_exp_node_sta.h"
25
26// Xilinx includes
27#include <xparameters.h>
28#include <xil_io.h>
29
30
31// Library includes
32#include "string.h"
33#include "stdlib.h"
34
35// WLAN includes
36#include "wlan_mac_802_11_defs.h"
37#include "wlan_mac_queue.h"
38#include "wlan_mac_event_log.h"
39#include "wlan_mac_ltg.h"
40#include "wlan_mac_packet_types.h"
41#include "wlan_mac_eth_util.h"
42#include "wlan_mac_network_info.h"
43#include "wlan_mac_sta_join.h"
44#include "wlan_mac_entries.h"
45#include "wlan_mac_sta.h"
46#include "wlan_mac_high.h"
47#include "wlan_mac_station_info.h"
48#include "wlan_mac_scan.h"
49
50
51/*************************** Constant Definitions ****************************/
52
53
54/*********************** Global Variable Definitions *************************/
55extern dl_list association_table;
56
57extern u8 my_aid;
58
59extern function_ptr_t wlan_exp_purge_all_wireless_tx_queue_callback;
60
61
62/*************************** Variable Definitions ****************************/
63
64
65/*************************** Functions Prototypes ****************************/
66
67
68/******************************** Functions **********************************/
69
70
71/*****************************************************************************/
72/**
73 * Process Node Commands
74 *
75 * This function is part of the Ethernet processing system and will process the
76 * various node related commands.
77 *
78 * @return  int              - Status of the command:
79 *                                 NO_RESP_SENT - No response has been sent
80 *                                 RESP_SENT    - A response has been sent
81 *
82 * @note    See on-line documentation for more information about the Ethernet
83 *          packet structure:  www.warpproject.org
84 *
85 *****************************************************************************/
86int process_wlan_exp_app_cmd(cmd_resp_hdr_t* cmd_hdr, eth_tx_queue_buffer_t* eth_tx_queue_buffer) {
87
88    //
89    // IMPORTANT ENDIAN NOTES:
90    //     - command
91    //         - header - Already endian swapped by the framework (safe to access directly)
92    //         - args   - Must be endian swapped as necessary by code (framework does not know the contents of the command)
93    //     - response
94    //         - header - Will be endian swapped by the framework (safe to write directly)
95    //         - args   - Must be endian swapped as necessary by code (framework does not know the contents of the response)
96    //
97
98    // Standard variables
99    u32 resp_sent = NO_RESP_SENT;
100
101    u32 cmd_id = CMD_TO_CMDID(cmd_hdr->cmd);
102
103    // Segment 0 length includes a fully formed command response header
104    //  because one was created with default values suitable for a responseless
105    //  acknowledgment.
106    cmd_resp_hdr_t* resp_hdr = (cmd_resp_hdr_t*)(eth_tx_queue_buffer->seg0
107                                                 + eth_tx_queue_buffer->seg0_len
108                                                 - sizeof(cmd_resp_hdr_t));
109
110    u32* cmd_args_32 = (u32*)((u8*)cmd_hdr + sizeof(cmd_resp_hdr_t));
111
112    //
113    // NOTE: Response header cmd, length, and num_args fields have already been initialized.
114    //
115
116    switch(cmd_id){
117
118
119//-----------------------------------------------------------------------------
120// WLAN Exp Node Commands that must be implemented in child classes
121//-----------------------------------------------------------------------------
122
123        //---------------------------------------------------------------------
124        case CMDID_NODE_RESET_STATE: {
125            // NODE_RESET_STATE Packet Format:
126            //   - cmd_args_32[0]  - Flags
127            //                     [0] - NODE_RESET_LOG
128            //                     [1] - NODE_RESET_TXRX_COUNTS
129            //                     [2] - NODE_RESET_LTG
130            //                     [3] - NODE_RESET_TX_DATA_QUEUE
131            //                     [4] - NODE_RESET_ASSOCIATIONS
132            //                     [5] - NODE_RESET_BSS_INFO
133            //
134            interrupt_state_t prev_interrupt_state;
135            u32 status = CMD_PARAM_SUCCESS;
136            u32 flags = Xil_Ntohl(cmd_args_32[0]);
137
138            // Disable interrupts so no packets interrupt the reset
139            prev_interrupt_state = wlan_platform_intc_stop();
140
141#if WLAN_SW_CONFIG_ENABLE_LOGGING
142            // Configure the LOG based on the flag bits
143            if (flags & CMD_PARAM_NODE_RESET_FLAG_LOG) {
144                wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_event_log, "Reset log\n");
145                event_log_reset();
146            }
147#endif //WLAN_SW_CONFIG_ENABLE_LOGGING
148
149            if (flags & CMD_PARAM_NODE_RESET_FLAG_TXRX_COUNTS) {
150                wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_counts, "Reseting Counts\n");
151#if WLAN_SW_CONFIG_ENABLE_TXRX_COUNTS
152                txrx_counts_zero_all();
153#endif
154            }
155
156#if WLAN_SW_CONFIG_ENABLE_LTG
157            if (flags & CMD_PARAM_NODE_RESET_FLAG_LTG) {
158                status = ltg_sched_remove(LTG_REMOVE_ALL);
159
160                if (status != 0) {
161                    wlan_exp_printf(WLAN_EXP_PRINT_ERROR, print_type_ltg, "Failed to remove all LTGs\n");
162                    status = CMD_PARAM_ERROR + CMD_PARAM_LTG_ERROR;
163                } else {
164                    wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_ltg, "Removing All LTGs\n");
165                }
166            }
167#endif //WLAN_SW_CONFIG_ENABLE_LTG
168
169            if (flags & CMD_PARAM_NODE_RESET_FLAG_TX_DATA_QUEUE) {
170                wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_queue, "Purging all data transmit queues\n");
171                wlan_exp_purge_all_wireless_tx_queue_callback();
172            }
173
174            if (flags & CMD_PARAM_NODE_RESET_FLAG_BSS) {
175                wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Resetting BSS\n");
176
177                // Note: Interrupts are currently disabled
178
179                // Stop any scan / join in progress
180                wlan_mac_sta_join_return_to_idle();
181
182                // STA disassociate command is the same for an individual AP or ALL
183                sta_disassociate();
184
185                // Set "my_bss_info" to NULL
186                configure_bss(NULL, 0);
187            }
188
189            if (flags & CMD_PARAM_NODE_RESET_FLAG_NETWORK_LIST) {
190                wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Resetting Network List\n");
191                wlan_mac_high_reset_network_list();
192            }
193
194            // Call MAC specific reset with the flags
195
196            // Re-enable interrupts
197            wlan_platform_intc_set_state(prev_interrupt_state);
198
199            // Send response of success
200            wlan_exp_add_u32_resp_arg(eth_tx_queue_buffer, resp_hdr, status);
201        }
202        break;
203
204
205        //---------------------------------------------------------------------
206        case CMDID_NODE_DISASSOCIATE: {
207            // Disassociate from the AP
208            //
209            // The MAC address argument is ignored and the STA will always disassociate
210            // from the AP when this command is used.
211            //
212            // Message format:
213            //     cmd_args_32[0:1]      MAC Address (All 0xFF means all station info)
214            //
215            // Response format:
216            //     resp_args_32[0]       Status
217            //
218            interrupt_state_t prev_interrupt_state;
219            u32 status = CMD_PARAM_SUCCESS;
220
221            wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Disassociate\n");
222
223            // Stop the join state machine if it is running
224            if (wlan_mac_sta_is_joining()) { wlan_mac_sta_join_return_to_idle(); }
225
226            // Stop the scan state machine if it is running
227            if (wlan_mac_scan_is_scanning()) { wlan_mac_scan_stop(); }
228
229            // Disable interrupts so no packets interrupt the disassociate
230            prev_interrupt_state = wlan_platform_intc_stop();
231
232            // Disassociate STA
233            status = sta_disassociate();
234
235            // Re-enable interrupts
236            wlan_platform_intc_set_state(prev_interrupt_state);
237
238            // Set return parameters and print info to console
239            if (status == 0) {
240                wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Disassociated from AP\n");
241                status = CMD_PARAM_SUCCESS;
242            } else {
243                wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Could not disassociate from AP\n");
244                status = CMD_PARAM_ERROR;
245            }
246
247
248            // Send response
249            wlan_exp_add_u32_resp_arg(eth_tx_queue_buffer, resp_hdr, status);
250        }
251        break;
252
253
254//-----------------------------------------------------------------------------
255// STA Specific Commands
256//-----------------------------------------------------------------------------
257
258        //---------------------------------------------------------------------
259        case CMDID_NODE_STA_SET_AID: {
260            // Set the AID
261            //
262            // Message format:
263            //     cmd_args_32[0]   AID
264            //
265            // Response format:
266            //     resp_args_32[0]  Status
267            //
268            u32 status = CMD_PARAM_SUCCESS;
269            u8 aid = (Xil_Ntohl(cmd_args_32[0]) & 0xFF);
270
271            // Set STA global AID field
272            my_aid = aid;
273
274            // Update the hex display with the new AID
275            wlan_platform_high_userio_disp_status(USERIO_DISP_STATUS_MEMBER_LIST_UPDATE, my_aid);
276
277            // Send response of status
278            wlan_exp_add_u32_resp_arg(eth_tx_queue_buffer, resp_hdr, status);
279        }
280        break;
281
282
283        //---------------------------------------------------------------------
284        case CMDID_NODE_STA_JOIN: {
285            // Join the given BSS
286            //
287            // Message format:
288            //     cmd_args_32[0:1] BSS ID (or CMD_PARAM_RSVD_MAC_ADDR if BSSID not set)
289            //     cmd_args_32[2]   Channel
290            //     cmd_args_32[3]   SSID Length
291            //     cmd_args_32[4:N] SSID (packed array of ascii character values)
292            //                          NOTE: The characters are copied using str functions
293            //                              and must be correctly processed on the host side
294            //
295            // Response format:
296            //     resp_args_32[0]  Status
297            //
298            u32 status = CMD_PARAM_SUCCESS;
299            u8 bssid[MAC_ADDR_LEN];
300            u8 channel = (Xil_Ntohl(cmd_args_32[2]) & 0xFF);
301            u32 ssid_length = Xil_Ntohl(cmd_args_32[3]);
302            char* ssid = (char *)&cmd_args_32[4];
303            volatile join_parameters_t* join_parameters;
304
305            wlan_exp_printf(WLAN_EXP_PRINT_INFO, print_type_node, "Joining the BSS\n");
306
307            // Get the BSSID
308            wlan_exp_get_mac_addr(&((u32 *)cmd_args_32)[0], &bssid[0]);
309
310            // Get the current join parameters
311            join_parameters = wlan_mac_sta_get_join_parameters();
312
313            // Free the current join SSID, it will be replaced
314            if (join_parameters->ssid != NULL) {
315                wlan_mac_high_free(join_parameters->ssid);
316            }
317
318            // SSID was "None", therefore we need to stop the join process
319            if (ssid_length == CMD_PARAM_RSVD) {
320                // Set the SSID to NULL
321                join_parameters->ssid = NULL;
322            } else {
323                // Set the SSID
324                join_parameters->ssid = strndup(ssid, SSID_LEN_MAX);
325
326                // Set the BSSID (reserved value is all zeros)
327                //     - Do not need to check if the value is all zero since that will be done
328                //       in the join function itself
329                memcpy((void *)join_parameters->bssid, bssid, MAC_ADDR_LEN);
330
331                // Set the channel (reserved value is zero)
332                //     - Do not need to check if the value is all zero since that will be done
333                //       in the join function itself
334                join_parameters->channel = channel;
335            }
336
337            // Call join function
338            wlan_mac_sta_join();
339
340            // Send response of status
341            wlan_exp_add_u32_resp_arg(eth_tx_queue_buffer, resp_hdr, status);
342        }
343        break;
344
345
346        //---------------------------------------------------------------------
347        case CMDID_NODE_STA_JOIN_STATUS: {
348            // Get the current wlan_mac_is_joining() status
349            //
350            // Message format:
351            //
352            // Response format:
353            //     resp_args_32[0]  Status
354            //     resp_args_32[1]  Is Joining?  (0 - No / 1 - Yes)
355            //                      Failure (CMD_PARAM_NODE_JOIN_FAILED)
356            //
357            u32 status = CMD_PARAM_SUCCESS;
358            u32 is_joining = wlan_mac_sta_is_joining();
359
360            // Send response of status
361            wlan_exp_add_u32_resp_arg(eth_tx_queue_buffer, resp_hdr, status);
362            wlan_exp_add_u32_resp_arg(eth_tx_queue_buffer, resp_hdr, is_joining);
363        }
364        break;
365
366
367        //---------------------------------------------------------------------
368        default: {
369            wlan_exp_printf(WLAN_EXP_PRINT_ERROR, print_type_node, "Unknown node command: 0x%x\n", cmd_id);
370        }
371        break;
372    }
373
374    return resp_sent;
375}
376
377
378
379#endif
Note: See TracBrowser for help on using the repository browser.