Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lantiq: fix ath9k-eeprom for AVM Fritz!Box 7430 #12247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Djfe
Copy link
Contributor

@Djfe Djfe commented Mar 22, 2023

@grische noticed that the extracted wifi calibration data (ath9k-eeprom) is incorrect.
Symptoms included:

  • wrong mac address
  • radio was detected like dbdc (2.4GHz and 5GHz support at the same time)

This patch fixes this by also reversing the order of bytes and throwing away the last 4 Bytes.
Unlike caldata.sh the fritz_cal_extract.c doesn't support reversing. So this patch combines both methods.


The new code is based on https://github.com/openwrt/openwrt/blob/master/package/base-files/files/lib/functions/caldata.sh#L64-L80

The issue was noticed here: freifunk-gluon/gluon#2270

iw list (before)
Wiphy phy0
      wiphy index: 0
      max # scan SSIDs: 4
      max scan IEs length: 2257 bytes
      max # sched scan SSIDs: 0
      max # match sets: 0
      Retry short limit: 7
      Retry long limit: 4
      Coverage class: 0 (up to 0m)
      Device supports AP-side u-APSD.
      Device supports T-DLS.
      Available Antennas: TX 0x7 RX 0x7
      Configured Antennas: TX 0x7 RX 0x7
      Supported interface modes:
               * IBSS
               * managed
               * AP
               * AP/VLAN
               * monitor
               * mesh point
               * P2P-client
               * P2P-GO
               * outside context of a BSS
      Band 1:
              Capabilities: 0x11ef
                      RX LDPC
                      HT20/HT40
                      SM Power Save disabled
                      RX HT20 SGI
                      RX HT40 SGI
                      TX STBC
                      RX STBC 1-stream
                      Max AMSDU length: 3839 bytes
                      DSSS/CCK HT40
              Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
              Minimum RX AMPDU time spacing: 8 usec (0x06)
              HT TX/RX MCS rate indexes supported: 0-23
              Frequencies:
                      * 2412 MHz [1] (20.0 dBm)
                      * 2417 MHz [2] (20.0 dBm)
                      * 2422 MHz [3] (20.0 dBm)
                      * 2427 MHz [4] (20.0 dBm)
                      * 2432 MHz [5] (20.0 dBm)
                      * 2437 MHz [6] (20.0 dBm)
                      * 2442 MHz [7] (20.0 dBm)
                      * 2447 MHz [8] (20.0 dBm)
                      * 2452 MHz [9] (20.0 dBm)
                      * 2457 MHz [10] (20.0 dBm)
                      * 2462 MHz [11] (20.0 dBm)
                      * 2467 MHz [12] (20.0 dBm)
                      * 2472 MHz [13] (20.0 dBm)
                      * 2484 MHz [14] (disabled)
      Band 2:
              Capabilities: 0x11ef
                      RX LDPC
                      HT20/HT40
                      SM Power Save disabled
                      RX HT20 SGI
                      RX HT40 SGI
                      TX STBC
                      RX STBC 1-stream
                      Max AMSDU length: 3839 bytes
                      DSSS/CCK HT40
              Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
              Minimum RX AMPDU time spacing: 8 usec (0x06)
              HT TX/RX MCS rate indexes supported: 0-23
              Frequencies:
                      * 5180 MHz [36] (15.0 dBm)
                      * 5200 MHz [40] (15.0 dBm)
                      * 5220 MHz [44] (15.0 dBm)
                      * 5240 MHz [48] (15.0 dBm)
                      * 5260 MHz [52] (15.0 dBm) (radar detection)
                      * 5280 MHz [56] (15.0 dBm) (radar detection)
                      * 5300 MHz [60] (15.0 dBm) (radar detection)
                      * 5320 MHz [64] (15.0 dBm) (radar detection)
                      * 5500 MHz [100] (15.0 dBm) (radar detection)
                      * 5520 MHz [104] (15.0 dBm) (radar detection)
                      * 5540 MHz [108] (15.0 dBm) (radar detection)
                      * 5560 MHz [112] (15.0 dBm) (radar detection)
                      * 5580 MHz [116] (15.0 dBm) (radar detection)
                      * 5600 MHz [120] (15.0 dBm) (radar detection)
                      * 5620 MHz [124] (15.0 dBm) (radar detection)
                      * 5640 MHz [128] (15.0 dBm) (radar detection)
                      * 5660 MHz [132] (15.0 dBm) (radar detection)
                      * 5680 MHz [136] (15.0 dBm) (radar detection)
                      * 5700 MHz [140] (15.0 dBm) (radar detection)
                      * 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)
      valid interface combinations:
               * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1, #{ IBSS } <= 1,
                 total <= 2048, #channels <= 1, STA/AP BI must match, radar detect widths: { 20 MHz (no HT), 20 MHz, 40 MHz }

      HT Capability overrides:
               * MCS: ff ff ff ff ff ff ff ff ff ff
               * maximum A-MSDU length
               * supported channel width
               * short GI for 40 MHz
               * max A-MPDU length exponent
               * min MPDU start spacing
      max # scan plans: 1
      max scan plan interval: -1
      max scan plan iterations: 0
      Supported extended features:
              * [ RRM ]: RRM
              * [ FILS_STA ]: STA FILS (Fast Initial Link Setup)
              * [ CQM_RSSI_LIST ]: multiple CQM_RSSI_THOLD records
              * [ CONTROL_PORT_OVER_NL80211 ]: control port over nl80211
              * [ TXQS ]: FQ-CoDel-enabled intermediate TXQs
              * [ AIRTIME_FAIRNESS ]: airtime fairness scheduling
              * [ SCAN_RANDOM_SN ]: use random sequence numbers in scans
              * [ SCAN_MIN_PREQ_CONTENT ]: use probe request with only rate IEs in scans
              * [ CAN_REPLACE_PTK0 ]: can safely replace PTK 0 when rekeying
              * [ CONTROL_PORT_NO_PREAUTH ]: disable pre-auth over nl80211 control port support
              * [ DEL_IBSS_STA ]: deletion of IBSS station support
              * [ MULTICAST_REGISTRATIONS ]: mgmt frame registration for multicast
              * [ SCAN_FREQ_KHZ ]: scan on kHz frequency support
              * [ CONTROL_PORT_OVER_NL80211_TX_STATUS ]: tx status for nl80211 control port support
iw list (with this patch)
Wiphy phy0
      wiphy index: 0
      max # scan SSIDs: 4
      max scan IEs length: 2257 bytes
      max # sched scan SSIDs: 0
      max # match sets: 0
      Retry short limit: 7
      Retry long limit: 4
      Coverage class: 0 (up to 0m)
      Device supports AP-side u-APSD.
      Device supports T-DLS.
      Available Antennas: TX 0x7 RX 0x7
      Configured Antennas: TX 0x7 RX 0x7
      Supported interface modes:
               * IBSS
               * managed
               * AP
               * AP/VLAN
               * monitor
               * mesh point
               * P2P-client
               * P2P-GO
               * outside context of a BSS
      Band 1:
              Capabilities: 0x11ef
                      RX LDPC
                      HT20/HT40
                      SM Power Save disabled
                      RX HT20 SGI
                      RX HT40 SGI
                      TX STBC
                      RX STBC 1-stream
                      Max AMSDU length: 3839 bytes
                      DSSS/CCK HT40
              Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
              Minimum RX AMPDU time spacing: 8 usec (0x06)
              HT TX/RX MCS rate indexes supported: 0-23
              Frequencies:
                      * 2412 MHz [1] (25.0 dBm)
                      * 2417 MHz [2] (25.0 dBm)
                      * 2422 MHz [3] (25.0 dBm)
                      * 2427 MHz [4] (25.0 dBm)
                      * 2432 MHz [5] (25.0 dBm)
                      * 2437 MHz [6] (25.0 dBm)
                      * 2442 MHz [7] (25.0 dBm)
                      * 2447 MHz [8] (25.0 dBm)
                      * 2452 MHz [9] (25.0 dBm)
                      * 2457 MHz [10] (25.0 dBm)
                      * 2462 MHz [11] (25.0 dBm)
                      * 2467 MHz [12] (disabled)
                      * 2472 MHz [13] (disabled)
                      * 2484 MHz [14] (disabled)
      valid interface combinations:
               * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1, #{ IBSS } <= 1,
                 total <= 2048, #channels <= 1, STA/AP BI must match, radar detect widths: { 20 MHz (no HT), 20 MHz, 40 MHz }

      HT Capability overrides:
               * MCS: ff ff ff ff ff ff ff ff ff ff
               * maximum A-MSDU length
               * supported channel width
               * short GI for 40 MHz
               * max A-MPDU length exponent
               * min MPDU start spacing
      max # scan plans: 1
      max scan plan interval: -1
      max scan plan iterations: 0
      Supported extended features:
              * [ RRM ]: RRM
              * [ FILS_STA ]: STA FILS (Fast Initial Link Setup)
              * [ CQM_RSSI_LIST ]: multiple CQM_RSSI_THOLD records
              * [ CONTROL_PORT_OVER_NL80211 ]: control port over nl80211
              * [ TXQS ]: FQ-CoDel-enabled intermediate TXQs
              * [ SCAN_RANDOM_SN ]: use random sequence numbers in scans
              * [ SCAN_MIN_PREQ_CONTENT ]: use probe request with only rate IEs in scans
              * [ CAN_REPLACE_PTK0 ]: can safely replace PTK 0 when rekeying
              * [ AIRTIME_FAIRNESS ]: airtime fairness scheduling
              * [ CONTROL_PORT_NO_PREAUTH ]: disable pre-auth over nl80211 control port support
              * [ DEL_IBSS_STA ]: deletion of IBSS station support
              * [ MULTICAST_REGISTRATIONS ]: mgmt frame registration for multicast
              * [ SCAN_FREQ_KHZ ]: scan on kHz frequency support
              * [ CONTROL_PORT_OVER_NL80211_TX_STATUS ]: tx status for nl80211 control port support

