Skip to content

iwinfo: add basic IEEE 802.11be support#10

Closed
cmonroe wants to merge 2 commits intoopenwrt:masterfrom
cmonroe:wifi7
Closed

iwinfo: add basic IEEE 802.11be support#10
cmonroe wants to merge 2 commits intoopenwrt:masterfrom
cmonroe:wifi7

Conversation

@cmonroe
Copy link
Copy Markdown
Contributor

@cmonroe cmonroe commented Jun 24, 2024

Add basic support for 802.11be / WiFi 7 to iwinfo.

Required for IEEE 802.11be support

Taken from the v6.6.15 mac80211 package

Signed-off-by: Koral Ilgun <koral.ilgun@smartrg.com>
Signed-off-by: Chad Monroe <chad@monroe.io>
Comment thread include/iwinfo.h
uint8_t is_he:1;
uint8_t he_gi;
uint8_t he_dcm;
uint8_t mhz;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks the ABI which I'd ideally like to avoid. If I am not mistaken, there should be two bytes of padding at the end of the struct, so maybe place the high mhz bits after the mss field. Also put the is_eht bitfield member directly after is_he to ensure that it ends up in the same byte.

Updated structure layout could look like:

struct iwinfo_rate_entry {
	uint32_t rate;
	int8_t mcs;
	uint8_t is_40mhz:1;
	uint8_t is_short_gi:1;
	uint8_t is_ht:1;
	uint8_t is_vht:1;
	uint8_t is_he:1;
	uint8_t is_eht:1;
	uint8_t he_gi;
	uint8_t he_dcm;
	uint8_t mhz_lo;
	uint8_t nss;
        uint8_t mhz_hi;
        uint8_t eht_gi;    
};

Comment thread iwinfo_cli.c Outdated
}
else if (r->is_eht)
{
p += snprintf(p, l, ", EHT-MCS %d, %dMHz", r->mcs, r->mhz);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the updated structure, this will become:
p += snprintf(p, l, ", EHT-MCS %d, %dMHz", r->mcs, r->mhz_hi * 256 + r->mhz);

Comment thread iwinfo_nl80211.c Outdated

if (len > sizeof(m->eht_phy_cap) - 1)
len = sizeof(m->eht_phy_cap) - 1;
memcpy(&((__u8 *)m->eht_phy_cap)[1],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use uint8_t here

Comment thread iwinfo_nl80211.c Outdated
}

// EHT
if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this no-op statement

Comment thread iwinfo_nl80211.c Outdated
nla_data(tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY]),
len);
}
if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this no-op statement

Comment thread iwinfo_nl80211.c Outdated
}
if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET]) {
}
if (tb[NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE]) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this no-op statement

Comment thread iwinfo_nl80211.c Outdated
ri[NL80211_RATE_INFO_160_MHZ_WIDTH])
re->mhz = 160;
else if (ri[NL80211_RATE_INFO_320_MHZ_WIDTH])
re->mhz = 320;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the updated structure layout, this should become

re->mhz_hi = 320 / 256, re->mhz = 320 % 256;

or

re->mhz_hi = 1, re->mhz = 64;

Comment thread iwinfo_lua.c Outdated
lua_pushboolean(L, r->is_eht);
lua_setfield(L, -2, rx ? "rx_eht" : "tx_eht");

lua_pushnumber(L, r->mhz);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the updated structure layout, this should become
lua_pushnumber(L, r->mhz_hi * 256 + r->mhz);

Add support for IEEE 802.11be via HW and HT modelist as well as
EHT specific rate information for associated STAs.

Signed-off-by: Koral Ilgun <koral.ilgun@smartrg.com>
Signed-off-by: Chad Monroe <chad@monroe.io>
@cmonroe
Copy link
Copy Markdown
Contributor Author

cmonroe commented Jun 26, 2024

Hi @jow-

Thanks for looking this over! I think I got all of your requested changes in the most recent push if you don't mind checking them. I tested that 20, 80, 160 and 320MHz bandwidths are still reported correctly via the CLI and ubus. In order for assoclist to display 320MHz correctly via ubus I've updated rpcd #5 as well.

