]> git.ipfire.org Git - people/ms/network.git/commitdiff
Make searching for the corresponding phy of a wireless device faster
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Aug 2014 17:36:43 +0000 (19:36 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 26 Aug 2014 17:36:43 +0000 (19:36 +0200)
src/functions/functions.device
src/functions/functions.phy

index b15e15ec96d190df16074a89393b0d146f07eb2b..7bcee8d53a9d912c46d1d7ca06899a30b6b7561b 100644 (file)
@@ -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 $@
 }
index 366eccc2c8245ca4f00c51bcf6a4d676e70fb32a..35f2b863b0d9b09b649e1b39b1ef6e8c99873af1 100644 (file)
@@ -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