]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - config/cfgroot/network-functions.pl
hostapd: Find device by MAC address
[ipfire-2.x.git] / config / cfgroot / network-functions.pl
index 9908ee8abd2089962f8a482f8222edc1066c7106..2f704dfbfe5efe889680d72ece0299e8f8fb65ac 100644 (file)
@@ -332,6 +332,28 @@ sub setup_upstream_proxy() {
        }
 }
 
+sub list_wireless_interfaces() {
+       my %interfaces = ();
+
+       opendir(INTERFACES, "/sys/class/net");
+
+       my $intf;
+       while ($intf = readdir(INTERFACES)) {
+               # Is this a wireless interface?
+               opendir(PHY80211, "/sys/class/net/$intf/phy80211") or next;
+               closedir(PHY80211);
+
+               # Read the MAC address
+               my $address = &get_nic_property($intf, "address");
+
+               $interfaces{$address} = "$address ($intf)";
+       }
+
+       closedir(INTERFACES);
+
+       return %interfaces;
+}
+
 my %wireless_status = ();
 
 sub _get_wireless_status($) {
@@ -416,7 +438,7 @@ sub get_nic_property {
        my $property = shift;
        my $result;
 
-       open(FILE, "/sys/class/net/$nicname/$property") or die("Could not read property");
+       open(FILE, "/sys/class/net/$nicname/$property") or die("Could not read property $property for $nicname");
        $result = <FILE>;
        close(FILE);
 
@@ -465,6 +487,28 @@ sub get_mac_by_name($) {
        return $mac;
 }
 
+sub get_intf_by_address($) {
+       my $address = shift;
+
+       opendir(INTERFACES, "/sys/class/net");
+
+       while (my $intf = readdir(INTERFACES)) {
+               next if ($intf eq "." or $intf eq "..");
+
+               my $intf_address = &get_nic_property($intf, "address");
+
+               # Skip interfaces without addresses
+               next if ($intf_address eq "");
+
+               # Return a match
+               return $intf if ($intf_address eq $address);
+       }
+
+       closedir(INTERFACES);
+
+       return undef;
+}
+
 #
 ## Function to get a list of all available network zones.
 #