Tuesday, October 4
Shadow

rtw89 CTRL-EVENT-BEACON-LOSS workaround

#!/bin/env python

# journalctl -u wpa_supplicant -f -o json | python event_listener.py

import json
import sys
import subprocess


__BEACON_LOSS = 'CTRL-EVENT-BEACON-LOSS'
__REASSOCIATE = ['/usr/bin/sudo', '/usr/sbin/wpa_cli', 'reassociate']
__WINDOW = 10 * 1_000_000
__THRESHOLD = 5


def main():
    messages = []
    for line in sys.stdin:
        msg = json.loads(line)
        print(msg['SYSLOG_TIMESTAMP'], msg['MESSAGE'])
        messages.insert(0, msg)
        if len(messages) > 100:
            messages.pop()
        t0 = int(msg['__REALTIME_TIMESTAMP'])
        tc = t0 - __WINDOW
        if __BEACON_LOSS in msg['MESSAGE']:
            error_count = 1
            for h in messages:
                if __BEACON_LOSS in h['MESSAGE']:
                    error_count += 1
                if int(h['__REALTIME_TIMESTAMP']) < tc:
                    break
            if error_count > __THRESHOLD:
                print(f'more than 5 in 10, reassociating...')
                cp = subprocess.run(__REASSOCIATE)
                print(f'Reassociate succeeded: {cp.returncode == 0}')


if __name__ == '__main__':
    main()

Leave a Reply