WiFi WP+Client mode

pull/827/merge^2
Adrian Batzill 2021-09-05 14:08:44 +01:00
rodzic 50487554ba
commit 82bde1a91e
12 zmienionych plików z 122 dodań i 123 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
interface=wlan0
interface=ap0
hw_mode=g
wmm_enabled=1
ieee80211n=1

Wyświetl plik

@ -1,4 +1,4 @@
interface=wlan0
interface=ap0
hw_mode=g
wmm_enabled=1
ieee80211n=1

Wyświetl plik

@ -3,68 +3,26 @@ auto lo
iface lo inet loopback
allow-hotplug eth0
auto eth0 # shouldn't be needed?
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
# AP or AP+Client -> create seperate ap0 virtual interface for the AP; optionally use wlan0 for client connection
iface ap0 inet static
address 192.168.10.1
netmask 255.255.255.0
pre-up /usr/sbin/rfkill unblock wifi
post-up /opt/stratux/bin/stratux-wifi.sh ap0 0;
post-up /opt/stratux/bin/stratux-wifi.sh 0
# Pure AP mode
iface wlan0 inet manual
pre-up /usr/sbin/rfkill unblock wifi; iw wlan0 set type managed; iw phy0 interface add ap0 type __ap; ifup ap0
wireless-power off
allow-hotplug p2p-wlan0-0
iface p2p-wlan0-0 inet static
address 192.168.10.1
pre-up /usr/sbin/rfkill unblock wifi
netmask 255.255.255.0
post-up /bin/systemctl restart isc-dhcp-server
post-down wpa_cli -i wlan0 terminate
post-down ifdown ap0; ifconfig ap0 down; iw ap0 del
#####################################################################
## Custom settings not for novice users!!!!!!
## Modify at your own risk!!!!!!!!!!!!!!!!!!!
##
## Second Wifi Dongle for local work and internet access
## This template is for adding a second wifi dongle to your PI for internet access while debugging
## You need to create a file /etc/wpa_supplicant/wpa_supplicant_wlan1.conf with your settings (see below)
##
## Uncomment the following lines as needed.
# allow-hotplug wlan1
# iface wlan1 inet manual
# wpa-roam /etc/wpa_supplicant/wpa_supplicant_wlan1.conf
# iface name_of_WPA_Config inet dhcp
# iface name_of_other_WPA_Config inet dhcp
## End of interfaces
#contents of /etc/wpa_supplicant/wpa_supplicant_wlan1.conf
#############################################################
# ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
# update_config=1
# network={
# ssid="SSID_1"
# id_str="name_of_WPA_Config"
# scan_ssid=1
# key_mgmt=WPA-PSK
# psk="mypassword"
# priority=1
# }
# network={
# ssid="SSID_2"
# id_str="name_of_other_WPA_Config"
# scan_ssid=1
# key_mgmt=WPA-PSK
# psk="mypassword"
# priority=3
# }
#############################################################

Wyświetl plik

