openWRT学习

发布时间 : 星期四 文章openWRT学习更新完毕开始阅读

openwrt学习

On the AP side you can enable 4-address frames for individual clients by isolating them in separate AP VLANs which are configured in 4-address mode. Such an AP VLAN will be limited to one client only, and this client will be used as the destination for all traffic on its interface, regardless of the destination MAC address in the packet headers. The advantage of this mode compared to regular WDS mode is that it's easier to configure and does not require a static list of peer MAC addresses on any side.

To enable 4-address mode when creating an interface you should add 4addr on, for example:

iw phy phy0 interface add moni0 type managed 4addr on

In hostapd you can enable this with the flag on hostapd.conf:

wds_sta=1

wifi启动

对于7161来讲,通过测试发现,通过/sbin/wifi脚本可以启动及关闭VAP。而每一次VAP修订,均会通过wifi up来再次生效。Wifi脚本会根据VAP的配置文件来创建相应的VAP,并调用hostapd来启用无线服务功能。配置文件如:

root@OpenWrt:/sbin# cat /etc/config/wireless config wifi-device 'radio0'

option type 'mac80211' option channel '11'

option macaddr '00:0e:8e:29:e5:98' option hwmode '11g' option txpower '27' option country 'CO'

config wifi-iface

option device 'radio0' option mode 'ap' option ssid 'OpenWrt' option encryption 'none'

config wifi-iface

option device 'radio0' option mode 'ap'

option encryption 'none'

版权所有?2012 成都科技有限公司

第 25 页 共 29 页

openwrt学习

option ssid 'ddd'

option wds '1'

/etc/init.d/rcS是设备的初始化接口,首先会执行system配置文件初始化,然后对/etc/rc.d下的所有可执行初始化脚本执行start操作。

在network的脚本中会执行/sbin/wifi up,在wifi脚本中会执行wifi_updown()函数脚本,如下:

wifi_updown() { [ enable = \ echo \ wifi_updown disable \ scan_wifi } for device in ${2:-$DEVICES}; do ( echo \ config_get disabled \

[ 1 == \ echo \ set disable }

config_get iftype \ 其中在7161上会通过调用enable_mac80211()脚本函数从而会将无线启动起来。 if eval \ echo \ eval \

echo \

eval \'$device'\|| echo \${1} failed\

else echo \

fi ); done }

设备首次启动会检测无线卡类型,检测是在/etc/rc.d中的boot脚本中: /sbin/wifi detect > /tmp/wireless.tmp

[ -s /tmp/wireless.tmp ] && { cat /tmp/wireless.tmp >> /etc/config/wireless

} rm -f /tmp/wireless.tmp

wifi_detect()会遍历所支持$DRIVER列表(当前打印为prism2 mac80211),判断并执行detect_mac80211()。脚本(boot中的)会创建一个默认配置文件(sample configuration file)。每一无线驱动都有自己的配置脚本(/lib/wifi/driver_name.sh),对于7161来讲则是

版权所有?2012 成都科技有限公司

第 26 页 共 29 页

openwrt学习

/lib/wifi/mac80211.sh。

hostapd的配置及启动是通过mac80211.sh来完成。在mac80211_hostapd_setup_base()中会根据当前的配置参数,写入hostapd的启动配置文件中/var/run/hostapd-phy0.conf。

enable_mac80211()中会启动hostapd,进行配置文件的实际生效,生效命令是hostapd -P /var/run/wifi-phy0.pid -B /var/run/hostap-phy0.conf。

注:

/sys/class/ieee80211/phy0/macaddress 中包括了phy0的MAC地址

root@OpenWrt:/tmp/sysinfo# cat /tmp/sysinfo/model 设备型号 Atheros PB44 reference board

root@OpenWrt:/tmp/sysinfo# cat /tmp/sysinfo/board_name board类型 unknown

WEB设置

LuCI(Lua Configuration Interface)

Openwrt中web页面是通过LuCI编写,这是什么东东只有上网搜索一下,此处是简单的说明。

LuCI作为“FFLuCI”诞生于2008年3月份,目的是为OpenWrt固件从 Whiterussian 到 Kamikaze实现快速配置接口。Lua是一个小巧的脚本语言,很容易嵌入其它语言。轻量级 LUA语言的官方版本只包括一个精简的核心和最基本的库。这使得LUA体积小、启动速度快,从而适合嵌入在别的程序里。UCI是OpenWrt中为实现所有系统配置的一个统一接口,英文名Unified Configuration Interface,即统一配置接口。LuCI,即是这两个项目的合体,可以实现路由的网页配置界面。

最初开发这个项目的原因是没有一个应用于嵌入式的免费,干净,可扩展以及维护简单的网页用户界 面接口。大部分相似的配置接口太依赖于大量的Shell脚本语言的应用,但是LuCi使用的是Lua编程语言,并将接口分为逻辑部分,如模板和视图。 LuCI使用的是面向对象的库和模板,确保了高效的执行,轻量的安装体积,更快的执行速度以及最重要的一个特性————更好的可维护性。

与此同时,LuCI从MVC-Webframework衍生出一个包含了很多库、程序以及Lua程序用户接口的集合,但是LuCI仍然专注于实现网页用户界面并成为OpenWrt Kamikaze官方的一份子。

LuCI是一个开放源码的独立项目,欢迎任何人的加入。

Web设置

Openwrt中web是通过LuCI编写,LuCI提供了丰富的接口,而将用户的配置保存,并

版权所有?2012 成都科技有限公司

第 27 页 共 29 页

openwrt学习

可通过调用linux中的脚本来进行实际应用。

因此我们猜测:

Openwrt有各模块的配置文件(在/etc/config/下),可通过web页面来修改,也可手动来修改;而对各模块的生效操作,可通过web来进行,也可手工来进行。

配置文件是各模块正确启动的依据,如果后续我们需要在openwrt基础上支持我们的产品,(1)可以直接在LuCI基础上以此为基础来写web代码;或(2)在当前代码基础上理清各模块的配置及生效接口,我们自己写web来实现。

具体可以/usr/lib/lua/luci/model/cbi/admin_network/wifi_add.lua为例。

m.uci:save(\保存配置

luci.sys.call(\通过脚本来实际应用 luci.sys.call(\

return os.execute(\ 执行reboot

静态页面在:

X:\\trunk\\build_dir\\target-mips_r2_uClibc-0.9.33\\root-ar71xx\%usr\\lib\\lua\\luci\\view下,即设备的\%usr\\lib\\lua\\luci\\view目录。

而类似于CGI的代码则在

X:\\trunk\\build_dir\\target-mips_r2_uClibc-0.9.33\\root-ar71xx\%usr\\lib\\lua\\luci\\controller\\admin下,即设备的\%usr\\lib\\lua\\luci\\controller\\admin目录。

web小测试

将/usr/lib/lua/luci/model/cbi/admin_network下的wifi.lua删除后,页面会报如下错误: /usr/lib/lua/luci/dispatcher.lua:449: Failed to execute arcombine dispatcher target for entry '/admin/network/wireless/radio0.network1'. The called action terminated with an exception:

/usr/lib/lua/luci/cbi.lua:75: Model 'admin_network/wifi' not found! stack traceback: [C]: in function 'assert'

/usr/lib/lua/luci/dispatcher.lua:449: in function 'dispatch' /usr/lib/lua/luci/dispatcher.lua:195: in function

频率信道转换函数

static int nl80211_freq2channel(int freq) {

版权所有?2012 成都科技有限公司

第 28 页 共 29 页

openwrt学习

}

if (freq == 2484)

return 14;

if (freq < 2484) return (freq - 2407) / 5; return (freq / 5) - 1000;

版权所有?2012 成都科技有限公司

第 29 页 共 29 页

联系合同范文客服:xxxxx#qq.com(#替换为@)