前面讲的配置方式对于上级无线固定不变而且永久存在的情况是好使的。但是如果上级无线找不到的话,OpenWRT让人恶心的地方是下级无线,也就是703n路由器自身提供的无线也无法正常启动。这样如果你没有随身带着网线的话就没有办法登录到703n的web界面了,也就没有办法修改或者禁用上级无线。这不得不说是一个很令人遗憾的事情。

fqrouter的解决方式是在/etc/config/wireless中配置一个或者多个上级无线interface。默认这些上级无线的interface都是被禁用的。这样哪怕是上级无线不存在的话,703n自己的无线也能启动起来。这个默认的禁用动作是由一个启动脚本完成的(/etc/init.d/disable_sta_mode_wifi_interfaces)

然后扫描附近有的无线,如果发现了已经保存的上级无线,就启用对应的无线interface。这个时候会等待10秒钟,如果10秒内没有完成上级无线的连接,这个无线interface又会被重新禁用。这是因为上级无线的密码可能输入错误。这个智能检测并启用无线的动作是由一个hotplug脚本完成(/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
/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
——————————————————————————

————————————————————————-
#!/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
}
————————————————————————

————————————————————————–
#!/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
——————————————————————————————–

www.fuyufu.com

转载于:https://blog.51cto.com/fuyufu/1150255

openwrt无线连接互联网的实现原理【2】相关推荐

  1. openwrt无线连接互联网的实现原理【1】

    DD-WRT中的repeater bridge联网方式,在OpenWRT中称为routed client mode masqueraded.实现原理是这样的: OpenWRT的网络分为device = ...

  2. openwrt【703n固件】用户友好的界面配置无线连接互联网

    一般703n的用户是不会用有线的方式接入互联网的.有两个原因: 一个是703n自身硬件资源有限,不太可能做为主力路由器. 另外一个原因是703n只有一个有线网口,一旦有线用来连接互联网了,无线又挂了就 ...

  3. [网络配置] 使用有线网络连接局域网,使用无线网络连接互联网

    文章目录 局域网配置 无线网配置 背景: 笔者这里的局域网本身是桥接了一个互联网,但是网速很慢,所以想只使用局域网访问其他设备,使用手机热点的无线网来连接互联网.本博客就对配置过程进行了记录. 简单总 ...

  4. openwrt 无线中继设置–固定IP+打印服务器和文件共享

    openwrt 无线中继设置–固定IP+打印服务器和文件共享 因为给TPLINK703N,编译16MROM成功,固件里加入了打印服务器和SAMBA,VSFTPD,USB挂载等功能,可使用有线连接上级路 ...

  5. 手把手教你用AirtestIDE无线连接手机

    1. 前言 一直以来,我们发现同学们都挺喜欢用无线的方式连接手机,正好安卓11出了个无线连接的新姿势,我们今天就一起来看看,如何用AirtestIDE无线连接你的Android设备~ 2. Andro ...

  6. 中国联通李福昌:探索无线连接的未来

    来源:C114通信网 文:李福昌 无线技术在当今社会中发挥着重要的作用,特别是5G商用以来,无线技术的应用从以个人为主扩展到面向生产和社会,逐步践行"5G改变社会"的目标.展望未来 ...

  7. 物联网6类技术无线连接技术的分析

    [daodu]物联网应用已经深入我们生活,方方面面都能出现物联网项目应用.那么,物联网无线连接技术有哪些呢?本文以6类无线技术为例,深刻分析各类优缺点.[/daodu] [yiji]1. 以太网[/y ...

  8. 阿里云:面向5G时代的物联网无线连接服务

    在4月24日落幕的2019中国联通合作伙伴大会"5G+物联网(IoT)论坛"上,阿里云高级运营专家李茁出席圆桌对话,分享了5G时代物联网如何更好地推动行业完成生产.管理和商业模式的 ...

  9. 物联网无线连接服务发布 阿里云全新产品,物联网设备专用的物联网卡与流量套餐...

    产品介绍: 物联网(英语:Internet of Things,缩写IoT)是互联网.传统电信网等信息承载体,让所有能行使独立功能的普通物体实现互联互通的网络.物联网无线连接服务是三大运营商面向企业客 ...

最新文章

  1. CSS添加多个背景图片
  2. linux+qt导入构建,如何在Qt Creator项目向导中添加自定义构建步骤?
  3. 汇编语言 利用ASCII以及AND OR进行字符串大小写转换
  4. matlab批量生成灰度图像_科学网—matlab彩色图像的批处理转换为灰度、二值和主成分图图像 - 金秀良的博文...
  5. Lilypad Pondg(POJ-3171)
  6. selenium chrome历史版本docker镜像分享
  7. xlsl打开.xlsx格式表格报错:xlrd\__init__.py XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+‘; not supported‘
  8. 注意力模型(Attention Model)理解和实现
  9. 基础软件皇冠上的明珠,数据库创新 | 创新场景50
  10. ( 方框打勾 java_Java 11手册:Java 11是否在所有正确的方框中打勾?
  11. opengl绘制卡通人物哆啦A梦
  12. C语言平面几何11-点关于直线的对称点
  13. 二进制,十进制,十六进制相互转换(小白友好)
  14. 华为高端麒麟芯片或将绝版,余承东:应对方案已出!【附演讲全文】
  15. 实战为上!深入解析20个运维命令
  16. ubuntu16.04+ROS+科大讯飞+图灵AI机器人(四)——加入图灵机器人
  17. 手机网络邻居访问电脑_一起来看看手机如何访问电脑局域网共享的文件夹
  18. 2020年计算机双非保研经历分享(2021届)
  19. MSSQL 2005 如何批量修改表的架构SQL Server - 海狼工作室 - 杨远 - 和讯博客
  20. E码通电子凭证服务平台 通用接口接入规范

热门文章

  1. 【转载】upper_bound 和 lowwer_bound 用法
  2. H264视频传输、编解码----RTP协议对H264数据帧拆包、打包、解包过程
  3. 历史上三大骑士团的崛起与演变
  4. linux系统777,drwxr-xr-x权限详解
  5. IIS的安装与网站架设(For asp.net4.0)
  6. 《图解TCP/IP》阅读笔记
  7. matlab模拟嫦娥奔月,2018年英语四级翻译模拟题:嫦娥奔月
  8. 我的1周年创作纪念日
  9. 反射进阶,编写反射代码值得注意的诸多细节
  10. LightningChart出现闪电图全黑问题应该如何解决