29 #include <linux/version.h> 30 #include <linux/netdevice.h> 31 #include <linux/etherdevice.h> 74 memset(&dbg->
stats, 0,
sizeof(
struct net_device_stats));
76 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) 77 dbg->
dev = alloc_netdev(
sizeof(
ec_debug_t *), name, NET_NAME_UNKNOWN, ether_setup);
79 dbg->
dev = alloc_netdev(
sizeof(
ec_debug_t *), name, ether_setup);
84 " for debug object!\n");
108 free_netdev(dbg->
dev);
117 const struct net_device *net_dev
125 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0) 126 eth_hw_addr_set(dbg->
dev, net_dev->dev_addr);
128 memcpy(dbg->
dev->dev_addr, net_dev->dev_addr, ETH_ALEN);
132 if ((result = register_netdev(dbg->
dev))) {
134 " error %i\n", result);
151 unregister_netdev(dbg->
dev);
171 if (!(skb = dev_alloc_skb(size))) {
172 dbg->
stats.rx_dropped++;
177 memcpy(skb_put(skb, size), data, size);
180 dbg->
stats.rx_packets++;
181 dbg->
stats.rx_bytes += size;
185 skb->protocol = eth_type_trans(skb, dbg->
dev);
186 skb->ip_summed = CHECKSUM_UNNECESSARY;
199 struct net_device *dev
216 struct net_device *dev
234 struct net_device *dev
240 dbg->
stats.tx_dropped++;
251 struct net_device *dev
void ec_debug_clear(ec_debug_t *dbg)
Debug interface destructor.
Network interface for debugging purposes.
uint8_t registered
net_device is opened
int ec_dbgdev_tx(struct sk_buff *, struct net_device *)
Transmits data via the virtual network device.
Debugging network interface.
Global definitions and macros.
EtherCAT master structure.
void ec_debug_unregister(ec_debug_t *dbg)
Unregister debug interface.
struct net_device * dev
net_device for virtual ethernet device
#define EC_MASTER_WARN(master, fmt, args...)
Convenience macro for printing master-specific warnings to syslog.
ec_master_t * master
EtherCAT master.
#define EC_MASTER_ERR(master, fmt, args...)
Convenience macro for printing master-specific errors to syslog.
void ec_debug_send(ec_debug_t *dbg, const uint8_t *data, size_t size)
Sends frame data to the interface.
void ec_debug_register(ec_debug_t *dbg, const struct net_device *net_dev)
Register debug interface.
int ec_debug_init(ec_debug_t *dbg, ec_device_t *device, const char *name)
Debug interface constructor.
int ec_dbgdev_stop(struct net_device *)
Stops the virtual network device.
struct net_device_stats * ec_dbgdev_stats(struct net_device *)
Gets statistics about the virtual network device.
int ec_dbgdev_open(struct net_device *)
Opens the virtual network device.
static const struct net_device_ops ec_dbg_netdev_ops
Device operations for debug interfaces.
ec_device_t * device
Parent device.
uint8_t opened
net_device is opened
#define EC_MASTER_INFO(master, fmt, args...)
Convenience macro for printing master-specific information to syslog.
struct net_device_stats stats
device statistics