From 9241a9d47b67ff6616a5bd669d948ae51186a61e Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 7 May 2020 12:28:19 -0400 Subject: [PATCH 01/46] captiveportal_enabled: False in default_vars.yml --- vars/default_vars.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/default_vars.yml b/vars/default_vars.yml index 953e7d51c..9d3875dac 100644 --- a/vars/default_vars.yml +++ b/vars/default_vars.yml @@ -152,7 +152,7 @@ dns_jail_enabled: False # July 2018 (https://github.com/iiab/iiab/pull/870) and that @georgejhunt # extensively later refined (PRs #1179, #1300, #1327, #2070). captiveportal_install: True -captiveportal_enabled: True +captiveportal_enabled: False captiveportal_port: 9090 captiveportal_splash_page: / # You might also want to set iiab_home_url (above!) From 7344fccb8ed1525603c9371fc6413b139479d129 Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 7 May 2020 12:29:05 -0400 Subject: [PATCH 02/46] captiveportal_enabled: False in local_vars_big.yml --- vars/local_vars_big.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/local_vars_big.yml b/vars/local_vars_big.yml index e69e4c303..82ed09cd8 100644 --- a/vars/local_vars_big.yml +++ b/vars/local_vars_big.yml @@ -92,7 +92,7 @@ dns_jail_enabled: False # July 2018 (https://github.com/iiab/iiab/pull/870) and that @georgejhunt # extensively later refined (PRs #1179, #1300, #1327, #2070). captiveportal_install: True -captiveportal_enabled: True +captiveportal_enabled: False captiveportal_splash_page: / # You might also want to set iiab_home_url (above!) # In a pinch, disable Captive Portal using instructions in http://FAQ.IIAB.IO From 6949ff11c31fa24a2c1dd37e39bce89505d1f471 Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 7 May 2020 12:29:42 -0400 Subject: [PATCH 03/46] captiveportal_enabled: False in local_vars_medium.yml --- vars/local_vars_medium.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/local_vars_medium.yml b/vars/local_vars_medium.yml index d2a33a1a6..21b070412 100644 --- a/vars/local_vars_medium.yml +++ b/vars/local_vars_medium.yml @@ -92,7 +92,7 @@ dns_jail_enabled: False # July 2018 (https://github.com/iiab/iiab/pull/870) and that @georgejhunt # extensively later refined (PRs #1179, #1300, #1327, #2070). captiveportal_install: True -captiveportal_enabled: True +captiveportal_enabled: False captiveportal_splash_page: / # You might also want to set iiab_home_url (above!) # In a pinch, disable Captive Portal using instructions in http://FAQ.IIAB.IO From 3bc6483d6e350a5cababf9de6aa48c0f19ca5e9c Mon Sep 17 00:00:00 2001 From: A Holt Date: Thu, 7 May 2020 12:30:10 -0400 Subject: [PATCH 04/46] captiveportal_enabled: False in local_vars_min.yml --- vars/local_vars_min.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/local_vars_min.yml b/vars/local_vars_min.yml index eb8cb8ca3..a650aaebd 100644 --- a/vars/local_vars_min.yml +++ b/vars/local_vars_min.yml @@ -92,7 +92,7 @@ dns_jail_enabled: False # July 2018 (https://github.com/iiab/iiab/pull/870) and that @georgejhunt # extensively later refined (PRs #1179, #1300, #1327, #2070). captiveportal_install: True -captiveportal_enabled: True +captiveportal_enabled: False captiveportal_splash_page: / # You might also want to set iiab_home_url (above!) # In a pinch, disable Captive Portal using instructions in http://FAQ.IIAB.IO From 8669a97d1833743bc83c74b6b7a4673ae7829748 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 21 Apr 2020 19:21:12 -0500 Subject: [PATCH 05/46] ap0 - split cloning --- .../templates/hostapd/clone-wifi.service.j2 | 20 +++++++++++++++++++ .../templates/hostapd/hostapd.service.j2 | 17 ++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 roles/network/templates/hostapd/clone-wifi.service.j2 diff --git a/roles/network/templates/hostapd/clone-wifi.service.j2 b/roles/network/templates/hostapd/clone-wifi.service.j2 new file mode 100644 index 000000000..ee351f95b --- /dev/null +++ b/roles/network/templates/hostapd/clone-wifi.service.j2 @@ -0,0 +1,20 @@ +[Unit] +Description=IIAB ap0 clone wifi device +Wants=network-pre.target +After=network-pre.target +Before=dhcpcd.service +Before=wpa_supplicant.service +Before=wpa_supplicant@{{ discovered_wireless_iface }}.service +Before=network-manager.service +Before=netplan-wpa@{{ discovered_wireless_iface }}.service +Before=hostapd.service + +[Service] +Type=simple +ExecStartPre=-/sbin/iw phy phy0 interface add ap0 type __ap +ExecStartPre=-/sbin/ip link set ap0 address {{ ap0_mac_addr }} +ExecStart=-/sbin/ip link set ap0 up +ExecStopPost=-/sbin/iw dev ap0 del + +[Install] +WantedBy=multi-user.target diff --git a/roles/network/templates/hostapd/hostapd.service.j2 b/roles/network/templates/hostapd/hostapd.service.j2 index a6ec1f79b..92a2e10d0 100644 --- a/roles/network/templates/hostapd/hostapd.service.j2 +++ b/roles/network/templates/hostapd/hostapd.service.j2 @@ -2,29 +2,16 @@ Description=Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator Wants=network-pre.target After=network-pre.target -{% if is_raspbian %} -Before=dhcpcd.service -{% endif %} -Before=wpa_supplicant.service -Before=wpa_supplicant@{{ discovered_wireless_iface }}.service -{% if network_manager_active %} -Before=network-manager.service -{% endif %} -{% if is_ubuntu and netplan.stdout.find("yaml") != -1 %} -Before=netplan-wpa-{{ discovered_wireless_iface }}.service -{% endif %} -Before=network.target +After=clone-wifi.service +Requires=clone-wifi.service [Service] Type=forking Restart=on-failure RestartSec=2 PIDFile=/run/hostapd.pid -ExecStartPre=-/sbin/iw phy phy0 interface add ap0 type __ap -ExecStartPre=-/sbin/ip link set ap0 address {{ ap0_mac_addr }} ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid /etc/hostapd/hostapd.conf ExecStartPost=-/sbin/ip link set ap0 up -ExecStopPost=-/sbin/iw dev ap0 del [Install] WantedBy=multi-user.target From e125537c0cef7bbb3aeb3e6a1f056681fc8b20c9 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 21 Apr 2020 19:22:35 -0500 Subject: [PATCH 06/46] ap0 - introduce wifi-test.service --- roles/network/templates/hostapd/test-wifi | 23 +++++++++++++++++++ .../templates/hostapd/wifi-test.service.j2 | 17 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 roles/network/templates/hostapd/test-wifi create mode 100644 roles/network/templates/hostapd/wifi-test.service.j2 diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi new file mode 100755 index 000000000..8cbc8e01c --- /dev/null +++ b/roles/network/templates/hostapd/test-wifi @@ -0,0 +1,23 @@ +IFACE={{ discovered_wireless_iface }} +SSID="" +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/\"> +fi + +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/\"// | > +fi +if [ -f /etc/iiab/iiab.env ]; then + source /etc/iiab/iiab.env + if [ ! -z $CLIENT_SSID ]; then + SSID=$CLIENT_SSID + fi +fi +sleep 3 +wpa_cli -i wlan0 scan > /dev/null +sleep 2 +FREQ=`wpa_cli -i wlan0 scan_results | grep $SSID | awk '{print $2}'` +echo "frequency is $FREQ for $SSID" +CHAN=$(((($FREQ - 2407)) / 5 )) +echo "channel is $CHAN for $SSID" + diff --git a/roles/network/templates/hostapd/wifi-test.service.j2 b/roles/network/templates/hostapd/wifi-test.service.j2 new file mode 100644 index 000000000..7c5ea4e42 --- /dev/null +++ b/roles/network/templates/hostapd/wifi-test.service.j2 @@ -0,0 +1,17 @@ +[Unit] +Description=IIAB find channel freq for ssid +After=wpa_supplicant.service +Wants=wpa_supplicant.service +Requires=wpa_supplicant.service +Before=hostapd.service +Before=dhcpcd.service +Before=network-manager.service +Before=netplan-wpa-{{ discovered_wireless_iface }}.service +Before=network.target + +[Service] +ExecStart=/sbin/test-wifi + +[Install] +WantedBy=multi-user.target + From c6a21403299bb35b7e41ee9c6fbb2d448921656b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 08:45:48 -0500 Subject: [PATCH 07/46] edit hostapd on the fly --- roles/network/templates/hostapd/test-wifi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 8cbc8e01c..6565efcf7 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -20,4 +20,6 @@ FREQ=`wpa_cli -i wlan0 scan_results | grep $SSID | awk '{print $2}'` echo "frequency is $FREQ for $SSID" CHAN=$(((($FREQ - 2407)) / 5 )) echo "channel is $CHAN for $SSID" - +cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf +sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf +systemctl reload-daemon From 575b66fb6e3c6c3d6cacf4d241a3dc3f71cfca2d Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 12:38:49 -0500 Subject: [PATCH 08/46] use the new routine --- roles/network/tasks/hostapd.yml | 40 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 8ecd42cd1..637169b02 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -19,22 +19,16 @@ host_channel: "{{ current_host_channel.stdout }}" when: current_host_channel.stdout is defined and current_host_channel.stdout != "" and current_host_channel.stdout|int <= 13 -- name: Create /etc/hostapd/hostapd.conf from template +- name: Create /etc/hostapd/hostapd.conf and backup .iiab from template template: - src: hostapd/hostapd.conf.j2 - dest: /etc/hostapd/hostapd.conf - owner: root - group: root - mode: 0644 - when: discovered_wireless_iface != "none" - -- name: Create backup /etc/hostapd/hostapd.conf.iiab from template - template: - src: hostapd/hostapd.conf.j2 - dest: /etc/hostapd/hostapd.conf.iiab owner: root group: root mode: 0644 + src: "{{ item.src }}" + dest: "{{ item.dest }}" + with_items: + - { src: 'hostapd/hostapd.conf.j2', dest: '/etc/hostapd/hostapd.conf' } + - { src: 'hostapd/hostapd.conf.j2', dest: '/etc/hostapd/hostapd.conf.iiab' } when: discovered_wireless_iface != "none" - name: Generate new random mac address for ap0 @@ -47,11 +41,16 @@ - name: Use custom 'hostapd' systemd service unit file using ap0 when wifi_up_down template: - src: hostapd/hostapd.service.j2 - dest: /etc/systemd/system/hostapd.service owner: root group: root mode: 0644 + src: "{{ item.src }}" + dest: "{{ item.dest }}" + with_items: + - { src: 'hostapd/hostapd.service.j2', dest: '/etc/systemd/system/hostapd.service' } + - { src: 'hostapd/clone-wifi.service.j2', dest: '/etc/systemd/system/clone-wifi.service' } + - { src: 'hostapd/wifi-test.service.j2', dest: '/etc/systemd/system/wifi-test.service' } + - { src: 'hostapd/test-wifi', dest: '/sbin/test-wifi' } when: discovered_wireless_iface != "none" and wifi_up_down - name: Use custom 'hostapd' systemd service unit file for {{ discovered_wireless_iface }} when not wifi_up_down @@ -137,7 +136,18 @@ systemd: name: hostapd enabled: yes - when: hostapd_enabled + when: hostapd_enabled and not wifi_up_down + +- name: Enable the Access Point 'hostapd' service + systemd: + name: "{{ item }}" + masked: no + enabled: yes + with_items: + - hostapd.service + - clone-wifi.service + - wifi-test.service + when: hostapd_enabled and wifi_up_down - name: Record HOSTAPD_ENABLED to {{ iiab_env_file }} lineinfile: From 000d4ec35ca3b20c8aae287e7a33f6a6be6c2e17 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 14:53:28 -0500 Subject: [PATCH 09/46] ap0 notes --- roles/network/templates/hostapd/README.ap0 | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 roles/network/templates/hostapd/README.ap0 diff --git a/roles/network/templates/hostapd/README.ap0 b/roles/network/templates/hostapd/README.ap0 new file mode 100644 index 000000000..ea53ec1da --- /dev/null +++ b/roles/network/templates/hostapd/README.ap0 @@ -0,0 +1,10 @@ +start up order +# network-pre bridge is created +clone-wifi +wpa_supplicant #--dbus version does not start the interface directly +test-wifi # uses dbus to scan the network grabbing the channel alters hostapd.conf if needed +hostapd + +# network +wpa_supplicant started by dhcpcd, wpa_supplicant@$IFACE netplan-wpa-$IFACE, or NetworkManager + From 37ed8a6ba424c7cc992f1b68c79c2f6dac2fb058 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 14:57:04 -0500 Subject: [PATCH 10/46] keep the pids known --- roles/network/templates/hostapd/clone-wifi.service.j2 | 4 ++-- roles/network/templates/hostapd/hostapd.service.j2 | 4 ++-- roles/network/templates/hostapd/wifi-test.service.j2 | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/roles/network/templates/hostapd/clone-wifi.service.j2 b/roles/network/templates/hostapd/clone-wifi.service.j2 index ee351f95b..c7171d66f 100644 --- a/roles/network/templates/hostapd/clone-wifi.service.j2 +++ b/roles/network/templates/hostapd/clone-wifi.service.j2 @@ -10,11 +10,11 @@ Before=netplan-wpa@{{ discovered_wireless_iface }}.service Before=hostapd.service [Service] -Type=simple +Type=oneshot +RemainAfterExit=yes ExecStartPre=-/sbin/iw phy phy0 interface add ap0 type __ap ExecStartPre=-/sbin/ip link set ap0 address {{ ap0_mac_addr }} ExecStart=-/sbin/ip link set ap0 up -ExecStopPost=-/sbin/iw dev ap0 del [Install] WantedBy=multi-user.target diff --git a/roles/network/templates/hostapd/hostapd.service.j2 b/roles/network/templates/hostapd/hostapd.service.j2 index 92a2e10d0..a60320519 100644 --- a/roles/network/templates/hostapd/hostapd.service.j2 +++ b/roles/network/templates/hostapd/hostapd.service.j2 @@ -7,8 +7,8 @@ Requires=clone-wifi.service [Service] Type=forking -Restart=on-failure -RestartSec=2 +#Restart=on-failure +#RestartSec=2 PIDFile=/run/hostapd.pid ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid /etc/hostapd/hostapd.conf ExecStartPost=-/sbin/ip link set ap0 up diff --git a/roles/network/templates/hostapd/wifi-test.service.j2 b/roles/network/templates/hostapd/wifi-test.service.j2 index 7c5ea4e42..39f87daba 100644 --- a/roles/network/templates/hostapd/wifi-test.service.j2 +++ b/roles/network/templates/hostapd/wifi-test.service.j2 @@ -10,6 +10,8 @@ Before=netplan-wpa-{{ discovered_wireless_iface }}.service Before=network.target [Service] +Type=oneshot +RemainAfterExit=yes ExecStart=/sbin/test-wifi [Install] From 964a592679abe9607f49ce0a71e7ddbb5cd8e4e5 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 15:56:57 -0500 Subject: [PATCH 11/46] service touch-ups --- roles/network/tasks/hostapd.yml | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 637169b02..5e4778650 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -39,19 +39,19 @@ set_fact: ap0_mac_addr: "{{ ap0_mac.stdout }}" -- name: Use custom 'hostapd' systemd service unit file using ap0 when wifi_up_down +- name: Use custom 'hostapd' systemd service unit file using ap0 template: owner: root group: root - mode: 0644 src: "{{ item.src }}" dest: "{{ item.dest }}" + mode: "{{ item.mode }}" with_items: - - { src: 'hostapd/hostapd.service.j2', dest: '/etc/systemd/system/hostapd.service' } - - { src: 'hostapd/clone-wifi.service.j2', dest: '/etc/systemd/system/clone-wifi.service' } - - { src: 'hostapd/wifi-test.service.j2', dest: '/etc/systemd/system/wifi-test.service' } - - { src: 'hostapd/test-wifi', dest: '/sbin/test-wifi' } - when: discovered_wireless_iface != "none" and wifi_up_down + - { src: 'hostapd/hostapd.service.j2', dest: '/etc/systemd/system/hostapd.service', mode: '0644' } + - { src: 'hostapd/clone-wifi.service.j2', dest: '/etc/systemd/system/clone-wifi.service', mode: '0644' } + - { src: 'hostapd/wifi-test.service.j2', dest: '/etc/systemd/system/wifi-test.service', mode: '0644'} + - { src: 'hostapd/test-wifi', dest: '/sbin/test-wifi', mode: '0755' } + when: discovered_wireless_iface != "none" - name: Use custom 'hostapd' systemd service unit file for {{ discovered_wireless_iface }} when not wifi_up_down template: @@ -138,10 +138,18 @@ enabled: yes when: hostapd_enabled and not wifi_up_down -- name: Enable the Access Point 'hostapd' service +- name: Disable ap0 related services + systemd: + name: "{{ item }}" + enabled: no + with_items: + - clone-wifi.service + - wifi-test.service + when: not wifi_up_down + +- name: Enable the Access Point 'hostapd' and ap0 related services systemd: name: "{{ item }}" - masked: no enabled: yes with_items: - hostapd.service From 4ad83f787b80609db8e5d87e745ffdb770a169bd Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 15:59:50 -0500 Subject: [PATCH 12/46] test-wifi touchups --- roles/network/templates/hostapd/test-wifi | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 6565efcf7..6634eee43 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -1,11 +1,12 @@ +#!/bin/bash IFACE={{ discovered_wireless_iface }} SSID="" 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/\"> + SSID=`grep ssid /run/netplan/wpa-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` fi 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/\"// | > + SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` fi if [ -f /etc/iiab/iiab.env ]; then source /etc/iiab/iiab.env @@ -14,11 +15,15 @@ if [ -f /etc/iiab/iiab.env ]; then fi fi sleep 3 -wpa_cli -i wlan0 scan > /dev/null +wpa_cli -i $IFACE scan > /dev/null sleep 2 -FREQ=`wpa_cli -i wlan0 scan_results | grep $SSID | awk '{print $2}'` +FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'` +if [ ! $FREQ -lt 2485 ]; then + FREQ="" +fi echo "frequency is $FREQ for $SSID" -CHAN=$(((($FREQ - 2407)) / 5 )) +CHAN=$(($FREQ - 2407 )) +CHAN=$(($CHAN / 5 )) echo "channel is $CHAN for $SSID" cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf From 842a14269a8cdcba67799ed69e504899b4a673ed Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 16:20:04 -0500 Subject: [PATCH 13/46] better handling of 2.4/5 on the same ssid --- roles/network/templates/hostapd/test-wifi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 6634eee43..2dc7ba2eb 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -18,11 +18,14 @@ sleep 3 wpa_cli -i $IFACE scan > /dev/null sleep 2 FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'` -if [ ! $FREQ -lt 2485 ]; then - FREQ="" -fi -echo "frequency is $FREQ for $SSID" -CHAN=$(($FREQ - 2407 )) +for result in $FREQ; do + echo "frequency $result found for $SSID" + if [ $result -lt 2485 ]; then + FREQ2=$result + fi +done +echo "Using $FREQ2 for $SSID" +CHAN=$(($FREQ2 - 2407 )) CHAN=$(($CHAN / 5 )) echo "channel is $CHAN for $SSID" cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf From 359f2b4b1cc9e94237cef5193df2b1c1faa63ca3 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 22 Apr 2020 17:41:24 -0500 Subject: [PATCH 14/46] br0 online tuning --- roles/network/templates/hostapd/test-wifi | 2 +- roles/network/templates/network/systemd-br0-network.j2 | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 2dc7ba2eb..758800df1 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -30,4 +30,4 @@ CHAN=$(($CHAN / 5 )) echo "channel is $CHAN for $SSID" cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf -systemctl reload-daemon +systemctl daemon-reload diff --git a/roles/network/templates/network/systemd-br0-network.j2 b/roles/network/templates/network/systemd-br0-network.j2 index 21dd6e1d2..619196b8b 100644 --- a/roles/network/templates/network/systemd-br0-network.j2 +++ b/roles/network/templates/network/systemd-br0-network.j2 @@ -6,6 +6,7 @@ Name=br0 Address={{ lan_ip }}/19 LinkLocalAddressing=no ConfigureWithoutCarrier=yes +RequiredForOnline=degraded-carrier # Commenting the below line as it has been causing race/looping issues between dnsmasq and systemd-resolved # IIAB ticket #1747 #DNS={{ lan_ip }} From 83793e72e4e243303ae98bfc79ab7cef1e31adb6 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 27 Apr 2020 09:44:17 -0500 Subject: [PATCH 15/46] running model --- roles/network/templates/hostapd/test-wifi | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 758800df1..eef776c15 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -14,20 +14,29 @@ if [ -f /etc/iiab/iiab.env ]; then SSID=$CLIENT_SSID fi fi -sleep 3 -wpa_cli -i $IFACE scan > /dev/null sleep 2 +wpa_cli -i $IFACE scan > /dev/null +sleep 1 FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'` for result in $FREQ; do - echo "frequency $result found for $SSID" + echo "frequency is $result for $SSID" if [ $result -lt 2485 ]; then FREQ2=$result fi done echo "Using $FREQ2 for $SSID" + CHAN=$(($FREQ2 - 2407 )) CHAN=$(($CHAN / 5 )) echo "channel is $CHAN for $SSID" cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf sed -i -e "s/^channel.*/channel=$CHAN/" /etc/hostapd/hostapd.conf -systemctl daemon-reload +systemctl stop wpa_supplicant +#systemctl daemon-reload +systemctl start hostapd +#systemctl stop wpa_supplicant +systemctl start wpa_supplicant +systemctl restart netplan-wpa-wlan0.service +systemctl stop dnsmasq.service +systemctl start dnsmasq.service +exit 0 From 6fb76de522eeee0e5ead309bbdfef4ad6d30f6cd Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 27 Apr 2020 10:34:43 -0500 Subject: [PATCH 16/46] deal with netplan --- roles/network/templates/hostapd/test-wifi | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index eef776c15..8a3e12da7 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -1,13 +1,23 @@ #!/bin/bash IFACE={{ discovered_wireless_iface }} +NETPLAN=0 SSID="" -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/\"//` +# covers systemd-networkd +if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then + SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` fi +# covers raspbian 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 +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/\"//` +fi +# IIAB hint for NetworkManager if [ -f /etc/iiab/iiab.env ]; then source /etc/iiab/iiab.env if [ ! -z $CLIENT_SSID ]; then @@ -32,11 +42,11 @@ echo "channel is $CHAN for $SSID" 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 -#systemctl daemon-reload systemctl start hostapd -#systemctl stop wpa_supplicant systemctl start wpa_supplicant -systemctl restart netplan-wpa-wlan0.service +if [ $NETPLAN -eq 1 ]; then + systemctl restart netplan-wpa-wlan0.service +fi systemctl stop dnsmasq.service systemctl start dnsmasq.service exit 0 From f150d09eae63289c5180612b769a14499e979568 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 27 Apr 2020 10:55:25 -0500 Subject: [PATCH 17/46] wifi-test needs before networkd --- roles/network/templates/hostapd/wifi-test.service.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/wifi-test.service.j2 b/roles/network/templates/hostapd/wifi-test.service.j2 index 39f87daba..a22f0b42e 100644 --- a/roles/network/templates/hostapd/wifi-test.service.j2 +++ b/roles/network/templates/hostapd/wifi-test.service.j2 @@ -2,9 +2,9 @@ Description=IIAB find channel freq for ssid After=wpa_supplicant.service Wants=wpa_supplicant.service -Requires=wpa_supplicant.service Before=hostapd.service Before=dhcpcd.service +Before=wpa_supplicant@{{ discovered_wireless_iface }}.service Before=network-manager.service Before=netplan-wpa-{{ discovered_wireless_iface }}.service Before=network.target From 9a55fdff9c90140a78f050d3f03964e8a218a730 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 27 Apr 2020 10:57:38 -0500 Subject: [PATCH 18/46] let wifi test start hostapd --- 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 5e4778650..865ce6bfd 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -152,7 +152,7 @@ name: "{{ item }}" enabled: yes with_items: - - hostapd.service +# - hostapd.service - clone-wifi.service - wifi-test.service when: hostapd_enabled and wifi_up_down From 664b540fdb2a8bddb5707e7408b4a5c5fc9c41ea Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 27 Apr 2020 11:10:37 -0500 Subject: [PATCH 19/46] update iiab-hotspot-on|off --- roles/network/templates/hostapd/clone-wifi.service.j2 | 1 + roles/network/templates/network/iiab-hotspot-off | 6 +++++- roles/network/templates/network/iiab-hotspot-on | 5 +++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/roles/network/templates/hostapd/clone-wifi.service.j2 b/roles/network/templates/hostapd/clone-wifi.service.j2 index c7171d66f..9fc83ddb8 100644 --- a/roles/network/templates/hostapd/clone-wifi.service.j2 +++ b/roles/network/templates/hostapd/clone-wifi.service.j2 @@ -15,6 +15,7 @@ RemainAfterExit=yes ExecStartPre=-/sbin/iw phy phy0 interface add ap0 type __ap ExecStartPre=-/sbin/ip link set ap0 address {{ ap0_mac_addr }} ExecStart=-/sbin/ip link set ap0 up +ExecStop=-/sbin/iw dev ap0 del [Install] WantedBy=multi-user.target diff --git a/roles/network/templates/network/iiab-hotspot-off b/roles/network/templates/network/iiab-hotspot-off index 7cc396dac..217bee07e 100755 --- a/roles/network/templates/network/iiab-hotspot-off +++ b/roles/network/templates/network/iiab-hotspot-off @@ -17,12 +17,16 @@ sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} #if grep -qi raspbian /etc/*release; then # ip link set dev wlan0 promisc on #fi + {% else %} systemctl disable hostapd systemctl stop hostapd sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} -echo " IIAB hotspot access point Disabled" {% if wifi_up_down %} +systemctl disable clone-wifi.service +systemctl disable wifi-test.service +systemctl stop clone-wifi.service +echo " IIAB hotspot access point Disabled" exit 0 {% else %} sed -i -e "s|managed=0|managed=1|" /etc/NetworkManager/conf.d/wifi-manage.conf diff --git a/roles/network/templates/network/iiab-hotspot-on b/roles/network/templates/network/iiab-hotspot-on index 03c038197..fd65c2ab5 100755 --- a/roles/network/templates/network/iiab-hotspot-on +++ b/roles/network/templates/network/iiab-hotspot-on @@ -1,5 +1,4 @@ #!/bin/bash - {% if is_raspbian %} # just do what we have always done in hotspot-on cp -f /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf @@ -23,13 +22,15 @@ sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} #fi {% else %} -systemctl enable hostapd sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} {% if wifi_up_down %} +systemctl enable clone-wifi.service +systemctl enable wifi-test.service echo -e "\nPlease reboot to activate hostapd feature.\n" exit 0 {% else %} sed -i -e "s|managed=1|managed=0|" /etc/NetworkManager/conf.d/wifi-manage.conf +systemctl enable hostapd echo -e "\nPlease reboot to activate hostapd feature.\n" exit 0 {% endif %} From ec7ad926d14bae31c555ac288c5bc0635d87c199 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 29 Apr 2020 12:47:43 -0500 Subject: [PATCH 20/46] netplan country= workaround --- roles/network/templates/hostapd/test-wifi | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 8a3e12da7..7903efe19 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -16,6 +16,7 @@ fi 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/\"//` + sed 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf fi # IIAB hint for NetworkManager if [ -f /etc/iiab/iiab.env ]; then From 1366bf507d57497e2541dba8ec37569563528a89 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 07:55:29 -0500 Subject: [PATCH 21/46] show what is being recoreded in iiab_env_file --- roles/network/tasks/computed_network.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/roles/network/tasks/computed_network.yml b/roles/network/tasks/computed_network.yml index 08540b94e..61dda59ce 100644 --- a/roles/network/tasks/computed_network.yml +++ b/roles/network/tasks/computed_network.yml @@ -128,20 +128,18 @@ iiab_lan_iface: "{{ user_lan_iface }}" when: not (user_lan_iface == "auto") -- name: Record IIAB_WAN_DEVICE to {{ iiab_env_file }} +- name: Record IIAB_WAN_DEVICE={{ iiab_wan_iface }} to {{ iiab_env_file }} lineinfile: path: "{{ iiab_env_file }}" regexp: '^IIAB_WAN_DEVICE=*' line: 'IIAB_WAN_DEVICE={{ iiab_wan_iface }}' - when: not installing #REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml -- name: Record IIAB_LAN_DEVICE to {{ iiab_env_file }} +- name: Record IIAB_LAN_DEVICE={{ iiab_lan_iface }} to {{ iiab_env_file }} lineinfile: path: "{{ iiab_env_file }}" regexp: '^IIAB_LAN_DEVICE=*' line: 'IIAB_LAN_DEVICE={{ iiab_lan_iface }}' state: present - when: not installing #REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml - name: Add 'computed_network' variable values to {{ iiab_ini_file }} ini_file: From c51575f02b3de3b39ab3b7fd037193ee3118b89b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 07:51:45 -0500 Subject: [PATCH 22/46] network main cleanup --- roles/network/tasks/main.yml | 55 +++++++++++------------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index fe61a9c0f..e1264b134 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -1,4 +1,5 @@ -- include_tasks: detected_network.yml +- name: detected_network + include_tasks: detected_network.yml - name: IF WIFI IS PRIMARY GATEWAY, PLEASE RUN 'iiab-hotspot-on' MANUALLY set_fact: @@ -11,25 +12,8 @@ # in hostapd.yml for later use by... # /usr/libexec/iiab-startup.sh, iiab-hotspot-off & iiab-hotspot-on # -# Separate Idea, Not Without Risks: should WiFi-as-gateway detection logic -# be encapsulated into roles/network/tasks/hostapd.yml in future? Whereas -# today "./runtags hostapd" doesn't exist & "./runtags AP" is UNSUPPORTED! - -#- name: RPi - reboot to AP post install - installed via wifi so the services are ready -# set_fact: -# iiab_lan_iface: br0 -# iiab_wan_iface: "{{ discovered_wired_iface }}" -# iiab_wireless_lan_iface: "{{ discovered_wireless_iface }}" -# iiab_wired_lan_iface: "" -# when: is_raspbian and discovered_wireless_iface is defined and discovered_wireless_iface == iiab_wan_iface and reboot_to_AP - -- include_tasks: computed_network.yml - -#- name: RPi - don't reboot to AP post install - installed via wifi - don't blow away current network -# set_fact: -# no_net_restart: True -# hostapd_enabled: False -# when: is_raspbian and discovered_wireless_iface is defined and discovered_wired_iface != iiab_wan_iface +- name: computed_network + include_tasks: computed_network.yml - name: Configure wondershaper include_tasks: wondershaper.yml @@ -53,42 +37,37 @@ when: is_ubuntu and not is_ubuntu_16 #### Start services - -- include_tasks: avahi.yml -- include_tasks: hostapd.yml -- include_tasks: computed_services.yml -- include_tasks: enable_services.yml - +- name: avahi + include_tasks: avahi.yml +- name: hostapd + include_tasks: hostapd.yml +- name: computed_services + include_tasks: computed_services.yml +- name: enable_services + include_tasks: enable_services.yml #### End services #### Start network layout - -- name: Redhat networking - include_tasks: ifcfg_mods.yml - when: is_redhat | bool - #and not installing +#- name: Redhat networking +# include_tasks: ifcfg_mods.yml +# when: is_redhat | bool - name: NetworkManager in use include_tasks: NM-debian.yml when: is_debuntu and network_manager_active - #and not installing - name: systemd-networkd in use include_tasks: sysd-netd-debian.yml when: is_debuntu and systemd_networkd_active - #and not installing - name: Raspbian uses dhcpcd only with no N-M or SYS-NETD active include_tasks: rpi_debian.yml when: is_raspbian - #and not installing - name: Not RPi, Not NetworkManager, Not systemd-networkd in use include_tasks: debian.yml when: (not is_raspbian and not network_manager_active and not systemd_networkd_active and is_debuntu) or is_ubuntu_16 - #and not installing - #### end network layout -- include_tasks: restart.yml - when: not installing # REMOVE THIS LINE IF installing IS ALWAYS false AS SET IN roles/0-init/defaults/main.yml +- name: Restart services + include_tasks: restart.yml From b60d4957a15005bb8b3c8b3d383bff6249ad20e6 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 07:56:55 -0500 Subject: [PATCH 23/46] ubuntu no reboot --- roles/network/tasks/restart.yml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index c87609893..ec9334840 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -2,13 +2,26 @@ #iiab_wireless_lan_iface(ap0) - wifi_up_down True needs hw #hostapd_enabled False - set in hostapd.yml to avoid the enable with wifi_up_down False #no_net_restart: True - main.yml discovered_wireless_iface == iiab_wan_iface -- name: Restart hostapd when WiFi is present but not when using WiFi as gateway +- name: Restart hostapd when WiFi is present but not when using WiFi as gateway with wifi_up_down False systemd: name: hostapd state: restarted + when: hostapd_enabled and (wifi_up_down or not no_net_restart) # when: iiab_wireless_lan_iface is defined and hostapd_enabled and discovered_wireless_iface != iiab_wan_iface # when: hostapd_enabled and iiab_wireless_lan_iface is defined and discovered_wireless_iface == iiab_wireless_lan_iface - when: hostapd_enabled and not no_net_restart + +- name: Restart clone-wifi wpa_supplicant service + systemd: + name: "{{ item }}" + state: restarted + with_items: + - clone-wifi + - wpa_supplicant + when: wifi_up_down and hostapd_enabled and is_ubuntu + +- name: Reload netplan for Wifi gateway on Ubuntu 18+ + shell: netplan apply + when: wifi_up_down and netplan.stdout.find("yaml") != -1 - name: Start named service systemd: @@ -72,7 +85,8 @@ - name: Checking if WiFi slave is active shell: brctl show br0 | grep {{ iiab_wireless_lan_iface }} | wc -l - when: hostapd_enabled and discovered_wireless_iface != iiab_wan_iface and iiab_lan_iface == "br0" +# when: hostapd_enabled and discovered_wireless_iface != iiab_wan_iface and iiab_lan_iface == "br0" + when: hostapd_enabled and iiab_lan_iface == "br0" register: wifi_slave - name: Restart hostapd if WiFi slave is inactive @@ -82,6 +96,8 @@ when: hostapd_enabled and wifi_slave.stdout is defined and wifi_slave.stdout == 0 #both interfaces.d and systemd-networkd should have br0 available and Appliance lacks br0 +#keep an eye on legacy wifi installs where br0 is present but not 'online' with an ip address +#due to hostapd didn't go to a carrier state. All others should get dnsmasq restarted - name: User choice of dnsmasq or dhcpd - restarting {{ dhcp_service2 }} systemd: name: "{{ dhcp_service2 }}" @@ -89,5 +105,3 @@ when: (not no_net_restart) or wifi_up_down #when: (iiab_network_mode != "Appliance") # Sufficient b/c br0 exists thanks to /etc/network/interfaces.d/iiab #when: iiab_network_mode != "Appliance" and iiab_wan_iface != discovered_wireless_iface -#keep an eye on legacy wifi installs where br0 is present but not 'online' with an ip address -#due to hostapd didn't go to a carrier state. All others should get dnsmasq restarted From 1bdd038b41039d54d72d4ab457c1d38791f23980 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 07:57:40 -0500 Subject: [PATCH 24/46] raspbian no reboot -- needs testing --- roles/network/tasks/restart.yml | 11 +++++++++++ roles/network/tasks/rpi_debian.yml | 10 +++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index ec9334840..918744cf4 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -10,6 +10,17 @@ # when: iiab_wireless_lan_iface is defined and hostapd_enabled and discovered_wireless_iface != iiab_wan_iface # when: hostapd_enabled and iiab_wireless_lan_iface is defined and discovered_wireless_iface == iiab_wireless_lan_iface +- name: Stop wpa_supplicant on Raspbian + shell: killall wpa_supplicant + when: is_raspbian + +# now pick up denyinterfaces and respawn wpa_supplicant +- name: Restart dhcpcd on Raspbian + systemd: + name: dhcpcd + state: restarted + when: is_raspbian + - name: Restart clone-wifi wpa_supplicant service systemd: name: "{{ item }}" diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index 31c1b7851..016f2f61d 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -51,13 +51,13 @@ daemon_reload: yes # now pick up denyinterfaces -- name: Restart dhcpcd - service: - name: dhcpcd - state: restarted +#- name: Restart dhcpcd +# service: +# name: dhcpcd +# state: restarted - name: Restart the networking service if appropriate - service: + systemd: name: networking enabled: yes state: restarted From 7ca4664473fd9caa827cb37d1e26b49d737823b8 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 08:58:37 -0500 Subject: [PATCH 25/46] flying edit only when different --- roles/network/templates/hostapd/test-wifi | 41 ++++++++++++++++++----- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 7903efe19..b11c58c1c 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -1,7 +1,12 @@ #!/bin/bash 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 wifi-test.service unit file. + # covers systemd-networkd if [ -f /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf ]; then SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant-$IFACE.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` @@ -9,6 +14,7 @@ fi # covers raspbian if [ -f /etc/wpa_supplicant/wpa_supplicant.conf ]; then + RASPBIAN=1 SSID=`grep ssid /etc/wpa_supplicant/wpa_supplicant.conf | awk -F = '{print $2}' | sed -r s/\"// | sed -r s/\"//` fi @@ -19,12 +25,17 @@ if [ -f /run/netplan/wpa-$IFACE.conf ]; then sed '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 if [ -f /etc/iiab/iiab.env ]; then source /etc/iiab/iiab.env if [ ! -z $CLIENT_SSID ]; then SSID=$CLIENT_SSID fi fi +# might need to start the dbus wpa_supplicant +#if [ $RASPBIAN -eq 1 ]; then +# systemctl start wpa_supplicant +#fi sleep 2 wpa_cli -i $IFACE scan > /dev/null sleep 1 @@ -40,14 +51,28 @@ echo "Using $FREQ2 for $SSID" CHAN=$(($FREQ2 - 2407 )) CHAN=$(($CHAN / 5 )) echo "channel is $CHAN for $SSID" -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 -systemctl start hostapd -systemctl start wpa_supplicant -if [ $NETPLAN -eq 1 ]; then - systemctl restart netplan-wpa-wlan0.service +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" + 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 + systemctl start hostapd + systemctl start wpa_supplicant + # This is more of a netplan workaround should go away. + if [ $NETPLAN -eq 1 ]; then + systemctl restart netplan-wpa-$IFACE.service + fi +else + #we started it stop it now, dhcpcd should launch it's version anyway +# if [ $RASPBIAN -eq 1 ]; then +# systemctl stop wpa_supplicant +# fi + # firmware might force the need to restart anyway +# systemctl stop wpa_supplicant + systemctl start hostapd +# systemctl start wpa_supplicant fi -systemctl stop dnsmasq.service systemctl start dnsmasq.service exit 0 From 050722f3a07e1fb948267585e5a405b986c7cbd2 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 11:09:31 -0500 Subject: [PATCH 26/46] ubuntu hook for channel change --- roles/network/tasks/hostapd.yml | 3 ++- roles/network/templates/hostapd/netd-disp | 1 - roles/network/templates/hostapd/netd-disp2 | 25 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 roles/network/templates/hostapd/netd-disp2 diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 865ce6bfd..0f14c238d 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -119,7 +119,7 @@ with_items: - { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/carrier.d/iiab-wifi' } - { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/no-carrier.d/iiab-wifi' } - - { src: 'hostapd/netd-disp', dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi' } + - { src: 'hostapd/netd-disp2', dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi2' } when: systemd_networkd_active and discovered_wireless_iface != "none" and wifi_up_down - name: Remove networkd-dispatcher hook wifi_up_down False @@ -130,6 +130,7 @@ - { dest: '/etc/networkd-dispatcher/carrier.d/iiab-wifi' } - { dest: '/etc/networkd-dispatcher/no-carrier.d/iiab-wifi' } - { dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi' } + - { dest: '/etc/networkd-dispatcher/routable.d/iiab-wifi2' } when: systemd_networkd_active and discovered_wireless_iface != "none" and not wifi_up_down - name: Enable the Access Point 'hostapd' service diff --git a/roles/network/templates/hostapd/netd-disp b/roles/network/templates/hostapd/netd-disp index af9a7977b..0ad9b7942 100644 --- a/roles/network/templates/hostapd/netd-disp +++ b/roles/network/templates/hostapd/netd-disp @@ -1,5 +1,4 @@ #!/bin/bash - if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then echo "NET-DISP-WiFi $IFACE $STATE" /usr/sbin/ip link set ap0 up diff --git a/roles/network/templates/hostapd/netd-disp2 b/roles/network/templates/hostapd/netd-disp2 new file mode 100644 index 000000000..991deb0fc --- /dev/null +++ b/roles/network/templates/hostapd/netd-disp2 @@ -0,0 +1,25 @@ +#!/bin/bash +if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then + echo "NET-DISP-WiFi $IFACE $STATE" + 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 ]; then + FREQ2=$result + fi + done + echo "Using $FREQ2 for $SSID" + CHAN=$(($FREQ2 - 2407 )) + CHAN=$(($CHAN / 5 )) + 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" + 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 + systemctl restart hostapd + systemctl start wpa_supplicant + fi + /usr/sbin/ip link set ap0 up +fi From 60a6484c519082fadce23babb485f051de811141 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 12:51:36 -0500 Subject: [PATCH 27/46] restart.yml netplan fix needs is_ubuntu --- roles/network/tasks/restart.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index 918744cf4..d94ac7377 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -32,7 +32,7 @@ - name: Reload netplan for Wifi gateway on Ubuntu 18+ shell: netplan apply - when: wifi_up_down and netplan.stdout.find("yaml") != -1 + when: wifi_up_down and is_ubuntu and netplan.stdout.find("yaml") != -1 - name: Start named service systemd: From 263010cfdfb119248de3dfb52e44b5aca1ced7e3 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 13:09:02 -0500 Subject: [PATCH 28/46] raspbian - only start clone-wifi if wired gateway is used --- roles/network/tasks/rpi_debian.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index 016f2f61d..12bfef4c4 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -50,11 +50,12 @@ systemd: daemon_reload: yes -# now pick up denyinterfaces -#- name: Restart dhcpcd -# service: -# name: dhcpcd -# state: restarted +- name: Clone wifi if needed + systemd: + name: clone-wifi + state: started + when: not no_net_restart +# might be able to pull off wifi with the staging in restart.yml - name: Restart the networking service if appropriate systemd: From c602bace6b2dd9bd2139949ddd4e62a4559742ef Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 14:39:26 -0500 Subject: [PATCH 29/46] hostapd.yml reload new services --- roles/network/tasks/hostapd.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 0f14c238d..83ad15424 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -143,6 +143,7 @@ systemd: name: "{{ item }}" enabled: no + daemon_reload: yes with_items: - clone-wifi.service - wifi-test.service @@ -152,6 +153,7 @@ systemd: name: "{{ item }}" enabled: yes + daemon_reload: yes with_items: # - hostapd.service - clone-wifi.service From 7fd6fc973746e964e683f3c10321f2712bf6edff Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 14:42:10 -0500 Subject: [PATCH 30/46] test wifi exit if no ssid is found --- roles/network/templates/hostapd/test-wifi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index b11c58c1c..7a8418bc1 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -2,7 +2,7 @@ IFACE={{ discovered_wireless_iface }} RASPBIAN=0 NETPLAN=0 -SSID="" +SSID="NA" # 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 wifi-test.service unit file. @@ -32,6 +32,11 @@ if [ -f /etc/iiab/iiab.env ]; then SSID=$CLIENT_SSID fi fi +echo "ssid is $SSID" +if [[ $SSID == "" ]]; then + echo "Couldn't find ssid to use exiting" + exit 0 +fi # might need to start the dbus wpa_supplicant #if [ $RASPBIAN -eq 1 ]; then # systemctl start wpa_supplicant From 25bd5a9b3c0f9fa3279498ebaea1d8a5440fee98 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 18:14:43 -0500 Subject: [PATCH 31/46] dhcpcd hook refinements --- roles/network/templates/hostapd/50-hostapd | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/roles/network/templates/hostapd/50-hostapd b/roles/network/templates/hostapd/50-hostapd index 47a769639..589a257cb 100644 --- a/roles/network/templates/hostapd/50-hostapd +++ b/roles/network/templates/hostapd/50-hostapd @@ -6,9 +6,23 @@ if [ "$interface" = "wlan0" ]; then # wpa_supplicant wants MHz for frequency= while hostapd wants channel..... whatever # FREQ=`iw wlan0 info|grep channel|cut -d' ' -f9` FREQ=`iw wlan0 info|grep channel|cut -d' ' -f2` - syslog info "40-iiab set channel $FREQ" - sed -i -e "s/^channel.*/channel=$FREQ /" /etc/hostapd/hostapd.conf - # will need a reboot for hostapd if the channel changed + FREQ2="" + for result in $FREQ; do + echo "frequency is $result for carrier" + if [ $result -lt 13 ]; then + FREQ2=$result + fi + done + echo "Using $FREQ2 for $SSID" + syslog info "50-iiab set channel $FREQ2" + HOSTAPD=`grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}'` + echo "Hostapd set for $HOSTAPD" + if [ $FREQ2 -ne $HOSTAPD ] && [ ! -z $FREQ2 ]; then + echo "Editing Hostapd for channel $FREQ2" + cp /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf + sed -i -e "s/^channel.*/channel=$FREQ /" /etc/hostapd/hostapd.conf +# systemctl restart hostapd + fi fi # spams the logging #syslog info "50-iiab set ap0 spam $REASON" From 323e5c7372b7847b6c80a27337c0c74dfdb7be6b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 18:15:04 -0500 Subject: [PATCH 32/46] don't use test-wifi for hostapd start --- roles/network/tasks/hostapd.yml | 2 +- roles/network/templates/hostapd/test-wifi | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/roles/network/tasks/hostapd.yml b/roles/network/tasks/hostapd.yml index 83ad15424..dd6b82698 100644 --- a/roles/network/tasks/hostapd.yml +++ b/roles/network/tasks/hostapd.yml @@ -155,7 +155,7 @@ enabled: yes daemon_reload: yes with_items: -# - hostapd.service + - hostapd.service - clone-wifi.service - wifi-test.service when: hostapd_enabled and wifi_up_down diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 7a8418bc1..3c948fbcb 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -69,15 +69,5 @@ if [ $CHAN -ne $HOSTAPD ]; then if [ $NETPLAN -eq 1 ]; then systemctl restart netplan-wpa-$IFACE.service fi -else - #we started it stop it now, dhcpcd should launch it's version anyway -# if [ $RASPBIAN -eq 1 ]; then -# systemctl stop wpa_supplicant -# fi - # firmware might force the need to restart anyway -# systemctl stop wpa_supplicant - systemctl start hostapd -# systemctl start wpa_supplicant fi -systemctl start dnsmasq.service exit 0 From 6e21b0b55b502e253e6bd7a68efd58f9935a35a9 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 18:36:01 -0500 Subject: [PATCH 33/46] rpi-next-run sync up --- roles/network/tasks/restart.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index d94ac7377..775627c2a 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -1,14 +1,10 @@ -#iiab_wireless_lan_iface(wlan0) - wifi_up_down False needs hw -#iiab_wireless_lan_iface(ap0) - wifi_up_down True needs hw #hostapd_enabled False - set in hostapd.yml to avoid the enable with wifi_up_down False #no_net_restart: True - main.yml discovered_wireless_iface == iiab_wan_iface - name: Restart hostapd when WiFi is present but not when using WiFi as gateway with wifi_up_down False systemd: name: hostapd state: restarted - when: hostapd_enabled and (wifi_up_down or not no_net_restart) -# when: iiab_wireless_lan_iface is defined and hostapd_enabled and discovered_wireless_iface != iiab_wan_iface -# when: hostapd_enabled and iiab_wireless_lan_iface is defined and discovered_wireless_iface == iiab_wireless_lan_iface + when: hostapd_enabled and not no_net_restart - name: Stop wpa_supplicant on Raspbian shell: killall wpa_supplicant From 23940fcdc4eb2f725e43d18d9750edf7ec8d35db Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Mon, 4 May 2020 20:28:37 -0500 Subject: [PATCH 34/46] past sync up netd-disp2 --- roles/network/templates/hostapd/netd-disp2 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/network/templates/hostapd/netd-disp2 b/roles/network/templates/hostapd/netd-disp2 index 991deb0fc..35645e65d 100644 --- a/roles/network/templates/hostapd/netd-disp2 +++ b/roles/network/templates/hostapd/netd-disp2 @@ -1,19 +1,22 @@ #!/bin/bash if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then echo "NET-DISP-WiFi $IFACE $STATE" - FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'` + FREQ=`wpa_cli -i $IFACE scan_results | grep : | awk '{print $2}'` for result in $FREQ; do - echo "frequency is $result for $SSID" - if [ $result -lt 2485 ]; then + echo "frequency is $result for carrier" + if [ $result -lt 2485 ] && [ ! -z $result ]; then FREQ2=$result + else + FREQ2="NA" fi done - echo "Using $FREQ2 for $SSID" + echo "Using $FREQ2 for carrier" CHAN=$(($FREQ2 - 2407 )) CHAN=$(($CHAN / 5 )) + echo "Using channel $CHAN for carrier" 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 ] && [[ ! $FREQ2 == "NA" ]]; 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 933ca564bd5e9ba68da20d08b5485fcbd7078297 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 5 May 2020 11:27:57 -0500 Subject: [PATCH 35/46] wpa workaround doc'd and moved --- roles/network/templates/hostapd/test-wifi | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 3c948fbcb..0a2f72f8f 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -22,6 +22,7 @@ fi 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/\"//` + # covers netplan lack of country= sed 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf fi # IIAB hint for NetworkManager @@ -41,9 +42,8 @@ fi #if [ $RASPBIAN -eq 1 ]; then # systemctl start wpa_supplicant #fi -sleep 2 wpa_cli -i $IFACE scan > /dev/null -sleep 1 +sleep 2 FREQ=`wpa_cli -i $IFACE scan_results | grep $SSID | awk '{print $2}'` for result in $FREQ; do echo "frequency is $result for $SSID" @@ -62,12 +62,16 @@ 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 - systemctl stop wpa_supplicant - systemctl start hostapd - systemctl start wpa_supplicant - # This is more of a netplan workaround should go away. - if [ $NETPLAN -eq 1 ]; then - systemctl restart netplan-wpa-$IFACE.service + # too soon to for raspbian to call hostapd but hostapd gets called after this script anyway. + if [ RASPBIAN -eq 0 ]; then + systemctl stop wpa_supplicant + systemctl start hostapd + systemctl start wpa_supplicant fi fi +# covers netplan lack of country= +if [ $NETPLAN -eq 1 ]; then + # This is more of a netplan workaround should go away. + systemctl restart netplan-wpa-$IFACE.service +fi exit 0 From 8190f4b7a94ea0d88bff2da7e8fcf72c29b1c000 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Tue, 5 May 2020 12:09:55 -0500 Subject: [PATCH 36/46] runtime - move clone-wifi - adjust services --- roles/network/tasks/restart.yml | 25 ++++++++++++++++--------- roles/network/tasks/rpi_debian.yml | 7 ------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index 775627c2a..d6d03a425 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -1,28 +1,35 @@ +- name: Clone wifi if needed + systemd: + name: clone-wifi + state: started + #hostapd_enabled False - set in hostapd.yml to avoid the enable with wifi_up_down False #no_net_restart: True - main.yml discovered_wireless_iface == iiab_wan_iface - name: Restart hostapd when WiFi is present but not when using WiFi as gateway with wifi_up_down False systemd: name: hostapd state: restarted - when: hostapd_enabled and not no_net_restart + when: hostapd_enabled and (wifi_up_down or not no_net_restart) - name: Stop wpa_supplicant on Raspbian shell: killall wpa_supplicant when: is_raspbian # now pick up denyinterfaces and respawn wpa_supplicant -- name: Restart dhcpcd on Raspbian - systemd: - name: dhcpcd - state: restarted - when: is_raspbian - -- name: Restart clone-wifi wpa_supplicant service +- name: Restart wpa_supplicant dhcpcd on Raspbian + systemd: + name: "{{ item }}" + state: restarted + with_items: + - wpa_supplicant + - dhcpcd + when: is_raspbian + +- name: Restart wpa_supplicant service on Ubuntu systemd: name: "{{ item }}" state: restarted with_items: - - clone-wifi - wpa_supplicant when: wifi_up_down and hostapd_enabled and is_ubuntu diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index 12bfef4c4..f9ee65cac 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -50,13 +50,6 @@ systemd: daemon_reload: yes -- name: Clone wifi if needed - systemd: - name: clone-wifi - state: started - when: not no_net_restart -# might be able to pull off wifi with the staging in restart.yml - - name: Restart the networking service if appropriate systemd: name: networking From 1b58d712cf1c3eb76a9fa2ded1c53332f25ec01f Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 6 May 2020 07:58:24 -0500 Subject: [PATCH 37/46] use iw in place of wpa_cli --- roles/network/templates/hostapd/50-hostapd | 2 +- roles/network/templates/hostapd/netd-disp2 | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/roles/network/templates/hostapd/50-hostapd b/roles/network/templates/hostapd/50-hostapd index 589a257cb..8697c283d 100644 --- a/roles/network/templates/hostapd/50-hostapd +++ b/roles/network/templates/hostapd/50-hostapd @@ -13,7 +13,7 @@ if [ "$interface" = "wlan0" ]; then FREQ2=$result fi done - echo "Using $FREQ2 for $SSID" + echo "Using $FREQ2 for carrier" syslog info "50-iiab set channel $FREQ2" HOSTAPD=`grep channel /etc/hostapd/hostapd.conf | awk -F = '{print $2}'` echo "Hostapd set for $HOSTAPD" diff --git a/roles/network/templates/hostapd/netd-disp2 b/roles/network/templates/hostapd/netd-disp2 index 35645e65d..78e258627 100644 --- a/roles/network/templates/hostapd/netd-disp2 +++ b/roles/network/templates/hostapd/netd-disp2 @@ -1,28 +1,21 @@ #!/bin/bash if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then echo "NET-DISP-WiFi $IFACE $STATE" - FREQ=`wpa_cli -i $IFACE scan_results | grep : | awk '{print $2}'` - for result in $FREQ; do - echo "frequency is $result for carrier" - if [ $result -lt 2485 ] && [ ! -z $result ]; then - FREQ2=$result - else - FREQ2="NA" - fi - done - echo "Using $FREQ2 for carrier" - CHAN=$(($FREQ2 - 2407 )) - CHAN=$(($CHAN / 5 )) + # If we are here we have a dhcp ip address + 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}'` echo "Hostapd set for $HOSTAPD" - if [ $CHAN -ne $HOSTAPD ] && [[ ! $FREQ2 == "NA" ]]; then + 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 systemctl restart hostapd systemctl start wpa_supplicant + else + echo "Upstream Channel greater than 13 or is the same - not changing hostapd.conf" fi + sleep 3 /usr/sbin/ip link set ap0 up fi From 2c7a720030d9057c63568ac3318d3be22c671d45 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 6 May 2020 08:10:34 -0500 Subject: [PATCH 38/46] test-wifi - exit if ssid is not found or channel is unavailable --- roles/network/templates/hostapd/test-wifi | 39 +++++++++++++---------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/roles/network/templates/hostapd/test-wifi b/roles/network/templates/hostapd/test-wifi index 0a2f72f8f..f1a1bc66c 100755 --- a/roles/network/templates/hostapd/test-wifi +++ b/roles/network/templates/hostapd/test-wifi @@ -22,8 +22,8 @@ fi 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/\"//` - # covers netplan lack of country= - sed 's|ctrl_interface=/run/wpa_supplicant|&\ncountry={{ host_country_code }}|' /run/netplan/wpa-$IFACE.conf + echo "cover netplan lack of country=" + sed -i 's|ctrl_interface=/run/wpa_supplicant|&\ncountry=US|' /run/netplan/wpa-$IFACE.conf fi # IIAB hint for NetworkManager # could scrape /etc/NetworkManager/system-connections/ looking for ssid @@ -34,25 +34,32 @@ if [ -f /etc/iiab/iiab.env ]; then fi fi echo "ssid is $SSID" -if [[ $SSID == "" ]]; then - echo "Couldn't find ssid to use exiting" +if [[ $SSID == "" ]] || [[ $SSID == "NA" ]]; then + echo "Couldn't find ssid $SSID to use exiting" + if [ $NETPLAN -eq 1 ]; then + echo "Netplan1" + fi exit 0 fi -# might need to start the dbus wpa_supplicant -#if [ $RASPBIAN -eq 1 ]; then -# systemctl start wpa_supplicant -#fi wpa_cli -i $IFACE scan > /dev/null sleep 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 ]; then + if [ $result -lt 2485 ] && [ $result -gt 2407 ]; then FREQ2=$result + break fi done echo "Using $FREQ2 for $SSID" - +if [[ $FREQ2 == "" ]]; then + echo "Couldn't find frequency to use exiting" + if [ $NETPLAN -eq 1 ]; then + echo "Netplan2" + 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" @@ -62,15 +69,13 @@ 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 - # too soon to for raspbian to call hostapd but hostapd gets called after this script anyway. - if [ RASPBIAN -eq 0 ]; then - systemctl stop wpa_supplicant - systemctl start hostapd - systemctl start wpa_supplicant - fi fi -# covers netplan lack of country= +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 From 35efbe8ea86703f0dd918f96682cc8fe95ba21e1 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 6 May 2020 08:18:40 -0500 Subject: [PATCH 39/46] hostapd keep a strict starting order --- roles/network/templates/hostapd/hostapd.service.j2 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/roles/network/templates/hostapd/hostapd.service.j2 b/roles/network/templates/hostapd/hostapd.service.j2 index a60320519..3135169eb 100644 --- a/roles/network/templates/hostapd/hostapd.service.j2 +++ b/roles/network/templates/hostapd/hostapd.service.j2 @@ -4,6 +4,11 @@ Wants=network-pre.target After=network-pre.target After=clone-wifi.service Requires=clone-wifi.service +Before=dhcpcd.service +Before=wpa_supplicant@{{ discovered_wireless_iface }}.service +Before=network-manager.service +Before=netplan-wpa-{{ discovered_wireless_iface }}.service +Before=network.target [Service] Type=forking From 0024a0c17f7d44bfda0606765931b36bd25dc3c0 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 6 May 2020 10:14:25 -0500 Subject: [PATCH 40/46] hotspots revised --- .../templates/network/iiab-hotspot-off | 28 ++++++++++--------- .../network/templates/network/iiab-hotspot-on | 23 ++++++++------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/roles/network/templates/network/iiab-hotspot-off b/roles/network/templates/network/iiab-hotspot-off index 217bee07e..1f6e1283e 100755 --- a/roles/network/templates/network/iiab-hotspot-off +++ b/roles/network/templates/network/iiab-hotspot-off @@ -1,4 +1,14 @@ #!/bin/bash +sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} +systemctl disable hostapd +systemctl stop hostapd +{% if wifi_up_down %} +systemctl disable clone-wifi.service +systemctl disable wifi-test.service +systemctl stop clone-wifi.service +echo " IIAB hotspot access point Disabled" +exit 0 +{% else %} {% if is_raspbian %} # hotspot-off before ap0_updown sed -i -e "s/^denyinterfaces/#denyinterfaces/" /etc/dhcpcd.conf @@ -9,7 +19,6 @@ systemctl stop hostapd systemctl daemon-reload systemctl restart dhcpcd #systemctl restart networking 6/15/2019 TFM removed -sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} # Temporary promiscuous-mode workaround for RPi's WiFi "10SEC disease" # Set wlan0 to promiscuous when AP's OFF (for possible WiFi gateway) # SEE ALSO iiab-hotspot-on + /usr/libexec/iiab-startup.sh @@ -17,20 +26,13 @@ sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} #if grep -qi raspbian /etc/*release; then # ip link set dev wlan0 promisc on #fi - {% else %} -systemctl disable hostapd -systemctl stop hostapd -sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }} -{% if wifi_up_down %} -systemctl disable clone-wifi.service -systemctl disable wifi-test.service -systemctl stop clone-wifi.service -echo " IIAB hotspot access point Disabled" -exit 0 -{% else %} -sed -i -e "s|managed=0|managed=1|" /etc/NetworkManager/conf.d/wifi-manage.conf +#ubuntu +if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ] + 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 {% endif %} +#wifi_up_down {% endif %} diff --git a/roles/network/templates/network/iiab-hotspot-on b/roles/network/templates/network/iiab-hotspot-on index fd65c2ab5..2c0854b82 100755 --- a/roles/network/templates/network/iiab-hotspot-on +++ b/roles/network/templates/network/iiab-hotspot-on @@ -1,4 +1,12 @@ #!/bin/bash +sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} +{% if wifi_up_down %} +systemctl enable clone-wifi.service +systemctl enable hostapd +systemctl enable wifi-test.service +echo -e "\nPlease reboot to activate hostapd feature.\n" +exit 0 +{% else %} {% if is_raspbian %} # just do what we have always done in hotspot-on cp -f /etc/hostapd/hostapd.conf.iiab /etc/hostapd/hostapd.conf @@ -11,7 +19,6 @@ systemctl daemon-reload systemctl restart dhcpcd systemctl start hostapd systemctl start dnsmasq -sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} # Temporary promiscuous-mode workaround for RPi's WiFi "10SEC disease" # Disable "promiscuous" on wlan0 when AP (i.e. no WiFi gateway) @@ -20,18 +27,14 @@ sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} #if grep -qi raspbian /etc/*release; then # ip link set dev wlan0 promisc off #fi - {% else %} -sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }} -{% if wifi_up_down %} -systemctl enable clone-wifi.service -systemctl enable wifi-test.service -echo -e "\nPlease reboot to activate hostapd feature.\n" -exit 0 -{% else %} -sed -i -e "s|managed=1|managed=0|" /etc/NetworkManager/conf.d/wifi-manage.conf +#ubuntu +if [ -f /etc/NetworkManager/conf.d/wifi-manage.conf ] + 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 {% endif %} +#wifi_up_down {% endif %} From 52c0f2aaea2fa19c3ade8ed50b978acd59733d32 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 6 May 2020 21:03:37 -0500 Subject: [PATCH 41/46] too aggressive in dhcpcd's 50-hook --- roles/network/templates/hostapd/50-hostapd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/templates/hostapd/50-hostapd b/roles/network/templates/hostapd/50-hostapd index 8697c283d..d1ab4ea7e 100644 --- a/roles/network/templates/hostapd/50-hostapd +++ b/roles/network/templates/hostapd/50-hostapd @@ -26,7 +26,7 @@ if [ "$interface" = "wlan0" ]; then fi # spams the logging #syslog info "50-iiab set ap0 spam $REASON" - if [ -e /sys/class/net/ap0 ] && ! [ "$reason" = "ROUTERADVERT" ]; then + if [ -e /sys/class/net/ap0 ] && [ "$reason" = "BOUND" ]; then syslog info "50-iiab set ap0 up $REASON" # keeps ap0 up so hostapd works ip link set ap0 up From a95d4762874faac485f2c261eb347d86cf8f4ce5 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 6 May 2020 15:51:40 -0400 Subject: [PATCH 42/46] rpi wifi-runtime changes --- roles/network/tasks/restart.yml | 31 ++---------------------- roles/network/tasks/rpi_debian.yml | 22 +++++++++++++++-- roles/network/tasks/sysd-netd-debian.yml | 11 +++++++++ 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index d6d03a425..7fe5294b9 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -1,37 +1,10 @@ -- name: Clone wifi if needed - systemd: - name: clone-wifi - state: started - -#hostapd_enabled False - set in hostapd.yml to avoid the enable with wifi_up_down False -#no_net_restart: True - main.yml discovered_wireless_iface == iiab_wan_iface -- name: Restart hostapd when WiFi is present but not when using WiFi as gateway with wifi_up_down False - systemd: - name: hostapd - state: restarted - when: hostapd_enabled and (wifi_up_down or not no_net_restart) - -- name: Stop wpa_supplicant on Raspbian - shell: killall wpa_supplicant - when: is_raspbian - -# now pick up denyinterfaces and respawn wpa_supplicant -- name: Restart wpa_supplicant dhcpcd on Raspbian +- name: Restart wpa_supplicant service systemd: name: "{{ item }}" state: restarted with_items: - wpa_supplicant - - dhcpcd - when: is_raspbian - -- name: Restart wpa_supplicant service on Ubuntu - systemd: - name: "{{ item }}" - state: restarted - with_items: - - wpa_supplicant - when: wifi_up_down and hostapd_enabled and is_ubuntu + when: wifi_up_down and hostapd_enabled - name: Reload netplan for Wifi gateway on Ubuntu 18+ shell: netplan apply diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index f9ee65cac..d3568dcda 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -50,10 +50,28 @@ systemd: daemon_reload: yes +- name: Clone wifi if needed + systemd: + name: clone-wifi + state: started + - name: Restart the networking service if appropriate systemd: name: networking enabled: yes state: restarted - when: not nobridge is defined # less is better - #when: not nobridge is defined and not no_net_restart + +- name: Restart hostapd when WiFi is present but not when using WiFi as gateway$ + systemd: + name: hostapd + state: restarted + when: hostapd_enabled and (wifi_up_down or not no_net_restart) + +- name: Stop wpa_supplicant on Raspbian + shell: killall wpa_supplicant + +# now pick up denyinterfaces and respawn wpa_supplicant +- name: Restart dhcpcd on Raspbian + systemd: + name: dhcpcd + state: restarted diff --git a/roles/network/tasks/sysd-netd-debian.yml b/roles/network/tasks/sysd-netd-debian.yml index 1b652e831..1ac9bb959 100644 --- a/roles/network/tasks/sysd-netd-debian.yml +++ b/roles/network/tasks/sysd-netd-debian.yml @@ -51,7 +51,18 @@ systemd: daemon_reload: yes +- name: Clone wifi if needed + systemd: + name: clone-wifi + state: started + - name: Restart the systemd-networkd service systemd: name: systemd-networkd state: restarted + +- name: Restart hostapd when WiFi is present but not when using WiFi as gateway$ + systemd: + name: hostapd + state: restarted + when: hostapd_enabled and (wifi_up_down or not no_net_restart) From 845a9611392e405f47b729389a96fd0c4edb008c Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 7 May 2020 08:47:47 -0500 Subject: [PATCH 43/46] forget about pre-reboot AP usage --- roles/network/tasks/rpi_debian.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/network/tasks/rpi_debian.yml b/roles/network/tasks/rpi_debian.yml index d3568dcda..426685864 100644 --- a/roles/network/tasks/rpi_debian.yml +++ b/roles/network/tasks/rpi_debian.yml @@ -61,14 +61,14 @@ enabled: yes state: restarted -- name: Restart hostapd when WiFi is present but not when using WiFi as gateway$ +- name: Restart hostapd when WiFi is present but not when using WiFi as gateway systemd: name: hostapd state: restarted when: hostapd_enabled and (wifi_up_down or not no_net_restart) -- name: Stop wpa_supplicant on Raspbian - shell: killall wpa_supplicant +#- name: Stop wpa_supplicant on Raspbian +# shell: killall wpa_supplicant # now pick up denyinterfaces and respawn wpa_supplicant - name: Restart dhcpcd on Raspbian From 04edaeaddd2a7dcd30a0de689c69e8ea88220157 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 7 May 2020 06:37:47 -0500 Subject: [PATCH 44/46] raspbian - wifi installs not assigning ip address to br0 in time for dnsmasq --- roles/network/tasks/restart.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index 7fe5294b9..b1f26ebf7 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -89,6 +89,6 @@ systemd: name: "{{ dhcp_service2 }}" state: restarted - when: (not no_net_restart) or wifi_up_down + when: (not no_net_restart) or (is_ubuntu_20 and wifi_up_down) #when: (iiab_network_mode != "Appliance") # Sufficient b/c br0 exists thanks to /etc/network/interfaces.d/iiab #when: iiab_network_mode != "Appliance" and iiab_wan_iface != discovered_wireless_iface From 1193b1518452c729391c28ea6ecddaceb84b538a Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 7 May 2020 07:46:05 -0500 Subject: [PATCH 45/46] once installed and rebooted br0 will be available --- roles/network/tasks/restart.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/roles/network/tasks/restart.yml b/roles/network/tasks/restart.yml index b1f26ebf7..f896923f1 100644 --- a/roles/network/tasks/restart.yml +++ b/roles/network/tasks/restart.yml @@ -89,6 +89,7 @@ systemd: name: "{{ dhcp_service2 }}" state: restarted - when: (not no_net_restart) or (is_ubuntu_20 and wifi_up_down) + when: (not no_net_restart or (is_ubuntu_20 and wifi_up_down)) or (iiab_stage|int == 9) + #when: (not no_net_restart or (is_ubuntu_20 and wifi_up_down)) #when: (iiab_network_mode != "Appliance") # Sufficient b/c br0 exists thanks to /etc/network/interfaces.d/iiab #when: iiab_network_mode != "Appliance" and iiab_wan_iface != discovered_wireless_iface From 054046bc37252d82ca090664ec49c3dee7ccf3e8 Mon Sep 17 00:00:00 2001 From: A Holt Date: Fri, 8 May 2020 19:05:16 -0400 Subject: [PATCH 46/46] nextcloud_required_ip no longer used --- roles/nextcloud/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/nextcloud/defaults/main.yml b/roles/nextcloud/defaults/main.yml index 19f333409..b72566dea 100644 --- a/roles/nextcloud/defaults/main.yml +++ b/roles/nextcloud/defaults/main.yml @@ -45,7 +45,7 @@ nextcloud_admin_user: 'Admin' nextcloud_admin_password: 'changeme' # 2019-09-04: UNUSED (due to changes in roles/nextcloud/templates/nextcloud.conf.j2) -nextcloud_required_ip: 10.0.0.0/8 192.168.0.0/16 +# nextcloud_required_ip: 10.0.0.0/8 192.168.0.0/16 # 2020-02-15: UNUSED at the time. Legacy remains from Apache: # nextcloud_allow_public_ips: True