From: Michael Tremer Date: Sun, 28 Dec 2014 00:50:33 +0000 (+0000) Subject: Add "network device list" command X-Git-Tag: 007~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f90dd58cafc136a8425c1f9d5e68ed7b3d76f4ce;p=network.git Add "network device list" command Will show a list of all different devices and details about them. --- diff --git a/src/functions/functions.device b/src/functions/functions.device index c9c471a1..c6a6d736 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -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 diff --git a/src/functions/functions.phy b/src/functions/functions.phy index 79a356ed..90288f76 100644 --- a/src/functions/functions.phy +++ b/src/functions/functions.phy @@ -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 diff --git a/src/functions/functions.serial b/src/functions/functions.serial index aaa3e4ea..170305b3 100644 --- a/src/functions/functions.serial +++ b/src/functions/functions.serial @@ -22,6 +22,15 @@ # 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} diff --git a/src/network b/src/network index 3d3b31ab..80ddae0d 100644 --- a/src/network +++ b/src/network @@ -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