2020-04-22 20:59:50 +00:00
|
|
|
#!/bin/bash
|
2020-04-22 00:22:35 +00:00
|
|
|
IFACE={{ discovered_wireless_iface }}
|
2020-05-04 13:58:37 +00:00
|
|
|
RASPBIAN=0
|
2020-04-27 15:34:43 +00:00
|
|
|
NETPLAN=0
|
2023-04-23 17:23:33 +00:00
|
|
|
SSID=""
|
2020-05-04 13:58:37 +00:00
|
|
|
# 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
|
2021-07-28 02:36:07 +00:00
|
|
|
# in the iiab-wifi-test.service unit file.
|
2020-05-04 13:58:37 +00:00
|
|
|
|
2020-04-27 15:34:43 +00:00
|
|
|
# covers systemd-networkd
|
|
|
|
if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then
|
2023-04-23 06:24:20 +00:00
|
|
|
echo "systemd-network"
|
2023-04-23 07:03:16 +00:00
|
|
|
SSID=$(grep ssid /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//)
|
2020-04-22 00:22:35 +00:00
|
|
|
fi
|
|
|
|
|
2023-04-23 06:24:20 +00:00
|
|
|
# covers stock raspbian
|
2020-04-22 00:22:35 +00:00
|
|
|
if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then
|
2023-04-23 06:24:20 +00:00
|
|
|
echo "RasPiOS"
|
2020-05-04 13:58:37 +00:00
|
|
|
RASPBIAN=1
|
2020-05-12 15:45:35 +00:00
|
|
|
if /usr/sbin/rfkill list wifi | grep -q "Soft blocked: yes" ; then
|
|
|
|
echo "unblocking WiFi"
|
|
|
|
rfkill unblock wifi
|
|
|
|
fi
|
2023-04-23 07:03:16 +00:00
|
|
|
SSID=$(grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//)
|
2020-04-22 00:22:35 +00:00
|
|
|
fi
|
2020-04-27 15:34:43 +00:00
|
|
|
|
2021-12-22 11:25:58 +00:00
|
|
|
# https://bugs.launchpad.net/ubuntu/+source/linux-firmware/+bug/1862760
|
|
|
|
# https://bugs.launchpad.net/netplan/+bug/1951586
|
2021-12-29 18:12:46 +00:00
|
|
|
# WiFi country code progress on arm64 OS's discussed on #3078
|
2023-04-20 15:02:34 +00:00
|
|
|
# covers netplan systemd use on server with bug workarounds
|
2023-04-18 21:08:08 +00:00
|
|
|
if [ -f /run/netplan/wpa-$IFACE.conf ]; then
|
2023-04-19 15:46:45 +00:00
|
|
|
NETPLAN=1
|
2023-04-23 06:24:20 +00:00
|
|
|
echo "Netplan systemd"
|
2023-04-23 07:03:16 +00:00
|
|
|
SSID=$(grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//)
|
2023-04-18 21:08:08 +00:00
|
|
|
REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }')
|
|
|
|
if [ -z "$REG_DOM" ]; then
|
2023-04-23 06:24:20 +00:00
|
|
|
echo "cover netplan wifi client lack of country= setting to {{ host_country_code }}"
|
2023-04-19 15:38:50 +00:00
|
|
|
sed -i "s|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|" /run/netplan/wpa-$IFACE.conf
|
2023-04-18 21:08:08 +00:00
|
|
|
else
|
|
|
|
echo "set hostapd wifi country to $REG_DOM"
|
|
|
|
if [ -f /etc/hostapd/hostapd.conf.iiab ]; then
|
2023-04-19 15:38:50 +00:00
|
|
|
sed -i "s|^country.*|country_code=$REG_DOM|" /etc/hostapd/hostapd.conf.iiab
|
2023-04-18 21:08:08 +00:00
|
|
|
cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf
|
|
|
|
fi
|
|
|
|
fi
|
2020-04-27 15:34:43 +00:00
|
|
|
fi
|
2023-04-18 21:08:08 +00:00
|
|
|
|
2020-04-27 15:34:43 +00:00
|
|
|
# IIAB hint for NetworkManager
|
2020-05-04 13:58:37 +00:00
|
|
|
# could scrape /etc/NetworkManager/system-connections/ looking for ssid
|
2020-04-22 00:22:35 +00:00
|
|
|
if [ -f /etc/iiab/iiab.env ]; then
|
|
|
|
source /etc/iiab/iiab.env
|
|
|
|
if [ ! -z $CLIENT_SSID ]; then
|
|
|
|
SSID=$CLIENT_SSID
|
|
|
|
fi
|
|
|
|
fi
|
2023-04-20 15:02:34 +00:00
|
|
|
|
|
|
|
# NetworkManager
|
2023-04-23 17:23:33 +00:00
|
|
|
if [ -z $SSID ] && [ ! -z $(pgrep NetworkManager) ]; then
|
2023-04-23 06:24:20 +00:00
|
|
|
echo "NetworkManager"
|
|
|
|
sleep 15
|
2023-04-20 15:02:34 +00:00
|
|
|
SSID=$(iw $IFACE info | grep ssid | awk '{print $2}' )
|
|
|
|
fi
|
2020-05-04 19:42:10 +00:00
|
|
|
echo "ssid is $SSID"
|
2023-04-20 15:02:34 +00:00
|
|
|
|
2023-04-23 06:59:52 +00:00
|
|
|
if [ -z $SSID ]; then
|
2020-05-06 13:10:34 +00:00
|
|
|
echo "Couldn't find ssid $SSID to use exiting"
|
|
|
|
if [ $NETPLAN -eq 1 ]; then
|
|
|
|
echo "Netplan1"
|
|
|
|
fi
|
2020-05-04 19:42:10 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2020-04-27 14:44:17 +00:00
|
|
|
wpa_cli -i $IFACE scan > /dev/null
|
2020-05-05 16:27:57 +00:00
|
|
|
sleep 2
|
2023-04-23 07:03:16 +00:00
|
|
|
FREQ=$(wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}')
|
2020-04-22 21:20:04 +00:00
|
|
|
for result in $FREQ; do
|
2020-04-27 14:44:17 +00:00
|
|
|
echo "frequency is $result for $SSID"
|
2020-05-06 13:10:34 +00:00
|
|
|
if [ $result -lt 2485 ] && [ $result -gt 2407 ]; then
|
2020-04-22 21:20:04 +00:00
|
|
|
FREQ2=$result
|
2020-05-06 13:10:34 +00:00
|
|
|
break
|
2020-09-08 00:08:51 +00:00
|
|
|
else
|
|
|
|
echo "channel $result is 5Ghz - ignoring"
|
2020-04-22 21:20:04 +00:00
|
|
|
fi
|
|
|
|
done
|
2023-04-23 06:24:20 +00:00
|
|
|
|
2020-04-22 21:20:04 +00:00
|
|
|
echo "Using $FREQ2 for $SSID"
|
2023-04-23 06:24:20 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-04-23 06:59:52 +00:00
|
|
|
if [ -z $FREQ2 ]; then
|
2020-05-06 13:10:34 +00:00
|
|
|
echo "Couldn't find frequency to use exiting"
|
|
|
|
if [ $NETPLAN -eq 1 ]; then
|
2023-04-23 06:24:20 +00:00
|
|
|
echo "Netplan3"
|
2020-05-06 13:10:34 +00:00
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-04-23 06:24:20 +00:00
|
|
|
|
2020-05-06 13:10:34 +00:00
|
|
|
# ubuntu on boot exits at this point timing - issue with wpa_cli and scanning
|
2020-04-22 21:20:04 +00:00
|
|
|
CHAN=$(($FREQ2 - 2407 ))
|
2020-04-22 20:59:50 +00:00
|
|
|
CHAN=$(($CHAN / 5 ))
|
2020-04-22 00:22:35 +00:00
|
|
|
echo "channel is $CHAN for $SSID"
|
2023-04-23 07:03:16 +00:00
|
|
|
HOSTAPD=$(grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}')
|
2020-05-04 13:58:37 +00:00
|
|
|
echo "Hostapd set for $HOSTAPD"
|
|
|
|
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
|
2023-04-23 06:24:20 +00:00
|
|
|
/bin/systemctl --no-block restart hostapd
|
2023-04-23 06:59:52 +00:00
|
|
|
echo "Restarted hostapd"
|
2020-04-27 15:34:43 +00:00
|
|
|
fi
|
2023-04-23 06:24:20 +00:00
|
|
|
|
2020-04-27 14:44:17 +00:00
|
|
|
exit 0
|