Skip to content

Commit

Permalink
Add code to workaround bug with wifi protocol on RPi3B
Browse files Browse the repository at this point in the history
  • Loading branch information
martignoni committed Nov 28, 2023
1 parent 095811b commit 3e7e0cb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bin/changewifisettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def is_regex_in_file(file_name, search_pattern):
def is_networkmanager():
return subprocess.run(['systemctl', '-q', 'is-active', 'NetworkManager']).returncode == 0

def is_pi3():
"""True if this is a Pi 3 B (not Plus!)."""
return "Pi 3 Model B Rev" in open('/proc/device-tree/model').read()

# Default access point settings.

default_channel = '11'
Expand All @@ -55,6 +59,13 @@ def is_networkmanager():
default_min_range = 10
default_max_range = 254

# Workaround a bug with WPA2 protocol on RPi3B.
# See https://github.com/moodlebox/moodlebox/issues/319.
if is_pi3():
proto = 'rsn,wpa'
else:
proto = 'rsn'

# Path of various config files.

kernel_cmdline_file = "/boot/firmware/cmdline.txt"
Expand Down Expand Up @@ -213,7 +224,7 @@ def do_password_protected():
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.psk', new_password])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.group', 'ccmp'])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.pairwise', 'ccmp'])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.proto', 'rsn'])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.proto', proto])
else:
# Set parameters adequately in hostapd config file.
if not password_protected and is_currently_protected:
Expand Down Expand Up @@ -244,7 +255,7 @@ def do_password():
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.psk', new_password])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.group', 'ccmp'])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.pairwise', 'ccmp'])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.proto', 'rsn'])
subprocess.run(['sudo', 'nmcli', 'con', 'mod', 'WifiAP', 'wifi-sec.proto', proto])
else:
# Set password in hostapd config file.
file_replace_line(hostapd_conf_file, '^wpa_passphrase=.*$', 'wpa_passphrase=' + new_password)
Expand Down

0 comments on commit 3e7e0cb

Please sign in to comment.