From 9cc2f50405e38b3ddd0b597c754fadf313384360 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Thu, 14 May 2020 15:52:13 +0800 Subject: [PATCH] netdev/register: configurable net packet size Change-Id: I2af571a0273e67a06c1b4543eac3ded7cfdd8060 Signed-off-by: chao.an --- net/netdev/netdev_register.c | 62 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index 3b00ee60eb..15a5d1d834 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -237,8 +237,8 @@ static int get_ifindex(void) * * Input Parameters: * dev - The device driver structure to be registered. - * lltype - Link level protocol used by the driver (Ethernet, SLIP, TUN, ... - * ... + * lltype - Link level protocol used by the driver (Ethernet, SLIP, TUN, + * ...) * * Returned Value: * 0:Success; negated errno on failure @@ -253,6 +253,8 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) { FAR char devfmt_str[IFNAMSIZ]; FAR const char *devfmt; + uint16_t pktsize = 0; + uint8_t llhdrlen = 0; int devnum; #ifdef CONFIG_NETDEV_IFINDEX int ifindex; @@ -268,63 +270,63 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) { #ifdef CONFIG_NET_LOOPBACK case NET_LL_LOOPBACK: /* Local loopback */ - dev->d_llhdrlen = 0; - dev->d_pktsize = NET_LO_PKTSIZE; - devfmt = NETDEV_LO_FORMAT; + llhdrlen = 0; + pktsize = NET_LO_PKTSIZE; + devfmt = NETDEV_LO_FORMAT; break; #endif #ifdef CONFIG_NET_ETHERNET case NET_LL_ETHERNET: /* Ethernet */ - dev->d_llhdrlen = ETH_HDRLEN; - dev->d_pktsize = CONFIG_NET_ETH_PKTSIZE; - devfmt = NETDEV_ETH_FORMAT; + llhdrlen = ETH_HDRLEN; + pktsize = CONFIG_NET_ETH_PKTSIZE; + devfmt = NETDEV_ETH_FORMAT; break; #endif #ifdef CONFIG_DRIVERS_IEEE80211 case NET_LL_IEEE80211: /* IEEE 802.11 */ - dev->d_llhdrlen = ETH_HDRLEN; - dev->d_pktsize = CONFIG_NET_ETH_PKTSIZE; - devfmt = NETDEV_WLAN_FORMAT; + llhdrlen = ETH_HDRLEN; + pktsize = CONFIG_NET_ETH_PKTSIZE; + devfmt = NETDEV_WLAN_FORMAT; break; #endif #ifdef CONFIG_NET_BLUETOOTH - case NET_LL_BLUETOOTH: /* Bluetooth */ - dev->d_llhdrlen = BLUETOOTH_MAX_HDRLEN; /* Determined at runtime */ + case NET_LL_BLUETOOTH: /* Bluetooth */ + llhdrlen = BLUETOOTH_MAX_HDRLEN; /* Determined at runtime */ #ifdef CONFIG_NET_6LOWPAN - dev->d_pktsize = CONFIG_NET_6LOWPAN_PKTSIZE; + pktsize = CONFIG_NET_6LOWPAN_PKTSIZE; #endif - devfmt = NETDEV_BNEP_FORMAT; + devfmt = NETDEV_BNEP_FORMAT; break; #endif #if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154) case NET_LL_IEEE802154: /* IEEE 802.15.4 MAC */ case NET_LL_PKTRADIO: /* Non-IEEE 802.15.4 packet radio */ - dev->d_llhdrlen = 0; /* Determined at runtime */ + llhdrlen = 0; /* Determined at runtime */ #ifdef CONFIG_NET_6LOWPAN - dev->d_pktsize = CONFIG_NET_6LOWPAN_PKTSIZE; + pktsize = CONFIG_NET_6LOWPAN_PKTSIZE; #endif - devfmt = NETDEV_WPAN_FORMAT; + devfmt = NETDEV_WPAN_FORMAT; break; #endif #ifdef CONFIG_NET_SLIP case NET_LL_SLIP: /* Serial Line Internet Protocol (SLIP) */ - dev->d_llhdrlen = 0; - dev->d_pktsize = CONFIG_NET_SLIP_PKTSIZE; - devfmt = NETDEV_SLIP_FORMAT; + llhdrlen = 0; + pktsize = CONFIG_NET_SLIP_PKTSIZE; + devfmt = NETDEV_SLIP_FORMAT; break; #endif #ifdef CONFIG_NET_TUN case NET_LL_TUN: /* Virtual Network Device (TUN) */ - dev->d_llhdrlen = 0; /* This will be overwritten by tun_ioctl + llhdrlen = 0; /* This will be overwritten by tun_ioctl * if used as a TAP (layer 2) device */ - dev->d_pktsize = CONFIG_NET_TUN_PKTSIZE; - devfmt = NETDEV_TUN_FORMAT; + pktsize = CONFIG_NET_TUN_PKTSIZE; + devfmt = NETDEV_TUN_FORMAT; break; #endif @@ -333,6 +335,18 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) return -EINVAL; } + /* Update the package length */ + + if (dev->d_llhdrlen == 0) + { + dev->d_llhdrlen = llhdrlen; + } + + if (dev->d_pktsize == 0) + { + dev->d_pktsize = pktsize; + } + /* Remember the verified link type */ dev->d_lltype = (uint8_t)lltype;