Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/zephyr/net/ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,20 @@ static inline bool net_eth_type_is_wifi(struct net_if *iface)
return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
}

/**
* @brief Check if the Ethernet L2 network interface is cabled ethernet.
*
* @param iface Pointer to network interface
*
* @return True if interface is cabled ethernet, False otherwise.
*/
static inline bool net_eth_type_is_ethernet(struct net_if *iface)
{
const struct ethernet_context *ctx = (struct ethernet_context *)net_if_l2_data(iface);

return ctx->eth_if_type == L2_ETH_IF_TYPE_ETHERNET;
}

/**
* @}
*/
Expand Down
16 changes: 16 additions & 0 deletions include/zephyr/net/net_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -3327,6 +3327,22 @@ int net_if_resume(struct net_if *iface);
bool net_if_is_suspended(struct net_if *iface);
#endif /* CONFIG_NET_POWER_MANAGEMENT */

/**
* @brief Check if the network interface is cabled ethernet
*
* @param iface Pointer to network interface
*
* @return True if interface is cabled ethernet, False otherwise.
*/
bool net_if_is_ethernet(struct net_if *iface);

/**
* @brief Get first Cabled Ethernet network interface.
*
* @return Pointer to network interface, NULL if not found.
*/
struct net_if *net_if_get_first_ethernet(void);

/**
* @brief Check if the network interface supports Wi-Fi.
*
Expand Down
22 changes: 21 additions & 1 deletion subsys/net/ip/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ struct net_if *net_if_get_default(void)
}

#if defined(CONFIG_NET_DEFAULT_IF_ETHERNET)
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
iface = net_if_get_first_ethernet();
#endif
#if defined(CONFIG_NET_DEFAULT_IF_IEEE802154)
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(IEEE802154));
Expand Down Expand Up @@ -6239,6 +6239,26 @@ void net_if_add_tx_timestamp(struct net_pkt *pkt)
}
#endif /* CONFIG_NET_PKT_TIMESTAMP_THREAD */

bool net_if_is_ethernet(struct net_if *iface)
{
if (IS_ENABLED(CONFIG_NET_L2_ETHERNET)) {
return net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET) &&
net_eth_type_is_ethernet(iface);
}

return false;
}

struct net_if *net_if_get_first_ethernet(void)
{
STRUCT_SECTION_FOREACH(net_if, iface) {
if (net_if_is_ethernet(iface)) {
return iface;
}
}
return NULL;
}

bool net_if_is_wifi(struct net_if *iface)
{
if (net_if_is_offloaded(iface)) {
Expand Down
Loading