openwrt学习总结(转载)

Openwrt编译及烧写
Build.tex      Building an image
       Openwrt 采用不同的方式来build a firmware ,从头开始来dowloading patching compiling 一切,包括交叉编译器。也就是说,openwrt 不包含任何可执行程序,甚至源代码,他自动下载源代码、打补丁来满足指定平台,并编译。通过修改template ,我们就可以改变此过程中的任何步骤。
        例如,如果一新的kernel 发布了,只需要简单地修订其中的一个makefile 文件就会download 最新的kernel patch ,编译新的firmware 映像。这不仅适用于kernel ,也适用于openwrt 的所有模块,包含openwrt 。这使得openwrt 保持最新的编译器、最新的内核及最新的应用。
     Download OpenWrt
       Openwrt 的下载方式:
       svncheckout svn://svn.openwrt.org/openwrt/trunk openwrt-trunk
        https://dev.openwrt.org/ 上有一个trac 接口,可用来检视svn 提交及浏览源代码仓库。
     The directory structure
        有四个关键目录:Tools Toolchain Package Target
      toolstoolchain
        其中tools toolchain 是通用工具,用来编译firmware image 、编译器及C 库。其编译结果是三个新的目录:build_dir/host ,临时目录,用来build target 独立的工具;build_dir/toolchain-<arch> ,用来编译特定architecture toolchain staging_dir/toolchain-<arch> toolchain 编译结果的安装目录;对于toolchain 目录不需要做任何事情,除非you intend to add a new version of one of the components above
      Package
       Package 包目录,在openwrt firmware 中,所有模块均是.ipk ,这种软件包可用来add to iremware 中来提供新的特性或去除以节省空间。这些软件包也是在主干外维护的,并可通过packagefeed 系统来获取到。
       ./scripts/feedsupdate
      
Those packages can be used to extend thefunctionality of the build system and need to be symlinked into the main trunk.Once you do that, the packages will show up in the menu for configuration. Youwould do something like this:
./scripts/feeds search nmap
Search results in feed 'packages':
nmap      Network exploration and/or security auditing utility
$ ./scripts/feeds install nmap
To include all packages, issue thefollowing command:
$ make package/symlinks
Target
Target 指的是嵌入式平台,包括特定嵌入式平台的内容。其中target/linux 目录,which is broken down by platform <arch> ,包含了特定平台的kernel patch  profile config Target/image 目录描述了怎么为特定平台打包firmware
Target package 步骤均会使用build_dir/<arch> 作为临时目录来编译,另外,toolchain target package 步骤所下载的内容均会放到dl 目录下。
Building OpenWrt
       
Creating packages
       
Creating binary packages
       
Creating kernel modules packages
       
Conventions
       
Troubleshooting
       
Using build environments
       
Config.tex 配置文件结构
Structure of the configuration files
配置文件分为sections options/values 对。每一section 有一type ,但不一定需要name 。每一option 有一个name value ,写在其所属于的section 中。
语法如下:
config     <type> ["<name>"]      # Section
   option  <name>"<value>"       # Option
每一参数应当是单一字符串,isformatted exactly like a parameter for a shell function 。引号及特殊字符规则仍然适用,他们将被shell 解释。
Parsing configuration files incustom scripts
        为了load configuration files ,必须包含通用功能脚本:
       ./etc/functions.sh
        这样就可以使用config_load<name> 来加载配置文件,功能会首先以<name> 作为文件名来检查,并从/etc/config 中加载。(这是最通用的使用方式)
       Ifyou want to use special callbacks for sections and/or options, you need todefine the following shell functions before running \texttt{config\_load} (afterincluding \texttt{/etc/functions.sh}):
config_cb() {
   local type="$1"
   local name="$2"
    #commands to be run for every section
}
option_cb() {
    #commands to be run for every option
}
wireless.tex文档部分学习
       WiFi 配置文件为/etc/config/wireless 。当前支持broadcom atheros mac80211
        设备首次启动会检测无线卡类型,并创建一个默认配置文件(sampleconfiguration file )。每一无线驱动都有自己的配置脚本(/lib/wifi/driver_name.sh ),用来处理驱动特定的选项及配置,脚本也会调用驱动特定的二进制如适用于broadcom wlc ,适用于atheros mac80211 hostapd wpa_supplicant
        这种结构(architecture )抽象了驱动配置。
        通用的broadcom 无线配置(略):
        通用的mac80211 无线配置(略):
通用的atheros无线配置:
config wifi-device      "wifi0"
   option type        "atheros"
   option channel      "5"
   option hwmode      "11g"
config wifi-iface
   option device       "wifi0"
#  option network  lan
   option mode         "ap"
   option ssid        "OpenWrt"
   option hidden       "0"
optionencryption   "none"
通用的多radio atheros无线配置:
configwifi-device  wifi0
    option type     atheros
    option channel  1
configwifi-iface
    option device   wifi0
#   option network  lan
    option mode     ap
    option ssid     OpenWrt_private
    option hidden   0
    option encryption none
configwifi-device  wifi1
    option type     atheros
    option channel  11
configwifi-iface
    option device   wifi1
#   option network  lan
    option mode     ap
    option ssid     OpenWrt_public
    option hidden   1
    option encryption none
配置文件详述
配置文件有两部分,一是wifi-device,指的是物理wifi接口,而wifi-iface指的是其上的虚拟接口,即VAP。
整个的配置文件如下:
configwifi-device    wifi device name
    option type       broadcom, atheros, mac80211      所支持的驱动类型
    option country    us, uk, fr, de, etc.          国家码
    option channel    1-14               wifi信道,依赖于国家码
    option maxassoc   1-128 (broadcom only) 关联的最大client数目,仅broadcom支持。
    option distance   1-n (meters)  AP与最远的client的距离,仅atheros芯片支持
    option hwmode     11b, 11g, 11a,11bg (atheros, mac80211) 频率带宽,仅atheros支持。
    option rxantenna  0,1,2 (atheros, broadcom) 接收端天线标识 (Antenna identifier)
    option txantenna  0,1,2 (atheros, broadcom) 发送端天线标识 (Antenna identifier)
    option txpower  transmission power in dBm 发射功率transmission power
configwifi-iface
    option network  the interface you want wifi to bridge withwifi要使用的网络接口
    option device   wifi0, wifi1, wifi2, wifiN wifi设备名
    option mode     ap, sta, adhoc, monitor, mesh, or wds 操作模式,有AP、clientmode、adhoc、monitor、mesh point mode(802.11s)及WDS点对点连接。
    option txpower  (deprecated) transmission power in dBm 发送功率,应设置在wifi-device。
    option ssid     ssid name SSID名字
    option bssid    bssid address 用于WDS,设置为otherWDS unit的MAC地址
    option encryption none, wep, psk, psk2,wpa, wpa2 加密设置,支持none、WEP、pre-shared key、及wpa radius。
    option key      encryption key
    option key1     key 1
    option key2     key 2
    option key3     key 3
    option key4     key 4
    option passphrase 0,1 0则将WPA psk为明文passphrase,1则为encoded passphrase。可通过wpa_passphrase工具产生加密的passphrase。在passphrase包含特殊字符时有用。此选项仅适用于mac80211或atheros。
    option server   ip address radius server IP地址
    option port     port radius server端口号,缺省为1812
    option hidden   0,1 0为广播SSID,1为隐藏
    option isolate  0,1 (broadcom)无线客户端隔离功能,0要禁止隔离,1为开启,缺省为0.
    option doth     0,1     (atheros,broadcom) Toggle 802.11h mode,0为禁止802.11h,1为启用,缺省为0.
    option wmm      0,1  (atheros,broadcom) Toggle 802.11e mode,0为禁止,1为启用,缺省为0.
Mesh Point
Mesh Point (802.11s) 仅mac80211 驱动支持,需要安装iw包来建立mesh link。Openwrt创建mshN mesh point接口,配置举例:
configwifi-device      "wlan0"
    option type            "mac80211"
    option channel      "5"
configwifi-iface
    option device       "wlan0"
    option network     lan
    option mode         "mesh"
    option mesh_id     "OpenWrt"
WDS
WirelessDistribution System
WDS是个非标准模式,可工作在同类设备间,但不能工作在不同的设备如broadcom和atheros设备间。
Unencrypted WDS connections
未加密的WDS配置如下,我们假定一端的BSSIDca:fe:ba:be:00:01,而另一端为BSSIDca:fe:ba:be:00:01:
configwifi-device      "wl0"
    option type            "broadcom"
    option channel      "5"
configwifi-iface
    option device       "wl0"
    option network     lan
    option mode         "ap"
    option ssid         "OpenWrt"
    option hidden       "0"
    option encryption   "none"
configwifi-iface
    option device       "wl0"
    option network      lan
    option mode         wds
    option ssid         "OpenWrt WDS"
    option bssid        "ca:fe:ba:be:00:02"
Encrypted WDS connections
可以加密wds连接,支持psk、psk2及psk+psk2模式,以下是一个使用AES加密算法的pre-sharedkey例子:
configwifi-device  wl0
    option type     broadcom
    option channel  5
configwifi-iface
    option device   "wl0"
    option network  lan
    option mode     ap
    option ssid     "OpenWrt"
    option encryption  psk2
    option key      "<key for clients>"
configwifi-iface
    option device   "wl0"
    option network  lan
    option mode     wds
    option bssid    ca:fe:ba:be:00:02
    option ssid     "OpenWrt WDS"
    option encryption   psk2
    option key      "<psk for WDS>"
802.1x configurations
       配置略
EAP-PEAP
       配置略
限制说明
Limitations
There arecertain limitations when combining modes. Only the following mode combinationsare supported:
WDS links canonly be used in pure AP mode and cannot use WEP (except when sharing the        settings with the master interface,which is done automatically).
VAP numdefaults to 4, but can be changed by loading the module with the maxvaps=Nparameter.
Adding a new driver configuration
       具体添加方式略
Network-scripts.tex Using the network scripts
为使用network,必须通过如下方式包含必须的shell脚本:
./etc/functions.sh      # common functions
include/lib/network     # include/lib/network/*.sh
scan_interfaces          # read and parse the network config
有些协议,如PPP会在运行期间改变配置的接口名,如PPPOE会将eth0改为ppp0,因此要运行scan_interface,而不是从配置中直接读取。运行scan_interface后,ifname选项将包含有效的接口名(用于iptraffic),如果物理设备名与此不同,则会保存在device选项中。
这意味着在scan_interface后运行config_get_lan_ifname,获取的结果可能与运行之前不同。
Writing protocol handers
添加协议处理
可通过在/lib/network下添加shell脚本来定制协议处理,脚本包含:
scan_<protocolname>(){
    local config="$1"
    # change the interface names if necessary
}
setup_interface_<protocolname>(){
    local interface="$1"
    local config="$2"
    # set up the interface
}
Network.tex      网络接口配置
网络配置文件为/etc/config/network,被分隔为多个接口配置。每一个接口配置或直接就是ethernet/wifi接口(如eth0、wl0),或包含多个接口的桥接口。
如:
configinterface     "lan"
    option ifname    "eth0"
    option proto     "static"
    option ipaddr    "192.168.1.1"
    option netmask   "255.255.255.0"
    option gateway   "192.168.1.254"
    option dns       "192.168.1.254"
其中ifname指定linux接口名,如果使用bridge接口则将ifname设置为接口列表,同时添加option type “bridge”。
可通过添加vlanid来支持vlan功能如eth0.1,具体参照switch一节。
此配置是一个简单的eth0静态配置,proto指定了接口使用的协议,支持none、static、dhcp,可通过install额外的包来支持其他的协议。
Static
当为static时,ipaddr与netmask必填,而gateway与dns可选,支持多个DNS服务器,中间以空格隔开即可,如:option dns       "192.168.1.254192.168.1.253" (optional)
如:
configinterface     "lan"
    option ifname    "eth0"
    option proto     "static"
    ...
    option dns       "192.168.1.254 192.168.1.253"(optional)
DHCP
DHCP当前仅接受ipaddr与hostname选项。其中ipaddr指定了dhcp server的地址,而hostname指定了客户的的hostname标识,两者均可选。
configinterface     "lan"
    option ifname    "eth0"
    option proto     "dhcp"
    option ipaddr    "192.168.1.1" (optional)
    option hostname  "openwrt" (optional)
PPPOE
PPP基础的协议,如PPPOE、PPTP支持下列选项:
Username:PPP用户名,用于PAP认证
Password:PPP密码
Keepalived:使用LCP ping PPP服务器,保活值,缺省间隔为5.
Demand:按需拨友,值指定了最大空闲时间。
Server:对端PPTP服务器IP地址
MTU设置
对所有协议,均可指定MTU,通过设置mtu选项即可,如:
configinterface     "lan"
    option ifname    "eth0"
    option proto     "pppoe"
    option username  "username"
    option password  "openwrt"
    option mtu          1492 (optional)
设置静态路由
Setting upstatic routes
可对指定的接口添加静态路由,在接口配置后会自动添加,举例配置:
config routefoo
       option interface lan
       option target 1.1.1.0
       option netmask 255.255.255.0
       option gateway 192.168.1.1
其中route节的名称可选,interface、target、gateway选项是必须的。如果netmsk不填,则默认为主机路由。
设置交换机
Setting up theswitch (currently broadcom only)
设置交换机,当前仅broadcom支持。
IPV6设置
Setting up IPv6connectivity
Init_script.tex 功能脚本
由于openwrt使用自己的初始script系统,所有的initscript必须使用/etc/rc.common作为wrapper安装在/etc/init.d/<name>下。
如/etc/init.d/httpd:
#!/bin/sh/etc/rc.common
# Copyright (C)2006 OpenWrt.org
START=50
start() {
    [ -d /www ] && httpd -p 80 -h /www-r OpenWrt
}
stop() {
    killall httpd
}
从上可以看出,script本身并不解析命令行参数,而是由/etc/rc.common来完成。
Start和stop是最基本的功能,几乎所有init script都要提供。Start是在运行/etc/init.d/httpdstart时来调用,可以是系统启动时,或用户手动运行此脚本时。
通过/etc/init.d/<name> enable/disable可以启用或禁止模块的初始化脚本,他是通过创建或删除/etc/rc.d中的符号连接来完成,而这些符号连接是/etc/init.d/rcS在启动阶段处理。
脚本运行的顺序是在初始脚本中通过变量START来定义,改变后需要再次运行/etc/init.d/<name>enable。
/etc/rc.common说明
#!/bin/sh                                
# Copyright (C)2006-2011 OpenWrt.org   
                                         
.$IPKG_INSTROOT/lib/functions.sh        
.$IPKG_INSTROOT/lib/functions/service.sh
                  
initscript=$1     
action=${2:-help}   
shift 2            
                    
start() {                                 
        return 0                                
}                                               
                                                
stop() {                                       
        return 0                                
}                                               
                                               
reload() {                                
        return 1                                                           
}                                                                          
                                                                           
restart() {                                                                                            
        trap '' TERM                                                                                 
        stop "$@"                                                                                      
        start "$@"                                                                                    
}                                                                                                     
                                                                                                      
boot() {                                                                                             
        start "$@"                                                   
}                                                                          
                                                                           
shutdown(){                                                               
        stop                                                                                          
}                                                                                                     
                                                                                                      
disable(){          禁止服务开启                                                                                 
        name="$(basename"${initscript}")"                                                            
        rm -f"$IPKG_INSTROOT"/etc/rc.d/S??$name                                                     
        rm -f"$IPKG_INSTROOT"/etc/rc.d/K??$name                           
}                                                                          
                                                                           
enable() {          开启服务                                                                                   
        name="$(basename"${initscript}")"                                                            
        disable                                                                                       
        [ -n "$START" -o -n"$STOP" ] || {                                                            
                echo "/etc/init.d/$namedoes not have a START or STOP value"                           
                return 1                                                                              
        }                                                                                             
        [ "$START" ] && ln -s"../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
        [ "$STOP"  ] && ln -s"../init.d/$name""$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
}
enabled(){                                                                                          
        name="$(basename"${initscript}")"                                                            
        [ -x"$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]                                
}                                                                     
                                                                           
depends(){                                                               
        return 0                                                           
}                                                                                                      
                                                                                                      
help() {                                                                                               
        cat <<EOF                                                                                    
Syntax:$initscript [command]                                                                        
                                                                                                     
Availablecommands:                                                        
        start  Start the service                                          
        stop   Stop the service                                            
        restart Restart the service                                                                  
        reload Reload configuration files (or restart if that fails)                                 
        enable Enable service autostart                                                              
        disable Disable service autostart                                                            
$EXTRA_HELP                                                                                            
EOF                                                                                                   
}                                                                                                     
                                                                                                      
."$initscript"          引用脚本                                                                           
                                                                     
ALL_COMMANDS="startstop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"  所有命令,包括标准的,及定制的
list_containsALL_COMMANDS "$action" || action=help                                                   
["$action" = "reload" ] && action='eval reload"$@" || restart "$@" && :'                             
$action"$@"
重载初始化脚本函数
可以通过如下方式覆盖这些标准的初始化脚本函数:
{boot()},boot时支持的命令,缺省为start。
        Commands to be run at boot time.Defaults to {start()}
{restart()} 重启动服务,缺省为stop然后再start。
        Restart your service. Defaults to{stop(); start()}
{reload()} 重新载入配置文件,缺省是restart。
        Reload the configuration files for yourservice. Defaults to {restart()}
定制脚本命令
也可定制命令,创建功能函数,在EXTRA_COMMANDS变量中引用,Helptext添加在EXTRA_HELP中。
如下:
status() {
    # print the status info
}
EXTRA_COMMANDS="status"
EXTRA_HELP="        status Print the status of the service"
在/etc/rc.common中可以看出,会包含此脚本,从而包含了其中的所有定义,从而可正确地去使用。
Iw
        openwrt 中,所有无线的配置均通过iw 命令来进行,如创建一个monitor  无线接口:iw phy phy0 interface add wd2jtype monitor
       Iw 的设备操作可通过mac80211.sh 中查看及分析。
        通过iw phy0 info 可查看硬件支持信息。


Iw命令行
        具体参数如下:
root@OpenWrt:/lib#iw
Usage:  iw [options] command
Options:
        --debug         enable netlink debugging
        --version       show version (3.3)
Commands:
        help
        event [-t] [-r][-f] ???
        phy
        list
        phy <phyname> info
               dev 操作
        dev 列出所有dev信息
        dev <devname> info列出指定dev信息
        dev <devname> del 删除VAP
        dev <devname> interface add<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags<flag>*] 添加VAP
        phy <phyname> interface add<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags<flag>*]
        dev <devname> ibss join<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT] [fixed-freq][<fixed bssid>] [beacon-interval <TU>] [basic-rates <rate inMbps,rate2,...>] [mcast-rate <rate in Mbps>] [key d:0:abcde]
        dev <devname> ibss leave
        dev <devname> station dump 列出关联的STA信息
        dev <devname> station set <MACaddress> vlan <ifindex>
        dev <devname> station set <MACaddress> plink_action <open|block>
        dev <devname> station del <MAC address>
        dev <devname> station get <MACaddress>
        dev <devname> survey dump
        dev <devname> mesh leave
        dev <devname> mesh join <meshID> [<param>=<value>]*
        dev <devname> mpath dump
        dev <devname> mpath set<destination MAC address> next_hop <next hop MAC address>
        dev <devname> mpath new<destination MAC address> next_hop <next hop MAC address>
        dev <devname> mpath del <MAC address>
        dev <devname> mpath get <MACaddress>
        dev <devname> scan [-u] [freq<freq>*] [ies <hex as 00:11:..>] [ssid <ssid>*|passive]
        dev <devname> scan trigger [freq<freq>*] [ies <hex as 00:11:..>] [ssid <ssid>*|passive]
        dev <devname> scan dump [-u]
        reg get
        reg set <ISO/IEC 3166-1 alpha2>
        dev <devname> connect [-w]<SSID> [<freq in MHz>] [<bssid>] [key 0:abcde d:1:6162636465]
        dev <devname> disconnect
        dev <devname> link
        dev <devname> offchannel<freq> <duration>
        dev <devname> cqm rssi<threshold|off> [<hysteresis>]
        phy <phyname> wowlan show
        phy <phyname> wowlan disable
       phy <phyname> wowlan enable [any] [disconnect] [magic-packet][gtk-rekey-failure] [eap-identity-request] [4way-handshake] [rfkill-release][patterns <pattern>*]
        dev <devname> roc start<freq> <time>
        phy <phyname> set antenna<bitmap> | all | <tx bitmap> <rx bitmap>
        dev <devname> set txpower<auto|fixed|limit> [<tx power in mBm>]
        phy <phyname> set txpower<auto|fixed|limit> [<tx power in mBm>]
        phy <phyname> set distance<distance>
        phy <phyname> set coverage<coverage class>
        phy <phyname> set netns<pid>
        phy <phyname> set rts <rtsthreshold|off>
        phy <phyname> set frag<fragmentation threshold|off>
        dev<devname> set channel <channel> [HT20|HT40+|HT40-]
        phy<phyname> set channel <channel> [HT20|HT40+|HT40-]
        dev<devname> set freq <freq> [HT20|HT40+|HT40-]
        phy<phyname> set freq <freq> [HT20|HT40+|HT40-]
        phy <phyname> set name <newname>
        dev <devname> set peer <MACaddress>
        dev <devname> set noack_map<map>
        dev <devname> set 4addr<on|off>
        dev <devname> set type<type>
        dev <devname> set meshid<meshid>
        dev <devname> set monitor<flag>*
        dev <devname> set mesh_param<param>=<value> [<param>=<value>]*
        dev <devname> set power_save<on|off>
        dev <devname> set bitrates[legacy-<2.4|5> <legacy rate in Mbps>*]
        dev <devname> get mesh_param[<param>]
        dev <devname> get power_save<param>
You can omitthe 'phy' or 'dev' if the identification is unique,
e.g. "iwwlan0 info" or "iw phy0 info". (Don't when scripting.)
Do NOTscreenscrape this tool, we don't consider its output stable.
root@OpenWrt:/lib#

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值