Wifi data rate in promiscuous mode?

SoftwareSamurai
Posts: 11
Joined: Wed Sep 13, 2017 11:51 pm

Wifi data rate in promiscuous mode?

Postby SoftwareSamurai » Thu Sep 14, 2017 4:03 pm

I'm researching potential new wifi packet protocols, so I'm playing around with the ESP32's promiscuous mode and the (currently unofficial) esp_wifi_80211_tx() function. I've done some testing and I've got a few questions I hope someone can answer. Here's my general setup:

+ esp_wifi_init() with the WIFI_INIT_CONFIG_DEFAULT() values
+ mode = WIFI_MODE_NULL
+ channel = 11 (using the default bandwidth)
+ did not change the protocol - appears to be defaulted to 802.11b/g/n
+ enabled promiscuous mode

1. Under these settings, what protocol is used when calling esp_wifi_80211_tx()?
I've done some timing tests, and I *think* it's using DSSS, 1 Mbps.

2. Is there any way for me to force it to use, say, OFDM, 54 Mbps?

3. Is there a way I can get, say, an event when the data packet sent via esp_wifi_80211_tx() is actually done transmitting?
I think there is, but I'm just not seeing it in the docs/headers files.

4. I've noticed that I can get "E (6348579) wifi: out of memory!" if I call esp_wifi_80211_tx() too many times (obviously).
Is there any way I can check how full the transmission queue/bufffer is before calling it?

Thanks!

FYI: I'm using the Arduino framework which contains the v2.1 ESP-IDF.

SoftwareSamurai
Posts: 11
Joined: Wed Sep 13, 2017 11:51 pm

Re: Wifi data rate in promiscuous mode?

Postby SoftwareSamurai » Wed Sep 27, 2017 1:54 pm

Should I have posted this in the ESP32 SDK forum instead?

jeanleflambeur
Posts: 5
Joined: Sun Oct 08, 2017 4:26 pm

Re: Wifi data rate in promiscuous mode?

Postby jeanleflambeur » Sun Oct 08, 2017 4:31 pm

Hi Samurai,

Did you find any answers? I'm especially interested in a callback whenever the packet was sent with the esp_wifi_80211_tx function. Without it it's impossible to schedule new packets...

Regarding your rate problem, there is this comment here:
Please note that the sniffer has a great impact on the throughput of the station or soft-AP Wi-Fi connection


Did you try to initialize your wifi with WIFI_MODE_NULL? Don't know if it makes sense as I didn't get to that part myself.
[EDIT] Just re-read your post. Doh! Yes you use MODE_NULL

jeanleflambeur
Posts: 5
Joined: Sun Oct 08, 2017 4:26 pm

Re: Wifi data rate in promiscuous mode?

Postby jeanleflambeur » Wed Oct 11, 2017 8:37 am

Found a way to set the fixed rate.
There is a github issue about this with some barely documented code:
//https://github.com/espressif/esp-idf/issues/833

The first 15 rates are identical to the esp8266 when using the wifi_set_user_fixed_rate(FIXED_RATE_MASK_ALL, x) function.

I checked every rate using wireshark and you can find them below. The SP is actually the short GI rate (400ns vs 800ns guard interval).
At max rate (31) I get around 40Mbps injection speed but I guess it depends a lot on the channel I'm using and how crowded my area is.

Code: Select all

typedef union {
     uint8_t fix_rate;
     uint8_t b5;
     uint8_t b4;
 
     struct {
         uint8_t b3;
         uint8_t b2;
     } b1;
 
     struct {
         uint32_t a1;
         uint8_t  a2;
         uint8_t  a3;
         uint8_t  a4;
         uint8_t  a5;
         struct {
             uint8_t a6;
             uint8_t a7;
         } a8[4];
         uint8_t a9;
         uint8_t a10;
         uint8_t a11;
         uint8_t a12;
     } a13;
 
 } wifi_internal_rate_t;
 
 /*
 wifi_internal_rate_t rate;
 rate.fix_rate = rate;
 esp_wifi_internal_set_rate(100, 1, 4, &rate);
 */
 esp_err_t esp_wifi_internal_set_rate(int a, int b, int c, wifi_internal_rate_t *d);
 
 
esp_err_t set_wifi_fixed_rate(uint8_t value)
{
  wifi_internal_rate_t rate;
  rate.fix_rate = value;
  return esp_wifi_internal_set_rate(100, 1, 4, &rate);
}

