mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
commit
dd1c3e450e
17 changed files with 311 additions and 119 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
@ -45,14 +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:
|
||||
src: hostapd/hostapd.service.j2
|
||||
dest: /etc/systemd/system/hostapd.service
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
when: discovered_wireless_iface != "none" and wifi_up_down
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
mode: "{{ item.mode }}"
|
||||
with_items:
|
||||
- { 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:
|
||||
|
@ -120,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
|
||||
|
@ -131,13 +130,35 @@
|
|||
- { 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
|
||||
systemd:
|
||||
name: hostapd
|
||||
enabled: yes
|
||||
when: hostapd_enabled
|
||||
when: hostapd_enabled and not wifi_up_down
|
||||
|
||||
- name: Disable ap0 related services
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
enabled: no
|
||||
daemon_reload: yes
|
||||
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 }}"
|
||||
enabled: yes
|
||||
daemon_reload: 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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#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
|
||||
- name: Restart wpa_supplicant service
|
||||
systemd:
|
||||
name: hostapd
|
||||
name: "{{ item }}"
|
||||
state: restarted
|
||||
# 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
|
||||
with_items:
|
||||
- wpa_supplicant
|
||||
when: wifi_up_down and hostapd_enabled
|
||||
|
||||
- name: Reload netplan for Wifi gateway on Ubuntu 18+
|
||||
shell: netplan apply
|
||||
when: wifi_up_down and is_ubuntu and netplan.stdout.find("yaml") != -1
|
||||
|
||||
- name: Start named service
|
||||
systemd:
|
||||
|
@ -72,7 +72,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,12 +83,13 @@
|
|||
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 }}"
|
||||
state: restarted
|
||||
when: (not no_net_restart) or 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
|
||||
#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
|
||||
|
|
|
@ -50,16 +50,28 @@
|
|||
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
|
||||
|
||||
- name: Restart the networking service if appropriate
|
||||
service:
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -6,13 +6,27 @@ 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 carrier"
|
||||
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"
|
||||
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
|
||||
|
|
10
roles/network/templates/hostapd/README.ap0
Normal file
10
roles/network/templates/hostapd/README.ap0
Normal file
|
@ -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
|
||||
|
21
roles/network/templates/hostapd/clone-wifi.service.j2
Normal file
21
roles/network/templates/hostapd/clone-wifi.service.j2
Normal file
|
@ -0,0 +1,21 @@
|
|||
[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=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
|
||||
ExecStop=-/sbin/iw dev ap0 del
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -2,29 +2,21 @@
|
|||
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 %}
|
||||
After=clone-wifi.service
|
||||
Requires=clone-wifi.service
|
||||
Before=dhcpcd.service
|
||||
{% endif %}
|
||||
Before=wpa_supplicant.service
|
||||
Before=wpa_supplicant@{{ discovered_wireless_iface }}.service
|
||||
{% if network_manager_active %}
|
||||
Before=wpa_supplicant@{{ discovered_wireless_iface }}.service
|
||||
Before=network-manager.service
|
||||
{% endif %}
|
||||
{% if is_ubuntu and netplan.stdout.find("yaml") != -1 %}
|
||||
Before=netplan-wpa-{{ discovered_wireless_iface }}.service
|
||||
{% endif %}
|
||||
Before=netplan-wpa-{{ discovered_wireless_iface }}.service
|
||||
Before=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
#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
|
||||
|
|
|
@ -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
|
||||
|
|
21
roles/network/templates/hostapd/netd-disp2
Normal file
21
roles/network/templates/hostapd/netd-disp2
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
if [ "$IFACE" == "{{ discovered_wireless_iface }}" ]; then
|
||||
echo "NET-DISP-WiFi $IFACE $STATE"
|
||||
# If we are here we have a dhcp ip address
|
||||
CHAN=`iw $IFACE info|grep channel|cut -d' ' -f2`
|
||||
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 ] && [ $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
|
82
roles/network/templates/hostapd/test-wifi
Executable file
82
roles/network/templates/hostapd/test-wifi
Executable file
|
@ -0,0 +1,82 @@
|
|||
#!/bin/bash
|
||||
IFACE={{ discovered_wireless_iface }}
|
||||
RASPBIAN=0
|
||||
NETPLAN=0
|
||||
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.
|
||||
|
||||
# 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
|
||||
RASPBIAN=1
|
||||
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/\"//`
|
||||
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
|
||||
if [ -f /etc/iiab/iiab.env ]; then
|
||||
source /etc/iiab/iiab.env
|
||||
if [ ! -z $CLIENT_SSID ]; then
|
||||
SSID=$CLIENT_SSID
|
||||
fi
|
||||
fi
|
||||
echo "ssid is $SSID"
|
||||
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
|
||||
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 ] && [ $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"
|
||||
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
|
||||
fi
|
||||
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
|
||||
exit 0
|
19
roles/network/templates/hostapd/wifi-test.service.j2
Normal file
19
roles/network/templates/hostapd/wifi-test.service.j2
Normal file
|
@ -0,0 +1,19 @@
|
|||
[Unit]
|
||||
Description=IIAB find channel freq for ssid
|
||||
After=wpa_supplicant.service
|
||||
Wants=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
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/sbin/test-wifi
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
@ -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
|
||||
|
@ -18,15 +27,12 @@ sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=False/" {{ iiab_env_file }}
|
|||
# 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 %}
|
||||
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 %}
|
||||
|
|
|
@ -1,5 +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
|
||||
|
@ -12,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)
|
||||
|
@ -21,16 +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 %}
|
||||
#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
|
||||
sed -i -e "s/^HOSTAPD_ENABLED.*/HOSTAPD_ENABLED=True/" {{ iiab_env_file }}
|
||||
{% if wifi_up_down %}
|
||||
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
|
||||
echo -e "\nPlease reboot to activate hostapd feature.\n"
|
||||
exit 0
|
||||
{% endif %}
|
||||
#wifi_up_down
|
||||
{% endif %}
|
||||
|
|
|
@ -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 }}
|
||||
|
|
Loading…
Add table
Reference in a new issue