From a1aaf70975c83cc7cab64935932b7ea0098f4f62 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Fri, 14 Apr 2023 08:50:23 -0500 Subject: [PATCH 01/12] 2210 2304 fixed https://bugs.launchpad.net/bugs/1951586 --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 6757846d3..918e66ebe 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -26,7 +26,7 @@ fi # 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 -if [ -f /run/netplan/wpa-$IFACE.conf ]; then +if [ -f /run/netplan/wpa-$IFACE.conf ] && ! $(grep country /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/\"//` echo "cover netplan lack of country=" From bb95816c793392a868439dd063655558b4ac5686 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 16 Apr 2023 04:31:03 -0500 Subject: [PATCH 02/12] use country value in hostapd if present --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 918e66ebe..2370c152f 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -26,11 +26,16 @@ fi # 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 -if [ -f /run/netplan/wpa-$IFACE.conf ] && ! $(grep country /run/netplan/wpa-$IFACE.conf); then +if [ -f /run/netplan/wpa-$IFACE.conf ] && $(grep country /run/netplan/wpa-$IFACE.conf); then + REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }') + sed -i -e "s/^country.*/country=$REG_DOM/" /etc/hostapd/hostapd.conf.iiab + cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf +else NETPLAN=1 SSID=`grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` echo "cover netplan lack of country=" - sed -i 's|ctrl_interface=/run/wpa_supplicant|&\ncountry=US|' /run/netplan/wpa-$IFACE.conf + sed -i 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf + fi # IIAB hint for NetworkManager # could scrape /etc/NetworkManager/system-connections/ looking for ssid From 2f321dc0a464f2cce71809e4b4379c4176270a62 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 16 Apr 2023 05:23:42 -0500 Subject: [PATCH 03/12] use 'iw reg get' in hostapd if present --- roles/network/tasks/sysd-netd-debian.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index f1b860d85..2be2772df 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -87,6 +87,17 @@ systemd: daemon_reload: yes +- name: Detect WiFi country code in use + command: iw reg get | grep country | grep -v UNSET | awk '{print $2}' | sed "s|:||" + register: REG_DOM + ignore_errors: True + when: discovered_wireless_iface != "none" + +- name: Set Wifi Region country code for hostapd when present + set_fact: + host_country_code: "{{ REG_DOM }}" + when: REG_DOM is defined and REG_DOM.stdout | length > 0 + - name: Clone wifi if needed systemd: name: iiab-clone-wifi From 7845a8bddc2d7abd3ef80a04cd2cf3b3a877aea2 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 16 Apr 2023 05:55:50 -0500 Subject: [PATCH 04/12] hints for iiab-hotspot-on|off --- roles/network/templates/hostapd/iiab-hotspot-off | 4 +++- roles/network/templates/hostapd/iiab-hotspot-on | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-hotspot-off b/roles/network/templates/hostapd/iiab-hotspot-off index eb5951c6b..98fb9dbf2 100755 --- a/roles/network/templates/hostapd/iiab-hotspot-off +++ b/roles/network/templates/hostapd/iiab-hotspot-off @@ -38,6 +38,8 @@ fi echo -e "\nPlease reboot to enable upstream WiFi access.\n" exit 0 {% endif %} +#is_raspbian +{% endif %} #wifi_up_down {% endif %} -{% endif %} +#network_enabled diff --git a/roles/network/templates/hostapd/iiab-hotspot-on b/roles/network/templates/hostapd/iiab-hotspot-on index 04d551774..3f809bf44 100755 --- a/roles/network/templates/hostapd/iiab-hotspot-on +++ b/roles/network/templates/hostapd/iiab-hotspot-on @@ -46,7 +46,10 @@ systemctl enable hostapd echo -e "\nPlease reboot to activate hostapd feature.\n" exit 0 {% endif %} +#is_raspbian +{% endif %} #wifi_up_down {% endif %} +#can_be_ap {% endif %} -{% endif %} +#network_enabled From 3ae4627956429bf7916c4e2b97b6962312e706e3 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 16 Apr 2023 19:20:11 -0500 Subject: [PATCH 05/12] use shell --- roles/network/tasks/sysd-netd-debian.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 2be2772df..680b8316e 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -88,14 +88,14 @@ daemon_reload: yes - name: Detect WiFi country code in use - command: iw reg get | grep country | grep -v UNSET | awk '{print $2}' | sed "s|:||" + 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" - name: Set Wifi Region country code for hostapd when present set_fact: - host_country_code: "{{ REG_DOM }}" + host_country_code: "{{ REG_DOM.stdout }}" when: REG_DOM is defined and REG_DOM.stdout | length > 0 - name: Clone wifi if needed From e63028f8eeb3d9d711e7cf8add5c9458a81a9f22 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 16 Apr 2023 19:38:48 -0500 Subject: [PATCH 06/12] record --- roles/network/tasks/restart.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index 1576a2af3..074ec5086 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -14,6 +14,16 @@ - 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 From f79f4c0f46cfc23b8eb8be56ffd8e241d0a0e5cd Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 18 Apr 2023 16:08:08 -0500 Subject: [PATCH 07/12] clearer logic --- .../templates/hostapd/iiab-test-wifi.j2 | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 2370c152f..e358d4dbb 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -26,17 +26,22 @@ fi # 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 -if [ -f /run/netplan/wpa-$IFACE.conf ] && $(grep country /run/netplan/wpa-$IFACE.conf); then - REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }') - sed -i -e "s/^country.*/country=$REG_DOM/" /etc/hostapd/hostapd.conf.iiab - cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf -else - NETPLAN=1 +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/\"//` - echo "cover netplan lack of country=" - sed -i 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf - + REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }') + if [ -z "$REG_DOM" ]; then + NETPLAN=1 + echo "cover netplan wifi client lack of country=" + 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" + if [ -f /etc/hostapd/hostapd.conf.iiab ]; then + sed -i 's|^country.*|country=$REG_DOM|' /etc/hostapd/hostapd.conf.iiab + cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf + fi + fi fi + # IIAB hint for NetworkManager # could scrape /etc/NetworkManager/system-connections/ looking for ssid if [ -f /etc/iiab/iiab.env ]; then From ff905ef5d878f830271bb0b16adf253640bf0f54 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 18 Apr 2023 23:35:43 -0500 Subject: [PATCH 08/12] dispatcher has a call to alter hostapd.conf --- roles/network/tasks/restart.yml | 8 ++++++++ roles/network/tasks/sysd-netd-debian.yml | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index 074ec5086..0e1ccd980 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -36,6 +36,14 @@ - { src: 'hostapd/hostapd.conf.j2', dest: '/etc/hostapd/hostapd.conf.iiab' } when: can_be_ap +- name: Enable & Restart networkd-dispatcher.service + systemd: + name: networkd-dispatcher + state: restarted + enabled: yes + masked: no + when: systemd_networkd_active + - name: Restart hostapd when WiFi is present but not when using WiFi as gateway with wifi_up_down False systemd: name: hostapd diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 680b8316e..e1b73db61 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -118,9 +118,3 @@ enabled: yes masked: no -- name: Enable & Restart networkd-dispatcher.service - systemd: - name: networkd-dispatcher - state: restarted - enabled: yes - masked: no From 27c3b1b9a08406e84ce27b3acb441a595c69e1c6 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 18 Apr 2023 23:33:56 -0500 Subject: [PATCH 09/12] Just set and let the next stanza in main handle the call --- roles/network/tasks/NM-debian.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roles/network/tasks/NM-debian.yml b/roles/network/tasks/NM-debian.yml index d5dad9ffc..200911a91 100644 --- a/roles/network/tasks/NM-debian.yml +++ b/roles/network/tasks/NM-debian.yml @@ -71,8 +71,9 @@ when: wan_ip != "dhcp" - name: Use systemd-networkd to handle br0 - include_tasks: sysd-netd-debian.yml - when: iiab_lan_iface == "br0" and not systemd_networkd_active + set_fact: + systemd_networkd_active: True + when: iiab_lan_iface == "br0" - name: Reload systemd systemd: From 5341cc6ca20af8ac0522736725f550f09723d7e5 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 19 Apr 2023 10:38:50 -0500 Subject: [PATCH 10/12] typo, use double quotes, always restart netplan wifi --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 6 +++--- roles/network/templates/hostapd/netd-disp2 | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index e358d4dbb..39ae8caa8 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -29,14 +29,14 @@ fi 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 }') + NETPLAN=1 if [ -z "$REG_DOM" ]; then - NETPLAN=1 echo "cover netplan wifi client lack of country=" - sed -i 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf + 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" if [ -f /etc/hostapd/hostapd.conf.iiab ]; then - sed -i 's|^country.*|country=$REG_DOM|' /etc/hostapd/hostapd.conf.iiab + sed -i "s|^country.*|country_code=$REG_DOM|" /etc/hostapd/hostapd.conf.iiab cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf fi fi diff --git a/roles/network/templates/hostapd/netd-disp2 b/roles/network/templates/hostapd/netd-disp2 index 78e258627..7b9218899 100644 --- a/roles/network/templates/hostapd/netd-disp2 +++ b/roles/network/templates/hostapd/netd-disp2 @@ -13,6 +13,9 @@ if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then systemctl stop wpa_supplicant systemctl restart hostapd systemctl start wpa_supplicant + if [ -f /run/netplan/wpa-wlan0.conf ]; then + systemctl restart netplan-wpa-wlan0.service + fi else echo "Upstream Channel greater than 13 or is the same - not changing hostapd.conf" fi From 3c3affb16a907e46e0ef32fdf8f0ac9f4a15bfb7 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 19 Apr 2023 10:44:39 -0500 Subject: [PATCH 11/12] softcode --- roles/network/templates/hostapd/netd-disp2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/network/templates/hostapd/netd-disp2 b/roles/network/templates/hostapd/netd-disp2 index 7b9218899..e6a8fca72 100644 --- a/roles/network/templates/hostapd/netd-disp2 +++ b/roles/network/templates/hostapd/netd-disp2 @@ -13,8 +13,8 @@ if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then systemctl stop wpa_supplicant systemctl restart hostapd systemctl start wpa_supplicant - if [ -f /run/netplan/wpa-wlan0.conf ]; then - systemctl restart netplan-wpa-wlan0.service + 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" From b286d9d6e940195d7d6dbc58479d0a98489c5ed8 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 19 Apr 2023 10:46:45 -0500 Subject: [PATCH 12/12] easier diff --- roles/network/templates/hostapd/iiab-test-wifi.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/iiab-test-wifi.j2 b/roles/network/templates/hostapd/iiab-test-wifi.j2 index 39ae8caa8..205f77fc7 100755 --- a/roles/network/templates/hostapd/iiab-test-wifi.j2 +++ b/roles/network/templates/hostapd/iiab-test-wifi.j2 @@ -27,9 +27,9 @@ fi # https://bugs.launchpad.net/netplan/+bug/1951586 # WiFi country code progress on arm64 OS's discussed on #3078 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/\"//` REG_DOM=$(grep country /run/netplan/wpa-$IFACE.conf | awk -F = '{ print $2 }') - NETPLAN=1 if [ -z "$REG_DOM" ]; then echo "cover netplan wifi client lack of country=" sed -i "s|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|" /run/netplan/wpa-$IFACE.conf