Skip to content

Commit 89b1a08

Browse files
committed
1 parent ae79829 commit 89b1a08

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

ffac-autoupdater-wifi-fallback/LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 2-Clause License
22

3-
Copyright (c) 2023 kb-light, Patric Steffen, Andreas Ziegler, Florian Maurer
3+
Copyright (c) 2024 kb-light, Patric Steffen, Andreas Ziegler, Florian Maurer, Maximilian Baumgartner
44

55
Redistribution and use in source and binary forms, with or without
66
modification, are permitted provided that the following conditions are met:

ffac-autoupdater-wifi-fallback/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# SPDX-FileCopyrightText: 2023 kb-light, Patric Steffen, Andreas Ziegler, Florian Maurer
1+
# SPDX-FileCopyrightText: 2024 kb-light, Patric Steffen, Andreas Ziegler, Florian Maurer, Maximilian Baumgartner
22
# SPDX-License-Identifier: BSD-2-Clause
33
include $(TOPDIR)/rules.mk
44

55
PKG_NAME:=ffac-autoupdater-wifi-fallback
6-
PKG_VERSION:=2
6+
PKG_VERSION:=3
77
PKG_LICENSE:=BSD-2-Clause
88

99
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
@@ -13,7 +13,7 @@ include $(TOPDIR)/../package/gluon.mk
1313

1414
define Package/$(PKG_NAME)
1515
TITLE:=Implements switching to fallback mode if we are cut off from the mesh
16-
DEPENDS:=+gluon-autoupdater +gluon-site +gluon-state-check +iw +libgluonutil +libiwinfo-lua +luabitop +luaposix +micrond +wpa-supplicant-mini
16+
DEPENDS:=+gluon-autoupdater +gluon-site +gluon-state-check +iw +libgluonutil +libiwinfo-lua +libubus-lua +luabitop +luaposix +micrond
1717
MAINTAINER:=Freifunk Aachen <[email protected]>
1818
endef
1919

ffac-autoupdater-wifi-fallback/luasrc/usr/sbin/autoupdater-wifi-fallback

+28-21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local util = require 'gluon.util'
55
local bit = require 'bit'
66
local fcntl = require 'posix.fcntl'
77
local unistd = require 'posix.unistd'
8+
local ubus = require('ubus').connect()
9+
local wireless = require 'gluon.wireless'
810

911
local configname = 'autoupdater-wifi-fallback'
1012
local lockfilename = '/var/lock/' .. configname .. '.lock'
@@ -95,30 +97,22 @@ end
9597

9698
local function switch_to_fallback_mode(radio, ssid, bssid)
9799
autil.log('out', 'connecting to ' .. radio .. ' ' .. ssid .. ' ' .. bssid)
98-
uci:delete_all('wireless', 'wifi-iface')
99-
uci:section('wireless', 'wifi-iface', 'fallback', {
100-
device = radio,
101-
network = 'fallback',
102-
mode = 'sta',
103-
disabled = false,
104-
macaddr = util.generate_mac(3, 10),
105-
bssid = bssid,
106-
ssid = ssid,
107-
ifname = 'fallback',
108-
encryption = 'none',
109-
})
110-
uci:set('wireless', radio, 'disabled', false)
111-
uci:save('wireless')
112-
113-
os.execute('wifi')
114-
os.execute('sleep 5')
115-
uci:revert('wireless')
100+
os.execute('sleep 2')
101+
ubus:call('network', 'add_dynamic', {name = "fallback", ifname = "fallback", proto = "dhcp", device = "fallback", l3_device = "fallback"})
102+
ubus:call('network', 'add_dynamic', {name = "fallback6", ifname = "fallback", proto = "dhcpv6", device = "fallback", l3_device = "fallback"})
103+
ubus:call('network.interface.fallback', 'add_device', {name = "fallback"})
104+
ubus:call('network.interface.fallback6', 'add_device', {name = "fallback"})
105+
ubus:call('network.interface.fallback', 'up', {})
106+
ubus:call('network.interface.fallback6', 'up', {})
107+
os.execute('sleep 2')
108+
os.execute('iw dev fallback connect ' .. ssid .. ' ' .. bssid)
116109
os.execute('sleep 20')
117110
end
118111

119112
local function revert_to_standard_mode()
120113
autil.log('out', 'going back to standard mode')
121-
os.execute('/etc/init.d/network restart')
114+
os.execute('/etc/init.d/wpad start')
115+
os.execute('wifi up')
122116
os.execute('sleep 30')
123117
end
124118

@@ -142,19 +136,32 @@ if (force or preflight_check()) and not connectivity_check() then
142136

143137
if force or tonumber(unreachable_since) + offset < os.time() then
144138
autil.log('out', 'going to fallback mode')
139+
os.execute('wifi down')
140+
os.execute('/etc/init.d/wpad status >/dev/null && /etc/init.d/wpad stop')
145141
for radio, netlist in pairs(autil.get_available_wifi_networks()) do
142+
local radio_config = uci:get_all('wireless', radio)
143+
local phy = wireless.find_phy(radio_config)
144+
autil.log('out', 'using ' .. phy .. ' to create fallback interface')
145+
os.execute('iw phy ' .. phy .. ' interface add fallback type managed')
146+
os.execute('ip link set dev fallback up')
146147
for _, net in ipairs(netlist) do
147148
switch_to_fallback_mode(radio, net.ssid, net.bssid)
148149
if run_autoupdater() == 0 then
149150
break
150151
end
152+
ubus:call('network.interface.fallback', 'down', {})
153+
ubus:call('network.interface.fallback', 'remove', {})
154+
ubus:call('network.interface.fallback6', 'down', {})
155+
ubus:call('network.interface.fallback6', 'remove', {})
156+
os.execute('iw dev fallback disconnect')
151157
end
158+
os.execute('iw dev fallback del')
152159
end
153-
-- this is only reached if no updated happened
160+
-- this is only reached if no update happened
154161
revert_to_standard_mode()
155162
end
156163
else
157164
uci:delete(configname, 'settings', 'unreachable_since')
158165
uci:delete(configname, 'settings', 'last_run')
159166
uci:save(configname)
160-
end
167+
end

0 commit comments

Comments
 (0)