RinCat / RTL88x2BU-Linux-Driver

Realtek RTL88x2BU WiFi USB Driver for Linux
GNU General Public License v2.0
1.26k stars 198 forks source link

iw reg set XX: different results for same country #49

Open jdefields opened 4 years ago

jdefields commented 4 years ago

Hi,

I'm using this driver to test a wireless dongle with the 8822 chipset. The driver seems to work well in most regards, except for setting up regions.

I’m seeing some strange behavior when switching back and forth between regions with 'iw reg set'. It seems like not all of the channel settings go back to where they were/should be. I was able to duplicate the results on an Nvidia Tegra TK1 system running linux 3.10, as well as a Xilinx Zynq system running 4.14. 'iw reg get' returns the expected results in each case.

For example the default country (00) has: iw list | grep MHz

Then if I set to (FR): iw reg set FR iw list | grep MHz

Then back to (00): iw reg set 00 iw list | grep MHz

Do you see a similar situation? Any ideas?

RinCat commented 4 years ago

Hi, I got different results:

iw list | grep MHz

  • 5720 MHz [144] (disabled)
  • 5745 MHz [149] (30.0 dBm)
  • 5765 MHz [153] (30.0 dBm)
  • 5785 MHz [157] (30.0 dBm)
  • 5805 MHz [161] (30.0 dBm)
  • 5825 MHz [165] (30.0 dBm)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)
  • 5885 MHz [177] (disabled)
iw reg set FR
iw list | grep MHz
  • 5720 MHz [144] (disabled)
  • 5745 MHz [149] (13.0 dBm)
  • 5765 MHz [153] (13.0 dBm)
  • 5785 MHz [157] (13.0 dBm)
  • 5805 MHz [161] (13.0 dBm)
  • 5825 MHz [165] (13.0 dBm)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)
  • 5885 MHz [177] (disabled)
iw reg set 00
iw list | grep MHz
  • 5720 MHz [144] (disabled)
  • 5745 MHz [149] (20.0 dBm)
  • 5765 MHz [153] (20.0 dBm)
  • 5785 MHz [157] (20.0 dBm)
  • 5805 MHz [161] (20.0 dBm)
  • 5825 MHz [165] (20.0 dBm)
  • 5845 MHz [169] (disabled)
  • 5865 MHz [173] (disabled)
  • 5885 MHz [177] (disabled)

It's possible the first one is default values and not the iw reg set one.

jdefields commented 4 years ago

Are you compiling with this flag: CONFIG_RTW_IOCTL_SET_COUNTRY

You should be seeing channels get disabled and enabled.

ID is a particularly restrictive country. What are you results for this:

iw reg set ID iw list | grep MHz

RinCat commented 4 years ago

I just noticed you are on ARM, so I cannot test that. But you can set the CONFIG_RTW_LOG_LEVEL to 5 and see if something wrong.

jdefields commented 4 years ago

Regardless of being on ARM or x86, can you post your results for: iw reg set ID iw list | grep MHz

If channels are not being disabled, you will still need the CONFIG_RTW_IOCTL_SET_COUNTRY flag to be set during x86 compilation. Otherwise channels will not be disabled on region switches.

See the code here: https://github.com/RinCat/RTL88x2BU-Linux-Driver/blob/master/core/rtw_ioctl_set.c#L894

jdefields commented 4 years ago

I think I may see part of the problem though. I added some additional debug to "rtw_set_country_cmd".

'00' is valid for wireless-regdb/crda, but appears to NOT be valid for this realtek driver:

iw reg set 00 [ 67.386258] cfg80211: Calling CRDA to update world regulatory domain [ 67.415758] rtw_set_country_cmd input country_code is not alpha2

RinCat commented 4 years ago

Yes, there is no "00" in the driver built-in country channel data. Which it usually let wireless-regdb/crda to control which channel can be used.

jdefields commented 4 years ago

I think '00' should probably be recognized as a valid region, since it's in the wireless-regdb database. The default setup for 00 in this driver is probably incorrect if it's getting set by CRDA, but then ultimately ignored because the driver thinks it's invalid.

With that said, at least now I understand the strange behavior I was seeing. This also means you cannot create customized regulatory domains, without patching the driver to add them.

RinCat commented 4 years ago

I Added this support, but notice it is not use the CRDA/wireless-db data. https://github.com/RinCat/RTL88x2BU-Linux-Driver/commit/3a6f393adda93ab0bc8998c8efc9cb8e438e04b4

jdefields commented 4 years ago

Are you saying that the rtl88x2bu driver would then override the power/no-ir/indoor/outdoor/etc settings in db.txt in wireless-regdb? I'll have to try modifying the db.txt on monday to see if that's the case. I could try something simple like changing the power settings for a supported country (i.e. US).

I would expect the settings in CRDA/wireless-db to further restrict anything set by the driver.

RinCat commented 4 years ago

They all followed the realtek built-in data set as hard limit. WiFi control system can set their limit too, but it may or may not works.

jdefields commented 4 years ago

I was using an older version of the driver, it seems some updates have gone in to the region settings since the version I was using (probably 12+ months ago). Now, crda/regdb power settings seem to apply reasonably well on top of the driver settings. Setting NO-IR in db.txt doesn't override the driver, but I could just change those settings in the driver as needed.

jdefields commented 4 years ago

I Added this support, but notice it is not use the CRDA/wireless-db data. 3a6f393

I'm testing with this change, and it looks good, though I'm confused by the initial power limits being set for the default region '00'. They seem to be all 30dBm. I don't think that matches the internal TX power setting or crda/regdb settings. Changing to 'US' then back to '00' will give the expected crda/regdb TX power settings for '00' (20dBM / 23dBm).

Do you know where the default of 30dBm may be being set in the driver?

RinCat commented 4 years ago

I only found where it init, but no idea where the 30 come from. https://github.com/RinCat/RTL88x2BU-Linux-Driver/blob/3a6f393adda93ab0bc8998c8efc9cb8e438e04b4/core/rtw_mlme_ext.c#L171

jdefields commented 4 years ago

I only found where it init, but no idea where the 30 come from.

https://github.com/RinCat/RTL88x2BU-Linux-Driver/blob/3a6f393adda93ab0bc8998c8efc9cb8e438e04b4/core/rtw_mlme_ext.c#L171

This code doesn't seem to run at boot.

This code does run when I use 'iw reg set' after logging in, and even in that case, I see the message: "there is no any txpwr_regd"

jdefields commented 3 years ago

@RinCat FYI, I have received some hardware-region-locked dongles. For those dongles, the enabled channels are correct when plugged in, but then get incorrectly adjusted with 'iw reg set' later on (you end up being able to enable channels that are physically disabled by the HW). In this case, you would NOT want CONFIG_RTW_IOCTL_SET_COUNTRY flag to be set, if you want the results of 'iw list | grep MHz' to match with what the dongle is actually capable of supporting.

This would be up to the user. I'm not sure that setting the default to Y is a good or bad idea. Just wanted to bring this to your attention. Basically this setting should match whether or not this dongle is hard region locked.

I still have the issue where the default power limit of all channels is set to 30dBm when plugging in, until you issue the first 'iw reg set' to any region other than 00. Even setting back to 00 does not set the channels all to 30dBm.

RinCat commented 3 years ago

The 30dbm seems come from firmware https://github.com/RinCat/RTL88x2BU-Linux-Driver/blob/f9085c8a656f48022e7985f19e7113357597e952/hal/hal_com_phycfg.c#L4083-L4089