# Wireless connection AR928X on FreeBSD 10.1



## AHR Inc (Apr 2, 2016)

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,

```
#!/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
```


----------



## AHR Inc (Apr 2, 2016)

```
10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401

ALL NETWORK ADAPTERS:
-------------------------------------------------------------------------------
alc0:alc.0: Atheros AR8152 v2.0 PCIe Fast Ethernet:Hooked
ath0:ath.0: Atheros 9280:Hooked
-------------------------------------------------------------------------------

SELECTED DEVICE:
-------------------------------------------------------------------------------
ath0  Atheros 9280 Hooked Wireless
-------------------------------------------------------------------------------

ath0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 2290
  ether 70:f1:a1:3d:1b:78
  nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
  media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
  status: no carrier

SSID/MESH ID  BSSID  CHAN RATE  S:N  INT CAPS
AHR-24  c4:04:15:3a:93:1c  1  54M -59:-96  100 EP  RSN HTCAP WPS WME
AHR-50  c4:04:15:3a:93:1b  153  54M -60:-96  100 EP  RSN HTCAP WPS WME

ath0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 2290
  ether 70:f1:a1:3d:1b:78
  nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
  media: IEEE 802.11 Wireless Ethernet autoselect mode 11g
  status: associated

wlan0: flags=8c43<UP,BROADCAST,RUNNING,OACTIVE,SIMPLEX,MULTICAST> metric 0 mtu 1500
  ether 70:f1:a1:3d:1b:78
  inet 10.40.1.129 netmask 0xffffff00 broadcast 10.40.1.255
  inet6 fe80::72f1:a1ff:fe3d:1b78%wlan0 prefixlen 64 scopeid 0x4
  nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
  media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
  status: no carrier
  ssid AHR-50 channel 3 (2422 MHz 11g)
  regdomain 106 indoor ecm authmode OPEN privacy OFF txpower 20 bmiss 7
  scanvalid 60 protmode CTS wme burst bintval 0


Successfully initialized wpa_supplicant
```

!!! After script is returning to prompt WPA_supplicant returns an error


----------



## tobik@ (Apr 2, 2016)

AHR Inc said:


> starting at line 180


Where does line 180 begin? The forum does not show line numbers.



AHR Inc said:


> !!! After script is returning to prompt WPA_supplicant returns an error


So what's the error message?

And why have you created a poll?


----------



## AHR Inc (Apr 2, 2016)

```
# bring down all interfaces
...
  # bring up selected device
  
  # connection
:)
  ifconfig wlan0 destroy
  ifconfig wlan0 create wlandev <device>
  ifconfig wlan0 inet 10.40.1.129 netmask 255.255.255.0 ssid <name>

  ifconfig wlan0 up list scan

  # restart
  wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D bsd
...
```


```
ERROR: wpa_supplicant[334]: ioctl[SISOCS80211, op=26, val=0, arg_len=0]: Operation not supported
```


----------



## AHR Inc (Apr 4, 2016)

This release *nic_v7.zip* shows good results but not happy as there are problems with identifying hardware and neither searching for Wireless in description is something that suggests “rock solid”

Until next release of net_vX.sh we can reference to:

https://forums.freebsd.org/threads/55734/


----------

