/[vps]/baselayout-vserver/branches/baselayout-1_12/net-scripts/net/iwconfig.sh
Gentoo

Diff of /baselayout-vserver/branches/baselayout-1_12/net-scripts/net/iwconfig.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 413 Revision 414
220 ESSIDVAR=$(bash_variable "${ESSID}") 220 ESSIDVAR=$(bash_variable "${ESSID}")
221 key=$(iwconfig_get_wep_key) 221 key=$(iwconfig_get_wep_key)
222 222
223 iwconfig_set_mode "${iface}" "${mode}" 223 iwconfig_set_mode "${iface}" "${mode}"
224 224
225 channel="channel_${ifvar}"
226 # We default the channel to 3
227 channel="${!channel:-3}"
228 if ! iwconfig "${iface}" channel "${channel}" ; then
229 ewarn "${iface} does not support setting the channel to \"${channel}\""
230 return 1
231 fi
232
233 # Now set the key 225 # Now set the key
234 if ! iwconfig "${iface}" key ${key} ; then 226 if ! iwconfig "${iface}" key ${key} ; then
235 if [[ ${key} != "off" ]]; then 227 if [[ ${key} != "off" ]]; then
236 ewarn "${iface} does not support setting keys" 228 ewarn "${iface} does not support setting keys"
237 ewarn "or the parameter \"mac_key_${ESSIDVAR}\" or \"key_${ESSIDVAR}\" is incorrect" 229 ewarn "or the parameter \"mac_key_${ESSIDVAR}\" or \"key_${ESSIDVAR}\" is incorrect"
242 if ! iwconfig "${iface}" essid "${ESSID}" ; then 234 if ! iwconfig "${iface}" essid "${ESSID}" ; then
243 eerror "${iface} does not support setting ESSID to \"${dessid}\"" 235 eerror "${iface} does not support setting ESSID to \"${dessid}\""
244 return 1 236 return 1
245 fi 237 fi
246 238
239 channel="channel_${ifvar}"
240 # We default the channel to 3
241 if ! iwconfig "${iface}" channel "${!channel:-3}" ; then
242 ewarn "${iface} does not support setting the channel to \"${!channel:-3}\""
243 return 1
244 fi
245
247 # Finally apply the user Config 246 # Finally apply the user Config
248 iwconfig_user_config "${iface}" "${ESSIDVAR}" 247 iwconfig_user_config "${iface}" "${ESSIDVAR}"
249 248
250 iwconfig_report "${iface}" 249 iwconfig_report "${iface}"
251 250
345# If we scanned the Access Point we know if we need WEP to associate or not 344# If we scanned the Access Point we know if we need WEP to associate or not
346# and if we have a WEP key for the ESSID or not 345# and if we have a WEP key for the ESSID or not
347# so we can fail gracefully without even trying to connect 346# so we can fail gracefully without even trying to connect
348iwconfig_associate() { 347iwconfig_associate() {
349 local iface="$1" mode="${2:-managed}" 348 local iface="$1" mode="${2:-managed}"
350 local mac="$3" wep_required="$4" freq="$5" w="(WEP Disabled)" 349 local mac="$3" wep_required="$4" freq="$5" chan="$6" w="(WEP Disabled)"
351 local dessid="${ESSID//\\\\/\\\\}" key= 350 local dessid="${ESSID//\\\\/\\\\}" key=
352 351
353 iwconfig_set_mode "${iface}" "${mode}" 352 iwconfig_set_mode "${iface}" "${mode}"
354 353
355 if [[ ${ESSID} == "any" ]]; then 354 if [[ ${ESSID} == "any" ]]; then
376 fi 375 fi
377 fi 376 fi
378 [[ ${key} != "off" ]] && w=$(iwconfig_get_wep_status "${iface}") 377 [[ ${key} != "off" ]] && w=$(iwconfig_get_wep_status "${iface}")
379 fi 378 fi
380 379
381 [[ -n ${freq} ]] && iwconfig "${iface}" freq "${freq}"
382 [[ -n ${mac} ]] && iwconfig "${iface}" ap "${mac}"
383
384 if ! iwconfig "${iface}" essid "${ESSID}" ; then 380 if ! iwconfig "${iface}" essid "${ESSID}" ; then
385 if [[ ${ESSID} != "any" ]]; then 381 if [[ ${ESSID} != "any" ]]; then
386 ewarn "${iface} does not support setting ESSID to \"${dessid}\"" 382 ewarn "${iface} does not support setting ESSID to \"${dessid}\""
387 fi 383 fi
388 fi 384 fi
389 385
386 # Only use channel or frequency
387 if [[ -n ${chan} ]] ; then
388 iwconfig "${iface}" channel "${chan}"
389 elif [[ -n ${freq} ]] ; then
390 iwconfig "${iface}" freq "${freq}"
391 fi
392 [[ -n ${mac} ]] && iwconfig "${iface}" ap "${mac}"
393
390 # Finally apply the user Config 394 # Finally apply the user Config
391 iwconfig_user_config "${iface}" "${ESSIDVAR}" 395 iwconfig_user_config "${iface}" "${ESSIDVAR}"
392 396
393 vebegin "Connecting to \"${dessid}\" in ${mode} mode ${w}" 397 vebegin "Connecting to \"${dessid}\" in ${mode} mode ${w}"
394 398
451 # Sleep if required 455 # Sleep if required
452 x="sleep_scan_${ifvar}" 456 x="sleep_scan_${ifvar}"
453 [[ -z ${!x} || ${!x} -gt 0 ]] && sleep "${!x:-1}" 457 [[ -z ${!x} || ${!x} -gt 0 ]] && sleep "${!x:-1}"
454 458
455 local error=true i=-1 line= 459 local error=true i=-1 line=
456 local -a mac=() essid=() enc=() qual=() mode=() 460 local -a mac=() essid=() enc=() qual=() mode=() freq=() chan=()
457 461
458 while read line; do 462 while read line; do
459 error=false 463 error=false
460 case "${line}" in 464 case "${line}" in
461 *Address:*) 465 *Address:*)
474 *'Encryption key:'*) 478 *'Encryption key:'*)
475 enc[i]="${line#*:}" 479 enc[i]="${line#*:}"
476 ;; 480 ;;
477 *Frequency:*) 481 *Frequency:*)
478 freq[i]="${line#*:}" 482 freq[i]="${line#*:}"
483 x="${freq[i]#* }"
484 freq[i]="${freq[i]%% *}${x:0:1}"
485 ;;
486 *Channel:*)
487 chan[i]="${line#*:}"
488 chan[i]="${chan[i]%% *}"
479 ;; 489 ;;
480 *Quality*) 490 *Quality*)
481 qual[i]="${line#*:}" 491 qual[i]="${line#*:}"
482 qual[i]="${qual[i]%/*}" 492 qual[i]="${qual[i]%/*}"
483 qual[i]="${qual[i]//[![:digit:]]/}" 493 qual[i]="${qual[i]//[![:digit:]]/}"
531 unset qual[y] 541 unset qual[y]
532 unset essid[y] 542 unset essid[y]
533 unset mode[y] 543 unset mode[y]
534 unset enc[y] 544 unset enc[y]
535 unset freq[y] 545 unset freq[y]
546 unset chan[y]
536 fi 547 fi
537 done 548 done
538 done 549 done
539 mac=( "${mac[@]}" ) 550 mac=( "${mac[@]}" )
540 qual=( "${qual[@]}" ) 551 qual=( "${qual[@]}" )
541 essid=( "${essid[@]}" ) 552 essid=( "${essid[@]}" )
542 mode=( "${mode[@]}" ) 553 mode=( "${mode[@]}" )
543 enc=( "${enc[@]}" ) 554 enc=( "${enc[@]}" )
544 freq=( "${freq[@]}" ) 555 freq=( "${freq[@]}" )
556 chan=( "${chan[@]}" )
545 557
546 for (( i=0; i<${#mac[@]}; i++ )); do 558 for (( i=0; i<${#mac[@]}; i++ )); do
547 # Don't like ad-hoc nodes by default 559 # Don't like ad-hoc nodes by default
548 [[ ${mode[i]} == "ad-hoc" ]] && (( qual[i]-=10000 )) 560 [[ ${mode[i]} == "ad-hoc" ]] && (( qual[i]-=10000 ))
549 sortline="${sortline}${qual[i]} ${i}\n" 561 sortline="${sortline}${qual[i]} ${i}\n"
555 mac_APs[i]="${mac[${sortline[x]}]}" 567 mac_APs[i]="${mac[${sortline[x]}]}"
556 essid_APs[i]="${essid[${sortline[x]}]}" 568 essid_APs[i]="${essid[${sortline[x]}]}"
557 mode_APs[i]="${mode[${sortline[x]}]}" 569 mode_APs[i]="${mode[${sortline[x]}]}"
558 enc_APs[i]="${enc[${sortline[x]}]}" 570 enc_APs[i]="${enc[${sortline[x]}]}"
559 freq_APs[i]="${freq[${sortline[x]}]}" 571 freq_APs[i]="${freq[${sortline[x]}]}"
572 chan_APs[i]="${chan[${sortline[x]}]}"
560 done 573 done
561 574
562 return 0 575 return 0
563} 576}
564 577
627 unset essid_APs[i] 640 unset essid_APs[i]
628 unset mode_APs[i] 641 unset mode_APs[i]
629 unset mac_APs[i] 642 unset mac_APs[i]
630 unset enc_APs[i] 643 unset enc_APs[i]
631 unset freq_APs[i] 644 unset freq_APs[i]
645 unset chan_APs[i]
632 done 646 done
633 647
634 # We need to squash our arrays so indexes work again 648 # We need to squash our arrays so indexes work again
635 essid_APs=( "${essid_APs[@]}" ) 649 essid_APs=( "${essid_APs[@]}" )
636 mode_APs=( "${mode_APs[@]}" ) 650 mode_APs=( "${mode_APs[@]}" )
637 mac_APs=( "${mac_APs[@]}" ) 651 mac_APs=( "${mac_APs[@]}" )
638 enc_APs=( "${enc_APs[@]}" ) 652 enc_APs=( "${enc_APs[@]}" )
639 freq_APs=( "${freq_APs[@]}" ) 653 freq_APs=( "${freq_APs[@]}" )
654 chan_APs=( "${chan_APs[@]}" )
640} 655}
641 656
642# bool iwconfig_force_preferred(char *iface) 657# bool iwconfig_force_preferred(char *iface)
643# 658#
644# Forces the preferred_aps list to associate in order 659# Forces the preferred_aps list to associate in order
677 for essid in "${preferred_aps[@]}"; do 692 for essid in "${preferred_aps[@]}"; do
678 for ((i=0; i<${#essid_APs[@]}; i++)); do 693 for ((i=0; i<${#essid_APs[@]}; i++)); do
679 if [[ ${essid} == "${essid_APs[i]}" ]]; then 694 if [[ ${essid} == "${essid_APs[i]}" ]]; then
680 ESSID="${essid}" 695 ESSID="${essid}"
681 iwconfig_associate "${iface}" "${mode_APs[i]}" "${mac_APs[i]}" \ 696 iwconfig_associate "${iface}" "${mode_APs[i]}" "${mac_APs[i]}" \
682 "${enc_APs[i]}" "${freq_APs[i]}" && return 0 697 "${enc_APs[i]}" "${freq_APs[i]}" "${chan_APs[i]}" && return 0
683 break 698 break
684 fi 699 fi
685 done 700 done
686 done 701 done
687 702
704 fi 719 fi
705 done 720 done
706 if ! ${has_preferred} ; then 721 if ! ${has_preferred} ; then
707 ESSID="${essid_APs[i]}" 722 ESSID="${essid_APs[i]}"
708 iwconfig_associate "${iface}" "${mode_APs[i]}" "${mac_APs[i]}" \ 723 iwconfig_associate "${iface}" "${mode_APs[i]}" "${mac_APs[i]}" \
709 "${enc_APs[i]}" "${freq_APs[i]}" && return 0 724 "${enc_APs[i]}" "${freq_APs[i]}" "${chan_APs[i]}" && return 0
710 fi 725 fi
711 done 726 done
712 727
713 return 1 728 return 1
714} 729}
749 unset essid_APs[j] 764 unset essid_APs[j]
750 unset mode_Aps[j] 765 unset mode_Aps[j]
751 unset mac_APs[j] 766 unset mac_APs[j]
752 unset enc_APs[j] 767 unset enc_APs[j]
753 unset freq_APs[j] 768 unset freq_APs[j]
769 unset chan_APs[j]
754 # We need to squash our arrays so that indexes work 770 # We need to squash our arrays so that indexes work
755 essid_APs=( "${essid_APs[@]}" ) 771 essid_APs=( "${essid_APs[@]}" )
756 mode_APs=( "${mode_APs[@]}" ) 772 mode_APs=( "${mode_APs[@]}" )
757 mac_APs=( "${mac_APs[@]}" ) 773 mac_APs=( "${mac_APs[@]}" )
758 enc_APs=( "${enc_APs[@]}" ) 774 enc_APs=( "${enc_APs[@]}" )
759 freq_APs=( "${freq_APs[@]}" ) 775 freq_APs=( "${freq_APs[@]}" )
776 chan_APs=( "${chan_APs[@]}" )
760 break 777 break
761 fi 778 fi
762 done 779 done
763 for ((j=0; j<${#preferred_aps[@]}; j++)); do 780 for ((j=0; j<${#preferred_aps[@]}; j++)); do
764 if [[ ${preferred_aps[j]} == "${e}" ]]; then 781 if [[ ${preferred_aps[j]} == "${e}" ]]; then
778# Then we scan for access points and try to connect to them in a predetermined order 795# Then we scan for access points and try to connect to them in a predetermined order
779# Once we're connected we show a report and then configure any interface 796# Once we're connected we show a report and then configure any interface
780# variables for the ESSID 797# variables for the ESSID
781iwconfig_configure() { 798iwconfig_configure() {
782 local iface="$1" e= x= ifvar=$(bash_variable "$1") 799 local iface="$1" e= x= ifvar=$(bash_variable "$1")
783 local -a essid_APs=() mac_APs=() mode_APs=() enc_APs=() freq_APs=() 800 local -a essid_APs=() mac_APs=() mode_APs=()
801 local -a enc_APs=() freq_APs=() chan_APs=()
784 802
785 ESSID="essid_${ifvar}" 803 ESSID="essid_${ifvar}"
786 ESSID="${!ESSID}" 804 ESSID="${!ESSID}"
787 805
788 # Setup ad-hoc mode? 806 # Setup ad-hoc mode?

Legend:
Removed from v.413  
changed lines
  Added in v.414

  ViewVC Help
Powered by ViewVC 1.1.20