📄 shared
字号:
#!/bin/bash# etc/wlan/shared## Copyright (C) 2002 AbsoluteValue Systems, Inc. All Rights Reserved.# --------------------------------------------------------------------## linux-wlan## The contents of this file are subject to the Mozilla Public# License Version 1.1 (the "License"); you may not use this file# except in compliance with the License. You may obtain a copy of# the License at http://www.mozilla.org/MPL/## Software distributed under the License is distributed on an "AS# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or# implied. See the License for the specific language governing# rights and limitations under the License.## Alternatively, the contents of this file may be used under the# terms of the GNU Public License version 2 (the "GPL"), in which# case the provisions of the GPL are applicable instead of the# above. If you wish to allow the use of your version of this file# only under the terms of the GPL and not to allow others to use# your version of this file under the MPL, indicate your decision# by deleting the provisions above and replace them with the notice# and other provisions required by the GPL. If you do not delete# the provisions above, a recipient may use your version of this# file under either the MPL or the GPL.## --------------------------------------------------------------------## Inquiries regarding the linux-wlan Open Source project can be# made directly to:## AbsoluteValue Systems Inc.# info@linux-wlan.com# http://www.linux-wlan.com## --------------------------------------------------------------------## Portions of the development of this software were funded by # Intersil Corporation as part of PRISM(R) chipset product development.## --------------------------------------------------------------------TMPDIR=/tmpif [ ! -n "$ECHO" ]; then ECHO=echofiif [ ! -n "$WLAN_UDEV" ] ; thenif [ -x /sbin/modprobe ] ; then MODPROBE=/sbin/modprobeelse ${ECHO} "/sbin/modprobe not found." exit 1fifiif [ -x /sbin/wlanctl-ng ] ; then WLANCTL=/sbin/wlanctl-ngelse ${ECHO} "/sbin/wlanctl-ng not found." exit 1fi# linux-wlan-ng > 0.2.4 there is no wland #if [ -x /sbin/wland ] ; then# WLAND=/sbin/wland#else# ${ECHO} "/sbin/wland not found."# exit 1#fiif [ ! -n "$WLAN_UDEV" ] ; thenif [ -f /proc/sys/kernel/hotplug -a \ -x `cat /proc/sys/kernel/hotplug` -a \ -f /etc/hotplug/wlan.agent ] ; then HAS_HOTPLUG=yelse HAS_HOTPLUG=nfifi# Source the wlan configurationif [ -f /etc/wlan/wlan.conf ] ; then . /etc/wlan/wlan.confelse ${ECHO} "/etc/wlan/wlan.conf not found." exit 0fi# Source NSD specific functions# nsd_fwload# nsd_mibset# Debian mod. If there is shared.dpkg-old we get a endless loopif [ "`ls /etc/wlan/shared.* 2>/dev/null`" ]; then for i in `find /etc/wlan -name 'shared.*' -and -not -name '*.dpkg*'` ; do . $i doneelse ${ECHO} "/etc/wlan/shared.* not found." exit 0fiis_true (){ # $1 == string containing a t/f indicator. [ "$1" = "y" -o "$1" = "Y" -o "$1" = "yes" -o "$1" = "YES" \ -o "$1" = "t" -o "$1" = "T" -o "$1" = "true" -o "$1" = "TRUE" ]}wlan_nsdname (){ # $1 == wlandev # Writes the given device's name to stdout grep 'nsd name' /proc/net/p80211/$1/wlandev | sed -e 's/.*: \(.*\)_.*/\1/'}wlan_enable (){ # $1 == wlandev #=======ENABLE IFSTATE============================= # Bring the device into its operable state # if running under udev module must be loaded to get here so skip checks if [ ! -n "$WLAN_UDEV" ] ; then $MODPROBE $1 # First, make sure the driver is loaded.... if ! ifconfig $1 > /dev/null 2>&1 ; then ${ECHO} "Error: Device $1 does not seem to be present." ${ECHO} "Make sure you've inserted the appropriate" ${ECHO} "modules or that your modules.conf file contains" ${ECHO} "the appropriate aliase(s)." return 1 fi fi # Call the nsd script's fwload function, in case the card needs # a firmware load, or could use an optional one. nsdname=`wlan_nsdname $1` if ! ${nsdname}_fwload $1 ; then ${ECHO} "Firmware failed to load for device $1" return 1 fi # Enable the interface result=`$WLANCTL $1 lnxreq_ifstate ifstate=enable` if [ $? = 0 ] ; then eval $result if [ $resultcode != "success" ]; then ${ECHO} "Failed to enable the device, resultcode=" \ $resultcode "." return 1 fi else ${ECHO} "Failed to enable the device, exitcode=" $? "." return 1 fi # Set any NSD specific MIBs ${nsdname}_mibset $1}wlan_user_mibs (){ # $1 == wlandev #=======USER MIB SETTINGS============================= # Set the user specified MIB items. for i in $USER_MIBS ; do result=`$WLANCTL $1 dot11req_mibset "mibattribute=$i"` if [ $? = 0 ] ; then eval $result if [ $resultcode != "success" ] ; then ${ECHO} "Failed to set user MIB $i." return 1 fi else ${ECHO} "Failed to set user MIB $i." return 1 fi done}wlan_source_config (){ # $1 == wlandev # XXX what about stray singlequotes. eval 'GOSSID="$SSID_'$1'"' wlan_source_config_for_ssid "$GOSSID"}wlan_source_config_for_ssid (){ # $1 == ssid[:bssid] # $2 == bssid (optional) DesiredSSID="$1" DesiredBSSID="$2" if [ -n "$2" ] ; then token_ssid=`echo $1 | sed -ne 's/\(.*\)\(:..:..:..:..:..:..\).*/\1/p'` token_bssid=`echo $1 | sed -ne 's/\(.*\):\(..:..:..:..:..:..\).*/\2/p'` if [ -n "$token_ssid" ] ; then DesiredSSID="$token_ssid" DesiredBSSID="$token_bssid" fi fi if [ -f "/etc/wlan/wlancfg-$DesiredSSID:$DesiredBSSID" ] ; then . "/etc/wlan/wlancfg-$DesiredSSID:$DesiredBSSID" elif [ -f "/etc/wlan/wlancfg-$DesiredSSID" ] ; then . "/etc/wlan/wlancfg-$DesiredSSID" else if [ -n "$1" ] ; then ${ECHO} "Failed to open network config file /etc/wlan/wlancfg-$1, using default." fi . "/etc/wlan/wlancfg-DEFAULT" fi}wlan_disable (){ # $1 == wlandev $WLANCTL $1 lnxreq_ifstate ifstate=disable} wlan_ssid_in_list (){ # $1 == wlandev, $2 == ssid, $3 == bssid eval 'GOSSID="$SSID_'$1'"' # This "eval" hackery is to allow escapes in GOSSID... cmd="for token in $GOSSID ; do ssid_token=\`echo \"\$token\" | sed -ne 's/\(.*\)\(:..:..:..:..:..:..\).*/\1/p'\` bssid_token=\`echo \"\$token\" | sed -ne 's/\(.*\):\(..:..:..:..:..:..\).*/\2/p'\` if [ -z \"\$ssid_token\" ] ; then ssid_token="\$token" fi if [ -n \"\$bssid_token\" ] ; then if [ \"\$bssid_token\" = \"\$3\" ] ; then return 0 fi elif [ \"\$2\" = \"\$ssid_token\" ] ; then return 0 fi done" eval "$cmd" return 1}wlan_supports_scan (){ # $1 == wlandev if is_true "$WLAN_SCAN" ; then cat /proc/net/p80211/$1/wlandev | grep 'scan' > /dev/null if [ $? = 0 ] ; then return 0 fi fi return 1}wlan_scan (){ # $1 == wlandev # find our allowed SSID list. # XXX what about stray singlequotes. eval 'GOSSID="$SSID_'$1'"' # kick off a quick scan with the broadcast SSID. wlan_scan_one $1 '' '' n if [ $? = 0 -a \ "$GOSSID" = "" ] ; then # if successful and our ssid list is null, return. sleep 1 return 0 fi # otherwise we walk through the list, and scan for eacn in turn. # this "eval" hackery is to allow escapes in GOSSID cmd="for token in $GOSSID ; do ssid_token=\`echo \"\$token\" | sed -ne 's/\(.*\)\(:..:..:..:..:..:..\).*/\1/p'\` bssid_token=\`echo \"\$token\" | sed -ne 's/\(.*\):\(..:..:..:..:..:..\).*/\2/p'\` if [ -z \"\$ssid_token\" ] ; then ssid_token=\"\$token\" fi wlan_scan_one \$1 \"\$ssid_token\" \"\$bssid_token\" if [ \$? = 0 ] ; then sleep 1 return 0 fi done" eval "$cmd" # We got to the end of the list. Maybe try "any" if is_true "$WLAN_ANY" ; then wlan_scan_one $1 sleep 1 return $? fi sleep 1 return 1}wlan_scan_one (){ # $1 == wlandev, [ $2 == ssid, $3 == bssid, $4 == append ] if [ -z "$4" ] ; then append=true else append=false fi numbss=0 result=`$WLANCTL $1 dot11req_scan bsstype=any bssid=ff:ff:ff:ff:ff:ff \ scantype=active probedelay=0 channellist=$ChannelList ssid="$2" \ minchanneltime=$ChannelMinTime maxchanneltime=$ChannelMaxTime append=$append` eval $result if [ $resultcode != 'success' ] ; then ${ECHO} "Scan failed ($resultcode) " return 1 fi ## XXX if numbss == 0, repeat with $2 $3 $4? i=0 bssfound="" # walk through the results and do first-cut matching. while [ $i -lt $numbss ] ; do result=`$WLANCTL $1 dot11req_scan_results bssindex=$i` eval $result if [ -n "$3" ] ; then if [ "$3" = "$bssid" ] ; then bssfound="$bssfound $i" fi elif [ -z "$2" ] ; then # if our ssid is "", then we pick the first entry. bssfound="$bssfound $i" elif [ "$2" = "$ssid" ] ; then bssfound="$bssfound $i" fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -