From d831f057692c82b4da7c0185178126d83b59427d Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 20 Apr 2023 10:02:34 -0500 Subject: [PATCH 01/35] NM ssid detection --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 205f77fc7..c3a49a847 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -22,10 +22,10 @@ if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` fi -# covers netplan's bugs workaround # https://bugs.launchpad.net/ubuntu/+source/linux-firmware/+bug/1862760 # https://bugs.launchpad.net/netplan/+bug/1951586 # WiFi country code progress on arm64 OS's discussed on #3078 +# covers netplan systemd use on server with bug workarounds if [ -f /run/netplan/wpa-$IFACE.conf ]; then NETPLAN=1 SSID=`grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` @@ -50,8 +50,14 @@ if [ -f /etc/iiab/iiab.env ]; then SSID=$CLIENT_SSID fi fi + +# NetworkManager +if [[ $SSID == "NA" ]]; then + SSID=$(iw $IFACE info | grep ssid | awk '{print $2}' ) +fi echo "ssid is $SSID" -if [[ $SSID == "" ]] || [[ $SSID == "NA" ]]; then + +if [[ $SSID == "" ]]; then echo "Couldn't find ssid $SSID to use exiting" if [ $NETPLAN -eq 1 ]; then echo "Netplan1" From 908c8f495136c19e7f420bddea6265b95c52d27d Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 20 Apr 2023 10:43:18 -0500 Subject: [PATCH 02/35] tighten up when to install ap0 file --- roles/network/tasks/NM-debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/NM-debian.yml b/roles/network/tasks/NM-debian.yml index 200911a91..9cb2cf1db 100644 --- a/roles/network/tasks/NM-debian.yml +++ b/roles/network/tasks/NM-debian.yml @@ -22,7 +22,7 @@ dest: /etc/NetworkManager/conf.d/ap0-manage.conf src: network/ap0-manage.conf mode: 0644 - when: wifi_up_down + when: discovered_wireless_iface != "none" and wifi_up_down - name: Copy manage.conf for NetworkManager when wifi_up_down False template: From 4fe56e787efbaa120aa1c1be2b9f2447ab72773f Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 20 Apr 2023 10:43:55 -0500 Subject: [PATCH 03/35] tighten up when to run wifi detection --- roles/network/tasks/hostapd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 3df0f2c36..7f5bd34a4 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -12,7 +12,7 @@ - name: Detect current Wifi channel shell: iw {{ discovered_wireless_iface }} info | grep channel | cut -d' ' -f2 register: current_client_channel - when: discovered_wireless_iface != "none" + when: has_wifi_gateway is defined - name: Setting WiFi channel to {{ current_client_channel.stdout }} set_fact: From 8aaa459d9c7bd29d8bae6dbfb334b982b602998a Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 20 Apr 2023 12:56:14 -0500 Subject: [PATCH 04/35] restarting seems excessive just use start --- roles/network/templates/network/dnsmasq.sh.j2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/roles/network/templates/network/dnsmasq.sh.j2 b/roles/network/templates/network/dnsmasq.sh.j2 index 00df42bf3..6a7f7179a 100755 --- a/roles/network/templates/network/dnsmasq.sh.j2 +++ b/roles/network/templates/network/dnsmasq.sh.j2 @@ -1,7 +1,6 @@ #!/bin/bash if [ "$IFACE" == "{{ iiab_lan_iface }}" ]; then - echo "Restarting dnsmasq in 5 seconds" - /bin/sleep 5 && /bin/systemctl --no-block restart dnsmasq.service - echo "Restarted dnsmasq" + /bin/systemctl --no-block start dnsmasq.service + echo "Started dnsmasq" fi From 07a63f3b8a57e5d7633ae637a4fca5e4a8861ce7 Mon Sep 17 00:00:00 2001 From: A Holt Date: Sat, 22 Apr 2023 09:59:29 -0400 Subject: [PATCH 05/35] Tighten up templates/hostapd/iiab-hotspot-off just a bit? --- roles/network/templates/hostapd/iiab-hotspot-off | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-hotspot-off b/roles/network/templates/hostapd/iiab-hotspot-off index 98fb9dbf2..0b917b4df 100755 --- a/roles/network/templates/hostapd/iiab-hotspot-off +++ b/roles/network/templates/hostapd/iiab-hotspot-off @@ -11,13 +11,11 @@ systemctl disable iiab-clone-wifi.service systemctl disable iiab-wifi-test.service systemctl stop iiab-clone-wifi.service echo " IIAB hotspot access point Disabled" -exit 0 +#exit 0 {% else %} {% if is_raspbian %} # hotspot-off before ap0_updown sed -i -e "s/^denyinterfaces/#denyinterfaces/" /etc/dhcpcd.conf -systemctl disable hostapd -systemctl stop hostapd #systemctl disable dnsmasq #systemctl stop dnsmasq systemctl daemon-reload @@ -35,8 +33,8 @@ systemctl restart dhcpcd if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ]; then sed -i -e "s|managed=0|managed=1|" /etc/NetworkManager/conf.d/wifi-manage.conf fi -echo -e "\nPlease reboot to enable upstream WiFi access.\n" -exit 0 +echo -e "\nIf you're enabling upstream WiFi, please reboot now.\n" +#exit 0 {% endif %} #is_raspbian {% endif %} From d1a7ab2b74adaf09599e726ec5e23d27d43ff155 Mon Sep 17 00:00:00 2001 From: A Holt Date: Sat, 22 Apr 2023 10:03:57 -0400 Subject: [PATCH 06/35] Tighten up templates/hostapd/iiab-hotspot-on just a bit? --- roles/network/templates/hostapd/iiab-hotspot-on | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-hotspot-on b/roles/network/templates/hostapd/iiab-hotspot-on index 3f809bf44..bd7c4fa0e 100755 --- a/roles/network/templates/hostapd/iiab-hotspot-on +++ b/roles/network/templates/hostapd/iiab-hotspot-on @@ -14,8 +14,7 @@ sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} systemctl enable iiab-clone-wifi.service systemctl enable hostapd systemctl enable iiab-wifi-test.service -echo -e "\nPlease reboot to activate hostapd feature.\n" -exit 0 +#exit 0 {% else %} {% if is_raspbian %} # just do what we have always done in hotspot-on @@ -38,13 +37,12 @@ systemctl start dnsmasq # ip link set dev wlan0 promisc off #fi {% else %} -#ubuntu +#ubuntu (or Mint, or pure Debian?) if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ]; then sed -i -e "s|managed=1|managed=0|" /etc/NetworkManager/conf.d/wifi-manage.conf fi systemctl enable hostapd -echo -e "\nPlease reboot to activate hostapd feature.\n" -exit 0 +#exit 0 {% endif %} #is_raspbian {% endif %} @@ -53,3 +51,5 @@ exit 0 #can_be_ap {% endif %} #network_enabled + +echo -e "\nPlease reboot to activate hostapd feature.\n" From cdc77b121ccda228401de111edf9b404cc1dbaa8 Mon Sep 17 00:00:00 2001 From: A Holt Date: Sat, 22 Apr 2023 10:06:54 -0400 Subject: [PATCH 07/35] Clarifying templates/hostapd/iiab-hotspot-off ? --- roles/network/templates/hostapd/iiab-hotspot-off | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/iiab-hotspot-off b/roles/network/templates/hostapd/iiab-hotspot-off index 0b917b4df..e59c18ebe 100755 --- a/roles/network/templates/hostapd/iiab-hotspot-off +++ b/roles/network/templates/hostapd/iiab-hotspot-off @@ -13,6 +13,7 @@ systemctl stop iiab-clone-wifi.service echo " IIAB hotspot access point Disabled" #exit 0 {% else %} +echo " IIAB hotspot access point Disabled" {% if is_raspbian %} # hotspot-off before ap0_updown sed -i -e "s/^denyinterfaces/#denyinterfaces/" /etc/dhcpcd.conf @@ -29,7 +30,7 @@ systemctl restart dhcpcd # ip link set dev wlan0 promisc on #fi {% else %} -#ubuntu +#ubuntu (or Mint, or pure Debian?) if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ]; then sed -i -e "s|managed=0|managed=1|" /etc/NetworkManager/conf.d/wifi-manage.conf fi From 319b75fe7d30083d58ff28ab6c1e61a9552533e7 Mon Sep 17 00:00:00 2001 From: A Holt Date: Sat, 22 Apr 2023 11:50:04 -0400 Subject: [PATCH 08/35] iiab-hotspot-off: sed "-e" flag optional --- roles/network/templates/hostapd/iiab-hotspot-off | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-hotspot-off b/roles/network/templates/hostapd/iiab-hotspot-off index e59c18ebe..25a5053be 100755 --- a/roles/network/templates/hostapd/iiab-hotspot-off +++ b/roles/network/templates/hostapd/iiab-hotspot-off @@ -3,7 +3,7 @@ echo -e "Networking role disabled\n" echo -e "For details, see: https://github.com/iiab/iiab/pull/3302\n" {% else %} -sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} +sed -i "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} systemctl disable hostapd systemctl stop hostapd {% if wifi_up_down %} @@ -16,7 +16,7 @@ echo " IIAB hotspot access point Disabled" echo " IIAB hotspot access point Disabled" {% if is_raspbian %} # hotspot-off before ap0_updown -sed -i -e "s/^denyinterfaces/#denyinterfaces/" /etc/dhcpcd.conf +sed -i "s/^denyinterfaces/#denyinterfaces/" /etc/dhcpcd.conf #systemctl disable dnsmasq #systemctl stop dnsmasq systemctl daemon-reload @@ -32,7 +32,7 @@ systemctl restart dhcpcd {% else %} #ubuntu (or Mint, or pure Debian?) if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ]; then - sed -i -e "s|managed=0|managed=1|" /etc/NetworkManager/conf.d/wifi-manage.conf + sed -i "s|managed=0|managed=1|" /etc/NetworkManager/conf.d/wifi-manage.conf fi echo -e "\nIf you're enabling upstream WiFi, please reboot now.\n" #exit 0 From 9ed5cd53c7aa020f75332a2cd8e69d9e1516e719 Mon Sep 17 00:00:00 2001 From: A Holt Date: Sat, 22 Apr 2023 11:50:51 -0400 Subject: [PATCH 09/35] iiab-hotspot-on: sed "-e" flag optional --- roles/network/templates/hostapd/iiab-hotspot-on | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-hotspot-on b/roles/network/templates/hostapd/iiab-hotspot-on index bd7c4fa0e..03ca2d4ae 100755 --- a/roles/network/templates/hostapd/iiab-hotspot-on +++ b/roles/network/templates/hostapd/iiab-hotspot-on @@ -9,7 +9,7 @@ echo -e "If you add Wi-Fi hardware, run 'cd /opt/iiab/iiab' then 'sudo ./iiab-ne echo -e "For details, see: https://github.com/iiab/iiab/pull/3179\n" exit 1 {% else %} -sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} +sed -i "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} {% if wifi_up_down %} systemctl enable iiab-clone-wifi.service systemctl enable hostapd @@ -19,7 +19,7 @@ systemctl enable iiab-wifi-test.service {% if is_raspbian %} # just do what we have always done in hotspot-on cp -f /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf -sed -i -e "s/^#denyinterfaces/denyinterfaces/" /etc/dhcpcd.conf +sed -i "s/^#denyinterfaces/denyinterfaces/" /etc/dhcpcd.conf # shut down wlan0 in case connected to network ip link set wlan0 down systemctl enable hostapd @@ -39,7 +39,7 @@ systemctl start dnsmasq {% else %} #ubuntu (or Mint, or pure Debian?) if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ]; then - sed -i -e "s|managed=1|managed=0|" /etc/NetworkManager/conf.d/wifi-manage.conf + sed -i "s|managed=1|managed=0|" /etc/NetworkManager/conf.d/wifi-manage.conf fi systemctl enable hostapd #exit 0 From 262ca468e977740764b0a0fc26dfa496c687c124 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 22 Apr 2023 22:05:01 -0500 Subject: [PATCH 10/35] tighten up when to run wifi detection more --- roles/network/tasks/hostapd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 7f5bd34a4..e46f810b9 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -12,7 +12,7 @@ - name: Detect current Wifi channel shell: iw {{ discovered_wireless_iface }} info | grep channel | cut -d' ' -f2 register: current_client_channel - when: has_wifi_gateway is defined + when: wifi_up_down and can_be_ap and has_wifi_gateway is defined - name: Setting WiFi channel to {{ current_client_channel.stdout }} set_fact: From 0c037b276305621f19fbd5cd6abd72dad90c1f41 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 01:24:20 -0500 Subject: [PATCH 11/35] \[], echo, run netplan restart sooner, NM wait, move hostapd restart --- .../templates/hostapd/iiab-test-wifi.j2 | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index c3a49a847..50f34fae2 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -9,11 +9,13 @@ SSID="NA" # covers systemd-networkd if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then + echo "systemd-network" SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` fi -# covers raspbian +# covers stock raspbian if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then + echo "RasPiOS" RASPBIAN=1 if /usr/sbin/rfkill list wifi | grep -q "Soft blocked: yes" ; then echo "unblocking WiFi" @@ -28,10 +30,11 @@ fi # covers netplan systemd use on server with bug workarounds if [ -f /run/netplan/wpa-$IFACE.conf ]; then NETPLAN=1 + echo "Netplan systemd" SSID=`grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }') if [ -z "$REG_DOM" ]; then - echo "cover netplan wifi client lack of country=" + echo "cover netplan wifi client lack of country= setting to {{ host_country_code }}" sed -i "s|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|" /run/netplan/wpa-$IFACE.conf else echo "set hostapd wifi country to $REG_DOM" @@ -52,12 +55,14 @@ if [ -f /etc/iiab/iiab.env ]; then fi # NetworkManager -if [[ $SSID == "NA" ]]; then +if [ $SSID == "NA" ] && [ ! -z $(pgrep NetworkManager) ]; then + echo "NetworkManager" + sleep 15 SSID=$(iw $IFACE info | grep ssid | awk '{print $2}' ) fi echo "ssid is $SSID" -if [[ $SSID == "" ]]; then +if [ $SSID == "" ]; then echo "Couldn't find ssid $SSID to use exiting" if [ $NETPLAN -eq 1 ]; then echo "Netplan1" @@ -76,14 +81,23 @@ for result in $FREQ; do echo "channel $result is 5Ghz - ignoring" fi done + echo "Using $FREQ2 for $SSID" -if [[ $FREQ2 == "" ]]; then + +if [ $NETPLAN -eq 1 ]; then + echo "Netplan2" + # This is more of a netplan workaround should go away. + /bin/systemctl restart netplan-wpa-$IFACE.service +fi + +if [ $FREQ2 == "" ]; then echo "Couldn't find frequency to use exiting" if [ $NETPLAN -eq 1 ]; then - echo "Netplan2" + echo "Netplan3" fi exit 0 fi + # ubuntu on boot exits at this point timing - issue with wpa_cli and scanning CHAN=$(($FREQ2 - 2407 )) CHAN=$(($CHAN / 5 )) @@ -94,14 +108,7 @@ if [ $CHAN -ne $HOSTAPD ]; then echo "Editing Hostapd for channel $CHAN" cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf + /bin/systemctl --no-block restart hostapd fi -systemctl stop wpa_supplicant -systemctl stop hostapd -systemctl start hostapd -systemctl start wpa_supplicant -if [ $NETPLAN -eq 1 ]; then - echo "Netplan3" - # This is more of a netplan workaround should go away. - systemctl restart netplan-wpa-$IFACE.service -fi + exit 0 From b17cab4794c3189decab7deb35d7dd7186a7a948 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 01:25:24 -0500 Subject: [PATCH 12/35] run after NM and netplan --- roles/network/templates/hostapd/iiab-wifi-test.service.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 index 682680a07..6f86b7e34 100644 --- a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 +++ b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 @@ -2,11 +2,11 @@ Description=IIAB find channel freq for ssid After=wpa_supplicant.service Wants=wpa_supplicant.service +After=NetworkManager.service +After=netplan-wpa-{{ discovered_wireless_iface }}.service Before=hostapd.service Before=dhcpcd.service Before=wpa_supplicant@{{ discovered_wireless_iface }}.service -Before=NetworkManager.service -Before=netplan-wpa-{{ discovered_wireless_iface }}.service Before=network.target [Service] From 472fdfd1527aae807fed80544fe30b382b5f00d6 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 01:59:52 -0500 Subject: [PATCH 13/35] style --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 50f34fae2..5b90cd691 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -62,7 +62,7 @@ if [ $SSID == "NA" ] && [ ! -z $(pgrep NetworkManager) ]; then fi echo "ssid is $SSID" -if [ $SSID == "" ]; then +if [ -z $SSID ]; then echo "Couldn't find ssid $SSID to use exiting" if [ $NETPLAN -eq 1 ]; then echo "Netplan1" @@ -90,7 +90,7 @@ if [ $NETPLAN -eq 1 ]; then /bin/systemctl restart netplan-wpa-$IFACE.service fi -if [ $FREQ2 == "" ]; then +if [ -z $FREQ2 ]; then echo "Couldn't find frequency to use exiting" if [ $NETPLAN -eq 1 ]; then echo "Netplan3" @@ -109,6 +109,7 @@ if [ $CHAN -ne $HOSTAPD ]; then cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf /bin/systemctl --no-block restart hostapd + echo "Restarted hostapd" fi exit 0 From a6cd9ded51d1e0233a06c4b2581e6fff4c7e0198 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 02:03:16 -0500 Subject: [PATCH 14/35] replace backtics --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 5b90cd691..0b92ca259 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -10,7 +10,7 @@ SSID="NA" # covers systemd-networkd if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then echo "systemd-network" - SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` + SSID=$(grep ssid /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//) fi # covers stock raspbian @@ -21,7 +21,7 @@ if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then echo "unblocking WiFi" rfkill unblock wifi fi - SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` + SSID=$(grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//) fi # https://bugs.launchpad.net/ubuntu/+source/linux-firmware/+bug/1862760 @@ -31,7 +31,7 @@ fi if [ -f /run/netplan/wpa-$IFACE.conf ]; then NETPLAN=1 echo "Netplan systemd" - SSID=`grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` + SSID=$(grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//) REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }') if [ -z "$REG_DOM" ]; then echo "cover netplan wifi client lack of country= setting to {{ host_country_code }}" @@ -71,7 +71,7 @@ if [ -z $SSID ]; then fi wpa_cli -i $IFACE scan > /dev/null sleep 2 -FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'` +FREQ=$(wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}') for result in $FREQ; do echo "frequency is $result for $SSID" if [ $result -lt 2485 ] && [ $result -gt 2407 ]; then @@ -102,7 +102,7 @@ fi CHAN=$(($FREQ2 - 2407 )) CHAN=$(($CHAN / 5 )) echo "channel is $CHAN for $SSID" -HOSTAPD=`grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}'` +HOSTAPD=$(grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}') echo "Hostapd set for $HOSTAPD" if [ $CHAN -ne $HOSTAPD ]; then echo "Editing Hostapd for channel $CHAN" From d7d6404c534d2314e6e62681b4079ab505da6c2b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 08:02:57 -0500 Subject: [PATCH 15/35] tighten up country code detection --- roles/network/tasks/rpi_debian.yml | 2 ++ roles/network/tasks/sysd-netd-debian.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index 4dbcd97ee..29b6e0591 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -39,6 +39,7 @@ shell: grep country /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' register: country_code ignore_errors: True + when: wifi_up_down and can_be_ap - name: Set country code for hostapd to value found in /etc/wpa_supplicant/wpa_supplicant.conf set_fact: @@ -52,6 +53,7 @@ line: country={{ host_country_code }} when: country_code is defined and country_code.stdout | length == 0 +# This should go away, should only be unblocked by raspi-config - name: Enable the WiFi with rfkill shell: rfkill unblock 0 ignore_errors: True diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index e1b73db61..6051971b9 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -91,7 +91,7 @@ shell: iw reg get | grep country | grep -v UNSET | awk '{print $2}' | sed "s|:||" register: REG_DOM ignore_errors: True - when: discovered_wireless_iface != "none" + when: wifi_up_down and can_be_ap and has_wifi_gateway is defined - name: Set Wifi Region country code for hostapd when present set_fact: From 348974be6fab3b0a11b986a3da98f7c3437a48a4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 08:21:09 -0500 Subject: [PATCH 16/35] stdout country code detection --- roles/network/tasks/sysd-netd-debian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 6051971b9..5f66db11c 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -96,7 +96,7 @@ - name: Set Wifi Region country code for hostapd when present set_fact: host_country_code: "{{ REG_DOM.stdout }}" - when: REG_DOM is defined and REG_DOM.stdout | length > 0 + when: REG_DOM.stdout is defined and REG_DOM.stdout | length > 0 - name: Clone wifi if needed systemd: From a49a0680d35c3530919363f25c20a94d069d3c58 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 12:23:33 -0500 Subject: [PATCH 17/35] drop NA --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 0b92ca259..b312867c2 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -2,7 +2,7 @@ IFACE={{ discovered_wireless_iface }} RASPBIAN=0 NETPLAN=0 -SSID="NA" +SSID="" # when we get here br0 should be available and dbus wpa_supplicant was started if enabled. None # of the backends that use wpa_supplicant should be active yet based on the Before= After= lines # in the iiab-wifi-test.service unit file. @@ -55,7 +55,7 @@ if [ -f /etc/iiab/iiab.env ]; then fi # NetworkManager -if [ $SSID == "NA" ] && [ ! -z $(pgrep NetworkManager) ]; then +if [ -z $SSID ] && [ ! -z $(pgrep NetworkManager) ]; then echo "NetworkManager" sleep 15 SSID=$(iw $IFACE info | grep ssid | awk '{print $2}' ) From c49adcf39596b7b39f673c24db605fd9837e3537 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 13:53:05 -0500 Subject: [PATCH 18/35] borrow some bits from iiab-clone-wifi --- roles/network/templates/hostapd/iiab-wifi-test.service.j2 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 index 6f86b7e34..4b3a5472c 100644 --- a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 +++ b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 @@ -1,5 +1,9 @@ [Unit] Description=IIAB find channel freq for ssid +Requires=network-pre.target +BindsTo=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device +After=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device +After=iiab-clone-wifi.service After=wpa_supplicant.service Wants=wpa_supplicant.service After=NetworkManager.service From bc4850a09c1d8544fbfa81d939d0543566d408dc Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 13:55:37 -0500 Subject: [PATCH 19/35] RasPiOS could be running NM backend, test if dhcpcd is running, drop rfkill --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index b312867c2..2fc85a962 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -3,9 +3,12 @@ IFACE={{ discovered_wireless_iface }} RASPBIAN=0 NETPLAN=0 SSID="" -# when we get here br0 should be available and dbus wpa_supplicant was started if enabled. None -# of the backends that use wpa_supplicant should be active yet based on the Before= After= lines -# in the iiab-wifi-test.service unit file. +# when we get here br0 should be available and dbus wpa_supplicant was started if enabled. Some +# of the backends that use wpa_supplicant should be active based on the Before= After= lines in +# the iiab-wifi-test.service unit file. + +echo "iiab-test-wifi called" +echo "running pid $$" # covers systemd-networkd if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then @@ -14,13 +17,9 @@ if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then fi # covers stock raspbian -if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then +if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ] && [ ! -z $(pgrep dhcpcd) ]; then echo "RasPiOS" RASPBIAN=1 - if /usr/sbin/rfkill list wifi | grep -q "Soft blocked: yes" ; then - echo "unblocking WiFi" - rfkill unblock wifi - fi SSID=$(grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//) fi From cf67d4c9d775861dd475db877defa808b42a6932 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 14:56:10 -0500 Subject: [PATCH 20/35] netplan-systemd staging --- roles/network/templates/hostapd/iiab-wifi-test.service.j2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 index 4b3a5472c..23223c854 100644 --- a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 +++ b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 @@ -3,6 +3,8 @@ Description=IIAB find channel freq for ssid Requires=network-pre.target BindsTo=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device After=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device +After=network-pre.target + After=iiab-clone-wifi.service After=wpa_supplicant.service Wants=wpa_supplicant.service @@ -11,7 +13,6 @@ After=netplan-wpa-{{ discovered_wireless_iface }}.service Before=hostapd.service Before=dhcpcd.service Before=wpa_supplicant@{{ discovered_wireless_iface }}.service -Before=network.target [Service] Type=oneshot From ef6486b09b929c863af4f2d3830c775e8a638f67 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 23 Apr 2023 16:11:03 -0500 Subject: [PATCH 21/35] grouping, recording, staging --- roles/network/tasks/computed_services.yml | 19 ----------- roles/network/tasks/hostapd.yml | 40 +++++++++++++++++++++++ roles/network/tasks/main.yml | 5 +-- roles/network/tasks/restart.yml | 10 ------ roles/network/tasks/sysd-netd-debian.yml | 11 ------- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/roles/network/tasks/computed_services.yml b/roles/network/tasks/computed_services.yml index 9527ed7d3..2a113ce15 100644 --- a/roles/network/tasks/computed_services.yml +++ b/roles/network/tasks/computed_services.yml @@ -81,22 +81,3 @@ value: "{{ dnsmasq_enabled }}" - option: no_net_restart value: "{{ no_net_restart }}" - - option: hostapd_enabled - value: "{{ hostapd_enabled }}" - - option: host_ssid - value: "{{ host_ssid }}" - - option: host_wifi_mode - value: "{{ host_wifi_mode }}" - - option: host_channel - value: "{{ host_channel }}" - -- name: Add 'network' variable 'current_client_channel' value if defined, to {{ iiab_ini_file }} - ini_file: - dest: "{{ iiab_ini_file }}" - section: network - option: "{{ item.option }}" - value: "{{ item.value | string }}" - with_items: - - option: client_wifi_channel - value: "{{ current_client_channel.stdout }}" - when: current_client_channel.stdout is defined diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index e46f810b9..7f732f73f 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -9,6 +9,17 @@ enabled: no when: not hostapd_enabled +- name: Detect WiFi country code in use + shell: iw reg get | grep country | grep -v UNSET | awk '{print $2}' | sed "s|:||" + register: REG_DOM + ignore_errors: True + when: wifi_up_down and can_be_ap and has_wifi_gateway is defined + +- name: Set Wifi Region country code for hostapd when present + set_fact: + host_country_code: "{{ REG_DOM.stdout }}" + when: REG_DOM.stdout is defined and REG_DOM.stdout | length > 0 + - name: Detect current Wifi channel shell: iw {{ discovered_wireless_iface }} info | grep channel | cut -d' ' -f2 register: current_client_channel @@ -88,3 +99,32 @@ regexp: '^HOSTAPD_ENABLED=*' line: 'HOSTAPD_ENABLED={{ hostapd_enabled }}' state: present + +- name: Record host_country_code_applied and host_channel in network of {{ iiab_ini_file }} + ini_file: + dest: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini + section: network + option: "{{ item.option }}" + value: "{{ item.value | string }}" + with_items: + - option: hostapd_enabled + value: "{{ hostapd_enabled }}" + - option: host_ssid + value: "{{ host_ssid }}" + - option: host_wifi_mode + value: "{{ host_wifi_mode }}" + - option: host_country_code_applied + value: "{{ host_country_code }}" + - option: host_channel + value: "{{ host_channel }}" + +- name: Add 'network' variable 'current_client_channel' value if defined, to {{ iiab_ini_file }} + ini_file: + dest: "{{ iiab_ini_file }}" + section: network + option: "{{ item.option }}" + value: "{{ item.value | string }}" + with_items: + - option: client_wifi_channel + value: "{{ current_client_channel.stdout }}" + when: current_client_channel.stdout is defined diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index f00939911..9e2954892 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -61,8 +61,6 @@ # when: squid_install and FQDN_changed and iiab_stage|int == 9 #### Start services - - name: hostapd - include_tasks: hostapd.yml - name: computed_services include_tasks: computed_services.yml - name: enable_services @@ -94,6 +92,9 @@ #when: (not is_raspbian and not network_manager_active and not systemd_networkd_active and is_debuntu) or is_ubuntu_16 #### end network layout + - name: hostapd + include_tasks: hostapd.yml + - name: Restart services include_tasks: restart.yml diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index 0e1ccd980..0d33f210f 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -14,16 +14,6 @@ - wpa_supplicant when: wifi_up_down and hostapd_enabled -- name: Record host_country_code_applied in network of iiab_ini_file - ini_file: - dest: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini - section: network - option: "{{ item.option }}" - value: "{{ item.value | string }}" - with_items: - - option: host_country_code_applied - value: "{{ host_country_code }}" - - name: Create /etc/hostapd/hostapd.conf and backup .iiab from template if needed template: owner: root diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 5f66db11c..1681f6cf7 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -87,17 +87,6 @@ systemd: daemon_reload: yes -- name: Detect WiFi country code in use - shell: iw reg get | grep country | grep -v UNSET | awk '{print $2}' | sed "s|:||" - register: REG_DOM - ignore_errors: True - when: wifi_up_down and can_be_ap and has_wifi_gateway is defined - -- name: Set Wifi Region country code for hostapd when present - set_fact: - host_country_code: "{{ REG_DOM.stdout }}" - when: REG_DOM.stdout is defined and REG_DOM.stdout | length > 0 - - name: Clone wifi if needed systemd: name: iiab-clone-wifi From d738fdc1efe5140358ed0f89be2dcb65bb14a8d5 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 01:10:03 -0500 Subject: [PATCH 22/35] use dash in place of bash, drop last bashism --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 2fc85a962..cbebb3439 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh IFACE={{ discovered_wireless_iface }} RASPBIAN=0 NETPLAN=0 @@ -44,15 +44,6 @@ if [ -f /run/netplan/wpa-$IFACE.conf ]; then fi fi -# IIAB hint for NetworkManager -# could scrape /etc/NetworkManager/system-connections/ looking for ssid -if [ -f /etc/iiab/iiab.env ]; then - source /etc/iiab/iiab.env - if [ ! -z $CLIENT_SSID ]; then - SSID=$CLIENT_SSID - fi -fi - # NetworkManager if [ -z $SSID ] && [ ! -z $(pgrep NetworkManager) ]; then echo "NetworkManager" From 995bc6308bbc76de5ae29d029b358df1e6ec747a Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 01:12:37 -0500 Subject: [PATCH 23/35] drop unused assignment --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index cbebb3439..6693090ae 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -19,7 +19,6 @@ fi # covers stock raspbian if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ] && [ ! -z $(pgrep dhcpcd) ]; then echo "RasPiOS" - RASPBIAN=1 SSID=$(grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//) fi From cb86366b134d016ff7ebec29fc8e3031bba9f7f3 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 01:38:56 -0500 Subject: [PATCH 24/35] shellcheck --- .../templates/hostapd/iiab-test-wifi.j2 | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 6693090ae..948c8bd2a 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -1,6 +1,5 @@ #!/bin/sh IFACE={{ discovered_wireless_iface }} -RASPBIAN=0 NETPLAN=0 SSID="" # when we get here br0 should be available and dbus wpa_supplicant was started if enabled. Some @@ -17,7 +16,7 @@ if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then fi # covers stock raspbian -if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ] && [ ! -z $(pgrep dhcpcd) ]; then +if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ] && [ -n "$(pgrep dhcpcd)" ]; then echo "RasPiOS" SSID=$(grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//) fi @@ -44,14 +43,14 @@ if [ -f /run/netplan/wpa-$IFACE.conf ]; then fi # NetworkManager -if [ -z $SSID ] && [ ! -z $(pgrep NetworkManager) ]; then +if [ -z "$SSID" ] && [ -n "$(pgrep NetworkManager)" ]; then echo "NetworkManager" sleep 15 SSID=$(iw $IFACE info | grep ssid | awk '{print $2}' ) fi echo "ssid is $SSID" -if [ -z $SSID ]; then +if [ -z "$SSID" ]; then echo "Couldn't find ssid $SSID to use exiting" if [ $NETPLAN -eq 1 ]; then echo "Netplan1" @@ -60,10 +59,10 @@ if [ -z $SSID ]; then fi wpa_cli -i $IFACE scan > /dev/null sleep 2 -FREQ=$(wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}') +FREQ=$(wpa_cli -i $IFACE scan_results | grep "$SSID" | awk '{print $2}') for result in $FREQ; do echo "frequency is $result for $SSID" - if [ $result -lt 2485 ] && [ $result -gt 2407 ]; then + if [ "$result" -lt 2485 ] && [ "$result" -gt 2407 ]; then FREQ2=$result break else @@ -79,7 +78,7 @@ if [ $NETPLAN -eq 1 ]; then /bin/systemctl restart netplan-wpa-$IFACE.service fi -if [ -z $FREQ2 ]; then +if [ -z "$FREQ2" ]; then echo "Couldn't find frequency to use exiting" if [ $NETPLAN -eq 1 ]; then echo "Netplan3" @@ -88,12 +87,12 @@ if [ -z $FREQ2 ]; then fi # ubuntu on boot exits at this point timing - issue with wpa_cli and scanning -CHAN=$(($FREQ2 - 2407 )) -CHAN=$(($CHAN / 5 )) +CHAN=$((FREQ2 - 2407 )) +CHAN=$((CHAN / 5 )) echo "channel is $CHAN for $SSID" HOSTAPD=$(grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}') echo "Hostapd set for $HOSTAPD" -if [ $CHAN -ne $HOSTAPD ]; then +if [ "$CHAN" -ne "$HOSTAPD" ]; then echo "Editing Hostapd for channel $CHAN" cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf From 04ce0a9d7fb9cf7ec45e64f1be25b27f1cc2f2c4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 09:17:07 -0500 Subject: [PATCH 25/35] netplan2 --- .../templates/hostapd/iiab-test-wifi.j2 | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 948c8bd2a..2df652560 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -5,6 +5,7 @@ SSID="" # when we get here br0 should be available and dbus wpa_supplicant was started if enabled. Some # of the backends that use wpa_supplicant should be active based on the Before= After= lines in # the iiab-wifi-test.service unit file. +# https://github.com/iiab/iiab/pull/3542#issuecomment-1519647266 echo "iiab-test-wifi called" echo "running pid $$" @@ -31,6 +32,7 @@ if [ -f /run/netplan/wpa-$IFACE.conf ]; then SSID=$(grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//) REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }') if [ -z "$REG_DOM" ]; then + NETPLAN=2 echo "cover netplan wifi client lack of country= setting to {{ host_country_code }}" sed -i "s|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|" /run/netplan/wpa-$IFACE.conf else @@ -52,11 +54,28 @@ echo "ssid is $SSID" if [ -z "$SSID" ]; then echo "Couldn't find ssid $SSID to use exiting" - if [ $NETPLAN -eq 1 ]; then + if [ $NETPLAN -gt 0 ]; then echo "Netplan1" fi exit 0 fi + +if [ $NETPLAN -gt 0 ]; then + echo "Netplan2" + wpa_processes=$(ps -A | grep wpa_supplicant | wc -l) + if [ $wpa_processes -eq 1 ]; then + # This is more of a netplan workaround should go away. + echo "Starting netplan wifi" + NETPLAN=2 + else + echo "Restarting netplan wifi" + fi + # This one handles the changing of the country code from above + if [ $NETPLAN -eq 2 ]; then + /bin/systemctl restart netplan-wpa-$IFACE.service + sleep 2 + fi +fi wpa_cli -i $IFACE scan > /dev/null sleep 2 FREQ=$(wpa_cli -i $IFACE scan_results | grep "$SSID" | awk '{print $2}') @@ -72,15 +91,9 @@ done echo "Using $FREQ2 for $SSID" -if [ $NETPLAN -eq 1 ]; then - echo "Netplan2" - # This is more of a netplan workaround should go away. - /bin/systemctl restart netplan-wpa-$IFACE.service -fi - if [ -z "$FREQ2" ]; then echo "Couldn't find frequency to use exiting" - if [ $NETPLAN -eq 1 ]; then + if [ $NETPLAN -gt 0 ]; then echo "Netplan3" fi exit 0 From a17103f14fc8006daa26cbcc0d987c0a53fd874b Mon Sep 17 00:00:00 2001 From: root Date: Mon, 24 Apr 2023 17:46:24 +0100 Subject: [PATCH 26/35] Explain & lint templates/hostapd/iiab-test-wifi.j2 --- adm-run-roles-tmp.yml | 15 +++++++++++++++ .../templates/hostapd/iiab-test-wifi.j2 | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 adm-run-roles-tmp.yml diff --git a/adm-run-roles-tmp.yml b/adm-run-roles-tmp.yml new file mode 100644 index 000000000..8f6888707 --- /dev/null +++ b/adm-run-roles-tmp.yml @@ -0,0 +1,15 @@ +--- +- hosts: all + become: yes + + vars_files: + - vars/default_vars.yml + - vars/{{ ansible_local.local_facts.os_ver }}.yml + - /etc/iiab/local_vars.yml + - /etc/iiab/iiab_state.yml + + roles: + - { role: 0-init } + - { role: captiveportal } + - { role: lokole } + - { role: network } diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 948c8bd2a..1fe9d09ff 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -1,4 +1,17 @@ #!/bin/sh + +# 2023-04-24 PR #3542 / PR #3549 context: +# "systemd-network" "RasPiOS" have files with the client wifi info within them, +# those can be parsed for the ssid without needing the related service running +# first. +# "Netplan systemd" "NetworkManager" need to be running to be able to parse for +# the ssid, from the generated config file for "Netplan systemd" and from the +# running environment for "NetworkManager". +# "iiab-wifi-test.service" acts as a bit of a traffic cop keeping the ordering +# of the services more deterministic when active and tries to catch a channel +# mismatch between client wifi's current setting and what is contained within +# hostapd.conf early in the boot process. + IFACE={{ discovered_wireless_iface }} NETPLAN=0 SSID="" @@ -87,8 +100,8 @@ if [ -z "$FREQ2" ]; then fi # ubuntu on boot exits at this point timing - issue with wpa_cli and scanning -CHAN=$((FREQ2 - 2407 )) -CHAN=$((CHAN / 5 )) +CHAN=$((FREQ2 - 2407)) +CHAN=$((CHAN / 5)) echo "channel is $CHAN for $SSID" HOSTAPD=$(grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}') echo "Hostapd set for $HOSTAPD" @@ -99,5 +112,3 @@ if [ "$CHAN" -ne "$HOSTAPD" ]; then /bin/systemctl --no-block restart hostapd echo "Restarted hostapd" fi - -exit 0 From 78603de7e6e3b1b99395f039b97c7da1ab937c5e Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 12:23:56 -0500 Subject: [PATCH 27/35] capture running code --- .../templates/hostapd/iiab-test-wifi.j2 | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 2df652560..25c61b3a2 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -61,21 +61,25 @@ if [ -z "$SSID" ]; then fi if [ $NETPLAN -gt 0 ]; then - echo "Netplan2" - wpa_processes=$(ps -A | grep wpa_supplicant | wc -l) - if [ $wpa_processes -eq 1 ]; then + echo "Netplan2 sleep 10" + sleep 10 + wifi_processes=$(ps -A | grep wpa_supplicant | wc -l) + if [ $wifi_processes -eq 1 ]; then # This is more of a netplan workaround should go away. - echo "Starting netplan wifi" + echo "Problem - Now Starting netplan wifi" NETPLAN=2 else - echo "Restarting netplan wifi" + echo "Not Restarting netplan wifi sleep 20" + sleep 20 fi # This one handles the changing of the country code from above if [ $NETPLAN -eq 2 ]; then - /bin/systemctl restart netplan-wpa-$IFACE.service - sleep 2 + echo "Restarting netplan-wpa-$IFACE sleep 20" + /bin/systemctl --no-block restart netplan-wpa-$IFACE.service + sleep 20 fi fi +sleep 10 wpa_cli -i $IFACE scan > /dev/null sleep 2 FREQ=$(wpa_cli -i $IFACE scan_results | grep "$SSID" | awk '{print $2}') @@ -99,9 +103,8 @@ if [ -z "$FREQ2" ]; then exit 0 fi -# ubuntu on boot exits at this point timing - issue with wpa_cli and scanning -CHAN=$((FREQ2 - 2407 )) -CHAN=$((CHAN / 5 )) +CHAN=$((FREQ2 - 2407)) +CHAN=$((CHAN / 5)) echo "channel is $CHAN for $SSID" HOSTAPD=$(grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}') echo "Hostapd set for $HOSTAPD" @@ -112,5 +115,3 @@ if [ "$CHAN" -ne "$HOSTAPD" ]; then /bin/systemctl --no-block restart hostapd echo "Restarted hostapd" fi - -exit 0 From ba9e9ee01ae133a6d17125e5c7e4bebd29b3e821 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 12:27:00 -0500 Subject: [PATCH 28/35] capture running service --- .../templates/hostapd/iiab-wifi-test.service.j2 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 index 23223c854..8d99e4a85 100644 --- a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 +++ b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 @@ -1,16 +1,10 @@ [Unit] Description=IIAB find channel freq for ssid -Requires=network-pre.target -BindsTo=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device -After=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device -After=network-pre.target - -After=iiab-clone-wifi.service -After=wpa_supplicant.service -Wants=wpa_supplicant.service +Requisite=sys-subsystem-net-devices-wlan0.device +Requisite=iiab-clone-wifi.service +Requisite=wpa_supplicant.service After=NetworkManager.service After=netplan-wpa-{{ discovered_wireless_iface }}.service -Before=hostapd.service Before=dhcpcd.service Before=wpa_supplicant@{{ discovered_wireless_iface }}.service From 088537b9b86b117d7529249cc09af66100744166 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 12:42:16 -0500 Subject: [PATCH 29/35] clean up netd-disp2 --- roles/network/templates/hostapd/netd-disp2 | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/roles/network/templates/hostapd/netd-disp2 b/roles/network/templates/hostapd/netd-disp2 index e6a8fca72..2e39b26c2 100644 --- a/roles/network/templates/hostapd/netd-disp2 +++ b/roles/network/templates/hostapd/netd-disp2 @@ -2,20 +2,15 @@ if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then echo "NET-DISP-WiFi $IFACE $STATE" # If we are here we have a dhcp ip address - CHAN=`iw $IFACE info|grep channel|cut -d' ' -f2` + CHAN=$(iw "$IFACE" info|grep channel|cut -d' ' -f2) echo "Using channel $CHAN for carrier" - HOSTAPD=`grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}'` + HOSTAPD=$(grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}') echo "Hostapd set for $HOSTAPD" if [ $CHAN -ne $HOSTAPD ] && [ $CHAN -lt 14 ]; then echo "Editing Hostapd for channel $CHAN" cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf - sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf - systemctl stop wpa_supplicant + sed -i "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf systemctl restart hostapd - systemctl start wpa_supplicant - if [ -f /run/netplan/wpa-$IFACE.conf ]; then - systemctl restart netplan-wpa-$IFACE.service - fi else echo "Upstream Channel greater than 13 or is the same - not changing hostapd.conf" fi From bfbb4f06f2891ef0894e64e52c33b56a4d5031cc Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 24 Apr 2023 13:48:24 -0400 Subject: [PATCH 30/35] Delete adm-run-roles-tmp.yml --- adm-run-roles-tmp.yml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 adm-run-roles-tmp.yml diff --git a/adm-run-roles-tmp.yml b/adm-run-roles-tmp.yml deleted file mode 100644 index 8f6888707..000000000 --- a/adm-run-roles-tmp.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- hosts: all - become: yes - - vars_files: - - vars/default_vars.yml - - vars/{{ ansible_local.local_facts.os_ver }}.yml - - /etc/iiab/local_vars.yml - - /etc/iiab/iiab_state.yml - - roles: - - { role: 0-init } - - { role: captiveportal } - - { role: lokole } - - { role: network } From 25e44b3385ad3674c3e9f69e3295ab8029d153aa Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 12:53:09 -0500 Subject: [PATCH 31/35] service set start timeout --- roles/network/templates/hostapd/iiab-wifi-test.service.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 index 8d99e4a85..450844b98 100644 --- a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 +++ b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 @@ -9,6 +9,7 @@ Before=dhcpcd.service Before=wpa_supplicant@{{ discovered_wireless_iface }}.service [Service] +TimeoutStartSec=120 Type=oneshot RemainAfterExit=yes ExecStart=/usr/sbin/iiab-test-wifi From fb2a9c82222f39c3d1a839454b335e71a1ee1ea1 Mon Sep 17 00:00:00 2001 From: A Holt Date: Mon, 24 Apr 2023 14:02:35 -0400 Subject: [PATCH 32/35] Revert c49adcf "borrow some bits from iiab-clone-wifi" (& preserve cf67d4c "netplan-systemd staging" ?) --- .../templates/hostapd/iiab-wifi-test.service.j2 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 index 23223c854..1110a9a21 100644 --- a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 +++ b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 @@ -1,11 +1,13 @@ [Unit] Description=IIAB find channel freq for ssid -Requires=network-pre.target -BindsTo=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device -After=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device -After=network-pre.target -After=iiab-clone-wifi.service +# 2023-04-24 PR #3549: c49adcf went too far and broke netplan-systemd +#Requires=network-pre.target +#BindsTo=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device +#After=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device +#After=iiab-clone-wifi.service + +After=network-pre.target After=wpa_supplicant.service Wants=wpa_supplicant.service After=NetworkManager.service @@ -13,6 +15,7 @@ After=netplan-wpa-{{ discovered_wireless_iface }}.service Before=hostapd.service Before=dhcpcd.service Before=wpa_supplicant@{{ discovered_wireless_iface }}.service +#Before=network.target [Service] Type=oneshot From 40e4b9cce9df8872ba7ad3339401256bb2c919b4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 25 Apr 2023 10:31:28 -0500 Subject: [PATCH 33/35] softcode --- roles/network/templates/hostapd/iiab-wifi-test.service.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 index 555bf06f6..baa73eed6 100644 --- a/roles/network/templates/hostapd/iiab-wifi-test.service.j2 +++ b/roles/network/templates/hostapd/iiab-wifi-test.service.j2 @@ -1,6 +1,6 @@ [Unit] Description=IIAB find channel freq for ssid -Requisite=sys-subsystem-net-devices-wlan0.device +Requisite=sys-subsystem-net-devices-{{ discovered_wireless_iface }}.device Requisite=iiab-clone-wifi.service Requisite=wpa_supplicant.service From 8eb29a9edea2b99833473c786c23bd660472d764 Mon Sep 17 00:00:00 2001 From: A Holt Date: Wed, 26 Apr 2023 18:57:05 -0400 Subject: [PATCH 34/35] rpi_debian.yml: Fix both "country_code is defined" -> "country_code.stdout is defined" --- roles/network/tasks/rpi_debian.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index 29b6e0591..247b969df 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -44,14 +44,14 @@ - name: Set country code for hostapd to value found in /etc/wpa_supplicant/wpa_supplicant.conf set_fact: host_country_code: "{{ country_code.stdout }}" - when: country_code is defined and country_code.stdout | length > 0 + when: country_code.stdout is defined and country_code.stdout | length > 0 - name: Put country code ({{ host_country_code }}) in /etc/wpa_supplicant/wpa_supplicant.conf if nec lineinfile: path: /etc/wpa_supplicant/wpa_supplicant.conf regexp: "^country.*" line: country={{ host_country_code }} - when: country_code is defined and country_code.stdout | length == 0 + when: country_code.stdout is defined and country_code.stdout | length == 0 # This should go away, should only be unblocked by raspi-config - name: Enable the WiFi with rfkill From df08ecfef6e6615cf171592caa90334224296ab4 Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 27 Apr 2023 07:49:40 -0400 Subject: [PATCH 35/35] "Couldn't find an UPSTREAM SSID in files like wpa_supplicant.conf" --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index d364c5a5f..709a92fbb 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -5,7 +5,7 @@ # those can be parsed for the ssid without needing the related service running # first. # "Netplan systemd" "NetworkManager" need to be running to be able to parse for -# the ssid, from the generated config file for "Netplan systemd" and from the +# the ssid, from the generated config file for "Netplan systemd" and from the # running environment for "NetworkManager". # "iiab-wifi-test.service" acts as a bit of a traffic cop keeping the ordering # of the services more deterministic when active and tries to catch a channel @@ -66,7 +66,9 @@ fi echo "ssid is $SSID" if [ -z "$SSID" ]; then - echo "Couldn't find ssid $SSID to use exiting" + echo "Couldn't find an UPSTREAM SSID in files like wpa_supplicant.conf -- so exiting." + echo "CLARIF: This is normal when UPSTREAM WIFI is not active, as there would be no" + echo "UPSTREAM SSID to extract, e.g. if 'wifi_up_down: False'" if [ $NETPLAN -gt 0 ]; then echo "Netplan1" fi