Skip to content

Commit 3d1531f

Browse files
authored
Merge pull request #2767 from mikaleppanen/lwip_2_0
Replace lwIP 1.4.1 with lwIP 2.0
2 parents 3f9a04c + e5c291d commit 3d1531f

File tree

329 files changed

+93576
-36198
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+93576
-36198
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
lwip/doc/*
2+
lwip/test/*
3+
lwip/src/apps/*
4+
lwip/src/netif/ppp/*
5+
lwip/src/netif/lwip_slipif.c
6+
lwip/src/include/lwip/apps/*
7+
lwip/src/include/posix/*

features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,29 @@ const char *EthernetInterface::get_mac_address()
5959

6060
const char *EthernetInterface::get_ip_address()
6161
{
62-
return lwip_get_ip_address();
62+
if (lwip_get_ip_address(_ip_address, sizeof _ip_address)) {
63+
return _ip_address;
64+
}
65+
66+
return 0;
6367
}
6468

6569
const char *EthernetInterface::get_netmask()
6670
{
67-
return lwip_get_netmask();
71+
if (lwip_get_netmask(_netmask, sizeof _netmask)) {
72+
return _netmask;
73+
}
74+
75+
return 0;
6876
}
6977

7078
const char *EthernetInterface::get_gateway()
7179
{
72-
return lwip_get_gateway();
80+
if (lwip_get_gateway(_gateway, sizeof _gateway)) {
81+
return _gateway;
82+
}
83+
84+
return 0;
7385
}
7486

7587
NetworkStack *EthernetInterface::get_stack()

features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class EthernetInterface : public EthInterface
9292
*/
9393
virtual const char *get_netmask();
9494

95-
/** Get the local gateway
95+
/** Get the local gateways
9696
*
9797
* @return Null-terminated representation of the local gateway
9898
* or null if no network mask has been recieved
@@ -107,7 +107,7 @@ class EthernetInterface : public EthInterface
107107
virtual NetworkStack *get_stack();
108108

109109
bool _dhcp;
110-
char _ip_address[NSAPI_IPv4_SIZE];
110+
char _ip_address[IPADDR_STRLEN_MAX];
111111
char _netmask[NSAPI_IPv4_SIZE];
112112
char _gateway[NSAPI_IPv4_SIZE];
113113
};

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

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

1215
#include "eth_arch.h"
1316
#include "sys_arch.h"
@@ -236,22 +239,114 @@ static err_t low_level_init(struct netif *netif)
236239

237240

238241
/**
239-
* This function is the ethernet packet send function. It calls
242+
* This function is the ipv4 ethernet packet send function. It calls
240243
* etharp_output after checking link status.
241244
*
242245
* \param[in] netif the lwip network interface structure for this enetif
243246
* \param[in] q Pointer to pbug to send
244247
* \param[in] ipaddr IP address
245248
* \return ERR_OK or error code
246249
*/
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)
248252
{
249253
/* Only send packet is link is up */
250-
if (netif->flags & NETIF_FLAG_LINK_UP)
254+
if (netif->flags & NETIF_FLAG_LINK_UP) {
251255
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+
}
252278

253279
return ERR_CONN;
254280
}
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
255350

256351
/** \brief Allocates a pbuf and returns the data from the incoming packet.
257352
*
@@ -322,7 +417,7 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
322417

323418
update_read_buffer(rx_buff[idx]->payload);
324419
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",
326421
p, length, idx));
327422

328423
/* Save size */
@@ -344,36 +439,18 @@ static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
344439
*/
345440
void k64f_enetif_input(struct netif *netif, int idx)
346441
{
347-
struct eth_hdr *ethhdr;
348442
struct pbuf *p;
349443

350444
/* move received packet into a new pbuf */
351445
p = k64f_low_level_input(netif, idx);
352446
if (p == NULL)
353447
return;
354448

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 */
375453
pbuf_free(p);
376-
break;
377454
}
378455
}
379456

@@ -432,7 +509,6 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
432509
struct pbuf *temp_pbuf;
433510
uint8_t *psend = NULL, *dst;
434511

435-
436512
temp_pbuf = pbuf_alloc(PBUF_RAW, p->tot_len + ENET_BUFF_ALIGNMENT, PBUF_RAM);
437513
if (NULL == temp_pbuf)
438514
return ERR_MEM;
@@ -569,14 +645,16 @@ err_t eth_arch_enetif_init(struct netif *netif)
569645
#else
570646
mbed_mac_address((char *)netif->hwaddr);
571647
#endif
572-
netif->hwaddr_len = ETHARP_HWADDR_LEN;
648+
649+
/* Ethernet address length */
650+
netif->hwaddr_len = ETH_HWADDR_LEN;
573651

574652
/* maximum transfer unit */
575653
netif->mtu = 1500;
576654

577655
/* device capabilities */
578656
// 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;
580658

581659
/* Initialize the hardware */
582660
netif->state = &k64f_enetdata;
@@ -592,7 +670,23 @@ err_t eth_arch_enetif_init(struct netif *netif)
592670
netif->name[0] = 'e';
593671
netif->name[1] = 'n';
594672

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
596690
netif->linkoutput = k64f_low_level_output;
597691

598692
/* CMSIS-RTOS, start tasks */
@@ -610,7 +704,12 @@ err_t eth_arch_enetif_init(struct netif *netif)
610704
/* Packet receive task */
611705
err = sys_sem_new(&k64f_enetdata.RxReadySem, 0);
612706
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
613711
sys_thread_new("receive_thread", packet_rx, netif->state, DEFAULT_THREAD_STACKSIZE, RX_PRIORITY);
712+
#endif
614713

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

0 commit comments

Comments
 (0)