//rates:
/*
0 - B 1Mb CCK
1 - B 2Mb CCK
2 - B 5.5Mb CCK
3 - B 11Mb CCK
4 - XXX Not working. Should be B 1Mb CCK SP
5 - B 2Mb CCK SP
6 - B 5.5Mb CCK SP
7 - B 11Mb CCK SP

8 - G 48Mb ODFM
9 - G 24Mb ODFM
10 - G 12Mb ODFM
11 - G 6Mb ODFM
12 - G 54Mb ODFM
13 - G 36Mb ODFM
14 - G 18Mb ODFM
15 - G 9Mb ODFM

16 - N 6.5Mb MCS0
17 - N 13Mb MCS1
18 - N 19.5Mb MCS2
19 - N 26Mb MCS3
20 - N 39Mb MCS4
21 - N 52Mb MCS5
22 - N 58Mb MCS6
23 - N 65Mb MCS7

24 - N 7.2Mb MCS0 SP
25 - N 14.4Mb MCS1 SP
26 - N 21.7Mb MCS2 SP
27 - N 28.9Mb MCS3 SP
28 - N 43.3Mb MCS4 SP
29 - N 57.8Mb MCS5 SP
30 - N 65Mb MCS6 SP
31 - N 72Mb MCS7 SP
*/


SoftwareSamurai
Posts: 11
Joined: Wed Sep 13, 2017 11:51 pm

Re: Wifi data rate in promiscuous mode?

Postby SoftwareSamurai » Wed Oct 11, 2017 8:46 pm

@ jeanleflambeur - Where is "esp_wifi_internal_set_rate()" defined in the ESP-IDF for the ESP32? I don't even see such a function in libnet80211.a.

jeanleflambeur
Posts: 5
Joined: Sun Oct 08, 2017 4:26 pm

Re: Wifi data rate in promiscuous mode?

Postby jeanleflambeur » Thu Oct 12, 2017 7:46 am

You should find it in libpp.a. I'm using the latest arduino esp32 idf.

Regarding the "E (6348579) wifi: out of memory!" error when injecting, you can silence it using esp_log_level_set("*", ESP_LOG_NONE); so that it doesn't kill your data rate. I didn't find any way to get notified when the packet is sent though.

SoftwareSamurai
Posts: 11
Joined: Wed Sep 13, 2017 11:51 pm

Re: Wifi data rate in promiscuous mode?

Postby SoftwareSamurai » Thu Oct 12, 2017 6:06 pm

Okay, found it - thanks! Seems to be working, more or less.

Out of curiosity, do you know what the first three params for esp_wifi_internal_set_rate() are?
Also, are you sure CCK was being used for rates 0 and 1? I thought 802.11b 1 Mbps and 2 Mbps rates were suppose to be DSSS? (Not really a big deal, just wondering.)

jeanleflambeur
Posts: 5
Joined: Sun Oct 08, 2017 4:26 pm

Re: Wifi data rate in promiscuous mode?

Postby jeanleflambeur » Sat Oct 14, 2017 5:50 pm

No idea about the extra params. I tried to play with them but got no meaningful info.
Wireshark told me the modulation was CCK. 1 & 2 Mbps 802.11B should be DSSS indeed but as far as I read, CCK and DSSS are very similar. Both are spread spectrum, just the coding sequence is different - but I don't have a thorough understanding of these modulations tbh.
For my purpose either is perfect - as I'm trying to get as much immunity to RC transmitters as possible and I don't really want to do channel hopping as it's very tricky to get the RX & TX in sync.

Did you manage to find a way to setup a callback for when a packet is transmitted?

SoftwareSamurai
Posts: 11
Joined: Wed Sep 13, 2017 11:51 pm

Re: Wifi data rate in promiscuous mode?

Postby SoftwareSamurai » Sun Oct 15, 2017 3:15 am

jeanleflambeur wrote:Did you manage to find a way to setup a callback for when a packet is transmitted?


Nope. I'm guessing espressif will need to add such a capability.

For my testing, I wrote a function that queues up WiFi packets to be transmitted until it fails (meaning the queue is full, which is defaulted to 32 I believe), then time how long it takes before I can add another packet to the queue. So far, with this crude method, it appears that the system it taking ~1.2 milliseconds to actually spit out a WiFi packet regardless of what transmit mode I'm in. I'm not sure if this delay is just the internal layers doing their work, or if it is taking some time to physically switch the radio from receive to transmit, transmit, then back to receive. I'm hoping it's just internal software gyration that can be greatly optimized down the road. (It's also possible that esp_wifi_80211_tx() is doing a memcpy() internally, which may also slow things down.)

I did find a function listed in ieee80211_ioctl.o, "wifi_txq_empty". Maybe it's a query to see if the transmit queue is empty? I haven't tried it yet though.

EDIT: I finally got a chance to check out "bool wifi_txq_empty();" and it does indeed report if the transmit queue is empty or not. However, that's just the outgoing queue itself. It doesn't actually report when the WiFi packet has been transmitted.

Who is online

Users browsing this forum: No registered users and 2 guests