#!/bin/ash

[ "$ACTION" == "add" ] || exit 0

PHYNBR=${DEVPATH##*/phy}

[ -n $PHYNBR ] || exit 0

. /lib/functions.sh
. /lib/functions/system.sh

OPATH=${DEVPATH##/devices/platform/}
OPATH=${OPATH%%/ieee*}

# 10 radios is enough for anyone!
for i in `seq 0 9`;
  do
  BUS=`uci get wireless.@wifi-device[$i].path`
  if [ "$BUS " == "$OPATH " ]
      then
      PHYNAME=${DEVPATH##*ieee80211/}
      NPHYNAME=`uci get wireless.@wifi-device[$i].phyname`
      if [ "$NPHYNAME " != " " ]
          then
          if [ "$PHYNAME " != "$NPHYNAME " ]
              then
              iw $PHYNAME set name $NPHYNAME
          fi
      fi
  fi
done
