Compare commits

...

28 Commits

Author SHA1 Message Date
Kuba Szczodrzyński
57a7df125b [LT] Add package.json 2023-02-25 21:11:48 +01:00
Kuba Szczodrzyński
33191e0a13 [LT] Add vendor changes from bdk_freertos/v2.0.2 (mutex) 2022-08-26 15:48:02 +02:00
Kuba Szczodrzyński
8e1df05d86 [LT] Add vendor changes from bdk_freertos/v2.0.2 (misc) 2022-08-26 15:47:48 +02:00
Kuba Szczodrzyński
e365bc3653 [LT] Add vendor changes from bdk_freertos/v2.0.2 (ip4.c/ripple20) 2022-08-26 15:47:42 +02:00
Kuba Szczodrzyński
369fee9353 [LT] Add vendor changes from bdk_freertos/v2.0.2 (memmang) 2022-08-26 15:47:35 +02:00
Kuba Szczodrzyński
898a3a5f07 [LT] Add vendor changes from bdk_freertos/v2.0.2 (opts) 2022-08-26 15:47:28 +02:00
Kuba Szczodrzyński
c195d2acdf [LT] Add port from bdk_freertos/v2.0.2 2022-08-26 15:47:20 +02:00
Simon Goldschmidt
6ca936f6b5 Prepare 2.1.3 release 2021-11-10 19:25:03 +01:00
Hu Keping
e7b74570d9 Remove unnecessary files in release tarball
This patch adds a few entries in .gitattributes to specify files that
should never end up in a distribution tarball.

Signed-off-by: Hu Keping <hukeping@huawei.com>
2021-11-10 19:18:11 +01:00
Sylvain Rochet
018c64ab94 PPP: assert if ppp_set_* functions are called when session is not dead
ppp_set_* functions that set the PPP session parameters must only be
called when the session is in a dead state (i.e. disconnected),
otherwise not fatal but surprising results may happen.
2021-10-13 21:30:13 +02:00
Sylvain Rochet
7e92fb3d7f PPP: remove LWIP_ASSERT_CORE_LOCKED on ppp_set_auth function
We do not have equivalents in PPPAPI for ppp_set_* functions because
calling them only makes sense while session is disconnected, furthermore
they are only setting structure members of the session configuration.
2021-10-13 21:29:29 +02:00
Dirk Ziegelmeier
051fbea5e6 Fix bug #54805: IP address can not be obtained over dhcp if PBUF_POOL_BUFSIZE is too small
Patch by Christoph Chang
2021-10-03 12:33:58 +02:00
Florent Matignon
214e2d90f3 bug #54700: Unexpected expiry of pending ARP table entry
New etharp queries should restart the 5 second timeout on the ARP
table entry if it is still pending.

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
(cherry picked from commit ffbe075d56)
2021-10-01 20:31:59 +02:00
Simon Goldschmidt
4022a19cbc altcp: fix altcp_tcp_close for LISTEN pcb
See bug #55219

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
(cherry picked from commit 064d816ea1)
2021-10-01 19:59:02 +02:00
Simon Goldschmidt
a32ea1e793 dhcp: don't set a default gateway if dhcp server doesn't give one
see bug #60578
2021-09-24 12:24:58 +02:00
Simon Goldschmidt
f67f2692d4 mqtt: check data_cb != NULL 2021-09-24 00:36:22 +02:00
Karol Domagalski
3b745f7154 ip4: ip4addr_aton: fix parsing of the octal IP representation 2021-09-24 00:29:45 +02:00
Erik Ekman
d876d3c4df ip6: Fix incorrect assert in ip6_frag()
New test case now passes.

Fixes bug #57374 (Found by Hiromasa Ito).
2021-09-24 00:12:20 +02:00
Erik Ekman
e8b0c52806 ip6: Add test for fragmenting special packet
Reproduces bug #57374 (Found by Hiromasa Ito).
2021-09-24 00:12:11 +02:00
Erik Ekman
5bd7518343 netdb: Accept '0' as service in lwip_getaddrinfo
Fixes bug #59925
2021-09-23 23:57:32 +02:00
Eric Koldeweij
51265f3f7d ip6: Fix crash in ip6_output with debug enabled
It turns out the crash only occurs if LWIP_DEBUG is enabled. If the
parameter dest is NULL the function tries to find a route using the
destination address of the packet instead. If this fails as well a
debug message is printed but it is still using dest causing a NULL
pointer dereference and crash at src/core/ipv6/ip6.c line 1312.

[erik@kryo.se: Apply fix to ip6_output_hinted as well]
2021-09-23 23:51:01 +02:00
Christoffer Lind
2e4932f23b dhcp: generate new xid for DHCP release 2021-09-23 23:44:11 +02:00
Simon Goldschmidt
dbd0bc8a2c netdb: fix alignment warning in debug output
see bug #58650
2021-09-15 08:05:41 +02:00
Oliver Hitz
e5627ec649 tcp: make tcp_listen() inherit the netbuf_idx of the original pcb
This simple patch causes tcp_listen() to inherit the netbuf_idx setting
of the original pcb. Without this, it is not possible to restrict a
socket to a specific interface using SO_BINDTODEVICE before listening.

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
2021-09-15 08:03:24 +02:00
Erik Ekman
5c8fd3158d unit: Support check v0.13.0 and later
Function name no longer needs to be fed separately when adding tests.

Also fix collision of non-static net_test variables in dhcp and netif
tests.
2021-08-16 08:56:06 +02:00
Erik Ekman
d5843944cc netif: Add test for netif_find 2021-08-16 08:45:25 +02:00
Erik Ekman
f62be85576 netif: Add test for netif_is_flag_set() 2021-08-16 08:45:25 +02:00
Simon Goldschmidt
f1bd63046e api_lib: fix duplicate NULL check with sys_sem_valid() 2021-08-16 08:36:09 +02:00
37 changed files with 2603 additions and 41 deletions

6
.gitattributes vendored
View File

@@ -2,3 +2,9 @@
*.txt text
*.c text
*.h text
# For git archive
.gitignore export-ignore
.gitattributes export-ignore
.travis.yml export-ignore
.vscode export-ignore

View File

@@ -38,7 +38,7 @@ PROJECT_NAME = "lwIP"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = "2.1.3.rc1"
PROJECT_NUMBER = "2.1.3"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a

5
package.json Normal file
View File

@@ -0,0 +1,5 @@
{
"name": "library-lwip",
"version": "2.1.3-bdk",
"description": "lwIP - A Lightweight TCPIP stack"
}

111
port/arch/cc.h Normal file
View File

