首先分享一下/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() {