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

panic when reading wifi scan results with unkown? auth mode #333

Closed
empirephoenix opened this issue Dec 21, 2023 · 8 comments
Closed

panic when reading wifi scan results with unkown? auth mode #333

empirephoenix opened this issue Dec 21, 2023 · 8 comments

Comments

@empirephoenix
Copy link
Contributor

When running the following snipped:

        for i in 1..11 {
            println!("Scanning channel {}", i);
            self.wifi_driver.start_scan(&ScanConfig{
                scan_type : ScanType::Passive(Duration::from_secs(1)),
                show_hidden: false,
                channel: Some(i),
                ..Default::default()
            }, true)?;
            let sr = self.wifi_driver.get_scan_result()?;
            for r in sr.iter(){
                println!("Found wifi {}", r.ssid);
            }
        }

I get the following output and panic:

Scanning channel 1
I (1336) esp_netif_lwip: DHCP server started on interface WIFI_AP_DEF with IP: 192.168.71.1
Found wifi FRITZ!Box 7590 WO
Scanning channel 2
Found wifi IB-JMD
Scanning channel 3
Scanning channel 4
Found wifi TP-Link_4A34
Scanning channel 5
Found wifi HUAWEI_H122_F5C8
Scanning channel 6
thread 'main' panicked at /home/empire/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-svc-0.47.3/src/wifi.rs:156:18:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is caused by this panic:

impl From<Newtype<wifi_auth_mode_t>> for AuthMethod {
    #[allow(non_upper_case_globals)]
    fn from(mode: Newtype<wifi_auth_mode_t>) -> Self {
        match mode.0 {
            [...] a bunch of other auth modes shortened
            wifi_auth_mode_t_WIFI_AUTH_WAPI_PSK => AuthMethod::WAPIPersonal,
            _ => panic!(),
        }
    }
}

A) Should this missing auth method be addded here?
B) If possible I would like to see a AuthMethod::Invalid or similar for these cases, as crashing a running application during a scan is something I would not expect to happen, after all crashing random devices with a wifi killer device is not something that I want.

I'm not really proficient with Rust, but I can try to do a pull request, especially for the B) case.

I have checked all ap's my laptop can find via "iwlist wlan0 scan" on channel 6, especially Cell 10 seems to be noteworthy for me due to it returning: Authentication Suites (1) : unknown (18) which kinda fits.