@@ -0,0 +1,111 @@
/*
* cc.h - Architecture environment, some compiler specific, some
* environment specific (probably should move env stuff
* to sys_arch.h.)
*
* Typedefs for the types used by lwip -
* u8_t, s8_t, u16_t, s16_t, u32_t, s32_t, mem_ptr_t
*
* Compiler hints for packing lwip's structures -
* PACK_STRUCT_FIELD(x)
* PACK_STRUCT_STRUCT
* PACK_STRUCT_BEGIN
* PACK_STRUCT_END
*
* Platform specific diagnostic output -
* LWIP_PLATFORM_DIAG(x) - non-fatal, print a message.
* LWIP_PLATFORM_ASSERT(x) - fatal, print message and abandon execution.
* Portability defines for printf formatters:
* U16_F, S16_F, X16_F, U32_F, S32_F, X32_F, SZT_F
*
* "lightweight" synchronization mechanisms -
* SYS_ARCH_DECL_PROTECT(x) - declare a protection state variable.
* SYS_ARCH_PROTECT(x) - enter protection mode.
* SYS_ARCH_UNPROTECT(x) - leave protection mode.
*
* If the compiler does not provide memset() this file must include a
* definition of it, or include a file which defines it.
*
* This file must either include a system-local <errno.h> which defines
* the standard *nix error codes, or it should #define LWIP_PROVIDE_ERRNO
* to make lwip/arch.h define the codes which are used throughout.
*/
#ifndef __CC_H__
#define __CC_H__
#include "typedef.h"
#include "uart_pub.h"
/*
* Typedefs for the types used by lwip -
* u8_t, s8_t, u16_t, s16_t, u32_t, s32_t, mem_ptr_t
*/
typedef unsigned char u8_t; /* Unsigned 8 bit quantity */
typedef signed char s8_t; /* Signed 8 bit quantity */
typedef unsigned short u16_t; /* Unsigned 16 bit quantity */
typedef signed short s16_t; /* Signed 16 bit quantity */
typedef unsigned long u32_t; /* Unsigned 32 bit quantity */
typedef signed long s32_t; /* Signed 32 bit quantity */
//typedef unsigned long mem_ptr_t; /* Unsigned 32 bit quantity */
typedef int intptr_t;
typedef unsigned int uintptr_t;
typedef int sys_prot_t;
#if defined(__GNUC__)
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT __attribute__((packed))
#define PACK_STRUCT_FIELD(x) x
#elif defined(__ICCARM__)
#define PACK_STRUCT_BEGIN __packed
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_FIELD(x) x
#else
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT
#define PACK_STRUCT_FIELD(x) x
#endif
/*
* Platform specific diagnostic output -
* LWIP_PLATFORM_DIAG(x) - non-fatal, print a message.
* LWIP_PLATFORM_ASSERT(x) - fatal, print message and abandon execution.
* Portability defines for printf formatters:
* U16_F, S16_F, X16_F, U32_F, S32_F, X32_F, SZT_F
*/
#ifndef LWIP_PLATFORM_ASSERT
#define LWIP_PLATFORM_ASSERT(x) \
do \
{ fatal_prf("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__); \
} while(0)
#endif
#ifndef LWIP_PLATFORM_DIAG
#define LWIP_PLATFORM_DIAG(x) do {fatal_prf x ;} while(0)
#endif
#define U16_F "4d"
#define S16_F "4d"
#define X16_F "4x"
#define U32_F "8ld"
#define S32_F "8ld"
#define X32_F "8lx"
/*
* unknow defination
*/
// cup byte order
#ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN
#endif
extern int bk_rand(); /* FIXME: move to right place */
#define LWIP_RAND() ((uint32_t)bk_rand())
#endif
// eof

56
port/arch/sys_arch.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __SYS_RTXC_H__
#define __SYS_RTXC_H__
#include "sys_rtos.h"
#define SYS_MBOX_NULL (xQueueHandle)0
#define SYS_SEM_NULL (xSemaphoreHandle)0
#define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE
typedef xSemaphoreHandle sys_sem_t;
typedef xQueueHandle sys_mbox_t;
typedef xTaskHandle sys_thread_t;
typedef struct _sys_arch_state_t
{
// Task creation data.
char cTaskName[configMAX_TASK_NAME_LEN];
unsigned short nStackDepth;
unsigned short nTaskCount;
} sys_arch_state_t;
/* Message queue constants. */
#define archMESG_QUEUE_LENGTH ( 32 )
#endif /* __SYS_RTXC_H__ */

335
port/ethernetif.c Normal file
View File

@@ -0,0 +1,335 @@
/**
* @file
* Ethernet Interface Skeleton
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*
* This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a
* search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface.
*/
#include "include.h"
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include <lwip/snmp.h>
#include "ethernetif.h"
#include <stdio.h>
#include <string.h>
#include "netif/etharp.h"
#include "lwip_netif_address.h"
#include "sa_station.h"
#include "drv_model_pub.h"
#include "mem_pub.h"
#include "common.h"
#include "hostapd_cfg.h"
#include "sk_intf.h"
#include "rw_pub.h"
#include "rtos_pub.h"
#include "param_config.h"
/* Define those to better describe your network interface. */
#define IFNAME0 'e'
#define IFNAME1 'n'
#include "uart_pub.h"
#define ETH_INTF_DEBUG
#ifdef ETH_INTF_DEBUG
#define ETH_INTF_PRT warning_prf
#define ETH_INTF_WARN warning_prf
#define ETH_INTF_FATAL fatal_prf
#else
#define ETH_INTF_PRT null_prf
#define ETH_INTF_WARN null_prf
#define ETH_INTF_FATAL null_prf
#endif
extern int bmsg_tx_sender(struct pbuf *p, uint32_t vif_idx);
/* Forward declarations. */
void ethernetif_input(int iface, struct pbuf *p);
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*
* @param netif the already initialized lwip network interface structure
* for this ethernetif
*/
const char wlan_name[][6] =
{
"wlan0\0",
"wlan1\0",
"wlan2\0",
"wlan3\0",
};
static void low_level_init(struct netif *netif)
{
VIF_INF_PTR vif_entry = (VIF_INF_PTR)(netif->state);
u8 *macptr = (u8*)&vif_entry->mac_addr;
#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname */
netif->hostname = (char*)&wlan_name[vif_entry->index];
#endif /* LWIP_NETIF_HOSTNAME */
//wifi_get_mac_address((char *)wireless_mac, type);
/* set MAC hardware address length */
ETH_INTF_PRT("enter low level!\r\n");
ETH_INTF_PRT("mac %2x:%2x:%2x:%2x:%2x:%2x\r\n", macptr[0], macptr[1], macptr[2],
macptr[3], macptr[4], macptr[5]);
netif->hwaddr_len = ETHARP_HWADDR_LEN;
os_memcpy(netif->hwaddr, macptr, ETHARP_HWADDR_LEN);
/* maximum transfer unit */
netif->mtu = 1500;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
ETH_INTF_PRT("leave low level!\r\n");
}
/**
* This function should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
* @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent
*
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become availale since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
int ret;
err_t err = ERR_OK;
uint8_t vif_idx = rwm_mgmt_get_netif2vif(netif);
//os_printf("output:%x\r\n", p);
ret = bmsg_tx_sender(p, (uint32_t)vif_idx);
if(0 != ret)
{
err = ERR_TIMEOUT;
}
return err;
}
/**
* This function should be called when a packet is ready to be read
* from the interface. It uses the function low_level_input() that
* should handle the actual reception of bytes from the network
* interface. Then the type of the received packet is determined and
* the appropriate input function is called.
*
* @param netif the lwip network interface structure for this ethernetif
*/
void
ethernetif_input(int iface, struct pbuf *p)
{
struct eth_hdr *ethhdr;
struct netif *netif;
if (p->len <= SIZEOF_ETH_HDR) {
pbuf_free(p);
return;
}
netif = rwm_mgmt_get_vif2netif((uint8_t)iface);
if(!netif) {
//ETH_INTF_PRT("ethernetif_input no netif found %d\r\n", iface);
pbuf_free(p);
p = NULL;
return;
}
/* points to packet payload, which starts with an Ethernet header */
ethhdr = p->payload;
switch (htons(ethhdr->type))
{
/* IP or ARP packet? */
case ETHTYPE_IP:
case ETHTYPE_ARP:
#if PPPOE_SUPPORT
/* PPPoE packet? */
case ETHTYPE_PPPOEDISC:
case ETHTYPE_PPPOE:
#endif /* PPPOE_SUPPORT */
/* full packet send to tcpip_thread to process */
if (netif->input(p, netif) != ERR_OK) // ethernet_input
{
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\r\n"));
pbuf_free(p);
p = NULL;
}
break;
case ETHTYPE_EAPOL:
ke_l2_packet_tx(p->payload, p->len, iface);
pbuf_free(p);
p = NULL;
break;
default:
pbuf_free(p);
p = NULL;
break;
}
}
/**
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
* This function should be passed as a parameter to netif_add().
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
err_t
ethernetif_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 10000000);
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
netif->output = etharp_output;
netif->linkoutput = low_level_output;
/* initialize the hardware */
low_level_init(netif);
return ERR_OK;
}
/**
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
* This function should be passed as a parameter to netifapi_netif_add().
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
err_t lwip_netif_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 10000000);
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
netif->output = etharp_output;
netif->linkoutput = low_level_output;
#ifdef CONFIG_IPV6
netif->output_ip6 = ethip6_output;
#endif
/* initialize the hardware */
low_level_init(netif);
return ERR_OK;
}
err_t lwip_netif_uap_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
//netif->state = NULL;
netif->name[0] = 'u';
netif->name[1] = 'a';
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
netif->output = etharp_output;
netif->linkoutput = low_level_output;
/* initialize the hardware */
low_level_init(netif);
return ERR_OK;
}
// eof

13
port/ethernetif.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __ETHERNETIF_H__
#define __ETHERNETIF_H__
#include "lwip/err.h"
#include "lwip/netif.h"
void ethernetif_recv(struct netif *netif, int total_len);
err_t ethernetif_init(struct netif *netif);
#endif

17
port/lwip_intf.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef __LWIP_INTF_H__
#define __LWIP_INTF_H__
#define LWIP_INTF_DEBUG
#ifdef LWIP_INTF_DEBUG
#define LWIP_INTF_PRT warning_prf
#define LWIP_INTF_WARN warning_prf
#define LWIP_INTF_FATAL fatal_prf
#else
#define LWIP_INTF_PRT null_prf
#define LWIP_INTF_WARN null_prf
#define LWIP_INTF_FATAL null_prf
#endif
#endif
// eof

48
port/lwip_netif_address.h Normal file
View File

@@ -0,0 +1,48 @@
#ifndef _MXCHIP_NETIF_ADDR_H_
#define _MXCHIP_NETIF_ADDR_H_
/** MLAN BSS type */
typedef enum _wifi_interface_type
{
WIFI_INTERFACE_TYPE_STA = 0,
WIFI_INTERFACE_TYPE_UAP = 1,
WIFI_INTERFACE_TYPE_ANY = 0xff,
} wifi_interface_type;
#define ADDR_TYPE_STATIC 1
#define ADDR_TYPE_DHCP 0
/** This data structure represents an IPv4 address */
struct ipv4_config {
/** DHCP_Disable DHCP_Client DHCP_Server */
unsigned addr_type;
/** The system's IP address in network order. */
unsigned address;
/** The system's default gateway in network order. */
unsigned gw;
/** The system's subnet mask in network order. */
unsigned netmask;
/** The system's primary dns server in network order. */
unsigned dns1;
/** The system's secondary dns server in network order. */
unsigned dns2;
};
/** Network IP configuration.
*
* This data structure represents the network IP configuration
* for IPv4 as well as IPv6 addresses
*/
struct wlan_ip_config {
#ifdef CONFIG_IPV6
/** The network IPv6 address configuration that should be
* associated with this interface. */
struct ipv6_config ipv6[MAX_IPV6_ADDRESSES];
#endif
/** The network IPv4 address configuration that should be
* associated with this interface. */
struct ipv4_config ipv4;
};
#endif

461
port/lwipopts.h Normal file
View File

@@ -0,0 +1,461 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__
#include "sys_config.h"
/**
* Loopback demo related options.
*/
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_HAVE_LOOPIF 1
#define LWIP_NETIF_LOOPBACK_MULTITHREADING 1
#define LWIP_LOOPBACK_MAX_PBUFS 8
#define TCPIP_THREAD_NAME "tcp/ip"
#define TCPIP_THREAD_STACKSIZE 512
#define TCPIP_THREAD_PRIO 7
#define DEFAULT_THREAD_STACKSIZE 200
#define DEFAULT_THREAD_PRIO 1
/* Disable lwIP asserts */
#define LWIP_NOASSERT 1
#define LWIP_DEBUG 0
#define LWIP_DEBUG_TRACE 0
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#define ETHARP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define IGMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#define AUTOIP_DEBUG LWIP_DBG_OFF
#define SNMP_MSG_DEBUG LWIP_DBG_OFF
#define SNMP_MIB_DEBUG LWIP_DBG_OFF
#define DNS_DEBUG LWIP_DBG_OFF
//#define LWIP_COMPAT_MUTEX 1
/**
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
* critical regions during buffer allocation, deallocation and memory
* allocation and deallocation.
*/
#define SYS_LIGHTWEIGHT_PROT 1
/*
------------------------------------
---------- Memory options ----------
------------------------------------
*/
/**
* MEM_ALIGNMENT: should be set to the alignment of the CPU
* 4 byte alignment -> #define MEM_ALIGNMENT 4
* 2 byte alignment -> #define MEM_ALIGNMENT 2
*/
#define MEM_ALIGNMENT 4
#define MAX_SOCKETS_TCP 12
#define MAX_LISTENING_SOCKETS_TCP 4
#define MAX_SOCKETS_UDP 22
#define TCP_SND_BUF_COUNT 5
/* Value of TCP_SND_BUF_COUNT denotes the number of buffers and is set by
* CONFIG option available in the SDK
*/
/* Buffer size needed for TCP: Max. number of TCP sockets * Size of pbuf *
* Max. number of TCP sender buffers per socket
*
* Listening sockets for TCP servers do not require the same amount buffer
* space. Hence do not consider these sockets for memory computation
*/
#define TCP_MEM_SIZE (MAX_SOCKETS_TCP * \
PBUF_POOL_BUFSIZE * (TCP_SND_BUF/TCP_MSS))
/* Buffer size needed for UDP: Max. number of UDP sockets * Size of pbuf
*/
#define UDP_MEM_SIZE (MAX_SOCKETS_UDP * PBUF_POOL_BUFSIZE)
/**
* MEM_SIZE: the size of the heap memory. If the application will send
* a lot of data that needs to be copied, this should be set high.
*/
#if ((defined(CFG_LWIP_MEM_POLICY))&&(CFG_LWIP_MEM_POLICY == LWIP_REDUCE_THE_PLAN))
#define MEM_SIZE (16*1024)
#else
#define MEM_SIZE (32*1024)
#endif
/*
------------------------------------------------
---------- Internal Memory Pool Sizes ----------
------------------------------------------------
*/
/**
* MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF).
* If the application sends a lot of data out of ROM (or other static memory),
* this should be set high.
*/
#define MEMP_NUM_PBUF 10
/**
* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections.
* (requires the LWIP_TCP option)
*/
#define MEMP_NUM_TCP_PCB MAX_SOCKETS_TCP
#define MEMP_NUM_TCP_PCB_LISTEN MAX_LISTENING_SOCKETS_TCP
/**
* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments.
* (requires the LWIP_TCP option)
*/
//#define MEMP_NUM_TCP_SEG 12
/**
* MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used
* for incoming packets.
* (only needed if you use tcpip.c)
*/
#define MEMP_NUM_TCPIP_MSG_INPKT 16
/**
* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts.
* (requires NO_SYS==0)
*/
#define MEMP_NUM_SYS_TIMEOUT 12
/**
* MEMP_NUM_NETBUF: the number of struct netbufs.
* (only needed if you use the sequential API, like api_lib.c)
*/
#define MEMP_NUM_NETBUF 16
/**
* MEMP_NUM_NETCONN: the number of struct netconns.
* (only needed if you use the sequential API, like api_lib.c)
*
* This number corresponds to the maximum number of active sockets at any
* given point in time. This number must be sum of max. TCP sockets, max. TCP
* sockets used for listening, and max. number of UDP sockets
*/
#define MEMP_NUM_NETCONN (MAX_SOCKETS_TCP + \
MAX_LISTENING_SOCKETS_TCP + MAX_SOCKETS_UDP)
/**
* PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
*/
#if ((defined(CFG_LWIP_MEM_POLICY))&&(CFG_LWIP_MEM_POLICY == LWIP_REDUCE_THE_PLAN))
#define PBUF_POOL_SIZE 3
#else
#define PBUF_POOL_SIZE 10
#endif
/*
----------------------------------
---------- Pbuf options ----------
----------------------------------
*/
/**
* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is
* designed to accomodate single full size TCP frame in one pbuf, including
* TCP_MSS, IP header, and link header.
*/
#define PBUF_POOL_BUFSIZE 1580
/*
---------------------------------
---------- RAW options ----------
---------------------------------
*/
/**
* LWIP_RAW==1: Enable application layer to hook into the IP layer itself.
*/
#define LWIP_RAW 1
#ifdef CONFIG_IPV6
#define LWIP_IPV6 1
#endif
/* Enable IPv4 Auto IP */
#ifdef CONFIG_AUTOIP
#define LWIP_AUTOIP 1
#define LWIP_DHCP_AUTOIP_COOP 1
#define LWIP_DHCP_AUTOIP_COOP_TRIES 5
#endif
/*
------------------------------------
---------- Socket options ----------
------------------------------------
*/
/**
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
*/
#define LWIP_SOCKET 1
#define LWIP_NETIF_API 1
/**
* LWIP_RECV_CB==1: Enable callback when a socket receives data.
*/
#define LWIP_RECV_CB 1
/**
* SO_REUSE==1: Enable SO_REUSEADDR option.
*/
#define SO_REUSE 1
#define SO_REUSE_RXTOALL 1
/**
* Enable TCP_KEEPALIVE
*/
#define LWIP_TCP_KEEPALIVE 1
/*
----------------------------------------
---------- Statistics options ----------
----------------------------------------
*/
/**
* LWIP_STATS==1: Enable statistics collection in lwip_stats.
*/
#define LWIP_STATS 1
/**
* LWIP_STATS_DISPLAY==1: Compile in the statistics output functions.
*/
#define LWIP_STATS_DISPLAY 0
/*
----------------------------------
---------- DHCP options ----------
----------------------------------
*/
/**
* LWIP_DHCP==1: Enable DHCP module.
*/
#define LWIP_DHCP 1
#define LWIP_NETIF_STATUS_CALLBACK 1
/**
* DNS related options, revisit later to fine tune.
*/
#define LWIP_DNS 1
#define DNS_TABLE_SIZE 2 // number of table entries, default 4
//#define DNS_MAX_NAME_LENGTH 64 // max. name length, default 256
#define DNS_MAX_SERVERS 2 // number of DNS servers, default 2
#define DNS_DOES_NAME_CHECK 1 // compare received name with given,def 0
#define DNS_MSG_SIZE 512
#define MDNS_MSG_SIZE 512
#define MDNS_TABLE_SIZE 1 // number of mDNS table entries
#define MDNS_MAX_SERVERS 1 // number of mDNS multicast addresses
/* TODO: Number of active UDP PCBs is equal to number of active UDP sockets plus
* two. Need to find the users of these 2 PCBs
*/
#define MEMP_NUM_UDP_PCB (MAX_SOCKETS_UDP + 2)
/* NOTE: some times the socket() call for SOCK_DGRAM might fail if you dont
* have enough MEMP_NUM_UDP_PCB */
/*
----------------------------------
---------- IGMP options ----------
----------------------------------
*/
/**
* LWIP_IGMP==1: Turn on IGMP module.
*/
#define LWIP_IGMP 1
/**
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
* SO_SNDTIMEO processing.
*/
#define LWIP_SO_SNDTIMEO 1
/**
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
* SO_RCVTIMEO processing.
*/
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
/**
* TCP_LISTEN_BACKLOG==1: Handle backlog connections.
*/
#define TCP_LISTEN_BACKLOG 1
#define LWIP_PROVIDE_ERRNO 1
#include <errno.h>
#define ERRNO 1
//#define LWIP_SNMP 1
/*
------------------------------------------------
---------- Network Interfaces options ----------
------------------------------------------------
*/
/**
* LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname
* field.
*/
#define LWIP_NETIF_HOSTNAME 1
/*
The STM32F107 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
- To use this feature let the following define uncommented.
- To disable it and process by CPU comment the the checksum.
*/
//#define CHECKSUM_BY_HARDWARE
#ifdef CHECKSUM_BY_HARDWARE
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 0
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 0
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 0
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 0
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 0
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 0
#else
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
#define CHECKSUM_GEN_IP 1
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
#define CHECKSUM_GEN_UDP 1
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
#define CHECKSUM_GEN_TCP 1
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
#define CHECKSUM_CHECK_IP 1
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
#define CHECKSUM_CHECK_UDP 1
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
#define CHECKSUM_CHECK_TCP 1
#endif
/**
* TCP_RESOURCE_FAIL_RETRY_LIMIT: limit for retrying sending of tcp segment
* on resource failure error returned by driver.
*/
#define TCP_RESOURCE_FAIL_RETRY_LIMIT 50
//#ifdef CONFIG_ENABLE_MXCHIP
/* save memory */
#if ((defined(CFG_LWIP_MEM_POLICY))&&(CFG_LWIP_MEM_POLICY == LWIP_REDUCE_THE_PLAN))
#define TCP_MSS (1500 - 40)
/* TCP receive window. */
#define TCP_WND (3 * TCP_MSS)
/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF (10*TCP_MSS)
#define TCP_SND_QUEUELEN (20)
#else
#define TCP_MSS (1500 - 40)
/* TCP receive window. */
#define TCP_WND (10*TCP_MSS)
/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF (10*TCP_MSS)
#define TCP_SND_QUEUELEN (20)
#endif
/* ARP before DHCP causes multi-second delay - turn it off */
#define DHCP_DOES_ARP_CHECK (0)
#define TCP_MAX_ACCEPT_CONN 5
#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN*2)
#define IP_REASS_MAX_PBUFS 0
#define IP_REASSEMBLY 0
#define IP_REASS_MAX_PBUFS 0
#define IP_REASSEMBLY 0
#define MEMP_NUM_REASSDATA 0
#define IP_FRAG 0
#define MEM_LIBC_MALLOC (0)
#define DEFAULT_UDP_RECVMBOX_SIZE 3 //each udp socket max buffer 3 packets.
#define MEMP_MEM_MALLOC (0)
#define TCP_MSL (TCP_TMR_INTERVAL)
#define LWIP_COMPAT_MUTEX_ALLOWED (1)
#define MEMP_STATS 1
#define MEM_STATS 1
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define LWIP_RIPPLE20 1
/* Beken specific LWIP options */
#define BK_DHCP 1
#endif /* __LWIPOPTS_H__ */

797
port/net.c Normal file
View File

