免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 22756 | 回复: 6
打印 上一主题 下一主题

[其它] OpenWRT 信道自动选择 [复制链接]

论坛徽章:
40
水瓶座
日期:2013-08-15 11:26:422015年辞旧岁徽章
日期:2015-03-03 16:54:152015年亚洲杯之乌兹别克斯坦
日期:2015-03-27 14:01:172015年亚洲杯之约旦
日期:2015-03-31 15:06:442015亚冠之首尔
日期:2015-06-16 23:24:37IT运维版块每日发帖之星
日期:2015-07-01 22:20:002015亚冠之德黑兰石油
日期:2015-07-08 09:32:07IT运维版块每日发帖之星
日期:2015-08-29 06:20:00IT运维版块每日发帖之星
日期:2015-08-29 06:20:00IT运维版块每日发帖之星
日期:2015-10-10 06:20:00IT运维版块每日发帖之星
日期:2015-10-11 06:20:00IT运维版块每日发帖之星
日期:2015-11-10 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-10-13 23:52 |只看该作者 |倒序浏览
现在Openwrt的信道 auto 模式总是自动锁定在 1 上,其实这个是很久的问题,这里是启动脚本 修改则个加上自己的信道选择算法 就可以自动选择信道了
  1. #!/bin/sh
  2. # Copyright (C) 2006 OpenWrt.org

  3. DEBUG=off

  4. . /lib/functions.sh

  5. usage() {
  6.     cat <<EOF
  7. Usage: $0 [down|detect]
  8. enables (default), disables or detects a wifi configuration.
  9. EOF
  10.     exit 1
  11. }
  12. find_net_config() {(

  13. best=$(autochannel)
  14. uci_channel=$(uci get wireless.radio0.channel)                        
  15. if [ "$uci_channel" = "auto" ];then                                   
  16.         channel=$best;                                          
  17.         orig=$(cat /var/run/hostapd-phy0.conf | grep "channel=")      
  18.         if [ -z $orig ];then                                          
  19.                 $orig='channel=1'                                    
  20.         fi                                                            
  21.         sed -i "s/$orig/channel=$channel/g" /var/run/hostapd-phy0.conf
  22. fi   
  23.         
  24.     local vif="$1"
  25.     local cfg
  26.     local ifname
  27.     config_get cfg "$vif" network
  28.     [ -z "$cfg" ] && {
  29.         include /lib/network
  30.         scan_interfaces
  31.         config_get ifname "$vif" ifname
  32.         cfg="$(find_config "$ifname")"
  33.     }
  34.     [ -z "$cfg" ] && return 0
  35.     echo "$cfg"
  36. )}
  37. bridge_interface() {(
  38.     local cfg="$1"
  39.     [ -z "$cfg" ] && return 0
  40.     include /lib/network
  41.     scan_interfaces
  42.     for cfg in $cfg; do
  43.         config_get iftype "$cfg" type
  44.         [ "$iftype" = bridge ] && config_get "$cfg" ifname
  45.         prepare_interface_bridge "$cfg"
  46.         return $?
  47.     done
  48. )}
  49. prepare_key_wep() {
  50.     local key="$1"
  51.     local hex=1
  52.     echo -n "$key" | grep -qE "[^a-fA-F0-9]" && hex=0
  53.     [ "${#key}" -eq 10 -a $hex -eq 1 ] || \
  54.     [ "${#key}" -eq 26 -a $hex -eq 1 ] || {
  55.         [ "${key:0:2}" = "s:" ] && key="${key#s:}"
  56.             key="$(echo -n "$key" | hexdump -ve '1/1 "%02x" ""')"
  57.     }
  58.     echo "$key"
  59. }
  60. wifi_fixup_hwmode() {
  61.     local device="$1"
  62.     local default="$2"
  63.     local hwmode hwmode_11n
  64.     config_get channel "$device" channel
  65.    
  66.     config_get hwmode "$device" hwmode
  67.     case "$hwmode" in
  68.         11bg) hwmode=bg;;
  69.         11a) hwmode=a;;
  70.         11b) hwmode=b;;
  71.         11g) hwmode=g;;
  72.         11n*)
  73.             hwmode_11n="${hwmode##11n}"
  74.             case "$hwmode_11n" in
  75.                 a|g) ;;
  76.                 default) hwmode_11n="$default"
  77.             esac
  78.             config_set "$device" hwmode_11n "$hwmode_11n"
  79.         ;;
  80.         *)
  81.             hwmode=
  82.             if [ "${channel:-0}" -gt 0 ]; then
  83.                 if [ "${channel:-0}" -gt 14 ]; then
  84.                     hwmode=a
  85.                 else
  86.                     hwmode=g
  87.                 fi
  88.             else
  89.                 hwmode="$default"
  90.             fi
  91.         ;;
  92.     esac
  93.     config_set "$device" hwmode "$hwmode"
  94. }
  95. wifi_updown() {
  96.     [ enable = "$1" ] && {
  97.         wifi_updown disable "$2"
  98.         scan_wifi
  99.     }
  100.     for device in ${2:-$DEVICES}; do (
  101.         config_get disabled "$device" disabled
  102.         [ 1 == "$disabled" ] && {
  103.             echo "'$device' is disabled"
  104.             set disable
  105.         }
  106.         config_get iftype "$device" type
  107.         if eval "type ${1}_$iftype" 2>/dev/null >/dev/null; then
  108.             eval "scan_$iftype '$device'"
  109.             eval "${1}_$iftype '$device'" || echo "$device($iftype): ${1} failed"
  110.         else
  111.             echo "$device($iftype): Interface type not supported"
  112.         fi
  113.     ); done
  114. }
  115. wifi_detect() {
  116.     for driver in ${2:-$DRIVERS}; do (
  117.         if eval "type detect_$driver" 2>/dev/null >/dev/null; then
  118.             eval "detect_$driver" || echo "$driver: Detect failed" >&2
  119.         else
  120.             echo "$driver: Hardware detection not supported" >&2
  121.         fi
  122.     ); done
  123. }
  124. start_net() {(
  125.     local iface="$1"
  126.     local config="$2"
  127.     local vifmac="$3"
  128.     [ -f "/var/run/$iface.pid" ] && kill "$(cat /var/run/${iface}.pid)" 2>/dev/null
  129.     [ -z "$config" ] || {
  130.         include /lib/network
  131.         scan_interfaces
  132.         for config in $config; do
  133.             setup_interface "$iface" "$config" "" "$vifmac"
  134.         done
  135.     }
  136. )}
  137. set_wifi_up() {
  138.     local cfg="$1"
  139.     local ifname="$2"
  140.     uci_set_state wireless "$cfg" up 1
  141.     uci_set_state wireless "$cfg" ifname "$ifname"
  142. }
  143. set_wifi_down() {
  144.     local cfg="$1"
  145.     local vifs vif vifstr
  146.     [ -f "/var/run/wifi-${cfg}.pid" ] &&
  147.         kill "$(cat "/var/run/wifi-${cfg}.pid")" 2>/dev/null
  148.     uci_revert_state wireless "$cfg"
  149.     config_get vifs "$cfg" vifs
  150.     for vif in $vifs; do
  151.         uci_revert_state wireless "$vif"
  152.     done
  153. }
  154. scan_wifi() {
  155.     local cfgfile="$1"
  156.     DEVICES=
  157.     config_cb() {
  158.         local type="$1"
  159.         local section="$2"
  160.         # section start
  161.         case "$type" in
  162.             wifi-device)
  163.                 append DEVICES "$section"
  164.                 config_set "$section" vifs ""
  165.                 config_set "$section" ht_capab ""
  166.             ;;
  167.         esac
  168.         # section end
  169.         config_get TYPE "$CONFIG_SECTION" TYPE
  170.         case "$TYPE" in
  171.             wifi-iface)
  172.                 config_get device "$CONFIG_SECTION" device
  173.                 config_get vifs "$device" vifs
  174.                 append vifs "$CONFIG_SECTION"
  175.                 config_set "$device" vifs "$vifs"
  176.             ;;
  177.         esac
  178.     }
  179.     config_load "${cfgfile:-wireless}"
  180. }
  181. DEVICES=
  182. DRIVERS=
  183. include /lib/wifi
  184. scan_wifi
  185. case "$1" in
  186.     down) wifi_updown "disable" "$2";;
  187.     detect) wifi_detect "$2";;
  188.     --help|help) usage;;
  189.     *) wifi_updown "enable" "$2";;
  190. esac
复制代码

论坛徽章:
0
2 [报告]
发表于 2013-10-14 20:02 |只看该作者
赞一个

论坛徽章:
0
3 [报告]
发表于 2013-12-06 09:36 |只看该作者
你好,我想问问,你的这个脚本是要修改那一个文件的呢???

论坛徽章:
0
4 [报告]
发表于 2013-12-29 17:52 |只看该作者
回复 3# nan1888

一般在/lib/wifi/目录下都会有一个驱动脚本,你可以自己写一个wlan.sh脚本,读取/etc/config/wireless配置文件
得到无线网卡信息,如驱动信息,然后映射到/lib/wifi/下的驱动脚本操作函数就可以了。


   

论坛徽章:
0
5 [报告]
发表于 2014-02-12 13:20 |只看该作者
回复 4# ssjmhyvi 那你文章里的脚本是在哪里的呢???


   

论坛徽章:
8
2015年辞旧岁徽章
日期:2015-03-03 16:54:15午马
日期:2015-02-04 12:00:07羊年新春福章
日期:2015-02-04 11:57:56双子座
日期:2014-12-02 11:44:59金牛座
日期:2014-10-08 16:47:08狮子座
日期:2014-08-29 13:37:46巳蛇
日期:2014-08-26 17:32:29NBA常规赛纪念章
日期:2015-05-04 22:32:03
6 [报告]
发表于 2014-03-20 09:34 |只看该作者
楼主高手,学习了。

论坛徽章:
0
7 [报告]
发表于 2014-03-20 13:18 |只看该作者
真不错的想法,也很实用!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP