diff --git a/drivers/enc28j60/enc28j60.c b/drivers/enc28j60/enc28j60.c index 2f55e699a0392b68a1cfac1491ab562511c98ba9..8da556202c6718f613faa78909fc2070fe79f4f9 100644 --- a/drivers/enc28j60/enc28j60.c +++ b/drivers/enc28j60/enc28j60.c @@ -454,6 +454,14 @@ static int nd_get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len) assert(max_len >= ETHERNET_ADDR_LEN); mac_get(dev, (uint8_t *)value); return ETHERNET_ADDR_LEN; + case NETOPT_LINK_CONNECTED: + if (cmd_r_phy(dev, REG_PHY_PHSTAT2) & PHSTAT2_LSTAT) { + *((netopt_enable_t *)value) = NETOPT_ENABLE; + } + else { + *((netopt_enable_t *)value) = NETOPT_DISABLE; + } + return sizeof(netopt_enable_t); default: return netdev_eth_get(netdev, opt, value, max_len); } diff --git a/drivers/encx24j600/encx24j600.c b/drivers/encx24j600/encx24j600.c index 47c5d3d32f41416eaee10451f297a20864f214fb..4f8cd3818c3acb714ad63b9ddbe5efe6686d7bc9 100644 --- a/drivers/encx24j600/encx24j600.c +++ b/drivers/encx24j600/encx24j600.c @@ -401,6 +401,14 @@ static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len) res = ETHERNET_ADDR_LEN; } break; + case NETOPT_LINK_CONNECTED: + if (reg_get((encx24j600_t *)dev, ENC_ESTAT) & ENC_PHYLNK) { + *((netopt_enable_t *)value) = NETOPT_ENABLE; + } + else { + *((netopt_enable_t *)value) = NETOPT_DISABLE; + } + return sizeof(netopt_enable_t); default: res = netdev_eth_get(dev, opt, value, max_len); break; diff --git a/sys/include/net/netopt.h b/sys/include/net/netopt.h index 65d283e13ed736e58af019892f78d36f5a0e2787..331a5c458593e205d89a337e4b608d0c7fc92d4a 100644 --- a/sys/include/net/netopt.h +++ b/sys/include/net/netopt.h @@ -276,6 +276,18 @@ typedef enum { */ NETOPT_IS_WIRED, + /** + * @brief (@ref netopt_enable_t) Phy link status. + * + * Returns NETOPT_ENABLE when the the link of the interface is up, + * NETOPT_DISABLE when the link is down. If the interface is wireless or + * doesn't support link status detection this function will return + * -ENOTSUP. + * + * @note Setting this option will always return -ENOTSUP. + */ + NETOPT_LINK_CONNECTED, + /** * @brief get a device's "type", e.g., ethernet, 802.15.4, ... */ diff --git a/sys/net/crosslayer/netopt/netopt.c b/sys/net/crosslayer/netopt/netopt.c index 227559f3cc1f78f530ba398627a29dc21025b827..951d2f0a90e1f215d834275809fc6107d1aa2759 100644 --- a/sys/net/crosslayer/netopt/netopt.c +++ b/sys/net/crosslayer/netopt/netopt.c @@ -62,6 +62,7 @@ static const char *_netopt_strmap[] = { [NETOPT_CSMA_MINBE] = "NETOPT_CSMA_MINBE", [NETOPT_MAC_NO_SLEEP] = "NETOPT_MAC_NO_SLEEP", [NETOPT_IS_WIRED] = "NETOPT_IS_WIRED", + [NETOPT_LINK_CONNECTED] = "NETOPT_LINK_CONNECTED", [NETOPT_DEVICE_TYPE] = "NETOPT_DEVICE_TYPE", [NETOPT_CHANNEL_PAGE] = "NETOPT_CHANNEL_PAGE", [NETOPT_CCA_THRESHOLD] = "NETOPT_CCA_THRESHOLD", diff --git a/sys/shell/commands/sc_gnrc_netif.c b/sys/shell/commands/sc_gnrc_netif.c index 7b494bb85c5a35117d1fbd65e1ed30714b0885cf..403fbadb8ff3407b1b7c6986cb47a5d8dff35828 100644 --- a/sys/shell/commands/sc_gnrc_netif.c +++ b/sys/shell/commands/sc_gnrc_netif.c @@ -426,6 +426,10 @@ static void _netif_list(kernel_pid_t iface) if (res >= 0) { printf(" CR: %s ", _netopt_coding_rate_str[u8]); } + res = gnrc_netapi_get(iface, NETOPT_LINK_CONNECTED, 0, &u8, sizeof(u8)); + if (res >= 0) { + printf(" Link: %s ", (netopt_enable_t)u8 ? "up" : "down" ); + } line_thresh = _newline(0U, line_thresh); res = gnrc_netapi_get(iface, NETOPT_ADDRESS_LONG, 0, hwaddr, sizeof(hwaddr)); if (res >= 0) {