Two questions, mostly for my own understanding if you have the time to share:

  1. Is adding the is_eht flag in the middle of iwinfo_rate_entry OK because all of the defined bitfields end up in the same byte?
  2. Does adding a new element not require an ABI change? The rpcd PR mentioned above will make rpcd reliant upon presence of mhz_hi and I wanted to make sure this is OK.

@jow-
Copy link
Copy Markdown
Contributor

jow- commented Jun 27, 2024

Hi,

Is adding the is_eht flag in the middle of iwinfo_rate_entry OK because all of the defined bitfields end up in the same byte?

Yes. The is_eht field is a single-bit bitfield member (due to the :1 suffix). Adjacent bitfield struct members with the same base type are packed into the same value, so a

struct {
  uint8_t foo:1;
  uint8_t bar:1;
  uint8_t baz:1;
}

... ends up being a struct with one byte holding three bits, while in contrast a

struct {
  uint8_t foo:1;
  uint8_t bar:1;
  bool something_else;
  uint8_t baz:1;
}

... ends up being three bytes large (first a byte holding two bits, then a byte holding a boolean 1 or 0 value, then another byte holding one bit).

Does adding a new element not require an ABI change?

It depends, in this particular case the structure size and layout did not change, so existing code built against an older libiwinfo loading a newer one will continue to work. It might not be able to make sense of the new values (e.g. wrongly report "64 MHz" for a 320 wide channel) but it will not crash trying to access nonexistent/invalid memory when the structures returned by iwinfo are larger than what the program expects.

The reason why we need to be somewhat careful with the ABI here is that some programs (e.g. LuCI) dlopen() libiwinfo at runtime, so the usual ABI handling mechanics in packages do not apply.

Here's my local testcase for the structure size:

@j7:~$ cat /tmp/structsize.c 
#include <stdint.h>
#include <stdio.h>

struct iwinfo_rate_entry_old {
	uint32_t rate;
	int8_t mcs;
	uint8_t is_40mhz:1;
	uint8_t is_short_gi:1;
	uint8_t is_ht:1;
	uint8_t is_vht:1;
	uint8_t is_he:1;
	uint8_t he_gi;
	uint8_t he_dcm;
	uint8_t mhz;
	uint8_t nss;
};

struct iwinfo_rate_entry_new {
	uint32_t rate;
	int8_t mcs;
	uint8_t is_40mhz:1;
	uint8_t is_short_gi:1;
	uint8_t is_ht:1;
	uint8_t is_vht:1;
	uint8_t is_he:1;
	uint8_t is_eht:1;
	uint8_t he_gi;
	uint8_t he_dcm;
	uint8_t mhz_lo;
	uint8_t nss;
        uint8_t mhz_hi;
        uint8_t eht_gi;
};


int main(int argc, char **argv) {
	printf("%zd, %zd\n",
		sizeof(struct iwinfo_rate_entry_old),
		sizeof(struct iwinfo_rate_entry_new));

	return 0;
}
jow@j7:~$ gcc -o /tmp/structsize /tmp/structsize.c && /tmp/structsize
12, 12
jow@j7:~$

The reason why it was possible in this case is that the original struct had two unused alignment padding bytes at the end.

@cmonroe
Copy link
Copy Markdown
Contributor Author

cmonroe commented Jun 28, 2024

Thanks for the super clear info, it is very helpful :)

The ABI change part makes a lot of sense now.. I was thinking about the problem backwards before your explanation.

Please let me know if any other changes are needed and thanks again for your help!

@rmandrad
Copy link
Copy Markdown

Successfully tested on Banana Pi4

@rmandrad
Copy link
Copy Markdown

@dangowrt is anyone monitoring the openwrt/rpcd repo ? @cmonroe has another pull related with 11be support but it doesn't have any feedback/approvers

Copy link
Copy Markdown

@danpawlik danpawlik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Tested-By: Daniel Pawlik pawlik.dan@gmail.com

@danpawlik
Copy link
Copy Markdown

any chance to merge that @jow- ? I see it has been already approved by Daniel.

danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 17, 2024
In the iwinfo fork, there are required patches [1][2] to make the BE wireless
standard be available in Luci.

