6
6
#include "lwip/stats.h"
7
7
#include "lwip/snmp.h"
8
8
#include "lwip/tcpip.h"
9
+ #include "lwip/ethip6.h"
10
+ #include "lwip/igmp.h"
11
+ #include "lwip/mld6.h"
9
12
#include "netif/etharp.h"
10
- #include "netif/ppp_oe .h"
13
+ #include "netif/ppp/pppoe .h"
11
14
12
15
#include "eth_arch.h"
13
16
#include "sys_arch.h"
@@ -236,22 +239,114 @@ static err_t low_level_init(struct netif *netif)
236
239
237
240
238
241
/**
239
- * This function is the ethernet packet send function. It calls
242
+ * This function is the ipv4 ethernet packet send function. It calls
240
243
* etharp_output after checking link status.
241
244
*
242
245
* \param[in] netif the lwip network interface structure for this enetif
243
246
* \param[in] q Pointer to pbug to send
244
247
* \param[in] ipaddr IP address
245
248
* \return ERR_OK or error code
246
249
*/
247
- err_t k64f_etharp_output (struct netif * netif , struct pbuf * q , ip_addr_t * ipaddr )
250
+ #if LWIP_IPV4
251
+ err_t k64f_etharp_output_ipv4 (struct netif * netif , struct pbuf * q , const ip4_addr_t * ipaddr )
248
252
{
249
253
/* Only send packet is link is up */
250
- if (netif -> flags & NETIF_FLAG_LINK_UP )
254
+ if (netif -> flags & NETIF_FLAG_LINK_UP ) {
251
255
return etharp_output (netif , q , ipaddr );
256
+ }
257
+
258
+ return ERR_CONN ;
259
+ }
260
+ #endif
261
+
262
+ /**
263
+ * This function is the ipv6 ethernet packet send function. It calls
264
+ * ethip6_output after checking link status.
265
+ *
266
+ * \param[in] netif the lwip network interface structure for this enetif
267
+ * \param[in] q Pointer to pbug to send
268
+ * \param[in] ipaddr IP address
269
+ * \return ERR_OK or error code
270
+ */
271
+ #if LWIP_IPV6
272
+ err_t k64f_etharp_output_ipv6 (struct netif * netif , struct pbuf * q , const ip6_addr_t * ipaddr )
273
+ {
274
+ /* Only send packet is link is up */
275
+ if (netif -> flags & NETIF_FLAG_LINK_UP ) {
276
+ return ethip6_output (netif , q , ipaddr );
277
+ }
252
278
253
279
return ERR_CONN ;
254
280
}
281
+ #endif
282
+
283
+ #if LWIP_IGMP
284
+ /**
285
+ * IPv4 address filtering setup.
286
+ *
287
+ * \param[in] netif the lwip network interface structure for this enetif
288
+ * \param[in] group IPv4 group to modify
289
+ * \param[in] action
290
+ * \return ERR_OK or error code
291
+ */
292
+ err_t igmp_mac_filter (struct netif * netif , const ip4_addr_t * group , u8_t action )
293
+ {
294
+ switch (action ) {
295
+ case IGMP_ADD_MAC_FILTER :
296
+ {
297
+ uint32_t group23 = ntohl (group -> addr ) & 0x007FFFFF ;
298
+ uint8_t addr [6 ];
299
+ addr [0 ] = LL_IP4_MULTICAST_ADDR_0 ;
300
+ addr [1 ] = LL_IP4_MULTICAST_ADDR_1 ;
301
+ addr [2 ] = LL_IP4_MULTICAST_ADDR_2 ;
302
+ addr [3 ] = group23 >> 16 ;
303
+ addr [4 ] = group23 >> 8 ;
304
+ addr [5 ] = group23 ;
305
+ ENET_AddMulticastGroup (ENET , addr );
306
+ return ERR_OK ;
307
+ }
308
+ case IGMP_DEL_MAC_FILTER :
309
+ /* As we don't reference count, silently ignore delete requests */
310
+ return ERR_OK ;
311
+ default :
312
+ return ERR_ARG ;
313
+ }
314
+ }
315
+ #endif
316
+
317
+ #if LWIP_IPV6_MLD
318
+ /**
319
+ * IPv6 address filtering setup.
320
+ *
321
+ * \param[in] netif the lwip network interface structure for this enetif
322
+ * \param[in] group IPv6 group to modify
323
+ * \param[in] action
324
+ * \return ERR_OK or error code
325
+ */
326
+ err_t mld_mac_filter (struct netif * netif , const ip6_addr_t * group , u8_t action )
327
+ {
328
+ switch (action ) {
329
+ case MLD6_ADD_MAC_FILTER :
330
+ {
331
+ uint32_t group32 = ntohl (group -> addr [3 ]);
332
+ uint8_t addr [6 ];
333
+ addr [0 ] = LL_IP6_MULTICAST_ADDR_0 ;
334
+ addr [1 ] = LL_IP6_MULTICAST_ADDR_1 ;
335
+ addr [2 ] = group32 >> 24 ;
336
+ addr [3 ] = group32 >> 16 ;
337
+ addr [4 ] = group32 >> 8 ;
338
+ addr [5 ] = group32 ;
339
+ ENET_AddMulticastGroup (ENET , addr );
340
+ return ERR_OK ;
341
+ }
342
+ case MLD6_DEL_MAC_FILTER :
343
+ /* As we don't reference count, silently ignore delete requests */
344
+ return ERR_OK ;
345
+ default :
346
+ return ERR_ARG ;
347
+ }
348
+ }
349
+ #endif
255
350
256
351
/** \brief Allocates a pbuf and returns the data from the incoming packet.
257
352
*
@@ -322,7 +417,7 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
322
417
323
418
update_read_buffer (rx_buff [idx ]-> payload );
324
419
LWIP_DEBUGF (UDP_LPC_EMAC | LWIP_DBG_TRACE ,
325
- ("k64f_low_level_input: Packet received: %p, size %d (index=%d)\n" ,
420
+ ("k64f_low_level_input: Packet received: %p, size %" PRIu32 " (index=%d)\n" ,
326
421
p , length , idx ));
327
422
328
423
/* Save size */
@@ -344,36 +439,18 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
344
439
*/
345
440
void k64f_enetif_input (struct netif * netif , int idx )
346
441
{
347
- struct eth_hdr * ethhdr ;
348
442
struct pbuf * p ;
349
443
350
444
/* move received packet into a new pbuf */
351
445
p = k64f_low_level_input (netif , idx );
352
446
if (p == NULL )
353
447
return ;
354
448
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 */
449
+ /* pass all packets to ethernet_input, which decides what packets it supports */
450
+ if (netif -> input (p , netif ) != ERR_OK ) {
451
+ LWIP_DEBUGF (NETIF_DEBUG , ("k64f_enetif_input: input error\n" ));
452
+ /* Free buffer */
375
453
pbuf_free (p );
376
- break ;
377
454
}
378
455
}
379
456
@@ -432,7 +509,6 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
432
509
struct pbuf * temp_pbuf ;
433
510
uint8_t * psend = NULL , * dst ;
434
511
435
-
436
512
temp_pbuf = pbuf_alloc (PBUF_RAW , p -> tot_len + ENET_BUFF_ALIGNMENT , PBUF_RAM );
437
513
if (NULL == temp_pbuf )
438
514
return ERR_MEM ;
@@ -569,14 +645,16 @@ err_t eth_arch_enetif_init(struct netif *netif)
569
645
#else
570
646
mbed_mac_address ((char * )netif -> hwaddr );
571
647
#endif
572
- netif -> hwaddr_len = ETHARP_HWADDR_LEN ;
648
+
649
+ /* Ethernet address length */
650
+ netif -> hwaddr_len = ETH_HWADDR_LEN ;
573
651
574
652
/* maximum transfer unit */
575
653
netif -> mtu = 1500 ;
576
654
577
655
/* device capabilities */
578
656
// TODOETH: check if the flags are correct below
579
- netif -> flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP ;
657
+ netif -> flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET ;
580
658
581
659
/* Initialize the hardware */
582
660
netif -> state = & k64f_enetdata ;
@@ -592,7 +670,23 @@ err_t eth_arch_enetif_init(struct netif *netif)
592
670
netif -> name [0 ] = 'e' ;
593
671
netif -> name [1 ] = 'n' ;
594
672
595
- netif -> output = k64f_etharp_output ;
673
+ #if LWIP_IPV4
674
+ netif -> output = k64f_etharp_output_ipv4 ;
675
+ #if LWIP_IGMP
676
+ netif -> igmp_mac_filter = igmp_mac_filter ;
677
+ netif -> flags |= NETIF_FLAG_IGMP ;
678
+ #endif
679
+ #endif
680
+ #if LWIP_IPV6
681
+ netif -> output_ip6 = k64f_etharp_output_ipv6 ;
682
+ #if LWIP_IPV6_MLD
683
+ netif -> mld_mac_filter = mld_mac_filter ;
684
+ netif -> flags |= NETIF_FLAG_MLD6 ;
685
+ #else
686
+ // Would need to enable all multicasts here - no API in fsl_enet to do that
687
+ #error "IPv6 multicasts won't be received if LWIP_IPV6_MLD is disabled, breaking the system"
688
+ #endif
689
+ #endif
596
690
netif -> linkoutput = k64f_low_level_output ;
597
691
598
692
/* CMSIS-RTOS, start tasks */
@@ -610,7 +704,12 @@ err_t eth_arch_enetif_init(struct netif *netif)
610
704
/* Packet receive task */
611
705
err = sys_sem_new (& k64f_enetdata .RxReadySem , 0 );
612
706
LWIP_ASSERT ("RxReadySem creation error" , (err == ERR_OK ));
707
+
708
+ #ifdef LWIP_DEBUG
709
+ sys_thread_new ("receive_thread" , packet_rx , netif -> state , DEFAULT_THREAD_STACKSIZE * 5 , RX_PRIORITY );
710
+ #else
613
711
sys_thread_new ("receive_thread" , packet_rx , netif -> state , DEFAULT_THREAD_STACKSIZE , RX_PRIORITY );
712
+ #endif
614
713
615
714
/* Transmit cleanup task */
616
715
err = sys_sem_new (& k64f_enetdata .TxCleanSem , 0 );
0 commit comments