@ -3,20 +3,48 @@ auto lo
iface lo inet loopback
allow-hotplug eth0
auto eth0 # shouldn't be needed?
iface eth0 inet dhcp
allow-hotplug wlan0
{{if eq .WiFiMode 0}}
iface wlan0 inet static
{{if or (eq .WiFiMode 0) (eq .WiFiMode 2)}}
# AP or AP+Client -> create seperate ap0 virtual interface for the AP; optionally use wlan0 for client connection
iface ap0 inet static
address {{.IpAddr}}
netmask 255.255.255.0
pre-up /usr/sbin/rfkill unblock wifi
{{else}}
post-up /opt/stratux/bin/stratux-wifi.sh ap0 0;
{{end}}
{{if eq .WiFiMode 0}}
# Pure AP mode
iface wlan0 inet manual
pre-up /usr/sbin/rfkill unblock wifi; iw wlan0 set type managed; iw phy0 interface add ap0 type __ap; ifup ap0
wireless-power off
post-down ifdown ap0; ifconfig ap0 down; iw ap0 del
{{end}}
{{if eq .WiFiMode 2}}
# AP+Client mode
iface wlan0 inet dhcp
pre-up /usr/sbin/rfkill unblock wifi; iw wlan0 set type managed; iw phy0 interface add ap0 type __ap; ifup ap0
wireless-power off
post-down ifdown ap0; ifconfig ap0 down; iw ap0 del
wpa-ssid {{.WiFiClientSSID}}
wpa-psk {{.WiFiClientPassword}}
{{end}}
{{if eq .WiFiMode 1}}
# Wifi-Direct -> run stratux-wifi on wlan0, p2p-wlan0-0 will be created by it / by wpa_supplicant
iface wlan0 inet manual
pre-down ifdown p2p-wlan0-0
{{end}}
post-up /opt/stratux/bin/stratux-wifi.sh {{.WiFiMode}} {{.WiFiDirectPin}}
post-up /opt/stratux/bin/stratux-wifi.sh wlan0 1 {{.WiFiDirectPin}}
wireless-power off
allow-hotplug p2p-wlan0-0
@ -24,50 +52,5 @@ iface p2p-wlan0-0 inet static
address {{.IpAddr}}
pre-up /usr/sbin/rfkill unblock wifi
netmask 255.255.255.0
post-up /bin/systemctl restart isc-dhcp-server
post-down wpa_cli -i wlan0 terminate
#####################################################################
## Custom settings not for novice users!!!!!!
## Modify at your own risk!!!!!!!!!!!!!!!!!!!
##
## Second Wifi Dongle for local work and internet access
## This template is for adding a second wifi dongle to your PI for internet access while debugging
## You need to create a file /etc/wpa_supplicant/wpa_supplicant_wlan1.conf with your settings (see below)
##
## Uncomment the following lines as needed.
# allow-hotplug wlan1
# iface wlan1 inet manual
# wpa-roam /etc/wpa_supplicant/wpa_supplicant_wlan1.conf
# iface name_of_WPA_Config inet dhcp
# iface name_of_other_WPA_Config inet dhcp
## End of interfaces
#contents of /etc/wpa_supplicant/wpa_supplicant_wlan1.conf
#############################################################
# ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
# update_config=1
# network={
# ssid="SSID_1"
# id_str="name_of_WPA_Config"
# scan_ssid=1
# key_mgmt=WPA-PSK
# psk="mypassword"
# priority=1
# }
# network={
# ssid="SSID_2"
# id_str="name_of_other_WPA_Config"
# scan_ssid=1
# key_mgmt=WPA-PSK
# psk="mypassword"
# priority=3
# }
#############################################################
{{end}}

Wyświetl plik

@ -35,8 +35,9 @@ apt autoremove -y
apt clean
#echo y | rpi-update
systemctl enable isc-dhcp-server
systemctl enable ssh
systemctl disable isc-dhcp-server # we start it manually on respective interfaces
systemctl disable dhcpcd
systemctl disable hciuart
systemctl disable hostapd

Wyświetl plik

@ -16,6 +16,19 @@ function wLog () {
}
wLog "Running Stratux WiFI Script."
interface=$1 # for dhcp and wpa_supplicant
mode=$2 # 0=ap, 1=wifi-direct, 2=ap+client
pin=$3 # wifi-direct pin
if [ "$1" == "0" ] || [ "$1" == "1" ] || [ "$1" == "2" ]; then
# compatibility to old /etc/network/interfaces before eu027
echo "COMPAT MODE"
interface="wlan0"
mode=$1
pin=$2
fi
echo "interface=${interface},mode=${mode}"
function prepare-start {
# Preliminaries. Kill off old services.
@ -26,6 +39,7 @@ function prepare-start {
/usr/bin/killall -9 hostapd
wLog "Stopping DHCP services "
/bin/systemctl stop isc-dhcp-server
/usr/bin/killall dhcpd
# Sometimes the PID file seems to remain and dhcpd becomes unable to start again?
# See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=868240
@ -49,23 +63,24 @@ function ap-start {
wLog "Restarting DHCP services"
/bin/systemctl restart isc-dhcp-server
/usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf $interface & disown
}
function wifi-direct-start {
echo "Starting wifi direct mode"
pin=$1
/sbin/wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
wpa_cli -i wlan0 p2p_group_add persistent=0 freq=2
/sbin/wpa_supplicant -B -i $interface -c /etc/wpa_supplicant/wpa_supplicant.conf
wpa_cli -i $interface p2p_group_add persistent=0 freq=2
(while wpa_cli -i p2p-wlan0-0 wps_pin any $pin > /dev/null; do sleep 1; done) & disown
ifup p2p-wlan0-0
/usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf p2p-wlan0-0 & disown
}
# function to build /tmp/hostapd.conf and start AP
prepare-start
if [ "$1" == "1" ]; then
wifi-direct-start $2
if [ "$mode" == "1" ]; then
wifi-direct-start
else
ap-start
fi

Wyświetl plik

@ -1193,6 +1193,8 @@ type settings struct {
WiFiMode int
WiFiDirectPin string
WiFiIPAddress string
WiFiClientSSID string
WiFiClientPassword string
SkyDemonAndroidHack bool
EstimateBearinglessDist bool
RadarLimits int

Wyświetl plik

@ -469,6 +469,10 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
setWiFiMode(int(val.(float64)))
case "WiFiDirectPin":
setWifiDirectPin(val.(string))
case "WiFiClientSSID":
setWifiClientSSID(val.(string))
case "WiFiClientPassword":
setWifiClientPassword(val.(string))
case "SkyDemonAndroidHack":
globalSettings.SkyDemonAndroidHack = val.(bool)
case "EstimateBearinglessDist":

Wyświetl plik

@ -37,6 +37,8 @@ type NetworkTemplateParams struct {
WiFiChannel int
WiFiDirectPin string
WiFiPassPhrase string
WiFiClientSSID string
WiFiClientPassword string
}
var hasChanged bool
@ -102,6 +104,19 @@ func setWifiDirectPin(pin string) {
}
}
func setWifiClientSSID(ssid string) {
if globalSettings.WiFiClientSSID != ssid {
globalSettings.WiFiClientSSID = ssid
hasChanged = true
}
}
func setWifiClientPassword(password string) {
if globalSettings.WiFiClientPassword != password {
globalSettings.WiFiClientPassword = password
hasChanged = true
}
}
func applyNetworkSettings(force bool) {
@ -139,6 +154,8 @@ func applyNetworkSettings(force bool) {
tplSettings.WiFiChannel = globalSettings.WiFiChannel
tplSettings.WiFiSSID = globalSettings.WiFiSSID
tplSettings.WiFiDirectPin = globalSettings.WiFiDirectPin
tplSettings.WiFiClientSSID = globalSettings.WiFiClientSSID
tplSettings.WiFiClientPassword = globalSettings.WiFiClientPassword
if tplSettings.WiFiChannel == 0 {
tplSettings.WiFiChannel = 1
@ -151,13 +168,6 @@ func applyNetworkSettings(force bool) {
tplSettings.WiFiSSID = "stratux"
}
overlayctl("unlock")
writeTemplate(STRATUX_HOME + "/cfg/dhcpd.conf.template", "/overlay/robase/etc/dhcp/dhcpd.conf", tplSettings)
writeTemplate(STRATUX_HOME + "/cfg/interfaces.template", "/overlay/robase/etc/network/interfaces", tplSettings)
writeTemplate(STRATUX_HOME + "/cfg/hostapd.conf.template", "/overlay/robase/etc/hostapd/hostapd.conf", tplSettings)
writeTemplate(STRATUX_HOME + "/cfg/wpa_supplicant.conf.template", "/overlay/robase/etc/wpa_supplicant/wpa_supplicant.conf", tplSettings)
overlayctl("lock")
go func() {
time.Sleep(time.Second)
cmd := exec.Command("ifdown", "wlan0")
@ -167,6 +177,14 @@ func applyNetworkSettings(force bool) {
if err := cmd.Wait(); err != nil {
log.Printf("Error shutting down WiFi: %s\n", err.Error())
}
overlayctl("unlock")
writeTemplate(STRATUX_HOME + "/cfg/dhcpd.conf.template", "/overlay/robase/etc/dhcp/dhcpd.conf", tplSettings)
writeTemplate(STRATUX_HOME + "/cfg/interfaces.template", "/overlay/robase/etc/network/interfaces", tplSettings)
writeTemplate(STRATUX_HOME + "/cfg/hostapd.conf.template", "/overlay/robase/etc/hostapd/hostapd.conf", tplSettings)
writeTemplate(STRATUX_HOME + "/cfg/wpa_supplicant.conf.template", "/overlay/robase/etc/wpa_supplicant/wpa_supplicant.conf", tplSettings)
overlayctl("lock")
cmd = exec.Command("ifup", "wlan0")
if err := cmd.Start(); err != nil {
log.Printf("Error starting WiFi: %s\n", err.Error())

Wyświetl plik

@ -70,6 +70,9 @@ cp -f overlayctl init-overlay /sbin/
systemctl disable apt-daily.timer
systemctl disable apt-daily-upgrade.timer
# We now start dhcpd manually on selected interfaces...
systemctl disable isc-dhcp-server
# cleanup after switch to overlayfs: remove tmpfs lines from fstab, move stratux.conf to /boot and potentially enable the overlay depending on user settings
cat /etc/fstab | grep -v tmpfs > /tmp/fstab
mv /tmp/fstab /etc/fstab

Wyświetl plik

@ -74,6 +74,9 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) {
$scope.WiFiMode = settings.WiFiMode.toString();
$scope.WiFiDirectPin = settings.WiFiDirectPin;
$scope.WiFiClientSSID = settings.WiFiClientSSID;
$scope.WiFiClientPassword = settings.WiFiClientPassword;
$scope.Channels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
$scope.OGNAddrType = settings.OGNAddrType.toString();
@ -356,7 +359,9 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) {
"WiFiSmartEnabled": $scope.WiFiSmartEnabled,
"WiFiIPAddress" : $scope.WiFiIPAddress,
"WiFiMode" : parseInt($scope.WiFiMode),
"WiFiDirectPin": $scope.WiFiDirectPin
"WiFiDirectPin": $scope.WiFiDirectPin,
"WiFiClientSSID": $scope.WiFiClientSSID,
"WiFiClientPassword": $scope.WiFiClientPassword
};
// console.log(angular.toJson(newsettings));

Wyświetl plik

@ -231,6 +231,7 @@
ng-change="WiFiSecurityEnabled=(WiFiSecurityEnabled || WiFiMode=='1')">
<option value="0" ng-selected="WiFiMode=='0'">AccessPoint</option>
<option value="1" ng-selected="WiFiMode=='1'">WiFi-Direct</option>
<option value="2" ng-selected="WiFiMode=='2'">AP+Client</option>
</select>
</div>
<div class="form-group reset-flow">
@ -238,7 +239,7 @@
<input class="col-xs-7" type="text" ssid-input ng-model="WiFiSSID"
placeholder="WiFi Network Name" />
</div>
<div class="form-group reset-flow" ng-show="WiFiMode=='0'">
<div class="form-group reset-flow" ng-show="(WiFiMode=='0' || WiFiMode=='2')">
<label class="control-label col-xs-5">Network Security</label>
<div class="col-xs-5">
<ui-switch ng-model="WiFiSecurityEnabled" settings-change></ui-switch>
@ -271,6 +272,15 @@
<input class="col-xs-7" type="text" ip-addr-input ng-model="WiFiIPAddress"
placeholder="192.168.10.1" />
</div>
<div class="form-group reset-flow" ng-show="WiFiMode=='2'">
<label class="control-label col-xs-5">WiFi Client SSID</label>
<input class="col-xs-7" type="text" ssid-input ng-model="WiFiClientSSID" />
</div>
<div class="form-group reset-flow" ng-show="WiFiMode=='2'">
<label class="control-label col-xs-5">WiFi Client Passphrase</label>
<input class="col-xs-7" type="text" wpa-input ng-model="WiFiClientPassword" />
</div>
<div class="form-group reset-flow">
<button class="btn btn-primary btn-block" ng-click="updateWiFi()">Submit WiFi
Changes</button>