wlan0     Scan completed :
          Cell 02 - Address: 80:2A:A8:14:E1:AF
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=69/70  Signal level=-41 dBm  
                    Encryption key:on
                    ESSID:"C3MA"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=000000267edb2828
                    Extra: Last beacon: 6274ms ago
                    IE: Unknown: 000443334D41
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030106
                    IE: Unknown: 0706444520010D14
                    IE: Unknown: 2A0102
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: 32043048606C
                    IE: Unknown: 0B050A004F127A
                    IE: Unknown: 460573D000000C
                    IE: Unknown: 2D1AAC011BFFFFFF0000000000000000000100000000000000000000
                    IE: Unknown: 3D1606000500000000000000000000000000000000000000
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F080500000200000040
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
                    IE: Unknown: DD0900037F01010000FF7F
                    IE: Unknown: DD1300156D00010140010237E58106802AA813E1AF
                    IE: Unknown: DD168CFDF00400004900000302097201000000003F000000
                    IE: Unknown: DD088CFDF00101020100
          Cell 03 - Address: A2:20:A6:16:86:8A
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=49/70  Signal level=-61 dBm  
                    Encryption key:on
                    ESSID:"frama-ampel"
                    Bit Rates:5.5 Mb/s; 11 Mb/s; 1 Mb/s; 2 Mb/s; 6 Mb/s
                              12 Mb/s; 24 Mb/s; 48 Mb/s
                    Bit Rates:54 Mb/s; 9 Mb/s; 18 Mb/s; 36 Mb/s
                    Mode:Master
                    Extra:tsf=000000039d72b2be
                    Extra: Last beacon: 6317ms ago
                    IE: Unknown: 000B6672616D612D616D70656C
                    IE: Unknown: 01088B9682840C183060
                    IE: Unknown: 030106
                    IE: Unknown: 32046C122448
                    IE: Unknown: DD0918FE34030100000000
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
                    IE: WPA Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : PSK
          Cell 07 - Address: D6:F1:51:20:70:38
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-37 dBm  
                    Encryption key:off
                    ESSID:"freifunk-rhein-neckar.de"
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
                              36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000006a270df86d
                    Extra: Last beacon: 6540ms ago
                    IE: Unknown: 00186672656966756E6B2D726865696E2D6E65636B61722E6465
                    IE: Unknown: 01088C129824B048606C
                    IE: Unknown: 030106
                    IE: Unknown: 0706444520010D14
                    IE: Unknown: 2A0100
                    IE: Unknown: 0B0501001D0000
                    IE: Unknown: 46057300000000
                    IE: Unknown: 3B025100
                    IE: Unknown: 2D1AED111BFFFF000000000000000000000100000000000000000000
                    IE: Unknown: 3D1606001500000000000000000000000000000000000000
                    IE: Unknown: 7F080400080201000140
                    IE: Unknown: DD180050F2020101810003A4000027A4000042435E0062322F00
          Cell 08 - Address: A0:E4:CB:04:6A:BE
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=45/70  Signal level=-65 dBm  
                    Encryption key:on
                    ESSID:"Speedlink-291"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
                              18 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 12 Mb/s; 24 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=0000010c84c8caa3
                    Extra: Last beacon: 6524ms ago
                    IE: Unknown: 000D53706565646C696E6B2D323931
                    IE: Unknown: 010882848B961224486C
                    IE: Unknown: 030106
                    IE: Unknown: 2A0104
                    IE: Unknown: 32040C183060
                    IE: Unknown: 2D1A6E1017FFFF0000010000000000000000000000000C0000000000
                    IE: Unknown: 3D1606000100000000000000000000000000000000000000
                    IE: Unknown: 3E0100
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
                    IE: Unknown: 0B05000025127A
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F0101
                    IE: Unknown: DD07000C4304000000
                    IE: Unknown: 0706444520010D10
                    IE: Unknown: DDBE0050F204104A0001101044000102103B000103104700102880288028801880A880A0E4CB046ABE1021001F5370686169726F6E20476D6248202861205A7958454C20436F6D70616E79291023001D5370686169726F6E20435045207769746820574C414E2D52543533393210240006534C353530311042000D533135343130343030333239311054000800060050F2040001101100135370686169726F6E204941442F526F7574657210080002210C103C0001011049000600372A000120
          Cell 10 - Address: D6:F1:51:20:70:3A
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-37 dBm  
                    Encryption key:on
                    ESSID:"owe.freifunk-rhein-neckar.de"
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
                              36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000006a0c4d76e1
                    Extra: Last beacon: 6524ms ago
                    IE: Unknown: 001C6F77652E6672656966756E6B2D726865696E2D6E65636B61722E6465
                    IE: Unknown: 01088C129824B048606C
                    IE: Unknown: 030106
                    IE: Unknown: 0706444520010D14
                    IE: Unknown: 2A0100
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : unknown (18)
                    IE: Unknown: 0B050000280000
                    IE: Unknown: 46057300000000
                    IE: Unknown: 3B025100
                    IE: Unknown: 2D1AED111BFFFF000000000000000000000100000000000000000000
                    IE: Unknown: 3D1606001500000000000000000000000000000000000000
                    IE: Unknown: 7F080400080201000140
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
          Cell 12 - Address: 86:2A:A8:14:E1:AF
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-40 dBm  
                    Encryption key:on
                    ESSID:""
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
                              36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=000000267ed8ab69
                    Extra: Last beacon: 6480ms ago
                    IE: Unknown: 0000
                    IE: Unknown: 01088C129824B048606C
                    IE: Unknown: 030106
                    IE: Unknown: 050400030000
                    IE: Unknown: 0706444520010D14
                    IE: Unknown: 2A0102
                    IE: Unknown: 0B0500004F127A
                    IE: Unknown: 2D1AAC011BFFFFFF0000000000000000000100000000000000000000
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: 3D1606000500000000000000000000000000000000000000
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F080500080200000040
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
                    IE: Unknown: DD0900037F01010000FF7F
                    IE: Unknown: DD088CFDF00101020100
                    IE: Unknown: DD168CFDF00400004900000302097201000000003F000000
                    IE: Unknown: DD1900156D00010128010237E58106802AA813E1AF820100870100
          Cell 13 - Address: D6:F1:51:20:70:39
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=70/70  Signal level=-37 dBm  
                    Encryption key:off
                    ESSID:""
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    ESSID:"ffrn-mesh"
                    Extra:Mesh Network Path Selection Protocol ID: 0x01
                    Extra:Path Selection Metric ID: 0x01
                    Extra:Congestion Control Mode ID: 0x00
                    Extra:Synchronization ID: 0x01
                    Extra:Authentication ID: 0x00
                    Extra:Formation Info: 0x00
                    Extra:Capabilities: 0x01
                    Mode:Unknown/bug
                    Extra:tsf=0000006a270e1180
                    Extra: Last beacon: 6514ms ago
                    IE: Unknown: 0000
                    IE: Unknown: 010882040B160C121824
                    IE: Unknown: 030106
                    IE: Unknown: 050401020000
                    IE: Unknown: 32043048606C
                    IE: Unknown: 2D1AEF111BFFFF000000000000000000000100000000000000000000
                    IE: Unknown: 3D16060003000000FFFF0000000000000000000000000000
                    IE: Unknown: 72096666726E2D6D657368
                    IE: Unknown: 710701010001000001
          Cell 18 - Address: 42:2B:50:F6:E6:95
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=16/70  Signal level=-94 dBm  
                    Encryption key:off
                    ESSID:"Vodafone Hotspot"
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
                              36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=00000003be728ae8
                    Extra: Last beacon: 6507ms ago
                    IE: Unknown: 0010566F6461666F6E6520486F7473706F74
                    IE: Unknown: 01088C129824B048606C
                    IE: Unknown: 030106
                    IE: Unknown: 050400020000
                    IE: Unknown: 0706455520010D14
                    IE: Unknown: 2A0100
                    IE: Unknown: 3B025100
                    IE: Unknown: 2D1A2D0017FFFFFF00000000000000C2010100000000001004870100
                    IE: Unknown: 3D1606001700000000000000000000000000000000000000
                    IE: Unknown: 7F080500000200000040
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
          Cell 22 - Address: 00:CB:7A:B5:BA:78
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=14/70  Signal level=-96 dBm  
                    Encryption key:on
                    ESSID:"LAN Solo"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                              24 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=000004f37ea1cc1a
                    Extra: Last beacon: 6490ms ago
                    IE: Unknown: 00084C414E20536F6C6F
                    IE: Unknown: 010882848B962430486C
                    IE: Unknown: 030106
                    IE: Unknown: 050400010000
                    IE: Unknown: 23021200
                    IE: Unknown: 2A0104
                    IE: Unknown: 32040C121860
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: 0B050500AB0000
                    IE: Unknown: 46053000000000
                    IE: Unknown: 2D1AEF1117FFFFFFFF00000000000000000000000000000000000000
                    IE: Unknown: 3D16060F0000000000000000000000000000000000000000
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F0A05000880010000C00140
                    IE: Unknown: FF2023050008120010222002C00F438518000C00AAFFAAFF3B1CC7711CC7711CC771
                    IE: Unknown: FF072404000022FCFF
                    IE: Unknown: FF0E260000A40820A408404308603208
                    IE: Unknown: DD1D0050F204104A0001101044000102103C0001031049000600372A000120
                    IE: Unknown: DD1F00904C0418BF0CB1698B0FAAFF0000AAFF0000C0050004000000C303012727
                    IE: Unknown: DD0A0010180205001C000001
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
                    IE: Unknown: 6C027F00
          Cell 27 - Address: 40:2B:50:F6:E6:85
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=15/70  Signal level=-95 dBm  
                    Encryption key:on
                    ESSID:"Vodafone-151D"
                    Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
                              36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=00000003be7282bd
                    Extra: Last beacon: 6507ms ago
                    IE: Unknown: 000D566F6461666F6E652D31353144
                    IE: Unknown: 01088C129824B048606C
                    IE: Unknown: 030106
                    IE: Unknown: 050400020000
                    IE: Unknown: 0706455520010D14
                    IE: Unknown: 2A0100
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: 3B025100
                    IE: Unknown: 2D1A2D0017FFFFFF00000000000000C2010100000000001004870100
                    IE: Unknown: 3D1606001700000000000000000000000000000000000000
                    IE: Unknown: 7F080500080200000040
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
                    IE: Unknown: DD220050F204104A00011010440001021057000101103C0001031049000600372A000120


