Skip to content

Time fix for packet, and filter addition #21

Description

@henriberisha

Stefan, thank you for this library.

Below are two code changes that i made to improve the results of all examples that you provide.

  1. Fix time issue when writing or sending a packet. Change the following lines:
    uint32_t timestamp = now(); //current timestamp
    uint32_t microseconds = (unsigned int)(micros() - millis() * 1000); //micro seconds offset (0 - 999)

into

uint32_t timestamp = now(); // current timestamp
uint32_t microseconds = (unsigned int)(micros() % 1000000U);

This will fix the relative time between packets, see below results:

relative_time_bad_offset

relative_time_fixed_offset

  1. Can add filter to capture management and data packets:
PCAP pcap = PCAP();
int ch = CHANNEL;
unsigned long lastChannelChange = 0;

const wifi_promiscuous_filter_t filter_data_mgmt = {
    .filter_mask = WIFI_PROMIS_FILTER_MASK_DATA | WIFI_PROMIS_FILTER_MASK_MGMT}; // this filter either DATA or MGMT frames```

```/* setup wifi */
nvs_flash_init();  
tcpip_adapter_init();  
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));  
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();  
ESP_ERROR_CHECK(esp_wifi_init(&cfg));  
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));  
ESP_ERROR_CHECK(esp_wifi_start());  
esp_wifi_set_promiscuous_filter(&filter_data_mgmt); // the filter is used here  
esp_wifi_set_promiscuous(true);  
esp_wifi_set_promiscuous_rx_cb(sniffer);  
wifi_second_chan_t secondCh = (wifi_second_chan_t)NULL;  
esp_wifi_set_channel(ch, secondCh);```


 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions