mirror of
https://github.com/openharmony/kernel_uniproton.git
synced 2026-07-18 16:54:29 -04:00
@@ -233,7 +233,10 @@ static_library("libkernel") {
|
||||
}
|
||||
|
||||
group("kernel") {
|
||||
deps = [ ":libkernel" ]
|
||||
deps = [
|
||||
":libkernel",
|
||||
"components",
|
||||
]
|
||||
}
|
||||
|
||||
executable("uniproton") {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "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 COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS 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.
|
||||
|
||||
group("components") {
|
||||
deps = [
|
||||
"net",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "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 COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS 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.
|
||||
|
||||
group("net") {
|
||||
deps = [
|
||||
"lwip-2.1",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "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 COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS 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.
|
||||
|
||||
import("//third_party/lwip/lwip.gni")
|
||||
import("//kernel/uniproton/components/net/lwip-2.1/lwip_porting.gni")
|
||||
|
||||
static_library("lwip-2.1") {
|
||||
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <lwip/sys.h>
|
||||
#include <lwip/etharp.h>
|
||||
#include <lwip/netifapi.h>
|
||||
#include <lwip/priv/api_msg.h>
|
||||
|
||||
#if LWIP_DHCP
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/prot/dhcp.h>
|
||||
|
||||
err_t dhcp_is_bound(struct netif *netif)
|
||||
{
|
||||
struct dhcp *dhcp = NULL;
|
||||
|
||||
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG);
|
||||
|
||||
dhcp = netif_dhcp_data(netif);
|
||||
LWIP_ERROR("netif->dhcp != NULL", (dhcp != NULL), return ERR_ARG);
|
||||
|
||||
if (dhcp->state == DHCP_STATE_BOUND) {
|
||||
return ERR_OK;
|
||||
} else {
|
||||
return ERR_INPROGRESS;
|
||||
}
|
||||
}
|
||||
#endif /* LWIP_DHCP */
|
||||
|
||||
static struct netif *netif_find_by_name(const char *name)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
NETIF_FOREACH(netif) {
|
||||
if (strcmp("lo", name) == 0 && (netif->name[0] == 'l' && netif->name[1] == 'o')) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: found lo\n"));
|
||||
return netif;
|
||||
}
|
||||
|
||||
if (strcmp(netif->full_name, name) == 0) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: found %s\n", name));
|
||||
return netif;
|
||||
}
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find_by_name: didn't find %s\n", name));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static err_t netifapi_do_find_by_name(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
msg->netif = netif_find_by_name(msg->msg.ifs.name);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
struct netif *netifapi_netif_find_by_name(const char *name)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
API_VAR_DECLARE(struct netifapi_msg, msg);
|
||||
API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, msg, ERR_MEM);
|
||||
API_VAR_REF(msg).netif = NULL;
|
||||
#if LWIP_MPU_COMPATIBLE
|
||||
if (strncpy_s(API_VAR_REF(msg).msg.ifs.name, NETIF_NAMESIZE, name, NETIF_NAMESIZE - 1)) {
|
||||
API_VAR_FREE(MEMP_NETIFAPI_MSG, msg);
|
||||
return netif;
|
||||
}
|
||||
API_VAR_REF(msg).msg.ifs.name[NETIF_NAMESIZE - 1] = '\0';
|
||||
#else
|
||||
API_VAR_REF(msg).msg.ifs.name = (char *)name;
|
||||
#endif /* LWIP_MPU_COMPATIBLE */
|
||||
|
||||
(void)tcpip_api_call(netifapi_do_find_by_name, &API_VAR_REF(msg).call);
|
||||
netif = msg.netif;
|
||||
API_VAR_FREE(MEMP_NETIFAPI_MSG, msg);
|
||||
|
||||
return netif;
|
||||
}
|
||||
|
||||
#if LWIP_IPV6
|
||||
int ip6addr_aton(const char *cp, ip6_addr_t *addr)
|
||||
{
|
||||
const int ipv6_blocks = 8;
|
||||
u16_t current_block_index = 0;
|
||||
u16_t current_block_value = 0;
|
||||
u16_t addr16[ipv6_blocks];
|
||||
u16_t *a16 = (u16_t *)addr->addr;
|
||||
int squash_pos = ipv6_blocks;
|
||||
int i;
|
||||
int num5 = 5;
|
||||
int num16 = 16;
|
||||
const unsigned char *sc = (const unsigned char *)cp;
|
||||
const char *ss = cp-1;
|
||||
|
||||
for (; ; sc++) {
|
||||
if (current_block_index >= ipv6_blocks) {
|
||||
return 0; // address too long
|
||||
}
|
||||
if (*sc == 0) {
|
||||
if (sc - ss == 1) {
|
||||
if (squash_pos != current_block_index) {
|
||||
return 0; // empty address or address ends with a single ':'
|
||||
} // else address ends with one valid "::"
|
||||
} else {
|
||||
addr16[current_block_index++] = current_block_value;
|
||||
}
|
||||
break;
|
||||
} else if (*sc == ':') {
|
||||
if (sc - ss == 1) {
|
||||
if (sc != cp || sc[1] != ':') {
|
||||
return 0; // address begins with a single ':' or contains ":::"
|
||||
} // else address begins with one valid "::"
|
||||
} else {
|
||||
addr16[current_block_index++] = current_block_value;
|
||||
}
|
||||
if (sc[1] == ':') {
|
||||
if (squash_pos != ipv6_blocks) {
|
||||
return 0; // more than one "::"
|
||||
}
|
||||
squash_pos = current_block_index;
|
||||
sc++;
|
||||
}
|
||||
ss = sc; // ss points to the recent ':' position
|
||||
current_block_value = 0;
|
||||
} else if (lwip_isxdigit(*sc) && (sc - ss) < num5) { // 4 hex-digits at most
|
||||
current_block_value = (current_block_value << 4) +
|
||||
(*sc | ('a' - 'A')) - '0' - ('a' - '9' - 1) * (*sc >= 'A');
|
||||
#if LWIP_IPV4
|
||||
} else if (*sc == '.' && current_block_index < ipv6_blocks - 1) {
|
||||
ip4_addr_t ip4;
|
||||
int ret = ip4addr_aton(ss+1, &ip4);
|
||||
if (!ret) {
|
||||
return 0;
|
||||
}
|
||||
ip4.addr = lwip_ntohl(ip4.addr);
|
||||
addr16[current_block_index++] = (u16_t)(ip4.addr >> num16);
|
||||
addr16[current_block_index++] = (u16_t)(ip4.addr);
|
||||
break;
|
||||
#endif /* LWIP_IPV4 */
|
||||
} else {
|
||||
return 0; // unexpected char or too many digits
|
||||
}
|
||||
}
|
||||
|
||||
if (squash_pos == ipv6_blocks && current_block_index != ipv6_blocks) {
|
||||
return 0; // address too short
|
||||
}
|
||||
if (squash_pos != ipv6_blocks && current_block_index == ipv6_blocks) {
|
||||
return 0; // unexpected "::" in address
|
||||
}
|
||||
|
||||
for (i = 0; i < squash_pos; ++i) {
|
||||
a16[i] = lwip_htons(addr16[i]);
|
||||
}
|
||||
for (; i < ipv6_blocks - current_block_index + squash_pos; ++i) {
|
||||
a16[i] = 0;
|
||||
}
|
||||
for (; i < ipv6_blocks; ++i) {
|
||||
a16[i] = lwip_htons(addr16[i - ipv6_blocks + current_block_index]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* LWIP_IPV6 */
|
||||
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_IFADDRS
|
||||
#if (LWIP_IPV4 || LWIP_IPV6) && LWIP_SOCKET
|
||||
#include "ifaddrs.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/tcpip.h"
|
||||
#include "lwip/priv/sockets_priv.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/dhcp.h"
|
||||
|
||||
struct ifaddrs_storage {
|
||||
struct ifaddrs ifa;
|
||||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in s4;
|
||||
#if LWIP_IPV6
|
||||
struct sockaddr_in6 s6;
|
||||
#endif
|
||||
} addr, netmask, dstaddr;
|
||||
char name[IFNAMSIZ];
|
||||
};
|
||||
|
||||
struct getifaddrs_arg {
|
||||
struct ifaddrs **ifap;
|
||||
sys_sem_t cb_completed;
|
||||
int ret;
|
||||
};
|
||||
|
||||
static int tcpip_init_finish = 1;
|
||||
void lwip_freeifaddrs(struct ifaddrs *ifa);
|
||||
static void ifaddrs_add_tail(struct ifaddrs **ifap, struct ifaddrs *ifaddr)
|
||||
{
|
||||
struct ifaddrs *temp = NULL;
|
||||
|
||||
ifaddr->ifa_next = NULL;
|
||||
if (*ifap == NULL) {
|
||||
*ifap = ifaddr;
|
||||
return;
|
||||
}
|
||||
|
||||
for (temp = *ifap; temp->ifa_next != NULL; temp = temp->ifa_next) {
|
||||
/* nothing */
|
||||
}
|
||||
|
||||
temp->ifa_next = ifaddr;
|
||||
}
|
||||
|
||||
static struct ifaddrs_storage *new_ifaddrs_storage(void)
|
||||
{
|
||||
struct ifaddrs *ifaddr = NULL;
|
||||
struct ifaddrs_storage *if_storage = NULL;
|
||||
|
||||
if_storage = (struct ifaddrs_storage *)mem_malloc(sizeof(struct ifaddrs_storage));
|
||||
if (if_storage != NULL) {
|
||||
(void)memset_s((void*)if_storage, sizeof(struct ifaddrs_storage), 0, sizeof(struct ifaddrs_storage));
|
||||
ifaddr = &if_storage->ifa;
|
||||
ifaddr->ifa_name = if_storage->name;
|
||||
ifaddr->ifa_addr = &if_storage->addr.sa;
|
||||
ifaddr->ifa_netmask = &if_storage->netmask.sa;
|
||||
ifaddr->ifa_dstaddr = &if_storage->dstaddr.sa;
|
||||
}
|
||||
|
||||
return if_storage;
|
||||
}
|
||||
|
||||
static int get_ifa_name(struct netif *netif, struct ifaddrs *ifaddr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
ifaddr->ifa_flags |= IFF_LOOPBACK;
|
||||
ret = snprintf_s(ifaddr->ifa_name, NETIF_NAMESIZE, (NETIF_NAMESIZE - 1), "%.2s", netif->name);
|
||||
} else {
|
||||
ret = snprintf_s(ifaddr->ifa_name, NETIF_NAMESIZE, (NETIF_NAMESIZE - 1), "%s", netif_get_name(netif));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if LWIP_IPV4
|
||||
static int get_ipv4_ifaddr(struct netif *netif, struct ifaddrs *ifaddr)
|
||||
{
|
||||
struct sockaddr_in *addr_in = NULL;
|
||||
|
||||
if (netif->flags & NETIF_FLAG_UP) {
|
||||
ifaddr->ifa_flags |= IFF_UP;
|
||||
}
|
||||
|
||||
if (netif->flags & NETIF_FLAG_ETHARP) {
|
||||
ifaddr->ifa_flags = ifaddr->ifa_flags & ((unsigned int)(~IFF_NOARP));
|
||||
} else {
|
||||
ifaddr->ifa_flags |= IFF_NOARP;
|
||||
}
|
||||
|
||||
if (netif->flags & NETIF_FLAG_BROADCAST) {
|
||||
ifaddr->ifa_flags |= IFF_BROADCAST;
|
||||
}
|
||||
|
||||
#if LWIP_DHCP
|
||||
if (dhcp_supplied_address(netif)) {
|
||||
ifaddr->ifa_flags |= IFF_DYNAMIC;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LWIP_IGMP
|
||||
if (netif->flags & NETIF_FLAG_IGMP) {
|
||||
ifaddr->ifa_flags |= IFF_MULTICAST;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (netif->flags & NETIF_FLAG_LINK_UP) {
|
||||
ifaddr->ifa_flags |= IFF_RUNNING;
|
||||
}
|
||||
|
||||
#if LWIP_HAVE_LOOPIF
|
||||
if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
addr_in = (struct sockaddr_in *)ifaddr->ifa_addr;
|
||||
addr_in->sin_family = AF_INET;
|
||||
addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->ip_addr)->addr;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
addr_in = (struct sockaddr_in *)ifaddr->ifa_addr;
|
||||
addr_in->sin_family = AF_INET;
|
||||
addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->ip_addr)->addr;
|
||||
|
||||
addr_in = (struct sockaddr_in *)ifaddr->ifa_netmask;
|
||||
addr_in->sin_family = AF_INET;
|
||||
addr_in->sin_addr.s_addr = ((ip4_addr_t *)&netif->netmask)->addr;
|
||||
|
||||
addr_in = (struct sockaddr_in *)ifaddr->ifa_broadaddr;
|
||||
addr_in->sin_family = AF_INET;
|
||||
addr_in->sin_addr.s_addr = (((ip4_addr_t *)&netif->ip_addr)->addr & ((ip4_addr_t *)&netif->netmask)->addr) |
|
||||
~((ip4_addr_t *)&netif->netmask)->addr;
|
||||
}
|
||||
|
||||
return get_ifa_name(netif, ifaddr);
|
||||
}
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
#if LWIP_IPV6
|
||||
/* Stack support to retrieve the below flags for ipv6
|
||||
IFF_UP
|
||||
IFF_MULTICAST
|
||||
IFF_RUNNING
|
||||
IFF_LOOPBACK
|
||||
*/
|
||||
static int get_ipv6_ifaddr(struct netif *netif, struct ifaddrs *ifaddr, int tmp_index)
|
||||
{
|
||||
struct sockaddr_in6 *addr_in6 = NULL;
|
||||
|
||||
/* As of now supports the below falgs only */
|
||||
if (netif->flags & NETIF_FLAG_UP) {
|
||||
ifaddr->ifa_flags |= IFF_UP;
|
||||
}
|
||||
|
||||
#if LWIP_IPV6_MLD
|
||||
if (netif->flags & NETIF_FLAG_MLD6) {
|
||||
ifaddr->ifa_flags |= IFF_MULTICAST;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (netif->flags & NETIF_FLAG_LINK_UP) {
|
||||
ifaddr->ifa_flags |= IFF_RUNNING;
|
||||
}
|
||||
|
||||
addr_in6 = (struct sockaddr_in6 *)ifaddr->ifa_addr;
|
||||
addr_in6->sin6_family = AF_INET6;
|
||||
inet6_addr_from_ip6addr(&addr_in6->sin6_addr, (ip6_addr_t *)&netif->ip6_addr[tmp_index]);
|
||||
|
||||
return get_ifa_name(netif, ifaddr);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void getifaddrs_internal(struct getifaddrs_arg *arg)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
struct ifaddrs *ifaddr = NULL;
|
||||
struct ifaddrs_storage *if_storage = NULL;
|
||||
|
||||
#if LWIP_IPV6
|
||||
int n;
|
||||
#endif
|
||||
|
||||
arg->ret = ENOMEM;
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
#if LWIP_IPV4
|
||||
if_storage = new_ifaddrs_storage();
|
||||
if (if_storage == NULL) {
|
||||
lwip_freeifaddrs(
|
||||
*(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */
|
||||
arg->ret = ENOMEM;
|
||||
goto RETURN;
|
||||
}
|
||||
|
||||
/* if get one or more netif info, then getifaddrs return 0(OK) */
|
||||
arg->ret = 0;
|
||||
ifaddr = &if_storage->ifa;
|
||||
(void)get_ipv4_ifaddr(netif, ifaddr);
|
||||
ifaddrs_add_tail(arg->ifap, ifaddr);
|
||||
#endif /* LWIP_IPV4 */
|
||||
#if LWIP_IPV6
|
||||
for (n = 0; n < LWIP_IPV6_NUM_ADDRESSES; n++) {
|
||||
if ((netif->ip6_addr_state[n] & IP6_ADDR_VALID) == 0) {
|
||||
continue;
|
||||
}
|
||||
if_storage = new_ifaddrs_storage();
|
||||
if (if_storage == NULL) {
|
||||
lwip_freeifaddrs(
|
||||
*(arg->ifap)); /* ifap is assigned to NULL in getifaddrs, so garbage value will not be there */
|
||||
arg->ret = ENOMEM;
|
||||
goto RETURN;
|
||||
}
|
||||
|
||||
/* if get one or more netif info, then getifaddrs return 0(OK) */
|
||||
arg->ret = 0;
|
||||
ifaddr = &if_storage->ifa;
|
||||
(void)get_ipv6_ifaddr(netif, ifaddr, n);
|
||||
ifaddrs_add_tail(arg->ifap, ifaddr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
RETURN:
|
||||
#if !LWIP_TCPIP_CORE_LOCKING
|
||||
sys_sem_signal(&arg->cb_completed);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
int lwip_getifaddrs(struct ifaddrs **ifap)
|
||||
{
|
||||
struct getifaddrs_arg arg;
|
||||
|
||||
LWIP_ERROR("lwip_getifaddrs : ifap is NULL", (ifap != NULL), return ERR_ARG);
|
||||
*ifap = NULL;
|
||||
|
||||
if (!tcpip_init_finish) {
|
||||
set_errno(EACCES);
|
||||
return -1;
|
||||
}
|
||||
arg.ret = 0;
|
||||
arg.ifap = ifap;
|
||||
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
LOCK_TCPIP_CORE();
|
||||
getifaddrs_internal(&arg);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
#else
|
||||
|
||||
if (sys_sem_new(&arg.cb_completed, 0) != ERR_OK) {
|
||||
set_errno(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tcpip_callback((tcpip_callback_fn)getifaddrs_internal, &arg);
|
||||
(void)sys_arch_sem_wait(&arg.cb_completed, 0);
|
||||
sys_sem_free(&arg.cb_completed);
|
||||
#endif
|
||||
|
||||
if (arg.ret != 0) {
|
||||
set_errno(arg.ret);
|
||||
*ifap = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void freeifaddrs_iteration(struct ifaddrs *ifa)
|
||||
{
|
||||
if (ifa == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ifa->ifa_next != NULL) {
|
||||
freeifaddrs_iteration(ifa->ifa_next);
|
||||
}
|
||||
|
||||
mem_free(ifa);
|
||||
}
|
||||
|
||||
void lwip_freeifaddrs(struct ifaddrs *ifa)
|
||||
{
|
||||
freeifaddrs_iteration(ifa);
|
||||
}
|
||||
|
||||
int getifaddrs(struct ifaddrs **ifap)
|
||||
{
|
||||
return lwip_getifaddrs(ifap);
|
||||
}
|
||||
|
||||
void freeifaddrs(struct ifaddrs *ifa)
|
||||
{
|
||||
lwip_freeifaddrs(ifa);
|
||||
}
|
||||
|
||||
#endif /* (LWIP_IPV4 || LWIP_IPV6) && LWIP_SOCKET */
|
||||
#endif /* LWIP_IFADDRS */
|
||||
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "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 COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS 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.
|
||||
|
||||
LWIP_PORTING_DIR = get_path_info(".", "abspath")
|
||||
|
||||
LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ]
|
||||
|
||||
LWIP_PORTING_FILES = [
|
||||
"$LWIP_PORTING_DIR/porting/src/driverif.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/netdb_porting.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/sockets_porting.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/sys_arch.c",
|
||||
"$LWIP_PORTING_DIR/enhancement/src/fixme.c",
|
||||
"$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c",
|
||||
]
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_CC_H_
|
||||
#define _LWIP_PORTING_CC_H_
|
||||
|
||||
#ifdef LITTLE_ENDIAN
|
||||
#undef LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifdef BIG_ENDIAN
|
||||
#undef BIG_ENDIAN
|
||||
#endif
|
||||
|
||||
#include <endian.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef htons
|
||||
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
|
||||
#endif
|
||||
|
||||
#define SOCKLEN_T_DEFINED
|
||||
#define SA_FAMILY_T_DEFINED
|
||||
#define IN_PORT_T_DEFINED
|
||||
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#define LWIP_ERRNO_STDINCLUDE
|
||||
#define LWIP_SOCKET_STDINCLUDE
|
||||
|
||||
#define LWIP_DNS_API_DEFINE_ERRORS 0
|
||||
#define LWIP_DNS_API_DEFINE_FLAGS 0
|
||||
#define LWIP_DNS_API_DECLARE_STRUCTS 0
|
||||
#define LWIP_DNS_API_DECLARE_H_ERRNO 0
|
||||
|
||||
#ifndef __SIZEOF_POINTER__
|
||||
#define __SIZEOF_POINTER__ 4 // 32 bit system
|
||||
#endif
|
||||
|
||||
#define OS_TASK_STATUS_DETACHED 0x0100 // reserved
|
||||
|
||||
#if defined(__arm__) && defined(__ARMCC_VERSION)
|
||||
/* Keil uVision4 tools */
|
||||
#define PACK_STRUCT_BEGIN __packed
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(fld) fld
|
||||
#define ALIGNED(n) __align(n)
|
||||
#elif defined (__IAR_SYSTEMS_ICC__)
|
||||
/* IAR Embedded Workbench tools */
|
||||
#define PACK_STRUCT_BEGIN __packed
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(fld) fld
|
||||
// #error NEEDS ALIGNED
|
||||
#else
|
||||
/* GCC tools (CodeSourcery) */
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(fld) fld
|
||||
#define ALIGNED(n) __attribute__((aligned (n)))
|
||||
#endif
|
||||
|
||||
#define LWIP_RAND rand
|
||||
|
||||
#ifndef LWIP_LOGGER
|
||||
#define LWIP_LOGGER(msg)
|
||||
#endif
|
||||
|
||||
extern void LwipLogPrintf(const char *fmt, ...);
|
||||
#define LWIP_PLATFORM_DIAG(vars) LwipLogPrintf vars
|
||||
#define LWIP_PLATFORM_ASSERT(x) do { \
|
||||
LWIP_PLATFORM_DIAG(("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__)); \
|
||||
} while (0)
|
||||
|
||||
#define init_waitqueue_head(...)
|
||||
#define poll_check_waiters(...)
|
||||
|
||||
#ifndef _BSD_SOURCE
|
||||
#define _BSD_SOURCE 1
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_PORTING_CC_H_ */
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_PERF_H_
|
||||
#define _LWIP_PORTING_PERF_H_
|
||||
|
||||
#if LWIP_PERF
|
||||
|
||||
#define PERF_START do { } while (0)
|
||||
#define PERF_STOP(x) do { } while (0)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_PORTING_PERF_H_ */
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_SYS_ARCH_H_
|
||||
#define _LWIP_PORTING_SYS_ARCH_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Semaphore
|
||||
*/
|
||||
typedef uint32_t sys_sem_t;
|
||||
|
||||
/**
|
||||
* Mutex
|
||||
*/
|
||||
typedef sys_sem_t sys_mutex_t;
|
||||
|
||||
/**
|
||||
* MessageBox
|
||||
*/
|
||||
typedef sys_sem_t sys_mbox_t;
|
||||
|
||||
/**
|
||||
* Protector
|
||||
*/
|
||||
typedef void *sys_prot_t;
|
||||
|
||||
/**
|
||||
* Thread
|
||||
*/
|
||||
typedef sys_sem_t sys_thread_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_PORTING_SYS_ARCH_H_ */
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_DHCP_H_
|
||||
#define _LWIP_PORTING_DHCP_H_
|
||||
|
||||
#include_next <lwip/dhcp.h>
|
||||
|
||||
err_t dhcp_is_bound(struct netif *netif);
|
||||
|
||||
#endif /* _LWIP_PORTING_DHCP_H_ */
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_INET_H_
|
||||
#define _LWIP_PORTING_INET_H_
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include_next <lwip/inet.h>
|
||||
|
||||
#if LWIP_IPV4
|
||||
#define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) \
|
||||
((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
|
||||
#define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) \
|
||||
(ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
|
||||
|
||||
/* directly map this to the lwip internal functions */
|
||||
#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
|
||||
#endif /* LWIP_IPV4 */
|
||||
#if LWIP_IPV6
|
||||
#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) do { \
|
||||
(target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \
|
||||
(target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \
|
||||
(target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \
|
||||
(target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3]; \
|
||||
} while (0)
|
||||
|
||||
#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) do { \
|
||||
(target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \
|
||||
(target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \
|
||||
(target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \
|
||||
(target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3]; \
|
||||
ip6_addr_clear_zone(target_ip6addr); \
|
||||
} while (0)
|
||||
|
||||
#endif /* LWIP_IPV6 */
|
||||
|
||||
#endif /* _LWIP_PORTING_INET_H_ */
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_LWIPOPTS_H_
|
||||
#define _LWIP_PORTING_LWIPOPTS_H_
|
||||
|
||||
// lwIP debug options, comment the ones you don't want
|
||||
#define LWIP_DEBUG 1
|
||||
#if LWIP_DEBUG
|
||||
#define ETHARP_DEBUG LWIP_DBG_OFF
|
||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||
#define API_MSG_DEBUG LWIP_DBG_OFF
|
||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||
#define IGMP_DEBUG LWIP_DBG_OFF
|
||||
#define INET_DEBUG LWIP_DBG_OFF
|
||||
#define IP_DEBUG LWIP_DBG_OFF
|
||||
#define DRIVERIF_DEBUG LWIP_DBG_OFF
|
||||
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
||||
#define RAW_DEBUG LWIP_DBG_OFF
|
||||
#define MEM_DEBUG LWIP_DBG_OFF
|
||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||
#define SYS_DEBUG LWIP_DBG_ON
|
||||
#define TIMERS_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_ERR_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 TCP_SACK_DEBUG LWIP_DBG_OFF
|
||||
#define TCP_TLP_DEBUG LWIP_DBG_OFF
|
||||
#define UDP_DEBUG LWIP_DBG_OFF
|
||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||
#define SLIP_DEBUG LWIP_DBG_OFF
|
||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||
#define AUTOIP_DEBUG LWIP_DBG_OFF
|
||||
#define DNS_DEBUG LWIP_DBG_OFF
|
||||
#define TFTP_DEBUG LWIP_DBG_OFF
|
||||
#define SYS_ARCH_DEBUG LWIP_DBG_OFF
|
||||
#define SNTP_DEBUG LWIP_DBG_OFF
|
||||
#define IP6_DEBUG LWIP_DBG_OFF
|
||||
#define DHCP6_DEBUG LWIP_DBG_OFF
|
||||
#define DRV_STS_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
// Options only in new opt.h
|
||||
#define LWIP_SOCKET_SELECT 0
|
||||
#define LWIP_SOCKET_POLL 1
|
||||
|
||||
// Options in old opt.h that differs from new opt.h
|
||||
#define MEM_ALIGNMENT __SIZEOF_POINTER__
|
||||
#define MEMP_NUM_NETDB 8
|
||||
#define IP_REASS_MAXAGE 3
|
||||
#define IP_SOF_BROADCAST 1
|
||||
#define IP_SOF_BROADCAST_RECV 1
|
||||
#define LWIP_MULTICAST_PING 1
|
||||
#define LWIP_RAW 1
|
||||
#define LWIP_DHCP_AUTOIP_COOP_TRIES 64
|
||||
#define TCP_LISTEN_BACKLOG 1
|
||||
#define TCP_DEFAULT_LISTEN_BACKLOG 16
|
||||
|
||||
#define LWIP_WND_SCALE 1
|
||||
#define TCP_RCV_SCALE 7
|
||||
|
||||
#define LWIP_NETIF_HOSTNAME 1
|
||||
#define LWIP_NETIF_TX_SINGLE_PBUF 1
|
||||
#define LWIP_NETCONN_FULLDUPLEX 1
|
||||
#define LWIP_COMPAT_SOCKETS 2
|
||||
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define RECV_BUFSIZE_DEFAULT 65535
|
||||
#define SO_REUSE_RXTOALL 1
|
||||
|
||||
#define LWIP_CHECKSUM_ON_COPY 1
|
||||
#define LWIP_IPV6 1
|
||||
#define LWIP_IPV6_NUM_ADDRESSES 5
|
||||
#define LWIP_ND6_NUM_PREFIXES 10
|
||||
#define LWIP_IPV6_DHCP6 1
|
||||
#define LWIP_IPV6_DHCP6_STATEFUL 1
|
||||
|
||||
// Options in old lwipopts.h
|
||||
#define ARP_QUEUEING 1
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE 32
|
||||
#define DEFAULT_RAW_RECVMBOX_SIZE 128
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 128
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 128
|
||||
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
|
||||
#define ETH_PAD_SIZE 0
|
||||
#define IP_REASS_MAX_PBUFS (((65535) / (IP_FRAG_MAX_MTU - 20 - 8) + 1) * MEMP_NUM_REASSDATA)
|
||||
#define LWIP_COMPAT_SOCKETS 2
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_OFF
|
||||
#define LWIP_DHCP 0
|
||||
#define LWIP_DNS 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_HAVE_LOOPIF 1
|
||||
#define LWIP_IGMP 1
|
||||
#define LWIP_NETIF_API 1
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||
#define LWIP_NETIF_LOOPBACK 1
|
||||
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
|
||||
#define LWIP_RAW 1
|
||||
#define LWIP_SO_RCVBUF 1
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
#define LWIP_STATS_DISPLAY 1
|
||||
#define MEM_LIBC_MALLOC 1
|
||||
#define MEMP_NUM_ARP_QUEUE (65535 * LWIP_CONFIG_NUM_SOCKETS / (IP_FRAG_MAX_MTU - 20 - 8))
|
||||
#define MEMP_NUM_NETBUF (65535 * 3 * LWIP_CONFIG_NUM_SOCKETS / (IP_FRAG_MAX_MTU - 20 - 8))
|
||||
#define MEMP_NUM_NETCONN LWIP_CONFIG_NUM_SOCKETS
|
||||
#define MEMP_NUM_PBUF (LWIP_CONFIG_NUM_SOCKETS*2)
|
||||
#define MEMP_NUM_RAW_PCB LWIP_CONFIG_NUM_SOCKETS
|
||||
#define MEMP_NUM_REASSDATA (IP_REASS_MAX_MEM_SIZE / 65535)
|
||||
#define MEMP_NUM_TCPIP_MSG_API 64
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT 512
|
||||
#define MEMP_NUM_TCP_PCB LWIP_CONFIG_NUM_SOCKETS
|
||||
#define MEMP_NUM_TCP_PCB_LISTEN LWIP_CONFIG_NUM_SOCKETS
|
||||
#define MEMP_NUM_TCP_SEG (((TCP_SND_BUF * 3 / 2) + TCP_WND) * LWIP_CONFIG_NUM_SOCKETS / TCP_MSS)
|
||||
#define MEMP_NUM_UDP_PCB LWIP_CONFIG_NUM_SOCKETS
|
||||
#define MEM_SIZE (4*1024*1024)
|
||||
#define PBUF_POOL_BUFSIZE 1550
|
||||
#define PBUF_POOL_SIZE 64
|
||||
#define SO_REUSE 1
|
||||
#define TCPIP_MBOX_SIZE 512
|
||||
#define TCPIP_THREAD_PRIO 5
|
||||
#define TCPIP_THREAD_STACKSIZE 0x800
|
||||
#define TCP_MAXRTX 64
|
||||
#define TCP_MSS 1400
|
||||
#define TCP_SND_BUF 65535
|
||||
#define TCP_SND_QUEUELEN ((8 * TCP_SND_BUF) / TCP_MSS)
|
||||
#define TCP_TTL 255
|
||||
#define TCP_WND 32768
|
||||
#define UDP_TTL 255
|
||||
|
||||
// Options in old lwipopts.h but kept in Defaults with new opt.h
|
||||
#define IP_FORWARD 0
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_ICMP 1
|
||||
#define LWIP_NETCONN 1
|
||||
#define LWIP_SOCKET 1
|
||||
#define LWIP_STATS 1
|
||||
#define LWIP_TCP 1
|
||||
#define LWIP_UDP 1
|
||||
#define NO_SYS 0
|
||||
#define TCP_QUEUE_OOSEQ LWIP_TCP
|
||||
|
||||
#if defined LWIP_STATS_DISPLAY && !LWIP_STATS
|
||||
#undef LWIP_STATS_DISPLAY
|
||||
#define LWIP_STATS_DISPLAY 0
|
||||
#endif
|
||||
|
||||
// Change some options for lwIP 2.1.2
|
||||
#undef TCP_MAXRTX
|
||||
#define TCP_MAXRTX 12
|
||||
|
||||
#undef LWIP_COMPAT_SOCKETS
|
||||
#define LWIP_COMPAT_SOCKETS 0
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + (LWIP_IPV6 * LWIP_IPV6_DHCP6))
|
||||
|
||||
#undef DEFAULT_ACCEPTMBOX_SIZE
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE LWIP_CONFIG_NUM_SOCKETS
|
||||
|
||||
#undef TCP_MSS
|
||||
#define TCP_MSS (IP_FRAG_MAX_MTU - 20 - 20)
|
||||
|
||||
#undef IP_SOF_BROADCAST_RECV
|
||||
#define IP_SOF_BROADCAST_RECV 0
|
||||
|
||||
/**
|
||||
* Defines whether to enable debugging for driver module.
|
||||
*/
|
||||
#ifndef DRIVERIF_DEBUG
|
||||
#define DRIVERIF_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
// Options for old lwipopts.h
|
||||
#define IP_FRAG_MAX_MTU 1500
|
||||
#define LWIP_CONFIG_NUM_SOCKETS 128
|
||||
#define IP_REASS_MAX_MEM_SIZE (MEM_SIZE / 4)
|
||||
|
||||
// Options for enhancement code, same for old lwipopts.h
|
||||
#define LWIP_NETIF_PROMISC 1
|
||||
#define LWIP_TFTP 1
|
||||
#define LWIP_DHCPS 1
|
||||
#define LWIP_ENABLE_NET_CAPABILITY 1
|
||||
#define LWIP_ENABLE_CAP_NET_BROADCAST 0
|
||||
|
||||
// Options for liteos_m
|
||||
#undef LWIP_NETIF_PROMISC
|
||||
#define LWIP_NETIF_PROMISC 0
|
||||
|
||||
#define MEMP_MEM_MALLOC 1
|
||||
|
||||
#undef LWIP_IPV6
|
||||
#define LWIP_IPV6 0
|
||||
|
||||
#undef LWIP_SOCKET_SELECT
|
||||
#define LWIP_SOCKET_SELECT 1
|
||||
|
||||
// Options for TcpTestSelect
|
||||
#undef LWIP_SOCKET_SELECT_FUNC
|
||||
#define LWIP_SOCKET_SELECT_FUNC 1
|
||||
|
||||
// Options for TcpTestPoll
|
||||
#undef LWIP_SOCKET_POLL_FUNC
|
||||
#define LWIP_SOCKET_POLL_FUNC 1
|
||||
|
||||
// use PBUF_RAM instead of PBUF_POOL in udp_input
|
||||
#define USE_PBUF_RAM_UDP_INPUT 1
|
||||
|
||||
#endif /* _LWIP_PORTING_LWIPOPTS_H_ */
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_NETDB_H_
|
||||
#define _LWIP_PORTING_NETDB_H_
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include <netdb.h>
|
||||
#include_next <lwip/netdb.h>
|
||||
|
||||
#endif /* _LWIP_PORTING_NETDB_H_ */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_NETIF_H_
|
||||
#define _LWIP_PORTING_NETIF_H_
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
#define netif_find netifapi_netif_find_by_name
|
||||
|
||||
#if LWIP_DHCPS
|
||||
#define LWIP_NETIF_CLIENT_DATA_INDEX_DHCP LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, \
|
||||
LWIP_NETIF_CLIENT_DATA_INDEX_DHCPS
|
||||
#endif
|
||||
|
||||
#define linkoutput linkoutput; \
|
||||
void (*drv_send)(struct netif *netif, struct pbuf *p); \
|
||||
u8_t (*drv_set_hwaddr)(struct netif *netif, u8_t *addr, u8_t len); \
|
||||
void (*drv_config)(struct netif *netif, u32_t config_flags, u8_t setBit); \
|
||||
char full_name[IFNAMSIZ]; \
|
||||
u16_t link_layer_type
|
||||
#include_next <lwip/netif.h>
|
||||
#undef linkoutput
|
||||
#if LWIP_DHCPS
|
||||
#undef LWIP_NETIF_CLIENT_DATA_INDEX_DHCP
|
||||
#endif
|
||||
|
||||
#include <lwip/etharp.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// redefine NETIF_NAMESIZE which was defined in netif.h
|
||||
#undef NETIF_NAMESIZE
|
||||
#define NETIF_NAMESIZE IFNAMSIZ
|
||||
|
||||
#define LOOPBACK_IF 0
|
||||
#define ETHERNET_DRIVER_IF 1
|
||||
#define WIFI_DRIVER_IF 801
|
||||
#define BT_PROXY_IF 802
|
||||
|
||||
err_t driverif_init(struct netif *netif);
|
||||
void driverif_input(struct netif *netif, struct pbuf *p);
|
||||
|
||||
#define netif_get_name(netif) ((netif)->full_name)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_PORTING_NETIF_H_ */
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_NETIFAPI_H_
|
||||
#define _LWIP_PORTING_NETIFAPI_H_
|
||||
|
||||
#include_next <lwip/netifapi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
err_t netifapi_dhcps_start(struct netif *netif, char *start_ip, u16_t ip_num);
|
||||
err_t netifapi_dhcps_stop(struct netif *netif);
|
||||
|
||||
#define netifapi_dhcp_cleanup(n) netifapi_netif_common(n, dhcp_cleanup, NULL)
|
||||
#define netifapi_dhcp_is_bound(n) netifapi_netif_common(n, NULL, dhcp_is_bound)
|
||||
|
||||
void netifapi_netif_rmv_ip6_address(struct netif *netif, ip_addr_t *ipaddr);
|
||||
struct netif *netifapi_netif_find_by_name(const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_PORTING_NETIFAPI_H_ */
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef _LWIP_PORTING_SOCKETS_H_
|
||||
#define _LWIP_PORTING_SOCKETS_H_
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/select.h>
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
#include_next <lwip/sockets.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN)
|
||||
#error "external FD_SETSIZE too small for number of sockets"
|
||||
#else
|
||||
#define LWIP_SELECT_MAXNFDS FD_SETSIZE
|
||||
#endif
|
||||
|
||||
#if IOV_MAX > 0xFFFF
|
||||
#error "IOV_MAX larger than supported by LwIP"
|
||||
#endif
|
||||
|
||||
#if LWIP_UDP && LWIP_UDPLITE
|
||||
#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
|
||||
#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
|
||||
#endif
|
||||
|
||||
// For BSD 4.4 socket sa_len compatibility
|
||||
#define DF_NADDR(addr) ip_addr_t naddr = (addr)
|
||||
#define SA_LEN(addr, _) (IP_IS_V4_VAL(addr) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
|
||||
#define sa_len sa_data[0] * 0 + SA_LEN(naddr, _)
|
||||
#define sin_len sin_zero[0]
|
||||
#define sin6_len sin6_addr.s6_addr[0]
|
||||
|
||||
// for sockets.c, TCP_KEEPALIVE is not supported currently
|
||||
#define TCP_KEEPALIVE 0xFF
|
||||
#define SIN_ZERO_LEN 8
|
||||
|
||||
int closesocket(int sockfd);
|
||||
int ioctlsocket(int s, long cmd, void *argp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_PORTING_SOCKETS_H_ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#ifndef __LITEOS_M_LWIPOPTS_H__
|
||||
#define __LITEOS_M_LWIPOPTS_H__
|
||||
|
||||
// Just redirect
|
||||
#include "lwip/lwipopts.h"
|
||||
|
||||
#endif // __LITEOS_M_LWIPOPTS_H__
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <lwip/sys.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip/snmp.h>
|
||||
#include <lwip/etharp.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/ethip6.h>
|
||||
|
||||
#define LWIP_NETIF_HOSTNAME_DEFAULT "default"
|
||||
#define LINK_SPEED_OF_YOUR_NETIF_IN_BPS 100000000 // 100Mbps
|
||||
|
||||
#define link_rx_drop cachehit
|
||||
#define link_rx_overrun cachehit
|
||||
|
||||
#define LWIP_STATIC static
|
||||
|
||||
#define NETIF_NAME_PREFIX_MAX_LENGTH 10
|
||||
#define NETIF_NAME_PREFIX_ETH "eth"
|
||||
#define NETIF_NAME_PREFIX_WIFI "wlan"
|
||||
#define NETIF_NAME_PREFIX_BT "bt"
|
||||
|
||||
#ifndef LWIP_NETIF_IFINDEX_MAX_EX
|
||||
#define LWIP_NETIF_IFINDEX_MAX_EX 255
|
||||
#endif
|
||||
|
||||
LWIP_STATIC void driverif_get_ifname_prefix(struct netif *netif, char *prefix, int prefixLen)
|
||||
{
|
||||
if (prefix == NULL || netif == NULL) {
|
||||
LWIP_ASSERT("invalid param", 0);
|
||||
return;
|
||||
}
|
||||
switch (netif->link_layer_type) {
|
||||
case ETHERNET_DRIVER_IF:
|
||||
strcpy_s(prefix, prefixLen, NETIF_NAME_PREFIX_ETH);
|
||||
break;
|
||||
case WIFI_DRIVER_IF:
|
||||
strcpy_s(prefix, prefixLen, NETIF_NAME_PREFIX_WIFI);
|
||||
break;
|
||||
case BT_PROXY_IF:
|
||||
strcpy_s(prefix, prefixLen, NETIF_NAME_PREFIX_BT);
|
||||
break;
|
||||
default:
|
||||
LWIP_ASSERT("invalid link_layer_type", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LWIP_STATIC void driverif_init_ifname(struct netif *netif)
|
||||
{
|
||||
struct netif *tmpnetif = NULL;
|
||||
char prefix[NETIF_NAME_PREFIX_MAX_LENGTH] = {0};
|
||||
|
||||
driverif_get_ifname_prefix(netif, prefix, NETIF_NAME_PREFIX_MAX_LENGTH);
|
||||
netif->name[0] = prefix[0];
|
||||
netif->name[1] = prefix[1];
|
||||
|
||||
if (netif->full_name[0] != '\0') {
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("netif already has fullname %s\n", netif->full_name));
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < LWIP_NETIF_IFINDEX_MAX_EX; ++i) {
|
||||
if (snprintf_s(netif->full_name, sizeof(netif->full_name), sizeof(netif->full_name) - 1,
|
||||
"%s%d", prefix, i) < 0) {
|
||||
break;
|
||||
}
|
||||
NETIF_FOREACH(tmpnetif) {
|
||||
if (strcmp(tmpnetif->full_name, netif->full_name) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tmpnetif == NULL) {
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("set fullname success %s\n", netif->full_name));
|
||||
return;
|
||||
}
|
||||
}
|
||||
netif->full_name[0] = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 driverif
|
||||
* @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).
|
||||
*/
|
||||
|
||||
LWIP_STATIC err_t driverif_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_output : send packet pbuf 0x%p of length %"U16_F" through netif 0x%p\n", \
|
||||
(void *)p, p->tot_len, (void *)netif));
|
||||
|
||||
#if PF_PKT_SUPPORT
|
||||
if (all_pkt_raw_pcbs != NULL) {
|
||||
p->flags = (u16_t)(p->flags & ~(PBUF_FLAG_LLMCAST | PBUF_FLAG_LLBCAST | PBUF_FLAG_HOST));
|
||||
p->flags |= PBUF_FLAG_OUTGOING;
|
||||
(void)raw_pkt_input(p, netif, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
(void)pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
|
||||
#endif
|
||||
|
||||
netif->drv_send(netif, p);
|
||||
|
||||
#if ETH_PAD_SIZE
|
||||
(void)pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
|
||||
#endif
|
||||
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
|
||||
LINK_STATS_INC(link.xmit);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void driverif_input_proc(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
u16_t ethhdr_type;
|
||||
struct eth_hdr *ethhdr = NULL;
|
||||
err_t ret = ERR_VAL;
|
||||
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
ethhdr_type = ntohs(ethhdr->type);
|
||||
|
||||
switch (ethhdr_type) {
|
||||
/* IP or ARP packet? */
|
||||
case ETHTYPE_IP:
|
||||
case ETHTYPE_IPV6:
|
||||
case ETHTYPE_ARP:
|
||||
#if ETHARP_SUPPORT_VLAN
|
||||
case ETHTYPE_VLAN:
|
||||
#endif /* ETHARP_SUPPORT_VLAN */
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet of type %"U16_F"\n", ethhdr_type));
|
||||
/* full packet send to tcpip_thread to process */
|
||||
if (netif->input != NULL) {
|
||||
ret = netif->input(p, netif);
|
||||
}
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input: IP input error\n"));
|
||||
(void)pbuf_free(p);
|
||||
LINK_STATS_INC(link.drop);
|
||||
LINK_STATS_INC(link.link_rx_drop);
|
||||
if (ret == ERR_MEM) {
|
||||
MIB2_STATS_NETIF_INC(netif, ifinoverruns);
|
||||
LINK_STATS_INC(link.link_rx_overrun);
|
||||
}
|
||||
} else {
|
||||
LINK_STATS_INC(link.recv);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet is of unsupported type %"U16_F"\n", \
|
||||
ethhdr_type));
|
||||
(void)pbuf_free(p);
|
||||
LINK_STATS_INC(link.drop);
|
||||
LINK_STATS_INC(link.link_rx_drop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function should be called by network driver to pass the input packet to LwIP.
|
||||
* Before calling this API, driver has to keep the packet in pbuf structure. Driver has to
|
||||
* call pbuf_alloc() with type as PBUF_RAM to create pbuf structure. Then driver
|
||||
* has to pass the pbuf structure to this API. This will add the pbuf into the TCPIP thread.
|
||||
* Once this packet is processed by TCPIP thread, pbuf will be freed. Driver is not required to
|
||||
* free the pbuf.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this driverif
|
||||
* @param p packet in pbuf structure format
|
||||
*/
|
||||
void driverif_input(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
#if PF_PKT_SUPPORT
|
||||
#if (DRIVERIF_DEBUG & LWIP_DBG_OFF)
|
||||
u16_t ethhdr_type;
|
||||
struct eth_hdr* ethhdr = NULL;
|
||||
#endif
|
||||
err_t ret = ERR_VAL;
|
||||
#endif
|
||||
|
||||
LWIP_ERROR("driverif_input : invalid arguments", ((netif != NULL) && (p != NULL)), return);
|
||||
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : going to receive input packet. netif 0x%p, pbuf 0x%p, \
|
||||
packet_length %"U16_F"\n", (void *)netif, (void *)p, p->tot_len));
|
||||
|
||||
/* points to packet payload, which starts with an Ethernet header */
|
||||
MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
|
||||
if (p->len < SIZEOF_ETH_HDR) {
|
||||
(void)pbuf_free(p);
|
||||
LINK_STATS_INC(link.drop);
|
||||
LINK_STATS_INC(link.link_rx_drop);
|
||||
return;
|
||||
}
|
||||
|
||||
#if PF_PKT_SUPPORT
|
||||
#if (DRIVERIF_DEBUG & LWIP_DBG_OFF)
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
ethhdr_type = ntohs(ethhdr->type);
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet of type %"U16_F" netif->input=%p\n", \
|
||||
ethhdr_type, netif->input));
|
||||
#endif
|
||||
|
||||
/* full packet send to tcpip_thread to process */
|
||||
if (netif->input) {
|
||||
ret = netif->input(p, netif);
|
||||
}
|
||||
if (ret != ERR_OK) {
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input: IP input error\n"));
|
||||
(void)pbuf_free(p);
|
||||
LINK_STATS_INC(link.drop);
|
||||
LINK_STATS_INC(link.link_rx_drop);
|
||||
if (ret == ERR_MEM) {
|
||||
LINK_STATS_INC(link.link_rx_overrun);
|
||||
}
|
||||
} else {
|
||||
LINK_STATS_INC(link.recv);
|
||||
}
|
||||
|
||||
#else
|
||||
driverif_input_proc(netif, p);
|
||||
#endif
|
||||
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_input : received packet is processed\n"));
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 driverif
|
||||
* @return ERR_OK if the loopif is initialized
|
||||
* ERR_MEM on Allocation Failure
|
||||
* any other err_t on error
|
||||
*/
|
||||
err_t driverif_init(struct netif *netif)
|
||||
{
|
||||
u16_t link_layer_type;
|
||||
|
||||
if (netif == NULL) {
|
||||
return ERR_IF;
|
||||
}
|
||||
link_layer_type = netif->link_layer_type;
|
||||
LWIP_ERROR("driverif_init : invalid link_layer_type in netif", \
|
||||
((link_layer_type == ETHERNET_DRIVER_IF) \
|
||||
|| (link_layer_type == WIFI_DRIVER_IF \
|
||||
|| link_layer_type == BT_PROXY_IF)), \
|
||||
return ERR_IF);
|
||||
|
||||
LWIP_ERROR("driverif_init : netif hardware length is greater than maximum supported", \
|
||||
(netif->hwaddr_len <= NETIF_MAX_HWADDR_LEN), return ERR_IF);
|
||||
|
||||
LWIP_ERROR("driverif_init : drv_send is null", (netif->drv_send != NULL), return ERR_IF);
|
||||
|
||||
#if LWIP_NETIF_PROMISC
|
||||
LWIP_ERROR("driverif_init : drv_config is null", (netif->drv_config != NULL), return ERR_IF);
|
||||
#endif
|
||||
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
/* Initialize interface hostname */
|
||||
netif->hostname = LWIP_NETIF_HOSTNAME_DEFAULT;
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
/*
|
||||
* 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, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
|
||||
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = driverif_output;
|
||||
|
||||
/* init the netif's full name */
|
||||
driverif_init_ifname(netif);
|
||||
|
||||
/* maximum transfer unit */
|
||||
netif->mtu = IP_FRAG_MAX_MTU;
|
||||
|
||||
/* device capabilities */
|
||||
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP |
|
||||
#if DRIVER_STATUS_CHECK
|
||||
NETIF_FLAG_DRIVER_RDY |
|
||||
#endif
|
||||
#if LWIP_IGMP
|
||||
NETIF_FLAG_IGMP |
|
||||
#endif
|
||||
|
||||
/**
|
||||
@page RFC-2710 RFC-2710
|
||||
@par Compliant Sections
|
||||
Section 5. Node State Transition Diagram
|
||||
@par Behavior Description
|
||||
MLD messages are sent for multicast addresses whose scope is 2
|
||||
(link-local), including Solicited-Node multicast addresses.\n
|
||||
Behavior:Stack will send MLD6 report /Done to solicited node multicast address
|
||||
if the LWIP_MLD6_ENABLE_MLD_ON_DAD is enabled. By default, this is disabled.
|
||||
*/
|
||||
/* Enable sending MLD report /done for solicited address during neighbour discovery */
|
||||
#if LWIP_IPV6 && LWIP_IPV6_MLD
|
||||
#if LWIP_MLD6_ENABLE_MLD_ON_DAD
|
||||
NETIF_FLAG_MLD6 |
|
||||
#endif /* LWIP_MLD6_ENABLE_MLD_ON_DAD */
|
||||
#endif
|
||||
NETIF_FLAG_LINK_UP;
|
||||
|
||||
#if DRIVER_STATUS_CHECK
|
||||
netif->waketime = -1;
|
||||
#endif /* DRIVER_STATUS_CHECK */
|
||||
LWIP_DEBUGF(DRIVERIF_DEBUG, ("driverif_init : Initialized netif 0x%p\n", (void *)netif));
|
||||
return ERR_OK;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include "lwip/netdb.h"
|
||||
|
||||
#if LWIP_DNS && LWIP_SOCKET
|
||||
|
||||
struct hostent *gethostbyname(const char *name)
|
||||
{
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return lwip_gethostbyname(name);
|
||||
}
|
||||
|
||||
int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result,
|
||||
int *h_errnop)
|
||||
{
|
||||
return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop);
|
||||
}
|
||||
|
||||
void freeaddrinfo(struct addrinfo *res)
|
||||
{
|
||||
lwip_freeaddrinfo(res);
|
||||
}
|
||||
|
||||
int getaddrinfo(const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints,
|
||||
struct addrinfo **restrict res)
|
||||
{
|
||||
return lwip_getaddrinfo(nodename, servname, hints, res);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,783 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
#include "lwip/priv/sockets_priv.h"
|
||||
#include "lwip/prot/dhcp.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/if_api.h"
|
||||
|
||||
#if !LWIP_COMPAT_SOCKETS
|
||||
#if LWIP_SOCKET
|
||||
|
||||
static err_t CheckNullPtr(void *ptr)
|
||||
{
|
||||
if (ptr == NULL) {
|
||||
set_errno(EFAULT);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||
{
|
||||
return lwip_accept(s, addr, addrlen);
|
||||
}
|
||||
|
||||
int bind(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
{
|
||||
CheckNullPtr(name);
|
||||
if (namelen < sizeof(*name)) {
|
||||
set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
return lwip_bind(s, name, namelen);
|
||||
}
|
||||
|
||||
int shutdown(int s, int how)
|
||||
{
|
||||
return lwip_shutdown(s, how);
|
||||
}
|
||||
|
||||
int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
|
||||
{
|
||||
CheckNullPtr(name);
|
||||
CheckNullPtr(namelen);
|
||||
return lwip_getpeername(s, name, namelen);
|
||||
}
|
||||
|
||||
int getsockname(int s, struct sockaddr *name, socklen_t *namelen)
|
||||
{
|
||||
CheckNullPtr(name);
|
||||
CheckNullPtr(namelen);
|
||||
return lwip_getsockname(s, name, namelen);
|
||||
}
|
||||
|
||||
int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
|
||||
{
|
||||
return lwip_getsockopt(s, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
|
||||
{
|
||||
return lwip_setsockopt(s, level, optname, optval, optlen);
|
||||
}
|
||||
|
||||
int closesocket(int s)
|
||||
{
|
||||
return lwip_close(s);
|
||||
}
|
||||
|
||||
int connect(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
{
|
||||
CheckNullPtr(name);
|
||||
if (namelen < sizeof(*name)) {
|
||||
set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
return lwip_connect(s, name, namelen);
|
||||
}
|
||||
|
||||
int listen(int s, int backlog)
|
||||
{
|
||||
return lwip_listen(s, backlog);
|
||||
}
|
||||
|
||||
ssize_t recv(int s, void *mem, size_t len, int flags)
|
||||
{
|
||||
CheckNullPtr(mem);
|
||||
return lwip_recv(s, mem, len, flags);
|
||||
}
|
||||
|
||||
ssize_t recvfrom(int s, void *mem, size_t len, int flags,
|
||||
struct sockaddr *from, socklen_t *fromlen)
|
||||
{
|
||||
CheckNullPtr(mem);
|
||||
return lwip_recvfrom(s, mem, len, flags, from, fromlen);
|
||||
}
|
||||
|
||||
ssize_t recvmsg(int s, struct msghdr *message, int flags)
|
||||
{
|
||||
CheckNullPtr(message);
|
||||
if (message->msg_iovlen) {
|
||||
CheckNullPtr(message->msg_iov);
|
||||
}
|
||||
return lwip_recvmsg(s, message, flags);
|
||||
}
|
||||
|
||||
ssize_t send(int s, const void *dataptr, size_t size, int flags)
|
||||
{
|
||||
CheckNullPtr(dataptr);
|
||||
return lwip_send(s, dataptr, size, flags);
|
||||
}
|
||||
|
||||
ssize_t sendmsg(int s, const struct msghdr *message, int flags)
|
||||
{
|
||||
return lwip_sendmsg(s, message, flags);
|
||||
}
|
||||
|
||||
ssize_t sendto(int s, const void *dataptr, size_t size, int flags,
|
||||
const struct sockaddr *to, socklen_t tolen)
|
||||
{
|
||||
CheckNullPtr(dataptr);
|
||||
if (to && tolen < sizeof(*to)) {
|
||||
set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
return lwip_sendto(s, dataptr, size, flags, to, tolen);
|
||||
}
|
||||
|
||||
int socket(int domain, int type, int protocol)
|
||||
{
|
||||
return lwip_socket(domain, type, protocol);
|
||||
}
|
||||
|
||||
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
|
||||
{
|
||||
return lwip_inet_ntop(af, src, dst, size);
|
||||
}
|
||||
|
||||
int inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
return lwip_inet_pton(af, src, dst);
|
||||
}
|
||||
|
||||
#ifndef LWIP_INET_ADDR_FUNC
|
||||
in_addr_t inet_addr(const char *cp)
|
||||
{
|
||||
return ipaddr_addr(cp);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef LWIP_INET_NTOA_FUNC
|
||||
char *inet_ntoa(struct in_addr addr)
|
||||
{
|
||||
return ip4addr_ntoa((const ip4_addr_t*)&(addr));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef LWIP_INET_ATON_FUNC
|
||||
int inet_aton(const char *cp, struct in_addr *addr)
|
||||
{
|
||||
return ip4addr_aton(cp, (ip4_addr_t*)addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
int ioctlsocket(int s, long cmd, void *argp)
|
||||
{
|
||||
return lwip_ioctl(s, cmd, argp);
|
||||
}
|
||||
|
||||
#ifdef LWIP_SOCKET_READ_FUNC
|
||||
ssize_t read(int fd, void *buf, size_t len)
|
||||
{
|
||||
return lwip_read(fd, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_SOCKET_WRITE_FUNC
|
||||
ssize_t write(int fd, const void *buf, size_t len)
|
||||
{
|
||||
return lwip_write(fd, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_SOCKET_CLOSE_FUNC
|
||||
int close(int fd)
|
||||
{
|
||||
return lwip_close(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_SOCKET_IOCTL_FUNC
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
UINTPTR arg = 0;
|
||||
va_list ap;
|
||||
va_start(ap, req);
|
||||
arg = va_arg(ap, UINTPTR);
|
||||
va_end(ap);
|
||||
return lwip_ioctl(fd, (long)req, (void *)arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_SOCKET_FCNTL_FUNC
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
int val = 0;
|
||||
va_list ap;
|
||||
va_start(ap, cmd);
|
||||
val = va_arg(ap, int);
|
||||
va_end(ap);
|
||||
return lwip_fcntl(fd, cmd, val);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LWIP_SOCKET_SELECT
|
||||
#ifdef LWIP_SOCKET_SELECT_FUNC
|
||||
int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout)
|
||||
{
|
||||
return lwip_select(maxfdp1, readset, writeset, exceptset, timeout);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LWIP_SOCKET_POLL
|
||||
#ifdef LWIP_SOCKET_POLL_FUNC
|
||||
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
{
|
||||
return lwip_poll(fds, nfds, timeout);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
unsigned int if_nametoindex(const char *ifname)
|
||||
{
|
||||
return lwip_if_nametoindex(ifname);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* !LWIP_COMPAT_SOCKETS */
|
||||
|
||||
struct lwip_ioctl_apimsg {
|
||||
struct tcpip_api_call_data call;
|
||||
struct lwip_sock *sock;
|
||||
long cmd;
|
||||
void *argp;
|
||||
};
|
||||
|
||||
static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call);
|
||||
|
||||
#define IOCTL_CMD_CASE_HANDLER() do { \
|
||||
err_t err; \
|
||||
struct lwip_ioctl_apimsg msg; \
|
||||
msg.sock = sock; \
|
||||
msg.cmd = cmd; \
|
||||
msg.argp = argp; \
|
||||
\
|
||||
err = tcpip_api_call(lwip_do_ioctl_impl, &msg.call); \
|
||||
if (err != ENOSYS) { \
|
||||
sock_set_errno(sock, err); \
|
||||
done_socket(sock); \
|
||||
return -(err != ERR_OK); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#include "../api/sockets.c"
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFCONF(struct ifreq *ifr)
|
||||
{
|
||||
struct ifconf *ifc = NULL;
|
||||
struct netif *netif = NULL;
|
||||
struct ifreq ifreq;
|
||||
struct sockaddr_in *sock_in = NULL;
|
||||
int pos;
|
||||
int len;
|
||||
int ret;
|
||||
|
||||
/* Format the caller's buffer. */
|
||||
ifc = (struct ifconf *)ifr;
|
||||
len = ifc->ifc_len;
|
||||
|
||||
/* Loop over the interfaces, and write an info block for each. */
|
||||
pos = 0;
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (ifc->ifc_buf == NULL) {
|
||||
pos = (pos + (int)sizeof(struct ifreq));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len < (int)sizeof(ifreq)) {
|
||||
break;
|
||||
}
|
||||
(void)memset_s(&ifreq, sizeof(struct ifreq), 0, sizeof(struct ifreq));
|
||||
if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
ret = snprintf_s(ifreq.ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%.2s", netif->name);
|
||||
if ((ret <= 0) || (ret >= IFNAMSIZ)) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("lwip_ioctl: snprintf_s ifr_name failed."));
|
||||
return ENOBUFS;
|
||||
}
|
||||
} else {
|
||||
ret = snprintf_s(ifreq.ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%s", netif_get_name(netif));
|
||||
if ((ret <= 0) || (ret >= IFNAMSIZ)) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("lwip_ioctl: snprintf_s ifr_name failed."));
|
||||
return ENOBUFS;
|
||||
}
|
||||
}
|
||||
|
||||
sock_in = (struct sockaddr_in *)&ifreq.ifr_addr;
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr.s_addr = ip_2_ip4(&netif->ip_addr)->addr;
|
||||
if (memcpy_s(ifc->ifc_buf + pos, sizeof(struct ifreq), &ifreq, sizeof(struct ifreq)) != EOK) {
|
||||
return ENOBUFS;
|
||||
}
|
||||
pos = pos + (int)sizeof(struct ifreq);
|
||||
len = len - (int)sizeof(struct ifreq);
|
||||
}
|
||||
|
||||
ifc->ifc_len = pos;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFADDR(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
struct sockaddr_in *sock_in = NULL;
|
||||
|
||||
/* get netif ipaddr */
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
} else {
|
||||
sock_in = (struct sockaddr_in *)&ifr->ifr_addr;
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr.s_addr = ip_2_ip4(&netif->ip_addr)->addr;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFNETMASK(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
struct sockaddr_in *sock_in = NULL;
|
||||
|
||||
/* get netif netmask */
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
} else {
|
||||
sock_in = (struct sockaddr_in *)&ifr->ifr_netmask;
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr.s_addr = ip_2_ip4(&netif->netmask)->addr;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFHWADDR(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
|
||||
/* get netif hw addr */
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
#if LWIP_HAVE_LOOPIF
|
||||
if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
return EPERM;
|
||||
}
|
||||
#endif /* LWIP_HAVE_LOOPIF */
|
||||
|
||||
if (memcpy_s((void *)ifr->ifr_hwaddr.sa_data, sizeof(ifr->ifr_hwaddr.sa_data),
|
||||
(void *)netif->hwaddr, netif->hwaddr_len) != EOK) {
|
||||
return EINVAL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCSIFFLAGS(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
|
||||
/* set netif hw addr */
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
#if LWIP_HAVE_LOOPIF
|
||||
if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
return EPERM;
|
||||
}
|
||||
#endif /* LWIP_HAVE_LOOPIF */
|
||||
|
||||
if (((unsigned short)ifr->ifr_flags & IFF_UP) && !(netif->flags & NETIF_FLAG_UP)) {
|
||||
(void)netif_set_up(netif);
|
||||
} else if (!((unsigned short)ifr->ifr_flags & IFF_UP) && (netif->flags & NETIF_FLAG_UP)) {
|
||||
(void)netif_set_down(netif);
|
||||
}
|
||||
if (((unsigned short)ifr->ifr_flags & IFF_RUNNING) && !(netif->flags & NETIF_FLAG_LINK_UP)) {
|
||||
(void)netif_set_link_up(netif);
|
||||
} else if (!((unsigned short)ifr->ifr_flags & IFF_RUNNING) && (netif->flags & NETIF_FLAG_LINK_UP)) {
|
||||
(void)netif_set_link_down(netif);
|
||||
}
|
||||
|
||||
if ((unsigned short)ifr->ifr_flags & IFF_BROADCAST) {
|
||||
netif->flags |= NETIF_FLAG_BROADCAST;
|
||||
} else {
|
||||
netif->flags = netif->flags & (~NETIF_FLAG_BROADCAST);
|
||||
}
|
||||
if ((unsigned short)ifr->ifr_flags & IFF_NOARP) {
|
||||
netif->flags = (netif->flags & (~NETIF_FLAG_ETHARP));
|
||||
} else {
|
||||
netif->flags |= NETIF_FLAG_ETHARP;
|
||||
}
|
||||
|
||||
if ((unsigned short)ifr->ifr_flags & IFF_MULTICAST) {
|
||||
#if LWIP_IGMP
|
||||
netif->flags |= NETIF_FLAG_IGMP;
|
||||
#endif /* LWIP_IGMP */
|
||||
#if LWIP_IPV6 && LWIP_IPV6_MLD
|
||||
netif->flags |= NETIF_FLAG_MLD6;
|
||||
#endif /* LWIP_IPV6_MLD */
|
||||
} else {
|
||||
#if LWIP_IGMP
|
||||
netif->flags = (netif->flags & ~NETIF_FLAG_IGMP);
|
||||
#endif /* LWIP_IGMP */
|
||||
#if LWIP_IPV6 && LWIP_IPV6_MLD
|
||||
netif->flags = (netif->flags & ~NETIF_FLAG_MLD6);
|
||||
#endif /* LWIP_IPV6_MLD */
|
||||
}
|
||||
|
||||
#if LWIP_DHCP
|
||||
if ((unsigned short)ifr->ifr_flags & IFF_DYNAMIC) {
|
||||
(void)dhcp_start(netif);
|
||||
} else {
|
||||
dhcp_stop(netif);
|
||||
#if !LWIP_DHCP_SUBSTITUTE
|
||||
dhcp_cleanup(netif);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LWIP_NETIF_PROMISC
|
||||
if (((unsigned short)ifr->ifr_flags & IFF_PROMISC)) {
|
||||
netif->flags |= NETIF_FLAG_PROMISC;
|
||||
} else {
|
||||
netif->flags &= ~NETIF_FLAG_PROMISC;
|
||||
}
|
||||
if (netif->drv_config) {
|
||||
netif->drv_config(netif, IFF_PROMISC, !!((unsigned short)ifr->ifr_flags & IFF_PROMISC));
|
||||
}
|
||||
#endif /* LWIP_NETIF_PROMISC */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFFLAGS(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
|
||||
/* set netif hw addr */
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
} else {
|
||||
if (netif->flags & NETIF_FLAG_UP) {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_UP;
|
||||
} else {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_UP;
|
||||
}
|
||||
if (netif->flags & NETIF_FLAG_LINK_UP) {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_RUNNING;
|
||||
} else {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_RUNNING;
|
||||
}
|
||||
if (netif->flags & NETIF_FLAG_BROADCAST) {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_BROADCAST;
|
||||
} else {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_BROADCAST;
|
||||
}
|
||||
if (netif->flags & NETIF_FLAG_ETHARP) {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_NOARP;
|
||||
} else {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_NOARP;
|
||||
}
|
||||
|
||||
#if LWIP_IGMP || LWIP_IPV6_MLD
|
||||
if (
|
||||
#if LWIP_IGMP
|
||||
(netif->flags & NETIF_FLAG_IGMP)
|
||||
#endif /* LWIP_IGMP */
|
||||
#if LWIP_IGMP && LWIP_IPV6_MLD
|
||||
||
|
||||
#endif /* LWIP_IGMP && LWIP_IPV6_MLD */
|
||||
#if LWIP_IPV6_MLD
|
||||
(netif->flags & NETIF_FLAG_MLD6)
|
||||
#endif /* LWIP_IPV6_MLD */
|
||||
) {
|
||||
ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags | IFF_MULTICAST);
|
||||
} else {
|
||||
ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags & (~IFF_MULTICAST));
|
||||
}
|
||||
#endif /* LWIP_IGMP || LWIP_IPV6_MLD */
|
||||
|
||||
#if LWIP_DHCP
|
||||
if (dhcp_supplied_address(netif)) {
|
||||
ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags | IFF_DYNAMIC);
|
||||
} else {
|
||||
ifr->ifr_flags = (short)((unsigned short)ifr->ifr_flags & (~IFF_DYNAMIC));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LWIP_HAVE_LOOPIF
|
||||
if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_LOOPBACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LWIP_NETIF_PROMISC
|
||||
if (netif->flags & NETIF_FLAG_PROMISC) {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) | IFF_PROMISC;
|
||||
} else {
|
||||
ifr->ifr_flags = ((unsigned short)(ifr->ifr_flags)) & ~IFF_PROMISC;
|
||||
}
|
||||
#endif /* LWIP_NETIF_PROMISC */
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFNAME(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
int ret;
|
||||
|
||||
for (netif = netif_list; netif != NULL; netif = netif->next) {
|
||||
if (ifr->ifr_ifindex == netif_get_index(netif)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
} else {
|
||||
if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
ret = snprintf_s(ifr->ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%.2s", netif->name);
|
||||
if ((ret <= 0) || (ret >= IFNAMSIZ)) {
|
||||
return ENOBUFS;
|
||||
}
|
||||
} else {
|
||||
ret = snprintf_s(ifr->ifr_name, IFNAMSIZ, (IFNAMSIZ - 1), "%s", netif_get_name(netif));
|
||||
if ((ret <= 0) || (ret >= IFNAMSIZ)) {
|
||||
return ENOBUFS;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static u8_t lwip_validate_ifname(const char *name, u8_t *let_pos)
|
||||
{
|
||||
unsigned short num_pos = 0;
|
||||
unsigned short letter_pos = 0;
|
||||
unsigned short pos = 0;
|
||||
u8_t have_num = 0;
|
||||
|
||||
/* if the first position of variable name is not letter, such as '6eth2' */
|
||||
if (!((*name >= 'a' && *name <= 'z') || (*name >= 'A' && *name <= 'Z'))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check if the position of letter is bigger than the the position of digital */
|
||||
while (*name != '\0') {
|
||||
if ((*name >= '0') && (*name <= '9')) {
|
||||
num_pos = pos;
|
||||
have_num = 1;
|
||||
} else if (((*name >= 'a') && (*name <= 'z')) || ((*name >= 'A') && (*name <= 'Z'))) {
|
||||
letter_pos = pos;
|
||||
if (have_num != 0) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
pos++;
|
||||
name++;
|
||||
}
|
||||
|
||||
/* for the speacil case as all position of variable name is letter, such as 'ethabc' */
|
||||
if (num_pos == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* cheak if the digital in the variable name is bigger than 255, such as 'eth266' */
|
||||
if (atoi(name - (pos - letter_pos - 1)) > 255) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*let_pos = (u8_t)letter_pos;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCSIFNAME(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
u8_t letter_pos = 0;
|
||||
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
} else if (netif->link_layer_type == LOOPBACK_IF) {
|
||||
return EPERM;
|
||||
} else if ((netif->flags & IFF_UP) != 0) {
|
||||
return EBUSY;
|
||||
} else {
|
||||
if (strncmp(ifr->ifr_name, ifr->ifr_newname, IFNAMSIZ) == 0) {
|
||||
/* not change */
|
||||
return 0;
|
||||
}
|
||||
|
||||
ifr->ifr_newname[IFNAMSIZ - 1] = '\0';
|
||||
if ((lwip_validate_ifname(ifr->ifr_newname, &letter_pos) == 0) || (strlen(ifr->ifr_newname) > (IFNAMSIZ - 1))) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (strncpy_s(netif->full_name, sizeof(netif->full_name), ifr->ifr_newname, strlen(ifr->ifr_newname)) != EOK) {
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFINDEX(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
} else {
|
||||
ifr->ifr_ifindex = netif_get_index(netif);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFMTU(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
|
||||
/* get netif hw addr */
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
} else {
|
||||
ifr->ifr_mtu = netif->mtu;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_internal_SIOCGIFBRDADDR(struct ifreq *ifr)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
struct sockaddr_in *sock_in = NULL;
|
||||
|
||||
/* get netif subnet broadcast addr */
|
||||
netif = netif_find(ifr->ifr_name);
|
||||
if (netif == NULL) {
|
||||
return ENODEV;
|
||||
}
|
||||
if (ip4_addr_isany_val(*(ip_2_ip4(&netif->netmask)))) {
|
||||
return ENXIO;
|
||||
}
|
||||
sock_in = (struct sockaddr_in *)&ifr->ifr_addr;
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr.s_addr = (ip_2_ip4(&((netif)->ip_addr))->addr | ~(ip_2_ip4(&netif->netmask)->addr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8_t lwip_ioctl_impl(const struct lwip_sock *sock, long cmd, void *argp)
|
||||
{
|
||||
u8_t err = 0;
|
||||
struct ifreq *ifr = (struct ifreq *)argp;
|
||||
u8_t is_ipv6 = 0;
|
||||
|
||||
/* allow it only on IPv6 sockets... */
|
||||
is_ipv6 = NETCONNTYPE_ISIPV6((unsigned int)(sock->conn->type));
|
||||
|
||||
switch ((u32_t)cmd) {
|
||||
case SIOCGIFCONF:
|
||||
if (is_ipv6 != 0) {
|
||||
err = EINVAL;
|
||||
} else {
|
||||
err = lwip_ioctl_internal_SIOCGIFCONF(ifr);
|
||||
}
|
||||
break;
|
||||
case SIOCGIFADDR:
|
||||
if (is_ipv6 != 0) {
|
||||
err = EINVAL;
|
||||
} else {
|
||||
err = lwip_ioctl_internal_SIOCGIFADDR(ifr);
|
||||
}
|
||||
break;
|
||||
case SIOCGIFNETMASK:
|
||||
if (is_ipv6 != 0) {
|
||||
err = EINVAL;
|
||||
} else {
|
||||
err = lwip_ioctl_internal_SIOCGIFNETMASK(ifr);
|
||||
}
|
||||
break;
|
||||
case SIOCGIFHWADDR:
|
||||
err = lwip_ioctl_internal_SIOCGIFHWADDR(ifr);
|
||||
break;
|
||||
case SIOCSIFFLAGS:
|
||||
err = lwip_ioctl_internal_SIOCSIFFLAGS(ifr);
|
||||
break;
|
||||
case SIOCGIFFLAGS:
|
||||
err = lwip_ioctl_internal_SIOCGIFFLAGS(ifr);
|
||||
break;
|
||||
case SIOCGIFNAME:
|
||||
err = lwip_ioctl_internal_SIOCGIFNAME(ifr);
|
||||
break;
|
||||
case SIOCSIFNAME:
|
||||
err = lwip_ioctl_internal_SIOCSIFNAME(ifr);
|
||||
break;
|
||||
case SIOCGIFINDEX:
|
||||
err = lwip_ioctl_internal_SIOCGIFINDEX(ifr);
|
||||
break;
|
||||
case SIOCGIFMTU:
|
||||
err = lwip_ioctl_internal_SIOCGIFMTU(ifr);
|
||||
break;
|
||||
case SIOCGIFBRDADDR:
|
||||
if (is_ipv6 != 0) {
|
||||
err = EINVAL;
|
||||
} else {
|
||||
err = lwip_ioctl_internal_SIOCGIFBRDADDR(ifr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
err = ENOSYS;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(UNIMPL: 0x%lx)\n", cmd));
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static err_t lwip_do_ioctl_impl(struct tcpip_api_call_data *call)
|
||||
{
|
||||
struct lwip_ioctl_apimsg *msg = (struct lwip_ioctl_apimsg *)(void *)call;
|
||||
return lwip_ioctl_impl(msg->sock, msg->cmd, msg->argp);
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd. 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. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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 COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS 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.
|
||||
*/
|
||||
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
#include <lwip/debug.h>
|
||||
#include "prt_typedef.h"
|
||||
#include "prt_task.h"
|
||||
#include "prt_queue.h"
|
||||
#include "prt_sem.h"
|
||||
#include "prt_config.h"
|
||||
#include "prt_sys.h"
|
||||
#include "prt_tick_external.h"
|
||||
#include "prt_task_external.h"
|
||||
#include "prt_clk.h"
|
||||
#include "target_config.h"
|
||||
#include "os_cpu_armv7_m_external.h"
|
||||
#include "prt_queue_external.h"
|
||||
|
||||
#ifndef OSCFG_KERNEL_SMP
|
||||
#define OSCFG_KERNEL_SMP 0
|
||||
#endif
|
||||
|
||||
#if (OSCFG_KERNEL_SMP)
|
||||
OS_SPIN_LOCK_INIT(arch_protect_spin);
|
||||
static u32_t lwprot_thread = OS_ERRNO_TSK_ID_INVALID;
|
||||
static int lwprot_count = 0;
|
||||
#endif /* OSCFG_KERNEL_SMP */
|
||||
|
||||
#define LWIP_LOG_BUF_SIZE 128
|
||||
|
||||
U64 ROUND_UP_DIV(U64 val, U64 div)
|
||||
{
|
||||
return (((val) + (div) - 1) / (div));
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread and System misc
|
||||
*/
|
||||
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio)
|
||||
{
|
||||
TskHandle taskID = OS_ERRNO_TSK_ID_INVALID;
|
||||
U32 ret;
|
||||
struct TskInitParam task;
|
||||
|
||||
if (name == NULL || (strlen(name) == 0)) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: name is null"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create host Task */
|
||||
task.taskEntry = (TskEntryFunc)thread;
|
||||
task.stackSize = (U32)stackSize;
|
||||
task.name = (char *)name;
|
||||
task.taskPrio = (TskPrior)prio;
|
||||
task.stackAddr = 0;
|
||||
ret = PRT_TaskCreate(&taskID, &task);
|
||||
if (ret != OS_OK) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: PRT_TaskCreate error %u\n", ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = PRT_TaskResume(taskID);
|
||||
if (ret != OS_OK) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: PRT_TaskResume error %u\n", ret));
|
||||
return ret;
|
||||
}
|
||||
return taskID;
|
||||
}
|
||||
|
||||
void sys_init(void)
|
||||
{
|
||||
U32 seedlsb = (U32)PRT_ClkGetCycleCount64();
|
||||
srand(seedlsb);
|
||||
}
|
||||
|
||||
u32_t sys_now(void)
|
||||
{
|
||||
return (u32_t)(((u32_t)PRT_TickGetCount() * OS_SYS_MS_PER_SECOND) / OS_TICK_PER_SECOND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protector
|
||||
*/
|
||||
sys_prot_t sys_arch_protect(void)
|
||||
{
|
||||
#if (OSCFG_KERNEL_SMP)
|
||||
/* Note that we are using spinlock instead of mutex for LiteOS-SMP here:
|
||||
* 1. spinlock is more effective for short critical region protection.
|
||||
* 2. this function is called only in task context, not in interrupt handler.
|
||||
* so it's not needed to disable interrupt.
|
||||
*/
|
||||
if (lwprot_thread != RUNNING_TASK->taskPid) {
|
||||
/* We are locking the spinlock where it has not been locked before
|
||||
* or is being locked by another thread */
|
||||
lwprot_thread = RUNNING_TASK->taskPid;
|
||||
lwprot_count = 1;
|
||||
} else {
|
||||
/* It is already locked by THIS thread */
|
||||
lwprot_count++;
|
||||
}
|
||||
#else
|
||||
PRT_TaskLock();
|
||||
|
||||
#endif /* OSCFG_KERNEL_SMP */
|
||||
return 0; /* return value is unused */
|
||||
}
|
||||
|
||||
void sys_arch_unprotect(sys_prot_t pval)
|
||||
{
|
||||
LWIP_UNUSED_ARG(pval);
|
||||
#if (OSCFG_KERNEL_SMP)
|
||||
if (lwprot_thread == RUNNING_TASK->taskPid) {
|
||||
lwprot_count--;
|
||||
if (lwprot_count == 0) {
|
||||
lwprot_thread = OS_ERRNO_TSK_ID_INVALID;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
PRT_TaskUnlock();
|
||||
#endif /* OSCFG_KERNEL_SMP */
|
||||
}
|
||||
|
||||
/**
|
||||
* MessageBox
|
||||
*/
|
||||
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
|
||||
{
|
||||
if (mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_new: mbox is null"));
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
char qName[] = "lwIP";
|
||||
U32 ret = PRT_QueueCreate((U16)size, sizeof(void *), (U32 *)mbox);
|
||||
switch (ret) {
|
||||
case OS_OK:
|
||||
return ERR_OK;
|
||||
case OS_ERRNO_QUEUE_CB_UNAVAILABLE:
|
||||
case OS_ERRNO_QUEUE_CREATE_NO_MEMORY:
|
||||
return ERR_MEM;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("%s: PRT_QueueCreate error %u\n", __FUNCTION__, ret));
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
|
||||
{
|
||||
if (mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox is null"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Caution: the second parameter is NOT &msg */
|
||||
enum QueuePrio prio = OS_QUEUE_NORMAL;
|
||||
U32 ret = PRT_QueueWrite((U32)(*mbox), (void*)&msg, sizeof(char *), OS_WAIT_FOREVER, (U32)prio);
|
||||
if (ret != OS_OK) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("%s: PRT_QueueWrite error %u\n", __FUNCTION__, ret));
|
||||
}
|
||||
}
|
||||
|
||||
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
|
||||
{
|
||||
if (mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_trypost: mbox is null"));
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
/* Caution: the second parameter is NOT &msg */
|
||||
enum QueuePrio prio = OS_QUEUE_NORMAL;
|
||||
U32 ret = PRT_QueueWrite((U32)(*mbox), (void*)&msg, sizeof(char *), 0, (U32)prio);
|
||||
switch (ret) {
|
||||
case OS_OK:
|
||||
return ERR_OK;
|
||||
case OS_ERRNO_QUEUE_NO_SOURCE:
|
||||
return ERR_MEM;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("%s: PRT_QueueWrite error %u\n", __FUNCTION__, ret));
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg)
|
||||
{
|
||||
(void)mbox;
|
||||
(void)msg;
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeoutMs)
|
||||
{
|
||||
if (mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_arch_mbox_fetch: mbox is null"));
|
||||
return (u32_t)ERR_ARG;
|
||||
}
|
||||
void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */
|
||||
U64 tick = ROUND_UP_DIV((U64)timeoutMs * OS_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND);
|
||||
U32 ret = PRT_QueueRead((U32)(*mbox), msg ? msg : &ignore, sizeof(void *), tick ? (U32)tick : OS_WAIT_FOREVER);
|
||||
switch (ret) {
|
||||
case OS_OK:
|
||||
return ERR_OK;
|
||||
case OS_ERRNO_QUEUE_NO_SOURCE:
|
||||
case OS_ERRNO_QUEUE_TIMEOUT:
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("%s: PRT_QueueRead error 0x%x\n", __FUNCTION__, ret));
|
||||
return SYS_ARCH_TIMEOUT; /* Errors should be treated as timeout */
|
||||
}
|
||||
|
||||
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
|
||||
{
|
||||
if (mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_arch_mbox_tryfetch: mbox is null"));
|
||||
return (u32_t)ERR_ARG;
|
||||
}
|
||||
|
||||
void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */
|
||||
U32 ret = PRT_QueueRead((U32)*mbox, msg ? msg : &ignore, sizeof(void *), 0);
|
||||
switch (ret) {
|
||||
case OS_OK:
|
||||
return ERR_OK;
|
||||
case OS_ERRNO_QUEUE_NO_SOURCE:
|
||||
return SYS_MBOX_EMPTY;
|
||||
case OS_ERRNO_QUEUE_TIMEOUT:
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("%s: PRT_QueueRead error %u\n", __FUNCTION__, ret));
|
||||
return SYS_MBOX_EMPTY; /* Errors should be treated as timeout */
|
||||
}
|
||||
|
||||
void sys_mbox_free(sys_mbox_t *mbox)
|
||||
{
|
||||
if (mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_free: mbox is null"));
|
||||
return;
|
||||
}
|
||||
(void)PRT_QueueDelete(*mbox);
|
||||
}
|
||||
|
||||
int sys_mbox_valid(sys_mbox_t *mbox)
|
||||
{
|
||||
if (*mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_valid: mbox is null"));
|
||||
return ERR_ARG;
|
||||
}
|
||||
U32 innerId = OS_QUEUE_INNER_ID(*mbox);
|
||||
struct TagQueCb *queueCb = NULL;
|
||||
queueCb = (struct TagQueCb *)GET_QUEUE_HANDLE(innerId);
|
||||
return queueCb->queueState == OS_QUEUE_USED;
|
||||
}
|
||||
|
||||
void sys_mbox_set_invalid(sys_mbox_t *mbox)
|
||||
{
|
||||
if (mbox == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_set_invalid: mbox is null"));
|
||||
return;
|
||||
}
|
||||
*mbox = OS_QUEUE_MAX_SUPPORT_NUM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Semaphore
|
||||
*/
|
||||
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_new: sem is null"));
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
U32 ret = PRT_SemCreate((U32)count, (SemHandle*)sem);
|
||||
if (ret != OS_OK) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void sys_sem_signal(sys_sem_t *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_signal: sem is null"));
|
||||
return;
|
||||
}
|
||||
(void)PRT_SemPost((SemHandle)(*sem));
|
||||
}
|
||||
|
||||
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeoutMs)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_arch_sem_wait: sem is null"));
|
||||
return (u32_t)ERR_ARG;
|
||||
}
|
||||
U64 tick = ROUND_UP_DIV((U64)timeoutMs * OS_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND);
|
||||
U32 ret = PRT_SemPend((SemHandle)(*sem), tick ? (U32)tick : OS_WAIT_FOREVER);
|
||||
switch (ret) {
|
||||
case OS_OK:
|
||||
return ERR_OK;
|
||||
case OS_ERRNO_SEM_TIMEOUT:
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("%s: PRT_SemPend error %u\n", __FUNCTION__, ret));
|
||||
return SYS_ARCH_TIMEOUT; /* Errors should be treated as timeout */
|
||||
}
|
||||
|
||||
void sys_sem_free(sys_sem_t *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_free: sem is null"));
|
||||
return;
|
||||
}
|
||||
(void)PRT_SemDelete((SemHandle)(*sem));
|
||||
}
|
||||
|
||||
int sys_sem_valid(sys_sem_t *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_valid: sem is null"));
|
||||
return ERR_ARG;
|
||||
}
|
||||
return (SemHandle)(*sem) != OS_SEM_MAX_SUPPORT_NUM;
|
||||
}
|
||||
|
||||
void sys_sem_set_invalid(sys_sem_t *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_set_invalid: sem is null"));
|
||||
return;
|
||||
}
|
||||
*sem = OS_SEM_MAX_SUPPORT_NUM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutex
|
||||
*/
|
||||
err_t sys_mutex_new(sys_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_sem_new: sem is null"));
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
U32 ret = PRT_SemCreate(1, (SemHandle*)(mutex));
|
||||
if (ret != OS_OK) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void sys_mutex_lock(sys_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_lock: mutex is null"));
|
||||
return;
|
||||
}
|
||||
|
||||
(void)PRT_SemPend((SemHandle)(*mutex), OS_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
void sys_mutex_unlock(sys_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_unlock: mutex is null"));
|
||||
return;
|
||||
}
|
||||
|
||||
(void)PRT_SemPost((SemHandle)(*mutex));
|
||||
}
|
||||
|
||||
void sys_mutex_free(sys_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_free: mutex is null"));
|
||||
return;
|
||||
}
|
||||
|
||||
(void)PRT_SemDelete((SemHandle)(*mutex));
|
||||
}
|
||||
|
||||
int sys_mutex_valid(sys_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_valid: mutex is null"));
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
return *mutex != OS_SEM_MAX_SUPPORT_NUM;
|
||||
}
|
||||
|
||||
void sys_mutex_set_invalid(sys_mutex_t *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
LWIP_DEBUGF(SYS_DEBUG, ("sys_mutex_set_invalid: mutex is null"));
|
||||
return;
|
||||
}
|
||||
|
||||
*mutex = OS_SEM_MAX_SUPPORT_NUM;
|
||||
}
|
||||
|
||||
void LwipLogPrintf(const char *fmt, ...)
|
||||
{
|
||||
if ((fmt == NULL) || (strlen(fmt) == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int len;
|
||||
char buf[LWIP_LOG_BUF_SIZE] = {0};
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
len = vsprintf_s(buf, sizeof(buf) - 1, fmt, ap);
|
||||
va_end(ap);
|
||||
if (len < 0) {
|
||||
LWIP_LOGGER("log param invalid or buf is not enough.");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s\n\r", buf);
|
||||
LWIP_LOGGER(buf);
|
||||
}
|
||||
Reference in New Issue
Block a user