From 4733a336e53db504df77436b2196efd0e589ea1d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 26 Aug 2014 19:36:43 +0200 Subject: [PATCH] Make searching for the corresponding phy of a wireless device faster --- src/functions/functions.device | 11 +++++++++++ src/functions/functions.phy | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/functions/functions.device b/src/functions/functions.device index b15e15ec..7bcee8d5 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -261,6 +261,17 @@ function device_is_wireless() { [ -d "${SYS_CLASS_NET}/${device}/phy80211" ] } +function device_get_phy() { + local device="${1}" + + if device_is_wireless "${device}"; then + print "$(<${SYS_CLASS_NET}/${device}/phy80211/name)" + return ${EXIT_OK} + fi + + return ${EXIT_ERROR} +} + function device_is_serial() { serial_exists $@ } diff --git a/src/functions/functions.phy b/src/functions/functions.phy index 366eccc2..35f2b863 100644 --- a/src/functions/functions.phy +++ b/src/functions/functions.phy @@ -45,16 +45,23 @@ function phy_list() { } function phy_get() { - local info=${1} + local info="${1}" local phy - if listmatch ${info} $(phy_list); then - phy="${info}" - elif device_exists ${info}; then - info=$(device_get_address ${info}) + # As this is already a valid phy, we don't need to search on... + if phy_exists "${info}"; then + print "${info}" + return ${EXIT_OK} fi - if [ -z "${phy}" ] && mac_is_valid ${info}; then + # If this is an existing device, we can figure out the name of the + # phy directly. + if device_exists ${info}; then + phy="$(device_get_phy ${info})" + + # If we just got the MAC address we need to walk though all + # available phys and find the right one. + elif mac_is_valid ${info}; then local i for i in $(phy_list); do if [ "${info}" = "$(phy_get_address ${i})" ]; then -- 2.47.3