#!/bin/bash

usage="
        Usage: $(basename "$0") <deviceId> [-h]
      Example: $(basename "$0") wlan0
Functionality: It resolves the phyId for the given deviceId, for example, returning \"phy0\" for \"wlan0\".
               It is the inverse function of PHY2DEV.

      Options:
	-h		Show usage information
"

while getopts 'h' OPT; do
    case $OPT in
        h)
            echo "$usage"
			exit 1
    esac
done

if [[ $# == 0 ]]; then
	(>&2 echo "Argument deviceId is mandatory.")
	echo "$usage"
	exit 1
fi

scriptDir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"

PhyPathMapping="$(${scriptDir}/GetPhyPathMapping)"
echo "$PhyPathMapping" | grep DEV:$1 | grep -Eo "PHY:\S+" | sed -e "s:PHY\:::g" | sed -e "s: ::g"