]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.device
Add function that returns a string about speed and duplex state of an interface
[people/ms/network.git] / src / functions / functions.device
index 55654764da967a24277f8c1ebf3f232f6f681f6f..f5c150dd22cd0c120ee941a53266ce021bb16fc1 100644 (file)
@@ -73,6 +73,19 @@ function device_exists() {
        serial_exists ${device}
 }
 
+function device_matches_pattern() {
+       local device="${1}"
+       assert isset device
+
+       local pattern="${2}"
+       assert isset pattern
+
+       pattern="^${pattern//N/[[:digit:]]+}$"
+
+       [[ ${device} =~ ${pattern} ]] \
+               && return ${EXIT_TRUE} || return ${EXIT_FALSE}
+}
+
 function device_delete() {
        local device=${1}
        assert isset device
@@ -151,8 +164,8 @@ function device_is_batman_adv() {
        [ -d "${SYS_CLASS_NET}/${1}/mesh" ]
 }
 
-# Check if the device is a batman-adv bridge port
-function device_is_batman_adv_port() {
+# Check if the device is a batman-adv slave port
+function device_is_batman_adv_slave() {
        local device="${1}"
 
        if [ -d "${SYS_CLASS_NET}/${device}/batman_adv" ]; then
@@ -193,6 +206,22 @@ function device_is_bridge_attached() {
        [ -d "${SYS_CLASS_NET}/${device}/brport" ]
 }
 
+function device_is_wireless_monitor() {
+       local device="${1}"
+       assert isset device
+
+       device_is_wireless "${device}" && \
+               device_matches_pattern "${device}" "${PORT_PATTERN_WIRELESS_MONITOR}"
+}
+
+function device_is_wireless_adhoc() {
+       local device="${1}"
+       assert isset device
+
+       device_is_wireless "${device}" && \
+               device_matches_pattern "${device}" "${PORT_PATTERN_WIRELESS_ADHOC}"
+}
+
 function device_get_bridge() {
        local device=${1}
        assert isset device
@@ -335,12 +364,12 @@ function device_get_type() {
        elif device_is_batman_adv ${device}; then
                echo "batman-adv"
 
-       elif device_is_batman_adv_port ${device}; then
-               echo "batman-adv-port"
-
        elif device_is_loopback ${device}; then
                echo "loopback"
 
+       elif device_is_wireless_adhoc ${device}; then
+               echo "wireless-adhoc"
+
        elif device_is_wireless ${device}; then
                echo "wireless"
 
@@ -768,3 +797,22 @@ function device_get_duplex() {
 
        __device_get_file ${device} duplex
 }
+
+function device_get_link_string() {
+       local device="${1}"
+       assert isset device
+
+       local s
+
+       local speed="$(device_get_speed "${device}")"
+       if isset speed; then
+               list_append s "${speed} MBit/s"
+       fi
+
+       local duplex="$(device_get_duplex "${device}")"
+       if isset duplex; then
+               list_append s "${duplex} duplex"
+       fi
+
+       print "${s}"
+}