Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions roles/network/templates/hostapd/iiab-test-wifi.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 $$"
Expand All @@ -44,6 +45,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
Expand All @@ -65,11 +67,32 @@ 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 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 "Problem - Now Starting netplan wifi"
NETPLAN=2
else
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
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}')
Expand All @@ -85,21 +108,14 @@ 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
fi

# ubuntu on boot exits at this point timing - issue with wpa_cli and scanning
CHAN=$((FREQ2 - 2407))
CHAN=$((CHAN / 5))
echo "channel is $CHAN for $SSID"
Expand Down
12 changes: 8 additions & 4 deletions roles/network/templates/hostapd/iiab-wifi-test.service.j2
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
[Unit]
Description=IIAB find channel freq for ssid
Requisite=sys-subsystem-net-devices-wlan0.device
Requisite=iiab-clone-wifi.service
Requisite=wpa_supplicant.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=network-pre.target
#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=network.target

[Service]
TimeoutStartSec=120
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/iiab-test-wifi
Expand Down
11 changes: 3 additions & 8 deletions roles/network/templates/hostapd/netd-disp2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down