nerves-networking / vintage_net_wifi

WiFi networking for VintageNet
Apache License 2.0
32 stars 18 forks source link

Unable to connect or scan for wireless access points on a RPi3 #103

Closed tclev closed 2 years ago

tclev commented 2 years ago

Describe the bug When either scanning for networks or trying to connect to a wireless network VintageNet throws an error and does not connect to the AP.

To Reproduce Steps to reproduce the behavior:

  1. From iex run log_attach
  2. Next run VintageNet.scan("wlan0")
  3. An error will be thrown with a stack trace:
17:17:43.466 [info]  WPASupplicant ignoring {:event, "WPS-AP-AVAILABLE"}

17:17:43.466 [info]  WPASupplicant ignoring {:event, "CTRL-EVENT-NETWORK-NOT-FOUND"}

17:17:43.481 [error] GenServer {VintageNet.Interface.Registry, {VintageNetWiFi.WPASupplicant, "wlan0"}} terminating
** (FunctionClauseError) no function clause matching in VintageNetWiFi.WPASupplicant.add_access_point/2
    (vintage_net_wifi 0.10.6) lib/vintage_net_wifi/wpa_supplicant.ex:481: VintageNetWiFi.WPASupplicant.add_access_point(%{access_points: %{"84:e3:42:81:b6:8a" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "84:e3:42:81:b6:8a", channel: 5, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2432, signal_dbm: -36, signal_percent: 92, ssid: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>}, "f8:bb:bf:0a:f7:86" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:86", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias"}, "f8:bb:bf:0a:f7:8f" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:8f", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias Guest"}, "f8:bb:bf:89:5f:c3" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:89:5f:c3", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -49, signal_percent: 80, ssid: "Alias"}, "f8:bb:bf:89:5f:c9" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:89:5f:c9", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -49, signal_percent: 80, ssid: "Alias Guest"}}, ap_mode: false, bssid_requester: #PID<0.1183.0>, clients: [], control_dir: "/tmp/vintage_net/wpa_supplicant", current_ap: nil, eap_status: %VintageNet.Interface.EAPStatus{method: nil, remote_certificate_verified?: false, status: nil, timestamp: nil}, ifname: "wlan0", keep_alive_interval: 60000, ll: #PID<0.1182.0>, peers: [], verbose: false, wpa_supplicant: "wpa_supplicant", wpa_supplicant_conf_path: "/tmp/vintage_net/wpa_supplicant.conf.wlan0"}, %VintageNetWiFi.MeshPeer{active_path_selection_metric_id: 1, active_path_selection_protocol_id: 1, age: 0, authentication_protocol_id: 1, band: :wifi_2_4_ghz, beacon_int: 100, bss_basic_rate_set: "10 20 55 110 60 120 240", bssid: "f8:bb:bf:89:5f:c1", capabilities: 16, channel: 1, congestion_control_mode_id: 0, est_throughput: 65000, flags: [:rsn, :sae, :ccmp, :mesh], frequency: 2412, id: 5, mesh_capability: %VintageNetWiFi.MeshPeer.Capabilities{accepting_peerings: true, forwarding: true, mbca_enabled: false, mcca_enabled: false, mcca_supported: false, power_slave_level: false, tbtt_adjusting: true}, mesh_formation_info: %VintageNetWiFi.MeshPeer.FormationInformation{connected_to_as: false, connected_to_mesh_gate: false, number_of_peerings: 2}, mesh_id: "4e044", noise_dbm: -89, quality: 0, signal_dbm: -50, signal_percent: 79, snr: 39, ssid: "4e044", synchronization_method_id: 1})
    (vintage_net_wifi 0.10.6) lib/vintage_net_wifi/wpa_supplicant.ex:198: VintageNetWiFi.WPASupplicant.handle_info/2
    (stdlib 3.17) gen_server.erl:695: :gen_server.try_dispatch/4
    (stdlib 3.17) gen_server.erl:771: :gen_server.handle_msg/6
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: {:bssid_result, %VintageNetWiFi.MeshPeer{active_path_selection_metric_id: 1, active_path_selection_protocol_id: 1, age: 0, authentication_protocol_id: 1, band: :wifi_2_4_ghz, beacon_int: 100, bss_basic_rate_set: "10 20 55 110 60 120 240", bssid: "f8:bb:bf:89:5f:c1", capabilities: 16, channel: 1, congestion_control_mode_id: 0, est_throughput: 65000, flags: [:rsn, :sae, :ccmp, :mesh], frequency: 2412, id: 5, mesh_capability: %VintageNetWiFi.MeshPeer.Capabilities{accepting_peerings: true, forwarding: true, mbca_enabled: false, mcca_enabled: false, mcca_supported: false, power_slave_level: false, tbtt_adjusting: true}, mesh_formation_info: %VintageNetWiFi.MeshPeer.FormationInformation{connected_to_as: false, connected_to_mesh_gate: false, number_of_peerings: 2}, mesh_id: "4e044", noise_dbm: -89, quality: 0, signal_dbm: -50, signal_percent: 79, snr: 39, ssid: "4e044", synchronization_method_id: 1}, #Function<4.102249467/2 in VintageNetWiFi.WPASupplicant."-fun.add_access_point/2-">}
State: %{access_points: %{"84:e3:42:81:b6:8a" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "84:e3:42:81:b6:8a", channel: 5, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2432, signal_dbm: -36, signal_percent: 92, ssid: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>}, "f8:bb:bf:0a:f7:86" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:86", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias"}, "f8:bb:bf:0a:f7:8f" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:8f", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias Guest"}, "f8:bb:bf:89:5f:c3" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:89:5f:c3", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -49, signal_percent: 80, ssid: "Alias"}, "f8:bb:bf:89:5f:c9" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:89:5f:c9", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -49, signal_percent: 80, ssid: "Alias Guest"}}, ap_mode: false, bssid_requester: #PID<0.1183.0>, clients: [], control_dir: "/tmp/vintage_net/wpa_supplicant", current_ap: nil, eap_status: %VintageNet.Interface.EAPStatus{method: nil, remote_certificate_verified?: false, status: nil, timestamp: nil}, ifname: "wlan0", keep_alive_interval: 60000, ll: #PID<0.1182.0>, peers: [], verbose: false, wpa_supplicant: "wpa_supplicant", wpa_supplicant_conf_path: "/tmp/vintage_net/wpa_supplicant.conf.wlan0"}

17:17:44.525 [debug] wpa_supplicant: Successfully initialized wpa_supplicant

Expected behavior It should connect to the AP, or in the case of scan return available APs (or at least not throw an error).

VintageNet Info

Output of VintageNet.info (please hide any sensitive information like WiFi PSKs)

iex(5)> VintageNet.info
VintageNet 0.11.4

All interfaces:       ["eth0", "lo", "wlan0"]
Available interfaces: ["eth0"]

Interface eth0
  Type: VintageNetEthernet
  Present: true
  State: :configured (0:45:37)
  Connection: :internet (0:45:33)
  Addresses: 2601:40f:600:bd8:ba27:ebff:fe87:b3ae/64, fd3f:84fb:b5aa:1:ba27:ebff:fe87:b3ae/64, 192.168.7.176/24, fe80::ba27:ebff:fe87:b3ae/64
  Configuration:
    %{ipv4: %{method: :dhcp}, type: VintageNetEthernet}

Interface usb0
  Type: VintageNetDirect
  Present: false
  Configuration:
    %{type: VintageNetDirect}

Interface wlan0
  Type: VintageNetWiFi
  Present: true
  State: :configured (0:45:35)
  Connection: :disconnected (0:45:37)
  Configuration:
    %{
      ipv4: %{method: :disabled},
      type: VintageNetWiFi,
      vintage_net_wifi: %{networks: []}
    }

:ok

Environment

|nerves_bootstrap| Loadpaths Start

Nerves environment MIX_TARGET: rpi3 MIX_ENV: dev

|nerves_bootstrap| Environment Variable List target: rpi3 toolchain: /home/tclev/.nerves/artifacts/nerves_toolchain_armv7_nerves_linux_gnueabihf-linux_x86_64-1.5.0 system: /home/tclev/.nerves/artifacts/nerves_system_rpi3-portable-1.18.1 app: .

|nerves_bootstrap| Loadpaths End


**Additional context**
I am running a wireless camera system which seems to be the AP with the null bytes. I've tried unplugging the device, but I still get the errors. The null AP doesn't show in the list. Here is the new error.

iex(2)> VintageNet.scan("wlan0") :ok

17:40:28.009 [info] WPASupplicant ignoring {:event, "WPS-AP-AVAILABLE"}

17:40:28.009 [info] WPASupplicant ignoring {:event, "CTRL-EVENT-NETWORK-NOT-FOUND"}

17:40:28.017 [error] GenServer {VintageNet.Interface.Registry, {VintageNetWiFi.WPASupplicant, "wlan0"}} terminating ** (FunctionClauseError) no function clause matching in VintageNetWiFi.WPASupplicant.add_access_point/2 (vintage_net_wifi 0.10.6) lib/vintage_net_wifi/wpa_supplicant.ex:481: VintageNetWiFi.WPASupplicant.add_access_point(%{access_points: %{"f8:bb:bf:0a:f7:86" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:86", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias"}, "f8:bb:bf:0a:f7:8f" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:8f", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias Guest"}}, ap_mode: false, bssid_requester: #PID<0.1171.0>, clients: [], control_dir: "/tmp/vintage_net/wpa_supplicant", current_ap: nil, eap_status: %VintageNet.Interface.EAPStatus{method: nil, remote_certificate_verified?: false, status: nil, timestamp: nil}, ifname: "wlan0", keep_alive_interval: 60000, ll: #PID<0.1169.0>, peers: [], verbose: false, wpa_supplicant: "wpa_supplicant", wpa_supplicant_conf_path: "/tmp/vintage_net/wpa_supplicant.conf.wlan0"}, %VintageNetWiFi.MeshPeer{active_path_selection_metric_id: 1, active_path_selection_protocol_id: 1, age: 0, authentication_protocol_id: 1, band: :wifi_2_4_ghz, beacon_int: 100, bss_basic_rate_set: "10 20 55 110 60 120 240", bssid: "f8:bb:bf:0a:f7:83", capabilities: 16, channel: 1, congestion_control_mode_id: 0, est_throughput: 65000, flags: [:rsn, :sae, :ccmp, :mesh], frequency: 2412, id: 2, mesh_capability: %VintageNetWiFi.MeshPeer.Capabilities{accepting_peerings: true, forwarding: true, mbca_enabled: false, mcca_enabled: false, mcca_supported: false, power_slave_level: false, tbtt_adjusting: true}, mesh_formation_info: %VintageNetWiFi.MeshPeer.FormationInformation{connected_to_as: false, connected_to_mesh_gate: false, number_of_peerings: 2}, mesh_id: "4e044", noise_dbm: -89, quality: 0, signal_dbm: -34, signal_percent: 93, snr: 55, ssid: "4e044", synchronization_method_id: 1}) (vintage_net_wifi 0.10.6) lib/vintage_net_wifi/wpa_supplicant.ex:198: VintageNetWiFi.WPASupplicant.handle_info/2 (stdlib 3.17) gen_server.erl:695: :gen_server.try_dispatch/4 (stdlib 3.17) gen_server.erl:771: :gen_server.handle_msg/6 (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3 Last message: {:bssid_result, %VintageNetWiFi.MeshPeer{active_path_selection_metric_id: 1, active_path_selection_protocol_id: 1, age: 0, authentication_protocol_id: 1, band: :wifi_2_4_ghz, beacon_int: 100, bss_basic_rate_set: "10 20 55 110 60 120 240", bssid: "f8:bb:bf:0a:f7:83", capabilities: 16, channel: 1, congestion_control_mode_id: 0, est_throughput: 65000, flags: [:rsn, :sae, :ccmp, :mesh], frequency: 2412, id: 2, mesh_capability: %VintageNetWiFi.MeshPeer.Capabilities{accepting_peerings: true, forwarding: true, mbca_enabled: false, mcca_enabled: false, mcca_supported: false, power_slave_level: false, tbtt_adjusting: true}, mesh_formation_info: %VintageNetWiFi.MeshPeer.FormationInformation{connected_to_as: false, connected_to_mesh_gate: false, number_of_peerings: 2}, mesh_id: "4e044", noise_dbm: -89, quality: 0, signal_dbm: -34, signal_percent: 93, snr: 55, ssid: "4e044", synchronization_method_id: 1}, #Function<4.102249467/2 in VintageNetWiFi.WPASupplicant."-fun.add_access_point/2-">} State: %{access_points: %{"f8:bb:bf:0a:f7:86" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:86", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias"}, "f8:bb:bf:0a:f7:8f" => %VintageNetWiFi.AccessPoint{band: :wifi_2_4_ghz, bssid: "f8:bb:bf:0a:f7:8f", channel: 1, flags: [:wpa2_psk_ccmp, :wpa2, :psk, :ccmp, :ess], frequency: 2412, signal_dbm: -33, signal_percent: 94, ssid: "Alias Guest"}}, ap_mode: false, bssid_requester: #PID<0.1171.0>, clients: [], control_dir: "/tmp/vintage_net/wpa_supplicant", current_ap: nil, eap_status: %VintageNet.Interface.EAPStatus{method: nil, remote_certificate_verified?: false, status: nil, timestamp: nil}, ifname: "wlan0", keep_alive_interval: 60000, ll: #PID<0.1169.0>, peers: [], verbose: false, wpa_supplicant: "wpa_supplicant", wpa_supplicant_conf_path: "/tmp/vintage_net/wpa_supplicant.conf.wlan0"}

17:40:29.052 [debug] wpa_supplicant: Successfully initialized wpa_supplicant

17:40:31.268 [info] cam1-reg: disabling

17:40:31.269 [info] cam-dummy-reg: disabling



Let me know if I can provide any other information.
jsimmonds2 commented 2 years ago

Was about to report the same crash. In my case the AP setup is called in Farmbot OS to run their Configurator.

In my environment it was an eero mesh router pair that triggered the crash . . for whatever reason these routers broadcast their mesh peer capability on a 'hidden' network ( though it has some hex SSID string matching the mesh_id ).

@tclev, I notice you also have a eero MAC in your last message :)

tclev commented 2 years ago

I do also have an Eero mesh system. So it may also be that. Would be wonderful if it was just this fix. 😀

fhunleth commented 2 years ago

@tclev @jsimmonds2 These are great hints. Thank you!

fhunleth commented 2 years ago

I was able to reproduce the reported stack traces via a unit test. It looked like the best fix for now was to ignore the special mesh network in the access point results. I don't think it would be possible to connect anyway.

It's getting late here, so I'm going to let the fix sit until tomorrow. I have one other bug with vintage_net_wifi that I want to investigate tomorrow. Hopefully I get a fix for it in, but if not, I'll push out a release anyway for both of you. Thanks again for the detailed report. It made it pretty easy to see what was happening.

tclev commented 2 years ago

I grabbed your latest branch and I'm now able to connect to the internet via wifi!

fhunleth commented 2 years ago

Awesome!!! Thanks for letting me know that it worked. I got distracted at work, but will merge now. And with confidence thanks to your report. :)