#!/bin/sh # Check wifi-devices before loading ath_pci drivers oldwifi=`ip link show | sed -n 's/.*\(wifi[0-9]\{1,\}\).*/\1/p'` # Load Atheros driver do_modprobe ath_pci autocreate=none $opt # Check difference - the new devices are atheros wifi=`ip link show | sed -n 's/.*\(wifi[0-9]\{1,\}\).*/\1/p'` # delete all previous already known devices for i in $oldwifi do wifi=`echo $wifi | sed "s/$i//"` done # now we need to go thru the devices and extract MAC, parse the WLAN-Config # and create the VAP's accordingly. [ "$wifi" ] || log_error "No ath_pci devices found." for i in $wifi do di=`grep 'wlan[0-9]\+:[ ]' /proc/net/dev | sed -n '/:/s/ *wlan\([0-9]\+\):.*/\1/p' | sort -nr | head -n 1` vapnum=0 vapsta_wlan='' vapmaster_n='0' wifi="$i" stanum=0 if [ -n "$WLAN_N" ] then if [ "$WLAN_N" -gt 0 ] then # Extract MAC-Address mac=`ip link show $i | sed -n 'y/abcdef/ABCDEF/;s/.*\(\([0-9A-F]\{2\}:\)\{5\}[0-9A-F]\{2\}\).\+/\1/p'` # Run through WLAN-Config for idx in `seq 1 $WLAN_N` do eval wmac=\$WLAN_${idx}_MAC wmac=`echo $wmac | sed 'y/abcdef/ABCDEF/'` if [ "$wmac" = "$mac" ] then # Extract diversity-settings from 1st matching MAC and set if wanted. if [ $vapnum -eq 0 ] then eval diversity=\$WLAN_${idx}_DIVERSITY case $diversity in yes) sysctl -w dev.$i.diversity=1 eval diversity=\$WLAN_${idx}_DIVERSITY_TX : ${diversity:=1} sysctl -w dev.$i.txantenna=$diversity eval diversity=\$WLAN_${idx}_DIVERSITY_RX : ${diversity:=1} sysctl -w dev.$i.rxantenna=$diversity ;; *) sysctl -w dev.$i.diversity=0 ;; esac unset diversity fi eval mode=\$WLAN_${idx}_MODE # Convert mode and disable if more than one sta-mode for this WLAN-Card case $mode in ad-hoc) mode=adhoc ;; managed) mode='sta nosbeacon' stanum=`expr $stanum + 1` if [ $stanum -gt 1 ] then mode= log_error "Warning: Only one MANAGED VAP on the same Card allowed: WLAN_${idx}" fi ;; master) mode=ap ;; monitor) mode=monitor ;; *) mode= ;; esac if [ -n "$mode" ] then vapnum=`expr $vapnum + 1` # Maximum 4 VAP are possible if [ $vapnum -le 4 ] then if [ -n "$di" ] then di=`expr $di \+ 1` else di=0 fi # need to seperate because sta has to be the last vap created case $mode in sta*) vapsta_wlan="wlan$di" vapsta_wlann="$idx" ;; *) vapmaster_n=`expr $vapmaster_n + 1` eval vapmaster_${vapmaster_n}_wlan="wlan$di" eval vapmaster_${vapmaster_n}_mode="$mode" eval vapmaster_${vapmaster_n}_wlann="$idx" ;; esac else log_error "Warning: Only 4 VAP on the same Card allowed: WLAN_${idx}" fi fi fi done if [ $vapnum -eq 0 ] then di=`expr $di \+ 1` log_error "Warning: no wlan-config found for $i MAC: $mac" case $WLAN_1_MODE in ad-hoc) mode=adhoc ;; managed) mode=sta ;; master) mode=ap ;; monitor) mode=monitor ;; *) mode= ;; esac if [ -n "$mode" ] then log_info "Creating VAP No. 1 onto wlan$di/$i mode $mode, MAC-Address: $mac" wlanconfig wlan$di create wlandev $i wlanmode $mode -bssid fi else if [ -n "$vapsta_wlan" ] then tv=`expr $vapmaster_n + 1` else tv='' fi for vapnum in `seq 1 $vapmaster_n` $tv do # Calculate resulting MAC-Address of new WLAN-Device case $vapnum in 2) mf='06' ;; 3) mf='0A' ;; 4) mf='0E' ;; *) mf='00' ;; esac wmac=`echo $mac | sed "s/..\(.*\)/$mf\1/"` # sta or other? if [ $vapnum -gt $vapmaster_n ] then wlan=$vapsta_wlan mode='sta nosbeacon' mod='sta' wlann=$vapsta_wlann else eval wlan=\$vapmaster_${vapnum}_wlan eval mode=\$vapmaster_${vapnum}_mode eval mod="$mode" eval wlann=\$vapmaster_${vapnum}_wlann fi log_info "Creating VAP $vapnum onto $wlan/$wifi mode $mod, MAC-Address: $wmac" # Actually create the VAP if [ $vapnum -eq 1 ] then extraoption='-bssid' else extraoption='' fi wlanconfig $wlan create wlandev $wifi wlanmode $mode $extraoption # Patch WLAN-Configuration for WLAN-Scripts running later eval WLAN_${wlann}_MAC=$wmac done fi fi fi done unset wifi unset vapnum unset stanum unset mf unset mode unset di unset mac unset wmac unset oldwifi