logread excerpt from booting with this patch

Wed Mar 22 15:28:10 2023 kern.warn kernel: [   15.386677] ifx_pcie_bios_map_irq port 0 dev 0000:01:00.0 slot 0 pin 1
Wed Mar 22 15:28:10 2023 kern.warn kernel: [   15.391990] ifx_pcie_bios_map_irq dev 0000:01:00.0 irq 144 assigned
Wed Mar 22 15:28:10 2023 kern.info kernel: [   15.398165] ath9k 0000:01:00.0: enabling device (0000 -> 0002)
Wed Mar 22 15:28:10 2023 kern.warn kernel: [   15.404630] ath9k 0000:01:00.0: Direct firmware load for ath9k-eeprom-pci-0000:01:00.0.bin failed with error -2
Wed Mar 22 15:28:10 2023 kern.warn kernel: [   15.414168] ath9k 0000:01:00.0: Falling back to sysfs fallback for: ath9k-eeprom-pci-0000:01:00.0.bin
Wed Mar 22 15:28:10 2023 kern.debug kernel: [   21.139726] ath: EEPROM regdomain: 0x0
Wed Mar 22 15:28:10 2023 kern.debug kernel: [   21.139753] ath: EEPROM indicates default country code should be used
Wed Mar 22 15:28:10 2023 kern.debug kernel: [   21.139764] ath: doing EEPROM country->regdmn map search
Wed Mar 22 15:28:10 2023 kern.debug kernel: [   21.139800] ath: country maps to regdmn code: 0x3a
Wed Mar 22 15:28:10 2023 kern.debug kernel: [   21.139814] ath: Country alpha2 being used: US
Wed Mar 22 15:28:10 2023 kern.debug kernel: [   21.139827] ath: Regpair used: 0x3a
Wed Mar 22 15:28:10 2023 kern.debug kernel: [   21.153345] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
Wed Mar 22 15:28:10 2023 kern.info kernel: [   21.158178] ieee80211 phy0: Atheros AR9300 Rev:3 mem=0xbc000000, irq=144

@grische noticed that the extracted wifi calibration data (ath9k-eeprom)
is incorrect.
Symptoms included:
- wrong mac address
- radio was detected like dbdc (2.4GHz and 5GHz support at the same time)

This patch fixes this by also reversing the order of bytes and throwing
away the last 4 Bytes.
Unlike caldata.sh the fritz_cal_extract.c doesn't support reversing.
So this patch combines both methods.

Signed-off-by: Felix Baumann <felix.bau@gmx.de>
@Djfe
Copy link
Contributor Author

Djfe commented Mar 22, 2023

Hopefully not related to this commit:
I noticed, that sometimes disabling wifi in LuCI triggers a state, where neither wifi down, nor wifi up will work anymore

Wed Mar 22 18:34:23 2023 kern.info kernel: [  273.898623] device phy0-ap0 left promiscuous mode
Wed Mar 22 18:34:23 2023 kern.info kernel: [  273.902271] br-lan: port 5(phy0-ap0) entered disabled state
Wed Mar 22 18:34:23 2023 daemon.notice netifd: radio0 (4861): WARNING: Variable 'data' does not exist or is not an array/object
Wed Mar 22 18:34:23 2023 daemon.notice netifd: radio0 (4861): Bug: PHY is undefined for device 'radio0'
Wed Mar 22 18:34:23 2023 daemon.notice netifd: Wireless device 'radio0' is now down
root@OpenWrt:~# wifi up
'radio0' is disabled
'radio0' is disabled
root@OpenWrt:~# wifi down
'radio0' is disabled

I reported something similar earlier, but that was on target MT7621 and wifi up/wifi down weren't affected. #11725
A reboot fixes this issue.
And I am able to enable/disable wifi most of the time (with LuCI as well as wifi down&wifi up)
It just sometimes enters this state it seems.

@Djfe
Copy link
Contributor Author

Djfe commented Mar 22, 2023

Ok did some further testing, my patch also works on Release 22. It would be nice to see this backported.

and the bug described above happens regardless of my patch.

Unlike #11725 this bug also exists in Release 22 and not just in master.
The workaround I found is: enable and disable WiFi again in LuCI instead of trying to disable it a second time with wifi down via ssh, after the first time disabling it in LuCI has failed.
After that enabling/disabling in LuCI works just fine.
Maybe the bug only happens once per system reboot or so, running wifi down when disabling in LuCI fails, seems to make it worse and I needed to reboot.
This bug doesn't seem to impact wifi overall and a reboot fixes it. And again: not related to this patch (phew)

logread from bug in release:

root@OpenWrt:~# logread -f
Wed Mar 22 15:31:06 2023 user.info : luci: accepted login on /admin/network/wireless for root from 192.168.1.211
Wed Mar 22 15:31:32 2023 daemon.info dnsmasq[1]: read /etc/hosts - 4 addresses
Wed Mar 22 15:31:32 2023 daemon.info dnsmasq[1]: read /tmp/hosts/dhcp.cfg01411c - 2 addresses
Wed Mar 22 15:31:32 2023 daemon.info dnsmasq[1]: read /tmp/hosts/odhcpd - 1 addresses
Wed Mar 22 15:31:32 2023 daemon.info dnsmasq-dhcp[1]: read /etc/ethers - 0 addresses
Wed Mar 22 15:31:40 2023 kern.debug kernel: [  149.031052] ath: EEPROM regdomain: 0x8114
Wed Mar 22 15:31:40 2023 kern.debug kernel: [  149.031090] ath: EEPROM indicates we should expect a country code
Wed Mar 22 15:31:40 2023 kern.debug kernel: [  149.031107] ath: doing EEPROM country->regdmn map search
Wed Mar 22 15:31:40 2023 kern.debug kernel: [  149.031123] ath: country maps to regdmn code: 0x37
Wed Mar 22 15:31:40 2023 kern.debug kernel: [  149.031144] ath: Country alpha2 being used: DE
Wed Mar 22 15:31:40 2023 kern.debug kernel: [  149.031161] ath: Regpair used: 0x37
Wed Mar 22 15:31:40 2023 kern.debug kernel: [  149.031184] ath: regdomain 0x8114 dynamically updated by user
Wed Mar 22 15:31:42 2023 daemon.notice hostapd: Configuration file: /var/run/hostapd-phy0.conf (phy wlan0) --> new PHY
Wed Mar 22 15:31:42 2023 kern.info kernel: [  150.998732] br-lan: port 5(wlan0) entered blocking state
Wed Mar 22 15:31:42 2023 kern.info kernel: [  151.002655] br-lan: port 5(wlan0) entered disabled state
Wed Mar 22 15:31:42 2023 kern.info kernel: [  151.008871] device wlan0 entered promiscuous mode
Wed Mar 22 15:31:42 2023 daemon.notice hostapd: wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
Wed Mar 22 15:31:42 2023 daemon.notice hostapd: ACS: Automatic channel selection started, this may take a bit
Wed Mar 22 15:31:42 2023 daemon.notice hostapd: wlan0: interface state COUNTRY_UPDATE->ACS
Wed Mar 22 15:31:42 2023 daemon.notice hostapd: wlan0: ACS-STARTED
Wed Mar 22 15:31:44 2023 daemon.notice netifd: Wireless device 'radio0' is now up
Wed Mar 22 15:31:44 2023 daemon.info dnsmasq[1]: read /etc/hosts - 4 addresses
Wed Mar 22 15:31:44 2023 daemon.info dnsmasq[1]: read /tmp/hosts/dhcp.cfg01411c - 2 addresses
Wed Mar 22 15:31:44 2023 daemon.info dnsmasq[1]: read /tmp/hosts/odhcpd - 1 addresses
Wed Mar 22 15:31:44 2023 daemon.info dnsmasq-dhcp[1]: read /etc/ethers - 0 addresses
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: ACS: Survey is missing noise floor
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: ACS: Survey is missing noise floor
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: ACS: Survey is missing noise floor
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: ACS: Survey is missing noise floor
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: ACS: Survey is missing noise floor
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: ACS: Survey is missing noise floor
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: wlan0: ACS-COMPLETED freq=2472 channel=13
Wed Mar 22 15:31:50 2023 kern.info kernel: [  159.262321] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Wed Mar 22 15:31:50 2023 kern.info kernel: [  159.267838] br-lan: port 5(wlan0) entered blocking state
Wed Mar 22 15:31:50 2023 kern.info kernel: [  159.272587] br-lan: port 5(wlan0) entered forwarding state
Wed Mar 22 15:31:50 2023 daemon.notice netifd: Network device 'wlan0' link is up
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: wlan0: interface state ACS->ENABLED
Wed Mar 22 15:31:50 2023 daemon.notice hostapd: wlan0: AP-ENABLED
Wed Mar 22 15:31:51 2023 kern.info kernel: [  159.626319] device wlan0 left promiscuous mode
Wed Mar 22 15:31:51 2023 kern.info kernel: [  159.629819] br-lan: port 5(wlan0) entered disabled state
Wed Mar 22 15:31:51 2023 daemon.notice netifd: radio0 (3592): WARNING: Variable 'data' does not exist or is not an array/object
Wed Mar 22 15:31:51 2023 daemon.notice netifd: radio0 (3592): Bug: PHY is undefined for device 'radio0'
Wed Mar 22 15:31:51 2023 daemon.notice netifd: Wireless device 'radio0' is now down
Wed Mar 22 15:31:55 2023 daemon.info dnsmasq[1]: read /etc/hosts - 4 addresses
Wed Mar 22 15:31:55 2023 daemon.info dnsmasq[1]: read /tmp/hosts/dhcp.cfg01411c - 2 addresses
Wed Mar 22 15:31:55 2023 daemon.info dnsmasq[1]: read /tmp/hosts/odhcpd - 1 addresses
Wed Mar 22 15:31:55 2023 daemon.info dnsmasq-dhcp[1]: read /etc/ethers - 0 addresses

it may say Wireless device 'radio0' is now down but it isn't. The wifi led stays lit and the device keeps on broadcasting the ssid.

@github-actions github-actions bot added the target/lantiq pull request/issue for lantiq target label Mar 23, 2023
@hauke
Copy link
Member

hauke commented Mar 26, 2023

I would prefer if you add a swap functionality to the fritz_cal_extract tool.

@Djfe
Copy link
Contributor Author

Djfe commented Mar 29, 2023

ok, I will try my best. I won't make any guarantees that I won't cause memory leaks. So please check my code thoroughly.
Can we get this patch into OpenWRT 22 as a backport? Maybe even as the shell code that it is now in the upcoming 22 release? (I'm not sure how long it takes me to come up with new c code, but I'll try)

@Djfe
Copy link
Contributor Author

Djfe commented Mar 29, 2023

The zlib implementation is streaming from mtd/stdin to the output in chunks of 1kB.
The two ways to modify this script I know of:

  • Create a dynamic array and then reverse it before writing. (There is no finite size atm. and the limit argument is optional)
  • Let zlib work like it used to and read the finished file afterwards, reverse it and write a second time to flash. (advantage: we can get the actual filesize)

What is the preferred approach? Do you know of a better one?

@Djfe Djfe changed the title lantiq: fix ath9k-eeprom for AVM Fritz!Box 7340 lantiq: fix ath9k-eeprom for AVM Fritz!Box 7430 May 9, 2023
@Djfe
Copy link
Contributor Author

Djfe commented Jun 27, 2023

@doesnotcompete I know it's been a while, but you can compile openwrt with my patch to get the FB7430 working :) (for now)
#9051
I won't have time to rework my fix into the fritz_cal_extract tool before Sept 10th sadly, so the fix won't find it's way into a release until then.

@Snowiiii
Copy link

Snowiiii commented Feb 2, 2024

Hey @Djfe im using openwrt with an Fritz!Box 7430 i wonder if you would help me to fix the bad Internet Performance on it
image
This is on ethernet...
We pay for 50Mbit/s down and 10Mbit/s up and before openwrt i had what i paid for but for some reason something is wrong with openwrt, I searched the Internet they recommend enabling SQM but that dosn't helped, So what i found that people said that its an upstream issue. Maybe you can help ?

@Djfe
Copy link
Contributor Author

Djfe commented Feb 3, 2024

Please open a separate issue and @ me there, thank you.

And please describe us which modem you are using.
and also: which device does the DSL login (PPPoE)?
Is your connection Dual Stack or Dual Stack Lite? (unless you don't know)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target/lantiq pull request/issue for lantiq target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants