From be93f4290c80b0fa6e50cb0d5dced67364403db6 Mon Sep 17 00:00:00 2001 From: cyoung Date: Sat, 21 Dec 2019 12:32:02 -0500 Subject: [PATCH] Add WiFi "Smart Mode" option. No default gateway. Allows iOS to choose internet source (cellular or WiFi). --- image/{dhcpd.conf => dhcpd-not_smart.conf} | 0 image/dhcpd-smart.conf | 13 +++++++++++++ main/gen_gdl90.go | 12 ++++++++++-- main/managementinterface.go | 3 +++ selfupdate/makeupdate.sh | 3 ++- selfupdate/update_footer.sh | 4 +++- web/plates/js/settings.js | 4 +++- web/plates/settings.html | 7 +++++++ 8 files changed, 41 insertions(+), 5 deletions(-) rename image/{dhcpd.conf => dhcpd-not_smart.conf} (100%) create mode 100644 image/dhcpd-smart.conf diff --git a/image/dhcpd.conf b/image/dhcpd-not_smart.conf similarity index 100% rename from image/dhcpd.conf rename to image/dhcpd-not_smart.conf diff --git a/image/dhcpd-smart.conf b/image/dhcpd-smart.conf new file mode 100644 index 00000000..7215e08b --- /dev/null +++ b/image/dhcpd-smart.conf @@ -0,0 +1,13 @@ +ddns-update-style none; +default-lease-time 86400; # 24 hours +max-lease-time 172800; # 48 hours +authoritative; +log-facility local7; +subnet 192.168.10.0 netmask 255.255.255.0 { + range 192.168.10.10 192.168.10.50; + option broadcast-address 192.168.10.255; + default-lease-time 12000; + max-lease-time 12000; + option domain-name "stratux.local"; + option domain-name-servers 4.2.2.2; +} diff --git a/main/gen_gdl90.go b/main/gen_gdl90.go index fd4c0bc9..20467546 100644 --- a/main/gen_gdl90.go +++ b/main/gen_gdl90.go @@ -296,8 +296,8 @@ func makeOwnshipReport() bool { msg[0] = 0x0A // Message type "Ownship". // Ownship Target Identify (see 3.5.1.2 of GDL-90 Specifications) - // First half of byte is 0 for 'No Traffic Alert' - // Second half of byte is 0 for 'ADS-B with ICAO' + // First half of byte is 0 for 'No Traffic Alert' + // Second half of byte is 0 for 'ADS-B with ICAO' msg[1] = 0x00 // Alert status, address type. code, _ := hex.DecodeString(globalSettings.OwnshipModeS) @@ -1125,6 +1125,7 @@ type settings struct { WiFiChannel int WiFiSecurityEnabled bool WiFiPassphrase string + WiFiSmartEnabled bool // "Smart WiFi" - disables the default gateway for iOS. } type status struct { @@ -1309,6 +1310,13 @@ func saveWiFiUserSettings() { fmt.Fprintf(writer, "wpa_passphrase=%s\n", globalSettings.WiFiPassphrase) } writer.Flush() + + // "Smart WiFi". Just use one of two pre-made dhcpd config files. + dhcpd_config := "/etc/dhcp/dhcpd-not_smart.conf" + if globalSettings.WiFiSmartEnabled { + dhcpd_config = "/etc/dhcp/dhcpd-smart.conf" + } + os.Symlink(dhcpd_config, "/etc/dhcp/dhcpd.conf") } func openReplay(fn string, compressed bool) (WriteCloser, error) { diff --git a/main/managementinterface.go b/main/managementinterface.go index cc74fd2e..166af0fd 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -378,6 +378,9 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) { case "WiFiPassphrase": globalSettings.WiFiPassphrase = val.(string) resetWiFi = true + case "WiFiSmartEnabled": + globalSettings.WiFiSmartEnabled = val.(bool) + resetWiFi = true default: log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key) } diff --git a/selfupdate/makeupdate.sh b/selfupdate/makeupdate.sh index e18fb5a5..12813cb7 100755 --- a/selfupdate/makeupdate.sh +++ b/selfupdate/makeupdate.sh @@ -36,7 +36,8 @@ cp image/99-uavionix.rules work/bin/ cp image/motd work/bin/ cp image/stratux-wifi.sh work/bin/ cp image/rc.local work/bin/ -cp image/dhcpd.conf work/bin/ +cp image/dhcpd-not_smart.conf work/bin/ +cp image/dhcpd-smart.conf work/bin/ cp image/interfaces work/bin/ cp image/logrotate.conf work/bin/ cp image/logrotate_d_stratux work/bin/ diff --git a/selfupdate/update_footer.sh b/selfupdate/update_footer.sh index c69dc76a..541765bd 100755 --- a/selfupdate/update_footer.sh +++ b/selfupdate/update_footer.sh @@ -87,7 +87,9 @@ cp -f ahrs_approx /usr/bin/ chmod 755 /usr/bin/ahrs_approx # DHCPD Config. -cp -f dhcpd.conf /etc/dhcp/dhcpd.conf +cp -f dhcpd-not_smart.conf /etc/dhcp/ +cp -f dhcpd-smart.conf /etc/dhcp/ +ln -s /etc/dhcp/dhcpd-not_smart.conf /etc/dhcp/dhcpd.conf # Interfaces file. cp -f interfaces /etc/network/interfaces diff --git a/web/plates/js/settings.js b/web/plates/js/settings.js index 2bffb268..48cac472 100644 --- a/web/plates/js/settings.js +++ b/web/plates/js/settings.js @@ -47,6 +47,7 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { $scope.WiFiPassphrase = settings.WiFiPassphrase; $scope.WiFiSecurityEnabled = settings.WiFiSecurityEnabled; $scope.WiFiChannel = settings.WiFiChannel; + $scope.WiFiSmartEnabled = settings.WiFiSmartEnabled; $scope.Channels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; } @@ -287,7 +288,8 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { "WiFiSSID" : $scope.WiFiSSID, "WiFiSecurityEnabled" : $scope.WiFiSecurityEnabled, "WiFiPassphrase" : $scope.WiFiPassphrase, - "WiFiChannel" : parseInt($scope.WiFiChannel) + "WiFiChannel" : parseInt($scope.WiFiChannel), + "WiFiSmartEnabled": $scope.WiFiSmartEnabled }; // console.log(angular.toJson(newsettings)); diff --git a/web/plates/settings.html b/web/plates/settings.html index bd6b03bf..faad5613 100644 --- a/web/plates/settings.html +++ b/web/plates/settings.html @@ -134,6 +134,12 @@ +
+ +
+ +
+
@@ -383,6 +389,7 @@

WiFi Security: {{WiFiSecurityEnabled}}

WiFi Passphrase: {{WiFiPassphrase}}

WiFi Channel: {{WiFiChannel}}

+

Smart mode: {{WiFiSmartEnabled}}

Your Stratux's WiFi services are now restarting to apply the new settings. This could take up to 30 seconds.
You might have to reconnect to your new WiFi SSID.