Skip to content

Commit 2f9c5e9

Browse files
author
Mika Leppänen
committed
Updated K64F mac for lwip 2.0 and IPv6
1 parent 98c452d commit 2f9c5e9

File tree

1 file changed

+128
-31
lines changed
  • features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_Freescale

1 file changed

+128
-31
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c

Lines changed: 128 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "lwip/stats.h"
77
#include "lwip/snmp.h"
88
#include "lwip/tcpip.h"
9+
#include "lwip/ethip6.h"
910
#include "netif/etharp.h"
10-
#include "netif/ppp_oe.h"
11+
#include "netif/ppp/pppoe.h"
1112

1213
#include "eth_arch.h"
1314
#include "sys_arch.h"
@@ -236,22 +237,114 @@ static err_t low_level_init(struct netif *netif)
236237

237238

238239
/**
239-
* This function is the ethernet packet send function. It calls
240+
* This function is the ipv4 ethernet packet send function. It calls
240241
* etharp_output after checking link status.
241242
*
242243
* \param[in] netif the lwip network interface structure for this enetif
243244
* \param[in] q Pointer to pbug to send
244245
* \param[in] ipaddr IP address
245246
* \return ERR_OK or error code
246247
*/
247-
err_t k64f_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
248+
#if LWIP_IPV4
249+
err_t k64f_etharp_output_ipv4(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
248250
{
249251
/* Only send packet is link is up */
250-
if (netif->flags & NETIF_FLAG_LINK_UP)
252+
if (netif->flags & NETIF_FLAG_LINK_UP) {
251253
return etharp_output(netif, q, ipaddr);
254+
}
255+
256+
return ERR_CONN;
257+
}
258+
#endif
259+
260+
/**
261+
* This function is the ipv6 ethernet packet send function. It calls
262+
* ethip6_output after checking link status.
263+
*
264+
* \param[in] netif the lwip network interface structure for this enetif
265+
* \param[in] q Pointer to pbug to send
266+
* \param[in] ipaddr IP address
267+
* \return ERR_OK or error code
268+
*/
269+
#if LWIP_IPV6
270+
err_t k64f_etharp_output_ipv6(struct netif *netif, struct pbuf *q, const ip6_addr_t *ipaddr)
271+
{
272+
/* Only send packet is link is up */
273+
if (netif->flags & NETIF_FLAG_LINK_UP) {
274+
return ethip6_output(netif, q, ipaddr);
275+
}
252276

253277
return ERR_CONN;
254278
}
279+
#endif
280+
281+
#if LWIP_IGMP
282+
/**
283+
* IPv4 address filtering setup.
284+
*
285+
* \param[in] netif the lwip network interface structure for this enetif
286+
* \param[in] group IPv4 group to modify
287+
* \param[in] action
288+
* \return ERR_OK or error code
289+
*/
290+
err_t igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, enum netif_mac_filter_action action)
291+
{
292+
switch (action) {
293+
case NETIF_ADD_MAC_FILTER:
294+
{
295+
uint32_t group23 = ntohl(group->addr) & 0x007FFFFF;
296+
uint8_t addr[6];
297+
addr[0] = LL_IP4_MULTICAST_ADDR_0;
298+
addr[1] = LL_IP4_MULTICAST_ADDR_1;
299+
addr[2] = LL_IP4_MULTICAST_ADDR_2;
300+
addr[3] = group23 >> 16;
301+
addr[4] = group23 >> 8;
302+
addr[5] = group23;
303+
ENET_AddMulticastGroup(ENET, addr);
304+
return ERR_OK;
305+
}
306+
case NETIF_DEL_MAC_FILTER:
307+
/* As we don't reference count, silently ignore delete requests */
308+
return ERR_OK;
309+
default:
310+
return ERR_ARG;
311+
}
312+
}
313+
#endif
314+
315+
#if LWIP_IPV6_MLD
316+
/**
317+
* IPv6 address filtering setup.
318+
*
319+
* \param[in] netif the lwip network interface structure for this enetif
320+
* \param[in] group IPv6 group to modify
321+
* \param[in] action
322+
* \return ERR_OK or error code
323+
*/
324+
err_t mld_mac_filter(struct netif *netif, const ip6_addr_t *group, enum netif_mac_filter_action action)
325+
{
326+
switch (action) {
327+
case NETIF_ADD_MAC_FILTER:
328+
{
329+
uint32_t group32 = ntohl(group->addr[3]);
330+
uint8_t addr[6];
331+
addr[0] = LL_IP6_MULTICAST_ADDR_0;
332+
addr[1] = LL_IP6_MULTICAST_ADDR_1;
333+
addr[2] = group32 >> 24;
334+
addr[3] = group32 >> 16;
335+
addr[4] = group32 >> 8;
336+
addr[5] = group32;
337+
ENET_AddMulticastGroup(ENET, addr);
338+
return ERR_OK;
339+
}
340+
case NETIF_DEL_MAC_FILTER:
341+
/* As we don't reference count, silently ignore delete requests */
342+
return ERR_OK;
343+
default:
344+
return ERR_ARG;
345+
}
346+
}
347+
#endif
255348

256349
/** \brief Allocates a pbuf and returns the data from the incoming packet.
257350
*
@@ -322,7 +415,7 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
322415

323416
update_read_buffer(rx_buff[idx]->payload);
324417
LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
325-
("k64f_low_level_input: Packet received: %p, size %d (index=%d)\n",
418+
("k64f_low_level_input: Packet received: %p, size %"PRIu32" (index=%d)\n",
326419
p, length, idx));
327420

328421
/* Save size */
@@ -344,36 +437,18 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
344437
*/
345438
void k64f_enetif_input(struct netif *netif, int idx)
346439
{
347-
struct eth_hdr *ethhdr;
348440
struct pbuf *p;
349441

350442
/* move received packet into a new pbuf */
351443
p = k64f_low_level_input(netif, idx);
352444
if (p == NULL)
353445
return;
354446

355-
/* points to packet payload, which starts with an Ethernet header */
356-
ethhdr = (struct eth_hdr*)p->payload;
357-
358-
switch (htons(ethhdr->type)) {
359-
case ETHTYPE_IP:
360-
case ETHTYPE_ARP:
361-
#if PPPOE_SUPPORT
362-
case ETHTYPE_PPPOEDISC:
363-
case ETHTYPE_PPPOE:
364-
#endif /* PPPOE_SUPPORT */
365-
/* full packet send to tcpip_thread to process */
366-
if (netif->input(p, netif) != ERR_OK) {
367-
LWIP_DEBUGF(NETIF_DEBUG, ("k64f_enetif_input: IP input error\n"));
368-
/* Free buffer */
369-
pbuf_free(p);
370-
}
371-
break;
372-
373-
default:
374-
/* Return buffer */
447+
/* pass all packets to ethernet_input, which decides what packets it supports */
448+
if (netif->input(p, netif) != ERR_OK) {
449+
LWIP_DEBUGF(NETIF_DEBUG, ("k64f_enetif_input: input error\n"));
450+
/* Free buffer */
375451
pbuf_free(p);
376-
break;
377452
}
378453
}
379454

@@ -432,7 +507,6 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
432507
struct pbuf *temp_pbuf;
433508
uint8_t *psend = NULL, *dst;
434509

435-
436510
temp_pbuf = pbuf_alloc(PBUF_RAW, p->tot_len + ENET_BUFF_ALIGNMENT, PBUF_RAM);
437511
if (NULL == temp_pbuf)
438512
return ERR_MEM;
@@ -569,14 +643,16 @@ err_t eth_arch_enetif_init(struct netif *netif)
569643
#else
570644
mbed_mac_address((char *)netif->hwaddr);
571645
#endif
572-
netif->hwaddr_len = ETHARP_HWADDR_LEN;
646+
647+
/* Ethernet address length */
648+
netif->hwaddr_len = ETH_HWADDR_LEN;
573649

574650
/* maximum transfer unit */
575651
netif->mtu = 1500;
576652

577653
/* device capabilities */
578654
// TODOETH: check if the flags are correct below
579-
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
655+
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET;
580656

581657
/* Initialize the hardware */
582658
netif->state = &k64f_enetdata;
@@ -592,7 +668,23 @@ err_t eth_arch_enetif_init(struct netif *netif)
592668
netif->name[0] = 'e';
593669
netif->name[1] = 'n';
594670

595-
netif->output = k64f_etharp_output;
671+
#if LWIP_IPV4
672+
netif->output = k64f_etharp_output_ipv4;
673+
#if LWIP_IGMP
674+
netif->igmp_mac_filter = igmp_mac_filter;
675+
netif->flags |= NETIF_FLAG_IGMP;
676+
#endif
677+
#endif
678+
#if LWIP_IPV6
679+
netif->output_ip6 = k64f_etharp_output_ipv6;
680+
#if LWIP_IPV6_MLD
681+
netif->mld_mac_filter = mld_mac_filter;
682+
netif->flags |= NETIF_FLAG_MLD6;
683+
#else
684+
// Would need to enable all multicasts here - no API in fsl_enet to do that
685+
#error "IPv6 multicasts won't be received if LWIP_IPV6_MLD is disabled, breaking the system"
686+
#endif
687+
#endif
596688
netif->linkoutput = k64f_low_level_output;
597689

598690
/* CMSIS-RTOS, start tasks */
@@ -610,7 +702,12 @@ err_t eth_arch_enetif_init(struct netif *netif)
610702
/* Packet receive task */
611703
err = sys_sem_new(&k64f_enetdata.RxReadySem, 0);
612704
LWIP_ASSERT("RxReadySem creation error", (err == ERR_OK));
705+
706+
#ifdef LWIP_DEBUG
707+
sys_thread_new("receive_thread", packet_rx, netif->state, DEFAULT_THREAD_STACKSIZE*5, RX_PRIORITY);
708+
#else
613709
sys_thread_new("receive_thread", packet_rx, netif->state, DEFAULT_THREAD_STACKSIZE, RX_PRIORITY);
710+
#endif
614711

615712
/* Transmit cleanup task */
616713
err = sys_sem_new(&k64f_enetdata.TxCleanSem, 0);

0 commit comments

Comments
 (0)