From 2fafd8559f463c9ed7d578f5f1441cf30897881d Mon Sep 17 00:00:00 2001 From: Hou Zhiqiang Date: Wed, 8 Dec 2021 15:01:15 +0800 Subject: [PATCH] net: socket: packet: Add EtherCAT protocol support Add EtherCAT protocol support, now applications can transmit/receive EtherCAT packets via RAW socket. Signed-off-by: Hou Zhiqiang --- include/net/ethernet.h | 4 ++++ subsys/net/lib/sockets/sockets_packet.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/net/ethernet.h b/include/net/ethernet.h index 4ef20be6afe..0712729a497 100644 --- a/include/net/ethernet.h +++ b/include/net/ethernet.h @@ -65,6 +65,7 @@ struct net_eth_addr { #define NET_ETH_PTYPE_PTP 0x88f7 #define NET_ETH_PTYPE_LLDP 0x88cc #define NET_ETH_PTYPE_ALL 0x0003 /* from linux/if_ether.h */ +#define NET_ETH_PTYPE_ECAT 0x88a4 #if !defined(ETH_P_ALL) #define ETH_P_ALL NET_ETH_PTYPE_ALL @@ -84,6 +85,9 @@ struct net_eth_addr { #if !defined(ETH_P_TSN) #define ETH_P_TSN NET_ETH_PTYPE_TSN #endif +#if !defined(ETH_P_ECAT) +#define ETH_P_ECAT NET_ETH_PTYPE_ECAT +#endif #define NET_ETH_MINIMAL_FRAME_SIZE 60 #define NET_ETH_MTU 1500 diff --git a/subsys/net/lib/sockets/sockets_packet.c b/subsys/net/lib/sockets/sockets_packet.c index 3e99f7622c9..ec33866250a 100644 --- a/subsys/net/lib/sockets/sockets_packet.c +++ b/subsys/net/lib/sockets/sockets_packet.c @@ -386,7 +386,8 @@ static const struct socket_op_vtable packet_sock_fd_op_vtable = { static bool packet_is_supported(int family, int type, int proto) { if (((type == SOCK_RAW) && (proto == ETH_P_ALL)) || - ((type == SOCK_RAW) && (proto == IPPROTO_RAW)) || + ((type == SOCK_RAW) && (proto == IPPROTO_RAW)) || + ((type == SOCK_RAW) && (proto == ETH_P_ECAT)) || ((type == SOCK_DGRAM) && (proto > 0))) { return true; }