How to obtain wifi packet rate in sniffer application?

doragasu
Posts: 16
Joined: Sat Apr 27, 2019 5:18 pm

How to obtain wifi packet rate in sniffer application?

Postby doragasu » Mon Jan 30, 2023 10:57 am

I want to build an application to measure WiFi channel load. This requires computing air time of received packets. My approach is:

1. Configure ESP32 in promiscuous mode, enable reception of all kind of packets.
2. In the rx callback, obtain the packet rate and packet length.
3. Using the rate and length, compute the tx time, and add the preamble: air_time = length * 8 / rate + 192 us.

For example if I receive a 1000 byte packet at 1 Mbps, the air time would be:

air_time = 1000 * 8 / 1e6 + 192e-6 = 8192 us.

The problem I have is I do not know exactly how to obtain the packet rate. Currently I examine the wifi_pkt_rx_ctrl_t data and do the following:

1. If the packet is 802.11n (sig_mode == 1), get bandwidth (20 or 40 MHz), SGI and MCS, decode using this table.
2. If the packet is 802.11bg (sig_mode == 0), use the rate field.

The problem is with step 2. I am having two problems with the rate field:

1. how is wifi_pkt_rx_ctrl_t::rate interpreted? Is it the bitrate in units of 500 kbps (so e.g. rate 22 means 11 Mbps)? Or should I interpret it using wifi_phy_rate_t enum (so e.g. rate 3 is 11 Mbps)?
2. Independently of how I interpret this field, I am having inconsistent values in the captures I am doing. For example I am not seeing frames transmitted at 1 Mbps, and there should be a lot because I am seen mostly beacon frames when I do a capture with a PC running Wireshark.

doragasu
Posts: 16
Joined: Sat Apr 27, 2019 5:18 pm

Re: How to obtain wifi packet rate in sniffer application?

Postby doragasu » Tue Jan 31, 2023 9:07 am

After reviewing carefully the capture, it looks like rate uses the wifi_phy_rate_t, but confirmation would be nice.

Who is online

Users browsing this forum: No registered users and 200 guests