Skip to content

Commit 1d2130f

Browse files
author
Mika Leppänen
committed
Updated STM mac for lwip 2.0 and IPv6.
1 parent a349c11 commit 1d2130f

File tree

1 file changed

+45
-8
lines changed
  • features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_STM

1 file changed

+45
-8
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_STM/stm32xx_emac.c

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "lwip/opt.h"
22

3-
#include "lwip/timers.h"
43
#include "netif/etharp.h"
54
#include "lwip/tcpip.h"
5+
#include "lwip/ethip6.h"
66
#include <string.h>
77
#include "cmsis_os.h"
88
#include "mbed_interface.h"
@@ -40,7 +40,14 @@ static sys_mutex_t tx_lock_mutex;
4040
/* function */
4141
static void _eth_arch_rx_task(void *arg);
4242
static void _eth_arch_phy_task(void *arg);
43-
static err_t _eth_arch_netif_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr);
43+
44+
#if LWIP_IPV4
45+
static err_t _eth_arch_netif_output_ipv4(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr);
46+
#endif
47+
#if LWIP_IPV6
48+
static err_t _eth_arch_netif_output_ipv6(struct netif *netif, struct pbuf *q, const ip6_addr_t *ipaddr);
49+
#endif
50+
4451
static err_t _eth_arch_low_level_output(struct netif *netif, struct pbuf *p);
4552
static struct pbuf * _eth_arch_low_level_input(struct netif *netif);
4653

@@ -112,7 +119,7 @@ static void _eth_arch_low_level_init(struct netif *netif)
112119

113120
#if LWIP_ARP || LWIP_ETHERNET
114121
/* set MAC hardware address length */
115-
netif->hwaddr_len = ETHARP_HWADDR_LEN;
122+
netif->hwaddr_len = ETH_HWADDR_LEN;
116123

117124
/* set MAC hardware address */
118125
netif->hwaddr[0] = EthHandle.Init.MACAddr[0];
@@ -356,22 +363,44 @@ static void _eth_arch_phy_task(void *arg)
356363
}
357364

358365
/**
359-
* This function is the ethernet packet send function. It calls
366+
* This function is the ethernet IPv4 packet send function. It calls
360367
* etharp_output after checking link status.
361368
*
362369
* \param[in] netif the lwip network interface structure for this lpc_enetif
363370
* \param[in] q Pointer to pbug to send
364371
* \param[in] ipaddr IP address
365372
* \return ERR_OK or error code
366373
*/
367-
static err_t _eth_arch_netif_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
374+
#if LWIP_IPV4
375+
static err_t _eth_arch_netif_output_ipv4(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
368376
{
369377
/* Only send packet is link is up */
370378
if (netif->flags & NETIF_FLAG_LINK_UP) {
371379
return etharp_output(netif, q, ipaddr);
372380
}
373381
return ERR_CONN;
374382
}
383+
#endif
384+
385+
/**
386+
* This function is the ethernet packet send function. It calls
387+
* etharp_output after checking link status.
388+
*
389+
* \param[in] netif the lwip network IPv6 interface structure for this lpc_enetif
390+
* \param[in] q Pointer to pbug to send
391+
* \param[in] ipaddr IP address
392+
* \return ERR_OK or error code
393+
*/
394+
#if LWIP_IPV6
395+
static err_t _eth_arch_netif_output_ipv6(struct netif *netif, struct pbuf *q, const ip6_addr_t *ipaddr)
396+
{
397+
/* Only send packet is link is up */
398+
if (netif->flags & NETIF_FLAG_LINK_UP) {
399+
return ethip6_output(netif, q, ipaddr);
400+
}
401+
return ERR_CONN;
402+
}
403+
#endif
375404

376405
/**
377406
* Should be called at the beginning of the program to set up the
@@ -387,13 +416,13 @@ static err_t _eth_arch_netif_output(struct netif *netif, struct pbuf *q, ip_addr
387416
err_t eth_arch_enetif_init(struct netif *netif)
388417
{
389418
/* set MAC hardware address */
390-
netif->hwaddr_len = ETHARP_HWADDR_LEN;
419+
netif->hwaddr_len = ETH_HWADDR_LEN;
391420

392421
/* maximum transfer unit */
393422
netif->mtu = 1500;
394423

395424
/* device capabilities */
396-
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
425+
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET;
397426

398427
#if LWIP_NETIF_HOSTNAME
399428
/* Initialize interface hostname */
@@ -403,7 +432,15 @@ err_t eth_arch_enetif_init(struct netif *netif)
403432
netif->name[0] = 'e';
404433
netif->name[1] = 'n';
405434

406-
netif->output = _eth_arch_netif_output;
435+
#if LWIP_IPV4
436+
netif->output = _eth_arch_netif_output_ipv4;
437+
netif->flags |= NETIF_FLAG_IGMP;
438+
#endif
439+
#if LWIP_IPV6
440+
netif->output_ip6 = _eth_arch_netif_output_ipv6;
441+
netif->flags |= NETIF_FLAG_MLD6;
442+
#endif
443+
407444
netif->linkoutput = _eth_arch_low_level_output;
408445

409446
/* semaphore */

0 commit comments

Comments
 (0)