Skip to content

Commit

Permalink
ffac-autoupdater-wifi-fallback: clarify interface and network, remove…
Browse files Browse the repository at this point in the history
… old wireless config change, remove unrequired ubus calls and params
  • Loading branch information
maurerle committed Nov 2, 2024
1 parent 53f47a9 commit ff62ced
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ uci:section('autoupdater-wifi-fallback', 'autoupdater-wifi-fallback', 'settings'
enabled = enabled,
})

uci:delete('wireless', 'fallback')
uci:delete('network', 'fallback')
uci:delete('network', 'fallback6')

Expand All @@ -32,7 +31,6 @@ uci:section('network', 'interface', 'fallback6',{

uci:save('autoupdater-wifi-fallback')
uci:save('network')
uci:save('wireless')

local file = io.open('/usr/lib/micron.d/autoupdater', 'r')
local content = file:read "*a"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,20 @@ end

local function switch_to_fallback_mode(radio, ssid, bssid)
autil.log('out', 'connecting to ' .. radio .. ' ' .. ssid .. ' ' .. bssid)
os.execute('sleep 2')
ubus:call('network', 'add_dynamic', {name = "fallback", ifname = "fallback", proto = "dhcp", device = "fallback", l3_device = "fallback"})
ubus:call('network', 'add_dynamic', {name = "fallback6", ifname = "fallback", proto = "dhcpv6", device = "fallback", l3_device = "fallback"})
ubus:call('network.interface.fallback', 'add_device', {name = "fallback"})
ubus:call('network.interface.fallback6', 'add_device', {name = "fallback"})
ubus:call('network.interface.fallback', 'up', {})
ubus:call('network.interface.fallback6', 'up', {})
os.execute('sleep 2')
os.execute('iw dev fallback connect ' .. ssid .. ' ' .. bssid)
os.execute('sleep 2')
ubus:call('network', 'add_dynamic', {name = "fallback", proto = "dhcp"})
ubus:call('network', 'add_dynamic', {name = "fallback6", proto = "dhcpv6"})
ubus:call('network.interface.fallback', 'add_device', {name = "fallback_if"})
ubus:call('network.interface.fallback6', 'add_device', {name = "fallback_if"})
os.execute('sleep 2')
os.execute('iw dev fallback_if connect ' .. ssid .. ' ' .. bssid)
os.execute('sleep 20')
end

local function revert_to_standard_mode()
autil.log('out', 'going back to standard mode')
os.execute('/etc/init.d/wpad start')
os.execute('wifi up')
os.execute('/etc/init.d/wpad start')
os.execute('wifi up')
os.execute('sleep 30')
end

Expand All @@ -136,28 +134,26 @@ if (force or preflight_check()) and not connectivity_check() then

if force or tonumber(unreachable_since) + offset < os.time() then
autil.log('out', 'going to fallback mode')
os.execute('wifi down')
os.execute('/etc/init.d/wpad status >/dev/null && /etc/init.d/wpad stop')
os.execute('wifi down')
os.execute('/etc/init.d/wpad status >/dev/null && /etc/init.d/wpad stop')
for radio, netlist in pairs(autil.get_available_wifi_networks()) do
local radio_config = uci:get_all('wireless', radio)
local phy = wireless.find_phy(radio_config)
autil.log('out', 'using ' .. phy .. ' to create fallback interface')
os.execute('iw phy ' .. phy .. ' interface add fallback type managed')
os.execute('ip link set dev fallback up')
local radio_config = uci:get_all('wireless', radio)
local phy = wireless.find_phy(radio_config)
autil.log('out', 'using ' .. phy .. ' to create fallback_if interface')
os.execute('iw phy ' .. phy .. ' interface add fallback_if type managed')
os.execute('ip link set dev fallback_if up')
for _, net in ipairs(netlist) do
switch_to_fallback_mode(radio, net.ssid, net.bssid)
if run_autoupdater() == 0 then
break
end
ubus:call('network.interface.fallback', 'down', {})
ubus:call('network.interface.fallback', 'remove', {})
ubus:call('network.interface.fallback6', 'down', {})
ubus:call('network.interface.fallback6', 'remove', {})
os.execute('iw dev fallback disconnect')
ubus:call('network.interface.fallback', 'remove', {})
ubus:call('network.interface.fallback6', 'remove', {})
os.execute('iw dev fallback_if disconnect')
end
os.execute('iw dev fallback del')
os.execute('iw dev fallback_if del')
end
-- this is only reached if no update happened
-- this is only reached if no update happened
revert_to_standard_mode()
end
else
Expand Down

0 comments on commit ff62ced

Please sign in to comment.