esp32-open-mac / esp32-open-mac

Reverse engineered wifi driver for the ESP32
464 stars 22 forks source link

Find way to get channel of packet #17

Open redfast00 opened 1 month ago

redfast00 commented 1 month ago

Right now, if you configure the channel to channel 7, you receive packets from both channel 7 and 8 (but only transmit on 7). We need to know which channel a packet is received on: if we don't know this, we might try to send packets on the wrong channel.

rottaran commented 1 month ago

I think this is related to 20MHz vs 40MHz channel settings. ESP-IDF has two functions for that configuration esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second) and esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw). On the ESP32, it was possible to accidentially set this up wrong. Then it receives on both channels for 40MHz frames while still sending 20MHz frames. On ESP32-S3 this failed and did not receive or send anything at all when wrong.

I only have experience with the monitor mode (promiscuous callback) in ESP-IDF. The struct wifi_pkt_rx_ctrl_t has fields cwb for the bandwidth, channel, and secondary_channel. So this information comes somewhere from the hardware.

redfast00 commented 1 month ago

We indeed receive a packet in the wifi_pkt_rx_ctrl_t format from the hardware; but the fields you mention (channel, secondary_channel) both appear to be set to 0. Maybe there is a bit we need to set to tell the hardware to fill in those fields? This will probably end in reverse engineering the blob a bit more to see how this works.