1 | /** @file wlan_mac_sta_uart_menu.c |
---|
2 | * @brief Station UART Menu |
---|
3 | * |
---|
4 | * This contains code for the 802.11 Station's UART menu. |
---|
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 | /***************************** Include Files *********************************/ |
---|
15 | #include "wlan_mac_high_sw_config.h" |
---|
16 | |
---|
17 | // Xilinx SDK includes |
---|
18 | #include "xparameters.h" |
---|
19 | #include "stdio.h" |
---|
20 | #include "stdlib.h" |
---|
21 | #include "string.h" |
---|
22 | |
---|
23 | // WLAN includes |
---|
24 | #include "wlan_mac_802_11_defs.h" |
---|
25 | #include "wlan_mac_queue.h" |
---|
26 | #include "wlan_mac_high.h" |
---|
27 | #include "wlan_mac_packet_types.h" |
---|
28 | #include "wlan_mac_eth_util.h" |
---|
29 | #include "wlan_mac_sta.h" |
---|
30 | #include "wlan_mac_sta_join.h" |
---|
31 | #include "ascii_characters.h" |
---|
32 | #include "wlan_mac_schedule.h" |
---|
33 | #include "wlan_mac_event_log.h" |
---|
34 | #include "wlan_mac_network_info.h" |
---|
35 | #include "wlan_mac_scan.h" |
---|
36 | #include "wlan_mac_station_info.h" |
---|
37 | #include "wlan_platform_common.h" |
---|
38 | |
---|
39 | |
---|
40 | // |
---|
41 | // Use the UART Menu |
---|
42 | // - If WLAN_USE_UART_MENU in wlan_mac_sta.h is commented out, then this function |
---|
43 | // will do nothing. This might be necessary to save code space. |
---|
44 | // |
---|
45 | |
---|
46 | |
---|
47 | #ifndef WLAN_USE_UART_MENU |
---|
48 | |
---|
49 | void uart_rx(u8 rxByte){ }; |
---|
50 | |
---|
51 | #else |
---|
52 | |
---|
53 | /*************************** Constant Definitions ****************************/ |
---|
54 | |
---|
55 | //----------------------------------------------- |
---|
56 | // UART Menu Modes |
---|
57 | #define UART_MODE_MAIN 0 |
---|
58 | #define UART_MODE_INTERACTIVE 1 |
---|
59 | #define UART_MODE_JOIN 2 |
---|
60 | |
---|
61 | |
---|
62 | /*********************** Global Variable Definitions *************************/ |
---|
63 | extern network_info_t* active_network_info; |
---|
64 | |
---|
65 | /*************************** Variable Definitions ****************************/ |
---|
66 | |
---|
67 | static volatile u8 uart_mode = UART_MODE_MAIN; |
---|
68 | static volatile u32 schedule_id; |
---|
69 | static volatile u32 check_join_status_id; |
---|
70 | static volatile u8 print_scheduled = 0; |
---|
71 | |
---|
72 | static char text_entry[SSID_LEN_MAX + 1]; |
---|
73 | static u8 curr_char = 0; |
---|
74 | |
---|
75 | /*************************** Functions Prototypes ****************************/ |
---|
76 | |
---|
77 | void print_main_menu(); |
---|
78 | |
---|
79 | void print_station_status(); |
---|
80 | |
---|
81 | void check_join_status(); |
---|
82 | |
---|
83 | void start_periodic_print(); |
---|
84 | void stop_periodic_print(); |
---|
85 | |
---|
86 | |
---|
87 | /*************************** Variable Definitions ****************************/ |
---|
88 | |
---|
89 | |
---|
90 | /******************************** Functions **********************************/ |
---|
91 | |
---|
92 | |
---|
93 | /*****************************************************************************/ |
---|
94 | /** |
---|
95 | * Process each character received by the UART |
---|
96 | * |
---|
97 | * The following functionality is supported: |
---|
98 | * - Main Menu |
---|
99 | * - Interactive Menu (prints all station infos) |
---|
100 | * - Print all counts |
---|
101 | * - Print event log size (hidden) |
---|
102 | * - Print Network List |
---|
103 | * - Print Malloc info (hidden) |
---|
104 | * - Join BSS |
---|
105 | * - Reset network list (hidden) |
---|
106 | * - Interactive Menu |
---|
107 | * - Reset counts |
---|
108 | * - Turn on/off "Traffic Blaster" (hidden) |
---|
109 | * |
---|
110 | * The escape key is used to return to the Main Menu. |
---|
111 | * |
---|
112 | *****************************************************************************/ |
---|
113 | void uart_rx(u8 rxByte){ |
---|
114 | volatile join_parameters_t* join_parameters; |
---|
115 | volatile scan_parameters_t* scan_params; |
---|
116 | u32 is_scanning; |
---|
117 | |
---|
118 | // ---------------------------------------------------- |
---|
119 | // Return to the Main Menu |
---|
120 | // - Stops any prints / LTGs |
---|
121 | if (rxByte == ASCII_ESC) { |
---|
122 | uart_mode = UART_MODE_MAIN; |
---|
123 | stop_periodic_print(); |
---|
124 | print_main_menu(); |
---|
125 | |
---|
126 | // Stop join process |
---|
127 | if (wlan_mac_sta_is_joining()) { |
---|
128 | wlan_mac_sta_join_return_to_idle(); |
---|
129 | } |
---|
130 | return; |
---|
131 | } |
---|
132 | |
---|
133 | switch(uart_mode){ |
---|
134 | |
---|
135 | // ------------------------------------------------ |
---|
136 | // Main Menu processing |
---|
137 | // |
---|
138 | case UART_MODE_MAIN: |
---|
139 | switch(rxByte){ |
---|
140 | |
---|
141 | // ---------------------------------------- |
---|
142 | // '1' - Switch to Interactive Menu |
---|
143 | // |
---|
144 | case ASCII_1: |
---|
145 | uart_mode = UART_MODE_INTERACTIVE; |
---|
146 | start_periodic_print(); |
---|
147 | break; |
---|
148 | |
---|
149 | // ---------------------------------------- |
---|
150 | // '2' - Print Station Info with Counts |
---|
151 | // |
---|
152 | case ASCII_2: |
---|
153 | station_info_print(NULL , STATION_INFO_PRINT_OPTION_FLAG_INCLUDE_COUNTS); |
---|
154 | break; |
---|
155 | |
---|
156 | // ---------------------------------------- |
---|
157 | // 'e' - Print event log size |
---|
158 | // |
---|
159 | case ASCII_e: |
---|
160 | #if WLAN_SW_CONFIG_ENABLE_LOGGING |
---|
161 | event_log_config_logging(EVENT_LOG_LOGGING_DISABLE); |
---|
162 | print_event_log_size(); |
---|
163 | event_log_config_logging(EVENT_LOG_LOGGING_ENABLE); |
---|
164 | #endif //WLAN_SW_CONFIG_ENABLE_LOGGING |
---|
165 | break; |
---|
166 | |
---|
167 | // ---------------------------------------- |
---|
168 | // 'a' - Print BSS information |
---|
169 | // |
---|
170 | case ASCII_a: |
---|
171 | print_network_info(); |
---|
172 | break; |
---|
173 | |
---|
174 | // ---------------------------------------- |
---|
175 | // 'm' - Display Heap / Malloc information |
---|
176 | // |
---|
177 | case ASCII_m: |
---|
178 | wlan_mac_high_display_mallinfo(); |
---|
179 | break; |
---|
180 | |
---|
181 | // ---------------------------------------- |
---|
182 | // 'x' - Reset network list |
---|
183 | // |
---|
184 | case ASCII_x: |
---|
185 | wlan_mac_high_reset_network_list(); |
---|
186 | break; |
---|
187 | |
---|
188 | // ---------------------------------------- |
---|
189 | // 's' - Scan |
---|
190 | // |
---|
191 | case ASCII_s: |
---|
192 | xil_printf("\f"); |
---|
193 | |
---|
194 | // Check if node is currently in a scan |
---|
195 | is_scanning = wlan_mac_scan_is_scanning(); |
---|
196 | |
---|
197 | // Stop the current scan to update the scan parameters |
---|
198 | if (is_scanning) { |
---|
199 | xil_printf("Stopping Scan\n"); |
---|
200 | wlan_mac_scan_stop(); |
---|
201 | } else { |
---|
202 | xil_printf("Starting Scan\n"); |
---|
203 | |
---|
204 | // Get current scan parameters |
---|
205 | scan_params = wlan_mac_scan_get_parameters(); |
---|
206 | |
---|
207 | // Free the current scan SSID, it will be replaced |
---|
208 | if (scan_params->ssid != NULL) { |
---|
209 | wlan_mac_high_free(scan_params->ssid); |
---|
210 | } |
---|
211 | |
---|
212 | // Set to passive scan |
---|
213 | scan_params->ssid = strndup("", SSID_LEN_MAX); |
---|
214 | |
---|
215 | wlan_mac_scan_start(); |
---|
216 | } |
---|
217 | break; |
---|
218 | // ---------------------------------------- |
---|
219 | // 'j' - Join |
---|
220 | // |
---|
221 | case ASCII_j: |
---|
222 | uart_mode = UART_MODE_JOIN; |
---|
223 | |
---|
224 | xil_printf("\f"); |
---|
225 | |
---|
226 | // Check if node is currently in a scan |
---|
227 | is_scanning = wlan_mac_scan_is_scanning(); |
---|
228 | |
---|
229 | // Stop the current scan to update the scan parameters |
---|
230 | if (is_scanning) { |
---|
231 | wlan_mac_scan_stop(); |
---|
232 | } |
---|
233 | |
---|
234 | // Print results of the scan |
---|
235 | print_network_info(); |
---|
236 | |
---|
237 | // Print prompt |
---|
238 | xil_printf("Enter SSID to join, please type a new string and press enter\n"); |
---|
239 | xil_printf(": "); |
---|
240 | break; |
---|
241 | } |
---|
242 | break; |
---|
243 | |
---|
244 | |
---|
245 | // ------------------------------------------------ |
---|
246 | // Interactive Menu processing |
---|
247 | // |
---|
248 | case UART_MODE_INTERACTIVE: |
---|
249 | switch(rxByte){ |
---|
250 | |
---|
251 | // ---------------------------------------- |
---|
252 | // 'r' - Reset station counts |
---|
253 | // |
---|
254 | case ASCII_r: |
---|
255 | #if WLAN_SW_CONFIG_ENABLE_TXRX_COUNTS |
---|
256 | txrx_counts_zero_all(); |
---|
257 | #endif |
---|
258 | break; |
---|
259 | } |
---|
260 | break; |
---|
261 | |
---|
262 | |
---|
263 | // ------------------------------------------------ |
---|
264 | // Get SSID to Join |
---|
265 | // |
---|
266 | case UART_MODE_JOIN: |
---|
267 | switch(rxByte){ |
---|
268 | |
---|
269 | // ---------------------------------------- |
---|
270 | // Press <Enter> - process new SSID |
---|
271 | // |
---|
272 | case ASCII_CR: |
---|
273 | // Create a '\0' as the final character so SSID is a proper string |
---|
274 | text_entry[curr_char] = 0; |
---|
275 | |
---|
276 | // Get the current join parameters |
---|
277 | join_parameters = wlan_mac_sta_get_join_parameters(); |
---|
278 | |
---|
279 | // Free the current join SSID, it will be replaced |
---|
280 | if (join_parameters->ssid != NULL) { |
---|
281 | wlan_mac_high_free(join_parameters->ssid); |
---|
282 | } |
---|
283 | |
---|
284 | // If SSID was not "", perform the join |
---|
285 | if (curr_char != 0) { |
---|
286 | // Set the SSID |
---|
287 | join_parameters->ssid = strndup(text_entry, SSID_LEN_MAX); |
---|
288 | |
---|
289 | // Clear the BSSID and channel |
---|
290 | bzero((void *)join_parameters->bssid, MAC_ADDR_LEN); |
---|
291 | join_parameters->channel = 0; |
---|
292 | |
---|
293 | // Call join function |
---|
294 | wlan_mac_sta_join(); |
---|
295 | |
---|
296 | // Reset SSID character pointer |
---|
297 | curr_char = 0; |
---|
298 | |
---|
299 | // Start the check_join_status |
---|
300 | check_join_status_id = wlan_mac_schedule_add_event(SCHEDULE_ID_COARSE, 100000, SCHEDULE_REPEAT_FOREVER, (void*)check_join_status); |
---|
301 | |
---|
302 | // Print info to screen |
---|
303 | // - Pause for a second since the return to the Main Menu will erase the screen |
---|
304 | xil_printf("\nJoining: %s\n", text_entry); |
---|
305 | |
---|
306 | } else { |
---|
307 | uart_mode = UART_MODE_MAIN; |
---|
308 | |
---|
309 | // Print error message |
---|
310 | xil_printf("\nNo SSID entered. Returning to Main Menu.\n"); |
---|
311 | |
---|
312 | // Wait a second before proceeding |
---|
313 | wlan_usleep(2000000); |
---|
314 | |
---|
315 | // Print the main menu |
---|
316 | print_main_menu(); |
---|
317 | } |
---|
318 | break; |
---|
319 | |
---|
320 | // ---------------------------------------- |
---|
321 | // Press <Delete> - Remove last character |
---|
322 | // |
---|
323 | case ASCII_DEL: |
---|
324 | if (curr_char > 0) { |
---|
325 | curr_char--; |
---|
326 | xil_printf("\b \b"); |
---|
327 | } |
---|
328 | break; |
---|
329 | |
---|
330 | // ---------------------------------------- |
---|
331 | // Process character |
---|
332 | // |
---|
333 | default: |
---|
334 | if (((rxByte <= ASCII_z) && (rxByte >= ASCII_A)) || |
---|
335 | (rxByte == ASCII_SPACE) || (rxByte == ASCII_DASH)) { |
---|
336 | if (curr_char < SSID_LEN_MAX) { |
---|
337 | xil_printf("%c", rxByte); |
---|
338 | text_entry[curr_char] = rxByte; |
---|
339 | curr_char++; |
---|
340 | } |
---|
341 | } |
---|
342 | break; |
---|
343 | } |
---|
344 | break; |
---|
345 | |
---|
346 | |
---|
347 | default: |
---|
348 | uart_mode = UART_MODE_MAIN; |
---|
349 | print_main_menu(); |
---|
350 | break; |
---|
351 | } |
---|
352 | } |
---|
353 | |
---|
354 | |
---|
355 | |
---|
356 | void print_main_menu(){ |
---|
357 | xil_printf("\f"); |
---|
358 | xil_printf("********************** Station Menu **********************\n"); |
---|
359 | xil_printf("[1] - Interactive Station Status\n"); |
---|
360 | xil_printf("[2] - Print all Observed Counts\n"); |
---|
361 | xil_printf("\n"); |
---|
362 | xil_printf("[a] - Display Network List\n"); |
---|
363 | xil_printf("[j] - Join a network\n"); |
---|
364 | xil_printf("[s] - Toggle active scan\n"); |
---|
365 | xil_printf("**********************************************************\n"); |
---|
366 | } |
---|
367 | |
---|
368 | |
---|
369 | |
---|
370 | void print_station_status(){ |
---|
371 | |
---|
372 | u64 timestamp; |
---|
373 | dl_entry* access_point_entry = NULL; |
---|
374 | station_info_t* access_point = NULL; |
---|
375 | |
---|
376 | if(active_network_info != NULL){ |
---|
377 | access_point_entry = active_network_info->members.first; |
---|
378 | access_point = ((station_info_t*)(access_point_entry->data)); |
---|
379 | } |
---|
380 | |
---|
381 | if (uart_mode == UART_MODE_INTERACTIVE) { |
---|
382 | timestamp = get_system_time_usec(); |
---|
383 | xil_printf("\f"); |
---|
384 | xil_printf("---------------------------------------------------\n"); |
---|
385 | |
---|
386 | if(active_network_info != NULL){ |
---|
387 | xil_printf(" MAC Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", |
---|
388 | access_point->addr[0],access_point->addr[1],access_point->addr[2],access_point->addr[3],access_point->addr[4],access_point->addr[5]); |
---|
389 | xil_printf(" - Last heard from %d ms ago\n",((u32)(timestamp - (access_point->latest_rx_timestamp)))/1000); |
---|
390 | } |
---|
391 | |
---|
392 | xil_printf("---------------------------------------------------\n"); |
---|
393 | xil_printf("\n"); |
---|
394 | xil_printf("[r] - reset counts\n\n"); |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | void check_join_status() { |
---|
399 | // If node is no longer in the join process: |
---|
400 | // - Check BSS info |
---|
401 | // - Return to Main Menu |
---|
402 | |
---|
403 | if (wlan_mac_sta_is_joining() == 0) { |
---|
404 | // Stop the scheduled event |
---|
405 | wlan_mac_schedule_remove_event(check_join_status_id); |
---|
406 | |
---|
407 | // Return to main menu |
---|
408 | uart_mode = UART_MODE_MAIN; |
---|
409 | |
---|
410 | if (active_network_info != NULL) { |
---|
411 | // Print success message |
---|
412 | xil_printf("\nSuccessfully Joined: %s\n", active_network_info->bss_config.ssid); |
---|
413 | } else { |
---|
414 | // Print error message |
---|
415 | xil_printf("\nJoin not successful. Returning to Main Menu.\n"); |
---|
416 | } |
---|
417 | |
---|
418 | // Wait a second before proceeding |
---|
419 | wlan_usleep(3000000); |
---|
420 | |
---|
421 | // Print the main menu |
---|
422 | print_main_menu(); |
---|
423 | } |
---|
424 | } |
---|
425 | |
---|
426 | |
---|
427 | |
---|
428 | |
---|
429 | void start_periodic_print(){ |
---|
430 | stop_periodic_print(); |
---|
431 | print_station_status(); |
---|
432 | print_scheduled = 1; |
---|
433 | schedule_id = wlan_mac_schedule_add_event(SCHEDULE_ID_COARSE, 1000000, SCHEDULE_REPEAT_FOREVER, (void*)print_station_status); |
---|
434 | } |
---|
435 | |
---|
436 | |
---|
437 | |
---|
438 | void stop_periodic_print(){ |
---|
439 | if (print_scheduled) { |
---|
440 | print_scheduled = 0; |
---|
441 | wlan_mac_schedule_remove_event(schedule_id); |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | |
---|
446 | |
---|
447 | #endif |
---|
448 | |
---|
449 | |
---|