]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Add "network device list" command
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Dec 2014 00:50:33 +0000 (00:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Dec 2014 00:55:05 +0000 (00:55 +0000)
Will show a list of all different devices and details
about them.

src/functions/functions.device
src/functions/functions.phy
src/functions/functions.serial
src/network

index c9c471a1bc49eb0c8c07f221391bdc9e24e20fab..c6a6d73679428ef2b11f83b31808dcd495005369 100644 (file)
@@ -58,6 +58,22 @@ function macify() {
        return ${EXIT_ERROR}
 }
 
+function device_list() {
+       local devices
+
+       # Add all interfaces
+       list_append devices $(devices_get_all)
+
+       # Add all PHYs
+       list_append devices $(phy_list)
+
+       # Add all serial devices
+       list_append devices $(serial_list)
+
+       # Return a sorted result
+       list_sort ${devices}
+}
+
 # Check if the device exists
 function device_exists() {
        local device=${1}
@@ -68,7 +84,11 @@ function device_exists() {
        # Check for a normal network device.
        [ -d "${SYS_CLASS_NET}/${device}" ] && return ${EXIT_OK}
 
-       # If the check above, did not find a result,
+       # If the check above did not find a result,
+       # we check for PHYs.
+       phy_exists "${device}" && return ${EXIT_OK}
+
+       # If the check above did not find a result,
        # we check for serial devices.
        serial_exists ${device}
 }
@@ -324,6 +344,10 @@ function device_get_phy() {
        return ${EXIT_ERROR}
 }
 
+function device_is_phy() {
+       phy_exists $@
+}
+
 function device_is_serial() {
        serial_exists $@
 }
@@ -398,6 +422,9 @@ function device_get_type() {
        elif device_is_serial ${device}; then
                echo "serial"
 
+       elif device_is_phy ${device}; then
+               echo "phy"
+
        else
                echo "unknown"
        fi
index 79a356ed2e0ffb51cd8571c0d6b5469f9c0f3663..90288f76921cb3d96d809637b41f3568027a1f41 100644 (file)
@@ -96,7 +96,7 @@ function phy_get_devices() {
        assert isset phy
 
        local device
-       for device in $(device_get_all); do
+       for device in $(devices_get_all); do
                local p="$(device_get_phy "${device}")"
 
                if [ "${phy}" = "${p}" ]; then
index aaa3e4eac2b347ed382b79f223e125a867574285..170305b300761d2e1def4b9445ae940cd8bb6bf6 100644 (file)
 # This is a list of baudrates that are supported.
 SERIAL_BAUDRATES="921600 460800 230400 115200 57600 38400 19200 9600"
 
+function serial_list() {
+       local device
+       for device in /dev/ttyUSB*; do
+               if serial_exists "${device}"; then
+                       echo "${device}"
+               fi
+       done
+}
+
 function serial_exists() {
        local device=${1}
 
index 3d3b31ab80fb23063d8087873e2149421cfbcb02..80ddae0dfe1976a498a7d66c70d87f3d16c14860 100644 (file)
@@ -58,35 +58,45 @@ function cli_device() {
                exit ${EXIT_OK}
        fi
 
-       local device=${1}
-       local action=${2}
-       shift 2
-
-       if ! isset device; then
-               cli_show_man network-device
-               return ${EXIT_ERROR}
-       fi
-
-       assert device_exists ${device}
+       local action="${1}"
+       shift
 
        case "${action}" in
-               discover)
-                       cli_device_discover ${device} $@
-                       ;;
-               monitor)
-                       cli_device_monitor "${device}" $@
-                       ;;
-               status)
-                       cli_device_status ${device}
-                       ;;
-               unlock)
-                       cli_device_serial_unlock ${device} $@
-                       ;;
-               ussd)
-                       cli_device_send_ussd_command "${device}" $@
+               list)
+                       cli_device_list $@
                        ;;
                *)
-                       cli_show_man network-device
+                       local device="${action}"
+                       action="${1}"
+                       shift
+
+                       if ! isset device; then
+                               cli_show_man network-device
+                               return ${EXIT_ERROR}
+                       fi
+
+                       assert device_exists ${device}
+
+                       case "${action}" in
+                               discover)
+                                       cli_device_discover ${device} $@
+                                       ;;
+                               monitor)
+                                       cli_device_monitor "${device}" $@
+                                       ;;
+                               status)
+                                       cli_device_status ${device}
+                                       ;;
+                               unlock)
+                                       cli_device_serial_unlock ${device} $@
+                                       ;;
+                               ussd)
+                                       cli_device_send_ussd_command "${device}" $@
+                                       ;;
+                               *)
+                                       cli_show_man network-device
+                                       ;;
+                       esac
                        ;;
        esac
 
@@ -94,8 +104,8 @@ function cli_device() {
 }
 
 function cli_device_status() {
-       local device=${1}
-       assert device_exists ${device}
+       local device="${1}"
+       assert isset device
 
        # Disable debugging output here.
        local log_disable_stdout=${LOG_DISABLE_STDOUT}
@@ -107,11 +117,17 @@ function cli_device_status() {
        cli_headline 1 "Device status: ${device}"
        cli_print_fmt1 1 "Name"         "${device}"
 
-       # Handle serial devices.
-       if [ "${type}" = "serial" ]; then
-               cli_device_status_serial ${device}
-               return $?
-       fi
+       # Handle special devices
+       case "${type}" in
+               phy)
+                       cli_device_status_phy "${device}"
+                       return $?
+                       ;;
+               serial)
+                       cli_device_status_serial "${device}"
+                       return $?
+                       ;;
+       esac
 
        # Print the device status.
        device_is_up ${device} &>/dev/null
@@ -170,6 +186,18 @@ function cli_device_status() {
                cli_space
        fi
 
+       case "${type}" in
+               wireless*)
+                       local phy="$(device_get_phy "${device}")"
+                       if isset phy; then
+                               cli_headline 2 "PHY"
+                               cli_print_fmt1 2 "Name" "${phy}"
+                               cli_print_fmt1 2 "Address" "$(phy_get_address "${phy}")"
+                               cli_space
+                       fi
+                       ;;
+       esac
+
        # Reset the logging level.
        LOG_DISABLE_STDOUT=${log_disable_stdout}
 }
@@ -235,6 +263,28 @@ function cli_device_status_serial() {
        cli_space
 }
 
+function cli_device_status_phy() {
+       local phy="${1}"
+       assert phy_exists "${phy}"
+
+       local address="$(phy_get_address "${phy}")"
+       cli_print_fmt1 1 "Address" "${address}"
+       cli_space
+
+       local devices="$(phy_get_devices "${phy}")"
+       if isset devices; then
+               cli_headline 2 "Soft interfaces"
+
+               local device
+               for device in ${devices}; do
+                       cli_print 2 "* %s" "${device}"
+               done
+               cli_space
+       fi
+
+       return ${EXIT_OK}
+}
+
 function cli_device_discover() {
        local device=${1}
        shift
@@ -440,6 +490,15 @@ function cli_device_monitor() {
        exit $?
 }
 
+function cli_device_list() {
+       local device
+       for device in $(device_list); do
+               cli_device_status "${device}"
+       done
+
+       exit ${EXIT_OK}
+}
+
 function cli_hostname() {
        if cli_help_requested $@; then
                cli_show_man network