Forked from fqrouter/00-only-enable-connectable-sta-mode-wifi-interface.sh
Last active
August 29, 2015 14:16
-
-
Save whhxp/a82853d885f93071418d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ -f /tmp/skip-only-enable-connectable-sta-mode-wifi-interface ] ; then | |
logger -s -t fqrouter skip-only-enable-connectable-sta-mode-wifi-interface found | |
return | |
fi | |
if [ "remove" == "$ACTION" -a "wlan0" == "$INTERFACE" ] ; then | |
/etc/init.d/disable_sta_mode_wifi_interfaces start | |
fi | |
if [ "add" == "$ACTION" -a "wlan0" == "$INTERFACE" ] ; then | |
logger -s -t fqrouter try to bring up sta mode wifi interface | |
sta-mode-wifi-interface-up & | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
START=19 # just before network start | |
disable_sta_mode_wifi_interface() { | |
local section="$1" | |
config_get mode $section 'mode' | |
config_get ssid $section 'ssid' | |
if [ sta == $mode ] ; then | |
logger -s -t fqrouter disable sta mode wifi interface $ssid | |
uci_set wireless $section disabled 1 | |
fi | |
} | |
start() { | |
config_load 'wireless' | |
config_foreach disable_sta_mode_wifi_interface 'wifi-iface' | |
uci_commit | |
logger -s -t fqrouter all sta mode wifi interfaces disabled | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/lua | |
require 'uci' | |
require 'dumper' | |
require 'nixio' | |
local pid_file = io.open('/tmp/sta-mode-wifi-interface-up.pid', 'r') | |
if pid_file ~= nil then | |
local that_pid = pid_file:read('*a') | |
io.close(pid_file) | |
os.execute('logger -s -t fqrouter sta-mode-wifi-interface-up that pid is: ' .. that_pid) | |
local cmdline_file = io.open('/proc/' .. that_pid .. '/cmdline', 'r') | |
if cmdline_file ~= nil then | |
io.close(cmdline_file) | |
os.execute('logger -s -t fqrouter sta-mode-wifi-interface-up found another instance ' .. that_pid) | |
os.exit() | |
end | |
end | |
local this_pid = nixio.getpid() | |
os.execute('echo -n ' .. this_pid .. ' > /tmp/sta-mode-wifi-interface-up.pid') | |
os.execute('logger -s -t fqrouter sta-mode-wifi-interface-up.pid: ' .. this_pid) | |
x = uci.cursor() | |
function exit_if_sta_mode_wifi_interface_enabled(section) | |
if 'sta' == section.mode and '0' == section.disabled then | |
os.execute('logger -s -t fqrouter std mod wifi interface ' .. section.ssid .. ' already enabled') | |
os.exit() | |
end | |
end | |
x:foreach('wireless', 'wifi-iface', exit_if_sta_mode_wifi_interface_enabled) | |
os.execute('logger -s -t fqrouter no sta mode wifi interface enabled') | |
function is_interface_up(ifname) | |
local f = assert(io.popen('ifconfig '..ifname, 'r')) | |
local output = assert(f:read('*a')) | |
return output:find('RUNNING') | |
end | |
for count=1,10 do | |
if is_interface_up('wlan0') then | |
break | |
end | |
os.execute('sleep 1') | |
end | |
if not is_interface_up('wlan0') then | |
os.execute('logger -s -t fqrouter wlan0 not up in given time') | |
os.exit() | |
end | |
os.execute('logger -s -t fqrouter wlan0 is up') | |
local ssid_list = {} | |
local ssid_present = {} | |
for i = 1, 3 do | |
local iw = require'luci.sys'.wifi.getiwinfo('radio0') | |
for k, v in ipairs(iw.scanlist or {}) do | |
if v.ssid ~= nil and ssid_present[v.ssid] == nil then | |
table.insert(ssid_list, v.ssid) | |
ssid_present[v.ssid] = v | |
end | |
end | |
os.execute('logger -s -t fqrouter "ssid list: ' .. table.concat(ssid_list, ', ') .. '"') | |
end | |
local no_sta_mode_wifi_interface_configured = true | |
function enable_sta_mode_wifi_interface(section) | |
if 'sta' == section.mode then | |
no_sta_mode_wifi_interface_configured = false | |
if ssid_present[section.ssid] ~= nil then | |
os.execute('logger -s -t fqrouter found ' .. section.ssid) | |
x:set('wireless', section['.name'], 'disabled', 0) | |
x:commit('wireless') | |
os.execute('touch /tmp/skip-only-enable-connectable-sta-mode-wifi-interface') | |
os.execute('wifi up') | |
os.execute('rm /tmp/skip-only-enable-connectable-sta-mode-wifi-interface') | |
os.execute('sleep 10') | |
if is_interface_up('wlan0-1') then | |
os.execute('rm /tmp/upstream-status') | |
else | |
os.execute('echo "UPSTREAM_TIMEOUT" > /tmp/upstream-status') | |
os.execute('logger -s -t fqrouter sta mode wifi interface not up in given time') | |
x:set('wireless', section['.name'], 'disabled', 1) | |
x:commit('wireless') | |
os.execute('touch /tmp/skip-only-enable-connectable-sta-mode-wifi-interface') | |
os.execute('wifi down') | |
os.execute('wifi up') | |
os.execute('rm /tmp/skip-only-enable-connectable-sta-mode-wifi-interface') | |
end | |
os.exit() | |
end | |
end | |
end | |
x = uci.cursor() | |
x:foreach('wireless', 'wifi-iface', enable_sta_mode_wifi_interface) | |
if no_sta_mode_wifi_interface_configured then | |
os.execute('echo "UPSTREAM_NOT_CONFIGURED" > /tmp/upstream-status') | |
os.execute('logger -s -t fqrouter no sta mode wifi interface configured') | |
else | |
os.execute('echo "UPSTREAM_NOT_AVAILABLE" > /tmp/upstream-status') | |
os.execute('logger -s -t fqrouter no sta mode wifi interface available') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment