Browse Source

ffho-autoupdater-wifi-fallback: bugfixes and improvements

/lib/gluon/upgrade/510-autoupdater-wifi-fallback:
- network config updated

/usr/lib/lua/autoupdater-wifi-fallback/util.lua:
- return radio, ssid and bssid

/usr/sbin/autoupdater-wifi-fallback:
- check if /sys/kernel/debug/batman_adv/bat0/gateways is readable
- update switch_to_fallback_mode() for own script /usr/sbin/wpa_supplicant
- improve log messages

/usr/sbin/wpa_supplicant: NEW
- script for executing iw dev <devname> connect [-w] <SSID> [<freq in MHz>] [<bssid>] [key 0:abcde d:1:6162636465]
- use bssid to specify the ap
Karsten Böddeker 8 years ago
parent
commit
a669bd4de5

+ 3 - 1
ffho/ffho-autoupdater-wifi-fallback/files/lib/gluon/upgrade/510-autoupdater-wifi-fallback

@@ -21,7 +21,9 @@ uci:delete('wireless', 'fallback')
 uci:delete('network','fallback')
 uci:section('network', 'interface', 'fallback',
   {
-    ifname = 'fallback',
+    proto = 'dhcpv6',
+    peerdns = 1,
+    sourcefilter = 0,
   }
 )
 

+ 2 - 3
ffho/ffho-autoupdater-wifi-fallback/files/usr/lib/lua/autoupdater-wifi-fallback/util.lua

@@ -16,9 +16,8 @@ function get_available_wifi_networks()
     if iw then
       local list = iw.scanlist(radio)
       for _, net in ipairs(list) do
-        local ssid = net.ssid:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*')
-        if ssid then
-          return radio, ssid
+        if net.ssid:match('.*[Ff][Rr][Ee][Ii][Ff][Uu][Nn][Kk].*') then
+          return radio, net.ssid, net.bssid
         end
       end
     end

+ 18 - 19
ffho/ffho-autoupdater-wifi-fallback/files/usr/sbin/autoupdater-wifi-fallback

@@ -48,13 +48,17 @@ local function preflight_check()
 end
 
 local function connectivity_check()
-  for line in io.lines("/sys/kernel/debug/batman_adv/bat0/gateways") do
-    local gateway_mac = line:match("^=?>? +([0-9a-f:]+)")
-    if gateway_mac then
-      if os.execute("batctl ping -t5 -c1 " .. gateway_mac .. " > /dev/null 2>&1") == 0 then
-        return true
+  local f = io.open('/sys/kernel/debug/batman_adv/bat0/gateways', 'r')
+  if f then
+    for line in f:lines() do
+      local gateway_mac = line:match("^=?>? +([0-9a-f:]+)")
+      if gateway_mac then
+        if os.execute("batctl ping -t5 -c1 " .. gateway_mac .. " > /dev/null 2>&1") == 0 then
+          return true
+        end
       end
     end
+    f:close()
   end
   
   -- connectivity check against updateserver
@@ -73,9 +77,8 @@ local function run_autoupdater()
   os.execute("/usr/sbin/autoupdater -f -b " .. branch_name)
 end
 
-local function switch_to_fallback_mode(ssid, radio)
-  print("connect to: " .. ssid .. " on " .. radio)
-  io.popen('logger -s -t autoupdater-wifi-fallback -p local0.info "going to fallback mode"')
+local function switch_to_fallback_mode(radio, ssid, bssid)
+  io.popen('logger -s -t autoupdater-wifi-fallback -p local0.info "connect to '  .. radio .. ' ' .. ssid .. ' ' .. bssid .. '"')
   uci:delete_all('wireless', 'wifi-iface')
   uci:section('wireless', 'wifi-iface', 'fallback',
     {
@@ -84,6 +87,8 @@ local function switch_to_fallback_mode(ssid, radio)
       mode = 'sta',
       disabled = 0,
       macaddr = gluon.generate_mac(3, 10),
+      bssid = bssid,
+      ssid = ssid,
       ifname = 'fallback',
       encryption = 'none',
     }
@@ -91,20 +96,13 @@ local function switch_to_fallback_mode(ssid, radio)
   uci:set('wireless', radio, 'disabled', 0)
   uci:save('wireless')
 
-  local f = io.open('/tmp/wpa-supplicant-fake', 'w')
-  f:write('#!/bin/sh\niw dev fallback connect -w ' .. ssid)
-  f:close()
-  fs.chmod('/tmp/wpa-supplicant-fake', 755)
-
-  io.popen("wifi")
+  os.execute("wifi")
   os.execute("sleep 5")
-  os.execute("echo \"2\" > /proc/sys/net/ipv6/conf/fallback/accept_ra")
   uci:revert('wireless')
   os.execute("sleep 20")
 end
 
 local function revert_to_standard_mode()
-  print("Going back to standard config")
   io.popen('logger -s -t autoupdater-wifi-fallback -p local0.info "going back to standard mode"')
   os.execute("/etc/init.d/network restart")
   os.execute("sleep 30")
@@ -129,9 +127,10 @@ if (force or preflight_check()) and not connectivity_check() then
   uci:save(configname)
   
   if force or tonumber(unreachable_since) + offset < os.time() then
-    local radio, wifiNetwork = get_available_wifi_networks()
-    if wifiNetwork then
-      switch_to_fallback_mode(wifiNetwork, radio)
+    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()

+ 0 - 1
ffho/ffho-autoupdater-wifi-fallback/files/usr/sbin/wpa_supplicant

@@ -1 +0,0 @@
-/tmp/wpa-supplicant-fake

+ 20 - 0
ffho/ffho-autoupdater-wifi-fallback/files/usr/sbin/wpa_supplicant

@@ -0,0 +1,20 @@
+#!/usr/bin/lua
+local uci = require('luci.model.uci').cursor()
+
+local ifnames = {}
+uci:foreach('wireless', 'wifi-iface',
+  function(s)
+    table.insert(ifnames, s['.name'])
+  end
+)
+
+for _, ifname in ipairs(ifnames) do
+  local iface = uci:get_all('wireless', ifname)
+  if not uci:get_bool('wireless', ifname, 'disabled') and iface.mode == 'sta' and iface.ifname and iface.device and iface.ssid then
+    local command = 'iw dev ' .. iface.ifname .. ' connect -w ' .. iface.ssid
+    if iface.bssid then
+      command = command .. ' ' .. iface.bssid
+    end
+    os.execute(command)
+  end
+end