@@ -0,0 +1,797 @@
#include "include.h"
#include <stdio.h>
#include <string.h>
#include <lwip/inet.h>
#include "netif/etharp.h"
#include "lwip/netif.h"
#include <lwip/netifapi.h>
#include <lwip/tcpip.h>
#include <lwip/dns.h>
#include <lwip/dhcp.h>
#include "lwip/prot/dhcp.h"
#include <lwip/sockets.h>
#include "ethernetif.h"
#include "sa_station.h"
#include "drv_model_pub.h"
#include "mem_pub.h"
#include "common.h"
#include "rw_pub.h"
#include "lwip_netif_address.h"
#include "rtos_pub.h"
#include "net.h"
#if CFG_ROLE_LAUNCH
#include "role_launch.h"
#endif
/* forward declaration */
FUNC_1PARAM_PTR bk_wlan_get_status_cb(void);
struct ipv4_config sta_ip_settings;
struct ipv4_config uap_ip_settings;
static int up_iface;
uint32_t sta_ip_start_flag = 0;
uint32_t uap_ip_start_flag = 0;
#ifdef CONFIG_IPV6
#define IPV6_ADDR_STATE_TENTATIVE "Tentative"
#define IPV6_ADDR_STATE_PREFERRED "Preferred"
#define IPV6_ADDR_STATE_INVALID "Invalid"
#define IPV6_ADDR_STATE_VALID "Valid"
#define IPV6_ADDR_STATE_DEPRECATED "Deprecated"
#define IPV6_ADDR_TYPE_LINKLOCAL "Link-Local"
#define IPV6_ADDR_TYPE_GLOBAL "Global"
#define IPV6_ADDR_TYPE_UNIQUELOCAL "Unique-Local"
#define IPV6_ADDR_TYPE_SITELOCAL "Site-Local"
#define IPV6_ADDR_UNKNOWN "Unknown"
#endif
#define net_e warning_prf
#define net_d warning_prf
typedef void (*net_sta_ipup_cb_fn)(void* data);
struct interface {
struct netif netif;
ip_addr_t ipaddr;
ip_addr_t nmask;
ip_addr_t gw;
};
FUNCPTR sta_connected_func;
static struct interface g_mlan = {{0}};
static struct interface g_uap = {{0}};
net_sta_ipup_cb_fn sta_ipup_cb = NULL;
extern void *net_get_sta_handle(void);
extern void *net_get_uap_handle(void);
extern err_t lwip_netif_init(struct netif *netif);
extern err_t lwip_netif_uap_init(struct netif *netif);
extern int net_get_if_ip_addr(uint32_t *ip, void *intrfc_handle);
extern int net_get_if_ip_mask(uint32_t *nm, void *intrfc_handle);
extern int net_configure_address(struct ipv4_config *addr, void *intrfc_handle);
extern int dhcp_server_start(void *intrfc_handle);
extern void dhcp_server_stop(void);
extern void net_configure_dns(struct wlan_ip_config *ip);
#ifdef CONFIG_IPV6
char *ipv6_addr_state_to_desc(unsigned char addr_state)
{
if (ip6_addr_istentative(addr_state))
return IPV6_ADDR_STATE_TENTATIVE;
else if (ip6_addr_ispreferred(addr_state))
return IPV6_ADDR_STATE_PREFERRED;
else if (ip6_addr_isinvalid(addr_state))
return IPV6_ADDR_STATE_INVALID;
else if (ip6_addr_isvalid(addr_state))
return IPV6_ADDR_STATE_VALID;
else if (ip6_addr_isdeprecated(addr_state))
return IPV6_ADDR_STATE_DEPRECATED;
else
return IPV6_ADDR_UNKNOWN;
}
char *ipv6_addr_type_to_desc(struct ipv6_config *ipv6_conf)
{
if (ip6_addr_islinklocal((ip6_addr_t *)ipv6_conf->address))
return IPV6_ADDR_TYPE_LINKLOCAL;
else if (ip6_addr_isglobal((ip6_addr_t *)ipv6_conf->address))
return IPV6_ADDR_TYPE_GLOBAL;
else if (ip6_addr_isuniquelocal((ip6_addr_t *)ipv6_conf->address))
return IPV6_ADDR_TYPE_UNIQUELOCAL;
else if (ip6_addr_issitelocal((ip6_addr_t *)ipv6_conf->address))
return IPV6_ADDR_TYPE_SITELOCAL;
else
return IPV6_ADDR_UNKNOWN;
}
#endif /* CONFIG_IPV6 */
int net_dhcp_hostname_set(char *hostname)
{
netif_set_hostname(&g_mlan.netif, hostname);
return 0;
}
void net_ipv4stack_init(void)
{
static bool tcpip_init_done = 0;
if (tcpip_init_done)
return;
net_d("Initializing TCP/IP stack\r\n");
tcpip_init(NULL, NULL);
tcpip_init_done = true;
}
#ifdef CONFIG_IPV6
void net_ipv6stack_init(struct netif *netif)
{
uint8_t mac[6];
netif->flags |= NETIF_IPV6_FLAG_UP;
/* Set Multicast filter for IPV6 link local address
* It contains first three bytes: 0x33 0x33 0xff (fixed)
* and last three bytes as last three bytes of device mac */
mac[0] = 0x33;
mac[1] = 0x33;
mac[2] = 0xff;
mac[3] = netif->hwaddr[3];
mac[4] = netif->hwaddr[4];
mac[5] = netif->hwaddr[5];
wifi_add_mcast_filter(mac);
netif_create_ip6_linklocal_address(netif, 1);
netif->ip6_autoconfig_enabled = 1;
/* IPv6 routers use multicast IPv6 ff02::1 and MAC address
33:33:00:00:00:01 for router advertisements */
mac[0] = 0x33;
mac[1] = 0x33;
mac[2] = 0x00;
mac[3] = 0x00;
mac[4] = 0x00;
mac[5] = 0x01;
wifi_add_mcast_filter(mac);
}
static void wm_netif_ipv6_status_callback(struct netif *n)
{
/* TODO: Implement appropriate functionality here*/
net_d("Received callback on IPv6 address state change");
wlan_wlcmgr_send_msg(WIFI_EVENT_NET_IPV6_CONFIG,
WIFI_EVENT_REASON_SUCCESS, NULL);
}
#endif /* CONFIG_IPV6 */
void net_wlan_init(void)
{
static int wlan_init_done = 0;
int ret;
if (!wlan_init_done) {
net_ipv4stack_init();
g_mlan.ipaddr.addr = INADDR_ANY;
ret = netifapi_netif_add(&g_mlan.netif, &g_mlan.ipaddr,
&g_mlan.ipaddr, &g_mlan.ipaddr, NULL,
lwip_netif_init, tcpip_input);
if (ret) {
/*FIXME: Handle the error case cleanly */
net_e("MLAN interface add failed");
}
#ifdef CONFIG_IPV6
net_ipv6stack_init(&g_mlan.netif);
#endif /* CONFIG_IPV6 */
ret = netifapi_netif_add(&g_uap.netif, &g_uap.ipaddr,
&g_uap.ipaddr, &g_uap.ipaddr, NULL,
lwip_netif_uap_init, tcpip_input);
if (ret) {
/*FIXME: Handle the error case cleanly */
net_e("UAP interface add failed");
}
wlan_init_done = 1;
}
return;
}
void net_set_sta_ipup_callback(void *fn)
{
sta_ipup_cb = (net_sta_ipup_cb_fn)fn;
}
void user_connected_callback(FUNCPTR fn)
{
sta_connected_func = fn;
}
static void wm_netif_status_static_callback(struct netif *n)
{
if (n->flags & NETIF_FLAG_UP)
{
// static IP success;
os_printf("using static ip...\n");
mhdr_set_station_status(RW_EVT_STA_GOT_IP);/* dhcp success*/
if(sta_ipup_cb != NULL)
sta_ipup_cb(NULL);
if(sta_connected_func != NULL)
(*sta_connected_func)();
}
else
{
// static IP fail;
}
}
static void wm_netif_status_callback(struct netif *n)
{
FUNC_1PARAM_PTR fn;
struct dhcp *dhcp;
u32 val;
if (n->flags & NETIF_FLAG_UP)
{
dhcp = netif_dhcp_data(n);
if(dhcp != NULL)
{
if (dhcp->state == DHCP_STATE_BOUND)
{
os_printf("ip_addr: %x\r\n", n->ip_addr.addr);
#if CFG_ROLE_LAUNCH
rl_pre_sta_set_status(RL_STATUS_STA_LAUNCHED);
#endif
fn = (FUNC_1PARAM_PTR)bk_wlan_get_status_cb();
if(fn)
{
val = RW_EVT_STA_GOT_IP;
(*fn)(&val);
}
mhdr_set_station_status(RW_EVT_STA_GOT_IP);
/* dhcp success*/
if(sta_ipup_cb != NULL)
sta_ipup_cb(NULL);
if(sta_connected_func != NULL)
(*sta_connected_func)();
}
else
{
// dhcp fail
}
}
else
{
// static IP success;
}
}
else
{
// dhcp fail;
}
}
static int check_iface_mask(void *handle, uint32_t ipaddr)
{
uint32_t interface_ip, interface_mask;
net_get_if_ip_addr(&interface_ip, handle);
net_get_if_ip_mask(&interface_mask, handle);
if (interface_ip > 0)
if ((interface_ip & interface_mask) ==
(ipaddr & interface_mask))
return 0;
return -1;
}
void *net_ip_to_interface(uint32_t ipaddr)
{
int ret;
void *handle;
/* Check mlan handle */
handle = net_get_sta_handle();
ret = check_iface_mask(handle, ipaddr);
if (ret == 0)
return handle;
/* Check uap handle */
handle = net_get_uap_handle();
ret = check_iface_mask(handle, ipaddr);
if (ret == 0)
return handle;
/* If more interfaces are added then above check needs to done for
* those newly added interfaces
*/
return NULL;
}
void *net_sock_to_interface(int sock)
{
struct sockaddr_in peer;
unsigned long peerlen = sizeof(struct sockaddr_in);
void *req_iface = NULL;
getpeername(sock, (struct sockaddr *)&peer, &peerlen);
req_iface = net_ip_to_interface(peer.sin_addr.s_addr);
return req_iface;
}
void *net_get_sta_handle(void)
{
return &g_mlan.netif;
}
void *net_get_uap_handle(void)
{
return &g_uap.netif;
}
void *net_get_netif_handle(uint8_t iface)
{
return NULL;
}
void net_interface_up(void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
netifapi_netif_set_up(&if_handle->netif);
}
void net_interface_down(void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
netifapi_netif_set_down(&if_handle->netif);
}
#ifdef CONFIG_IPV6
void net_interface_deregister_ipv6_callback(void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
if (intrfc_handle == &g_mlan)
netif_set_ipv6_status_callback(&if_handle->netif, NULL);
}
#endif
void net_interface_dhcp_stop(void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
netifapi_dhcp_stop(&if_handle->netif);
netif_set_status_callback(&if_handle->netif, NULL);
}
void sta_ip_down(void)
{
if(sta_ip_start_flag)
{
os_printf("sta_ip_down\r\n");
sta_ip_start_flag = 0;
netifapi_netif_set_down(&g_mlan.netif);
netif_set_status_callback(&g_mlan.netif, NULL);
netifapi_dhcp_stop(&g_mlan.netif);
}
}
void sta_ip_start(void)
{
struct wlan_ip_config address = {0};
if(!sta_ip_start_flag)
{
os_printf("sta_ip_start\r\n");
sta_ip_start_flag = 1;
net_configure_address(&sta_ip_settings, net_get_sta_handle());
return;
}
os_printf("sta_ip_start2:0x%x\r\n", address.ipv4.address);
net_get_if_addr(&address, net_get_sta_handle());
if((mhdr_get_station_status() == RW_EVT_STA_CONNECTED)
&& (0 != address.ipv4.address))
{
mhdr_set_station_status(RW_EVT_STA_GOT_IP);
}
}
void sta_set_vif_netif(void)
{
rwm_mgmt_set_vif_netif(&g_mlan.netif);
}
void ap_set_vif_netif(void)
{
rwm_mgmt_set_vif_netif(&g_uap.netif);
}
void sta_set_default_netif(void)
{
netifapi_netif_set_default(net_get_sta_handle());
}
void ap_set_default_netif(void)
{
// as the default netif is sta's netif, so ap need to send
// boardcast or not sub net packets, need set ap netif before
// send those packets, after finish sending, reset default netif
// to sat's netif.
netifapi_netif_set_default(net_get_uap_handle());
}
void reset_default_netif(void)
{
if (sta_ip_is_start()) {
netifapi_netif_set_default(net_get_sta_handle());
} else {
netifapi_netif_set_default(NULL);
}
}
uint32_t sta_ip_is_start(void)
{
return sta_ip_start_flag;
}
void uap_ip_down(void)
{
if (uap_ip_start_flag )
{
os_printf("uap_ip_down\r\n");
uap_ip_start_flag = 0;
netifapi_netif_set_down(&g_uap.netif);
netif_set_status_callback(&g_uap.netif, NULL);
dhcp_server_stop();
}
}
void uap_ip_start(void)
{
if ( !uap_ip_start_flag )
{
os_printf("uap_ip_start\r\n");
uap_ip_start_flag = 1;
net_configure_address(&uap_ip_settings, net_get_uap_handle());
}
}
uint32_t uap_ip_is_start(void)
{
return uap_ip_start_flag;
}
#define DEF_UAP_IP 0xc0a80a01UL /* 192.168.10.1 */
void ip_address_set(int iface, int dhcp, char *ip, char *mask, char*gw, char*dns)
{
uint32_t tmp;
struct ipv4_config addr;
memset(&addr, 0, sizeof(struct ipv4_config));
if (dhcp == 1) {
addr.addr_type = ADDR_TYPE_DHCP;
} else {
addr.addr_type = ADDR_TYPE_STATIC;
tmp = inet_addr((char*)ip);
addr.address = (tmp);
tmp = inet_addr((char*)mask);
if (tmp == 0xFFFFFFFF)
tmp = 0x00FFFFFF;// if not set valid netmask, set as 255.255.255.0
addr.netmask= (tmp);
tmp = inet_addr((char*)gw);
addr.gw = (tmp);
tmp = inet_addr((char*)dns);
addr.dns1 = (tmp);
}
if (iface == 1) // Station
memcpy(&sta_ip_settings, &addr, sizeof(addr));
else
memcpy(&uap_ip_settings, &addr, sizeof(addr));
}
int net_configure_address(struct ipv4_config *addr, void *intrfc_handle)
{
if (!intrfc_handle)
return -1;
struct interface *if_handle = (struct interface *)intrfc_handle;
net_d("\r\nconfiguring interface %s (with %s)",
(if_handle == &g_mlan) ? "mlan" :"uap",
(addr->addr_type == ADDR_TYPE_DHCP)
? "DHCP client" : "Static IP");
netifapi_netif_set_down(&if_handle->netif);
/* De-register previously registered DHCP Callback for correct
* address configuration.
*/
netif_set_status_callback(&if_handle->netif, NULL);
#ifdef CONFIG_IPV6
if (if_handle == &g_mlan) {
netif_set_ipv6_status_callback(&if_handle->netif,
wm_netif_ipv6_status_callback);
/* Explicitly call this function so that the linklocal address
* gets updated even if the interface does not get any IPv6
* address in its lifetime */
wm_netif_ipv6_status_callback(&if_handle->netif);
}
#endif
switch (addr->addr_type) {
case ADDR_TYPE_STATIC:
if_handle->ipaddr.addr = addr->address;
if_handle->nmask.addr = addr->netmask;
if_handle->gw.addr = addr->gw;
netifapi_netif_set_addr(&if_handle->netif, &if_handle->ipaddr,
&if_handle->nmask, &if_handle->gw);
netifapi_netif_set_up(&if_handle->netif);
net_configure_dns((struct wlan_ip_config *)addr);
if(if_handle == &g_mlan)
{
netif_set_status_callback(&if_handle->netif,
wm_netif_status_static_callback);
}
break;
case ADDR_TYPE_DHCP:
/* Reset the address since we might be transitioning from static to DHCP */
memset(&if_handle->ipaddr, 0, sizeof(ip_addr_t));
memset(&if_handle->nmask, 0, sizeof(ip_addr_t));
memset(&if_handle->gw, 0, sizeof(ip_addr_t));
netifapi_netif_set_addr(&if_handle->netif, &if_handle->ipaddr,
&if_handle->nmask, &if_handle->gw);
netif_set_status_callback(&if_handle->netif,
wm_netif_status_callback);
netifapi_netif_set_up(&if_handle->netif);
netifapi_dhcp_start(&if_handle->netif);
break;
default:
break;
}
/* Finally this should send the following event. */
if (if_handle == &g_mlan) {
// static IP up;
/* XXX For DHCP, the above event will only indicate that the
* DHCP address obtaining process has started. Once the DHCP
* address has been obtained, another event,
* WD_EVENT_NET_DHCP_CONFIG, should be sent to the wlcmgr.
*/
up_iface = 1;
// we always set sta netif as the default.
sta_set_default_netif();
} else {
// softap IP up, start dhcp server;
dhcp_server_start(net_get_uap_handle());
up_iface = 0;
// as the default netif is sta's netif, so ap need to send
// boardcast or not sub net packets, need set ap netif before
// send those packets, after finish sending, reset default netif
// to sta's netif.
os_printf("def netif is no ap's netif, sending boardcast or no-subnet ip packets may failed\r\n");
}
return 0;
}
int net_get_if_addr(struct wlan_ip_config *addr, void *intrfc_handle)
{
const ip_addr_t *tmp;
struct interface *if_handle = (struct interface *)intrfc_handle;
if(netif_is_up(&if_handle->netif)) {
addr->ipv4.address = if_handle->netif.ip_addr.addr;
addr->ipv4.netmask = if_handle->netif.netmask.addr;
addr->ipv4.gw = if_handle->netif.gw.addr;
tmp = dns_getserver(0);
addr->ipv4.dns1 = tmp->addr;
tmp = dns_getserver(1);
addr->ipv4.dns2 = tmp->addr;
}
return 0;
}
int net_get_if_macaddr(void *macaddr, void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
os_memcpy(macaddr, &if_handle->netif.hwaddr[0], if_handle->netif.hwaddr_len);
return 0;
}
#ifdef CONFIG_IPV6
int net_get_if_ipv6_addr(struct wlan_ip_config *addr, void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
int i;
for (i = 0; i < MAX_IPV6_ADDRESSES; i++) {
memcpy(addr->ipv6[i].address,
if_handle->netif.ip6_addr[i].addr, 16);
addr->ipv6[i].addr_state = if_handle->netif.ip6_addr_state[i];
}
/* TODO carry out more processing based on IPv6 fields in netif */
return 0;
}
int net_get_if_ipv6_pref_addr(struct wlan_ip_config *addr, void *intrfc_handle)
{
int i, ret = 0;
struct interface *if_handle = (struct interface *)intrfc_handle;
for (i = 0; i < MAX_IPV6_ADDRESSES; i++) {
if (if_handle->netif.ip6_addr_state[i] == IP6_ADDR_PREFERRED) {
memcpy(addr->ipv6[ret++].address,
if_handle->netif.ip6_addr[i].addr, 16);
}
}
return ret;
}
#endif /* CONFIG_IPV6 */
int net_get_if_ip_addr(uint32_t *ip, void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
*ip = if_handle->netif.ip_addr.addr;
return 0;
}
int net_get_if_gw_addr(uint32_t *ip, void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
*ip = if_handle->netif.gw.addr;
return 0;
}
int net_get_if_ip_mask(uint32_t *nm, void *intrfc_handle)
{
struct interface *if_handle = (struct interface *)intrfc_handle;
*nm = if_handle->netif.netmask.addr;
return 0;
}
void net_configure_dns(struct wlan_ip_config *ip)
{
ip_addr_t tmp;
if (ip->ipv4.addr_type == ADDR_TYPE_STATIC) {
if (ip->ipv4.dns1 == 0)
ip->ipv4.dns1 = ip->ipv4.gw;
if (ip->ipv4.dns2 == 0)
ip->ipv4.dns2 = ip->ipv4.dns1;
tmp.addr = ip->ipv4.dns1;
dns_setserver(0, &tmp);
tmp.addr = ip->ipv4.dns2;
dns_setserver(1, &tmp);
}
/* DNS MAX Retries should be configured in lwip/dns.c to 3/4 */
/* DNS Cache size of about 4 is sufficient */
}
void net_wlan_initial(void)
{
net_ipv4stack_init();
#ifdef CONFIG_IPV6
net_ipv6stack_init(&g_mlan.netif);
#endif /* CONFIG_IPV6 */
}
void net_wlan_add_netif(void *mac)
{
VIF_INF_PTR vif_entry = NULL;
struct interface *wlan_if = NULL;
err_t err;
u8 vif_idx;
u8 *b = (u8*)mac;
if(!b || (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5])))
return;
vif_idx = rwm_mgmt_vif_mac2idx(mac);
if(vif_idx == 0xff) {
os_printf("net_add_netif-not-found\r\n");
return ;
}
vif_entry = rwm_mgmt_vif_idx2ptr(vif_idx);
if(!vif_entry) {
os_printf("net_wlan_add_netif not vif found, %d\r\n", vif_idx);
return ;
}
if(vif_entry->type == VIF_AP) {
wlan_if = &g_uap;
} else if(vif_entry->type == VIF_STA) {
wlan_if = &g_mlan;
} else {
os_printf("net_wlan_add_netif with other role\r\n");
return ;
}
wlan_if->ipaddr.addr = INADDR_ANY;
err = netifapi_netif_add(&wlan_if->netif,
&wlan_if->ipaddr,
&wlan_if->ipaddr,
&wlan_if->ipaddr,
(void*)vif_entry,
ethernetif_init,
tcpip_input);
if (err)
{
os_printf("net_wlan_add_netif failed\r\n");
}
else
{
vif_entry->priv = &wlan_if->netif;
}
os_printf("[net]addvif_idx:%d\r\n", vif_idx);
}
void net_wlan_remove_netif(void *mac)
{
err_t err;
u8 vif_idx;
VIF_INF_PTR vif_entry = NULL;
struct netif *netif = NULL;
u8 *b = (u8*)mac;
if(!b || (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5])))
return;
vif_idx = rwm_mgmt_vif_mac2idx(mac);
if(vif_idx == 0xff) {
os_printf("net_wlan_add_netif not vif idx found\r\n");
return ;
}
vif_entry = rwm_mgmt_vif_idx2ptr(vif_idx);
if(!vif_entry) {
os_printf("net_wlan_add_netif not vif found, %d\r\n", vif_idx);
return ;
}
netif = (struct netif *)vif_entry->priv;
if(!netif) {
os_printf("net_wlan_remove_netif netif is null\r\n");
return;
}
err = netifapi_netif_remove(netif);
if(err != ERR_OK) {
os_printf("net_wlan_remove_netif failed\r\n");
} else {
netif->state = NULL;
}
os_printf("[net]remoVif_idx:%d\r\n", vif_idx);
}
//eof