[1] openwrt/iwinfo#11
[2] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 17, 2024
In the iwinfo fork, there are required patches [1][2] to make the BE wireless
standard be available in Luci.

[1] openwrt/iwinfo#11
[2] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 21, 2024
The rpcd repository contains a patch [1] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [2][3].

[1] - openwrt/rpcd#5
[2] openwrt/iwinfo#11
[3] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 21, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10

(cherry picked from commit 97d6044)
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 23, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 24, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 24, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 26, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 26, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 27, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10

(cherry picked from commit c616208)
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 29, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10

(cherry picked from commit c616208)
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 29, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10

(cherry picked from commit c616208)
@cmonroe cmonroe closed this Sep 29, 2024
@cmonroe cmonroe deleted the wifi7 branch September 29, 2024 21:32
danpawlik added a commit to danpawlik/openwrt that referenced this pull request Sep 30, 2024
This commit provides switch luci project to use branch that contains
patch for BE standard [1].
The rpcd repository contains a patch [2] that will bring BE wireless
standard.
Also update iwinfo project to apply patches [3][4].

[1] - openwrt/luci#7279
[2] - openwrt/rpcd#5
[3] openwrt/iwinfo#11
[4] openwrt/iwinfo#10

(cherry picked from commit c616208)
rmandrad added a commit to rmandrad/luci that referenced this pull request Oct 3, 2024
Tested with banana rpi-4

In order to complete 11be support - the below pulls will need to be applied

RPCD - openwrt/rpcd#5
iwinfo - openwrt/iwinfo#10

Signed-off-by: Rudy Andram <rmandrad@gmail.com>
Tested-By: Daniel Pawlik <pawlik.dan@gmail.com>
rmandrad added a commit to rmandrad/luci that referenced this pull request Oct 3, 2024
Tested with banana rpi-4

In order to complete 11be support - the below pulls will need to be applied

RPCD - openwrt/rpcd#5
iwinfo - openwrt/iwinfo#10

Signed-off-by: Rudy Andram <rmandrad@gmail.com>
Tested-By: Daniel Pawlik <pawlik.dan@gmail.com>
rmandrad added a commit to rmandrad/luci that referenced this pull request Oct 3, 2024
Tested with banana rpi-4

In order to complete 11be support - the below pulls will need to be applied

RPCD - openwrt/rpcd#5
iwinfo - openwrt/iwinfo#10

Signed-off-by: Rudy Andram <rmandrad@gmail.com>
Tested-By: Daniel Pawlik <pawlik.dan@gmail.com>

correct ; with , instead for the declaration of eht
rmandrad added a commit to rmandrad/luci that referenced this pull request Oct 3, 2024
Tested with banana rpi-4

In order to complete 11be support - the below pulls will need to be applied

RPCD - openwrt/rpcd#5
iwinfo - openwrt/iwinfo#10

Signed-off-by: Rudy Andram <rmandrad@gmail.com>
Tested-By: Daniel Pawlik <pawlik.dan@gmail.com>

correct ; with , instead for the declaration of eht
rmandrad added a commit to rmandrad/luci that referenced this pull request Oct 3, 2024
Tested with banana rpi-4

In order to complete 11be support - the below pulls will need to be applied

RPCD - openwrt/rpcd#5
iwinfo - openwrt/iwinfo#10

Signed-off-by: Rudy Andram <rmandrad@gmail.com>
Tested-By: Daniel Pawlik <pawlik.dan@gmail.com>

correct ; with , instead for the declaration of eht
@systemcrash
Copy link
Copy Markdown

@cmonroe Can you also take care of the 240(/160+80) MHz case?

@cmonroe
Copy link
Copy Markdown
Contributor Author

cmonroe commented Nov 9, 2024

Daniel merged the changed from this PR via 4b7c47c and 268a662

@Neustradamus
Copy link
Copy Markdown

@cmonroe: Thanks :)

@Neustradamus
Copy link
Copy Markdown

Dear all, @cmonroe, @jow-, @rmandrad, @danpawlik, @systemcrash, @dangowrt,

There is a new PR linked to 11be done by @prokowsoftware here:

Can you look?

Thanks in advance.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants