Commit db4bf8d4 authored by Vivekananda Uppunda's avatar Vivekananda Uppunda Committed by Anas Nashif
Browse files

net: l2: ethernet: bring in TX-Injection mode to l2 ethernet

This set of changes brings in raw packet tx injection mode
feature to ethernet and removes it from being a Wi-Fi only feature.

It was earlier envisaged as Wi-Fi net management feature only.

Signed-off-by: default avatarVivekananda Uppunda <vivekananda.uppunda@nordicsemi.no>
parent 114548ef
Loading
Loading
Loading
Loading
+16 −0
Changes for include/zephyr/net/ethernet.h: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -179,6 +179,9 @@ enum ethernet_hw_caps {

	/** TXTIME supported */
	ETHERNET_TXTIME			= BIT(19),

	/** TX-Injection supported */
	ETHERNET_TXINJECTION_MODE	= BIT(20),
};

/** @cond INTERNAL_HIDDEN */
@@ -197,6 +200,7 @@ enum ethernet_config_type {
	ETHERNET_CONFIG_TYPE_FILTER,
	ETHERNET_CONFIG_TYPE_PORTS_NUM,
	ETHERNET_CONFIG_TYPE_T1S_PARAM,
	ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
};

enum ethernet_qav_param_type {
@@ -442,6 +446,7 @@ struct ethernet_config {
		bool auto_negotiation;
		bool full_duplex;
		bool promisc_mode;
		bool txinjection_mode;

		struct {
			bool link_10bt;
@@ -1029,6 +1034,17 @@ void net_eth_carrier_off(struct net_if *iface);
 */
int net_eth_promisc_mode(struct net_if *iface, bool enable);

/**
 * @brief Set TX-Injection mode either ON or OFF.
 *
 * @param iface Network interface
 *
 * @param enable on (true) or off (false)
 *
 * @return 0 if mode set or unset was successful, <0 otherwise.
 */
int net_eth_txinjection_mode(struct net_if *iface, bool enable);

/**
 * @brief Return PTP clock that is tied to this ethernet network interface.
 *
+13 −0
Changes for include/zephyr/net/ethernet_mgmt.h: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ enum net_request_ethernet_cmd {
	NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM,
	NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM,
	NET_REQUEST_ETHERNET_CMD_SET_T1S_PARAM,
	NET_REQUEST_ETHERNET_CMD_SET_TXINJECTION_MODE,
	NET_REQUEST_ETHERNET_CMD_GET_TXINJECTION_MODE,
};

#define NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION			\
@@ -134,6 +136,16 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM);

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_T1S_PARAM);

#define NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE				\
	(_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_TXINJECTION_MODE)

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE);

#define NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE				\
	(_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_TXINJECTION_MODE)

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE);

struct net_eth_addr;
struct ethernet_qav_param;
struct ethernet_qbv_param;
@@ -145,6 +157,7 @@ struct ethernet_req_params {
		bool auto_negotiation;
		bool full_duplex;
		bool promisc_mode;
		bool txinjection_mode;

		struct {
			bool link_10bt;
+14 −0
Changes for subsys/net/l2/ethernet/ethernet.c: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1201,6 +1201,20 @@ int net_eth_promisc_mode(struct net_if *iface, bool enable)
}
#endif/* CONFIG_NET_PROMISCUOUS_MODE */

int net_eth_txinjection_mode(struct net_if *iface, bool enable)
{
	struct ethernet_req_params params;

	if (!(net_eth_get_hw_capabilities(iface) & ETHERNET_TXINJECTION_MODE)) {
		return -ENOTSUP;
	}

	params.txinjection_mode = enable;

	return net_mgmt(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE, iface,
			&params, sizeof(struct ethernet_req_params));
}

void ethernet_init(struct net_if *iface)
{
	struct ethernet_context *ctx = net_if_l2_data(iface);
+26 −0
Changes for subsys/net/l2/ethernet/ethernet_mgmt.c: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -200,6 +200,13 @@ static int ethernet_set_config(uint32_t mgmt_request,
		memcpy(&config.t1s_param, &params->t1s_param,
		       sizeof(struct ethernet_t1s_param));
		type = ETHERNET_CONFIG_TYPE_T1S_PARAM;
	} else if (mgmt_request == NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE) {
		if (!is_hw_caps_supported(dev, ETHERNET_TXINJECTION_MODE)) {
			return -ENOTSUP;
		}

		config.txinjection_mode = params->txinjection_mode;
		type = ETHERNET_CONFIG_TYPE_TXINJECTION_MODE;
	} else {
		return -EINVAL;
	}
@@ -237,6 +244,9 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_PROMISC_MODE,
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_T1S_PARAM,
				  ethernet_set_config);

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE,
				  ethernet_set_config);

static int ethernet_get_config(uint32_t mgmt_request,
			       struct net_if *iface,
			       void *data, size_t len)
@@ -430,6 +440,19 @@ static int ethernet_get_config(uint32_t mgmt_request,
				config.txtime_param.enable_txtime;
			break;
		}
	} else if (mgmt_request == NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE) {
		if (!is_hw_caps_supported(dev, ETHERNET_TXINJECTION_MODE)) {
			return -ENOTSUP;
		}

		type = ETHERNET_CONFIG_TYPE_TXINJECTION_MODE;

		ret = api->get_config(dev, type, &config);
		if (ret) {
			return ret;
		}

		params->txinjection_mode = config.txinjection_mode;
	} else {
		return -EINVAL;
	}
@@ -455,6 +478,9 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBU_PARAM,
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM,
				  ethernet_get_config);

NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE,
				  ethernet_get_config);

void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface)
{
	net_mgmt_event_notify(NET_EVENT_ETHERNET_CARRIER_ON, iface);