6
6
#include "lwip/stats.h"
7
7
#include "lwip/snmp.h"
8
8
#include "lwip/tcpip.h"
9
+ #include "lwip/ethip6.h"
9
10
#include "netif/etharp.h"
10
- #include "netif/ppp_oe .h"
11
+ #include "netif/ppp/pppoe .h"
11
12
12
13
#include "eth_arch.h"
13
14
#include "sys_arch.h"
@@ -236,22 +237,114 @@ static err_t low_level_init(struct netif *netif)
236
237
237
238
238
239
/**
239
- * This function is the ethernet packet send function. It calls
240
+ * This function is the ipv4 ethernet packet send function. It calls
240
241
* etharp_output after checking link status.
241
242
*
242
243
* \param[in] netif the lwip network interface structure for this enetif
243
244
* \param[in] q Pointer to pbug to send
244
245
* \param[in] ipaddr IP address
245
246
* \return ERR_OK or error code
246
247
*/
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 )
248
250
{
249
251
/* Only send packet is link is up */
250
- if (netif -> flags & NETIF_FLAG_LINK_UP )
252
+ if (netif -> flags & NETIF_FLAG_LINK_UP ) {
251
253
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
+ }
252
276
253
277
return ERR_CONN ;
254
278
}
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
255
348
256
349
/** \brief Allocates a pbuf and returns the data from the incoming packet.
257
350
*
@@ -322,7 +415,7 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
322
415
323
416
update_read_buffer (rx_buff [idx ]-> payload );
324
417
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" ,
326
419
p , length , idx ));
327
420
328
421
/* Save size */
@@ -344,36 +437,18 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
344
437
*/
345
438
void k64f_enetif_input (struct netif * netif , int idx )
346
439
{
347
- struct eth_hdr * ethhdr ;
348
440
struct pbuf * p ;
349
441
350
442
/* move received packet into a new pbuf */
351
443
p = k64f_low_level_input (netif , idx );
352
444
if (p == NULL )
353
445
return ;
354
446
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 */
375
451
pbuf_free (p );
376
- break ;
377
452
}
378
453
}
379
454
@@ -432,7 +507,6 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
432
507
struct pbuf * temp_pbuf ;
433
508
uint8_t * psend = NULL , * dst ;
434
509
435
-
436
510
temp_pbuf = pbuf_alloc (PBUF_RAW , p -> tot_len + ENET_BUFF_ALIGNMENT , PBUF_RAM );
437
511
if (NULL == temp_pbuf )
438
512
return ERR_MEM ;
@@ -569,14 +643,16 @@ err_t eth_arch_enetif_init(struct netif *netif)
569
643
#else
570
644
mbed_mac_address ((char * )netif -> hwaddr );
571
645
#endif
572
- netif -> hwaddr_len = ETHARP_HWADDR_LEN ;
646
+
647
+ /* Ethernet address length */
648
+ netif -> hwaddr_len = ETH_HWADDR_LEN ;
573
649
574
650
/* maximum transfer unit */
575
651
netif -> mtu = 1500 ;
576
652
577
653
/* device capabilities */
578
654
// 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 ;
580
656
581
657
/* Initialize the hardware */
582
658
netif -> state = & k64f_enetdata ;
@@ -592,7 +668,23 @@ err_t eth_arch_enetif_init(struct netif *netif)
592
668
netif -> name [0 ] = 'e' ;
593
669
netif -> name [1 ] = 'n' ;
594
670
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
596
688
netif -> linkoutput = k64f_low_level_output ;
597
689
598
690
/* CMSIS-RTOS, start tasks */
@@ -610,7 +702,12 @@ err_t eth_arch_enetif_init(struct netif *netif)
610
702
/* Packet receive task */
611
703
err = sys_sem_new (& k64f_enetdata .RxReadySem , 0 );
612
704
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
613
709
sys_thread_new ("receive_thread" , packet_rx , netif -> state , DEFAULT_THREAD_STACKSIZE , RX_PRIORITY );
710
+ #endif
614
711
615
712
/* Transmit cleanup task */
616
713
err = sys_sem_new (& k64f_enetdata .TxCleanSem , 0 );
0 commit comments