Promiscuous mode in WiFi is stoped by UART driver

Xarlan
Posts: 12
Joined: Tue Jul 10, 2018 3:09 pm

Promiscuous mode in WiFi is stoped by UART driver

Postby Xarlan » Wed Feb 27, 2019 8:56 am

Hello
I use ESP-IDF v 3.1.2
devbord - ESP32-PICO-KIT.
I try to realize wi-fi sniffer, send via UART captured 802.11 frame. Also in asynchronous mode receive settings from PC.
So, this code is initialize UART

Code: Select all

	
uart_config_t uart_cfg = {
	.baud_rate = UART_2_PC_BAUD_RATE,
	.data_bits = UART_DATA_8_BITS,
	.parity    = UART_PARITY_DISABLE,
	.stop_bits = UART_STOP_BITS_1,
	.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
							 };
ESP_ERROR_CHECK(uart_param_config(UART_2_PC, &uart_cfg));
ESP_ERROR_CHECK(uart_set_pin(UART_2_PC, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_driver_install(UART_2_PC, 4096, 4096, 0, NULL, 0));
Also I was created 2 task:

Code: Select all

		
xReturned = xTaskCreatePinnedToCore(vUartWiFi, "UartWiFi", 8192, NULL, 1, NULL, 1);
	if (xReturned != pdPASS)
		{
			printf("Can't create UartWifi task\n");
			printf("ESP32 will be reset after 3 sec\n");
			vTaskDelay(3000/ portTICK_PERIOD_MS);
			esp_restart();
		}

xReturned = xTaskCreatePinnedToCore(vUartSettings, "UartSettings", 4096, NULL, 12, NULL, 1);
	if (xReturned != pdPASS)
		{
			printf("Can't create UartSettings task\n");
			printf("ESP32 will be reset after 3 sec\n");
			vTaskDelay(3000/ portTICK_PERIOD_MS);
			esp_restart();
		}
task "UartWiFi"
receive 802.11 frame from callback, analyze this frame and send via uart. I use

Code: Select all

uart_write_bytes(UART_2_PC, (char*) pkt, wifi_frame.ESP32_RADIO_METADATA.sig_len);
This function work good. At PC side I receive 802.11 frame correctly.

the main idea of task "UartSettings"
receive settings (set/get channel WiFi, enable/disable promiscuous mode etc) from PC

Code: Select all

void vUartSettings(void *pvParameters)
{

	uint8_t tlv_cmd[CMD_TLV_BUFFER];
//	tlv_cmd_t tlv_cmd;
	size_t len_tlv_cmd =0;
	int rx_bytes;
	uint8_t current_wifi_channel;

	while(1)
	{
		uart_get_buffered_data_len(UART_2_PC, &len_tlv_cmd);
//		printf("\n*******\n");
//		printf("Rx bytes = %d\n", len_tlv_cmd);
//		printf("*******\n");
		if (len_tlv_cmd > 0)
		{
			rx_bytes = uart_read_bytes(UART_2_PC, tlv_cmd, len_tlv_cmd, 10000/portTICK_RATE_MS);
			if (rx_bytes > 0)
			{
				switch(tlv_cmd[0])
				{
					case 1:
						printf("start/stop sniffer\n");
						esp_wifi_set_promiscuous(true);
						break;

					default:
						printf("\n*******\nUnknown cmd\n*****\n");
				}
			}
		}
	}

	vTaskDelete(NULL);
}
The function "uart_get_buffered_data_len" work correct. But when "uart_read_bytes" has executed - promiscuous mode is stop. I also changed the latst argument (ticks_to_wait) set to "0", "NULL" or "other_value". Nothing happen.
Every time "uart_read_bytes" executed -> promiscuous mode if OFF.

What could be wrong?

Thank you.

P.S.
Full code avaible here

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 88 guests