Rt2860v2.sh
Revision as of 12:13, 11 January 2015 by Onnowpurbo (talk | contribs)
#!/bin/sh # # by lintel@gmail.com, hoowa.sun@gmail.com # # by memccpy@gmail.com 2014.8 append DRIVERS "rt2860v2" prepare_config() { #获取参数 存储配置的变量 目标配置关键字 # Get parameter storage configuration variable target configuration keyword local num=0 mode disabled #准备产生RaX的无线配置 # Ready to produce RaX wireless configuration local device=$1 #获取当前用户配置的无线Mac # Get current user configurable wireless Mac config_get macaddr $device macaddr #获取当前的无线频道 # Get the current wireless channel config_get channel $device channel #获取当前的802.11无线模式 # Get the current 802.11 wireless mode config_get hwmode $device mode #获取WMM支持 # Get WMM support config_get wmm $device wmm #获取设备的传输功率 # Obtaining transmission power of the device config_get txpower $device txpower #获取设备的HT(频宽) # Get equipment HT (bandwidth) config_get ht $device ht #获取国家代码 # Get country code config_get country $device country #是否有MAC过滤 # Is there MAC filtering config_get macpolicy $device macpolicy #MAC地址过滤列表 # MAC address filtering list config_get maclist $device maclist #字符格式转义 # Escape character format ra_maclist="${maclist// /;};" #是否支持GREEN AP功能 # GREEN AP function support config_get_bool greenap $device greenap 0 config_get_bool antdiv "$device" diversity config_get frag "$device" frag 2346 config_get rts "$device" rts 2347 config_get distance "$device" distance config_get hidessid "$device" hidden 0 #获取该Radio下面的虚拟接口 # Get the Radio following virtual interface config_get vifs "$device" vifs #获取虚拟接口的数量,并提前配置SSID # Get the number of virtual interfaces, and pre-configured SSID for vif in $vifs; do let num+=1 config_get_bool disabled "$vif" disabled 0 config_get mode "$vif" mode 0 #如果某个SSID接口需要隐藏,则所有的接口都隐藏 # If a need to hide the SSID interface, all interfaces are hidden [ "$hidessid" == "0" ] && { config_get hidessid $vif hidden 0 } #已经关闭的接口以及sta模式的排除在外。 # The interface has been closed and the sta mode excluded. [ "$mode" = "sta" ]&& { let num-=1 continue } [ "$disabled" == "1" ]&& { let num-=1 continue } case $num in 1) config_get ssid1 "$vif" ssid ;; 2) config_get ssid2 "$vif" ssid ;; 3) config_get ssid3 "$vif" ssid ;; 4) config_get ssid4 "$vif" ssid ;; *) ;; esac done #开始准备HT模式配置,注意HT模式仅在11N下有效。 # Began to prepare HT mode configuration, note HT mode is only valid under 11N. HT=1 HT_CE=1 if [ "$ht" = "20" ]; then HT=0 elif [ "$ht" = "20+40" ]; then HT=1 HT_CE=1 elif [ "$ht" = "40" ] ; then HT=1 HT_CE=0 else echo "ht config has some problem!use default!!!" HT=0 HT_CE=1 fi # 在HT40模式下,需要另外的一个频道,如果EXTCHA=0,则当前第二频道为$channel + 4. # In HT40 mode, requires an additional channel, if EXTCHA = 0, then the current of the second channel for $ channel + 4. # 如果EXTCHA=1,则当前的第二频道为$channel - 4. # If EXTCHA = 1, then the current second channel for $ channel - 4. # 如果当前频道被限制在1-4,则是当前频道+ 4,若否,则为当前频道-4 # If the current channel is limited to 1-4, it is the current channel + 4, if not, for the current channel -4 EXTCHA=1 [ "$channel" != auto ] && [ "$channel" -lt "5" ] && EXTCHA=1 #配置自动选择无线频道 # Configured to automatically select the wireless channel [ "$channel" == "auto" ] && { channel=11 AutoChannelSelect=2 } #开始判断WiFi的MAC过滤方式. # Begin to judge the WiFi MAC filtering. case "$macpolicy" in allow|2) ra_macfilter=1; ;; deny|1) ra_macfilter=2; ;; *|disable|none|0) ra_macfilter=0; ;; esac cat > /tmp/RT2860.dat<<EOF #The word of "Default" must not be removed Default CountryRegion=0 CountryRegionABand=7 CountryCode=${country:-US} BssidNum=${num:-1} SSID1=${ssid1:-OpenWrt_SSID1} SSID2=${ssid2:-OpenWrt_SSID2} SSID3=${ssid3:-OpenWrt_SSID3} SSID4=${ssid4:-OpenWrt_SSID4} SSID5= SSID6= SSID7= SSID8= WirelessMode=${hwmode:-9} FixedTxMode= TxRate=0 MacAddress=${macaddr} Channel=${channel:-11} BasicRate=15 BeaconPeriod=100 DtimPeriod=1 TxPower=${txpower:-100} DisableOLBC=0 BGProtection=0 TxAntenna= RxAntenna= TxPreamble=1 RTSThreshold=${rts:-2347} FragThreshold=${frag:-2346} TxBurst=1 PktAggregate=1 AutoProvisionEn=0 FreqDelta=0 TurboRate=0 WmmCapable=${wmm:-0} APAifsn=3;7;1;1 APCwmin=4;4;3;2 APCwmax=6;10;4;3 APTxop=0;0;94;47 APACM=0;0;0;0 BSSAifsn=3;7;2;2 BSSCwmin=4;4;3;2 BSSCwmax=10;10;4;3 BSSTxop=0;0;94;47 BSSACM=0;0;0;0 AckPolicy=0;0;0;0 APSDCapable=0 DLSCapable=0 NoForwarding=0 NoForwardingBTNBSSID=0 HideSSID=${hidessid:-0} ShortSlot=1 AutoChannelSelect=${AutoChannelSelect:-0} IEEE8021X=0 IEEE80211H=0 CarrierDetect=0 ITxBfEn=0 PreAntSwitch= PhyRateLimit=0 DebugFlags=0 ETxBfEnCond=0 ITxBfTimeout=0 ETxBfTimeout=0 ETxBfNoncompress=0 ETxBfIncapable=0 FineAGC=0 StreamMode=0 StreamModeMac0= StreamModeMac1= StreamModeMac2= StreamModeMac3= CSPeriod=6 RDRegion= StationKeepAlive=0 DfsLowerLimit=0 DfsUpperLimit=0 DfsOutdoor=0 SymRoundFromCfg=0 BusyIdleFromCfg=0 DfsRssiHighFromCfg=0 DfsRssiLowFromCfg=0 DFSParamFromConfig=0 FCCParamCh0= FCCParamCh1= FCCParamCh2= FCCParamCh3= CEParamCh0= CEParamCh1= CEParamCh2= CEParamCh3= JAPParamCh0= JAPParamCh1= JAPParamCh2= JAPParamCh3= JAPW53ParamCh0= JAPW53ParamCh1= JAPW53ParamCh2= JAPW53ParamCh3= FixDfsLimit=0 LongPulseRadarTh=0 AvgRssiReq=0 DFS_R66=0 BlockCh= GreenAP=0 PreAuth=0 AuthMode=OPEN EncrypType=NONE WapiPsk1=0123456789 WapiPsk2= WapiPsk3= WapiPsk4= WapiPsk5= WapiPsk6= WapiPsk7= WapiPsk8= WapiPskType=0 Wapiifname= WapiAsCertPath= WapiUserCertPath= WapiAsIpAddr= WapiAsPort= RekeyMethod=DISABLE RekeyInterval=3600 PMKCachePeriod=10 MeshAutoLink=0 MeshAuthMode= MeshEncrypType= MeshDefaultkey=0 MeshWEPKEY= MeshWPAKEY= MeshId= WPAPSK1=12345678 WPAPSK2= WPAPSK3= WPAPSK4= WPAPSK5= WPAPSK6= WPAPSK7= WPAPSK8= DefaultKeyID=1 Key1Type=0 Key1Str1= Key1Str2= Key1Str3= Key1Str4= Key1Str5= Key1Str6= Key1Str7= Key1Str8= Key2Type=0 Key2Str1= Key2Str2= Key2Str3= Key2Str4= Key2Str5= Key2Str6= Key2Str7= Key2Str8= Key3Type=0 Key3Str1= Key3Str2= Key3Str3= Key3Str4= Key3Str5= Key3Str6= Key3Str7= Key3Str8= Key4Type=0 Key4Str1= Key4Str2= Key4Str3= Key4Str4= Key4Str5= Key4Str6= Key4Str7= Key4Str8= HSCounter=0 HT_HTC=1 HT_RDG=1 HT_LinkAdapt=0 HT_OpMode=0 HT_MpduDensity=5 HT_EXTCHA=${EXTCHA} HT_BW=${HT:-0} HT_AutoBA=1 HT_BADecline=0 HT_AMSDU=0 HT_BAWinSize=64 HT_GI=1 HT_STBC=1 HT_MCS=33 HT_TxStream=2 HT_RxStream=2 HT_PROTECT=1 HT_DisallowTKIP=1 HT_BSSCoexistence=${HT_CE:-1} GreenAP=${greenap:-0} WscConfMode=0 WscConfStatus=1 WCNTest=0 AccessPolicy0=${ra_macfilter:-0} AccessControlList0=${ra_maclist:-0} AccessPolicy1=0 AccessControlList1= AccessPolicy2=0 AccessControlList2= AccessPolicy3=0 AccessControlList3= AccessPolicy4=0 AccessControlList4= AccessPolicy5=0 AccessControlList5= AccessPolicy6=0 AccessControlList6= AccessPolicy7=0 AccessControlList7= WdsEnable=0 WdsPhyMode= WdsEncrypType=NONE WdsList= Wds0Key= Wds1Key= Wds2Key= Wds3Key= RADIUS_Server= RADIUS_Port=1812 RADIUS_Key1= RADIUS_Key2= RADIUS_Key3= RADIUS_Key4= RADIUS_Key5= RADIUS_Key6= RADIUS_Key7= RADIUS_Key8= RADIUS_Acct_Server= RADIUS_Acct_Port=1813 RADIUS_Acct_Key= own_ip_addr= Ethifname= EAPifname= PreAuthifname= session_timeout_interval=0 idle_timeout_interval=0 WiFiTest=0 TGnWifiTest=0 ApCliEnable=0 ApCliSsid= ApCliBssid= ApCliAuthMode= ApCliEncrypType= ApCliWPAPSK= ApCliDefaultKeyID=0 ApCliKey1Type=0 ApCliKey1Str= ApCliKey2Type=0 ApCliKey2Str= ApCliKey3Type=0 ApCliKey3Str= ApCliKey4Type=0 ApCliKey4Str= RadioOn=1 SSID= WPAPSK=0123456789 Key1Str= Key2Str= Key3Str= Key4Str= EOF } reload_rt2860v2() { ifconfig ra0 down rmmod rt2860v2_ap insmod rt2860v2_ap ifconfig ra0 up } scan_rt2860v2() { local device="$1" } disable_rt2860v2() { local device="$1" set_wifi_down $device ifconfig $device down true } rt2860v2_start_vif() { local vif="$1" local ifname="$2" local net_cfg net_cfg="$(find_net_config "$vif")" [ -z "$net_cfg" ] || start_net "$ifname" "$net_cfg" set_wifi_up "$vif" "$ifname" } enable_rt2860v2() { #传参过来的第一个参数是Radio0 local device="$1" dmode if_num=0; config_get_bool disabled "$device" disabled 0 if [ "$disabled" = "1" ] ;then ifconfig ra0 down return fi #开始准备该设备的无