From 04ce0a9d7fb9cf7ec45e64f1be25b27f1cc2f2c4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 09:17:07 -0500 Subject: [PATCH 1/5] 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 78603de7e6e3b1b99395f039b97c7da1ab937c5e Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 12:23:56 -0500 Subject: [PATCH 2/5] 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 3/5] 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 4/5] 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 25e44b3385ad3674c3e9f69e3295ab8029d153aa Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 24 Apr 2023 12:53:09 -0500 Subject: [PATCH 5/5] 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