Browse Source

ffho-autoupdater-wifi-fallback: let get_available_wifi_networks() return a table of possible wifi networks

Karsten Böddeker 7 years ago
parent
commit
d09c13a692

+ 7 - 6
ffho/ffho-autoupdater-wifi-fallback/luasrc/usr/lib/lua/autoupdater-wifi-fallback/util.lua

@@ -7,25 +7,26 @@ function get_available_wifi_networks()
 
   uci:foreach('wireless', 'wifi-device',
     function(s)
-      table.insert(radios, s['.name'])
+      list[s['.name']] = {}
     end
   )
-  for _, radio in ipairs(radios) do
+
+  for radio, _ in pairs(radios) do
     local wifitype = iwinfo.type(radio)
     local iw = iwinfo[wifitype]
     if iw then
-      local list = iw.scanlist(radio)
-      for _, net in ipairs(list) do
+      local tmplist = iw.scanlist(radio)
+      for _, net in ipairs(tmplist) do
         if net.ssid and net.bssid then
           if net.ssid:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*') then
-            return radio, net.ssid, net.bssid
+            table.insert (radios[radio], net)
           end
         end
       end
     end
   end
 
-  return false
+  return radios
 end
 
 function get_update_hosts(branch)

+ 7 - 6
ffho/ffho-autoupdater-wifi-fallback/luasrc/usr/sbin/autoupdater-wifi-fallback

@@ -128,13 +128,14 @@ if (force or preflight_check()) and not connectivity_check() then
 
   if force or tonumber(unreachable_since) + offset < os.time() then
     io.popen('logger -s -t autoupdater-wifi-fallback -p local0.info "going to fallback mode"')
-    local radio, ssid, bssid = get_available_wifi_networks()
-    if radio and ssid and bssid then
-      switch_to_fallback_mode(radio, ssid, bssid)
-      run_autoupdater()
-      -- this is only reached if no updated happened
-      revert_to_standard_mode()
+    for radio, netlist in pairs(get_available_wifi_networks()) do
+      for _, net in ipairs(netlist) do
+        switch_to_fallback_mode(radio, net.ssid, net.bssid)
+        run_autoupdater()
+      end
     end
+    -- this is only reached if no updated happened
+    revert_to_standard_mode()
   end
 else
   uci:delete(configname, 'settings','unreachable_since')