Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Txinjection pull #1468

Merged
merged 3 commits into from
Jan 26, 2024
Merged
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
64 changes: 64 additions & 0 deletions include/zephyr/net/ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -196,6 +199,8 @@ enum ethernet_config_type {
ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
ETHERNET_CONFIG_TYPE_FILTER,
ETHERNET_CONFIG_TYPE_PORTS_NUM,
ETHERNET_CONFIG_TYPE_T1S_PARAM,
ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
};

enum ethernet_qav_param_type {
Expand All @@ -206,7 +211,53 @@ enum ethernet_qav_param_type {
ETHERNET_QAV_PARAM_TYPE_STATUS,
};

enum ethernet_t1s_param_type {
ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
};

/** @endcond */
struct ethernet_t1s_param {
/** Type of T1S parameter */
enum ethernet_t1s_param_type type;
union {
/* PLCA is the Physical Layer (PHY) Collision
* Avoidance technique employed with multidrop
* 10Base-T1S standard.
*
* The PLCA parameters are described in standard [1]
* as registers in memory map 4 (MMS = 4) (point 9.6).
*
* IDVER (PLCA ID Version)
* CTRL0 (PLCA Control 0)
* CTRL1 (PLCA Control 1)
* STATUS (PLCA Status)
* TOTMR (PLCA TO Control)
* BURST (PLCA Burst Control)
*
* Those registers are implemented by each OA TC6
* compliant vendor (like for e.g. LAN865x - e.g. [2]).
*
* Documents:
* [1] - "OPEN Alliance 10BASE-T1x MAC-PHY Serial
* Interface" (ver. 1.1)
* [2] - "DS60001734C" - LAN865x data sheet
*/
struct {
/** T1S PLCA enabled */
bool enable;
/** T1S PLCA node id range: 0 to 254 */
uint8_t node_id;
/** T1S PLCA node count range: 1 to 255 */
uint8_t node_count;
/** T1S PLCA burst count range: 0x0 to 0xFF */
uint8_t burst_count;
/** T1S PLCA burst timer */
uint8_t burst_timer;
/** T1S PLCA TO value */
uint8_t to_timer;
} plca;
};
};

struct ethernet_qav_param {
/** ID of the priority queue to use */
Expand Down Expand Up @@ -395,6 +446,7 @@ struct ethernet_config {
bool auto_negotiation;
bool full_duplex;
bool promisc_mode;
bool txinjection_mode;

struct {
bool link_10bt;
Expand All @@ -404,6 +456,7 @@ struct ethernet_config {

struct net_eth_addr mac_address;

struct ethernet_t1s_param t1s_param;
struct ethernet_qav_param qav_param;
struct ethernet_qbv_param qbv_param;
struct ethernet_qbu_param qbu_param;
Expand Down Expand Up @@ -981,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.
*
Expand Down
20 changes: 20 additions & 0 deletions include/zephyr/net/ethernet_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ enum net_request_ethernet_cmd {
NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM,
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 \
Expand Down Expand Up @@ -128,6 +131,21 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBU_PARAM);

NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM);

#define NET_REQUEST_ETHERNET_SET_T1S_PARAM \
(_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_T1S_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;
Expand All @@ -139,6 +157,7 @@ struct ethernet_req_params {
bool auto_negotiation;
bool full_duplex;
bool promisc_mode;
bool txinjection_mode;

struct {
bool link_10bt;
Expand All @@ -152,6 +171,7 @@ struct ethernet_req_params {
struct ethernet_qbv_param qbv_param;
struct ethernet_qbu_param qbu_param;
struct ethernet_txtime_param txtime_param;
struct ethernet_t1s_param t1s_param;

int priority_queues_num;
int ports_num;
Expand Down
14 changes: 14 additions & 0 deletions subsys/net/l2/ethernet/ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,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);
Expand Down
37 changes: 37 additions & 0 deletions subsys/net/l2/ethernet/ethernet_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ static int ethernet_set_config(uint32_t mgmt_request,

config.promisc_mode = params->promisc_mode;
type = ETHERNET_CONFIG_TYPE_PROMISC_MODE;
} else if (mgmt_request == NET_REQUEST_ETHERNET_SET_T1S_PARAM) {
if (net_if_is_up(iface)) {
return -EACCES;
}

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;
}
Expand Down Expand Up @@ -226,6 +241,12 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXTIME_PARAM,
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_PROMISC_MODE,
ethernet_set_config);

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)
Expand Down Expand Up @@ -419,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;
}
Expand All @@ -444,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);
Expand Down
10 changes: 0 additions & 10 deletions subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,6 @@ void parse_mode_args_to_params(const struct shell *sh, int argc,
static struct option long_options[] = {{"if-index", optional_argument, 0, 'i'},
{"sta", no_argument, 0, 's'},
{"monitor", no_argument, 0, 'm'},
{"tx-injection", no_argument, 0, 't'},
{"promiscuous", no_argument, 0, 'p'},
{"ap", no_argument, 0, 'a'},
{"softap", no_argument, 0, 'k'},
{"get", no_argument, 0, 'g'},
Expand All @@ -1555,12 +1553,6 @@ void parse_mode_args_to_params(const struct shell *sh, int argc,
case 'm':
mode->mode |= WIFI_MONITOR_MODE;
break;
case 't':
mode->mode |= WIFI_TX_INJECTION_MODE;
break;
case 'p':
mode->mode |= WIFI_PROMISCUOUS_MODE;
break;
case 'a':
mode->mode |= WIFI_AP_MODE;
break;
Expand Down Expand Up @@ -1962,8 +1954,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(wifi_commands,
"[-i, --if-index <idx>] : Interface index\n"
"[-s, --sta] : Station mode\n"
"[-m, --monitor] : Monitor mode\n"
"[-p, --promiscuous] : Promiscuous mode\n"
"[-t, --tx-injection] : TX-Injection mode\n"
"[-a, --ap] : AP mode\n"
"[-k, --softap] : Softap mode\n"
"[-h, --help] : Help\n"
Expand Down
Loading