I am not happy with the Connection part in the script bellow (starting at line 180). Deeply appreciate help with connecting the Wireless Device after bringing down the network. This is very useful for replicating errors if any while installing versions of FreeBSD on the same machine. The target is not to reset the whole network with netif restart -- kind of bypassing rc.conf settings.
Thank you,
	
	
	
		
				
			Thank you,
		Code:
	
	#!/bin/sh
# some vars to work with
NCD_tmp="NCD_tmp.txt"; WCD_tmp="WCD_tmp.txt"; WCD_run="NCD"; i=""; j=""; c=0;
NCD_rmt(){
  # start fresh
  NCD_run="$1"
  if [ "$NCD_run" == "NCD" ] ; then
  if [ -e "$NCD_tmp" ]; then
  rm $NCD_tmp
  touch $NCD_tmp
  sleep 1
  fi
  fi
  if [ "$NCD_run" == "WCD" ] ; then
  if [ -e "$WCD_tmp" ]; then
  rm $WCD_tmp
  touch $WCD_tmp
  sleep 1
  fi
  fi
}
# 02  Network Controller Device
NCD_src=`sysctl -a dev | grep class=0x02`
NCD_rmt $WCD_run
for i in $NCD_src; do
  echo ${i} >> $NCD_tmp
done
i="";
NCD_fld=$(grep ":" $NCD_tmp | awk -F : '{ print $1 }')
if [ ! -z "$NCD_fld" ]; then
  NCD_rmt $WCD_run
  for i in $NCD_fld; do
  NCD_dev=$(echo ${i} | cut -d'.' -f2)
  NCD_cnt=$(echo ${i} | cut -d'.' -f3)
  NCD_dsc=$(sysctl -a dev.${NCD_dev}.${NCD_cnt}.%desc | cut -d':' -f2)
  echo "${NCD_dev}${NCD_cnt}:${NCD_dev}.${NCD_cnt}:${NCD_dsc}:Hooked" >> $NCD_tmp
  done
fi
# lets run pciconf
WCD_run="WCD"; i="";
WCD_src=`pciconf -lv | grep class=0x02`
NCD_rmt $WCD_run
for i in $WCD_src; do
  echo ${i} >> $WCD_tmp
done
i="";
WCD_fld=$(grep ":" $WCD_tmp | awk -F : '{ print $1 }')
if [ ! -z "$WCD_fld" ]; then
  WCD_xmp=$(grep ":" $NCD_tmp | awk -F : '{ print $1 }')
  for i in $WCD_fld; do
  WCD_nme=$(grep "${i}" $WCD_tmp)
  WCD_sta=$(pciconf -a ${WCD_nme} | cut -d' ' -f2 -f3 -f4)
  # device
  WCD_dsc=$(pciconf -lv ${WCD_nme} | grep device)
  WCD_dsc=$(echo ${WCD_dsc} | cut -d'=' -f2)
  WCD_dsc=$(echo "$WCD_dsc" | sed "s/\'//g")
  WCD_pci=$(echo ${i} | cut -d'@' -f1)
  NCD_res=$(grep "${WCD_pci}" $NCD_tmp)
  # if no results from grep, should be a new device
  if [ -z "$NCD_res" ]; then
  # This will not work if double digits
  WCD_max=9
  for j in $(seq 1 $WCD_max); do
  if [ ! -z $(echo ${WCD_pci} | grep ${j}) ]; then
  WCD_two=$(echo "$WCD_pci" | sed "s/$j/\.$j/g")
  echo "${WCD_pci}:${WCD_two}:${WCD_dsc}:${WCD_sta}" >> $NCD_tmp
  fi
  done
  fi
  done
fi
  if [ -e "$WCD_tmp" ]; then
  rm $WCD_tmp
  sleep 1
  fi
# Example usage of data colected in tmp file:
XMP_exm(){
  i=""
  NCD_xmp=$(grep ":" $NCD_tmp | awk -F : '{ print $1 }')
  echo ""
  echo "-------------------------------------------------------------------------------"
  for i in $NCD_xmp; do
  c=`expr $c + 1`
  XMP_dsc=$(grep "${i}" $NCD_tmp | awk -F : '{ print $3 }')
  echo "[${c}] [${i}] ${XMP_dsc}"
  done
  echo ""
  echo "Select Network Controller Device to work with"
  echo "Enter the number coresponding to network device listed above (default [1]):"
  read XMP_sel
  if [ -z "$XMP_sel" ]; then
  XMP_sel=1
  fi
  echo "Selection made is: "${XMP_sel}
  echo ""
  i=""; c=0;
  XMP_xmp=$(grep ":" $NCD_tmp | awk -F : '{ print $1 }')
  for i in $XMP_xmp; do
  c=`expr $c + 1`
  if [ "$XMP_sel" -eq "$c" ] ; then
  # lets get some info on selection
  XMP_con=$(grep "${i}" $NCD_tmp | awk -F : '{ print $4 }')
  XMP_dsc=$(grep "${i}" $NCD_tmp | awk -F : '{ print $3 }')
  XMP_dev=$(grep "${i}" $NCD_tmp | awk -F : '{ print $1 }')
  fi
  done
  XMP_sta=$(pciconf -lv ${XMP_dev} | grep -i device | cut -d'=' -f2)
  XMP_cek="Wired"
  for i in $XMP_sta; do
  if [ "$i" == "Wireless" ] ; then
  XMP_cek="Wireless"
  fi
  done
  XMP_err="none"
  if [ "$XMP_con" != "Hooked" ] ; then
  XMP_err="Error: device selected is not attached to system -- manual intervention required"
  XMP_dev=""; XMP_dsc=""; XMP_con="";
  fi
  echo ""
  echo "ALL NETWORK ADAPTERS:"
  echo "-------------------------------------------------------------------------------"
  cat $NCD_tmp
  echo "-------------------------------------------------------------------------------"
  echo ""
  echo "SELECTED DEVICE:"
  echo "-------------------------------------------------------------------------------"
  echo "${XMP_dev} ${XMP_dsc} ${XMP_con} ${XMP_cek}"
  echo "-------------------------------------------------------------------------------"
  CON_funk $XMP_err $XMP_cek $XMP_dev
}
CON_funk(){
  i=""
  CON_err="$1"
  CON_cek="$2"
  CON_dev="$3"
  CON_arr=$(grep ":" $NCD_tmp | awk -F : '{ print $1 }')
  if [ "$CON_cek" == "Wireless" ] ; then
  if [ "$CON_err" == "none" ] ; then
  # bring down all interfaces
  ifconfig wlan0 down
  for i in $CON_arr; do
  ifconfig $i down
  sleep 1
  done
  # bring up selected device
  ifconfig $CON_dev up
  # connection
  ifconfig $CON_dev
  ifconfig wlan0 destroy
  ifconfig wlan0 create wlandev ${CON_dev}
  ifconfig wlan0 inet 10.40.1.129 netmask 255.255.255.0 ssid AHR-50
  ifconfig wlan0 up list scan
  sleep 3
   
  ifconfig ${CON_dev}; echo ""; echo "";
  ifconfig wlan0; echo ""; echo "";
  # restart
  wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D bsd
  #/etc/rc.d/netif restart wlan0
  #/etc/rc.d/wpa_supplicant restart wlan0
  else
  echo ${CON_err}
  fi
  else
  echo "This script will not process Non Wireless Devices!"
  fi
}
XMP_exm