21
port/net.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef _NET_H_
#define _NET_H_
#include "lwip_netif_address.h"
extern void uap_ip_down(void);
extern void uap_ip_start(void);
extern void sta_ip_down(void);
extern void sta_ip_start(void);
extern uint32_t uap_ip_is_start(void);
extern uint32_t sta_ip_is_start(void);
extern void *net_get_sta_handle(void);
extern void *net_get_uap_handle(void);
extern void net_wlan_remove_netif(void *mac);
extern int net_get_if_macaddr(void *macaddr, void *intrfc_handle);
extern int net_get_if_addr(struct wlan_ip_config *addr, void *intrfc_handle);
extern void ip_address_set(int iface, int dhcp, char *ip, char *mask, char*gw, char*dns);
#endif // _NET_H_
// eof

500
port/sys_arch.c Normal file
View File

@@ -0,0 +1,500 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/* lwIP includes. */
#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/mem.h"
#include "lwip/stats.h"
#include "sys_rtos.h"
#include "lwip/timeouts.h"
#include "rtos_pub.h"
#include "portmacro.h"
#define CFG_ENABLE_LWIP_MUTEX 1
#if CFG_ENABLE_LWIP_MUTEX
static sys_mutex_t sys_arch_mutex;
#endif
/*-----------------------------------------------------------------------------------*/
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{
(void ) size;
if (size > 0)
*mbox = xQueueCreate( size, sizeof( void * ) );
else
*mbox = xQueueCreate( archMESG_QUEUE_LENGTH, sizeof( void * ) );
#if SYS_STATS
++lwip_stats.sys.mbox.used;
if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) {
lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
}
#endif /* SYS_STATS */
if (*mbox == NULL)
return ERR_MEM;
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
/*
Deallocates a mailbox. If there are messages still present in the
mailbox when the mailbox is deallocated, it is an indication of a
programming error in lwIP and the developer should be notified.
*/
void sys_mbox_free(sys_mbox_t *mbox)
{
if( uxQueueMessagesWaiting( *mbox ) )
{
/* Line for breakpoint. Should never break here! */
portNOP();
#if SYS_STATS
lwip_stats.sys.mbox.err++;
#endif /* SYS_STATS */
// TODO notify the user of failure.
}
vQueueDelete( *mbox );
#if SYS_STATS
--lwip_stats.sys.mbox.used;
#endif /* SYS_STATS */
}
/*-----------------------------------------------------------------------------------*/
// Posts the "msg" to the mailbox.
void sys_mbox_post(sys_mbox_t *mbox, void *data)
{
while ( xQueueSendToBack(*mbox, &data, portMAX_DELAY ) != pdTRUE ){}
}
/*-----------------------------------------------------------------------------------*/
// Try to post the "msg" to the mailbox.
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
{
err_t result;
if ( xQueueSend( *mbox, &msg, 0 ) == pdPASS )
{
result = ERR_OK;
}
else {
// could not post, queue must be full
result = ERR_MEM;
#if SYS_STATS
lwip_stats.sys.mbox.err++;
#endif /* SYS_STATS */
}
return result;
}
/*-----------------------------------------------------------------------------------*/
/*
Blocks the thread until a message arrives in the mailbox, but does
not block the thread longer than "timeout" milliseconds (similar to
the sys_arch_sem_wait() function). The "msg" argument is a result
parameter that is set by the function (i.e., by doing "*msg =
ptr"). The "msg" parameter maybe NULL to indicate that the message
should be dropped.
The return values are the same as for the sys_arch_sem_wait() function:
Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a
timeout.
Note that a function with a similar name, sys_mbox_fetch(), is
implemented by lwIP.
*/
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
{
void *dummyptr;
portTickType StartTime, EndTime, Elapsed;
StartTime = xTaskGetTickCount();
if ( msg == NULL )
{
msg = &dummyptr;
}
if ( timeout != 0 )
{
if ( pdTRUE == xQueueReceive( *mbox, &(*msg), timeout / portTICK_RATE_MS ) )
{
EndTime = xTaskGetTickCount();
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
return ( Elapsed );
}
else // timed out blocking for message
{
*msg = NULL;
return SYS_ARCH_TIMEOUT;
}
}
else // block forever for a message.
{
while( pdTRUE != xQueueReceive( *mbox, &(*msg), portMAX_DELAY ) ){} // time is arbitrary
EndTime = xTaskGetTickCount();
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
return ( Elapsed ); // return time blocked TODO test
}
}
/*-----------------------------------------------------------------------------------*/
/*
Similar to sys_arch_mbox_fetch, but if message is not ready immediately, we'll
return with SYS_MBOX_EMPTY. On success, 0 is returned.
*/
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
{
void *dummyptr;
if ( msg == NULL )
{
msg = &dummyptr;
}
if ( pdTRUE == xQueueReceive( *mbox, &(*msg), 0 ) )
{
return ERR_OK;
}
else
{
return SYS_MBOX_EMPTY;
}
}
/*----------------------------------------------------------------------------------*/
int sys_mbox_valid(sys_mbox_t *mbox)
{
if (*mbox == SYS_MBOX_NULL)
return 0;
else
return 1;
}
/*-----------------------------------------------------------------------------------*/
void sys_mbox_set_invalid(sys_mbox_t *mbox)
{
*mbox = SYS_MBOX_NULL;
}
/*-----------------------------------------------------------------------------------*/
// Creates a new semaphore. The "count" argument specifies
// the initial state of the semaphore.
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
vSemaphoreCreateBinary(*sem );
if(*sem == NULL)
{
#if SYS_STATS
++lwip_stats.sys.sem.err;
#endif /* SYS_STATS */
return ERR_MEM;
}
if(count == 0) // Means it can't be taken
{
xSemaphoreTake(*sem,1);
}
#if SYS_STATS
++lwip_stats.sys.sem.used;
if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
}
#endif /* SYS_STATS */
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
/*
Blocks the thread while waiting for the semaphore to be
signaled. If the "timeout" argument is non-zero, the thread should
only be blocked for the specified time (measured in
milliseconds).
If the timeout argument is non-zero, the return value is the number of
milliseconds spent waiting for the semaphore to be signaled. If the
semaphore wasn't signaled within the specified time, the return value is
SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore
(i.e., it was already signaled), the function may return zero.
Notice that lwIP implements a function with a similar name,
sys_sem_wait(), that uses the sys_arch_sem_wait() function.
*/
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
{
portTickType StartTime, EndTime, Elapsed;
StartTime = xTaskGetTickCount();
if( timeout != 0)
{
if( xSemaphoreTake( *sem, timeout / portTICK_RATE_MS ) == pdTRUE )
{
EndTime = xTaskGetTickCount();
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
return (Elapsed); // return time blocked TODO test
}
else
{
return SYS_ARCH_TIMEOUT;
}
}
else // must block without a timeout
{
while( xSemaphoreTake( *sem, portMAX_DELAY) != pdTRUE)
{
;
}
EndTime = xTaskGetTickCount();
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
return ( Elapsed ); // return time blocked
}
}
/*-----------------------------------------------------------------------------------*/
// Signals a semaphore
void sys_sem_signal(sys_sem_t *sem)
{
xSemaphoreGive(*sem);
}
/*-----------------------------------------------------------------------------------*/
// Deallocates a semaphore
void sys_sem_free(sys_sem_t *sem)
{
#if SYS_STATS
--lwip_stats.sys.sem.used;
#endif /* SYS_STATS */
vQueueDelete(*sem);
}
/*-----------------------------------------------------------------------------------*/
int sys_sem_valid(sys_sem_t *sem)
{
if (*sem == SYS_SEM_NULL)
return 0;
else
return 1;
}
/*-----------------------------------------------------------------------------------*/
void sys_sem_set_invalid(sys_sem_t *sem)
{
*sem = SYS_SEM_NULL;
}
/*-----------------------------------------------------------------------------------*/
err_t sys_mutex_trylock(sys_mutex_t *pxMutex)
{
if (xSemaphoreTake(*pxMutex, 0) == pdPASS)
return 0;
else
return -1;
}
/*-----------------------------------------------------------------------------------*/
// Initialize sys arch
void sys_init(void)
{
#if CFG_ENABLE_LWIP_MUTEX
sys_mutex_new(&sys_arch_mutex);
#endif
}
/*-----------------------------------------------------------------------------------*/
/* Mutexes*/
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Create a new mutex*/
err_t sys_mutex_new(sys_mutex_t *mutex) {
*mutex = xSemaphoreCreateMutex();
if(*mutex == NULL)
{
#if SYS_STATS
++lwip_stats.sys.mutex.err;
#endif /* SYS_STATS */
return ERR_MEM;
}
#if SYS_STATS
++lwip_stats.sys.mutex.used;
if (lwip_stats.sys.mutex.max < lwip_stats.sys.mutex.used) {
lwip_stats.sys.mutex.max = lwip_stats.sys.mutex.used;
}
#endif /* SYS_STATS */
return ERR_OK;
}
/*-----------------------------------------------------------------------------------*/
/* Deallocate a mutex*/
void sys_mutex_free(sys_mutex_t *mutex)
{
#if SYS_STATS
--lwip_stats.sys.mutex.used;
#endif /* SYS_STATS */
vQueueDelete(*mutex);
}
/*-----------------------------------------------------------------------------------*/
/* Lock a mutex*/
void sys_mutex_lock(sys_mutex_t *mutex)
{
sys_arch_sem_wait(mutex, BEKEN_WAIT_FOREVER);
}
/*-----------------------------------------------------------------------------------*/
/* Unlock a mutex*/
void sys_mutex_unlock(sys_mutex_t *mutex)
{
xSemaphoreGive(*mutex);
}
/*-----------------------------------------------------------------------------------*/
// TODO
/*-----------------------------------------------------------------------------------*/
/*
Starts a new thread with priority "prio" that will begin its execution in the
function "thread()". The "arg" argument will be passed as an argument to the
thread() function. The id of the new thread is returned. Both the id and
the priority are system dependent.
*/
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread , void *arg, int stacksize, int prio)
{
xTaskHandle CreatedTask;
int result;
result = xTaskCreate( thread, ( portCHAR * ) name, stacksize, arg, prio, &CreatedTask );
if(result == pdPASS)
{
return CreatedTask;
}
else
{
return NULL;
}
}
int sys_thread_delete(xTaskHandle pid)
{
return pdPASS;
}
/*
This optional function does a "fast" critical region protection and returns
the previous protection level. This function is only called during very short
critical regions. An embedded system which supports ISR-based drivers might
want to implement this function by disabling interrupts. Task-based systems
might want to implement this by using a mutex or disabling tasking. This
function should support recursive calls from the same task or interrupt. In
other words, sys_arch_protect() could be called while already protected. In
that case the return value indicates that it is already protected.
sys_arch_protect() is only required if your port is supporting an operating
system.
*/
sys_prot_t sys_arch_protect(void)
{
#if CFG_ENABLE_LWIP_MUTEX
sys_mutex_lock(&sys_arch_mutex);
return 0;
#else
return port_disable_interrupts_flag();
#endif
}
/*
This optional function does a "fast" set of critical region protection to the
value specified by pval. See the documentation for sys_arch_protect() for
more information. This function is only required if your port is supporting
an operating system.
*/
void sys_arch_unprotect(sys_prot_t pval)
{
#if CFG_ENABLE_LWIP_MUTEX
(void)pval;
sys_mutex_unlock(&sys_arch_mutex);
#else
port_enable_interrupts_flag(pval);
#endif
}
/*
* Prints an assertion messages and aborts execution.
*/
void sys_assert( const char *msg )
{
(void) msg;
/*FSL:only needed for debugging*/
os_printf(msg);
os_printf("\n\r");
vPortEnterCritical();
for(;;)
;
}
u32_t sys_now(void)
{
return xTaskGetTickCount() * portTICK_RATE_MS;
}
u32_t sys_jiffies(void)
{
return xTaskGetTickCount() * portTICK_RATE_MS;
}
void sys_arch_msleep(int ms)
{
vTaskDelay(ms / portTICK_RATE_MS);
}
// eof

