lakinduakash / linux-wifi-hotspot

Feature-rich wifi hotspot creator for Linux which provides both GUI and command-line interface. It is also able to create a hotspot using the same wifi card which is connected to an AP already ( Similar to Windows 10).
BSD 2-Clause "Simplified" License
3.26k stars 300 forks source link

After awakening system from being asleep Wi Hotspot needs to be manually restarted (ap0: IEEE 802.11: disassociated due to inactivity) #388

Closed AntonSamokat closed 6 months ago

AntonSamokat commented 6 months ago

Describe the bug After awakening system from being asleep Wi Hospot needs to be manually restarted. Applicable both to GUI and service versions of the tool.

To Reproduce Steps to reproduce the behavior:

  1. Enable Wi Hotspot on device 1
  2. Connect to the network from device 2
  3. Suspend device 1 (systemctl suspend)
  4. Awake device 1

Expected behavior Wi Hotspot Screenshots If applicable, add screenshots to help explain your problem.

Desktop:

Additional context systemctl status create_ap output:

create_ap.service - Create AP Service
     Loaded: loaded (/lib/systemd/system/create_ap.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2024-04-05 09:10:53 MSK; 4h 15min ago
   Main PID: 970 (create_ap)
      Tasks: 5 (limit: 8971)
     Memory: 7.1M
     CGroup: /system.slice/create_ap.service
             ├─  970 /bin/bash /usr/bin/create_ap --config /etc/create_ap.conf
             ├─ 2133 dnsmasq -C /tmp/create_ap.wlp3s0.conf.w7941yyL/dnsmasq.conf -x /tmp/create_ap.wlp3s0.conf.w7941yyL/dnsm>
             ├─ 2134 /bin/bash /usr/bin/create_ap --config /etc/create_ap.conf
             ├─ 2136 /usr/sbin/hostapd /tmp/create_ap.wlp3s0.conf.w7941yyL/hostapd.conf
             └─89039 sleep 2

dnsmasq-dhcp[2133]: DHCPDISCOVER(ap0) c1:c1:c1:55:bb:ff
dnsmasq-dhcp[2133]: DHCPOFFER(ap0) 192.168.12.137 c1:c1:c1:55:bb:ff
dnsmasq-dhcp[2133]: DHCPREQUEST(ap0) 192.168.12.137 c1:c1:c1:55:bb:ff
dnsmasq-dhcp[2133]: DHCPACK(ap0) 192.168.12.137 c1:c1:c1:55:bb:ff Redmi7A-d91
hostapd[2136]: ap0: STA c1:c1:c1:55:bb:ff IEEE 802.11: disassociated due to inactivity
create_ap[2136]: ap0: AP-STA-DISCONNECTED c1:c1:c1:55:bb:ff
create_ap[2136]: ap0: STA c1:c1:c1:55:bb:ff IEEE 802.11: disassociated due to inactivity
create_ap[2136]: ap0: STA c1:c1:c1:55:bb:ff IEEE 802.11: deauthenticated due to inactivity (timer D>
hostapd[2136]: ap0: STA c1:c1:c1:55:bb:ff IEEE 802.11: deauthenticated due to inactivity (timer DEA>
create_ap[2136]: Failed to set beacon parameters
AntonSamokat commented 6 months ago

I've found solution on the level of system - to restart Wi Fi Hotspot service (systemctl restart create_ap) by the system upon wake up.

Need to create script (for example, restart-wifi-hotspot.sh) in /lib/systemd/system-sleep/:

cd /lib/systemd/system-sleep/; name='restart-wifi-hotspot.sh'; sudo touch "$name"; sudo chmod ug-x "$name"; sudo vim "$name"

With the following content:

#!/bin/sh

case $1/$2 in
  pre/*)
    # Place your pre suspend commands here, or `exit 0` if no pre suspend action required
    ;;
  post/*)
    # Place your post suspend (resume) commands here, or `exit 0` if no post suspend action required
    systemctl restart create_ap  # resturts wifi-hotspot service
    ;;
esac

Tested on Ubuntu 20.04

Source: sleep - Run Script on Wakeup? - Ask Ubuntu