1、
1.1 打开 /barrier_breaker/package/base-files/files/etc/init.d
加入 disable_sta_mode_wifi_interfaces
#!/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' config_get disabled $section 'disabled' #获取的是uci中的内容,如果uci中没有才获取配置文件 if [ sta == $mode ] ; then if [ 0 -eq $disabled ] || [ -z $disabled ] ; then #判断disabled是否为0或为空 logger -s -t fqrouter disable sta mode wifi interface $ssid uci_set wireless $section disabled 1 else subvar="no_need_sta" echo "$subvar" > /tmp/temp.txt #不加目录不知存在什么地方 logger -s -t fqrouter does not need to open sta mode exit fi 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 }
注意:(1)、其中包含两个条件的判断语句要这样写
if [ 0 -eq $disabled ] || [ -z $disabled ] ; then
或
if [[ 0 -eq $disabled || -z $disabled ]] ; then
注意中括号要和里面的内容要有空格隔开。
(2)、赋值语句要这样写
subvar="no_need_sta"
等号两边不能有空格
1.2 设置权限为775
2、
2.1 打开 /barrier_breaker/package/base-files/files/etc/hotplug.d/net
加入00-only-enable-connectable-sta-mode-wifi-interface
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 #先remove sta模式的wifi,会禁用上级wifi /etc/init.d/disable_sta_mode_wifi_interfaces start fi if [ "add" == "$ACTION" -a "wlan0" == "$INTERFACE" ] ; then #再搜索是否存在上级wifi,存在则添加 read pvar < /tmp/temp.txt if [ "no_need_sta" == "$pvar" ] ; then logger -s -t fqrouter exit sta mode success rm /tmp/temp.txt exit else logger -s -t fqrouter try to bring up sta mode wifi interface # try to bring up sta mode wifi interface为打印出来的内容 sta-mode-wifi-interface-up & #在后台运行 fi fi
3.2 设置权限为664
3、
3.1 打开 barrier_breaker/package/base-files/files/sbin
加入 sta-mode-wifi-interface-up
#!/usr/bin/lua require 'uci' --require 'dumper' require 'nixio' x = uci.cursor() --move by tingpan 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) --1有执行 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) --2有执行,下次会继续执行到该处 x:set('wireless', 'cfg053579', 'disabled', 0) --add by tingpan 恢复配置的初始值,为下次作准备。 x:commit('wireless') os.exit() end end local this_pid = nixio.getpid() --获取pid 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) --[[ --检查是否已经开启sta模式,在最开始时有作判断,此处注释 x = uci.cursor() --可放x:foreach前试试 function exit_if_sta_mode_wifi_interface_enabled(section) --怎么似乎执行不到该处 if 'sta' == section.mode and '0' == section.disabled then --根据uci作判断,不按配置文件判断 os.execute('logger -s -t fqrouter std mod wifi interface ' .. section.ssid .. ' already enabled') --当一开始时没有关闭sta模式的wifi,则执行 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') --3有执行 ]]-- 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') --如果有配置上级wifi,而又不存在时,有用 os.execute('wifi up') --add by tingpan 有用,如果按原来的话要再重启一次 x:set('wireless', 'cfg053579', 'disabled', 0) --add by tingpan 恢复配置的初始值,为下次作准备。 x:commit('wireless') os.exit() end os.execute('logger -s -t fqrouter wlan0 is up') --4有执行,已经开启wifi了 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, ', ') .. '"') --5、会列出搜到的所有信号 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 --if not (ssid_present[section.ssid] ~= nil) or '0' == section.disabled then --同时满足两个条件要这样写 os.execute('logger -s -t fqrouter found ' .. section.ssid) --6、查找到想要的信号,之后继续执行脚本文件 x:set('wireless', section['.name'], 'disabled', 0) --会执行到该句子 section['.name'] 为cfg053579 x:commit('wireless') os.execute('touch /tmp/skip-only-enable-connectable-sta-mode-wifi-interface') os.execute('wifi up') --相当于重启wifi 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) --设置disabled为1 x:commit('wireless') os.execute('touch /tmp/skip-only-enable-connectable-sta-mode-wifi-interface') os.execute('wifi down') --关闭wifi,ap和sta模式都关闭 os.execute('wifi up') os.execute('rm /tmp/skip-only-enable-connectable-sta-mode-wifi-interface') end x:set('wireless', section['.name'], 'disabled', 0) --add by tingpan 恢复配置的初始值,为下次作准备。 x:commit('wireless') os.exit() end end end x = uci.cursor() x:foreach('wireless', 'wifi-iface', enable_sta_mode_wifi_interface) --3、 if no_sta_mode_wifi_interface_configured then --如果没有设置sta模式 os.execute('echo "UPSTREAM_NOT_CONFIGURED" > /tmp/upstream-status') --写入到该文件中 os.execute('logger -s -t fqrouter no sta mode wifi interface configured') --在log文件中记录 else --有设置却没搜到 os.execute('echo "UPSTREAM_NOT_AVAILABLE" > /tmp/upstream-status') os.execute('logger -s -t fqrouter no sta mode wifi interface available') x:set('wireless', 'cfg053579', 'disabled', 0) --add by tingpan 恢复配置的初始值,为下次作准备。 x:commit('wireless') end
3.2设置权限为775
相关资源: