mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 03:05:40 +08:00
Networking: Improve naming and simplify some logic of previous commit.
This commit is contained in:
@@ -97,7 +97,7 @@ void icmpv6_advertise(FAR struct net_driver_s *dev,
|
|||||||
{
|
{
|
||||||
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
|
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
|
||||||
FAR struct icmpv6_neighbor_advertise_s *adv;
|
FAR struct icmpv6_neighbor_advertise_s *adv;
|
||||||
uint16_t l1size;
|
uint16_t lladdrsize;
|
||||||
uint16_t l3size;
|
uint16_t l3size;
|
||||||
|
|
||||||
/* Set up the IPv6 header */
|
/* Set up the IPv6 header */
|
||||||
@@ -108,8 +108,8 @@ void icmpv6_advertise(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
/* Length excludes the IPv6 header */
|
/* Length excludes the IPv6 header */
|
||||||
|
|
||||||
l1size = netdev_dev_l1size(dev);
|
lladdrsize = netdev_dev_lladdrsize(dev);
|
||||||
l3size = SIZEOF_ICMPV6_NEIGHBOR_ADVERTISE_S(l1size);
|
l3size = SIZEOF_ICMPV6_NEIGHBOR_ADVERTISE_S(lladdrsize);
|
||||||
ipv6->len[0] = (l3size >> 8);
|
ipv6->len[0] = (l3size >> 8);
|
||||||
ipv6->len[1] = (l3size & 0xff);
|
ipv6->len[1] = (l3size & 0xff);
|
||||||
|
|
||||||
@@ -137,14 +137,14 @@ void icmpv6_advertise(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
/* Set up the options */
|
/* Set up the options */
|
||||||
|
|
||||||
adv->opttype = ICMPv6_OPT_TGTLLADDR; /* Option type */
|
adv->opttype = ICMPv6_OPT_TGTLLADDR; /* Option type */
|
||||||
adv->optlen = ICMPv6_OPT_OCTECTS(l1size); /* Option length in octets */
|
adv->optlen = ICMPv6_OPT_OCTECTS(lladdrsize); /* Option length in octets */
|
||||||
|
|
||||||
/* Copy our link layer address into the message
|
/* Copy our link layer address into the message
|
||||||
* REVISIT: What if the link layer is not Ethernet?
|
* REVISIT: What if the link layer is not Ethernet?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
memcpy(adv->tgtlladdr, &dev->d_mac, l1size);
|
memcpy(adv->tgtlladdr, &dev->d_mac, lladdrsize);
|
||||||
|
|
||||||
/* Calculate the checksum over both the ICMP header and payload */
|
/* Calculate the checksum over both the ICMP header and payload */
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev)
|
|||||||
FAR struct icmpv6_srclladdr_s *srcaddr;
|
FAR struct icmpv6_srclladdr_s *srcaddr;
|
||||||
FAR struct icmpv6_mtu_s *mtu;
|
FAR struct icmpv6_mtu_s *mtu;
|
||||||
FAR struct icmpv6_prefixinfo_s *prefix;
|
FAR struct icmpv6_prefixinfo_s *prefix;
|
||||||
uint16_t l1size;
|
uint16_t lladdrsize;
|
||||||
uint16_t l3size;
|
uint16_t l3size;
|
||||||
|
|
||||||
/* Set up the IPv6 header */
|
/* Set up the IPv6 header */
|
||||||
@@ -125,9 +125,9 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev)
|
|||||||
|
|
||||||
/* Length excludes the IPv6 header */
|
/* Length excludes the IPv6 header */
|
||||||
|
|
||||||
l1size = netdev_dev_l1size(dev);
|
lladdrsize = netdev_dev_lladdrsize(dev);
|
||||||
l3size = sizeof(icmpv6_router_advertise_s) +
|
l3size = sizeof(icmpv6_router_advertise_s) +
|
||||||
SIZEOF_ICMPV6_SRCLLADDR_S(l1size) +
|
SIZEOF_ICMPV6_SRCLLADDR_S(lladdrsize) +
|
||||||
sizeof(struct icmpv6_mtu_s) +
|
sizeof(struct icmpv6_mtu_s) +
|
||||||
sizeof(icmpv6_prefixinfo_s);
|
sizeof(icmpv6_prefixinfo_s);
|
||||||
|
|
||||||
@@ -160,13 +160,13 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev)
|
|||||||
srcaddr = (FAR struct icmpv6_srclladdr_s *)
|
srcaddr = (FAR struct icmpv6_srclladdr_s *)
|
||||||
((FAR uint8_t *)adv + sizeof(icmpv6_router_advertise_s));
|
((FAR uint8_t *)adv + sizeof(icmpv6_router_advertise_s));
|
||||||
srcaddr->opttype = ICMPv6_OPT_SRCLLADDR;
|
srcaddr->opttype = ICMPv6_OPT_SRCLLADDR;
|
||||||
srcaddr->optlen = ICMPv6_OPT_OCTECTS(l1size);
|
srcaddr->optlen = ICMPv6_OPT_OCTECTS(lladdrsize);
|
||||||
memcpy(srcaddr->srclladdr, &dev->d_mac, l1size);
|
memcpy(srcaddr->srclladdr, &dev->d_mac, lladdrsize);
|
||||||
|
|
||||||
/* Set up the MTU option */
|
/* Set up the MTU option */
|
||||||
|
|
||||||
mtu = (FAR struct icmpv6_mtu_s *)
|
mtu = (FAR struct icmpv6_mtu_s *)
|
||||||
((FAR uint8_t *)srcaddr + SIZEOF_ICMPV6_SRCLLADDR_S(l1size));
|
((FAR uint8_t *)srcaddr + SIZEOF_ICMPV6_SRCLLADDR_S(lladdrsize));
|
||||||
mtu = &adv->mtu;
|
mtu = &adv->mtu;
|
||||||
mtu->opttype = ICMPv6_OPT_MTU;
|
mtu->opttype = ICMPv6_OPT_MTU;
|
||||||
mtu->optlen = 1;
|
mtu->optlen = 1;
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev)
|
|||||||
FAR struct ipv6_hdr_s *ipv6;
|
FAR struct ipv6_hdr_s *ipv6;
|
||||||
FAR struct icmpv6_router_solicit_s *sol;
|
FAR struct icmpv6_router_solicit_s *sol;
|
||||||
FAR struct eth_hdr_s *eth;
|
FAR struct eth_hdr_s *eth;
|
||||||
uint16_t l1size;
|
uint16_t lladdrsize;
|
||||||
uint16_t l3size;
|
uint16_t l3size;
|
||||||
|
|
||||||
/* Set up the IPv6 header (most is probably already in place) */
|
/* Set up the IPv6 header (most is probably already in place) */
|
||||||
@@ -105,8 +105,8 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev)
|
|||||||
|
|
||||||
/* Length excludes the IPv6 header */
|
/* Length excludes the IPv6 header */
|
||||||
|
|
||||||
l1size = netdev_dev_l1size(dev);
|
lladdrsize = netdev_dev_lladdrsize(dev);
|
||||||
l3size = SIZEOF_ICMPV6_ROUTER_SOLICIT_S(l1size);
|
l3size = SIZEOF_ICMPV6_ROUTER_SOLICIT_S(lladdrsize);
|
||||||
ipv6->len[0] = (l3size >> 8);
|
ipv6->len[0] = (l3size >> 8);
|
||||||
ipv6->len[1] = (l3size & 0xff);
|
ipv6->len[1] = (l3size & 0xff);
|
||||||
|
|
||||||
@@ -135,14 +135,14 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev)
|
|||||||
|
|
||||||
/* Set up the options */
|
/* Set up the options */
|
||||||
|
|
||||||
sol->opttype = ICMPv6_OPT_SRCLLADDR; /* Option type */
|
sol->opttype = ICMPv6_OPT_SRCLLADDR; /* Option type */
|
||||||
sol->optlen = ICMPv6_OPT_OCTECTS(l1size); /* Option length in octets */
|
sol->optlen = ICMPv6_OPT_OCTECTS(lladdrsize); /* Option length in octets */
|
||||||
|
|
||||||
/* Copy our link layer address into the message
|
/* Copy our link layer address into the message
|
||||||
* REVISIT: What if the link layer is not Ethernet?
|
* REVISIT: What if the link layer is not Ethernet?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
memcpy(sol->srclladdr, &dev->d_mac, l1size);
|
memcpy(sol->srclladdr, &dev->d_mac, lladdrsize);
|
||||||
|
|
||||||
/* Calculate the checksum over both the ICMP header and payload */
|
/* Calculate the checksum over both the ICMP header and payload */
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ void icmpv6_solicit(FAR struct net_driver_s *dev,
|
|||||||
{
|
{
|
||||||
FAR struct ipv6_hdr_s *ipv6;
|
FAR struct ipv6_hdr_s *ipv6;
|
||||||
FAR struct icmpv6_neighbor_solicit_s *sol;
|
FAR struct icmpv6_neighbor_solicit_s *sol;
|
||||||
uint16_t l1size;
|
uint16_t lladdrsize;
|
||||||
uint16_t l3size;
|
uint16_t l3size;
|
||||||
|
|
||||||
/* Set up the IPv6 header (most is probably already in place) */
|
/* Set up the IPv6 header (most is probably already in place) */
|
||||||
@@ -115,8 +115,8 @@ void icmpv6_solicit(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
/* Length excludes the IPv6 header */
|
/* Length excludes the IPv6 header */
|
||||||
|
|
||||||
l1size = netdev_dev_l1size(dev);
|
lladdrsize = netdev_dev_lladdrsize(dev);
|
||||||
l3size = SIZEOF_ICMPV6_NEIGHBOR_SOLICIT_S(l1size);
|
l3size = SIZEOF_ICMPV6_NEIGHBOR_SOLICIT_S(lladdrsize);
|
||||||
ipv6->len[0] = (l3size >> 8);
|
ipv6->len[0] = (l3size >> 8);
|
||||||
ipv6->len[1] = (l3size & 0xff);
|
ipv6->len[1] = (l3size & 0xff);
|
||||||
|
|
||||||
@@ -149,14 +149,14 @@ void icmpv6_solicit(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
/* Set up the options */
|
/* Set up the options */
|
||||||
|
|
||||||
sol->opttype = ICMPv6_OPT_SRCLLADDR; /* Option type */
|
sol->opttype = ICMPv6_OPT_SRCLLADDR; /* Option type */
|
||||||
sol->optlen = ICMPv6_OPT_OCTECTS(l1size); /* Option length in octets */
|
sol->optlen = ICMPv6_OPT_OCTECTS(lladdrsize); /* Option length in octets */
|
||||||
|
|
||||||
/* Copy our link layer address into the message
|
/* Copy our link layer address into the message
|
||||||
* REVISIT: What if the link layer is not Ethernet?
|
* REVISIT: What if the link layer is not Ethernet?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
memcpy(sol->srclladdr, &dev->d_mac, l1size);
|
memcpy(sol->srclladdr, &dev->d_mac, lladdrsize);
|
||||||
|
|
||||||
/* Calculate the checksum over both the ICMP header and payload */
|
/* Calculate the checksum over both the ICMP header and payload */
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ void neighbor_add(FAR net_ipv6addr_t ipaddr, uint8_t lltype,
|
|||||||
#ifdef CONFIG_NET_MULTILINK
|
#ifdef CONFIG_NET_MULTILINK
|
||||||
g_neighbors[oldest_ndx].ne_addr.u.na_lltype = lltype;
|
g_neighbors[oldest_ndx].ne_addr.u.na_lltype = lltype;
|
||||||
#endif
|
#endif
|
||||||
memcpy(&g_neighbors[oldest_ndx].ne_addr.u, addr, netdev_type_l1size(lltype));
|
memcpy(&g_neighbors[oldest_ndx].ne_addr.u, addr, netdev_type_lladdrsize(lltype));
|
||||||
|
|
||||||
/* Dump the contents of the new entry */
|
/* Dump the contents of the new entry */
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ NETDEV_CSRCS += netdev_register.c netdev_ioctl.c netdev_txnotify.c
|
|||||||
NETDEV_CSRCS += netdev_findbyname.c netdev_findbyaddr.c netdev_findbyindex.c
|
NETDEV_CSRCS += netdev_findbyname.c netdev_findbyaddr.c netdev_findbyindex.c
|
||||||
NETDEV_CSRCS += netdev_count.c netdev_foreach.c netdev_unregister.c
|
NETDEV_CSRCS += netdev_count.c netdev_foreach.c netdev_unregister.c
|
||||||
NETDEV_CSRCS += netdev_carrier.c netdev_default.c netdev_verify.c
|
NETDEV_CSRCS += netdev_carrier.c netdev_default.c netdev_verify.c
|
||||||
NETDEV_CSRCS += netdev_l1size.c
|
NETDEV_CSRCS += netdev_lladdrsize.c
|
||||||
|
|
||||||
ifeq ($(CONFIG_NET_RXAVAIL),y)
|
ifeq ($(CONFIG_NET_RXAVAIL),y)
|
||||||
NETDEV_CSRCS += netdev_rxnotify.c
|
NETDEV_CSRCS += netdev_rxnotify.c
|
||||||
|
|||||||
+48
-7
@@ -47,6 +47,31 @@
|
|||||||
|
|
||||||
#include <nuttx/net/ip.h>
|
#include <nuttx/net/ip.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* If there is only one supported link layer, then the size of the link
|
||||||
|
* layer address is a constant.
|
||||||
|
*
|
||||||
|
* NOTE: Literal constants are used here to avoid bringing in all of the
|
||||||
|
* header files where they are correctly defined.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONFIG_NET_MULTILINK
|
||||||
|
# if defined(CONFIG_NET_ETHERNET)
|
||||||
|
# define NETDEV_LLADDRSIZE 6 /* IFHWADDRLEN */
|
||||||
|
# elif defined(CONFIG_NET_6LOWPAN)
|
||||||
|
# ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||||
|
# define NETDEV_LLADDRSIZE 10 /* NET_6LOWPAN_EADDRSIZE */
|
||||||
|
# else
|
||||||
|
# define NETDEV_LLADDRSIZE 2 /* NET_6LOWPAN_SADDRSIZE */
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# define NETDEV_LLADDRSIZE 0 /* No link layer address */
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -438,15 +463,12 @@ int netdev_count(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netdev_dev_l1size and netdev_type_llsize
|
* Name: netdev_type_lladdrsize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Size of the MAC address associated with a device or with a link layer
|
* Returns the size of the MAC address associated with a link layer type.
|
||||||
* type.
|
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* dev - A reference to the device of interest
|
|
||||||
* OR
|
|
||||||
* lltype - link layer type code
|
* lltype - link layer type code
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
@@ -454,8 +476,27 @@ int netdev_count(void);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int netdev_type_l1size(uint8_t lltype);
|
int netdev_type_lladdrsize(uint8_t lltype);
|
||||||
int netdev_dev_l1size(FAR struct net_driver_s *dev);
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netdev_dev_lladdrsize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Returns the size of the MAC address associated with a network device.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* dev - A reference to the device of interest
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The size of the MAC address associated with this device
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_MULTILINK
|
||||||
|
# define netdev_dev_lladdrsize(dev) netdev_type_lladdrsize((dev)->d_lltype)
|
||||||
|
#else
|
||||||
|
# define netdev_dev_lladdrsize(dev) NETDEV_LLADDRSIZE
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* net/netdev/netdev_l1size.c
|
* net/netdev/netdev_lladdrsize.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@@ -54,15 +54,12 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netdev_dev_l1size and netdev_type_llsize
|
* Name: netdev_type_lladdrsize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Size of the MAC address associated with a device or with a link layer
|
* Returns the size of the MAC address associated with a link layer type.
|
||||||
* type.
|
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* dev - A reference to the device of interest
|
|
||||||
* OR
|
|
||||||
* lltype - link layer type code
|
* lltype - link layer type code
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
@@ -70,13 +67,15 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int netdev_type_l1size(uint8_t lltype)
|
int netdev_type_lladdrsize(uint8_t lltype)
|
||||||
{
|
{
|
||||||
/* Get the length of the address for this link layer type */
|
/* Get the length of the address for this link layer type */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_ETHERNET
|
#ifdef CONFIG_NET_ETHERNET
|
||||||
if (lltype == NET_LL_ETHERNET)
|
if (lltype == NET_LL_ETHERNET)
|
||||||
{
|
{
|
||||||
|
/* size of the Ethernet MAC address */
|
||||||
|
|
||||||
return IFHWADDRLEN;
|
return IFHWADDRLEN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -84,6 +83,10 @@ int netdev_type_l1size(uint8_t lltype)
|
|||||||
#ifdef CONFIG_NET_6LOWPAN
|
#ifdef CONFIG_NET_6LOWPAN
|
||||||
if (lltype == NET_LL_IEEE802154)
|
if (lltype == NET_LL_IEEE802154)
|
||||||
{
|
{
|
||||||
|
/* 6LoWPAN can be configured to use either extended or short
|
||||||
|
* addressing.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
||||||
return NET_6LOWPAN_EADDRSIZE;
|
return NET_6LOWPAN_EADDRSIZE;
|
||||||
#else
|
#else
|
||||||
@@ -93,25 +96,10 @@ int netdev_type_l1size(uint8_t lltype)
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
/* Either the link layer type associated with lltype has no address,
|
||||||
|
* or support for that link layer type is not enabled.
|
||||||
|
*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int netdev_dev_l1size(FAR struct net_driver_s *dev)
|
|
||||||
{
|
|
||||||
/* Get the length of the address for this device */
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_MULTILINK)
|
|
||||||
return netdev_type_l1size(dev->d_lltype);
|
|
||||||
#elif defined(CONFIG_NET_ETHERNET)
|
|
||||||
return IFHWADDRLEN;
|
|
||||||
#elif defined(CONFIG_NET_6LOWPAN)
|
|
||||||
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
||||||
return NET_6LOWPAN_EADDRSIZE;
|
|
||||||
#else
|
|
||||||
return NET_6LOWPAN_SADDRSIZE;
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user