1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
#!/bin/sh
####################################################################
## makeVAP
##
## This script is used to create AP or Station instances (VAPs).  It
## will NOT actually join the bridge or do any RF configuration.
##
## The form of the command is
##
## makeVAP <Mode> <ESSID> <Channel_String> <beaconint>
##
## Where
##     Mode:    Either ap, ap-wds, sta, or sta-wds
##              (access point or station)
##     ESSID:   ESSID String
##     Channel: String indicating the channel configuration.  This is in
##     String   the form inst:RF:channel:mode where
##              Inst = Interface instance (which radio, 0 or 1)
##              RF   = RF indicates radio should be configured with the specified parameters
##              channel = channel to put the AP on, use 11A or 11G to scan
##              mode = operating mode, one of
##              11AST         : 11 A Static Turbo (Legacy)
##              AUTO          : Legacy Scan Mode
##              11A           : Legacy 11A mode
##              11B
##              11G
##              FH
##              TA
##              TG
##              11NAHT20
##              11NGHT20
##              11NAHT40PLUS
##              11NAHT40MINUS
##              11NGHT40PLUS  
##              11NGHT40MINUS
##              11NAHT40 (valid only when channel=11na)
##              11NGHT40 (valid only when channel=11ng)
##
##
## beaconint:   This is the beacon interval desired for this VAP.  Note
##              that this is system wide, and will override the current
##              beacon interval for ALL vaps.  You MUST also include the
##              RF command for this option.
##
## Examples:
##   Access Point with RF
##      makeVAP ap OpenAP 0:RF:6:
##   Access Point with RF, beacon interval of 400 ms
##      makeVAP ap OpenAP RF 400
##   Access Point w/o RF
##      makeVAP ap NormAP
##   WDS Root AP
##      makeVAP ap-wds RootAP RF
##   WDS Repeater (two commands)
##      makeVAP sta-wds RPTR RF
##      makeVAP ap-wds RPTR
##
###################################################################

. /etc/ath/apcfg

if [ "${1}" = "" ]; then
    echo "makeVAP usage"
    echo "makeVAP mode essid IFstr"
    echo
    echo "mode: [ap | ap-wds | sta | sta-wds | sta-fwd]"
    echo "essid: up to 32 character ESSID string"
    echo "RF: Include RF commands"
    echo "beaconint: Beacon interval, milliseconds"
    echo
    exit
fi

MODE=`echo $1 | cut -f 1 -d '-'`
SUB_MODE=`echo $1 | cut -f 2 -d '-'`
IND_MODE=`echo $1 | cut -f 3 -d '-'`

IFNUM=`echo $3 | cut -f 1 -d ':'`
RF=`echo $3 | cut -f 2 -d ':'`
PRI_CH=`echo $3 | cut -f 3 -d ':'`
CH_MODE=`echo $3 | cut -f 4 -d ':'`

if [ "${IFNUM}" != "0" -a "${IFNUM}" != "1" ]; then
    IFNUM=0
fi

##
## Need to select the proper radio parameters based on the interface
## ID
##

if [ "${IFNUM}" = "1" ]; then
    R_SHORTGI=$SHORTGI_2
	R_CWMMODE=$CWMMODE_2
    R_AMPDUENABLE=$AMPDUENABLE_2
	R_AMPDUFRAMES=$AMPDUFRAMES_2
	R_AMPDULIMIT=$AMPDULIMIT_2
	R_TXCHAIN=$TX_CHAINMASK_2
	R_RXCHAIN=$RX_CHAINMASK_2
else
    R_SHORTGI=$SHORTGI
	R_CWMMODE=$CWMMODE
    R_AMPDUENABLE=$AMPDUENABLE
	R_AMPDUFRAMES=$AMPDUFRAMES
	R_AMPDULIMIT=$AMPDULIMIT
	R_TXCHAIN=$TX_CHAINMASK
	R_RXCHAIN=$RX_CHAINMASK
fi

ESSID=$2
BEACONINT=$4

##
## First, let's see if we have the modules loaded.  If not, call the
## rc.wlan script to load them
##

MODLIST=`lsmod | grep ath_hal`

if [ "${MODLIST}" = "" ]; then
    /etc/rc.d/rc.wlan up

    ##
	## Check for bad return value.  If so, exit
	##

	if [ $? != 0 ]; then
	    exit 255
	fi
else
    echo "Modules already loaded"
fi

echo Creating ${MODE} for "${ESSID}" on ${BRIDGE}

##
## Create the instance
##

if [ "${MODE}" = "sta" ]; then
    if [ "${IND_MODE}" = "ind" ]; then
        APNAME=`wlanconfig ath create wlandev radio$IFNUM wlanmode ${MODE}`
    else
        APNAME=`wlanconfig ath create wlandev radio$IFNUM wlanmode ${MODE} nosbeacon`
    fi
    APMODE="mode managed"
