EliasKotlyar / Xiaomi-Dafang-Hacks

4.16k stars 1k forks source link

Can't connect to hidden wifi network after access point mode has started #1809

Open joshuahaertel opened 2 years ago

joshuahaertel commented 2 years ago

Description

My wifi network is hidden. I am able to successfully connect to it. Occasionally my access point restarts when there is a lot of network traffic. Most of my camera's reconnect without a problem. Often one of them will not reconnect though and the camera remains in AP mode.

What did you do to debug the issue

After looking at the code, it looks like that is because it passes a WPA station timeout and when the AP mode kicks in the polling works by checking for an SSID, which it will never find: https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/blob/f1cf7dad8b818cda9b64d4b139ae1398a63924e6/firmware_mod/scripts/wifi.sh#L175-L194

Looking at the iwlist command, it looks like one way to fix this might be to include the ssid in the scan call iwlist wlan0 scanning essid [hidden-network] https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/blob/f1cf7dad8b818cda9b64d4b139ae1398a63924e6/firmware_mod/scripts/wifi.sh#L172

Evidence

Wifi logs from /system/sdcard/log/wifi

04/10/22 18:42:37 Disconnected
04/10/22 18:42:37 Stopping wpa_action watchdog
04/10/22 18:42:37 Killing pid  (/var/run/wpa_action.pid)
04/10/22 18:42:37 Waiting pid  (/var/run/wpa_action.pid)
04/10/22 18:42:37 Removing pidfile /var/run/wpa_action.pid
04/10/22 18:42:37 Starting wpa_action watchdog
04/10/22 18:42:37 wpa_action watchdog sleeping 60 seconds
04/10/22 18:43:37 wpa_action watchdog switching to ap mode
04/10/22 18:43:37 Starting access point mode
04/10/22 18:43:37 Stopping station mode
04/10/22 18:43:37 Stopping wpa_action watchdog
04/10/22 18:43:37 Killing pid  (/var/run/wpa_action.pid)
04/10/22 18:43:37 Waiting pid  (/var/run/wpa_action.pid)
04/10/22 18:43:37 Removing pidfile /var/run/wpa_action.pid
04/10/22 18:43:37 Stopping wpa_cli
04/10/22 18:43:38 Killing pid 208 (/var/run/wpa_cli.pid)
04/10/22 18:43:38 Waiting pid 208 (/var/run/wpa_cli.pid)
04/10/22 18:43:38 Removing pidfile /var/run/wpa_cli.pid
04/10/22 18:43:38 Stopping udhcpc
04/10/22 18:43:38 Killing pid  (/var/run/udhcpc.wlan0.pid)
04/10/22 18:43:38 Waiting pid  (/var/run/udhcpc.wlan0.pid)
04/10/22 18:43:38 Removing pidfile /var/run/udhcpc.wlan0.pid
04/10/22 18:43:38 Stopping wpa_supplicant
04/10/22 18:43:38 Killing pid 193 (/var/run/wpa_supplicant.pid)
04/10/22 18:43:38 Waiting pid 193 (/var/run/wpa_supplicant.pid)
04/10/22 18:43:38 Removing pidfile /var/run/wpa_supplicant.pid
04/10/22 18:43:38 Resetting interface
04/10/22 18:43:38 Starting hostapd
04/10/22 18:43:39 Starting udhcpd
04/10/22 18:43:39 Starting ap_scanner
04/10/22 18:43:39 ap_scanner sleeping 30 seconds
04/10/22 18:44:11 ap_scanner found 7 ssids
04/10/22 18:44:11 ap_scanner found no configured ssid
04/10/22 18:44:11 ap_scanner sleeping 30 seconds
04/10/22 18:44:43 ap_scanner found 11 ssids
04/10/22 18:44:43 ap_scanner found no configured ssid
04/10/22 18:44:43 ap_scanner sleeping 30 seconds
04/10/22 18:45:15 ap_scanner found 13 ssids
04/10/22 18:45:15 ap_scanner found no configured ssid
04/10/22 18:45:15 ap_scanner sleeping 30 seconds
04/10/22 18:45:47 ap_scanner found 13 ssids
04/10/22 18:45:47 ap_scanner found no configured ssid
04/10/22 18:45:47 ap_scanner sleeping 30 seconds
04/10/22 18:46:19 ap_scanner found 11 ssids
04/10/22 18:46:19 ap_scanner found no configured ssid
04/10/22 18:46:19 ap_scanner sleeping 30 seconds
04/10/22 18:46:50 ap_scanner found 12 ssids

Contribute Back

I will attempt a fix this month and make a PR if it is successful.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

wp-coin commented 11 months ago

I have the same problem. Did you find a fix?

joshuahaertel commented 11 months ago

Because I was originally in a pinch, I just made the network public and used a very strong password. As mentioned in the original comment, I suspect you can modify this:

https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/blob/116c1ad53d04933ac91842d981d17015555a584f/firmware_mod/scripts/wifi.sh#L172

To be something like this:

local SSID="$(ap_scanner_ssid)"
iwlist "$WIFI_IFACE" scanning essid $SSID | grep '^[[:space:]]*ESSID:' | grep -v '""' | cut -d ":" -f2