summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-21 15:04:39 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-21 15:04:39 -0600
commitf304e6d9f59548e4fbc483dda5793045ada5fac1 (patch)
treec91bb833173e7978eeccb1d0421f2da15bfc4611
parent81c1d19567e22a715fc0e2f6009f58f5f460f88a (diff)
downloadpx4-nuttx-f304e6d9f59548e4fbc483dda5793045ada5fac1.tar.gz
px4-nuttx-f304e6d9f59548e4fbc483dda5793045ada5fac1.tar.bz2
px4-nuttx-f304e6d9f59548e4fbc483dda5793045ada5fac1.zip
STM32 Ethernet: Port IPv6 address filtering from the Tiva TM4C driver
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_eth.c71
1 files changed, 68 insertions, 3 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_eth.c b/nuttx/arch/arm/src/stm32/stm32_eth.c
index 4dc1c8105..7b451020f 100644
--- a/nuttx/arch/arm/src/stm32/stm32_eth.c
+++ b/nuttx/arch/arm/src/stm32/stm32_eth.c
@@ -654,8 +654,10 @@ static void stm32_txtimeout(int argc, uint32_t arg, ...);
static int stm32_ifup(struct net_driver_s *dev);
static int stm32_ifdown(struct net_driver_s *dev);
static int stm32_txavail(struct net_driver_s *dev);
-#ifdef CONFIG_NET_IGMP
+#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6)
static int stm32_addmac(struct net_driver_s *dev, FAR const uint8_t *mac);
+#endif
+#ifdef CONFIG_NET_IGMP
static int stm32_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac);
#endif
#ifdef CONFIG_NETDEV_PHY_IOCTL
@@ -691,6 +693,9 @@ static inline void stm32_ethgpioconfig(FAR struct stm32_ethmac_s *priv);
static void stm32_ethreset(FAR struct stm32_ethmac_s *priv);
static int stm32_macconfig(FAR struct stm32_ethmac_s *priv);
static void stm32_macaddress(FAR struct stm32_ethmac_s *priv);
+#ifdef CONFIG_NET_ICMPv6
+static void stm32_ipv6multicast(FAR struct stm32_ethmac_s *priv);
+#endif
static int stm32_macenable(FAR struct stm32_ethmac_s *priv);
static int stm32_ethconfig(FAR struct stm32_ethmac_s *priv);
@@ -2303,7 +2308,7 @@ static uint32_t stm32_calcethcrc(const uint8_t *data, size_t length)
*
****************************************************************************/
-#ifdef CONFIG_NET_IGMP
+#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6)
static int stm32_addmac(struct net_driver_s *dev, FAR const uint8_t *mac)
{
uint32_t crc;
@@ -2340,7 +2345,7 @@ static int stm32_addmac(struct net_driver_s *dev, FAR const uint8_t *mac)
return OK;
}
-#endif
+#endif /* CONFIG_NET_IGMP || CONFIG_NET_ICMPv6 */
/****************************************************************************
* Function: stm32_rmmac
@@ -3472,6 +3477,60 @@ static void stm32_macaddress(FAR struct stm32_ethmac_s *priv)
}
/****************************************************************************
+ * Function: stm32_ipv6multicast
+ *
+ * Description:
+ * Configure the IPv6 multicast MAC address.
+ *
+ * Parameters:
+ * priv - A reference to the private driver state structure
+ *
+ * Returned Value:
+ * OK on success; Negated errno on failure.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_ICMPv6
+static void stm32_ipv6multicast(FAR struct stm32_ethmac_s *priv)
+{
+ struct net_driver_s *dev;
+ uint16_t tmp16;
+ uint8_t mac[6];
+
+ /* For ICMPv6, we need to add the IPv6 multicast address
+ *
+ * For IPv6 multicast addresses, the Ethernet MAC is derived by
+ * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00,
+ * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map
+ * to the Ethernet MAC address 33:33:00:01:00:03.
+ *
+ * NOTES: This appears correct for the ICMPv6 Router Solicitation
+ * Message, but the ICMPv6 Neighbor Solicitation message seems to
+ * use 33:33:ff:01:00:03.
+ */
+
+ mac[0] = 0x33;
+ mac[1] = 0x33;
+
+ dev = &priv->dev;
+ tmp16 = dev->d_ipv6addr[6];
+ mac[2] = 0xff;
+ mac[3] = tmp16 >> 8;
+
+ tmp16 = dev->d_ipv6addr[7];
+ mac[4] = tmp16 & 0xff;
+ mac[5] = tmp16 >> 8;
+
+ nvdbg("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+
+ (void)stm32_addmac(dev, mac);
+}
+#endif /* CONFIG_NET_ICMPv6 */
+
+/****************************************************************************
* Function: stm32_macenable
*
* Description:
@@ -3495,6 +3554,12 @@ static int stm32_macenable(FAR struct stm32_ethmac_s *priv)
stm32_macaddress(priv);
+#ifdef CONFIG_NET_ICMPv6
+ /* Set up the IPv6 multicast address */
+
+ stm32_ipv6multicast(priv);
+#endif
+
/* Enable transmit state machine of the MAC for transmission on the MII */
regval = stm32_getreg(STM32_ETH_MACCR);