update openharmony 1.0.1

This commit is contained in:
mamingshuai
2021-03-11 20:30:40 +08:00
parent c343c46b91
commit 778c8b9930
234 changed files with 9721 additions and 3414 deletions
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_
#include <stdio.h>
#include <stdlib.h>
#include "securec.h"
#include "log.h"
#ifdef htons
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
#endif
#define LWIP_PROVIDE_ERRNO 1
#define __SIZEOF_POINTER__ 4 // 32位系统
#define LOS_TASK_STATUS_DETACHED 0x0100 // 预留字段
#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
extern void HilogPrintf(const char *fmt, ...);
#ifndef HILOG_INFO
#define HILOG_INFO(...)
#ifndef HILOG_MODULE_APP
#define HILOG_MODULE_APP 0
#endif
#endif
#ifndef HILOG_ERROR
#define HILOG_ERROR(...)
#endif
#define LWIP_PLATFORM_DIAG(vars) HilogPrintf vars
#define LWIP_PLATFORM_ASSERT(x) do {HILOG_ERROR(HILOG_MODULE_APP, \
"Assertion \"%s\" errno %d line %d in %s\n", \
x, errno, __LINE__, __FILE__);} while (0)
#define mem_clib_malloc LWIP_MEM_ALLOC
#define mem_clib_free LWIP_MEM_FREE
#define mem_clib_calloc LWIP_MEM_CALLOC
#define init_waitqueue_head(...)
#define poll_check_waiters(...)
#define IOCTL_CMD_CASE_HANDLER()
#define DF_NADDR(addr)
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.114.114")))
#define DNS_SERVER_ADDRESS_SECONDARY(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.115.115")))
#endif /* _LWIP_PORTING_CC_H_ */
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 { /* something to do */ } while (0)
#define PERF_STOP(x) do { /* something to do */ } while (0)
#endif
#endif /* _LWIP_PORTING_PERF_H_ */
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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>
#include "memory_pool.h"
#include "los_mux.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Mutex
*/
typedef uint32_t sys_mutex_t;
/**
* Semaphore
*/
typedef uint32_t sys_sem_t;
/**
* MessageBox
*/
typedef uint32_t sys_mbox_t;
/**
* Protector
*/
typedef void *sys_prot_t;
/**
* Thread
*/
typedef uint32_t sys_thread_t;
#ifdef __cplusplus
}
#endif
#endif /* _LWIP_PORTING_SYS_ARCH_H_ */
@@ -0,0 +1,299 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 0
#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_OFF
#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 // Caution
#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 2
#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 1
#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 CONFIG_NFILE_DESCRIPTORS 1
#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS
#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) // (512*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 0x6000
#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
// 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 LOSCFG_NET_LWIP_SACK_TFTP
#define LWIP_DHCPS 1
#define LWIP_ENABLE_NET_CAPABILITY 1
#define LWIP_ENABLE_CAP_NET_BROADCAST 0
// Options for GT
#undef LWIP_NETIF_PROMISC
#define LWIP_NETIF_PROMISC 0
#undef LWIP_ICMP
#define LWIP_ICMP 0
#undef LWIP_DHCP
#define LWIP_DHCP 0
#undef LWIP_IGMP
#define LWIP_IGMP 0
#undef LWIP_IPV6
#define LWIP_IPV6 0
#undef LWIP_IPV6_DHCP6
#define LWIP_IPV6_DHCP6 0
#undef TCP_SND_BUF
#define TCP_SND_BUF (65535 / 3)
#undef TCP_WND
#define TCP_WND ((TCP_SND_BUF * 2) / 3)
#undef TCP_SND_QUEUELEN
#define TCP_SND_QUEUELEN (2 * (TCP_SND_BUF / TCP_MSS))
#undef MEMP_NUM_NETDB
#define MEMP_NUM_NETDB 1
#undef MEMP_NUM_ARP_QUEUE
#define MEMP_NUM_ARP_QUEUE 4
#undef MEMP_NUM_NETBUF
#define MEMP_NUM_NETBUF 12
#undef MEMP_NUM_NETCONN
#define MEMP_NUM_NETCONN 32
#undef MEMP_NUM_PBUF
#define MEMP_NUM_PBUF 0
#undef PBUF_POOL_SIZE
#define PBUF_POOL_SIZE 0
#undef MEMP_NUM_RAW_PCB
#define MEMP_NUM_RAW_PCB 8
#undef MEMP_NUM_REASSDATA
#define MEMP_NUM_REASSDATA 12
#undef MEMP_NUM_TCPIP_MSG_API
#define MEMP_NUM_TCPIP_MSG_API 32
#undef MEMP_NUM_TCPIP_MSG_INPKT
#define MEMP_NUM_TCPIP_MSG_INPKT 32
#undef MEMP_NUM_TCP_PCB
#define MEMP_NUM_TCP_PCB 8
#undef MEMP_NUM_TCP_PCB_LISTEN
#define MEMP_NUM_TCP_PCB_LISTEN 4
#undef MEMP_NUM_TCP_SEG
#define MEMP_NUM_TCP_SEG 64
#undef MEMP_NUM_UDP_PCB
#define MEMP_NUM_UDP_PCB 4
#undef TCPIP_THREAD_STACKSIZE
#define TCPIP_THREAD_STACKSIZE 0x1000
#undef LWIP_SOCKET_SELECT
#define LWIP_SOCKET_SELECT 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,77 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_
#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 LWIP_NETIF_FULLNAME 16
#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[LWIP_NETIF_FULLNAME]; \
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> // For ETHARP_HWADDR_LEN, by `hieth-sf src/interface.c' and `wal/wal_net.c'
#ifdef __cplusplus
extern "C" {
#endif
// redefine NETIF_NAMESIZE which was defined in netif.h
#undef NETIF_NAMESIZE
#define NETIF_NAMESIZE LWIP_NETIF_FULLNAME
#define LOOPBACK_IF 0 // 772
#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);
#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) 2020-2021 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,38 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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,39 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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_NETDB_PORTING_H__
#define __LITEOS_NETDB_PORTING_H__
#include "lwip/netdb.h"
struct hostent *gethostbyname(const char *name);
#endif // __LITEOS_NETDB_PORTING_H__
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 _SYS_SOCKET_PORTING_H
#define _SYS_SOCKET_PORTING_H
#include "lwip/sockets.h"
#ifdef __cplusplus
extern "C" {
#endif
int socket (int, int, int);
int bind (int, const struct sockaddr *, socklen_t);
int connect (int, const struct sockaddr *, socklen_t);
int listen (int, int);
int accept (int, struct sockaddr *__restrict, socklen_t *__restrict);
int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict);
ssize_t send (int, const void *, size_t, int);
ssize_t recv (int, void *, size_t, int);
ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
ssize_t sendmsg (int, const struct msghdr *, int);
ssize_t recvmsg (int, struct msghdr *, int);
int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict);
int setsockopt (int, int, int, const void *, socklen_t);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
int inet_pton(int af, const char *src, void *dst);
int shutdown (int, int);
int closesocket(int sockfd);
int ioctlsocket(int s, long cmd, void *argp);
#if LWIP_SOCKET_SELECT
int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout);
#endif
#if LWIP_SOCKET_POLL
int poll(struct pollfd *fds, nfds_t nfds, int timeout);
#endif
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,357 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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/snmp.h>
#include <lwip/etharp.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,40 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <stdio.h>
#include <stdlib.h>
#include "lwip/tcpip.h"
#include "ohos_init.h"
void TcpIpPortingInit()
{
tcpip_init(NULL, NULL);
}
SYSEX_SERVICE_INIT(TcpIpPortingInit);
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "netdb.h"
struct hostent *gethostbyname(const char *name)
{
if (name == NULL) {
return NULL;
}
return lwip_gethostbyname(name);
}
@@ -0,0 +1,181 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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/priv/sockets_priv.h"
#include <lwip/sockets.h>
#if !LWIP_COMPAT_SOCKETS
#define CHECK_NULL_PTR(ptr) do { if ((ptr) == NULL) { set_errno(EFAULT); return -1; } } while (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)
{
CHECK_NULL_PTR(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)
{
CHECK_NULL_PTR(name);
CHECK_NULL_PTR(namelen);
return lwip_getpeername(s, name, namelen);
}
int getsockname(int s, struct sockaddr *name, socklen_t *namelen)
{
CHECK_NULL_PTR(name);
CHECK_NULL_PTR(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)
{
CHECK_NULL_PTR(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)
{
CHECK_NULL_PTR(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)
{
CHECK_NULL_PTR(mem);
return lwip_recvfrom(s, mem, len, flags, from, fromlen);
}
ssize_t recvmsg(int s, struct msghdr *message, int flags)
{
CHECK_NULL_PTR(message);
if (message->msg_iovlen) {
CHECK_NULL_PTR(message->msg_iov);
}
return lwip_recvmsg(s, message, flags);
}
ssize_t send(int s, const void *dataptr, size_t size, int flags)
{
CHECK_NULL_PTR(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)
{
CHECK_NULL_PTR(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);
}
int ioctlsocket(int s, long cmd, void *argp)
{
return lwip_ioctl(s, cmd, argp);
}
#if LWIP_SOCKET_SELECT
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
#if LWIP_SOCKET_POLL
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
{
return lwip_poll(fds, nfds, timeout);
}
#endif
#endif /* !LWIP_COMPAT_SOCKETS */
+342
View File
@@ -0,0 +1,342 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <los_task.h>
#include <los_tick.h>
#include <los_queue.h>
#include <los_sem.h>
#include <los_mux.h>
#include "cmsis_os2.h"
#include <los_timer.h>
#include <los_config.h>
#define YES 1
#define NO 0
#define LOSCFG_KERNEL_SMP NO
#if (LOSCFG_KERNEL_SMP == YES)
SPIN_LOCK_INIT(arch_protect_spin);
static u32_t lwprot_thread = LOS_ERRNO_TSK_ID_INVALID;
static int lwprot_count = 0;
#endif /* LOSCFG_KERNEL_SMP == YES */
#define ROUND_UP_DIV(val, div) (((val) + (div) - 1) / (div))
#define LWIP_LOG_BUF_SIZE 64
/**
* Thread and System misc
*/
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio)
{
UINT32 taskID = LOS_ERRNO_TSK_ID_INVALID;
UINT32 ret;
TSK_INIT_PARAM_S task = {0};
/* Create host Task */
task.pfnTaskEntry = (TSK_ENTRY_FUNC)thread;
task.uwStackSize = stackSize;
task.pcName = (char *)name;
task.usTaskPrio = prio;
task.uwArg = (UINTPTR)arg;
task.uwResved = LOS_TASK_STATUS_DETACHED;
ret = LOS_TaskCreate(&taskID, &task);
if (ret != LOS_OK) {
LWIP_DEBUGF(SYS_DEBUG, ("sys_thread_new: LOS_TaskCreate error %u\n", ret));
return -1;
}
return taskID;
}
void sys_init(void)
{
/* set rand seed to make random sequence diff on every startup */
UINT32 seedhsb, seedlsb;
HalGetCpuCycle(&seedhsb, &seedlsb);
srand(seedlsb);
}
u32_t sys_now(void)
{
/* Lwip docs mentioned like wraparound is not a problem in this funtion */
return (u32_t)osKernelGetTickCount();
}
/**
* Protector
*/
sys_prot_t sys_arch_protect(void)
{
#if (LOSCFG_KERNEL_SMP == YES)
/* 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 != LOS_CurTaskIDGet()) {
/* We are locking the spinlock where it has not been locked before
* or is being locked by another thread */
LOS_SpinLock(&arch_protect_spin);
lwprot_thread = LOS_CurTaskIDGet();
lwprot_count = 1;
} else {
/* It is already locked by THIS thread */
lwprot_count++;
}
#else
LOS_TaskLock();
#endif /* LOSCFG_KERNEL_SMP == YES */
return 0; /* return value is unused */
}
void sys_arch_unprotect(sys_prot_t pval)
{
LWIP_UNUSED_ARG(pval);
#if (LOSCFG_KERNEL_SMP == YES)
if (lwprot_thread == LOS_CurTaskIDGet()) {
lwprot_count--;
if (lwprot_count == 0) {
lwprot_thread = LOS_ERRNO_TSK_ID_INVALID;
LOS_SpinUnlock(&arch_protect_spin);
}
}
#else
LOS_TaskUnlock();
#endif /* LOSCFG_KERNEL_SMP == YES */
}
/**
* MessageBox
*/
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
{
CHAR qName[] = "lwIP";
UINT32 ret = LOS_QueueCreate(qName, (UINT16)size, mbox, 0, sizeof(void *));
switch (ret) {
case LOS_OK:
return ERR_OK;
case LOS_ERRNO_QUEUE_CB_UNAVAILABLE:
case LOS_ERRNO_QUEUE_CREATE_NO_MEMORY:
return ERR_MEM;
default:
break;
}
LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueCreate error %u\n", __FUNCTION__, ret));
return ERR_ARG;
}
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
{
/* Caution: the second parameter is NOT &msg */
UINT32 ret = LOS_QueueWrite(*mbox, msg, sizeof(char *), LOS_WAIT_FOREVER);
if (ret != LOS_OK) {
LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueWrite error %u\n", __FUNCTION__, ret));
}
}
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
{
/* Caution: the second parameter is NOT &msg */
UINT32 ret = LOS_QueueWrite(*mbox, msg, sizeof(char *), 0);
switch (ret) {
case LOS_OK:
return ERR_OK;
case LOS_ERRNO_QUEUE_ISFULL:
return ERR_MEM;
default:
break;
}
LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueWrite error %u\n", __FUNCTION__, ret));
return ERR_ARG;
}
err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg);
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeoutMs)
{
void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */
UINT64 tick = ROUND_UP_DIV((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND);
UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void *), tick ? (UINT32)tick : LOS_WAIT_FOREVER);
switch (ret) {
case LOS_OK:
return ERR_OK;
case LOS_ERRNO_QUEUE_ISEMPTY:
case LOS_ERRNO_QUEUE_TIMEOUT:
return SYS_ARCH_TIMEOUT;
default:
break;
}
LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueRead error %u\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)
{
void *ignore = 0; /* if msg==NULL, the fetched msg should be dropped */
UINT32 ret = LOS_QueueRead(*mbox, msg ? msg : &ignore, sizeof(void *), 0);
switch (ret) {
case LOS_OK:
return ERR_OK;
case LOS_ERRNO_QUEUE_ISEMPTY:
return SYS_MBOX_EMPTY;
case LOS_ERRNO_QUEUE_TIMEOUT:
return SYS_ARCH_TIMEOUT;
default:
break;
}
LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_QueueRead error %u\n", __FUNCTION__, ret));
return SYS_MBOX_EMPTY; /* Errors should be treated as timeout */
}
void sys_mbox_free(sys_mbox_t *mbox)
{
(void)LOS_QueueDelete(*mbox);
}
int sys_mbox_valid(sys_mbox_t *mbox)
{
QUEUE_INFO_S queueInfo;
return LOS_OK == LOS_QueueInfoGet(*mbox, &queueInfo);
}
void sys_mbox_set_invalid(sys_mbox_t *mbox)
{
*mbox = LOSCFG_BASE_IPC_QUEUE_LIMIT;
}
/**
* Semaphore
*/
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
UINT32 ret = LOS_SemCreate(count, sem);
if (ret != LOS_OK) {
return ERR_ARG;
}
return ERR_OK;
}
void sys_sem_signal(sys_sem_t *sem)
{
(void)LOS_SemPost(*sem);
}
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeoutMs)
{
UINT64 tick = ROUND_UP_DIV((UINT64)timeoutMs * LOSCFG_BASE_CORE_TICK_PER_SECOND, OS_SYS_MS_PER_SECOND);
UINT32 ret = LOS_SemPend(*sem, tick ? (UINT32)tick : LOS_WAIT_FOREVER); // timeoutMs 0 means wait forever
switch (ret) {
case LOS_OK:
return ERR_OK;
case LOS_ERRNO_SEM_TIMEOUT:
return SYS_ARCH_TIMEOUT;
default:
break;
}
LWIP_DEBUGF(SYS_DEBUG, ("%s: LOS_SemPend error %u\n", __FUNCTION__, ret));
return SYS_ARCH_TIMEOUT; /* Errors should be treated as timeout */
}
void sys_sem_free(sys_sem_t *sem)
{
(void)LOS_SemDelete(*sem);
}
int sys_sem_valid(sys_sem_t *sem)
{
return *sem != LOSCFG_BASE_IPC_SEM_LIMIT;
}
void sys_sem_set_invalid(sys_sem_t *sem)
{
*sem = LOSCFG_BASE_IPC_SEM_LIMIT;
}
/**
* Mutex
*/
err_t sys_mutex_new(sys_mutex_t *mutex)
{
UINT32 ret = LOS_MuxCreate(mutex);
if (ret != LOS_OK) {
return ERR_ARG;
}
return ERR_OK;
}
void sys_mutex_lock(sys_mutex_t *mutex)
{
(void)LOS_MuxPend(*mutex, LOS_WAIT_FOREVER);
}
void sys_mutex_unlock(sys_mutex_t *mutex)
{
(void)LOS_MuxPost(*mutex);
}
void sys_mutex_free(sys_mutex_t *mutex)
{
(void)LOS_MuxDelete(*mutex);
}
int sys_mutex_valid(sys_mutex_t *mutex)
{
return *mutex != LOSCFG_BASE_IPC_MUX_LIMIT;
}
void sys_mutex_set_invalid(sys_mutex_t *mutex)
{
*mutex = LOSCFG_BASE_IPC_MUX_LIMIT;
}
void HilogPrintf(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) {
HILOG_INFO(HILOG_MODULE_APP, "log param invalid or buf is not enough.");
return;
}
HILOG_INFO(HILOG_MODULE_APP, buf);
}