else
    APNAME=`wlanconfig ath create wlandev radio$IFNUM wlanmode ${MODE}`
    if [ "${MODE}" = "adhoc" ]; then
        APMODE="mode adhoc"
    else
        APMODE="mode master"
    fi
fi

echo Added ${APNAME} ${APMODE}

##
## Enable WDS if selected
##

if [ "${SUB_MODE}" = "wds" ]; then
    iwpriv ${APNAME} wds 1
fi

## AP_STARTMODE = extap
## This will come for the station vap of repeater
if [ "${SUB_MODE}" = "ext" ]; then
	iwpriv ${APNAME} extap 1
fi


##
## Enable VAP Independant mode - for repeater-ind conf
##

if [ "${IND_MODE}" = "ind" ]; then
    if [ $PRI_CH = 11na -o $PRI_CH = 11ng ]; then
        echo "Auto Channel selection is not allowed for VAP independant mode"
        exit 255
    else
        iwpriv ${APNAME} vap_ind 1
    fi
fi

## ACS is only for AP only or Ad-Hoc mode
if [ "${MODE}" = "sta" ]; then
    if [ $CH_MODE = 11NAHT40 -o $CH_MODE = 11NGHT40 ]; then
        echo "Auto Channel selection is not for sta mode"
        exit 255
    fi
fi

##
## Enable Station forwarding if selected
##

if [ "${SUB_MODE}" = "fwd" ]; then
    iwpriv ${APNAME} stafwd 1
fi

##
## Disable Background Scan
##

iwpriv ${APNAME} bgscan 0

##
# set various debug modes
##

if [ "${DEBUGMODE}" = "" ]; then
    DEBUGMODE=0x100
fi

if [ "${HALDEBUG}" = "" ]; then
    HALDEBUG=0x0
fi

if [ "${ATHDEBUG}" = "" ]; then
    ATHDEBUG=0x0
fi

iwpriv radio$IFNUM HALDbg $HALDEBUG
iwpriv radio$IFNUM ATHDebug $ATHDEBUG
iwpriv ${APNAME} dbgLVL $DEBUGMODE

##
## Operating Mode passed in through call.  Determine the frequeny, or if a 
## scan is required
##

if [ $PRI_CH = 11na -o $PRI_CH = 11ng ]; then
    FREQ="freq 0"
else
    FREQ="freq $PRI_CH"
fi

if [ "${AP_CHANBW}" != "" ]; then
    #
    # Channel bandwidth was specified
    #

    iwpriv ${APNAME} chanbw ${AP_CHANBW}
fi

##
#####################################################################
## Check for RF command. If so, set the RF parameters, else do the
## simple cofiguration.
##

if [ "${RF}" = "RF" ]; then

    #
    # 11n configuration section
    # increase queue length
    #

    ifconfig ${APNAME} txqueuelen $TXQUEUELEN
    ifconfig radio$IFNUM txqueuelen $TXQUEUELEN

    # turn on halfgi
    iwpriv ${APNAME} shortgi $R_SHORTGI

    iwpriv ${APNAME} noedgech $NO_EDGE_CH

    iwpriv ${APNAME} mode $CH_MODE

    #
    # Check to see if we are in one of the 11NG bands that require
    # ANI processing
    #

    BAND=`echo $CH_MODE | grep 11NG`

    if [ "${BAND}" != "" ]; then
        iwpriv radio$IFNUM ForBiasAuto 1
    fi

    IS11G=`echo $CH_MODE | grep 11G`
    IS11NG=`echo $CH_MODE | grep 11NG`
	
    if [ "${IS11G}" != "" -o "${IS11NG}" != "" ]; then
        iwpriv ${APNAME} vap_doth 0
    fi
	
####################
####### TEMP WORKAROUND
####################

    PLUS=`echo $CH_MODE | grep PLUS`
    MINUS=`echo $CH_MODE | grep MINUS`

    if [ "${PLUS}" != "" ]; then
        iwpriv ${APNAME} extoffset 1
    fi
    if [ "${MINUS}" != "" ]; then
        iwpriv ${APNAME} extoffset -1
    fi