If there is anything additionally I can submit to help, or I should try to add a unknown enum type

@ivmarkov
Copy link
Collaborator

I think we should do the following:

  • Wrap this in an Option
  • Fix the Wifi code to return None. As in, change impl From<Newtype<wifi_auth_mode_t>> for AuthMethod { to
    impl From<Newtype<wifi_auth_mode_t>> for Option<AuthMethod> { and then where it currently says panic, return None
  • Extend the AuthMethod enum with additional authentication options, and then map them in the From impl. Here's a list of additional authentications recognized by the ESP IDF in the meantime: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_wifi.html

If you are willing to work on a PR, I can support with feedback/suggestions.

@ivmarkov
Copy link
Collaborator

... and thank you for the analysis!

@empirephoenix
Copy link
Contributor Author

empirephoenix commented Dec 21, 2023

Is there a good reason against adding a AuthMethod.Unknown instead and use this instead of the panic?
I kinda find it strange to get a Some(None) in case of a open wifi.
Also it would not cause less of an change for already existing code.
I will do a PR.

@Vollbrecht
Copy link
Collaborator

One thing to notice that between esp-idf v4.4.6 and v5.1.2 there are difference in the upstream defined types. Look the diff from here and here

@ivmarkov
Copy link
Collaborator

Is there a good reason against adding a AuthMethod.Unknown instead and use this instead of the panic? I kinda find it strange to get a Some(None) in case of a open wifi.

If the wifi is open, you'll get `Some(AuthMethod::None), not Option::None.

And then ask yourself the question what shall we do when you put AuthMethod::Unknown in a Configuration object? Hence why I prefer Option in the ap info struct.

@empirephoenix
Copy link
Contributor Author

Ah ok that makes sense, impossible to represent invalid invariant then

I think I want to do this in in multiple steps, first getting it to not crash and the new auth methods then after that.
https://github.com/esp-rs/esp-idf-svc/pull/335/files

Any ideas how to get rid of the now new unwraps? Or make the other From return Option as well, as it cannot be converted in case of a unknown auth method?

@empirephoenix
Copy link
Contributor Author

Ok, I think I have a acceptable version now, sadly I did not manage to understand where the wifi_auth_mode_t is mapped so I did not manage to add the ~3 additional auth methods mentioned in the documentation

@ivmarkov
Copy link
Collaborator

The suggested PR was merged, so let's close it.

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants