Openwrt的wifi脚本分析

本文深入分析了OpenWrt系统中用于管理WiFi的/sbin/wifi脚本,探讨了不同命令如'up', 'down', 'detect'等如何调用相关函数。特别地,详细解释了'wifi up'命令的工作流程,它通过执行'ubus call network reload'来启用网络设备,并进一步调用wifi_updown函数以实现WiFi的开启。" 115985200,10407145,ChatBot开发:损失函数与准确率详解,"['人工智能', 'python', '自然语言处理', '机器学习', '对话系统']
摘要由CSDN通过智能技术生成

首先分享一下/sbin/wifi脚本

#!/bin/sh                                                            
# Copyright (C) 2006 OpenWrt.org                                     

. /lib/functions.sh                                                  
. /usr/share/libubox/jshn.sh                                         

usage() {                                                            
        cat <<EOF                                                    
Usage: $0 [down|detect|reload|status]                                
enables (default), disables or detects a wifi configuration.              
EOF                                                                               
        exit 1                                                       
}                                                                           

ubus_wifi_cmd() {                                                    
        local cmd="$1"                                               
        local dev="$2"                                               

        json_init                                                    
        [ -n "$2" ] && json_add_string device "$2"                   
        ubus call network.wireless "$1" "$(json_dump)"               
}                                                                    

find_net_config() {(                                                 
        local vif="$1"                                               
        local cfg                                                    
        local ifname                                                 

        config_get cfg "$vif" network                                

        [ -z "$cfg" ] && {                                           
                include /lib/network                                    
                scan_interfaces                                         

                config_get ifname "$vif" ifname                                              

                cfg="$(find_config "$ifname")"                               
        }                                                                    
        [ -z "$cfg" ] && return 0                                       
        echo "$cfg"                                                     
)}                                                                                           


bridge_interface() {(                                                                        
        local cfg="$1"                                                                       
        [ -z "$cfg" ] && return 0                                                            

        include /lib/network                                                                 
        scan_interfaces                                                                      

        for cfg in $cfg; do                                                                  
                config_get iftype "$cfg" type                                                
                [ "$iftype" = bridge ] && config_get "$cfg" ifname                           
                prepare_interface_bridge "$cfg"                                              
                return $?                                                                    
        done                                                                                 
)}                                                                                           

prepare_key_wep() {                                                                          
        local key="$1"                                                                       
        local hex=1                                                                          

        echo -n "$key" | grep -qE "[^a-fA-F0-9]" && hex=0                                    
        [ "${#key}" -eq 10 -a $hex -eq 1 ] || \                                              
        [ "${#key}" -eq 26 -a $hex -eq 1 ] || {                                              
                [ "${key:0:2}" = "s:" ] && key="${key#s:}"                   
                key="$(echo -n "$key" | hexdump -ve '1/1 "%02x" ""')"             
        }                                                                         
        echo "$key"                                                               
} 
 wifi_fixup_hwmode() {                     
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值