#######################

    #
    # Set Aggregation State
    #

    iwpriv radio$IFNUM AMPDU $R_AMPDUENABLE

    # set number of sub-frames in an ampdu

    iwpriv radio$IFNUM AMPDUFrames $R_AMPDUFRAMES

    # set ampdu limit

    iwpriv radio$IFNUM AMPDULim $R_AMPDULIMIT
    
    # 'g'-only mode (no 'b' stations)
    iwpriv ${APNAME} pureg $PUREG

    # 'n'-only mode (no legacy b/g/a stations)
    iwpriv ${APNAME} puren $PUREN
    #
    # set SSID and frequency
    #

    if [ "_${ESSID}" != "_any" ]; then
    	iwconfig ${APNAME} essid "${ESSID}" ${APMODE} ${FREQ}
    else
        iwconfig ${APNAME} ${APMODE} ${FREQ}
    fi

    #
    # IBSS setup channel
    # IBSS aggregation    
    #
    if [ "${MODE}" = "adhoc" ]; then
        iwconfig ${APNAME} channel ${AP_PRIMARY_CH}
        iwpriv ${APNAME} ampdu $AMPDUENABLE  
    fi

    #
    # If rate control is not auto, set the manual settings
    #
    
    if [ "${RATECTL}" != "auto" ]; then
        iwpriv ${APNAME} set11NRates $MANRATE
        iwpriv ${APNAME} set11NRetries $MANRETRIES
    fi

    #
    # Set the chain masks
    #

    if [ "${R_TXCHAIN}" != "" -a "${R_TXCHAIN}" != "0" ]; then
        iwpriv radio$IFNUM txchainmask $R_TXCHAIN
	fi

    if [ "${R_RXCHAIN}" != ""  -a "${R_RXCHAIN}" != "0" ]; then
        iwpriv radio$IFNUM rxchainmask $R_RXCHAIN
    fi

    #
    # An extra IE is provided for Intel interop
    #

    echo 1 > /proc/sys/dev/ath/htdupieenable

    #
    # This is where extra commands are executed.
    #

    if [ "${AP_EXTRA}" != "" ]; then
        echo $AP_EXTRA | grep ';'
        #There is at least one command that ends with ';'
        if [ "$?" -eq "0" ]; then
            _more_cmds=1
            while [ ${_more_cmds} -ne 0 ];
            do
                _cmd=`echo $AP_EXTRA | cut -f $_more_cmds -d ';'`
                if [ "${_cmd}" != "" ];
                then
                    $_cmd
                    _more_cmds=`expr $_more_cmds + 1`
                else
                    _more_cmds=0
                fi
                _cmd=""
            done
        else
            #probably user setting did not have a ';', cut command fails if
            #not set
            ${AP_EXTRA}
        fi
    fi

else
    ####
    # set SSID only
    ###

    iwpriv ${APNAME} mode ${CH_MODE}
    iwconfig ${APNAME} essid "${ESSID}" ${APMODE} ${FREQ}

fi

##
## Check for multiple VAPs.  If the VAP name is ath2 we assume we want the
## beacon interval to be 400 ms
##

if [ "${BEACONINT}" != "" ]; then
    #
    # Beacon interval was specified
    #

    iwpriv ${APNAME} bintval ${BEACONINT}
fi

#VOW related configurations
if [ "${IFNUM}" = "0" ]; then
    if [ "${VOW_ENABLE}" = "1" ]; then
    #apply all commands if video enabled
    #All video options are enabled by default and no dynamic configuration
        ifconfig ${APNAME} allmulti
        iwpriv ${APNAME} mcastenhance 2
        iwpriv ${APNAME} acparams 1 0 1 0
        iwpriv radio0 setKeySrchAlways 1
        iwpriv radio0 setPhyRestartWar 1
    else
        iwpriv radio0 setVowExt 0
        ifconfig ${APNAME} -allmulti
        iwpriv radio0 setKeySrchAlways 0
        iwpriv ${APNAME} mcastenhance 0
        iwpriv ${APNAME} acparams 1 0 0 0
        iwpriv radio0 set_vsp_enable 0
        iwpriv radio0 setPhyRestartWar 0
    fi

    if [ "${VOW_DEBUG}" = "1" ]; then
        iwpriv radio0 setVowExtStats 1
    else
        iwpriv radio0 setVowExtStats 0
    fi
fi

if [ "${IFNUM}" = "1" ]; then
    if [ "${VOW_ENABLE_2}" = "1" ]; then
    #apply all commands if video enabled
    #All video options are enabled by default and no dynamic configuration
        ifconfig ${APNAME} allmulti
        iwpriv ${APNAME} mcastenhance 2
        iwpriv ${APNAME} acparams 1 0 1 0
        iwpriv radio1 setKeySrchAlways 1
        iwpriv radio1 setPhyRestartWar 1
    else
        iwpriv radio1 setVowExt 0
        ifconfig ${APNAME} -allmulti
        iwpriv radio1 setKeySrchAlways 0
        iwpriv ${APNAME} mcastenhance 0
        iwpriv ${APNAME} acparams 1 0 0 0
        iwpriv radio1 set_vsp_enable 0
        iwpriv radio1 setPhyRestartWar 0
    fi

    if [ "${VOW_DEBUG_2}" = "1" ]; then
        iwpriv radio1 setVowExtStats 1
    else
        iwpriv radio1 setVowExtStats 0
    fi
fi

if [ "${AP_HIDESSID}" = "1" ]; then
     iwpriv ${APNAME} hide_ssid 1
fi

##
## Script Complete
##

echo Created ${APNAME} mode ${MODE} for "${ESSID}"