update openharmony 1.0.1
This commit is contained in:
40
components/backtrace/BUILD.gn
Normal file
40
components/backtrace/BUILD.gn
Normal file
@@ -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.
|
||||
|
||||
static_library("backtrace") {
|
||||
sources = [ "los_backtrace.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"../../kernel/include",
|
||||
"../../kernel/arch/include",
|
||||
"../../utils",
|
||||
"./",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
277
components/backtrace/los_backtrace.c
Normal file
277
components/backtrace/los_backtrace.c
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* 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 "los_backtrace.h"
|
||||
#include "los_task.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
#if (LOSCFG_BACKTRACE_TYPE == 1)
|
||||
#define OS_BACKTRACE_START 2
|
||||
/* Thumb instruction, so the pc must be an odd number */
|
||||
#define OS_IS_THUMB_INSTRUCTION(pc) ((pc & 0x1) == 1)
|
||||
|
||||
/* BL or BLX instruction flag. */
|
||||
#define OS_BL_INS_MASK 0xF800
|
||||
#define OS_BL_INS_HIGH 0xF800
|
||||
#define OS_BL_INS_LOW 0xF000
|
||||
#define OS_BLX_INX_MASK 0xFF00
|
||||
#define OS_BLX_INX 0x4700
|
||||
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
STATIC INLINE UINTPTR HalSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
STATIC INLINE UINTPTR HalSpGet(VOID)
|
||||
{
|
||||
UINTPTR sp;
|
||||
__asm volatile("mov %0, sp" : "=r" (sp));
|
||||
return sp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalPspGet(VOID)
|
||||
{
|
||||
UINTPTR psp;
|
||||
__asm volatile("mrs %0, psp" : "=r" (psp));
|
||||
return psp;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalMspGet(VOID)
|
||||
{
|
||||
UINTPTR msp;
|
||||
__asm volatile("mrs %0, msp" : "=r" (msp));
|
||||
return msp;
|
||||
}
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
STATIC INLINE BOOL OsInsIsBlOrBlx(UINTPTR addr)
|
||||
{
|
||||
UINT16 ins1 = *((UINT16 *)addr);
|
||||
UINT16 ins2 = *((UINT16 *)(addr + 2)); /* 2: Thumb instruction is two bytes. */
|
||||
|
||||
if (((ins2 & OS_BL_INS_MASK) == OS_BL_INS_HIGH) &&
|
||||
((ins1 & OS_BL_INS_MASK) == OS_BL_INS_LOW)) {
|
||||
return TRUE;
|
||||
} else if ((ins2 & OS_BLX_INX_MASK) == OS_BLX_INX) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsStackAddrGet(UINTPTR *stackStart, UINTPTR *stackEnd)
|
||||
{
|
||||
if (HalSpGet() != HalPspGet()) {
|
||||
*stackStart = HalMspGet();
|
||||
*stackEnd = CSTACK_END_ADDR;
|
||||
} else {
|
||||
UINT32 taskID = LOS_CurTaskIDGet();
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
*stackStart = HalSpGet();
|
||||
*stackEnd = (UINTPTR)taskCB->topOfStack + taskCB->stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR OsAddrIsValid(UINTPTR sp)
|
||||
{
|
||||
UINTPTR pc;
|
||||
BOOL ret;
|
||||
|
||||
/* The stack space pointed to by the current SP may store the LR,
|
||||
so need decrease a word to PC. */
|
||||
pc = *((UINTPTR *)sp) - sizeof(UINTPTR);
|
||||
|
||||
if (!OS_IS_THUMB_INSTRUCTION(pc)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* PC in thumb mode is an odd number, fix the PC address by decreasing one byte. */
|
||||
pc = *((UINTPTR *)sp) - 1;
|
||||
|
||||
ret = OsStackDataIsCodeAddr(pc);
|
||||
if (ret == FALSE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = OsInsIsBlOrBlx(pc - sizeof(UINTPTR));
|
||||
if (ret == FALSE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount)
|
||||
{
|
||||
if (LR == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
UINTPTR stackStart;
|
||||
UINTPTR stackEnd;
|
||||
UINT32 count = 0;
|
||||
UINT32 index = 0;
|
||||
UINTPTR sp;
|
||||
UINTPTR pc;
|
||||
|
||||
OsStackAddrGet(&stackStart, &stackEnd);
|
||||
|
||||
/* Traverse the stack space and find the LR address. */
|
||||
for (sp = stackStart; sp < stackEnd; sp += sizeof(UINTPTR)) {
|
||||
pc = OsAddrIsValid(sp);
|
||||
if ((pc != 0) && (count < LRSize)) {
|
||||
if (index++ < jumpCount) {
|
||||
continue;
|
||||
}
|
||||
LR[count] = pc;
|
||||
count++;
|
||||
if (count == LRSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count < LRSize) {
|
||||
LR[count] = 0;
|
||||
}
|
||||
}
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 2)
|
||||
STATIC INLINE BOOL OsBackTraceFpCheck(UINT32 value);
|
||||
#define OS_BACKTRACE_START 1
|
||||
#define OS_RA_OFFSET 4
|
||||
#define OS_FP_OFFSET 8
|
||||
#define OS_FP_ALIGN(value) (((UINT32)(value) & (UINT32)(LOSCFG_STACK_POINT_ALIGN_SIZE - 1)) == 0)
|
||||
#define OS_FP_CHECK(value) (((UINT32)(value) != FP_INIT_VALUE) && OS_FP_ALIGN(value))
|
||||
|
||||
STATIC INLINE UINTPTR OsFpGet(VOID)
|
||||
{
|
||||
UINTPTR fp = 0;
|
||||
__asm volatile("mv %0, s0" : "=r"(fp));
|
||||
dsb();
|
||||
return fp;
|
||||
}
|
||||
|
||||
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount)
|
||||
{
|
||||
UINT32 backFp = OsFpGet();
|
||||
UINT32 tmpFp;
|
||||
UINT32 backRa;
|
||||
UINT32 count = 0;
|
||||
UINT32 index = 0;
|
||||
|
||||
if (LR == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (OS_FP_CHECK(backFp)) {
|
||||
tmpFp = backFp;
|
||||
backRa = *((UINT32 *)(UINTPTR)(tmpFp - OS_RA_OFFSET));
|
||||
backFp = *((UINT32 *)(UINTPTR)(tmpFp - OS_FP_OFFSET));
|
||||
if (index++ < jumpCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LR[count] = backRa;
|
||||
count++;
|
||||
if ((count == LRSize) || (backFp == tmpFp) ||
|
||||
(!OsStackDataIsCodeAddr(backRa))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count < LRSize) {
|
||||
LR[count] = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error Unknown backtrace type.
|
||||
#endif
|
||||
|
||||
VOID LOS_BackTrace(VOID)
|
||||
{
|
||||
UINTPTR LR[BACKTRACE_MAX_DEPTH] = {0};
|
||||
UINT32 index;
|
||||
|
||||
LOS_RecordLR(LR, BACKTRACE_MAX_DEPTH, OS_BACKTRACE_START);
|
||||
|
||||
if (LOS_TaskIsRunning()) {
|
||||
PRINTK("taskName = %s\n", g_losTask.runTask->taskName);
|
||||
PRINTK("taskID = %u\n", g_losTask.runTask->taskID);
|
||||
}
|
||||
|
||||
PRINTK("----- traceback start -----\r\n");
|
||||
for (index = 0; index < BACKTRACE_MAX_DEPTH; index++) {
|
||||
if (LR[index] == 0) {
|
||||
break;
|
||||
}
|
||||
PRINTK("traceback %d -- lr = 0x%x\r\n", index, LR[index]);
|
||||
}
|
||||
PRINTK("----- traceback end -----\r\n");
|
||||
}
|
||||
|
||||
VOID LOS_BackTraceInit(VOID)
|
||||
{
|
||||
OsBackTraceHookSet(LOS_RecordLR);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
162
components/backtrace/los_backtrace.h
Normal file
162
components/backtrace/los_backtrace.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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 _LOS_BACKTRACE_H
|
||||
#define _LOS_BACKTRACE_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define BACKTRACE_MAX_DEPTH LOSCFG_BACKTRACE_DEPTH
|
||||
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
#if (LOSCFG_BACKTRACE_TYPE == 1)
|
||||
/* The default name of the code section and CSTACK section are given below,
|
||||
and the user can be adjust it according to the linker script file. */
|
||||
#if defined(__ICCARM__)
|
||||
/* The default code section name is .text */
|
||||
#define CODE_SECTION_NAME ".text"
|
||||
/* The default C stack section name is CSTACK */
|
||||
#define CSTACK_SECTION_NAME "CSTACK"
|
||||
#pragma section=CODE_SECTION_NAME
|
||||
#pragma section=CSTACK_SECTION_NAME
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and modify the OsStackDataIsCodeAddr function
|
||||
to support searching in multiple code sections */
|
||||
#define CODE_START_ADDR ((UINTPTR)__section_begin(CODE_SECTION_NAME))
|
||||
#define CODE_END_ADDR ((UINTPTR)__section_end(CODE_SECTION_NAME))
|
||||
#define CSTACK_START_ADDR ((UINTPTR)__section_begin(CSTACK_SECTION_NAME))
|
||||
#define CSTACK_END_ADDR ((UINTPTR)__section_end(CSTACK_SECTION_NAME))
|
||||
#elif defined(__CC_ARM) || defined(__CLANG_ARM)
|
||||
/* The default code section name is ER_IROM1 */
|
||||
#define CODE_SECTION_NAME ER_IROM1
|
||||
/* The default C stack section name is STACK */
|
||||
#define CSTACK_SECTION_NAME STACK
|
||||
|
||||
#define SECTION_START(_name_) _name_##$$Base
|
||||
#define SECTION_END(_name_) _name_##$$Limit
|
||||
#define CSTACK_SECTION_START(_name_) SECTION_START(_name_)
|
||||
#define CSTACK_SECTION_END(_name_) SECTION_END(_name_)
|
||||
|
||||
#define IMAGE_SECTION_START(_name_) Image$$##_name_##$$Base
|
||||
#define IMAGE_SECTION_END(_name_) Image$$##_name_##$$Limit
|
||||
#define CODE_SECTION_START(_name_) IMAGE_SECTION_START(_name_)
|
||||
#define CODE_SECTION_END(_name_) IMAGE_SECTION_END(_name_)
|
||||
|
||||
extern CHAR *CSTACK_SECTION_START(CSTACK_SECTION_NAME);
|
||||
extern CHAR *CSTACK_SECTION_END(CSTACK_SECTION_NAME);
|
||||
extern CHAR *CODE_SECTION_START(CODE_SECTION_NAME);
|
||||
extern CHAR *CODE_SECTION_END(CODE_SECTION_NAME);
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and modify the OsStackDataIsCodeAddr function
|
||||
to support searching in multiple code sections */
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START(CODE_SECTION_NAME))
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END(CODE_SECTION_NAME))
|
||||
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START(CSTACK_SECTION_NAME))
|
||||
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END(CSTACK_SECTION_NAME))
|
||||
#elif defined(__GNUC__)
|
||||
/* The defalut code section start address */
|
||||
#define CODE_SECTION_START _stext
|
||||
/* The defalut code section end address */
|
||||
#define CODE_SECTION_END _etext
|
||||
/* The default C stack section start address */
|
||||
#define CSTACK_SECTION_START _sstack
|
||||
/* The default C stack section end address */
|
||||
#define CSTACK_SECTION_END _estack
|
||||
|
||||
extern CHAR *CODE_SECTION_START;
|
||||
extern CHAR *CODE_SECTION_END;
|
||||
extern CHAR *CSTACK_SECTION_START;
|
||||
extern CHAR *CSTACK_SECTION_END;
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and modify the OsStackDataIsCodeAddr function
|
||||
to support searching in multiple code sections */
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
|
||||
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START)
|
||||
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END)
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 2)
|
||||
#if defined(__GNUC__)
|
||||
/* The defalut code section start address */
|
||||
#define CODE_SECTION_START __text_start
|
||||
/* The defalut code section end address */
|
||||
#define CODE_SECTION_END __text_end
|
||||
|
||||
extern CHAR *CODE_SECTION_START;
|
||||
extern CHAR *CODE_SECTION_END;
|
||||
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function is used to judge whether the data in the stack is a code section address.
|
||||
The default code section is only one, but there may be more than one. Modify the
|
||||
judgment condition to support multiple code sections. */
|
||||
STATIC INLINE BOOL OsStackDataIsCodeAddr(UINTPTR value)
|
||||
{
|
||||
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* This function is currently used to register the memory leak check hook,
|
||||
other uses do not need to be called temporarily. */
|
||||
VOID LOS_BackTraceInit(VOID);
|
||||
|
||||
/* This function is used to print the function call stack. */
|
||||
VOID LOS_BackTrace(VOID);
|
||||
|
||||
/* This function is used to record the function call stack. */
|
||||
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
74
components/bounds_checking_function/BUILD.gn
Executable file
74
components/bounds_checking_function/BUILD.gn
Executable file
@@ -0,0 +1,74 @@
|
||||
# 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.
|
||||
|
||||
static_library("sec") {
|
||||
include_dirs = [ "//third_party/bounds_checking_function/include" ]
|
||||
|
||||
sources = [
|
||||
"//third_party/bounds_checking_function/src/fscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/fwscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/gets_s.c",
|
||||
"//third_party/bounds_checking_function/src/memcpy_s.c",
|
||||
"//third_party/bounds_checking_function/src/memmove_s.c",
|
||||
"//third_party/bounds_checking_function/src/memset_s.c",
|
||||
"//third_party/bounds_checking_function/src/scanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/securecutil.c",
|
||||
"//third_party/bounds_checking_function/src/secureinput_a.c",
|
||||
"//third_party/bounds_checking_function/src/secureinput_w.c",
|
||||
"//third_party/bounds_checking_function/src/secureprintoutput_a.c",
|
||||
"//third_party/bounds_checking_function/src/secureprintoutput_w.c",
|
||||
"//third_party/bounds_checking_function/src/snprintf_s.c",
|
||||
"//third_party/bounds_checking_function/src/sprintf_s.c",
|
||||
"//third_party/bounds_checking_function/src/sscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/strcat_s.c",
|
||||
"//third_party/bounds_checking_function/src/strcpy_s.c",
|
||||
"//third_party/bounds_checking_function/src/strncat_s.c",
|
||||
"//third_party/bounds_checking_function/src/strncpy_s.c",
|
||||
"//third_party/bounds_checking_function/src/strtok_s.c",
|
||||
"//third_party/bounds_checking_function/src/swprintf_s.c",
|
||||
"//third_party/bounds_checking_function/src/swscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vfscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vfwscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vsnprintf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vsprintf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vsscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vswprintf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vswscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/vwscanf_s.c",
|
||||
"//third_party/bounds_checking_function/src/wcscat_s.c",
|
||||
"//third_party/bounds_checking_function/src/wcscpy_s.c",
|
||||
"//third_party/bounds_checking_function/src/wcsncat_s.c",
|
||||
"//third_party/bounds_checking_function/src/wcsncpy_s.c",
|
||||
"//third_party/bounds_checking_function/src/wcstok_s.c",
|
||||
"//third_party/bounds_checking_function/src/wmemcpy_s.c",
|
||||
"//third_party/bounds_checking_function/src/wmemmove_s.c",
|
||||
"//third_party/bounds_checking_function/src/wscanf_s.c",
|
||||
]
|
||||
}
|
||||
37
components/cppsupport/BUILD.gn
Normal file
37
components/cppsupport/BUILD.gn
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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.
|
||||
|
||||
static_library("cppsupport") {
|
||||
sources = [ "los_cppsupport.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"../../utils",
|
||||
"./",
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
40
components/cpup/BUILD.gn
Normal file
40
components/cpup/BUILD.gn
Normal file
@@ -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.
|
||||
|
||||
static_library("cpup") {
|
||||
sources = [ "los_cpup.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"../../kernel/include",
|
||||
"../../kernel/arch/include",
|
||||
"../../utils",
|
||||
"./",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
42
components/exchook/BUILD.gn
Normal file
42
components/exchook/BUILD.gn
Normal file
@@ -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.
|
||||
|
||||
static_library("exchook") {
|
||||
sources = [
|
||||
"los_exc_info.c",
|
||||
"los_exchook.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"../../kernel/arch/include",
|
||||
"../../kernel/include",
|
||||
"../../utils",
|
||||
"./",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
@@ -41,6 +41,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
#define INFO_TYPE_AND_SIZE 8
|
||||
|
||||
#define MAX_SCENE_INFO_SIZE (INFO_TYPE_AND_SIZE + sizeof(ExcInfo) + sizeof(EXC_CONTEXT_S))
|
||||
@@ -108,6 +109,7 @@ typedef struct {
|
||||
|
||||
VOID OsExcMsgDumpInit(VOID);
|
||||
extern UINT8 g_excMsgArray[MAX_EXC_MEM_SIZE];
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
4
components/exchook/los_exchook.c
Normal file → Executable file
4
components/exchook/los_exchook.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
4
components/exchook/los_exchook.h
Normal file → Executable file
4
components/exchook/los_exchook.h
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
39
components/fs/BUILD.gn
Normal file
39
components/fs/BUILD.gn
Normal file
@@ -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.
|
||||
|
||||
declare_args() {
|
||||
enable_ohos_kernel_liteos_m_fatfs = true
|
||||
}
|
||||
|
||||
group("fs") {
|
||||
deps = []
|
||||
if (enable_ohos_kernel_liteos_m_fatfs == true) {
|
||||
deps += [ "fatfs:fatfs" ]
|
||||
}
|
||||
}
|
||||
47
components/fs/fatfs/BUILD.gn
Normal file
47
components/fs/fatfs/BUILD.gn
Normal file
@@ -0,0 +1,47 @@
|
||||
# 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.
|
||||
|
||||
static_library("fatfs") {
|
||||
sources = [
|
||||
"fatfs.c",
|
||||
"fs.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../../../kernel/arch/include",
|
||||
"../../../kernel/include",
|
||||
"../../../utils",
|
||||
"../../../kal/cmsis",
|
||||
"../../../kal",
|
||||
"../../../kal/posix/include",
|
||||
"./",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//third_party/FatFs/source/",
|
||||
]
|
||||
}
|
||||
148
components/fs/fatfs/fatfs.c
Normal file → Executable file
148
components/fs/fatfs/fatfs.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
@@ -29,21 +29,18 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_compiler.h"
|
||||
#include "fcntl.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "dirent.h"
|
||||
#include "stdio.h"
|
||||
#include "ff.h"
|
||||
#if FF_USE_EXPAND
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include "fatfs.h"
|
||||
#include "errno.h"
|
||||
#include "limits.h"
|
||||
#include "pthread.h"
|
||||
#include "time.h"
|
||||
#include "securec.h"
|
||||
#include "ff.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_debug.h"
|
||||
#include "fatfs.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
#define FS_SUCCESS 0
|
||||
@@ -55,10 +52,6 @@
|
||||
#define FAT_MAX_OPEN_DIRS 8
|
||||
#endif /* FAT_MAX_OPEN_DIRS */
|
||||
|
||||
#ifndef FAT_MAX_OPEN_FILES
|
||||
#define FAT_MAX_OPEN_FILES 50
|
||||
#endif /* FAT_MAX_OPEN_FILES */
|
||||
|
||||
#ifndef FS_LOCK_TIMEMOUT_SEC
|
||||
#define FS_LOCK_TIMEMOUT_SEC 15
|
||||
#endif /* FS_LOCK_TIMEMOUT_SEC */
|
||||
@@ -327,9 +320,9 @@ static int FatfsErrno(int result)
|
||||
return status;
|
||||
}
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
int fatfs_mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
INT32 index;
|
||||
FRESULT res;
|
||||
@@ -386,7 +379,7 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int umount(const char *target)
|
||||
int fatfs_umount(const char *target)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -482,7 +475,7 @@ static int CloseAll(int index)
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
int umount2(const char *target, int flag)
|
||||
int fatfs_umount2(const char *target, int flag)
|
||||
{
|
||||
INT32 index;
|
||||
INT32 ret;
|
||||
@@ -546,7 +539,7 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int open(const char *path, int oflag, ...)
|
||||
int fatfs_open(const char *path, int oflag, ...)
|
||||
{
|
||||
FRESULT res;
|
||||
UINT32 i;
|
||||
@@ -626,7 +619,7 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
int fatfs_close(int fd)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -667,7 +660,7 @@ int close(int fd)
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t nbyte)
|
||||
ssize_t fatfs_read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -699,7 +692,7 @@ ssize_t read(int fd, void *buf, size_t nbyte)
|
||||
return (ssize_t)lenRead;
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void *buf, size_t nbyte)
|
||||
ssize_t fatfs_write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -743,7 +736,7 @@ ERROUT:
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
off_t fatfs_lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -787,7 +780,7 @@ ERROUT:
|
||||
}
|
||||
|
||||
/* Remove the specified FILE */
|
||||
int unlink(const char *path)
|
||||
int fatfs_unlink(const char *path)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -833,7 +826,7 @@ OUT:
|
||||
}
|
||||
|
||||
/* Return information about a file */
|
||||
int fstat(int fd, struct stat *buf)
|
||||
int fatfs_fstat(int fd, struct stat *buf)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
@@ -864,7 +857,7 @@ int fstat(int fd, struct stat *buf)
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
int stat(const char *__restrict path, struct stat *__restrict buf)
|
||||
int fatfs_stat(const char *path, struct stat *buf)
|
||||
{
|
||||
FRESULT res;
|
||||
FILINFO fileInfo = {0};
|
||||
@@ -918,7 +911,7 @@ OUT:
|
||||
}
|
||||
|
||||
/* Synchronize all changes to Flash */
|
||||
int fsync(int fd)
|
||||
int fatfs_fsync(int fd)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -952,7 +945,7 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode)
|
||||
int fatfs_mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -996,7 +989,7 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
DIR *opendir(const char *dirName)
|
||||
DIR *fatfs_opendir(const char *dirName)
|
||||
{
|
||||
FRESULT res;
|
||||
UINT32 openNum = 0;
|
||||
@@ -1058,7 +1051,7 @@ ERROUT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
struct dirent *fatfs_readdir(DIR *dir)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -1095,7 +1088,7 @@ struct dirent *readdir(DIR *dir)
|
||||
return &g_retValue;
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
int fatfs_closedir(DIR *dir)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -1126,7 +1119,7 @@ int closedir(DIR *dir)
|
||||
return FS_SUCCESS;
|
||||
}
|
||||
|
||||
int rmdir(const char *path)
|
||||
int fatfs_rmdir(const char *path)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -1170,7 +1163,7 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int rename(const char *oldName, const char *newName)
|
||||
int fatfs_rename(const char *oldName, const char *newName)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
@@ -1214,7 +1207,7 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf)
|
||||
int fatfs_statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
FATFS *fs = NULL;
|
||||
UINT32 freeClust;
|
||||
@@ -1264,6 +1257,85 @@ OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int do_truncate(int fd, off_t length, UINT count)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret = FR_OK;
|
||||
DWORD csz;
|
||||
|
||||
csz = (DWORD)(g_handle[fd].fil.obj.fs)->csize * SS(g_handle[fd].fil.obj.fs); /* Cluster size */
|
||||
if (length > csz * count) {
|
||||
#if FF_USE_EXPAND
|
||||
res = f_expand(&g_handle[fd].fil, 0, (FSIZE_t)(length), FALLOC_FL_KEEP_SIZE);
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
ret = FS_FAILURE;
|
||||
return ret;
|
||||
#endif
|
||||
} else if (length < csz * count) {
|
||||
res = f_truncate(&g_handle[fd].fil, (FSIZE_t)length);
|
||||
}
|
||||
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = FS_FAILURE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_handle[fd].fil.obj.objsize = length; /* Set file size to length */
|
||||
g_handle[fd].fil.flag |= 0x40; /* Set modified flag */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fatfs_ftruncate(int fd, off_t length)
|
||||
{
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
UINT count;
|
||||
DWORD fclust;
|
||||
|
||||
if (!IsValidFd(fd)) {
|
||||
errno = EBADF;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if ((length < 0) || (length > UINT_MAX)) {
|
||||
errno = EINVAL;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
ret = FsLock();
|
||||
if (ret != 0) {
|
||||
errno = ret;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (!FsCheckByID(g_handle[fd].fil.obj.fs->id)) {
|
||||
errno = EACCES;
|
||||
ret = FS_FAILURE;
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
res = f_getclustinfo(&g_handle[fd].fil, &fclust, &count);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = FS_FAILURE;
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
ret = do_truncate(fd, length, count);
|
||||
if (ret != FR_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
ret = FS_SUCCESS;
|
||||
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fatfs_fdisk(int pdrv, const unsigned int *partTbl)
|
||||
{
|
||||
INT32 index;
|
||||
@@ -1348,4 +1420,4 @@ int fatfs_format(const char *dev, int sectors, int option)
|
||||
OUT:
|
||||
FsUnlock();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
40
components/fs/fatfs/fatfs.h
Normal file → Executable file
40
components/fs/fatfs/fatfs.h
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
@@ -32,17 +32,51 @@
|
||||
#ifndef _FATFS_H
|
||||
#define _FATFS_H
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "dirent.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "fs_config.h"
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef FAT_MAX_OPEN_FILES
|
||||
#define FAT_MAX_OPEN_FILES 50
|
||||
#endif /* FAT_MAX_OPEN_FILES */
|
||||
|
||||
/* Format options */
|
||||
#define FMT_FAT 0x01
|
||||
#define FMT_FAT32 0x02
|
||||
#define FMT_ANY 0x07
|
||||
|
||||
int fatfs_mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
int fatfs_umount(const char *target);
|
||||
int fatfs_umount2(const char *target, int flag);
|
||||
int fatfs_open(const char *path, int oflag, ...);
|
||||
int fatfs_close(int fd);
|
||||
ssize_t fatfs_read(int fd, void *buf, size_t nbyte);
|
||||
ssize_t fatfs_write(int fd, const void *buf, size_t nbyte);
|
||||
off_t fatfs_lseek(int fd, off_t offset, int whence);
|
||||
int fatfs_unlink(const char *path);
|
||||
int fatfs_fstat(int fd, struct stat *buf);
|
||||
int fatfs_stat(const char *path, struct stat *buf);
|
||||
int fatfs_fsync(int fd);
|
||||
int fatfs_mkdir(const char *path, mode_t mode);
|
||||
DIR *fatfs_opendir(const char *dirName);
|
||||
struct dirent *fatfs_readdir(DIR *dir);
|
||||
int fatfs_closedir(DIR *dir);
|
||||
int fatfs_rmdir(const char *path);
|
||||
int fatfs_rename(const char *oldName, const char *newName);
|
||||
int fatfs_statfs(const char *path, struct statfs *buf);
|
||||
int fatfs_ftruncate(int fd, off_t length);
|
||||
|
||||
/**
|
||||
* @brief divide a physical drive (SD card, U disk, and MMC card), this function is OHOS-specific
|
||||
* @param pdrv physical drive number.
|
||||
@@ -77,4 +111,4 @@ int fatfs_format(const char *dev, int sectors, int option);
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _FATFS_H */
|
||||
#endif /* _FATFS_H */
|
||||
|
||||
343
components/fs/fatfs/fs.c
Executable file
343
components/fs/fatfs/fs.c
Executable file
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* 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 "fatfs.h"
|
||||
#include "dirent.h"
|
||||
#include "errno.h"
|
||||
#include "fcntl.h"
|
||||
#include "securec.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "sys/stat.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
#include "lwip/lwipopts.h"
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS LWIP_CONFIG_NUM_SOCKETS
|
||||
#else
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS 0
|
||||
#endif
|
||||
|
||||
#define CONFIG_NFILE_DESCRIPTORS FAT_MAX_OPEN_FILES /* only for random currently */
|
||||
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
#include "hks_client.h"
|
||||
#define RANDOM_DEV_FD CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS
|
||||
#define RANDOM_DEV_PATH "/dev/random"
|
||||
#endif
|
||||
|
||||
#define FREE_AND_SET_NULL(ptr) do { \
|
||||
free(ptr); \
|
||||
ptr = NULL; \
|
||||
} while (0)
|
||||
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
/**
|
||||
* @brief Get canonical form of a given path based on cwd(Current working directory).
|
||||
*
|
||||
* @param cwd Indicates the current working directory.
|
||||
* @param path Indicates the path to be canonicalization.
|
||||
* @param buf Indicates the pointer to the buffer where the result will be return.
|
||||
* @param bufSize Indicates the size of the buffer.
|
||||
* @return Returns the length of the canonical path.
|
||||
*
|
||||
* @attention if path is an absolute path, cwd is ignored. if cwd if not specified, it is assumed to be root('/').
|
||||
* if the buffer is not big enough the result will be truncated, but the return value will always be the
|
||||
* length of the canonical path.
|
||||
*/
|
||||
static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, size_t bufSize)
|
||||
{
|
||||
size_t offset;
|
||||
if (!path) {
|
||||
path = "";
|
||||
}
|
||||
|
||||
if (!cwd || path[0] == '/') {
|
||||
cwd = "";
|
||||
}
|
||||
|
||||
offset = strlen("///") + 1; // three '/' and one '\0'
|
||||
size_t tmpLen = strlen(cwd) + strlen(path) + offset;
|
||||
char *tmpBuf = (char *)malloc(tmpLen);
|
||||
if (tmpBuf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *p;
|
||||
/* replace /./ to / */
|
||||
offset = strlen("/./") - 1;
|
||||
while ((p = strstr(tmpBuf, "/./")) != NULL) {
|
||||
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* replace // to / */
|
||||
while ((p = strstr(tmpBuf, "//")) != NULL) {
|
||||
if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* handle /../ (e.g., replace /aa/bb/../ to /aa/) */
|
||||
offset = strlen("/../") - 1;
|
||||
while ((p = strstr(tmpBuf, "/../")) != NULL) {
|
||||
char *start = p;
|
||||
while (start > tmpBuf && *(start - 1) != '/') {
|
||||
--start;
|
||||
}
|
||||
if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t totalLen = strlen(tmpBuf);
|
||||
/* strip the last / */
|
||||
if (totalLen > 1 && tmpBuf[totalLen - 1] == '/') {
|
||||
tmpBuf[--totalLen] = 0;
|
||||
}
|
||||
|
||||
if (!buf || bufSize == 0) {
|
||||
free(tmpBuf);
|
||||
return totalLen;
|
||||
}
|
||||
|
||||
if (EOK != memcpy_s(buf, bufSize, tmpBuf, (((totalLen + 1) > bufSize) ? bufSize : (totalLen + 1)))) {
|
||||
free(tmpBuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
buf[bufSize - 1] = 0;
|
||||
free(tmpBuf);
|
||||
return totalLen;
|
||||
}
|
||||
#endif
|
||||
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
return fatfs_mount(source, target, filesystemtype, mountflags, data);
|
||||
}
|
||||
|
||||
int umount(const char *target)
|
||||
{
|
||||
return fatfs_umount(target);
|
||||
}
|
||||
|
||||
int umount2(const char *target, int flag)
|
||||
{
|
||||
return fatfs_umount2(target, flag);
|
||||
}
|
||||
|
||||
int open(const char *path, int oflag, ...)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
|
||||
if ((unsigned)oflag & ~flags) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t pathLen = strlen(path) + 1;
|
||||
char *canonicalPath = (char *)malloc(pathLen);
|
||||
if (!canonicalPath) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
if (GetCanonicalPath(NULL, path, canonicalPath, pathLen) == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(canonicalPath, RANDOM_DEV_PATH) == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
if ((O_ACCMODE & (unsigned)oflag) != O_RDONLY) {
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
if ((unsigned)oflag & O_DIRECTORY) {
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
return RANDOM_DEV_FD;
|
||||
}
|
||||
if (strcmp(canonicalPath, "/") == 0 || strcmp(canonicalPath, "/dev") == 0) {
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
if ((unsigned)oflag & O_DIRECTORY) {
|
||||
errno = EPERM;
|
||||
return -1;
|
||||
}
|
||||
errno = EISDIR;
|
||||
return -1;
|
||||
}
|
||||
FREE_AND_SET_NULL(canonicalPath);
|
||||
#endif
|
||||
return fatfs_open(path, oflag);
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
|
||||
return closesocket(fd);
|
||||
}
|
||||
#endif
|
||||
return fatfs_close(fd);
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
if (nbyte == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (buf == NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (nbyte > 1024) {
|
||||
nbyte = 1024; /* hks_generate_random: random_size must <= 1024 */
|
||||
}
|
||||
struct hks_blob key = {HKS_BLOB_TYPE_RAW, (uint8_t *)buf, nbyte};
|
||||
if (hks_generate_random(&key) != 0) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
return (ssize_t)nbyte;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
|
||||
return recv(fd, buf, nbyte, 0);
|
||||
}
|
||||
#endif
|
||||
return fatfs_read(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
errno = EBADF; /* "/dev/random" is readonly */
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
if (fd >= CONFIG_NFILE_DESCRIPTORS && fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
|
||||
return send(fd, buf, nbyte, 0);
|
||||
}
|
||||
#endif
|
||||
return fatfs_write(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
return fatfs_lseek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int unlink(const char *path)
|
||||
{
|
||||
return fatfs_unlink(path);
|
||||
}
|
||||
|
||||
int fstat(int fd, struct stat *buf)
|
||||
{
|
||||
return fatfs_fstat(fd, buf);
|
||||
}
|
||||
|
||||
int stat(const char *path, struct stat *buf)
|
||||
{
|
||||
return fatfs_stat(path, buf);
|
||||
}
|
||||
|
||||
int fsync(int fd)
|
||||
{
|
||||
return fatfs_fsync(fd);
|
||||
}
|
||||
|
||||
int mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
return fatfs_mkdir(path, mode);
|
||||
}
|
||||
|
||||
DIR *opendir(const char *dirName)
|
||||
{
|
||||
return fatfs_opendir(dirName);
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
return fatfs_readdir(dir);
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
return fatfs_closedir(dir);
|
||||
}
|
||||
|
||||
int rmdir(const char *path)
|
||||
{
|
||||
return fatfs_rmdir(path);
|
||||
}
|
||||
|
||||
int rename(const char *oldName, const char *newName)
|
||||
{
|
||||
return fatfs_rename(oldName, newName);
|
||||
}
|
||||
|
||||
int statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
return fatfs_statfs(path, buf);
|
||||
}
|
||||
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
return fatfs_ftruncate(fd, length);
|
||||
}
|
||||
178
components/net/lwip-2.1/enhancement/src/fixme.c
Normal file
178
components/net/lwip-2.1/enhancement/src/fixme.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* 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/etharp.h>
|
||||
#include <lwip/netifapi.h>
|
||||
#include <lwip/priv/api_msg.h>
|
||||
|
||||
#define NETIFAPI_VAR_REF(name) API_VAR_REF(name)
|
||||
#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name)
|
||||
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
|
||||
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
|
||||
|
||||
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;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
NETIFAPI_VAR_REF(msg).netif = NULL;
|
||||
#if LWIP_MPU_COMPATIBLE
|
||||
if (strncpy_s(NETIFAPI_VAR_REF(msg).msg.ifs.name, NETIF_NAMESIZE, name, NETIF_NAMESIZE - 1)) {
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return netif;
|
||||
}
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.name[NETIF_NAMESIZE - 1] = '\0';
|
||||
#else
|
||||
NETIFAPI_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;
|
||||
NETIFAPI_VAR_FREE(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;
|
||||
const char *sc = 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) < 5) { // 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 >> 16);
|
||||
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 */
|
||||
104
components/net/lwip-2.1/porting/include/arch/cc.h
Normal file
104
components/net/lwip-2.1/porting/include/arch/cc.h
Normal file
@@ -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_ */
|
||||
42
components/net/lwip-2.1/porting/include/arch/perf.h
Normal file
42
components/net/lwip-2.1/porting/include/arch/perf.h
Normal file
@@ -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_ */
|
||||
72
components/net/lwip-2.1/porting/include/arch/sys_arch.h
Normal file
72
components/net/lwip-2.1/porting/include/arch/sys_arch.h
Normal file
@@ -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_ */
|
||||
299
components/net/lwip-2.1/porting/include/lwip/lwipopts.h
Normal file
299
components/net/lwip-2.1/porting/include/lwip/lwipopts.h
Normal file
@@ -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_ */
|
||||
77
components/net/lwip-2.1/porting/include/lwip/netif.h
Normal file
77
components/net/lwip-2.1/porting/include/lwip/netif.h
Normal file
@@ -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_ */
|
||||
54
components/net/lwip-2.1/porting/include/lwip/netifapi.h
Normal file
54
components/net/lwip-2.1/porting/include/lwip/netifapi.h
Normal file
@@ -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_ */
|
||||
38
components/net/lwip-2.1/porting/include/lwipopts.h
Normal file
38
components/net/lwip-2.1/porting/include/lwipopts.h
Normal file
@@ -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__
|
||||
39
components/net/lwip-2.1/porting/include/netdb.h
Normal file
39
components/net/lwip-2.1/porting/include/netdb.h
Normal file
@@ -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__
|
||||
79
components/net/lwip-2.1/porting/include/sys/socket.h
Normal file
79
components/net/lwip-2.1/porting/include/sys/socket.h
Normal file
@@ -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
|
||||
357
components/net/lwip-2.1/porting/src/driverif.c
Normal file
357
components/net/lwip-2.1/porting/src/driverif.c
Normal file
@@ -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;
|
||||
}
|
||||
40
components/net/lwip-2.1/porting/src/lwip_init.c
Normal file
40
components/net/lwip-2.1/porting/src/lwip_init.c
Normal file
@@ -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);
|
||||
40
components/net/lwip-2.1/porting/src/netdb_porting.c
Normal file
40
components/net/lwip-2.1/porting/src/netdb_porting.c
Normal file
@@ -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);
|
||||
}
|
||||
181
components/net/lwip-2.1/porting/src/sockets_porting.c
Normal file
181
components/net/lwip-2.1/porting/src/sockets_porting.c
Normal file
@@ -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
components/net/lwip-2.1/porting/src/sys_arch.c
Executable file
342
components/net/lwip-2.1/porting/src/sys_arch.c
Executable 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);
|
||||
}
|
||||
78
components/net/test/lwip_test.h
Normal file
78
components/net/test/lwip_test.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_TEST_H
|
||||
#define LWIP_TEST_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include "log.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int g_testCase;
|
||||
extern int g_testError;
|
||||
extern int g_testTemp;
|
||||
#define LWIP_TEST_RET_OK 0
|
||||
#define LWIP_TEST_RET_ERR 1
|
||||
|
||||
#define LOCALHOST "127.0.0.1"
|
||||
#define STACK_IP LOCALHOST
|
||||
#define STACK_PORT 2277
|
||||
#define PEER_PORT STACK_PORT
|
||||
#define SERVER_PORT STACK_PORT
|
||||
#define CLIENT_PORT 2288
|
||||
#define PEER_IP LOCALHOST
|
||||
#define BUF_SIZE (128 * 1)
|
||||
#define IOV_LENGTH 2
|
||||
#define STACK_TEST_SIZE (0x800UL)
|
||||
|
||||
#define ICUNIT_ASSERT_NOT_EQUAL(a, b, c) if ((a) == (b)) { \
|
||||
g_testError = (c); \
|
||||
LWIP_ASSERT("lwip test", 0); \
|
||||
}
|
||||
#define ICUNIT_ASSERT_EQUAL(a, b, c) if ((a) != (b)) { \
|
||||
g_testError = (c); \
|
||||
LWIP_ASSERT("lwip test", 0); \
|
||||
}
|
||||
|
||||
#define LogPrintln(fmt, ...) \
|
||||
HILOG_INFO(HILOG_MODULE_APP, fmt "%c", \
|
||||
##__VA_ARGS__, \
|
||||
('\n' == " "fmt[sizeof(" "fmt)-2]) ? '\0' : '\n') // trailing newline is auto appended
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_TEST_H */
|
||||
43
components/net/test/net_socket_test_001.c
Normal file
43
components/net/test/net_socket_test_001.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
|
||||
#define TEST_CASE 110
|
||||
|
||||
int SocketTest(void)
|
||||
{
|
||||
LogPrintln("net_socket_test_001.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int fd = socket(0, 0, 0);
|
||||
LWIP_ASSERT("socket invalid param.", fd == -1);
|
||||
return LWIP_TEST_RET_OK;
|
||||
}
|
||||
116
components/net/test/net_socket_test_002.c
Normal file
116
components/net/test/net_socket_test_002.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
|
||||
#define MSG "Hi, I am UDP"
|
||||
#define TEST_CASE 120
|
||||
|
||||
static char g_buf[BUF_SIZE + 1] = { 0 };
|
||||
|
||||
int UdpTest(void)
|
||||
{
|
||||
LogPrintln("net_socket_test_002.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
int ret;
|
||||
struct msghdr msg = { 0 };
|
||||
struct iovec iov[IOV_LENGTH] = { 0 };
|
||||
int recvCount = 0;
|
||||
|
||||
/* socket creation */
|
||||
sfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
LWIP_ASSERT("socket invalid param.", sfd != -1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT);
|
||||
ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LWIP_ASSERT("socket invalid param.", ret == 0);
|
||||
|
||||
/* send */
|
||||
clnAddr.sin_family = AF_INET;
|
||||
clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
clnAddr.sin_port = htons(PEER_PORT);
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), MSG);
|
||||
ret = sendto(sfd, g_buf, strlen(MSG), 0, (struct sockaddr*)&clnAddr,
|
||||
(socklen_t)sizeof(clnAddr));
|
||||
LWIP_ASSERT("socket invalid param.", ret != -1);
|
||||
|
||||
ret = ioctlsocket(sfd, FIONREAD, &recvCount);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 1);
|
||||
LogPrintln("udp recv count %d", recvCount);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr,
|
||||
&clnAddrLen);
|
||||
LWIP_ASSERT("socket invalid param.", ret == strlen(MSG));
|
||||
|
||||
/* sendmsg */
|
||||
clnAddr.sin_family = AF_INET;
|
||||
clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
clnAddr.sin_port = htons(PEER_PORT);
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), MSG);
|
||||
msg.msg_name = &clnAddr;
|
||||
msg.msg_namelen = sizeof(clnAddr);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = IOV_LENGTH;
|
||||
iov[0].iov_base = g_buf;
|
||||
iov[0].iov_len = strlen(MSG);
|
||||
iov[1].iov_base = g_buf;
|
||||
iov[1].iov_len = strlen(MSG);
|
||||
ret = sendmsg(sfd, &msg, 0);
|
||||
LWIP_ASSERT("socket invalid param.", ret == IOV_LENGTH * strlen(MSG));
|
||||
|
||||
/* recvmsg */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
|
||||
msg.msg_name = &clnAddr;
|
||||
msg.msg_namelen = sizeof(clnAddr);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
iov[0].iov_base = g_buf;
|
||||
iov[0].iov_len = sizeof(g_buf);
|
||||
ret = recvmsg(sfd, &msg, 0);
|
||||
LWIP_ASSERT("socket invalid param.", ret == IOV_LENGTH * strlen(MSG));
|
||||
|
||||
/* close socket */
|
||||
ret = closesocket(sfd);
|
||||
LWIP_ASSERT("socket invalid param.", ret != -1);
|
||||
return LWIP_TEST_RET_OK;
|
||||
}
|
||||
|
||||
252
components/net/test/net_socket_test_003.c
Normal file
252
components/net/test/net_socket_test_003.c
Normal file
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include "lwipopts.h"
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
|
||||
#define SRV_MSG "Hi, I am TCP server"
|
||||
#define CLI_MSG "Hi, I am TCP client"
|
||||
#define TEST_CASE 130
|
||||
|
||||
static char g_buf[BUF_SIZE + 1] = { 0 };
|
||||
extern sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio);
|
||||
|
||||
static int SampleTcpServer()
|
||||
{
|
||||
g_testCase++;
|
||||
int sfd, lsfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
struct msghdr msg = { 0 };
|
||||
struct iovec iov[IOV_LENGTH] = { 0 };
|
||||
int ret;
|
||||
|
||||
/* tcp server */
|
||||
lsfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create server socket inet stream: %d", lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT);
|
||||
ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
|
||||
ret = listen(lsfd, 0);
|
||||
LogPrintln("listen socket %d: %d", lsfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 3);
|
||||
|
||||
sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
|
||||
LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
|
||||
|
||||
/* send */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG);
|
||||
ret = send(sfd, g_buf, strlen(SRV_MSG), 0);
|
||||
LogPrintln("server send on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 5);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
ret = recv(sfd, g_buf, sizeof(g_buf), 0);
|
||||
LogPrintln("server recv on socket %d: %d", sfd, ret);
|
||||
LogPrintln("ser:%s", g_buf);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 6);
|
||||
|
||||
/* sendmsg */
|
||||
clnAddr.sin_family = AF_INET;
|
||||
clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
clnAddr.sin_port = htons(PEER_PORT);
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG);
|
||||
msg.msg_name = &clnAddr;
|
||||
msg.msg_namelen = sizeof(clnAddr);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = IOV_LENGTH;
|
||||
iov[0].iov_base = g_buf;
|
||||
iov[0].iov_len = strlen(SRV_MSG);
|
||||
iov[1].iov_base = g_buf;
|
||||
iov[1].iov_len = strlen(SRV_MSG);
|
||||
ret = sendmsg(sfd, &msg, 0);
|
||||
LogPrintln("sendmsg on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(SRV_MSG), 7);
|
||||
|
||||
/* recvmsg */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
|
||||
msg.msg_name = &clnAddr;
|
||||
msg.msg_namelen = sizeof(clnAddr);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
iov[0].iov_base = g_buf;
|
||||
iov[0].iov_len = sizeof(g_buf);
|
||||
ret = recvmsg(sfd, &msg, 0);
|
||||
LogPrintln("recvmsg on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(CLI_MSG), 8);
|
||||
|
||||
ret = shutdown(sfd, SHUT_RDWR);
|
||||
LogPrintln("shutdown socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 9);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10);
|
||||
ret = closesocket(lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 11);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SampleTcpClient()
|
||||
{
|
||||
g_testCase++;
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
int ret;
|
||||
struct msghdr msg = { 0 };
|
||||
struct iovec iov[IOV_LENGTH] = { 0 };
|
||||
struct sockaddr addr;
|
||||
socklen_t addrLen = sizeof(addr);
|
||||
|
||||
/* tcp client connection */
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create client socket inet stream: %d", sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
srvAddr.sin_port = htons(PEER_PORT);
|
||||
ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 11);
|
||||
|
||||
/* test getpeername */
|
||||
ret = getpeername(sfd, &addr, &addrLen);
|
||||
LogPrintln("getpeername %d %s:%d: %d", \
|
||||
sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 12);
|
||||
ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 13);
|
||||
ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
|
||||
inet_addr(PEER_IP), 14);
|
||||
|
||||
/* test getsockname */
|
||||
ret = getsockname(sfd, &addr, &addrLen);
|
||||
LogPrintln("getsockname %d %s:%d: %d", \
|
||||
sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 15);
|
||||
ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 16);
|
||||
ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
|
||||
inet_addr(STACK_IP), 17);
|
||||
|
||||
/* send */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG);
|
||||
ret = send(sfd, g_buf, strlen(CLI_MSG), 0);
|
||||
LogPrintln("client send on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 18);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
ret = recv(sfd, g_buf, sizeof(g_buf), 0);
|
||||
LogPrintln("client recv on socket %d: %d", sfd, ret);
|
||||
LogPrintln("cli:%s", g_buf);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 19);
|
||||
|
||||
/* sendmsg */
|
||||
clnAddr.sin_family = AF_INET;
|
||||
clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
clnAddr.sin_port = htons(PEER_PORT);
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG);
|
||||
msg.msg_name = &clnAddr;
|
||||
msg.msg_namelen = sizeof(clnAddr);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = IOV_LENGTH;
|
||||
iov[0].iov_base = g_buf;
|
||||
iov[0].iov_len = strlen(CLI_MSG);
|
||||
iov[1].iov_base = g_buf;
|
||||
iov[1].iov_len = strlen(CLI_MSG);
|
||||
ret = sendmsg(sfd, &msg, 0);
|
||||
LogPrintln("sendmsg on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 2 * strlen(CLI_MSG), 20);
|
||||
|
||||
/* recvmsg */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
|
||||
msg.msg_name = &clnAddr;
|
||||
msg.msg_namelen = sizeof(clnAddr);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
iov[0].iov_base = g_buf;
|
||||
iov[0].iov_len = sizeof(g_buf);
|
||||
ret = recvmsg(sfd, &msg, 0);
|
||||
LogPrintln("recvmsg on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(SRV_MSG), 21);
|
||||
|
||||
ret = shutdown(sfd, SHUT_RDWR);
|
||||
LogPrintln("shutdown socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 22);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TcpServerRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpServer();
|
||||
}
|
||||
|
||||
static void TcpClientRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpClient();
|
||||
}
|
||||
|
||||
void TcpTest()
|
||||
{
|
||||
LogPrintln("net_socket_test_003.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int ret;
|
||||
ret = sys_thread_new("tcp_server", TcpServerRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
|
||||
ret = sys_thread_new("tcp_client", TcpClientRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
|
||||
}
|
||||
87
components/net/test/net_socket_test_004.c
Normal file
87
components/net/test/net_socket_test_004.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
|
||||
#define TEST_CASE 140
|
||||
#define OPT_TIMEOUT 1000
|
||||
|
||||
int SockOptTest()
|
||||
{
|
||||
LogPrintln("net_socket_test_004.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int ret, error, flag;
|
||||
struct timeval timeout;
|
||||
socklen_t len;
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(fd, -1, 1);
|
||||
|
||||
error = -1;
|
||||
len = sizeof(error);
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
|
||||
LogPrintln("getsockopt(%d, SOL_SOCKET, SO_ERROR, &error, &len)=%d, error=%d, len=%d, errno=%d", \
|
||||
fd, ret, error, len, errno);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
ICUNIT_ASSERT_EQUAL(error, 0, 3);
|
||||
|
||||
len = sizeof(timeout);
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 4);
|
||||
|
||||
timeout.tv_sec = OPT_TIMEOUT;
|
||||
len = sizeof(timeout);
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 5);
|
||||
|
||||
(void)memset_s(&timeout, len, 0, len);
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 6);
|
||||
ICUNIT_ASSERT_EQUAL(timeout.tv_sec, OPT_TIMEOUT, 7);
|
||||
|
||||
error = -1;
|
||||
len = sizeof(error);
|
||||
ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
|
||||
LogPrintln("getsockopt(%d, SOL_SOCKET, SO_ERROR, &error, &len)=%d, error=%d, len=%d, errno=%d", \
|
||||
fd, ret, error, len, errno);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 8);
|
||||
ICUNIT_ASSERT_EQUAL(error, 0, 9);
|
||||
|
||||
flag = 1;
|
||||
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
|
||||
LogPrintln("setsockopt(TCP_NODELAY) ret=%d", ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 10);
|
||||
|
||||
ret = closesocket(fd);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 11);
|
||||
|
||||
return LWIP_TEST_RET_OK;
|
||||
}
|
||||
67
components/net/test/net_socket_test_005.c
Normal file
67
components/net/test/net_socket_test_005.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
|
||||
#define TEST_CASE 150
|
||||
|
||||
int ByteOrderTest(void)
|
||||
{
|
||||
LogPrintln("net_socket_test_005.c enter");
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
g_testCase = TEST_CASE + 1;
|
||||
uint32_t hl = ntohl(0x12345678);
|
||||
ICUNIT_ASSERT_EQUAL(hl, 0x78563412, 1);
|
||||
|
||||
uint32_t nl = htonl(0x12345678);
|
||||
ICUNIT_ASSERT_EQUAL(nl, 0x78563412, 2);
|
||||
|
||||
uint16_t hs = ntohs(0x1234);
|
||||
ICUNIT_ASSERT_EQUAL(hs, 0x3412, 3);
|
||||
|
||||
uint16_t ns = htons(0x1234);
|
||||
ICUNIT_ASSERT_EQUAL(ns, 0x3412, 4);
|
||||
#else
|
||||
g_testCase = TEST_CASE;
|
||||
uint32_t hl = ntohl(0x12345678);
|
||||
ICUNIT_ASSERT_EQUAL(hl, 0x12345678, 5);
|
||||
|
||||
uint32_t nl = htonl(0x12345678);
|
||||
ICUNIT_ASSERT_EQUAL(nl, 0x12345678, 6);
|
||||
|
||||
uint16_t hs = ntohs(0x1234);
|
||||
ICUNIT_ASSERT_EQUAL(hs, 0x1234, 7);
|
||||
|
||||
uint16_t ns = htons(0x1234);
|
||||
ICUNIT_ASSERT_EQUAL(ns, 0x1234, 8);
|
||||
#endif
|
||||
return LWIP_TEST_RET_OK;
|
||||
}
|
||||
62
components/net/test/net_socket_test_006.c
Normal file
62
components/net/test/net_socket_test_006.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
|
||||
#define TEST_CASE 160
|
||||
#define TEMP_BUF_SIZE 32
|
||||
int InetTest()
|
||||
{
|
||||
LogPrintln("net_socket_test_006.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
struct in_addr in;
|
||||
int ret = inet_pton(AF_INET, "300.10.10.10", &in);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 1);
|
||||
|
||||
ret = inet_pton(AF_INET, "10.11.12.13", &in);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 1, 2);
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
g_testCase++;
|
||||
ICUNIT_ASSERT_EQUAL(in.s_addr, 0x0d0c0b0a, 3);
|
||||
#else
|
||||
ICUNIT_ASSERT_EQUAL(in.s_addr, 0x0a0b0c0d, 4);
|
||||
#endif
|
||||
|
||||
const char *p = inet_ntoa(in);
|
||||
ICUNIT_ASSERT_EQUAL(strcmp(p, "10.11.12.13"), 0, 5);
|
||||
|
||||
char buf[TEMP_BUF_SIZE];
|
||||
p = inet_ntop(AF_INET, &in, buf, sizeof(buf));
|
||||
ICUNIT_ASSERT_EQUAL(p, buf, 6);
|
||||
ICUNIT_ASSERT_EQUAL(strcmp(p, "10.11.12.13"), 0, 7);
|
||||
|
||||
return LWIP_TEST_RET_OK;
|
||||
}
|
||||
109
components/net/test/net_socket_test_007.c
Normal file
109
components/net/test/net_socket_test_007.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include "lwipopts.h"
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
|
||||
static char g_buf[BUF_SIZE + 1] = { 0 };
|
||||
static char g_buf_temp[BUF_SIZE + 1] = { 0 };
|
||||
|
||||
#define SEND_UDP_COUNT 10000 // send count
|
||||
#define TEST_CASE 170
|
||||
|
||||
extern sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio);
|
||||
static void UdpTestMoreTask(void *p)
|
||||
{
|
||||
(void)p;
|
||||
LogPrintln("net_socket_test_007.c enter");
|
||||
if (g_testCase < TEST_CASE) {
|
||||
g_testCase = TEST_CASE;
|
||||
} else {
|
||||
g_testCase++;
|
||||
}
|
||||
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* socket creation */
|
||||
sfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
LWIP_ASSERT("socket invalid param.", sfd != -1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT);
|
||||
ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LWIP_ASSERT("socket invalid param.", ret == 0);
|
||||
|
||||
/* send */
|
||||
clnAddr.sin_family = AF_INET;
|
||||
clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
clnAddr.sin_port = htons(PEER_PORT);
|
||||
if (g_buf_temp[0] == '\0') {
|
||||
for (i = 0; i < BUF_SIZE; i++) {
|
||||
g_buf_temp[i] = 'U';
|
||||
}
|
||||
g_buf_temp[BUF_SIZE] = '\0';
|
||||
}
|
||||
|
||||
LogPrintln("udp begin send");
|
||||
for (i = 0; i < SEND_UDP_COUNT; i++) {
|
||||
ret = memcpy_s(g_buf, sizeof(g_buf), g_buf_temp, sizeof(g_buf_temp));
|
||||
ICUNIT_ASSERT_EQUAL(ret, EOK, 1);
|
||||
ret = sendto(sfd, g_buf, BUF_SIZE, 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr));
|
||||
LWIP_ASSERT("socket invalid param.", ret != -1);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr,
|
||||
&clnAddrLen);
|
||||
LWIP_ASSERT("socket invalid param.", ret == BUF_SIZE);
|
||||
}
|
||||
LogPrintln("udp end send");
|
||||
|
||||
/* close socket */
|
||||
ret = closesocket(sfd);
|
||||
LWIP_ASSERT("socket invalid param.", ret != -1);
|
||||
}
|
||||
|
||||
void UdpTestMore()
|
||||
{
|
||||
int ret;
|
||||
ret = sys_thread_new("udp_more", UdpTestMoreTask, NULL,
|
||||
STACK_TEST_SIZE * 2, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10);
|
||||
}
|
||||
|
||||
187
components/net/test/net_socket_test_008.c
Normal file
187
components/net/test/net_socket_test_008.c
Normal file
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include "lwipopts.h"
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
|
||||
#define SEND_TCP_COUNT 1000 // send count
|
||||
#define STACK_PORT_8 2288
|
||||
#define TEST_CASE 180
|
||||
|
||||
static char g_serverSendBuf[BUF_SIZE + 1] = { 0 };
|
||||
static char g_clientRecvBuf[BUF_SIZE + 1] = { 0 };
|
||||
|
||||
extern sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio);
|
||||
|
||||
static void InitMsgBuf()
|
||||
{
|
||||
int i;
|
||||
if (g_serverSendBuf[0] != '\0') {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < BUF_SIZE; i++) {
|
||||
g_serverSendBuf[i] = 'S';
|
||||
}
|
||||
g_serverSendBuf[BUF_SIZE] = '\0';
|
||||
}
|
||||
|
||||
static int SampleTcpServer()
|
||||
{
|
||||
g_testCase++;
|
||||
int sfd, lsfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* tcp server */
|
||||
lsfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create server socket inet stream: %d", lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_8);
|
||||
ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
|
||||
ret = listen(lsfd, 0);
|
||||
LogPrintln("listen socket %d: %d", lsfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 3);
|
||||
|
||||
sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
|
||||
LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
|
||||
|
||||
for (i = 0; i < SEND_TCP_COUNT; i++) {
|
||||
/* send */
|
||||
ret = send(sfd, g_serverSendBuf, BUF_SIZE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, BUF_SIZE, 5);
|
||||
}
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 7);
|
||||
ret = closesocket(lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SampleTcpClient()
|
||||
{
|
||||
g_testCase++;
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
int ret;
|
||||
int i;
|
||||
struct sockaddr addr;
|
||||
socklen_t addrLen = sizeof(addr);
|
||||
int recvCount = 0;
|
||||
|
||||
/* tcp client connection */
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create client socket inet stream: %d", sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 7);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_8);
|
||||
ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 8);
|
||||
|
||||
/* test getpeername */
|
||||
ret = getpeername(sfd, &addr, &addrLen);
|
||||
LogPrintln("getpeername %d %s:%d: %d",
|
||||
sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 9);
|
||||
ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 10);
|
||||
ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
|
||||
inet_addr(PEER_IP), 11);
|
||||
|
||||
/* test getsockname */
|
||||
ret = getsockname(sfd, &addr, &addrLen);
|
||||
LogPrintln("getsockname %d %s:%d: %d",
|
||||
sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 12);
|
||||
ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 13);
|
||||
ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
|
||||
inet_addr(STACK_IP), 14);
|
||||
|
||||
LogPrintln("tcp begin recv");
|
||||
for (i = 0; i < 2 * SEND_TCP_COUNT; i++) {
|
||||
/* recv */
|
||||
(void)memset_s(g_clientRecvBuf, sizeof(g_clientRecvBuf), 0, sizeof(g_clientRecvBuf));
|
||||
ret = recv(sfd, g_clientRecvBuf, BUF_SIZE, 0);
|
||||
recvCount += ret;
|
||||
if (recvCount >= BUF_SIZE * SEND_TCP_COUNT) {
|
||||
LogPrintln("client recv on socket %d: %d, i = %d", sfd, recvCount, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(recvCount, BUF_SIZE * SEND_TCP_COUNT, recvCount);
|
||||
LogPrintln("tcp end recv");
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 17);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TcpServerRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpServer();
|
||||
}
|
||||
|
||||
static void TcpClientRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpClient();
|
||||
}
|
||||
|
||||
void TcpTestMore()
|
||||
{
|
||||
LogPrintln("net_socket_test_008.c enter");
|
||||
if (g_testCase < TEST_CASE) {
|
||||
g_testCase = TEST_CASE;
|
||||
}
|
||||
|
||||
int ret;
|
||||
InitMsgBuf();
|
||||
ret = sys_thread_new("tcp_server_more", TcpServerRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 17);
|
||||
|
||||
ret = sys_thread_new("tcp_client_more", TcpClientRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 18);
|
||||
}
|
||||
167
components/net/test/net_socket_test_009.c
Normal file
167
components/net/test/net_socket_test_009.c
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include "lwipopts.h"
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
|
||||
#define SRV_MSG "Hi, I am TCP server"
|
||||
#define CLI_MSG "Hi, I am TCP client"
|
||||
|
||||
#define TEST_CASE 190
|
||||
#define STACK_PORT_9 2299
|
||||
#define TIME_OUT 10 // timeout 10s
|
||||
|
||||
static char g_buf[BUF_SIZE + 1] = { 0 };
|
||||
|
||||
extern sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio);
|
||||
|
||||
static int SampleTcpServer()
|
||||
{
|
||||
#if LWIP_SOCKET_SELECT
|
||||
g_testCase++;
|
||||
int sfd, lsfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
fd_set fdsr;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
|
||||
/* tcp server */
|
||||
lsfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create server socket inet stream: %d", lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_9);
|
||||
ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
|
||||
ret = listen(lsfd, 0);
|
||||
LogPrintln("listen socket %d: %d", lsfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 3);
|
||||
|
||||
FD_ZERO(&fdsr);
|
||||
FD_SET(lsfd, &fdsr);
|
||||
// timeout setting
|
||||
tv.tv_sec = TIME_OUT;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
ret = select(lsfd + 1, &fdsr, NULL, NULL, &tv);
|
||||
if (ret < 0) {
|
||||
LogPrintln("select error");
|
||||
ICUNIT_ASSERT_EQUAL(-1, 0, 4);
|
||||
} else if (ret == 0) {
|
||||
LogPrintln("select timeout");
|
||||
ICUNIT_ASSERT_EQUAL(-1, 0, 5);
|
||||
}
|
||||
|
||||
sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
|
||||
LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 6);
|
||||
|
||||
/* send */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG);
|
||||
ret = send(sfd, g_buf, strlen(SRV_MSG), 0);
|
||||
LogPrintln("server send on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 7);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
|
||||
ret = closesocket(lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 9);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SampleTcpClient()
|
||||
{
|
||||
#if LWIP_SOCKET_SELECT
|
||||
g_testCase++;
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
int ret;
|
||||
|
||||
/* tcp client connection */
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create client socket inet stream: %d", sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_9);
|
||||
ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 11);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
ret = recv(sfd, g_buf, sizeof(g_buf), 0);
|
||||
LogPrintln("client recv on socket %d: %d", sfd, ret);
|
||||
LogPrintln("cli:%s", g_buf);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 12);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TcpServerRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpServer();
|
||||
}
|
||||
|
||||
static void TcpClientRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpClient();
|
||||
}
|
||||
|
||||
void TcpTestSelect()
|
||||
{
|
||||
LogPrintln("net_socket_test_009.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int ret;
|
||||
ret = sys_thread_new("tcp_server_select", TcpServerRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
|
||||
ret = sys_thread_new("tcp_client_select", TcpClientRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
|
||||
}
|
||||
162
components/net/test/net_socket_test_010.c
Normal file
162
components/net/test/net_socket_test_010.c
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include "lwipopts.h"
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
|
||||
#define SRV_MSG "Hi, I am TCP server"
|
||||
#define CLI_MSG "Hi, I am TCP client"
|
||||
|
||||
#define TEST_CASE 200
|
||||
#define STACK_PORT_10 2230
|
||||
#define POLL_OPEN_MAX 10
|
||||
#define TIME_OUT (1000 * 10) // timeout 10s
|
||||
static char g_buf[BUF_SIZE + 1] = { 0 };
|
||||
|
||||
extern sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio);
|
||||
|
||||
static int SampleTcpServer()
|
||||
{
|
||||
#if LWIP_SOCKET_POLL
|
||||
g_testCase++;
|
||||
int sfd, lsfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
struct pollfd client[POLL_OPEN_MAX] = {0};
|
||||
int ret;
|
||||
|
||||
/* tcp server */
|
||||
lsfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create server socket inet stream: %d", lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_10);
|
||||
ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
|
||||
ret = listen(lsfd, 0);
|
||||
LogPrintln("listen socket %d: %d", lsfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 3);
|
||||
|
||||
client[0].fd = lsfd;
|
||||
client[0].events = POLLIN;
|
||||
ret = poll(client, 1, TIME_OUT);
|
||||
if (ret < 0) {
|
||||
LogPrintln("poll error");
|
||||
ICUNIT_ASSERT_EQUAL(-1, 0, 4);
|
||||
} else if (ret == 0) {
|
||||
LogPrintln("poll timeout");
|
||||
ICUNIT_ASSERT_EQUAL(-1, 0, 5);
|
||||
}
|
||||
|
||||
sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
|
||||
LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 6);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
ret = recv(sfd, g_buf, sizeof(g_buf), 0);
|
||||
LogPrintln("server recv on socket %d: %d", sfd, ret);
|
||||
LogPrintln("ser:%s", g_buf);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 7);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
|
||||
ret = closesocket(lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 9);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SampleTcpClient()
|
||||
{
|
||||
#if LWIP_SOCKET_POLL
|
||||
g_testCase++;
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
int ret;
|
||||
|
||||
/* tcp client connection */
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
LogPrintln("create client socket inet stream: %d", sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_10);
|
||||
ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 11);
|
||||
|
||||
/* send */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG);
|
||||
ret = send(sfd, g_buf, strlen(CLI_MSG), 0);
|
||||
LogPrintln("client send on socket %d: %d", sfd, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 12);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TcpServerRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpServer();
|
||||
}
|
||||
|
||||
static void TcpClientRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
(void)SampleTcpClient();
|
||||
}
|
||||
|
||||
void TcpTestPoll()
|
||||
{
|
||||
LogPrintln("net_socket_test_010.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int ret;
|
||||
ret = sys_thread_new("tcp_server_poll", TcpServerRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
|
||||
ret = sys_thread_new("tcp_client_poll", TcpClientRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
|
||||
}
|
||||
440
components/net/test/net_socket_test_011.c
Normal file
440
components/net/test/net_socket_test_011.c
Normal file
@@ -0,0 +1,440 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include <lwip/netif.h>
|
||||
#include <lwip/netifapi.h>
|
||||
#include <lwip/pbuf.h>
|
||||
#include <lwip/ip4_addr.h>
|
||||
#include <lwip/ip4.h>
|
||||
#include <lwip/ip.h>
|
||||
#include <lwip/def.h>
|
||||
#include <lwip/udp.h>
|
||||
#include <lwip/inet_chksum.h>
|
||||
#include "lwip/prot/iana.h"
|
||||
|
||||
#define MSG "Hi, I am testing BT netif."
|
||||
#define STACK_IP_BT "192.168.167.1"
|
||||
#define PEER_IP_BT "100.100.100.100"
|
||||
#define GATEWAY_IP_BT "192.168.167.239"
|
||||
#define NETIF_MAC "121212"
|
||||
#define PEER_MAC "454545"
|
||||
#define NETIF_NAME_BT "bt1000"
|
||||
#define TEST_CASE 210
|
||||
static char g_buf[BUF_SIZE + 1] = { 0 };
|
||||
struct netif *btProxyNf = NULL;
|
||||
|
||||
static void ReplayArpTask();
|
||||
static void ArpPackageProc(struct netif *netif, struct pbuf *p);
|
||||
extern void driverif_input(struct netif *netif, struct pbuf *p);
|
||||
static void ReplayArpEncodeEthernet(struct netif *netif, struct pbuf *p);
|
||||
|
||||
static void ReplayUdpEncodeEthernet(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
ret = pbuf_add_header(p, SIZEOF_ETH_HDR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 1);
|
||||
|
||||
struct eth_hdr *ethhdr;
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
ethhdr->type = lwip_htons(ETHTYPE_IP);
|
||||
SMEMCPY(ðhdr->dest, NETIF_MAC, ETH_HWADDR_LEN);
|
||||
SMEMCPY(ðhdr->src, PEER_MAC, ETH_HWADDR_LEN);
|
||||
|
||||
driverif_input(netif, p);
|
||||
}
|
||||
|
||||
static void ReplayUdpEncodeIp(struct pbuf *p, ip4_addr_t *src, ip4_addr_t *dest)
|
||||
{
|
||||
struct ip_hdr *iphdr;
|
||||
int ret;
|
||||
#if CHECKSUM_GEN_IP_INLINE
|
||||
u32_t chk_sum = 0;
|
||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||
|
||||
// ip header
|
||||
ret = pbuf_add_header(p, IP_HLEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
iphdr = (struct ip_hdr *)p->payload;
|
||||
IPH_TTL_SET(iphdr, UDP_TTL);
|
||||
IPH_PROTO_SET(iphdr, IP_PROTO_UDP);
|
||||
|
||||
#if CHECKSUM_GEN_IP_INLINE
|
||||
chk_sum += PP_NTOHS(IP_PROTO_UDP | (ttl << 8));
|
||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||
|
||||
/* dest cannot be NULL here */
|
||||
ip4_addr_copy(iphdr->dest, *dest);
|
||||
#if CHECKSUM_GEN_IP_INLINE
|
||||
chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
|
||||
chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
|
||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||
|
||||
u16_t ip_hlen = IP_HLEN;
|
||||
IPH_VHL_SET(iphdr, 4, ip_hlen / 4);
|
||||
IPH_TOS_SET(iphdr, 0);
|
||||
#if CHECKSUM_GEN_IP_INLINE
|
||||
chk_sum += PP_NTOHS(tos | (iphdr->_v_hl << 8));
|
||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||
IPH_LEN_SET(iphdr, lwip_htons(p->tot_len));
|
||||
#if CHECKSUM_GEN_IP_INLINE
|
||||
chk_sum += iphdr->_len;
|
||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||
IPH_OFFSET_SET(iphdr, 0);
|
||||
IPH_ID_SET(iphdr, lwip_htons(0));
|
||||
#if CHECKSUM_GEN_IP_INLINE
|
||||
chk_sum += iphdr->_id;
|
||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||
ip4_addr_copy(iphdr->src, *src);
|
||||
|
||||
#if CHECKSUM_GEN_IP_INLINE
|
||||
chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF;
|
||||
chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16;
|
||||
chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
|
||||
chk_sum = (chk_sum >> 16) + chk_sum;
|
||||
chk_sum = ~chk_sum;
|
||||
IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
|
||||
iphdr->_chksum = (u16_t)chk_sum; /* network order */
|
||||
}
|
||||
#if LWIP_CHECKSUM_CTRL_PER_NETIF
|
||||
else {
|
||||
IPH_CHKSUM_SET(iphdr, 0);
|
||||
}
|
||||
#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
|
||||
#else /* CHECKSUM_GEN_IP_INLINE */
|
||||
IPH_CHKSUM_SET(iphdr, 0);
|
||||
#if CHECKSUM_GEN_IP
|
||||
IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
|
||||
IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen));
|
||||
}
|
||||
#endif /* CHECKSUM_GEN_IP */
|
||||
#endif /* CHECKSUM_GEN_IP_INLINE */
|
||||
|
||||
ReplayUdpEncodeEthernet(btProxyNf, p);
|
||||
}
|
||||
|
||||
static void ReplayUdp(void *ptemp)
|
||||
{
|
||||
struct udp_hdr *udphdr;
|
||||
ip4_addr_t sipaddr, dipaddr;
|
||||
int size = strlen(MSG);
|
||||
int ret;
|
||||
(void)ptemp;
|
||||
|
||||
LogPrintln("encode udp replay packet");
|
||||
inet_pton(AF_INET, PEER_IP_BT, &sipaddr);
|
||||
inet_pton(AF_INET, STACK_IP_BT, &dipaddr);
|
||||
|
||||
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
|
||||
u16_t chksum = LWIP_CHKSUM_COPY(p->payload, MSG, size);
|
||||
|
||||
// udp header
|
||||
ret = pbuf_add_header(p, UDP_HLEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 1);
|
||||
udphdr = (struct udp_hdr *)p->payload;
|
||||
udphdr->src = lwip_htons(STACK_PORT);
|
||||
udphdr->dest = lwip_htons(STACK_PORT);
|
||||
udphdr->len = lwip_htons(p->tot_len);
|
||||
/* in UDP, 0 checksum means 'no checksum' */
|
||||
u16_t udpchksum = ip_chksum_pseudo_partial(p, IP_PROTO_UDP, p->tot_len, UDP_HLEN, &sipaddr, &dipaddr);
|
||||
u32_t acc = udpchksum + (u16_t)~(chksum);
|
||||
udpchksum = FOLD_U32T(acc);
|
||||
if (udpchksum == 0x0000) {
|
||||
udpchksum = 0xffff;
|
||||
}
|
||||
udphdr->chksum = udpchksum;
|
||||
udphdr->chksum = 0;
|
||||
|
||||
ReplayUdpEncodeIp(p, &sipaddr, &dipaddr);
|
||||
}
|
||||
|
||||
static void ReplayUdpTask()
|
||||
{
|
||||
int ret;
|
||||
ret = sys_thread_new("replay_udp", ReplayUdp, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 3);
|
||||
}
|
||||
|
||||
static void ParsePackageIpUdp(struct netif *netif, struct pbuf *btBuf)
|
||||
{
|
||||
// get scr_addr and dest_addr from ip head
|
||||
const struct ip_hdr *iphdr;
|
||||
iphdr = (const struct ip_hdr *)btBuf->payload;
|
||||
ip4_addr_p_t ip4_addr_scr = iphdr->src;
|
||||
ip4_addr_p_t ip4_addr_dest = iphdr->dest;
|
||||
char buf[32];
|
||||
int dataLen;
|
||||
|
||||
// get scr_port and dest port from tcp head
|
||||
u16_t scr_port, dest_port;
|
||||
void *data;
|
||||
struct udp_hdr *udphdr;
|
||||
udphdr = (struct udp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr));
|
||||
scr_port = udphdr->src;
|
||||
dest_port = udphdr->dest;
|
||||
data = (void *)((u8_t *)udphdr + UDP_HLEN);
|
||||
|
||||
LogPrintln("======Bt netif send package======");
|
||||
LogPrintln("netif full name %s", netif->full_name);
|
||||
(void)inet_ntop(AF_INET, &ip4_addr_scr.addr, buf, sizeof(buf));
|
||||
LogPrintln("package src ip %s", buf);
|
||||
(void)inet_ntop(AF_INET, &ip4_addr_dest.addr, buf, sizeof(buf));
|
||||
LogPrintln("package dest ip %s", buf);
|
||||
LogPrintln("package src port %d", lwip_ntohs(scr_port));
|
||||
LogPrintln("package dest port %d", lwip_ntohs(dest_port));
|
||||
LogPrintln("send data %s", (char *)data);
|
||||
dataLen = lwip_ntohs(udphdr->len) - UDP_HLEN;
|
||||
LogPrintln("send data length %d", dataLen);
|
||||
ICUNIT_ASSERT_EQUAL(dataLen, strlen(MSG), 4);
|
||||
LogPrintln("=================================");
|
||||
|
||||
// 回应udp报文
|
||||
ReplayUdpTask();
|
||||
}
|
||||
|
||||
static void ParsePackageEthernet(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
u16_t next_hdr_offset = SIZEOF_ETH_HDR;
|
||||
// get src mac and dest mac
|
||||
struct eth_hdr *ethhdr;
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
u16_t type = ethhdr->type;
|
||||
|
||||
LogPrintln("ParsePackageEthernet type is %d", type);
|
||||
switch (type) {
|
||||
#if LWIP_IPV4 && LWIP_ARP
|
||||
/* IP packet? */
|
||||
case PP_HTONS(ETHTYPE_IP): // 0x0008
|
||||
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
|
||||
return;
|
||||
}
|
||||
/* skip Ethernet header (min. size checked above) */
|
||||
if (pbuf_remove_header(p, next_hdr_offset)) {
|
||||
return;
|
||||
} else {
|
||||
/* pass to IP layer */
|
||||
ParsePackageIpUdp(netif, p);
|
||||
}
|
||||
break;
|
||||
|
||||
case PP_HTONS(ETHTYPE_ARP): // 0x0608
|
||||
if (!(netif->flags & NETIF_FLAG_ETHARP)) {
|
||||
return;
|
||||
}
|
||||
/* skip Ethernet header (min. size checked above) */
|
||||
if (pbuf_remove_header(p, next_hdr_offset)) {
|
||||
return;
|
||||
} else {
|
||||
/* pass p to ARP module */
|
||||
LogPrintln("recv arp packet");
|
||||
ArpPackageProc(netif, p);
|
||||
}
|
||||
break;
|
||||
#endif /* LWIP_IPV4 && LWIP_ARP */
|
||||
|
||||
default:
|
||||
LogPrintln("type is other %d", type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void BtProxySend(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
if (netif == NULL || p == NULL) {
|
||||
LogPrintln("%s : netif = NUll or p = NULL!", __func__);
|
||||
return;
|
||||
}
|
||||
#if ETH_PAD_SIZE
|
||||
(void)pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
|
||||
#endif
|
||||
ParsePackageEthernet(netif, p);
|
||||
}
|
||||
|
||||
static struct netif *CreateBtNetIf()
|
||||
{
|
||||
struct netif *btNetif = NULL;
|
||||
btNetif = (struct netif *)malloc(sizeof(struct netif));
|
||||
if (btNetif == NULL) {
|
||||
LogPrintln("%s fail : netif malloc fail!", __func__);
|
||||
LWIP_ASSERT("btNetif malloc fail.", 0);
|
||||
return NULL;
|
||||
}
|
||||
(void)memset_s(btNetif, sizeof(struct netif), 0, sizeof(struct netif));
|
||||
btNetif->drv_send = BtProxySend;
|
||||
btNetif->link_layer_type = BT_PROXY_IF;
|
||||
btNetif->hwaddr_len = ETH_HWADDR_LEN;
|
||||
(void)memcpy_s(&btNetif->hwaddr, sizeof(btNetif->hwaddr), NETIF_MAC, ETH_HWADDR_LEN);
|
||||
(void)memcpy_s(&btNetif->full_name, sizeof(btNetif->full_name), NETIF_NAME_BT, sizeof(NETIF_NAME_BT));
|
||||
ip4_addr_t gw, ipaddr, netmask;
|
||||
IP4_ADDR(&gw, 192, 168, 167, 239);
|
||||
IP4_ADDR(&ipaddr, 192, 168, 167, 1);
|
||||
IP4_ADDR(&netmask, 255, 255, 255, 255);
|
||||
int ret = 0;
|
||||
if ((ret = netifapi_netif_add(btNetif, &ipaddr, &netmask, &gw, btNetif, driverif_init, tcpip_input)) != ERR_OK) {
|
||||
LogPrintln("%s : netifapi_netif_add fail!,ret=%d", __func__, ret);
|
||||
LWIP_ASSERT("btNetif add fail.", 0);
|
||||
return NULL;
|
||||
}
|
||||
LogPrintln("netifapi_netif_add success!");
|
||||
netif_set_link_up(btNetif);
|
||||
netifapi_netif_set_up(btNetif);
|
||||
return btNetif;
|
||||
}
|
||||
|
||||
int UdpTestNetif(void)
|
||||
{
|
||||
LogPrintln("net_socket_test_011.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
struct ifreq nif;
|
||||
int ret;
|
||||
|
||||
// 注册网卡
|
||||
btProxyNf = CreateBtNetIf();
|
||||
|
||||
/* socket creation */
|
||||
sfd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
LWIP_ASSERT("socket invalid param.", sfd != -1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP_BT);
|
||||
srvAddr.sin_port = htons(STACK_PORT);
|
||||
ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
LWIP_ASSERT("socket invalid param.", ret == 0);
|
||||
|
||||
/* 指定网卡接口 */
|
||||
char *inface = NETIF_NAME_BT;
|
||||
(void)strcpy_s(nif.ifr_name, sizeof(nif.ifr_name), inface);
|
||||
if (setsockopt(sfd, SOL_SOCKET, SO_BINDTODEVICE, (char *)&nif, sizeof(nif)) < 0) {
|
||||
LogPrintln("set intaface fail");
|
||||
LWIP_ASSERT("set intaface fail.", 0);
|
||||
}
|
||||
|
||||
/* send */
|
||||
clnAddr.sin_family = AF_INET;
|
||||
clnAddr.sin_addr.s_addr = inet_addr(PEER_IP_BT);
|
||||
clnAddr.sin_port = htons(PEER_PORT);
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
(void)strcpy_s(g_buf, sizeof(g_buf), MSG);
|
||||
ret = sendto(sfd, g_buf, strlen(MSG), 0, (struct sockaddr*)&clnAddr,
|
||||
(socklen_t)sizeof(clnAddr));
|
||||
LogPrintln("client send success: %d", sfd);
|
||||
LWIP_ASSERT("socket invalid param.", ret != -1);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
|
||||
ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr,
|
||||
&clnAddrLen);
|
||||
LWIP_ASSERT("socket invalid param.", ret == strlen(MSG));
|
||||
LogPrintln("cli recv: %s", g_buf);
|
||||
|
||||
/* close socket */
|
||||
ret = closesocket(sfd);
|
||||
LWIP_ASSERT("socket invalid param.", ret != -1);
|
||||
return LWIP_TEST_RET_OK;
|
||||
}
|
||||
|
||||
static void ArpPackageProc(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
struct etharp_hdr *hdr;
|
||||
ip4_addr_t sipaddr, dipaddr;
|
||||
hdr = (struct etharp_hdr *)p->payload;
|
||||
|
||||
if (hdr->opcode != PP_HTONS(ARP_REQUEST)) {
|
||||
LogPrintln("opcode %d is not arp request", hdr->opcode);
|
||||
return;
|
||||
}
|
||||
|
||||
inet_pton(AF_INET, GATEWAY_IP_BT, &sipaddr);
|
||||
inet_pton(AF_INET, STACK_IP_BT, &dipaddr);
|
||||
if (memcmp(&hdr->dipaddr, &sipaddr, sizeof(ip4_addr_t)) != EOK) {
|
||||
LogPrintln("hdr->dipaddr %u is invalid", hdr->dipaddr);
|
||||
return;
|
||||
}
|
||||
|
||||
// 回应arp报文
|
||||
ReplayArpTask();
|
||||
}
|
||||
|
||||
static void ReplayArpEncodeEthernet(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
int ret;
|
||||
ret = pbuf_add_header(p, SIZEOF_ETH_HDR);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 1);
|
||||
|
||||
struct eth_hdr *ethhdr;
|
||||
ethhdr = (struct eth_hdr *)p->payload;
|
||||
ethhdr->type = lwip_htons(ETHTYPE_ARP);
|
||||
SMEMCPY(ðhdr->dest, NETIF_MAC, ETH_HWADDR_LEN);
|
||||
SMEMCPY(ðhdr->src, PEER_MAC, ETH_HWADDR_LEN);
|
||||
|
||||
driverif_input(netif, p);
|
||||
}
|
||||
|
||||
static void ReplayArp(void *ptemp)
|
||||
{
|
||||
struct etharp_hdr *hdr;
|
||||
ip4_addr_t sipaddr, dipaddr;
|
||||
|
||||
(void)ptemp;
|
||||
LogPrintln("encode arp replay packet");
|
||||
inet_pton(AF_INET, GATEWAY_IP_BT, &sipaddr);
|
||||
inet_pton(AF_INET, STACK_IP_BT, &dipaddr);
|
||||
struct pbuf *p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_HDR, PBUF_RAM);
|
||||
hdr = (struct etharp_hdr *)p->payload;
|
||||
hdr->opcode = PP_HTONS(ARP_REPLY);
|
||||
/* Write the ARP MAC-Addresses */
|
||||
SMEMCPY(&hdr->shwaddr, PEER_MAC, ETH_HWADDR_LEN);
|
||||
SMEMCPY(&hdr->dhwaddr, NETIF_MAC, ETH_HWADDR_LEN);
|
||||
/* Copy struct ip4_addr_wordaligned to aligned ip4_addr, to support compilers without
|
||||
* structure packing. */
|
||||
IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->sipaddr, &sipaddr);
|
||||
IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->dipaddr, &dipaddr);
|
||||
hdr->hwtype = PP_HTONS(LWIP_IANA_HWTYPE_ETHERNET);
|
||||
hdr->proto = PP_HTONS(ETHTYPE_IP);
|
||||
/* set hwlen and protolen */
|
||||
hdr->hwlen = ETH_HWADDR_LEN;
|
||||
hdr->protolen = sizeof(ip4_addr_t);
|
||||
|
||||
ReplayArpEncodeEthernet(btProxyNf, p);
|
||||
}
|
||||
|
||||
static void ReplayArpTask()
|
||||
{
|
||||
int ret;
|
||||
ret = sys_thread_new("replay_arp", ReplayArp, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
}
|
||||
152
components/net/test/net_socket_test_012.c
Executable file
152
components/net/test/net_socket_test_012.c
Executable file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include "lwipopts.h"
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
|
||||
#define SRV_MSG "Hi, I am TCP server"
|
||||
#define CLI_MSG "Hi, I am TCP client"
|
||||
#define TEST_CASE 220
|
||||
#define TEST_COUNT 100
|
||||
#define STACK_PORT_TCP_DUP_START 3000
|
||||
|
||||
static int g_portServer = STACK_PORT_TCP_DUP_START;
|
||||
static int g_portClient = STACK_PORT_TCP_DUP_START;
|
||||
|
||||
static char g_bufServer[BUF_SIZE + 1] = { 0 };
|
||||
static char g_bufClient[BUF_SIZE + 1] = { 0 };
|
||||
extern sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio);
|
||||
|
||||
static int SampleTcpServer()
|
||||
{
|
||||
int sfd, lsfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
int ret;
|
||||
|
||||
/* tcp server */
|
||||
lsfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(g_portServer);
|
||||
g_portServer++;
|
||||
ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
|
||||
ret = listen(lsfd, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 3);
|
||||
|
||||
sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
|
||||
|
||||
/* send */
|
||||
(void)memset_s(g_bufServer, sizeof(g_bufServer), 0, sizeof(g_bufServer));
|
||||
(void)strcpy_s(g_bufServer, sizeof(g_bufServer), SRV_MSG);
|
||||
ret = send(sfd, g_bufServer, strlen(SRV_MSG), 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 5);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10);
|
||||
ret = closesocket(lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 11);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SampleTcpClient()
|
||||
{
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
int ret;
|
||||
|
||||
/* tcp client connection */
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
srvAddr.sin_port = htons(g_portClient);
|
||||
g_portClient++;
|
||||
ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 11);
|
||||
|
||||
/* recv */
|
||||
(void)memset_s(g_bufClient, sizeof(g_bufClient), 0, sizeof(g_bufClient));
|
||||
ret = recv(sfd, g_bufClient, sizeof(g_bufClient), 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 19);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TcpServerRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
g_testCase++;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < TEST_COUNT; i++) {
|
||||
(void)SampleTcpServer();
|
||||
}
|
||||
LogPrintln("tcp server g_portServer = %d", g_portServer);
|
||||
}
|
||||
|
||||
static void TcpClientRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
g_testCase++;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < TEST_COUNT; i++) {
|
||||
(void)SampleTcpClient();
|
||||
}
|
||||
LogPrintln("tcp server g_portClient = %d", g_portClient);
|
||||
}
|
||||
|
||||
void TcpTestDup()
|
||||
{
|
||||
LogPrintln("net_socket_test_012.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int ret;
|
||||
ret = sys_thread_new("tcp_server_dup", TcpServerRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
|
||||
ret = sys_thread_new("tcp_client_dup", TcpClientRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
|
||||
}
|
||||
139
components/net/test/net_socket_test_013.c
Executable file
139
components/net/test/net_socket_test_013.c
Executable file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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_test.h"
|
||||
#include "lwipopts.h"
|
||||
#include <arch/sys_arch.h>
|
||||
#include <lwip/sys.h>
|
||||
|
||||
#define TEST_CASE 230
|
||||
#define STACK_PORT_TCP_LONG 2231
|
||||
#define TCP_LONG_BUF_SIZE (2 * 1024)
|
||||
|
||||
extern sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stackSize, int prio);
|
||||
|
||||
static int SampleTcpServer()
|
||||
{
|
||||
int sfd, lsfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
struct sockaddr_in clnAddr = { 0 };
|
||||
socklen_t clnAddrLen = sizeof(clnAddr);
|
||||
int ret;
|
||||
static char serverBuf[TCP_LONG_BUF_SIZE] = {0};
|
||||
|
||||
/* tcp server */
|
||||
lsfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_TCP_LONG);
|
||||
ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 2);
|
||||
|
||||
ret = listen(lsfd, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 3);
|
||||
|
||||
sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
|
||||
|
||||
/* send */
|
||||
ret = send(sfd, serverBuf, TCP_LONG_BUF_SIZE, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, TCP_LONG_BUF_SIZE, 6);
|
||||
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 7);
|
||||
ret = closesocket(lsfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SampleTcpClient()
|
||||
{
|
||||
int sfd;
|
||||
struct sockaddr_in srvAddr = { 0 };
|
||||
int ret, i;
|
||||
int recvCount = 0;
|
||||
static char clientBuf[TCP_LONG_BUF_SIZE] = {0};
|
||||
|
||||
/* tcp client connection */
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 9);
|
||||
|
||||
srvAddr.sin_family = AF_INET;
|
||||
srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
|
||||
srvAddr.sin_port = htons(STACK_PORT_TCP_LONG);
|
||||
ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, 10);
|
||||
|
||||
/* recv */
|
||||
for (i = 0; i < TCP_LONG_BUF_SIZE; i++) {
|
||||
ret = recv(sfd, clientBuf, TCP_LONG_BUF_SIZE, 0);
|
||||
recvCount += ret;
|
||||
if (recvCount >= TCP_LONG_BUF_SIZE) {
|
||||
LogPrintln("client recv on socket %d: %d, i = %d", sfd, recvCount, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ICUNIT_ASSERT_NOT_EQUAL(i, TCP_LONG_BUF_SIZE, 12);
|
||||
ret = closesocket(sfd);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void TcpServerRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
g_testCase++;
|
||||
(void)SampleTcpServer();
|
||||
}
|
||||
|
||||
static void TcpClientRoutine(void *p)
|
||||
{
|
||||
(void)p;
|
||||
g_testCase++;
|
||||
(void)SampleTcpClient();
|
||||
}
|
||||
|
||||
void TcpTestLong()
|
||||
{
|
||||
LogPrintln("net_socket_test_013.c enter");
|
||||
g_testCase = TEST_CASE;
|
||||
int ret;
|
||||
ret = sys_thread_new("tcp_server_long", TcpServerRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
|
||||
|
||||
ret = sys_thread_new("tcp_client_long", TcpClientRoutine, NULL,
|
||||
STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
|
||||
}
|
||||
145
components/net/test/test_main.c
Normal file
145
components/net/test/test_main.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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 "sys/socket.h"
|
||||
#include "hos_cmsis_adp.h"
|
||||
|
||||
#define LWIP_TEST_TIMEOUT 1000 // timeout 1s
|
||||
#define LWIP_TEST_COUNT_FLAG 100
|
||||
|
||||
#define SOCKET_TEST 310
|
||||
#define UDP_TEST 320
|
||||
#define TCP_TEST 330
|
||||
#define OPT_TEST 340
|
||||
#define ORDER_TEST 350
|
||||
#define INET_TEST 360
|
||||
#define UDP_MORE_TEST 370
|
||||
#define TCP_MORE_TEST 380
|
||||
#define TCP_SELECT_TEST 390
|
||||
#define TCP_POLL_TEST 400
|
||||
#define NETIF_TEST 410
|
||||
#define TCP_DUP_TEST 420
|
||||
#define TCP_LONG_TEST 430
|
||||
|
||||
int g_lwipTimerCount = 0;
|
||||
int g_testCase = LWIP_TEST_COUNT_FLAG;
|
||||
int g_testError = 0;
|
||||
int g_testTemp = LWIP_TEST_COUNT_FLAG;
|
||||
extern void abort(void);
|
||||
extern int SocketTest(void);
|
||||
extern int UdpTest(void);
|
||||
extern void TcpTest();
|
||||
extern int SockOptTest();
|
||||
extern int ByteOrderTest(void);
|
||||
extern int InetTest();
|
||||
extern int UdpTestMore(void);
|
||||
extern void TcpTestMore();
|
||||
extern void TcpTestSelect();
|
||||
extern void TcpTestPoll();
|
||||
extern int UdpTestNetif(void);
|
||||
extern void TcpTestDup();
|
||||
extern void TcpTestLong();
|
||||
|
||||
// time out 1s
|
||||
static void LwipTestTimeoutCallback(void const *argument)
|
||||
{
|
||||
g_lwipTimerCount++;
|
||||
switch (g_lwipTimerCount) {
|
||||
case SOCKET_TEST:
|
||||
SocketTest();
|
||||
break;
|
||||
case UDP_TEST:
|
||||
UdpTest();
|
||||
break;
|
||||
case TCP_TEST:
|
||||
TcpTest();
|
||||
break;
|
||||
case OPT_TEST:
|
||||
SockOptTest();
|
||||
break;
|
||||
case ORDER_TEST:
|
||||
ByteOrderTest();
|
||||
break;
|
||||
case INET_TEST:
|
||||
InetTest();
|
||||
break;
|
||||
case UDP_MORE_TEST:
|
||||
UdpTestMore();
|
||||
break;
|
||||
case TCP_MORE_TEST:
|
||||
TcpTestMore();
|
||||
break;
|
||||
case TCP_SELECT_TEST:
|
||||
TcpTestSelect();
|
||||
break;
|
||||
case TCP_POLL_TEST:
|
||||
TcpTestPoll();
|
||||
break;
|
||||
case NETIF_TEST:
|
||||
UdpTestNetif();
|
||||
break;
|
||||
case TCP_DUP_TEST:
|
||||
TcpTestDup();
|
||||
break;
|
||||
case TCP_LONG_TEST:
|
||||
TcpTestLong();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
osTimerId_t g_lwipTestTimerId = NULL;
|
||||
|
||||
void LwipTestStartTimer(uint32 timeout)
|
||||
{
|
||||
osStatus_t status;
|
||||
if (g_lwipTestTimerId != NULL) {
|
||||
status = osTimerStart(g_lwipTestTimerId, timeout);
|
||||
if (status != osOK) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
g_lwipTestTimerId = osTimerNew((osTimerFunc_t)LwipTestTimeoutCallback, osTimerPeriodic, NULL, NULL);
|
||||
if (g_lwipTestTimerId == NULL) {
|
||||
return;
|
||||
}
|
||||
status = osTimerStart(g_lwipTestTimerId, timeout);
|
||||
if (status != osOK) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LwipTestEnter()
|
||||
{
|
||||
LwipTestStartTimer(LWIP_TEST_TIMEOUT);
|
||||
}
|
||||
Reference in New Issue
Block a user