View File

@@ -14,7 +14,7 @@ set(LWIP_VERSION_REVISION "3")
# LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases
# LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for Git versions
# Numbers 1..31 are reserved for release candidates
set(LWIP_VERSION_RC "1")
set(LWIP_VERSION_RC "LWIP_RC_RELEASE")
if ("${LWIP_VERSION_RC}" STREQUAL "LWIP_RC_RELEASE")
set(LWIP_VERSION_STRING

View File

@@ -1346,7 +1346,7 @@ void
netconn_thread_init(void)
{
sys_sem_t *sem = LWIP_NETCONN_THREAD_SEM_GET();
if ((sem == NULL) || !sys_sem_valid(sem)) {
if (!sys_sem_valid(sem)) {
/* call alloc only once */
LWIP_NETCONN_THREAD_SEM_ALLOC();
LWIP_ASSERT("LWIP_NETCONN_THREAD_SEM_ALLOC() failed", sys_sem_valid(LWIP_NETCONN_THREAD_SEM_GET()));
@@ -1357,7 +1357,7 @@ void
netconn_thread_cleanup(void)
{
sys_sem_t *sem = LWIP_NETCONN_THREAD_SEM_GET();
if ((sem != NULL) && sys_sem_valid(sem)) {
if (sys_sem_valid(sem)) {
/* call free only once */
LWIP_NETCONN_THREAD_SEM_FREE();
}

View File

@@ -128,8 +128,7 @@ lwip_gethostbyname(const char *name)
if (s_hostent.h_addr_list != NULL) {
u8_t idx;
for (idx = 0; s_hostent.h_addr_list[idx]; idx++) {
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip_addr_t *)s_hostent.h_addr_list[idx])));
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa(s_phostent_addr[idx])));
}
}
#endif /* DNS_DEBUG */
@@ -306,7 +305,11 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
/* service name specified: convert to port number
* @todo?: currently, only ASCII integers (port numbers) are supported (AI_NUMERICSERV)! */
port_nr = atoi(servname);
if ((port_nr <= 0) || (port_nr > 0xffff)) {
if (port_nr == 0 && (servname[0] != '0')) {
/* atoi failed - service was not numeric */
return EAI_SERVICE;
}
if ((port_nr < 0) || (port_nr > 0xffff)) {
return EAI_SERVICE;
}
}

View File

@@ -772,7 +772,9 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_len, u16_t length, u
LWIP_DEBUGF(MQTT_DEBUG_WARN,( "mqtt_message_received: Received short packet (payload)\n"));
goto out_disconnect;
}
client->data_cb(client->inpub_arg, var_hdr_payload + payload_offset, payload_length, remaining_length == 0 ? MQTT_DATA_FLAG_LAST : 0);
if (client->data_cb != NULL) {
client->data_cb(client->inpub_arg, var_hdr_payload + payload_offset, payload_length, remaining_length == 0 ? MQTT_DATA_FLAG_LAST : 0);
}
/* Reply if QoS > 0 */
if (remaining_length == 0 && qos > 0) {
/* Send PUBACK for QoS 1 or PUBREC for QoS 2 */

View File

@@ -161,21 +161,25 @@ static void
altcp_tcp_remove_callbacks(struct tcp_pcb *tpcb)
{
tcp_arg(tpcb, NULL);
tcp_recv(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_err(tpcb, NULL);
tcp_poll(tpcb, NULL, tpcb->pollinterval);
if (tpcb->state != LISTEN) {
tcp_recv(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_err(tpcb, NULL);
tcp_poll(tpcb, NULL, tpcb->pollinterval);
}
}
static void
altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
{
tcp_arg(tpcb, conn);
tcp_recv(tpcb, altcp_tcp_recv);
tcp_sent(tpcb, altcp_tcp_sent);
tcp_err(tpcb, altcp_tcp_err);
/* tcp_poll is set when interval is set by application */
/* listen is set totally different :-) */
/* this might be called for LISTN when close fails... */
if (tpcb->state != LISTEN) {
tcp_recv(tpcb, altcp_tcp_recv);
tcp_sent(tpcb, altcp_tcp_sent);
tcp_err(tpcb, altcp_tcp_err);
/* tcp_poll is set when interval is set by application */
}
}
static void

View File

@@ -1120,13 +1120,6 @@ dhcp_bind(struct netif *netif)
}
ip4_addr_copy(gw_addr, dhcp->offered_gw_addr);
/* gateway address not given? */
if (ip4_addr_isany_val(gw_addr)) {
/* copy network address */
ip4_addr_get_network(&gw_addr, &dhcp->offered_ip_addr, &sn_mask);
/* use first host address on network as gateway */
ip4_addr_set_u32(&gw_addr, ip4_addr_get_u32(&gw_addr) | PP_HTONL(0x00000001UL));
}
#if LWIP_DHCP_AUTOIP_COOP
if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
@@ -1354,6 +1347,7 @@ dhcp_release_and_stop(struct netif *netif)
/* create and initialize the DHCP message header */
struct pbuf *p_out;
u16_t options_out_len;
dhcp_set_state(dhcp, DHCP_STATE_OFF);
p_out = dhcp_create_msg(netif, dhcp, DHCP_RELEASE, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
@@ -1373,6 +1367,8 @@ dhcp_release_and_stop(struct netif *netif)
/* remove IP address from interface (prevents routing from selecting this interface) */
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
} else {
dhcp_set_state(dhcp, DHCP_STATE_OFF);
}
#if LWIP_DHCP_AUTOIP_COOP
@@ -1382,8 +1378,6 @@ dhcp_release_and_stop(struct netif *netif)
}
#endif /* LWIP_DHCP_AUTOIP_COOP */
dhcp_set_state(dhcp, DHCP_STATE_OFF);
if (dhcp->pcb_allocated != 0) {
dhcp_dec_pcb_refcount(); /* free DHCP PCB if not needed any more */
dhcp->pcb_allocated = 0;
@@ -1514,6 +1508,7 @@ dhcp_parse_reply(struct pbuf *p, struct dhcp *dhcp)
u8_t *options;
u16_t offset;
u16_t offset_max;
u16_t options_offset;
u16_t options_idx;
u16_t options_idx_max;
struct pbuf *q;
@@ -1546,6 +1541,7 @@ dhcp_parse_reply(struct pbuf *p, struct dhcp *dhcp)
options_idx_max = p->tot_len;
again:
q = p;
options_offset = options_idx;
while ((q != NULL) && (options_idx >= q->len)) {
options_idx = (u16_t)(options_idx - q->len);
options_idx_max = (u16_t)(options_idx_max - q->len);
@@ -1619,7 +1615,7 @@ again:
case (DHCP_OPTION_OVERLOAD):
LWIP_DHCP_INPUT_ERROR("len == 1", len == 1, return ERR_VAL;);
/* decode overload only in options, not in file/sname: invalid packet */
LWIP_DHCP_INPUT_ERROR("overload in file/sname", options_idx == DHCP_OPTIONS_OFS, return ERR_VAL;);
LWIP_DHCP_INPUT_ERROR("overload in file/sname", options_offset == DHCP_OPTIONS_OFS, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_OVERLOAD;
break;
case (DHCP_OPTION_MESSAGE_TYPE):

View File

@@ -983,6 +983,14 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q)
/* We don't re-send arp request in etharp_tmr, but we still queue packets,
since this failure could be temporary, and the next packet calling
etharp_query again could lead to sending the queued packets. */
} else {
/* ARP request successfully sent */
if ((arp_table[i].state == ETHARP_STATE_PENDING) && !is_new_entry) {
/* A new ARP request has been sent for a pending entry. Reset the ctime to
not let it expire too fast. */
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: reset ctime for entry %"S16_F"\n", (s16_t)i));
arp_table[i].ctime = 0;
}
}
if (q == NULL) {
return result;

View File

@@ -408,6 +408,51 @@ ip4_input_accept(struct netif *netif)
return 0;
}
#if LWIP_RIPPLE20
/**
* parse ipv4 IP options
* return: < 0 if IP options contain invalid option, = 0 Ok.
*/
int ip4_parse_opt(u8 *opt, int len)
{
int ret = 0;
u8 type, item_len;
while (len > 1) {
type = *opt;
opt++;
item_len = *opt;
len -= item_len;
opt++;
/* avoid infinite recusive */
if (type != 0 && item_len == 0)
return -1;
switch (type) {
case 0:
/* End of Option List */
return ret;
case 7: {
/* RR Option */
u8 *pointer = opt;
if (*pointer < 4 || (*pointer % 4))
return -1;
break;
}
}
/* Forward to next option */
opt += item_len - 2;
}
return ret;
}
#endif /* LWIP_RIPPLE20 */
/**
* This function is called by the network interface device driver when
* an IP packet is received. The function does the basic checks of the
@@ -470,6 +515,18 @@ ip4_input(struct pbuf *p, struct netif *inp)
pbuf_realloc(p, iphdr_len);
}
#if LWIP_RIPPLE20
/* Parse IP options */
if (iphdr_hlen > 20) {
u8 *opt = (u8*)p->payload;
if (ip4_parse_opt(opt + 20, iphdr_hlen - 20)) {
pbuf_free(p);
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IP packet dropped due to invalid IP options\n"));
return ERR_OK;
}
}
#endif
/* header length exceeds first pbuf length, or ip length exceeds total pbuf length? */
if ((iphdr_hlen > p->len) || (iphdr_len > p->tot_len) || (iphdr_hlen < IP_HLEN)) {
if (iphdr_hlen < IP_HLEN) {

View File

@@ -173,6 +173,8 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr)
}
for (;;) {
if (lwip_isdigit(c)) {
if((base == 8) && ((u32_t)(c - '0') >= 8))
break;
val = (val * base) + (u32_t)(c - '0');
c = *++cp;
} else if (base == 16 && lwip_isxdigit(c)) {

View File

@@ -1305,6 +1305,7 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
ip6_addr_copy_from_packed(src_addr, ip6hdr->src);
ip6_addr_copy_from_packed(dest_addr, ip6hdr->dest);
netif = ip6_route(&src_addr, &dest_addr);
dest = &dest_addr;
}
if (netif == NULL) {
@@ -1364,6 +1365,7 @@ ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest,
ip6_addr_copy_from_packed(src_addr, ip6hdr->src);
ip6_addr_copy_from_packed(dest_addr, ip6hdr->dest);
netif = ip6_route(&src_addr, &dest_addr);
dest = &dest_addr;
}
if (netif == NULL) {

View File

@@ -781,7 +781,7 @@ ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest)
return ERR_MEM;
}
LWIP_ASSERT("this needs a pbuf in one piece!",
(p->len >= (IP6_HLEN)));
(rambuf->len >= (IP6_HLEN)));
SMEMCPY(rambuf->payload, original_ip6hdr, IP6_HLEN);
ip6hdr = (struct ip6_hdr *)rambuf->payload;
frag_hdr = (struct ip6_frag_hdr *)((u8_t*)rambuf->payload + IP6_HLEN);

View File

@@ -180,13 +180,13 @@ mem_trim(void *mem, mem_size_t size)
* allow these defines to be overridden.
*/
#ifndef mem_clib_free
#define mem_clib_free free
#define mem_clib_free os_free
#endif
#ifndef mem_clib_malloc
#define mem_clib_malloc malloc
#define mem_clib_malloc os_malloc
#endif
#ifndef mem_clib_calloc
#define mem_clib_calloc calloc
#define mem_clib_calloc os_calloc
#endif
#if LWIP_STATS && MEM_STATS

View File

@@ -890,7 +890,7 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
lpcb->state = LISTEN;
lpcb->prio = pcb->prio;
lpcb->so_options = pcb->so_options;
lpcb->netif_idx = NETIF_NO_INDEX;
lpcb->netif_idx = pcb->netif_idx;
lpcb->ttl = pcb->ttl;
lpcb->tos = pcb->tos;
#if LWIP_IPV4 && LWIP_IPV6

View File

@@ -54,7 +54,7 @@ extern "C" {
/** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
/** period (in milliseconds) of the application calling dhcp_fine_tmr() */
#define DHCP_FINE_TIMER_MSECS 500
#define DHCP_FINE_TIMER_MSECS 100
#define DHCP_BOOT_FILE_LEN 128U

View File

@@ -58,7 +58,7 @@ extern "C" {
/** For release candidates, this is set to 1..254
* For official releases, this is set to 255 (LWIP_RC_RELEASE)
* For development versions (Git), this is set to 0 (LWIP_RC_DEVELOPMENT) */
#define LWIP_VERSION_RC 1
#define LWIP_VERSION_RC LWIP_RC_RELEASE
/** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */
#define LWIP_RC_RELEASE 255

View File

@@ -828,6 +828,14 @@
#if !defined IP_FORWARD_ALLOW_TX_ON_RX_NETIF || defined __DOXYGEN__
#define IP_FORWARD_ALLOW_TX_ON_RX_NETIF 0
#endif
/**
* LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS==1: randomize the local port for the first
* local TCP/UDP pcb (default==0). This can prevent creating predictable port
* numbers after booting a device.
*/
#if !defined LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS || defined __DOXYGEN__
#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS 1
#endif
/**
* @}
*/

View File

@@ -68,6 +68,7 @@ enum lwip_ieee_eth_type {
ETHTYPE_PPPOE = 0x8864U,
/** Jumbo Frames */
ETHTYPE_JUMBO = 0x8870U,
ETHTYPE_EAPOL = 0x888EU,
/** Process field network */
ETHTYPE_PROFINET = 0x8892U,
/** Ethernet for control automation technology */

View File

@@ -40,6 +40,7 @@
#define LWIP_HDR_SOCKETS_H
#include "lwip/opt.h"
#include "mem_pub.h"
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
@@ -476,7 +477,7 @@ typedef struct ipv6_mreq {
#define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] | (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))))
#define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7))))
#define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
#define FD_ZERO(p) os_memset((void*)(p), 0, sizeof(*(p)))
typedef struct fd_set
{
@@ -515,7 +516,7 @@ struct pollfd
/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
* by your system, set this to 0 and include <sys/time.h> in cc.h */
#ifndef LWIP_TIMEVAL_PRIVATE
#define LWIP_TIMEVAL_PRIVATE 1
#define LWIP_TIMEVAL_PRIVATE 0
#endif
#if LWIP_TIMEVAL_PRIVATE

View File

@@ -38,6 +38,7 @@
#define LWIP_HDR_SYS_H
#include "lwip/opt.h"
#include "rtos_pub.h"
#ifdef __cplusplus
extern "C" {
@@ -120,6 +121,8 @@ typedef void (*lwip_thread_fn)(void *arg);
#else /* LWIP_COMPAT_MUTEX */
typedef beken_mutex_t sys_mutex_t;
/**
* @ingroup sys_mutex
* Create a new mutex.

View File

@@ -216,7 +216,8 @@ static err_t ppp_netif_output(struct netif *netif, struct pbuf *pb, u16_t protoc
/***********************************/
#if PPP_AUTH_SUPPORT
void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd) {
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD", pcb->phase == PPP_PHASE_DEAD);
#if PAP_SUPPORT
pcb->settings.refuse_pap = !(authtype & PPPAUTHTYPE_PAP);
#endif /* PAP_SUPPORT */
@@ -238,6 +239,8 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas
#if MPPE_SUPPORT
/* Set MPPE configuration */
void ppp_set_mppe(ppp_pcb *pcb, u8_t flags) {
LWIP_ASSERT("pcb->phase == PPP_PHASE_DEAD", pcb->phase == PPP_PHASE_DEAD);
if (flags == PPP_MPPE_DISABLE) {
pcb->settings.require_mppe = 0;
return;

View File

@@ -9,7 +9,7 @@
#error "This tests needs LWIP_NETIF_EXT_STATUS_CALLBACK enabled"
#endif
struct netif net_test;
static struct netif net_test;
/* Setups/teardown functions */
@@ -215,13 +215,67 @@ START_TEST(test_netif_extcallbacks)
}
END_TEST
START_TEST(test_netif_flag_set)
{
ip4_addr_t addr;
ip4_addr_t netmask;
ip4_addr_t gw;
LWIP_UNUSED_ARG(_i);
IP4_ADDR(&addr, 0, 0, 0, 0);
IP4_ADDR(&netmask, 0, 0, 0, 0);
IP4_ADDR(&gw, 0, 0, 0, 0);
netif_add(&net_test, &addr, &netmask, &gw, &net_test, testif_init, ethernet_input);
fail_if(netif_is_flag_set(&net_test, NETIF_FLAG_UP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_BROADCAST));
fail_if(netif_is_flag_set(&net_test, NETIF_FLAG_LINK_UP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_ETHARP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_ETHERNET));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_IGMP));
fail_unless(netif_is_flag_set(&net_test, NETIF_FLAG_MLD6));
netif_remove(&net_test);
}
END_TEST
START_TEST(test_netif_find)
{
struct netif net0;
struct netif net1;
LWIP_UNUSED_ARG(_i);
/* No netifs available */
fail_unless(netif_find("ch0") == NULL);
/* Add netifs with known names */
fail_unless(netif_add_noaddr(&net0, NULL, testif_init, ethernet_input) == &net0);
net0.num = 0;
fail_unless(netif_add_noaddr(&net1, NULL, testif_init, ethernet_input) == &net1);
net1.num = 1;
fail_unless(netif_find("ch0") == &net0);
fail_unless(netif_find("CH0") == NULL);
fail_unless(netif_find("ch1") == &net1);
fail_unless(netif_find("ch3") == NULL);
/* atoi failure is not treated as zero */
fail_unless(netif_find("chX") == NULL);
fail_unless(netif_find("ab0") == NULL);
netif_remove(&net0);
netif_remove(&net1);
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
netif_suite(void)
{
testfunc tests[] = {
TESTFUNC(test_netif_extcallbacks)
TESTFUNC(test_netif_extcallbacks),
TESTFUNC(test_netif_flag_set),
TESTFUNC(test_netif_find)
};
return create_suite("NETIF", tests, sizeof(tests)/sizeof(testfunc), netif_setup, netif_teardown);
}

View File

@@ -6,7 +6,7 @@
#include "lwip/etharp.h"
#include "netif/ethernet.h"
struct netif net_test;
static struct netif net_test;
static const u8_t broadcast[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

View File

@@ -287,6 +287,43 @@ START_TEST(test_ip6_lladdr)
}
END_TEST
/* Reproduces bug #57374 */
START_TEST(test_ip6_frag_pbuf_len_assert)
{
ip_addr_t my_addr = IPADDR6_INIT_HOST(0x20010db8, 0x0, 0x0, 0x1);
ip_addr_t peer_addr = IPADDR6_INIT_HOST(0x20010db8, 0x0, 0x0, 0x4);
struct pbuf *payload, *hdr;
err_t err;
int i;
/* Configure and enable local address */
test_netif6.mtu = 1500;
netif_set_up(&test_netif6);
netif_ip6_addr_set(&test_netif6, 0, ip_2_ip6(&my_addr));
netif_ip6_addr_set_state(&test_netif6, 0, IP6_ADDR_VALID);
/* Create packet with lots of small pbufs around mtu limit */
payload = pbuf_alloc(PBUF_RAW, 1400, PBUF_POOL);
fail_unless(payload != NULL);
for (i = 0; i < 16; i++) {
struct pbuf *p = pbuf_alloc(PBUF_RAW, 32, PBUF_RAM);
fail_unless(p != NULL);
pbuf_cat(payload, p);
}
/* Prefix with header like UDP would */
hdr = pbuf_alloc(PBUF_IP, 8, PBUF_RAM);
fail_unless(hdr != NULL);
pbuf_chain(hdr, payload);
/* Send it and don't crash while fragmenting */
err = ip6_output_if_src(hdr, ip_2_ip6(&my_addr), ip_2_ip6(&peer_addr), 15, 0, IP_PROTO_UDP, &test_netif6);
fail_unless(err == ERR_OK);
pbuf_free(hdr);
pbuf_free(payload);
}
END_TEST
/** Create the suite including all tests for this module */
Suite *
ip6_suite(void)
@@ -296,7 +333,8 @@ ip6_suite(void)
TESTFUNC(test_ip6_aton_ipv4mapped),
TESTFUNC(test_ip6_ntoa_ipv4mapped),
TESTFUNC(test_ip6_ntoa),
TESTFUNC(test_ip6_lladdr)
TESTFUNC(test_ip6_lladdr),
TESTFUNC(test_ip6_frag_pbuf_len_assert)
};
return create_suite("IPv6", tests, sizeof(tests)/sizeof(testfunc), ip6_setup, ip6_teardown);
}

View File

@@ -13,6 +13,7 @@
#define EXPECT_RETX(x, y) do { fail_unless(x); if(!(x)) { return y; }} while(0)
#define EXPECT_RETNULL(x) EXPECT_RETX(x, NULL)
#if (CHECK_MAJOR_VERSION == 0 && CHECK_MINOR_VERSION < 13)
typedef struct {
TFun func;
const char *name;
@@ -24,6 +25,15 @@ typedef struct {
#define tcase_add_named_test(tc,tf) \
_tcase_add_test((tc),(tf).func,(tf).name,0, 0, 0, 1)
#else
/* From 0.13.0 check keeps track of the method name internally */
typedef const TTest * testfunc;
#define TESTFUNC(x) x
#define tcase_add_named_test(tc,tf) tcase_add_test(tc,tf)
#endif
/** typedef for a function returning a test suite */
typedef Suite* (suite_getter_fn)(void);