diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-06-12 18:41:40 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-06-12 18:42:37 +0200 |
commit | 1bcb12570c3b6f26009801ee6006b2ab305d088f (patch) | |
tree | 44647592262b0ba3b757b2a8dbe8a93c368617ff /modules/luci-base/htdocs/luci-static/resources/network.js | |
parent | 8c71b1d01ee234c5681684e9aae5f63dbe9ebb07 (diff) |
luci-base: network.js: add link status information accessors
Fixes: #5121
Fixes: 8c71b1d01e ("luci-mod-network: add port status to bridge vlan filter matrix")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static/resources/network.js')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/network.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/network.js b/modules/luci-base/htdocs/luci-static/resources/network.js index 39b8b2dc85..17dd055e25 100644 --- a/modules/luci-base/htdocs/luci-static/resources/network.js +++ b/modules/luci-base/htdocs/luci-static/resources/network.js @@ -393,6 +393,7 @@ function initNetworkState(refresh) { name: name, rawname: name, flags: dev.flags, + link: dev.link, stats: dev.stats, macaddr: dev.mac, type: dev.type, @@ -3134,6 +3135,47 @@ Device = baseclass.extend(/** @lends LuCI.network.Device.prototype */ { }, /** + * Get the carrier state of the network device. + * + * @returns {boolean} + * Returns true if the device has a carrier, e.g. when a cable is + * inserted into an ethernet port of false if there is none. + */ + getCarrier: function() { + var link = this._devstate('link'); + return (link != null ? link.carrier || false : false); + }, + + /** + * Get the current link speed of the network device if available. + * + * @returns {number|null} + * Returns the current speed of the network device in Mbps. If the + * device supports no ethernet speed levels, null is returned. + * If the device supports ethernet speeds but has no carrier, -1 is + * returned. + */ + getSpeed: function() { + var link = this._devstate('link'); + return (link != null ? link.speed || null : null); + }, + + /** + * Get the current duplex mode of the network device if available. + * + * @returns {string|null} + * Returns the current duplex mode of the network device. Returns + * either "full" or "half" if the device supports duplex modes or + * null if the duplex mode is unknown or unsupported. + */ + getDuplex: function() { + var link = this._devstate('link'), + duplex = link ? link.duplex : null; + + return (duplex != 'unknown') ? duplex : null; + }, + + /** * Get the primary logical interface this device is assigned to. * * @returns {null|LuCI.network.Protocol} |