#!/bin/sh
# checks for deaf interfaces and brings them up
# for r44952

for num in 0 1;
do
  if [ -f /sys/kernel/debug/ieee80211/phy$num/statistics/received_fragment_count ] ; then
    count_a=`cat /sys/kernel/debug/ieee80211/phy$num/statistics/received_fragment_count`
    sleep 1
    count_b=`cat /sys/kernel/debug/ieee80211/phy$num/statistics/received_fragment_count`
    if [ $count_a == $count_b ]; then
      netdev=$(ls -1d /sys/kernel/debug/ieee80211/phy$num/netdev* | head -n1 |cut -d \: -f 2)
      logger "phy$num is deaf (or has absolutely no neighbours?)... scanning with $netdev"
      iw $netdev scan &> /dev/null
    fi
  fi
done

