[go: up one dir, main page]

File: wpa.py

package info (click to toggle)
comitup 1.43-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,252 kB
  • sloc: python: 3,093; javascript: 1,261; sh: 95; makefile: 34
file content (44 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python3
# Copyright (c) 2019 David Steele <dsteele@gmail.com>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# License-Filename: LICENSE

import logging
import subprocess
import time

log = logging.getLogger("comitup")

# The AP hotspot is eventually failing. Restarting wpa_supplicant recovers it.
# I haven't found a way to detect that the wpa_supplicant is not working
# properly without involving the outside world.
#
# The minimal workaround fix is to call disconnect, then reconnect from
# wpa_cli.

last_kick_time: float = 0
kick_period_secs: int = 5 * 60


def needs_kick(devstring: str) -> bool:
    return (time.time() - kick_period_secs) > last_kick_time


def kick_wpa(devstring: str) -> None:
    global last_kick_time

    log.debug("Kicking wpa on {}".format(devstring))

    for wpa_cmd in ("disconnect", "reconnect"):
        shell_cmd = "/sbin/wpa_cli -i {0} {1} > /dev/null 2>&1".format(
            devstring, wpa_cmd
        )
        subprocess.run(shell_cmd.split(), capture_output=True)

    last_kick_time = time.time()


def check_wpa(devstring: str) -> None:
    if needs_kick(devstring):
        kick_wpa(devstring)