From: SnickerSun Date: Mon, 27 Jan 2025 16:15:08 +0000 (+0800) Subject: 添加 4gSDK V1.0 库及源码 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F1644%2F6;p=mirrors%2FFD230.git 添加 4gSDK V1.0 库及源码 --- diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/CMakeLists.txt new file mode 100644 index 000000000..94ec0cbd0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/CMakeLists.txt @@ -0,0 +1,110 @@ +#=============================================================================== +# @brief cmake entry +# Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== +cmake_minimum_required(VERSION 3.14.1) +set(CMAKE_SYSTEM_NAME "Generic") + +if(NOT DEFINED CHIP) + message(FATAL_ERROR "Chip is not defined ") +endif() + +set(Python3_EXECUTABLE ${PY_PATH}) +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) +endif(CCACHE_FOUND) + +# default hso module_name & AUTO_DEF_FILE_ID, redefine these var in sub cmake file will +# override these value just in sub directory but not others +set(MODULE_NAME "pf") +set(AUTO_DEF_FILE_ID TRUE) + +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) +get_filename_component(ROOT_DIR "${PROJECT_SOURCE_DIR}" ABSOLUTE) +set(CMAKE_DIR "${ROOT_DIR}/build/cmake") +set(BIN_DIR "${ROOT_DIR}/interim_binary") + +include("${CMAKE_DIR}/build_function.cmake") +include("${CMAKE_DIR}/global_variable.cmake") +include("${CMAKE_DIR}/build_script.cmake") +include("${CMAKE_DIR}/build_command.cmake") +include("${CMAKE_DIR}/build_hso_database.cmake") +include("${CMAKE_DIR}/build_component.cmake") +include("${CMAKE_DIR}/build_sdk.cmake") + +if(${BUILD_TYPE} STREQUAL "UT") + KCONFIG_GET_PARAMS("${ROOT_DIR}/build/menuconfig/test/platform/ut.config") + include("${CMAKE_DIR}/build_ut.cmake") + return() +endif() + +if(${BUILD_TYPE} STREQUAL "FUZZ") + KCONFIG_GET_PARAMS("${ROOT_DIR}/build/menuconfig/test/platform/ut.config") + include("${CMAKE_DIR}/build_fuzz.cmake") + return() +endif() + +project(${CHIP}_CFBB C ASM CXX) +set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "") + +if(EXISTS ${CMAKE_BINARY_DIR}/auto_gen_libfunc.lds) + file(REMOVE ${CMAKE_BINARY_DIR}/auto_gen_libfunc.lds) +endif() + +set(TARGET_COMPONENT "${RAM_COMPONENT}" "${ROM_COMPONENT}") +set(TARGET_NAME ${BIN_NAME}) +file(WRITE ${PROJECT_BINARY_DIR}/temp/__null___.c "int __null___(void) {return 0;}") +add_executable(${BIN_NAME} ${PROJECT_BINARY_DIR}/temp/__null___.c) +set_target_properties(${BIN_NAME} PROPERTIES RUNTIME_OUTPUT_NAME ${BIN_NAME}.elf) +target_compile_options(${BIN_NAME} PRIVATE "${CCFLAGS}") + +include("${CMAKE_DIR}/build_rom_callback.cmake") +if(${BUILD_ROM_CALLBACK}) + build_rom_callback() +endif() + +set(KCONFIG_PATH "${ROOT_DIR}/build/config/target_config/${CHIP}/menuconfig/${CORE}/${BUILD_TARGET_NAME}.config") +if(EXISTS ${KCONFIG_PATH}) + KCONFIG_GET_PARAMS(${KCONFIG_PATH}) + set(USE_KCONFIG True) +endif() + +add_subdirectory_if_exist(application) +add_subdirectory_if_exist(bt) +add_subdirectory_if_exist(bootloader) +add_subdirectory_if_exist(kernel) +add_subdirectory_if_exist(drivers) +add_subdirectory_if_exist(middleware) +add_subdirectory_if_exist(open_source) +add_subdirectory_if_exist(protocol) +add_subdirectory_if_exist(test) +add_subdirectory_if_exist(include) +add_subdirectory_if_exist(vendor) +add_subdirectory_if_exist(zhihui) + +include("${CMAKE_DIR}/open_source.cmake") +include("${CMAKE_DIR}/build_linker.cmake") + +if (NOT DEFINED ROM_COMPONENT) +add_custom_target(GENERAT_BIN ALL + COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary -R .logstr -R .ARM -R .ARM ${TARGET_NAME}.elf ${TARGET_NAME}.bin + COMMENT "post_build:gen bin file" + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${TARGET_NAME} +) +else() +add_custom_target(GENERAT_BIN ALL + COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary -R .logstr -R .ARM.exidx -R .ARM.extab -R .*_romtext ${TARGET_NAME}.elf ${TARGET_NAME}.bin + COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary -j .*_romtext ${TARGET_NAME}.elf ${TARGET_NAME}_rom.bin + COMMENT "post_build:gen rom and ram bin file" + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${TARGET_NAME} +) +endif() + +include("${CMAKE_DIR}/build_ssb.cmake") +include("${CMAKE_DIR}/build_elf_info.cmake") + +create_hso_db() +generate_project_file() diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/audio/vendor/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/application/audio/vendor/CMakeLists.txt new file mode 100644 index 000000000..c1c31962b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/audio/vendor/CMakeLists.txt @@ -0,0 +1,72 @@ +#[[ +Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. +Description: CMake audio sample module. +Author: audio +Create: 2023-06-09 +]] + +set(SAP_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../drivers/drivers/driver/audio/source) +#=================================================================================== +include(${SAP_TOP_DIR}/build/cmake/audio_config.cmake) +#=================================================================================== +set(COMPONENT_NAME audio_vendor) +set(MODULE_NAME "dsp") +set(AUTO_DEF_FILE_ID TRUE) +#=================================================================================== +set(COMPONENT_SRC ) +#=================================================================================== +set(COMPONENT_INC + ${SAP_UAPI_DIR} + ${SAP_TOP_DIR}/include + ${SAP_TOP_DIR}/drv/vendor + ${SAP_TOP_DIR}/drv/include + ${SAP_TOP_DIR}/drv/common/include + ${SAP_TOP_DIR}/drv/arch/include + ${SAP_TOP_DIR}/drv/arch/${CFG_SAP_CHIP_TYPE}/include + ${SAP_TOP_DIR}/core/include + ${SAP_TOP_DIR}/core/common/include + ${SAP_TOP_DIR}/core/arch/${CFG_SAP_CHIP_TYPE}/include + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/common +) +#=================================================================================== +if("${CFG_SAP_VENDOR_DRIVER_AW88262_SUPPORT}" STREQUAL "y") +set(COMPONENT_SRC ${COMPONENT_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/aw88262/aw88262.c +) +set(COMPONENT_INC ${COMPONENT_INC} + ${CMAKE_CURRENT_SOURCE_DIR}/aw88262 +) +endif() + +if("${CFG_SAP_VENDOR_DRIVER_AW88166_SUPPORT}" STREQUAL "y") +set(COMPONENT_SRC ${COMPONENT_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166/aw88166.c + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166/aw883xx.c + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166/aw883xx_calib.c + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166/aw883xx_device.c + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166/product_init_files/aw88166/aw883xx_pid_2066_init.c +) +set(COMPONENT_INC ${COMPONENT_INC} + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166 + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166/product_init_files/aw88166 + ${CMAKE_CURRENT_SOURCE_DIR}/aw88166/config/aw88166/mono/16bit +) +endif() + +if("${CFG_SAP_VENDOR_DRIVER_ANC_CODEC_SUPPORT}" STREQUAL "y") +set(COMPONENT_SRC ${COMPONENT_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/anc_codec/anc_codec.c +) +set(COMPONENT_INC ${COMPONENT_INC} + ${CMAKE_CURRENT_SOURCE_DIR}/anc_codec + ${CMAKE_CURRENT_SOURCE_DIR}/anc_codec/sai01_dac_32.768k +) +endif() +#=================================================================================== +set(COMPONENT_DEF + "SAP_PROC_SUPPORT" +) +#=================================================================================== +include(${SAP_TOP_DIR}/build/cmake/audio_common.cmake) +install_sdk(${CMAKE_CURRENT_SOURCE_DIR}/aw88166 "*") diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/audio/vendor/aw88166/aw88166.c b/sdk_release/v1.0/4gsdk_new/code/sdk/application/audio/vendor/aw88166/aw88166.c new file mode 100644 index 000000000..a0f2d29a3 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/audio/vendor/aw88166/aw88166.c @@ -0,0 +1,278 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: source file for aw88166 driver + */ + +#include +#include "soc_osal.h" +#include "audio_debug.h" +#include "gpio.h" +#include "hal_gpio.h" +#include "i2c.h" +#include "pinctrl.h" +#include "vendor_common.h" +#include "soc_uapi_vendor.h" + +#include "aw883xx_init.h" +#include "aw883xx.h" +#include "aw_params.h" + +static td_bool g_aw88166_i2c_inited = TD_FALSE; + +#define AW88166_PWR_ON_PIN S_AGPIO_L25 +#define AW88166_I2C_BUS_ID I2C_BUS_3 +#define AW88166_I2C_DEV_ADDR 0x34 + +static td_s32 aw_dev0_i2c_write_func(td_u16 dev_addr, td_u8 reg_addr, td_u8 *pdata, td_u16 len) +{ + td_s32 ret; + i2c_data_t data; + const td_u8 reg_addr_len = sizeof(reg_addr); /* data len of reg_addr */ + const td_u8 send_len = len + reg_addr_len; /* pdata bytes && reg_addr len */ + td_u8 *send_data = osal_kmalloc_align(send_len, 0, 8); /* 8 : Align up to 8 bytes */ + + if (send_data == TD_NULL) { + ret = -1; /* -1:FAILED ERR CODE */ + vendor_log_fun_err(malloc, ret); + return ret; + } + + /* pack reg addr & reg data */ + *send_data = reg_addr; /* reg_addr */ + ret = memcpy_s(send_data + reg_addr_len, (send_len - reg_addr_len), pdata, len); /* pdata */ + if (ret != EOK) { + vendor_log_fun_err(memcpy_s, ret); + goto out; + } + + data.send_buf = send_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; + ret = (td_s32)uapi_i2c_master_write(AW88166_I2C_BUS_ID, dev_addr, &data); + if (ret != ERRCODE_SUCC) { + vendor_log_fun_err(uapi_i2c_master_write, ret); + goto out; + } + +out: + if (send_data != TD_NULL) { + osal_kfree(send_data); + } + return ret; +} + +static td_s32 aw_dev0_i2c_read_func(td_u16 dev_addr, td_u8 reg_addr, td_u8 *pdata, td_u16 len) +{ + td_s32 ret; + + i2c_data_t data; + + data.send_buf = ®_addr; + data.send_len = sizeof(reg_addr); + data.receive_buf = pdata; + data.receive_len = len; + ret = (td_s32)uapi_i2c_master_writeread(AW88166_I2C_BUS_ID, dev_addr, &data); + if (ret != ERRCODE_SUCC) { + vendor_log_fun_err(uapi_i2c_master_writeread, ret); + return ret; + } + + return AUDIO_SUCCESS; +} + +static td_void aw_dev0_reset_gpio_ctl(bool state) +{ + uapi_gpio_set_val(AW88166_PWR_ON_PIN, state); +} + +static td_void aw88166_pwr_on_pin_init(td_void) +{ + uapi_gpio_set_dir(AW88166_PWR_ON_PIN, GPIO_DIRECTION_OUTPUT); +} + +static td_s32 aw88166_i2c_init(td_void) +{ + td_s32 ret; + audio_func_enter(); + + /* init i2c */ + vendor_trace_log_u32(AW88166_I2C_BUS_ID); + ret = (td_s32)uapi_i2c_master_init(AW88166_I2C_BUS_ID, I2C_BAUDRATE, I2C_HIGH_SPEED_CODE); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(uapi_i2c_master_init, ret); + return ret; + } + + vendor_printf("aw88166 i2c init success\n"); + audio_func_exit(); + return AUDIO_SUCCESS; +} + +static td_s32 aw88166_i2c_deinit(td_void) +{ + td_s32 ret; + audio_func_enter(); + + /* deinit i2c */ + vendor_trace_log_u32(AW88166_I2C_BUS_ID); + ret = (td_s32)uapi_i2c_deinit(AW88166_I2C_BUS_ID); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(uapi_i2c_deinit, ret); + return ret; + } + + vendor_printf("aw88166 i2c deinit success\n"); + audio_func_exit(); + return AUDIO_SUCCESS; +} + +td_s32 aw883xx_pid_2066_dev_init(td_void *aw883xx); + +struct aw_init_info init_info[] = { + { + .dev = AW_DEV_0, + .i2c_addr = AW88166_I2C_DEV_ADDR, + .re_min = 2000, /* awinic:If the re_min(ohms) and re_max(ohms) are not set, the default value is used */ + .re_max = 39000, + .mix_chip_count = AW_DEV0_MIX_CHIP_NUM, + .prof_info = g_dev0_prof_info, + .i2c_read_func = aw_dev0_i2c_read_func, + .i2c_write_func = aw_dev0_i2c_write_func, + .reset_gpio_ctl = aw_dev0_reset_gpio_ctl, + .dev_init_ops = {aw883xx_pid_2066_dev_init}, + } +}; + +static td_s32 audio_aw88166_configuration(const uapi_vendor_codec_attr *attr) +{ + td_s32 ret; + + /* awinic:Control interface of dev0 */ + /* awinic:initialization */ + ret = aw883xx_smartpa_init((td_void *)&init_info[AW_DEV_0]); + if (ret != AUDIO_SUCCESS) { + vendor_printf("aw883xx_smartpa_init already init\n"); + } + /* awinic:set mode "Music", "aw_params.h" contains id information */ + ret = aw883xx_set_profile_byname(AW_DEV_0, "Music"); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_set_profile_byname, ret); + } + + vendor_unused(attr); + return ret; +} + +static td_s32 audio_aw88166_deconfiguration(td_void) +{ + /* awinic:Free the requested memory when PA is not used */ + aw883xx_smartpa_deinit(AW_DEV_0); + + return AUDIO_SUCCESS; +} + +td_s32 audio_aw88166_init(const uapi_vendor_codec_attr *attr) +{ + td_s32 ret; + + audio_func_enter(); + + aw88166_pwr_on_pin_init(); + + if (g_aw88166_i2c_inited != TD_TRUE) { + ret = aw88166_i2c_init(); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw88166_i2c_init, ret); + return ret; + } + g_aw88166_i2c_inited = TD_TRUE; + } else { + ret = 0; + } + + ret = audio_aw88166_configuration(attr); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(audio_aw88166_configuration, ret); + } + + return AUDIO_SUCCESS; +} + +td_s32 audio_aw88166_deinit(td_void) +{ + td_s32 ret; + audio_func_enter(); + + ret = audio_aw88166_deconfiguration(); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(audio_aw88166_deconfiguration, ret); + } + + if (g_aw88166_i2c_inited != TD_FALSE) { + ret = aw88166_i2c_deinit(); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw88166_i2c_deinit, ret); + return ret; + } + g_aw88166_i2c_inited = TD_FALSE; + } else { + ret = AUDIO_SUCCESS; + } + + audio_func_exit(); + return ret; +} + +td_s32 audio_aw88166_start(const uapi_vendor_codec_attr *attr) +{ + td_s32 ret; + + audio_func_enter(); + + /* awinic:The platform needs to output I2s first, and then ctl start */ + ret = aw883xx_ctrl_state(AW_DEV_0, AW_START); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_ctrl_state, ret); + } + + vendor_unused(attr); + return ret; +} + +td_s32 audio_aw88166_stop(td_void) +{ + td_s32 ret; + audio_func_enter(); + + /* awinic:The platform needs to control the stop first and then stop I2S */ + ret = aw883xx_ctrl_state(AW_DEV_0, AW_STOP); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_ctrl_state, ret); + } + audio_func_exit(); + return ret; +} + +td_s32 audio_aw88166_set_aef_profile(uapi_snd_aef_profile aef_profile) +{ + td_s32 ret; + + audio_func_enter(); + + /* awinic:set mode "Receiver"/"Music", "aw_params.h" contains id information */ + if (aef_profile == UAPI_SND_AEF_PROFILE_VOIP) { + /* awinic:set mode "Receiver" */ + ret = aw883xx_set_profile_byname(AW_DEV_0, "Receiver"); + } else { + /* awinic:set mode "Music" */ + ret = aw883xx_set_profile_byname(AW_DEV_0, "Music"); + } + + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_set_profile_byname, ret); + } + + audio_func_exit(); + return ret; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/service_init.c b/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/service_init.c new file mode 100644 index 000000000..2fc04cd01 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/service_init.c @@ -0,0 +1,143 @@ + +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Application core board init function for standard + * Author: + * Create: + */ + +#ifdef __LITEOS__ +#include "partition.h" +#endif +#include "pm.h" +#include "cpu_utils.h" +#include "log_common.h" +#include "log_uart.h" +#include "exception.h" +#include "log_oml_exception.h" +#ifdef HSO_SUPPORT +#include "dfx_system_init.h" +#endif +#include "debug_print.h" +#ifdef SUPPORT_AT_GRAPHIC +#include "graphic_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_OHOSFWK +#include "ohosfwk_at_process.h" +#endif +#ifdef SUPPORT_AT_APP +#include "app_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_AUDIO +#include "audio_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_BT_MANAGER +#include "bt_manager_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_MEDIA +#include "media_cmd_manager.h" +#endif + +#ifdef SUPPORT_AT_CAT1 +#include "cat1_at_cmd.h" +#endif + +#include "log_file.h" +#ifdef CONFIG_OTA_UPDATE_SUPPORT +#include "upg.h" +#endif +static void register_at_service(void) +{ +#ifdef SUPPORT_AT_GRAPHIC + uint32_t graphic_cmd_count; + at_cmd_table_t *graphic_table = get_graphic_cmd_table(&graphic_cmd_count); + at_cmd_add_moudle(graphic_table, graphic_cmd_count); +#endif +#ifdef SUPPORT_AT_OHOSFWK +#ifdef JS_ENABLE + uint32_t ohosfwk_cmd_count; + at_cmd_table_t *ohosfwk_table = get_ohosfwk_cmd_table(&ohosfwk_cmd_count); + at_cmd_add_moudle(ohosfwk_table, ohosfwk_cmd_count); +#endif +#endif +#ifdef SUPPORT_AT_APP + uint32_t app_cmd_count; + at_cmd_table_t *app_table = get_app_cmd_table(&app_cmd_count); + at_cmd_add_moudle(app_table, app_cmd_count); +#endif +#ifdef SUPPORT_AT_AUDIO + uint32_t audio_cmd_count; + at_cmd_table_t *audio_table = get_audio_cmd_table(&audio_cmd_count); + at_cmd_add_moudle(audio_table, audio_cmd_count); +#endif +#ifdef SUPPORT_AT_BT_MANAGER + uint32_t bt_manager_cmd_count; + at_cmd_table_t *bt_manager_table = get_bt_manager_cmd_table(&bt_manager_cmd_count); + at_cmd_add_moudle(bt_manager_table, bt_manager_cmd_count); +#endif +#ifdef SUPPORT_AT_MEDIA + uint32_t media_cmd_count; + at_cmd_table_t *media_table = get_media_cmd_table(&media_cmd_count); + at_cmd_add_moudle(media_table, media_cmd_count); +#endif + +#ifdef SUPPORT_AT_CAT1 + uint32_t cat1_cmd_count; + at_cmd_table_t *cat1_table = get_cat1_cmd_table(&cat1_cmd_count); + at_cmd_add_moudle(cat1_table, cat1_cmd_count); +#endif + +} + +#ifdef CONFIG_OTA_UPDATE_SUPPORT +static void upg_putc(const char c) +{ + printf("%c", c); +} +#endif + +void service_init(void) +{ +#if defined(FREERTOS_TEST) + // freertos demo test + extern int main_full(void); + (void)main_full(); + for (;;) { + } +#endif + + /* dfx init step 1: log init */ + log_init(); + log_init_after_rtos(); + log_uart_init_after_rtos(); + + cpu_utils_init(); + hal_register_exception_dump_callback(log_exception_dump); + uapi_partition_init(); + PRINT("partition init success"NEWLINE); + +#ifdef CONFIG_OTA_UPDATE_SUPPORT + upg_func_t upg_func = {0}; + upg_func.malloc = malloc; + upg_func.free = free; + upg_func.serial_putc = upg_putc; + (void)uapi_upg_init(&upg_func); + PRINT("upg init success\r\n"); +#endif + + uapi_nv_init(); +#ifdef SUPPORT_AT_BT_MANAGER + set_calibration_from_nv(); +#endif + /* dfx init step 2: dfx init */ +#ifdef HSO_SUPPORT + dfx_system_init(); +#endif + /* power manager init */ + uapi_pm_init(); +#ifdef SUPPORT_POWER_MANAGER + uapi_power_display_init(); +#endif + + register_at_service(); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/thread_init.c b/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/thread_init.c new file mode 100644 index 000000000..0a1257638 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/thread_init.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Application Core OS Initialize Interface for Standard + * Author: + * Create: 2021-03-09 + */ +#include "thread_init.h" +#include "tcxo.h" +#include "log_common.h" +#include "log_def.h" +#include "log_uart.h" +#include "log_file.h" +#ifdef __LITEOS__ +#include "los_status.h" +#endif +#include "pmu_interrupt.h" +#include "log_reg_dump.h" +#include "watchdog.h" +#include "preserve.h" +#include "hal_reboot.h" +#include "pinctrl_porting.h" +#include "pm_sleep.h" +#include "pm_lpc.h" +#include "pm_control.h" +#include "dfx_system_init.h" +#include "cpu_load.h" +#include "exception_dump.h" + +#ifdef SUPPORT_AT_CMD +#include "at_cmd_api.h" +#endif + +#ifdef SUPPORT_AT_GRAPHIC +#include "graphic_msg_manager.h" +#include "graphic_rx_process.h" +#endif + +#ifdef SUPPORT_AT_APP +#include "app_msg_manager.h" +#include "app_rx_process.h" +#endif + +#ifdef SUPPORT_AT_AUDIO +#include "audio_msg_manager.h" +#include "audio_rx_process.h" +#endif + +#ifdef SUPPORT_AT_BT_MANAGER +#include "bt_manager_msg_manager.h" +#include "bt_manager_rx_process.h" +#endif + +#ifdef SUPPORT_AT_MEDIA +#include "media_msg_manager.h" +#include "media_rx_process.h" +#endif + +#include "clocks_config.h" +#ifdef SUPPORT_POWER_MANAGER +#include "power_display_service.h" +#endif + +#if defined(__FREERTOS__) +#include "FreeRTOS.h" +#if defined(FREERTOS_DEBUG) +#include "debug_cmd.h" +#endif +#endif + +#ifdef SUPPORT_MEDIA_AUDIO_MANAGER +#include "audio_manager_c_wrapper.h" +#endif +#include "clocks_config.h" +#include "sys/time.h" +#include "time.h" +#include "log_panic.h" +#include "nandflash_config.h" +#ifdef SUPPORT_AUTO_OTA +#include "auto_ota_service.h" +#endif + +#define EMMC_BASE_ADDR 0x52062000 + +#define TASK_COMMON_APP_DELAY_MS 5000 + +#define TASK_PRIORITY_APP (osPriority_t)(17) +#define TASK_PRIORITY_LOG (osPriority_t)(18) +#define TASK_PRIORITY_CMD (osPriority_t)(17) +#define TASK_PRIORITY_BRANDY_APP (osPriority_t)(15) +#define TASK_PRIORITY_SDK (osPriority_t)(31) +#define TASK_PRIORITY_DFX_MSG (osPriority_t)(18) +#define TASK_PRIORITY_TRANSMIT (osPriority_t)(20) +#define TASK_PRIORITY_SAVE_FILE (osPriority_t)(36) +#define TASK_PRIORITY_AUTO_OTA (osPriority_t)(36) + +#define BTH_SDK_STACK_SIZE 0xC00 +#define AT_GRAPHIC_STACK_SIZE 0xC00 +#define AT_APP_STACK_SIZE 0x1000 +#define AT_AUDIO_STACK_SIZE 0x1000 +#define AT_BT_MANAGER_STACK_SIZE 0x1000 +#define AT_MEDIA_STACK_SIZE 0x1000 +#define DFX_MSG_STACK_SIZE 0x2000 +#define PM_DISPLAY_MSG_STACK_SIZE 0xc00 +#define AT_OHOSFWK_STACK_SIZE 0xC00 +#define APP_MAIN_STACK_SIZE 0xC00 +#define SAVE_FILE_STACK_SIZE 0xC00 +#define AUTO_OTA_STACK_SIZE 0xC00 + +#define TIME_MAX 64 +#define USEC_TO_MILLI 1000 +#define TCXO_TICKS_PER_MILLISECOND 32000 + +static void app_main(const void *unused); +void cmd_processor_entry(const void *args); +void cmd_main_add_functions(void); +void bt_acore_task_main(const void *pvParams); +int msg_process_thread(void *data); +errcode_t thread_msg_event_init(void); +int transmit_process_thread(void *data); +errcode_t transmit_thread_msg_init(void); +void system_time_cali(void); +#ifdef SUPPORT_32K_MEAS +void uapi_32k_systick_measurements(void); +#endif +osSemaphoreId_t g_semaphore_save = NULL; +void save_file_main(void); + +static uint32_t g_app_delay_ms = TASK_COMMON_APP_DELAY_MS; +app_task_definition_t g_app_tasks[] = { + { { "app", 0, NULL, 0, NULL, APP_MAIN_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)app_main, NULL, NULL, USE_DTCM_MEM }, +#if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == NO) + { { "log", 0, NULL, 0, NULL, (0xC00), TASK_PRIORITY_LOG, 0, 0 }, + (osThreadFunc_t)log_main, NULL, NULL, USE_DTCM_MEM }, +#endif + { { "bt_sdk", 0, NULL, 0, NULL, BTH_SDK_STACK_SIZE, TASK_PRIORITY_SDK, 0, 0 }, + (osThreadFunc_t)bt_acore_task_main, NULL, NULL, USE_DTCM_MEM }, +#ifdef SUPPORT_AT_CMD + { { "at_cmd", 0, NULL, 0, NULL, 0x1C00, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)at_cmd_task_process_handler, NULL, + (CreateQueueFunction_t)at_cmd_task_queue_init, USE_DTCM_MEM }, +#endif +#if defined(SUPPORT_AT_GRAPHIC) + { { "at_graphic", 0, NULL, 0, NULL, AT_GRAPHIC_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)graphic_at_task_process_handler, NULL, + (CreateQueueFunction_t)graphic_at_task_queue_init, USE_EXTEND_MEM }, +#endif +#ifdef SUPPORT_AT_APP + { { "at_app", 0, NULL, 0, NULL, AT_APP_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)app_at_task_process_handler, NULL, + (CreateQueueFunction_t)app_at_task_queue_init, USE_EXTEND_MEM }, +#endif +#ifdef SUPPORT_AT_AUDIO + { { "at_audio", 0, NULL, 0, NULL, AT_AUDIO_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)audio_at_task_process_handler, NULL, + (CreateQueueFunction_t)audio_at_task_queue_init, USE_DTCM_MEM }, +#endif +#ifdef SUPPORT_AT_BT_MANAGER + { { "at_bt_manager", 0, NULL, 0, NULL, AT_BT_MANAGER_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)bt_manager_task_process_handler, NULL, + (CreateQueueFunction_t)bt_manager_at_task_queue_init, USE_DTCM_MEM }, +#endif +#ifdef SUPPORT_AT_MEDIA + { { "at_media", 0, NULL, 0, NULL, AT_MEDIA_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)media_at_task_process_handler, NULL, + (CreateQueueFunction_t)media_at_task_queue_init, USE_DTCM_MEM }, +#endif +#ifdef HSO_SUPPORT + { { "dfx_msg", 0, NULL, 0, NULL, DFX_MSG_STACK_SIZE, TASK_PRIORITY_DFX_MSG, 0, 0 }, + (osThreadFunc_t)msg_process_thread, NULL, + (CreateQueueFunction_t)thread_msg_event_init, USE_DTCM_MEM }, +#endif +#if (CONFIG_DFX_SUPPORT_TRANSMIT_FILE == DFX_YES && !defined(MEMORY_MINI)) + { { "transmit", 0, NULL, 0, NULL, DFX_MSG_STACK_SIZE, TASK_PRIORITY_TRANSMIT, 0, 0 }, + (osThreadFunc_t)transmit_process_thread, NULL, + (CreateQueueFunction_t)transmit_thread_msg_init, USE_DTCM_MEM }, +#endif +#if defined(SUPPORT_POWER_MANAGER) && !defined(SUPPORT_AT_OHOSFWK) + /* OHOS场景,pms不需要独立的队列和线程,事件由UI线程接管处理 */ + { { "power_display", 0, NULL, 0, NULL, PM_DISPLAY_MSG_STACK_SIZE, TASK_PRIORITY_TRANSMIT, 0, 0 }, + (osThreadFunc_t)power_display_msg_thread, NULL, + (CreateQueueFunction_t)power_display_task_init, USE_DTCM_MEM }, +#endif + { { "save_file", 0, NULL, 0, NULL, SAVE_FILE_STACK_SIZE, TASK_PRIORITY_SAVE_FILE, 0, 0 }, + (osThreadFunc_t)save_file_main, NULL, NULL, USE_EXTEND_MEM }, +#ifdef SUPPORT_AUTO_OTA + { { "auto_ota", 0, NULL, 0, NULL, AUTO_OTA_STACK_SIZE, TASK_PRIORITY_AUTO_OTA, 0, 0 }, + (osThreadFunc_t)auto_ota_task_main, NULL, NULL, USE_DTCM_MEM }, +#endif +}; + +osSemaphoreId_t get_save_file_semaphore(void) +{ + return g_semaphore_save; +} + +void save_file_main(void) +{ + if (osKernelGetState() == osKernelRunning) { + dump_norflash_trace_to_file(); + } + g_semaphore_save = osSemaphoreNew(1, 0, NULL); + if (!g_semaphore_save) { + panic(PANIC_LOG, LOG_PANIC_MUTEX_NOT_READY); + return; + } + for (;;) { + // If there has been log indicator get run again + if (osKernelGetState() == osKernelRunning) { + if (osSemaphoreAcquire(g_semaphore_save, osWaitForever) != osOK) { + panic(PANIC_LOG, LOG_PANIC_MUTEX_NOT_READY); + } + nand_driver_init(SPEED_SLOW); + set_trans_type(TRANS_BY_CPU_SINGLE_LINE); +#if defined SAVE_EXC_INFO + save_preserve_file_to_nand(); + save_btram_file_to_nand(); + save_btrace_file_to_nand(); +#endif + hal_reboot_chip(); + } + osDelay(1000); + } +} + +void set_app_delay_time(uint32_t time) +{ + g_app_delay_ms = time; +} + +void thread_init(void) +{ + /* Create queues before tasks in case they are used during initialisation. */ + for (uint8_t i = 0; i < (sizeof(g_app_tasks) / sizeof(app_task_definition_t)); i++) { + if (g_app_tasks[i].create_queue_handle) { + g_app_tasks[i].create_queue_handle(); + } + } + + /* Create tasks */ + for (uint8_t i = 0; i < (sizeof(g_app_tasks) / sizeof(app_task_definition_t)); i++) { + if (g_app_tasks[i].use_mem == USE_EXTEND_MEM) { + g_app_tasks[i].attr.stack_mem = memalign(16, g_app_tasks[i].attr.stack_size); // 16字节对齐 +#if defined(__FREERTOS__) + g_app_tasks[i].attr.cb_size = sizeof(StaticTask_t); + g_app_tasks[i].attr.cb_mem = memalign(16, sizeof(StaticTask_t)); // 16字节对齐 +#endif + } + g_app_tasks[i].task_handle = osThreadNew(g_app_tasks[i].func, NULL, &(g_app_tasks[i].attr)); + if (g_app_tasks[i].task_handle == NULL) { + panic(PANIC_TASK_CREATE_FAILED, i); + } + } +} + +static void print_system_sleep_info(void) +{ +#if ENABLE_LOW_POWER == YES + uint32_t deepsleep_time, lightsleep_time; + uint32_t deepsleep_cnt, lightsleep_cnt; + + sleep_info_t *sleep_info = pm_get_sleep_info(); + + deepsleep_time = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_DS].total_slp_time); + deepsleep_cnt = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_DS].total_slp_count); + + lightsleep_time = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_LS].total_slp_time); + lightsleep_cnt = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_LS].total_slp_count); + + uint32_t sys_slp = readw(0x57004088); + PRINT("sys_slp: 0x%x\r\n", sys_slp); + reg16_setbit(0x57004088, 1); // clr slp history + reg16_setbit(0x57004088, 0); // clr slp history + + bool m_core_sleep = pmu_msystem_sleep_history(); + pmu_msystem_sleep_history_clear(); + PRINT("M core deepsleep time:%d, lightsleep time:%d, m sleep flag:%d"NEWLINE, + deepsleep_time, lightsleep_time, (uint8_t)m_core_sleep); + PRINT("M core deepsleep cnt:%d, lightsleep cnt:%d"NEWLINE, deepsleep_cnt, lightsleep_cnt); + PRINT("M core last veto id:%d, last veto count:%d"NEWLINE, sleep_info->sleep_veto.last_veto_id, + sleep_info->sleep_veto.last_veto_count); + + oml_pf_log_print1(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, "sys_slp: 0x%d", sys_slp); + oml_pf_log_print4(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, + "App run time:%d, app deepsleep time:%d, lightsleep time:%d, m sleep flag:%d", + (uint32_t)los_system_system_run_time(), deepsleep_time, lightsleep_time, (uint8_t)m_core_sleep); +#endif +} + +#ifdef SUPPORT_32K_MEAS +/* 使用32M tcxo 测量 systick的32K频率值 */ +void uapi_32k_systick_measurements(void) +{ + uint64_t cali_ms = 500; // 单次测量时长(ms) + uint64_t start_count = 0; + uint64_t total_count = 0; + uint64_t freq_32k = 0; + + uint32_t irq = osal_irq_lock(); + start_count = uapi_tcxo_get_count(); + uapi_systick_delay_ms(cali_ms); + total_count = uapi_tcxo_get_count() - start_count; + osal_irq_restore(irq); + + freq_32k = (STANDARD_32K_FREQUENCY * cali_ms * TCXO_TICKS_PER_MILLISECOND) / (total_count); + PRINT("32M_count = %llu, after calculation 32K freq = %llu."NEWLINE, total_count, freq_32k); + oml_pf_log_print2(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, + "32M_count = %llu, after calculation 32K freq = %llu.", total_count, freq_32k); + return; +} +#endif + +void system_time_cali(void) +{ + struct timeval tv = { 0 }; + + if (gettimeofday(&tv, NULL)) { + return; + } + return; +} + +static void app_main(const void *unused) +{ + unused(unused); + dfx_set_log_enable(); +#ifdef SUPPORT_MEDIA_AUDIO_MANAGER + bool success = AudioManagerInit(); + PRINT("audio manager init %s\r\n", success ? "ok" : "error"); +#endif + oml_pf_log_print0(LOG_BCORE_PLT, LOG_NUM_DEBUG, LOG_LEVEL_INFO, "App main"); +#if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == NO) + log_exception_dump_reg_check(); +#endif + uapi_pm_request_mode(PM_ID_DEBUG, PM_MODE_LP); + PRINT("app_main run start."NEWLINE); + while (1) { //lint !e716 Main Loop + (void)osDelay(g_app_delay_ms); + uapi_watchdog_kick(); + uapi_logfile_fsync(STORE_DIAG); +#ifdef SUPPORT_32K_MEAS + uapi_32k_systick_measurements(); +#endif + system_time_cali(); +#ifndef XTS_SUPPORT + PRINT("app_main run start."NEWLINE); + print_system_sleep_info(); + oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, "App run ok."); +#endif + } +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/thread_pri_init.c new file mode 100644 index 000000000..ed74fbba4 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -0,0 +1,402 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Application Core OS Priority Initialize Interface for Standard + * Author: + * Create: 2022-12-03 + */ +#include "debug_print.h" +#include "thread_init.h" +#include "common_def.h" +#include "pm.h" +#include "watchdog.h" +#include "cpu_trace.h" +#include "non_os_reboot.h" +/* after reboot system emmc need write exc info to the file system from sector */ +#if defined(SAVE_EXC_INFO) && defined(CFG_DRIVERS_MMC) +#include "exception.h" +#endif +#ifdef CFG_DRIVERS_MMC +#ifdef __LITEOS__ +#include "soc/mmc.h" +#endif +#include "soc_mmc.h" +#endif +#include "soc_lcd_api.h" +#ifdef CFG_DRIVERS_NANDFLASH +#include "nandflash_config.h" +#include "yaffs_nand_drv.h" +#endif +#if defined(TPTYPE_TMA525B) +#include "tma525b_drv1.h" +#elif defined(TPTYPE_ZTW523) +#include "ztw523_touch1.h" +#elif defined(TPTYPE_FT6X46) +#include "ft6x46_touch1.h" +#else +#include "ztw523_touch1.h" +#endif + +#ifdef SUPPORT_CAT1_SERVICE +#include "cat1_pub_api.h" +#endif +#ifdef SUPPORT_BATTERY_SERVICE +#include "battery_service.h" +#endif +#include "thread_pri_init.h" +#if DSP_EXIST == YES +#include "soc_uapi_audio_sys.h" +#include "soc_uapi_vendor.h" +#include "soc_uapi_sound.h" +/* Audio codec vendor select according to hardware connection: + * define AUDIO_SMARTPA_AW88166 : macro to init smartpa aw88166; + * define AUDIO_SMARTPA_AW88166_I2S_ID UAPI_SND_OUT_PORT_I2S0 : macro to specify i2s id connecting to smartpa aw88166; + */ +#if 0 +#define AUDIO_SMARTPA_AW88262 +#define AUDIO_SMARTPA_AW88262_I2S_ID UAPI_SND_OUT_PORT_I2S2 +#else +#define AUDIO_SMARTPA_AW88166 +#define AUDIO_SMARTPA_AW88166_I2S_ID UAPI_SND_OUT_PORT_I2S0 +#endif +#endif /* DSP_EXIST */ +#include "panic.h" +#include "board_init.h" +#include "kernel_init.h" +#ifdef SUPPORT_AT_OHOSFWK +#include "ohosfwk_startup.h" +#endif +#include "clocks_config.h" +#include "board_init.h" +#include "upg.h" +#include "upg_definitions.h" +#include "nv.h" +#include "nv_upg.h" + +#define EMMC_BASE_ADDR 0x52062000 +#define TASK_PRIORITY_APP (osPriority_t)(17) +#define TICK_TEN_MS (10U) +#define WAIT_BT_BOOTUP_TIME 200U +#define UPG_HEAD_MAGIC 0x55AA55AA +#define UPG_END_MAGIC 0xAA55AA55 +#define UPG_FLAG_MAGIC 0xFFFFFFFF + +static void thread_main(const void *unused); +void bt_acore_btc_ipc_receive_init(void); + +app_task_definition_t g_thread_pri = { { "thread_pri", 0, NULL, 0, NULL, (0x1000), TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)thread_main, NULL, NULL, USE_DTCM_MEM }; +store_class g_store_init_select = STORE_CLASS_NAND; + +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) +static void sample_gfx_init(void) +{ +#if defined(TPTYPE_TMA525B) + tma525b_host_init_sample(); +#elif defined(TPTYPE_ZTW523) + ztw523_host_init_sample(); +#elif defined(TPTYPE_FT6X46) + ft6x46_host_init_sample(); +#else + ztw523_host_init_sample(); +#endif + uapi_lcd_init(); +#ifdef SUPPORT_GPU_GMMU + drv_gmmu_module_init(); +#endif + uapi_vau_module_init(); + uapi_dpu_module_init(); +#ifdef SUPPORT_GPU_JPEG + uapi_jpeg_module_init(); +#endif +} +#endif + +#ifdef CFG_DRIVERS_MMC +static void emmc_init(void) +{ + /** + * FPGA解复位, 设置CMD_CONFLICT_CHECK + * 之后才能设置管脚 + */ + writew(EMMC_BASE_ADDR + 0x508, 0); + init_emmc_pinmux(); + int ret = emmc_drv_context_init(); + if (ret != ENOERR) { + PRINT("emmc init error:[%d]"NEWLINE, ret); + } + mmc_set_first_init_flag(true); + mmc_set_sleep_init_flag(true); + PRINT("emmc init success\r\n"); + +#if defined(SAVE_EXC_INFO) + if (emmc_exc_info_write() != ERRCODE_SUCC) { + PRINT("emmc_exc_info_write failed"NEWLINE); + } +#endif +} +#endif + +#ifdef CFG_SDIO_EMMC_COEXIST +static void sdio_init(void) +{ + init_sdio_pinmux(); + sdio_drv_context_init(); +} +#endif + +#ifdef CFG_DRIVERS_NANDFLASH +static void nandflash_init(void) +{ + int32_t ret = 0; + ret = nandflash_filesystem_init(); + if (ret != 0) { + PRINT("nandflash init error[%d]"NEWLINE, ret); + } + PRINT("nandflash init success\r\n"); +} +#endif + +static void board_version_class_print(void) +{ + PRINT("**********startup info**********\r\n"); + PRINT("os init class is %s."NEWLINE, (g_os_init_select == OS_CLASS_LITEOS) ? "liteos" : "freertos"); + PRINT("store init class is %s."NEWLINE, (g_store_init_select == STORE_CLASS_NAND) ? "nandflash" : "emmc"); + PRINT("display init class is %s."NEWLINE, (g_display_init_select == DISPLAY_CLASS_QSPI) ? "QSPI" : "MIPI"); + PRINT("board init class is %s."NEWLINE, (g_board_init_select == BOARD_CLASS_E0B2) ? "E0B2" : "E0B4"); +#ifdef CONFIG_PSRAM_SUPPORT + PRINT("psram density is %s."NEWLINE, (get_psram_density() == PSRAM_DENSITY_16M) ? "16MB" : "32MB"); +#endif + PRINT("**********startup info**********\r\n"); +} + +#if DSP_EXIST == YES +/** + * The sample code of the vendor, + * which will be implemented by the customer in the future + */ +#ifdef AUDIO_SMARTPA_AW88262 +td_s32 audio_aw88262_init(const uapi_vendor_codec_attr *attr); +td_s32 audio_aw88262_deinit(td_void); + +static uapi_vendor_driver g_aw88262_driver = { + .out_port = AUDIO_SMARTPA_AW88262_I2S_ID, + .init = audio_aw88262_init, + .deinit = audio_aw88262_deinit, + .set_aef_profile = TD_NULL, +}; + +static td_s32 audio_aw88262_register_driver(void) +{ + return uapi_audio_vendor_register(&g_aw88262_driver); +} +#endif /* AUDIO_SMARTPA_AW88262 */ + +#ifdef AUDIO_SMARTPA_AW88166 +td_s32 audio_aw88166_init(const uapi_vendor_codec_attr *attr); +td_s32 audio_aw88166_deinit(td_void); /* Call when device power off */ +td_s32 audio_aw88166_start(const uapi_vendor_codec_attr *attr); +td_s32 audio_aw88166_stop(td_void); +td_s32 audio_aw88166_set_aef_profile(uapi_snd_aef_profile aef_profile); + +static uapi_vendor_driver g_aw88166_driver = { + .out_port = AUDIO_SMARTPA_AW88166_I2S_ID, + .init = audio_aw88166_start, + .deinit = audio_aw88166_stop, + .set_aef_profile = audio_aw88166_set_aef_profile, +}; + +static td_s32 audio_aw88166_register_driver(void) +{ + const uapi_vendor_codec_attr attr = {}; + + audio_aw88166_init(&attr); /* Init aw88166 once when device power on */ + + return uapi_audio_vendor_register(&g_aw88166_driver); +} +#endif /* AUDIO_SMARTPA_AW88166 */ + +static void audio_smartpa_init(void) +{ + uint32_t ret; + +#ifdef AUDIO_SMARTPA_AW88262 + ret = (uint32_t)audio_aw88262_register_driver(); + if (ret != 0) { + PRINT("aw88262 register driver error\r\n"); + } +#endif /* AUDIO_SMARTPA_AW88262 */ + +#ifdef AUDIO_SMARTPA_AW88166 + ret = (uint32_t)audio_aw88166_register_driver(); + if (ret != 0) { + PRINT("aw88166 register driver error\r\n"); + } +#endif /* AUDIO_SMARTPA_AW88166 */ +} +#endif /* DSP_EXIST */ + +#if DSP_EXIST == YES +static void audio_init() +{ + (void)osDelay(TICK_TEN_MS); + uapi_watchdog_kick(); + + audio_smartpa_init(); + + uint32_t ret = (uint32_t)uapi_audio_init(); + if (ret != 0) { + PRINT("audio init error:[%d]\r\n", ret); + } else { + PRINT("audio init OK\r\n"); + } +} +#endif + +void rc_calibration_func_notify(void) +{ +#ifdef SUPPORT_RC_CALIBRATION + /* BT核用来通知MCU 32K校准值 */ + writew(GLB_CTL_D_RB_BASE + GLB_GP_D_REG3, 0x0); + /* 通知BTæ ¸ 32K时钟来源 */ + writew(GLB_CTL_D_RB_BASE + GLB_GP_D_REG2, CLOCK_SOURCE_RC); +#else + writew(GLB_CTL_D_RB_BASE + GLB_GP_D_REG2, CLOCK_SOURCE_XO); +#endif +} + +static void force_to_sleep(void) +{ + if (reg16_getbits(0x5702C010, 0x8, 0x8) == 0x5A) { // 特殊模式下,强制进入深睡中 + reg16_clrbits(0x5702C010, 0x8, 0x8); + uapi_tcxo_delay_ms(WAIT_BT_BOOTUP_TIME); + hal_pmu_cldo_enable_slp_bypass(HAL_PMU_CLDO1, TURN_OFF); + uapi_sys_force_mcu_only_deep_sleep_mode(0); + } +} + +#ifdef CONFIG_OTA_UPDATE_SUPPORT +static void upg_check_upgrade(void) +{ + uint32_t fota_address = 0; + errcode_t ret_val = (errcode_t)upg_get_upgrade_flag_flash_start_addr(&fota_address); + if (ret_val != ERRCODE_SUCC) { + return; + } + + fota_upgrade_flag_area_t upg_flag_info; + ret_val = (errcode_t)upg_flash_read(fota_address, sizeof(fota_upgrade_flag_area_t), (uint8_t *)(&upg_flag_info)); + if (ret_val != ERRCODE_SUCC) { + return; + } + + if (!(upg_flag_info.head_magic == UPG_HEAD_MAGIC && + upg_flag_info.head_end_magic == UPG_END_MAGIC && + upg_flag_info.complete_flag == UPG_FLAG_MAGIC)) { + /* 不需要升级直接返回 */ + PRINT("No need to upgrade...\r\n"); + return; + } + + PRINT("upgrading.......\r\n"); + ret_val = uapi_upg_start(); + if (ret_val != ERRCODE_SUCC) { + PRINT("upgrade failed, ret = 0x%x\r\n", ret_val); + } else { + PRINT("upgrade success\r\n"); + } + upg_reboot(); +} +#endif + +static void thread_main(const void *unused) +{ + PRINT("thread_main start "NEWLINE); + unused(unused); + rc_calibration_func_notify(); + bt_acore_btc_ipc_receive_init(); + uapi_pm_control(PM_BT_POWER_UP_AND_RUN); +#ifdef FORCE_TO_DEEP_SLEEP + force_to_sleep(); +#endif + los_vfs_init(); + uint32_t ret = dpal_driver_base_init(); + if (ret != 0) { + PRINT("dpal driver base init error"NEWLINE); + panic(PANIC_ASSERT, __LINE__); + } +#ifdef CFG_DRIVERS_MMC + emmc_init(); + g_store_init_select = STORE_CLASS_EMMC; + sdiom_internal_freq_handler_register(mmc_set_internal_clk); +#endif +#ifdef CFG_SDIO_EMMC_COEXIST + sdio_init(); +#endif +#ifdef CFG_DRIVERS_NANDFLASH + yaffs_nand_drv_checkptset(YAFFS_CHECKPT_SKIPED); + nandflash_init(); + g_store_init_select = STORE_CLASS_NAND; +#endif + + reboot_cause_t cause = get_cpu_utils_reset_cause(); + if ((cause != REBOOT_CAUSE_APPLICATION_STD_CHIP_WDT_FRST) && + (cause != REBOOT_CAUSE_APPLICATION_XIP_CTRL) && + (cause != REBOOT_CAUSE_APPLICATION_XIP_CACHE)) { + cpu_trace_enable_mcpu_repeat(); + } else { + PRINT("nmi reboot cause: 0x%x, reason: 0x%x"NEWLINE, cause, get_fault_reason()); + // save cputrace memory if chip watchdog reset + hal_cpu_trace_clock_enable(); + panic(PANIC_ASSERT, cause); + } + + uapi_pm_control(PM_DISPLAY_POWER_UP_AND_RUN); + (void)osDelay(TICK_TEN_MS); + +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) + sample_gfx_init(); +#else + uapi_pm_control(PM_DISPLAY_POWER_OFF); +#endif + +#if DSP_EXIST == YES + audio_init(); +#endif + board_version_class_print(); + uapi_watchdog_kick(); +#ifdef CONFIG_OTA_UPDATE_SUPPORT + upg_check_upgrade(); +#endif + /* nv init and file system init must be before nv_upg_upgrade_task_process */ + (void)nv_upg_upgrade_task_process(); + thread_init(); + button_app_init(); + uapi_calendar_init(); + +#ifdef SUPPORT_BATTERY_SERVICE + uapi_battery_init(); +#endif + +#ifdef SUPPORT_CAT1_SERVICE + cat1_server_init(); +#endif + +#ifdef SUPPORT_AT_OHOSFWK + ohos_startup(); +#endif +#ifdef CONFIG_SYSTEM_VIEW + SEGGER_SYSVIEW_Conf(); + // 请在抓取systemview开始的地方调用SEGGER_SYSVIEW_Start接口 +#endif + uapi_pm_remove_sleep_veto(PM_ID_DEBUG); + set_startup_finish_flag(); +} + +void thread_pri_init(void) +{ + /* Create tasks */ + g_thread_pri.task_handle = osThreadNew(g_thread_pri.func, NULL, &(g_thread_pri.attr)); + if (g_thread_pri.task_handle == NULL) { + PRINT("create thread pri failed!"); + } +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp new file mode 100644 index 000000000..4bb5fe565 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -0,0 +1,442 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainClockView + * Author: + * Create: 2021-08-14 + */ + +#include "MainClockView.h" +#include "MainPresenterSample.h" +#include "components/ui_label.h" +#include "wearable_log.h" +#include "ui_resource_image.h" +#include "common/image_cache_manager.h" +#include +#include "battery_hal.h" +namespace OHOS { +static MainClockView *g_pMainClockView = nullptr; + +static constexpr uint16_t FONT_DEFAULT_SIZE = 25; +static constexpr uint16_t FONT_TEXT_SIZE = 24; +static constexpr uint16_t STEP_LABEL_X = 100; +static constexpr uint16_t STEP_LABEL_Y = 230; +static constexpr uint16_t BATTERYP_LABEL_X = 315; +static constexpr uint16_t BATTERYP_LABEL_Y = 230; +static constexpr uint16_t TEXT_WIDTH = 60; +static constexpr uint16_t TEXT_HEIGHT = 35; +static constexpr uint16_t POINT_POSITION_X = 202; +static constexpr uint16_t POINT_POSITION_Y = 16; +static constexpr uint16_t SECOND_POINT_POSITION_Y = 16; +static constexpr uint16_t POINT_CENTER_X = 25; +static constexpr uint16_t POINT_CENTER_Y = 211; +static constexpr uint16_t STEP_CHAR_NUM = 255; +static constexpr int16_t STEP_LABLE_WIDTH = 75; +static constexpr int16_t STEP_LABLE_SIZE = 35; +static constexpr uint16_t WEEKLABEL_POSITION_X = 247; +static constexpr uint16_t WEEKLABEL_POSITION_Y = 122; +static constexpr uint16_t HEARTRATELABEL_POSITION_X = 198; +static constexpr uint16_t HEARTRATELABEL_POSITION_Y = 330; +static constexpr uint16_t HEARTRATE_POSITION_X = 156; +static constexpr uint16_t HEARTRATE_POSITION_Y = 260; +static constexpr uint16_t PROGRESS_POSITION_X = 53; +static constexpr uint16_t PROGRESS_POSITION_Y = 54; +static constexpr uint16_t BIGCIRCLE_POSITION_X = 202; +static constexpr uint16_t BIGCIRCLE_POSITION_Y = 202; +static constexpr uint16_t MEDCIRCLE_POSITION_X = 202; +static constexpr uint16_t MEDCIRCLE_POSITION_Y = 202; +static constexpr uint16_t SMALLCIRCLE_POSITION_X = 202; +static constexpr uint16_t SMALLCIRCLE_POSITION_Y = 202; +static constexpr uint16_t WEEKDAY_POSITION_X = 193; +static constexpr uint16_t WEEKDAY_POSITION_Y = 127; +static constexpr int16_t SEC_TO_MILLI = 1000; +static constexpr int16_t USEC_TO_MILLI = 1000; +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr int16_t HOURLY_SYSTEM = 24; +static constexpr int16_t INTERVAL = 30; + +MainClockView::MainClockView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::MainClockView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pMainClockView = this; +} + +MainClockView::~MainClockView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::~MainClockView"); + if (viewiInitStatus) { + mainSweepClock->RemoveAll(); + delete curFace; + curFace = nullptr; + delete stepLabel; + stepLabel = nullptr; + delete batteryLabel; + batteryLabel = nullptr; + delete secondHand; + secondHand = nullptr; + delete minuteHand; + minuteHand = nullptr; + delete hourHand; + hourHand = nullptr; + delete weekLabel; + weekLabel = nullptr; + delete heartRateLabel; + heartRateLabel = nullptr; + delete heartRate; + heartRate = nullptr; + delete hand24Hour; + hand24Hour = nullptr; + delete weekDay; + weekDay = nullptr; + delete progress; + progress = nullptr; + delete bigCircle; + bigCircle = nullptr; + delete medCircle; + medCircle = nullptr; + delete smallCircle; + smallCircle = nullptr; + Remove(mainSweepClock); + delete mainSweepClock; + mainSweepClock = nullptr; + g_pMainClockView = nullptr; + } +} + +MainClockView *MainClockView::GetInstance(void) +{ + return g_pMainClockView; +} + +void MainClockView::InitStepValue() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue"); + uint32_t stepValue; + int weekToday = ActivityModel::GetInstance()->GetWeekToday(); + ActivityModel::GetInstance()->GetStepData((StepDataDistribute)weekToday, &stepValue); + char stepChar[STEP_CHAR_NUM] = {0}; + if (sprintf_s(stepChar, STEP_CHAR_NUM, "%d", stepValue) == -1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue error"); + return; + } + if (stepLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue nullptr"); + return; + } + stepLabel->SetText(stepChar); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); +} + +bool MainClockView::InitLabelView(void) +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + stepLabel = new UILabelButton(); + if (stepLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stepLabel new fail"); + return false; + } + stepLabel->SetPosition(STEP_LABEL_X, STEP_LABEL_Y); + stepLabel->Resize(STEP_LABLE_WIDTH, STEP_LABLE_SIZE); + stepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + stepLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + stepLabel->SetViewId(MAIN_CLICK_ACTIVITY); + stepLabel->SetTouchable(true); + stepLabel->SetOnClickListener(clickListener); + InitStepValue(); + + batteryLabel = new UILabel(); + if (batteryLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail"); + return false; + } + batteryLabel->SetPosition(BATTERYP_LABEL_X, BATTERYP_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + float voltage = 0.0F; + int power = battery_get_voltage(&voltage); + char tmp[16]={0}; + sprintf(tmp,"%d%c",power,'%'); + batteryLabel->SetText(tmp); + batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + + heartRateLabel = new UILabel(); + if (heartRateLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateLabel new fail"); + return false; + } + heartRateLabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); + heartRateLabel->SetText("--"); + heartRateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + heartRateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + heartRateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + + weekLabel = new UILabel(); + if (weekLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekLabel new fail"); + return false; + } + weekLabel->SetPosition(WEEKLABEL_POSITION_X, WEEKLABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); + weekLabel->SetText("2"); + weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); + weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + return true; +} + +bool MainClockView::InitCenterCircleView(void) +{ + bigCircle = new Image(); + if (bigCircle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bigCircle new fail"); + return false; + } + if (!LoadClockImage(bigCircle, CLOCK_BIGCIRCLE_IMAGE_PATH)) { + return false; + } + + medCircle = new Image(); + if (medCircle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "medCircle new fail"); + return false; + } + if (!LoadClockImage(medCircle, CLOCK_MEDCIRCLE_IMAGE_PATH)) { + return false; + } + + smallCircle = new Image(); + if (smallCircle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "smallCircle new fail"); + return false; + } + if (!LoadClockImage(smallCircle, CLOCK_CIRCLE_IMAGE_PATH)) { + return false; + } + return true; +} + +bool MainClockView::InitHandView(void) +{ + secondHand = new Image(); + if (secondHand == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); + return false; + } + if (!LoadClockImage(secondHand, CLOCK_SECONDHAND)) { + return false; + } + + minuteHand = new Image(); + if (minuteHand == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "minuteHand new fail"); + return false; + } + if (!LoadClockImage(minuteHand, CLOCK_MINUTEHAND)) { + return false; + } + hourHand = new Image(); + if (hourHand == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hourHand new fail"); + return false; + } + if (!LoadClockImage(hourHand, CLOCK_HOURHAND)) { + return false; + } + + hand24Hour = new Image(); + if (hand24Hour == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hand24Hour new fail"); + return false; + } + if (!LoadClockImage(hand24Hour, CLOCK_HAND24HOUR_IMAGE_PATH)) { + return false; + } + return true; +} + +bool MainClockView::LoadClockImage(Image *view, uint32_t resId) +{ + std::string file = CLOCK_IAMGES; + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; +} + +bool MainClockView::LoadClockImage(UIImageView *view, uint32_t resId) +{ + std::string file = CLOCK_IAMGES; + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; +} + +bool MainClockView::InitSweepClock(void) +{ + curFace = new UIImageView(); + if (curFace == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail"); + return false; + } + curFace->SetPosition(0, 0); + + if (!LoadClockImage(curFace, CLOCK_MAIN_FACE_IMAGE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace LoadClockImage CLOCK_MAIN_FACE_IMAGE fail"); + return false; + } + + if (!InitLabelView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelView() fail"); + return false; + } + if (!InitCenterCircleView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitCenterCircleView() fail"); + return false; + } + heartRate = new UIImageView(); + if (heartRate == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRate new fail"); + return false; + } + heartRate->SetPosition(HEARTRATE_POSITION_X, HEARTRATE_POSITION_Y); + if (!LoadClockImage(heartRate, CLOCK_HEARTRATE_IMAGE_PATH)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRate LoadClockImage CLOCK_HEARTRATE_IMAGE_PATH fail"); + return false; + } + + progress = new UIImageView(); + if (progress == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress new fail"); + return false; + } + progress->SetPosition(PROGRESS_POSITION_X, PROGRESS_POSITION_Y); + if (!LoadClockImage(progress, CLOCK_PROGRESS_IMAGE_PATH)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress LoadClockImage CLOCK_PROGRESS_IMAGE_PATH fail"); + return false; + } + + InitHandView(); + weekDay = new UIImageView(); + if (weekDay == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekDay new fail"); + return false; + } + weekDay->SetPosition(WEEKDAY_POSITION_X, WEEKDAY_POSITION_Y); + if (!LoadClockImage(weekDay, CLOCK_THURSDAY_IMAGE_PATH)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekDay LoadClockImage CLOCK_THURSDAY_IMAGE_PATH fail"); + return false; + } + return true; +} + +void MainClockView::PreLoad(void) +{ + if (!viewiInitStatus) { + InitView(); + viewiInitStatus = true; + } +} + +void MainClockView::UnLoad(void) +{ + // Main clock view is commonly used page, so we do not release it's resources inner slice. +} + +bool MainClockView::InitView(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView"); + + mainSweepClock = new UISweepClock(); + if (mainSweepClock == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); + return false; + } + if (!InitSweepClock()) { + return false; + } + + mainSweepClock->Add(curFace); + mainSweepClock->Add(stepLabel); + mainSweepClock->Add(heartRate); + mainSweepClock->Add(weekLabel); + mainSweepClock->Add(heartRateLabel); + mainSweepClock->Add(weekDay); + mainSweepClock->Add(progress); + mainSweepClock->Add(batteryLabel); + Add(mainSweepClock); + + mainSweepClock->SetDragParentInstead(true); + mainSweepClock->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + // {214, 3}: position x, y {14, 223}: center x, y + mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand, + { POINT_POSITION_X, SECOND_POINT_POSITION_Y }, { POINT_CENTER_X, POINT_CENTER_Y }); + mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand, + { POINT_POSITION_X, POINT_POSITION_Y }, { POINT_CENTER_X, POINT_CENTER_Y }); + mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand, { POINT_POSITION_X, POINT_POSITION_Y }, + { POINT_CENTER_X, POINT_CENTER_Y }); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::SECOND_HAND, *smallCircle, + { SMALLCIRCLE_POSITION_X, SMALLCIRCLE_POSITION_Y }); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::MINUTE_HAND, *medCircle, + { MEDCIRCLE_POSITION_X, MEDCIRCLE_POSITION_Y }); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::HOUR_HAND, *bigCircle, + { BIGCIRCLE_POSITION_X, BIGCIRCLE_POSITION_Y }); + + mainSweepClock->SetInitTime24Hour(0, 0, 0); + mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL); + InitDateTime(); + SetCoverable(true); + return true; +} + +void MainClockView::RefreshStep(int step) +{ + char stepChar[STEP_CHAR_NUM] = {0}; + + (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step); + stepLabel->SetText(stepChar); +} + +void MainClockView::RefreshHeartRate(int value) +{ + if (value == 0) { + heartRateLabel->SetText("--"); + return; + } + char heartRateChar[STEP_CHAR_NUM] = {0}; + + (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value); + heartRateLabel->SetText(heartRateChar); +} + +void MainClockView::InitDateTime(void) +{ + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + mainSweepClock->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec); +} + +void MainClockView::UpdateTime(void) +{ + struct timeval tv; + gettimeofday(&tv, nullptr); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / MIN_TO_HOUR; + uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR); + uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * + SEC_TO_MILLI + uSecond / USEC_TO_MILLI); + mainSweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1); +} +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp new file mode 100644 index 000000000..d50c4e1b5 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -0,0 +1,335 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: WeekStep + * Author: + * Create: 2021-09-11 + */ + +#include "PullUpDownView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/screen.h" +#include "MainPresenterSample.h" +#include "ScreenModels.h" +#include "SettingModel.h" +#include "ui_resource_image.h" +#include "battery_hal.h" + +namespace OHOS { + +static PullUpDownView *g_pPullUpDownView = nullptr; + +constexpr int16_t DISTURB_IMG_X = 117; +constexpr int16_t DISTURB_IMG_Y = 50; +constexpr int16_t SCREEN_IMG_X = 251; +constexpr int16_t SCREEN_IMG_Y = 50; +constexpr int16_t PHONE_IMG_X = 49; +constexpr int16_t PHONE_IMG_Y = 184; +constexpr int16_t ALARM_IMG_X = 184; +constexpr int16_t ALARM_IMG_Y = 184; +constexpr int16_t SETTING_IMG_X = 319; +constexpr int16_t SETTING_IMG_Y = 184; + +constexpr int16_t BLUETOOTH_IMG_X = 145; +constexpr int16_t BLUETOOTH_IMG_Y = 335; +constexpr int16_t BATTERY_IMG_X = 195; +constexpr int16_t BATTERY_IMG_Y = 340; + +constexpr int16_t DISTURB_LABEL_X = 136; +constexpr int16_t DISTURB_LABEL_Y = 145; +constexpr int16_t SCREEN_LABEL_X = 270; +constexpr int16_t SCREEN_LABEL_Y = 145; +constexpr int16_t PHONE_LABEL_X = 68; +constexpr int16_t PHONE_LABEL_Y = 279; +constexpr int16_t ALARM_LABEL_X = 203; +constexpr int16_t ALARM_LABEL_Y = 279; +constexpr int16_t SETTING_LABEL_X = 338; +constexpr int16_t SETTING_LABEL_Y = 279; + +constexpr int16_t BATTERY_LABEL_X = 247; +constexpr int16_t BATTERY_LABEL_Y = 335; +constexpr int16_t DATE_LABEL_X = 173; +constexpr int16_t DATE_LABEL_Y = 374; + +constexpr int16_t FONT_DEFAULT_SIZE = 24; +constexpr int16_t TEXT_WIDTH = 86; +constexpr int16_t TEXT_HEIGHT = 30; + +constexpr int16_t NONOTICE_LABLE_X = 141; +constexpr int16_t NONOTICE_LABLE_Y = 212; + +PullUpDownView::PullUpDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::PullUpDownView"); + g_pPullUpDownView = this; +} + +PullUpDownView::~PullUpDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::~PullUpDownView"); + RemoveAll(); + delete dnotDisturb; + dnotDisturb = nullptr; + delete briScreen; + briScreen = nullptr; + delete finPhone; + finPhone = nullptr; + delete droAlarm; + droAlarm = nullptr; + delete droSetting; + droSetting = nullptr; + delete dnotDisturbLable; + dnotDisturbLable = nullptr; + delete briScreenLable; + briScreenLable = nullptr; + delete finPhoneLable; + finPhoneLable = nullptr; + delete droAlarmLable; + droAlarmLable = nullptr; + delete droSettingLable; + droSettingLable = nullptr; + delete bluetooth; + bluetooth = nullptr; + delete battery; + battery = nullptr; + delete batteryLable; + batteryLable = nullptr; + delete dateLable; + dateLable = nullptr; + g_pPullUpDownView = nullptr; +} + +PullUpDownView *PullUpDownView::GetInstance(void) +{ + return g_pPullUpDownView; +} + +void PullUpDownView::InitSubViewImg(void) +{ + if (HealthModel::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); + return; + } + + dnotDisturb = new UIImageView(); + if (dnotDisturb == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturb new fail"); + return; + } + dnotDisturb->SetPosition(DISTURB_IMG_X, DISTURB_IMG_Y); + if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB_B); + } + dnotDisturb->SetViewId(DROPDOWN_CLICK_DONOTDISTURB); + dnotDisturb->SetTouchable(true); + dnotDisturb->SetOnClickListener(clickListener); // 进入勿扰模式 + + briScreen = new UIImageView(); + if (briScreen == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreen new fail"); + return; + } + briScreen->SetPosition(SCREEN_IMG_X, SCREEN_IMG_Y); + if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN_B); + } + briScreen->SetViewId(DROPDOWN_CLICK_BRIGHTENSCREEN); + briScreen->SetTouchable(true); + briScreen->SetOnClickListener(clickListener); // 进入亮屏模式 +} + +void PullUpDownView::InitViewImg(void) +{ + InitSubViewImg(); + + finPhone = new UIImageView(); + if (finPhone == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhone new fail"); + return; + } + finPhone->SetPosition(PHONE_IMG_X, PHONE_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, finPhone, DROPDOWN_DROPDOWN_FIND_PHONE); + finPhone->SetViewId(DROPDOWN_CLICK_FINDMYPHONE); // 找手机界面 DROP_DOWN_FIND_PHONE + finPhone->SetTouchable(true); + finPhone->SetOnClickListener(clickListener); + + droAlarm = new UIImageView(); + if (droAlarm == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droAlarm new fail"); + return; + } + droAlarm->SetPosition(ALARM_IMG_X, ALARM_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droAlarm, DROPDOWN_DROPDOWN_ALARM); + droAlarm->SetViewId(DROPDOWN_CLICK_ALARM); // 进入闹钟App DROP_DOWN_ALARM + droAlarm->SetTouchable(true); + droAlarm->SetOnClickListener(clickListener); + + droSetting = new UIImageView(); + if (droSetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSetting new fail"); + return; + } + droSetting->SetPosition(SETTING_IMG_X, SETTING_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droSetting, DROPDOWN_DROPDOWN_SETTING); + droSetting->SetViewId(DROPDOWN_CLICK_SETTING); // 进入设置界面 DROP_DOWN_SETTING + droSetting->SetTouchable(true); + droSetting->SetOnClickListener(clickListener); +} + +void PullUpDownView::InitViewLable(void) +{ + dnotDisturbLable = new UILabel(); + if (dnotDisturbLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturbLable new fail"); + return; + } + dnotDisturbLable->SetPosition(DISTURB_LABEL_X, DISTURB_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + dnotDisturbLable->SetText("勿扰"); + dnotDisturbLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + dnotDisturbLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + briScreenLable = new UILabel(); + if (briScreenLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreenLable new fail"); + return; + } + briScreenLable->SetPosition(SCREEN_LABEL_X, SCREEN_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + briScreenLable->SetText("亮屏"); + briScreenLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + briScreenLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + finPhoneLable = new UILabel(); + if (finPhoneLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); + return; + } + finPhoneLable->SetPosition(PHONE_LABEL_X, PHONE_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + finPhoneLable->SetText("找手机"); + finPhoneLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + finPhoneLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + droAlarmLable = new UILabel(); + if (finPhoneLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); + return; + } + droAlarmLable->SetPosition(ALARM_LABEL_X, ALARM_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + droAlarmLable->SetText("闹钟"); + droAlarmLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + droAlarmLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + droSettingLable = new UILabel(); + if (droSettingLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSettingLable new fail"); + return; + } + droSettingLable->SetPosition(SETTING_LABEL_X, SETTING_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + droSettingLable->SetText("设置"); + droSettingLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + droSettingLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); +} + +void PullUpDownView::InitViewInfo(void) +{ + bluetooth = new UIImageView(); // 蓝牙状态显示 + if (bluetooth == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth new fail"); + return; + } + bluetooth->SetPosition(BLUETOOTH_IMG_X, BLUETOOTH_IMG_Y); + if (BluetoothModel::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth model nullptr"); + return; + } + + if (SettingModel::GetInstance().GetBlueToothConnectStatus()) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); + } + + battery = new UIImageView(); // 电量状态显示 + if (battery == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery new fail"); + return; + } + battery->SetPosition(BATTERY_IMG_X, BATTERY_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, battery, DROPDOWN_DROPDOWN_BATTERY); + batteryLable = new UILabel(); + if (batteryLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLable new fail"); + return; + } + batteryLable->SetPosition(BATTERY_LABEL_X, BATTERY_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + float voltage = 0.0F; + int power = battery_get_voltage(&voltage); + char tmp[16]={0}; + sprintf(tmp,"%d%c",power,'%'); + batteryLable->SetText(tmp); + batteryLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + batteryLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + dateLable = new UILabel(); + if (dateLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dateLable new fail"); + return; + } + dateLable->SetPosition(DATE_LABEL_X, DATE_LABEL_Y, 192, TEXT_HEIGHT); // TEXT_WIDTH = 192 + dateLable->SetText("10/23 星期五"); + dateLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + dateLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); +} + +bool PullUpDownView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView"); + clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + + InitViewImg(); + InitViewLable(); + InitViewInfo(); + + Add(dnotDisturb); + Add(dnotDisturbLable); + Add(briScreen); + Add(briScreenLable); + Add(finPhone); + Add(finPhoneLable); + Add(droAlarm); + Add(droAlarmLable); + Add(droSetting); + Add(droSettingLable); + Add(bluetooth); + Add(battery); + Add(batteryLable); + Add(dateLable); + + SetTouchable(true); + SetIntercept(true); + + return true; +} + +void PullUpDownView::PreLoad(void) +{ + if (!viewiInitStatus) { + InitView(); + viewiInitStatus = true; + } +} + +void PullUpDownView::UpdateBlueToothStatus(int status) +{ + if (bluetooth == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth nullptr"); + return; + } + if (status == 1) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); + } + bluetooth->Invalidate(); + return; +} + +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp new file mode 100644 index 000000000..f26446d2c --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023. All rights reserved. + * Description: DialModelPower + * Author: + * Create: 2023-12 + */ + +#include "RegisterDialModel.h" +#include "DialModelPower.h" +#include "battery_hal.h" + +REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_POWER, OHOS::DialModelPower::GetInstance()); + +namespace OHOS { +bool DialModelPower::GetDialFloatData(DialDataType& type, float& out) +{ + (void)type; + // out = power_; + + float voltage = 0.0F; + power_ = battery_get_voltage(&voltage); + out = static_cast(power_); + return true; +} +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp new file mode 100644 index 000000000..35ba07c27 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Reboot Presenter + * Create: 2022-04-28 + */ + +#include "RebootPresenter.h" +#include "RebootView.h" +#include "RebootModel.h" +#include "drag_event.h" +#include "wearable_log.h" + +namespace OHOS { +static RebootPresenter *g_pRebootPresenter = nullptr; + +RebootPresenter::RebootPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::RebootPresenter"); + g_pRebootPresenter = this; +} + +RebootPresenter::~RebootPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::~RebootPresenter"); + g_pRebootPresenter = nullptr; +} + +RebootPresenter *RebootPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter GetInstance"); + return g_pRebootPresenter; +} + +void RebootPresenter::OnStart() +{ + Presenter::OnStart(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::On Start "); +} + +void RebootPresenter::OnPause(void) {} + +void RebootPresenter::OnResume(void) {} + +void RebootPresenter::OnStop(void) {} + + +extern "C" +{ +extern void uapi_sys_shipmode(uint32_t arg); +extern uint32_t mcu_os_sys_reset(uint8_t *para, uint32_t para_len); +} +bool RebootPresenter::OnClick(UIView& view, const ClickEvent& event) +{ + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick OnClick"); + if (strcmp(view.GetViewId(), REBOOT_BUTTON) == 0) { + RebootView::GetInstance()->ChangeView(REBOOTVIEW, REBOOTDEVICEVIEW); + } else if (strcmp(view.GetViewId(), SHUTDOWN_BUTTON) == 0) { + RebootView::GetInstance()->ChangeView(REBOOTVIEW, SHUTDOWNDEVICEVIEW); + } else if (strcmp(view.GetViewId(), REBOOTDEVICE_BUTTON) == 0) { + // 重启 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "REBOOTDEVICE_BUTTON OnClick"); + mcu_os_sys_reset(NULL,NULL); + } else if (strcmp(view.GetViewId(), SHUTDOWNDEVICE_BUTTON) == 0) { + // 关机 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SHUTDOWNDEVICE_BUTTON OnClick"); + uapi_sys_shipmode(0); + } + return true; +} + +bool RebootPresenter::OnDrag(UIView& view, const DragEvent& event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::OnDrag"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + if (strcmp(view.GetViewId(), REBOOT_VIEW) == 0) { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } else if (strcmp(view.GetViewId(), REBOOTDEVICE_VIEW) == 0) { + if (RebootModel::GetInstance()->GetExitsView() == 0) { + RebootView::GetInstance()->ChangeView(REBOOTDEVICEVIEW, REBOOTVIEW); + } else { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + RebootModel::GetInstance()->SetExitsView(false); + } + } else if (strcmp(view.GetViewId(), SHUTDOWNDEVICE_VIEW) == 0) { + if (RebootModel::GetInstance()->GetExitsView() == 0) { + RebootView::GetInstance()->ChangeView(SHUTDOWNDEVICEVIEW, REBOOTVIEW); + } else { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + RebootModel::GetInstance()->SetExitsView(false); + } + } + } + return true; +} +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/application/wstp/at_service/app/app_at_process.c b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wstp/at_service/app/app_at_process.c new file mode 100644 index 000000000..6cea89186 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/application/wstp/at_service/app/app_at_process.c @@ -0,0 +1,2787 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Media task process + * Author: + * Create: + */ +#if defined(__LITEOS__) +#include "los_memory.h" +#include "los_memory_pri.h" +#ifdef CFG_DRIVERS_MMC +#include "soc/mmc.h" +#endif +#endif + +#ifdef CFG_DRIVERS_MMC +#include "hci.h" +#include "soc_mmc.h" +#endif + +#if defined(__FREERTOS__) +#ifdef FREERTOS_DEBUG +#include "xlt_memory_pri.h" +#include "task_debug.h" +#endif +#endif + +#include "debug_print.h" +#include "td_base.h" +#include "securec.h" +#include "log_file.h" +#include "dfx_adapt_layer.h" +#include "dirent.h" +#include "uart.h" +#include "uapi_crc.h" +#include "tcxo.h" +#include "cmsis_os2.h" +#include "lcd_bus.h" +#include "soc_vau_type.h" +#include "soc_dpu_type.h" +#include "soc_mipi_tx.h" +#include "touch_screen_def.h" +#include "nandflash.h" +#include "efuse.h" +#include "psram_drv.h" +#include "flash.h" +#include "adc.h" +#include "exception.h" +#include "fcntl.h" +#include +#include "common_def.h" +#include "unistd.h" +#include "watchdog.h" +#include "button_porting.h" +#include "hal_reboot.h" +#include "app_msg_manager.h" +#include "sys/statfs.h" +#include "asm/memmap_config.h" +#include "watchdog_porting.h" +#include "thread_init.h" + +#include "pm.h" +#include "pm_veto.h" +#include "pm_lp_stub.h" +#include "pm_definition.h" +#include "build_version.h" +#include "at_cmd_api.h" +#include "app_test_fs.h" +#include "app_common_api.h" +#include "app_tx_process.h" +#include "dfx_feature_config.h" +#include "app_at_process.h" +#include "pm_veto.h" +#include "input_app.h" +#include "lpc_core.h" +#include "diag_msg.h" +#include "pmu_ldo.h" +#include "soc_gmmu_api.h" +#include "pinctrl.h" +#include "non_os_reboot.h" +#include "km.h" +#include "cipher_api.h" +#include "key_deriv_porting.h" +#include "otp_map.h" +#ifdef CFG_DRIVERS_NANDFLASH +#include "nandflash_config.h" +#endif + +#if defined(SW_RTT_DEBUG) +#include "SEGGER_RTT.h" +#endif +#ifdef SUPPORT_POWER_MANAGER +#include "power_display_service.h" +#endif +#include "i2c.h" +#include "calendar.h" + +#ifdef SUPPORT_FILE_SPLIT_COMBINE +#include "msg_center_protocol.h" +#endif + +#ifdef SUPPORT_ALIPAY_SEC +#include "alipay_feature.h" +#endif + +#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) +#define DIAG_RES_LEN 4 +#define FF_VOLUMES_NUM 4 +#define ADC_AUTODATA_PRT_SIZE 4 +#define ADC_AUTODATA_PRT_INDEX1 1 +#define ADC_AUTODATA_PRT_INDEX2 2 +#define ADC_AUTODATA_PRT_INDEX3 3 +#define ADC_AUTODATA_PRT_INDEX4 4 +#define VER_STR_MAX 128 +#define FILE_MAX_NUM 32 +#define MAX_FILE_PATH_LEN 128 +#define TEST_MSG_MAX_SIZE 40 +#define LOG_FILE_ARG_NUM 6 +#define FS_NODE_INFO_SPACE 16 +#define MB_SIZE (1024 * 1024) +#define KB_SIZE (1024) +#define ONE_SECOND (1000000) +#define DTCM_RAM_OFF (400 * 1024) // dtcm偏移,从最后未使用的dtcm作为测试内存 +#define INVALID_HANDLE (0xFFFFFFFF) + +#ifdef CONFIG_PSRAM_SUPPORT +#define LCD_FILL_COLOR_ADDR 0x6D200000 +#else +#define LCD_FILL_COLOR_ADDR 0x60280000 +#endif + +#define POWER_KEY_PARAM_LEN 0x2 +#define CALENDAR_PARAM_LEN 0x6 +#ifdef CFG_DRIVERS_MMC +#define FS_VOLUMES_NUM 4 +#define FS_VOLUME_STRS "/system/", "/user/", "/update/", "/music/" +extern unsigned int mmc_set_clock_with_way2(struct hci_softc *sc, unsigned int cfg_clock); +uint32_t g_app_emmc_clk = SDIOM_SRC_CLK_FREQ_LVL_98M_VAL; +#endif + +#ifdef CFG_DRIVERS_NANDFLASH +#ifndef MEMORY_MINI +#define FS_VOLUMES_NUM 4 +#define FS_VOLUME_STRS "/system/", "/update/", "/music/", "/user/" +#else +#define FS_VOLUMES_NUM 1 +#define FS_VOLUME_STRS "/user/" +#endif +#endif + +#define AT_I2C_PARA_CNT 4 +#define AT_I2C_REG_ARRAY_LEN 8 + +#define AT_PARA_IDX2 2 +#define AT_PARA_IDX3 3 +#define AT_PARA_IDX4 4 +#define AT_PARA_IDX5 5 +#define AT_PARA_IDX6 6 +#define AT_PARA_IDX7 7 +#define AT_PARA_IDX8 8 + +#define OFFSET_8 8 +#define OFFSET_16 16 +#define OFFSET_24 24 + +#define AES_SALT_LENGTH 16 +#define AES_IV_LENGTH 16 +// AES_SAMPLE_TEST_LEN must be an integer multiple of 32 bytes. +#define AES_SAMPLE_TEST_LEN 64 +#define ALIPAY_EXIT_LPM_DELAY_LEN 100 + +#ifdef SUPPORT_FILE_SPLIT_COMBINE +/* 文件拆分合并测试 */ +#define ORIGIN_FILE_PATH "/user/test/ssb.bin" +#define FILE_LIST_PATH "/user/test/flist.txt" +#define COMBINE_FILE_PATH "/user/test/ssb_c.bin" +#endif + +#ifdef SUPPORT_AUTO_OTA +extern uint8_t g_auto_ota_upload_mode; +#ifndef ONE_ADDR_LEN +#define ONE_ADDR_LEN 2 +#endif +#ifndef ADDR_MAC_LEN +#define ADDR_MAC_LEN 6 +#endif +#endif + +const uint8_t g_decrypt_aes_salt[AES_SALT_LENGTH] = { 0x0 }; +const uint8_t g_decrypt_aes_iv[AES_IV_LENGTH] = { 0x0 }; +// The length of the GID must be 32 bytes and cannot be changed. +const uint8_t g_decrypt_aes_gid[OTP_SECURITY_KEY_GID_LEN] = { 0x0 }; +// This is the ASCII code of the string to be encrypted. +const uint8_t g_decrypt_aes_encryp[AES_SAMPLE_TEST_LEN] = {}; +// This is the ASCII code of the string to be decrypted. +const uint8_t g_decrypt_aes_decryp[AES_SAMPLE_TEST_LEN] = {0x15, 0x56, 0xa7, 0x38, 0x7f, 0xd3, 0x69, 0x72, 0x16, + 0x2, 0xda, 0x36, 0xf3, 0x99, 0xcd, 0xf7, 0x49, 0xf4, 0x2d, 0x15, 0x77, 0xd5, 0x4f, 0xdd, 0x14, 0xd1, 0xc3, + 0x7f, 0x41, 0xd6, 0x99, 0x47, 0x2f, 0xb1, 0x34, 0xdf, 0x87, 0xa0, 0x49, 0x53, 0x23, 0x43, 0xf0, 0x96, 0xed, + 0xbf, 0x5, 0x1d, 0x78, 0xc4, 0xa3, 0xfe, 0xf2, 0xa3, 0xb7, 0x8e, 0x29, 0xd9, 0xd0, 0x86, 0xc5, 0x5f, 0xc4, 0x8f}; + +static const char * const g_volume_names[FS_VOLUMES_NUM] = { FS_VOLUME_STRS }; + +#if DSP_L2RAM_AREA_SIZE == 8 +extern void *__l2m_dsp_data_end; +#else +extern void *__l2m_gpu_data_end; +#endif + +diag_ser_header_t g_mcu_diag_header; // 用于保存diag回复包头内容 +bool g_app_diag_flag = false; // 用于控制执行功能后是否回复diag消息 + +pm_id_t g_pm_req_mode_usr = PM_ID_DEBUG; +#ifdef CONFIG_LOW_POWER_TEST +static bool g_dpu_ready_flag = false; +#else +static bool g_dpu_ready_flag = true; +#endif + +void wstp_print(const char *str, ...) +{ + static uint8_t s[256]; // 256 means string max length. + va_list args; + int32_t str_len; + + if ((str == NULL) || (strlen(str) == 0)) { + return; + } + + va_start(args, str); + str_len = vsprintf_s((char *)s, sizeof(s), str, args); + va_end(args); + + if (str_len < 0) { + return; + } +#if defined(SW_RTT_DEBUG) + SEGGER_RTT_Write(0, (const char *)s, str_len); +#else + if (hal_uart_get_funcs(SW_DEBUG_UART_BUS) == NULL) { + return; + } + uapi_uart_write(SW_DEBUG_UART_BUS, (const void *)s, str_len, 0); +#endif +} + +void factory_test_print(const uint8_t return_code, const char *str, ...) +{ + static uint8_t s[256]; // 256 means string max length. + va_list args; + int32_t str_len; + + if ((str == NULL) || (strlen(str) == 0)) { + return; + } + + va_start(args, str); + str_len = vsprintf_s((char *)s, sizeof(s), str, args); + va_end(args); + + if (str_len <= 0) { + return; + } +#ifdef SW_UART_DEBUG + wstp_print("[Factory]|%s.\r\n", s); +#endif +#ifdef FT_BT_UART + at_cmd_send_abt_result_to_bt((const void *)s, str_len); +#endif +#ifdef FT_DONGLE + // 发送spp包 + uint8_t table_len = 2 + str_len; // return_code + str_len + payload + diag_ser_header_t header_temp = { + .ser_id = DIAG_SER_APP_TEST, + .cmd_id = FTDONGLERETURN, + .src = DIAG_FRAME_FID_MCU, // DIAG_FRAME_FID_MCU + .dst = DIAG_FRAME_FID_PHONE, // DIAG_FRAME_FID_PHONE + .crc_en = true, + .ack_en = false, + .length = 2 + table_len, // moduld + cmd + table_len + }; + factory_print_table *ft_table = (factory_print_table*)malloc(sizeof(factory_print_table)); + if (ft_table == NULL) { + return; + } + ft_table->return_code = return_code; + ft_table->payload_len = str_len; + if (memcpy_s(ft_table->payload, FT_PAYLOAD_LEN_MAX, s, str_len) != EOK) { + wstp_print("[Factory]|memcpy_s fail!\r\n"); + free(ft_table); + return; + } + send_spp_diag_msg(true, &header_temp, ft_table, table_len); + free(ft_table); +#endif +} + +void print_at_cmd_ret(int ret) +{ + uint32_t irq_sts = osal_irq_lock(); + if (ret == ERRCODE_SUCC) { + wstp_print("\r\nOK~\r\n"); + } else { + wstp_print("\r\nERR~\r\n"); + } + +#ifdef FT_BT_UART + if (ret == ERRCODE_SUCC) { + at_cmd_send_abt_result_to_bt((uint8_t *)"\r\nOK~\r\n", strlen("\r\nOK~\r\n")); + } else { + at_cmd_send_abt_result_to_bt((uint8_t *)"\r\nERR~\r\n", strlen("\r\nERR~\r\n")); + } +#endif + osal_irq_restore(irq_sts); +} + +/* Diag消息获取TLV中V值数据处理接口 */ +uint32_t parse_tlv_2value(uint8_t* data, uint16_t data_len, uint8_t** out, uint32_t *out_len) +{ + unused(data_len); + uint8_t num[WORD_WIDTH] = {0}; + uint8_t* ptr = data; + uint8_t len; + uint32_t length = 0; + int i; + + ptr++; + // 动态len运算,7bit为1代表剩下0-6bit为真实长度,7bit为0,0-6bit代表后面几个字节为真实长度。 + len = *(uint8_t*)ptr++; + if (((len & BIT7) >> 7) == 1) { + length = len & (~BIT7); + } else { + // 按照len数值,将真实长度数据小端保存到num中,默认最大长度四个字节,已够用 + for (i = 0; i < len; i++) { + num[i] = *ptr++; + } + length = *(uint32_t*)num; + } + *out = ptr; + *out_len = length; + return ERRCODE_SUCC; +} + +/* diag消息再封装转发app task接口 */ +uint32_t mcu_diag_cmd_process(diag_ser_data_t *data) +{ + app_msg_info_t* app_msg; + uint8_t* ptr; + uint32_t paylen; + diag_ser_frame_t* frame = (diag_ser_frame_t*)data->payload; + + if (data == NULL) { + return ERRCODE_FAIL; + } + + parse_tlv_2value(frame->tlv, data->header.length, &ptr, &paylen); + app_msg = (app_msg_info_t*)osal_kmalloc(sizeof(app_msg_info_t) + data->header.length, OSAL_GFP_KERNEL); + if (app_msg == NULL) { + wstp_print("mcu_diag_cmd_process malloc fail!!"NEWLINE); + return ERRCODE_FAIL; + } + (void)memset_s(app_msg, sizeof(app_msg_info_t) + data->header.length, 0, sizeof(app_msg_info_t) + data->header.length); + (void)memcpy_s(&g_mcu_diag_header, sizeof(diag_ser_header_t), &(data->header), sizeof(diag_ser_header_t)); + app_msg->id = data->header.cmd_id; + app_msg->payload_len = paylen; + if (app_msg->payload_len > 0 && data != NULL) { + if (memcpy_s(app_msg->payload, app_msg->payload_len, (const void *)ptr, paylen) != EOK) { + wstp_print("mcu_diag_cmd_process data memcpy error!"NEWLINE); + osal_kfree(app_msg); + return ERRCODE_FAIL; + } + } + g_app_diag_flag = true; + app_at_msg_send((uint8_t *)app_msg, sizeof(app_msg_info_t) + paylen); + osal_kfree(app_msg); + return ERRCODE_SUCC; +} + +/* 封装返回结果成Diag数据回发给BTH SPP +param descrip: + send: 用于控制是否做diag消息回复 + data: 用于传入diag包包头信息 + payload: 回复tlv数据 + pay_len: 回复tlv数据长度 +*/ +uint32_t send_spp_diag_msg(bool send, diag_ser_header_t *data, uint8_t* payload, uint32_t pay_len) +{ + uint8_t size; + diag_ser_data_t* diag_data; + diag_ser_frame_t* frame; + uint32_t result = ERRCODE_FAIL; + + // send为false,则直接返回 + if (send == false) { + return ERRCODE_SUCC; + } + + size = sizeof(diag_ser_data_t) + sizeof(diag_ser_frame_t) + pay_len; + diag_data = (diag_ser_data_t *)malloc(size); + if (diag_data == NULL) { + return ERRCODE_FAIL; + } + + (void)memcpy_s(&(diag_data->header), sizeof(diag_ser_header_t), data, sizeof(diag_ser_header_t)); + frame = (diag_ser_frame_t*)&(diag_data->payload); + frame->module_id = data->ser_id; + frame->cmd_id = data->cmd_id; + (void)memcpy_s(&(frame->tlv), pay_len, payload, pay_len); + diag_data->header.crc_en = 1; + diag_data->header.length = size - sizeof(diag_ser_data_t); + diag_data->header.dst = DIAG_FRAME_FID_PHONE; + diag_data->header.src = data->dst; + result = uapi_diag_service_send_data(diag_data); + free(diag_data); + return result; +} + +uint32_t mcu_os_sys_reset(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint8_t res[DIAG_RES_LEN] = {0x80, 0x82, 0x00, 0x00}; + + send_spp_diag_msg(g_app_diag_flag, &g_mcu_diag_header, res, DIAG_RES_LEN); + reset_deal_with_fs(); + + set_cpu_utils_reset_cause(REBOOT_CAUSE_APPLICATION_SYSRESETREQ); + hal_reboot_chip(); + return ERRCODE_SUCC; +} + +uint32_t mcu_fs_test(uint8_t *para, uint32_t para_len) +{ + test_file_system(para, para_len); + return ERRCODE_SUCC; +} + +uint32_t mcu_os_heap_info(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#if LOSCFG_MEM_TASK_STAT && defined __LITEOS__ + LosMemPoolInfo *heapMan = (LosMemPoolInfo*)OS_EXTEND_MEM_ADDR; + TSK_INFO_S task_info; + uint32_t taskId; + + wstp_print("\r\n"); + OsMemInfoPrint(OS_EXTEND_MEM_ADDR); + wstp_print("\n\t\tstack name task id used size peak size\n"); + for (taskId = 0; taskId <= LOSCFG_BASE_CORE_TSK_LIMIT; taskId++) { + if (0 != LOS_TaskInfoGet(taskId, &task_info)) { + // 过滤掉无用的task id + continue; + } + wstp_print("%22s %-5d 0x%-8x 0x%-8x\n", task_info.acName, taskId, + heapMan->stat.taskMemstats[taskId].memUsed, heapMan->stat.taskMemstats[taskId].memPeak); + } + wstp_print("\r\n\r\n"); + + heapMan = (LosMemPoolInfo*)OS_SYS_MEM_ADDR; + OsMemInfoPrint(OS_SYS_MEM_ADDR); + wstp_print("\n\t\tstack name task id used size peak size\n"); + for (taskId = 0; taskId <= LOSCFG_BASE_CORE_TSK_LIMIT; taskId++) { + if (0 != LOS_TaskInfoGet(taskId, &task_info)) { + // 过滤掉无用的task id + continue; + } + wstp_print("%22s %-5d 0x%-8x 0x%-8x\n", task_info.acName, taskId, + heapMan->stat.taskMemstats[taskId].memUsed, heapMan->stat.taskMemstats[taskId].memPeak); + } + wstp_print("\r\n"); + +#endif +#if defined __FREERTOS__ && defined FREERTOS_DEBUG + freertos_heap_print(); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_os_stack_info(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + +#if LOSCFG_MEM_TASK_STAT && defined __LITEOS__ + TSK_INFO_S task_info; + uint32_t taskId; + + wstp_print("\n stack name task id prio status stack addr total size used size peak size\n" + " -------------- ------- --- ------ --------- -------- -------- --------\n"); + for (taskId = 0; taskId <= LOSCFG_BASE_CORE_TSK_LIMIT; taskId++) { + if (0 != LOS_TaskInfoGet(taskId, &task_info)) { + continue; + } + wstp_print("%22s %-5d %-2d %-2d %-10p 0x%-8x 0x%-8x 0x%-8x\n", task_info.acName, + task_info.uwTaskID, task_info.usTaskPrio, task_info.usTaskStatus, task_info.uwTopOfStack, + task_info.uwStackSize, task_info.uwCurrUsed, task_info.uwPeakUsed); + } +#endif + +#if defined __FREERTOS__ && defined FREERTOS_DEBUG + vTaskInfoPrint(); +#endif + + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_format(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + int ret, i; + + /* 解决后台文件打开导致格式化失败的问题,先关闭可能打开的后台文件*/ + for (i = 0; i < FILE_MAX_NUM; i++) { + close(i); + } + /* 如果离线日志打开,则关闭离线日志 */ + uapi_zdiag_set_offline_log_enable(false); + +#ifdef CFG_DRIVERS_MMC + wstp_print("\r\nemmc format,wait a moment!\r\n"); + ret = emmc_drv_format(); + if (ret != ENOERR) { + ret = ERRCODE_FAIL; + } else { + ret = ERRCODE_SUCC; + } +#endif + +#ifdef CFG_DRIVERS_NANDFLASH + wstp_print("\r\nnandflash format,wait a moment!\r\n"); + nandflash_yaffs_format(); + ret = ERRCODE_SUCC; +#endif + + return ret; +} + +static uint32_t mcu_fs_rw_test(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t *ptr = NULL; + int ret; + char path[] = "/user/user_test.log"; + FILE *fp = NULL; + + fp = fopen(path, "w+"); + if (fp == NULL) { + wstp_print("open fail\r\n"); + return ERRCODE_FAIL; + } + ret = test_libc_rw(fp); + fclose(fp); + remove(path); + + return ret; +} + +static uint32_t mcu_fs_set_clk(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_MMC + char *ptr = (char*)para; + uint8_t mode = 0; + struct hci_softc *sc; + if (para == NULL) { + return ERRCODE_FAIL; + } + + mode = (uint8_t)strtoul(ptr, NULL, 0); + sc = get_mmc_resource(0); + if (mode == 0) { + wstp_print("set emmc clk to 98M!!!\r\n"); + mmc_set_clock_with_way2(sc, SDIOM_SRC_CLK_FREQ_LVL_98M_VAL); + g_app_emmc_clk = SDIOM_SRC_CLK_FREQ_LVL_98M_VAL; + } else if (mode == 1) { + wstp_print("set emmc clk to 32M!!!\r\n"); + mmc_set_clock_with_way2(sc, SDIOM_SRC_CLK_LOW_FREQ_VAL); + g_app_emmc_clk = SDIOM_SRC_CLK_LOW_FREQ_VAL; + } else { + wstp_print("Input para Error!!!\r\n"); + return ERRCODE_FAIL; + } +#endif + + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_read_clk(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_MMC + wstp_print("\r\nclock:%d", g_app_emmc_clk); +#endif + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_check(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t FileSize = 0; + uint32_t times; + uint32_t len; + char FilePath[MAX_FILE_PATH_SIZE] = "/user/"; + FILE *fp = NULL; + + if (para_len == 0) { + return ERRCODE_FAIL; + } + + ptr++; + if (memcpy_s(FilePath + strlen(FilePath), (MAX_FILE_PATH_SIZE - strlen(FilePath) - 1), ptr, + (strchr(ptr, '"') - ptr)) != EOK) { + wstp_print("memcpy ERR!,The file path is too long,\ + the total length of the file path should be less than %d\r\n", MAX_FILE_PATH_SIZE); + return ERRCODE_FAIL; + } + + ptr += (strchr(ptr, '"') - ptr); + ptr += TEST_PARA_2; + FileSize = strtoul(ptr, NULL, 0); + if (FileSize > FS_TEST_1M_BYTES) { FileSize = FS_TEST_1M_BYTES; } + times = (FileSize / BYTES_LEN_4K) ? (FileSize / BYTES_LEN_4K) : 1; + + fp = fopen(FilePath, "r"); + if (fp == NULL) { + wstp_print("open fail!path:%s\r\n", FilePath); + return ERRCODE_FAIL; + } + + len = test_libc_read(fp, times); + fclose(fp); + if (len == times * BYTES_LEN_4K) { + return ERRCODE_SUCC; + } else { + return ERRCODE_FAIL; + } +} + + +static int32_t rm_dir(const char *pathname) +{ + struct dirent *dirent = NULL; + struct stat stat_info; + DIR *d = NULL; + char *fullpath = NULL; + int ret; + + (void)memset_s(&stat_info, sizeof(stat_info), 0, sizeof(struct stat)); + if (stat(pathname, &stat_info) != 0) { + wstp_print("read file info fail! %s, err=%d\n", pathname, get_errno()); + return -1; + } + + if (S_ISREG(stat_info.st_mode)) { + wstp_print("rm path: %s \n", pathname); + return unlink(pathname); + } + d = opendir(pathname); + while (1) { + dirent = readdir(d); + if (dirent == NULL) { + break; + } + if (strcmp(dirent->d_name, "..") && strcmp(dirent->d_name, ".")) { + size_t fullpathBufSize = strlen(pathname) + strlen(dirent->d_name) + 2; // 2 is sep eof length + fullpath = (char *)malloc(fullpathBufSize); + if (fullpath == NULL) { + wstp_print("malloc failure!\n"); + (void)closedir(d); + return -1; + } + ret = snprintf_s(fullpath, fullpathBufSize, fullpathBufSize - 1, "%s/%s", pathname, dirent->d_name); + if (ret < 0) { + wstp_print("name is too long!\n"); + free(fullpath); + (void)closedir(d); + return -1; + } + (void)rm_dir(fullpath); + free(fullpath); + } + } + (void)closedir(d); + return rmdir(pathname); +} + +static uint32_t mcu_fs_rm(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + if (para_len == 0) { + return ERRCODE_FAIL; + } + + char *ptr = (char *)para; + char file_path[MAX_FILE_PATH_SIZE] = ""; + + ptr++; + if (memcpy_s(file_path + strlen(file_path), (MAX_FILE_PATH_SIZE - strlen(file_path) - 1), ptr, + (strchr(ptr, '"') - ptr)) != EOK) { + wstp_print("memcpy ERR!,The file path is %s, max len is %d\r\n", para, MAX_FILE_PATH_SIZE); + return ERRCODE_FAIL; + } + + wstp_print("excute rm path:%s\r\n", file_path); + if (rm_dir(file_path) >= 0) { + return ERRCODE_SUCC; + } else { + return ERRCODE_FAIL; + } +} + +static uint32_t mcu_get_wstp_version(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + char str[VER_STR_MAX]; +#if (defined BUILD_TIME) && (defined TARGET_NAME) + (void)sprintf_s(str, VER_STR_MAX, "\r\nVersion:%s %s %s\r\n", + get_version_string(), TARGET_NAME, BUILD_TIME); +#else + (void)sprintf_s(str, VER_STR_MAX, "\r\nVersion:%s\r\n", get_version_string()); +#endif + wstp_print(str); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_write(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t FileSize = 0; + uint32_t times; + uint32_t len; + char FilePath[MAX_FILE_PATH_SIZE] = "/user/"; + + if (para_len == 0) { + return ERRCODE_FAIL; + } + + ptr++; + if (memcpy_s(FilePath + strlen(FilePath), (MAX_FILE_PATH_SIZE - strlen(FilePath) - 1), ptr, + (strchr(ptr, '"') - ptr)) != EOK) { + wstp_print("memcpy ERR!,The file path is too long,\ + the total length of the file path should be less than %d\r\n", MAX_FILE_PATH_SIZE); + return ERRCODE_FAIL; + } + ptr += (strchr(ptr, '"') - ptr); + ptr += TEST_PARA_2; + FileSize = strtoul(ptr, NULL, 0); + remove(FilePath); + if (FileSize > FS_TEST_1M_BYTES) { FileSize = FS_TEST_1M_BYTES; } + times = (FileSize / BYTES_LEN_4K) ? (FileSize / BYTES_LEN_4K) : 1; + + FILE *fp = NULL; + fp = fopen(FilePath, "w+"); + if (fp == NULL) { + wstp_print("open fail!path:%s\r\n", FilePath); + return ERRCODE_FAIL; + } + + len = test_libc_write(fp, times); + fclose(fp); + if (len == times * BYTES_LEN_4K) { + return ERRCODE_SUCC; + } else { + return ERRCODE_FAIL; + } +} + +#if (CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE == DFX_YES) +static uint32_t mcu_init_logfile(uint8_t *para, store_file_cfg_t *cfg, uint32_t *arr, uint32_t arr_len) +{ + char *ptr = (char *)para; + char *ptr_end = NULL; + + if (strtoul(ptr, &ptr_end, 0) <= 0) { + return ERRCODE_FAIL; + } + + for (uint32_t j = 0; j < arr_len; j++) { + arr[j] = strtoul(ptr, &ptr_end, 0); + ptr = ptr_end + 1; + } + + uint32_t clear_flag = 0; + uint32_t i = 0; + + cfg->mult_files = arr[i++]; + cfg->file_size = arr[i++]; + cfg->enable_cache = arr[i++]; + cfg->cache_size = arr[i++]; + i++; + clear_flag = arr[i]; + cfg->path = "/user/test/"; + cfg->name = "log_file_write_0222.bin"; + wstp_print("mult_files = %d, file_size = %d, enable_cache = %d, cache_size = %d clear_flag = %d\r\n", + cfg->mult_files, cfg->file_size, cfg->enable_cache, cfg->cache_size, clear_flag); + + errcode_t ret = uapi_logfile_init(); + if (ret != ERRCODE_SUCC) { + wstp_print("init logfile %s failed.\r\n", cfg->name); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +static uint32_t mcu_clear_logfile_dir(store_file_cfg_t *cfg) +{ + static uint8_t full_path[MAX_FILE_PATH_LEN] = {0}; + struct dirent *pdirent = NULL; + DIR *d = NULL; + uint32_t ret = ERRCODE_SUCC; + + d = opendir(cfg->path); + if (d == NULL) { + if (mkdir(cfg->path, S_IREAD | S_IWRITE) != 0) { + wstp_print("mkdir %s failed!\r\n", cfg->path); + ret = ERRCODE_FAIL; + } + } else { + do { + pdirent = readdir(d); + if (pdirent == NULL) { + break; + } + wstp_print("file_dir clear start!\r\n"); + if (strncpy_s((char *)full_path, MAX_FILE_PATH_LEN, cfg->path, strlen(cfg->path)) != EOK) { + ret = ERRCODE_FAIL; + break; + } + if (strcat_s((char *)full_path, MAX_FILE_PATH_LEN, pdirent->d_name) != EOK) { + ret = ERRCODE_FAIL; + break; + } + if (remove((char *)full_path) != 0) { + wstp_print("remove %s failed!\r\n", full_path); + ret = ERRCODE_FAIL; + break; + } + } while (pdirent != NULL); + } + (void)closedir(d); + return ret; +} +#endif /* CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE */ + +static uint32_t mcu_logfile_write(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#if (CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE == DFX_YES) + wstp_print("logfile test start!\r\n"); + char test_msg[TEST_MSG_MAX_SIZE] = {0}; + #define TEST_NUM_ID 4 + /* + arg[0] -- multi_num + arg[1] -- file_size + arg[2] -- enable_cache + arg[3] -- cache_size + arg[4] -- test timer + arg[5] -- clear flag + */ + uint32_t arg[LOG_FILE_ARG_NUM] = {0}; + store_file_cfg_t cfg = {0}; + + if (mcu_init_logfile(para, &cfg, arg, LOG_FILE_ARG_NUM) != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + + if (arg[LOG_FILE_ARG_NUM - 1] != 0) { /* arg[5] -- clear flag */ + if (mcu_clear_logfile_dir(&cfg) != ERRCODE_SUCC) { + wstp_print("clear file_dir error!\r\n"); + return ERRCODE_FAIL; + } + } + + errcode_t ret = uapi_logfile_open(STORE_DIAG, &cfg); + if (ret != ERRCODE_SUCC) { + wstp_print("open log_file %s failed.\r\n", cfg.name); + return ERRCODE_FAIL; + } + + for (uint32_t i = 0; i < arg[TEST_NUM_ID]; i++) { /* arg[2] -- test timer */ + (void)memset_s(test_msg, sizeof(test_msg), 0, sizeof(test_msg)); + if (sprintf_s(test_msg, sizeof(test_msg), "abcdef%10d", i + 1) < 0) { + wstp_print("sprintf_s failed.\r\n"); + return ERRCODE_FAIL; + } + ret = uapi_logfile_write(STORE_DIAG, 0, (uint8_t*)&test_msg, strlen(test_msg)); + if (ret != ERRCODE_SUCC) { + wstp_print("write logfile failed.\r\n"); + return ERRCODE_FAIL; + } + dfx_sleep(10); /* 10 : sleep 10ms */ + } + + ret = uapi_logfile_close(STORE_DIAG); + if (ret != ERRCODE_SUCC) { + wstp_print("close logfile %s failed.\r\n", cfg.name); + return ERRCODE_FAIL; + } +#endif /* CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE */ + return ERRCODE_SUCC; +} + +uint32_t mcu_test_dtcm_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + + char *test_buf = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, APP_DTCM_ORIGIN, BUFF_LEN_48K) != 0) { + wstp_print("[dctm mem test]dtcm read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time); + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[dctm mem test]dtcm read time:%dus bw:%dMB/s\r\n", total_time, bw); + + irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, APP_DTCM_ORIGIN, BUFF_LEN_48K) != 0) { + wstp_print("[dctm mem test]dtcm write memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time); + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[dctm mem test]dtcm write time:%dus bw:%dMB/s\r\n", total_time, bw); + return ERRCODE_SUCC; +} + +uint32_t mcu_test_l2m_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + +#if DSP_L2RAM_AREA_SIZE == 8 + char* l2m_ptr = (char*)(&__l2m_dsp_data_end); +#else + char* l2m_ptr = (char*)(&__l2m_gpu_data_end); +#endif + char *test_buf = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, l2m_ptr, BUFF_LEN_48K) != 0) { + wstp_print("[l2ram mem test]l2ram read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = end_time - start_time; + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[l2m mem test]l2m read time:%dus bw:%dMB/s\r\n", total_time, bw); + + irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(l2m_ptr, BUFF_LEN_48K, test_buf, BUFF_LEN_48K) != 0) { + wstp_print("[l2ram mem test]l2ram write memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = end_time - start_time; + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[l2m mem test]l2m write time:%dus bw:%dMB/s\r\n", total_time, bw); + + return ERRCODE_SUCC; +} + +uint32_t mcu_test_mmc_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_MMC + char* path = "/user/test_spped.bin"; + wstp_print("emmc fs bw test start!please wait...\r\n"); + fs_test_rw_speed(path, BYTES_LEN_128); + fs_test_rw_speed(path, BYTES_LEN_512); + fs_test_rw_speed(path, BYTES_LEN_1K); + fs_test_rw_speed(path, BYTES_LEN_4K); + fs_test_rw_speed(path, BYTES_LEN_8K); +#else + wstp_print("[emmc mem test]The current version does not support EMMC.\r\n"); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_test_psram_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + +#ifdef CONFIG_PSRAM_SUPPORT + char *test_buf = (char*)malloc(BUFF_LEN_48K); + if (test_buf == NULL) { + wstp_print("[psram mem test]buf malloc fail!\r\n"); + return ERRCODE_FAIL; + } + char *test_buf1 = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf1, BUFF_LEN_48K, test_buf, BUFF_LEN_48K) != 0) { + wstp_print("[psram mem test]psram read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time) - TCXO_ERROR; + bw = ONE_SECOND / total_time * BUFF_LEN_48K / MB_SIZE; + wstp_print("[psram mem test]psram read time:%dus bw:%dMB/s\r\n", total_time, bw); + + irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, test_buf1, BUFF_LEN_48K) != 0) { + wstp_print("[psram mem test]psram write memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time) - TCXO_ERROR; + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[psram mem test]psram write time:%dus bw:%dMB/s\r\n", total_time, bw); + free(test_buf); +#else + wstp_print("[psram mem test]The current version does not support PSRAM.\r\n"); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_test_norflash_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + + char *test_buf = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, FLASH_RESERVED_ADDR, BUFF_LEN_48K) != 0) { + wstp_print("[norflash mem test]norflash read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time); + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[norflash mem test]nor flash read time:%dus bw:%dMB/s\r\n", total_time, bw); + + return ERRCODE_SUCC; +} + +uint32_t mcu_test_nandflash_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_NANDFLASH + char* path = "/user/test_spped.bin"; + wstp_print("nandflash fs bw test start!please wait...\r\n"); + fs_test_rw_speed(path, BYTES_LEN_128); + fs_test_rw_speed(path, BYTES_LEN_512); + fs_test_rw_speed(path, BYTES_LEN_1K); + fs_test_rw_speed(path, BYTES_LEN_4K); + fs_test_rw_speed(path, BYTES_LEN_8K); +#else + wstp_print("[nandflash mem test]The current version does not support nandflash.\r\n"); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_get_fs_info(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + int i; + struct statfs file_buf = {0}; + + for (i = 0; i < FS_VOLUMES_NUM; i++) { + /* 获取文件系统状态 */ + if (statfs(g_volume_names[i], &file_buf) != 0) { + return ERRCODE_FAIL; + } + + if (file_buf.f_bfree >= FS_NODE_INFO_SPACE) { + file_buf.f_bfree = file_buf.f_bfree - FS_NODE_INFO_SPACE; + } else { + file_buf.f_bfree = 0; + } + + wstp_print("[FS INFO]%s:\r\n", g_volume_names[i]); + wstp_print("[FS INFO]total size=%uKB used size=%uKB free size=%uKB\r\n", + ((uint32_t)(file_buf.f_blocks * file_buf.f_bsize) / KB_SIZE), + ((uint32_t)((file_buf.f_blocks - file_buf.f_bfree) * file_buf.f_bsize) / KB_SIZE), + ((uint32_t)(file_buf.f_bfree * file_buf.f_bsize) / KB_SIZE)); + } + + return ERRCODE_SUCC; +} + +static void pm_lcd_on_pre_handle(void) +{ + display_resume_power_on(); +#ifdef QSPI_DISPLAY + writew(0x5700c058, 0x0); // sagpio_l22 set gpio mode +#else + writew(0x5700c058, 0x1); // sagpio_l22 set te mode +#endif + writew(0x5700c658, 0x2); // sagpio_l22 open ie +#ifndef QSPI_DISPLAY + pmu_ldo_power_on(PMU_LDO_AUXLDO3, TURN_ON); +#endif +} + +uint32_t mcu_pm_lcd_on(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef SUPPORT_POWER_MANAGER + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + return display_api->turn_on_screen(); +#endif + uapi_pm_request_mode(PM_ID_VIDEO, PM_MODE_PERFORMACE); + + if (lcd_get_status()) { + wstp_print("\r\nLCD has benn on\r\n"); + return ERRCODE_SUCC; + } + pm_lcd_on_pre_handle(); + lcd_bus_api *bus_api = lcd_get_bus_api(); + ext_errno ret = bus_api->bus_resume(); + if (ret != 0) { + wstp_print("bus resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#ifndef QSPI_DISPLAY + if (g_dpu_ready_flag == false) { + ret = drv_dpu_resume(NULL); + if (ret != 0) { + wstp_print("drv dpu resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } + } +#endif +#ifdef SUPPORT_GPU_JPEG + (void)drv_jpeg_resume(NULL); +#endif + ret = drv_vau_resume(NULL); + if (ret != 0) { + wstp_print("drv vau resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#ifdef SUPPORT_GPU_GMMU + ret = drv_gmmu_resume(NULL); + if (ret != 0) { + wstp_print("drv gmmu resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#endif + ret = uapi_lcd_init(); + if (ret != 0 && ret != EXT_ERR_MIPI_ALREADY_INIT) { + wstp_print("LCD init error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) + NotifyScreenOn(); // Instruct the uikit to start the display operation. +#endif + if (g_dpu_ready_flag == false) { + touch_screen_resume(); // open touch + } +#ifdef CONFIG_CLDO1PD_SUPPORT + pmu_control_cldo1_sleep_bypass(TURN_ON); +#endif + lcd_set_status(true); + return ERRCODE_SUCC; +} +uint32_t mcu_pm_into_ship_mode(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uapi_sys_shipmode(0); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_into_force_ds_mode(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + set_cpu_utils_reset_cause(REBOOT_CAUSE_APPLICATION_SYSRESETREQ); + writew(0x5702C010, 0x5A5A); + hal_reboot_chip(); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_req_mode(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + + if (strcmp((char*)para, "lp") == 0) { + errcode_t ret = uapi_pm_request_mode(g_pm_req_mode_usr, PM_MODE_LP); + wstp_print("pm requst mode user 0x%x reuest mode lp, ret 0x%x.\r\n", g_pm_req_mode_usr, ret); + } else if (strcmp((char*)para, "performace") == 0) { + errcode_t ret = uapi_pm_request_mode(g_pm_req_mode_usr, PM_MODE_PERFORMACE); + wstp_print("pm requst mode user 0x%x reuest mode perfermance, ret 0x%x.\r\n", g_pm_req_mode_usr, ret); + } else if (strcmp((char*)para, "normal") == 0) { + errcode_t ret = uapi_pm_request_mode(g_pm_req_mode_usr, PM_MODE_NORMAL); + wstp_print("pm requst mode user 0x%x reuest mode normal, ret 0x%x.\r\n", g_pm_req_mode_usr, ret); + } else if (strcmp((char*)para, "clean") == 0) { + for (pm_id_t i = 0; i < PM_ID_MAX; i++) { + uapi_pm_request_mode(i, PM_MODE_LP); + } + wstp_print("pm mode back to lp mode for all users.\r\n"); + } else { + wstp_print("pm request mode is not supported.\r\n"); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +uint32_t mcu_set_pm_req_mode_usr(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + uint8_t pm_id = *(char*)para - '0'; + + if (pm_id >= PM_ID_MAX) { + wstp_print("pm requst mode user 0x%x check fail.\r\n", pm_id); + return ERRCODE_FAIL; + } + g_pm_req_mode_usr = (pm_id_t)pm_id; + + wstp_print("pm requst mode user 0x%x reuest mode.\r\n", g_pm_req_mode_usr); + return ERRCODE_SUCC; +} + +static void pm_print_veto_info(void) +{ + uint8_t i = 0; + pm_veto_t *pm_veto_ptr = pm_veto_get_info(); + wstp_print("last_veto_id=%d, last_veto_lr=%x, veto_timeout_timestamp=%llu, total_counts=%d\r\n", + pm_veto_ptr->last_veto_id, pm_veto_ptr->last_veto_lr, pm_veto_ptr->veto_timeout_timestamp, + pm_veto_ptr->veto_counts.total_counts); + for (i = 0; i < PM_ID_MAX; i++) { + // wstp_print("sub_counts[%d] = %d\r\n", i, pm_veto_ptr->veto_counts.sub_counts[i]); + wstp_print("sub_counts[%d] %s = %d\r\n", i,get_pm_id_name(i), pm_veto_ptr->veto_counts.sub_counts[i]); + } +} + +static void lpc_print_veto_info(void) +{ + uint8_t i = 0; + volatile lpc_veto_type *lpc_veto_ptr = lpc_get_sys_sleep_veto(); + wstp_print("g_lpc_mcpu_i2c_sleep_vetos=%d\r\n", lpc_get_mcpu_i2c_sleep_veto()); + for (i = 0; i < LPC_ID_MAX; i++) { + wstp_print("i=%d, lpc_sleep_vetos=%d, lr_pointer=%x\r\n", + i, lpc_veto_ptr[i].lpc_sleep_vetos, lpc_veto_ptr[i].lr_pointer); + } +} + +uint32_t mcu_pm_dfx_mode(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uapi_get_current_pm_mode_info(); + pm_print_veto_info(); + lpc_print_veto_info(); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_cldo1_power_down(uint8_t *para, uint32_t para_len) +{ + unused(para); + + if (strcmp((char*)para, "yes") == 0) { + pmu_control_cldo1_sleep_bypass(TURN_OFF); + wstp_print("pm request cldo1 power down at sleep.\r\n"); + } else if (strcmp((char*)para, "no") == 0) { + pmu_control_cldo1_sleep_bypass(TURN_ON); + wstp_print("pm request cldo1 power on at sleep.\r\n"); + } else { + wstp_print("pm request cldo1 para is not supported.\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +static void mcu_aes_get_password(uint32_t keyslot) +{ + errcode_t ret; + uapi_drv_klad_attr_t test_klad_attr = { + .klad_cfg = { + .rootkey_type = UAPI_DRV_KDF_HARD_KEY_TYPE_ABRK_REE, + }, + .key_cfg = { + .engine = UAPI_DRV_KLAD_ENGINE_AES, + .decrypt_support = true, + .encrypt_support = true, + }, + }; + uapi_drv_klad_effective_key_t test_klad_key = { + .kdf_hard_alg = UAPI_DRV_KDF_HARD_ALG_SHA256, + .key_parity = false, + .key_size = 16, // 16 固定的密钥长度 + .salt = (uint8_t *)g_decrypt_aes_salt, + .salt_length = sizeof(g_decrypt_aes_salt), + }; + + uint32_t klad; + ret = uapi_drv_klad_create(&klad); + if (ret != ERRCODE_SUCC) { + return; + } + + ret = uapi_drv_klad_attach(klad, UAPI_DRV_KLAD_DEST_MCIPHER, keyslot); + if (ret != ERRCODE_SUCC) { + return; + } + + ret = uapi_drv_klad_set_attr(klad, &test_klad_attr); + if (ret != ERRCODE_SUCC) { + (void)uapi_drv_klad_destroy(klad); + return; + } + + ret = uapi_drv_klad_set_effective_key(klad, &test_klad_key); + if (ret != ERRCODE_SUCC) { + (void)uapi_drv_klad_destroy(klad); + return; + } + + ret = uapi_drv_klad_detach(klad, UAPI_DRV_KLAD_DEST_MCIPHER, keyslot); + if (ret != ERRCODE_SUCC) { + wstp_print("[ERR] %d, %s (%d)\n", ret, __FUNCTION__, __LINE__); + (void)uapi_drv_klad_destroy(klad); + return; + } + + (void)uapi_drv_klad_destroy(klad); +} + +static errcode_t mcu_test_crypto_cipher_create(uint32_t *cipher, uint32_t *keyslot) +{ + errcode_t ret; + uapi_drv_cipher_symc_attr_t cipher_attr = { + .symc_alg = UAPI_DRV_CIPHER_SYMC_ALG_AES, + .work_mode = UAPI_DRV_CIPHER_SYMC_WORK_MODE_CBC, + .symc_type = UAPI_DRV_CIPHER_SYMC_TYPE_NORMAL, + .is_long_term = true + }; + + ret = uapi_drv_cipher_symc_create(cipher, &cipher_attr); + if (ret != ERRCODE_SUCC) { + return ret; + } + + ret = uapi_drv_keyslot_create(keyslot, UAPI_DRV_KEYSLOT_TYPE_MCIPHER); + if (ret != ERRCODE_SUCC) { + goto cleanup0; + } + + ret = uapi_drv_cipher_symc_attach(*cipher, *keyslot); + if (ret != ERRCODE_SUCC) { + goto cleanup1; + } + + return ERRCODE_SUCC; + +cleanup1: + (void)uapi_drv_keyslot_destroy(*keyslot); +cleanup0: + (void)uapi_drv_cipher_symc_destroy(*cipher); + + return ret; +} + +static errcode_t mcu_aes_cipher_process(aes_cypto_t crypt, uint8_t *src, uint8_t *dst, uint32_t len) +{ + errcode_t ret = ERRCODE_SUCC; + uint32_t cipher = INVALID_HANDLE; + uint32_t keyslot = INVALID_HANDLE; + uapi_drv_cipher_buf_attr_t src_buf = { .phys_addr = src, .buf_sec = UAPI_DRV_CIPHER_BUF_NONSECURE, }; + uapi_drv_cipher_buf_attr_t dst_buf = { .phys_addr = dst, .buf_sec = UAPI_DRV_CIPHER_BUF_NONSECURE, }; + + uapi_drv_cipher_symc_ctrl_t ctrl = { + .symc_alg = UAPI_DRV_CIPHER_SYMC_ALG_AES, + .work_mode = UAPI_DRV_CIPHER_SYMC_WORK_MODE_CBC, + .symc_key_length = UAPI_DRV_CIPHER_SYMC_KEY_128BIT, + .symc_bit_width = UAPI_DRV_CIPHER_SYMC_BIT_WIDTH_128BIT, + .iv_change_flag = UAPI_DRV_CIPHER_SYMC_IV_CHANGE_ONE_PKG, + .iv_length = sizeof(g_decrypt_aes_iv), + }; + + (void)memcpy_s(ctrl.iv, sizeof(ctrl.iv), g_decrypt_aes_iv, sizeof(g_decrypt_aes_iv)); + + ret = mcu_test_crypto_cipher_create(&cipher, &keyslot); + if (ret != ERRCODE_SUCC) { + return ret; + } + + ret = uapi_drv_cipher_symc_set_config(cipher, &ctrl); + if (ret != ERRCODE_SUCC) { + return ret; + } + + mcu_aes_get_password(keyslot); + + if (crypt == AES_ENCRYPT_TEST) { + ret = uapi_drv_cipher_symc_encrypt(cipher, &src_buf, &dst_buf, len); + } else { + ret = uapi_drv_cipher_symc_decrypt(cipher, &src_buf, &dst_buf, len); + } + + (void)uapi_drv_cipher_symc_detach(cipher, keyslot); + (void)uapi_drv_keyslot_destroy(keyslot); + (void)uapi_drv_cipher_destroy(cipher); + return ret; +} + +uint32_t mcu_aes_decrypt_sample(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint32_t test_len = AES_SAMPLE_TEST_LEN; + uint8_t *test_src_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_src_addr == NULL) { + return ERRCODE_FAIL; + } + uint8_t *test_dst_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_dst_addr == NULL) { + free(test_src_addr); + return ERRCODE_FAIL; + } + + (void)memset_s(test_src_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + (void)memset_s(test_dst_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + + wstp_print("mcu aes decrypt sample start.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + test_src_addr[i] = g_decrypt_aes_decryp[i]; + } + mcu_aes_cipher_process(AES_DECRYPT_TEST, test_src_addr, test_dst_addr, AES_SAMPLE_TEST_LEN); + wstp_print("mcu aes decrypt result.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + wstp_print("i=0x%x, src=0x%02x, dst=0x%02x\r\n", i, test_src_addr[i], test_dst_addr[i]); + } + wstp_print("mcu aes decrypt sample end.\r\n"); + free(test_src_addr); + free(test_dst_addr); + return ERRCODE_SUCC; +} + +uint32_t mcu_aes_encrypt_sample(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint32_t test_len = AES_SAMPLE_TEST_LEN; + uint8_t *test_src_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_src_addr == NULL) { + return ERRCODE_FAIL; + } + uint8_t *test_dst_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_dst_addr == NULL) { + free(test_src_addr); + return ERRCODE_FAIL; + } + + (void)memset_s(test_src_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + (void)memset_s(test_dst_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + + wstp_print("mcu aes encrypt sample start.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + test_src_addr[i] = g_decrypt_aes_encryp[i]; + } + mcu_aes_cipher_process(AES_ENCRYPT_TEST, test_src_addr, test_dst_addr, AES_SAMPLE_TEST_LEN); + wstp_print("mcu aes encrypt result.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + wstp_print("i=0x%x, src=0x%02x, dst=0x%02x\r\n", i, test_src_addr[i], test_dst_addr[i]); + } + wstp_print("mcu aes encrypt sample end.\r\n"); + free(test_src_addr); + free(test_dst_addr); + return ERRCODE_SUCC; +} + +uint32_t mcu_aes_set_gid(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t i; + uint8_t security_key = 0; + // After security_Key is set, GID cannot be configured and read. + (void)uapi_efuse_read_bit(&security_key, OTP_DEBUG_FUSED, OTP_DEBUG_FUSED_SECURIY_KEY_EN_ACCESS_BIT); + if (security_key == 0x1) { + wstp_print("gid forbit read, because security_key is closed.\r\n"); + return ERRCODE_FAIL; + } + + uint8_t *test_efuse_gid = (uint8_t*)malloc(sizeof(uint8_t) * OTP_SECURITY_KEY_GID_LEN); + if (test_efuse_gid == NULL) { + return ERRCODE_FAIL; + } + (void)memset_s(test_efuse_gid, OTP_SECURITY_KEY_GID_LEN, 0, OTP_SECURITY_KEY_GID_LEN); + (void)uapi_efuse_read_buffer(test_efuse_gid, OTP_SECURITY_KEY_GID, OTP_SECURITY_KEY_GID_LEN); + for (i = 0; i < OTP_SECURITY_KEY_GID_LEN; i++) { + wstp_print("current gid[0x%02x] val[0x%02x]\r\n", i, test_efuse_gid[i]); + } + wstp_print("start write into efuse gid.\r\n"); + (void)uapi_efuse_write_buffer(OTP_SECURITY_KEY_GID, g_decrypt_aes_gid, OTP_SECURITY_KEY_GID_LEN); + wstp_print("write into efuse gid completely.\r\n"); + (void)uapi_efuse_read_buffer(test_efuse_gid, OTP_SECURITY_KEY_GID, OTP_SECURITY_KEY_GID_LEN); + for (i = 0; i < OTP_SECURITY_KEY_GID_LEN; i++) { + wstp_print("write into gid[0x%02x] val[0x%02x]\r\n", i, test_efuse_gid[i]); + } + (void)uapi_efuse_write_bit(OTP_DEBUG_FUSED, OTP_DEBUG_FUSED_SECURIY_KEY_EN_ACCESS_BIT); + wstp_print("gid read locked.\r\n"); + free(test_efuse_gid); + return ERRCODE_SUCC; +} + +#if defined(CONFIG_ADC_SUPPORT_AUTO_SCAN) +#define ADC_SAMPLE_TIMES 10 +#define ADC_SAMPLE_DATA_LEN 10010 +uint32_t g_adc_sample_times = 0; +uint32_t g_save_adc_index = 0; +uint32_t *g_save_adc_data = NULL; +static uint32_t adc_auto_sample_show_data(uint8_t *para, uint32_t para_len) +{ + wstp_print("g_save_adc_index = %d\r\n", g_save_adc_index); + for (uint32_t i = 0; i < g_save_adc_index; i++) { + wstp_print("%d\r\n", g_save_adc_data[i]); + } + + g_save_adc_index = 0; + g_adc_sample_times = 0; + free(g_save_adc_data); + g_save_adc_data = NULL; + return ERRCODE_SUCC; +} + +static void adc_autosample_callback(uint8_t channel, uint32_t *buffer, uint32_t length, bool *next) +{ + unused(next); + if (g_adc_sample_times >= ADC_SAMPLE_TIMES) { + wstp_print("g_adc_sample_times = %d\r\n", g_adc_sample_times); + uapi_adc_auto_scan_ch_disable(channel); + return; + } + + memcpy_s(g_save_adc_data + g_save_adc_index, length * sizeof(uint32_t), buffer, length * sizeof(uint32_t)); + g_save_adc_index += length; + g_adc_sample_times++; + wstp_print("length = %d\r\n", length); + return; +} + +static uint32_t adc_auto_sample_by_diag(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + uint32_t channel = 0; + uint32_t freq = 0; + uint32_t sample_time = 0; + uint32_t idx = 0; + uint32_t tmp[ADC_AUTODATA_PRT_INDEX3] = {0}; + token = strtok_s((char*)ptr, ",", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 10); // 10: 十进制 + token = strtok_s(NULL, ",", &next_token); + } + channel = tmp[0]; + freq = tmp[ADC_AUTODATA_PRT_INDEX1]; + sample_time = tmp[ADC_AUTODATA_PRT_INDEX2]; + + adc_scan_config_t config = {0}; + config.freq = (uint8_t)freq; + config.long_sample_time = sample_time; + + g_save_adc_data = (uint32_t *)malloc(sizeof(uint32_t) * ADC_SAMPLE_DATA_LEN); + if (g_save_adc_data == NULL) { + wstp_print("malloc g_save_adc_data fail!\r\n"); + return ERRCODE_FAIL; + } + (void)uapi_adc_init(ADC_CLOCK_500KHZ); + (void)uapi_adc_power_en(AFE_SCAN_MODE_MAX_NUM, true); + return(uapi_adc_auto_scan_ch_enable((uint8_t)channel, config, adc_autosample_callback)); +} + +static uint32_t adc_auto_sample_disable(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + uint32_t ret = 0; + uint32_t channel = strtoul(ptr, NULL, 10); // 10: 十进制 + wstp_print("disable adc auto sample , channel = %x\r\n", channel); + + return(uapi_adc_auto_scan_ch_disable(channel)); +} +#endif + +static void pm_lcd_off_handle(void) +{ + writew(0x570000c0, 0x0); // display logic crg reset + writew(0x57004034, 0x100); // display close power +#ifndef QSPI_DISPLAY + pmu_ldo_power_on(PMU_LDO_AUXLDO3, TURN_OFF); + hal_pmu_auxldo_enable_high_resistance(HAL_PMU_AUXLDO3, TURN_ON); +#endif +#ifdef CONFIG_CLDO1PD_SUPPORT + pmu_control_cldo1_sleep_bypass(TURN_OFF); +#endif +} + +uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef SUPPORT_POWER_MANAGER + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + return display_api->turn_off_screen(); +#endif + if (!lcd_get_status()) { + wstp_print("\r\nLCD has benn off\r\n"); + return ERRCODE_SUCC; + } +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) + NotifyScreenOff(); // Instruct the uikit to close the display operation. +#endif + osDelay(100); // Wait 100ms for the uikit to complete display. + touch_screen_suspend(); // close touch + ext_errno ret = drv_vau_suspend(NULL); + if (ret != 0) { + wstp_print("drv vau suspend error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#ifdef SUPPORT_GPU_JPEG + (void)drv_jpeg_suspend(NULL); +#endif +#ifndef QSPI_DISPLAY + ret = drv_dpu_suspend(NULL); + if (ret != 0) { + wstp_print("drv dpu suspend error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#endif +#ifdef SUPPORT_GPU_GMMU + ret = drv_gmmu_suspend(NULL); + if (ret != 0) { + wstp_print("drv gmmu suspend error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#endif + ret = uapi_lcd_deinit(); + if (ret != 0) { + wstp_print("lcd deinit error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } + pm_lcd_off_handle(); + lcd_set_status(false); + g_dpu_ready_flag = false; + display_suspend_power_off(); + uapi_pm_request_mode(PM_ID_VIDEO, PM_MODE_LP); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_add_vote(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_DEBUG); + if (cnt == 0) { + uapi_pm_add_sleep_veto(PM_ID_DEBUG); + } else { + wstp_print("MCU has got pm_id_debug vote\r\n"); + } + wstp_print("\r\nMCU WAKEUP SUCCESS\r\n"); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_remove_vote(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_DEBUG); + if (cnt == 1) { + uapi_pm_remove_sleep_veto(PM_ID_DEBUG); + } else { + wstp_print("MCU has delete pm_id_debug vote\r\n"); + } + wstp_print("\r\nMCU SLEEP SUCCESS\r\n"); + uapi_tcxo_delay_ms(5); // delay 5ms for print debug infor with uart + return ERRCODE_SUCC; +} + +uint32_t mcu_dfx_get_cur_second(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint32_t cur_second = dfx_get_cur_second(); + + wstp_print("cur_second = %d\r\n", cur_second); + return ERRCODE_SUCC; +} + +uint32_t get_ids(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + uint16_t nandflash_id; + uapi_nandflash_read_id(&nandflash_id); + wstp_print("[nandflash id:] %x\r\n", nandflash_id); +#endif + flash_info_t norflash_id; + uapi_flash_get_info(0, &norflash_id); + wstp_print("[norflash id:] %x\r\n", norflash_id.flash_id); + wstp_print("[sdk id:]%s \r\n", uapi_sdk_read_id()); + uint8_t soc_id[20]; // 20 is soc id length + uapi_soc_read_id(soc_id, 20); // 20 is soc id length + wstp_print("[soc id:]\r\n"); + for (uint8_t i = 0; i < 20; i += 2) { // 20 is soc id length, 2 means use 16bits + wstp_print("0x%04X ", *((uint16_t *)&soc_id[i])); + if ((i + 2) % 8 == 0) { wstp_print("\r\n"); } // 2&8 will word wrap + } + wstp_print("\r\n"); + return ERRCODE_SUCC; +} + +uint32_t lcd_test_light(uint8_t *data, uint32_t data_len) +{ + char *ptr = (char *)data; + uint32_t light_input = strtoul(ptr, NULL, 16); + wstp_print("light = %x \r\n", light_input); + uapi_lcd_set_brightness(light_input); + return ERRCODE_SUCC; +} + +uint32_t at_nand_write_read(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t page = strtoul(ptr, NULL, 10); + wstp_print("page = %d \r\n", page); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (page >= freertos_nandflash_driver->pages_per_block * freertos_nandflash_driver->total_block) { + wstp_print("page error exceed max page = %d \r\n", page); + return ERRCODE_FAIL; + } + test_nand_flash_read_8(freertos_nandflash_driver, page); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_write_write(uint8_t *data, uint32_t data_len) +{ + PRINT("nand wite\r\n"); +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t page = strtoul(ptr, NULL, 10); + wstp_print("page = %d \r\n", page); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (page >= freertos_nandflash_driver->pages_per_block * freertos_nandflash_driver->total_block) { + wstp_print("page error exceed max page = %d \r\n", page); + return ERRCODE_FAIL; + } + test_nand_flash_write_width8(freertos_nandflash_driver, page); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_write_erase(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t block = strtoul(ptr, NULL, 10); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + wstp_print("block = %d total_block = %d\r\n", block, freertos_nandflash_driver->total_block); + if (block >= freertos_nandflash_driver->total_block) { + erase_all(freertos_nandflash_driver); + wstp_print("erase all block\r\n"); + return ERRCODE_SUCC; + } + freertos_nandflash_driver->erase_block(block); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_mark_bad(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t block = strtoul(ptr, NULL, 10); + wstp_print("mark block%d = %x is bad\r\n", block); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (block >= freertos_nandflash_driver->total_block) { + wstp_print("exceed max block = %d \r\n", block); + return ERRCODE_FAIL; + } + freertos_nandflash_driver->mark_bad_block(block); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_check_bad(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t block = strtoul(ptr, NULL, 10); + wstp_print("check block%d = %x is bad?\r\n", block); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (block >= freertos_nandflash_driver->total_block) { + wstp_print("exceed max block = %d \r\n", block); + return ERRCODE_FAIL; + } + uint32_t ret = freertos_nandflash_driver->check_bad_block(block); + wstp_print("is bad? ret = %d\r\n", ret); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_set_mode(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t mode = strtoul(ptr, NULL, 10); + if (mode == 0) { + wstp_print("set mode to SPEED_HIGH DMA_FOUR_LINE\r\n", mode); + nand_driver_init(SPEED_HIGH); + set_trans_type(TRANS_BY_DMA_QUAD); + } else { + wstp_print("set mode to SPEED_SLOW CPU_SINGLE_LINE\r\n", mode); + nand_driver_init(SPEED_SLOW); + set_trans_type(TRANS_BY_CPU_SINGLE_LINE); + } +#endif + return ERRCODE_SUCC; +} + +uint32_t lcd_fill(uint8_t *data, uint32_t data_len) +{ + char *ptr = (char *)data; + uint32_t color_input = strtoul(ptr, NULL, 16); + wstp_print("color = %x \r\n", color_input); + + td_handle vau_handle; + ext_vau_surface src_surface = {0}; + + src_surface.width = 454; // 454 screen width + src_surface.height = 454; // 454 screen height + src_surface.phy_addr = LCD_FILL_COLOR_ADDR; + src_surface.vir_addr = (td_uchar *)src_surface.phy_addr; + src_surface.color_fmt = EXT_GFX_FMT_ARGB8888; + src_surface.compress_mode = EXT_GFX_COMPRESS_NONE; + src_surface.argb_order = EXT_GFX_FMT_ORDER_ARGB; + src_surface.rect.x = 0; + src_surface.rect.y = 0; + src_surface.rect.width = src_surface.width; + src_surface.rect.height = src_surface.height; + src_surface.stride = 1824; /* 454 * 32 / 8 = 1816 16字节对齐得1824 */ + src_surface.is_color_surface = TD_TRUE; + src_surface.color = color_input; + +#ifdef MIPI_ULPS_SUPPORT + uapi_mipi_tx_exit_ulps(); +#endif + + vau_handle = uapi_vau_create(); + uapi_vau_fill(vau_handle, &src_surface); + uapi_vau_submit(vau_handle, TD_FALSE, 1000); /* 1000 ms timeout */ + + td_handle dpu_handle; + ext_dpu_layer_info layer_info = {0}; + ext_dpu_surface dpu_surface = {0}; + + layer_info.width = src_surface.width; + layer_info.height = src_surface.height; + layer_info.layer_id = EXT_DPU_LAYER_ID1; + layer_info.layer_fmt = src_surface.color_fmt; + layer_info.compress_mode = src_surface.compress_mode; + layer_info.buf_mode = EXT_DPU_BUFFER_MODE_NORMAL; + + dpu_surface.width = src_surface.width; + dpu_surface.height = src_surface.height; + dpu_surface.stride = src_surface.stride; + dpu_surface.phy_addr = src_surface.phy_addr; + dpu_surface.vir_addr = src_surface.vir_addr; + dpu_surface.update_rect = TD_NULL; + dpu_surface.color_fmt = src_surface.color_fmt; + dpu_surface.compress_mode = src_surface.compress_mode; + + uapi_dpu_create_layer(&layer_info, &dpu_handle); + uapi_dpu_set_layer_vblank(dpu_handle, TD_TRUE); + uapi_dpu_set_layer_info(dpu_handle, &dpu_surface); + uapi_dpu_refresh_layers(); + + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_no_resume_touch(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *data = (char *)para; + if (data == NULL) { return ERRCODE_FAIL; } + uint8_t flag = strtoul(data, NULL, 0); + if (flag == 1) { + touch_screen_restart(); + } + set_touch_resume_flag(flag); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_set_mcu_dynamic_power(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *data = (char *)para; + if (data == NULL) { return ERRCODE_FAIL; } + uint8_t flag = strtoul(data, NULL, 0); + if (flag == 0) { + pm_set_mcu_dynamic_power_flag(0); + } else { + pm_set_mcu_dynamic_power_flag(1); + } + return ERRCODE_SUCC; +} + +static void button_callback_press(void) +{ + PRINT("power key press."NEWLINE); +} + +static void button_callback_click(void) +{ + PRINT("power key click."NEWLINE); +} + +static void button_callback_click_2(void) +{ + PRINT("power key click double."NEWLINE); +} + +static void button_callback1(void) +{ + PRINT("power key long press 1s."NEWLINE); +} + +static void button_callback2(void) +{ + PRINT("power key long press 2s."NEWLINE); +} + +static void button_callback3(void) +{ + PRINT("power key long press 3s."NEWLINE); +} + +static void button_callback4(void) +{ + PRINT("power key long press 4s."NEWLINE); +} + +static void button_callback5(void) +{ + PRINT("power key long press 5s."NEWLINE); +} + +static void button_callback6(void) +{ + PRINT("power key long press 6s."NEWLINE); +} + +static void button_callback7(void) +{ + PRINT("power key long press 7s."NEWLINE); +} + +static void button_callback8(void) +{ + PRINT("power key long press 8s."NEWLINE); +} + +static void button_callback9(void) +{ + PRINT("power key long press 9s."NEWLINE); +} + +static void button_callback_1_over(void) +{ + PRINT("power key long press 1s over."NEWLINE); +} + +static void button_callback_2_over(void) +{ + PRINT("power key long press 2s over."NEWLINE); +} + +static void button_callback_3_over(void) +{ + PRINT("power key long press 3s over."NEWLINE); +} + +static void button_callback_4_over(void) +{ + PRINT("power key long press 4s over."NEWLINE); +} + +static void button_callback_5_over(void) +{ + PRINT("power key long press 5s over."NEWLINE); +} + +static void button_callback_6_over(void) +{ + PRINT("power key long press 6s over."NEWLINE); +} + +static void button_callback_7_over(void) +{ + PRINT("power key long press 7s over."NEWLINE); +} + +static void button_callback_8_over(void) +{ + PRINT("power key long press 8s over."NEWLINE); +} + +static void button_callback_9_over(void) +{ + PRINT("power key long press 9s over."NEWLINE); +} + +uint32_t mcu_button_sample(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uapi_button_register_event_cb(button_callback_press, BUTTON_PWR_PRESS); + uapi_button_register_event_cb(button_callback_click, BUTTON_PWR_CLICKUP); + uapi_button_register_event_cb(button_callback_click_2, BUTTON_PWR_CLICKUP_2); + + uapi_button_register_event_cb(button_callback1, BUTTON_PWR_LONGPRESS_1S); + uapi_button_register_event_cb(button_callback2, BUTTON_PWR_LONGPRESS_2S); + uapi_button_register_event_cb(button_callback3, BUTTON_PWR_LONGPRESS_3S); + uapi_button_register_event_cb(button_callback4, BUTTON_PWR_LONGPRESS_4S); + uapi_button_register_event_cb(button_callback5, BUTTON_PWR_LONGPRESS_5S); + uapi_button_register_event_cb(button_callback6, BUTTON_PWR_LONGPRESS_6S); + uapi_button_register_event_cb(button_callback7, BUTTON_PWR_LONGPRESS_7S); + uapi_button_register_event_cb(button_callback8, BUTTON_PWR_LONGPRESS_8S); + uapi_button_register_event_cb(button_callback9, BUTTON_PWR_LONGPRESS_9S); + + uapi_button_register_event_cb(button_callback_1_over, BUTTON_PWR_LONGPRESS_1S_OVER); + uapi_button_register_event_cb(button_callback_2_over, BUTTON_PWR_LONGPRESS_2S_OVER); + uapi_button_register_event_cb(button_callback_3_over, BUTTON_PWR_LONGPRESS_3S_OVER); + uapi_button_register_event_cb(button_callback_4_over, BUTTON_PWR_LONGPRESS_4S_OVER); + uapi_button_register_event_cb(button_callback_5_over, BUTTON_PWR_LONGPRESS_5S_OVER); + uapi_button_register_event_cb(button_callback_6_over, BUTTON_PWR_LONGPRESS_6S_OVER); + uapi_button_register_event_cb(button_callback_7_over, BUTTON_PWR_LONGPRESS_7S_OVER); + uapi_button_register_event_cb(button_callback_8_over, BUTTON_PWR_LONGPRESS_8S_OVER); + uapi_button_register_event_cb(button_callback_9_over, BUTTON_PWR_LONGPRESS_9S_OVER); + return ERRCODE_SUCC; +} + +static uint32_t mcu_power_key_config(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + uint32_t power_level = 0; + uint32_t power_type = 0; + uint32_t idx = 0; + uint32_t tmp[POWER_KEY_PARAM_LEN] = {0}; + token = strtok_s((char*)ptr, " ", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 10); // 10: 十进制 + token = strtok_s(NULL, " ", &next_token); + } + power_type = tmp[0]; + power_level = tmp[1]; + printf("power type:%d power_level:%d \r\n", power_type, power_level); + if (uapi_power_set_mode(power_type) != ERRCODE_SUCC) { + printf("power type:%d error.", power_type); + } + if (uapi_power_time_mode(power_level) != ERRCODE_SUCC) { + printf("power level:%d error.", power_level); + } + + return ERRCODE_SUCC; +} + +static uint32_t mcu_calendar_set_date(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + calendar_t date; + uint32_t idx = 0; + uint32_t tmp[CALENDAR_PARAM_LEN] = {0}; + token = strtok_s((char*)ptr, " ", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 10); // 10: 十进制 + token = strtok_s(NULL, " ", &next_token); + } + date.year = tmp[0]; + date.mon = tmp[1]; + date.day = tmp[2]; + date.hour = tmp[3]; + date.min = tmp[4]; + date.sec = tmp[5]; + + errcode_t ret = uapi_calendar_set_datetime(&date); + if (ret == ERRCODE_SUCC) { + printf("Set datetime success: %d-%d-%d %d:%d:%d\r\n", date.year, date.mon, date.day, date.hour, date.min, + date.sec); + return ERRCODE_SUCC; + } + printf("Set datetime failed, error code = %d \r\n", ret); + return ret; +} + +static uint32_t mcu_calendar_get_date(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + calendar_t date; + + errcode_t ret = uapi_calendar_get_datetime(&date); + if (ret == ERRCODE_SUCC) { + printf("Get datetime success: %d-%d-%d %d:%d:%d\r\n", date.year, date.mon, date.day, date.hour, date.min, + date.sec); + return ERRCODE_SUCC; + } + printf("Get datetime failed, error code = %d \r\n", ret); + + return ret; +} + +#ifdef SUPPROT_EXECUTE_CORMARK +static uint32_t mcu_coremark_test(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint32_t irq_sts = osal_irq_lock(); + watchdog_turnoff_clk(); + coremark_test(); + watchdog_turnon_clk(); + osal_irq_restore(irq_sts); + return ERRCODE_SUCC; +} +#endif + +static uint32_t mcu_set_app_delay_time(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t delay_time = strtoul(ptr, NULL, 0); + if (delay_time == 0) { + delay_time = 10000; // 10000 ms + } + wstp_print("app set delay_time = %d\r\n", delay_time); + set_app_delay_time(delay_time); + return ERRCODE_SUCC; +} + +static uint32_t mcu_set_cldo1_voltage(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint8_t cldo = strtoul(ptr, NULL, 0); + if (cldo > PMU_LDO_MAX) { cldo = 0; } + ptr++; + ptr++; + uint8_t voltage = strtoul(ptr, NULL, 0); + if (voltage > 15) { voltage = 14; } // the max voltage of cldo is 15, 14 is the default value. + wstp_print("app set cldo=%d voltage = %d\r\n", cldo, voltage); + pmu_ldo_power_on((pmu_ldo_t)cldo, 1); + if (((pmu_ldo_t)cldo == PMU_LDO_CLDO1) || ((pmu_ldo_t)cldo == PMU_LDO_CLDO1) || + ((pmu_ldo_t)cldo == PMU_LDO_CLDO1)) { + hal_pmu_cldo_enable_bypass((hal_pmu_cldo_t)cldo, 0); + } + pmu_ldo_power_vset((pmu_ldo_t)cldo, voltage); + return ERRCODE_SUCC; +} + +static uint32_t mcu_nand_aging_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); +#ifdef CFG_DRIVERS_NANDFLASH + return nandflash_aging_test((char*)para); +#else + return ERRCODE_SUCC; +#endif +} + +static uint32_t mcu_norflash_aging_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + return flash_aging_test((char*)para); +} + +static uint32_t mcu_set_pin_pull(uint8_t *para, uint32_t para_len) +{ + int ret; + uint32_t pin = 0; + uint32_t levl = 0; + char* ptr = (char*)para; + char* pos = strchr((char*)ptr, ','); + if (pos == NULL) { + return ERRCODE_FAIL; + } + *pos = '\0'; + + pin = strtoul(ptr, NULL, 0); + if (pin < 0) { + pin = 0; + } + ptr = pos + 1; + levl = strtoul(ptr, NULL, 0); + if ((pin_pull_t)levl > PIN_PULL_MAX) { + levl = 0; + } + uapi_pin_set_pull((pin_t)pin, (pin_pull_t)levl); + return ERRCODE_SUCC; +} + +static uint32_t mcu_get_pin_pull(uint8_t *para, uint32_t para_len) +{ + pin_t pin = 0; + pin_pull_t level = 0; + wstp_print("all pin levl:\r\n"); + for (uint16_t i = 0; i < PIN_NONE; i++) { + level = uapi_pin_get_pull((pin_t)i); + wstp_print("i=%d level=%d\r\n", i, level); + } + return ERRCODE_SUCC; +} + +static uint32_t mcu_set_time(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + return set_system_time((char*)para); +} + +static uint32_t mcu_get_time(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + return get_system_time(); +} + +#ifdef SUPPORT_POWER_MANAGER +static uint32_t mcu_pms_set_screenoff_time(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + uint32_t type; + uint32_t timeout; + char *pos; + char *ptr = (char *)para; + errcode_t ret = ERRCODE_SUCC; + pos = strchr((char *)ptr, ','); + if (pos == NULL) { + return ERRCODE_FAIL; + } + *pos = '\0'; + type = strtoul(ptr, NULL, 0); + pos++; + timeout = strtoul(pos, NULL, 0); + wstp_print("app set screen off: type = %u, timeut = %u.\r\n", type, timeout); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (type == 0) { + ret = display_api->set_screen_auto_off_timeout(timeout); + } else if (type == 1) { + ret = display_api->set_screen_set_keepon_timeout(timeout); + } else { + return ERRCODE_FAIL; + } + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + + +static uint32_t mcu_pms_set_screenoff_enable(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t inputpara = strtoul(ptr, NULL, 0); + bool enable = true; + if (inputpara == 0) { + enable = false; + } + wstp_print("app set screen off enable = %u, para = %u. \r\n", enable, inputpara); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + display_api->set_auto_timeout_function(enable); + return ERRCODE_SUCC; +} + +static uint32_t mcu_pms_set_screen_state(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + wstp_print("app set screen state :%s. \r\n", ptr); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (strcmp(ptr, "ON") == 0) { + display_api->turn_on_screen(); + } else if (strcmp(ptr, "OFF") == 0) { + display_api->turn_off_screen(); + } else { + wstp_print("app set screen input para err.\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +static uint32_t mcu_pms_get_screen_state(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + screen_state_t state = display_api->get_screen_state(); + wstp_print("app get screen state = %u, on is %u, off is %u. \r\n", state, SCREEN_ON, SCREEN_OFF); + return ERRCODE_SUCC; +} +#endif + +#ifdef FT_DONGLE +uint32_t mcu_check_dongle_connected(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + // 通过diag返回包作为factory_tools判断SPP的连接状态依据 + // 仅供factory_tools做判断用,此AT命令不对外用 + wstp_print("Received dongle check msg.\r\n"); + return ERRCODE_SUCC; +} +#endif + +uint32_t mcu_i2c_write_byte(i2c_bus_t bus, uint16_t slave_addr, uint32_t reg_addr, uint32_t reg_val) +{ + errcode_t ret; + i2c_data_t data; + + uint8_t send_buf[AT_I2C_REG_ARRAY_LEN] = { 0 }; + send_buf[0] = (reg_addr >> OFFSET_24) & 0xff; + send_buf[1] = (reg_addr >> OFFSET_16) & 0xff; + send_buf[AT_PARA_IDX2] = (reg_addr >> OFFSET_8) & 0xff; + send_buf[AT_PARA_IDX3] = reg_addr & 0xff; + send_buf[AT_PARA_IDX4] = reg_val & 0xff; + send_buf[AT_PARA_IDX5] = (reg_val >> OFFSET_8) & 0xff; + send_buf[AT_PARA_IDX6] = (reg_val >> OFFSET_16) & 0xff; + send_buf[AT_PARA_IDX7] = (reg_val >> OFFSET_24) & 0xff; + + data.send_buf = send_buf; + data.send_len = 8; // 8: 发送长度 + data.receive_buf = NULL; + data.receive_len = 0; + + ret = uapi_i2c_master_write(bus, slave_addr, &data); + if (ret != ERRCODE_SUCC) { + wstp_print("===== Error: mcu_i2c_write_byte: I2C write ret = 0x%x! =====\r\n", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +int32_t mcu_i2c_read_byte(i2c_bus_t bus, uint16_t slave_addr, uint32_t read_addr, uint32_t *read_val) +{ + errcode_t ret; + i2c_data_t data; + + uint8_t reg_addr[4] = { 0 }; + reg_addr[0] = (read_addr >> OFFSET_24) & 0xff; + reg_addr[1] = (read_addr >> OFFSET_16) & 0xff; + reg_addr[AT_PARA_IDX2] = (read_addr >> OFFSET_8) & 0xff; + reg_addr[AT_PARA_IDX3] = read_addr & 0xff; + + data.send_buf = reg_addr; + data.send_len = 4; // 4: 发送长度 + data.receive_buf = (uint8_t *)read_val; + data.receive_len = 4; // 4: 接收长度 + + ret = uapi_i2c_master_write(bus, slave_addr, &data); + if (ret != ERRCODE_SUCC) { + wstp_print("===== Error: mcu_i2c_read_byte: I2C write ret = 0x%x! =====\r\n", ret); + return ERRCODE_FAIL; + } + + ret = uapi_i2c_master_read(bus, slave_addr, &data); + if (ret != ERRCODE_SUCC) { + wstp_print("===== Error: mcu_i2c_read_byte: I2C read ret = 0x%x! =====\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +static uint32_t mcu_i2c_write(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + errcode_t ret; + + uint32_t idx = 0; + uint32_t bus = 0; + uint32_t slave_addr = 0; + uint32_t write_addr = 0; + uint32_t write_val = 0; + + uint32_t tmp[AT_I2C_PARA_CNT] = {0}; + token = strtok_s((char*)ptr, ",", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 16); // 16: 十六进制 + token = strtok_s(NULL, ",", &next_token); + } + + bus = tmp[0]; + slave_addr = tmp[1]; + write_addr = tmp[AT_PARA_IDX2]; + write_val = tmp[AT_PARA_IDX3]; + + return mcu_i2c_write_byte((i2c_bus_t)bus, slave_addr, write_addr, write_val); +} + +static uint32_t mcu_i2c_read(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + errcode_t ret; + uint32_t read_val; + + uint32_t idx = 0; + uint32_t bus = 0; + uint32_t slave_addr = 0; + uint32_t read_addr = 0; + + uint32_t tmp[AT_I2C_PARA_CNT] = {0}; + token = strtok_s((char*)ptr, ",", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 16); // 16: 十六进制 + token = strtok_s(NULL, ",", &next_token); + } + + bus = tmp[0]; + slave_addr = tmp[1]; + read_addr = tmp[AT_PARA_IDX2]; + + ret = mcu_i2c_read_byte((i2c_bus_t)bus, slave_addr, read_addr, &read_val); + if (ret == ERRCODE_SUCC) { + wstp_print("Read val: [ 0x%x ]\r\n", read_val); + } + + return ret; +} +#ifdef SUPPORT_ALIPAY_SEC +static uint32_t mcu_alipay_sec_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + wstp_print("mcu_alipay_sec_test start.\r\n"); + uapi_alipay_svr_init(); + const alipay_svr_api_t *alipay_api = alipay_svr_get_api(); + alipay_api->exit_lpm(); + osDelay(ALIPAY_EXIT_LPM_DELAY_LEN); + yunit_sdk_test(); + alipay_api->enter_lpm(); + wstp_print("mcu_alipay_sec_test end.\r\n"); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_alipay_debug(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + uapi_alipay_svr_init(); + svr_alipay_debug(); + return ERRCODE_SUCC; +} + +static uint32_t mcu_alipay_pl_verify(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + int32_t compat_ret = 0; + int32_t cert_ret = 0; + uapi_alipay_svr_init(); + const alipay_svr_api_t *alipay_api = alipay_svr_get_api(); + alipay_api->exit_lpm(); + osDelay(ALIPAY_EXIT_LPM_DELAY_LEN); + cert_ret = test_get_credential(); + wstp_print("get cert ret=%d.\r\n", cert_ret); + compat_ret = hal_hardware_compat_check(); + wstp_print("compat check ret=%d.\r\n", compat_ret); + alipay_api->enter_lpm(); + if (cert_ret == 0 && compat_ret == 0) { + return ERRCODE_SUCC; + } + return ERRCODE_FAIL; +} + +static uint32_t mcu_alipay_reset(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + (void)uapi_alipay_svr_reset(); + return ERRCODE_SUCC; +} +#endif + +#ifdef SUPPORT_FILE_SPLIT_COMBINE +static uint32_t mcu_file_spilt_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + wstp_print("mcu_file_spilt_test start.\r\n"); + msg_center_split_file(ORIGIN_FILE_PATH, FILE_SPILT_MAX_SIZE, FILE_LIST_PATH); + wstp_print("mcu_file_spilt_test end.\r\n"); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_file_combine_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + wstp_print("mcu_file_combine_test start.\r\n"); + msg_center_combine_file(FILE_LIST_PATH, COMBINE_FILE_PATH); + wstp_print("mcu_file_combine_test end.\r\n"); + + return ERRCODE_SUCC; +} +#endif + +#ifdef JS_ENABLE +static uint32_t mcu_get_trans_channel_test(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + msg_center_get_trans_channel(); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_set_trans_channel_test(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t select = strtoul(ptr, NULL, 10); /* 10进制 */ + msg_center_set_trans_channel(select); + + return ERRCODE_SUCC; +} +#endif + +#ifdef SUPPORT_AUTO_OTA +static uint32_t mcu_auto_ota_block(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + g_auto_ota_upload_mode = 1;// 阻塞等待升级包上传 + wstp_print("auto_ota block!\r\n"); + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_run(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + g_auto_ota_upload_mode = 0; // 升级包上传完成后auto_ota继续执行 + wstp_print("auto_ota run!\r\n"); + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_del_mac(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + wstp_print("para = %s\r\n", para); + uint8_t addr[ADDR_MAC_LEN] = {0}; + char tmp[ONE_ADDR_LEN + 1] = {0}; + char *p = (char *)para; + + for (uint8_t i = 0; i < ADDR_MAC_LEN; i++) { + memcpy_s(tmp, ONE_ADDR_LEN + 1, p, ONE_ADDR_LEN); + tmp[ONE_ADDR_LEN] = '\0'; + addr[i] = strtol(tmp, NULL, 16); // 16进制 + p = p + ONE_ADDR_LEN; + } + + wstp_print("mcu_auto_ota_del_mac, mac = %02x%02x%02x%02x%02x%02x\r\n", addr[5], addr[4], addr[3], addr[2], addr[1], + addr[0]); + bool res = auto_ota_dev_del(addr); + wstp_print("auto_ota_dev_del, res = %d\r\n", res); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_add_mac(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + wstp_print("enter mcu_auto_ota_add_mac\r\n"); + wstp_print("para = %s\r\n", para); + uint8_t addr[ADDR_MAC_LEN] = {0}; + char tmp[ONE_ADDR_LEN + 1] = {0}; + char *p = (char *)para; + + for (uint8_t i = 0; i < ADDR_MAC_LEN; i++) { + memcpy_s(tmp, ONE_ADDR_LEN + 1, p, ONE_ADDR_LEN); + tmp[ONE_ADDR_LEN] = '\0'; + addr[i] = strtol(tmp, NULL, 16); // 16进制 + p = p + ONE_ADDR_LEN; + } + + wstp_print("mcu_auto_ota_add_mac, mac = %02x%02x%02x%02x%02x%02x\r\n", addr[5], addr[4], addr[3], addr[2], addr[1], + addr[0]); + auto_ota_dev_add(addr); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_show_mac(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + wstp_print("enter mcu_auto_ota_show_mac\r\n"); + + auto_ota_dev_show(); + + return ERRCODE_SUCC; +} +#endif + +static const app_process_table g_app_funcs[] = { + { RESET, mcu_os_sys_reset }, + { FSTEST, mcu_fs_test }, + { FSFORMAT, mcu_fs_format }, + { FSRWTEST, mcu_fs_rw_test }, + { FSSETCLK, mcu_fs_set_clk }, + { FSREADCLK, mcu_fs_read_clk }, + { FSWRITE, mcu_fs_write }, + { FSCHECK, mcu_fs_check }, + { FSRM, mcu_fs_rm }, + { GETWSTPVER, mcu_get_wstp_version }, + { LOGWRITE, mcu_logfile_write }, + { HEAPINFO, mcu_os_heap_info }, + { STACKINFO, mcu_os_stack_info }, + { TESTDTCMBW, mcu_test_dtcm_baudwidth }, + { TESTL2MBW, mcu_test_l2m_baudwidth }, + { TESTMMCBW, mcu_test_mmc_baudwidth }, + { TESTPSRAMBW, mcu_test_psram_baudwidth }, + { TESTNORFLASHBW, mcu_test_norflash_baudwidth }, + { TESTNANDFLASHBW, mcu_test_nandflash_baudwidth }, + { GETFSINFO, mcu_get_fs_info }, + { PMRMVOTE, mcu_pm_remove_vote }, + { PMADDVOTE, mcu_pm_add_vote }, + { LCDON, mcu_pm_lcd_on }, + { LCDOFF, mcu_pm_lcd_off }, + { SHIPMODE, mcu_pm_into_ship_mode }, + { FORCEDEEPSLEEP, mcu_pm_into_force_ds_mode }, + { PMMODESET, mcu_pm_req_mode }, + { PMMODEUSR, mcu_set_pm_req_mode_usr}, + { PMMODEGET, mcu_pm_dfx_mode }, + { GETCURSEC, mcu_dfx_get_cur_second}, + { LCDFILL, lcd_fill }, + { GETIDS, get_ids }, + { LCDLIGHT, lcd_test_light }, + { RESUMETOUCH, mcu_pm_no_resume_touch }, + { MCUDYMPW, mcu_pm_set_mcu_dynamic_power }, + { PMCLDO1PD, mcu_pm_cldo1_power_down }, + { AESDECRYPT, mcu_aes_decrypt_sample }, + { AESENCRYPT, mcu_aes_encrypt_sample }, + { AESSETGID, mcu_aes_set_gid }, + { SETCALENDAR, mcu_calendar_set_date }, + { GETCALENDAR, mcu_calendar_get_date }, +#if defined(CONFIG_ADC_SUPPORT_AUTO_SCAN) + { ADCAUTOSAMPLE, adc_auto_sample_by_diag }, + { ADCCLOSEAUTOSAMPLE, adc_auto_sample_disable }, + { ADCSHOWDATA, adc_auto_sample_show_data }, +#endif + { BUTTON, mcu_button_sample }, + { POWERKEY, mcu_power_key_config }, +#ifdef SUPPROT_EXECUTE_CORMARK + { COREMARKTEST, mcu_coremark_test }, +#endif + { NANDREAD, at_nand_write_read}, + { NANDWRITE, at_nand_write_write}, + { NANDERASE, at_nand_write_erase}, + { NANDMARK, at_nand_mark_bad}, + { NANDCHECK, at_nand_check_bad}, + { NANDSETMODE, at_nand_set_mode}, + { SETAPPDELAY, mcu_set_app_delay_time }, + { SETCLDO1VOL, mcu_set_cldo1_voltage }, + { NANDAGINGTEST, mcu_nand_aging_test }, + { FLASHAGINGTEST, mcu_norflash_aging_test }, + { SETPINPULL, mcu_set_pin_pull }, + { GETPINPULL, mcu_get_pin_pull }, + { TIMESET, mcu_set_time }, + { TIMEGET, mcu_get_time }, +#ifdef SUPPORT_POWER_MANAGER + { SETSCREENOFFTIME, mcu_pms_set_screenoff_time }, + { SETSCREENOFFFUNC, mcu_pms_set_screenoff_enable }, + { SETSCREENSTATE, mcu_pms_set_screen_state }, + { GETSCREENSTATE, mcu_pms_get_screen_state }, +#endif +#ifdef FT_DONGLE + { DONGLECONNECTED, mcu_check_dongle_connected }, +#endif + { I2CWRITE, mcu_i2c_write }, + { I2CREAD, mcu_i2c_read }, +#ifdef SUPPORT_ALIPAY_SEC + { ALIPAYSECTEST, mcu_alipay_sec_test }, + { ALIPAYDEBUG, mcu_alipay_debug }, + { ALIPAYVERIFY, mcu_alipay_pl_verify }, + { ALIPAYRESET, mcu_alipay_reset }, +#endif +#ifdef SUPPORT_FILE_SPLIT_COMBINE + { FILESPLIT, mcu_file_spilt_test }, + { FILECOMBINE, mcu_file_combine_test }, +#endif +#ifdef JS_ENABLE + { GETTRANSCHAN, mcu_get_trans_channel_test }, + { SETTRANSCHAN, mcu_set_trans_channel_test }, +#endif +#ifdef SUPPORT_AUTO_OTA + { AUTOOTABLOCK, mcu_auto_ota_block }, + { AUTOOTARUN, mcu_auto_ota_run }, + { AUTOOTADELMAC, mcu_auto_ota_del_mac }, + { AUTOOTAADDMAC, mcu_auto_ota_add_mac }, + { AUTOOTASHOWMAC, mcu_auto_ota_show_mac }, +#endif +}; + +void app_at_process(uint8_t *data, uint32_t data_len) +{ + unused(data_len); + if (data == NULL) { + return; + } + int32_t ret = ERRCODE_FAIL; + uint8_t reply_data[DIAG_RES_LEN] = {0}; + app_msg_info_t *msg = (app_msg_info_t *)(data); + + for (uint32_t i = 0; i < ARRAY_COUNT(g_app_funcs); i++) { + if (msg->id == g_app_funcs[i].id) { + ret = g_app_funcs[i].func(msg->payload, msg->payload_len); + } + } + print_at_cmd_ret(ret); + + // phone remote control, need reply to spp + if (g_app_diag_flag) { + reply_data[0x0] = 0x80; + reply_data[0x1] = 0x82; + reply_data[0x2] = 0; + reply_data[0x3] = (uint8_t)ret; + ret = send_spp_diag_msg(g_app_diag_flag, &g_mcu_diag_header, reply_data, DIAG_RES_LEN); + wstp_print("mcu_at_process send msg to spp %s.\r\n", (ret == ERRCODE_SUCC) ? "success" : "failure"); + } + + if (ret != ERRCODE_SUCC) { + wstp_print("app_at_process func fail! MsgID=0x%x ret=%d "NEWLINE, msg->id, ret); + } + g_app_diag_flag = false; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/build/config/target_config/brandy/config.py b/sdk_release/v1.0/4gsdk_new/code/sdk/build/config/target_config/brandy/config.py new file mode 100644 index 000000000..4e37b1eea --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/build/config/target_config/brandy/config.py @@ -0,0 +1,328 @@ +#!/usr/bin/env python3 +# encoding=utf-8 +# ============================================================================ +# @brief Target Definitions File +# Copyright CompanyNameMagicTag 2022-2022. All rights reserved. +# ============================================================================ + +target = { + #target1: liteos + lvgl + nandflash + mipi + no psram + mini_audio 典型单封LVGL版本 + 'brandy-target1': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'std_libs': [], + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_ZDIAG_NV_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'MEMORY_MINI', 'ENABLE_LVGL', 'SW_UART_DEBUG', "SAVE_EXC_INFO", + "CONFIG_LOW_POWER_TEST", 'MIPI_ULPS_SUPPORT', 'ENABLE_ECC', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'CONFIG_NV_SUPPORT_ASYNCHRONOUS_STORE=0'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc','fs_yaffs2', 'x_vfs_private', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', + 'audio_at_service', 'media_at_service', 'bt_manager_at_service', + "audio_proc", "audio_dump", "audio_probe", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media_mini', 'gpu', 'graphic_lvgl_mini', 'bgh_audio', 'dfx_set'], + 'image_analysis': True, + 'dsp_version': 'mini', + 'packet': True, + 'fs_image': False, + }, + #target3: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + 'brandy-target3': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'ENABLE_UIKIT', 'SUPPORT_GPU_JPEG', 'SUPPORT_GPU_GMMU', 'SUPPORT_GPU_OPENVG', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'HASH_MEM_COPY','MIPI_ULPS_SUPPORT', 'CONFIG_LOW_POWER_TEST', + 'ENABLE_ECC', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', + 'audio_at_service', 'media_at_service', 'bt_manager_at_service', + "audio_proc", "audio_dump", "audio_probe", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'graphic_test', 'bgh_audio', 'dfx_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False + }, + #target4: liteos + nandflash + psram + mini_audio + no gui 外设类版本 + 'brandy-target4': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'std_libs': ['c++', 'c++abi', 'unwind'], + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'I2C_SLAVE_REG_ADDR_4BYTE', 'SUPPORT_CXX', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'HASH_MEM_COPY', + 'CONFIG_ZDIAG_NV_SUPPORT', 'SUPPORT_BLE', 'SUPPORT_BREDR', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'CONFIG_PSRAM_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', + 'CONFIG_LOW_POWER_TEST', 'CONFIG_ADC_SUPPORT_AUTO_SCAN', + 'CONFIG_ADC_SUPPORT_LONG_SAMPLE', 'ENABLE_ECC', 'CONFIG_DIAG_GPU_PROC_SUPPORT', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'partition', 'partition_brandy', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc','fs_yaffs2', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'app_at_service', + 'audio_at_service', 'bt_manager_at_service', "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'gpu', 'media_target4', 'update_app', 'dfx_set', 'bgh_audio', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False, + }, + #target5: freertos + lvgl + nand + mipi + psram + audio + media 典型合封LVGL版本 + 'brandy-target5': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_freertos_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SUPPORT_BLE', "SUPPORT_BREDR", 'ENABLE_LVGL', "SUPPORT_GPU_JPEG", "SUPPORT_GPU_GMMU", "SUPPORT_GPU_OPENVG", + 'SW_UART_DEBUG', 'MEMORY_NO_CACHE', "SAVE_EXC_INFO", "HASH_MEM_COPY", 'MIPI_ULPS_SUPPORT', + 'CONFIG_LOW_POWER_TEST', 'ENABLE_ECC', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + 'lcd', 'qspi_display', 'partition', 'partition_brandy', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd','graphic_at_service', 'app_at_service', + 'audio_at_service', 'media_at_service', 'bt_manager_at_service', + "audio_proc", "audio_dump", "audio_probe", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_lvgl', 'bgh_audio', 'update_app', 'dfx_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False + }, + #native-js: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + #用户可参考user版本,删除reg/mem dump + 'brandy-native-js': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'ENABLE_UIKIT', 'SUPPORT_GPU_JPEG', 'SUPPORT_GPU_GMMU', 'SUPPORT_GPU_OPENVG', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'HASH_MEM_COPY', 'JS_ENABLE', 'CONFIG_LOW_POWER_TEST', + 'FT_SINGLE_UART', + 'TPTYPE_FT6X46', + 'BOARD_FD230', + 'CFG_FLASH_SIZE=16', + 'SUPPORT_CAT1_SERVICE', + 'TEST_4G_SDK', + 'SUPPORT_BATTERY_SERVICE', + 'ENABLE_ECC', 'MIPI_ULPS_SUPPORT', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'bt_manager_at_service', + 'batterry_service', + 'huks_sdk', + 'cat1Service','cat1Test', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', 'x_vfs_private', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', 'ohosfwk_at_service', + "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc",'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': True + }, + #native-js-user: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + #离线日志版本 + #删除reg/mem dump,写法如下:'-:DUMP_MEM_SUPPORT', '-:DUMP_REG_SUPPORT', '-:SUPPORT_DFX_EXCEPTION' + 'brandy-native-js-user': { + 'base_target_name': 'brandy-native-js', + 'defines': ['-:SW_UART_DEBUG', '-:DUMP_MEM_SUPPORT', '-:DUMP_REG_SUPPORT', '-:SUPPORT_DFX_EXCEPTION'], + }, + #auto-ota-server + 'brandy-auto-ota-ser': { + 'base_target_name': 'brandy-native-js', + 'defines': ['SUPPORT_AUTO_OTA_SERVER', 'CONFIG_DFX_SUPPORT_DIAG_UP_MACHINE=1'], + }, + #auto-ota-client + 'brandy-auto-ota-cli': { + 'base_target_name': 'brandy-native-js', + 'defines': ['SUPPORT_AUTO_OTA_SERVER', 'SUPPORT_AUTO_OTA', 'CONFIG_DFX_SUPPORT_DIAG_UP_MACHINE=1'], + 'ram_component': ['auto_ota'] + }, + #native-xts: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + 'brandy-xts': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'ENABLE_UIKIT', 'SUPPORT_GPU_JPEG', 'SUPPORT_GPU_GMMU', 'SUPPORT_GPU_OPENVG', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'HASH_MEM_COPY', 'JS_ENABLE', 'CONFIG_LOW_POWER_TEST', + 'ENABLE_ECC', 'XTS_SUPPORT', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', 'x_vfs_private', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', 'ohosfwk_at_service', + "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'xts_set', 'xts_test_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False + }, + + 'brandy-target1-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'MEMORY_MINI', 'SW_UART_DEBUG', + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-target3-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', "HASH_MEM_COPY", + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-target4-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', 'HASH_MEM_COPY', + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'pm_service', 'pm_brandy', + 'ulp_aon', 'hal_l2ram', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-target5-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_freertos_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", "__FREERTOS__", 'ENABLE_UIKIT', 'SW_UART_DEBUG', + "HASH_MEM_COPY", 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'pm_service', 'pm_brandy', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-native-js-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', "HASH_MEM_COPY", + 'FT_SINGLE_UART','TPTYPE_FT6X46','CFG_FLASH_SIZE=16', + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header', + 'at_cmd' + ], + 'ram_component_set': ['pinctrl', 'dfx_set' ,'gpu'] + }, + 'brandy-xts-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', "HASH_MEM_COPY", + 'ENABLE_ECC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set'] + }, + 'testsuite-brandy-sdk': { + 'base_target_name': 'target_brandy_testsuite_application', + 'board': 'evb', + 'defines': ['SW_UART_DEBUG', 'USE_CMSIS_OS', 'CFG_DRIVERS_NANDFLASH', + 'PRE_ASIC', 'BRANDY_PRODUCT_EVB4', + '_ALL_SOURCE', '__LITEOS__', 'SUPPORT_CXX', 'ENABLE_UIKIT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'MULTIPLEXING_UART', + 'CONFIG_SPI_SUPPORT_POLL_AND_DMA_AUTO_SWITCH', 'CONFIG_SPI_AUTO_SWITCH_DMA_THRESHOLD=0x8', + 'CONFIG_I2C_SUPPORT_POLL_AND_DMA_AUTO_SWITCH', 'CONFIG_I2C_POLL_AND_DMA_AUTO_SWITCH_THRESHOLD=0x8'], + 'ram_component': ["osal", "arch_port", "liteos_port", 'psram', 'pm_service', 'pm_brandy', + 'hal_mips', 'lcd', 'qspi_display', 'hal_dma_v100', "dfx_port_brandy", + 'dfx_log_brandy', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', 'ulp_aon', + 'hal_l2ram', "test_security", "test_spi", 'dfx_file_operation', + "test_timer", "test_int", "test_pm", + "test_lcd", "test_qspi_display", "test_systick", "test_tcxo", "test_watchdog", + "test_vfs_emmc", "test_flash", "test_pwm", "test_i2c", "test_cmsis", + "test_xip", "test_mipi", "test_touch", 'algorithm', 'test_sdio', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2' , 'nand_flash' , 'mtd_com', + 'cmn_header', 'test_calendar', 'test_gpio', 'test_pinctrl', 'test_dma', 'test_uart', + 'test_reboot', 'test_rtc_unified', + 'test_nandflash', 'test_adc', 'test_pmp', 'efuse', 'hal_efuse_v100', 'efuse_porting'], + 'ram_component_set': ['dfx_set', '-:gpu_test', 'rtc_unified'], + 'os': 'liteos', + }, + 'brandy-ssb': { + 'base_target_name': 'target_ssb_template_brandy', + 'board': 'evb', + 'defines': ["-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", "PRE_ASIC", "BRANDY_PRODUCT_EVB4", + "SSB_USE_PLL", "VERSION_STANDARD", "BUILD_APPLICATION_SSB", "LIBBOOTLOADER", "LIBCODELOADER", + "LIBCPU_UTILS", "LIBAPP_VERSION", "LIBPANIC", "LIBCONNECTIVITY", "LIBERROR_CODE", "LIBSEC_RANDOM", + "LIBCODELOADER_SSB", "LIBJLINK_LOAD", "LIBLIB_UTILS", "LIBBUILD_VERSION", + 'ENABLE_ECC', + "CFG_DRIVERS_NANDFLASH", + 'CFG_FLASH_SIZE=16', + "NO_TIMEOUT", "CONFIG_UART_BAUD_RATE_DIV_8", 'SW_UART_DEBUG', 'LARGE_BUFFER', + 'FT_SINGLE_UART' + ], + 'ram_component': ['arch_port', 'hal_l2ram', 'sec_boot', 'libboundscheck', + 'dfx_exception', 'error_code', 'psram', 'osal', 'cmn_header', 'boot_ulp', 'boot_nandflash', 'boot_emmc'], + 'ram_component_set': ['pinctrl'], + 'target': 'ssb', + } +} + +target_group = { + # ci protect target list + 'pack_brandy_target1': ['brandy-ssb', 'brandy-target1-r', 'brandy-target1'], + 'pack_brandy_target3': ['brandy-ssb', 'brandy-target3-r', 'brandy-target3'], + 'pack_brandy_target4': ['brandy-ssb', 'brandy-target4-r', 'brandy-target4'], + 'pack_brandy_target5': ['brandy-ssb', 'brandy-target5-r', 'brandy-target5'], + 'pack_brandy_native_js': ['brandy-ssb', 'brandy-native-js-r', 'brandy-native-js'], + 'pack_brandy_native_js_user': ['brandy-ssb', 'brandy-native-js-r', 'brandy-native-js-user'], + 'pack_brandy_xts': ['brandy-ssb', 'brandy-xts-r', 'brandy-xts'], + + 'brandy_all': ['brandy-ssb', + 'brandy-target1', 'brandy-target3', 'brandy-target4', 'brandy-target5', 'brandy-native-js', 'brandy-native-js-user', 'brandy-xts', + 'brandy-target1-r', 'brandy-target3-r', 'brandy-target4-r', 'brandy-target5-r', 'brandy-native-js-r', 'brandy-xts-r', + 'testsuite-brandy-sdk'] +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h new file mode 100644 index 000000000..887e38351 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h @@ -0,0 +1,301 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2018-2021. All rights reserved. + * Description: brandy evb board config + * Author: @CompanyNameTag + * Create: 2020-02-19 + */ +#ifndef BOARD_EVB_CONFIG_H +#define BOARD_EVB_CONFIG_H + +#include "pinctrl_porting.h" +#include "gpio_porting.h" +#include "platform_types.h" + +// #ifdef SUPPORT_CAT1_SERVICE +// #include "cat1_ctl.h" +// #endif + +/** + * @addtogroup connectivity_config_boards + * @{ + */ +/** + * @brief Global evb pio functions. + */ +const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO0 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO1 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO2 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO3 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO4 clk + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO5 cs + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO6 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO7 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO8 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO9 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO10 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO11 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO12 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO13 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO14 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO15 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO16 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO17 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO18 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO19 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO20 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO21 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO22 clk + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO23 ce + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO24 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO25 + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO0 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO1 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO2 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO3 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO4 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO5 NC +#if (defined CFG_DRIVERS_NANDFLASH) + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO6 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO7 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO8 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO9 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_HGPIO10 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_HGPIO11 cs0 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_HGPIO12 cs1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_HGPIO13 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_HGPIO14 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_HGPIO15 clk +#else + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO6 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO7 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO8 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO9 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO10 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO11 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO12 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO13 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO14 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO15 emmc clk +#endif + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO0 NC + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO1 NC + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO2 NC + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO3 NC + +// #if (defined BRANDY_PRODUCT_EVB4) + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO4 NC +// #else + // { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO4 NC +// #endif + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO5 NC +#ifdef A5133_USE_HW_SPI + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_MGPIO6 SPI1 DI + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_MGPIO7 SPI1 DO + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_MGPIO8 SPI1 CLK + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_MGPIO9 SPI1 CS0 + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO10 SPI1 CS1 NC +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_MGPIO6 SPI1 DI + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_MGPIO7 SPI1 DO + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO8 SPI1 CLK + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO9 SPI1 CS0 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO10 SPI1 CS1 NC +#endif + { HAL_PIO_FUNC_I2C0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO11 i2c0 SCL NC + { HAL_PIO_FUNC_I2C0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO12 I2C0 SDA + { HAL_PIO_FUNC_I2C1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO13 I2C1 SCL touch i2c + { HAL_PIO_FUNC_I2C1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO14 I2C1 SDA + { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO15 I2C2 SCL Sensor 6�� ָ���� ���� + { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO16 I2C2 SDA Sensor + { HAL_PIO_FUNC_I2C3_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO17 i2c3 SCL smart pa\ Ԥ��������� \��ȫоƬ + { HAL_PIO_FUNC_I2C3_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO18 I2C3 SDA + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO19 uart1 tx + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO20 uart1 rx + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO21 uart1 rts + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO22 uart1 cts + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO23 NC + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO24 NC + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO25 NC + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO26 NC +#if (defined QSPI_DISPLAY) + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO27 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO28 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO29 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO30 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO31 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO32 +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO27 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO28 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO29 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO30 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO31 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO32 +#endif + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO33 huart tx + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO34 huart rx + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO35 + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO36 +#if 0 + { HAL_PIO_FUNC_UART2_M2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO37 uart tx + { HAL_PIO_FUNC_UART2_M2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO38 uart rx +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO37 uart tx NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO38 uart rx NC +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L0 NC + + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L1 i2s1 + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L2 + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L3 + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L4 + + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L5 + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L6 i2s0 + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L7 + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L8 + +#if (defined FT_BT_UART) + { HAL_PIO_FUNC_UART2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L9 uart2 txd + { HAL_PIO_FUNC_UART2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_AGPIO_L10 uart2 rxd +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L9 dsp uart TP35 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L10 dsp uart TP36 +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_AGPIO_L11 G_INT1 + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L12 i2c data HX3507_SDIO + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L13 i2c CLK HX3507_SCLK + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L14 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L15 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L16 NC + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L17 HX3507_INT not use + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L18 VDDEN //��ʱ���ã�����VDDIO Ĭ�Ͽ��� EXt V3.0 EXt V1.8 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_AGPIO_L19 G_INT2 //��ʱ���� + + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_AGPIO_L20 0.2C_CHRG + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L21 NTC_VDD_ON 给低打开 NTC上拉电源 +#ifdef QSPI_DISPLAY + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L22 QSPI TE +#else + { HAL_PIO_FUNC_TE, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L22 MIPI TE +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L23 CAT_1_PWR_ON ����CAT_1�����ţ����߿��� CAT1��Դ ������Ч + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L24 LCM_EN + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L25 //////////// audio pa reset + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L26 ���ʸ�λ PPG reset + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L27 LCM reset +#ifdef SUPPORT_A5133_SERVICE + //{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_AGPIO_L28 CAT_1复位 CAT1_RESET_N 拉低有效 +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L28 CAT_1复位 CAT1_RESET_N 拉低有效 +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L29 charge done info 检测是否充满电 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L30 KP_MKIN1 唤醒 CAT1 ,输出 +#ifdef SUPPORT_A5133_SERVICE + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L31 控制A5133开关 +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L31 KP_MKOUIT1 唤醒 蓝牙 ,输入 +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_L32 NC + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R0 PRG_LED_POWER ON ���ʵȵ�Դ���ƽ� + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R1 SE_REST ��ȫоƬ��λ���ѽ� + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 VIBR_PWM ������ƽ� ����Ԥ������������λ�� + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_R3 NC + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_AGPIO_R4 tp reset + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R5 touch int + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R6 PRG_INT �����ж� + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R7 GYRO_INT2 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R8 GYRO_INT1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R9 BAT_CHARGE_OFF �ص���� �¶ȸߵ�ʱ�� + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R10 Key2 ///////////////////HAL_PIO_IE_ENBALE input enable + +#if CORE == APPS + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO0 mode not config + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO1 mode not config + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO2 mode not config + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO3 mode not config + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO4 + { HAL_PIO_FUNC_SWD, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // ULP_GPIO5 + { HAL_PIO_FUNC_SWD, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // ULP_GPIO6 +#endif +}; +/** + * @} + */ + + +/** + * @addtogroup connectivity_config_boards + * @{ + */ +/** + * @brief Global evb gpio functions. + * + * + * typedef struct { + pin_t gpio; + hal_gpio_direction_t direction; + hal_gpio_level_t level; + uint32_t triger; + hal_gpio_callback_t callback; +} hal_gpio_config_t; + */ + + +#define DEFAULT_POWERON_CAT1 1 + +const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { + +#if DEFAULT_POWERON_CAT1 + // S_AGPIO_L23 CAT_1_PWR_ON ----- high power on + { S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, + // S_AGPIO_L28 Cat1 reset ---- low reset + { S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, +#else + // S_AGPIO_L23 CAT_1_PWR_ON ----- high power on + { S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + // S_AGPIO_L28 Cat1 reset ---- low reset + { S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, +#endif + // S_AGPIO_L12 SDIO_BT + { S_AGPIO_L12, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + // S_AGPIO_L13 SCLK_BT + { S_AGPIO_L13, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + + // S_AGPIO_L26 PPG reset + { S_AGPIO_L26, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + // S_AGPIO_R0 PRG_LED_POWER ON + { S_AGPIO_R0, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + + //S_AGPIO_L21 NTC_VDD_ON NTC + { S_AGPIO_L21, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, +#if 0 //默认正常充电 +// #define GPIO_PIN_ENABLE_CHARGE S_AGPIO_R9 //low enable +// #define GPIO_PIN_ENABLE_CHARGE_0_2C S_AGPIO_L20 //low 0.2c 低电流充电 + { S_AGPIO_R9, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + { S_AGPIO_L20, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, +#else + { S_AGPIO_R9, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, + { S_AGPIO_L20, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, +#endif + + { S_AGPIO_R2, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, +// EXT LDO V3.0 V1.8 + { S_AGPIO_L18, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, + + /**S_AGPIO_R1 GPO alipay resetpin*/ + { S_AGPIO_R1, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, + +}; +/** + * @} + */ +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/boards/brandy_evb/product/product_evb4_standard.h b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/boards/brandy_evb/product/product_evb4_standard.h new file mode 100644 index 000000000..5a917df45 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/boards/brandy_evb/product/product_evb4_standard.h @@ -0,0 +1,235 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2020-2023. All rights reserved. + * Description: product EVB4 standard config + * Author: @CompanyNameTag + * Create: 2023-03-07 + */ +#ifndef PRODUCT_EVB4_STANDARD_CONFIG_H +#define PRODUCT_EVB4_STANDARD_CONFIG_H + +/** + * @defgroup connectivity_config_product PRODUCT + * @ingroup connectivity_config + * @{ + */ +/* Platform board config, need check if it support or not carefully. */ +#define BTH_WITH_SMART_WEAR YES +#define APP_WRITE_OTP_ENABLE NO +#define APP_HEAP_SIZE 0x18000 // the minimum APP heap size (96kB) +#define USE_FLASH_SUSPEND_AND_RESUME NO +#define WAIT_APPS_DUMP_FOREVER NO +#define TWS_MPU_XIP_PROTECT NO +#define SSB_IMAGE_PAGES 27 +#ifdef CONFIG_LOW_POWER_TEST +#define ENABLE_LOW_POWER YES +#else +#define ENABLE_LOW_POWER NO +#endif +#if defined(CFG_FLASH_SIZE) && (CFG_FLASH_SIZE == 16) +#define DTB_IMAGE_PAGES 0 +#define RECOVERY_IMAGE_PAGES 256 +#define RESERVE_IMAGE_PAGES 64 +#define BT_IMAGE_PAGES 112 +#define HIFI0_IMAGE_PAGES 192 +#define HIFI0_CODEC_PAGES 448 +#define APP_IMAGE_PAGES 2048 +#else +#define DTB_IMAGE_PAGES 0 +#define RECOVERY_IMAGE_PAGES 64 +#define RESERVE_IMAGE_PAGES 0 +#define BT_IMAGE_PAGES 112 +#define HIFI0_IMAGE_PAGES 112 +#define HIFI0_CODEC_PAGES 320 +#define APP_IMAGE_PAGES 1353 +#endif +#define NV_IMAGE_PAGES 4 +#define FOTA_IMAGE_PAGES 3 +#define FOTA_IMAGE_START 0x770000 +#define SSB_FOTA_OFFSET 0x0 +#define XO_CTRIM_VALUR_DEFAULT 0x56 +#define DSP1_IPC_ENABLE NO +#define APP_BTN_TASK_MONITOR_ENABLE NO +#define SSB_FOTA_MODE_TWS YES +#define DSP_EXTEND_OCRAM_SIZE 1310720 // Unit byte, = 1280 KB +#define OSC_EN_CALLBACK_BY_PLT YES +#define BT_MIPS_DEBUG NO +#define NON_OS_CRITICAL_RECORD NO +#define ENABLE_MASSDATA_RECORD NO +#define USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG NO +#define COMPRESS_LOG_TRIGGER_THRESHOLD 0 +#define COMPRESS_LOG_COUNT_THRESHOLD 0xFFFFFFFF +#define EXCEPTION_TEST_ENABLE NO +#define LOG_LEVEL_APP_DEFAULT_CONFIG 3 // Info level +#define LOG_LEVEL_BT_DEFAULT_CONFIG 3 // Info level +#define LOG_LEVEL_DSP_DEFAULT_CONFIG 3 // Info level +#define BCPU_HEAP_MININUM_SIZE 0xA000 // 40KB +#define SYS_DEBUG_MODE_ENABLE YES +#define PROMPT_TONE_REGION_LENGTH 0x2800 +#define AUDIO_DATA_STREAM_REGION_LENGTH 0x2000 +#define BT_MASSDATA_LENGTH 0x400 +#define APP_MASSDATA_LENGTH 0x800 +#define APP_LOGGING_LENGTH 0x1C00 +#define DSP_LOGGING_LENGTH 0x2000 +#define PSRAM_DENSITY_MB 32 +#define RC_CLOCK_ON NO +#define SMART_WATCH_BT_COEX_PIN_SWITCH NO // pinmux switch in the Coexistence of BT and WiFi of smart watch +#define CAP_SENSOR_BUFF_LEN 128 +#define BT_L2RAM_AREA_SIZE 3 // 384k, Reference the enum Value of hal_b_memory_share_config_t +#define DSP_L2RAM_AREA_TOTAL 10 +#define GPU_L2RAM_AREA_TOTAL 11 +#ifndef CONFIG_PSRAM_SUPPORT +#define DSP_L2RAM_AREA_SIZE 6 // 无PSRAM & 小型化场景分配给DSP 6块*128K=768KB 剩余512K系统使用 +#else +#if defined(CONFIG_SEA_PHS_SUPPORT) +#define DSP_L2RAM_AREA_SIZE 10 // 语音唤醒场景分配给DSP 10块*128K=1280KB DSP L2M不给系统使用 +#else +#define DSP_L2RAM_AREA_SIZE 8 // 正常场景分配给DSP 8块*128K=1024KB 剩余256K系统使用 +#endif /* CONFIG_SEA_PHS_SUPPORT */ +#endif /* CONFIG_PSRAM_SUPPORT */ +#define PUYA_FLASH_SUPPORT YES + +/********************display config********************/ +#define DOUBLE_BUFFER 1 +#if defined(QSPI_DISPLAY) +#define RESOLUTION_WIDTH 194 +#define RESOLUTION_HEIGHT 368 +#elif defined(MEMORY_MINI) +#define RESOLUTION_WIDTH 240 +#define RESOLUTION_HEIGHT 296 +#elif defined(SUPPORT_SOFT_SEND_FRM) +#define RESOLUTION_WIDTH 368 +#define RESOLUTION_HEIGHT 448 +#else +#define RESOLUTION_WIDTH 466//454 +#define RESOLUTION_HEIGHT 466//454 +#endif + +/********************Other module board config********************/ +#define BTC_SWITCH_COEX YES +#define BTC_SMART_WEAR_WLCOEX YES +#define BTC_WITH_SMART_WEAR YES +#define BTC_TWS_MONITOR YES +#define BTC_ICO_SUPPORT YES +#define BTC_DUAL_ANT_SWITCH_SUPPORT NO +#define BTC_GET_EMC_FROM_PLATFORM YES // 后续耳机产品通过HCI传递NV数据实现后,该选项需要置为NO +#define BTSNOOP_ENABLE NO +#define TWS_USER_CHR_RECORD NO +#define BTH_WEAR_ENABLE_AUDIO_SINK NO +#define BTH_WEAR_ENABLE_AUDIO_GATEWAY NO +#define BTH_WEAR_BREDR_DOUBLE_CONNECT NO +#define BTC_DFX_LOG_HELP_SUPPORT NO +#define FACTORY_CALI NO +#define BTH_WEAR_ENABLE_CONNECT_MANAGER NO +#define BTH_WEAR_ENABLE_BLE_FEATURES YES +#define BTH_WEAR_ENABLE_HFP_FEATURES NO +#define WEAR_USER_CONFIG NO +#define BTH_HIGH_POWER YES +#define MULTI_CONNECT YES +#define BTH_CONFIG_HDAP YES +#define DEVICE_MANAGE_FEATURE YES +#define BTH_CALL_LC3_32K YES +#define BTH_ENABLE_LC3_CODEC YES +#define ENABLE_CHANGE_DEVICE_NAME YES +#define BTH_DIP_PRODUCT_ID 0x4106 +#define BTH_ENABLE_L2HC_CODEC YES +#define ENABLE_BT_XO_16M NO +#define BTH_WSTP_CMD_SUPPORT YES +#define PRODUCT_SUPPORT_MODE_SWITCH YES +#define BT_MANAGER_DEPLOYED 2 +#define BT_CODEC_TID 2 +#define BTH_WEAR_ENABLE_AVRCP_TARGET NO +#define BTH_WEAR_ENABLE_AVRCP_CONTROLLER NO +#define BTH_WEAR_ENABLE_AUDIO_SOURCE NO +#define BTH_WEAR_ALLOW_INQUIRY_SCAN YES +#define BTH_WEAR_ENABLE_HALL_STATE NO + +// 音频内置输入设备 +#define BUILTIN_AI_PORT 0x50 // 参考 soc_uapi_ai.h 中 UAPI_AI_PORT_LPADC0 枚举 +#define BUILTIN_AI_PORT_ATTR_ADC_RX_TYPE 0 // 参考 soc_uapi_ai.h 中 UAPI_AI_RX_DEFAULT 枚举 +#define BUILTIN_AI_PCM_ATTR_AUDIO_CH 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_1 枚举 +#define BUILTIN_AI_PCM_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define BUILTIN_AI_PCM_ATTR_SAMPLE_RATE 16000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_16K 枚举 +#define BUILTIN_AI_PCM_ATTR_FRAME_PER_SEC 100 // 每秒帧数 + +// 音频内置输出设备 +#define BUILTIN_SND_OUT_PORT 0x10 // 参考 soc_uapi_sound.h 中 UAPI_SND_OUT_PORT_I2S0 枚举 +#define BUILTIN_SND_OUT_PORT_NUM 1 // 端口个数 +#define BUILTIN_SND_OUT_AUDIO_CH 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define BUILTIN_SND_OUT_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define BUILTIN_SND_OUT_SAMPLE_RATE 48000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_48K 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_BCLK 8 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_BCLK_8_DIV 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_AUDIO_CH 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_STD_MODE 0 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_STD_MODE 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_MASTER 1 // 1:主设备,0:从设备 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_MCLK 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_MCLK_256_FS 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_PCM_DELAY 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_PCM_1_DELAY 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_SAMPLE_RISE_EDGE 1 // 参考 soc_uapi_audio.h 中 pcm_sample_rise_edge 成员 + +// 音频外挂输入设备 +#define EXTERNAL_AI_PORT 1 // 参考 soc_uapi_ai.h 中 UAPI_AI_PORT_I2S1 枚举 +#define EXTERNAL_AI_I2S_ATTR_MASTER 0 // 1:主设备,0:从设备 +#define EXTERNAL_AI_I2S_ATTR_I2S_MODE 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_PCM_MODE 枚举 +#define EXTERNAL_AI_I2S_ATTR_MCLK 6 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_MCLK_1536_FS 枚举 +#define EXTERNAL_AI_I2S_ATTR_BCLK 48 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_BCLK_48_DIV 枚举 +#define EXTERNAL_AI_I2S_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_AI_I2S_ATTR_AUDIO_CH 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_AI_I2S_ATTR_SAMPLE_RISE_EDGE 1 // 参考 soc_uapi_audio.h 中 pcm_sample_rise_edge 成员 +#define EXTERNAL_AI_I2S_ATTR_PCM_DELAY_CYCLE 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_PCM_1_DELAY 枚举 +#define EXTERNAL_AI_PCM_ATTR_CHANNELS 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_AI_PCM_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_AI_PCM_ATTR_SAMPLE_RATE 8000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_16K 枚举 +#define EXTERNAL_AI_PCM_ATTR_FRAME_PER_SEC 50 // 每秒帧数 , EG810 pcm 20ms 一帧 + +// 音频外挂输出设备 +#define EXTERNAL_SND_OUT_PORT 0x11 // 参考 soc_uapi_sound.h 中 UAPI_SND_OUT_PORT_I2S1 枚举 +#define EXTERNAL_SND_OUT_AUDIO_CHANNEL 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_SND_OUT_AUDIO_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_SND_OUT_AUDIO_SAMPLE_RATE 8000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_16K 枚举 +#define EXTERNAL_SND_OUT_PORT_NUM 1 // 端口个数 +#define EXTERNAL_SND_OUT_I2S_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_SND_OUT_I2S_ATTR_CHANNEL 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_SND_OUT_I2S_ATTR_I2S_MODE 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_PCM_MODE 枚举 +#define EXTERNAL_SND_OUT_I2S_ATTR_MCLK 6 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_MCLK_1536_FS 枚举 12.288M /16k = +#define EXTERNAL_SND_OUT_I2S_ATTR_MASTER 0 // 1:主设备,0:从设备 +#define EXTERNAL_SND_OUT_I2S_ATTR_SAMPLE_RISE_EDGE 1 // 参考 soc_uapi_audio.h 中 pcm_sample_rise_edge 成员 +#define EXTERNAL_SND_OUT_I2S_ATTR_BCLK 48 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_BCLK_48_DIV 枚举 12.288M / 256k = 48 + +// Sleep option +#define CONFIG_PM_TICKLESS_EN YES +#define CONFIG_PM_POWER_GATING_EN YES +#define CONFIG_PM_SLEEP_RECORD_EN YES +#define CONFIG_PM_VETO_TRACK_EN NO +#define CONFIG_PM_SLEEP_INT_EN NO + +// Double-click the key +#define CONFIG_SUPPORT_BUTTON_DOUBLE_CLICK NO + +// LCD VCI_EN +#define VCI_LCD_GPIO S_AGPIO_L24 +#define DISPLAY_TE_GPIO S_AGPIO_L22 +#define RESET_LCD_GPIO S_AGPIO_L27 + +// TP CONFIG +#define ZTW523_I2C_BUS I2C_BUS_1 +#define ZTW523_INT_GPIO S_AGPIO_R5 +#define ZTW523_RESET_GPIO S_AGPIO_R4 +#define TMA525B_I2C_BUS I2C_BUS_1 +#define TMA525B_INT_GPIO S_AGPIO_R5 +#define TMA525B_RESET_GPIO S_AGPIO_R4 + +// TRACK MODE +#define SND_TRACK_MODE_BT_MUSIC 0 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_STEREO 枚举 +#define SND_TRACK_MODE_BT_SCO 1 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_DOUBLE_MONO 枚举 +#define SND_TRACK_MODE_LOCAL_CAT1 1 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_DOUBLE_MONO 枚举 +#define SND_TRACK_MODE_BT_CAT1 0 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_STEREO 枚举 +#define SND_TRACK_MODE_LOCAL_MUSIC 1 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_DOUBLE_MONO 枚举 + + +#define FT6X46_I2C_BUS I2C_BUS_1 +#define FT6X46_INT_GPIO S_AGPIO_R5 +#define FT6X46_RESET_GPIO S_AGPIO_R4 +/** + * @} + */ +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c new file mode 100644 index 000000000..025bdb90e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c @@ -0,0 +1,484 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: CLOCKS CONFIG PRIVATE SOURCE. + */ +#include "clocks_config_priv.h" +#include "product.h" + +#if !defined(BUILD_APPLICATION_ROM) +// FVCO : FREF *(FBDIV+FRAC/(2^24))/REFDIV ;CLK_PLL:FVCO/POSTDIV1/POSTDIV2 +static cmu_pll_config_t g_pll_cfg = { + PLL_FBDIV_NUM, + PLL_FRAC_H_NUM, + PLL_FRAC_L_NUM, + PLL_POSTDIV1_NUM, + PLL_POSTDIV2_NUM, +}; + +#ifdef BUILD_APPLICATION_SSB +static clocks_clk_cfg_t g_ssb_clk_cfg[CLOCKS_CCRG_MODULE_MAX] = { + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4 }, // CLOCKS_CCRG_MODULE_MCU_CORE + { CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8 }, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + { CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9 }, // CLOCKS_CCRG_MODULE_COM_BUS + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3 }, // CLOCKS_CCRG_MODULE_SDIOM + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5 }, // CLOCKS_CCRG_MODULE_MEM_BUS + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4 }, // CLOCKS_CCRG_MODULE_XIP_OPI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8 }, // CLOCKS_CCRG_MODULE_XIP_QSPI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6 }, // CLOCKS_CCRG_MODULE_GPU + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6 }, // CLOCKS_CCRG_MODULE_HIFI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36 }, // CLOCKS_CCRG_MODULE_CODEC + { CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_PAD_OUT0 + { CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_PAD_OUT1 + { CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_PAD_OUT2 +}; +#else +/************************** System clock Config ***********************/ +static const clocks_clk_cfg_t g_system_all_core_clocks[CLOCKS_CONFIG_MAX][CLOCKS_CCRG_MODULE_MAX] = { + /* All 32M */ + { + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + }, + /* All 64M */ + { + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, + /* PLL */ + { + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, + /* PLL 0.9v */ + { + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_10}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, + /* test */ + { + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_4}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, +}; + +/************************** System core clock Config ******************/ +static const system_clocks_freq_config_t g_system_clocks_freq_config[CLOCKS_FREQ_MAX] = { + { // CLOCKS_M32_B32_D_0 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M32_B32_D_1 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M32_B32_D_2 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:98M + }, + { // CLOCKS_M32_B32_D_3 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M32_B32_D_4 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M32_B32_D_5 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M32_B64_D_0 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M32_B64_D_1 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M32_B64_D_2 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:98M + }, + { // CLOCKS_M32_B64_D_3 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M32_B64_D_4 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M32_B64_D_5 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M64_B32_D_0 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M64_B32_D_1 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M64_B32_D_2 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:96.7M + }, + { // CLOCKS_M64_B32_D_3 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M64_B32_D_4 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M64_B32_D_5 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M64_B64_D_0 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M64_B64_D_1 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M64_B64_D_2 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:96.7M + }, + { // CLOCKS_M64_B64_D_3 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M64_B64_D_4 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M64_B64_D_5 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M_H_B64_D_H + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // mcu:221M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, +}; + +static const system_display_freq_config_t g_system_display_freq_config[CLOCKS_DISPLAY_FREQ_MAX] = { + { // CLOCKS_DISPLAY_FREQ_0 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // opi:32M -> psram:16M + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // gpu:closed + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // membus:follow mcu_clk/2 + }, + { // CLOCKS_DISPLAY_FREQ_1 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // opi:64M -> psram:32M + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // gpu:closed + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // membus:follow mcu_clk/2 + }, + { // CLOCKS_DISPLAY_FREQ_2 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // psram:147M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // gpu:110M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // membus:110M + }, + { // CLOCKS_DISPLAY_FREQ_3 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // psram:133M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // gpu:159.6M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // membus:199.5M + }, + { // CLOCKS_DISPLAY_FREQ_4 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // psram:159M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // gpu:190.8M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // membus:190.8M + }, +}; + +/************************** MCU core clock Config *********************/ +static const system_mcu_core_clk_cfg_t g_system_mcu_freq_config[CLOCKS_MCU_FREQ_MAX] = { + { // CLOCKS_M_H16 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_2}, // mcu_clk:16M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // psram_clk:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_2}, // membus:16M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // flash: norflash & nandflash:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // sdiom:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // gpu:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // spi:32M + }, + { // CLOCKS_M32 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu_clk:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // psram_clk:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // membus:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // flash: norflash & nandflash 32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // sdiom: 32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // gpu: 32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // spi: 32M + }, + { // CLOCKS_RC + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // mcu_clk:49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // psram_clk:49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // membus:49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // flash: norflash & nandflash 49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // sdiom: 49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // gpu: 49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // spi: 49.152M + }, + { // CLOCKS_M64 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu_clk:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // psram_clk:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // membus:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // flash: norflash & nandflash 64M +#if defined (CFG_DRIVERS_MMC) + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // sdiom: 64M +#else + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // sdiom: 64M +#endif + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // gpu: 64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // spi: 64M + }, + { // CLOCKS_M_H0 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // mcu_clk:110M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // psram_clk:225M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // membus:110M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // flash: norflash & nandflash: 176M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // sdiom:295M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // gpu:147M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // spi:98M + }, + { // CLOCKS_M_H1 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // mcu_clk:221M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // psram_clk:295M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // membus:177M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // flash: norflash & nandflash:177M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // sdiom:295M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // gpu:147M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_10}, // spi:88M + }, +}; + +static const clocks_clk_cfg_t g_system_sdio_freq_config[CLOCKS_SDIO_FREQ_MAX] = { + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // 32M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // 50M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // 64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // 294.912M +}; + +/************************** MCU core all perips clock Config *********************/ +static const system_mcu_perip_clk_t g_system_mcu_perp_clk_set_config[] = { + /* Clocks M_CLKEN0 region */ + {HAL_CLOCKS_APP_SEC_CLK, TURN_ON}, // sec clock + {HAL_CLOCKS_APP_DIAG_CLK, TURN_ON}, // diag clock + {HAL_CLOCKS_APP_PWM_CLK, TURN_OFF}, // pwm clock + {HAL_CLOCKS_APP_X2H_MEM_BUS_CLK, TURN_ON}, // x2h_mem_bus clock + + /* Clocks M_CLKEN1 region */ + {HAL_CLOCKS_APP_TIMER_CLK, TURN_ON}, // timer clock + {HAL_CLOCKS_APP_SPI0_M_CLK, TURN_OFF}, // spi0 clock + {HAL_CLOCKS_APP_SPI1_MS_CLK, TURN_OFF}, // spi1 clock + {HAL_CLOCKS_APP_SPI2_MS_CLK, TURN_OFF}, // spi2 clock + {HAL_CLOCKS_APP_UART_H0_CLK, TURN_ON}, // uart h0 clock + {HAL_CLOCKS_APP_UART_H1_CLK, TURN_ON}, // uart h1 clock + {HAL_CLOCKS_APP_I2C0_CLK, TURN_OFF}, // i2c0 clock + {HAL_CLOCKS_APP_I2C1_CLK, TURN_ON}, // i2c1 clock + {HAL_CLOCKS_APP_I2C2_CLK, TURN_ON}, // i2c2 clock + {HAL_CLOCKS_APP_I2C3_CLK, TURN_ON}, // i2c3 clock + {HAL_CLOCKS_APP_QSPI_1CS_CLK, TURN_ON}, // qspi clock + {HAL_CLOCKS_APP_XIP_BUS_CLK, TURN_ON}, // xip bus clock + {HAL_CLOCKS_APP_COM_BUS_DSP_CLK, TURN_ON}, // com bus dsp clock + {HAL_CLOCKS_APP_BT_TGTWS_CLK, TURN_ON}, // bt tgws clock no closed will affect bt call + + /* Clocks M_CLKEN2 region */ + {HAL_CLOCKS_APP_PULSE_CAPTURE_CLK, TURN_OFF}, // pulse_capture_clken clock + {HAL_CLOCKS_APP_M_DAP_CLK, TURN_ON}, // m_dap_clken clock + {HAL_CLOCKS_APP_RC_CLK, TURN_ON}, // rc clock + {HAL_CLOCKS_APP_XO_CLK, TURN_ON}, // xo clock +}; +#endif + +/*********************** clk cg config **********************************/ +#if (CLK_AUTO_CG_ENABLE == YES) +static const system_clk_cg_t g_system_clkcg_config[] = { + {HAL_CLOCKS_MODULE_AUTO_CG_COM_BUS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_CACHE, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MEM_AHB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AON, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_BT, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_MAIN, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_SDIO_M, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SDIO_CFG, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DISPLAY, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_CFG, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MAIN_AXI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DISPLAY_AXI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_PERP_AXI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_OPI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_FCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_TCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_SDIO, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_BSUB_FCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_BSUB_TCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_APB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AH2H_MCU_SUB_TAON, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AH2H_MCU_SUB_SEC, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AH2H_SH2H_MCU_SUB_MFSH2H, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SH2H_MCU_SUB_SFH2H, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_PERP_AXI_GLB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SDMA_MTOP_SDMA, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DMA_MTOP_SDMA, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_BTOP_DMA_SDMA, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_OPI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_QSPI2, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_QSPI1, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_QSPI0, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SPI2_2CS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SPI1_3CS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SPI0_3CS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_CACHE_H2H, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_CACHE, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MAIN_AXI_GLB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DSP_SHARE, TURN_OFF}, +}; +#endif + +cmu_pll_config_t clocks_pll_cfg_get(void) +{ + return g_pll_cfg; +} + +#ifdef BUILD_APPLICATION_SSB +clocks_clk_cfg_t const *clocks_ssb_clk_cfg_get(void) +{ + return g_ssb_clk_cfg; +} +#else +clocks_clk_cfg_t const *clocks_system_all_clocks_get(system_clocks_config_t clk_level) +{ + return g_system_all_core_clocks[clk_level]; +} + +system_clocks_freq_config_t clocks_system_freq_cfg_get(system_clocks_freq_t clk_level) +{ + return g_system_clocks_freq_config[clk_level]; +} + +system_display_freq_config_t clocks_system_display_freq_get(system_display_freq_t clk_level) +{ + return g_system_display_freq_config[clk_level]; +} + +system_mcu_core_clk_cfg_t clocks_system_mcu_freq_get(system_mcu_freq_t clk_level) +{ + return g_system_mcu_freq_config[clk_level]; +} + +clocks_clk_cfg_t clocks_system_sdio_freq_get(system_sdio_freq_t clk_level) +{ + return g_system_sdio_freq_config[clk_level]; +} + +system_mcu_perip_clk_t *clocks_system_mcu_perip_clock_config_get(uint32_t *length) +{ + *length = sizeof(g_system_mcu_perp_clk_set_config) / sizeof(system_mcu_perip_clk_t); + return g_system_mcu_perp_clk_set_config; +} + +#if (CLK_AUTO_CG_ENABLE == YES) +system_clk_cg_t const *clock_system_cg_config_get(uint32_t *length) +{ + *length = sizeof(g_system_clkcg_config) / sizeof(system_clk_cg_t); + return g_system_clkcg_config; +} +#endif +#endif +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/config/pmp_config.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/config/pmp_config.c new file mode 100644 index 000000000..8fc7df3cc --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/config/pmp_config.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: chip pmp init config file. + */ +#include "pmp_config.h" +#include "stdbool.h" +#include "drv_pmp.h" +#include "memory_config.h" +#include "product.h" +#define L2MEM_DSP_ADDR_START 0x60100000 +#define L2MEM_DSP_ADDR_LEN 0x100000 + +#define L2MEM_GPU_ADDR_START 0x60240000 +#define L2MEM_GPU_ADDR_LEN 0x20000 + +#if PSRAM_DENSITY_MB == 16 +#define PSRAM_ADDR_START 0x6C000000 +#define PSRAM_ADDR_LEN 0x800000 +#define PSRAM_SECOND_ADDR_START 0x6C800000 +#define PSRAM_SECOND_ADDR_LEN 0x800000 +#else /* PSRAM_DENSITY_MB == 32 */ +#define PSRAM_ADDR_START 0x6C000000 +#define PSRAM_ADDR_LEN 0x1000000 +#define PSRAM_SECOND_ADDR_START 0x6D000000 +#define PSRAM_SECOND_ADDR_LEN 0x1000000 +#endif + +#define NOR_FLASH_ADDR_START FLASH_START +#define NOR_FLASH_ADDR_LEN FLASH_LENGTH + +#define BOOTROM_PMP_LENGTH 0x10000 +#define ITCM_PMP_LENGTH 0x10000 +#define ITCM_PMP_SECOND_LENGTH 0x20000 +#define DTCM_PMP_LENGTH 0x80000 + +typedef enum { + BOOTROM_IDX = 0, + ITCM_IDX = 1, + ITCM_SECOND_IDX = 2, + DTCM_IDX = 3, + L2RAM_IDX = 4, + SHARE_MEM_IDX = 5, + BT_RAM_APP_MAPPING_IDX = 6, + REG_ADDR_0_IDX = 7, /* reg 0x5x */ + REG_ADDR_1_IDX = 8, /* reg 0xa3 */ + CPU_ADDR_IDX = 9, /* reg 0xa3 */ +#ifdef CONFIG_PSRAM_SUPPORT + PSRAM_IDX, + PSRAM_SECOND_IDX, +#endif + NOR_FLASH_IDX, + BACKGROUND_IDX = 15, + MAX_REGION_NUM +} region_index_t; + +pmp_conf_t g_region_attr[MAX_REGION_NUM]; + +static void pmp_init_config(void) +{ + /* bootrom 可读不可写不可执行 */ + g_region_attr[BOOTROM_IDX].idx = BOOTROM_IDX; + g_region_attr[BOOTROM_IDX].addr = ROM_START; + g_region_attr[BOOTROM_IDX].size = 0x100; + g_region_attr[BOOTROM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[BOOTROM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_NEXECUTE; + g_region_attr[BOOTROM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[BOOTROM_IDX].conf.lock = true; + + /* ITCM 第一段 可读可执行不可写 */ + g_region_attr[ITCM_IDX].idx = ITCM_IDX; + g_region_attr[ITCM_IDX].addr = APP_ITCM_ORIGIN; + g_region_attr[ITCM_IDX].size = ITCM_PMP_LENGTH; + g_region_attr[ITCM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[ITCM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_EXECUTE; + g_region_attr[ITCM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[ITCM_IDX].conf.lock = true; + + /* ITCM 第二段 可读可执行不可写 */ + g_region_attr[ITCM_SECOND_IDX].idx = ITCM_SECOND_IDX; + g_region_attr[ITCM_SECOND_IDX].addr = (APP_ITCM_ORIGIN + ITCM_PMP_LENGTH); + g_region_attr[ITCM_SECOND_IDX].size = ITCM_PMP_SECOND_LENGTH; + g_region_attr[ITCM_SECOND_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[ITCM_SECOND_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_EXECUTE; + g_region_attr[ITCM_SECOND_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[ITCM_SECOND_IDX].conf.lock = true; + + /* DTCM 可读可写不可执行 */ + g_region_attr[DTCM_IDX].idx = DTCM_IDX; + g_region_attr[DTCM_IDX].addr = APP_DTCM_ORIGIN; + g_region_attr[DTCM_IDX].size = DTCM_PMP_LENGTH; + g_region_attr[DTCM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[DTCM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[DTCM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[DTCM_IDX].conf.lock = true; + + /* L2MEM 可读可执行可写 no cache属性 */ + g_region_attr[L2RAM_IDX].idx = L2RAM_IDX; + g_region_attr[L2RAM_IDX].addr = 0x60000000; + g_region_attr[L2RAM_IDX].size = 0x2000000; + g_region_attr[L2RAM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[L2RAM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_EXECUTE; + g_region_attr[L2RAM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[L2RAM_IDX].conf.lock = true; + + /* SHARE_MEM_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[SHARE_MEM_IDX].idx = SHARE_MEM_IDX; + g_region_attr[SHARE_MEM_IDX].addr = 0x87000000; + g_region_attr[SHARE_MEM_IDX].size = 0x20000; + g_region_attr[SHARE_MEM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[SHARE_MEM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_EXECUTE; + g_region_attr[SHARE_MEM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[SHARE_MEM_IDX].conf.lock = true; + + /* BT_RAM_APP_MAPPING_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[BT_RAM_APP_MAPPING_IDX].idx = BT_RAM_APP_MAPPING_IDX; + g_region_attr[BT_RAM_APP_MAPPING_IDX].addr = 0xA6000000; + g_region_attr[BT_RAM_APP_MAPPING_IDX].size = 0x200000; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.lock = true; + + /* REG_ADDR_0_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[REG_ADDR_0_IDX].idx = REG_ADDR_0_IDX; + g_region_attr[REG_ADDR_0_IDX].addr = 0x50000000; + g_region_attr[REG_ADDR_0_IDX].size = 0x10000000; + g_region_attr[REG_ADDR_0_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[REG_ADDR_0_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[REG_ADDR_0_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[REG_ADDR_0_IDX].conf.lock = true; + + /* REG_ADDR_1_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[REG_ADDR_1_IDX].idx = REG_ADDR_1_IDX; + g_region_attr[REG_ADDR_1_IDX].addr = 0xA3000000; + g_region_attr[REG_ADDR_1_IDX].size = 0x10000; + g_region_attr[REG_ADDR_1_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[REG_ADDR_1_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[REG_ADDR_1_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[REG_ADDR_1_IDX].conf.lock = true; + + /* CPU_ADDR_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[CPU_ADDR_IDX].idx = CPU_ADDR_IDX; + g_region_attr[CPU_ADDR_IDX].addr = 0xB0000000; + g_region_attr[CPU_ADDR_IDX].size = 0x10000000; + g_region_attr[CPU_ADDR_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[CPU_ADDR_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[CPU_ADDR_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[CPU_ADDR_IDX].conf.lock = true; + +#ifdef CONFIG_PSRAM_SUPPORT + /* PSRAM 第一段 可读可写不可执行 打开cache属性 */ + g_region_attr[PSRAM_IDX].idx = PSRAM_IDX; + g_region_attr[PSRAM_IDX].addr = PSRAM_ADDR_START; + g_region_attr[PSRAM_IDX].size = PSRAM_ADDR_LEN; + g_region_attr[PSRAM_IDX].conf.pmp_attr = PMP_ATTR_WRITEBACK_RWALLOCATE; + g_region_attr[PSRAM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[PSRAM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[PSRAM_IDX].conf.lock = true; + + /* PSRAM 第二段 可读可写不可执行 关闭cache属性 */ + g_region_attr[PSRAM_SECOND_IDX].idx = PSRAM_SECOND_IDX; + g_region_attr[PSRAM_SECOND_IDX].addr = PSRAM_SECOND_ADDR_START; + g_region_attr[PSRAM_SECOND_IDX].size = PSRAM_SECOND_ADDR_LEN; + g_region_attr[PSRAM_SECOND_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[PSRAM_SECOND_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[PSRAM_SECOND_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[PSRAM_SECOND_IDX].conf.lock = true; +#endif + + /* Flash 可读不可写可执行 打开cache属性 */ + g_region_attr[NOR_FLASH_IDX].idx = NOR_FLASH_IDX; + g_region_attr[NOR_FLASH_IDX].addr = NOR_FLASH_ADDR_START; + g_region_attr[NOR_FLASH_IDX].size = NOR_FLASH_ADDR_LEN; + g_region_attr[NOR_FLASH_IDX].conf.pmp_attr = PMP_ATTR_WRITEBACK_RWALLOCATE; + g_region_attr[NOR_FLASH_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_EXECUTE; + g_region_attr[NOR_FLASH_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[NOR_FLASH_IDX].conf.lock = true; + + /* BACKGROUND_IDX 不可读不可写不可执行 */ + g_region_attr[BACKGROUND_IDX].idx = BACKGROUND_IDX; + g_region_attr[BACKGROUND_IDX].addr = 0x0; + g_region_attr[BACKGROUND_IDX].size = 0xFFFFFFFF; /* 4GB */ + g_region_attr[BACKGROUND_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[BACKGROUND_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_NO_ACCESS; + g_region_attr[BACKGROUND_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[BACKGROUND_IDX].conf.lock = true; +} + +void pmp_init(void) +{ + pmp_init_config(); + uapi_pmp_config(g_region_attr, MAX_REGION_NUM); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c new file mode 100644 index 000000000..9d2fc862f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c @@ -0,0 +1,489 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides uart port template \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-06-06, Create file. \n + */ +#include +#include "dma_porting.h" +#include "debug_print.h" +#include "hal_uart_v120.h" +#include "uart_porting.h" +#ifdef SUPPORT_HAL_PINCTRL +#include "pinctrl_porting.h" +#include "pinctrl.h" +#endif +#include "uart.h" +#include "oal_interface.h" +#include "platform_core.h" +#include "securec.h" +#include "soc_osal.h" +#ifdef SUPPORT_CLOCKS_CORE +#include "clocks_core_common.h" +#endif +#if defined(SUPPORT_TEST_COMMON) +#include "test_suite_uart.h" +#endif +#if defined(SUPPORT_AT_CMD) +#include "at_cmd_api.h" +#endif +#ifndef BUILD_APPLICATION_SSB +#include "log_uart.h" +#include "cmsis_os.h" +#endif +#if defined(SW_RTT_DEBUG) +#include "SEGGER_RTT.h" +#endif + +#ifdef SUPPORT_CAT1_SERVICE +#include "cat1_pub_api.h" +#endif + +#ifdef BUILD_APPLICATION_SSB +#define UART_RX_BUFFER_SIZE 1 +#else +#define UART_RX_BUFFER_SIZE 56 +#endif + +#define AT_BLE_HEADER_LENGTH 49 +#define AT_CMD_BUFSIZE_MAX 256 +#define UARTILPR 0x20 +#define UARTIBRD 0x24 +#define UARTFBRD 0x28 +#define UARTLCRH 0x2c +#define UARTCR 0x30 +#define UARTIFLS 0x34 +#define UARTIMSC 0x38 +#define UARTDMACR 0x48 +#define UARTRESET (M_CTL_RB_BASE + 0x0168) +#define UARTBUS0 0x1 +#define UARTBUS1 0x0 +typedef struct { + pin_mode_t tx_pin_mode; + pin_mode_t rx_pin_mode; + pin_mode_t cts_pin_mode; + pin_mode_t rts_pin_mode; +} uart_pin_mode_t; + +typedef struct uart_config { + uart_pin_config_t pin; + uart_pin_mode_t pin_mode; + core_irq_t irq_num; + osal_irq_handler irq_func; + uart_rx_callback_t rx_callback; + uart_attr_t line_config; + uart_buffer_config_t buffer_config; +#ifndef BUILD_APPLICATION_SSB + osal_mutex uart_mutex; + bool support_mutex; +#endif +} uart_config_t; + +const uintptr_t g_uart_base_addrs[UART_BUS_MAX_NUM] = { + (uintptr_t)UART0_BASE, + (uintptr_t)UART1_BASE, +}; + +uintptr_t uart_porting_base_addr_get(uart_bus_t bus) +{ + return g_uart_base_addrs[bus]; +} + +static bool g_sw_debug_uart_enabled = false; +uint8_t g_uart0_rx_buffer[UART_RX_BUFFER_SIZE]; +uint8_t g_uart1_rx_buffer[UART_RX_BUFFER_SIZE]; +#if defined(SUPPORT_AT_CMD) +static void at_cmd_uart_rx_callback(const void *buf, uint16_t buf_len, bool remaining); +#endif + +void log_factory_at_callback(const void *buffer, uint16_t length, bool remaining); + +static uart_config_t g_uart_config[UART_BUS_MAX_NUMBER] = { +#ifdef BUILD_APPLICATION_SSB + /* UART_BUS_0 for debug print */ + { + { + .tx_pin = S_MGPIO19, + .rx_pin = S_MGPIO20, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX + }, + UART_0_IRQN, + (osal_irq_handler)irq_uart0_handler, + NULL, + { + .baud_rate = 115200, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart0_rx_buffer, + } + }, + /* UART_BUS_1 for codeloader */ + { + { + .tx_pin = S_MGPIO33, + .rx_pin = S_MGPIO34, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + }, + UART_1_IRQN, + (osal_irq_handler)irq_uart1_handler, + NULL, + { + .baud_rate = 115200, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart1_rx_buffer, + } + } +#else + /** UART_BUS_0, which is used to at cmd and debug print in wstp version, + * and which is used to testustie and debug print in testsuite version + */ + { + { + .tx_pin = S_MGPIO19, + .rx_pin = S_MGPIO20, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX + }, + UART_0_IRQN, + (osal_irq_handler)irq_uart0_handler, +#if defined(SUPPORT_TEST_COMMON) + test_suite_uart_rx_callback, +#elif defined(SUPPORT_AT_CMD) + at_cmd_uart_rx_callback, +#else + NULL, +#endif + { + #ifdef SUPPORT_CAT1_SERVICE + .baud_rate = 921600, + #else + .baud_rate = 115200, + #endif + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart0_rx_buffer, + }, + NULL, +#if defined(SUPPORT_TEST_COMMON) + false, +#else + true, +#endif + }, + /* UART_BUS_1 is used to hso uart */ + { + { + .tx_pin = S_MGPIO33, + .rx_pin = S_MGPIO34, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX + }, + UART_1_IRQN, + (osal_irq_handler)irq_uart1_handler, +#ifndef FT_SINGLE_UART +#if SYS_DEBUG_MODE_ENABLE == YES + log_uart_rx_callback, +#endif +#else + log_factory_at_callback, +#endif + { + .baud_rate = 500000, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart1_rx_buffer, + }, + NULL, + false + } +#endif +}; +static uart_recovery_regs_t g_uart_recovery_reg[UART_BUS_MAX_NUMBER] = { 0 }; + +#ifdef FT_SINGLE_UART +void log_factory_at_callback(const void *buffer, uint16_t length, bool remaining) +{ + log_uart_rx_callback(buffer, length, remaining); + if (zdiag_is_enable() == false) { + at_cmd_msg_receive_handler((uint8_t *)buffer, length); + hal_uart_clear_pending(UART_BUS_1); + } +} +#endif + +void uart_port_register_hal_funcs(uart_bus_t bus) +{ + hal_uart_register_funcs(bus, hal_uart_v120_funcs_get()); +} + +void uart_port_unregister_hal_funcs(uart_bus_t bus) +{ + hal_uart_unregister_funcs(bus); +} + +uint32_t uart_port_get_clock_value(uart_bus_t bus) +{ + return uart_get_clock_value(bus); +} + +void uart_port_config_pinmux(uart_bus_t bus) +{ + UNUSED(bus); + uapi_pin_set_mode(g_uart_config[UART_BUS_1].pin.tx_pin, g_uart_config[UART_BUS_1].pin_mode.tx_pin_mode); + uapi_pin_set_mode(g_uart_config[UART_BUS_1].pin.rx_pin, g_uart_config[UART_BUS_1].pin_mode.rx_pin_mode); + uapi_pin_set_mode(g_uart_config[UART_BUS_0].pin.tx_pin, g_uart_config[UART_BUS_0].pin_mode.tx_pin_mode); + uapi_pin_set_mode(g_uart_config[UART_BUS_0].pin.rx_pin, g_uart_config[UART_BUS_0].pin_mode.rx_pin_mode); +} + +void uart_port_register_irq(uart_bus_t bus) +{ + osal_irq_request(g_uart_config[bus].irq_num, g_uart_config[bus].irq_func, NULL, NULL, NULL); + osal_irq_set_priority(g_uart_config[bus].irq_num, irq_prio(g_uart_config[bus].irq_num)); + osal_irq_enable(g_uart_config[bus].irq_num); +} + +void uart_port_unregister_irq(uart_bus_t bus) +{ + osal_irq_disable(g_uart_config[bus].irq_num); +} + +void irq_uart0_handler(void) +{ + hal_uart_irq_handler(UART_BUS_0); +} + +void irq_uart1_handler(void) +{ + hal_uart_irq_handler(UART_BUS_1); +} + +#ifdef SUPPORT_AT_CMD +static void at_cmd_uart_rx_callback(const void *buf, uint16_t buf_len, bool remaining) +{ + unused(remaining); + #ifndef FT_SINGLE_UART + at_cmd_msg_receive_handler((uint8_t *)buf, buf_len); + #endif + + #ifdef SUPPORT_CAT1_SERVICE + cat1_uart_receive_handler((uint8_t *)buf, buf_len); + #endif + hal_uart_clear_pending(SW_DEBUG_UART_BUS); +} +#endif + +void uart_config_init(void) +{ + for (uint8_t i = 0; i < UART_BUS_MAX_NUM; i++) { + if ((g_uart_config[i].pin.tx_pin != PIN_NONE) || (g_uart_config[i].pin.rx_pin != PIN_NONE)) { + uapi_uart_init(i, &(g_uart_config[i].pin), &(g_uart_config[i].line_config), NULL, + &(g_uart_config[i].buffer_config)); + } + if (g_uart_config[i].rx_callback != NULL) { + uapi_uart_register_rx_callback(i, UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE, + (uint32_t)(g_uart_config[i].buffer_config.rx_buffer_size), + g_uart_config[i].rx_callback); + } + +#ifndef BUILD_APPLICATION_SSB + if (g_uart_config[i].support_mutex == true) { + osal_mutex_init(&(g_uart_config[i].uart_mutex)); + } +#endif + } +} + +#if (defined SW_UART_DEBUG)||(defined FT_SINGLE_UART) +void sw_debug_uart_deinit(void) +{ + uapi_uart_deinit(SW_DEBUG_UART_BUS); +} + +void sw_debug_uart_init(uint32_t baud_rate) +{ + g_uart_config[SW_DEBUG_UART_BUS].line_config.baud_rate = baud_rate; + uapi_uart_init(SW_DEBUG_UART_BUS, &(g_uart_config[SW_DEBUG_UART_BUS].pin), + &(g_uart_config[SW_DEBUG_UART_BUS].line_config), NULL, + &(g_uart_config[SW_DEBUG_UART_BUS].buffer_config)); +} + +void sw_debug_uart_reset_baund(void) +{ + while (uapi_uart_has_pending_transmissions(SW_DEBUG_UART_BUS)) { } + uapi_uart_set_attr(SW_DEBUG_UART_BUS, &g_uart_config[SW_DEBUG_UART_BUS].line_config); +} +#endif + +void print_str(const char *str, ...) +{ + static uint8_t s[1024]; // 1024 means string max length. + va_list args; + int32_t str_len; + + if ((str == NULL) || (strlen(str) == 0)) { + return; + } + + va_start(args, str); + str_len = vsprintf_s((char *)s, sizeof(s), str, args); + va_end(args); + + if (str_len < 0) { + return; + } +#if defined(SW_RTT_DEBUG) + SEGGER_RTT_Write(0, (const char *)s, str_len); +#elif defined(SW_UART_DEBUG) + if (hal_uart_get_funcs(SW_DEBUG_UART_BUS) == NULL) { + return; + } + uapi_uart_write(SW_DEBUG_UART_BUS, (const void *)s, (uint32_t)str_len, 0); +#else +#endif +} + +void hal_uart_clear_pending(uart_bus_t uart) +{ + switch (uart) { + case UART_BUS_0: + int_clear_pending_irq(UART_0_IRQN); + break; + case UART_BUS_1: + int_clear_pending_irq(UART_1_IRQN); + break; + default: + break; + } +} + +#if defined(CONFIG_UART_SUPPORT_DMA) +uint8_t uart_port_get_dma_trans_dest_handshaking(uart_bus_t bus) +{ + switch (bus) { + case UART_BUS_0: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_L_TX; + case UART_BUS_1: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_H0_TX; + default: + return (uint8_t)HAL_DMA_HANDSHAKING_MAX_NUM; + } +} + +uint8_t uart_port_get_dma_trans_src_handshaking(uart_bus_t bus) +{ + switch (bus) { + case UART_BUS_0: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_L_RX; + case UART_BUS_1: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_H0_RX; + default: + return (uint8_t)HAL_DMA_HANDSHAKING_MAX_NUM; + } +} +#endif /* CONFIG_UART_SUPPORT_DMA */ + +uint32_t uart_porting_lock(uart_bus_t bus) +{ +#ifndef BUILD_APPLICATION_SSB + if ((g_uart_config[bus].support_mutex == true) && (osKernelGetState() == osKernelRunning) && + (osal_in_interrupt() == 0)) { + return (uint32_t)osal_mutex_lock_timeout(&(g_uart_config[bus].uart_mutex), OSAL_MUTEX_WAIT_FOREVER); + } +#else + UNUSED(bus); +#endif + return ERRCODE_SUCC; +} + +void uart_porting_unlock(uart_bus_t bus, uint32_t irq_sts) +{ +#ifndef BUILD_APPLICATION_SSB + unused(irq_sts); + if ((g_uart_config[bus].support_mutex == true) && (osKernelGetState() == osKernelRunning) && + (osal_in_interrupt() == 0)) { + osal_mutex_unlock(&(g_uart_config[bus].uart_mutex)); + } +#else + UNUSED(bus); + UNUSED(irq_sts); +#endif +} + +void uart_save_reg(uart_bus_t bus) +{ + uint32_t base = uart_porting_base_addr_get(bus); + g_uart_recovery_reg[bus].uartilpr = readw(base + UARTILPR); + g_uart_recovery_reg[bus].uartibrd = readw(base + UARTIBRD); + g_uart_recovery_reg[bus].uartfbrd = readw(base + UARTFBRD); + g_uart_recovery_reg[bus].uartlcr_h = readw(base + UARTLCRH); + g_uart_recovery_reg[bus].uartcr = readw(base + UARTCR); + g_uart_recovery_reg[bus].uartifls = readw(base + UARTIFLS); + g_uart_recovery_reg[bus].uartimsc = readw(base + UARTIMSC); + g_uart_recovery_reg[bus].uartdmacr = readw(base + UARTDMACR); +} + +void uart_recovery_reg(uart_bus_t bus) +{ + uint16_t uart_bit = UARTBUS0; + if (bus == UART_BUS_0) { + uart_bit = UARTBUS0; + } else if (bus == UART_BUS_1) { + uart_bit = UARTBUS1; + } + reg16_clrbit(UARTRESET, uart_bit); + reg16_setbit(UARTRESET, uart_bit); + uint32_t base = uart_porting_base_addr_get(bus); + writew(base + UARTILPR, g_uart_recovery_reg[bus].uartilpr); + writew(base + UARTIBRD, g_uart_recovery_reg[bus].uartibrd); + writew(base + UARTFBRD, g_uart_recovery_reg[bus].uartfbrd); + writew(base + UARTLCRH, g_uart_recovery_reg[bus].uartlcr_h); + writew(base + UARTCR, g_uart_recovery_reg[bus].uartcr); + writew(base + UARTIFLS, g_uart_recovery_reg[bus].uartifls); + writew(base + UARTIMSC, g_uart_recovery_reg[bus].uartimsc); + writew(base + UARTDMACR, g_uart_recovery_reg[bus].uartdmacr); +} \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/lcd_config.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/lcd_config.c new file mode 100644 index 000000000..2b0b2b38a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/lcd_config.c @@ -0,0 +1,429 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Lcd driver configuration. + * Author: @CompanyNameTag + * Create: 2022-03-05 + */ + +#include +#include "common_def.h" +#include "lcd_config.h" + +#define LCD_EDO_466X466_SCREEN_ID 0x1133 +#define LCD_EDO_454X454_SCREEN_ID 0xf00 +#define LCD_BOE_454X454_SCREEN_ID 0x500 +#define LCD_SH_240X296_SCREEN_ID 0x101 +#define LCD_BOE_194X368_SCREEN_ID 0x4a00 + +const combo_dev_cfg_t g_panel_466x466_60_config = { + .devno = 0, + .lane_id = {0, -1}, + .out_mode = OUT_MODE_DSI_CMD, + .out_format = OUT_FORMAT_RGB_24BIT, + .sync_info = { + .hsa_pixels = 10, // hsa 10 pixels + .hbp_pixels = 10, // hbp 10 pixels + .hact_pixels = 466, // hact 466 pixels + .hfp_pixels = 10, // hfp 10 pixels + .vsa_lines = 4, // vsa 4 lines + .vbp_lines = 12, // vbp 12 lines + .vact_lines = 466, // vact 466 lines + .vfp_lines = 10, // vfp 10 lines + }, + .phy_data_rate = 480, // 480Mbps + .pixel_clk = 20000, // 20000KHz +}; +const combo_dev_cfg_t g_panel_454x454_60_config = { + .devno = 0, + .lane_id = {0, -1}, + .out_mode = OUT_MODE_DSI_CMD, + .out_format = OUT_FORMAT_RGB_24BIT, + .sync_info = { + .hsa_pixels = 10, // hsa 10 pixels + .hbp_pixels = 10, // hbp 10 pixels + .hact_pixels = 454, // hact 454 pixels + .hfp_pixels = 10, // hfp 10 pixels + .vsa_lines = 4, // vsa 4 lines + .vbp_lines = 12, // vbp 12 lines + .vact_lines = 454, // vact 454 lines + .vfp_lines = 10, // vfp 10 lines + }, + .phy_data_rate = 480, // 480Mbps + .pixel_clk = 20000, // 20000KHz +}; + +const combo_dev_cfg_t g_panel_240x296_60_config = { + .devno = 0, + .lane_id = {0, -1}, + .out_mode = OUT_MODE_DSI_CMD, + .out_format = OUT_FORMAT_RGB_24BIT, + .sync_info = { + .hsa_pixels = 4, // hsa 14 pixels hpw + .hbp_pixels = 11, // hbp 11 pixels HBP + .hact_pixels = 368, // hact 240 pixels HPX + .hfp_pixels = 14, // hfp 14 pixels hfp + .vsa_lines = 2, // vsa 2 lines vpw + .vbp_lines = 6, // vbp 6 lines vbp + .vact_lines = 448, // vact 296 lines vpx + .vfp_lines = 8, // vfp 8 lines vfp + }, + .phy_data_rate = 480, // 480Mbps + .pixel_clk = 20000, // 20000KHz +}; + +const combo_dev_cfg_t g_panel_194x368_qspi_config = { + .out_format = OUT_FORMAT_RGB_24BIT, + .sync_info = { + .hact_pixels = 194, // hact 368 pixels + .vact_lines = 368, // vact 368 lines + }, +}; + +/* display off sequence for common lcd */ +const lcd_cmd_sequ g_common_cmd_display_off[] = { + {1, 2, {0xfe, 0x00}, 0}, /* select default cmd page */ + {1, 1, {0x28}, 0}, /* display off */ + {1, 1, {0x10}, 120}, /* sleep in */ +}; + +/* display off sequence for common lcd */ +const lcd_cmd_sequ g_common_466x466_cmd_display_off[] = { + {1, 2, {0xfe, 0x00}, 0}, /* select default cmd page */ + {1, 1, {0x28}, 0}, /* display off */ + {1, 1, {0x10}, 120}, /* sleep in */ + {1, 2, {0x4f, 0x01}, 0}, /* ½ødeepstandby ״̬ */ +}; + +/* sleep in sequence for common lcd */ +const lcd_cmd_sequ g_common_cmd_sleep_in[] = { + {1, 2, {0xfe, 0x00}, 0}, /* select default cmd page */ + {1, 1, {0x28}, 0}, /* display off */ + {1, 1, {0x10}, 120}, /* sleep in */ +}; + +/* sleep in sequence for common lcd */ +const lcd_cmd_sequ g_common_cmd_sleep_out[] = { + {1, 2, {0xfe, 0x00}, 0}, /* select default cmd page */ + {1, 1, {0x11}, 120}, /* sleep out */ + {1, 1, {0x29}, 0}, /* display on */ +}; + +/* idle in sequence for EDO and BOE 454*454 lcd */ +lcd_cmd_sequ g_common_cmd_idle_in[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x39}, 0}, +}; + +/* idle out sequence for EDO and BOE 454*454 lcd */ +const lcd_cmd_sequ g_common_cmd_idle_out[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x38}, 0}, +}; + +/* te on sequence for EDO and BOE 454*454 lcd */ +const lcd_cmd_sequ g_common_cmd_te_on[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x35}, 0}, +}; + +/* te off sequence for EDO and BOE 454*454 lcd */ +const lcd_cmd_sequ g_common_cmd_te_off[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x34}, 0}, +}; + +/* set brightness sequence for EDO and BOE 454*454 lcd */ +lcd_cmd_sequ g_common_cmd_brightness[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 2, {0x51, 0xff}, 0}, +}; +const lcd_cmd_sequ g_edo_466x466_screen_init_on[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 2, {0x3a, 0x77}, 0}, + {1, 2, {0x35, 0x00}, 0}, + {1, 2, {0x53, 0x20}, 0}, + // {1, 2, {0x51, 0xff}, 0}, + {1, 2, {0x63, 0xff}, 0}, + {1, 5, {0x2A, 0x00, 0x06, 0x01, 0xd7}, 0}, + {1, 5, {0x2B, 0x00, 0x00, 0x01, 0xd1}, 0}, + {1, 3, {0x44, 0x01, 0xc5}, 0}, + {1, 1, {0x11}, 120}, + {1, 1, {0x29}, 0}, +}; + + +/* init sequence for EDO 454*454 lcd */ +const lcd_cmd_sequ g_edo_454x454_screen_init_on[] = { + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x30, 0x43}, 0}, /* set LCD frequency to 15HZ */ + {1, 2, {0xfe, 0x00}, 0}, + {1, 2, {0x3a, 0x77}, 0}, + {1, 2, {0x53, 0x20}, 0}, + {1, 2, {0x51, 0xff}, 0}, + {0, 5, {0x2a, 0x00, 0x0e, 0x01, 0xd3}, 0}, + {0, 5, {0x2b, 0x00, 0x00, 0x01, 0xc5}, 0}, + {1, 3, {0x44, 0x01, 0xc5}, 0}, + {1, 2, {0x35, 0x00}, 0}, + {1, 1, {0x11}, 120}, + {1, 1, {0x29}, 0}, +}; + +/* init sequence for BOE 454*454 lcd */ +const lcd_cmd_sequ g_boe_454x454_screen_init_on[] = { + {1, 2, {0xfe, 0x0d}, 0}, + {1, 2, {0x01, 0x00}, 0}, + {1, 2, {0x03, 0x00}, 0}, + {1, 2, {0x1b, 0x00}, 0}, + {1, 2, {0x1d, 0x00}, 0}, + {1, 2, {0x37, 0x00}, 0}, + {1, 2, {0x39, 0x00}, 0}, + {1, 2, {0x52, 0x58}, 0}, + {1, 2, {0x53, 0x00}, 0}, + + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x72, 0x05}, 0}, + {1, 2, {0x73, 0x16}, 0}, + {1, 2, {0x74, 0x0c}, 0}, + + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x18, 0x55}, 0}, + {1, 2, {0xc5, 0x10}, 0}, + {1, 2, {0x72, 0x0e}, 0}, + {1, 2, {0x73, 0x1c}, 0}, + + {1, 2, {0xfe, 0x07}, 0}, + {1, 2, {0x15, 0x04}, 0}, + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x0a, 0xf8}, 0}, + + {1, 2, {0xfe, 0x00}, 0}, + {1, 2, {0x51, 0xff}, 0}, + {1, 2, {0x35, 0x00}, 0}, + {0, 5, {0x2a, 0x00, 0x0c, 0x01, 0xd1}, 0}, + {0, 5, {0x2b, 0x00, 0x00, 0x01, 0xc5}, 0}, + {1, 2, {0x53, 0x20}, 0}, + {1, 1, {0x11}, 120}, + {1, 1, {0x29}, 0}, +}; + +const lcd_cmd_sequ g_sh_240x296_screen_init_on[] = { + {1, 1, {0x11}, 5}, + {1, 5, {0x2a, 0x00, 0x00, 0x01, 0x6f}, 1}, + {1, 5, {0x2b, 0x00, 0x00, 0x01, 0xbf}, 1}, + {1, 3, {0x44, 0x01, 0xbf}, 1}, + {1, 2, {0x35, 0x00}, 1}, + {1, 2, {0x3a, 0x77}, 1}, + {1, 2, {0x53, 0x20}, 80}, + {1, 1, {0x29}, 0}, +}; + +const lcd_cmd_sequ g_boe_194x368_screen_init_on[] = { + {0, 2, {0xfe, 0x00}, 0}, + {0, 3, {0x44, 0x00, 0xB7}, 0}, + {0, 2, {0x3a, 0x77}, 0}, + {0, 2, {0x51, 0x80}, 0}, + {0, 2, {0x35, 0x0}, 0}, + {0, 5, {0x2a, 0x00, 0x00, 0x00, 0xc1}, 0}, + {0, 1, {0x11}, 120}, + {0, 1, {0x29}, 100}, + {0, 1, {0x39}, 0}, +}; + +const lcd_cmds_sequ g_display_off_cmds = { + .cmd = g_common_cmd_display_off, + .cmd_cnt = array_size(g_common_cmd_display_off), +}; + +const lcd_cmds_sequ g_466x466_display_off_cmds = { + .cmd = g_common_466x466_cmd_display_off, + .cmd_cnt = array_size(g_common_466x466_cmd_display_off), +}; + +const lcd_cmds_sequ g_idle_in_cmds = { + .cmd = g_common_cmd_idle_in, + .cmd_cnt = array_size(g_common_cmd_idle_in), +}; + +const lcd_cmds_sequ g_idle_out_cmds = { + .cmd = g_common_cmd_idle_out, + .cmd_cnt = array_size(g_common_cmd_idle_out), +}; + +const lcd_cmds_sequ g_te_on_cmds = { + .cmd = g_common_cmd_te_on, + .cmd_cnt = array_size(g_common_cmd_te_on), +}; + +const lcd_cmds_sequ g_te_off_cmds = { + .cmd = g_common_cmd_te_off, + .cmd_cnt = array_size(g_common_cmd_te_off), +}; + +const lcd_cmds_sequ g_brightness_cmds = { + .cmd = g_common_cmd_brightness, + .cmd_cnt = array_size(g_common_cmd_brightness), +}; + +const lcd_cmds_sequ g_edo_466x466_screen_init_on_cmds = { + .cmd = g_edo_466x466_screen_init_on, + .cmd_cnt = array_size(g_edo_466x466_screen_init_on), +}; + +const lcd_cmds_sequ g_edo_454x454_screen_init_on_cmds = { + .cmd = g_edo_454x454_screen_init_on, + .cmd_cnt = array_size(g_edo_454x454_screen_init_on), +}; + +const lcd_cmds_sequ g_boe_454x454_screen_init_on_cmds = { + .cmd = g_boe_454x454_screen_init_on, + .cmd_cnt = array_size(g_boe_454x454_screen_init_on), +}; + +const lcd_cmds_sequ g_sh_240x296_screen_init_on_cmds = { + .cmd = g_sh_240x296_screen_init_on, + .cmd_cnt = array_size(g_sh_240x296_screen_init_on), +}; + +const lcd_cmds_sequ g_boe_194x368_screen_init_on_cmds = { + .cmd = g_boe_194x368_screen_init_on, + .cmd_cnt = array_size(g_boe_194x368_screen_init_on), +}; + +const lcd_cmds_sequ g_sleep_in_cmds = { + .cmd = g_common_cmd_sleep_in, + .cmd_cnt = array_size(g_common_cmd_sleep_in), +}; + +const lcd_cmds_sequ g_sleep_out_cmds = { + .cmd = g_common_cmd_sleep_out, + .cmd_cnt = array_size(g_common_cmd_sleep_out), +}; + +const lcd_drv_cfg g_lcd_driver_ops[] = { + { + .bus_type = BUS_DISPLAY_MIPI, + .bus_cfg = &g_panel_466x466_60_config, + .x_start = 0x6, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_EDO_466X466_SCREEN_ID, + .display_on_cmds = &g_edo_466x466_screen_init_on_cmds, + .display_off_cmds = &g_466x466_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0x04, + .lcd_id_info.read_len = 3, + }, + { + .bus_type = BUS_DISPLAY_MIPI, + .bus_cfg = &g_panel_454x454_60_config, + .x_start = 0xe, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_EDO_454X454_SCREEN_ID, + .display_on_cmds = &g_edo_454x454_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0x04, + .lcd_id_info.read_len = 3, + }, + { + .bus_type = BUS_DISPLAY_MIPI, + .bus_cfg = &g_panel_454x454_60_config, + .x_start = 0xc, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_BOE_454X454_SCREEN_ID, + .display_on_cmds = &g_boe_454x454_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0x04, + .lcd_id_info.read_len = 3, + }, + { + .bus_type = BUS_DISPLAY_MIPI, + .bus_cfg = &g_panel_240x296_60_config, + .x_start = 0, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_SH_240X296_SCREEN_ID, + .display_on_cmds = &g_sh_240x296_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0xda, + .lcd_id_info.read_len = 3, + }, + { + .bus_type = BUS_DISPLAY_QSPI, + .bus_cfg = &g_panel_194x368_qspi_config, + .x_start = 0, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_BOE_194X368_SCREEN_ID, + .display_on_cmds = &g_boe_194x368_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0x04, + .lcd_id_info.read_len = 3, + } +}; + +lcd_drv_cfg *lcd_get_driver_ops(void) +{ + return g_lcd_driver_ops; +} + +uint32_t lcd_get_ops_num(void) +{ + return array_size(g_lcd_driver_ops); +} + +combo_dev_cfg_t *lcd_get_bus_escape_config(void) +{ + return g_lcd_driver_ops[0].bus_cfg; +} + +lcd_drv_cfg *lcd_get_driver_config(uint32_t id) +{ + uint32_t i; + if (id == 0) { + return NULL; + } + + for (i = 0; i < array_size(g_lcd_driver_ops); i++) { + if (g_lcd_driver_ops[i].lcd_id == id) { + return &(g_lcd_driver_ops[i]); + } + } + + return NULL; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/lcd_private.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/lcd_private.c new file mode 100644 index 000000000..e34f881d8 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/lcd_private.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Lcd private interface. + * Author: @CompanyNameTag + * Create: 2022-03-05 + */ + +#include "lcd_private.h" +#include "tcxo.h" +#include "chip_io.h" +#include "platform_core.h" +#include "gpio.h" +#include "pinctrl_porting.h" +#include "product.h" +#include "pinctrl.h" +static void lcd_drv_power_on(void) +{ +#ifndef QSPI_DISPLAY + uapi_gpio_set_dir(VCI_LCD_GPIO, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(VCI_LCD_GPIO, GPIO_LEVEL_HIGH); +#endif + uapi_gpio_set_dir(RESET_LCD_GPIO, GPIO_DIRECTION_OUTPUT); + + uapi_gpio_set_val(RESET_LCD_GPIO, GPIO_LEVEL_LOW); + uapi_tcxo_delay_ms(10); /* delay 10 ms */ + + uapi_gpio_set_val(RESET_LCD_GPIO, GPIO_LEVEL_HIGH); + uapi_tcxo_delay_ms(10); /* delay 10 ms */ +} +#define USE_OUTPUT_CTL 1 +static void lcd_drv_power_off(void) +{ +#if USE_OUTPUT_CTL + //uapi_gpio_set_dir(RESET_LCD_GPIO, GPIO_DIRECTION_OUTPUT); + //uapi_gpio_set_val(RESET_LCD_GPIO, GPIO_LEVEL_LOW); + #ifndef QSPI_DISPLAY + uapi_gpio_set_dir(VCI_LCD_GPIO, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(VCI_LCD_GPIO, GPIO_LEVEL_LOW); + #endif + uapi_tcxo_delay_ms(10); /* delay 10 ms */ + int resetvalue = uapi_gpio_get_output_val(RESET_LCD_GPIO); + int lcd_envalue = uapi_gpio_get_output_val(VCI_LCD_GPIO); + printf("Output RESET_LCD_GPIO %d , VCI_LCD_GPIO %d\r\n",resetvalue,lcd_envalue); +#else + uapi_gpio_set_val(RESET_LCD_GPIO, GPIO_LEVEL_LOW); + uapi_gpio_set_dir(RESET_LCD_GPIO, GPIO_DIRECTION_INPUT); //¨¦¨¨??3¨¦Input¡ê?¨º??a¨¢??a????¦Ì? ¡ê?¡ê? + uapi_pin_set_pull(RESET_LCD_GPIO, PIN_PULL_DOWN); + #ifndef QSPI_DISPLAY + uapi_gpio_set_val(VCI_LCD_GPIO, GPIO_LEVEL_LOW); + uapi_gpio_set_dir(VCI_LCD_GPIO, GPIO_DIRECTION_INPUT); + uapi_pin_set_pull(VCI_LCD_GPIO, PIN_PULL_DOWN); + #endif + uapi_tcxo_delay_ms(10); /* delay 10 ms */ + int resetvalue = uapi_gpio_get_val(RESET_LCD_GPIO); + int lcd_envalue = uapi_gpio_get_val(VCI_LCD_GPIO); + printf("Input RESET_LCD_GPIO %d , VCI_LCD_GPIO %d\r\n",resetvalue,lcd_envalue); +#endif + +} + +static lcd_drv_private g_lcd_private_api = { + .power_on = lcd_drv_power_on, + .power_off = lcd_drv_power_off, +}; + +lcd_drv_private *lcd_drv_get_private_api(void) +{ + return &g_lcd_private_api; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/soc_lcd_api.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/soc_lcd_api.c new file mode 100644 index 000000000..56f8542af --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/lcd/soc_lcd_api.c @@ -0,0 +1,767 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Lcd driver. + * Author: @CompanyNameTag + * Create: 2022-03-05 + */ + +#include "soc_lcd_api.h" +#include +#include "soc_errno.h" +#include "soc_osal.h" +#include "soc_mipi_tx.h" +#include "lcd_config.h" +#include "lcd_bus.h" +#include "lcd_mipi.h" +#include "lcd_qspi.h" +#include "lcd_common.h" +#include "lcd_private.h" +#include "pinctrl_porting.h" + +typedef struct lcd_attr { + bool info_register; /* 注册指定屏幕组件标志 */ + bool is_inited; /* LCD组件初始化标志 */ + lcd_type screen_type; /* LCD屏类型 */ + uint32_t lcd_id; /* LCD ID号 */ + lcd_drv_cfg *lcd_cfg; /* LCD参数 */ + uint8_t brightness; /* 显示亮度参数 */ + ext_lcd_status status; /* LCD状态标志 */ + osal_mutex lcd_mutex; /* LCD驱动多线程调用保护信号量 */ + lcd_bus_api *bus_api; /* 总线接口 */ + lcd_drv_common *common_api; /* LCD公共接口 */ + lcd_drv_private *private_api; /* LCD差异化接口 */ +} lcd_attr; + +lcd_attr g_lcd_info = {0}; +volatile bool g_idle_before_sleep = false; /* false: normal display, true: idle mode */ +static bool g_lcd_on_flag = false; + +bool lcd_get_status(void) +{ + return g_lcd_on_flag; +} + +void lcd_set_status(bool lcd_on) +{ + g_lcd_on_flag = lcd_on; +} + +static ext_errno lcd_lock_init(void) +{ + ext_errno ret; + if (g_lcd_info.lcd_mutex.mutex != NULL) { + return EXT_ERR_SUCCESS; + } + + ret = osal_mutex_init(&(g_lcd_info.lcd_mutex)); + if (ret != EXT_ERR_SUCCESS) { + g_lcd_info.lcd_mutex.mutex = NULL; + return ret; + } + if (g_lcd_info.lcd_mutex.mutex == NULL) { + return EXT_ERR_LCD_MUTEX_INIT_FAIL; + } + return EXT_ERR_SUCCESS; +} + +static void lcd_lock_deinit(void) +{ + if (g_lcd_info.lcd_mutex.mutex != NULL) { + osal_mutex_destroy(&(g_lcd_info.lcd_mutex)); + } + + g_lcd_info.lcd_mutex.mutex = NULL; +} + +static void lcd_lock(void) +{ + if (g_lcd_info.lcd_mutex.mutex == NULL) { + return; + } + osal_mutex_lock(&(g_lcd_info.lcd_mutex)); +} + +static void lcd_unlock(void) +{ + if (g_lcd_info.lcd_mutex.mutex == NULL) { + return; + } + osal_mutex_unlock(&(g_lcd_info.lcd_mutex)); +} + +static void lcd_set_display_info(void) +{ + if (g_lcd_info.bus_api->bus_register_panel_info != NULL) { + g_lcd_info.bus_api->bus_register_panel_info(g_lcd_info.lcd_cfg->x_start, g_lcd_info.lcd_cfg->y_start, + g_lcd_info.lcd_cfg->fps); + } +} + +static ext_errno lcd_auto_adapt_init_prepare(void) +{ + ext_errno ret; + combo_dev_cfg_t *escape_config = lcd_get_bus_escape_config(); + + /* init with default parameter */ + ret = g_lcd_info.bus_api->bus_init(escape_config); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("default bus_init fail, ret = %X\r\n", ret); + return ret; + } + + ret = g_lcd_info.common_api->get_chip_id(&g_lcd_info.lcd_id); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("get_chip_id fail, ret = %X\r\n", ret); + } + + if (g_lcd_info.bus_api->bus_deinit() != EXT_ERR_SUCCESS) { + lcd_err("bus deinit fail\r\n"); + } + + return ret; +} + +static ext_errno lcd_assigned_id_check(void) +{ + if (g_lcd_info.common_api->chip_id_check == NULL) { + return EXT_ERR_LCD_INVALID_NULL_POINTER; + } + + return g_lcd_info.common_api->chip_id_check(); +} + +static ext_errno lcd_get_ops(void) +{ + ext_errno ret = 0; + g_lcd_info.bus_api = lcd_get_bus_api(); + g_lcd_info.common_api = lcd_drv_get_common_api(); + g_lcd_info.private_api = lcd_drv_get_private_api(); + + if (g_lcd_info.bus_api == NULL || g_lcd_info.common_api == NULL || g_lcd_info.private_api == NULL) { + return EXT_ERR_LCD_GET_ATTR_FAIL; + } + + if (g_lcd_info.private_api->power_on == NULL) { + return EXT_ERR_LCD_GET_ATTR_FAIL; + } + g_lcd_info.private_api->power_on(); + + if (!g_lcd_info.info_register) { + ret = lcd_auto_adapt_init_prepare(); + if (ret != EXT_ERR_SUCCESS) { + goto fail; + } + } + + g_lcd_info.lcd_cfg = g_lcd_info.common_api->get_lcd_config(); + if (g_lcd_info.lcd_cfg == NULL) { + lcd_err("lcd_cfg empty!\r\n"); + goto fail; + } + ret = g_lcd_info.bus_api->bus_init(g_lcd_info.lcd_cfg->bus_cfg); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_init fail, ret = %X\r\n", ret); + return ret; + } + + if (g_lcd_info.info_register) { + ret = lcd_assigned_id_check(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("chip id check error, ret = 0x%x\r\n", ret); + g_lcd_info.bus_api->bus_deinit(); + goto fail; + } + } + + if (g_lcd_info.brightness == 0) + g_lcd_info.brightness = DEFAULT_BRIGHTNESS; + + return EXT_ERR_SUCCESS; +fail: + + if (g_lcd_info.private_api->power_off != NULL) { + g_lcd_info.private_api->power_off(); + } + g_lcd_info.bus_api = NULL; + g_lcd_info.common_api = NULL; + g_lcd_info.private_api = NULL; + return ret; +} + +ext_lcd_status uapi_lcd_get_status(void) +{ + return g_lcd_info.status; +} + +bool uapi_is_lcd_connect(void) +{ + return g_lcd_info.is_inited; +} + +static ext_errno lcd_display_on(void) +{ + ext_errno ret; + uint32_t retry_count = 3; + lcd_lock(); + + for (; retry_count > 0; retry_count--) { + ret = g_lcd_info.common_api->display_on(g_lcd_info.brightness); + if (ret == EXT_ERR_SUCCESS) { + ret = g_lcd_info.bus_api->bus_enable(); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + + g_lcd_info.private_api->power_off(); + g_lcd_info.private_api->power_on(); + + g_lcd_info.bus_api->bus_deinit(); + ret = g_lcd_info.bus_api->bus_init(g_lcd_info.lcd_cfg->bus_cfg); + if (ret != EXT_ERR_SUCCESS) { + g_lcd_info.private_api->power_off(); + continue; + } + } + if (retry_count > 0) { + g_lcd_info.status.disp_status = LCD_NORMAL_DISPLAY; + g_lcd_info.status.te_status = LCD_TE_ON; + } + + lcd_unlock(); + + return ret; +} + +ext_errno uapi_lcd_display_on(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_NORMAL_DISPLAY) { + return EXT_ERR_SUCCESS; + } + + ret = lcd_display_on(); + + return ret; +} + +ext_errno uapi_lcd_display_off(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_DISPLAY_OFF) { + return EXT_ERR_SUCCESS; + } + + ret = g_lcd_info.common_api->display_off(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("display_off fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + ret = g_lcd_info.bus_api->bus_disable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_disable fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + + g_lcd_info.status.disp_status = LCD_DISPLAY_OFF; + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_enter_sleep_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_SLEEP_MODE) { + return EXT_ERR_SUCCESS; + } else if (g_lcd_info.status.disp_status == LCD_DISPLAY_OFF) { + return EXT_ERR_LCD_NOT_SUPPORT_OFF_TO_SLEEP; + } + + if (g_lcd_info.status.disp_status == LCD_IDLE_MODE) { + g_idle_before_sleep = true; + } else { + g_idle_before_sleep = false; + } + + ret = g_lcd_info.common_api->enter_sleep_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("enter sleep mode fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + ret = g_lcd_info.bus_api->bus_disable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_disable fail, ret = %X\r\n", ret); + return ret; + } + g_lcd_info.status.disp_status = LCD_SLEEP_MODE; + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_exit_sleep_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status != LCD_SLEEP_MODE) { + return EXT_ERR_LCD_NOT_IN_SLEEP_MODE; + } + + ret = g_lcd_info.common_api->exit_sleep_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("exit sleep mode fail, ret = %X\r\n", ret); + return ret; + } + + lcd_lock(); + ret = g_lcd_info.bus_api->bus_enable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("enable bus fail when exit sleep, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + + if (g_idle_before_sleep) { + g_lcd_info.status.disp_status = LCD_IDLE_MODE; + } else { + g_lcd_info.status.disp_status = LCD_NORMAL_DISPLAY; + } + + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_enter_idle_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_IDLE_MODE) { + return EXT_ERR_SUCCESS; + } + if (g_lcd_info.status.disp_status != LCD_NORMAL_DISPLAY) { + return EXT_ERR_LCD_NOT_SUPPORT_CUR_TO_IDLE; + } + + lcd_lock(); + ret = g_lcd_info.common_api->enter_idle_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("enter_idle_mode fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.disp_status = LCD_IDLE_MODE; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_exit_idle_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status != LCD_IDLE_MODE) { + return EXT_ERR_LCD_NOT_IN_IDLE_MODE; + } + + lcd_lock(); + ret = g_lcd_info.common_api->exit_idle_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("exit_idle_mode fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.disp_status = LCD_NORMAL_DISPLAY; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +static ext_errno lcd_te_param_check(void) +{ + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.screen_type == VIDEO_LCD) { + return EXT_ERR_LCD_VIDEO_SCREEN_NOT_SUPPORT_TE; + } + if (g_lcd_info.status.disp_status != LCD_NORMAL_DISPLAY && g_lcd_info.status.disp_status != LCD_IDLE_MODE) { + return EXT_ERR_LCD_INVALID_TE_ON_MODE; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_te_on(void) +{ + ext_errno ret = lcd_te_param_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + if (g_lcd_info.status.te_status == LCD_TE_ON) { + return EXT_ERR_SUCCESS; + } + + lcd_lock(); + ret = g_lcd_info.common_api->te_on(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("te_on fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.te_status = LCD_TE_ON; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_te_off(void) +{ + ext_errno ret = lcd_te_param_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + if (g_lcd_info.status.te_status == LCD_TE_OFF) { + return EXT_ERR_SUCCESS; + } + + lcd_lock(); + ret = g_lcd_info.common_api->te_off(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("te_off fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.te_status = LCD_TE_OFF; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_set_brightness(uint16_t value) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status > LCD_IDLE_MODE) { + return EXT_ERR_LCD_IN_DISPLAY_OFF_STATE; + } + + lcd_lock(); + ret = g_lcd_info.common_api->set_brightness(value); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("set_brightness fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.brightness = (uint8_t)value; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_get_brightness(uint16_t *value) +{ + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + *value = g_lcd_info.brightness; + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_write_reg(lcd_cmd_sequ *cmds, uint32_t cmd_count) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + + if (cmds == NULL || cmd_count == 0) { + return EXT_ERR_LCD_INVALID_WRITE_CMD; + } + lcd_lock(); + ret = g_lcd_info.common_api->write(cmds, cmd_count); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("write reg fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_read_reg(uint8_t cmd, uint8_t *buff, uint8_t buff_len) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status > LCD_SLEEP_MODE) { + return EXT_ERR_LCD_IN_DISPLAY_OFF_STATE; + } + if (buff == NULL || buff_len == 0) { + return EXT_ERR_LCD_INVALID_READ_CMD; + } + lcd_lock(); + ret = g_lcd_info.common_api->read(cmd, buff, buff_len); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("read reg fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_init(void) +{ + if (g_lcd_info.is_inited) { + return EXT_ERR_SUCCESS; + } + + ext_errno ret = lcd_get_ops(); + if (ret != EXT_ERR_SUCCESS && ret != EXT_ERR_MIPI_ALREADY_INIT) { + lcd_err("lcd_get_ops fail, ret = %X\r\n", ret); + return ret; + } + + ret = lcd_lock_init(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("lcd_lock_init fail, ret = %X\r\n", ret); + return ret; + } + + lcd_set_display_info(); + + ret = lcd_display_on(); + if (ret != EXT_ERR_SUCCESS) { + g_lcd_info.bus_api->bus_deinit(); + lcd_lock_deinit(); + lcd_err("lcd_display_on fail, ret = %X\r\n", ret); + return ret; + } + + g_lcd_info.is_inited = true; + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_deinit(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_SUCCESS; + } + + if (g_lcd_info.status.disp_status != LCD_DISPLAY_OFF) { + ret = g_lcd_info.common_api->display_off(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("display_off fail, ret = %X\r\n", ret); + } + + ret = g_lcd_info.bus_api->bus_disable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_disable fail, ret = %X\r\n", ret); + } + } + lcd_lock(); + ret = g_lcd_info.bus_api->bus_deinit(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_deinit fail, ret = %X\r\n", ret); + } + g_lcd_info.private_api->power_off(); + + g_lcd_info.status.disp_status = LCD_DISPLAY_OFF; + g_lcd_info.is_inited = false; + lcd_unlock(); + + lcd_lock_deinit(); + + return EXT_ERR_SUCCESS; +} + +static ext_errno lcd_lp_ctrl_check(void) +{ + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + + if (g_lcd_info.bus_api == NULL) { + return EXT_ERR_LCD_GET_ATTR_FAIL; + } + + if (g_lcd_info.bus_api->bus_lp_ctrl == NULL) { + return EXT_ERR_LCD_NOT_SUPPORT_FUNC; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_enter_sdlp(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_ENTER_SDLP); +} + +ext_errno uapi_lcd_exit_sdlp(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_EXIT_SDLP); +} + +ext_errno uapi_lcd_exit_ulps(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_EXIT_ULPS); +} + +ext_errno uapi_lcd_clear_exit_ulps(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_CLEAR_EXIT_ULPS); +} + +static void lcd_register_qspi_bus(void) +{ + lcd_bus_api qspi_bus_api = {0}; + + qspi_bus_api.bus_init = lcd_qspi_init; + qspi_bus_api.bus_deinit = lcd_qspi_deinit; + qspi_bus_api.bus_enable = lcd_qspi_enable; + qspi_bus_api.bus_disable = lcd_qspi_disable; + qspi_bus_api.bus_write_cmd = lcd_qspi_write_cmd; + qspi_bus_api.bus_read_cmd = lcd_qspi_read_cmd; + qspi_bus_api.bus_send_frame = lcd_qspi_send_frame; + qspi_bus_api.bus_suspend = lcd_qspi_suspend; + qspi_bus_api.bus_resume = lcd_qspi_resume; + qspi_bus_api.bus_register_te_isr = lcd_qspi_register_te_isr; + + lcd_bus_register_api(&qspi_bus_api, BUS_DISPLAY_QSPI); +} + +static void lcd_register_mipi_bus(void) +{ + lcd_bus_api mipi_bus_api = {0}; + + mipi_bus_api.bus_init = mipi_bus_init, + mipi_bus_api.bus_deinit = mipi_bus_deinit, + mipi_bus_api.bus_enable = mipi_bus_enable, + mipi_bus_api.bus_disable = mipi_bus_disable, + mipi_bus_api.bus_write_cmd = mipi_bus_write, + mipi_bus_api.bus_read_cmd = mipi_bus_read, + mipi_bus_api.bus_lp_ctrl = mipi_bus_lp_ctrl, + mipi_bus_api.bus_register_panel_info = mipi_bus_register_panel_info, + mipi_bus_api.bus_get_panel_timing = mipi_bus_get_panel_timing, + mipi_bus_api.bus_get_partial_display_cmd = mipi_bus_get_partial_display_cmd, + mipi_bus_api.bus_update_panel = mipi_bus_update_panel, + mipi_bus_api.bus_refresh_area = mipi_bus_refresh_area, + mipi_bus_api.bus_suspend = mipi_bus_suspend, + mipi_bus_api.bus_resume = mipi_bus_resume, + lcd_bus_register_api(&mipi_bus_api, BUS_DISPLAY_MIPI); +} + +static ext_errno lcd_info_check(const lcd_drv_cfg *info) +{ + if (info == NULL) { + return EXT_ERR_LCD_INVALID_NULL_POINTER; + } + + if ((info->bus_type != BUS_DISPLAY_MIPI) && (info->bus_type != BUS_DISPLAY_QSPI)) { + return EXT_ERR_LCD_INVALID_SCREEN_OPS; + } + + if (info->lcd_id == 0) { + return EXT_ERR_LCD_INVALID_CHIP_ID; + } + + if ((info->display_on_cmds == NULL) || (info->display_off_cmds == NULL)) { + return EXT_ERR_LCD_INVALID_WRITE_CMD; + } + + if (info->lcd_id_info.read_len == 0) { + return EXT_ERR_LCD_INVALID_READ_CMD; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_info_register(lcd_drv_cfg *info) +{ + ext_errno ret; + + ret = lcd_info_check(info); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + if (g_lcd_info.is_inited) { + return EXT_ERR_LCD_INIT_ALREADY; + } + + if (g_lcd_info.common_api == NULL) { + g_lcd_info.common_api = lcd_drv_get_common_api(); + } + + if (g_lcd_info.common_api->set_lcd_config == NULL) { + return EXT_ERR_LCD_NOT_SUPPORT_FUNC; + } + + ret = g_lcd_info.common_api->set_lcd_config(info); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + if (info->bus_type == BUS_DISPLAY_MIPI) { + lcd_register_mipi_bus(); + } else { + lcd_register_qspi_bus(); + } + + g_lcd_info.info_register = true; + + return EXT_ERR_SUCCESS; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/CMakeLists.txt new file mode 100644 index 000000000..6971096df --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/CMakeLists.txt @@ -0,0 +1,92 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. +#=============================================================================== +set(COMPONENT_NAME "touch") + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_drv.c + ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_queue1.c +) + +if("TPTYPE_TMA525B" IN_LIST DEFINES) +set(SOURCES ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch/tma525b_ctrl.c + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch/tma525b_drv1.c + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch/tma525b_touch1.c +) +elseif("TPTYPE_ZTW523" IN_LIST DEFINES) +set(SOURCES ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_ctrl.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_drv1.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_touch1.c +) +elseif("TPTYPE_FT6X46" IN_LIST DEFINES) +set(SOURCES ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/ft6x46_touch/ft6x46_ctrl.c + ${CMAKE_CURRENT_SOURCE_DIR}/ft6x46_touch/ft6x46_drv1.c + ${CMAKE_CURRENT_SOURCE_DIR}/ft6x46_touch/ft6x46_touch1.c +) +else() +set(SOURCES ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_ctrl.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_drv1.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_touch1.c +) +endif() + +if("TPTYPE_TMA525B" IN_LIST DEFINES) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch + ${ROOT_DIR}/middleware/services/gui/hal/input/include +) +elseif("TPTYPE_ZTW523" IN_LIST DEFINES) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch + ${ROOT_DIR}/middleware/services/gui/hal/input/include +) +elseif("TPTYPE_FT6X46" IN_LIST DEFINES) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/ft6x46_touch + ${ROOT_DIR}/middleware/services/gui/hal/input/include +) +else() +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch + ${ROOT_DIR}/middleware/services/gui/hal/input/include +) +endif() + +set(PRIVATE_HEADER +) + +set(PRIVATE_DEFINES +) + +set(PUBLIC_DEFINES +) + +# use this when you want to add ccflags like -include xxx +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -Wno-incompatible-function-pointer-types + -Wno-unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +build_component() + +install_sdk(${CMAKE_CURRENT_SOURCE_DIR} "*") diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_ctrl.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_ctrl.c new file mode 100644 index 000000000..7a4753583 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_ctrl.c @@ -0,0 +1,446 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: ztw523 touch driver. + * Author: @CompanyNameTag + * Create: 2022-04-12 + */ + +#include "ft6x46_ctrl.h" +#include "securec.h" +#include "cmsis_os2.h" +#include "soc_osal.h" +#include "common_def.h" +#include "pinctrl.h" +#include "chip_io.h" +#include "tcxo.h" +#include "time.h" +#include "i2c.h" +#include "gpio.h" +#include "hal_gpio.h" +#include "hal_i2c.h" +#include "touch_screen_def.h" + +bool g_host_dev_init_flag = TD_FALSE; +ft6x46_ctrl_attr g_ctrl_attr; +touch_callback g_ft6x46_callback = NULL; + +static uint8_t g_tp_recv_buf[FT6X46_INPUT_SIZE] = {0}; + +osTimerId_t g_ft6x46_timer = NULL; + +static bool g_ft6x46_timer_is_running = false; + +static void ft6x46_gpio_isr_handle(pin_t pin, uintptr_t param) +{ + unused(pin); + unused(param); + if (g_ft6x46_callback != NULL) { + g_ft6x46_callback(); + } +} + +ext_errno ft6x46_register_handle(const ft6x46_ctrl_ops *peri_data, touch_callback func) +{ + unused(peri_data); + ext_errno ret; + + + //tp_err("ft6x46_register_handle*****************888888888"); + g_ft6x46_callback = func; + /* register int io interrupt handler */ + uapi_gpio_init(); + gpio_select_core(FT6X46_INT_GPIO, CORE); + uapi_gpio_set_dir(FT6X46_INT_GPIO, GPIO_DIRECTION_INPUT); + ret = uapi_gpio_register_isr_func(FT6X46_INT_GPIO, GPIO_INTERRUPT_FALLING_EDGE, ft6x46_gpio_isr_handle); + if (ret != 0) { + tp_err("ft6x46 int callback register fail! ret=0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno ft6x46_unregister_handle(const ft6x46_ctrl_ops *peri_data) +{ + unused(peri_data); + ext_errno ret; + + /* unregister interrupt handler */ + uapi_gpio_unregister_isr_func(FT6X46_INT_GPIO); + g_ft6x46_callback = NULL; + + return EXT_ERR_SUCCESS; +} + +static ext_errno tp_peripheral_init_status_check(void) +{ + if (g_host_dev_init_flag != TD_TRUE) { + return EXT_ERR_TP_DEV_INFO_NOT_REGISTER; + } + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_ctrl_attr_check(const ft6x46_ctrl_attr *device_attr) +{ + unused(device_attr); + return EXT_ERR_SUCCESS; +} + +static ext_errno tp_i2c_rd_wr_param_check(const uint8_t *data_buf, uint32_t data_len) +{ + unused(data_buf); + unused(data_len); + ext_errno ret = tp_peripheral_init_status_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno tp_i2c_data_read(uint8_t reg_addr, uint8_t *data_buf, uint32_t data_len) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + + + ret = tp_i2c_rd_wr_param_check(data_buf, data_len); + if (ret != 0) { + tp_err("tp data read param invalid! ret=0x%x", ret); + return ret; + } + + if (memset_s(g_tp_recv_buf, data_len, 0, data_len) != EOK) { + tp_err("tp read buff set fail! ret=0x%x", ret); + return EXT_ERR_FAILURE; + } + + data.send_buf = ®_addr; + data.send_len = FT6X46_CMD_SEND_LEN; + data.receive_buf = g_tp_recv_buf; + data.receive_len = data_len; + + for (retry = 0; retry < FT6X46_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(FT6X46_I2C_BUS, FT6X46_I2C_ADDR, &data); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp data read fail! ret=0x%x", ret); + return ret; + } + ret = (uint32_t)memcpy_s(data_buf, data_len, g_tp_recv_buf, data_len); + if (ret != EOK) { + tp_err("tp data buf content copy fail! ret=0x%x", ret); + return ret; + } + return EXT_ERR_SUCCESS; +} + + +ext_errno tp_ft6x46_i2c_data_read(uint8_t reg_addr, uint8_t *data_buf, uint32_t data_len) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + //uint8_t tp_reg_addr[FT6X46_REG_BYTE_LEN]; + + ret = tp_i2c_rd_wr_param_check(data_buf, data_len); + if (ret != 0) { + tp_err("tp data read param invalid! ret=0x%x", ret); + return ret; + } + + memset_s(data_buf, data_len, 0, data_len); + //tp_reg_addr[FT6X46_I2C_SEND_INDEX0] = reg_addr & 0xff; + //tp_reg_addr[FT6X46_I2C_SEND_INDEX1] = (reg_addr >> OFFSET_8_BITS) & 0xff; + + data.send_buf = ®_addr; + data.send_len = sizeof(reg_addr); + data.receive_buf = data_buf; + data.receive_len = data_len; + + for (retry = 0; retry < FT6X46_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(FT6X46_I2C_BUS, FT6X46_I2C_ADDR, &data); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp data read fail! ret=0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno tp_i2c_cmd_write(uint8_t cmd) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + //uint8_t tp_reg_addr[FT6X46_CMD_SEND_LEN]; + + ret = tp_peripheral_init_status_check(); + if (ret != 0) { + tp_err("host peripheral not init! ret=0x%x", ret); + return ret; + } + //tp_reg_addr[FT6X46_I2C_SEND_INDEX0] = cmd & 0xff; + //tp_reg_addr[FT6X46_I2C_SEND_INDEX1] = (cmd >> OFFSET_8_BITS) & 0xff; + + data.send_buf = &cmd; + data.send_len = FT6X46_CMD_SEND_LEN; + data.receive_buf = NULL; + data.receive_len = 0; + + for (retry = 0; retry < FT6X46_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(FT6X46_I2C_BUS, FT6X46_I2C_ADDR, &data); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp data write fail! ret=0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno tp_i2c_data_write(uint8_t reg_addr, uint8_t *data_buf, uint16_t data_len) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + uint16_t send_len; + + ret = tp_i2c_rd_wr_param_check(data_buf, data_len); + if (ret != 0) { + tp_err("tp data write param invalid! ret=0x%x", ret); + return ret; + } + + send_len = data_len + sizeof(uint8_t); + + write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); + if (write_data == NULL) { + tp_err("tp send buff malloc fail!"); + return EXT_ERR_MALLOC_FAILURE; + } + + write_data[FT6X46_I2C_SEND_INDEX0] = reg_addr; + ret = (uint32_t)memcpy_s(write_data + sizeof(uint8_t), send_len - sizeof(uint8_t), data_buf, data_len); + if (ret != EOK) { + tp_err("tp send_buf content copy fail! ret=0x%x", ret); + osal_kfree(write_data); + return ret; + } + + data.send_buf = write_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; + + for (retry = 0; retry < FT6X46_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(FT6X46_I2C_BUS, FT6X46_I2C_ADDR, &data); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp data write fail! ret=0x%x", ret); + osal_kfree(write_data); + return ret; + } + + osal_kfree(write_data); + return EXT_ERR_SUCCESS; +} + +ext_errno tp_ft6x46_i2c_data_write(uint8_t reg_addr, uint8_t *data_buf, uint16_t data_len) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + uint16_t send_len; + + ret = tp_i2c_rd_wr_param_check(data_buf, data_len); + if (ret != 0) { + tp_err("tp data write param invalid! ret=0x%x", ret); + return ret; + } + + send_len = data_len + sizeof(uint8_t); + + write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); + if (write_data == NULL) { + tp_err("tp send buff malloc fail!"); + return EXT_ERR_MALLOC_FAILURE; + } + + write_data[FT6X46_I2C_SEND_INDEX0] = reg_addr; + ret = (uint32_t)memcpy_s(write_data + sizeof(uint8_t), send_len - sizeof(uint8_t), data_buf, data_len); + if (ret != EOK) { + tp_err("tp send_buf content copy fail! ret=0x%x", ret); + osal_kfree(write_data); + return ret; + } + + data.send_buf = write_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; + + for (retry = 0; retry < FT6X46_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(FT6X46_I2C_BUS, FT6X46_I2C_ADDR, &data); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp data write fail! ret=0x%x", ret); + osal_kfree(write_data); + return ret; + } + + osal_kfree(write_data); + return EXT_ERR_SUCCESS; +} + +ext_errno tp_ft6x46_i2c_data_write_reg(uint8_t addr, uint8_t val) +{ + return tp_ft6x46_i2c_data_write(addr, &val, 1); +} + +void ft6x46_check_error(void) +{ + uint8_t data_buf[3] = {0}; + uint8_t cnt = 0; + + tp_i2c_data_read(0x91, &data_buf[0], 1); + LOS_Mdelay(1); + tp_i2c_data_read(0x91, &data_buf[1], 1); + LOS_Mdelay(1); + tp_i2c_data_read(0x91, &data_buf[2], 1); + LOS_Mdelay(1); + + if(data_buf[0] == data_buf[1] && data_buf[1] == data_buf[2]) + { + // printf("ft6x46_check_error !!!! 0x%x \n",data_buf[0]); + ft6x46_resume_reset(); + } + +} + +ext_errno ft6x46_host_peripheral_init(ft6x46_ctrl_attr *attr) +{ + ext_errno ret; + + if (attr == NULL) { + tp_err("ft6x46 communication interface cfg is empty!"); + return EXT_ERR_FAILURE; + } + ret = ft6x46_ctrl_attr_check(attr); + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp invalid dev attr! ret=0x%x", ret); + return ret; + } + + ret = (ext_errno)memcpy_s(&(g_ctrl_attr), sizeof(ft6x46_ctrl_attr), attr, sizeof(ft6x46_ctrl_attr)); + if (ret != EOK) { + tp_err("tp attr content copy fail! ret=0x%x", ret); + return ret; + } + + /* init i2c */ + errcode_t result; + result = uapi_i2c_master_init(FT6X46_I2C_BUS, 100000, I2C_SPEED_MODE_SS); /* 400000: 400KHz */ + if (result != EXT_ERR_SUCCESS) { + tp_err("tp i2c init fail! ret=0x%x", result); + return EXT_ERR_SUCCESS; + } + + tp_print("TOUCH:i2c_id = %d i2c_speed = %d slave_addr = 0x%x \r\n", + g_ctrl_attr.i2c_id, g_ctrl_attr.i2c_speed, FT6X46_I2C_ADDR); + g_host_dev_init_flag = true; + + + g_ft6x46_timer = osTimerNew((osTimerFunc_t)ft6x46_check_error, osTimerPeriodic, NULL, NULL); + + return EXT_ERR_SUCCESS; +} + +ext_errno ft6x46_host_init_sample(void) +{ + ext_errno ret; + PRINT("**********ft6x46_host_init_sample**********\r\n"); + ret = ft6x46_host_peripheral_init(&g_ctrl_attr); + ret = ft6x46_init(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("tp host init fail! ret=0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno ft6x46_reset(void) +{ + uapi_gpio_set_dir(FT6X46_RESET_GPIO, GPIO_DIRECTION_OUTPUT); + /* Config Gpio For Reset Pin */ + uapi_gpio_set_val(FT6X46_RESET_GPIO, GPIO_LEVEL_HIGH); + /* reset high delay 20ms */ + osDelay(20); + uapi_gpio_set_val(FT6X46_RESET_GPIO, GPIO_LEVEL_LOW); + /* reset low delay 100ms */ + osDelay(100); + uapi_gpio_set_val(FT6X46_RESET_GPIO, GPIO_LEVEL_HIGH); + /* reset high delay 200ms */ + osDelay(200); + return EXT_ERR_SUCCESS; +} + +void ft6x46_resume_reset(void) +{ + uapi_gpio_set_dir(FT6X46_RESET_GPIO, GPIO_DIRECTION_OUTPUT); + /* drvdata is global variable point and no need to handle null */ + uapi_gpio_set_val(FT6X46_RESET_GPIO, GPIO_LEVEL_HIGH); + osDelay(1); + uapi_gpio_set_val(FT6X46_RESET_GPIO, GPIO_LEVEL_LOW); + /* delay 10ms */ + osDelay(10); + uapi_gpio_set_val(FT6X46_RESET_GPIO, GPIO_LEVEL_HIGH); + /* delay 100ms */ + osDelay(100); + // uapi_gpio_set_dir(FT6X46_RESET_GPIO, GPIO_DIRECTION_INPUT); +} + + +void ft6x46_check_error_timer_start(uint32_t rtc_ms) +{ + if (g_ft6x46_timer == NULL) + return; + if (g_ft6x46_timer_is_running) + osTimerStop(g_ft6x46_timer); + if (g_ft6x46_timer_is_running == true) + osTimerStart(g_ft6x46_timer, rtc_ms); + g_ft6x46_timer_is_running = true; +} + +void ft6x46_check_error_timer_stop(void) +{ + if (g_ft6x46_timer == NULL) + return; + if (g_ft6x46_timer_is_running) + { + osTimerStop(g_ft6x46_timer); + g_ft6x46_timer_is_running = false; + } + +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_ctrl.h b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_ctrl.h new file mode 100644 index 000000000..3403bb558 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_ctrl.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: ztw523 touch driver. + * Author: @CompanyNameTag + * Create: 2022-04-12 + */ + +#ifndef FT6X46_CTRL_H +#define FT6X46_CTRL_H + +#include "stdio.h" +#include "debug_print.h" +#include "stdint.h" +#include "product.h" +#include "td_base.h" +#include "platform_core.h" +#include "ft6x46_touch1.h" + +/* host peripheral definitions */ + +//#define FT6X46_I2C_ADDR 0x20 +#define FT6X46_I2C_ADDR 0x38 +#define FT6X46_I2C_SPEED I2C_SPEED_MODE_SS +#define FT6X46_REG_BYTE_LEN 2 +#define OFFSET_8_BITS 8 +#define FT6X46_REG_WRITE_LEN 4 + +#define FT6X46_CMD_SEND_LEN 2 +// #define FT6X46_CMD_SEND_LEN 1 + +#define FT6X46_REG_DATA_LEN 2 +#define FT6X46_I2C_TIME_MAX 3 +#define FT6X46_INPUT_SIZE 156 + +#define FT6X46_I2C_SEND_INDEX0 0 +#define FT6X46_I2C_SEND_INDEX1 1 +#define FT6X46_I2C_SEND_INDEX2 2 +#define FT6X46_I2C_SEND_INDEX3 3 + + +#define FTS_REG_POWER_MODE 0xA5 + + +typedef struct { + uint32_t int_gpio; + uint32_t reset_gpio; + i2c_bus_t i2c_id; + uint32_t i2c_speed; +} ft6x46_ctrl_attr; + +typedef ext_errno (*ft6x46_bus_init)(ft6x46_ctrl_attr *attr); + +typedef struct { + ft6x46_ctrl_attr attr; + ft6x46_bus_init bus_init; +} ft6x46_ctrl_ops; + +ext_errno ft6x46_host_peripheral_init(ft6x46_ctrl_attr *attr); +ext_errno ft6x46_register_handle(const ft6x46_ctrl_ops *peri_data, touch_callback func); +ext_errno ft6x46_unregister_handle(const ft6x46_ctrl_ops *peri_data); +ext_errno ft6x46_reset(void); +void ft6x46_resume_reset(void); +void ft6x46_delay(uint32_t ms); + +ext_errno tp_ft6x46_i2c_data_read(uint8_t reg_addr, uint8_t *data_buf, uint32_t data_len); +ext_errno tp_ft6x46_i2c_data_write(uint8_t reg_addr, uint8_t *data_buf, uint16_t data_len); +ext_errno tp_ft6x46_i2c_data_write_reg(uint8_t addr, uint8_t val); + +void ft6x46_check_error_timer_start(uint32_t rtc_ms); +void ft6x46_check_error_timer_stop(void); + +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_drv1.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_drv1.c new file mode 100644 index 000000000..928c58eac --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_drv1.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: ztw523 touch driver. + * Author: @CompanyNameTag + * Create: 2022-04-12 + */ + +#include "ft6x46_drv1.h" +#include "touch_screen_def.h" +#include "ft6x46_ctrl.h" +#include "i2c.h" +#include "debug_print.h" +#include "hal_i2c.h" + +static ext_errno ft6x46_drv_init(ft6x46_ctrl_ops *config) +{ + ext_errno ret; + ft6x46_ctrl_ops *ops = config; + + tp_err("ft6x46_drv_init!11111"); + + if (ops == NULL) { + tp_err("peripheral ops is empty!"); + return EXT_ERR_FAILURE; + } + + if (ops->bus_init == NULL) { + tp_err("peripheral bus_init func is empty!"); + return EXT_ERR_FAILURE; + } + + ret = ops->bus_init(&(ops->attr)); + if (ret != EXT_ERR_SUCCESS) { + tp_err("ZTW523 bus_init fail! ret = 0x%x", ret); + return ret; + } + + ret = ft6x46_init(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("ZTW523 init fail! ret = 0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_drv_deinit(void) +{ + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_drv_get_info(uint8_t *data, uint8_t data_len) +{ + return ft6x46_irq_callback(data, data_len); +} + +static ext_errno ft6x46_drv_suspend(void) +{ + //return ft6x46_set_power_mode(MC_TP_SUSPEND_SCAN); + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_drv_resume(void) +{ + //return ft6x46_set_power_mode(MC_TP_RESUME_SCAN); + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_drv_sleep(void) +{ + //return ft6x46_set_power_mode(MC_TP_SLEEP_WORK_MODE); + return EXT_ERR_SUCCESS; +} + +touch_peripheral_api g_ft6x46_api = { + .touch_init = ft6x46_drv_init, + .touch_deinit = ft6x46_drv_deinit, + .touch_get_tpinfo = ft6x46_drv_get_info, + .touch_suspend = ft6x46_drv_suspend, + .touch_resume = ft6x46_drv_resume, + .touch_sleep = ft6x46_drv_sleep, + .touch_bus_init = ft6x46_host_peripheral_init, + .register_callback = ft6x46_register_handle, + .unregister_callback = ft6x46_unregister_handle, +}; + +ft6x46_ctrl_ops g_ft6x46_ctrl = { + .attr = { + .int_gpio = FT6X46_INT_GPIO, + .i2c_id = FT6X46_I2C_BUS, + .i2c_speed = I2C_SPEED_MODE_SS, + }, + .bus_init = (ft6x46_bus_init)ft6x46_host_peripheral_init, +}; + +void *touch_screen_get_api(void) +{ + return ((void *)&g_ft6x46_api); +} + +void *touch_screen_get_peri_attr(void) +{ + return ((void *)&g_ft6x46_ctrl); +} \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_drv1.h b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_drv1.h new file mode 100644 index 000000000..c26f3a4f0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_drv1.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: ztw523 touch driver. + * Author: @CompanyNameTag + * Create: 2022-04-12 + */ + +#ifndef FT6X46_DRV1_H +#define FT6X46_DRV1_H + +void *touch_screen_get_api(void); +void *touch_screen_get_peri_attr(void); + +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c new file mode 100644 index 000000000..aa6f91c5d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c @@ -0,0 +1,980 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: ft6x46 touch driver. + * Author: @CompanyNameTag + * Create: 2021-05-29 + */ + +#include "ft6x46_touch1.h" +#include "time.h" +#include "soc_osal.h" +#include "osal_timer.h" +#include "osal_mutex.h" +#include "securec.h" +#include "ft6x46_ctrl.h" +#include "tcxo.h" +#include "cmsis_os2.h" +#include "common_def.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +ft6x46_drv_data g_ft6x46_drv = { + .chip_status = FT6X46_NOT_READY, + .ops_mux = {0}, + .int_mask = FT6X46_INT_MASK, + .work_status = FT6X46_WORK_INVALID, + .fw_upgrade_flag = TD_FALSE, + .gesture_wakeup = TD_FALSE, + .host_dev_init_flag = TD_FALSE, + .chip_info = FT6X46_DEVICE_INFO, + .p_void = NULL, +}; +static ext_errno ft6x46_config(void); +static void ft6x46_set_irq_mode(ft6x46_irq_status irq_status, uint16_t irq_mask) +{ + unused(irq_mask); + ext_errno ret; + uint16_t reg_write = 0; + + tp_print("TOUCH:set irq mode %d", irq_status); + + switch (irq_status) { + case FT6X46_IRQ_DISABLE: + /* Write Int Register */ + reg_write = FT6X46_INT_NONE; + // ret = tp_i2c_reg_write(FT6X46_INT_ENABLE_FLAG, reg_write); + // if (ret != EXT_ERR_SUCCESS) { + // tp_err("TOUCH:set irq mode disable 0x%x", ret); + // return; + // } + break; + + case FT6X46_IRQ_ENABLE: + /* Write Int Register */ + reg_write = FT6X46_INT_MASK; + // ret = tp_i2c_reg_write(FT6X46_INT_ENABLE_FLAG, reg_write); + // if (ret != EXT_ERR_SUCCESS) { + // tp_err("TOUCH:set irq mode enable 0x%x", ret); + // return; + // } + break; + + default: + tp_err("TOUCH:not support irq mode 0x%x", irq_status); + break; + } + + return; +} + +static ext_errno ft6x46_parse_gesture_input(void) +{ + ext_errno ret; + uint16_t gesture_val; + uint16_t reg_read; + uint16_t reg_write; + + reg_read = 0; + // ret = tp_i2c_data_read(FT6X46_GESTURE_WAKEUP_REG, (uint8_t *)®_read, FT6X46_DATA_LEN); + // if (ret != EXT_ERR_SUCCESS) { + // tp_err("TOUCH:parse gesture input read fail 0x%x", ret); + // return EXT_ERR_FAILURE; + // } + gesture_val = reg_read; + tp_print("TOUCH:parse gesture input ok 0x%x", reg_read); + + reg_write = 0; + // ret = tp_i2c_reg_write(FT6X46_GESTURE_WAKEUP_REG, reg_write); + // if (ret != EXT_ERR_SUCCESS) { + // tp_err("TOUCH:parse gesture input write fail 0x%x", ret); + // return EXT_ERR_FAILURE; + // } + + switch (gesture_val) { + case FT6X46_GESTURE_SIGNAL_CLICK: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_SHORT_CLICK; + break; + case FT6X46_GESTURE_DOUBLE_CLICK: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_DOUBLE_CLICK; + break; + case FT6X46_GESTURE_SLIDE_UP: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_SLIDE_UP; + break; + case FT6X46_GESTURE_SLIDE_DOWN: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_SLIDE_DOWN; + break; + default: + tp_err("TOUCH:gesture %d not Support", gesture_val); + return EXT_ERR_FAILURE; + } + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_parse_touch_input(void) +{ + static uint8_t touch_input[FT6X46_TOUCHINFO_LEN] = { 0 }; + uint16_t touch_status; + uint16_t x_axis; + uint16_t y_axis; + uint8_t sub_status; + + ext_errno ret = tp_i2c_data_read(FT6X46_POINT_STATUS_REG, touch_input, FT6X46_TOUCHINFO_LEN); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:touch input read error! ret = 0x%x", ret); + return EXT_ERR_FAILURE; + } + touch_status = ((uint16_t)touch_input[FT6X46_STATUSH_OFFSET] << FT6X46_REGDATA_SHIFT) | + (touch_input[FT6X46_STATUSL_OFFSET]); + if ((touch_status & FT6X46_PALM_MASK) != 0) { + g_ft6x46_drv.touch_msg.tp_event = MC_TP_COVER; + return EXT_ERR_SUCCESS; + } + + if (touch_status != 0) { + sub_status = touch_input[FT6X46_SUBSTATUS_OFFSET] & FT6X46_TOUCHINFO_MASK; + x_axis = ((uint16_t)touch_input[FT6X46_XH_OFFSET] << FT6X46_REGDATA_SHIFT) | (touch_input[FT6X46_XL_OFFSET]); + y_axis = ((uint16_t)touch_input[FT6X46_YH_OFFSET] << FT6X46_REGDATA_SHIFT) | (touch_input[FT6X46_YL_OFFSET]); + + switch (sub_status) { + case FT6X46_TOUCH_DOWN: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_PRESS; + break; + /* Need To Modify For UI */ + case FT6X46_TOUCH_EXIST: + case FT6X46_TOUCH_MOVE: + case FT6X46_TOUCH_NONE: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_MOVE; + break; + case FT6X46_TOUCH_UP: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_RELEASE; + break; + + default: + tp_err("TOUCH:parse input wrong status|substatus 0x%08x", + ((uint32_t)touch_status << FT6X46_SHIFT_16_BIT) | (uint32_t)sub_status); + return EXT_ERR_FAILURE; + } + g_ft6x46_drv.touch_msg.tp_event_info.x_axis[0] = x_axis; + g_ft6x46_drv.touch_msg.tp_event_info.y_axis[0] = y_axis; + g_ft6x46_drv.touch_msg.tv_usec = (uint32_t)uapi_tcxo_get_ms(); + } else { + g_ft6x46_drv.touch_msg.tp_event = MC_TP_INVALID; + tp_print("TOUCH:parse wrong touchstatus %d", touch_status); + return EXT_ERR_SUCCESS; + } + + return EXT_ERR_SUCCESS; +} + + +/*Max point numbers of gesture trace*/ +#define MAX_POINTS_GESTURE_TRACE 6 +/*Length of gesture information*/ +#define MAX_LEN_GESTURE_INFO (MAX_POINTS_GESTURE_TRACE * 4 + 2) + +/*Max point numbers of touch trace*/ +#define MAX_POINTS_TOUCH_TRACE 1 +/*Length of touch information*/ +#define MAX_LEN_TOUCH_INFO (MAX_POINTS_TOUCH_TRACE * 6 + 2) + +/*Max touch points that touch controller supports*/ +#define FTS_MAX_POINTS_SUPPORT 10 + +struct fts_ts_event { + int x; /*x coordinate */ + int y; /*y coordinate */ + int p; /* pressure */ + int type; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */ + int id; /*touch ID */ + int area; /*touch area*/ +}; + +static ext_errno fts_touch_process(void) +{ + ext_errno ret; + uint8_t i = 0; + uint8_t base = 0; + uint8_t regaddr = 0x01; + uint8_t buf[MAX_LEN_TOUCH_INFO];/*A maximum of two points are supported*/ + uint8_t point_num = 0; + uint8_t touch_event_nums = 0; + uint8_t point_id = 0; + struct fts_ts_event events[FTS_MAX_POINTS_SUPPORT]; /* multi-touch */ + + + /*read touch information from reg0x01*/ + ret = tp_ft6x46_i2c_data_read(regaddr, buf, MAX_LEN_TOUCH_INFO); + if (ret != EXT_ERR_SUCCESS) { + tp_err("Read touch information from reg0x01 fails"); + return ret; + } + + /*print touch buffer, for debug usage*/ + //log_touch_buf(buf, MAX_LEN_TOUCH_INFO); + + //if ((buf[1] == 0xFF) && (buf[2] == 0xFF) && (buf[3] == 0xFF)) { + // tp_err("FW initialization, need recovery"); + // if (fts_data->gesture_support && fts_data->suspended) + // fts_write_reg(FTS_REG_GESTURE_EN, FTS_REG_GESTURE_ENABLE); + //} + + /*parse touch information based on register map*/ + memset(events, 0xFF, sizeof(struct fts_ts_event) * FTS_MAX_POINTS_SUPPORT); + point_num = buf[1] & 0x0F; + if (point_num > FTS_MAX_POINTS_SUPPORT) { + tp_err("invalid point_num(%d)", point_num); + return EXT_ERR_FAILURE; + } + + for (i = 0; i < MAX_POINTS_TOUCH_TRACE; i++) { + base = 2 + i * 6; + point_id = buf[base + 2] >> 4; + if (point_id >= MAX_POINTS_TOUCH_TRACE) { + tp_err("abnormal touch data point_id %d\r\n",point_id); + break; + } + + events[i].x = ((buf[base] & 0x0F) << 8) + buf[base + 1]; + events[i].y = ((buf[base + 2] & 0x0F) << 8) + buf[base + 3]; + events[i].id = point_id; + events[i].type = (buf[base] >> 6) & 0x03; + events[i].p = buf[base + 4]; + events[i].area = buf[base + 5]; + if (((events[i].type == 0) || (events[i].type == 2)) & (point_num == 0)) { + tp_err("abnormal touch data from fw"); + return EXT_ERR_FAILURE; + } + + touch_event_nums++; + } + + if (touch_event_nums == 0) { + tp_err("no touch point information(%02x)", buf[1]); + return EXT_ERR_FAILURE; + } + + /*print touch information*/ + //log_touch_info(events, touch_event_nums); + + /*Now you have get the touch information, you can report anything(X/Y coordinates...) you want to system*/ + /*TODO...(report touch information to system)*/ + /*Below sample code is a pseudo code*/ + + for (i = 0; i < touch_event_nums; i++) { + #if 0 + if ((events[i].type == 0) || (events[i].type == 2)) { + /* The event of point(point id is events[i].id) is down event, the finger of this id stands for is + * pressing on the screen.*/ + /*TODO...(down event)*/ + } else { + /*TODO...(up event)*/ + } + #endif + switch (events[i].type) { + case 0: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_PRESS; + break; + /* Need To Modify For UI */ + case 2: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_MOVE; + break; + case 1: + g_ft6x46_drv.touch_msg.tp_event = MC_TP_RELEASE; + break; + + default: + tp_err("TOUCH:parse input wrong status|substatus"); + return EXT_ERR_FAILURE; + } + g_ft6x46_drv.touch_msg.tp_event_info.x_axis[0] = events[i].x; + g_ft6x46_drv.touch_msg.tp_event_info.y_axis[0] = events[i].y; + g_ft6x46_drv.touch_msg.tv_usec = (uint32_t)uapi_tcxo_get_ms(); + tp_print("event %d, x %d, y %d, time %d", + g_ft6x46_drv.touch_msg.tp_event, + g_ft6x46_drv.touch_msg.tp_event_info.x_axis[0], + g_ft6x46_drv.touch_msg.tp_event_info.y_axis[0], + g_ft6x46_drv.touch_msg.tv_usec); + } + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_parse_input(void) +{ + ext_errno ret = EXT_ERR_FAILURE; + uint16_t reg_write; + + if (g_ft6x46_drv.gesture_wakeup == TD_TRUE) { + ret = ft6x46_parse_gesture_input(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:parse gesture input fail 0x%x", ret); + return EXT_ERR_FAILURE; + } + } else { + ret = ft6x46_parse_touch_input(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:parse touch input fail 0x%x", ret); + return EXT_ERR_FAILURE; + } + } + /* clear int */ + reg_write = FT6X46_CLEAR_INT_STATUS_CMD; + ret = tp_i2c_cmd_write(reg_write); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:parse input clear int fail 0x%x", ret); + return EXT_ERR_FAILURE; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno ft6x46_irq_callback(uint8_t *data_buf, uint8_t data_len) +{ + unused(data_len); + g_ft6x46_drv.touch_msg.tp_event = MC_TP_INVALID; + + int32_t mem_ret; + static int fail_count = 0; + if (g_ft6x46_drv.work_status != FT6X46_WORK_NORMAL) { + tp_print("TOUCH:ft6x46_irq_callback not in normal mode skip read touch"); + return ERRCODE_FAIL; + } + + fts_touch_process(); + + // if (fts_touch_process() != ERRCODE_SUCC) + // { + // fail_count ++ ; + // }else{ + // fail_count = 0; + // } + // if (fail_count%50 == 49){ + // tp_print("TOUCH:ft6x46_irq_callback fail to reset touch "); + // hal_custom_resume_touch(); + // } + + mem_ret = memcpy_s(data_buf, sizeof(input_event_info), &(g_ft6x46_drv.touch_msg), sizeof(input_event_info)); + if (mem_ret != EOK) { + tp_err("TOUCH:mem cpy error, ret = 0x%x", mem_ret); + return EXT_ERR_FAILURE; + } + + return EXT_ERR_SUCCESS; +} + +/* chip id */ +#define FTS_CHIP_IDH 0x64 +#define FTS_CHIP_IDL 0x56 + + +#define FTS_CMD_READ_ID 0x90 + +/* register address */ +#define FTS_REG_CHIP_ID 0xA3 +#define FTS_REG_CHIP_ID2 0x9F + +#define FTS_CMD_START_DELAY 12 + + +static ext_errno ft6x46_power_sequence(void) +{ + ext_errno ret; + uint8_t chip_id[2] = { 0 }; + + /*delay 200ms,wait fw*/ + osDelay(FT6X46_GENERAL_DELAY_200); + + /*get chip id*/ + ret = tp_ft6x46_i2c_data_read(FTS_REG_CHIP_ID, &chip_id[0], 1); + if (ret != EXT_ERR_SUCCESS) { + tp_err("222222222get ic information, error1"); + return EXT_ERR_TP_ZTW523_POWERUP_READ_CHIPID; + } + ret = tp_ft6x46_i2c_data_read(FTS_REG_CHIP_ID2, &chip_id[1], 1); + if (ret != EXT_ERR_SUCCESS) { + tp_err("3333333get ic information, error2"); + return EXT_ERR_TP_ZTW523_POWERUP_READ_CHIPID; + } + // tp_print("11111111111111get ic information, chip id = 0x%02x%02x", chip_id[0], chip_id[1]); + if ((FTS_CHIP_IDH == chip_id[0]) && (FTS_CHIP_IDL == chip_id[1])) { + tp_warning("get ic information, chip id = 0x%02x%02x", chip_id[0], chip_id[1]); + return EXT_ERR_SUCCESS; + } + + // tp_err("fw is invalid, need read boot id"); + ret = tp_ft6x46_i2c_data_write_reg(0x55, 0xAA); + if (ret != EXT_ERR_SUCCESS) { + tp_err("start cmd write fail"); + return ret; + } + + osDelay(FTS_CMD_START_DELAY); + ret = tp_ft6x46_i2c_data_read(FTS_CMD_READ_ID, chip_id, 2); + if((ret == EXT_ERR_SUCCESS) && ((FTS_CHIP_IDH == chip_id[0]) && (FTS_CHIP_IDL == chip_id[1]))) { + tp_err("get ic information, boot id = 0x%02x%02x", chip_id[0], chip_id[1]); + ret = EXT_ERR_SUCCESS; + } else { + tp_err("read boot id fail,read:0x%02x%02x", chip_id[0], chip_id[1]); + return EXT_ERR_FAILURE; + } + return ret; + +} + +static void ft6x46_clear_interrupt(uint8_t retry_times, uint16_t delay) +{ + uint16_t reg_write = FT6X46_CLEAR_INT_STATUS_CMD; + ext_errno ret; + uint8_t times; + for (times = 1; times <= retry_times; times++) { + ret = tp_i2c_cmd_write(reg_write); + if (ret == EXT_ERR_SUCCESS) { + return; + } + osDelay(delay); + } + + if (times > retry_times) { + tp_warning("TOUCH:Clear Int Cmd1! ret = 0x%x", ret); + } +} + +static ext_errno ft6x46_reg_config(void) +{ + ext_errno ret; + // uint16_t reg_write; + + // /* Initial Touch Mode */ + // reg_write = FT6X46_POINT_MODE; +// ret = tp_i2c_reg_write(FT6X46_INITIAL_TOUCH_MODE, reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_INIT_TOUCHMODE; +// } + +// ret = tp_i2c_reg_write(FT6X46_TOUCH_MODE, reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_TOUCHMODE; +// } + +// /* Set Finger Num */ +// reg_write = FT6X46_MAX_SUPPORTED_FINGER_NUM; +// ret = tp_i2c_reg_write(FT6X46_SUPPORTED_FINGER_NUM, reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_FINGER_NUM; +// } + +// /* Set X Resolution */ +// reg_write = FT6X46_RES_MAX_X; +// ret = tp_i2c_reg_write(FT6X46_X_RESOLUTION, reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_XRES; +// } + +// /* Set Y Resolution */ +// reg_write = FT6X46_RES_MAX_Y; +// ret = tp_i2c_reg_write(FT6X46_Y_RESOLUTION, reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_YRES; +// } + +// /* Set Lock Point Range */ +// ret = tp_i2c_reg_write(FT6X46_HOLD_POINT_TRESHHOLD, FT6X46_POINT_TRESHHOLD); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_YRES; +// } + +// /* Write Calib Cmd */ +// reg_write = FT6X46_CALIBRATE_CMD; +// ret = tp_i2c_cmd_write(reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_CALIBCMD; +// } + +// /* Write Int Register */ +// reg_write = FT6X46_INT_MASK; +// ret = tp_i2c_reg_write(FT6X46_INT_ENABLE_FLAG, reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_INTMASK; +// } +// #ifdef FT6X46_GESTURE_WAKEUP +// /* Write Gesture Register */ +// reg_write = FT6X46_GESTURE_WAKEUP_INIT; +// ret = tp_i2c_reg_write(FT6X46_GESTURE_WAKEUP_REG, reg_write); +// if (ret != EXT_ERR_SUCCESS) { +// return EXT_ERR_TP_ZTW523_CONFIG_WRITE_GESWAKEUP; +// } +// #endif + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_configuration(void) +{ + ext_errno ret; + uint8_t retry_times = 0; + uint16_t reg_read; + uint16_t reg_write; + + /* Software Reset */ + reg_write = FT6X46_SWRESET_CMD; + for (retry_times = 0; retry_times < FT6X46_RETRY_TIMES; retry_times++) { + ret = tp_i2c_cmd_write(reg_write); + if (ret == EXT_ERR_SUCCESS) { + break; + } + osDelay(FT6X46_RESETHIGH_DELAY); + } + + if (retry_times >= FT6X46_RETRY_TIMES) { + tp_err("TOUCH:configuration sw reset fail! ret = 0x%x", ret); + return EXT_ERR_TP_ZTW523_CONFIG_RESET; + } + + /* Read Firmware Version */ + reg_read = 0; + ret = tp_i2c_data_read(FT6X46_FIRMWARE_VERSION, (uint8_t *)®_read, FT6X46_DATA_LEN); + if (ret != EXT_ERR_SUCCESS) { + return EXT_ERR_TP_ZTW523_CONFIG_READ_FWVERSION; + } + g_ft6x46_drv.firmware_version = reg_read; + + /* Read Minor Firmware Version */ + reg_read = 0; + ret = tp_i2c_data_read(FT6X46_MINOR_FW_VERSION, (uint8_t *)®_read, FT6X46_DATA_LEN); + if (ret != EXT_ERR_SUCCESS) { + return EXT_ERR_TP_ZTW523_CONFIG_READ_FWMINORVERSION; + } + g_ft6x46_drv.minor_firmware_version = reg_read; + + /* Read Hw ID */ + reg_read = 0; + ret = tp_i2c_data_read(FT6X46_HW_ID, (uint8_t *)®_read, FT6X46_DATA_LEN); + if (ret != EXT_ERR_SUCCESS) { + tp_err("configuration error (read hw id) 0x%x", ret); + return EXT_ERR_TP_ZTW523_GET_HWID_READ_ID; + } + g_ft6x46_drv.chip_hw_id = reg_read; + + /* Read Register Version */ + reg_read = 0; + ret = tp_i2c_data_read(FT6X46_DATA_VERSION_REG, (uint8_t *)®_read, FT6X46_DATA_LEN); + if (ret != EXT_ERR_SUCCESS) { + return EXT_ERR_TP_ZTW523_CONFIG_READ_DATAREG; + } + g_ft6x46_drv.reg_version = reg_read; + + ret = ft6x46_reg_config(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + /* Write Clear Int Cmd */ + ft6x46_clear_interrupt(FT6X46_RETRY_TIMES, FT6X46_GENERAL_DELAY_1); + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_get_panel_info(void) +{ + ext_errno ret; + uint16_t reg_read = 0; + /* Read X Channel Num */ + ret = tp_i2c_data_read(FT6X46_TOTAL_NUMBER_OF_X, (uint8_t *)®_read, FT6X46_DATA_LEN); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:GetPanelInfo error read x channel 0x%x", ret); + return EXT_ERR_FAILURE; + } + + g_ft6x46_drv.panel_info.xchannel_num = reg_read; + /* Read Y Channel Num */ + reg_read = 0; + ret = tp_i2c_data_read(FT6X46_TOTAL_NUMBER_OF_Y, (uint8_t *)®_read, FT6X46_DATA_LEN); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:GetPanelInfo error read y channel 0x%x", ret); + return EXT_ERR_FAILURE; + } + + g_ft6x46_drv.panel_info.ychannel_num = reg_read; + g_ft6x46_drv.panel_info.total_dnd_num = + g_ft6x46_drv.panel_info.xchannel_num * g_ft6x46_drv.panel_info.ychannel_num; + g_ft6x46_drv.panel_info.total_self_dnd_num = + g_ft6x46_drv.panel_info.xchannel_num + g_ft6x46_drv.panel_info.ychannel_num; + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_standby(void) +{ + ext_errno ret; + uint16_t reg_write; + uint8_t retry_times; + + if ((g_ft6x46_drv.work_status == FT6X46_WORK_STANDBY) || (g_ft6x46_drv.work_status == FT6X46_WORK_SLEEP)) { + tp_print("alread standby or sleep"); + return EXT_ERR_SUCCESS; + } + /* Disabel Irq */ + ft6x46_set_irq_mode(FT6X46_IRQ_DISABLE, FT6X46_INT_NONE); + + reg_write = FT6X46_POWER_CTL_BEGIN; + ret = tp_i2c_cmd_write(reg_write); + if (ret != EXT_ERR_SUCCESS) { + ft6x46_set_irq_mode(FT6X46_IRQ_ENABLE, FT6X46_INT_MASK); + tp_err("standby failed 0x%x", ret); + return EXT_ERR_FAILURE; + } + /* delay 10 ms */ + osDelay(FT6X46_GENERAL_DELAY_10); + /* Send Clear Int Cmd */ + reg_write = FT6X46_CLEAR_INT_STATUS_CMD; + for (retry_times = 0; retry_times < FT6X46_INIT_RETRY_TIMERS; retry_times++) { + ret = tp_i2c_cmd_write(reg_write); + if (ret == EXT_ERR_SUCCESS) { + break; + } + /* delay 10 ms */ + osDelay(FT6X46_GENERAL_DELAY_10); + } + + /* Send Idle Cmd */ + reg_write = FT6X46_IDLE_CMD; + for (retry_times = 0; retry_times < FT6X46_INIT_RETRY_TIMERS; retry_times++) { + ret = tp_i2c_cmd_write(reg_write); + if (ret == EXT_ERR_SUCCESS) { + break; + } + /* delay 10 ms */ + osDelay(FT6X46_GENERAL_DELAY_10); + } + + reg_write = FT6X46_POWER_CTL_END; + ret = tp_i2c_cmd_write(reg_write); + if (ret != EXT_ERR_SUCCESS) { + ft6x46_set_irq_mode(FT6X46_IRQ_ENABLE, FT6X46_INT_MASK); + tp_err("standby failed 0x%x", ret); + return EXT_ERR_FAILURE; + } + /* delay 10 ms */ + osDelay(FT6X46_GENERAL_DELAY_10); + ft6x46_set_irq_mode(FT6X46_IRQ_ENABLE, FT6X46_INT_MASK); + g_ft6x46_drv.work_status = FT6X46_WORK_STANDBY; + return EXT_ERR_SUCCESS; +} + +ext_errno ft6x46_suspend(void) +{ + ext_errno ret; + // uint16_t reg_write; + // uint8_t retry_times = 0; + + if (g_ft6x46_drv.work_status == FT6X46_WORK_SLEEP) { + tp_print("TOUCH:alread suspend"); + return EXT_ERR_SUCCESS; + } + /*Host writes 0x03 to register address 0xA5 to enter into sleep mode.*/ + ret = tp_ft6x46_i2c_data_write_reg(FTS_REG_POWER_MODE, 0x03); + if(ret != 0) { + tp_err("ft6x46_suspend enter sleep mode fails.ret:0x%X",ret); + return EXT_ERR_FAILURE; + } else { + tp_warning("ft6x46_suspend enter sleep mode success."); + } + + ft6x46_set_irq_mode(FT6X46_IRQ_DISABLE, FT6X46_INT_MASK); + g_ft6x46_drv.work_status = FT6X46_WORK_SLEEP; + + ft6x46_check_error_timer_stop(); + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_resume_post(void) +{ + ext_errno ret; + // uint16_t reg_write; + // uint16_t cmd_write; + + // reg_write = FT6X46_ENABLE; + // ret = tp_i2c_reg_write(FT6X46_REG_CMD_ENABLE, reg_write); + // if (ret != EXT_ERR_SUCCESS) { + // tp_err("resume post reg cmd failed 0x%x", ret); + // return EXT_ERR_FAILURE; + // } + // /* delay for ms */ + // osDelay(FT6X46_GENERAL_DELAY_1); + + // cmd_write = FT6X46_REG_INTN_CLEAR; + // ret = tp_i2c_cmd_write(cmd_write); + // if (ret != EXT_ERR_SUCCESS) { + // return EXT_ERR_TP_ZTW523_POWERUP_INTN_CLEAR; + // } + // osDelay(FT6X46_GENERAL_DELAY_1); + + // reg_write = FT6X46_ENABLE; + // ret = tp_i2c_reg_write(FT6X46_REG_NVM, reg_write); + // if (ret != EXT_ERR_SUCCESS) { + // tp_err("resume post reg nvm failed 0x%x", ret); + // return EXT_ERR_FAILURE; + // } + // osDelay(FT6X46_GENERAL_DELAY_1); + + // reg_write = FT6X46_ENABLE; + // ret = tp_i2c_reg_write(FT6X46_REG_PROGRAM_START, reg_write); + // if (ret != EXT_ERR_SUCCESS) { + // tp_err("resume post reg program start failed 0x%x", ret); + // return EXT_ERR_FAILURE; + // } + + // osDelay(FT6X46_GENERAL_DELAY_50); /* delay 50 ms */ + + return EXT_ERR_SUCCESS; +} +ext_errno ft6x46_resume(void) +{ + ext_errno ret; + uint8_t retry_times = 0; + + g_ft6x46_drv.work_status = FT6X46_WORK_RESUME; + + ft6x46_resume_reset(); + + /* Step 2 power up */ + ret = ft6x46_power_sequence(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:init powerup fail 0x%x", ret); + goto resume_exit; + } + + /* Record Status For Init */ + g_ft6x46_drv.chip_status = FT6X46_READY; + g_ft6x46_drv.work_status = FT6X46_WORK_NORMAL; + +#ifdef FT6X46_GESTURE_WAKEUP + g_ft6x46_drv.gesture_wakeup = TD_FALSE; +#endif + /* Enable Irq */ + ft6x46_set_irq_mode(FT6X46_IRQ_ENABLE, FT6X46_INT_MASK); + + ft6x46_check_error_timer_start(1000); + + return EXT_ERR_SUCCESS; + +resume_exit: + + /* Enable Irq */ + ft6x46_set_irq_mode(FT6X46_IRQ_DISABLE, FT6X46_INT_MASK); + + tp_err("resume failed 0x%x", ret); + + return EXT_ERR_FAILURE; +} + +ext_errno ft6x46_get_power_mode(uint32_t *power_mode) +{ + if (power_mode == NULL) { + return EXT_ERR_FAILURE; + } + + *power_mode = (uint32_t)(g_ft6x46_drv.work_status); + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_set_standby_mode(void) +{ + ext_errno ret; + + ret = ft6x46_standby(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:ft6x46 set standby 0x%x", ret); + return EXT_ERR_FAILURE; + } +#ifdef FT6X46_GESTURE_WAKEUP + g_ft6x46_drv.gesture_wakeup = TD_TRUE; +#endif + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_set_sleep_mode(void) +{ + ext_errno ret; + + ret = ft6x46_suspend(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:ft6x46 set suspend fail 0x%x", ret); + } +#ifdef FT6X46_GESTURE_WAKEUP + g_ft6x46_drv.gesture_wakeup = TD_FALSE; +#endif + g_ft6x46_drv.work_status = FT6X46_WORK_SLEEP; + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_set_normal_mode(void) +{ + ext_errno ret; + uint16_t reg_write; + + if (g_ft6x46_drv.work_status == FT6X46_WORK_NORMAL) { + return EXT_ERR_SUCCESS; + } + + reg_write = FT6X46_SDRAM_RESET; + ret = tp_i2c_cmd_write(reg_write); + if (ret != EXT_ERR_SUCCESS) { + return EXT_ERR_FAILURE; + } + /* delay 50ms */ + osDelay(FT6X46_GENERAL_DELAY_50); + ret = ft6x46_power_sequence(); + if (ret != EXT_ERR_SUCCESS) { + return EXT_ERR_FAILURE; + } + ft6x46_set_irq_mode(FT6X46_IRQ_ENABLE, FT6X46_INT_MASK); + g_ft6x46_drv.work_status = FT6X46_WORK_NORMAL; +#ifdef FT6X46_GESTURE_WAKEUP + g_ft6x46_drv.gesture_wakeup = TD_FALSE; +#endif + return EXT_ERR_SUCCESS; +} + +ext_errno ft6x46_set_power_mode(tp_work_mode power_mode) +{ + ext_errno ret = EXT_ERR_SUCCESS; + + switch (power_mode) { + case MC_TP_SLEEP_WORK_MODE: + case MC_TP_SUSPEND_SCAN: + ret = ft6x46_set_sleep_mode(); + break; + case MC_TP_NORMAL_WORK_MODE: + case MC_TP_RESUME_SCAN: + ret = ft6x46_set_normal_mode(); + break; + case MC_TP_STANDBY_WORK_MODE: + ret = ft6x46_set_standby_mode(); + break; + default: + tp_err("TOUCH:ft6x46 not support powermode 0x%x", power_mode); + ret = EXT_ERR_FAILURE; + break; + } + + return ret; +} + +static ext_errno ft6x46_config(void) +{ + ext_errno ret; + + /* Step 1 hardware reset */ + ret = ft6x46_reset(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:Init reset fail 0x%x", ret); + return EXT_ERR_TP_ZTW523_INIT_RESET; + } + + /* Step 2 power up */ + ret = ft6x46_power_sequence(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:init powerup fail 0x%x", ret); + return EXT_ERR_TP_ZTW523_INIT_POWERUP; + } + +#if 0 + /* Step 3 configuration */ + ret = ft6x46_configuration(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:init config fail 0x%x", ret); + return EXT_ERR_TP_ZTW523_INIT_CONFIG; + } + + /* Step 3 Panel Info */ + ret = ft6x46_get_panel_info(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:init get panelinfo fail 0x%x", ret); + return EXT_ERR_TP_ZTW523_INIT_GETINFO; + } +#endif + + /* Record Status For Init */ + g_ft6x46_drv.chip_status = FT6X46_READY; + g_ft6x46_drv.work_status = FT6X46_WORK_NORMAL; + + return EXT_ERR_SUCCESS; +} + +static ext_errno ft6x46_resource_deinit(void) +{ + g_ft6x46_drv.work_status = FT6X46_WORK_INVALID; + g_ft6x46_drv.fw_upgrade_flag = TD_FALSE; + osal_mutex_destroy(&g_ft6x46_drv.ops_mux); + + return EXT_ERR_SUCCESS; +} + +ext_errno ft6x46_init(void) +{ + ext_errno ret = EXT_ERR_FAILURE; + ext_errno err_ret; + + /* create tp operation mutex */ + if (g_ft6x46_drv.ops_mux.mutex == NULL) { + ret = osal_mutex_init(&(g_ft6x46_drv.ops_mux)); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:ft6x46 init create mux lock fail 0x%x", ret); + return EXT_ERR_FAILURE; + } + } + + /* get tp operater mutex */ + ret = osal_mutex_lock_timeout(&g_ft6x46_drv.ops_mux, FT6X46_OPERATER_MUTEX_WAIT_TIME); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:ft6x46 init wait mux lock fail 0x%x", ret); + goto init_fail; + } + + /* tp hardware reset and init */ + ret = ft6x46_config(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:ft6x46 init fail 0x%x", ret); + goto init_fail; + } + + /* release tp operater mutex */ + osal_mutex_unlock(&g_ft6x46_drv.ops_mux); + + tp_print("TOUCH:ft6x46 init succ!"); + return EXT_ERR_SUCCESS; + +init_fail: + /* release tp operater mutex */ + osal_mutex_unlock(&g_ft6x46_drv.ops_mux); + err_ret = ft6x46_resource_deinit(); + if (err_ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH:delete mux lock err! ret = 0x%x", err_ret); + } + return ret; +} + +ext_errno ft6x46_deinit(void) +{ + ext_errno ret = ft6x46_resource_deinit(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("TOUCH: ft6x46 deinit fail! ret = 0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +#ifdef __cplusplus +#if __cplusplus + } +#endif +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.h b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.h new file mode 100644 index 000000000..b0e57762f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.h @@ -0,0 +1,421 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: ztw523 touch driver. + * Author: @CompanyNameTag + * Create: 2021-05-29 + */ + +#ifndef FT6X46_TOUCH1_H +#define FT6X46_TOUCH1_H + +#include "stdio.h" +#include "soc_errno.h" +#include "soc_osal.h" +#include "touch_screen_def.h" +#include "platform_core.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +/* ztw523 definitions */ +/* max wait time */ +#define FT6X46_OPERATER_MUTEX_WAIT_TIME 3000 /* operater tp mutex timeout ms */ +#define FT6X46_CMCP_WAIT_TIMEOUT 1000 +/* define some properties value */ +#define FT6X46_ENABLE 0x0001 +#define FT6X46_DISABLE 0x0000 +#define FT6X46_DATA_LEN 2 +#define FT6X46_POWERON_DELAY 100 +#define FT6X46_POWEROFF_DELAY 100 +#define FT6X46_RESETHIGH_DELAY 10 +#define FT6X46_CLEARINT_DELAY 10 +#define FT6X46_FIRMWAREON_DELAY 200 +#define FT6X46_INIT_RETRY_TIMERS 3 +#define FT6X46_SETMODE_RETRY_TIMERS 3 +#define FT6X46_SOFTRESET_RETRY_TIMES 10 +#define FT6X46_RETRY_TIMES 10 +#define FT6X46_DEVICE_INFO "zinitix,ft6x46" +#define FT6X46_DEVICE_INFO_SIZE sizeof(FT6X46_DEVICE_INFO) +#define FT6X46_MAX_SUPPORTED_FINGER_NUM 1 +#define FT6X46_POINT_MODE 1 +#define FT6X46_CALIB_TOUCH_MODE 0x07 +#define FT6X46_REGDATA_SHIFT 8 +#define FT6X46_GENERAL_DELAY_1 1 +#define FT6X46_GENERAL_DELAY_5 5 +#define FT6X46_GENERAL_DELAY_10 10 +#define FT6X46_GENERAL_DELAY_20 20 +#define FT6X46_GENERAL_DELAY_25 25 +#define FT6X46_GENERAL_DELAY_30 30 +#define FT6X46_GENERAL_DELAY_50 50 +#define FT6X46_GENERAL_DELAY_100 100 +#define FT6X46_GENERAL_DELAY_200 200 +#define FT6X46_GENERAL_DELAY_500 500 +#define FT6X46_GENERAL_RETRY_1 1 +#define FT6X46_GENERAL_RETRY_2 2 +#define FT6X46_GENERAL_RETRY_3 3 +#define FT6X46_GENERAL_RETRY_4 4 +#define FT6X46_GENERAL_RETRY_10 10 +#define FT6X46_RAWDATA_DELAY_FOR_HOST 100 +#define FT6X46_FW_JUMP_CODE 0x0048 +#define FT6X46_REPORT_RATE 60 +#define FT6X46_PIXEL_THRESHOLD 5 + +#ifndef FT6X46_RES_MAX_X +#define FT6X46_RES_MAX_X 466 +#endif + +#ifndef FT6X46_RES_MAX_Y +#define FT6X46_RES_MAX_Y 466 +#endif + +#ifndef FT6X46_POINT_TRESHHOLD +#define FT6X46_POINT_TRESHHOLD 0x19 +#endif + +#define FT6X46_TOUCHINFO_HEAD_LEN 4 +#define FT6X46_POINTINFO_LEN 6 +#define FT6X46_TOUCHINFO_LEN (FT6X46_TOUCHINFO_HEAD_LEN + FT6X46_POINTINFO_LEN * FT6X46_MAX_SUPPORTED_FINGER_NUM) + +#define FT6X46_INT_NONE 0x0000 +#define FT6X46_INT_MASK 0x081F +#define FT6X46_PALM_MASK 0x0010 +#define FT6X46_GESTURE_WAKEUP_INIT 0 +#define FT6X46_FIRMWARE_SIZE 48 +#define ZTW_PAGE_SIZE_128 128 +#define ZTW_PAGE_SIZE_64 64 +#define ZTW_SECTOR_SIZE 8 +#define ZTW_CHIPID_F400 0xF400 +#define ZTW_CHIPID_E240 0xE240 +#define ZTW_CHIPID_E700 0xE700 +#define ZTW_CHIPID_E548 0xE548 +#define ZTW_CHIPID_E538 0xE538 +#define ZTW_CHIPID_E532 0xE532 +#define ZTW_VENDOR_ID 0x5A49 +#define FT6X46_CHIP_ID 0xE628 +/* define touch info offset */ +#define FT6X46_STATUSL_OFFSET 0 +#define FT6X46_STATUSH_OFFSET 1 +#define FT6X46_EVENTL_OFFSET 2 +#define FT6X46_EVENTH_OFFSET 3 +#define FT6X46_XL_OFFSET 4 +#define FT6X46_XH_OFFSET 5 +#define FT6X46_YL_OFFSET 6 +#define FT6X46_YH_OFFSET 7 +#define FT6X46_WIDTH_OFFSET 8 +#define FT6X46_SUBSTATUS_OFFSET 9 +/* define data shift and mask */ +#define FT6X46_SHIFT_8_BIT 8 +#define FT6X46_SHIFT_16_BIT 16 +#define FT6X46_SHIFT_24_BIT 24 +#define FT6X46_MASK_BYTE 0xFF +/* define FT6X46_HIGH_SPEED_DMA rely on iic dma support */ +#ifdef FT6X46_HIGH_SPEED_DMA +#define FT6X46_TOUCH_POINT_MODE 0 +#else +#define FT6X46_TOUCH_POINT_MODE 1 +#endif + +#define FT6X46_SEC_MODE 48 +#define FT6X46_NORMAL_MODE 5 +#define FT6X46_DND_MODE 11 /* mutual cap */ +#define FT6X46_SELF_DND_MODE 17 /* self cap */ +#define FT6X46_DNDSKIP_CNT 1 +#define FT6X46_SELFDNDSKIP_CNT 1 +/* Config Reg Info */ +#define FT6X46_REG_CMD_ENABLE 0xC000 +#define FT6X46_REG_CHIP_ID 0xCC00 +#define FT6X46_REG_INTN_CLEAR 0xC004 +#define FT6X46_REG_NVM 0xC002 +#define FT6X46_REG_NVM_VPP 0xC003 +#define FT6X46_REG_NVM_WP 0xC104 +#define FT6X46_REG_PROGRAM_START 0xC001 +#define FT6X46_POWER_CTL_BEGIN 0x000A +#define FT6X46_POWER_CTL_END 0x000B +#define FT6X46_CALIB_CTL1 0xC003 +#define FT6X46_CALIB_CTL2 0xC104 +#define FT6X46_SDRAM_RESET 0x0FF8 +#define FT6X46_REPORT_REG 0x0186 /* 设置中断上报频率 */ +#define FT6X46_PIXEL_THRESHOLD_REG 0x00C3 +/* Register Map */ +#define FT6X46_SWRESET_CMD 0x0000 +#define FT6X46_WAKEUP_CMD 0x0001 +#define FT6X46_IDLE_CMD 0x0004 +#define FT6X46_SLEEP_CMD 0x0005 +#define FT6X46_CLEAR_INT_STATUS_CMD 0x0003 +#define FT6X46_CALIBRATE_CMD 0x0006 +#define FT6X46_SAVE_STATUS_CMD 0x0007 +#define FT6X46_SAVE_CALIBRATION_CMD 0x0008 +#define FT6X46_RECALL_FACTORY_CMD 0x000f +#define FT6X46_SENSITIVITY 0x0020 +#define FT6X46_I2C_CHECKSUM_WCNT 0x016a +#define FT6X46_I2C_CHECKSUM_RESULT 0x016c +#define FT6X46_DEBUG_REG 0x0115 /* 0~7 */ +#define FT6X46_TOUCH_MODE 0x0010 +#define FT6X46_CHIP_REVISION 0x0011 +#define FT6X46_FIRMWARE_VERSION 0x0012 +#define FT6X46_MINOR_FW_VERSION 0x0121 +#define FT6X46_DATA_VERSION_REG 0x0013 +#define FT6X46_HW_ID 0x0014 +#define FT6X46_SUPPORTED_FINGER_NUM 0x0015 +#define FT6X46_EEPROM_INFO 0x0018 +#define FT6X46_INITIAL_TOUCH_MODE 0x0019 +#define FT6X46_CHIP_HW_REVISION 0x001A +#define FT6X46_IC_VENDOR_ID 0x001C +#define FT6X46_TSM_MODULE_ID 0x001E +#define FT6X46_TOTAL_NUMBER_OF_X 0x0060 +#define FT6X46_TOTAL_NUMBER_OF_Y 0x0061 +#define FT6X46_DELAY_RAW_FOR_HOST 0x007f +#define FT6X46_BUTTON_SUPPORTED_NUM 0x00B0 +#define FT6X46_BUTTON_SENSITIVITY 0x00B2 +#define FT6X46_X_RESOLUTION 0x00C0 +#define FT6X46_Y_RESOLUTION 0x00C1 +#define FT6X46_HOLD_POINT_TRESHHOLD 0x00C3 +#define FT6X46_POINT_STATUS_REG 0x0080 +#define FT6X46_ICON_STATUS_REG 0x00AA +#define FT6X46_AFE_FREQUENCY 0x0100 +#define FT6X46_DND_N_COUNT 0x0122 +#define FT6X46_DND_U_COUNT 0x0135 +#define FT6X46_RAWDATA_REG 0x0200 +#define FT6X46_EEPROM_INFO_REG 0x0018 +#define FT6X46_INT_ENABLE_FLAG 0x00f0 +#define FT6X46_PERIODICAL_INTERRUPT_INTERVAL 0x00f1 +#define FT6X46_CHECKSUM_RESULT 0x012c +#define FT6X46_GESTURE_WAKEUP_REG 0x0126 + +#define FT6X46_TOUCHINFO_MASK 0x0F +#define FT6X46_TOUCH_EXIST 0x01 +#define FT6X46_TOUCH_DOWN 0x03 +#define FT6X46_TOUCH_MOVE 0x05 +#define FT6X46_TOUCH_UP 0x08 +#define FT6X46_TOUCH_NONE 0x07 + +#define FT6X46_SUB_BIT_EXIST 0 +#define FT6X46_SUB_BIT_DOWN 1 +#define FT6X46_SUB_BIT_MOVE 2 +#define FT6X46_SUB_BIT_UP 3 +#define FT6X46_SUB_BIT_UPDATE 4 +#define FT6X46_SUB_BIT_WAIT 5 + +#ifndef FT6X46_TSP_X_CHANNEL_NUM +#define FT6X46_TSP_X_CHANNEL_NUM 6 +#endif + +#ifndef FT6X46_TSP_Y_CHANNEL_NUM +#define FT6X46_TSP_Y_CHANNEL_NUM 6 +#endif + +#define FT6X46_TSP_DND_NUM (FT6X46_TSP_X_CHANNEL_NUM * FT6X46_TSP_Y_CHANNEL_NUM) +#define FT6X46_TSP_SELFDND_NUM (FT6X46_TSP_X_CHANNEL_NUM + FT6X46_TSP_Y_CHANNEL_NUM) + +/* firmware info */ +#define FT6X46_FIRMWARE_VERSION_L 0 +#define FT6X46_FIRMWARE_VERSION_H 1 +#define FT6X46_FIRMWARE_VERSION_OFFSET 52 +#define FT6X46_FIRMWARE_MINOR_VERSION_OFFSET 56 +#define FT6X46_FIRMWARE_DATA_VERSION_OFFSET 60 +#define FT6X46_FIRMWARE_OFFSET_ZERO 0 +#define FT6X46_FIRMWARE_CONVERT_DATA_STEP 2 +#define FT6X46_FIRMWARE_CONVERT_DATA_OFFSET 1 +/* file op code */ +#define FT6X46_FILE_ERROR (-1) +#define FT6X46_FILE_OK 0 +/* upgrade info */ +#define FT6X46_FWGRADE_CMD_NUM 3 +/* rawdata info */ +#define FT6X46_RAWDATA_CMD_NUM 2 +/* define gesture macro */ +#define FT6X46_GESTURE_WAKEUP 1 + +/* self_dnd dnd parameter */ +#define FT6X46_SEC_SELF_DND_N_COUNT 15 +#define FT6X46_SEC_SELF_DND_U_COUNT 2 +#define FT6X46_SEC_SELF_DND_FREQUENCY 80 + +#define FT6X46_SEC_DND_N_COUNT 27 +#define FT6X46_SEC_DND_U_COUNT 3 +#define FT6X46_SEC_DND_FREQUENCY 240 + +/* host peripheral typedef */ +typedef ext_errno (*tp_irq_callback)(void); + +/* ZTW523 driver typedef */ +typedef enum { + FT6X46_POWERDOWN = 0, + FT6X46_POWERUP, +} ft6x46_sw_power_status; + +typedef enum { + FT6X46_WORK_NORMAL = 0, + FT6X46_WORK_STANDBY, + FT6X46_WORK_GETCMCP, + FT6X46_WORK_SLEEP, + FT6X46_WORK_SUSPEND, + FT6X46_WORK_RESUME, + FT6X46_WORK_INVALID, +} ft6x46_work_status; + +typedef enum { + FT6X46_NOT_READY = 0, + FT6X46_READY, +} ft6x46_device_status; + +typedef enum { + MC_BUTTON_RELEASE = 0, /* button release */ + MC_BUTTON_PRESSED = 1, /* button pressed */ +} button_event_type; + +typedef enum { + MC_TOUCHKEY_EVENT_PRESS = 0, + MC_TOUCHKEY_EVENT_RELASSE, + MC_TOUCHKEY_EVENT_LONG_PRESS, + MC_TOUCHKEY_EVENT_INVALID, +} touch_key_event_type; + +typedef enum { + FT6X46_GESTURE_NONE = 0, + FT6X46_GESTURE_SIGNAL_CLICK = 1, + FT6X46_GESTURE_DOUBLE_CLICK = 2, + FT6X46_GESTURE_SLIDE_UP = 4, + FT6X46_GESTURE_SLIDE_DOWN = 5, +} ft6x46_gesture_event; + +typedef enum { + FT6X46_IRQ_DISABLE = 0, + FT6X46_IRQ_ENABLE, +} ft6x46_irq_status; + +typedef enum { + MC_TP_NORMAL_WORK_MODE = 0, /* tp normal mode */ + MC_TP_STANDBY_WORK_MODE, /* tp idle mode */ + MC_TP_BOOTLOADER_WORK_MODE, + MC_TP_SLEEP_WORK_MODE, + MC_TP_SUSPEND_SCAN, + MC_TP_RESUME_SCAN, + MC_TP_MAX_MODE, +} tp_work_mode; + +typedef enum { + MC_TP_UPGRADE_NEED_FLAG, + MC_TP_UPGRADE_START_ASYN, + MC_TP_UPGRADE_STATUS, + MC_TP_UPGRADE_SYNC, +} mc_tp_upgrade; + +typedef struct { + uint32_t reset_gpio; + uint32_t int_gpio; + i2c_bus_t i2c_id; + uint32_t i2c_baudrate; +} tp_peripheral_attr; + +typedef struct { + uint16_t button_code; +} button_dev_info; + +typedef struct { + uint16_t xchannel_num; + uint16_t ychannel_num; + uint16_t total_dnd_num; + uint16_t total_self_dnd_num; +} ft6x46_panel_data; + +typedef struct { + uint32_t skip_cnt; + int16_t dnd_data[FT6X46_TSP_DND_NUM]; + int16_t self_dnd_data[FT6X46_TSP_SELFDND_NUM]; +} ft6x46_tsp_rawdata; + +typedef enum { + MC_TP_RAW_DATA, + MC_TP_BASE_DATA, + MC_TP_NOS_DATA, + MC_TP_SIG_DATA, + MC_TP_FT_DATA, + MC_TP_NT_DATA, + MC_TP_MAX_DATA, + MC_TP_CM_CP_DATA, /* 7, CM CP data */ + MC_TP_INT_COUNT_DATA, /* 8, TP Int count */ + MC_TP_NOISE_METRICS_DATA, + MC_TP_DATA_STRUCTURE_DATA, + MC_TP_PANEL_SCAN_CM_DATA, + MC_TP_PANEL_SCAN_CP_DATA, + MC_TP_START_RAW_TRANS, + MC_TP_STOP_RAW_TRANS, + MC_TP_START_GET_WATER_TEMPR, /* 15, start get and print water level and temprature */ + MC_TP_STOP_GET_WATER_TEMPR, /* 16, stop get and print water level and temprature */ + MC_TP_RAW_MAX, +} mc_tp_rawdata; + +typedef struct { + mc_tp_rawdata cmd; + uint8_t *data_buf; + uint8_t data_in_len; + uint32_t data_out_len; + uint32_t data_addr; +} touch_rawdata_info; + +/* define for drv process talbe */ +typedef ext_errno (*touch_drv_upgrade_handle)(uint8_t *data_buff, uint8_t buf_len); +typedef struct { + mc_tp_upgrade cmd_id; + touch_drv_upgrade_handle process_cb; +} touch_drv_upgrade_proc; + +typedef ext_errno (*touch_hal_rawdata_handle)(uint8_t *data_buf, uint8_t buf_len); +typedef struct { + mc_tp_rawdata cmd_id; + touch_hal_rawdata_handle process_cb; +} touch_drv_rawdata_proc; + +typedef struct { + uint16_t chip_id; + uint16_t vendor_id; + uint16_t chip_hw_id; + uint8_t chip_info[FT6X46_DEVICE_INFO_SIZE]; + uint16_t firmware_version; + uint16_t minor_firmware_version; + uint16_t reg_version; + uint32_t flash_fw_version; + uint16_t int_mask; + uint16_t touch_mode; + uint32_t irq_count; + uint32_t touch_count; + uint32_t page_size; + uint16_t header_size; + uint16_t image_size; + osal_mutex ops_mux; + bool fw_upgrade_flag; + bool gesture_wakeup; + bool host_dev_init_flag; + ft6x46_sw_power_status power_status; + ft6x46_work_status work_status; + ft6x46_sw_power_status chip_sw_power_status; + ft6x46_device_status chip_status; + input_event_info touch_msg; + ft6x46_panel_data panel_info; + tp_peripheral_attr dev_attr; + ft6x46_tsp_rawdata tsp_raw_data; + void *p_void; + uint32_t tp_event; + touch_drv_upgrade_proc upgrade_table[FT6X46_FWGRADE_CMD_NUM]; + touch_drv_rawdata_proc raw_data_table[FT6X46_RAWDATA_CMD_NUM]; +} ft6x46_drv_data; + +ext_errno ft6x46_init(void); +ext_errno ft6x46_deinit(void); +ext_errno ft6x46_set_power_mode(tp_work_mode power_mode); +ext_errno ft6x46_get_power_mode(uint32_t *power_mode); +ext_errno ft6x46_resume(void); +ext_errno ft6x46_suspend(void); +ext_errno ft6x46_irq_callback(uint8_t *data_buf, uint8_t data_len); +ext_errno ft6x46_host_init_sample(void); +#ifdef __cplusplus +#if __cplusplus + } +#endif +#endif + +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c new file mode 100644 index 000000000..a8e28701b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c @@ -0,0 +1,492 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: touch screen driver. + * Author: @CompanyNameTag + * Create: 2022-04-12 + */ + +#include "touch_screen_drv.h" +#include "tcxo.h" +#include "i2c.h" +#include "common_def.h" +#include "soc_osal.h" +#include "touch_screen_def.h" +#include "input_app.h" +#if defined(TPTYPE_TMA525B) +#include "tma525b_drv1.h" +#include "tma525b_ctrl.h" +#elif defined(TPTYPE_ZTW523) +#include "ztw523_drv1.h" +#include "ztw523_ctrl.h" +#elif defined(TPTYPE_FT6X46) +#include "ft6x46_drv1.h" +#include "ft6x46_ctrl.h" +#else +#include "ztw523_drv1.h" +#include "ztw523_ctrl.h" +#endif + +#if defined(TPTYPE_TMA525B) +#define TOUCH_I2C_BUS TMA525B_I2C_BUS +#define TOUCH_INT_GPIO TMA525B_INT_GPIO +#define TOUCH_RESET_GPIO TMA525B_RESET_GPIO +#elif defined(TPTYPE_ZTW523) +#define TOUCH_I2C_BUS ZTW523_I2C_BUS +#define TOUCH_INT_GPIO ZTW523_INT_GPIO +#define TOUCH_RESET_GPIO ZTW523_RESET_GPIO +#elif defined(TPTYPE_FT6X46) +#define TOUCH_I2C_BUS FT6X46_I2C_BUS +#define TOUCH_INT_GPIO FT6X46_INT_GPIO +#define TOUCH_RESET_GPIO FT6X46_RESET_GPIO +#else +#define TOUCH_I2C_BUS ZTW523_I2C_BUS +#define TOUCH_INT_GPIO ZTW523_INT_GPIO +#define TOUCH_RESET_GPIO ZTW523_RESET_GPIO +#endif + +#define TOUCH_SCREEN_DEV_NAME_LEN 16 +#define TOUCH_SCREEN_DEVNAME "input/event" +#define TOUCH_SCREEN_DYNAMIC_MINOR 65 +#define TOUCH_SCREEN_CMDID_MAX 16 + +#define TOUCH_SCREEN_TASK_PRIO 5 +#define TOUCH_SCREEN_TASK_SIZE 0x800 +#define TOUCH_SCREEN_QUEUE_MAX_SIZE 60 +#define TOUCH_SCREEN_READY_EVENT (1 << 0) + +struct ts_driver_data g_touch_drv = {0}; +struct ts_driver_data *g_attr = NULL; + +report_event_cb g_report_event_cb = NULL; + +#if defined(SUPPORT_POWER_MANAGER) +event_callback_func g_power_manager_cb = NULL; +#endif + +static struct ts_driver_data *touch_screen_get_driver_data(void) +{ + return &g_touch_drv; +} + +static uint32_t touch_screen_get_state(struct ts_driver_data *tsdd) +{ + if (tsdd != NULL && tsdd->queue != NULL) { + return (uint32_t)ts_queue_is_empty(tsdd->queue); + } + + if (tsdd == NULL) { + tp_err("tsdd is null!"); + return EXT_ERR_FAILURE; + } + if (tsdd->queue == NULL) { + tp_err("tsdd queue is null!"); + } + + return EXT_ERR_FAILURE; +} + +static void convert_touch_info(input_dev_data_t* data, input_event_info* touch_info) +{ + data->x = (int16_t)touch_info->tp_event_info.x_axis[0]; + data->y = (int16_t)touch_info->tp_event_info.y_axis[0]; + data->type = INDEV_TYPE_TOUCH; + data->timestamp = (uint32_t)touch_info->tv_usec; + if ((touch_info->tp_event == MC_TP_PRESS) || (touch_info->tp_event == MC_TP_MOVE)) { + data->state = INDEV_STATE_PRESS; + } else if (touch_info->tp_event == MC_TP_RELEASE) { + data->state = INDEV_STATE_RELEASE; + } else { + data->state = INDEV_STATE_UNKNOWN; + } +} + +static void report_or_enqueue_event(input_event_info* touch_info, struct ts_driver_data *tsdd) +{ + if (g_report_event_cb != NULL) { + input_dev_data_t data; + convert_touch_info(&data, touch_info); + if (data.state == INDEV_STATE_UNKNOWN) { + return; + } + g_report_event_cb(&data); + } else { + int32_t ret = ts_en_queue(tsdd->queue, touch_info); + if (ret != EXT_ERR_SUCCESS) { + tp_err("Failed to enqueue ts queue! ret=0x%x", ret); + } + } +} +#if defined(SUPPORT_POWER_MANAGER) +static void report_event_to_power_manager(input_event_info *touch_info) +{ + if (g_power_manager_cb != NULL) { + input_dev_data_t data; + convert_touch_info(&data, touch_info); + if (data.state == INDEV_STATE_UNKNOWN) { + return; + } + g_power_manager_cb(data.state, 0); + } + return; +} + +uint32_t ts_register_power_manager_cb(event_callback_func callback) +{ + if (g_power_manager_cb != NULL) { + return EXT_ERR_FAILURE; + } + g_power_manager_cb = callback; + return EXT_ERR_SUCCESS; +} +#endif +ext_errno touch_info_process(void) +{ + struct ts_driver_data *tsdd = touch_screen_get_driver_data(); + input_event_info touch_info; + int32_t ret = 0; + + if (tsdd->touch_api->touch_get_tpinfo != NULL) { + ret = tsdd->touch_api->touch_get_tpinfo((uint8_t *)(&touch_info), sizeof(input_event_info)); + if (ret != EXT_ERR_SUCCESS) { + tp_err("get touch info fail! ret=0x%x", ret); + return ret; + } + + report_or_enqueue_event(&touch_info, tsdd); +#if defined(SUPPORT_POWER_MANAGER) + report_event_to_power_manager(&touch_info); +#endif + } + + return EXT_ERR_SUCCESS; +} + +static void ts_callback_func(void) +{ + ext_errno ret; + if (g_attr != NULL) { + common_notify_mail_t mail = {0}; + mail.comm.app = APP_TOUCH; + ret = osal_msg_queue_write_copy(get_app_queue_id(), (void *)&mail, + sizeof(common_notify_mail_t), 0); + if (ret != OSAL_SUCCESS) { + tp_err("touch app msg send failed! err=0x%x! \r\n", ret); + } + } +} + +static ext_errno ts_register_callback(struct ts_driver_data *attr) +{ + ext_errno ret = EXT_ERR_FAILURE; + g_attr = attr; + + if (attr->touch_api->register_callback != NULL) { + ret = attr->touch_api->register_callback(attr->private_data, ts_callback_func); + if (ret != EXT_ERR_SUCCESS) { + tp_err("register touch screen callback fail! ret=0x%x", ret); + return ret; + } + } else { + tp_err("touch screen callback register func is empty!"); + } + + return ret; +} + +static ext_errno ts_unregister_callback(struct ts_driver_data *attr) +{ + ext_errno ret = EXT_ERR_FAILURE; + + if (attr->touch_api->unregister_callback != NULL) { + ret = attr->touch_api->unregister_callback(attr->private_data); + if (ret != EXT_ERR_SUCCESS) { + tp_err("unregister touch screen callback fail! ret=0x%x", ret); + return ret; + } + g_attr = NULL; + } else { + tp_err("touch screen callback unregister func is empty!"); + } + + return ret; +} + +static int32_t ts_dev_open(const void *private_data) +{ + int32_t ret; + struct ts_driver_data *tsdd = NULL; + if (private_data == NULL) { + tp_err("ts_open: invalid dev or driver_data!\n"); + return EXT_ERR_FAILURE; + } + + // todo: get tsdd from private_data + tsdd = touch_screen_get_driver_data(); + tsdd->queue = ts_init_queue(TOUCH_SCREEN_QUEUE_MAX_SIZE); + if (tsdd->queue == NULL) { + tp_err("create touch screen queue fail!\r\n"); + return EXT_ERR_FAILURE; + } + ret = osal_event_init(&(tsdd->event)); + if (ret != EXT_ERR_SUCCESS) { + tp_err("touch osal_event_init fail! ret=0x%x\r\n", ret); + return ret; + } + + tsdd->task_handle = osal_kthread_create((osal_kthread_handler)touch_info_process, + (void *)touch_screen_get_driver_data(), + "touch_screen", TOUCH_SCREEN_TASK_SIZE); + if (tsdd->task_handle == NULL) { + tp_err("create touch screen thread fail!\r\n"); + return EXT_ERR_FAILURE; + } + osal_kthread_set_priority(tsdd->task_handle, TOUCH_SCREEN_TASK_PRIO); + + if (tsdd->touch_api->touch_init != NULL) { + ret = tsdd->touch_api->touch_init(tsdd->private_data); + if (ret != EXT_ERR_SUCCESS) { + tp_err("touch_init fail! ret=0x%x\r\n", ret); + return ret; + } + } + + ret = ts_register_callback(tsdd); + if (ret != EXT_ERR_SUCCESS) { + tp_err("register callback fail! ret=0x%x\r\n", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +static int32_t ts_dev_release(const void *private_data) +{ + int32_t ret; + struct ts_driver_data *tsdd = NULL; + if (private_data == NULL) { + tp_err("ts_dev_release: invalid dev or driver_data!\n"); + return EXT_ERR_FAILURE; + } + + // todo: get tsdd from private_data + tsdd = touch_screen_get_driver_data(); + ret = ts_unregister_callback(tsdd); + if (ret != EXT_ERR_SUCCESS) { + tp_err("unregister callback fail! ret=0x%x\r\n", ret); + return ret; + } + return EXT_ERR_SUCCESS; +} + +static uint32_t ts_dev_poll(const osal_poll *osal_poll, const void *private_data) +{ + unused(osal_poll); + unused(private_data); + // todo: get tsdd from private_data + struct ts_driver_data *tsdd = NULL; + tsdd = touch_screen_get_driver_data(); + if (tsdd == NULL) { + tp_err("ts_driver_data is NULL"); + return EXT_ERR_FAILURE; + } + + if (tsdd->ops->priv_operator != NULL && tsdd->ops->priv_operator(tsdd) == 0) { + return OSAL_POLLIN | OSAL_POLLRDNORM; + } + + return EXT_ERR_SUCCESS; +} + +static int32_t ts_ioctl_read_touch_info(uint32_t cmd, void *arg, const void *private_data) +{ + unused(cmd); + ext_errno ret; + struct ts_driver_data *tsdd = NULL; + input_event_info *touch_info = (input_event_info *)arg; + + if (private_data == NULL) { + tp_err("invalid dev or driver_data!"); + return EXT_ERR_FAILURE; + } + + // todo: get tsdd from private_data + tsdd = touch_screen_get_driver_data(); + if (tsdd->queue == NULL) { + tp_err("invalid touch screen queue!"); + return EXT_ERR_FAILURE; + } + + ret = ts_de_queue(tsdd->queue, touch_info); + if (ret != EXT_ERR_SUCCESS) { + tp_err("get touch info fail! ret=0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +static osal_ioctl_cmd g_ts_cmd_list[TOUCH_SCREEN_CMDID_MAX] = { + {TOUCH_SCREEN_GET_EVENT, ts_ioctl_read_touch_info}, +}; + +static osal_dev *g_ts_dev = NULL; +static osal_fileops g_ts_ops = { + .open = ts_dev_open, + .release = ts_dev_release, + .poll = ts_dev_poll, + .cmd_list = g_ts_cmd_list, + .cmd_cnt = sizeof(g_ts_cmd_list) / sizeof(g_ts_cmd_list[0]), +}; + +struct ts_ops g_ts_status_ops = { + .priv_operator = touch_screen_get_state, +}; + +static ext_errno touch_screen_register_device(void) +{ + ext_errno ret; + + g_touch_drv.private_data = touch_screen_get_peri_attr(); + g_touch_drv.touch_api = touch_screen_get_api(); + g_touch_drv.ops = &g_ts_status_ops; + g_ts_dev = osal_dev_create(TOUCH_SCREEN_DEVNAME); + g_ts_dev->minor = TOUCH_SCREEN_DYNAMIC_MINOR; + g_ts_dev->fops = &g_ts_ops; + + ret = osal_dev_register(g_ts_dev); + if (ret != 0) { + tp_err("touch screen osal_dev_register --------failed! ret=0x%x\n", ret); + return EXT_ERR_FAILURE; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno touch_screen_module_init(void) +{ + ext_errno ret; + + ret = touch_screen_register_device(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("touch_screen_register_device ----------failed! ret=0x%x\n", ret); + } + tp_err("touch_screen_register_device ----------succ!!!\n"); + + return EXT_ERR_SUCCESS; +} + +ext_errno touch_screen_module_deinit(void) +{ + return EXT_ERR_SUCCESS; +} + +uint32_t ts_register_report_event_cb(report_event_cb callback) +{ + if (g_report_event_cb != NULL) { + return EXT_ERR_FAILURE; + } + g_report_event_cb = callback; + return EXT_ERR_SUCCESS; +} + +uint32_t ts_unregister_report_event_cb(void) +{ + g_report_event_cb = NULL; + return EXT_ERR_SUCCESS; +} + +uint32_t ts_init(void) +{ + int32_t ret; + struct ts_driver_data *tsdd = NULL; + + g_touch_drv.private_data = touch_screen_get_peri_attr(); + g_touch_drv.touch_api = touch_screen_get_api(); + g_touch_drv.ops = &g_ts_status_ops; + tsdd = touch_screen_get_driver_data(); + tsdd->queue = ts_init_queue(TOUCH_SCREEN_QUEUE_MAX_SIZE); + if (tsdd->queue == NULL) { + tp_err("create touch screen queue fail!\r\n"); + return EXT_ERR_FAILURE; + } + + ret = ts_register_callback(tsdd); + if (ret != EXT_ERR_SUCCESS) { + tp_err("register callback fail! ret=0x%x\r\n", ret); + return EXT_ERR_FAILURE; + } + + return EXT_ERR_SUCCESS; +} + +uint32_t ts_read(const input_dev_data_t* data) +{ + unused(data); + return EXT_ERR_SUCCESS; +} + +uint32_t ts_close(void) +{ + return EXT_ERR_SUCCESS; +} + +void touch_screen_suspend(void) +{ + touch_peripheral_api *touch_ptr = touch_screen_get_api(); + ext_errno ret = touch_ptr->touch_sleep(); + if (ret != EXT_ERR_SUCCESS) { tp_err("touch sleep ret=0x%x", ret); } +#if defined(TPTYPE_FT6X46) + if (ft6x46_suspend() == EXT_ERR_SUCCESS){ + i2c_save_reg(TOUCH_I2C_BUS); + uapi_gpio_disable_interrupt(TOUCH_INT_GPIO); // close tp_int gpio interrupt + } +#else + i2c_save_reg(TOUCH_I2C_BUS); + uapi_gpio_disable_interrupt(TOUCH_INT_GPIO); // close tp_int gpio interrupt +#endif +} + +void touch_screen_resume(void) +{ + uapi_gpio_disable_interrupt(TOUCH_INT_GPIO); // close tp_int gpio interrupt + i2c_recovery_reg(TOUCH_I2C_BUS); +#if defined(TPTYPE_TMA525B) + tma525b_init(); + touch_peripheral_api *touch_ptr = (touch_peripheral_api*)touch_screen_get_api(); + ext_errno ret = touch_ptr->touch_resume(); + if (ret != EXT_ERR_SUCCESS) { tp_err("touch resume ret=0x%x", ret); } +#elif defined(TPTYPE_ZTW523) + ztw523_resume(); +#elif defined(TPTYPE_FT6X46) + ft6x46_resume(); +#else + ztw523_resume(); +#endif + uapi_gpio_enable_interrupt(TOUCH_INT_GPIO); // open tp_int gpio interrupt +} + +void touch_suspend_for_i2c(void) +{ + i2c_save_reg(TOUCH_I2C_BUS); +} + +void touch_resume_for_i2c(void) +{ + i2c_recovery_reg(TOUCH_I2C_BUS); +} + +void touch_screen_restart(void) +{ + uapi_i2c_deinit(TOUCH_I2C_BUS); + uapi_i2c_master_init(TOUCH_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ +#if defined(TPTYPE_TMA525B) + tma525b_resume(); +#elif defined(TPTYPE_ZTW523) + ztw523_resume(); +#elif defined(TPTYPE_FT6X46) + ft6x46_resume(); +#else + ztw523_resume(); +#endif + uapi_gpio_enable_interrupt(TOUCH_INT_GPIO); // open tp_int gpio interrupt +} \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h b/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h new file mode 100644 index 000000000..2bc0c7537 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h @@ -0,0 +1,449 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: PM definitions header file + */ + +#ifndef LIB_PM_DEFINITION_H +#define LIB_PM_DEFINITION_H + +#include "chip_io.h" + +/** + * @defgroup middleware_utils_pm_api PM + * @ingroup middleware_utils + * @{ + */ + +/** + * @if Eng + * @brief PM module Id. + * @else + * @brief PM 模块 ID + * @endif + */ +typedef enum { + PM_ID_BSP, + PM_ID_SYS, + PM_ID_BTH, + PM_ID_BTC, + PM_ID_AUDIO, + PM_ID_VIDEO, + PM_ID_DMA, + PM_ID_DPU, + PM_ID_VAU, + PM_ID_BUTTON, + PM_ID_DEBUG, + PM_ID_ADC, + PM_ID_DFX, + PM_ID_SCREEN, + PM_ID_STORAGE, + PM_ID_TOUCH, + PM_ID_JPEG, + PM_ID_JS, + PM_ID_MSGCENTER, + PM_ID_SPI_DMA, + PM_ID_I2C_DMA, + PM_ID_UART_DMA, + PM_ID_HEART,//新增,心率芯片 + PM_ID_MOTOR,//新增,马达 + PM_ID_GSENSOR,//新增,加速计 + PM_ID_CAT1,//Cat1 communication + PM_ID_P_TEST,//产测 + PM_ID_BUTTON_GPIO,//gpio按键 + PM_ID_MAX, +} pm_id_t; + +/** + * 通过pm_id_t 获取pm_id名字 +*/ +char* get_pm_id_name(int pmid); + + + +/** + * @if Eng + * @brief Key running status of the system. + * @else + * @brief 系统关键运行状态 + * @endif + */ +typedef enum { + PM_STATE_LIGHT_SLEEP, /*!< @if Eng Light Sleep state + @else 浅睡状态 @endif */ + PM_STATE_DEEP_SLEEP, /*!< @if Eng Deep sleep state + @else 深睡状态 @endif */ + PM_STATE_WKUP_FROM_LIGHT_SLEEP, /*!< @if Eng Wakeup from LightSleep + @else 浅睡唤醒 @endif */ + PM_STATE_WKUP_FROM_DEEP_SLEEP, /*!< @if Eng Wakeup from DeepSleep + @else 深睡唤醒 @endif */ + PM_STATE_POWER_ON, /*!< @if Eng Power ON state + @else 上电模式 @endif */ + PM_STATE_POWER_OFF, /*!< @if Eng Power off state + @else 下电模式 @endif */ + PM_STATE_WORK, /*!< @if Eng Working On state + @else 工作模式 @endif */ + PM_STATE_MAX, +} pm_states_t; + +typedef enum { + PM_MODE_NONE, + PM_MODE_LP, + PM_MODE_NORMAL, + PM_MODE_PERFORMACE, + PM_MODE_RESET, + PM_MODE_MAX, +} pm_mode_t; + +typedef enum { + PM_DEV_NONE, + PM_DEV_M_MGPIO, + PM_DEV_M_TIMER, + PM_DEV_M_RTC, + PM_DEV_M_CWDT, + PM_DEV_M_I2C0, + PM_DEV_M_I2C1, + PM_DEV_M_I2C2, + PM_DEV_M_I2C3, + PM_DEV_M_MDMA, + PM_DEV_M_MSDMA, + PM_DEV_M_SPI0, + PM_DEV_M_SPI1, + PM_DEV_M_SPI2, + PM_DEV_M_QSPI2, + PM_DEV_M_UART_H0, + PM_DEV_M_UART_H1, + + PM_DEV_HS_SDIO, + PM_DEV_HS_QSPI1, + PM_DEV_HS_HGPIO, + + PM_DEV_MEM_XIP, + PM_DEV_MEM_QSPI0, + PM_DEV_MEM_OPI, + PM_DEV_MEM_EGPIO, + + PM_DEV_B_WDT, + PM_DEV_B_TIMER, + PM_DEV_B_UART_L1, + + PM_DEV_DISPLAY, + + PM_DEV_AUDIO, + PM_DEV_MAX, +} pm_dev_id_t; + +typedef enum { + /* sys sub region. */ + PMU_ID_SUB_B_SOC = 0, + PMU_ID_SUB_BT_CBB, + PMU_ID_SUB_B_MEM, + PMU_ID_SUB_BT_EM, + PMU_ID_SUB_MCU_HS, + PMU_ID_SUB_DISPLAY, + PMU_ID_SUB_AUDIO, + PMU_ID_SUB_S_EGPIO, + PMU_ID_SUB_BT_RF, + PMU_ID_SUB_MCU, + PMU_ID_SUB_MEM, + PMU_ID_SUB_COM, + PMU_ID_SUB_L2M_GMMU, + PMU_ID_SUB_L2M_DSP, + PMU_ID_SUB_XIP_MEM, + PMU_ID_SUB_BMEM_RAM, + + /* ldo region. */ + PMU_ID_LDO_CLDO1, + PMU_ID_LDO_CLDO2, + PMU_ID_LDO_CLDO3, + PMU_ID_LDO_XLDO, + PMU_ID_LDO_CMU_LDO, + PMU_ID_LDO_INTLDO1, + PMU_ID_LDO_INTLDO2, + PMU_ID_LDO_AUXLDO0, + PMU_ID_LDO_AUXLDO1, + PMU_ID_LDO_AUXLDO2, + PMU_ID_LDO_AUXLDO3, + PMU_ID_LDO_IOLDO, + + /* simo region. */ + PMU_ID_SIMO_VDD0P8, + PMU_ID_SIMO_VDD1P9, + PMU_ID_SIMO_VDD1P0, + PMU_ID_SIMO_VDD1P3, + PMU_ID_SIMO_VDD0P8_BCORE, + PMU_ID_SIMO_MAX, + PMU_ID_MAX, +} pmu_id_t; + +typedef enum { + PMU_CLDO_LEVEL_0P400V = 0, + PMU_CLDO_LEVEL_0P425V = 1, + PMU_CLDO_LEVEL_0P450V = 2, + PMU_CLDO_LEVEL_0P475V = 3, + PMU_CLDO_LEVEL_0P500V = 4, + PMU_CLDO_LEVEL_0P525V = 5, + PMU_CLDO_LEVEL_0P550V = 6, + PMU_CLDO_LEVEL_0P575V = 7, + PMU_CLDO_LEVEL_0P600V = 8, + PMU_CLDO_LEVEL_0P625V = 9, + PMU_CLDO_LEVEL_0P650V = 10, + PMU_CLDO_LEVEL_0P675V = 11, + PMU_CLDO_LEVEL_0P700V = 12, + PMU_CLDO_LEVEL_0P750V = 13, + PMU_CLDO_LEVEL_0P800V = 14, + PMU_CLDO_LEVEL_0P850V = 15, +} pmu_cldo_level_t; + +typedef enum { + PMU_AUXLDO_LEVEL_1P600V = 0, + PMU_AUXLDO_LEVEL_1P625V = 1, + PMU_AUXLDO_LEVEL_1P650V = 2, + PMU_AUXLDO_LEVEL_1P675V = 3, + PMU_AUXLDO_LEVEL_1P700V = 4, + PMU_AUXLDO_LEVEL_1P725V = 5, + PMU_AUXLDO_LEVEL_1P750V = 6, + PMU_AUXLDO_LEVEL_1P775V = 7, + PMU_AUXLDO_LEVEL_1P800V = 8, + PMU_AUXLDO_LEVEL_1P825V = 9, + PMU_AUXLDO_LEVEL_1P850V = 10, + PMU_AUXLDO_LEVEL_1P875V = 11, + PMU_AUXLDO_LEVEL_1P900V = 12, + PMU_AUXLDO_LEVEL_1P925V = 13, + PMU_AUXLDO_LEVEL_1P950V = 14, + PMU_AUXLDO_LEVEL_1P975V = 15, +} pmu_auxldo_level_t; + +typedef enum { + PMU_IOLDO_LEVEL_1P600V = 0, + PMU_IOLDO_LEVEL_1P625V = 1, + PMU_IOLDO_LEVEL_1P650V = 2, + PMU_IOLDO_LEVEL_1P675V = 3, + PMU_IOLDO_LEVEL_1P700V = 4, + PMU_IOLDO_LEVEL_1P725V = 5, + PMU_IOLDO_LEVEL_1P750V = 6, + PMU_IOLDO_LEVEL_1P775V = 7, + PMU_IOLDO_LEVEL_1P800V = 8, + PMU_IOLDO_LEVEL_1P825V = 9, + PMU_IOLDO_LEVEL_1P850V = 10, + PMU_IOLDO_LEVEL_1P875V = 11, + PMU_IOLDO_LEVEL_1P900V = 12, + PMU_IOLDO_LEVEL_1P925V = 13, + PMU_IOLDO_LEVEL_1P950V = 14, + PMU_IOLDO_LEVEL_1P975V = 15, +} pmu_ioldo_level_t; + +typedef enum { + PMU_INTLDO1_LEVEL_1P80V = 0, + PMU_INTLDO1_LEVEL_1P78V = 1, + PMU_INTLDO1_LEVEL_1P82V = 2, + PMU_INTLDO1_LEVEL_1P84V = 3, + PMU_INTLDO1_LEVEL_1P86V = 4, + PMU_INTLDO1_LEVEL_1P88V = 5, + PMU_INTLDO1_LEVEL_1P90V = 6, + PMU_INTLDO1_LEVEL_1P92V = 7, +} pmu_intldo1_level_type_t; + +typedef enum { + PMU_INTLDO2_LEVEL_1P78V = 0, + PMU_INTLDO2_LEVEL_1P80V = 1, + PMU_INTLDO2_LEVEL_1P82V = 2, + PMU_INTLDO2_LEVEL_1P84V = 3, + PMU_INTLDO2_LEVEL_1P86V = 4, + PMU_INTLDO2_LEVEL_1P88V = 5, + PMU_INTLDO2_LEVEL_1P90V = 6, + PMU_INTLDO2_LEVEL_1P92V = 7, +} pmu_intldo2_level_type_t; + +typedef enum { + PMU_XLDO_LEVEL_1P600V = 0, + PMU_XLDO_LEVEL_1P625V = 1, + PMU_XLDO_LEVEL_1P650V = 2, + PMU_XLDO_LEVEL_1P675V = 3, + PMU_XLDO_LEVEL_1P700V = 4, + PMU_XLDO_LEVEL_1P725V = 5, + PMU_XLDO_LEVEL_1P750V = 6, + PMU_XLDO_LEVEL_1P775V = 7, + PMU_XLDO_LEVEL_1P800V = 8, + PMU_XLDO_LEVEL_1P825V = 9, + PMU_XLDO_LEVEL_1P850V = 10, +} pmu_xldo_level_type_t; + +typedef enum { + PMU_CMU_LDO_LEVEL_0P720V = 0, + PMU_CMU_LDO_LEVEL_0P740V = 1, + PMU_CMU_LDO_LEVEL_0P760V = 2, + PMU_CMU_LDO_LEVEL_0P780V = 3, + PMU_CMU_LDO_LEVEL_0P800V = 4, + PMU_CMU_LDO_LEVEL_0P820V = 5, + PMU_CMU_LDO_LEVEL_0P840V = 6, + PMU_CMU_LDO_LEVEL_0P860V = 7, + PMU_CMU_LDO_LEVEL_0P880V = 8, + PMU_CMU_LDO_LEVEL_0P900V = 9, + PMU_CMU_LDO_LEVEL_0P920V = 10, + PMU_CMU_LDO_LEVEL_0P940V = 11, + PMU_CMU_LDO_LEVEL_0P960V = 12, + PMU_CMU_LDO_LEVEL_0P980V = 13, + PMU_CMU_LDO_LEVEL_1P000V = 14, + PMU_CMU_LDO_LEVEL_1P020V = 15, +} pmu_cmu_ldo_level_type_t; + +/* simo1_vo2&simo2_vo2 */ +typedef enum { + PMU_VDD0P8_1P0_0P600V = 0, + PMU_VDD0P8_1P0_0P625V = 1, + PMU_VDD0P8_1P0_0P650V = 2, + PMU_VDD0P8_1P0_0P675V = 3, + PMU_VDD0P8_1P0_0P700V = 4, + PMU_VDD0P8_1P0_0P725V = 5, + PMU_VDD0P8_1P0_0P750V = 6, + PMU_VDD0P8_1P0_0P775V = 7, + PMU_VDD0P8_1P0_0P800V = 8, + PMU_VDD0P8_1P0_0P825V = 9, + PMU_VDD0P8_1P0_0P850V = 10, + PMU_VDD0P8_1P0_0P875V = 11, + PMU_VDD0P8_1P0_0P900V = 12, + PMU_VDD0P8_1P0_0P925V = 13, + PMU_VDD0P8_1P0_0P950V = 14, + PMU_VDD0P8_1P0_0P975V = 15, + PMU_VDD0P8_1P0_1P000V = 16, + PMU_VDD0P8_1P0_1P025V = 17, + PMU_VDD0P8_1P0_1P050V = 18, + PMU_VDD0P8_1P0_1P075V = 19, + PMU_VDD0P8_1P0_1P100V = 20, +} pmu_vdd0p8_level_t; + +/* simo1_vo1&simo2_vo1 */ +typedef enum { + PMU_VDD1P9_1P3_0P800V = 0, + PMU_VDD1P9_1P3_0P850V = 2, + PMU_VDD1P9_1P3_0P900V = 4, + PMU_VDD1P9_1P3_0P950V = 6, + PMU_VDD1P9_1P3_1P000V = 8, + PMU_VDD1P9_1P3_1P050V = 10, + PMU_VDD1P9_1P3_1P100V = 12, + PMU_VDD1P9_1P3_1P150V = 14, + PMU_VDD1P9_1P3_1P200V = 16, + PMU_VDD1P9_1P3_1P250V = 18, + PMU_VDD1P9_1P3_1P300V = 20, + PMU_VDD1P9_1P3_1P350V = 22, + PMU_VDD1P9_1P3_1P400V = 24, + PMU_VDD1P9_1P3_1P450V = 26, + PMU_VDD1P9_1P3_1P500V = 28, + PMU_VDD1P9_1P3_1P550V = 30, + PMU_VDD1P9_1P3_1P600V = 32, + PMU_VDD1P9_1P3_1P650V = 34, + PMU_VDD1P9_1P3_1P700V = 36, + PMU_VDD1P9_1P3_1P750V = 38, + PMU_VDD1P9_1P3_1P800V = 40, + PMU_VDD1P9_1P3_1P850V = 42, + PMU_VDD1P9_1P3_1P900V = 44, + PMU_VDD1P9_1P3_1P950V = 46, + PMU_VDD1P9_1P3_2P000V = 48, +} pmu_vdd1p9_level_t; + +typedef enum { + // MSUB Perip & BUS + CLOCKS_ID_M_TIMER, + CLOCKS_ID_M_SMDMA, + CLOCKS_ID_M_MDMA, + CLOCKS_ID_M_I2C0, + CLOCKS_ID_M_I2C1, + CLOCKS_ID_M_I2C2, + CLOCKS_ID_M_I2C3, + CLOCKS_ID_M_SPI0, + CLOCKS_ID_M_SPI1, + CLOCKS_ID_M_SPI2, + CLOCKS_ID_M_UART_H0, + CLOCKS_ID_M_UART_H1, + CLOCKS_ID_M_EMMC, + CLOCKS_ID_M_SDIO, + CLOCKS_ID_M_PWM, + // BSUB Perip & BUS + CLOCKS_ID_B_UART, + CLOCKS_ID_B_TRNG, + CLOCKS_ID_B_DIAG, + CLOCKS_ID_B_CPU_TRACE, + CLOCKS_ID_B_TIMER, + CLOCKS_ID_B_WDT, + CLOCKS_ID_B_TSENSOR, + // AON + CLOCKS_ID_AON_GPIO0, + CLOCKS_ID_AON_GPIO1, + CLOCKS_ID_AON_GPIO2, + CLOCKS_ID_AON_GPIO3, + CLOCKS_ID_AON_GPIO4, + CLOCKS_ID_AON_RTC, + CLOCKS_ID_AON_CWDT, + // MEM SUB + CLOCKS_ID_MEM_QSPI0, + CLOCKS_ID_MEM_OPI, + // DAON SUB + CLOCKS_ID_DAON_GPIO, + + // Module + CLOCKS_ID_SOC_MCU_CORE, + CLOCKS_ID_SOC_MCU_PERP_LS, + CLOCKS_ID_SOC_MCU_PERP_UART, + CLOCKS_ID_SOC_MCU_PERP_SPI, + CLOCKS_ID_SOC_COM_BUS, + CLOCKS_ID_SOC_SDIOM, + CLOCKS_ID_SOC_MEM_BUS, + CLOCKS_ID_SOC_XIP_OPI, + CLOCKS_ID_SOC_XIP_QSPI, + CLOCKS_ID_SOC_GPU, + CLOCKS_ID_SOC_HIFI, + CLOCKS_ID_SOC_CODEC, + CLOCKS_ID_SOC_BT_CORE, + CLOCKS_ID_SOC_MAX, + CLOCKS_ID_MAX, +} clocks_id_t; + +typedef enum { + CLOCKS_SRC_RC = 0, + CLOCKS_SRC_TCXO = 1, + CLOCKS_SRC_TCXO_2X = 2, + CLOCKS_SRC_PLL = 3, + CLOCKS_SRC_32K = 4, + CLOCKS_SRC_PAD_CLKIN = 5, + CLOCKS_SRC_MAX, +} clocks_src_t; + +typedef struct { + uint8_t *data; + uint32_t len; + uint32_t (*handler)(uint8_t *data, uint32_t len); +} pm_fsm_content_t; + +/** + * @if Eng + * @brief Operating functions of peripheral devices. + * @else + * @brief 外设的设备处理函数 + * @endif + */ +typedef struct { + uint32_t (*suspend)(void); + uint32_t (*resume)(void); + uint32_t (*ioctl)(uint8_t type, uint8_t *data, uint32_t len); +} pm_dev_ops_t; + +/** + * @if Eng + * @brief The global list of device functions is filled by the driver and + bus and registered with the PM module.Supports single-point registration with the PM module in services. + * @else + * @brief 设备函数全局列表,由驱动、总线填充,统一注册到pm模块;同时支持在业务中单点注册至pm模块 + * @endif + */ +#define PM_ALL_DEV { \ + {PM_DEV_M_TIMER, {NULL, NULL, pm_dev_ostimer_ioctl}}, \ + {PM_DEV_M_CWDT, {NULL, NULL, pm_dev_wdt_ioctl}}, \ + {PM_DEV_M_RTC, {NULL, NULL, pm_dev_rtc_ioctl}}, \ + {PM_DEV_M_UART_H0, {NULL, NULL, NULL}}, \ +} + +/** + * @} + */ + +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/pm.c b/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/pm.c new file mode 100644 index 000000000..d9a125a31 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/pm.c @@ -0,0 +1,254 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: pm dev operations code + */ + +#include "pm.h" +#include "pm_sleep.h" +#include "pm_veto.h" +#include "pm_dev.h" +#include "pm_fsm.h" +#include "clocks_core.h" +#include "chip_io.h" +#include "rtc.h" +#include "watchdog.h" +#include "watchdog_porting.h" +#include "securec.h" +#include "pmu_interrupt.h" + +typedef struct { + uint32_t slp_ms; + uint32_t handle; + rtc_callback_t cb; +} pm_rtc_timer_t; + +typedef struct { + pm_dev_id_t dev_id; + pm_dev_ops_t dev_ops; +} pm_dev_t; + +#if CORE == MASTER_BY_ALL +static clocks_clk_cfg_t g_cpu_cfg; +#endif + +#define PM_SHIPMODE_DELAY_SLEEP_MS 100 + +// ostimer +static uint32_t pm_dev_ostimer_ioctl(uint8_t type, uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); + switch (type) { + case DEV_OSTIMER_ENABLE: + pm_os_timer_enable(); + break; + case DEV_OSTIMER_DISABLE: + pm_os_timer_disable(); + break; + default: + break; + } + return 0; +} + +// rtc +static uint32_t rtc_start_wkup_timer(uint8_t *data, uint32_t len) +{ + if (len != sizeof(pm_rtc_timer_t)) { + return (uint32_t)ERRCODE_PM_ERROR; + } + + pm_rtc_timer_t *timer = (pm_rtc_timer_t *)data; + uint32_t wakeup_time = timer->slp_ms; + rtc_handle_t *handle = (rtc_handle_t)(timer->handle); + if (handle == NULL) { + return (uint32_t)ERRCODE_PM_ERROR; + } + if (*handle == NULL) { + uapi_rtc_create(RTC_0, handle); + uapi_rtc_start(*handle, wakeup_time, (rtc_callback_t)timer->cb, 0); + } else { + uapi_rtc_start(*handle, wakeup_time, (rtc_callback_t)timer->cb, 0); + } + return (uint32_t)ERRCODE_SUCC; +} + +static uint32_t pm_dev_rtc_ioctl(uint8_t type, uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); + switch (type) { + case DEV_RTC_START: + return rtc_start_wkup_timer(data, len); + default: + break; + } + return 0; +} + +static uint32_t pm_dev_wdt_ioctl(uint8_t type, uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); + switch (type) { + case DEV_WDT_ENABLE: + watchdog_turnon_clk(); + uapi_watchdog_set_time(watchdog_get_conifgtime); + uapi_watchdog_enable(WDT_MODE_INTERRUPT); + break; + case DEV_WDT_DISABLE: + watchdog_turnon_clk(); + uapi_watchdog_disable(); + watchdog_turnoff_clk(); + break; + default: + break; + } + return 0; +} + +static void pm_dev_register_sleep_ops(void) +{ + pm_dev_t all_devs[] = PM_ALL_DEV; + + for (uint8_t i = 0; i < sizeof(all_devs) / sizeof(pm_dev_t); i++) { + uapi_pm_register_dev_ops(all_devs[i].dev_id, &(all_devs[i].dev_ops)); + } +} + +static uint32_t core_crg_switch(uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); +#if CORE == MASTER_BY_ALL + if (data == NULL) { + return 0; + } + + if (data[0] == PM_STATE_DEEP_SLEEP) { + // todo + } else if (data[0] == PM_STATE_WKUP_FROM_DEEP_SLEEP) { + // todo + } +#endif + return 0; +} + +static void pm_fsm_register_sleep_handler(void) +{ + uint8_t state = PM_STATE_DEEP_SLEEP; + pm_fsm_content_t content = {&state, 1, core_crg_switch}; + uapi_pm_register_fsm_handler(PM_ID_SYS, PM_STATE_DEEP_SLEEP, &content); + + state = PM_STATE_WKUP_FROM_DEEP_SLEEP; + uapi_pm_register_fsm_handler(PM_ID_SYS, PM_STATE_WKUP_FROM_DEEP_SLEEP, &content); +} + +void uapi_pm_init(void) +{ + pm_veto_init(); + pm_dev_register_sleep_ops(); + pm_fsm_register_sleep_handler(); +#if ENABLE_LOW_POWER == YES +#ifdef __LITEOS__ + LOS_LowpowerHookReg(uapi_pm_enter_sleep); +#endif + uapi_pm_add_sleep_veto(PM_ID_DEBUG); +#endif +} + +void uapi_sys_force_mcu_only_deep_sleep_mode(uint32_t arg) +{ + UNUSED(arg); + uint32_t irq = osal_irq_lock(); + + reg16_clrbit(0x57000168, 0x2); // close watchdog clock + pm_enter_deep_sleep_only_ulp_wakeup(); + osal_irq_restore(irq); +} + +void uapi_sys_shipmode(uint32_t arg) +{ + UNUSED(arg); + uint32_t irq = osal_irq_lock(); + uapi_pm_control(PM_BT_POWER_OFF); + uapi_pm_control(PM_DSP_POWER_OFF); + uapi_pm_control(PM_DISPLAY_POWER_OFF); + + /* clr ulp int and event */ + writel(0x5702C1E4, 0x3F); + writel(0x5702C1EC, 0x3F); + uapi_tcxo_delay_us(PM_SHIPMODE_DELAY_SLEEP_MS); + + reg16_clrbit(0x5702c508, POS_14); + writew(0x5700450c, 0x100); + + // gpio + writew(0x5702C200, 0x0); + writew(0x5702C204, 0x0); + writew(0x5702C208, 0x0); + writew(0x5702C20c, 0x0); + writew(0x5702C210, 0x0); + + writew(0x5702c200, 0x7); + writew(0x57030004, 0x0); + writew(0x57030038, 0x1); + writew(0x5703003c, 0x1); + writew(0x57030034, 0x0); + writew(0x57030030, 0x1); + + writew(0x570040d8, 0xc000); + writew(0x5702c028, 0x0); + writew(0x5702c024, 0x3); + writew(0x5702c1d0, 0x1); + writew(0x5702C038, 0x0); + writew(0x5702C1F0, 0x1C); + writew(0x5702C110, 0x101); + writew(0x570040d0, 0x1); + writew(0x570040e0, 0x1); + osal_irq_restore(irq); +} + + +const char* pm_id_name_arr[] ={ + "PM_ID_BSP", + "PM_ID_SYS", + "PM_ID_BTH", + "PM_ID_BTC", + "PM_ID_AUDIO", + "PM_ID_VIDEO", + "PM_ID_DMA", + "PM_ID_DPU", + "PM_ID_VAU", + "PM_ID_BUTTON", + "PM_ID_DEBUG", + "PM_ID_ADC", + "PM_ID_DFX", + "PM_ID_SCREEN", + "PM_ID_STORAGE", + "PM_ID_TOUCH", + "PM_ID_JPEG", + "PM_ID_JS", + "PM_ID_MSGCENTER", + "PM_ID_SPI_DMA", + "PM_ID_I2C_DMA", + "PM_ID_UART_DMA", + "PM_ID_HEART",//ÐÂÔö£¬ÐÄÂÊоƬ + "PM_ID_MOTOR",//ÐÂÔö£¬Âí´ï + "PM_ID_GSENSOR",//ÐÂÔö£¬¼ÓËÙ¼Æ + "PM_ID_CAT1",//Cat1 communication + "PM_ID_P_TEST", + "PM_ID_BUTTON_GPIO",//GPIO°´¼ü + "PM_ID_MAX" +}; + +char* get_pm_id_name(int pmid) +{ + + int count = sizeof(pm_id_name_arr)/sizeof(char*); + if (pmid> count -1) + pmid = count -1; + if (pmid< PM_ID_BSP) + pmid = PM_ID_BSP; + return pm_id_name_arr[pmid]; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/service/pm_sleep.c b/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/service/pm_sleep.c new file mode 100644 index 000000000..ec719d85d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/middleware/chips/brandy/pm/service/pm_sleep.c @@ -0,0 +1,369 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: pm sleep manage code + */ + +#include "pm_sleep.h" +#include "pm.h" +#include "pm_definition.h" +#include "errcode.h" +#include "pm_os.h" +#include "pm_veto.h" +#include "pm_dev.h" +#include "pm_fsm.h" +#include "pm_lpc.h" +#include "pm_core.h" +#include "pm_clocks.h" +#include "clocks_config.h" +#include "arch_encoding.h" +#include "arch_barrier.h" +#include "debug_print.h" +#include "pmu_interrupt.h" +#if CONFIG_PM_TICKLESS_EN == YES +#include "pm_tickless.h" +#endif +#include "non_os_reboot.h" + +#define PM_SLEEP_THRESHOLD_WFI_ONLY_MS 10 +#define PM_SLEEP_THRESHOLD_DEEPSLEEP_MS 20 +#define PM_SLEEP_SEL_TRACE 0x5700041c +#define PM_SLEEP_TRACE_SEL_TAG(val) (writew(PM_SLEEP_SEL_TRACE, val)) +#define PM_SLEEP_SEL_EVENT 0x777 +#define PM_SLEEP_TRACE_DEF_VAL 0x5a5a +#define PM_OS_US_TO_MS 1000 +#define RTC_TIMER_INT_STATUS 0x57024010 +#define PM_RTC_LOAD_COUNT_REG 0x57024000 +#define PM_RTC_CUR_ALERT_US 64000000 +#define PM_RTC_LOAD_THRESHOLD_MS (CLOCK_32K_CALI_FREQ / 50) + +enum { + PM_SLEEP_STATE_IDLE, + PM_SLEEP_STATE_GOTO_DS, + PM_SLEEP_STATE_WKUP_PRE, +}; + +typedef enum { + SLP_INFO_TIME_BASE = 0, + SLP_INFO_LIGHTSLEEP, + SLP_INFO_DEEPSLEEP, + SLP_INFO_VETO, + SLP_INFO_MAX, +} slp_record_info_t; + +static sleep_info_t g_sleep_info = {0}; + +#if CONFIG_PM_POWER_GATING_EN == YES +static uint8_t g_pm_stop_state = 0; +#endif + +static uint16_t g_pm_sleep_threshold = PM_SLEEP_THRESHOLD_DEEPSLEEP_MS; +static uint8_t g_pm_mcu_dynamic_power_flag = 0; + +static void pm_enter_deepsleep_set_flag(void) +{ + writew(GLB_CTL_B_RB_BASE + 0x18, 0x5a5a); +} + +static void pm_enter_deepsleep_cancel_flag(void) +{ + writew(GLB_CTL_B_RB_BASE + 0x18, 0xa5a5); +} + +static void pm_sleep_info_record(slp_record_info_t info) +{ +#if CONFIG_PM_SLEEP_RECORD_EN == YES + if (info == SLP_INFO_TIME_BASE) { + g_sleep_info.sleep_base_time = pm_core_get_current_ms(); + } else if (info == SLP_INFO_LIGHTSLEEP) { + g_sleep_info.sleep_history[PM_SLEEP_LS].total_slp_count++; + g_sleep_info.sleep_history[PM_SLEEP_LS].total_slp_time += + (pm_core_get_current_ms() - g_sleep_info.sleep_base_time); + } else if (info == SLP_INFO_DEEPSLEEP) { + g_sleep_info.sleep_history[PM_SLEEP_DS].total_slp_count++; + g_sleep_info.sleep_history[PM_SLEEP_DS].total_slp_time += + (pm_core_get_current_ms() - g_sleep_info.sleep_base_time); + } else if (info == SLP_INFO_VETO) { + g_sleep_info.sleep_veto.last_veto_count = pm_veto_get_info()->veto_counts.total_counts; + g_sleep_info.sleep_veto.last_veto_id = pm_veto_get_info()->last_veto_id; + } + g_sleep_info.event.slp_event = lpc_sleep_get_all_status(LPC_EVT_ACTION); + g_sleep_info.event.wkup_event = lpc_wakeup_get_all_status(LPC_EVT_ACTION); +#else + UNUSED(info); +#endif +} + +static void pm_sleep_prepare(uint8_t sleep_type) +{ + pm_states_t state; + if (sleep_type == PM_SLEEP_LS) { + state = PM_STATE_LIGHT_SLEEP; + lpc_lightsleep_config(); + } else if (sleep_type == PM_SLEEP_DS) { + state = PM_STATE_DEEP_SLEEP; + lpc_deepsleep_config(); + } + + for (pm_id_t id = 0; id < PM_ID_MAX; id++) { + pm_process_fsm_handler(id, state); + } +} + +static void pm_wkup_prepare(uint8_t sleep_type) +{ + pm_states_t state; + lpc_sleep_all_status_clear(LPC_EVT_ACTION); + lpc_wakeup_all_status_clear(LPC_EVT_ACTION); + + if (sleep_type == PM_SLEEP_LS) { + state = PM_STATE_WKUP_FROM_LIGHT_SLEEP; + } else if (sleep_type == PM_SLEEP_DS) { + state = PM_STATE_WKUP_FROM_DEEP_SLEEP; + } + + for (pm_id_t id = 0; id < PM_ID_MAX; id++) { + pm_process_fsm_handler(id, state); + } +} + +static inline void pm_enter_wfi(void) +{ + reg16_setbits(0x57004704, 0x1, 0x1, 0x0); + while (reg16_getbits(0x57004708, 0x1, 0x1) != 0) { + reg16_setbits(0x57004700, 0x1, 0x1, 0x1); + } + lpc_wfi(); +} + +static void pm_enter_light_sleep(void) +{ + pm_sleep_prepare(PM_SLEEP_LS); + // 进入wfi + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + pm_wkup_prepare(PM_SLEEP_LS); +} + +static void pm_enter_lock_irq(void) +{ + clear_custom_csr(0x300, 0x3); +} + +static void pm_enter_unlock_irq(void) +{ + set_custom_csr(0x300, 0x3); +} + +static void pm_enter_enable_irq(uint32_t irq) +{ + reg8_write(CLIC_BASE_REG + sys_clic_intie(irq), 0x1); +} + +static void pm_enter_disable_irq(uint32_t irq) +{ + reg8_write(CLIC_BASE_REG + sys_clic_intie(irq), 0x0); +} + +void pm_enter_deep_sleep_wfi(void) +{ + wfi(); + pm_enter_lock_irq(); + // wait soc aon low power ready + while (reg16_getbits(0x52000D00, 0x0, 0x4) != 0) { + } + lowpower_cpu_resume(); +} + +void pm_wkup_event_by_ulp_callback(void) +{ + set_cpu_utils_reset_cause(REBOOT_CAUSE_APPLICATION_SYSRESETREQ); + hal_reboot_chip(); +} + +void pm_enter_deep_sleep_only_ulp_wakeup(void) +{ + reg16_clrbit(0x520003e4, 0x3); // close mdam clock in deepsleep + if (pm_dev_suspend() != ERRCODE_SUCC) { + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + return; + } + g_pm_stop_state = PM_SLEEP_STATE_GOTO_DS; + pm_sleep_prepare(PM_SLEEP_DS); + pm_core_suspend_min(); + + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_TRACE_DEF_VAL); + if (g_pm_stop_state == PM_SLEEP_STATE_GOTO_DS) { + g_pm_stop_state = PM_SLEEP_STATE_WKUP_PRE; + pm_core_close_all_irq(); + pm_enter_enable_irq(M_WAKEUP_IRQN); + lpc_allow_deepsleep(); + pm_enter_unlock_irq(); + if (pmu_mcpu_allow_to_sleep_status() == TURN_ON) { + dsb(); + pm_enter_deepsleep_cancel_flag(); + writew(0x57004684, 0x2000); // only open ulp wakeup event + writew(0x57004728, 0x0); + writew(0x57004694, 0x2000); // only open ulp wakeup interrupt + writew(0x5702c1f0, 0x8); // only open ulp wakeup powerkey interrupt + pm_enter_deep_sleep_wfi(); + } + pm_enter_lock_irq(); + } else if (g_pm_stop_state == PM_SLEEP_STATE_WKUP_PRE) { + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_SEL_EVENT); + pm_enter_disable_irq(M_WAKEUP_IRQN); + lpc_forbid_deepsleep(); + pm_core_resume_min(); + pm_dev_resume(); + } + uint16_t status = pmu_lpm_wakeup_get_status(LPM_EVT_ACTION, PMU_LPM_MCPU_ULP_WAKEUP); + pm_wkup_prepare(PM_SLEEP_DS); + pm_sleep_info_record(SLP_INFO_DEEPSLEEP); + reg16_setbit(0x520003e4, 0x3); // open mdam clock after deepsleep + if (status != 0) { + pm_wkup_event_by_ulp_callback(); + } +} +#ifdef SUPPORT_CAT1_SERVICE +#include "cat1_pub_api.h" +void pm_wkup_event_by_uart_callback(void) +{ + if(cat1_api_custom_is_cmd_rx_enabled()) + uapi_pm_add_sleep_veto(PM_ID_DEBUG); +} +#else +void pm_wkup_event_by_uart_callback(void) +{ + uapi_pm_add_sleep_veto(PM_ID_DEBUG); +} +#endif + +static void pm_enter_deep_sleep(void) +{ + reg16_clrbit(0x520003e4, 0x3); // close mdam clock in deepsleep +#if CONFIG_PM_POWER_GATING_EN == YES + if (pm_dev_suspend() != ERRCODE_SUCC) { + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + return; + } + g_pm_stop_state = PM_SLEEP_STATE_GOTO_DS; + pm_sleep_prepare(PM_SLEEP_DS); + pm_core_suspend(); + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_TRACE_DEF_VAL); + if (g_pm_stop_state == PM_SLEEP_STATE_GOTO_DS) { + g_pm_stop_state = PM_SLEEP_STATE_WKUP_PRE; + pm_core_close_all_irq(); + pm_enter_enable_irq(M_WAKEUP_IRQN); + lpc_allow_deepsleep(); + pm_enter_unlock_irq(); + if (pmu_mcpu_allow_to_sleep_status() == TURN_ON) { + dsb(); + pm_enter_deepsleep_cancel_flag(); + pm_enter_deep_sleep_wfi(); + } + pm_enter_lock_irq(); + } else if (g_pm_stop_state == PM_SLEEP_STATE_WKUP_PRE) { + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_SEL_EVENT); + pm_enter_disable_irq(M_WAKEUP_IRQN); + lpc_forbid_deepsleep(); + pm_core_resume(); + pm_dev_resume(); + } +#else + pm_sleep_prepare(PM_SLEEP_DS); + lpc_allow_deepsleep(); + pm_enter_wfi(); + lpc_forbid_deepsleep(); +#endif +#ifndef FT_SINGLE_UART + uint16_t status = pmu_lpm_wakeup_get_status(LPM_EVT_ACTION, PMU_LPM_MCPU_UART_H1_RX_WAKEUP); +#else + uint16_t status = pmu_lpm_wakeup_get_status(LPM_EVT_ACTION, PMU_LPM_MCPU_UART_H0_RX_WAKEUP); +#endif + if (status != 0) { + pm_wkup_event_by_uart_callback(); + } + pm_wkup_prepare(PM_SLEEP_DS); + pm_sleep_info_record(SLP_INFO_DEEPSLEEP); + reg16_setbit(0x520003e4, 0x3); // open mdam clock after deepsleep +} + +sleep_info_t *pm_get_sleep_info(void) +{ + return &g_sleep_info; +} + +void pm_enter_sleep(uint32_t sleep_ms_val) +{ + uint32_t status; + uint32_t sleep_ms = sleep_ms_val; + uint32_t rtc_times = 0; + uint32_t rtc_times_alert = 0; + if ((g_pm_mcu_dynamic_power_flag == 1) || hal_ipc_get_core_clr_sts(CORES_BT_CORE)) { + return; + } + if (sleep_ms == 0) { + return; + } + uapi_rtc_get_current_time_us(0, &rtc_times); + if (rtc_times > PM_RTC_CUR_ALERT_US) { + rtc_times_alert = rtc_times; + rtc_times = rtc_porting_cycle_2_us(readl(PM_RTC_LOAD_COUNT_REG)); + } + if (rtc_times < PM_OS_US_TO_MS && rtc_times > 0) { + return; + } + rtc_times /= PM_OS_US_TO_MS; + if (sleep_ms > rtc_times && rtc_times != 0) { + sleep_ms = rtc_times; + } + if (sleep_ms <= PM_SLEEP_THRESHOLD_WFI_ONLY_MS || pm_get_sleep_veto()) { + status = pm_os_irq_lock(); + pm_sleep_info_record(SLP_INFO_TIME_BASE); + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + pm_os_irq_restore(status); + return; + } + + pm_sleep_info_record(SLP_INFO_TIME_BASE); + pm_sleep_info_record(SLP_INFO_VETO); + + pm_enter_deepsleep_set_flag(); + status = pm_os_irq_lock(); + if ((sleep_ms <= g_pm_sleep_threshold) || pm_get_sleep_veto() || readl(RTC_TIMER_INT_STATUS) == 1 || + ((readl(PM_RTC_LOAD_COUNT_REG) < PM_RTC_LOAD_THRESHOLD_MS) && (rtc_times_alert > PM_RTC_CUR_ALERT_US))) { + pm_enter_deepsleep_cancel_flag(); + pm_enter_light_sleep(); + } else { +#if CONFIG_PM_TICKLESS_EN == YES + pm_tickless_start(sleep_ms); +#endif + pm_enter_deep_sleep(); +#if CONFIG_PM_TICKLESS_EN == YES + pm_tickless_stop(sleep_ms); +#endif + } + pm_os_irq_restore(status); + pm_enter_deepsleep_cancel_flag(); +} + +void pm_set_sleep_threshold(uint16_t ms) +{ + if (ms < PM_SLEEP_THRESHOLD_WFI_ONLY_MS) { + return ; + } + g_pm_sleep_threshold = ms; +} + +void pm_set_mcu_dynamic_power_flag(uint8_t flag) +{ + g_pm_mcu_dynamic_power_flag = flag; +} + +void uapi_pm_enter_sleep(void) +{ + uint32_t sleep_ms = pm_os_get_sleep_ms(); + pm_enter_sleep(sleep_ms); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/tools/pkg/chip_packet/brandy/packet.py b/sdk_release/v1.0/4gsdk_new/code/sdk/tools/pkg/chip_packet/brandy/packet.py new file mode 100644 index 000000000..d81921870 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/tools/pkg/chip_packet/brandy/packet.py @@ -0,0 +1,225 @@ +#!/usr/bin/env python3 +# encoding=utf-8 +# ============================================================================ +# @brief packet files +# ============================================================================ + +import os +import sys + +PY_PATH = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(PY_PATH) +PKG_DIR = os.path.dirname(PY_PATH) +PKG_DIR = os.path.dirname(PKG_DIR) +from packet_create import create_sha_file +from packet_create import packet_bin + +TOOLS_DIR = os.path.dirname(PKG_DIR) +SDK_DIR = os.path.dirname(TOOLS_DIR) +sys.path.append(os.path.join(SDK_DIR, "build", "script")) +sys.path.append(os.path.join(SDK_DIR, 'build', 'config')) +sys.path.append(os.path.join(SDK_DIR, "build", "script", "nv")) +from enviroment import TargetEnvironment +from param_packet import gen_flash_part_bin +from nv_binary import nv_begin + +# brandy packet +def build_brandy_other_bin(pack_style_str, flash_size): + ''' build brandy partition and nv ''' + chip_dir = os.path.join(SDK_DIR, "build", "config", "target_config", "brandy") + # 分区配置文件路径 + partition_cfg = os.path.join(chip_dir, "param_sector") + if flash_size.endswith("0x1000000"): + partition_cfg = os.path.join(partition_cfg, "param_sector_16M.json") + else: + partition_cfg = os.path.join(partition_cfg, "param_sector.json") + + partition_bin = os.path.join(SDK_DIR, "output", "brandy", "partition_table.bin") + # nv配置文件路径 + nv_config_json = os.path.join(chip_dir, "nv_bin_cfg") + if pack_style_str.endswith("-user"): + nv_config_json = os.path.join(nv_config_json, "mk_nv_bin_cfg_user.json") + else: + nv_config_json = os.path.join(nv_config_json, "mk_nv_bin_cfg_eng.json") + targets = ["acore"] + # 输出路径 + nv_output_path = os.path.join(SDK_DIR, "output", "brandy", "nv_bin") + + if not os.path.exists(nv_output_path): + os.makedirs(nv_output_path) + + gen_flash_part_bin(partition_cfg, partition_bin) + nv_begin(nv_config_json, targets, 0) + +def make_all_in_one_packet_8M(pack_style_str): + # make all in one packet + bin_dir = os.path.join(PKG_DIR, "bin", "brandy") + application_dir = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + pack_style_str) + recovery_target = "%s-r" % pack_style_str + recovery_target = recovery_target.replace('-user', '') + recovery_bin = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + recovery_target, + "recovery.bin") + recovery_bx = recovery_bin + "|0x70050000|0x40000|100" + + upload_app_fwpkg = os.path.join(PKG_DIR, "fwpkg", "brandy", "upload_app.fwpkg") + + ssb = os.path.join(SDK_DIR, "output", "brandy", "acore", "brandy-ssb", "ssb.bin") + if not os.path.exists(ssb): + ssb = os.path.join(bin_dir, "ssb.bin") + print("ssb_path: ", ssb) + ssb_bx = ssb + "|0x70000000|0x20000|0" + + partition = os.path.join(SDK_DIR, "output", "brandy", "partition_table.bin") + partition_bx = partition + "|0x7004F000|0x1000|100" + nv = os.path.join(SDK_DIR, "output", "brandy", "nv_bin", "brandy_all_nv.bin") + # nv_bx = nv + "|0x707F9000|0x4000|100" + nv_bx = nv + "|0x70FF9000|0x4000|100" + + app = os.path.join(application_dir, "application.bin") + # app_bx = app + "|0x702B0000|0x549000|18" #origin + # define APP_IMAGE_PAGES (1353+2560) + # 2560*4*1024= 0xA00000 + app_bx = app + "|0x702B0000|0xD49000|18" + + bt = os.path.join(bin_dir, "bt.bin") + bt_bx = bt + "|0x70090000|0x70000|20" + + target_env = TargetEnvironment(pack_style_str) + dsp_version = target_env.get("dsp_version") + dsp_main = os.path.join(bin_dir, "dsp", dsp_version, "dsp_main.bin") + dsp_main_bx = dsp_main + "|0x70100000|0x70000|22" + dsp_overlay = os.path.join(bin_dir, "dsp", dsp_version, "dsp_overlay.bin") + dsp_overlay_bx = dsp_overlay + "|0x70170000|0x140000|26" + + fs = os.path.join(application_dir, "file.bin") + fs_bx = fs + "|0xFFFFFFFF|0xFFFFFFFF|101" + + try: + packet_post_agvs = list() + packet_post_agvs.append(ssb_bx) + packet_post_agvs.append(partition_bx) + packet_post_agvs.append(app_bx) + packet_post_agvs.append(recovery_bx) + packet_post_agvs.append(bt_bx) + packet_post_agvs.append(dsp_main_bx) + packet_post_agvs.append(dsp_overlay_bx) + packet_post_agvs.append(nv_bx) + packet_post_agvs.append(fs_bx) + packet_bin(upload_app_fwpkg, packet_post_agvs) + except Exception as e: + print(e) + exit(-1) + +def make_all_in_one_packet_16M(pack_style_str): + # make all in one packet + bin_dir = os.path.join(PKG_DIR, "bin", "brandy") + application_dir = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + pack_style_str) + recovery_target = "%s-r" % pack_style_str + recovery_target = recovery_target.replace('-user', '') + recovery_bin = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + recovery_target, + "recovery.bin") + recovery_bx = recovery_bin + "|0x70B80000|0x100000|100" + + upload_app_fwpkg = os.path.join(PKG_DIR, "fwpkg", "brandy", "upload_app.fwpkg") + + ssb = os.path.join(SDK_DIR, "output", "brandy", "acore", "brandy-ssb", "ssb.bin") + if not os.path.exists(ssb): + ssb = os.path.join(bin_dir, "ssb.bin") + print("ssb_path: ", ssb) + ssb_bx = ssb + "|0x70000000|0x20000|0" + + partition = os.path.join(SDK_DIR, "output", "brandy", "partition_table.bin") + partition_bx = partition + "|0x7004F000|0x1000|100" + nv = os.path.join(SDK_DIR, "output", "brandy", "nv_bin", "brandy_all_nv.bin") + nv_bx = nv + "|0x70C80000|0x4000|100" + + app = os.path.join(application_dir, "application.bin") + app_bx = app + "|0x70380000|0x800000|18" + + bt = os.path.join(bin_dir, "bt.bin") + bt_bx = bt + "|0x70090000|0x70000|20" + + target_env = TargetEnvironment(pack_style_str) + dsp_version = target_env.get("dsp_version") + dsp_main = os.path.join(bin_dir, "dsp", dsp_version, "dsp_main.bin") + dsp_main_bx = dsp_main + "|0x70100000|0xC0000|22" + dsp_overlay = os.path.join(bin_dir, "dsp", dsp_version, "dsp_overlay.bin") + dsp_overlay_bx = dsp_overlay + "|0x701C0000|0x1C0000|26" + + fs = os.path.join(application_dir, "file.bin") + fs_bx = fs + "|0xFFFFFFFF|0xFFFFFFFF|101" + + try: + packet_post_agvs = list() + packet_post_agvs.append(ssb_bx) + packet_post_agvs.append(partition_bx) + packet_post_agvs.append(app_bx) + packet_post_agvs.append(recovery_bx) + packet_post_agvs.append(bt_bx) + packet_post_agvs.append(dsp_main_bx) + packet_post_agvs.append(dsp_overlay_bx) + packet_post_agvs.append(nv_bx) + packet_post_agvs.append(fs_bx) + packet_bin(upload_app_fwpkg, packet_post_agvs) + except Exception as e: + print(e) + exit(-1) + + +def make_all_in_one_packet(pack_style_str, flash_size): + # make all in one packet + build_brandy_other_bin(pack_style_str, flash_size) + if flash_size.endswith("0x1000000"): + make_all_in_one_packet_16M(pack_style_str) + else: + make_all_in_one_packet_8M(pack_style_str) + +def is_packing_files_exist(soc, pack_style_str): + """ + 判断打包文件是否存在 + :return: + """ + packing_files = get_packing_files(soc, pack_style_str) + lost_files = list() + for f_path in packing_files: + if not os.path.isfile(f_path): + lost_files.append(f_path) + return lost_files + +def get_packing_files(soc, pack_style_str): + """ + 直接添加需要打包的文件路径 + :return: + """ + packing_files = list() + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "ssb.bin")) + application_path = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + pack_style_str, + "application.bin") + packing_files.append(application_path) + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "bt.bin")) + + target_env = TargetEnvironment(pack_style_str) + dsp_version = target_env.get("dsp_version") + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "dsp", dsp_version, "dsp_main.bin")) + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "dsp", dsp_version, "dsp_overlay.bin")) + return packing_files diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/CMakeLists.txt new file mode 100644 index 000000000..89e122472 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/CMakeLists.txt @@ -0,0 +1,71 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== + +set(COMPONENT_NAME "cat1Test") + + +set(PUBLIC_HEADER +${CMAKE_CURRENT_SOURCE_DIR} +) +set(PRIVATE_HEADER +) +set(lwiptest_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/test_main.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_001.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_002.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_003.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_004.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_005.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_006.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_007.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_008.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_009.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_010.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_011.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_012.c + ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_013.c +) +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/cat1_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/cat1_porting.c + ${lwiptest_SRCS} +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + # -std=c++11 + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + # -Wno-c++11-narrowing + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES +SUPPORT_AT_CAT1 +) + +set(PRIVATE_DEFINES +) + +build_component() diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_at_cmd.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_at_cmd.c new file mode 100644 index 000000000..d38173d8b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_at_cmd.c @@ -0,0 +1,528 @@ + +#include "at_cmd_api.h" +#include "pm_control.h" +#include "cat1_at_cmd.h" +#include "cat1_pub_api.h" +#include +#include +#include +#include +#include +#include +#include "cat1_log.h" + + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) +#define CUSTOM_UTILS_MAX_ARGC 8 +#define CUSTOM_UTILS_MAX_ARGV_LEN 256 + +#define CUSTOM_UTILS_SUCCESS 0 +#define CUSTOM_UTILS_FAILED (-1) + + +#include "app_at_process.h" + +static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen, + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN], uint32_t* argc) +{ + uint32_t pos = 0; + *argc = 0; + + for (uint32_t i = 0; i < paraLen; i++) { + if ((para[i] == ' ' || para[i] == '\n') && pos != 0) { + argv[*argc][pos] = '\0'; + *argc += 1; + pos = 0; + if (*argc >= CUSTOM_UTILS_MAX_ARGC) { + return CUSTOM_UTILS_FAILED; + } + } else { + argv[*argc][pos] = para[i]; + pos++; + if (pos >= CUSTOM_UTILS_MAX_ARGV_LEN) { + return CUSTOM_UTILS_FAILED; + } + } + } + if (pos != 0) { + *argc += 1; + } + + return CUSTOM_UTILS_SUCCESS; +} + + +static uint32_t cat1_power(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + cat1_print_err("CAT1TEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 1) { + cat1_print_err("CAT1TEST ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + // char *mode = (char*)argv[0]; + int enabled = atoi((char*)argv[0]); + + cat1_print_info("CAT1TEST ATCMD power enable %d \n",enabled); + + if(enabled == 1) + { + cat1_api_enable_cat1(true); + }else{ + cat1_api_enable_cat1(false); + } + + return ERRCODE_SUCC; +} +static uint32_t at_cat1_dial(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + cat1_print_err("CAT1TEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 1) { + cat1_print_err("CAT1TEST ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + char *phoneno = (char*)argv[0]; + + cat1_print_info("CAT1TEST ATCMD dial %s \n",phoneno); + + cat1_cmd_send(CMD_4G_MAKE_CALL,phoneno,strlen(phoneno)); + + return ERRCODE_SUCC; +} +static uint32_t at_cat1_answer(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + cat1_print_info("CAT1TEST ATCMD answer \n"); + cat1_cmd_send(CMD_4G_ANSWER_CALL,NULL,0); + return ERRCODE_SUCC; +} +static uint32_t at_cat1_hungup(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + cat1_print_info("CAT1TEST ATCMD hungup \n"); + + cat1_cmd_send(CMD_4G_HUNGUP_CALL,NULL,0); + return ERRCODE_SUCC; +} + +static uint32_t at_cat1_gettime(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + + cat1_print_info("CAT1TEST ATCMD gettime \n"); + + cat1_cmd_send(CMD_4G_GET_TIME,NULL,0); + + return ERRCODE_SUCC; +} + +static uint32_t at_cat1_getsignal(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + + cat1_print_info("CAT1TEST ATCMD getsignal \n"); + + cat1_cmd_send(CMD_4G_GET_SIGNAL,NULL,0); + + return ERRCODE_SUCC; +} +static uint32_t at_cat1_getver(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + cat1_print_info("CAT1TEST ATCMD cat1 getver \n"); + cat1_cmd_send(CMD_4G_GET_VERSION,NULL,0); + + return ERRCODE_SUCC; +} + +extern void LwipTestEnter(void); + +static uint32_t cat1_nettest(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + cat1_print_info("CAT1TEST ATCMD nettest \n"); + LwipTestEnter(); + + return ERRCODE_SUCC; +} +static uint32_t cat1_wakeup(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + cat1_print_err("CAT1TEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + if (argc != 1) { + cat1_print_err("CAT1TEST ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + // char *mode = (char*)argv[0]; + int enabled = atoi((char*)argv[0]); + if(enabled == 0) + { + cat1_api_keep_wakeup(0); + cat1_api_wakeup_cat1(0); + } + else + { + cat1_api_keep_wakeup(1); + cat1_api_wakeup_cat1(1); + } + cat1_print_info("CAT1TEST ATCMD keepwakeup cat1 enabled = %d\n",enabled); + + return ERRCODE_SUCC; +} +#include "lwip/api_shell.h" +static uint32_t cat1_ping(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + cat1_print_err("CAT1TEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + cat1_api_wakeup_cat1(1); + cat1_api_keep_wakeup(1); + u32_t sret= OsShellPing( argc, (const char *)argv[0]); + cat1_print_info("CAT1TEST ATCMD ping ret = 0x%X\n",sret); + cat1_api_keep_wakeup(0); + cat1_api_wakeup_cat1(0); + return ERRCODE_SUCC; +} +static uint32_t cat1_ifconfig(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + cat1_print_err("CAT1TEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + u32_t sret = lwip_ifconfig( argc, (const char**)argv); + cat1_print_info("CAT1TEST ATCMD ifconfig ret = 0x%X\n",sret); + + return ERRCODE_SUCC; +} + +static uint32_t at_cat1_senddtmf(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + cat1_print_info("CAT1TEST SENDDTMF %s \n",para); + cat1_cmd_send(CMD_4G_SEND_DTMF,para,strlen(para)); + return ERRCODE_SUCC; +} + + +static uint32_t at_cat1_atcmd(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + cat1_print_info("CAT1TEST ATCMD %s \n",para); + cat1_cmd_send(CMD_4G_AT,para,strlen(para)); + + return ERRCODE_SUCC; +} + + +#include "audio_manager_c_wrapper.h" + +static uint32_t VoiceCallSetVolume(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + cat1_print_err("CAT1TEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + int32_t linearVolume = atoi((char *)argv[0]); + ret = AudioManagerSetVolume(AUDIO_STREAM_VOICE_CALL_VOLTE, linearVolume); + if (ret != 0) { + cat1_print_err("SetVolume:%d failed", linearVolume); + return -1; + } + cat1_print_info("SetVolume:%d success", linearVolume); + return 0; +} + +#ifdef SUPPORT_CAT1_SERVICE +#include "lwip/altcp_tls.h" +#include "lwip/apps/http_client.h" +// #define USING_HTTPS +#ifdef USING_HTTPS + +// SSL CA PEMs +/* AWS */ +/* AZURE */ +const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n" +"MIICrDCCAlKgAwIBAgIJAJo+BOgbcQBUMAoGCCqGSM49BAMDMIGwMQswCQYDVQQG\n" +"EwJVUzEOMAwGA1UECAwFVGV4YXMxDzANBgNVBAcMBkF1c3RpbjEQMA4GA1UECgwH\n" +"T1NJc29mdDEQMA4GA1UECwwHT1NJc29mdDE5MDcGA1UEAwwwZWMyLTE4LTEzMC03\n" +"OC01MC5ldS13ZXN0LTIuY29tcHV0ZS5hbWF6b25hd3MuY29tMSEwHwYJKoZIhvcN\n" +"AQkBFhJkbG9wZXpAb3Npc29mdC5jb20wHhcNMTgwNjIwMjA1ODA3WhcNMjgwNjE3\n" +"MjA1ODA3WjCBsDELMAkGA1UEBhMCVVMxDjAMBgNVBAgMBVRleGFzMQ8wDQYDVQQH\n" +"DAZBdXN0aW4xEDAOBgNVBAoMB09TSXNvZnQxEDAOBgNVBAsMB09TSXNvZnQxOTA3\n" +"BgNVBAMMMGVjMi0xOC0xMzAtNzgtNTAuZXUtd2VzdC0yLmNvbXB1dGUuYW1hem9u\n" +"YXdzLmNvbTEhMB8GCSqGSIb3DQEJARYSZGxvcGV6QG9zaXNvZnQuY29tMFkwEwYH\n" +"KoZIzj0CAQYIKoZIzj0DAQcDQgAEe4ufVcWu5MwkbE4d6iF1cOhQpgmamQF61RNl\n" +"KiDCfN2jZxR6WYTMHE1UECwZKB7Vj4cMczEgecGAjjjk/Nqnr6NTMFEwHQYDVR0O\n" +"BBYEFE8wR6UrcQxeUTVayZNRUZVIX9ViMB8GA1UdIwQYMBaAFE8wR6UrcQxeUTVa\n" +"yZNRUZVIX9ViMA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwMDSAAwRQIgfS68\n" +"tBUHIJxatGCbZS2vVvCXSR2ojHMkkrxVOfoBCMwCIQDAk7ODHjFev0hX1eoHjtky\n" +"e0wjSDehvRytFUNZ9yqwag==\n" +"-----END CERTIFICATE-----\n" +"-----BEGIN CERTIFICATE-----\n" +"MIICQzCCAegCCQCTvXzEGfGkljAKBggqhkjOPQQDAzCBqDELMAkGA1UEBhMCVVMx\n" +"CzAJBgNVBAgMAlRYMQ8wDQYDVQQHDAZBdXN0aW4xEDAOBgNVBAoMB09TSXNvZnQx\n" +"EDAOBgNVBAsMB0hvdXN0b24xNDAyBgNVBAMMK3Bpc3lzdGVtNzQ2NTYud2VzdGV1\n" +"cm9wZS5jbG91ZGFwcC5henVyZS5jb20xITAfBgkqhkiG9w0BCQEWEmRsb3BlekBv\n" +"c2lzb2Z0LmNvbTAeFw0xODA1MTYxNDI1MzJaFw0yODA1MTMxNDI1MzJaMIGoMQsw\n" +"CQYDVQQGEwJVUzELMAkGA1UECAwCVFgxDzANBgNVBAcMBkF1c3RpbjEQMA4GA1UE\n" +"CgwHT1NJc29mdDEQMA4GA1UECwwHSG91c3RvbjE0MDIGA1UEAwwrcGlzeXN0ZW03\n" +"NDY1Ni53ZXN0ZXVyb3BlLmNsb3VkYXBwLmF6dXJlLmNvbTEhMB8GCSqGSIb3DQEJ\n" +"ARYSZGxvcGV6QG9zaXNvZnQuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\n" +"u67uXtCYyzZe3si9Dv3ai/e5/MuAFQNkjdJCNMDijZFomiCSlm9TETi4zkBG8lxk\n" +"zT+6OQsmoG/Zbp5ZNNI+4zAKBggqhkjOPQQDAwNJADBGAiEA4NqJMQQFhPFLvWbK\n" +"H1/egQjtly1ML0G4mCemIQfhSBkCIQCaIBAiTNVefJxL5cEvg1MnNRMfConzRFqD\n" +"u1PsWfdL5A==\n" +"-----END CERTIFICATE-----\n"; + +altcp_allocator_t *g_allocator = NULL; +#endif +static uint8_t g_http_download_started=0; +/** + * uint8_t *server, + * uint16_t port, + * uint8_t *uri, + * uint8_t *otadatapath, + * httpc_result_fn callback_result_fn, + * httpc_headers_done_fn callback_headers_done_fn, + * httpc_file_rx_fn callback_file_rx_fn +*/ +static httpc_connection_t settings = {0}; +errcode_t http_single_download_start( uint8_t *server, uint16_t port,uint8_t *uri, uint8_t *otadatapath, httpc_result_fn callback_result_fn, httpc_headers_done_fn callback_headers_done_fn, httpc_file_rx_fn callback_file_rx_fn) +{ + + if( server == NULL || uri == NULL || otadatapath == NULL) + { + wstp_print("http_single_download_start failed, param is null \n"); + return ERRCODE_FAIL; + } + if(g_http_download_started==1) + { + wstp_print("http_single_download_start failed, already started \n"); + return ERRCODE_FAIL; + }else{ + g_http_download_started = 1; + } + //通讯开始,唤醒cat1 + cat1_api_keep_wakeup(1); + //httpc_connection_t settings = {0}; + + + + #ifdef USING_HTTPS + + if (strncmp("https",(char*)uri,5)==0) + { + size_t calen = sizeof(SSL_CA_PEM); + struct altcp_tls_config *tlsconfig = altcp_tls_create_config_client((const uint8_t *)SSL_CA_PEM,calen); + wstp_print("custom_start_ota_download pa perm %s \n======len %d \r\n",SSL_CA_PEM,calen); + g_allocator = malloc(sizeof(altcp_allocator_t)); + if (g_allocator==NULL) return ERRCODE_MALLOC; + g_allocator->alloc = altcp_tls_alloc; + g_allocator->arg = (void*)tlsconfig; + settings.altcp_allocator=g_allocator; + } + #endif + + + settings.result_fn=callback_result_fn; + settings.file_rx_fn = callback_file_rx_fn; + settings.headers_done_fn=callback_headers_done_fn; + + settings.use_post = 0 ; + + httpc_state_t* connection=NULL; + cat1_print_info(" http_single_download_start Server: %s\n", server); + cat1_print_info(" http_single_download_start Port: %d\n", port); + cat1_print_info(" http_single_download_start URI: %s\n", uri); + cat1_print_info(" http_single_download_start Filepath: %s\n", otadatapath); + + err_t rett = httpc_get_file_dns_to_disk( + (const char*) server, + port, + (const char*) uri, + (const httpc_connection_t *)&settings, + NULL, + (const char*) otadatapath, + &connection); + if (rett== ERRCODE_SUCC) + { + g_http_download_started = 1; + } + return rett; +} + +/*** + * stop函数要在result里面执行,表示下载结束 + * */ +errcode_t http_single_download_stop(void) +{ + //通讯结束,休眠cat1 + cat1_api_keep_wakeup(0); + g_http_download_started = 0; + return ERRCODE_SUCC; +} +void httpc_download_result(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err) +{ + wstp_print("httpc_download_result , httpc_result_t %d, rx_content_len %d , srv_res %d, err %d\n", + httpc_result,rx_content_len,srv_res,err); + + http_single_download_stop(); + return ; +} +static uint32_t file_total_len = 0; +err_t httpc_download_headers_done(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len) +{ + wstp_print("httpc_download_headers_done , hdr_len %d ,content_len %d\n",hdr_len,content_len); + file_total_len = content_len; + return 0; +} +err_t httpc_download_file_recv_ui(httpc_state_t *connection, u32_t rx_len,u32_t rx_total_len) +{ + wstp_print("httpc_download_file_recv_ui recv %d bytes total received %d filelen %d\r\n",rx_len,rx_total_len,file_total_len); + return 0; +} + +static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 4) { + wstp_print("CUSTOM_UTILSTEST ATCMD Set Parameter Failed argc %d\nshould input:\nAT^HTTPDOWNLOAD=server port file_full_uri file_savepath\n",argc); + return ERRCODE_FAIL; + } + + //通讯开始,唤醒cat1 + cat1_api_keep_wakeup(1); + uint8_t *server = (uint8_t*)argv[0]; + uint16_t port = atoi((const char*)argv[1]); + uint8_t *uri = (uint8_t*)argv[2]; + uint8_t *otadatapath = (uint8_t*)argv[3]; + wstp_print("custom_start_ota_download %s:%d %s to %s\r\n",server,port,uri,otadatapath); + + err_t rett = http_single_download_start(server,port,uri,otadatapath,httpc_download_result,httpc_download_headers_done,httpc_download_file_recv_ui); + + wstp_print("custom_start_ota_download %d \r\n",rett); + return ERRCODE_SUCC; +} + +#else +static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + return ERRCODE_SUCC; +} +#endif + + +static uint32_t custom_enable_cat1_debug_log(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + wstp_print("cat1 ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc <1) { + wstp_print("cat1 ATCMD Set Parameter Failed argc %d\n",argc); + return ERRCODE_FAIL; + } + + uint16_t loglevel = atoi((const char*)argv[0]); + g_cat1_enable_debug=loglevel; + wstp_print("Set Cat1 LOGLEVEL %d\n",loglevel); + return ERRCODE_SUCC; +} + +static const at_cmd_table_t g_cat1_cmd[] = { + { (char *)"AT^CAT1POWER", cat1_power, (char *)"1" }, + { (char *)"AT^CAT1DIAL", at_cat1_dial, (char *)"1" }, + { (char *)"AT^CAT1ANSWER", at_cat1_answer, (char *)"1" }, + { (char *)"AT^CAT1HUNGUP", at_cat1_hungup, (char *)"1" }, + { (char *)"AT^CAT1GETSIGNAL", at_cat1_getsignal, (char *)"1" }, + { (char *)"AT^CAT1GETTIME", at_cat1_gettime, (char *)"1" }, + { (char *)"AT^CAT1GETVER", at_cat1_getver, (char *)"1" }, + { (char *)"AT^CAT1NETTEST", cat1_nettest, (char *)"1" }, + { (char *)"AT^PING", cat1_ping, (char *)"1" }, + { (char *)"AT^WAKECAT1", cat1_wakeup, (char *)"1" }, + { (char *)"AT^IFCONFIG", cat1_ifconfig, (char *)"1" }, + { (char *)"AT^CAT1AT", at_cat1_atcmd, (char *)"1" }, + { (char *)"AT^CALLVOLUME", VoiceCallSetVolume, (char *)"1" }, + { (char *)"AT^SENDDTMF", at_cat1_senddtmf, (char *)"1" }, + { (char *)"AT^HTTPDOWNLOAD", custom_start_ota_download, (char *)" " }, + { (char *)"AT^CAT1LOGLEVEL", custom_enable_cat1_debug_log, (char *)" " }, +}; + +at_cmd_table_t *get_cat1_cmd_table(uint32_t *cmd_count) +{ + *cmd_count = ARRAY_COUNT(g_cat1_cmd); + return (at_cmd_table_t *)g_cat1_cmd; +} +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_at_cmd.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_at_cmd.h new file mode 100644 index 000000000..84aa281be --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_at_cmd.h @@ -0,0 +1,32 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides at cmd register func \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-07-20, Create file. \n + */ +#ifndef CAT1_AT_PROCESS_H +#define CAT1_AT_PROCESS_H + +#include +#include +#include "errcode.h" +#include "soc_osal.h" +#include "at_cmd_api.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +at_cmd_table_t *get_cat1_cmd_table(uint32_t *cmd_count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_porting.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_porting.c new file mode 100644 index 000000000..087026c33 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/cat1_porting.c @@ -0,0 +1,231 @@ +/** + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: get time + * Author: + * Create: + */ + +#include "cat1_porting.h" +#include "cat1_log.h" +#include "pm_definition.h" + +uint8_t g_cat1_enable_debug=CAT1_LOG_LEVEL_INFO; + +static uint16_t g_timezone_quarters = 0xFFFF; +/** + * return quarters for timezone +*/ +static uint16_t get_timezone(void) +{ + /*从系统中获取timezone*/ + if (g_timezone_quarters==0xFFFF) + return (8*15) ; + + return g_timezone_quarters; +} + +#define SECONDS_PER_MINUTE 60 /* seconds per minute */ +#define MINUTES_PER_HOUR 60 /* minutes per hour */ +#define MINUTES_PER_QUARTER 15 /* seconds per quarter */ +#define QUARTERS_PER_HOUR 4 /* quarters per hour */ +#define MSEC_PER_SEC 1000 +#define USEC_PER_MSEC 1000 +#define TZ_ADDRESS 0x5702C014 +#define MAX_TIMEZONE_HOURS 24 +#define TIME_MAX 64 + +static void set_timezone(uint16_t timezone_quarters) +{ + g_timezone_quarters = timezone_quarters; +} +static uint32_t sync_time_utc(uint32_t timestamp, uint32_t timezone_quarters) +{ + printf("sync time utc timestamp %d, timezone_in_quarters %d \r\n", timestamp, timezone_quarters); + uint32_t seconds; + if (timezone_quarters > (MAX_TIMEZONE_HOURS * QUARTERS_PER_HOUR)) { + return ERRCODE_FAIL; + } + if (timestamp == 0) { + return ERRCODE_FAIL; + } + seconds = timestamp; + set_timezone(timezone_quarters); + struct timeval tv = {0}; + struct timezone tzone = {0}; + tv.tv_sec = seconds; + tv.tv_usec = 0; + tzone.tz_dsttime = 0; + tzone.tz_minuteswest = timezone_quarters * MINUTES_PER_QUARTER; + return settimeofday(&tv, &tzone); +} + +static time_ctl_funcs_t g_cat1_time_ctl_funcs={ + get_timezone, + set_timezone, + sync_time_utc, +}; + + +void cat1_api_remove_cat1_vote(void) +{ + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_CAT1); + if (cnt == 1) { + uapi_pm_remove_sleep_veto(PM_ID_CAT1); + } else { + // cat1_print_dbg("CAT1 SERVICE MCU has delete pm_id_cat1 vote\r\n"); + } + cat1_print_dbg("\r\nCAT1 SERVICE MCU SLEEP SUCCESS\r\n"); +} +void cat1_api_add_cat1_vote(void) +{ + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_CAT1); + if (cnt == 0) { + uapi_pm_add_sleep_veto(PM_ID_CAT1); + } else { + // cat1_print_dbg("CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + } + cat1_print_dbg("\r\nCAT1 SERVICE MCU WAKEUP SUCCESS\r\n"); +} + +static uint8_t cat1_voice=0; + +uint8_t cat1_api_get_cat1_volte_voice_state(void) +{ + cat1_print_dbg("cat1_api_get_cat1_volte_voice_state %d \n",cat1_voice); + return cat1_voice; +} + +int32_t cat1_api_start_cat1_volte_voice(void) +{ + cat1_print_dbg("cat1_api_start_cat1_volte_voice\n"); + + int32_t ret = ERRCODE_FAIL; + int32_t argc = 1; + uint8_t *argv = (uint8_t *)"start"; + + if(cat1_voice==0) + { + ret = VoiceCallVolteSample(argc, (const char **)&argv); + if(ret==0) + cat1_voice=1; + } + + + cat1_print_dbg("ret %d %d ",ret, cat1_voice); + + return ret; +} + +int32_t cat1_api_stop_cat1_volte_voice(void) +{ + cat1_print_dbg("cat1_api_stop_cat1_volte_voice\n"); + + int32_t ret = ERRCODE_FAIL; + int32_t argc = 1; + uint8_t *argv = (uint8_t *)"stop"; + + if(cat1_voice!=0) + { + ret = VoiceCallVolteSample(argc, (const char **)&argv); + if(ret==0) + cat1_voice=0; + } + + cat1_print_dbg("ret %d %d ",ret, cat1_voice); + + return ret; + +} + +#include "power_display_service.h" +/*获取屏幕状态: return 1 need update */ +uint8_t cat1_api_need_update_signal(void) +{ + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + screen_state_t state = display_api->get_screen_state(); + // printf("uapi_get_screen_state = %s . \r\n", state==SCREEN_ON?"on":"off"); + if( state == SCREEN_ON){ + return 1; + }else{ + return 0; + } +} +errcode_t cat1_msg_callback(MESSAGE_4G_T msg, void *msg_buf, uint16_t msglen) +{ + + switch(msg) + { + case MESSAGE_4G_POWERON://无参数 + cat1_print_warning("MESSAGE_4G_POWERON pyver(%s) modemver(%s)", + cat1_api_runtime_get_cat1_pyver(), + cat1_api_runtime_get_cat1_modemver() + ); + break; + case MESSAGE_4G_POWEROFF: //无参数 + cat1_print_warning("MESSAGE_4G_POWEROFF"); + break; + case MESSAGE_4G_NETWORK_CONNECTED: //无参数 + cat1_print_warning("MESSAGE_4G_NETWORK_CONNECTED"); + cat1_cmd_send(CMD_4G_GET_TIME,NULL,0); + break; + case MESSAGE_4G_NETWORK_DISCONNECTED: //无参数 + cat1_print_warning("MESSAGE_4G_NETWORK_DISCONNECTED"); + break; + case MESSAGE_4G_NETWORK_STAT_CHANGED: //含signal,sim,运营商, + cat1_print_warning("MESSAGE_4G_NETWORK_STAT_CHANGED netstat(%d),signal(%d),sim(%d),network(%s),imei(%s)", + cat1_api_runtime_get_cat1_networkstat(), + cat1_api_runtime_get_cat1_signal(), + cat1_api_runtime_get_cat1_simstat(), + cat1_api_runtime_get_cat1_networktype()==0?"无网络":(cat1_api_runtime_get_cat1_networktype()==1?"GSM":(cat1_api_runtime_get_cat1_networktype()==2?"3G":"4G/LTE")), + cat1_api_runtime_get_cat1_imei() + ); + break; + case MESSAGE_4G_CALL_COMMING: //带电话号 + cat1_print_warning("MESSAGE_4G_CALL_COMMING %s",msg_buf); + break; + case MESSAGE_4G_CALL_CONNECTED: //带电话号 + cat1_print_warning("MESSAGE_4G_CALL_CONNECTED %s",msg_buf); + break; + case MESSAGE_4G_CALL_DISCONNECTED: //带电话号 + cat1_print_warning("MESSAGE_4G_CALL_DISCONNECTED %s",msg_buf); + break; + case MESSAGE_4G_SMS_RECEIVED: //返回值为字符串 + cat1_print_warning("MESSAGE_4G_SMS_RECEIVED %s",msg_buf); + break; + case MESSAGE_4G_AT_RECEIVED: //返回值为字符串 + cat1_print_warning("MESSAGE_4G_AT_RECEIVED %s",msg_buf); + break; + case MESSAGE_4G_TIME_SYNCED: //无参数 + cat1_print_warning("MESSAGE_4G_TIME_SYNCED"); + break; + case MESSAGE_4G_VERSION_SYNCED: //无参数 + cat1_print_warning("MESSAGE_4G_VERSION_SYNCED"); + break; + default: + + break; + } + return ERRCODE_SUCC; +} + +errcode_t cat1_api_porting_init(void) +{ + + cat1_register_time_ctl_functions(&g_cat1_time_ctl_funcs); + ctl_pin_4g_t pins={ + PIN_NONE, //bat_pin + 1, + S_AGPIO_L23, // pwr_pin + 1, + S_AGPIO_L28,//reset_pin + 0, + S_AGPIO_L31,//ring_pin + 1,//risingEdge + S_AGPIO_L30,//wakemodem_pin + 1, + }; + cat1_register_ctl_pin(pins); + cat1_register_msg_callback(cat1_msg_callback); + + return ERRCODE_SUCC; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/lwip_test.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/lwip_test.h new file mode 100644 index 000000000..33596887e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/lwip_test.h @@ -0,0 +1,80 @@ +/* + * 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 "lwip/arch.h" +#include "lwip/sockets.h" +#include +#include +#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); \ + } + + +#include "debug_print.h" + +#define LogPrintln(fmt, arg...) \ + PRINT("[lwip] %s: " fmt "\n", __FUNCTION__, ##arg) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_TEST_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_001.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_001.c new file mode 100644 index 000000000..a92e9ba27 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_001.c @@ -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; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_002.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_002.c new file mode 100644 index 000000000..139b8ef7e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_002.c @@ -0,0 +1,127 @@ +/* + * 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 +#include + +#define MSG "Hi, I am UDP" +#define TEST_CASE 120 + +static char g_buf[BUF_SIZE + 1] = { 0 }; + +void UdpTestTask(void *p) +{ + (void)p; + 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; +} + +int UdpTest() +{ + int ret = sys_thread_new("udp_test", UdpTestTask, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + return ret; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_003.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_003.c new file mode 100644 index 000000000..d9e896109 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_003.c @@ -0,0 +1,251 @@ +/* + * 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 +#include + +#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 }; + +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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_004.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_004.c new file mode 100644 index 000000000..e1a841013 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_004.c @@ -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; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_005.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_005.c new file mode 100644 index 000000000..c7ec42892 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_005.c @@ -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; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_006.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_006.c new file mode 100644 index 000000000..59a2789be --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_006.c @@ -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; +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_007.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_007.c new file mode 100644 index 000000000..bb4d6c9dc --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_007.c @@ -0,0 +1,108 @@ +/* + * 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 +#include + +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 + +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); +} + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_008.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_008.c new file mode 100644 index 000000000..f46106a87 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_008.c @@ -0,0 +1,185 @@ +/* + * 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 +#include + +#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 }; + +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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_009.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_009.c new file mode 100644 index 000000000..95b678f42 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_009.c @@ -0,0 +1,165 @@ +/* + * 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 +#include + +#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 }; + +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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_010.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_010.c new file mode 100644 index 000000000..354cbbd8f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_010.c @@ -0,0 +1,160 @@ +/* + * 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 +#include + +#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 }; + +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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_011.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_011.c new file mode 100644 index 000000000..c64f9b779 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_011.c @@ -0,0 +1,444 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#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("================================="); + + 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; + + 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; +} + +static void UdpTestNetifTask(void *p) +{ + (void)p; + 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; +} + +int UdpTestNetif() +{ + int ret = sys_thread_new("udp_test_netif", UdpTestNetifTask, NULL, + STACK_TEST_SIZE, TCPIP_THREAD_PRIO); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23); + return ret; +} + +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; + } + + 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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_012.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_012.c new file mode 100644 index 000000000..9967c8b3a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_012.c @@ -0,0 +1,151 @@ +/* + * 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 +#include + +#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 }; + +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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_013.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_013.c new file mode 100644 index 000000000..e1a7623df --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/net_socket_test_013.c @@ -0,0 +1,137 @@ +/* + * 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 +#include + +#define TEST_CASE 230 +#define STACK_PORT_TCP_LONG 2231 +#define TCP_LONG_BUF_SIZE (2 * 1024) + +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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/test_main.c b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/test_main.c new file mode 100644 index 000000000..ad6ee11b0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gTest/net_test/test_main.c @@ -0,0 +1,160 @@ +/* + * 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" +#include "cmsis_os2.h" +#include "lwip_test.h" + +#define LWIP_TEST_TIMEOUT 1000 // timeout 1s +#define LWIP_TEST_COUNT_FLAG 100 + +#define SOCKET_TEST 10 +#define UDP_TEST 20 +#define TCP_TEST 30 +#define OPT_TEST 40 +#define ORDER_TEST 50 +#define INET_TEST 60 +#define UDP_MORE_TEST 70 +#define TCP_MORE_TEST 80 +#define TCP_SELECT_TEST 90 +#define TCP_POLL_TEST 100 +#define NETIF_TEST 110 +#define TCP_DUP_TEST 120 +#define TCP_LONG_TEST 130 + +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(); + + +osTimerId_t g_lwipTestTimerId = NULL; + +// time out 1s +static void LwipTestTimeoutCallback(void const *argument) +{ + + g_lwipTimerCount++; + LogPrintln("LwipTestTimeoutCallback enter %d",g_lwipTimerCount); + if(g_lwipTimerCount > 130) + { + if (g_lwipTestTimerId != NULL) { + osTimerStop(g_lwipTestTimerId); + } + g_lwipTimerCount = 0; + } + 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; + } +} + + +void LwipTestStartTimer(uint32_t timeout) +{ + osStatus_t status; + LogPrintln("LwipTestStartTimer timeout %d",timeout); + + 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); +} diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/CMakeLists.txt new file mode 100644 index 000000000..4d14d6bbd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory_if_exist(cat1Service) diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/CMakeLists.txt new file mode 100644 index 000000000..bed8d8a3e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/CMakeLists.txt @@ -0,0 +1,46 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== + +set(COMPONENT_NAME "cat1Service") + +set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lwip) + +set(PUBLIC_HEADER + ${LWIP_DIR}/port/lwip-2.1/porting/include + ${LWIP_DIR}/src/include +) + +set(PRIVATE_HEADER +) +set(SOURCES +) +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES +SUPPORT_CAT1_SERVICE +) + +set(PRIVATE_DEFINES +) + +if("TEST_4G_SDK" IN_LIST DEFINES) + find_library(LIB_PATH_4GSDK lib/libcat1Service.a ${CMAKE_CURRENT_SOURCE_DIR}) + target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_4GSDK} PRIVATE -Wl,--whole-archive) +endif() + + +build_component() diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_ctl.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_ctl.h new file mode 100644 index 000000000..a37589abd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_ctl.h @@ -0,0 +1,44 @@ + +#ifndef __CAT1_CTL_H +#define __CAT1_CTL_H + + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "stdint.h" +#include "platform_core.h" + + +void cat1_api_gpio_init(void); +void cat1_api_uart_init(void); + +/**set powerpin 1/0*/ +uint32_t cat1_api_cat1_power_on(uint32_t pwron); +/**set resetpin 0/1*/ +uint32_t cat1_api_cat1_reset(uint32_t pwron); + +uint32_t cat1_api_cat1_bat_on(uint32_t pwron); + +/**set powerpin 1 ,set resetpin 0*/ +void power_on_cat1(void); +/**set powerpin 0 ,set resetpin 1*/ +void power_off_cat1(void); + +void cat1_api_wakeup_cat1(uint8_t wakeup); +void cat1_api_keep_wakeup(uint8_t keep_wakeup); + +void cat1_suspend(void); +void cat1_resume(void); + +/** + * @brief cat1唤醒蓝牙中断处理函数,要加入 board_evb.h 或者自己配置到gpio中断中 + * +*/ +void cat1_ring_isr_callback(pin_t pin, uintptr_t param); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_log.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_log.h new file mode 100644 index 000000000..c355e0453 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_log.h @@ -0,0 +1,41 @@ +/** + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. + * + * Description: Board log port. \n + * + * History: \n + * 2023-05-06, Create file. \n + */ +#ifndef CAT1_LOG_PORT_H +#define CAT1_LOG_PORT_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +extern uint8_t g_cat1_enable_debug; +typedef enum{ + CAT1_LOG_LEVEL_ERROR, + CAT1_LOG_LEVEL_WARNING, + CAT1_LOG_LEVEL_INFO, + CAT1_LOG_LEVEL_DBG, + CAT1_LOG_LEVEL_MAX +} CAT1_LOG_LEVEL_E; +/* 通过printf直接打印,不需要日志时需要注释掉define后半部分. */ +#define cat1_print_dbg(fmt, args...) if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_DBG) printf("[CAT1_DBG]" fmt "\n", ##args) +#define cat1_print_info(fmt, args...) if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_INFO) printf("[CAT1_INFO]" fmt "\n", ##args) +#define cat1_print_warning(fmt, args...) if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_WARNING) printf("[CAT1_WRN]" fmt "\n", ##args) +#define cat1_print_err(fmt, args...) if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_ERROR) printf("[CAT1_ERR]" fmt "\n", ##args) + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_porting.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_porting.h new file mode 100644 index 000000000..995b6465c --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_porting.h @@ -0,0 +1,64 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. \n + * + * Description: Button driver header file \n + * Author: @CompanyNameTag \n + * History: \n + * 2023-02-24, Create file. \n + */ +#ifndef CAT1_PORTING_H +#define CAT1_PORTING_H +#include "cat1_types.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/***********用户需要实现的代码***********/ + +/** + * @brief 用户实现,在cat1指令执行完毕后,取消投票 +*/ +void cat1_api_remove_cat1_vote(void); +/** + * @brief 用户实现,在cat1指令执行前,添加投票 +*/ +void cat1_api_add_cat1_vote(void); + +/** + * @brief 用户自行实现,电话开始时切换语音通路 + * @return 0 success +*/ +int32_t cat1_api_start_cat1_volte_voice(void); +/** + * @brief 用户自行实现,电话结束时关闭语音通路 + * @return 0 success +*/ +int32_t cat1_api_stop_cat1_volte_voice(void); + +/** + * @brief 用户自行实现,获取语音通路占用情况 + * @return 1 语音占用 0 语音空闲 +*/ +uint8_t cat1_api_get_cat1_volte_voice_state(void); + + +/** + * @brief 用户实现,根据业务需要,确认是否5秒更新一次信号强度 + * @return 1 需要更新信号 0 停止跟新信号 +*/ +uint8_t cat1_api_need_update_signal(void); + +/*** + * @brief 移植初始化代码,需要用户实现,开机会被 cat1_server_init()执行 + * + * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE . +*/ +errcode_t cat1_api_porting_init(void); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_pub_api.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_pub_api.h new file mode 100644 index 000000000..3686147fa --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_pub_api.h @@ -0,0 +1,103 @@ +#ifndef CAT1_PUB_API_H +#define CAT1_PUB_API_H + +#include "cat1_types.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/***************移植过程中系统需要使用的函数*******************/ + + +/** + * @brief 串口接收函数,加入到uart_porting 中断处理中 +*/ +void cat1_uart_receive_handler(uint8_t *buffer, int32_t size); + +/** + * return cmd uart rx enable flag + * true 代表 接收缓存 + * false 代表 不接收缓存 +*/ +bool cat1_api_custom_is_cmd_rx_enabled(void); + +/** + * @brief cat1 服务初始化. + * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE . +*/ +errcode_t cat1_server_init(void); + +/** + * @brief cat1 开关机设置, 输入 true 开机, false 关机 +*/ +void cat1_api_enable_cat1(bool isopen); + +/** + * @brief 获取cat1是否使能(开机)状态 + * +*/ +bool cat1_api_is_cat1_enabled(void); + + + + +/** + * @brief 发送指令给Cat1,输入 CMD_4G_T , cmd_buf 为指令所需参数. + * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE . +*/ +errcode_t cat1_cmd_send(CMD_4G_T cmd,void *cmd_buf,uint16_t cmdlen); + +/** + * @brief 注册消息回调函数,需要用户自己实现回调函数处理逻辑 + * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE . + * */ +errcode_t cat1_register_msg_callback(f_cat1_msg_callback func); + + +/** + * @brief 注册控制4G的gpio值,包括控制电源以及唤醒中断的IO + * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE . +*/ +errcode_t cat1_register_ctl_pin(ctl_pin_4g_t ctl_pin); + +/** + * @brief 注册消息回调函数,需要用户自己实现回调函数处理逻辑 + * 用来实现sntp的时间同步,包含timezone的存储和utc时间同步 + * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE . + * */ +errcode_t cat1_register_time_ctl_functions(time_ctl_funcs_t *funcs); + + + +/** + * @brief 唤醒Cat1,开放给自定义cat1操作时使用,防止cat1 没有被唤醒,标准指令内部都已经执行了该指令,并且执行完内部指令后,会自动关闭唤醒cat1的io +*/ +void cat1_api_wakeup_cat1(uint8_t wakeup); + +/** + * @brief 保持唤醒Cat1,开放给自定义cat1操作时使用,keep_wakeup=1 可以防止cat1 在执行内部指令后被自动关闭。keep_wakeup = 0后 标准指令执行完毕io会被自动关闭。 +*/ +void cat1_api_keep_wakeup(uint8_t keep_wakeup); + + + +/******************* get Cat1 runtime status **********************/ +uint8_t cat1_api_runtime_get_cat1_powerstat(void); +uint8_t cat1_api_runtime_get_cat1_networkstat(void); +int cat1_api_runtime_get_cat1_signal(void); +int cat1_api_runtime_get_cat1_simstat(void); +uint8_t cat1_api_runtime_get_cat1_networktype(void); +// char* cat1_api_runtime_get_cat1_operator(void); //暂未解析 +char* cat1_api_runtime_get_cat1_imei(void); +char* cat1_api_runtime_get_cat1_pyver(void); +char* cat1_api_runtime_get_cat1_modemver(void); + + +#include "cat1_porting.h" + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_types.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_types.h new file mode 100644 index 000000000..cfa0401fb --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_types.h @@ -0,0 +1,108 @@ +#ifndef CAT1_TYPES_H +#define CAT1_TYPES_H +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +#include +#include +#include +#include "chip_io.h" +#include "errcode.h" +#include "time.h" +#include "sys/time.h" +#include "platform_core.h" + + +typedef enum _4g_message +{ + MESSAGE_4G_POWERON,//无参数 (BOOTUP) + MESSAGE_4G_POWEROFF,//无参数 + MESSAGE_4G_NETWORK_CONNECTED,//无参数 + MESSAGE_4G_NETWORK_DISCONNECTED,//无参数 + MESSAGE_4G_NETWORK_STAT_CHANGED,//含signal,sim,运营商, + MESSAGE_4G_CALL_COMMING,//带电话号 + MESSAGE_4G_CALL_CONNECTED,//带电话号 + MESSAGE_4G_CALL_DISCONNECTED,//带电话号 + MESSAGE_4G_SMS_RECEIVED, //返回值为字符串 + MESSAGE_4G_AT_RECEIVED, //返回值为字符串 + MESSAGE_4G_TIME_SYNCED,//时间同步完成 + MESSAGE_4G_VERSION_SYNCED,//版本同步完成 + MESSAGE_4G_MAX, +} MESSAGE_4G_T; + + +typedef enum _4g_cmd +{ + CMD_4G_POWERON,//无参数 + CMD_4G_POWEROFF,//无参数 + CMD_4G_GET_SIGNAL,//无参数 + CMD_4G_GET_VERSION,//无参数 + CMD_4G_GET_TIME,//无参数 + CMD_4G_MAKE_CALL,//需要输入参数 电话号 + CMD_4G_ANSWER_CALL,//无参数 + CMD_4G_HUNGUP_CALL,//无参数 + CMD_4G_SEND_DTMF, //需要输入参数 DTMF NUM(单个数字) , 包括 0 ~ 9, * , # + CMD_4G_AT, //需要AT指令,要求结尾带\r\n + CMD_4G_MAX, +} CMD_4G_T; + +typedef struct { + uint8_t bat_pin; //控制Cat1 battery 的gpio,没有控制,设置为 PIN_NONE 即可 + uint8_t bat_pin_en_value; + uint8_t pwr_pin; //控制cat1开机键的gpio + uint8_t pwr_pin_en_value; + uint8_t reset_pin; //控制cat1重置键的gpio + uint8_t reset_pin_en_value; + uint8_t ring_pin; //cat1唤醒蓝牙用的gpio + uint8_t ring_pin_en_value; + uint8_t wakemodem_pin; //蓝牙唤醒cat1用的gpio + uint8_t wakemodem_pin_en_value; +} ctl_pin_4g_t; + + +typedef enum{ + CAT1_2G, + CAT1_3G, + CAT1_4G, + CAT1_5G +} cat1_network_type_t; + + + +/** + * @brief Cat1返回的消息处理函数,客户自行定义同类型函数实现对消息的处理. + * 输入 MESSAGE_4G_T + * 输入 msg_buf 为根据MESSAGE类型传入的对应参数 + * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE . +*/ +typedef errcode_t (*f_cat1_msg_callback)(MESSAGE_4G_T msg, void *msg_buf, uint16_t msglen); + + +/** + * @brief 获取系统时区 单位 quarters(15分钟) + * @return 时区 单位quarter(15分钟). +*/ +typedef uint16_t (*f_get_timezone)(void); + +/** + * @brief 设置时区(单位quarter,15分钟) + * @return void. +*/ +typedef void (*f_set_timezone)(uint16_t timezone_quarters); +/** + * @brief 同步时间到系统,输入 utc_timestamp(单位秒) 加 时区(单位quarter,15分钟) + * @return void. + */ +typedef uint32_t (*f_sync_time_utc)(uint32_t timestamp, uint32_t timezone_quarters); + +typedef struct +{ + f_get_timezone get_timezone; + f_set_timezone set_timezone; + f_sync_time_utc sync_time_utc; +} time_ctl_funcs_t; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_utils.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_utils.h new file mode 100644 index 000000000..1d1319f3e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/cat1_utils.h @@ -0,0 +1,40 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. \n + * + * Description: Button driver header file \n + * Author: @CompanyNameTag \n + * History: \n + * 2023-02-24, Create file. \n + */ +#ifndef CAT1_UTILS_H +#define CAT1_UTILS_H +#include "cat1_types.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +#include "cat1_log.h" +#include "hal_gpio.h" +#include "soc_osal.h" +#include "platform_core.h" +#include +#include "thread_init.h" + +#define TASK_PRIORITY_APP (osPriority_t)(17) +#define TASK_PRIORITY_LOG (osPriority_t)(18) +#define TASK_PRIORITY_CMD (osPriority_t)(17) +#define TASK_PRIORITY_BRANDY_APP (osPriority_t)(15) +#define TASK_PRIORITY_SDK (osPriority_t)(31) +#define TASK_PRIORITY_DFX_MSG (osPriority_t)(18) +#define TASK_PRIORITY_TRANSMIT (osPriority_t)(20) + +errcode_t cat1_create_osThread_custom(app_task_definition_t *task_cfg); +errcode_t cat1_terminate_thread(void* thread_id); +errcode_t cat1_suspend_thread(void* thread_id); +errcode_t cat1_resume_thread(void* thread_id); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/custom_http_download.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/custom_http_download.h new file mode 100644 index 000000000..8d4829bd6 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/include/custom_http_download.h @@ -0,0 +1,30 @@ +#ifndef __CUSTOM_HTTP_DOWNLOAD_H_ +#define __CUSTOM_HTTP_DOWNLOAD_H_ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +#include "errcode.h" +#ifdef SUPPORT_CAT1_SERVICE +#include "lwip/apps/http_client.h" +/** + * uint8_t *server, + * uint16_t port, + * uint8_t *uri, + * uint8_t *otadatapath, + * httpc_result_fn callback_result_fn, + * httpc_headers_done_fn callback_headers_done_fn, + * httpc_file_rx_fn callback_file_rx_fn +*/ +errcode_t http_single_download_start( uint8_t *server, uint16_t port,uint8_t *uri, uint8_t *otadatapath, httpc_result_fn callback_result_fn, httpc_headers_done_fn callback_headers_done_fn, httpc_file_rx_fn callback_file_rx_fn); +/** + * stop函数要在result里面执行,表示下载结束 +*/ +errcode_t http_single_download_stop(void); +#endif + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lib/libcat1Service.a b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lib/libcat1Service.a new file mode 100644 index 000000000..3ddc5282d Binary files /dev/null and b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lib/libcat1Service.a differ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/cc.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/cc.h new file mode 100644 index 000000000..289f750bc --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/cc.h @@ -0,0 +1,113 @@ +/* + * 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_ + +#ifdef LITTLE_ENDIAN +#undef LITTLE_ENDIAN +#endif + +#ifdef BIG_ENDIAN +#undef BIG_ENDIAN +#endif + +#include +#include +#include +#include "securec.h" + +#ifdef htons +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS +#endif + +// #define SOCKLEN_T_DEFINED +// #define SA_FAMILY_T_DEFINED +// #define IN_PORT_T_DEFINED + +#define LWIP_TIMEVAL_PRIVATE 1 +#define LWIP_ERRNO_STDINCLUDE +#define LWIP_SOCKET_STDINCLUDE + +#define LWIP_DNS_API_DEFINE_ERRORS 0 +#define LWIP_DNS_API_DEFINE_FLAGS 0 +#define LWIP_DNS_API_DECLARE_STRUCTS 0 +#define LWIP_DNS_API_DECLARE_H_ERRNO 0 + +#ifndef __SIZEOF_POINTER__ +#define __SIZEOF_POINTER__ 4 // 32 bit system +#endif + +// #define LOS_TASK_STATUS_DETACHED 0x0100 // reserved + +#if defined(__arm__) && defined(__ARMCC_VERSION) + /* Keil uVision4 tools */ + #define PACK_STRUCT_BEGIN __packed + #define PACK_STRUCT_STRUCT + #define PACK_STRUCT_END + #define PACK_STRUCT_FIELD(fld) fld + #define ALIGNED(n) __align(n) +#elif defined (__IAR_SYSTEMS_ICC__) + /* IAR Embedded Workbench tools */ + #define PACK_STRUCT_BEGIN __packed + #define PACK_STRUCT_STRUCT + #define PACK_STRUCT_END + #define PACK_STRUCT_FIELD(fld) fld + // #error NEEDS ALIGNED +#else + /* GCC tools (CodeSourcery) */ + #define PACK_STRUCT_BEGIN + #define PACK_STRUCT_STRUCT __attribute__ ((__packed__)) + #define PACK_STRUCT_END + #define PACK_STRUCT_FIELD(fld) fld + #define ALIGNED(n) __attribute__((aligned (n))) +#endif + +#define LWIP_RAND rand + +#ifndef LWIP_LOGGER +#define LWIP_LOGGER(msg) printf(msg) +#endif + +extern void LwipLogPrintf(const char *fmt, ...); +#define LWIP_PLATFORM_DIAG(vars) LwipLogPrintf vars +#define LWIP_PLATFORM_ASSERT(x) do { \ + LWIP_PLATFORM_DIAG(("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__)); \ + } while (0) + +// #define init_waitqueue_head(...) +// #define poll_check_waiters(...) + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE 1 +#endif + +#endif /* _LWIP_PORTING_CC_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/perf.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/perf.h new file mode 100644 index 000000000..43147ef77 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/perf.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_PERF_H_ +#define _LWIP_PORTING_PERF_H_ + +#if LWIP_PERF + +#define PERF_START do { /* something to do */ } while (0) +#define PERF_STOP(x) do { /* something to do */ } while (0) + +#endif + +#endif /* _LWIP_PORTING_PERF_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/sys_arch.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/sys_arch.h new file mode 100644 index 000000000..3541e9072 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/arch/sys_arch.h @@ -0,0 +1,70 @@ +/* + * 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 + +#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_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h new file mode 100644 index 000000000..31e01f698 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/api_shell.h @@ -0,0 +1,56 @@ +/* + * 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_API_SHELL_H +#define LWIP_API_SHELL_H + +#include "arch/cc.h" +#include "lwip/opt.h" + +#if defined (__cplusplus) && __cplusplus +extern "C" { +#endif + +u32_t lwip_ifconfig(int argc, const char **argv); +u32_t OsShellPing(int argc, const char *argv); + +void get_ping_hostname(char *databuf,uint8_t len); +void get_ping_result(char *databuf,uint16_t len); + +#ifndef LWIP_TESTBED +static +#endif +int OsPingFunc(u32_t *parg); + +#if defined (__cplusplus) && __cplusplus +} +#endif +#endif /* LWIP_HDR_API_SHELL_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/dhcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/dhcp.h new file mode 100644 index 000000000..70f9b9bf9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/dhcp.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021-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_DHCP_H_ +#define _LWIP_PORTING_DHCP_H_ + +#include_next + +err_t dhcp_is_bound(struct netif *netif); + +#endif /* _LWIP_PORTING_DHCP_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/inet.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/inet.h new file mode 100644 index 000000000..5f1dacc73 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/inet.h @@ -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. + */ + +#ifndef _LWIP_PORTING_INET_H_ +#define _LWIP_PORTING_INET_H_ + +#include +#include +#include_next + +#if LWIP_IPV4 +#define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) \ + ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) +#define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) \ + (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) + +/* directly map this to the lwip internal functions */ +#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen) +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 +#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) \ + {(target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \ + (target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \ + (target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \ + (target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3];} +#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) \ + {(target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \ + (target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \ + (target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \ + (target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3]; \ + ip6_addr_clear_zone(target_ip6addr);} +#endif /* LWIP_IPV6 */ + +#endif /* _LWIP_PORTING_INET_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h new file mode 100644 index 000000000..6589e428e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_LWIPOPTS_H_ +#define _LWIP_PORTING_LWIPOPTS_H_ + +// lwIP debug options, comment the ones you don't want +#define LWIP_DEBUG 1 +#if LWIP_DEBUG +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define DRIVERIF_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_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_ON +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#define DRV_STS_DEBUG LWIP_DBG_OFF +#define HTTPC_DEBUG LWIP_DBG_ON + +#define ALTCP_MBEDTLS_MEM_DEBUG LWIP_DBG_ON +#define ALTCP_MBEDTLS_DEBUG LWIP_DBG_ON +#define ALTCP_MBEDTLS_LIB_DEBUG LWIP_DBG_ON +#endif + + + +// Options only in new opt.h +#define LWIP_SOCKET_SELECT 0 +#define LWIP_SOCKET_POLL 1 + + +// Options for old lwipopts.h +#define MEM_SIZE (4*1024*1024) // (512*1024) +#define IP_FRAG_MAX_MTU 1500 +#define LWIP_CONFIG_NUM_SOCKETS 128 +#define IP_REASS_MAX_MEM_SIZE (MEM_SIZE / 4) + +// 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 1 //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 +#if LWIP_IPV6 +#define DNS_SERVER_ADDRESS(ipaddr) ip_addr_set_ip4_u32(ipaddr,ipaddr_addr("8.8.8.8")) +#define DNS_SERVER_ADDRESS_SECONDARY(ipaddr) ip_addr_set_ip4_u32(ipaddr,ipaddr_addr("114.114.114.114")) +#else +#define DNS_SERVER_ADDRESS(ipaddr) ip4_addr_set_u32(ipaddr,ipaddr_addr("8.8.8.8")) +#define DNS_SERVER_ADDRESS_SECONDARY(ipaddr) ip4_addr_set_u32(ipaddr,ipaddr_addr("114.114.114.114")) +#endif + +#define LWIP_ETHERNET 1 +#define LWIP_HAVE_LOOPIF 1 +#define LWIP_IGMP 1 +#define LWIP_NETIF_API 1 +#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_LOOPBACK 1 +#define LWIP_POSIX_SOCKETS_IO_NAMES 0 +#define LWIP_RAW 1 +#define LWIP_SO_RCVBUF 1 +#define LWIP_SO_RCVTIMEO 1 +#define LWIP_SO_SNDTIMEO 1 +#define LWIP_STATS_DISPLAY 1 +#define MEM_LIBC_MALLOC 1 +#define MEMP_NUM_ARP_QUEUE (65535 * LWIP_CONFIG_NUM_SOCKETS / (IP_FRAG_MAX_MTU - 20 - 8)) +#define MEMP_NUM_NETBUF (65535 * 3 * LWIP_CONFIG_NUM_SOCKETS / (IP_FRAG_MAX_MTU - 20 - 8)) +#define MEMP_NUM_NETCONN LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_PBUF LWIP_CONFIG_NUM_SOCKETS*2 +#define MEMP_NUM_RAW_PCB LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_REASSDATA (IP_REASS_MAX_MEM_SIZE / 65535) +#define MEMP_NUM_TCPIP_MSG_API 64 +#define MEMP_NUM_TCPIP_MSG_INPKT 512 +#define MEMP_NUM_TCP_PCB LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_TCP_PCB_LISTEN LWIP_CONFIG_NUM_SOCKETS +#define MEMP_NUM_UDP_PCB LWIP_CONFIG_NUM_SOCKETS +#define PBUF_POOL_BUFSIZE 1550 +#define PBUF_POOL_SIZE 64 +#define SO_REUSE 1 +#define TCPIP_MBOX_SIZE 512 +#define TCPIP_THREAD_PRIO 16 //osPriorityBelowNormal 16 +#define TCPIP_THREAD_STACKSIZE 0x6000 +#define TCP_MAXRTX 64 +// #define TCP_MSS 1400 +#define TCP_MSS (IP_FRAG_MAX_MTU - 20 - 20) +#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 +#define MEMP_NUM_TCP_SEG (((TCP_SND_BUF * 3 / 2) + TCP_WND) * LWIP_CONFIG_NUM_SOCKETS / TCP_MSS) + +// 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 + +#define LWIP_ALTCP 1 +#define LWIP_ALTCP_TLS 1 +#define LWIP_ALTCP_TLS_MBEDTLS 1 + + +#if defined LWIP_STATS_DISPLAY && !LWIP_STATS +#undef LWIP_STATS_DISPLAY +#define LWIP_STATS_DISPLAY 0 +#endif + +// Change some options for lwIP 2.1.2 +#undef TCP_MAXRTX +#define TCP_MAXRTX 12 + +#undef LWIP_COMPAT_SOCKETS +#define LWIP_COMPAT_SOCKETS 0 + +#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + (LWIP_IPV6 * LWIP_IPV6_DHCP6)) + +#undef DEFAULT_ACCEPTMBOX_SIZE +#define DEFAULT_ACCEPTMBOX_SIZE LWIP_CONFIG_NUM_SOCKETS + +// #undef TCP_MSS +// #define TCP_MSS (IP_FRAG_MAX_MTU - 20 - 20) + +#undef IP_SOF_BROADCAST_RECV +#define IP_SOF_BROADCAST_RECV 0 + +/** + * Defines whether to enable debugging for driver module. + */ +#ifndef DRIVERIF_DEBUG +#define DRIVERIF_DEBUG LWIP_DBG_OFF +#endif + + + +// Options for 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 liteos_m +#undef LWIP_NETIF_PROMISC +#define LWIP_NETIF_PROMISC 0 + +#define MEMP_MEM_MALLOC 1 + +// #undef LWIP_IPV6 +// #define LWIP_IPV6 0 + +#undef LWIP_SOCKET_SELECT +#define LWIP_SOCKET_SELECT 1 + + +/* MIB2 stats are required to check IPv4 reassembly results */ +#define MIB2_STATS 1 +#define SLIP_RX_FROM_ISR 1 + +// use PBUF_RAM instead of PBUF_POOL in udp_input +#define USE_PBUF_RAM_UDP_INPUT 1 + +#ifdef LOSCFG_FS_VFS +#include "vfs_config.h" +#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS +#endif + +#define LWIP_SOCKET_IOCTL 0 +#define LWIP_SOCKET_FCNTL 0 + +#define LWIP_HTTPC_HAVE_FILE_IO 1 +#define HTTPC_DEBUG_REQUEST 1 + +#if 1 +#define LWIP_DHCP_MAX_NTP_SERVERS 1 +#define SNTP_SERVER_DNS 1 +#if SNTP_SERVER_DNS +#define SNTP_SERVER_ADDRESS "pool.ntp.org" //"pool.ntp.org" +#endif +#else +#define LWIP_DHCP_MAX_NTP_SERVERS 3 +#define SNTP_SERVER_DNS 1 +#if SNTP_SERVER_DNS +#define SNTP_SERVER_ADDRESS "cn.pool.ntp.org" //"pool.ntp.org" +#define SNTP_SERVER_ADDRESS2 "ntp1.aliyun.com" //"pool.ntp.org" +#define SNTP_SERVER_ADDRESS3 "pool.ntp.org" //"pool.ntp.org" +#endif +#endif + + +#define SNTP_CHECK_RESPONSE 2 + +#define SNTP_SET_SYSTEM_TIME(sec) cat1_sntp_set_time_utc(sec) + +#endif /* _LWIP_PORTING_LWIPOPTS_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netdb.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netdb.h new file mode 100644 index 000000000..0533eb329 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netdb.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_NETDB_H_ +#define _LWIP_PORTING_NETDB_H_ + +#include "lwip/arch.h" +#include +#include_next + +#endif /* _LWIP_PORTING_NETDB_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netif.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netif.h new file mode 100644 index 000000000..04aff212f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netif.h @@ -0,0 +1,82 @@ +/* + * 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_ + +#include "lwip/arch.h" +#include +#include + +#define netif_find netifapi_netif_find_by_name + +#if LWIP_DHCPS +#define LWIP_NETIF_CLIENT_DATA_INDEX_DHCP LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, \ + LWIP_NETIF_CLIENT_DATA_INDEX_DHCPS +#endif + +#define linkoutput linkoutput; \ + void (*drv_send)(struct netif *netif, struct pbuf *p); \ + u8_t (*drv_set_hwaddr)(struct netif *netif, u8_t *addr, u8_t len); \ + void (*drv_config)(struct netif *netif, u32_t config_flags, u8_t setBit); \ + char full_name[IFNAMSIZ]; \ + u16_t link_layer_type +#include_next +#undef linkoutput +#if LWIP_DHCPS +#undef LWIP_NETIF_CLIENT_DATA_INDEX_DHCP +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// redefine NETIF_NAMESIZE which was defined in netif.h +#undef NETIF_NAMESIZE +#define NETIF_NAMESIZE IFNAMSIZ + +#define LOOPBACK_IF 0 +#define ETHERNET_DRIVER_IF 1 +#define WIFI_DRIVER_IF 801 +#define BT_PROXY_IF 802 + +err_t driverif_init(struct netif *netif); +void driverif_input(struct netif *netif, struct pbuf *p); + +#define netif_get_name(netif) ((netif)->full_name) + +#ifdef __cplusplus +} +#endif + +#endif /* _LWIP_PORTING_NETIF_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netifapi.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netifapi.h new file mode 100644 index 000000000..44858b7c0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/netifapi.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LWIP_PORTING_NETIFAPI_H_ +#define _LWIP_PORTING_NETIFAPI_H_ + +#include_next + +#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_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/sockets.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/sockets.h new file mode 100644 index 000000000..adf0985f6 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/sockets.h @@ -0,0 +1,83 @@ +/* + * 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_SOCKETS_H_ +#define _LWIP_PORTING_SOCKETS_H_ + +#include "lwip/arch.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include_next + +#ifdef __cplusplus +extern "C" { +#endif + +#if FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) +#error "external FD_SETSIZE too small for number of sockets" +#else +#define LWIP_SELECT_MAXNFDS FD_SETSIZE +#endif + +#if IOV_MAX > 0xFFFF +#error "IOV_MAX larger than supported by LwIP" +#endif + +#if LWIP_UDP && LWIP_UDPLITE +#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ +#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ +#endif + +// For BSD 4.4 socket sa_len compatibility +#define DF_NADDR(addr) ip_addr_t naddr = (addr) +#define SA_LEN(addr, _) (IP_IS_V4_VAL(addr) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) +#define sa_len sa_data[0] * 0 + SA_LEN(naddr, _) +#define sin_len sin_zero[0] +#define sin6_len sin6_addr.s6_addr[0] + +// for sockets.c, TCP_KEEPALIVE is not supported currently +#define TCP_KEEPALIVE 0xFF +#define SIN_ZERO_LEN 8 + +int closesocket(int sockfd); +int ioctlsocket(int s, long cmd, void *argp); + +#ifdef __cplusplus +} +#endif + +#endif /* _LWIP_PORTING_SOCKETS_H_ */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwipopts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwipopts.h new file mode 100644 index 000000000..4f1ab7216 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/port/lwip-2.1/porting/include/lwipopts.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LITEOS_M_LWIPOPTS_H__ +#define __LITEOS_M_LWIPOPTS_H__ + +// Just redirect +#include "lwip/lwipopts.h" + +#endif // __LITEOS_M_LWIPOPTS_H__ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/arpa/inet.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/arpa/inet.h new file mode 100644 index 000000000..0ed9baf3d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/arpa/inet.h @@ -0,0 +1,33 @@ +/** + * @file + * This file is a posix wrapper for lwip/sockets.h. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "lwip/sockets.h" diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/net/if.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/net/if.h new file mode 100644 index 000000000..6b8e63a52 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/net/if.h @@ -0,0 +1,36 @@ +/** + * @file + * This file is a posix wrapper for lwip/if_api.h. + */ + +/* + * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "lwip/if_api.h" diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/netdb.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/netdb.h new file mode 100644 index 000000000..12d4c7f56 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/netdb.h @@ -0,0 +1,33 @@ +/** + * @file + * This file is a posix wrapper for lwip/netdb.h. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "lwip/netdb.h" diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/sys/socket.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/sys/socket.h new file mode 100644 index 000000000..0ed9baf3d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/posix/sys/socket.h @@ -0,0 +1,33 @@ +/** + * @file + * This file is a posix wrapper for lwip/sockets.h. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "lwip/sockets.h" diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/stdc/errno.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/stdc/errno.h new file mode 100644 index 000000000..98a9aec99 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/compat/stdc/errno.h @@ -0,0 +1,33 @@ +/** + * @file + * This file is a posix/stdc wrapper for lwip/errno.h. + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "lwip/errno.h" diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp.h new file mode 100644 index 000000000..1b245449e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp.h @@ -0,0 +1,206 @@ +/** + * @file + * Application layered TCP connection API (to be used from TCPIP thread)\n + * + * This file contains the generic API. + * For more details see @ref altcp_api. + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_ALTCP_H +#define LWIP_HDR_ALTCP_H + +#include "lwip/opt.h" + +#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/tcpbase.h" +#include "lwip/err.h" +#include "lwip/pbuf.h" +#include "lwip/ip_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct altcp_pcb; +struct altcp_functions; + +typedef err_t (*altcp_accept_fn)(void *arg, struct altcp_pcb *new_conn, err_t err); +typedef err_t (*altcp_connected_fn)(void *arg, struct altcp_pcb *conn, err_t err); +typedef err_t (*altcp_recv_fn)(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err); +typedef err_t (*altcp_sent_fn)(void *arg, struct altcp_pcb *conn, u16_t len); +typedef err_t (*altcp_poll_fn)(void *arg, struct altcp_pcb *conn); +typedef void (*altcp_err_fn)(void *arg, err_t err); + +typedef struct altcp_pcb* (*altcp_new_fn)(void *arg, u8_t ip_type); + +struct altcp_pcb { + const struct altcp_functions *fns; + struct altcp_pcb *inner_conn; + void *arg; + void *state; + /* application callbacks */ + altcp_accept_fn accept; + altcp_connected_fn connected; + altcp_recv_fn recv; + altcp_sent_fn sent; + altcp_poll_fn poll; + altcp_err_fn err; + u8_t pollinterval; +}; + +/** @ingroup altcp */ +typedef struct altcp_allocator_s { + /** Allocator function */ + altcp_new_fn alloc; + /** Argument to allocator function */ + void *arg; +} altcp_allocator_t; + +struct altcp_pcb *altcp_new(altcp_allocator_t *allocator); +struct altcp_pcb *altcp_new_ip6(altcp_allocator_t *allocator); +struct altcp_pcb *altcp_new_ip_type(altcp_allocator_t *allocator, u8_t ip_type); + +void altcp_arg(struct altcp_pcb *conn, void *arg); +void altcp_accept(struct altcp_pcb *conn, altcp_accept_fn accept); +void altcp_recv(struct altcp_pcb *conn, altcp_recv_fn recv); +void altcp_sent(struct altcp_pcb *conn, altcp_sent_fn sent); +void altcp_poll(struct altcp_pcb *conn, altcp_poll_fn poll, u8_t interval); +void altcp_err(struct altcp_pcb *conn, altcp_err_fn err); + +void altcp_recved(struct altcp_pcb *conn, u16_t len); +err_t altcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port); +err_t altcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected); + +/* return conn for source code compatibility to tcp callback API only */ +struct altcp_pcb *altcp_listen_with_backlog_and_err(struct altcp_pcb *conn, u8_t backlog, err_t *err); +#define altcp_listen_with_backlog(conn, backlog) altcp_listen_with_backlog_and_err(conn, backlog, NULL) +/** @ingroup altcp */ +#define altcp_listen(conn) altcp_listen_with_backlog_and_err(conn, TCP_DEFAULT_LISTEN_BACKLOG, NULL) + +void altcp_abort(struct altcp_pcb *conn); +err_t altcp_close(struct altcp_pcb *conn); +err_t altcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx); + +err_t altcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags); +err_t altcp_output(struct altcp_pcb *conn); + +u16_t altcp_mss(struct altcp_pcb *conn); +u16_t altcp_sndbuf(struct altcp_pcb *conn); +u16_t altcp_sndqueuelen(struct altcp_pcb *conn); +void altcp_nagle_disable(struct altcp_pcb *conn); +void altcp_nagle_enable(struct altcp_pcb *conn); +int altcp_nagle_disabled(struct altcp_pcb *conn); + +void altcp_setprio(struct altcp_pcb *conn, u8_t prio); + +err_t altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port); +ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local); +u16_t altcp_get_port(struct altcp_pcb *conn, int local); + +#if LWIP_TCP_KEEPALIVE +void altcp_keepalive_disable(struct altcp_pcb *conn); +void altcp_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count); +#endif + +#ifdef LWIP_DEBUG +enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn); +#endif + +#ifdef __cplusplus +} +#endif + +#else /* LWIP_ALTCP */ + +/* ALTCP disabled, define everything to link against tcp callback API (e.g. to get a small non-ssl httpd) */ + +#include "lwip/tcp.h" + +#define altcp_accept_fn tcp_accept_fn +#define altcp_connected_fn tcp_connected_fn +#define altcp_recv_fn tcp_recv_fn +#define altcp_sent_fn tcp_sent_fn +#define altcp_poll_fn tcp_poll_fn +#define altcp_err_fn tcp_err_fn + +#define altcp_pcb tcp_pcb +#define altcp_tcp_new_ip_type tcp_new_ip_type +#define altcp_tcp_new tcp_new +#define altcp_tcp_new_ip6 tcp_new_ip6 + +#define altcp_new(allocator) tcp_new() +#define altcp_new_ip6(allocator) tcp_new_ip6() +#define altcp_new_ip_type(allocator, ip_type) tcp_new_ip_type(ip_type) + +#define altcp_arg tcp_arg +#define altcp_accept tcp_accept +#define altcp_recv tcp_recv +#define altcp_sent tcp_sent +#define altcp_poll tcp_poll +#define altcp_err tcp_err + +#define altcp_recved tcp_recved +#define altcp_bind tcp_bind +#define altcp_connect tcp_connect + +#define altcp_listen_with_backlog_and_err tcp_listen_with_backlog_and_err +#define altcp_listen_with_backlog tcp_listen_with_backlog +#define altcp_listen tcp_listen + +#define altcp_abort tcp_abort +#define altcp_close tcp_close +#define altcp_shutdown tcp_shutdown + +#define altcp_write tcp_write +#define altcp_output tcp_output + +#define altcp_mss tcp_mss +#define altcp_sndbuf tcp_sndbuf +#define altcp_sndqueuelen tcp_sndqueuelen +#define altcp_nagle_disable tcp_nagle_disable +#define altcp_nagle_enable tcp_nagle_enable +#define altcp_nagle_disabled tcp_nagle_disabled +#define altcp_setprio tcp_setprio + +#define altcp_get_tcp_addrinfo tcp_get_tcp_addrinfo +#define altcp_get_ip(pcb, local) ((local) ? (&(pcb)->local_ip) : (&(pcb)->remote_ip)) + +#ifdef LWIP_DEBUG +#define altcp_dbg_get_tcp_state tcp_dbg_get_tcp_state +#endif + +#endif /* LWIP_ALTCP */ + +#endif /* LWIP_HDR_ALTCP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp_tcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp_tcp.h new file mode 100644 index 000000000..dbde58468 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp_tcp.h @@ -0,0 +1,72 @@ +/** + * @file + * Application layered TCP connection API (to be used from TCPIP thread)\n + * This interface mimics the tcp callback API to the application while preventing + * direct linking (much like virtual functions). + * This way, an application can make use of other application layer protocols + * on top of TCP without knowing the details (e.g. TLS, proxy connection). + * + * This file contains the base implementation calling into tcp. + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_ALTCP_TCP_H +#define LWIP_HDR_ALTCP_TCP_H + +#include "lwip/opt.h" + +#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/altcp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct altcp_pcb *altcp_tcp_new_ip_type(u8_t ip_type); + +#define altcp_tcp_new() altcp_tcp_new_ip_type(IPADDR_TYPE_V4) +#define altcp_tcp_new_ip6() altcp_tcp_new_ip_type(IPADDR_TYPE_V6) + +struct altcp_pcb *altcp_tcp_alloc(void *arg, u8_t ip_type); + +struct tcp_pcb; +struct altcp_pcb *altcp_tcp_wrap(struct tcp_pcb *tpcb); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_ALTCP */ + +#endif /* LWIP_HDR_ALTCP_TCP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp_tls.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp_tls.h new file mode 100644 index 000000000..ff797f27f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/altcp_tls.h @@ -0,0 +1,143 @@ +/** + * @file + * Application layered TCP/TLS connection API (to be used from TCPIP thread) + * + * @defgroup altcp_tls TLS layer + * @ingroup altcp + * This file contains function prototypes for a TLS layer. + * A port to ARM mbedtls is provided in the apps/ tree + * (LWIP_ALTCP_TLS_MBEDTLS option). + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_ALTCP_TLS_H +#define LWIP_HDR_ALTCP_TLS_H + +#include "lwip/opt.h" + +#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ + +#if LWIP_ALTCP_TLS + +#include "lwip/altcp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup altcp_tls + * ALTCP_TLS configuration handle, content depends on port (e.g. mbedtls) + */ +struct altcp_tls_config; + +/** @ingroup altcp_tls + * Create an ALTCP_TLS server configuration handle prepared for multiple certificates + */ +struct altcp_tls_config *altcp_tls_create_config_server(uint8_t cert_count); + +/** @ingroup altcp_tls + * Add a certificate to an ALTCP_TLS server configuration handle + */ +err_t altcp_tls_config_server_add_privkey_cert(struct altcp_tls_config *config, + const u8_t *privkey, size_t privkey_len, + const u8_t *privkey_pass, size_t privkey_pass_len, + const u8_t *cert, size_t cert_len); + +/** @ingroup altcp_tls + * Create an ALTCP_TLS server configuration handle with one certificate + * (short version of calling @ref altcp_tls_create_config_server and + * @ref altcp_tls_config_server_add_privkey_cert) + */ +struct altcp_tls_config *altcp_tls_create_config_server_privkey_cert(const u8_t *privkey, size_t privkey_len, + const u8_t *privkey_pass, size_t privkey_pass_len, + const u8_t *cert, size_t cert_len); + +/** @ingroup altcp_tls + * Create an ALTCP_TLS client configuration handle + */ +struct altcp_tls_config *altcp_tls_create_config_client(const u8_t *cert, size_t cert_len); + +/** @ingroup altcp_tls + * Create an ALTCP_TLS client configuration handle with two-way server/client authentication + */ +struct altcp_tls_config *altcp_tls_create_config_client_2wayauth(const u8_t *ca, size_t ca_len, const u8_t *privkey, size_t privkey_len, + const u8_t *privkey_pass, size_t privkey_pass_len, + const u8_t *cert, size_t cert_len); + +/** @ingroup altcp_tls + * Free an ALTCP_TLS configuration handle + */ +void altcp_tls_free_config(struct altcp_tls_config *conf); + +/** @ingroup altcp_tls + * Free an ALTCP_TLS global entropy instance. + * All ALTCP_TLS configuration are linked to one altcp_tls_entropy_rng structure + * that handle an unique system entropy & ctr_drbg instance. + * This function allow application to free this altcp_tls_entropy_rng structure + * when all configuration referencing it were destroyed. + * This function does nothing if some ALTCP_TLS configuration handle are still + * active. + */ +void altcp_tls_free_entropy(void); + +/** @ingroup altcp_tls + * Create new ALTCP_TLS layer wrapping an existing pcb as inner connection (e.g. TLS over TCP) + */ +struct altcp_pcb *altcp_tls_wrap(struct altcp_tls_config *config, struct altcp_pcb *inner_pcb); + +/** @ingroup altcp_tls + * Create new ALTCP_TLS pcb and its inner tcp pcb + */ +struct altcp_pcb *altcp_tls_new(struct altcp_tls_config *config, u8_t ip_type); + +/** @ingroup altcp_tls + * Create new ALTCP_TLS layer pcb and its inner tcp pcb. + * Same as @ref altcp_tls_new but this allocator function fits to + * @ref altcp_allocator_t / @ref altcp_new.\n + 'arg' must contain a struct altcp_tls_config *. + */ +struct altcp_pcb *altcp_tls_alloc(void *arg, u8_t ip_type); + +/** @ingroup altcp_tls + * Return pointer to internal TLS context so application can tweak it. + * Real type depends on port (e.g. mbedtls) + */ +void *altcp_tls_context(struct altcp_pcb *conn); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_ALTCP_TLS */ +#endif /* LWIP_ALTCP */ +#endif /* LWIP_HDR_ALTCP_TLS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/api.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/api.h new file mode 100644 index 000000000..c2afaf26d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/api.h @@ -0,0 +1,431 @@ +/** + * @file + * netconn API (to be used from non-TCPIP threads) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_API_H +#define LWIP_HDR_API_H + +#include "lwip/opt.h" + +#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ +/* Note: Netconn API is always available when sockets are enabled - + * sockets are implemented on top of them */ + +#include "lwip/arch.h" +#include "lwip/netbuf.h" +#include "lwip/sys.h" +#include "lwip/ip_addr.h" +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Throughout this file, IP addresses and port numbers are expected to be in + * the same byte order as in the corresponding pcb. + */ + +/* Flags for netconn_write (u8_t) */ +#define NETCONN_NOFLAG 0x00 +#define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */ +#define NETCONN_COPY 0x01 +#define NETCONN_MORE 0x02 +#define NETCONN_DONTBLOCK 0x04 +#define NETCONN_NOAUTORCVD 0x08 /* prevent netconn_recv_data_tcp() from updating the tcp window - must be done manually via netconn_tcp_recvd() */ +#define NETCONN_NOFIN 0x10 /* upper layer already received data, leave FIN in queue until called again */ + +/* Flags for struct netconn.flags (u8_t) */ +/** This netconn had an error, don't block on recvmbox/acceptmbox any more */ +#define NETCONN_FLAG_MBOXCLOSED 0x01 +/** Should this netconn avoid blocking? */ +#define NETCONN_FLAG_NON_BLOCKING 0x02 +/** Was the last connect action a non-blocking one? */ +#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04 +#if LWIP_NETCONN_FULLDUPLEX + /** The mbox of this netconn is being deallocated, don't use it anymore */ +#define NETCONN_FLAG_MBOXINVALID 0x08 +#endif /* LWIP_NETCONN_FULLDUPLEX */ +/** If a nonblocking write has been rejected before, poll_tcp needs to + check if the netconn is writable again */ +#define NETCONN_FLAG_CHECK_WRITESPACE 0x10 +#if LWIP_IPV6 +/** If this flag is set then only IPv6 communication is allowed on the + netconn. As per RFC#3493 this features defaults to OFF allowing + dual-stack usage by default. */ +#define NETCONN_FLAG_IPV6_V6ONLY 0x20 +#endif /* LWIP_IPV6 */ +#if LWIP_NETBUF_RECVINFO +/** Received packet info will be recorded for this netconn */ +#define NETCONN_FLAG_PKTINFO 0x40 +#endif /* LWIP_NETBUF_RECVINFO */ +/** A FIN has been received but not passed to the application yet */ +#define NETCONN_FIN_RX_PENDING 0x80 + +/* Helpers to process several netconn_types by the same code */ +#define NETCONNTYPE_GROUP(t) ((t)&0xF0) +#define NETCONNTYPE_DATAGRAM(t) ((t)&0xE0) +#if LWIP_IPV6 +#define NETCONN_TYPE_IPV6 0x08 +#define NETCONNTYPE_ISIPV6(t) (((t)&NETCONN_TYPE_IPV6) != 0) +#define NETCONNTYPE_ISUDPLITE(t) (((t)&0xF3) == NETCONN_UDPLITE) +#define NETCONNTYPE_ISUDPNOCHKSUM(t) (((t)&0xF3) == NETCONN_UDPNOCHKSUM) +#else /* LWIP_IPV6 */ +#define NETCONNTYPE_ISIPV6(t) (0) +#define NETCONNTYPE_ISUDPLITE(t) ((t) == NETCONN_UDPLITE) +#define NETCONNTYPE_ISUDPNOCHKSUM(t) ((t) == NETCONN_UDPNOCHKSUM) +#endif /* LWIP_IPV6 */ + +/** @ingroup netconn_common + * Protocol family and type of the netconn + */ +enum netconn_type { + NETCONN_INVALID = 0, + /** TCP IPv4 */ + NETCONN_TCP = 0x10, +#if LWIP_IPV6 + /** TCP IPv6 */ + NETCONN_TCP_IPV6 = NETCONN_TCP | NETCONN_TYPE_IPV6 /* 0x18 */, +#endif /* LWIP_IPV6 */ + /** UDP IPv4 */ + NETCONN_UDP = 0x20, + /** UDP IPv4 lite */ + NETCONN_UDPLITE = 0x21, + /** UDP IPv4 no checksum */ + NETCONN_UDPNOCHKSUM = 0x22, + +#if LWIP_IPV6 + /** UDP IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ + NETCONN_UDP_IPV6 = NETCONN_UDP | NETCONN_TYPE_IPV6 /* 0x28 */, + /** UDP IPv6 lite (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ + NETCONN_UDPLITE_IPV6 = NETCONN_UDPLITE | NETCONN_TYPE_IPV6 /* 0x29 */, + /** UDP IPv6 no checksum (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ + NETCONN_UDPNOCHKSUM_IPV6 = NETCONN_UDPNOCHKSUM | NETCONN_TYPE_IPV6 /* 0x2a */, +#endif /* LWIP_IPV6 */ + + /** Raw connection IPv4 */ + NETCONN_RAW = 0x40 +#if LWIP_IPV6 + /** Raw connection IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ + , NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6 /* 0x48 */ +#endif /* LWIP_IPV6 */ +}; + +/** Current state of the netconn. Non-TCP netconns are always + * in state NETCONN_NONE! */ +enum netconn_state { + NETCONN_NONE, + NETCONN_WRITE, + NETCONN_LISTEN, + NETCONN_CONNECT, + NETCONN_CLOSE +}; + +/** Used to inform the callback function about changes + * + * Event explanation: + * + * In the netconn implementation, there are three ways to block a client: + * + * - accept mbox (sys_arch_mbox_fetch(&conn->acceptmbox, &accept_ptr, 0); in netconn_accept()) + * - receive mbox (sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0); in netconn_recv_data()) + * - send queue is full (sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0); in lwip_netconn_do_write()) + * + * The events have to be seen as events signaling the state of these mboxes/semaphores. For non-blocking + * connections, you need to know in advance whether a call to a netconn function call would block or not, + * and these events tell you about that. + * + * RCVPLUS events say: Safe to perform a potentially blocking call call once more. + * They are counted in sockets - three RCVPLUS events for accept mbox means you are safe + * to call netconn_accept 3 times without being blocked. + * Same thing for receive mbox. + * + * RCVMINUS events say: Your call to to a possibly blocking function is "acknowledged". + * Socket implementation decrements the counter. + * + * For TX, there is no need to count, its merely a flag. SENDPLUS means you may send something. + * SENDPLUS occurs when enough data was delivered to peer so netconn_send() can be called again. + * A SENDMINUS event occurs when the next call to a netconn_send() would be blocking. + */ +enum netconn_evt { + NETCONN_EVT_RCVPLUS, + NETCONN_EVT_RCVMINUS, + NETCONN_EVT_SENDPLUS, + NETCONN_EVT_SENDMINUS, + NETCONN_EVT_ERROR +}; + +#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) +/** Used for netconn_join_leave_group() */ +enum netconn_igmp { + NETCONN_JOIN, + NETCONN_LEAVE +}; +#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ + +#if LWIP_DNS +/* Used for netconn_gethostbyname_addrtype(), these should match the DNS_ADDRTYPE defines in dns.h */ +#define NETCONN_DNS_DEFAULT NETCONN_DNS_IPV4_IPV6 +#define NETCONN_DNS_IPV4 0 +#define NETCONN_DNS_IPV6 1 +#define NETCONN_DNS_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */ +#define NETCONN_DNS_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */ +#endif /* LWIP_DNS */ + +/* forward-declare some structs to avoid to include their headers */ +struct ip_pcb; +struct tcp_pcb; +struct udp_pcb; +struct raw_pcb; +struct netconn; +struct api_msg; + +/** A callback prototype to inform about events for a netconn */ +typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len); + +/** A netconn descriptor */ +struct netconn { + /** type of the netconn (TCP, UDP or RAW) */ + enum netconn_type type; + /** current state of the netconn */ + enum netconn_state state; + /** the lwIP internal protocol control block */ + union { + struct ip_pcb *ip; + struct tcp_pcb *tcp; + struct udp_pcb *udp; + struct raw_pcb *raw; + } pcb; + /** the last asynchronous unreported error this netconn had */ + err_t pending_err; +#if !LWIP_NETCONN_SEM_PER_THREAD + /** sem that is used to synchronously execute functions in the core context */ + sys_sem_t op_completed; +#endif + /** mbox where received packets are stored until they are fetched + by the netconn application thread (can grow quite big) */ + sys_mbox_t recvmbox; +#if LWIP_TCP + /** mbox where new connections are stored until processed + by the application thread */ + sys_mbox_t acceptmbox; +#endif /* LWIP_TCP */ +#if LWIP_NETCONN_FULLDUPLEX + /** number of threads waiting on an mbox. This is required to unblock + all threads when closing while threads are waiting. */ + int mbox_threads_waiting; +#endif + /** only used for socket layer */ +#if LWIP_SOCKET + int socket; +#endif /* LWIP_SOCKET */ +#if LWIP_SO_SNDTIMEO + /** timeout to wait for sending data (which means enqueueing data for sending + in internal buffers) in milliseconds */ + s32_t send_timeout; +#endif /* LWIP_SO_RCVTIMEO */ +#if LWIP_SO_RCVTIMEO + /** timeout in milliseconds to wait for new data to be received + (or connections to arrive for listening netconns) */ + u32_t recv_timeout; +#endif /* LWIP_SO_RCVTIMEO */ +#if LWIP_SO_RCVBUF + /** maximum amount of bytes queued in recvmbox + not used for TCP: adjust TCP_WND instead! */ + int recv_bufsize; + /** number of bytes currently in recvmbox to be received, + tested against recv_bufsize to limit bytes on recvmbox + for UDP and RAW, used for FIONREAD */ + int recv_avail; +#endif /* LWIP_SO_RCVBUF */ +#if LWIP_SO_LINGER + /** values <0 mean linger is disabled, values > 0 are seconds to linger */ + s16_t linger; +#endif /* LWIP_SO_LINGER */ + /** flags holding more netconn-internal state, see NETCONN_FLAG_* defines */ + u8_t flags; +#if LWIP_TCP + /** TCP: when data passed to netconn_write doesn't fit into the send buffer, + this temporarily stores the message. + Also used during connect and close. */ + struct api_msg *current_msg; +#endif /* LWIP_TCP */ + /** A callback function that is informed about events for this netconn */ + netconn_callback callback; +}; + +/** This vector type is passed to @ref netconn_write_vectors_partly to send + * multiple buffers at once. + * ATTENTION: This type has to directly map struct iovec since one is casted + * into the other! + */ +struct netvector { + /** pointer to the application buffer that contains the data to send */ + const void *ptr; + /** size of the application data to send */ + size_t len; +}; + +/** Register an Network connection event */ +#define API_EVENT(c,e,l) if (c->callback) { \ + (*c->callback)(c, e, l); \ + } + +/* Network connection functions: */ + +/** @ingroup netconn_common + * Create new netconn connection + * @param t @ref netconn_type */ +#define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL) +#define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c) +struct netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, + netconn_callback callback); +err_t netconn_prepare_delete(struct netconn *conn); +err_t netconn_delete(struct netconn *conn); +/** Get the type of a netconn (as enum netconn_type). */ +#define netconn_type(conn) (conn->type) + +err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr, + u16_t *port, u8_t local); +/** @ingroup netconn_common */ +#define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0) +/** @ingroup netconn_common */ +#define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1) + +err_t netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port); +err_t netconn_bind_if(struct netconn *conn, u8_t if_idx); +err_t netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port); +err_t netconn_disconnect (struct netconn *conn); +err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog); +/** @ingroup netconn_tcp */ +#define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG) +err_t netconn_accept(struct netconn *conn, struct netconn **new_conn); +err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf); +err_t netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf); +err_t netconn_recv_udp_raw_netbuf_flags(struct netconn *conn, struct netbuf **new_buf, u8_t apiflags); +err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf); +err_t netconn_recv_tcp_pbuf_flags(struct netconn *conn, struct pbuf **new_buf, u8_t apiflags); +err_t netconn_tcp_recvd(struct netconn *conn, size_t len); +err_t netconn_sendto(struct netconn *conn, struct netbuf *buf, + const ip_addr_t *addr, u16_t port); +err_t netconn_send(struct netconn *conn, struct netbuf *buf); +err_t netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size, + u8_t apiflags, size_t *bytes_written); +err_t netconn_write_vectors_partly(struct netconn *conn, struct netvector *vectors, u16_t vectorcnt, + u8_t apiflags, size_t *bytes_written); +/** @ingroup netconn_tcp */ +#define netconn_write(conn, dataptr, size, apiflags) \ + netconn_write_partly(conn, dataptr, size, apiflags, NULL) +err_t netconn_close(struct netconn *conn); +err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx); + +#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) +err_t netconn_join_leave_group(struct netconn *conn, const ip_addr_t *multiaddr, + const ip_addr_t *netif_addr, enum netconn_igmp join_or_leave); +err_t netconn_join_leave_group_netif(struct netconn *conn, const ip_addr_t *multiaddr, + u8_t if_idx, enum netconn_igmp join_or_leave); +#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ +#if LWIP_DNS +#if LWIP_IPV4 && LWIP_IPV6 +err_t netconn_gethostbyname_addrtype(const char *name, ip_addr_t *addr, u8_t dns_addrtype); +#define netconn_gethostbyname(name, addr) netconn_gethostbyname_addrtype(name, addr, NETCONN_DNS_DEFAULT) +#else /* LWIP_IPV4 && LWIP_IPV6 */ +err_t netconn_gethostbyname(const char *name, ip_addr_t *addr); +#define netconn_gethostbyname_addrtype(name, addr, dns_addrtype) netconn_gethostbyname(name, addr) +#endif /* LWIP_IPV4 && LWIP_IPV6 */ +#endif /* LWIP_DNS */ + +err_t netconn_err(struct netconn *conn); +#define netconn_recv_bufsize(conn) ((conn)->recv_bufsize) + +#define netconn_set_flags(conn, set_flags) do { (conn)->flags = (u8_t)((conn)->flags | (set_flags)); } while(0) +#define netconn_clear_flags(conn, clr_flags) do { (conn)->flags = (u8_t)((conn)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0) +#define netconn_is_flag_set(conn, flag) (((conn)->flags & (flag)) != 0) + +/** Set the blocking status of netconn calls (@todo: write/send is missing) */ +#define netconn_set_nonblocking(conn, val) do { if(val) { \ + netconn_set_flags(conn, NETCONN_FLAG_NON_BLOCKING); \ +} else { \ + netconn_clear_flags(conn, NETCONN_FLAG_NON_BLOCKING); }} while(0) +/** Get the blocking status of netconn calls (@todo: write/send is missing) */ +#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0) + +#if LWIP_IPV6 +/** @ingroup netconn_common + * TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) + */ +#define netconn_set_ipv6only(conn, val) do { if(val) { \ + netconn_set_flags(conn, NETCONN_FLAG_IPV6_V6ONLY); \ +} else { \ + netconn_clear_flags(conn, NETCONN_FLAG_IPV6_V6ONLY); }} while(0) +/** @ingroup netconn_common + * TCP: Get the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) + */ +#define netconn_get_ipv6only(conn) (((conn)->flags & NETCONN_FLAG_IPV6_V6ONLY) != 0) +#endif /* LWIP_IPV6 */ + +#if LWIP_SO_SNDTIMEO +/** Set the send timeout in milliseconds */ +#define netconn_set_sendtimeout(conn, timeout) ((conn)->send_timeout = (timeout)) +/** Get the send timeout in milliseconds */ +#define netconn_get_sendtimeout(conn) ((conn)->send_timeout) +#endif /* LWIP_SO_SNDTIMEO */ +#if LWIP_SO_RCVTIMEO +/** Set the receive timeout in milliseconds */ +#define netconn_set_recvtimeout(conn, timeout) ((conn)->recv_timeout = (timeout)) +/** Get the receive timeout in milliseconds */ +#define netconn_get_recvtimeout(conn) ((conn)->recv_timeout) +#endif /* LWIP_SO_RCVTIMEO */ +#if LWIP_SO_RCVBUF +/** Set the receive buffer in bytes */ +#define netconn_set_recvbufsize(conn, recvbufsize) ((conn)->recv_bufsize = (recvbufsize)) +/** Get the receive buffer in bytes */ +#define netconn_get_recvbufsize(conn) ((conn)->recv_bufsize) +#endif /* LWIP_SO_RCVBUF*/ + +#if LWIP_NETCONN_SEM_PER_THREAD +void netconn_thread_init(void); +void netconn_thread_cleanup(void); +#else /* LWIP_NETCONN_SEM_PER_THREAD */ +#define netconn_thread_init() +#define netconn_thread_cleanup() +#endif /* LWIP_NETCONN_SEM_PER_THREAD */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_NETCONN || LWIP_SOCKET */ + +#endif /* LWIP_HDR_API_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/FILES b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/FILES new file mode 100644 index 000000000..adfc0f334 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/FILES @@ -0,0 +1,2 @@ +This directory contains application headers. +Every application shall provide one api file APP.h and optionally one options file APP_opts.h diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/altcp_proxyconnect.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/altcp_proxyconnect.h new file mode 100644 index 000000000..65d31279d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/altcp_proxyconnect.h @@ -0,0 +1,79 @@ +/** + * @file + * Application layered TCP connection API that executes a proxy-connect. + * + * This file provides a starting layer that executes a proxy-connect e.g. to + * set up TLS connections through a http proxy. + */ + +/* + * Copyright (c) 2018 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ + +#ifndef LWIP_HDR_APPS_ALTCP_PROXYCONNECT_H +#define LWIP_HDR_APPS_ALTCP_PROXYCONNECT_H + +#include "lwip/opt.h" + +#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/ip_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct altcp_proxyconnect_config { + ip_addr_t proxy_addr; + u16_t proxy_port; +}; + + +struct altcp_pcb *altcp_proxyconnect_new(struct altcp_proxyconnect_config *config, struct altcp_pcb *inner_pcb); +struct altcp_pcb *altcp_proxyconnect_new_tcp(struct altcp_proxyconnect_config *config, u8_t ip_type); + +struct altcp_pcb *altcp_proxyconnect_alloc(void *arg, u8_t ip_type); + +#if LWIP_ALTCP_TLS +struct altcp_proxyconnect_tls_config { + struct altcp_proxyconnect_config proxy; + struct altcp_tls_config *tls_config; +}; + +struct altcp_pcb *altcp_proxyconnect_tls_alloc(void *arg, u8_t ip_type); +#endif /* LWIP_ALTCP_TLS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_ALTCP */ +#endif /* LWIP_HDR_APPS_ALTCP_PROXYCONNECT_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h new file mode 100644 index 000000000..71aa59939 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h @@ -0,0 +1,105 @@ +/** + * @file + * Application layered TCP/TLS connection API (to be used from TCPIP thread) + * + * This file contains options for an mbedtls port of the TLS layer. + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_ALTCP_TLS_OPTS_H +#define LWIP_HDR_ALTCP_TLS_OPTS_H + +#include "lwip/opt.h" + +#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ + +/** LWIP_ALTCP_TLS_MBEDTLS==1: use mbedTLS for TLS support for altcp API + * mbedtls include directory must be reachable via include search path + */ +#ifndef LWIP_ALTCP_TLS_MBEDTLS +#define LWIP_ALTCP_TLS_MBEDTLS 0 +#endif + +/** Configure debug level of this file */ +#ifndef ALTCP_MBEDTLS_DEBUG +#define ALTCP_MBEDTLS_DEBUG LWIP_DBG_OFF +#endif + +/** Configure lwIP debug level of the mbedTLS library */ +#ifndef ALTCP_MBEDTLS_LIB_DEBUG +#define ALTCP_MBEDTLS_LIB_DEBUG LWIP_DBG_OFF +#endif + +/** Configure minimum internal debug level of the mbedTLS library */ +#ifndef ALTCP_MBEDTLS_LIB_DEBUG_LEVEL_MIN +#define ALTCP_MBEDTLS_LIB_DEBUG_LEVEL_MIN 0 +#endif + +/** Enable the basic session cache + * ATTENTION: Using a session cache can lower security by reusing keys! + */ +#ifndef ALTCP_MBEDTLS_USE_SESSION_CACHE +#define ALTCP_MBEDTLS_USE_SESSION_CACHE 0 +#endif + +/** Maximum cache size of the basic session cache */ +#ifndef ALTCP_MBEDTLS_SESSION_CACHE_SIZE +#define ALTCP_MBEDTLS_SESSION_CACHE_SIZE 30 +#endif + +/** Set a session timeout in seconds for the basic session cache */ +#ifndef ALTCP_MBEDTLS_SESSION_CACHE_TIMEOUT_SECONDS +#define ALTCP_MBEDTLS_SESSION_CACHE_TIMEOUT_SECONDS (60 * 60) +#endif + +/** Use session tickets to speed up connection setup (needs + * MBEDTLS_SSL_SESSION_TICKETS enabled in mbedTLS config). + * ATTENTION: Using session tickets can lower security by reusing keys! + */ +#ifndef ALTCP_MBEDTLS_USE_SESSION_TICKETS +#define ALTCP_MBEDTLS_USE_SESSION_TICKETS 0 +#endif + +/** Session ticket cipher */ +#ifndef ALTCP_MBEDTLS_SESSION_TICKET_CIPHER +#define ALTCP_MBEDTLS_SESSION_TICKET_CIPHER MBEDTLS_CIPHER_AES_256_GCM +#endif + +/** Maximum timeout for session tickets */ +#ifndef ALTCP_MBEDTLS_SESSION_TICKET_TIMEOUT_SECONDS +#define ALTCP_MBEDTLS_SESSION_TICKET_TIMEOUT_SECONDS (60 * 60 * 24) +#endif + +#endif /* LWIP_ALTCP */ + +#endif /* LWIP_HDR_ALTCP_TLS_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/fs.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/fs.h new file mode 100644 index 000000000..67b9a60a9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/fs.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_APPS_FS_H +#define LWIP_HDR_APPS_FS_H + +#include "httpd_opts.h" +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define FS_READ_EOF -1 +#define FS_READ_DELAYED -2 + +#if HTTPD_PRECALCULATED_CHECKSUM +struct fsdata_chksum { + u32_t offset; + u16_t chksum; + u16_t len; +}; +#endif /* HTTPD_PRECALCULATED_CHECKSUM */ + +#define FS_FILE_FLAGS_HEADER_INCLUDED 0x01 +#define FS_FILE_FLAGS_HEADER_PERSISTENT 0x02 +#define FS_FILE_FLAGS_HEADER_HTTPVER_1_1 0x04 +#define FS_FILE_FLAGS_SSI 0x08 + +/** Define FS_FILE_EXTENSION_T_DEFINED if you have typedef'ed to your private + * pointer type (defaults to 'void' so the default usage is 'void*') + */ +#ifndef FS_FILE_EXTENSION_T_DEFINED +typedef void fs_file_extension; +#endif + +struct fs_file { + const char *data; + int len; + int index; + /* pextension is free for implementations to hold private (extensional) + arbitrary data, e.g. holding some file state or file system handle */ + fs_file_extension *pextension; +#if HTTPD_PRECALCULATED_CHECKSUM + const struct fsdata_chksum *chksum; + u16_t chksum_count; +#endif /* HTTPD_PRECALCULATED_CHECKSUM */ + u8_t flags; +#if LWIP_HTTPD_CUSTOM_FILES + u8_t is_custom_file; +#endif /* LWIP_HTTPD_CUSTOM_FILES */ +#if LWIP_HTTPD_FILE_STATE + void *state; +#endif /* LWIP_HTTPD_FILE_STATE */ +}; + +#if LWIP_HTTPD_FS_ASYNC_READ +typedef void (*fs_wait_cb)(void *arg); +#endif /* LWIP_HTTPD_FS_ASYNC_READ */ + +err_t fs_open(struct fs_file *file, const char *name); +void fs_close(struct fs_file *file); +#if LWIP_HTTPD_DYNAMIC_FILE_READ +#if LWIP_HTTPD_FS_ASYNC_READ +int fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg); +#else /* LWIP_HTTPD_FS_ASYNC_READ */ +int fs_read(struct fs_file *file, char *buffer, int count); +#endif /* LWIP_HTTPD_FS_ASYNC_READ */ +#endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */ +#if LWIP_HTTPD_FS_ASYNC_READ +int fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg); +#endif /* LWIP_HTTPD_FS_ASYNC_READ */ +int fs_bytes_left(struct fs_file *file); + +#if LWIP_HTTPD_FILE_STATE +/** This user-defined function is called when a file is opened. */ +void *fs_state_init(struct fs_file *file, const char *name); +/** This user-defined function is called when a file is closed. */ +void fs_state_free(struct fs_file *file, void *state); +#endif /* #if LWIP_HTTPD_FILE_STATE */ + +struct fsdata_file { + const struct fsdata_file *next; + const unsigned char *name; + const unsigned char *data; + int len; + u8_t flags; +#if HTTPD_PRECALCULATED_CHECKSUM + u16_t chksum_count; + const struct fsdata_chksum *chksum; +#endif /* HTTPD_PRECALCULATED_CHECKSUM */ +}; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_FS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/http_client.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/http_client.h new file mode 100644 index 000000000..1cce15ef4 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/http_client.h @@ -0,0 +1,171 @@ +/** + * @file + * HTTP client + */ + +/* + * Copyright (c) 2018 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ + +#ifndef LWIP_HDR_APPS_HTTP_CLIENT_H +#define LWIP_HDR_APPS_HTTP_CLIENT_H + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "lwip/err.h" +#include "lwip/altcp.h" +#include "lwip/prot/iana.h" +#include "lwip/pbuf.h" + +#if LWIP_TCP && LWIP_CALLBACK_API + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup httpc + * HTTPC_HAVE_FILE_IO: define this to 1 to have functions dowloading directly + * to disk via fopen/fwrite. + * These functions are example implementations of the interface only. + */ +#ifndef LWIP_HTTPC_HAVE_FILE_IO +#define LWIP_HTTPC_HAVE_FILE_IO 0 +#endif + +/** + * @ingroup httpc + * The default TCP port used for HTTP + */ +#define HTTP_DEFAULT_PORT LWIP_IANA_PORT_HTTP + +/** + * @ingroup httpc + * HTTP client result codes + */ +typedef enum ehttpc_result { + /** File successfully received */ + HTTPC_RESULT_OK = 0, + /** Unknown error */ + HTTPC_RESULT_ERR_UNKNOWN = 1, + /** Connection to server failed */ + HTTPC_RESULT_ERR_CONNECT = 2, + /** Failed to resolve server hostname */ + HTTPC_RESULT_ERR_HOSTNAME = 3, + /** Connection unexpectedly closed by remote server */ + HTTPC_RESULT_ERR_CLOSED = 4, + /** Connection timed out (server didn't respond in time) */ + HTTPC_RESULT_ERR_TIMEOUT = 5, + /** Server responded with an error code */ + HTTPC_RESULT_ERR_SVR_RESP = 6, + /** Local memory error */ + HTTPC_RESULT_ERR_MEM = 7, + /** Local abort */ + HTTPC_RESULT_LOCAL_ABORT = 8, + /** Content length mismatch */ + HTTPC_RESULT_ERR_CONTENT_LEN = 9 +} httpc_result_t; + +typedef struct _httpc_state httpc_state_t; + +/** + * @ingroup httpc + * Prototype of a http client callback function + * + * @param arg argument specified when initiating the request + * @param httpc_result result of the http transfer (see enum httpc_result_t) + * @param rx_content_len number of bytes received (without headers) + * @param srv_res this contains the http status code received (if any) + * @param err an error returned by internal lwip functions, can help to specify + * the source of the error but must not necessarily be != ERR_OK + */ +typedef void (*httpc_result_fn)(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err); + +/** + * @ingroup httpc + * Prototype of http client callback: called when the headers are received + * + * @param connection http client connection + * @param arg argument specified when initiating the request + * @param hdr header pbuf(s) (may contain data also) + * @param hdr_len length of the heders in 'hdr' + * @param content_len content length as received in the headers (-1 if not received) + * @return if != ERR_OK is returned, the connection is aborted + */ +typedef err_t (*httpc_headers_done_fn)(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len); +typedef err_t (*httpc_file_rx_fn)(httpc_state_t *connection, u32_t rx_len,u32_t rx_total_len); + +typedef struct _httpc_connection { + ip_addr_t proxy_addr; + u16_t proxy_port; + u8_t use_proxy; + /* @todo: add username:pass? */ + +#if LWIP_ALTCP + altcp_allocator_t *altcp_allocator; +#endif + + /* this callback is called when the transfer is finished (or aborted) */ + httpc_result_fn result_fn; + /* this callback is called after receiving the http headers + It can abort the connection by returning != ERR_OK */ + httpc_headers_done_fn headers_done_fn; + + /* this callback is called after receiving some bytes of download file + */ + httpc_file_rx_fn file_rx_fn; + //添加post + u8_t use_post; + u16_t arglen; + u8_t* args; + + +} httpc_connection_t; + +err_t httpc_get_file(const ip_addr_t* server_addr, u16_t port, const char* uri, const httpc_connection_t *settings, + altcp_recv_fn recv_fn, void* callback_arg, httpc_state_t **connection); +err_t httpc_get_file_dns(const char* server_name, u16_t port, const char* uri, const httpc_connection_t *settings, + altcp_recv_fn recv_fn, void* callback_arg, httpc_state_t **connection); + +#if LWIP_HTTPC_HAVE_FILE_IO +err_t httpc_get_file_to_disk(const ip_addr_t* server_addr, u16_t port, const char* uri, const httpc_connection_t *settings, + void* callback_arg, const char* local_file_name, httpc_state_t **connection); +err_t httpc_get_file_dns_to_disk(const char* server_name, u16_t port, const char* uri, const httpc_connection_t *settings, + void* callback_arg, const char* local_file_name, httpc_state_t **connection); +#endif /* LWIP_HTTPC_HAVE_FILE_IO */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_TCP && LWIP_CALLBACK_API */ + +#endif /* LWIP_HDR_APPS_HTTP_CLIENT_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/httpd.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/httpd.h new file mode 100644 index 000000000..e872429f2 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/httpd.h @@ -0,0 +1,255 @@ +/** + * @file + * HTTP server + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * This version of the file has been modified by Texas Instruments to offer + * simple server-side-include (SSI) and Common Gateway Interface (CGI) + * capability. + */ + +#ifndef LWIP_HDR_APPS_HTTPD_H +#define LWIP_HDR_APPS_HTTPD_H + +#include "httpd_opts.h" +#include "lwip/err.h" +#include "lwip/pbuf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_HTTPD_CGI + +/** + * @ingroup httpd + * Function pointer for a CGI script handler. + * + * This function is called each time the HTTPD server is asked for a file + * whose name was previously registered as a CGI function using a call to + * http_set_cgi_handlers. The iIndex parameter provides the index of the + * CGI within the cgis array passed to http_set_cgi_handlers. Parameters + * pcParam and pcValue provide access to the parameters provided along with + * the URI. iNumParams provides a count of the entries in the pcParam and + * pcValue arrays. Each entry in the pcParam array contains the name of a + * parameter with the corresponding entry in the pcValue array containing the + * value for that parameter. Note that pcParam may contain multiple elements + * with the same name if, for example, a multi-selection list control is used + * in the form generating the data. + * + * The function should return a pointer to a character string which is the + * path and filename of the response that is to be sent to the connected + * browser, for example "/thanks.htm" or "/response/error.ssi". + * + * The maximum number of parameters that will be passed to this function via + * iNumParams is defined by LWIP_HTTPD_MAX_CGI_PARAMETERS. Any parameters in + * the incoming HTTP request above this number will be discarded. + * + * Requests intended for use by this CGI mechanism must be sent using the GET + * method (which encodes all parameters within the URI rather than in a block + * later in the request). Attempts to use the POST method will result in the + * request being ignored. + * + */ +typedef const char *(*tCGIHandler)(int iIndex, int iNumParams, char *pcParam[], + char *pcValue[]); + +/** + * @ingroup httpd + * Structure defining the base filename (URL) of a CGI and the associated + * function which is to be called when that URL is requested. + */ +typedef struct +{ + const char *pcCGIName; + tCGIHandler pfnCGIHandler; +} tCGI; + +void http_set_cgi_handlers(const tCGI *pCGIs, int iNumHandlers); + +#endif /* LWIP_HTTPD_CGI */ + +#if LWIP_HTTPD_CGI || LWIP_HTTPD_CGI_SSI + +#if LWIP_HTTPD_CGI_SSI +/* we have to prototype this struct here to make it available for the handler */ +struct fs_file; + +/** Define this generic CGI handler in your application. + * It is called once for every URI with parameters. + * The parameters can be stored to the object passed as connection_state, which + * is allocated to file->state via fs_state_init() from fs_open() or fs_open_custom(). + * Content creation via SSI or complete dynamic files can retrieve the CGI params from there. + */ +extern void httpd_cgi_handler(struct fs_file *file, const char* uri, int iNumParams, + char **pcParam, char **pcValue +#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE + , void *connection_state +#endif /* LWIP_HTTPD_FILE_STATE */ + ); +#endif /* LWIP_HTTPD_CGI_SSI */ + +#endif /* LWIP_HTTPD_CGI || LWIP_HTTPD_CGI_SSI */ + +#if LWIP_HTTPD_SSI + +/** + * @ingroup httpd + * Function pointer for the SSI tag handler callback. + * + * This function will be called each time the HTTPD server detects a tag of the + * form in files with extensions mentioned in the g_pcSSIExtensions + * array (currently .shtml, .shtm, .ssi, .xml, .json) where "name" appears as + * one of the tags supplied to http_set_ssi_handler in the tags array. The + * returned insert string, which will be appended after the the string + * "" in file sent back to the client, should be written to pointer + * pcInsert. iInsertLen contains the size of the buffer pointed to by + * pcInsert. The iIndex parameter provides the zero-based index of the tag as + * found in the tags array and identifies the tag that is to be processed. + * + * The handler returns the number of characters written to pcInsert excluding + * any terminating NULL or HTTPD_SSI_TAG_UNKNOWN when tag is not recognized. + * + * Note that the behavior of this SSI mechanism is somewhat different from the + * "normal" SSI processing as found in, for example, the Apache web server. In + * this case, the inserted text is appended following the SSI tag rather than + * replacing the tag entirely. This allows for an implementation that does not + * require significant additional buffering of output data yet which will still + * offer usable SSI functionality. One downside to this approach is when + * attempting to use SSI within JavaScript. The SSI tag is structured to + * resemble an HTML comment but this syntax does not constitute a comment + * within JavaScript and, hence, leaving the tag in place will result in + * problems in these cases. In order to avoid these problems, define + * LWIP_HTTPD_SSI_INCLUDE_TAG as zero in your lwip options file, or use JavaScript + * style block comments in the form / * # name * / (without the spaces). + */ +typedef u16_t (*tSSIHandler)( +#if LWIP_HTTPD_SSI_RAW + const char* ssi_tag_name, +#else /* LWIP_HTTPD_SSI_RAW */ + int iIndex, +#endif /* LWIP_HTTPD_SSI_RAW */ + char *pcInsert, int iInsertLen +#if LWIP_HTTPD_SSI_MULTIPART + , u16_t current_tag_part, u16_t *next_tag_part +#endif /* LWIP_HTTPD_SSI_MULTIPART */ +#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE + , void *connection_state +#endif /* LWIP_HTTPD_FILE_STATE */ + ); + +/** Set the SSI handler function + * (if LWIP_HTTPD_SSI_RAW==1, only the first argument is used) + */ +void http_set_ssi_handler(tSSIHandler pfnSSIHandler, + const char **ppcTags, int iNumTags); + +/** For LWIP_HTTPD_SSI_RAW==1, return this to indicate the tag is unknown. + * In this case, the webserver writes a warning into the page. + * You can also just return 0 to write nothing for unknown tags. + */ +#define HTTPD_SSI_TAG_UNKNOWN 0xFFFF + +#endif /* LWIP_HTTPD_SSI */ + +#if LWIP_HTTPD_SUPPORT_POST + +/* These functions must be implemented by the application */ + +/** + * @ingroup httpd + * Called when a POST request has been received. The application can decide + * whether to accept it or not. + * + * @param connection Unique connection identifier, valid until httpd_post_end + * is called. + * @param uri The HTTP header URI receiving the POST request. + * @param http_request The raw HTTP request (the first packet, normally). + * @param http_request_len Size of 'http_request'. + * @param content_len Content-Length from HTTP header. + * @param response_uri Filename of response file, to be filled when denying the + * request + * @param response_uri_len Size of the 'response_uri' buffer. + * @param post_auto_wnd Set this to 0 to let the callback code handle window + * updates by calling 'httpd_post_data_recved' (to throttle rx speed) + * default is 1 (httpd handles window updates automatically) + * @return ERR_OK: Accept the POST request, data may be passed in + * another err_t: Deny the POST request, send back 'bad request'. + */ +err_t httpd_post_begin(void *connection, const char *uri, const char *http_request, + u16_t http_request_len, int content_len, char *response_uri, + u16_t response_uri_len, u8_t *post_auto_wnd); + +/** + * @ingroup httpd + * Called for each pbuf of data that has been received for a POST. + * ATTENTION: The application is responsible for freeing the pbufs passed in! + * + * @param connection Unique connection identifier. + * @param p Received data. + * @return ERR_OK: Data accepted. + * another err_t: Data denied, http_post_get_response_uri will be called. + */ +err_t httpd_post_receive_data(void *connection, struct pbuf *p); + +/** + * @ingroup httpd + * Called when all data is received or when the connection is closed. + * The application must return the filename/URI of a file to send in response + * to this POST request. If the response_uri buffer is untouched, a 404 + * response is returned. + * + * @param connection Unique connection identifier. + * @param response_uri Filename of response file, to be filled when denying the request + * @param response_uri_len Size of the 'response_uri' buffer. + */ +void httpd_post_finished(void *connection, char *response_uri, u16_t response_uri_len); + +#if LWIP_HTTPD_POST_MANUAL_WND +void httpd_post_data_recved(void *connection, u16_t recved_len); +#endif /* LWIP_HTTPD_POST_MANUAL_WND */ + +#endif /* LWIP_HTTPD_SUPPORT_POST */ + +void httpd_init(void); + +#if HTTPD_ENABLE_HTTPS +struct altcp_tls_config; +void httpd_inits(struct altcp_tls_config *conf); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_HTTPD_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/httpd_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/httpd_opts.h new file mode 100644 index 000000000..8723961fd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/httpd_opts.h @@ -0,0 +1,396 @@ +/** + * @file + * HTTP server options list + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + * This version of the file has been modified by Texas Instruments to offer + * simple server-side-include (SSI) and Common Gateway Interface (CGI) + * capability. + */ + +#ifndef LWIP_HDR_APPS_HTTPD_OPTS_H +#define LWIP_HDR_APPS_HTTPD_OPTS_H + +#include "lwip/opt.h" +#include "lwip/prot/iana.h" + +/** + * @defgroup httpd_opts Options + * @ingroup httpd + * @{ + */ + +/** Set this to 1 to support CGI (old style). + * + * This old style CGI support works by registering an array of URLs and + * associated CGI handler functions (@ref http_set_cgi_handlers). + * This list is scanned just before fs_open is called from request handling. + * The handler can return a new URL that is used internally by the httpd to + * load the returned page (passed to fs_open). + * + * Use this CGI type e.g. to execute specific actions and return a page that + * does not depend on the CGI parameters. + */ +#if !defined LWIP_HTTPD_CGI || defined __DOXYGEN__ +#define LWIP_HTTPD_CGI 0 +#endif + +/** Set this to 1 to support CGI (new style). + * + * This new style CGI support works by calling a global function + * (@ref tCGIHandler) for all URLs that are found. fs_open is called first + * and the URL can not be written by the CGI handler. Instead, this handler gets + * passed the http file state, an object where it can store information derived + * from the CGI URL or parameters. This file state is later passed to SSI, so + * the SSI code can return data depending on CGI input. + * + * Use this CGI handler if you want CGI information passed on to SSI. + */ +#if !defined LWIP_HTTPD_CGI_SSI || defined __DOXYGEN__ +#define LWIP_HTTPD_CGI_SSI 0 +#endif + +/** Set this to 1 to support SSI (Server-Side-Includes) + * + * In contrast to other http servers, this only calls a preregistered callback + * function (@see http_set_ssi_handler) for each tag (in the format of + * ) encountered in SSI-enabled pages. + * SSI-enabled pages must have one of the predefined SSI-enabled file extensions. + * All files with one of these extensions are parsed when sent. + * + * A downside of the current SSI implementation is that persistent connections + * don't work, as the file length is not known in advance (and httpd currently + * relies on the Content-Length header for persistent connections). + * + * To save memory, the maximum tag length is limited (@see LWIP_HTTPD_MAX_TAG_NAME_LEN). + * To save memory, the maximum insertion string length is limited (@see + * LWIP_HTTPD_MAX_TAG_INSERT_LEN). If this is not enought, @ref LWIP_HTTPD_SSI_MULTIPART + * can be used. + */ +#if !defined LWIP_HTTPD_SSI || defined __DOXYGEN__ +#define LWIP_HTTPD_SSI 0 +#endif + +/** Set this to 1 to implement an SSI tag handler callback that gets a const char* + * to the tag (instead of an index into a pre-registered array of known tags) + * If this is 0, the SSI handler callback function is only called pre-registered tags. + */ +#if !defined LWIP_HTTPD_SSI_RAW || defined __DOXYGEN__ +#define LWIP_HTTPD_SSI_RAW 0 +#endif + +/** Set this to 0 to prevent parsing the file extension at runtime to decide + * if a file should be scanned for SSI tags or not. + * Default is 1 (file extensions are checked using the g_pcSSIExtensions array) + * Set to 2 to override this runtime test function. + * + * This is enabled by default, but if you only use a newer version of makefsdata + * supporting the "-ssi" option, this info is already present in + */ +#if !defined LWIP_HTTPD_SSI_BY_FILE_EXTENSION || defined __DOXYGEN__ +#define LWIP_HTTPD_SSI_BY_FILE_EXTENSION 1 +#endif + +/** Set this to 1 to support HTTP POST */ +#if !defined LWIP_HTTPD_SUPPORT_POST || defined __DOXYGEN__ +#define LWIP_HTTPD_SUPPORT_POST 0 +#endif + +/* The maximum number of parameters that the CGI handler can be sent. */ +#if !defined LWIP_HTTPD_MAX_CGI_PARAMETERS || defined __DOXYGEN__ +#define LWIP_HTTPD_MAX_CGI_PARAMETERS 16 +#endif + +/** LWIP_HTTPD_SSI_MULTIPART==1: SSI handler function is called with 2 more + * arguments indicating a counter for insert string that are too long to be + * inserted at once: the SSI handler function must then set 'next_tag_part' + * which will be passed back to it in the next call. */ +#if !defined LWIP_HTTPD_SSI_MULTIPART || defined __DOXYGEN__ +#define LWIP_HTTPD_SSI_MULTIPART 0 +#endif + +/* The maximum length of the string comprising the SSI tag name + * ATTENTION: tags longer than this are ignored, not truncated! + */ +#if !defined LWIP_HTTPD_MAX_TAG_NAME_LEN || defined __DOXYGEN__ +#define LWIP_HTTPD_MAX_TAG_NAME_LEN 8 +#endif + +/* The maximum length of string that can be returned to replace any given tag + * If this buffer is not long enough, use LWIP_HTTPD_SSI_MULTIPART. + */ +#if !defined LWIP_HTTPD_MAX_TAG_INSERT_LEN || defined __DOXYGEN__ +#define LWIP_HTTPD_MAX_TAG_INSERT_LEN 192 +#endif + +#if !defined LWIP_HTTPD_POST_MANUAL_WND || defined __DOXYGEN__ +#define LWIP_HTTPD_POST_MANUAL_WND 0 +#endif + +/** This string is passed in the HTTP header as "Server: " */ +#if !defined HTTPD_SERVER_AGENT || defined __DOXYGEN__ +#define HTTPD_SERVER_AGENT "lwIP/" LWIP_VERSION_STRING " (http://savannah.nongnu.org/projects/lwip)" +#endif + +/** Set this to 1 if you want to include code that creates HTTP headers + * at runtime. Default is off: HTTP headers are then created statically + * by the makefsdata tool. Static headers mean smaller code size, but + * the (readonly) fsdata will grow a bit as every file includes the HTTP + * header. */ +#if !defined LWIP_HTTPD_DYNAMIC_HEADERS || defined __DOXYGEN__ +#define LWIP_HTTPD_DYNAMIC_HEADERS 0 +#endif + +#if !defined HTTPD_DEBUG || defined __DOXYGEN__ +#define HTTPD_DEBUG LWIP_DBG_OFF +#endif + +/** Set this to 1 to use a memp pool for allocating + * struct http_state instead of the heap. + * If enabled, you'll need to define MEMP_NUM_PARALLEL_HTTPD_CONNS + * (and MEMP_NUM_PARALLEL_HTTPD_SSI_CONNS for SSI) to set the size of + * the pool(s). + */ +#if !defined HTTPD_USE_MEM_POOL || defined __DOXYGEN__ +#define HTTPD_USE_MEM_POOL 0 +#endif + +/** The server port for HTTPD to use */ +#if !defined HTTPD_SERVER_PORT || defined __DOXYGEN__ +#define HTTPD_SERVER_PORT LWIP_IANA_PORT_HTTP +#endif + +/** The https server port for HTTPD to use */ +#if !defined HTTPD_SERVER_PORT_HTTPS || defined __DOXYGEN__ +#define HTTPD_SERVER_PORT_HTTPS LWIP_IANA_PORT_HTTPS +#endif + +/** Enable https support? */ +#if !defined HTTPD_ENABLE_HTTPS || defined __DOXYGEN__ +#define HTTPD_ENABLE_HTTPS 0 +#endif + +/** Maximum retries before the connection is aborted/closed. + * - number of times pcb->poll is called -> default is 4*500ms = 2s; + * - reset when pcb->sent is called + */ +#if !defined HTTPD_MAX_RETRIES || defined __DOXYGEN__ +#define HTTPD_MAX_RETRIES 4 +#endif + +/** The poll delay is X*500ms */ +#if !defined HTTPD_POLL_INTERVAL || defined __DOXYGEN__ +#define HTTPD_POLL_INTERVAL 4 +#endif + +/** Priority for tcp pcbs created by HTTPD (very low by default). + * Lower priorities get killed first when running out of memory. + */ +#if !defined HTTPD_TCP_PRIO || defined __DOXYGEN__ +#define HTTPD_TCP_PRIO TCP_PRIO_MIN +#endif + +/** Set this to 1 to enable timing each file sent */ +#if !defined LWIP_HTTPD_TIMING || defined __DOXYGEN__ +#define LWIP_HTTPD_TIMING 0 +#endif +/** Set this to 1 to enable timing each file sent */ +#if !defined HTTPD_DEBUG_TIMING || defined __DOXYGEN__ +#define HTTPD_DEBUG_TIMING LWIP_DBG_OFF +#endif + +/** Set this to one to show error pages when parsing a request fails instead + of simply closing the connection. */ +#if !defined LWIP_HTTPD_SUPPORT_EXTSTATUS || defined __DOXYGEN__ +#define LWIP_HTTPD_SUPPORT_EXTSTATUS 0 +#endif + +/** Set this to 0 to drop support for HTTP/0.9 clients (to save some bytes) */ +#if !defined LWIP_HTTPD_SUPPORT_V09 || defined __DOXYGEN__ +#define LWIP_HTTPD_SUPPORT_V09 1 +#endif + +/** Set this to 1 to enable HTTP/1.1 persistent connections. + * ATTENTION: If the generated file system includes HTTP headers, these must + * include the "Connection: keep-alive" header (pass argument "-11" to makefsdata). + */ +#if !defined LWIP_HTTPD_SUPPORT_11_KEEPALIVE || defined __DOXYGEN__ +#define LWIP_HTTPD_SUPPORT_11_KEEPALIVE 0 +#endif + +/** Set this to 1 to support HTTP request coming in in multiple packets/pbufs */ +#if !defined LWIP_HTTPD_SUPPORT_REQUESTLIST || defined __DOXYGEN__ +#define LWIP_HTTPD_SUPPORT_REQUESTLIST 1 +#endif + +#if LWIP_HTTPD_SUPPORT_REQUESTLIST +/** Number of rx pbufs to enqueue to parse an incoming request (up to the first + newline) */ +#if !defined LWIP_HTTPD_REQ_QUEUELEN || defined __DOXYGEN__ +#define LWIP_HTTPD_REQ_QUEUELEN 5 +#endif + +/** Number of (TCP payload-) bytes (in pbufs) to enqueue to parse and incoming + request (up to the first double-newline) */ +#if !defined LWIP_HTTPD_REQ_BUFSIZE || defined __DOXYGEN__ +#define LWIP_HTTPD_REQ_BUFSIZE LWIP_HTTPD_MAX_REQ_LENGTH +#endif + +/** Defines the maximum length of a HTTP request line (up to the first CRLF, + copied from pbuf into this a global buffer when pbuf- or packet-queues + are received - otherwise the input pbuf is used directly) */ +#if !defined LWIP_HTTPD_MAX_REQ_LENGTH || defined __DOXYGEN__ +#define LWIP_HTTPD_MAX_REQ_LENGTH LWIP_MIN(1023, (LWIP_HTTPD_REQ_QUEUELEN * PBUF_POOL_BUFSIZE)) +#endif +#endif /* LWIP_HTTPD_SUPPORT_REQUESTLIST */ + +/** This is the size of a static buffer used when URIs end with '/'. + * In this buffer, the directory requested is concatenated with all the + * configured default file names. + * Set to 0 to disable checking default filenames on non-root directories. + */ +#if !defined LWIP_HTTPD_MAX_REQUEST_URI_LEN || defined __DOXYGEN__ +#define LWIP_HTTPD_MAX_REQUEST_URI_LEN 63 +#endif + +/** Maximum length of the filename to send as response to a POST request, + * filled in by the application when a POST is finished. + */ +#if !defined LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN || defined __DOXYGEN__ +#define LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN 63 +#endif + +/** Set this to 0 to not send the SSI tag (default is on, so the tag will + * be sent in the HTML page */ +#if !defined LWIP_HTTPD_SSI_INCLUDE_TAG || defined __DOXYGEN__ +#define LWIP_HTTPD_SSI_INCLUDE_TAG 1 +#endif + +/** Set this to 1 to call tcp_abort when tcp_close fails with memory error. + * This can be used to prevent consuming all memory in situations where the + * HTTP server has low priority compared to other communication. */ +#if !defined LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR || defined __DOXYGEN__ +#define LWIP_HTTPD_ABORT_ON_CLOSE_MEM_ERROR 0 +#endif + +/** Set this to 1 to kill the oldest connection when running out of + * memory for 'struct http_state' or 'struct http_ssi_state'. + * ATTENTION: This puts all connections on a linked list, so may be kind of slow. + */ +#if !defined LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED || defined __DOXYGEN__ +#define LWIP_HTTPD_KILL_OLD_ON_CONNECTIONS_EXCEEDED 0 +#endif + +/** Set this to 1 to send URIs without extension without headers + * (who uses this at all??) */ +#if !defined LWIP_HTTPD_OMIT_HEADER_FOR_EXTENSIONLESS_URI || defined __DOXYGEN__ +#define LWIP_HTTPD_OMIT_HEADER_FOR_EXTENSIONLESS_URI 0 +#endif + +/** Default: Tags are sent from struct http_state and are therefore volatile */ +#if !defined HTTP_IS_TAG_VOLATILE || defined __DOXYGEN__ +#define HTTP_IS_TAG_VOLATILE(ptr) TCP_WRITE_FLAG_COPY +#endif + +/* By default, the httpd is limited to send 2*pcb->mss to keep resource usage low + when http is not an important protocol in the device. */ +#if !defined HTTPD_LIMIT_SENDING_TO_2MSS || defined __DOXYGEN__ +#define HTTPD_LIMIT_SENDING_TO_2MSS 1 +#endif + +/* Define this to a function that returns the maximum amount of data to enqueue. + The function have this signature: u16_t fn(struct altcp_pcb* pcb); + The best place to define this is the hooks file (@see LWIP_HOOK_FILENAME) */ +#if !defined HTTPD_MAX_WRITE_LEN || defined __DOXYGEN__ +#if HTTPD_LIMIT_SENDING_TO_2MSS +#define HTTPD_MAX_WRITE_LEN(pcb) ((u16_t)(2 * altcp_mss(pcb))) +#endif +#endif + +/*------------------- FS OPTIONS -------------------*/ + +/** Set this to 1 and provide the functions: + * - "int fs_open_custom(struct fs_file *file, const char *name)" + * Called first for every opened file to allow opening files + * that are not included in fsdata(_custom).c + * - "void fs_close_custom(struct fs_file *file)" + * Called to free resources allocated by fs_open_custom(). + */ +#if !defined LWIP_HTTPD_CUSTOM_FILES || defined __DOXYGEN__ +#define LWIP_HTTPD_CUSTOM_FILES 0 +#endif + +/** Set this to 1 to support fs_read() to dynamically read file data. + * Without this (default=off), only one-block files are supported, + * and the contents must be ready after fs_open(). + */ +#if !defined LWIP_HTTPD_DYNAMIC_FILE_READ || defined __DOXYGEN__ +#define LWIP_HTTPD_DYNAMIC_FILE_READ 0 +#endif + +/** Set this to 1 to include an application state argument per file + * that is opened. This allows to keep a state per connection/file. + */ +#if !defined LWIP_HTTPD_FILE_STATE || defined __DOXYGEN__ +#define LWIP_HTTPD_FILE_STATE 0 +#endif + +/** HTTPD_PRECALCULATED_CHECKSUM==1: include precompiled checksums for + * predefined (MSS-sized) chunks of the files to prevent having to calculate + * the checksums at runtime. */ +#if !defined HTTPD_PRECALCULATED_CHECKSUM || defined __DOXYGEN__ +#define HTTPD_PRECALCULATED_CHECKSUM 0 +#endif + +/** LWIP_HTTPD_FS_ASYNC_READ==1: support asynchronous read operations + * (fs_read_async returns FS_READ_DELAYED and calls a callback when finished). + */ +#if !defined LWIP_HTTPD_FS_ASYNC_READ || defined __DOXYGEN__ +#define LWIP_HTTPD_FS_ASYNC_READ 0 +#endif + +/** Filename (including path) to use as FS data file */ +#if !defined HTTPD_FSDATA_FILE || defined __DOXYGEN__ +/* HTTPD_USE_CUSTOM_FSDATA: Compatibility with deprecated lwIP option */ +#if defined(HTTPD_USE_CUSTOM_FSDATA) && (HTTPD_USE_CUSTOM_FSDATA != 0) +#define HTTPD_FSDATA_FILE "fsdata_custom.c" +#else +#define HTTPD_FSDATA_FILE "fsdata.c" +#endif +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_APPS_HTTPD_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/lwiperf.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/lwiperf.h new file mode 100644 index 000000000..cc86e7f87 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/lwiperf.h @@ -0,0 +1,100 @@ +/** + * @file + * lwIP iPerf server implementation + */ + +/* + * Copyright (c) 2014 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_APPS_LWIPERF_H +#define LWIP_HDR_APPS_LWIPERF_H + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define LWIPERF_TCP_PORT_DEFAULT 5001 + +/** lwIPerf test results */ +enum lwiperf_report_type +{ + /** The server side test is done */ + LWIPERF_TCP_DONE_SERVER, + /** The client side test is done */ + LWIPERF_TCP_DONE_CLIENT, + /** Local error lead to test abort */ + LWIPERF_TCP_ABORTED_LOCAL, + /** Data check error lead to test abort */ + LWIPERF_TCP_ABORTED_LOCAL_DATAERROR, + /** Transmit error lead to test abort */ + LWIPERF_TCP_ABORTED_LOCAL_TXERROR, + /** Remote side aborted the test */ + LWIPERF_TCP_ABORTED_REMOTE +}; + +/** Control */ +enum lwiperf_client_type +{ + /** Unidirectional tx only test */ + LWIPERF_CLIENT, + /** Do a bidirectional test simultaneously */ + LWIPERF_DUAL, + /** Do a bidirectional test individually */ + LWIPERF_TRADEOFF +}; + +/** Prototype of a report function that is called when a session is finished. + This report function can show the test results. + @param report_type contains the test result */ +typedef void (*lwiperf_report_fn)(void *arg, enum lwiperf_report_type report_type, + const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port, + u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec); + +void* lwiperf_start_tcp_server(const ip_addr_t* local_addr, u16_t local_port, + lwiperf_report_fn report_fn, void* report_arg); +void* lwiperf_start_tcp_server_default(lwiperf_report_fn report_fn, void* report_arg); +void* lwiperf_start_tcp_client(const ip_addr_t* remote_addr, u16_t remote_port, + enum lwiperf_client_type type, + lwiperf_report_fn report_fn, void* report_arg); +void* lwiperf_start_tcp_client_default(const ip_addr_t* remote_addr, + lwiperf_report_fn report_fn, void* report_arg); + +void lwiperf_abort(void* lwiperf_session); + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_LWIPERF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns.h new file mode 100644 index 000000000..20d7ee2a2 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns.h @@ -0,0 +1,105 @@ +/** + * @file + * MDNS responder + */ + + /* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman + * + */ + +#ifndef LWIP_HDR_APPS_MDNS_H +#define LWIP_HDR_APPS_MDNS_H + +#include "lwip/apps/mdns_opts.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_MDNS_RESPONDER + +enum mdns_sd_proto { + DNSSD_PROTO_UDP = 0, + DNSSD_PROTO_TCP = 1 +}; + +#define MDNS_PROBING_CONFLICT 0 +#define MDNS_PROBING_SUCCESSFUL 1 + +#define MDNS_LABEL_MAXLEN 63 + +struct mdns_host; +struct mdns_service; + +/** Callback function to add text to a reply, called when generating the reply */ +typedef void (*service_get_txt_fn_t)(struct mdns_service *service, void *txt_userdata); + +/** Callback function to let application know the result of probing network for name + * uniqueness, called with result MDNS_PROBING_SUCCESSFUL if no other node claimed + * use for the name for the netif or a service and is safe to use, or MDNS_PROBING_CONFLICT + * if another node is already using it and mdns is disabled on this interface */ +typedef void (*mdns_name_result_cb_t)(struct netif* netif, u8_t result); + +void mdns_resp_init(void); + +void mdns_resp_register_name_result_cb(mdns_name_result_cb_t cb); + +err_t mdns_resp_add_netif(struct netif *netif, const char *hostname, u32_t dns_ttl); +err_t mdns_resp_remove_netif(struct netif *netif); +err_t mdns_resp_rename_netif(struct netif *netif, const char *hostname); + +s8_t mdns_resp_add_service(struct netif *netif, const char *name, const char *service, enum mdns_sd_proto proto, u16_t port, u32_t dns_ttl, service_get_txt_fn_t txt_fn, void *txt_userdata); +err_t mdns_resp_del_service(struct netif *netif, s8_t slot); +err_t mdns_resp_rename_service(struct netif *netif, s8_t slot, const char *name); + +err_t mdns_resp_add_service_txtitem(struct mdns_service *service, const char *txt, u8_t txt_len); + +void mdns_resp_restart(struct netif *netif); +void mdns_resp_announce(struct netif *netif); + +/** + * @ingroup mdns + * Announce IP settings have changed on netif. + * Call this in your callback registered by netif_set_status_callback(). + * No need to call this function when LWIP_NETIF_EXT_STATUS_CALLBACK==1, + * this handled automatically for you. + * @param netif The network interface where settings have changed. + */ +#define mdns_resp_netif_settings_changed(netif) mdns_resp_announce(netif) + +#endif /* LWIP_MDNS_RESPONDER */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_MDNS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns_opts.h new file mode 100644 index 000000000..45f2c50ca --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns_opts.h @@ -0,0 +1,81 @@ +/** + * @file + * MDNS responder + */ + + /* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman + * + */ + +#ifndef LWIP_HDR_APPS_MDNS_OPTS_H +#define LWIP_HDR_APPS_MDNS_OPTS_H + +#include "lwip/opt.h" + +/** + * @defgroup mdns_opts Options + * @ingroup mdns + * @{ + */ + +/** + * LWIP_MDNS_RESPONDER==1: Turn on multicast DNS module. UDP must be available for MDNS + * transport. IGMP is needed for IPv4 multicast. + */ +#ifndef LWIP_MDNS_RESPONDER +#define LWIP_MDNS_RESPONDER 0 +#endif /* LWIP_MDNS_RESPONDER */ + +/** The maximum number of services per netif */ +#ifndef MDNS_MAX_SERVICES +#define MDNS_MAX_SERVICES 1 +#endif + +/** MDNS_RESP_USENETIF_EXTCALLBACK==1: register an ext_callback on the netif + * to automatically restart probing/announcing on status or address change. + */ +#ifndef MDNS_RESP_USENETIF_EXTCALLBACK +#define MDNS_RESP_USENETIF_EXTCALLBACK LWIP_NETIF_EXT_STATUS_CALLBACK +#endif + +/** + * MDNS_DEBUG: Enable debugging for multicast DNS. + */ +#ifndef MDNS_DEBUG +#define MDNS_DEBUG LWIP_DBG_OFF +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_APPS_MDNS_OPTS_H */ + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns_priv.h new file mode 100644 index 000000000..9635b5b10 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mdns_priv.h @@ -0,0 +1,74 @@ +/** + * @file + * MDNS responder private definitions + */ + + /* + * Copyright (c) 2015 Verisure Innovation AB + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Ekman + * + */ +#ifndef LWIP_HDR_MDNS_PRIV_H +#define LWIP_HDR_MDNS_PRIV_H + +#include "lwip/apps/mdns_opts.h" +#include "lwip/pbuf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_MDNS_RESPONDER + +/* Domain struct and methods - visible for unit tests */ + +#define MDNS_DOMAIN_MAXLEN 256 +#define MDNS_READNAME_ERROR 0xFFFF + +struct mdns_domain { + /* Encoded domain name */ + u8_t name[MDNS_DOMAIN_MAXLEN]; + /* Total length of domain name, including zero */ + u16_t length; + /* Set if compression of this domain is not allowed */ + u8_t skip_compression; +}; + +err_t mdns_domain_add_label(struct mdns_domain *domain, const char *label, u8_t len); +u16_t mdns_readname(struct pbuf *p, u16_t offset, struct mdns_domain *domain); +int mdns_domain_eq(struct mdns_domain *a, struct mdns_domain *b); +u16_t mdns_compress_domain(struct pbuf *pbuf, u16_t *offset, struct mdns_domain *domain); + +#endif /* LWIP_MDNS_RESPONDER */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_MDNS_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt.h new file mode 100644 index 000000000..c2bb2288f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt.h @@ -0,0 +1,205 @@ +/** + * @file + * MQTT client + */ + +/* + * Copyright (c) 2016 Erik Andersson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Andersson + * + */ +#ifndef LWIP_HDR_APPS_MQTT_CLIENT_H +#define LWIP_HDR_APPS_MQTT_CLIENT_H + +#include "lwip/apps/mqtt_opts.h" +#include "lwip/err.h" +#include "lwip/ip_addr.h" +#include "lwip/prot/iana.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mqtt_client_s mqtt_client_t; + +#if LWIP_ALTCP && LWIP_ALTCP_TLS +struct altcp_tls_config; +#endif + +/** @ingroup mqtt + * Default MQTT port (non-TLS) */ +#define MQTT_PORT LWIP_IANA_PORT_MQTT +/** @ingroup mqtt + * Default MQTT TLS port */ +#define MQTT_TLS_PORT LWIP_IANA_PORT_SECURE_MQTT + +/*---------------------------------------------------------------------------------------------- */ +/* Connection with server */ + +/** + * @ingroup mqtt + * Client information and connection parameters */ +struct mqtt_connect_client_info_t { + /** Client identifier, must be set by caller */ + const char *client_id; + /** User name, set to NULL if not used */ + const char* client_user; + /** Password, set to NULL if not used */ + const char* client_pass; + /** keep alive time in seconds, 0 to disable keep alive functionality*/ + u16_t keep_alive; + /** will topic, set to NULL if will is not to be used, + will_msg, will_qos and will retain are then ignored */ + const char* will_topic; + /** will_msg, see will_topic */ + const char* will_msg; + /** will_qos, see will_topic */ + u8_t will_qos; + /** will_retain, see will_topic */ + u8_t will_retain; +#if LWIP_ALTCP && LWIP_ALTCP_TLS + /** TLS configuration for secure connections */ + struct altcp_tls_config *tls_config; +#endif +}; + +/** + * @ingroup mqtt + * Connection status codes */ +typedef enum +{ + /** Accepted */ + MQTT_CONNECT_ACCEPTED = 0, + /** Refused protocol version */ + MQTT_CONNECT_REFUSED_PROTOCOL_VERSION = 1, + /** Refused identifier */ + MQTT_CONNECT_REFUSED_IDENTIFIER = 2, + /** Refused server */ + MQTT_CONNECT_REFUSED_SERVER = 3, + /** Refused user credentials */ + MQTT_CONNECT_REFUSED_USERNAME_PASS = 4, + /** Refused not authorized */ + MQTT_CONNECT_REFUSED_NOT_AUTHORIZED_ = 5, + /** Disconnected */ + MQTT_CONNECT_DISCONNECTED = 256, + /** Timeout */ + MQTT_CONNECT_TIMEOUT = 257 +} mqtt_connection_status_t; + +/** + * @ingroup mqtt + * Function prototype for mqtt connection status callback. Called when + * client has connected to the server after initiating a mqtt connection attempt by + * calling mqtt_client_connect() or when connection is closed by server or an error + * + * @param client MQTT client itself + * @param arg Additional argument to pass to the callback function + * @param status Connect result code or disconnection notification @see mqtt_connection_status_t + * + */ +typedef void (*mqtt_connection_cb_t)(mqtt_client_t *client, void *arg, mqtt_connection_status_t status); + + +/** + * @ingroup mqtt + * Data callback flags */ +enum { + /** Flag set when last fragment of data arrives in data callback */ + MQTT_DATA_FLAG_LAST = 1 +}; + +/** + * @ingroup mqtt + * Function prototype for MQTT incoming publish data callback function. Called when data + * arrives to a subscribed topic @see mqtt_subscribe + * + * @param arg Additional argument to pass to the callback function + * @param data User data, pointed object, data may not be referenced after callback return, + NULL is passed when all publish data are delivered + * @param len Length of publish data fragment + * @param flags MQTT_DATA_FLAG_LAST set when this call contains the last part of data from publish message + * + */ +typedef void (*mqtt_incoming_data_cb_t)(void *arg, const u8_t *data, u16_t len, u8_t flags); + + +/** + * @ingroup mqtt + * Function prototype for MQTT incoming publish function. Called when an incoming publish + * arrives to a subscribed topic @see mqtt_subscribe + * + * @param arg Additional argument to pass to the callback function + * @param topic Zero terminated Topic text string, topic may not be referenced after callback return + * @param tot_len Total length of publish data, if set to 0 (no publish payload) data callback will not be invoked + */ +typedef void (*mqtt_incoming_publish_cb_t)(void *arg, const char *topic, u32_t tot_len); + + +/** + * @ingroup mqtt + * Function prototype for mqtt request callback. Called when a subscribe, unsubscribe + * or publish request has completed + * @param arg Pointer to user data supplied when invoking request + * @param err ERR_OK on success + * ERR_TIMEOUT if no response was received within timeout, + * ERR_ABRT if (un)subscribe was denied + */ +typedef void (*mqtt_request_cb_t)(void *arg, err_t err); + + +err_t mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ipaddr, u16_t port, mqtt_connection_cb_t cb, void *arg, + const struct mqtt_connect_client_info_t *client_info); + +void mqtt_disconnect(mqtt_client_t *client); + +mqtt_client_t *mqtt_client_new(void); +void mqtt_client_free(mqtt_client_t* client); + +u8_t mqtt_client_is_connected(mqtt_client_t *client); + +void mqtt_set_inpub_callback(mqtt_client_t *client, mqtt_incoming_publish_cb_t, + mqtt_incoming_data_cb_t data_cb, void *arg); + +err_t mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_cb_t cb, void *arg, u8_t sub); + +/** @ingroup mqtt + *Subscribe to topic */ +#define mqtt_subscribe(client, topic, qos, cb, arg) mqtt_sub_unsub(client, topic, qos, cb, arg, 1) +/** @ingroup mqtt + * Unsubscribe to topic */ +#define mqtt_unsubscribe(client, topic, cb, arg) mqtt_sub_unsub(client, topic, 0, cb, arg, 0) + +err_t mqtt_publish(mqtt_client_t *client, const char *topic, const void *payload, u16_t payload_length, u8_t qos, u8_t retain, + mqtt_request_cb_t cb, void *arg); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_MQTT_CLIENT_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt_opts.h new file mode 100644 index 000000000..4226d21e8 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt_opts.h @@ -0,0 +1,103 @@ +/** + * @file + * MQTT client options + */ + +/* + * Copyright (c) 2016 Erik Andersson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Andersson + * + */ +#ifndef LWIP_HDR_APPS_MQTT_OPTS_H +#define LWIP_HDR_APPS_MQTT_OPTS_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup mqtt_opts Options + * @ingroup mqtt + * @{ + */ + +/** + * Output ring-buffer size, must be able to fit largest outgoing publish message topic+payloads + */ +#ifndef MQTT_OUTPUT_RINGBUF_SIZE +#define MQTT_OUTPUT_RINGBUF_SIZE 256 +#endif + +/** + * Number of bytes in receive buffer, must be at least the size of the longest incoming topic + 8 + * If one wants to avoid fragmented incoming publish, set length to max incoming topic length + max payload length + 8 + */ +#ifndef MQTT_VAR_HEADER_BUFFER_LEN +#define MQTT_VAR_HEADER_BUFFER_LEN 128 +#endif + +/** + * Maximum number of pending subscribe, unsubscribe and publish requests to server . + */ +#ifndef MQTT_REQ_MAX_IN_FLIGHT +#define MQTT_REQ_MAX_IN_FLIGHT 4 +#endif + +/** + * Seconds between each cyclic timer call. + */ +#ifndef MQTT_CYCLIC_TIMER_INTERVAL +#define MQTT_CYCLIC_TIMER_INTERVAL 5 +#endif + +/** + * Publish, subscribe and unsubscribe request timeout in seconds. + */ +#ifndef MQTT_REQ_TIMEOUT +#define MQTT_REQ_TIMEOUT 30 +#endif + +/** + * Seconds for MQTT connect response timeout after sending connect request + */ +#ifndef MQTT_CONNECT_TIMOUT +#define MQTT_CONNECT_TIMOUT 100 +#endif + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_MQTT_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt_priv.h new file mode 100644 index 000000000..b775913ca --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/mqtt_priv.h @@ -0,0 +1,104 @@ +/** + * @file + * MQTT client (private interface) + */ + +/* + * Copyright (c) 2016 Erik Andersson + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Erik Andersson + * + */ +#ifndef LWIP_HDR_APPS_MQTT_PRIV_H +#define LWIP_HDR_APPS_MQTT_PRIV_H + +#include "lwip/apps/mqtt.h" +#include "lwip/altcp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Pending request item, binds application callback to pending server requests */ +struct mqtt_request_t +{ + /** Next item in list, NULL means this is the last in chain, + next pointing at itself means request is unallocated */ + struct mqtt_request_t *next; + /** Callback to upper layer */ + mqtt_request_cb_t cb; + void *arg; + /** MQTT packet identifier */ + u16_t pkt_id; + /** Expire time relative to element before this */ + u16_t timeout_diff; +}; + +/** Ring buffer */ +struct mqtt_ringbuf_t { + u16_t put; + u16_t get; + u8_t buf[MQTT_OUTPUT_RINGBUF_SIZE]; +}; + +/** MQTT client */ +struct mqtt_client_s +{ + /** Timers and timeouts */ + u16_t cyclic_tick; + u16_t keep_alive; + u16_t server_watchdog; + /** Packet identifier generator*/ + u16_t pkt_id_seq; + /** Packet identifier of pending incoming publish */ + u16_t inpub_pkt_id; + /** Connection state */ + u8_t conn_state; + struct altcp_pcb *conn; + /** Connection callback */ + void *connect_arg; + mqtt_connection_cb_t connect_cb; + /** Pending requests to server */ + struct mqtt_request_t *pend_req_queue; + struct mqtt_request_t req_list[MQTT_REQ_MAX_IN_FLIGHT]; + void *inpub_arg; + /** Incoming data callback */ + mqtt_incoming_data_cb_t data_cb; + mqtt_incoming_publish_cb_t pub_cb; + /** Input */ + u32_t msg_idx; + u8_t rx_buffer[MQTT_VAR_HEADER_BUFFER_LEN]; + /** Output ring-buffer */ + struct mqtt_ringbuf_t output; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_MQTT_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/netbiosns.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/netbiosns.h new file mode 100644 index 000000000..a326d33b1 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/netbiosns.h @@ -0,0 +1,51 @@ +/** + * @file + * NETBIOS name service responder + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ +#ifndef LWIP_HDR_APPS_NETBIOS_H +#define LWIP_HDR_APPS_NETBIOS_H + +#include "lwip/apps/netbiosns_opts.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void netbiosns_init(void); +#ifndef NETBIOS_LWIP_NAME +void netbiosns_set_name(const char* hostname); +#endif +void netbiosns_stop(void); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_NETBIOS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/netbiosns_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/netbiosns_opts.h new file mode 100644 index 000000000..1f51ab02a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/netbiosns_opts.h @@ -0,0 +1,66 @@ +/** + * @file + * NETBIOS name service responder options + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ +#ifndef LWIP_HDR_APPS_NETBIOS_OPTS_H +#define LWIP_HDR_APPS_NETBIOS_OPTS_H + +#include "lwip/opt.h" + +/** + * @defgroup netbiosns_opts Options + * @ingroup netbiosns + * @{ + */ + +/** NetBIOS name of lwip device + * This must be uppercase until NETBIOS_STRCMP() is defined to a string + * comparision function that is case insensitive. + * If you want to use the netif's hostname, use this (with LWIP_NETIF_HOSTNAME): + * (ip_current_netif() != NULL ? ip_current_netif()->hostname != NULL ? ip_current_netif()->hostname : "" : "") + * + * If this is not defined, netbiosns_set_name() can be called at runtime to change the name. + */ +#ifdef __DOXYGEN__ +#define NETBIOS_LWIP_NAME "NETBIOSLWIPDEV" +#endif + +/** Respond to NetBIOS name queries + * Default is disabled + */ +#if !defined LWIP_NETBIOS_RESPOND_NAME_QUERY || defined __DOXYGEN__ +#define LWIP_NETBIOS_RESPOND_NAME_QUERY 0 +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_APPS_NETBIOS_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/smtp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/smtp.h new file mode 100644 index 000000000..fb4a4a7cc --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/smtp.h @@ -0,0 +1,128 @@ +#ifndef LWIP_HDR_APPS_SMTP_H +#define LWIP_HDR_APPS_SMTP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "lwip/apps/smtp_opts.h" +#include "lwip/err.h" +#include "lwip/prot/iana.h" + +/** The default TCP port used for SMTP */ +#define SMTP_DEFAULT_PORT LWIP_IANA_PORT_SMTP +/** The default TCP port used for SMTPS */ +#define SMTPS_DEFAULT_PORT LWIP_IANA_PORT_SMTPS + +/** Email successfully sent */ +#define SMTP_RESULT_OK 0 +/** Unknown error */ +#define SMTP_RESULT_ERR_UNKNOWN 1 +/** Connection to server failed */ +#define SMTP_RESULT_ERR_CONNECT 2 +/** Failed to resolve server hostname */ +#define SMTP_RESULT_ERR_HOSTNAME 3 +/** Connection unexpectedly closed by remote server */ +#define SMTP_RESULT_ERR_CLOSED 4 +/** Connection timed out (server didn't respond in time) */ +#define SMTP_RESULT_ERR_TIMEOUT 5 +/** Server responded with an unknown response code */ +#define SMTP_RESULT_ERR_SVR_RESP 6 +/** Out of resources locally */ +#define SMTP_RESULT_ERR_MEM 7 + +/** Prototype of an smtp callback function + * + * @param arg argument specified when initiating the email + * @param smtp_result result of the mail transfer (see defines SMTP_RESULT_*) + * @param srv_err if aborted by the server, this contains the error code received + * @param err an error returned by internal lwip functions, can help to specify + * the source of the error but must not necessarily be != ERR_OK + */ +typedef void (*smtp_result_fn)(void *arg, u8_t smtp_result, u16_t srv_err, err_t err); + +/** This structure is used as argument for smtp_send_mail_int(), + * which in turn can be used with tcpip_callback() to send mail + * from interrupt context, e.g. like this: + * struct smtp_send_request *req; (to be filled) + * tcpip_try_callback(smtp_send_mail_int, (void*)req); + * + * For member description, see parameter description of smtp_send_mail(). + * When using with tcpip_callback, this structure has to stay allocated + * (e.g. using mem_malloc/mem_free) until its 'callback_fn' is called. + */ +struct smtp_send_request { + const char *from; + const char* to; + const char* subject; + const char* body; + smtp_result_fn callback_fn; + void* callback_arg; + /** If this is != 0, data is *not* copied into an extra buffer + * but used from the pointers supplied in this struct. + * This means less memory usage, but data must stay untouched until + * the callback function is called. */ + u8_t static_data; +}; + + +#if SMTP_BODYDH + +#ifndef SMTP_BODYDH_BUFFER_SIZE +#define SMTP_BODYDH_BUFFER_SIZE 256 +#endif /* SMTP_BODYDH_BUFFER_SIZE */ + +struct smtp_bodydh { + u16_t state; + u16_t length; /* Length of content in buffer */ + char buffer[SMTP_BODYDH_BUFFER_SIZE]; /* buffer for generated content */ +#ifdef SMTP_BODYDH_USER_SIZE + u8_t user[SMTP_BODYDH_USER_SIZE]; +#endif /* SMTP_BODYDH_USER_SIZE */ +}; + +enum bdh_retvals_e { + BDH_DONE = 0, + BDH_WORKING +}; + +/** Prototype of an smtp body callback function + * It receives a struct smtp_bodydh, and a buffer to write data, + * must return BDH_WORKING to be called again and BDH_DONE when + * it has finished processing. This one tries to fill one TCP buffer with + * data, your function will be repeatedly called until that happens; so if you + * know you'll be taking too long to serve your request, pause once in a while + * by writing length=0 to avoid hogging system resources + * + * @param arg argument specified when initiating the email + * @param smtp_bodydh state handling + buffer structure + */ +typedef int (*smtp_bodycback_fn)(void *arg, struct smtp_bodydh *bodydh); + +err_t smtp_send_mail_bodycback(const char *from, const char* to, const char* subject, + smtp_bodycback_fn bodycback_fn, smtp_result_fn callback_fn, void* callback_arg); + +#endif /* SMTP_BODYDH */ + + +err_t smtp_set_server_addr(const char* server); +void smtp_set_server_port(u16_t port); +#if LWIP_ALTCP && LWIP_ALTCP_TLS +struct altcp_tls_config; +void smtp_set_tls_config(struct altcp_tls_config *tls_config); +#endif +err_t smtp_set_auth(const char* username, const char* pass); +err_t smtp_send_mail(const char *from, const char* to, const char* subject, const char* body, + smtp_result_fn callback_fn, void* callback_arg); +err_t smtp_send_mail_static(const char *from, const char* to, const char* subject, const char* body, + smtp_result_fn callback_fn, void* callback_arg); +void smtp_send_mail_int(void *arg); +#ifdef LWIP_DEBUG +const char* smtp_result_str(u8_t smtp_result); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SMTP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/smtp_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/smtp_opts.h new file mode 100644 index 000000000..bc743f679 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/smtp_opts.h @@ -0,0 +1,81 @@ +#ifndef LWIP_HDR_APPS_SMTP_OPTS_H +#define LWIP_HDR_APPS_SMTP_OPTS_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup smtp_opts Options + * @ingroup smtp + * + * @{ + */ + +/** Set this to 1 to enable data handler callback on BODY */ +#ifndef SMTP_BODYDH +#define SMTP_BODYDH 0 +#endif + +/** SMTP_DEBUG: Enable debugging for SNTP. */ +#ifndef SMTP_DEBUG +#define SMTP_DEBUG LWIP_DBG_OFF +#endif + +/** Maximum length reserved for server name including terminating 0 byte */ +#ifndef SMTP_MAX_SERVERNAME_LEN +#define SMTP_MAX_SERVERNAME_LEN 256 +#endif + +/** Maximum length reserved for username */ +#ifndef SMTP_MAX_USERNAME_LEN +#define SMTP_MAX_USERNAME_LEN 32 +#endif + +/** Maximum length reserved for password */ +#ifndef SMTP_MAX_PASS_LEN +#define SMTP_MAX_PASS_LEN 32 +#endif + +/** Set this to 0 if you know the authentication data will not change + * during the smtp session, which saves some heap space. */ +#ifndef SMTP_COPY_AUTHDATA +#define SMTP_COPY_AUTHDATA 1 +#endif + +/** Set this to 0 to save some code space if you know for sure that all data + * passed to this module conforms to the requirements in the SMTP RFC. + * WARNING: use this with care! + */ +#ifndef SMTP_CHECK_DATA +#define SMTP_CHECK_DATA 1 +#endif + +/** Set this to 1 to enable AUTH PLAIN support */ +#ifndef SMTP_SUPPORT_AUTH_PLAIN +#define SMTP_SUPPORT_AUTH_PLAIN 1 +#endif + +/** Set this to 1 to enable AUTH LOGIN support */ +#ifndef SMTP_SUPPORT_AUTH_LOGIN +#define SMTP_SUPPORT_AUTH_LOGIN 1 +#endif + +/* Memory allocation/deallocation can be overridden... */ +#ifndef SMTP_STATE_MALLOC +#define SMTP_STATE_MALLOC(size) mem_malloc(size) +#define SMTP_STATE_FREE(ptr) mem_free(ptr) +#endif + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* SMTP_OPTS_H */ + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp.h new file mode 100644 index 000000000..a3f8eb150 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp.h @@ -0,0 +1,135 @@ +/** + * @file + * SNMP server main API - start and basic configuration + */ + +/* + * Copyright (c) 2001, 2002 Leon Woestenberg + * Copyright (c) 2001, 2002 Axon Digital Design B.V., The Netherlands. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Leon Woestenberg + * Martin Hentschel + * + */ +#ifndef LWIP_HDR_APPS_SNMP_H +#define LWIP_HDR_APPS_SNMP_H + +#include "lwip/apps/snmp_opts.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/err.h" +#include "lwip/apps/snmp_core.h" + +/** SNMP variable binding descriptor (publically needed for traps) */ +struct snmp_varbind +{ + /** pointer to next varbind, NULL for last in list */ + struct snmp_varbind *next; + /** pointer to previous varbind, NULL for first in list */ + struct snmp_varbind *prev; + + /** object identifier */ + struct snmp_obj_id oid; + + /** value ASN1 type */ + u8_t type; + /** object value length */ + u16_t value_len; + /** object value */ + void *value; +}; + +/** + * @ingroup snmp_core + * Agent setup, start listening to port 161. + */ +void snmp_init(void); +void snmp_set_mibs(const struct snmp_mib **mibs, u8_t num_mibs); + +void snmp_set_device_enterprise_oid(const struct snmp_obj_id* device_enterprise_oid); +const struct snmp_obj_id* snmp_get_device_enterprise_oid(void); + +void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable); +void snmp_trap_dst_ip_set(u8_t dst_idx, const ip_addr_t *dst); + +/** Generic trap: cold start */ +#define SNMP_GENTRAP_COLDSTART 0 +/** Generic trap: warm start */ +#define SNMP_GENTRAP_WARMSTART 1 +/** Generic trap: link down */ +#define SNMP_GENTRAP_LINKDOWN 2 +/** Generic trap: link up */ +#define SNMP_GENTRAP_LINKUP 3 +/** Generic trap: authentication failure */ +#define SNMP_GENTRAP_AUTH_FAILURE 4 +/** Generic trap: EGP neighbor lost */ +#define SNMP_GENTRAP_EGP_NEIGHBOR_LOSS 5 +/** Generic trap: enterprise specific */ +#define SNMP_GENTRAP_ENTERPRISE_SPECIFIC 6 + +err_t snmp_send_trap_generic(s32_t generic_trap); +err_t snmp_send_trap_specific(s32_t specific_trap, struct snmp_varbind *varbinds); +err_t snmp_send_trap(const struct snmp_obj_id* oid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds); + +#define SNMP_AUTH_TRAPS_DISABLED 0 +#define SNMP_AUTH_TRAPS_ENABLED 1 +void snmp_set_auth_traps_enabled(u8_t enable); +u8_t snmp_get_auth_traps_enabled(void); + +u8_t snmp_v1_enabled(void); +u8_t snmp_v2c_enabled(void); +u8_t snmp_v3_enabled(void); +void snmp_v1_enable(u8_t enable); +void snmp_v2c_enable(u8_t enable); +void snmp_v3_enable(u8_t enable); + +const char * snmp_get_community(void); +const char * snmp_get_community_write(void); +const char * snmp_get_community_trap(void); +void snmp_set_community(const char * const community); +void snmp_set_community_write(const char * const community); +void snmp_set_community_trap(const char * const community); + +void snmp_coldstart_trap(void); +void snmp_authfail_trap(void); + +typedef void (*snmp_write_callback_fct)(const u32_t* oid, u8_t oid_len, void* callback_arg); +void snmp_set_write_callback(snmp_write_callback_fct write_callback, void* callback_arg); + +#endif /* LWIP_SNMP */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SNMP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_core.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_core.h new file mode 100644 index 000000000..6021c7222 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_core.h @@ -0,0 +1,377 @@ +/** + * @file + * SNMP core API for implementing MIBs + */ + +/* + * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Christiaan Simons + * Martin Hentschel + */ + +#ifndef LWIP_HDR_APPS_SNMP_CORE_H +#define LWIP_HDR_APPS_SNMP_CORE_H + +#include "lwip/apps/snmp_opts.h" + +#if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/ip_addr.h" +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* basic ASN1 defines */ +#define SNMP_ASN1_CLASS_UNIVERSAL 0x00 +#define SNMP_ASN1_CLASS_APPLICATION 0x40 +#define SNMP_ASN1_CLASS_CONTEXT 0x80 +#define SNMP_ASN1_CLASS_PRIVATE 0xC0 + +#define SNMP_ASN1_CONTENTTYPE_PRIMITIVE 0x00 +#define SNMP_ASN1_CONTENTTYPE_CONSTRUCTED 0x20 + +/* universal tags (from ASN.1 spec.) */ +#define SNMP_ASN1_UNIVERSAL_END_OF_CONTENT 0 +#define SNMP_ASN1_UNIVERSAL_INTEGER 2 +#define SNMP_ASN1_UNIVERSAL_OCTET_STRING 4 +#define SNMP_ASN1_UNIVERSAL_NULL 5 +#define SNMP_ASN1_UNIVERSAL_OBJECT_ID 6 +#define SNMP_ASN1_UNIVERSAL_SEQUENCE_OF 16 + +/* application specific (SNMP) tags (from SNMPv2-SMI) */ +#define SNMP_ASN1_APPLICATION_IPADDR 0 /* [APPLICATION 0] IMPLICIT OCTET STRING (SIZE (4)) */ +#define SNMP_ASN1_APPLICATION_COUNTER 1 /* [APPLICATION 1] IMPLICIT INTEGER (0..4294967295) => u32_t */ +#define SNMP_ASN1_APPLICATION_GAUGE 2 /* [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) => u32_t */ +#define SNMP_ASN1_APPLICATION_TIMETICKS 3 /* [APPLICATION 3] IMPLICIT INTEGER (0..4294967295) => u32_t */ +#define SNMP_ASN1_APPLICATION_OPAQUE 4 /* [APPLICATION 4] IMPLICIT OCTET STRING */ +#define SNMP_ASN1_APPLICATION_COUNTER64 6 /* [APPLICATION 6] IMPLICIT INTEGER (0..18446744073709551615) */ + +/* context specific (SNMP) tags (from RFC 1905) */ +#define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_INSTANCE 1 + +/* full ASN1 type defines */ +#define SNMP_ASN1_TYPE_END_OF_CONTENT (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_END_OF_CONTENT) +#define SNMP_ASN1_TYPE_INTEGER (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_INTEGER) +#define SNMP_ASN1_TYPE_OCTET_STRING (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_OCTET_STRING) +#define SNMP_ASN1_TYPE_NULL (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_NULL) +#define SNMP_ASN1_TYPE_OBJECT_ID (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_OBJECT_ID) +#define SNMP_ASN1_TYPE_SEQUENCE (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_CONSTRUCTED | SNMP_ASN1_UNIVERSAL_SEQUENCE_OF) +#define SNMP_ASN1_TYPE_IPADDR (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_IPADDR) +#define SNMP_ASN1_TYPE_IPADDRESS SNMP_ASN1_TYPE_IPADDR +#define SNMP_ASN1_TYPE_COUNTER (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_COUNTER) +#define SNMP_ASN1_TYPE_COUNTER32 SNMP_ASN1_TYPE_COUNTER +#define SNMP_ASN1_TYPE_GAUGE (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_GAUGE) +#define SNMP_ASN1_TYPE_GAUGE32 SNMP_ASN1_TYPE_GAUGE +#define SNMP_ASN1_TYPE_UNSIGNED32 SNMP_ASN1_TYPE_GAUGE +#define SNMP_ASN1_TYPE_TIMETICKS (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_TIMETICKS) +#define SNMP_ASN1_TYPE_OPAQUE (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_OPAQUE) +#if LWIP_HAVE_INT64 +#define SNMP_ASN1_TYPE_COUNTER64 (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_COUNTER64) +#endif + +#define SNMP_VARBIND_EXCEPTION_OFFSET 0xF0 +#define SNMP_VARBIND_EXCEPTION_MASK 0x0F + +/** error codes predefined by SNMP prot. */ +typedef enum { + SNMP_ERR_NOERROR = 0, +/* +outdated v1 error codes. do not use anmore! +#define SNMP_ERR_NOSUCHNAME 2 use SNMP_ERR_NOSUCHINSTANCE instead +#define SNMP_ERR_BADVALUE 3 use SNMP_ERR_WRONGTYPE,SNMP_ERR_WRONGLENGTH,SNMP_ERR_WRONGENCODING or SNMP_ERR_WRONGVALUE instead +#define SNMP_ERR_READONLY 4 use SNMP_ERR_NOTWRITABLE instead +*/ + SNMP_ERR_GENERROR = 5, + SNMP_ERR_NOACCESS = 6, + SNMP_ERR_WRONGTYPE = 7, + SNMP_ERR_WRONGLENGTH = 8, + SNMP_ERR_WRONGENCODING = 9, + SNMP_ERR_WRONGVALUE = 10, + SNMP_ERR_NOCREATION = 11, + SNMP_ERR_INCONSISTENTVALUE = 12, + SNMP_ERR_RESOURCEUNAVAILABLE = 13, + SNMP_ERR_COMMITFAILED = 14, + SNMP_ERR_UNDOFAILED = 15, + SNMP_ERR_NOTWRITABLE = 17, + SNMP_ERR_INCONSISTENTNAME = 18, + + SNMP_ERR_NOSUCHINSTANCE = SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_INSTANCE +} snmp_err_t; + +/** internal object identifier representation */ +struct snmp_obj_id +{ + u8_t len; + u32_t id[SNMP_MAX_OBJ_ID_LEN]; +}; + +struct snmp_obj_id_const_ref +{ + u8_t len; + const u32_t* id; +}; + +extern const struct snmp_obj_id_const_ref snmp_zero_dot_zero; /* administrative identifier from SNMPv2-SMI */ + +/** SNMP variant value, used as reference in struct snmp_node_instance and table implementation */ +union snmp_variant_value +{ + void* ptr; + const void* const_ptr; + u32_t u32; + s32_t s32; +#if LWIP_HAVE_INT64 + u64_t u64; +#endif +}; + + +/** +SNMP MIB node types + tree node is the only node the stack can process in order to walk the tree, + all other nodes are assumed to be leaf nodes. + This cannot be an enum because users may want to define their own node types. +*/ +#define SNMP_NODE_TREE 0x00 +/* predefined leaf node types */ +#define SNMP_NODE_SCALAR 0x01 +#define SNMP_NODE_SCALAR_ARRAY 0x02 +#define SNMP_NODE_TABLE 0x03 +#define SNMP_NODE_THREADSYNC 0x04 + +/** node "base class" layout, the mandatory fields for a node */ +struct snmp_node +{ + /** one out of SNMP_NODE_TREE or any leaf node type (like SNMP_NODE_SCALAR) */ + u8_t node_type; + /** the number assigned to this node which used as part of the full OID */ + u32_t oid; +}; + +/** SNMP node instance access types */ +typedef enum { + SNMP_NODE_INSTANCE_ACCESS_READ = 1, + SNMP_NODE_INSTANCE_ACCESS_WRITE = 2, + SNMP_NODE_INSTANCE_READ_ONLY = SNMP_NODE_INSTANCE_ACCESS_READ, + SNMP_NODE_INSTANCE_READ_WRITE = (SNMP_NODE_INSTANCE_ACCESS_READ | SNMP_NODE_INSTANCE_ACCESS_WRITE), + SNMP_NODE_INSTANCE_WRITE_ONLY = SNMP_NODE_INSTANCE_ACCESS_WRITE, + SNMP_NODE_INSTANCE_NOT_ACCESSIBLE = 0 +} snmp_access_t; + +struct snmp_node_instance; + +typedef s16_t (*node_instance_get_value_method)(struct snmp_node_instance*, void*); +typedef snmp_err_t (*node_instance_set_test_method)(struct snmp_node_instance*, u16_t, void*); +typedef snmp_err_t (*node_instance_set_value_method)(struct snmp_node_instance*, u16_t, void*); +typedef void (*node_instance_release_method)(struct snmp_node_instance*); + +#define SNMP_GET_VALUE_RAW_DATA 0x4000 /* do not use 0x8000 because return value of node_instance_get_value_method is signed16 and 0x8000 would be the signed bit */ + +/** SNMP node instance */ +struct snmp_node_instance +{ + /** prefilled with the node, get_instance() is called on; may be changed by user to any value to pass an arbitrary node between calls to get_instance() and get_value/test_value/set_value */ + const struct snmp_node* node; + /** prefilled with the instance id requested; for get_instance() this is the exact oid requested; for get_next_instance() this is the relative starting point, stack expects relative oid of next node here */ + struct snmp_obj_id instance_oid; + + /** ASN type for this object (see snmp_asn1.h for definitions) */ + u8_t asn1_type; + /** one out of instance access types defined above (SNMP_NODE_INSTANCE_READ_ONLY,...) */ + snmp_access_t access; + + /** returns object value for the given object identifier. Return values <0 to indicate an error */ + node_instance_get_value_method get_value; + /** tests length and/or range BEFORE setting */ + node_instance_set_test_method set_test; + /** sets object value, only called when set_test() was successful */ + node_instance_set_value_method set_value; + /** called in any case when the instance is not required anymore by stack (useful for freeing memory allocated in get_instance/get_next_instance methods) */ + node_instance_release_method release_instance; + + /** reference to pass arbitrary value between calls to get_instance() and get_value/test_value/set_value */ + union snmp_variant_value reference; + /** see reference (if reference is a pointer, the length of underlying data may be stored here or anything else) */ + u32_t reference_len; +}; + + +/** SNMP tree node */ +struct snmp_tree_node +{ + /** inherited "base class" members */ + struct snmp_node node; + u16_t subnode_count; + const struct snmp_node* const *subnodes; +}; + +#define SNMP_CREATE_TREE_NODE(oid, subnodes) \ + {{ SNMP_NODE_TREE, (oid) }, \ + (u16_t)LWIP_ARRAYSIZE(subnodes), (subnodes) } + +#define SNMP_CREATE_EMPTY_TREE_NODE(oid) \ + {{ SNMP_NODE_TREE, (oid) }, \ + 0, NULL } + +/** SNMP leaf node */ +struct snmp_leaf_node +{ + /** inherited "base class" members */ + struct snmp_node node; + snmp_err_t (*get_instance)(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); + snmp_err_t (*get_next_instance)(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); +}; + +/** represents a single mib with its base oid and root node */ +struct snmp_mib +{ + const u32_t *base_oid; + u8_t base_oid_len; + const struct snmp_node *root_node; +}; + +#define SNMP_MIB_CREATE(oid_list, root_node) { (oid_list), (u8_t)LWIP_ARRAYSIZE(oid_list), root_node } + +/** OID range structure */ +struct snmp_oid_range +{ + u32_t min; + u32_t max; +}; + +/** checks if incoming OID length and values are in allowed ranges */ +u8_t snmp_oid_in_range(const u32_t *oid_in, u8_t oid_len, const struct snmp_oid_range *oid_ranges, u8_t oid_ranges_len); + +typedef enum { + SNMP_NEXT_OID_STATUS_SUCCESS, + SNMP_NEXT_OID_STATUS_NO_MATCH, + SNMP_NEXT_OID_STATUS_BUF_TO_SMALL +} snmp_next_oid_status_t; + +/** state for next_oid_init / next_oid_check functions */ +struct snmp_next_oid_state +{ + const u32_t* start_oid; + u8_t start_oid_len; + + u32_t* next_oid; + u8_t next_oid_len; + u8_t next_oid_max_len; + + snmp_next_oid_status_t status; + void* reference; +}; + +void snmp_next_oid_init(struct snmp_next_oid_state *state, + const u32_t *start_oid, u8_t start_oid_len, + u32_t *next_oid_buf, u8_t next_oid_max_len); +u8_t snmp_next_oid_precheck(struct snmp_next_oid_state *state, const u32_t *oid, u8_t oid_len); +u8_t snmp_next_oid_check(struct snmp_next_oid_state *state, const u32_t *oid, u8_t oid_len, void* reference); + +void snmp_oid_assign(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len); +void snmp_oid_combine(struct snmp_obj_id* target, const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len); +void snmp_oid_prefix(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len); +void snmp_oid_append(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len); +u8_t snmp_oid_equal(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len); +s8_t snmp_oid_compare(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len); + +#if LWIP_IPV4 +u8_t snmp_oid_to_ip4(const u32_t *oid, ip4_addr_t *ip); +void snmp_ip4_to_oid(const ip4_addr_t *ip, u32_t *oid); +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 +u8_t snmp_oid_to_ip6(const u32_t *oid, ip6_addr_t *ip); +void snmp_ip6_to_oid(const ip6_addr_t *ip, u32_t *oid); +#endif /* LWIP_IPV6 */ +#if LWIP_IPV4 || LWIP_IPV6 +u8_t snmp_ip_to_oid(const ip_addr_t *ip, u32_t *oid); +u8_t snmp_ip_port_to_oid(const ip_addr_t *ip, u16_t port, u32_t *oid); + +u8_t snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip); +u8_t snmp_oid_to_ip_port(const u32_t *oid, u8_t oid_len, ip_addr_t *ip, u16_t *port); +#endif /* LWIP_IPV4 || LWIP_IPV6 */ + +struct netif; +u8_t netif_to_num(const struct netif *netif); + +snmp_err_t snmp_set_test_ok(struct snmp_node_instance* instance, u16_t value_len, void* value); /* generic function which can be used if test is always successful */ + +err_t snmp_decode_bits(const u8_t *buf, u32_t buf_len, u32_t *bit_value); +err_t snmp_decode_truthvalue(const s32_t *asn1_value, u8_t *bool_value); +u8_t snmp_encode_bits(u8_t *buf, u32_t buf_len, u32_t bit_value, u8_t bit_count); +u8_t snmp_encode_truthvalue(s32_t *asn1_value, u32_t bool_value); + +struct snmp_statistics +{ + u32_t inpkts; + u32_t outpkts; + u32_t inbadversions; + u32_t inbadcommunitynames; + u32_t inbadcommunityuses; + u32_t inasnparseerrs; + u32_t intoobigs; + u32_t innosuchnames; + u32_t inbadvalues; + u32_t inreadonlys; + u32_t ingenerrs; + u32_t intotalreqvars; + u32_t intotalsetvars; + u32_t ingetrequests; + u32_t ingetnexts; + u32_t insetrequests; + u32_t ingetresponses; + u32_t intraps; + u32_t outtoobigs; + u32_t outnosuchnames; + u32_t outbadvalues; + u32_t outgenerrs; + u32_t outgetrequests; + u32_t outgetnexts; + u32_t outsetrequests; + u32_t outgetresponses; + u32_t outtraps; +#if LWIP_SNMP_V3 + u32_t unsupportedseclevels; + u32_t notintimewindows; + u32_t unknownusernames; + u32_t unknownengineids; + u32_t wrongdigests; + u32_t decryptionerrors; +#endif +}; + +extern struct snmp_statistics snmp_stats; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_SNMP */ + +#endif /* LWIP_HDR_APPS_SNMP_CORE_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_mib2.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_mib2.h new file mode 100644 index 000000000..2f4a68935 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_mib2.h @@ -0,0 +1,78 @@ +/** + * @file + * SNMP MIB2 API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Dirk Ziegelmeier + * + */ +#ifndef LWIP_HDR_APPS_SNMP_MIB2_H +#define LWIP_HDR_APPS_SNMP_MIB2_H + +#include "lwip/apps/snmp_opts.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ +#if SNMP_LWIP_MIB2 + +#include "lwip/apps/snmp_core.h" + +extern const struct snmp_mib mib2; + +#if SNMP_USE_NETCONN +#include "lwip/apps/snmp_threadsync.h" +void snmp_mib2_lwip_synchronizer(snmp_threadsync_called_fn fn, void* arg); +extern struct snmp_threadsync_instance snmp_mib2_lwip_locks; +#endif + +#ifndef SNMP_SYSSERVICES +#define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2)) +#endif + +void snmp_mib2_set_sysdescr(const u8_t* str, const u16_t* len); /* read-only be defintion */ +void snmp_mib2_set_syscontact(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize); +void snmp_mib2_set_syscontact_readonly(const u8_t *ocstr, const u16_t *ocstrlen); +void snmp_mib2_set_sysname(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize); +void snmp_mib2_set_sysname_readonly(const u8_t *ocstr, const u16_t *ocstrlen); +void snmp_mib2_set_syslocation(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize); +void snmp_mib2_set_syslocation_readonly(const u8_t *ocstr, const u16_t *ocstrlen); + +#endif /* SNMP_LWIP_MIB2 */ +#endif /* LWIP_SNMP */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SNMP_MIB2_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_opts.h new file mode 100644 index 000000000..c892d22af --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_opts.h @@ -0,0 +1,297 @@ +/** + * @file + * SNMP server options list + */ + +/* + * Copyright (c) 2015 Dirk Ziegelmeier + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Dirk Ziegelmeier + * + */ +#ifndef LWIP_HDR_SNMP_OPTS_H +#define LWIP_HDR_SNMP_OPTS_H + +#include "lwip/opt.h" + +/** + * @defgroup snmp_opts Options + * @ingroup snmp + * @{ + */ + +/** + * LWIP_SNMP==1: This enables the lwIP SNMP agent. UDP must be available + * for SNMP transport. + * If you want to use your own SNMP agent, leave this disabled. + * To integrate MIB2 of an external agent, you need to enable + * LWIP_MIB2_CALLBACKS and MIB2_STATS. This will give you the callbacks + * and statistics counters you need to get MIB2 working. + */ +#if !defined LWIP_SNMP || defined __DOXYGEN__ +#define LWIP_SNMP 0 +#endif + +/** + * SNMP_USE_NETCONN: Use netconn API instead of raw API. + * Makes SNMP agent run in a worker thread, so blocking operations + * can be done in MIB calls. + */ +#if !defined SNMP_USE_NETCONN || defined __DOXYGEN__ +#define SNMP_USE_NETCONN 0 +#endif + +/** + * SNMP_USE_RAW: Use raw API. + * SNMP agent does not run in a worker thread, so blocking operations + * should not be done in MIB calls. + */ +#if !defined SNMP_USE_RAW || defined __DOXYGEN__ +#define SNMP_USE_RAW 1 +#endif + +#if SNMP_USE_NETCONN && SNMP_USE_RAW +#error SNMP stack can use only one of the APIs {raw, netconn} +#endif + +#if LWIP_SNMP && !SNMP_USE_NETCONN && !SNMP_USE_RAW +#error SNMP stack needs a receive API and UDP {raw, netconn} +#endif + +#if SNMP_USE_NETCONN +/** + * SNMP_STACK_SIZE: Stack size of SNMP netconn worker thread + */ +#if !defined SNMP_STACK_SIZE || defined __DOXYGEN__ +#define SNMP_STACK_SIZE DEFAULT_THREAD_STACKSIZE +#endif + +/** + * SNMP_THREAD_PRIO: SNMP netconn worker thread priority + */ +#if !defined SNMP_THREAD_PRIO || defined __DOXYGEN__ +#define SNMP_THREAD_PRIO DEFAULT_THREAD_PRIO +#endif +#endif /* SNMP_USE_NETCONN */ + +/** + * SNMP_TRAP_DESTINATIONS: Number of trap destinations. At least one trap + * destination is required + */ +#if !defined SNMP_TRAP_DESTINATIONS || defined __DOXYGEN__ +#define SNMP_TRAP_DESTINATIONS 1 +#endif + +/** + * Only allow SNMP write actions that are 'safe' (e.g. disabling netifs is not + * a safe action and disabled when SNMP_SAFE_REQUESTS = 1). + * Unsafe requests are disabled by default! + */ +#if !defined SNMP_SAFE_REQUESTS || defined __DOXYGEN__ +#define SNMP_SAFE_REQUESTS 1 +#endif + +/** + * The maximum length of strings used. + */ +#if !defined SNMP_MAX_OCTET_STRING_LEN || defined __DOXYGEN__ +#define SNMP_MAX_OCTET_STRING_LEN 127 +#endif + +/** + * The maximum number of Sub ID's inside an object identifier. + * Indirectly this also limits the maximum depth of SNMP tree. + */ +#if !defined SNMP_MAX_OBJ_ID_LEN || defined __DOXYGEN__ +#define SNMP_MAX_OBJ_ID_LEN 50 +#endif + +#if !defined SNMP_MAX_VALUE_SIZE || defined __DOXYGEN__ +/** + * The minimum size of a value. + */ +#define SNMP_MIN_VALUE_SIZE (2 * sizeof(u32_t*)) /* size required to store the basic types (8 bytes for counter64) */ +/** + * The maximum size of a value. + */ +#define SNMP_MAX_VALUE_SIZE LWIP_MAX(LWIP_MAX((SNMP_MAX_OCTET_STRING_LEN), sizeof(u32_t)*(SNMP_MAX_OBJ_ID_LEN)), SNMP_MIN_VALUE_SIZE) +#endif + +/** + * The snmp read-access community. Used for write-access and traps, too + * unless SNMP_COMMUNITY_WRITE or SNMP_COMMUNITY_TRAP are enabled, respectively. + */ +#if !defined SNMP_COMMUNITY || defined __DOXYGEN__ +#define SNMP_COMMUNITY "public" +#endif + +/** + * The snmp write-access community. + * Set this community to "" in order to disallow any write access. + */ +#if !defined SNMP_COMMUNITY_WRITE || defined __DOXYGEN__ +#define SNMP_COMMUNITY_WRITE "private" +#endif + +/** + * The snmp community used for sending traps. + */ +#if !defined SNMP_COMMUNITY_TRAP || defined __DOXYGEN__ +#define SNMP_COMMUNITY_TRAP "public" +#endif + +/** + * The maximum length of community string. + * If community names shall be adjusted at runtime via snmp_set_community() calls, + * enter here the possible maximum length (+1 for terminating null character). + */ +#if !defined SNMP_MAX_COMMUNITY_STR_LEN || defined __DOXYGEN__ +#define SNMP_MAX_COMMUNITY_STR_LEN LWIP_MAX(LWIP_MAX(sizeof(SNMP_COMMUNITY), sizeof(SNMP_COMMUNITY_WRITE)), sizeof(SNMP_COMMUNITY_TRAP)) +#endif + +/** + * The OID identifiying the device. This may be the enterprise OID itself or any OID located below it in tree. + */ +#if !defined SNMP_DEVICE_ENTERPRISE_OID || defined __DOXYGEN__ +#define SNMP_LWIP_ENTERPRISE_OID 26381 +/** + * IANA assigned enterprise ID for lwIP is 26381 + * @see http://www.iana.org/assignments/enterprise-numbers + * + * @note this enterprise ID is assigned to the lwIP project, + * all object identifiers living under this ID are assigned + * by the lwIP maintainers! + * @note don't change this define, use snmp_set_device_enterprise_oid() + * + * If you need to create your own private MIB you'll need + * to apply for your own enterprise ID with IANA: + * http://www.iana.org/numbers.html + */ +#define SNMP_DEVICE_ENTERPRISE_OID {1, 3, 6, 1, 4, 1, SNMP_LWIP_ENTERPRISE_OID} +/** + * Length of SNMP_DEVICE_ENTERPRISE_OID + */ +#define SNMP_DEVICE_ENTERPRISE_OID_LEN 7 +#endif + +/** + * SNMP_DEBUG: Enable debugging for SNMP messages. + */ +#if !defined SNMP_DEBUG || defined __DOXYGEN__ +#define SNMP_DEBUG LWIP_DBG_OFF +#endif + +/** + * SNMP_MIB_DEBUG: Enable debugging for SNMP MIBs. + */ +#if !defined SNMP_MIB_DEBUG || defined __DOXYGEN__ +#define SNMP_MIB_DEBUG LWIP_DBG_OFF +#endif + +/** + * Indicates if the MIB2 implementation of LWIP SNMP stack is used. + */ +#if !defined SNMP_LWIP_MIB2 || defined __DOXYGEN__ +#define SNMP_LWIP_MIB2 LWIP_SNMP +#endif + +/** + * Value return for sysDesc field of MIB2. + */ +#if !defined SNMP_LWIP_MIB2_SYSDESC || defined __DOXYGEN__ +#define SNMP_LWIP_MIB2_SYSDESC "lwIP" +#endif + +/** + * Value return for sysName field of MIB2. + * To make sysName field settable, call snmp_mib2_set_sysname() to provide the necessary buffers. + */ +#if !defined SNMP_LWIP_MIB2_SYSNAME || defined __DOXYGEN__ +#define SNMP_LWIP_MIB2_SYSNAME "FQDN-unk" +#endif + +/** + * Value return for sysContact field of MIB2. + * To make sysContact field settable, call snmp_mib2_set_syscontact() to provide the necessary buffers. + */ +#if !defined SNMP_LWIP_MIB2_SYSCONTACT || defined __DOXYGEN__ +#define SNMP_LWIP_MIB2_SYSCONTACT "" +#endif + +/** + * Value return for sysLocation field of MIB2. + * To make sysLocation field settable, call snmp_mib2_set_syslocation() to provide the necessary buffers. + */ +#if !defined SNMP_LWIP_MIB2_SYSLOCATION || defined __DOXYGEN__ +#define SNMP_LWIP_MIB2_SYSLOCATION "" +#endif + +/** + * This value is used to limit the repetitions processed in GetBulk requests (value == 0 means no limitation). + * This may be useful to limit the load for a single request. + * According to SNMP RFC 1905 it is allowed to not return all requested variables from a GetBulk request if system load would be too high. + * so the effect is that the client will do more requests to gather all data. + * For the stack this could be useful in case that SNMP processing is done in TCP/IP thread. In this situation a request with many + * repetitions could block the thread for a longer time. Setting limit here will keep the stack more responsive. + */ +#if !defined SNMP_LWIP_GETBULK_MAX_REPETITIONS || defined __DOXYGEN__ +#define SNMP_LWIP_GETBULK_MAX_REPETITIONS 0 +#endif + +/** + * @} + */ + +/* + ------------------------------------ + ---------- SNMPv3 options ---------- + ------------------------------------ +*/ + +/** + * LWIP_SNMP_V3==1: This enables EXPERIMENTAL SNMPv3 support. LWIP_SNMP must + * also be enabled. + * THIS IS UNDER DEVELOPMENT AND SHOULD NOT BE ENABLED IN PRODUCTS. + */ +#ifndef LWIP_SNMP_V3 +#define LWIP_SNMP_V3 0 +#endif + +#ifndef LWIP_SNMP_V3_MBEDTLS +#define LWIP_SNMP_V3_MBEDTLS LWIP_SNMP_V3 +#endif + +#ifndef LWIP_SNMP_V3_CRYPTO +#define LWIP_SNMP_V3_CRYPTO LWIP_SNMP_V3_MBEDTLS +#endif + +#ifndef LWIP_SNMP_CONFIGURE_VERSIONS +#define LWIP_SNMP_CONFIGURE_VERSIONS 0 +#endif + +#endif /* LWIP_HDR_SNMP_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_scalar.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_scalar.h new file mode 100644 index 000000000..40a060c64 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_scalar.h @@ -0,0 +1,113 @@ +/** + * @file + * SNMP server MIB API to implement scalar nodes + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Martin Hentschel + * + */ + +#ifndef LWIP_HDR_APPS_SNMP_SCALAR_H +#define LWIP_HDR_APPS_SNMP_SCALAR_H + +#include "lwip/apps/snmp_opts.h" +#include "lwip/apps/snmp_core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ + +/** basic scalar node */ +struct snmp_scalar_node +{ + /** inherited "base class" members */ + struct snmp_leaf_node node; + u8_t asn1_type; + snmp_access_t access; + node_instance_get_value_method get_value; + node_instance_set_test_method set_test; + node_instance_set_value_method set_value; +}; + + +snmp_err_t snmp_scalar_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); +snmp_err_t snmp_scalar_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); + +#define SNMP_SCALAR_CREATE_NODE(oid, access, asn1_type, get_value_method, set_test_method, set_value_method) \ + {{{ SNMP_NODE_SCALAR, (oid) }, \ + snmp_scalar_get_instance, \ + snmp_scalar_get_next_instance }, \ + (asn1_type), (access), (get_value_method), (set_test_method), (set_value_method) } + +#define SNMP_SCALAR_CREATE_NODE_READONLY(oid, asn1_type, get_value_method) SNMP_SCALAR_CREATE_NODE(oid, SNMP_NODE_INSTANCE_READ_ONLY, asn1_type, get_value_method, NULL, NULL) + +/** scalar array node - a tree node which contains scalars only as children */ +struct snmp_scalar_array_node_def +{ + u32_t oid; + u8_t asn1_type; + snmp_access_t access; +}; + +typedef s16_t (*snmp_scalar_array_get_value_method)(const struct snmp_scalar_array_node_def*, void*); +typedef snmp_err_t (*snmp_scalar_array_set_test_method)(const struct snmp_scalar_array_node_def*, u16_t, void*); +typedef snmp_err_t (*snmp_scalar_array_set_value_method)(const struct snmp_scalar_array_node_def*, u16_t, void*); + +/** basic scalar array node */ +struct snmp_scalar_array_node +{ + /** inherited "base class" members */ + struct snmp_leaf_node node; + u16_t array_node_count; + const struct snmp_scalar_array_node_def* array_nodes; + snmp_scalar_array_get_value_method get_value; + snmp_scalar_array_set_test_method set_test; + snmp_scalar_array_set_value_method set_value; +}; + +snmp_err_t snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); +snmp_err_t snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); + +#define SNMP_SCALAR_CREATE_ARRAY_NODE(oid, array_nodes, get_value_method, set_test_method, set_value_method) \ + {{{ SNMP_NODE_SCALAR_ARRAY, (oid) }, \ + snmp_scalar_array_get_instance, \ + snmp_scalar_array_get_next_instance }, \ + (u16_t)LWIP_ARRAYSIZE(array_nodes), (array_nodes), (get_value_method), (set_test_method), (set_value_method) } + +#endif /* LWIP_SNMP */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SNMP_SCALAR_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_snmpv2_framework.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_snmpv2_framework.h new file mode 100644 index 000000000..47409cc20 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_snmpv2_framework.h @@ -0,0 +1,32 @@ +/* +Generated by LwipMibCompiler +*/ + +#ifndef LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H +#define LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H + +#include "lwip/apps/snmp_opts.h" +#if LWIP_SNMP + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "lwip/apps/snmp_core.h" + +extern const struct snmp_obj_id usmNoAuthProtocol; +extern const struct snmp_obj_id usmHMACMD5AuthProtocol; +extern const struct snmp_obj_id usmHMACSHAAuthProtocol; + +extern const struct snmp_obj_id usmNoPrivProtocol; +extern const struct snmp_obj_id usmDESPrivProtocol; +extern const struct snmp_obj_id usmAESPrivProtocol; + +extern const struct snmp_mib snmpframeworkmib; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LWIP_SNMP */ +#endif /* LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_snmpv2_usm.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_snmpv2_usm.h new file mode 100644 index 000000000..88cfcd8eb --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_snmpv2_usm.h @@ -0,0 +1,24 @@ +/* +Generated by LwipMibCompiler +*/ + +#ifndef LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H +#define LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H + +#include "lwip/apps/snmp_opts.h" +#if LWIP_SNMP + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include "lwip/apps/snmp_core.h" + +extern const struct snmp_mib snmpusmmib; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LWIP_SNMP */ +#endif /* LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_table.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_table.h new file mode 100644 index 000000000..4988b51c2 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_table.h @@ -0,0 +1,134 @@ +/** + * @file + * SNMP server MIB API to implement table nodes + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Martin Hentschel + * + */ + +#ifndef LWIP_HDR_APPS_SNMP_TABLE_H +#define LWIP_HDR_APPS_SNMP_TABLE_H + +#include "lwip/apps/snmp_opts.h" +#include "lwip/apps/snmp_core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ + +/** default (customizable) read/write table */ +struct snmp_table_col_def +{ + u32_t index; + u8_t asn1_type; + snmp_access_t access; +}; + +/** table node */ +struct snmp_table_node +{ + /** inherited "base class" members */ + struct snmp_leaf_node node; + u16_t column_count; + const struct snmp_table_col_def* columns; + snmp_err_t (*get_cell_instance)(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, struct snmp_node_instance* cell_instance); + snmp_err_t (*get_next_cell_instance)(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance); + /** returns object value for the given object identifier */ + node_instance_get_value_method get_value; + /** tests length and/or range BEFORE setting */ + node_instance_set_test_method set_test; + /** sets object value, only called when set_test() was successful */ + node_instance_set_value_method set_value; +}; + +snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); +snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); + +#define SNMP_TABLE_CREATE(oid, columns, get_cell_instance_method, get_next_cell_instance_method, get_value_method, set_test_method, set_value_method) \ + {{{ SNMP_NODE_TABLE, (oid) }, \ + snmp_table_get_instance, \ + snmp_table_get_next_instance }, \ + (u16_t)LWIP_ARRAYSIZE(columns), (columns), \ + (get_cell_instance_method), (get_next_cell_instance_method), \ + (get_value_method), (set_test_method), (set_value_method)} + +#define SNMP_TABLE_GET_COLUMN_FROM_OID(oid) ((oid)[1]) /* first array value is (fixed) row entry (fixed to 1) and 2nd value is column, follow3ed by instance */ + + +/** simple read-only table */ +typedef enum { + SNMP_VARIANT_VALUE_TYPE_U32, + SNMP_VARIANT_VALUE_TYPE_S32, + SNMP_VARIANT_VALUE_TYPE_PTR, + SNMP_VARIANT_VALUE_TYPE_CONST_PTR +} snmp_table_column_data_type_t; + +struct snmp_table_simple_col_def +{ + u32_t index; + u8_t asn1_type; + snmp_table_column_data_type_t data_type; /* depending of what union member is used to store the value*/ +}; + +/** simple read-only table node */ +struct snmp_table_simple_node +{ + /* inherited "base class" members */ + struct snmp_leaf_node node; + u16_t column_count; + const struct snmp_table_simple_col_def* columns; + snmp_err_t (*get_cell_value)(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len); + snmp_err_t (*get_next_cell_instance_and_value)(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len); +}; + +snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); +snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); + +#define SNMP_TABLE_CREATE_SIMPLE(oid, columns, get_cell_value_method, get_next_cell_instance_and_value_method) \ + {{{ SNMP_NODE_TABLE, (oid) }, \ + snmp_table_simple_get_instance, \ + snmp_table_simple_get_next_instance }, \ + (u16_t)LWIP_ARRAYSIZE(columns), (columns), (get_cell_value_method), (get_next_cell_instance_and_value_method) } + +s16_t snmp_table_extract_value_from_s32ref(struct snmp_node_instance* instance, void* value); +s16_t snmp_table_extract_value_from_u32ref(struct snmp_node_instance* instance, void* value); +s16_t snmp_table_extract_value_from_refconstptr(struct snmp_node_instance* instance, void* value); + +#endif /* LWIP_SNMP */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SNMP_TABLE_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_threadsync.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_threadsync.h new file mode 100644 index 000000000..a25dbf2d0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmp_threadsync.h @@ -0,0 +1,114 @@ +/** + * @file + * SNMP server MIB API to implement thread synchronization + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Dirk Ziegelmeier + * + */ + +#ifndef LWIP_HDR_APPS_SNMP_THREADSYNC_H +#define LWIP_HDR_APPS_SNMP_THREADSYNC_H + +#include "lwip/apps/snmp_opts.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/apps/snmp_core.h" +#include "lwip/sys.h" + +typedef void (*snmp_threadsync_called_fn)(void* arg); +typedef void (*snmp_threadsync_synchronizer_fn)(snmp_threadsync_called_fn fn, void* arg); + + +/** Thread sync runtime data. For internal usage only. */ +struct threadsync_data +{ + union { + snmp_err_t err; + s16_t s16; + } retval; + union { + const u32_t *root_oid; + void *value; + } arg1; + union { + u8_t root_oid_len; + u16_t len; + } arg2; + const struct snmp_threadsync_node *threadsync_node; + struct snmp_node_instance proxy_instance; +}; + +/** Thread sync instance. Needed EXCATLY once for every thread to be synced into. */ +struct snmp_threadsync_instance +{ + sys_sem_t sem; + sys_mutex_t sem_usage_mutex; + snmp_threadsync_synchronizer_fn sync_fn; + struct threadsync_data data; +}; + +/** SNMP thread sync proxy leaf node */ +struct snmp_threadsync_node +{ + /* inherited "base class" members */ + struct snmp_leaf_node node; + + const struct snmp_leaf_node *target; + struct snmp_threadsync_instance *instance; +}; + +snmp_err_t snmp_threadsync_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); +snmp_err_t snmp_threadsync_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance); + +/** Create thread sync proxy node */ +#define SNMP_CREATE_THREAD_SYNC_NODE(oid, target_leaf_node, threadsync_instance) \ + {{{ SNMP_NODE_THREADSYNC, (oid) }, \ + snmp_threadsync_get_instance, \ + snmp_threadsync_get_next_instance }, \ + (target_leaf_node), \ + (threadsync_instance) } + +/** Create thread sync instance data */ +void snmp_threadsync_init(struct snmp_threadsync_instance *instance, snmp_threadsync_synchronizer_fn sync_fn); + +#endif /* LWIP_SNMP */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SNMP_THREADSYNC_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmpv3.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmpv3.h new file mode 100644 index 000000000..e0dda6499 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/snmpv3.h @@ -0,0 +1,114 @@ +/** + * @file + * Additional SNMPv3 functionality RFC3414 and RFC3826. + */ + +/* + * Copyright (c) 2016 Elias Oenal. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Elias Oenal + */ + +#ifndef LWIP_HDR_APPS_SNMP_V3_H +#define LWIP_HDR_APPS_SNMP_V3_H + +#include "lwip/apps/snmp_opts.h" +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_SNMP && LWIP_SNMP_V3 + +typedef enum +{ + SNMP_V3_AUTH_ALGO_INVAL = 0, + SNMP_V3_AUTH_ALGO_MD5 = 1, + SNMP_V3_AUTH_ALGO_SHA = 2 +} snmpv3_auth_algo_t; + +typedef enum +{ + SNMP_V3_PRIV_ALGO_INVAL = 0, + SNMP_V3_PRIV_ALGO_DES = 1, + SNMP_V3_PRIV_ALGO_AES = 2 +} snmpv3_priv_algo_t; + +typedef enum +{ + SNMP_V3_USER_STORAGETYPE_OTHER = 1, + SNMP_V3_USER_STORAGETYPE_VOLATILE = 2, + SNMP_V3_USER_STORAGETYPE_NONVOLATILE = 3, + SNMP_V3_USER_STORAGETYPE_PERMANENT = 4, + SNMP_V3_USER_STORAGETYPE_READONLY = 5 +} snmpv3_user_storagetype_t; + +/* + * The following callback functions must be implemented by the application. + * There is a dummy implementation in snmpv3_dummy.c. + */ + +void snmpv3_get_engine_id(const char **id, u8_t *len); +err_t snmpv3_set_engine_id(const char* id, u8_t len); + +u32_t snmpv3_get_engine_boots(void); +void snmpv3_set_engine_boots(u32_t boots); + +u32_t snmpv3_get_engine_time(void); +void snmpv3_reset_engine_time(void); + +err_t snmpv3_get_user(const char* username, snmpv3_auth_algo_t *auth_algo, u8_t *auth_key, snmpv3_priv_algo_t *priv_algo, u8_t *priv_key); +u8_t snmpv3_get_amount_of_users(void); +err_t snmpv3_get_user_storagetype(const char *username, snmpv3_user_storagetype_t *storagetype); +err_t snmpv3_get_username(char *username, u8_t index); + +/* The following functions are provided by the SNMPv3 agent */ + +void snmpv3_engine_id_changed(void); +s32_t snmpv3_get_engine_time_internal(void); + +void snmpv3_password_to_key_md5( + const u8_t *password, /* IN */ + size_t passwordlen, /* IN */ + const u8_t *engineID, /* IN - pointer to snmpEngineID */ + u8_t engineLength, /* IN - length of snmpEngineID */ + u8_t *key); /* OUT - pointer to caller 16-octet buffer */ + +void snmpv3_password_to_key_sha( + const u8_t *password, /* IN */ + size_t passwordlen, /* IN */ + const u8_t *engineID, /* IN - pointer to snmpEngineID */ + u8_t engineLength, /* IN - length of snmpEngineID */ + u8_t *key); /* OUT - pointer to caller 20-octet buffer */ + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SNMP_V3_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/sntp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/sntp.h new file mode 100644 index 000000000..c7515d40e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/sntp.h @@ -0,0 +1,89 @@ +/** + * @file + * SNTP client API + */ + +/* + * Copyright (c) 2007-2009 Frédéric Bernon, Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Frédéric Bernon, Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_APPS_SNTP_H +#define LWIP_HDR_APPS_SNTP_H + +#include "lwip/apps/sntp_opts.h" +#include "lwip/ip_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* SNTP operating modes: default is to poll using unicast. + The mode has to be set before calling sntp_init(). */ +#define SNTP_OPMODE_POLL 0 +#define SNTP_OPMODE_LISTENONLY 1 +void sntp_setoperatingmode(u8_t operating_mode); +u8_t sntp_getoperatingmode(void); +/** + * sntp Initialize this module. + * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC). + * 1、cn.ntp.org.cn:服务器地址为202.114.10.51,由中国科学院国家授时中心提供; + * 2、ntp.aliyun.com:由阿里云提供的SNTP服务器,位于杭州,提供多个服务器地址; + * 3、ntp2.sysu.edu.cn:由中山大学提供的SNTP服务器,位于广州。 + * 1、ntp.pool.org:(default) 由多个机构提供的NTP服务器集群,可提供全球覆盖的时间同步服务; + * 2、ntp1.aliyun.com:由阿里云提供的公共时间服务器池之一,提供高可用的时间同步服务; + * 3、cn.pool.ntp.org:中国境内的公共时间服务器池,由多个机构维护。 + */ +void sntp_init(void); +void sntp_stop(void); +u8_t sntp_enabled(void); + +void sntp_setserver(u8_t idx, const ip_addr_t *addr); +const ip_addr_t* sntp_getserver(u8_t idx); + +#if SNTP_MONITOR_SERVER_REACHABILITY +u8_t sntp_getreachability(u8_t idx); +#endif /* SNTP_MONITOR_SERVER_REACHABILITY */ + +#if SNTP_SERVER_DNS +void sntp_setservername(u8_t idx, const char *server); +const char *sntp_getservername(u8_t idx); +#endif /* SNTP_SERVER_DNS */ + +#if SNTP_GET_SERVERS_FROM_DHCP || SNTP_GET_SERVERS_FROM_DHCPV6 +void sntp_servermode_dhcp(int set_servers_from_dhcp); +#else /* SNTP_GET_SERVERS_FROM_DHCP || SNTP_GET_SERVERS_FROM_DHCPV6 */ +#define sntp_servermode_dhcp(x) +#endif /* SNTP_GET_SERVERS_FROM_DHCP || SNTP_GET_SERVERS_FROM_DHCPV6 */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_SNTP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/sntp_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/sntp_opts.h new file mode 100644 index 000000000..cb6277164 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/sntp_opts.h @@ -0,0 +1,215 @@ +/** + * @file + * SNTP client options list + */ + +/* + * Copyright (c) 2007-2009 Frédéric Bernon, Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Frédéric Bernon, Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_APPS_SNTP_OPTS_H +#define LWIP_HDR_APPS_SNTP_OPTS_H + +#include "lwip/opt.h" +#include "lwip/prot/iana.h" + +/** + * @defgroup sntp_opts Options + * @ingroup sntp + * @{ + */ + +/** SNTP macro to change system time in seconds + * Define SNTP_SET_SYSTEM_TIME_US(sec, us) to set the time in microseconds + * instead of this one if you need the additional precision. Alternatively, + * define SNTP_SET_SYSTEM_TIME_NTP(sec, frac) in order to work with native + * NTP timestamps instead. + */ +#if !defined SNTP_SET_SYSTEM_TIME || defined __DOXYGEN__ +#define SNTP_SET_SYSTEM_TIME(sec) LWIP_UNUSED_ARG(sec) +#endif + +/** The maximum number of SNTP servers that can be set */ +#if !defined SNTP_MAX_SERVERS || defined __DOXYGEN__ +#define SNTP_MAX_SERVERS LWIP_DHCP_MAX_NTP_SERVERS +#endif + +/** Set this to 1 to implement the callback function called by dhcp when + * NTP servers are received. */ +#if !defined SNTP_GET_SERVERS_FROM_DHCP || defined __DOXYGEN__ +#define SNTP_GET_SERVERS_FROM_DHCP LWIP_DHCP_GET_NTP_SRV +#endif + +/** Set this to 1 to implement the callback function called by dhcpv6 when + * NTP servers are received. */ +#if !defined SNTP_GET_SERVERS_FROM_DHCPV6 || defined __DOXYGEN__ +#define SNTP_GET_SERVERS_FROM_DHCPV6 LWIP_DHCP6_GET_NTP_SRV +#endif + +/** Set this to 1 to support DNS names (or IP address strings) to set sntp servers + * One server address/name can be defined as default if SNTP_SERVER_DNS == 1: + * \#define SNTP_SERVER_ADDRESS "pool.ntp.org" + */ +#if !defined SNTP_SERVER_DNS || defined __DOXYGEN__ +#define SNTP_SERVER_DNS 0 +#endif + +/** + * SNTP_DEBUG: Enable debugging for SNTP. + */ +#if !defined SNTP_DEBUG || defined __DOXYGEN__ +#define SNTP_DEBUG LWIP_DBG_OFF +#endif + +/** SNTP server port */ +#if !defined SNTP_PORT || defined __DOXYGEN__ +#define SNTP_PORT LWIP_IANA_PORT_SNTP +#endif + +/** Sanity check: + * Define this to + * - 0 to turn off sanity checks (default; smaller code) + * - >= 1 to check address and port of the response packet to ensure the + * response comes from the server we sent the request to. + * - >= 2 to check returned Originate Timestamp against Transmit Timestamp + * sent to the server (to ensure response to older request). + * - >= 3 @todo: discard reply if any of the VN, Stratum, or Transmit Timestamp + * fields is 0 or the Mode field is not 4 (unicast) or 5 (broadcast). + * - >= 4 @todo: to check that the Root Delay and Root Dispersion fields are each + * greater than or equal to 0 and less than infinity, where infinity is + * currently a cozy number like one second. This check avoids using a + * server whose synchronization source has expired for a very long time. + */ +#if !defined SNTP_CHECK_RESPONSE || defined __DOXYGEN__ +#define SNTP_CHECK_RESPONSE 0 +#endif + +/** Enable round-trip delay compensation. + * Compensate for the round-trip delay by calculating the clock offset from + * the originate, receive, transmit and destination timestamps, as per RFC. + * + * The calculation requires compiler support for 64-bit integers. Also, either + * SNTP_SET_SYSTEM_TIME_US or SNTP_SET_SYSTEM_TIME_NTP has to be implemented + * for setting the system clock with sub-second precision. Likewise, either + * SNTP_GET_SYSTEM_TIME or SNTP_GET_SYSTEM_TIME_NTP needs to be implemented + * with sub-second precision. + * + * Although not strictly required, it makes sense to combine this option with + * SNTP_CHECK_RESPONSE >= 2 for sanity-checking of the received timestamps. + * Also, in order for the round-trip calculation to work, the difference + * between the local clock and the NTP server clock must not be larger than + * about 34 years. If that limit is exceeded, the implementation will fall back + * to setting the clock without compensation. In order to ensure that the local + * clock is always within the permitted range for compensation, even at first + * try, it may be necessary to store at least the current year in non-volatile + * memory. + */ +#if !defined SNTP_COMP_ROUNDTRIP || defined __DOXYGEN__ +#define SNTP_COMP_ROUNDTRIP 0 +#endif + +/** According to the RFC, this shall be a random delay + * between 1 and 5 minutes (in milliseconds) to prevent load peaks. + * This can be defined to a random generation function, + * which must return the delay in milliseconds as u32_t. + * Turned off by default. + */ +#if !defined SNTP_STARTUP_DELAY || defined __DOXYGEN__ +#ifdef LWIP_RAND +#define SNTP_STARTUP_DELAY 1 +#else +#define SNTP_STARTUP_DELAY 0 +#endif +#endif + +/** If you want the startup delay to be a function, define this + * to a function (including the brackets) and define SNTP_STARTUP_DELAY to 1. + */ +#if !defined SNTP_STARTUP_DELAY_FUNC || defined __DOXYGEN__ +#define SNTP_STARTUP_DELAY_FUNC (LWIP_RAND() % 5000) +#endif + +/** SNTP receive timeout - in milliseconds + * Also used as retry timeout - this shouldn't be too low. + * Default is 15 seconds. Must not be beolw 15 seconds by specification (i.e. 15000) + */ +#if !defined SNTP_RECV_TIMEOUT || defined __DOXYGEN__ +#define SNTP_RECV_TIMEOUT 15000 +#endif + +/** SNTP update delay - in milliseconds + * Default is 1 hour. Must not be beolw 60 seconds by specification (i.e. 60000) + */ +#if !defined SNTP_UPDATE_DELAY || defined __DOXYGEN__ +#define SNTP_UPDATE_DELAY 3600000 +#endif + +/** SNTP macro to get system time, used with SNTP_CHECK_RESPONSE >= 2 + * to send in request and compare in response. Also used for round-trip + * delay compensation if SNTP_COMP_ROUNDTRIP != 0. + * Alternatively, define SNTP_GET_SYSTEM_TIME_NTP(sec, frac) in order to + * work with native NTP timestamps instead. + */ +#if !defined SNTP_GET_SYSTEM_TIME || defined __DOXYGEN__ +#define SNTP_GET_SYSTEM_TIME(sec, us) do { (sec) = 0; (us) = 0; } while(0) +#endif + +/** Default retry timeout (in milliseconds) if the response + * received is invalid. + * This is doubled with each retry until SNTP_RETRY_TIMEOUT_MAX is reached. + */ +#if !defined SNTP_RETRY_TIMEOUT || defined __DOXYGEN__ +#define SNTP_RETRY_TIMEOUT SNTP_RECV_TIMEOUT +#endif + +/** Maximum retry timeout (in milliseconds). */ +#if !defined SNTP_RETRY_TIMEOUT_MAX || defined __DOXYGEN__ +#define SNTP_RETRY_TIMEOUT_MAX (SNTP_RETRY_TIMEOUT * 10) +#endif + +/** Increase retry timeout with every retry sent + * Default is on to conform to RFC. + */ +#if !defined SNTP_RETRY_TIMEOUT_EXP || defined __DOXYGEN__ +#define SNTP_RETRY_TIMEOUT_EXP 1 +#endif + +/** Keep a reachability shift register per server + * Default is on to conform to RFC. + */ +#if !defined SNTP_MONITOR_SERVER_REACHABILITY || defined __DOXYGEN__ +#define SNTP_MONITOR_SERVER_REACHABILITY 1 +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_APPS_SNTP_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/tftp_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/tftp_opts.h new file mode 100644 index 000000000..198f632b6 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/tftp_opts.h @@ -0,0 +1,106 @@ +/** + * + * @file tftp_opts.h + * + * @author Logan Gunthorpe + * + * @brief Trivial File Transfer Protocol (RFC 1350) implementation options + * + * Copyright (c) Deltatee Enterprises Ltd. 2013 + * All rights reserved. + * + */ + +/* + * Redistribution and use in source and binary forms, with or without + * modification,are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Author: Logan Gunthorpe + * + */ + +#ifndef LWIP_HDR_APPS_TFTP_OPTS_H +#define LWIP_HDR_APPS_TFTP_OPTS_H + +#include "lwip/opt.h" +#include "lwip/prot/iana.h" + +/** + * @defgroup tftp_opts Options + * @ingroup tftp + * @{ + */ + +/** + * Enable TFTP debug messages + */ +#if !defined TFTP_DEBUG || defined __DOXYGEN__ +#define TFTP_DEBUG LWIP_DBG_OFF +#endif + +/** + * TFTP server port + */ +#if !defined TFTP_PORT || defined __DOXYGEN__ +#define TFTP_PORT LWIP_IANA_PORT_TFTP +#endif + +/** + * TFTP timeout + */ +#if !defined TFTP_TIMEOUT_MSECS || defined __DOXYGEN__ +#define TFTP_TIMEOUT_MSECS 10000 +#endif + +/** + * Max. number of retries when a file is read from server + */ +#if !defined TFTP_MAX_RETRIES || defined __DOXYGEN__ +#define TFTP_MAX_RETRIES 5 +#endif + +/** + * TFTP timer cyclic interval + */ +#if !defined TFTP_TIMER_MSECS || defined __DOXYGEN__ +#define TFTP_TIMER_MSECS (TFTP_TIMEOUT_MSECS / 10) +#endif + +/** + * Max. length of TFTP filename + */ +#if !defined TFTP_MAX_FILENAME_LEN || defined __DOXYGEN__ +#define TFTP_MAX_FILENAME_LEN 20 +#endif + +/** + * Max. length of TFTP mode + */ +#if !defined TFTP_MAX_MODE_LEN || defined __DOXYGEN__ +#define TFTP_MAX_MODE_LEN 7 +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_APPS_TFTP_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/tftp_server.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/tftp_server.h new file mode 100644 index 000000000..0a7fbee02 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/apps/tftp_server.h @@ -0,0 +1,95 @@ +/** + * + * @file tftp_server.h + * + * @author Logan Gunthorpe + * + * @brief Trivial File Transfer Protocol (RFC 1350) + * + * Copyright (c) Deltatee Enterprises Ltd. 2013 + * All rights reserved. + * + */ + +/* + * Redistribution and use in source and binary forms, with or without + * modification,are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Author: Logan Gunthorpe + * + */ + +#ifndef LWIP_HDR_APPS_TFTP_SERVER_H +#define LWIP_HDR_APPS_TFTP_SERVER_H + +#include "lwip/apps/tftp_opts.h" +#include "lwip/err.h" +#include "lwip/pbuf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup tftp + * TFTP context containing callback functions for TFTP transfers + */ +struct tftp_context { + /** + * Open file for read/write. + * @param fname Filename + * @param mode Mode string from TFTP RFC 1350 (netascii, octet, mail) + * @param write Flag indicating read (0) or write (!= 0) access + * @returns File handle supplied to other functions + */ + void* (*open)(const char* fname, const char* mode, u8_t write); + /** + * Close file handle + * @param handle File handle returned by open() + */ + void (*close)(void* handle); + /** + * Read from file + * @param handle File handle returned by open() + * @param buf Target buffer to copy read data to + * @param bytes Number of bytes to copy to buf + * @returns >= 0: Success; < 0: Error + */ + int (*read)(void* handle, void* buf, int bytes); + /** + * Write to file + * @param handle File handle returned by open() + * @param pbuf PBUF adjusted such that payload pointer points + * to the beginning of write data. In other words, + * TFTP headers are stripped off. + * @returns >= 0: Success; < 0: Error + */ + int (*write)(void* handle, struct pbuf* p); +}; + +err_t tftp_init(const struct tftp_context* ctx); +void tftp_cleanup(void); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_APPS_TFTP_SERVER_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/arch.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/arch.h new file mode 100644 index 000000000..58dae33aa --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/arch.h @@ -0,0 +1,393 @@ +/** + * @file + * Support for different processor and compiler architectures + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_ARCH_H +#define LWIP_HDR_ARCH_H + +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif + +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif + +#include "arch/cc.h" + +/** + * @defgroup compiler_abstraction Compiler/platform abstraction + * @ingroup sys_layer + * All defines related to this section must not be placed in lwipopts.h, + * but in arch/cc.h! + * If the compiler does not provide memset() this file must include a + * definition of it, or include a file which defines it. + * These options cannot be \#defined in lwipopts.h since they are not options + * of lwIP itself, but options of the lwIP port to your system. + * @{ + */ + +/** Define the byte order of the system. + * Needed for conversion of network data to host byte order. + * Allowed values: LITTLE_ENDIAN and BIG_ENDIAN + */ +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif + +/** Define random number generator function of your system */ +#ifdef __DOXYGEN__ +#define LWIP_RAND() ((u32_t)rand()) +#endif + +/** Platform specific diagnostic output.\n + * Note the default implementation pulls in printf, which may + * in turn pull in a lot of standard libary code. In resource-constrained + * systems, this should be defined to something less resource-consuming. + */ +#ifndef LWIP_PLATFORM_DIAG +#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0) +#include +#include +#endif + +/** Platform specific assertion handling.\n + * Note the default implementation pulls in printf, fflush and abort, which may + * in turn pull in a lot of standard libary code. In resource-constrained + * systems, this should be defined to something less resource-consuming. + */ +#ifndef LWIP_PLATFORM_ASSERT +#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); fflush(NULL); abort();} while(0) +#include +#include +#endif + +/** Define this to 1 in arch/cc.h of your port if you do not want to + * include stddef.h header to get size_t. You need to typedef size_t + * by yourself in this case. + */ +#ifndef LWIP_NO_STDDEF_H +#define LWIP_NO_STDDEF_H 0 +#endif + +#if !LWIP_NO_STDDEF_H +#include /* for size_t */ +#endif + +/** Define this to 1 in arch/cc.h of your port if your compiler does not provide + * the stdint.h header. You need to typedef the generic types listed in + * lwip/arch.h yourself in this case (u8_t, u16_t...). + */ +#ifndef LWIP_NO_STDINT_H +#define LWIP_NO_STDINT_H 0 +#endif + +/* Define generic types used in lwIP */ +#if !LWIP_NO_STDINT_H +#include +/* stdint.h is C99 which should also provide support for 64-bit integers */ +#if !defined(LWIP_HAVE_INT64) && defined(UINT64_MAX) +#define LWIP_HAVE_INT64 1 +#endif +typedef uint8_t u8_t; +typedef int8_t s8_t; +typedef uint16_t u16_t; +typedef int16_t s16_t; +typedef uint32_t u32_t; +typedef int32_t s32_t; +#if LWIP_HAVE_INT64 +typedef uint64_t u64_t; +typedef int64_t s64_t; +#endif +typedef uintptr_t mem_ptr_t; +#endif + +/** Define this to 1 in arch/cc.h of your port if your compiler does not provide + * the inttypes.h header. You need to define the format strings listed in + * lwip/arch.h yourself in this case (X8_F, U16_F...). + */ +#ifndef LWIP_NO_INTTYPES_H +#define LWIP_NO_INTTYPES_H 0 +#endif + +/* Define (sn)printf formatters for these lwIP types */ +#if !LWIP_NO_INTTYPES_H +#include +#ifndef X8_F +#define X8_F "02" PRIx8 +#endif +#ifndef U16_F +#define U16_F PRIu16 +#endif +#ifndef S16_F +#define S16_F PRId16 +#endif +#ifndef X16_F +#define X16_F PRIx16 +#endif +#ifndef U32_F +#define U32_F PRIu32 +#endif +#ifndef S32_F +#define S32_F PRId32 +#endif +#ifndef X32_F +#define X32_F PRIx32 +#endif +#ifndef SZT_F +#define SZT_F PRIuPTR +#endif +#endif + +/** Define this to 1 in arch/cc.h of your port if your compiler does not provide + * the limits.h header. You need to define the type limits yourself in this case + * (e.g. INT_MAX, SSIZE_MAX). + */ +#ifndef LWIP_NO_LIMITS_H +#define LWIP_NO_LIMITS_H 0 +#endif + +/* Include limits.h? */ +#if !LWIP_NO_LIMITS_H +#include +#endif + +/* Do we need to define ssize_t? This is a compatibility hack: + * Unfortunately, this type seems to be unavailable on some systems (even if + * sys/types or unistd.h are available). + * Being like that, we define it to 'int' if SSIZE_MAX is not defined. + */ +#ifdef SSIZE_MAX +/* If SSIZE_MAX is defined, unistd.h should provide the type as well */ +#ifndef LWIP_NO_UNISTD_H +#define LWIP_NO_UNISTD_H 0 +#endif +#if !LWIP_NO_UNISTD_H +#include +#endif +#else /* SSIZE_MAX */ +typedef int ssize_t; +#define SSIZE_MAX INT_MAX +#endif /* SSIZE_MAX */ + +/* some maximum values needed in lwip code */ +#define LWIP_UINT32_MAX 0xffffffff + +/** Define this to 1 in arch/cc.h of your port if your compiler does not provide + * the ctype.h header. If ctype.h is available, a few character functions + * are mapped to the appropriate functions (lwip_islower, lwip_isdigit...), if + * not, a private implementation is provided. + */ +#ifndef LWIP_NO_CTYPE_H +#define LWIP_NO_CTYPE_H 0 +#endif + +#if LWIP_NO_CTYPE_H +#define lwip_in_range(c, lo, up) ((u8_t)(c) >= (lo) && (u8_t)(c) <= (up)) +#define lwip_isdigit(c) lwip_in_range((c), '0', '9') +#define lwip_isxdigit(c) (lwip_isdigit(c) || lwip_in_range((c), 'a', 'f') || lwip_in_range((c), 'A', 'F')) +#define lwip_islower(c) lwip_in_range((c), 'a', 'z') +#define lwip_isspace(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || (c) == '\r' || (c) == '\t' || (c) == '\v') +#define lwip_isupper(c) lwip_in_range((c), 'A', 'Z') +#define lwip_tolower(c) (lwip_isupper(c) ? (c) - 'A' + 'a' : c) +#define lwip_toupper(c) (lwip_islower(c) ? (c) - 'a' + 'A' : c) +#else +#include +#define lwip_isdigit(c) isdigit((unsigned char)(c)) +#define lwip_isxdigit(c) isxdigit((unsigned char)(c)) +#define lwip_islower(c) islower((unsigned char)(c)) +#define lwip_isspace(c) isspace((unsigned char)(c)) +#define lwip_isupper(c) isupper((unsigned char)(c)) +#define lwip_tolower(c) tolower((unsigned char)(c)) +#define lwip_toupper(c) toupper((unsigned char)(c)) +#endif + +/** C++ const_cast(val) equivalent to remove constness from a value (GCC -Wcast-qual) */ +#ifndef LWIP_CONST_CAST +#define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val)) +#endif + +/** Get rid of alignment cast warnings (GCC -Wcast-align) */ +#ifndef LWIP_ALIGNMENT_CAST +#define LWIP_ALIGNMENT_CAST(target_type, val) LWIP_CONST_CAST(target_type, val) +#endif + +/** Get rid of warnings related to pointer-to-numeric and vice-versa casts, + * e.g. "conversion from 'u8_t' to 'void *' of greater size" + */ +#ifndef LWIP_PTR_NUMERIC_CAST +#define LWIP_PTR_NUMERIC_CAST(target_type, val) LWIP_CONST_CAST(target_type, val) +#endif + +/** Avoid warnings/errors related to implicitly casting away packed attributes by doing a explicit cast */ +#ifndef LWIP_PACKED_CAST +#define LWIP_PACKED_CAST(target_type, val) LWIP_CONST_CAST(target_type, val) +#endif + +/** Allocates a memory buffer of specified size that is of sufficient size to align + * its start address using LWIP_MEM_ALIGN. + * You can declare your own version here e.g. to enforce alignment without adding + * trailing padding bytes (see LWIP_MEM_ALIGN_BUFFER) or your own section placement + * requirements.\n + * e.g. if you use gcc and need 32 bit alignment:\n + * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] \_\_attribute\_\_((aligned(4)))\n + * or more portable:\n + * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u32_t variable_name[(size + sizeof(u32_t) - 1) / sizeof(u32_t)] + */ +#ifndef LWIP_DECLARE_MEMORY_ALIGNED +#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)] +#endif + +/** Calculate memory size for an aligned buffer - returns the next highest + * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and + * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4). + */ +#ifndef LWIP_MEM_ALIGN_SIZE +#define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U)) +#endif + +/** Calculate safe memory size for an aligned buffer when using an unaligned + * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the + * start (e.g. if buffer is u8_t[] and actual data will be u32_t*) + */ +#ifndef LWIP_MEM_ALIGN_BUFFER +#define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U)) +#endif + +/** Align a memory pointer to the alignment defined by MEM_ALIGNMENT + * so that ADDR % MEM_ALIGNMENT == 0 + */ +#ifndef LWIP_MEM_ALIGN +#define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** Packed structs support. + * Placed BEFORE declaration of a packed struct.\n + * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n + * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here. + */ +#ifndef PACK_STRUCT_BEGIN +#define PACK_STRUCT_BEGIN +#endif /* PACK_STRUCT_BEGIN */ + +/** Packed structs support. + * Placed AFTER declaration of a packed struct.\n + * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n + * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here. + */ +#ifndef PACK_STRUCT_END +#define PACK_STRUCT_END +#endif /* PACK_STRUCT_END */ + +/** Packed structs support. + * Placed between end of declaration of a packed struct and trailing semicolon.\n + * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n + * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here. + */ +#ifndef PACK_STRUCT_STRUCT +#if defined(__GNUC__) || defined(__clang__) +#define PACK_STRUCT_STRUCT __attribute__((packed)) +#else +#define PACK_STRUCT_STRUCT +#endif +#endif /* PACK_STRUCT_STRUCT */ + +/** Packed structs support. + * Wraps u32_t and u16_t members.\n + * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n + * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here. + */ +#ifndef PACK_STRUCT_FIELD +#define PACK_STRUCT_FIELD(x) x +#endif /* PACK_STRUCT_FIELD */ + +/** Packed structs support. + * Wraps u8_t members, where some compilers warn that packing is not necessary.\n + * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n + * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here. + */ +#ifndef PACK_STRUCT_FLD_8 +#define PACK_STRUCT_FLD_8(x) PACK_STRUCT_FIELD(x) +#endif /* PACK_STRUCT_FLD_8 */ + +/** Packed structs support. + * Wraps members that are packed structs themselves, where some compilers warn that packing is not necessary.\n + * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n + * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here. + */ +#ifndef PACK_STRUCT_FLD_S +#define PACK_STRUCT_FLD_S(x) PACK_STRUCT_FIELD(x) +#endif /* PACK_STRUCT_FLD_S */ + +/** PACK_STRUCT_USE_INCLUDES==1: Packed structs support using \#include files before and after struct to be packed.\n + * The file included BEFORE the struct is "arch/bpstruct.h".\n + * The file included AFTER the struct is "arch/epstruct.h".\n + * This can be used to implement struct packing on MS Visual C compilers, see + * the Win32 port in the lwIP contrib repository for reference. + * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n + * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here. + */ +#ifdef __DOXYGEN__ +#define PACK_STRUCT_USE_INCLUDES +#endif + +/** Eliminates compiler warning about unused arguments (GCC -Wextra -Wunused). */ +#ifndef LWIP_UNUSED_ARG +#define LWIP_UNUSED_ARG(x) (void)x +#endif /* LWIP_UNUSED_ARG */ + +/** LWIP_PROVIDE_ERRNO==1: Let lwIP provide ERRNO values and the 'errno' variable. + * If this is disabled, cc.h must either define 'errno', include , + * define LWIP_ERRNO_STDINCLUDE to get included or + * define LWIP_ERRNO_INCLUDE to or equivalent. + */ +#if defined __DOXYGEN__ +#define LWIP_PROVIDE_ERRNO +#endif + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_ARCH_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/autoip.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/autoip.h new file mode 100644 index 000000000..1d85bccff --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/autoip.h @@ -0,0 +1,99 @@ +/** + * @file + * + * AutoIP Automatic LinkLocal IP Configuration + */ + +/* + * + * Copyright (c) 2007 Dominik Spies + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Dominik Spies + * + * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform + * with RFC 3927. + * + */ + +#ifndef LWIP_HDR_AUTOIP_H +#define LWIP_HDR_AUTOIP_H + +#include "lwip/opt.h" + +#if LWIP_IPV4 && LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/netif.h" +/* #include "lwip/udp.h" */ +#include "lwip/etharp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** AutoIP Timing */ +#define AUTOIP_TMR_INTERVAL 100 +#define AUTOIP_TICKS_PER_SECOND (1000 / AUTOIP_TMR_INTERVAL) + +/** AutoIP state information per netif */ +struct autoip +{ + /** the currently selected, probed, announced or used LL IP-Address */ + ip4_addr_t llipaddr; + /** current AutoIP state machine state */ + u8_t state; + /** sent number of probes or announces, dependent on state */ + u8_t sent_num; + /** ticks to wait, tick is AUTOIP_TMR_INTERVAL long */ + u16_t ttw; + /** ticks until a conflict can be solved by defending */ + u8_t lastconflict; + /** total number of probed/used Link Local IP-Addresses */ + u8_t tried_llipaddr; +}; + + +void autoip_set_struct(struct netif *netif, struct autoip *autoip); +/** Remove a struct autoip previously set to the netif using autoip_set_struct() */ +#define autoip_remove_struct(netif) do { (netif)->autoip = NULL; } while (0) +err_t autoip_start(struct netif *netif); +err_t autoip_stop(struct netif *netif); +void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr); +void autoip_tmr(void); +void autoip_network_changed(struct netif *netif); +u8_t autoip_supplied_address(const struct netif *netif); + +/* for lwIP internal use by ip4.c */ +u8_t autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr); + +#define netif_autoip_data(netif) ((struct autoip*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 && LWIP_AUTOIP */ + +#endif /* LWIP_HDR_AUTOIP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/debug.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/debug.h new file mode 100644 index 000000000..579fd242b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/debug.h @@ -0,0 +1,159 @@ +/** + * @file + * Debug messages infrastructure + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_DEBUG_H +#define LWIP_HDR_DEBUG_H + +#include "lwip/arch.h" +#include "lwip/opt.h" + +/** + * @defgroup debugging_levels LWIP_DBG_MIN_LEVEL and LWIP_DBG_TYPES_ON values + * @ingroup lwip_opts_debugmsg + * @{ + */ + +/** @name Debug level (LWIP_DBG_MIN_LEVEL) + * @{ + */ +/** Debug level: ALL messages*/ +#define LWIP_DBG_LEVEL_ALL 0x00 +/** Debug level: Warnings. bad checksums, dropped packets, ... */ +#define LWIP_DBG_LEVEL_WARNING 0x01 +/** Debug level: Serious. memory allocation failures, ... */ +#define LWIP_DBG_LEVEL_SERIOUS 0x02 +/** Debug level: Severe */ +#define LWIP_DBG_LEVEL_SEVERE 0x03 +/** + * @} + */ + +#define LWIP_DBG_MASK_LEVEL 0x03 +/* compatibility define only */ +#define LWIP_DBG_LEVEL_OFF LWIP_DBG_LEVEL_ALL + +/** @name Enable/disable debug messages completely (LWIP_DBG_TYPES_ON) + * @{ + */ +/** flag for LWIP_DEBUGF to enable that debug message */ +#define LWIP_DBG_ON 0x80U +/** flag for LWIP_DEBUGF to disable that debug message */ +#define LWIP_DBG_OFF 0x00U +/** + * @} + */ + +/** @name Debug message types (LWIP_DBG_TYPES_ON) + * @{ + */ +/** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */ +#define LWIP_DBG_TRACE 0x40U +/** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */ +#define LWIP_DBG_STATE 0x20U +/** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */ +#define LWIP_DBG_FRESH 0x10U +/** flag for LWIP_DEBUGF to halt after printing this debug message */ +#define LWIP_DBG_HALT 0x08U +/** + * @} + */ + +/** + * @} + */ + +/** + * @defgroup lwip_assertions Assertion handling + * @ingroup lwip_opts_debug + * @{ + */ +/** + * LWIP_NOASSERT: Disable LWIP_ASSERT checks: + * To disable assertions define LWIP_NOASSERT in arch/cc.h. + */ +#ifdef __DOXYGEN__ +#define LWIP_NOASSERT +#undef LWIP_NOASSERT +#endif +/** + * @} + */ + +#ifndef LWIP_NOASSERT +#define LWIP_ASSERT(message, assertion) do { if (!(assertion)) { \ + LWIP_PLATFORM_ASSERT(message); }} while(0) +#else /* LWIP_NOASSERT */ +#define LWIP_ASSERT(message, assertion) +#endif /* LWIP_NOASSERT */ + +#ifndef LWIP_ERROR +#ifdef LWIP_DEBUG +#define LWIP_PLATFORM_ERROR(message) LWIP_PLATFORM_DIAG((message)) +#else +#define LWIP_PLATFORM_ERROR(message) +#endif + +/* if "expression" isn't true, then print "message" and execute "handler" expression */ +#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ + LWIP_PLATFORM_ERROR(message); handler;}} while(0) +#endif /* LWIP_ERROR */ + +/** Enable debug message printing, but only if debug message type is enabled + * AND is of correct type AND is at least LWIP_DBG_LEVEL. + */ +#ifdef __DOXYGEN__ +#define LWIP_DEBUG +#undef LWIP_DEBUG +#endif + +#ifdef LWIP_DEBUG +#define LWIP_DEBUGF(debug, message) do { \ + if ( \ + ((debug) & LWIP_DBG_ON) && \ + ((debug) & LWIP_DBG_TYPES_ON) && \ + ((s16_t)((debug) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \ + LWIP_PLATFORM_DIAG(message); \ + if ((debug) & LWIP_DBG_HALT) { \ + while(1); \ + } \ + } \ + } while(0) + +#else /* LWIP_DEBUG */ +#define LWIP_DEBUGF(debug, message) +#endif /* LWIP_DEBUG */ + +#endif /* LWIP_HDR_DEBUG_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/def.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/def.h new file mode 100644 index 000000000..dfb266d18 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/def.h @@ -0,0 +1,152 @@ +/** + * @file + * various utility macros + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +/** + * @defgroup perf Performance measurement + * @ingroup sys_layer + * All defines related to this section must not be placed in lwipopts.h, + * but in arch/perf.h! + * Measurement calls made throughout lwip, these can be defined to nothing. + * - PERF_START: start measuring something. + * - PERF_STOP(x): stop measuring something, and record the result. + */ + +#ifndef LWIP_HDR_DEF_H +#define LWIP_HDR_DEF_H + +/* arch.h might define NULL already */ +#include "lwip/arch.h" +#include "lwip/opt.h" +#if LWIP_PERF +#include "arch/perf.h" +#else /* LWIP_PERF */ +#define PERF_START /* null definition */ +#define PERF_STOP(x) /* null definition */ +#endif /* LWIP_PERF */ + +#ifdef __cplusplus +extern "C" { +#endif + +#define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y)) +#define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y)) + +/* Get the number of entries in an array ('x' must NOT be a pointer!) */ +#define LWIP_ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0])) + +/** Create u32_t value from bytes */ +#define LWIP_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \ + ((u32_t)((b) & 0xff) << 16) | \ + ((u32_t)((c) & 0xff) << 8) | \ + (u32_t)((d) & 0xff)) + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#if BYTE_ORDER == BIG_ENDIAN +#define lwip_htons(x) ((u16_t)(x)) +#define lwip_ntohs(x) ((u16_t)(x)) +#define lwip_htonl(x) ((u32_t)(x)) +#define lwip_ntohl(x) ((u32_t)(x)) +#define PP_HTONS(x) ((u16_t)(x)) +#define PP_NTOHS(x) ((u16_t)(x)) +#define PP_HTONL(x) ((u32_t)(x)) +#define PP_NTOHL(x) ((u32_t)(x)) +#else /* BYTE_ORDER != BIG_ENDIAN */ +#ifndef lwip_htons +u16_t lwip_htons(u16_t x); +#endif +#define lwip_ntohs(x) lwip_htons(x) + +#ifndef lwip_htonl +u32_t lwip_htonl(u32_t x); +#endif +#define lwip_ntohl(x) lwip_htonl(x) + +/* These macros should be calculated by the preprocessor and are used + with compile-time constants only (so that there is no little-endian + overhead at runtime). */ +#define PP_HTONS(x) ((u16_t)((((x) & (u16_t)0x00ffU) << 8) | (((x) & (u16_t)0xff00U) >> 8))) +#define PP_NTOHS(x) PP_HTONS(x) +#define PP_HTONL(x) ((((x) & (u32_t)0x000000ffUL) << 24) | \ + (((x) & (u32_t)0x0000ff00UL) << 8) | \ + (((x) & (u32_t)0x00ff0000UL) >> 8) | \ + (((x) & (u32_t)0xff000000UL) >> 24)) +#define PP_NTOHL(x) PP_HTONL(x) +#endif /* BYTE_ORDER == BIG_ENDIAN */ + +/* Provide usual function names as macros for users, but this can be turned off */ +#ifndef LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS +#define htons(x) lwip_htons(x) +#define ntohs(x) lwip_ntohs(x) +#define htonl(x) lwip_htonl(x) +#define ntohl(x) lwip_ntohl(x) +#endif + +/* Functions that are not available as standard implementations. + * In cc.h, you can #define these to implementations available on + * your platform to save some code bytes if you use these functions + * in your application, too. + */ + +#ifndef lwip_itoa +/* This can be #defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform */ +void lwip_itoa(char* result, size_t bufsize, int number); +#endif +#ifndef lwip_strnicmp +/* This can be #defined to strnicmp() or strncasecmp() depending on your platform */ +int lwip_strnicmp(const char* str1, const char* str2, size_t len); +#endif +#ifndef lwip_stricmp +/* This can be #defined to stricmp() or strcasecmp() depending on your platform */ +int lwip_stricmp(const char* str1, const char* str2); +#endif +#ifndef lwip_strnstr +/* This can be #defined to strnstr() depending on your platform */ +char* lwip_strnstr(const char* buffer, const char* token, size_t n); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_DEF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dhcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dhcp.h new file mode 100644 index 000000000..7384dffdf --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dhcp.h @@ -0,0 +1,178 @@ +/** + * @file + * DHCP client API + */ + +/* + * Copyright (c) 2001-2004 Leon Woestenberg + * Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Leon Woestenberg + * + */ +#ifndef LWIP_HDR_DHCP_H +#define LWIP_HDR_DHCP_H + +#include "lwip/opt.h" + +#if LWIP_DHCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/netif.h" +#include "lwip/udp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** period (in seconds) of the application calling dhcp_coarse_tmr() */ +#define DHCP_COARSE_TIMER_SECS 60 +/** period (in milliseconds) of the application calling dhcp_coarse_tmr() */ +#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL) +/** period (in milliseconds) of the application calling dhcp_fine_tmr() */ +#define DHCP_FINE_TIMER_MSECS 500 + +#define DHCP_BOOT_FILE_LEN 128U + +#if LWIP_DNS && LWIP_DHCP_MAX_DNS_SERVERS +#if DNS_MAX_SERVERS > LWIP_DHCP_MAX_DNS_SERVERS +#define LWIP_DHCP_PROVIDE_DNS_SERVERS LWIP_DHCP_MAX_DNS_SERVERS +#else +#define LWIP_DHCP_PROVIDE_DNS_SERVERS DNS_MAX_SERVERS +#endif +#else +#define LWIP_DHCP_PROVIDE_DNS_SERVERS 0 +#endif + +/** Option handling: options are parsed in dhcp_parse_reply + * and saved in an array where other functions can load them from. + * This might be moved into the struct dhcp (not necessarily since + * lwIP is single-threaded and the array is only used while in recv + * callback). */ +enum dhcp_option_idx { + DHCP_OPTION_IDX_OVERLOAD = 0, + DHCP_OPTION_IDX_MSG_TYPE, + DHCP_OPTION_IDX_SERVER_ID, + DHCP_OPTION_IDX_LEASE_TIME, + DHCP_OPTION_IDX_T1, + DHCP_OPTION_IDX_T2, + DHCP_OPTION_IDX_SUBNET_MASK, + DHCP_OPTION_IDX_ROUTER, +#if LWIP_DHCP_PROVIDE_DNS_SERVERS + DHCP_OPTION_IDX_DNS_SERVER, + DHCP_OPTION_IDX_DNS_SERVER_LAST = DHCP_OPTION_IDX_DNS_SERVER + LWIP_DHCP_PROVIDE_DNS_SERVERS - 1, +#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS */ +#if LWIP_DHCP_GET_NTP_SRV + DHCP_OPTION_IDX_NTP_SERVER, + DHCP_OPTION_IDX_NTP_SERVER_LAST = DHCP_OPTION_IDX_NTP_SERVER + LWIP_DHCP_MAX_NTP_SERVERS - 1, +#endif /* LWIP_DHCP_GET_NTP_SRV */ + DHCP_OPTION_IDX_MAX +}; + +/* AutoIP cooperation flags (struct dhcp.autoip_coop_state) */ +typedef enum { + DHCP_AUTOIP_COOP_STATE_OFF = 0, + DHCP_AUTOIP_COOP_STATE_ON = 1 +} dhcp_autoip_coop_state_enum_t; + +struct dhcp +{ + /** transaction identifier of last sent request */ + u32_t xid; + /** track PCB allocation state */ + u8_t pcb_allocated; + /** current DHCP state machine state */ + u8_t state; + /** retries of current request */ + u8_t tries; +#if LWIP_DHCP_AUTOIP_COOP + u8_t autoip_coop_state; +#endif + u8_t subnet_mask_given; + + u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */ + u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */ + u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */ + u16_t t1_renew_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next renew try */ + u16_t t2_rebind_time; /* #ticks with period DHCP_COARSE_TIMER_SECS until next rebind try */ + u16_t lease_used; /* #ticks with period DHCP_COARSE_TIMER_SECS since last received DHCP ack */ + u16_t t0_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for lease time */ + ip_addr_t server_ip_addr; /* dhcp server address that offered this lease (ip_addr_t because passed to UDP) */ + ip4_addr_t offered_ip_addr; + ip4_addr_t offered_sn_mask; + ip4_addr_t offered_gw_addr; + + u32_t offered_t0_lease; /* lease period (in seconds) */ + u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */ + u32_t offered_t2_rebind; /* recommended rebind time (usually 87.5 of lease period) */ +#if LWIP_DHCP_BOOTP_FILE + ip4_addr_t offered_si_addr; + char boot_file_name[DHCP_BOOT_FILE_LEN]; +#endif /* LWIP_DHCP_BOOTPFILE */ + /** Holds the decoded option values, only valid while in dhcp_recv. */ + u32_t rx_options_val[DHCP_OPTION_IDX_MAX]; + /** Holds a flag which option was received and is contained in dhcp_rx_options_val, only valid while in dhcp_recv. */ + u8_t rx_options_given[DHCP_OPTION_IDX_MAX]; +}; + + +void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp); +/** Remove a struct dhcp previously set to the netif using dhcp_set_struct() */ +#define dhcp_remove_struct(netif) netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, NULL) +void dhcp_cleanup(struct netif *netif); +err_t dhcp_start(struct netif *netif); +err_t dhcp_renew(struct netif *netif); +err_t dhcp_release(struct netif *netif); +void dhcp_stop(struct netif *netif); +void dhcp_release_and_stop(struct netif *netif); +void dhcp_inform(struct netif *netif); +void dhcp_network_changed(struct netif *netif); +#if DHCP_DOES_ARP_CHECK +void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr); +#endif +u8_t dhcp_supplied_address(const struct netif *netif); +/* to be called every minute */ +void dhcp_coarse_tmr(void); +/* to be called every half second */ +void dhcp_fine_tmr(void); + +#if LWIP_DHCP_GET_NTP_SRV +/** This function must exist, in other to add offered NTP servers to + * the NTP (or SNTP) engine. + * See LWIP_DHCP_MAX_NTP_SERVERS */ +extern void dhcp_set_ntp_servers(u8_t num_ntp_servers, const ip4_addr_t* ntp_server_addrs); +#endif /* LWIP_DHCP_GET_NTP_SRV */ + +#define netif_dhcp_data(netif) ((struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_DHCP */ + +#endif /*LWIP_HDR_DHCP_H*/ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dhcp6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dhcp6.h new file mode 100644 index 000000000..5cc4a0159 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dhcp6.h @@ -0,0 +1,104 @@ +/** + * @file + * + * DHCPv6 client: IPv6 address autoconfiguration as per + * RFC 3315 (stateful DHCPv6) and + * RFC 3736 (stateless DHCPv6). + */ + +/* + * Copyright (c) 2018 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + */ + +#ifndef LWIP_HDR_IP6_DHCP6_H +#define LWIP_HDR_IP6_DHCP6_H + +#include "lwip/opt.h" + +#if LWIP_IPV6_DHCP6 /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/err.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** period (in milliseconds) of the application calling dhcp6_tmr() */ +#define DHCP6_TIMER_MSECS 500 + +struct dhcp6 +{ + /** transaction identifier of last sent request */ + u32_t xid; + /** track PCB allocation state */ + u8_t pcb_allocated; + /** current DHCPv6 state machine state */ + u8_t state; + /** retries of current request */ + u8_t tries; + /** if request config is triggered while another action is active, this keeps track of it */ + u8_t request_config_pending; + /** #ticks with period DHCP6_TIMER_MSECS for request timeout */ + u16_t request_timeout; +#if LWIP_IPV6_DHCP6_STATEFUL + /* @todo: add more members here to keep track of stateful DHCPv6 data, like lease times */ +#endif /* LWIP_IPV6_DHCP6_STATEFUL */ +}; + +void dhcp6_set_struct(struct netif *netif, struct dhcp6 *dhcp6); +/** Remove a struct dhcp6 previously set to the netif using dhcp6_set_struct() */ +#define dhcp6_remove_struct(netif) netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6, NULL) +void dhcp6_cleanup(struct netif *netif); + +err_t dhcp6_enable_stateful(struct netif *netif); +err_t dhcp6_enable_stateless(struct netif *netif); +void dhcp6_disable(struct netif *netif); + +void dhcp6_tmr(void); + +void dhcp6_nd6_ra_trigger(struct netif *netif, u8_t managed_addr_config, u8_t other_config); + +#if LWIP_DHCP6_GET_NTP_SRV +/** This function must exist, in other to add offered NTP servers to + * the NTP (or SNTP) engine. + * See LWIP_DHCP6_MAX_NTP_SERVERS */ +extern void dhcp6_set_ntp_servers(u8_t num_ntp_servers, const ip_addr_t* ntp_server_addrs); +#endif /* LWIP_DHCP6_GET_NTP_SRV */ + +#define netif_dhcp6_data(netif) ((struct dhcp6*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6_DHCP6 */ + +#endif /* LWIP_HDR_IP6_DHCP6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net.h new file mode 100644 index 000000000..77aee4889 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net.h @@ -0,0 +1,78 @@ +/* Copyright (c) 2021-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_HDR_DISTRIBUTED_NET_H +#define LWIP_HDR_DISTRIBUTED_NET_H + +#include "lwip/opt.h" + +#if LWIP_ENABLE_DISTRIBUTED_NET + +#include "lwip/sockets.h" + +#define IP4_MAX_ADDR_LEN 16 /* strlen(255.255.255.255) + 1 */ + +#define LOCAL_SERVER_IP "127.0.0.1" + +#define SOCKET_TO_INDEX(socket) ((socket)-LWIP_SOCKET_OFFSET) + +#define INDEX_TO_SOCKET(index) ((index) + LWIP_SOCKET_OFFSET) + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +#define INIT_SOCK_ADDR(addr, ip_string, port) \ + do { \ + (addr)->sin_family = AF_INET; \ + (addr)->sin_port = lwip_htons(port); \ + (addr)->sin_addr.s_addr = ipaddr_addr(ip_string); \ + } while (0) + +#define SET_MSG_ADDR(hdr, addr, addr_len) \ + do { \ + ((struct msghdr *)(hdr))->msg_name = (void *)(addr); \ + ((struct msghdr *)(hdr))->msg_namelen = (addr_len); \ + } while (0) + +void set_distributed_net_socket(int sock); + +void reset_distributed_net_socket(int sock); + +u16_t get_local_tcp_server_port(void); + +u16_t get_local_udp_server_port(void); + +u8_t is_distributed_net_enabled(void); + +int enable_distributed_net(u16_t tcp_port, u16_t udp_port); + +int disable_distributed_net(void); + +#endif /* LWIP_ENABLE_DISTRIBUTED_NET */ + +#endif /* LWIP_HDR_DISTRIBUTED_NET_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net_core.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net_core.h new file mode 100644 index 000000000..cd5d7898b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net_core.h @@ -0,0 +1,78 @@ +/* Copyright (c) 2021-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_HDR_DISTRIBUTED_NET_CORE_H +#define LWIP_HDR_DISTRIBUTED_NET_CORE_H + +#include "lwip/opt.h" + +#if LWIP_ENABLE_DISTRIBUTED_NET + +#include "lwip/distributed_net/distributed_net.h" +#include "lwip/sockets.h" + +#define DNS_PORT 53 + +#define CHECK_PARA(exp, err) \ + do { \ + if (!(exp)) { \ + set_errno(err); \ + return -1; \ + } \ + } while (0) + +#define IS_LOCAL_UDP_SERVER_ADDR(addr) \ + ((addr)->sin_addr.s_addr == ipaddr_addr(LOCAL_SERVER_IP) && (addr)->sin_port == ntohs(get_local_udp_server_port())) + +#define IS_DNS_PORT(addr) (ntohs((addr).sin_port) == DNS_PORT) + +typedef struct tcp_connect_data { + char dest_addr[IP4_MAX_ADDR_LEN]; + u32_t dest_port; +} tcp_connect_data; + +int distributed_net_connect(int sock, const struct sockaddr *addr, socklen_t addr_len); + +int distributed_net_close(int sock); + +#if LWIP_USE_GET_HOST_BY_NAME_EXTERNAL +ssize_t distributed_net_sendto(int sock, const void *buf, size_t buf_len, int flags, const struct sockaddr *addr, + socklen_t addr_len); + +#if LWIP_DISTRIBUTED_NET_ENABLE_SENDMSG +ssize_t distributed_net_sendmsg(int sock, const struct msghdr *hdr, int flags); +#endif + +ssize_t distributed_net_recvfrom(int sock, void *buf, size_t buf_len, int flags, struct sockaddr *from, + socklen_t *from_len); +#endif /* LWIP_USE_GET_HOST_BY_NAME_EXTERNAL */ + +#endif /* LWIP_ENABLE_DISTRIBUTED_NET */ + +#endif /* LWIP_HDR_DISTRIBUTED_NET_CORE_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net_utils.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net_utils.h new file mode 100644 index 000000000..0c7e1edff --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/distributed_net_utils.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2021-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_HDR_DISTRIBUTED_NET_UTILS_H +#define LWIP_HDR_DISTRIBUTED_NET_UTILS_H + +#include "lwip/opt.h" + +#if LWIP_ENABLE_DISTRIBUTED_NET + +#include "lwip/sockets.h" + +u8_t is_no_proxy_network_segment(const struct sockaddr_in *addr_in); + +#endif /* LWIP_ENABLE_DISTRIBUTED_NET */ + +#endif /* LWIP_HDR_DISTRIBUTED_NET_UTILS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/udp_transmit.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/udp_transmit.h new file mode 100644 index 000000000..23f76bf57 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/distributed_net/udp_transmit.h @@ -0,0 +1,62 @@ +/* Copyright (c) 2021-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_HDR_UDP_TRANSMIT_H +#define LWIP_HDR_UDP_TRANSMIT_H + +#include "lwip/opt.h" + +#if LWIP_ENABLE_DISTRIBUTED_NET + +typedef struct udp_data { + char dest_addr[IP4_MAX_ADDR_LEN]; + u32_t dest_port; + char payload[]; +} udp_data; + +#if LWIP_USE_GET_HOST_BY_NAME_EXTERNAL + +#include "lwip/distributed_net/distributed_net.h" +#include "lwip/sockets.h" + +#define MAX_UDP_PAYLOAD_LEN 1024 + +#define MAX_IOV_NUM 32 + +#define UDP_PAYLOAD_LEN(send_len) ((send_len) - (ssize_t)sizeof(udp_data)) + +ssize_t udp_transmit_sendto(int sock, const void *buf, size_t buf_len, const struct sockaddr_in *dest_addr); + +ssize_t udp_transmit_sendmsg(int sock, const struct msghdr *hdr); + +#endif /* LWIP_USE_GET_HOST_BY_NAME_EXTERNAL */ + +#endif /* LWIP_ENABLE_DISTRIBUTED_NET */ + +#endif /* LWIP_HDR_UDP_TRANSMIT_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dns.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dns.h new file mode 100644 index 000000000..091341544 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/dns.h @@ -0,0 +1,131 @@ +/** + * @file + * DNS API + */ + +/** + * lwip DNS resolver header file. + + * Author: Jim Pettinato + * April 2007 + + * ported from uIP resolv.c Copyright (c) 2002-2003, Adam Dunkels. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LWIP_HDR_DNS_H +#define LWIP_HDR_DNS_H + +#include "lwip/opt.h" + +#if LWIP_DNS + +#include "lwip/ip_addr.h" +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** DNS timer period */ +#define DNS_TMR_INTERVAL 1000 + +/* DNS resolve types: */ +#define LWIP_DNS_ADDRTYPE_IPV4 0 +#define LWIP_DNS_ADDRTYPE_IPV6 1 +#define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */ +#define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */ +#if LWIP_IPV4 && LWIP_IPV6 +#ifndef LWIP_DNS_ADDRTYPE_DEFAULT +#define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6 +#endif +#elif LWIP_IPV4 +#define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4 +#else +#define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6 +#endif + +#if DNS_LOCAL_HOSTLIST +/** struct used for local host-list */ +struct local_hostlist_entry { + /** static hostname */ + const char *name; + /** static host address in network byteorder */ + ip_addr_t addr; + struct local_hostlist_entry *next; +}; +#define DNS_LOCAL_HOSTLIST_ELEM(name, addr_init) {name, addr_init, NULL} +#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC +#ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN +#define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH +#endif +#define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1)) +#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ +#endif /* DNS_LOCAL_HOSTLIST */ + +#if LWIP_IPV4 +extern const ip_addr_t dns_mquery_v4group; +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 +extern const ip_addr_t dns_mquery_v6group; +#endif /* LWIP_IPV6 */ + +/** Callback which is invoked when a hostname is found. + * A function of this type must be implemented by the application using the DNS resolver. + * @param name pointer to the name that was looked up. + * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname, + * or NULL if the name could not be found (or on any other error). + * @param callback_arg a user-specified callback argument passed to dns_gethostbyname +*/ +typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg); + +void dns_init(void); +void dns_tmr(void); +void dns_setserver(u8_t numdns, const ip_addr_t *dnsserver); +const ip_addr_t* dns_getserver(u8_t numdns); +err_t dns_gethostbyname(const char *hostname, ip_addr_t *addr, + dns_found_callback found, void *callback_arg); +err_t dns_gethostbyname_addrtype(const char *hostname, ip_addr_t *addr, + dns_found_callback found, void *callback_arg, + u8_t dns_addrtype); + + +#if DNS_LOCAL_HOSTLIST +size_t dns_local_iterate(dns_found_callback iterator_fn, void *iterator_arg); +err_t dns_local_lookup(const char *hostname, ip_addr_t *addr, u8_t dns_addrtype); +#if DNS_LOCAL_HOSTLIST_IS_DYNAMIC +int dns_local_removehost(const char *hostname, const ip_addr_t *addr); +err_t dns_local_addhost(const char *hostname, const ip_addr_t *addr); +#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ +#endif /* DNS_LOCAL_HOSTLIST */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_DNS */ + +#endif /* LWIP_HDR_DNS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/err.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/err.h new file mode 100644 index 000000000..887d9b3fd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/err.h @@ -0,0 +1,117 @@ +/** + * @file + * lwIP Error codes + */ +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_ERR_H +#define LWIP_HDR_ERR_H + +#include "lwip/opt.h" +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup infrastructure_errors Error codes + * @ingroup infrastructure + * @{ + */ + +/** Definitions for error constants. */ +typedef enum { +/** No error, everything OK. */ + ERR_OK = 0, +/** Out of memory error. */ + ERR_MEM = -1, +/** Buffer error. */ + ERR_BUF = -2, +/** Timeout. */ + ERR_TIMEOUT = -3, +/** Routing problem. */ + ERR_RTE = -4, +/** Operation in progress */ + ERR_INPROGRESS = -5, +/** Illegal value. */ + ERR_VAL = -6, +/** Operation would block. */ + ERR_WOULDBLOCK = -7, +/** Address in use. */ + ERR_USE = -8, +/** Already connecting. */ + ERR_ALREADY = -9, +/** Conn already established.*/ + ERR_ISCONN = -10, +/** Not connected. */ + ERR_CONN = -11, +/** Low-level netif error */ + ERR_IF = -12, + +/** Connection aborted. */ + ERR_ABRT = -13, +/** Connection reset. */ + ERR_RST = -14, +/** Connection closed. */ + ERR_CLSD = -15, +/** Illegal argument. */ + ERR_ARG = -16 +} err_enum_t; + +/** Define LWIP_ERR_T in cc.h if you want to use + * a different type for your platform (must be signed). */ +#ifdef LWIP_ERR_T +typedef LWIP_ERR_T err_t; +#else /* LWIP_ERR_T */ +typedef s8_t err_t; +#endif /* LWIP_ERR_T*/ + +/** + * @} + */ + +#ifdef LWIP_DEBUG +extern const char *lwip_strerr(err_t err); +#else +#define lwip_strerr(x) "" +#endif /* LWIP_DEBUG */ + +#if !NO_SYS +int err_to_errno(err_t err); +#endif /* !NO_SYS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_ERR_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/errno.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/errno.h new file mode 100644 index 000000000..40996578c --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/errno.h @@ -0,0 +1,200 @@ +/** + * @file + * Posix Errno defines + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_ERRNO_H +#define LWIP_HDR_ERRNO_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef LWIP_PROVIDE_ERRNO + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No child processes */ +#define EAGAIN 11 /* Try again */ +#define ENOMEM 12 /* Out of memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device or resource busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* File table overflow */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math argument out of domain of func */ +#define ERANGE 34 /* Math result not representable */ +#define EDEADLK 35 /* Resource deadlock would occur */ +#define ENAMETOOLONG 36 /* File name too long */ +#define ENOLCK 37 /* No record locks available */ +#define ENOSYS 38 /* Function not implemented */ +#define ENOTEMPTY 39 /* Directory not empty */ +#define ELOOP 40 /* Too many symbolic links encountered */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define ENOMSG 42 /* No message of desired type */ +#define EIDRM 43 /* Identifier removed */ +#define ECHRNG 44 /* Channel number out of range */ +#define EL2NSYNC 45 /* Level 2 not synchronized */ +#define EL3HLT 46 /* Level 3 halted */ +#define EL3RST 47 /* Level 3 reset */ +#define ELNRNG 48 /* Link number out of range */ +#define EUNATCH 49 /* Protocol driver not attached */ +#define ENOCSI 50 /* No CSI structure available */ +#define EL2HLT 51 /* Level 2 halted */ +#define EBADE 52 /* Invalid exchange */ +#define EBADR 53 /* Invalid request descriptor */ +#define EXFULL 54 /* Exchange full */ +#define ENOANO 55 /* No anode */ +#define EBADRQC 56 /* Invalid request code */ +#define EBADSLT 57 /* Invalid slot */ + +#define EDEADLOCK EDEADLK + +#define EBFONT 59 /* Bad font file format */ +#define ENOSTR 60 /* Device not a stream */ +#define ENODATA 61 /* No data available */ +#define ETIME 62 /* Timer expired */ +#define ENOSR 63 /* Out of streams resources */ +#define ENONET 64 /* Machine is not on the network */ +#define ENOPKG 65 /* Package not installed */ +#define EREMOTE 66 /* Object is remote */ +#define ENOLINK 67 /* Link has been severed */ +#define EADV 68 /* Advertise error */ +#define ESRMNT 69 /* Srmount error */ +#define ECOMM 70 /* Communication error on send */ +#define EPROTO 71 /* Protocol error */ +#define EMULTIHOP 72 /* Multihop attempted */ +#define EDOTDOT 73 /* RFS specific error */ +#define EBADMSG 74 /* Not a data message */ +#define EOVERFLOW 75 /* Value too large for defined data type */ +#define ENOTUNIQ 76 /* Name not unique on network */ +#define EBADFD 77 /* File descriptor in bad state */ +#define EREMCHG 78 /* Remote address changed */ +#define ELIBACC 79 /* Can not access a needed shared library */ +#define ELIBBAD 80 /* Accessing a corrupted shared library */ +#define ELIBSCN 81 /* .lib section in a.out corrupted */ +#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ +#define ELIBEXEC 83 /* Cannot exec a shared library directly */ +#ifndef EILSEQ +#define EILSEQ 84 /* Illegal byte sequence */ +#endif +#define ERESTART 85 /* Interrupted system call should be restarted */ +#define ESTRPIPE 86 /* Streams pipe error */ +#define EUSERS 87 /* Too many users */ +#define ENOTSOCK 88 /* Socket operation on non-socket */ +#define EDESTADDRREQ 89 /* Destination address required */ +#define EMSGSIZE 90 /* Message too long */ +#define EPROTOTYPE 91 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 92 /* Protocol not available */ +#define EPROTONOSUPPORT 93 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EPFNOSUPPORT 96 /* Protocol family not supported */ +#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#define EADDRINUSE 98 /* Address already in use */ +#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ +#define ENETDOWN 100 /* Network is down */ +#define ENETUNREACH 101 /* Network is unreachable */ +#define ENETRESET 102 /* Network dropped connection because of reset */ +#define ECONNABORTED 103 /* Software caused connection abort */ +#define ECONNRESET 104 /* Connection reset by peer */ +#define ENOBUFS 105 /* No buffer space available */ +#define EISCONN 106 /* Transport endpoint is already connected */ +#define ENOTCONN 107 /* Transport endpoint is not connected */ +#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ +#define ETOOMANYREFS 109 /* Too many references: cannot splice */ +#define ETIMEDOUT 110 /* Connection timed out */ +#define ECONNREFUSED 111 /* Connection refused */ +#define EHOSTDOWN 112 /* Host is down */ +#define EHOSTUNREACH 113 /* No route to host */ +#define EALREADY 114 /* Operation already in progress */ +#define EINPROGRESS 115 /* Operation now in progress */ +#define ESTALE 116 /* Stale NFS file handle */ +#define EUCLEAN 117 /* Structure needs cleaning */ +#define ENOTNAM 118 /* Not a XENIX named type file */ +#define ENAVAIL 119 /* No XENIX semaphores available */ +#define EISNAM 120 /* Is a named type file */ +#define EREMOTEIO 121 /* Remote I/O error */ +#define EDQUOT 122 /* Quota exceeded */ + +#define ENOMEDIUM 123 /* No medium found */ +#define EMEDIUMTYPE 124 /* Wrong medium type */ + +#ifndef errno +extern int errno; +#endif + +#else /* LWIP_PROVIDE_ERRNO */ + +/* Define LWIP_ERRNO_STDINCLUDE if you want to include here */ +#ifdef LWIP_ERRNO_STDINCLUDE +#include +#else /* LWIP_ERRNO_STDINCLUDE */ +/* Define LWIP_ERRNO_INCLUDE to an equivalent of to include the error defines here */ +#ifdef LWIP_ERRNO_INCLUDE +#include LWIP_ERRNO_INCLUDE +#endif /* LWIP_ERRNO_INCLUDE */ +#endif /* LWIP_ERRNO_STDINCLUDE */ + +#endif /* LWIP_PROVIDE_ERRNO */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_ERRNO_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/etharp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/etharp.h new file mode 100644 index 000000000..2036b2464 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/etharp.h @@ -0,0 +1,105 @@ +/** + * @file + * Ethernet output function - handles OUTGOING ethernet level traffic, implements + * ARP resolving. + * To be used in most low-level netif implementations + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * Copyright (c) 2003-2004 Leon Woestenberg + * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +#ifndef LWIP_HDR_NETIF_ETHARP_H +#define LWIP_HDR_NETIF_ETHARP_H + +#include "lwip/opt.h" + +#if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/pbuf.h" +#include "lwip/ip4_addr.h" +#include "lwip/netif.h" +#include "lwip/ip4.h" +#include "lwip/prot/ethernet.h" + +#if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/prot/etharp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** 1 seconds period */ +#define ARP_TMR_INTERVAL 1000 + +#if ARP_QUEUEING +/** struct for queueing outgoing packets for unknown address + * defined here to be accessed by memp.h + */ +struct etharp_q_entry { + struct etharp_q_entry *next; + struct pbuf *p; +}; +#endif /* ARP_QUEUEING */ + +#define etharp_init() /* Compatibility define, no init needed. */ +void etharp_tmr(void); +ssize_t etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr, + struct eth_addr **eth_ret, const ip4_addr_t **ip_ret); +int etharp_get_entry(size_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret); +err_t etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr); +err_t etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q); +err_t etharp_request(struct netif *netif, const ip4_addr_t *ipaddr); +/** For Ethernet network interfaces, we might want to send "gratuitous ARP"; + * this is an ARP packet sent by a node in order to spontaneously cause other + * nodes to update an entry in their ARP cache. + * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */ +#define etharp_gratuitous(netif) etharp_request((netif), netif_ip4_addr(netif)) +void etharp_cleanup_netif(struct netif *netif); + +#if ETHARP_SUPPORT_STATIC_ENTRIES +err_t etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr); +err_t etharp_remove_static_entry(const ip4_addr_t *ipaddr); +#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */ + +void etharp_input(struct pbuf *p, struct netif *netif); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 && LWIP_ARP */ +#endif /* LWIP_ARP || LWIP_ETHERNET */ + +#endif /* LWIP_HDR_NETIF_ETHARP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ethip6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ethip6.h new file mode 100644 index 000000000..5e88dffd0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ethip6.h @@ -0,0 +1,68 @@ +/** + * @file + * + * Ethernet output for IPv6. Uses ND tables for link-layer addressing. + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ + +#ifndef LWIP_HDR_ETHIP6_H +#define LWIP_HDR_ETHIP6_H + +#include "lwip/opt.h" + +#if LWIP_IPV6 && LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/pbuf.h" +#include "lwip/ip6.h" +#include "lwip/ip6_addr.h" +#include "lwip/netif.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +err_t ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 && LWIP_ETHERNET */ + +#endif /* LWIP_HDR_ETHIP6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/icmp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/icmp.h new file mode 100644 index 000000000..f5a31fd4c --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/icmp.h @@ -0,0 +1,110 @@ +/** + * @file + * ICMP API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_ICMP_H +#define LWIP_HDR_ICMP_H + +#include "lwip/opt.h" +#include "lwip/pbuf.h" +#include "lwip/ip_addr.h" +#include "lwip/netif.h" +#include "lwip/prot/icmp.h" + +#if LWIP_IPV6 && LWIP_ICMP6 +#include "lwip/icmp6.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** ICMP destination unreachable codes */ +enum icmp_dur_type { + /** net unreachable */ + ICMP_DUR_NET = 0, + /** host unreachable */ + ICMP_DUR_HOST = 1, + /** protocol unreachable */ + ICMP_DUR_PROTO = 2, + /** port unreachable */ + ICMP_DUR_PORT = 3, + /** fragmentation needed and DF set */ + ICMP_DUR_FRAG = 4, + /** source route failed */ + ICMP_DUR_SR = 5 +}; + +/** ICMP time exceeded codes */ +enum icmp_te_type { + /** time to live exceeded in transit */ + ICMP_TE_TTL = 0, + /** fragment reassembly time exceeded */ + ICMP_TE_FRAG = 1 +}; + +#if LWIP_IPV4 && LWIP_ICMP /* don't build if not configured for use in lwipopts.h */ + +void icmp_input(struct pbuf *p, struct netif *inp); +void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t); +void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); + +#endif /* LWIP_IPV4 && LWIP_ICMP */ + +#if LWIP_IPV4 && LWIP_IPV6 +#if LWIP_ICMP && LWIP_ICMP6 +#define icmp_port_unreach(isipv6, pbuf) ((isipv6) ? \ + icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT) : \ + icmp_dest_unreach(pbuf, ICMP_DUR_PORT)) +#elif LWIP_ICMP +#define icmp_port_unreach(isipv6, pbuf) do{ if(!(isipv6)) { icmp_dest_unreach(pbuf, ICMP_DUR_PORT);}}while(0) +#elif LWIP_ICMP6 +#define icmp_port_unreach(isipv6, pbuf) do{ if(isipv6) { icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT);}}while(0) +#else +#define icmp_port_unreach(isipv6, pbuf) +#endif +#elif LWIP_IPV6 && LWIP_ICMP6 +#define icmp_port_unreach(isipv6, pbuf) icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT) +#elif LWIP_IPV4 && LWIP_ICMP +#define icmp_port_unreach(isipv6, pbuf) icmp_dest_unreach(pbuf, ICMP_DUR_PORT) +#else /* (LWIP_IPV6 && LWIP_ICMP6) || (LWIP_IPV4 && LWIP_ICMP) */ +#define icmp_port_unreach(isipv6, pbuf) +#endif /* (LWIP_IPV6 && LWIP_ICMP6) || (LWIP_IPV4 && LWIP_ICMP) LWIP_IPV4*/ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_ICMP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/icmp6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/icmp6.h new file mode 100644 index 000000000..0ccb78994 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/icmp6.h @@ -0,0 +1,72 @@ +/** + * @file + * + * IPv6 version of ICMP, as per RFC 4443. + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ +#ifndef LWIP_HDR_ICMP6_H +#define LWIP_HDR_ICMP6_H + +#include "lwip/opt.h" +#include "lwip/pbuf.h" +#include "lwip/ip6_addr.h" +#include "lwip/netif.h" +#include "lwip/prot/icmp6.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_ICMP6 && LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +void icmp6_input(struct pbuf *p, struct netif *inp); +void icmp6_dest_unreach(struct pbuf *p, enum icmp6_dur_code c); +void icmp6_packet_too_big(struct pbuf *p, u32_t mtu); +void icmp6_time_exceeded(struct pbuf *p, enum icmp6_te_code c); +void icmp6_time_exceeded_with_addrs(struct pbuf *p, enum icmp6_te_code c, + const ip6_addr_t *src_addr, const ip6_addr_t *dest_addr); +void icmp6_param_problem(struct pbuf *p, enum icmp6_pp_code c, const void *pointer); + +#endif /* LWIP_ICMP6 && LWIP_IPV6 */ + + +#ifdef __cplusplus +} +#endif + + +#endif /* LWIP_HDR_ICMP6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/if_api.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/if_api.h new file mode 100644 index 000000000..bbf679f7a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/if_api.h @@ -0,0 +1,71 @@ +/** + * @file + * Interface Identification APIs from: + * RFC 3493: Basic Socket Interface Extensions for IPv6 + * Section 4: Interface Identification + */ + +/* + * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Joel Cunningham + * + */ +#ifndef LWIP_HDR_IF_H +#define LWIP_HDR_IF_H + +#include "lwip/opt.h" + +#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef LWIP_SOCKET_STDINCLUDE +#ifndef IF_NAMESIZE +#define IF_NAMESIZE NETIF_NAMESIZE +#endif +#endif /* LWIP_SOCKET_STDINCLUDE */ +char * lwip_if_indextoname(unsigned int ifindex, char *ifname); +unsigned int lwip_if_nametoindex(const char *ifname); + +#if LWIP_COMPAT_SOCKETS +#define if_indextoname(ifindex, ifname) lwip_if_indextoname(ifindex,ifname) +#define if_nametoindex(ifname) lwip_if_nametoindex(ifname) +#endif /* LWIP_COMPAT_SOCKETS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_SOCKET */ + +#endif /* LWIP_HDR_IF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/igmp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/igmp.h new file mode 100644 index 000000000..ffd80e680 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/igmp.h @@ -0,0 +1,115 @@ +/** + * @file + * IGMP API + */ + +/* + * Copyright (c) 2002 CITEL Technologies 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 CITEL Technologies Ltd 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 CITEL TECHNOLOGIES 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 CITEL TECHNOLOGIES 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. + * + * This file is a contribution to the lwIP TCP/IP stack. + * The Swedish Institute of Computer Science and Adam Dunkels + * are specifically granted permission to redistribute this + * source code. +*/ + +#ifndef LWIP_HDR_IGMP_H +#define LWIP_HDR_IGMP_H + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "lwip/netif.h" +#include "lwip/pbuf.h" + +#if LWIP_IPV4 && LWIP_IGMP /* don't build if not configured for use in lwipopts.h */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* IGMP timer */ +#define IGMP_TMR_INTERVAL 100 /* Milliseconds */ +#define IGMP_V1_DELAYING_MEMBER_TMR (1000/IGMP_TMR_INTERVAL) +#define IGMP_JOIN_DELAYING_MEMBER_TMR (500 /IGMP_TMR_INTERVAL) + +/* Compatibility defines (don't use for new code) */ +#define IGMP_DEL_MAC_FILTER NETIF_DEL_MAC_FILTER +#define IGMP_ADD_MAC_FILTER NETIF_ADD_MAC_FILTER + +/** + * igmp group structure - there is + * a list of groups for each interface + * these should really be linked from the interface, but + * if we keep them separate we will not affect the lwip original code + * too much + * + * There will be a group for the all systems group address but this + * will not run the state machine as it is used to kick off reports + * from all the other groups + */ +struct igmp_group { + /** next link */ + struct igmp_group *next; + /** multicast address */ + ip4_addr_t group_address; + /** signifies we were the last person to report */ + u8_t last_reporter_flag; + /** current state of the group */ + u8_t group_state; + /** timer for reporting, negative is OFF */ + u16_t timer; + /** counter of simultaneous uses */ + u8_t use; +}; + +/* Prototypes */ +void igmp_init(void); +err_t igmp_start(struct netif *netif); +err_t igmp_stop(struct netif *netif); +void igmp_report_groups(struct netif *netif); +struct igmp_group *igmp_lookfor_group(struct netif *ifp, const ip4_addr_t *addr); +void igmp_input(struct pbuf *p, struct netif *inp, const ip4_addr_t *dest); +err_t igmp_joingroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr); +err_t igmp_joingroup_netif(struct netif *netif, const ip4_addr_t *groupaddr); +err_t igmp_leavegroup(const ip4_addr_t *ifaddr, const ip4_addr_t *groupaddr); +err_t igmp_leavegroup_netif(struct netif *netif, const ip4_addr_t *groupaddr); +void igmp_tmr(void); + +/** @ingroup igmp + * Get list head of IGMP groups for netif. + * Note: The allsystems group IP is contained in the list as first entry. + * @see @ref netif_set_igmp_mac_filter() + */ +#define netif_igmp_data(netif) ((struct igmp_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 && LWIP_IGMP */ + +#endif /* LWIP_HDR_IGMP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/inet.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/inet.h new file mode 100644 index 000000000..466f3598c --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/inet.h @@ -0,0 +1,169 @@ +/** + * @file + * This file (together with sockets.h) aims to provide structs and functions from + * - arpa/inet.h + * - netinet/in.h + * + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_INET_H +#define LWIP_HDR_INET_H + +#include "lwip/opt.h" +#include "lwip/def.h" +#include "lwip/ip_addr.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif +#ifndef LWIP_SOCKET_STDINCLUDE +/* If your port already typedef's in_addr_t, define IN_ADDR_T_DEFINED + to prevent this code from redefining it. */ +#if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED) +typedef u32_t in_addr_t; +#endif + +struct in_addr { + in_addr_t s_addr; +}; + +struct in6_addr { + union { + u32_t u32_addr[4]; + u8_t u8_addr[16]; + } un; +#define s6_addr un.u8_addr +}; + +/** 255.255.255.255 */ +#define INADDR_NONE IPADDR_NONE +/** 127.0.0.1 */ +#define INADDR_LOOPBACK IPADDR_LOOPBACK +/** 0.0.0.0 */ +#define INADDR_ANY IPADDR_ANY +/** 255.255.255.255 */ +#define INADDR_BROADCAST IPADDR_BROADCAST + +/** This macro can be used to initialize a variable of type struct in6_addr + to the IPv6 wildcard address. */ +#define IN6ADDR_ANY_INIT {{{0,0,0,0}}} +/** This macro can be used to initialize a variable of type struct in6_addr + to the IPv6 loopback address. */ +#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,PP_HTONL(1)}}} +/** This variable is initialized by the system to contain the wildcard IPv6 address. */ +extern const struct in6_addr in6addr_any; + +/* Definitions of the bits in an (IPv4) Internet address integer. + + On subnets, host and network parts are found according to + the subnet mask, not these masks. */ +#define IN_CLASSA(a) IP_CLASSA(a) +#define IN_CLASSA_NET IP_CLASSA_NET +#define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT +#define IN_CLASSA_HOST IP_CLASSA_HOST +#define IN_CLASSA_MAX IP_CLASSA_MAX + +#define IN_CLASSB(b) IP_CLASSB(b) +#define IN_CLASSB_NET IP_CLASSB_NET +#define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT +#define IN_CLASSB_HOST IP_CLASSB_HOST +#define IN_CLASSB_MAX IP_CLASSB_MAX + +#define IN_CLASSC(c) IP_CLASSC(c) +#define IN_CLASSC_NET IP_CLASSC_NET +#define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT +#define IN_CLASSC_HOST IP_CLASSC_HOST +#define IN_CLASSC_MAX IP_CLASSC_MAX + +#define IN_CLASSD(d) IP_CLASSD(d) +#define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */ +#define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */ +#define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */ +#define IN_CLASSD_MAX IP_CLASSD_MAX + +#define IN_MULTICAST(a) IP_MULTICAST(a) + +#define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a) +#define IN_BADCLASS(a) IP_BADCLASS(a) + +#define IN_LOOPBACKNET IP_LOOPBACKNET + + +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN IP4ADDR_STRLEN_MAX +#endif +#if LWIP_IPV6 +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN IP6ADDR_STRLEN_MAX +#endif +#endif + +#if LWIP_IPV4 + +#define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) +#define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) + +/* directly map this to the lwip internal functions */ +#define inet_addr(cp) ipaddr_addr(cp) +#define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr) +#define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr)) +#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen) + +#endif /* LWIP_IPV4 */ + +#if LWIP_IPV6 +#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) {(target_in6addr)->un.u32_addr[0] = (source_ip6addr)->addr[0]; \ + (target_in6addr)->un.u32_addr[1] = (source_ip6addr)->addr[1]; \ + (target_in6addr)->un.u32_addr[2] = (source_ip6addr)->addr[2]; \ + (target_in6addr)->un.u32_addr[3] = (source_ip6addr)->addr[3];} +#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) {(target_ip6addr)->addr[0] = (source_in6addr)->un.u32_addr[0]; \ + (target_ip6addr)->addr[1] = (source_in6addr)->un.u32_addr[1]; \ + (target_ip6addr)->addr[2] = (source_in6addr)->un.u32_addr[2]; \ + (target_ip6addr)->addr[3] = (source_in6addr)->un.u32_addr[3]; \ + ip6_addr_clear_zone(target_ip6addr);} + +/* directly map this to the lwip internal functions */ +#define inet6_aton(cp, addr) ip6addr_aton(cp, (ip6_addr_t*)addr) +#define inet6_ntoa(addr) ip6addr_ntoa((const ip6_addr_t*)&(addr)) +#define inet6_ntoa_r(addr, buf, buflen) ip6addr_ntoa_r((const ip6_addr_t*)&(addr), buf, buflen) + +#endif /* LWIP_IPV6 */ +#endif /* LWIP_SOCKET_STDINCLUDE */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_INET_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/inet_chksum.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/inet_chksum.h new file mode 100644 index 000000000..76893ef52 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/inet_chksum.h @@ -0,0 +1,105 @@ +/** + * @file + * IP checksum calculation functions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_INET_CHKSUM_H +#define LWIP_HDR_INET_CHKSUM_H + +#include "lwip/opt.h" + +#include "lwip/pbuf.h" +#include "lwip/ip_addr.h" + +/** Swap the bytes in an u16_t: much like lwip_htons() for little-endian */ +#ifndef SWAP_BYTES_IN_WORD +#define SWAP_BYTES_IN_WORD(w) (((w) & 0xff) << 8) | (((w) & 0xff00) >> 8) +#endif /* SWAP_BYTES_IN_WORD */ + +/** Split an u32_t in two u16_ts and add them up */ +#ifndef FOLD_U32T +#define FOLD_U32T(u) ((u32_t)(((u) >> 16) + ((u) & 0x0000ffffUL))) +#endif + +#if LWIP_CHECKSUM_ON_COPY +/** Function-like macro: same as MEMCPY but returns the checksum of copied data + as u16_t */ +# ifndef LWIP_CHKSUM_COPY +# define LWIP_CHKSUM_COPY(dst, src, len) lwip_chksum_copy(dst, src, len) +# ifndef LWIP_CHKSUM_COPY_ALGORITHM +# define LWIP_CHKSUM_COPY_ALGORITHM 1 +# endif /* LWIP_CHKSUM_COPY_ALGORITHM */ +# else /* LWIP_CHKSUM_COPY */ +# define LWIP_CHKSUM_COPY_ALGORITHM 0 +# endif /* LWIP_CHKSUM_COPY */ +#else /* LWIP_CHECKSUM_ON_COPY */ +# define LWIP_CHKSUM_COPY_ALGORITHM 0 +#endif /* LWIP_CHECKSUM_ON_COPY */ + +#ifdef __cplusplus +extern "C" { +#endif + +u16_t inet_chksum(const void *dataptr, u16_t len); +u16_t inet_chksum_pbuf(struct pbuf *p); +#if LWIP_CHKSUM_COPY_ALGORITHM +u16_t lwip_chksum_copy(void *dst, const void *src, u16_t len); +#endif /* LWIP_CHKSUM_COPY_ALGORITHM */ + +#if LWIP_IPV4 +u16_t inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, + const ip4_addr_t *src, const ip4_addr_t *dest); +u16_t inet_chksum_pseudo_partial(struct pbuf *p, u8_t proto, + u16_t proto_len, u16_t chksum_len, const ip4_addr_t *src, const ip4_addr_t *dest); +#endif /* LWIP_IPV4 */ + +#if LWIP_IPV6 +u16_t ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, + const ip6_addr_t *src, const ip6_addr_t *dest); +u16_t ip6_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, + u16_t chksum_len, const ip6_addr_t *src, const ip6_addr_t *dest); +#endif /* LWIP_IPV6 */ + + +u16_t ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len, + const ip_addr_t *src, const ip_addr_t *dest); +u16_t ip_chksum_pseudo_partial(struct pbuf *p, u8_t proto, u16_t proto_len, + u16_t chksum_len, const ip_addr_t *src, const ip_addr_t *dest); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_INET_H */ + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/init.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/init.h new file mode 100644 index 000000000..6cabfc8fd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/init.h @@ -0,0 +1,100 @@ +/** + * @file + * lwIP initialization API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_INIT_H +#define LWIP_HDR_INIT_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup lwip_version Version + * @ingroup lwip + * @{ + */ + +/** X.x.x: Major version of the stack */ +#define LWIP_VERSION_MAJOR 2 +/** x.X.x: Minor version of the stack */ +#define LWIP_VERSION_MINOR 1 +/** x.x.X: Revision of the stack */ +#define LWIP_VERSION_REVISION 3 +/** For release candidates, this is set to 1..254 + * For official releases, this is set to 255 (LWIP_RC_RELEASE) + * For development versions (Git), this is set to 0 (LWIP_RC_DEVELOPMENT) */ +#define LWIP_VERSION_RC LWIP_RC_RELEASE + +/** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ +#define LWIP_RC_RELEASE 255 +/** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for Git versions */ +#define LWIP_RC_DEVELOPMENT 0 + +#define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) +#define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) +#define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) + +/* Some helper defines to get a version string */ +#define LWIP_VERSTR2(x) #x +#define LWIP_VERSTR(x) LWIP_VERSTR2(x) +#if LWIP_VERSION_IS_RELEASE +#define LWIP_VERSION_STRING_SUFFIX "" +#elif LWIP_VERSION_IS_DEVELOPMENT +#define LWIP_VERSION_STRING_SUFFIX "d" +#else +#define LWIP_VERSION_STRING_SUFFIX "rc" LWIP_VERSTR(LWIP_VERSION_RC) +#endif + +/** Provides the version of the stack */ +#define LWIP_VERSION ((LWIP_VERSION_MAJOR) << 24 | (LWIP_VERSION_MINOR) << 16 | \ + (LWIP_VERSION_REVISION) << 8 | (LWIP_VERSION_RC)) +/** Provides the version of the stack as string */ +#define LWIP_VERSION_STRING LWIP_VERSTR(LWIP_VERSION_MAJOR) "." LWIP_VERSTR(LWIP_VERSION_MINOR) "." LWIP_VERSTR(LWIP_VERSION_REVISION) LWIP_VERSION_STRING_SUFFIX + +/** + * @} + */ + +/* Modules initialization */ +void lwip_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_INIT_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/init.h.cmake.in b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/init.h.cmake.in new file mode 100644 index 000000000..9b609b742 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/init.h.cmake.in @@ -0,0 +1,100 @@ +/** + * @file + * lwIP initialization API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_INIT_H +#define LWIP_HDR_INIT_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup lwip_version Version + * @ingroup lwip + * @{ + */ + +/** X.x.x: Major version of the stack */ +#define LWIP_VERSION_MAJOR ${LWIP_VERSION_MAJOR} +/** x.X.x: Minor version of the stack */ +#define LWIP_VERSION_MINOR ${LWIP_VERSION_MINOR} +/** x.x.X: Revision of the stack */ +#define LWIP_VERSION_REVISION ${LWIP_VERSION_REVISION} +/** For release candidates, this is set to 1..254 + * For official releases, this is set to 255 (LWIP_RC_RELEASE) + * For development versions (Git), this is set to 0 (LWIP_RC_DEVELOPMENT) */ +#define LWIP_VERSION_RC ${LWIP_VERSION_RC} + +/** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ +#define LWIP_RC_RELEASE 255 +/** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for Git versions */ +#define LWIP_RC_DEVELOPMENT 0 + +#define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) +#define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) +#define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) + +/* Some helper defines to get a version string */ +#define LWIP_VERSTR2(x) #x +#define LWIP_VERSTR(x) LWIP_VERSTR2(x) +#if LWIP_VERSION_IS_RELEASE +#define LWIP_VERSION_STRING_SUFFIX "" +#elif LWIP_VERSION_IS_DEVELOPMENT +#define LWIP_VERSION_STRING_SUFFIX "d" +#else +#define LWIP_VERSION_STRING_SUFFIX "rc" LWIP_VERSTR(LWIP_VERSION_RC) +#endif + +/** Provides the version of the stack */ +#define LWIP_VERSION ((LWIP_VERSION_MAJOR) << 24 | (LWIP_VERSION_MINOR) << 16 | \ + (LWIP_VERSION_REVISION) << 8 | (LWIP_VERSION_RC)) +/** Provides the version of the stack as string */ +#define LWIP_VERSION_STRING LWIP_VERSTR(LWIP_VERSION_MAJOR) "." LWIP_VERSTR(LWIP_VERSION_MINOR) "." LWIP_VERSTR(LWIP_VERSION_REVISION) LWIP_VERSION_STRING_SUFFIX + +/** + * @} + */ + +/* Modules initialization */ +void lwip_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_INIT_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip.h new file mode 100644 index 000000000..653c3b2f4 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip.h @@ -0,0 +1,330 @@ +/** + * @file + * IP API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_IP_H +#define LWIP_HDR_IP_H + +#include "lwip/opt.h" + +#include "lwip/def.h" +#include "lwip/pbuf.h" +#include "lwip/ip_addr.h" +#include "lwip/err.h" +#include "lwip/netif.h" +#include "lwip/ip4.h" +#include "lwip/ip6.h" +#include "lwip/prot/ip.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* This is passed as the destination address to ip_output_if (not + to ip_output), meaning that an IP header already is constructed + in the pbuf. This is used when TCP retransmits. */ +#define LWIP_IP_HDRINCL NULL + +/** pbufs passed to IP must have a ref-count of 1 as their payload pointer + gets altered as the packet is passed down the stack */ +#ifndef LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX +#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p) LWIP_ASSERT("p->ref == 1", (p)->ref == 1) +#endif + +#if LWIP_NETIF_USE_HINTS +#define IP_PCB_NETIFHINT ;struct netif_hint netif_hints +#else /* LWIP_NETIF_USE_HINTS */ +#define IP_PCB_NETIFHINT +#endif /* LWIP_NETIF_USE_HINTS */ + +/** This is the common part of all PCB types. It needs to be at the + beginning of a PCB type definition. It is located here so that + changes to this common part are made in one location instead of + having to change all PCB structs. */ +#define IP_PCB \ + /* ip addresses in network byte order */ \ + ip_addr_t local_ip; \ + ip_addr_t remote_ip; \ + /* Bound netif index */ \ + u8_t netif_idx; \ + /* Socket options */ \ + u8_t so_options; \ + /* Type Of Service */ \ + u8_t tos; \ + /* Time To Live */ \ + u8_t ttl \ + /* link layer address resolution hint */ \ + IP_PCB_NETIFHINT + +struct ip_pcb { + /* Common members of all PCB types */ + IP_PCB; +}; + +/* + * Option flags per-socket. These are the same like SO_XXX in sockets.h + */ +#define SOF_REUSEADDR 0x04U /* allow local address reuse */ +#define SOF_KEEPALIVE 0x08U /* keep connections alive */ +#define SOF_BROADCAST 0x20U /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ + +/* These flags are inherited (e.g. from a listen-pcb to a connection-pcb): */ +#define SOF_INHERITED (SOF_REUSEADDR|SOF_KEEPALIVE) + +/** Global variables of this module, kept in a struct for efficient access using base+index. */ +struct ip_globals +{ + /** The interface that accepted the packet for the current callback invocation. */ + struct netif *current_netif; + /** The interface that received the packet for the current callback invocation. */ + struct netif *current_input_netif; +#if LWIP_IPV4 + /** Header of the input packet currently being processed. */ + const struct ip_hdr *current_ip4_header; +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 + /** Header of the input IPv6 packet currently being processed. */ + struct ip6_hdr *current_ip6_header; +#endif /* LWIP_IPV6 */ + /** Total header length of current_ip4/6_header (i.e. after this, the UDP/TCP header starts) */ + u16_t current_ip_header_tot_len; + /** Source IP address of current_header */ + ip_addr_t current_iphdr_src; + /** Destination IP address of current_header */ + ip_addr_t current_iphdr_dest; +}; +extern struct ip_globals ip_data; + + +/** Get the interface that accepted the current packet. + * This may or may not be the receiving netif, depending on your netif/network setup. + * This function must only be called from a receive callback (udp_recv, + * raw_recv, tcp_accept). It will return NULL otherwise. */ +#define ip_current_netif() (ip_data.current_netif) +/** Get the interface that received the current packet. + * This function must only be called from a receive callback (udp_recv, + * raw_recv, tcp_accept). It will return NULL otherwise. */ +#define ip_current_input_netif() (ip_data.current_input_netif) +/** Total header length of ip(6)_current_header() (i.e. after this, the UDP/TCP header starts) */ +#define ip_current_header_tot_len() (ip_data.current_ip_header_tot_len) +/** Source IP address of current_header */ +#define ip_current_src_addr() (&ip_data.current_iphdr_src) +/** Destination IP address of current_header */ +#define ip_current_dest_addr() (&ip_data.current_iphdr_dest) + +#if LWIP_IPV4 && LWIP_IPV6 +/** Get the IPv4 header of the current packet. + * This function must only be called from a receive callback (udp_recv, + * raw_recv, tcp_accept). It will return NULL otherwise. */ +#define ip4_current_header() ip_data.current_ip4_header +/** Get the IPv6 header of the current packet. + * This function must only be called from a receive callback (udp_recv, + * raw_recv, tcp_accept). It will return NULL otherwise. */ +#define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header)) +/** Returns TRUE if the current IP input packet is IPv6, FALSE if it is IPv4 */ +#define ip_current_is_v6() (ip6_current_header() != NULL) +/** Source IPv6 address of current_header */ +#define ip6_current_src_addr() (ip_2_ip6(&ip_data.current_iphdr_src)) +/** Destination IPv6 address of current_header */ +#define ip6_current_dest_addr() (ip_2_ip6(&ip_data.current_iphdr_dest)) +/** Get the transport layer protocol */ +#define ip_current_header_proto() (ip_current_is_v6() ? \ + IP6H_NEXTH(ip6_current_header()) :\ + IPH_PROTO(ip4_current_header())) +/** Get the transport layer header */ +#define ip_next_header_ptr() ((const void*)((ip_current_is_v6() ? \ + (const u8_t*)ip6_current_header() : (const u8_t*)ip4_current_header()) + ip_current_header_tot_len())) + +/** Source IP4 address of current_header */ +#define ip4_current_src_addr() (ip_2_ip4(&ip_data.current_iphdr_src)) +/** Destination IP4 address of current_header */ +#define ip4_current_dest_addr() (ip_2_ip4(&ip_data.current_iphdr_dest)) + +#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */ + +/** Get the IPv4 header of the current packet. + * This function must only be called from a receive callback (udp_recv, + * raw_recv, tcp_accept). It will return NULL otherwise. */ +#define ip4_current_header() ip_data.current_ip4_header +/** Always returns FALSE when only supporting IPv4 only */ +#define ip_current_is_v6() 0 +/** Get the transport layer protocol */ +#define ip_current_header_proto() IPH_PROTO(ip4_current_header()) +/** Get the transport layer header */ +#define ip_next_header_ptr() ((const void*)((const u8_t*)ip4_current_header() + ip_current_header_tot_len())) +/** Source IP4 address of current_header */ +#define ip4_current_src_addr() (&ip_data.current_iphdr_src) +/** Destination IP4 address of current_header */ +#define ip4_current_dest_addr() (&ip_data.current_iphdr_dest) + +#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */ + +/** Get the IPv6 header of the current packet. + * This function must only be called from a receive callback (udp_recv, + * raw_recv, tcp_accept). It will return NULL otherwise. */ +#define ip6_current_header() ((const struct ip6_hdr*)(ip_data.current_ip6_header)) +/** Always returns TRUE when only supporting IPv6 only */ +#define ip_current_is_v6() 1 +/** Get the transport layer protocol */ +#define ip_current_header_proto() IP6H_NEXTH(ip6_current_header()) +/** Get the transport layer header */ +#define ip_next_header_ptr() ((const void*)(((const u8_t*)ip6_current_header()) + ip_current_header_tot_len())) +/** Source IP6 address of current_header */ +#define ip6_current_src_addr() (&ip_data.current_iphdr_src) +/** Destination IP6 address of current_header */ +#define ip6_current_dest_addr() (&ip_data.current_iphdr_dest) + +#endif /* LWIP_IPV6 */ + +/** Union source address of current_header */ +#define ip_current_src_addr() (&ip_data.current_iphdr_src) +/** Union destination address of current_header */ +#define ip_current_dest_addr() (&ip_data.current_iphdr_dest) + +/** Gets an IP pcb option (SOF_* flags) */ +#define ip_get_option(pcb, opt) ((pcb)->so_options & (opt)) +/** Sets an IP pcb option (SOF_* flags) */ +#define ip_set_option(pcb, opt) ((pcb)->so_options = (u8_t)((pcb)->so_options | (opt))) +/** Resets an IP pcb option (SOF_* flags) */ +#define ip_reset_option(pcb, opt) ((pcb)->so_options = (u8_t)((pcb)->so_options & ~(opt))) + +#if LWIP_IPV4 && LWIP_IPV6 +/** + * @ingroup ip + * Output IP packet, netif is selected by source address + */ +#define ip_output(p, src, dest, ttl, tos, proto) \ + (IP_IS_V6(dest) ? \ + ip6_output(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto) : \ + ip4_output(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto)) +/** + * @ingroup ip + * Output IP packet to specified interface + */ +#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \ + (IP_IS_V6(dest) ? \ + ip6_output_if(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \ + ip4_output_if(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif)) +/** + * @ingroup ip + * Output IP packet to interface specifying source address + */ +#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \ + (IP_IS_V6(dest) ? \ + ip6_output_if_src(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif) : \ + ip4_output_if_src(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif)) +/** Output IP packet that already includes an IP header. */ +#define ip_output_if_hdrincl(p, src, dest, netif) \ + (IP_IS_V6(dest) ? \ + ip6_output_if(p, ip_2_ip6(src), LWIP_IP_HDRINCL, 0, 0, 0, netif) : \ + ip4_output_if(p, ip_2_ip4(src), LWIP_IP_HDRINCL, 0, 0, 0, netif)) +/** Output IP packet with netif_hint */ +#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \ + (IP_IS_V6(dest) ? \ + ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif_hint) : \ + ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, netif_hint)) +/** + * @ingroup ip + * Get netif for address combination. See \ref ip6_route and \ref ip4_route + */ +#define ip_route(src, dest) \ + (IP_IS_V6(dest) ? \ + ip6_route(ip_2_ip6(src), ip_2_ip6(dest)) : \ + ip4_route_src(ip_2_ip4(src), ip_2_ip4(dest))) +/** + * @ingroup ip + * Get netif for IP. + */ +#define ip_netif_get_local_ip(netif, dest) (IP_IS_V6(dest) ? \ + ip6_netif_get_local_ip(netif, ip_2_ip6(dest)) : \ + ip4_netif_get_local_ip(netif)) +#define ip_debug_print(is_ipv6, p) ((is_ipv6) ? ip6_debug_print(p) : ip4_debug_print(p)) + +err_t ip_input(struct pbuf *p, struct netif *inp); + +#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */ + +#define ip_output(p, src, dest, ttl, tos, proto) \ + ip4_output(p, src, dest, ttl, tos, proto) +#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \ + ip4_output_if(p, src, dest, ttl, tos, proto, netif) +#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \ + ip4_output_if_src(p, src, dest, ttl, tos, proto, netif) +#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \ + ip4_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) +#define ip_output_if_hdrincl(p, src, dest, netif) \ + ip4_output_if(p, src, LWIP_IP_HDRINCL, 0, 0, 0, netif) +#define ip_route(src, dest) \ + ip4_route_src(src, dest) +#define ip_netif_get_local_ip(netif, dest) \ + ip4_netif_get_local_ip(netif) +#define ip_debug_print(is_ipv6, p) ip4_debug_print(p) + +#define ip_input ip4_input + +#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */ + +#define ip_output(p, src, dest, ttl, tos, proto) \ + ip6_output(p, src, dest, ttl, tos, proto) +#define ip_output_if(p, src, dest, ttl, tos, proto, netif) \ + ip6_output_if(p, src, dest, ttl, tos, proto, netif) +#define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \ + ip6_output_if_src(p, src, dest, ttl, tos, proto, netif) +#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \ + ip6_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) +#define ip_output_if_hdrincl(p, src, dest, netif) \ + ip6_output_if(p, src, LWIP_IP_HDRINCL, 0, 0, 0, netif) +#define ip_route(src, dest) \ + ip6_route(src, dest) +#define ip_netif_get_local_ip(netif, dest) \ + ip6_netif_get_local_ip(netif, dest) +#define ip_debug_print(is_ipv6, p) ip6_debug_print(p) + +#define ip_input ip6_input + +#endif /* LWIP_IPV6 */ + +#define ip_route_get_local_ip(src, dest, netif, ipaddr) do { \ + (netif) = ip_route(src, dest); \ + (ipaddr) = ip_netif_get_local_ip(netif, dest); \ +}while(0) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_IP_H */ + + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4.h new file mode 100644 index 000000000..fd35a3369 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4.h @@ -0,0 +1,111 @@ +/** + * @file + * IPv4 API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_IP4_H +#define LWIP_HDR_IP4_H + +#include "lwip/opt.h" + +#if LWIP_IPV4 + +#include "lwip/def.h" +#include "lwip/pbuf.h" +#include "lwip/ip4_addr.h" +#include "lwip/err.h" +#include "lwip/netif.h" +#include "lwip/prot/ip4.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef LWIP_HOOK_IP4_ROUTE_SRC +#define LWIP_IPV4_SRC_ROUTING 1 +#else +#define LWIP_IPV4_SRC_ROUTING 0 +#endif + +/** Currently, the function ip_output_if_opt() is only used with IGMP */ +#define IP_OPTIONS_SEND (LWIP_IPV4 && LWIP_IGMP) + +#define ip_init() /* Compatibility define, no init needed. */ +struct netif *ip4_route(const ip4_addr_t *dest); +#if LWIP_IPV4_SRC_ROUTING +struct netif *ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest); +#else /* LWIP_IPV4_SRC_ROUTING */ +#define ip4_route_src(src, dest) ip4_route(dest) +#endif /* LWIP_IPV4_SRC_ROUTING */ +err_t ip4_input(struct pbuf *p, struct netif *inp); +err_t ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, u8_t proto); +err_t ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, u8_t proto, struct netif *netif); +err_t ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, u8_t proto, struct netif *netif); +#if LWIP_NETIF_USE_HINTS +err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, u8_t proto, struct netif_hint *netif_hint); +#endif /* LWIP_NETIF_USE_HINTS */ +#if IP_OPTIONS_SEND +err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options, + u16_t optlen); +err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, + u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options, + u16_t optlen); +#endif /* IP_OPTIONS_SEND */ + +#if LWIP_MULTICAST_TX_OPTIONS +void ip4_set_default_multicast_netif(struct netif* default_multicast_netif); +#endif /* LWIP_MULTICAST_TX_OPTIONS */ + +#define ip4_netif_get_local_ip(netif) (((netif) != NULL) ? netif_ip_addr4(netif) : NULL) + +#if IP_DEBUG +void ip4_debug_print(struct pbuf *p); +#else +#define ip4_debug_print(p) +#endif /* IP_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 */ + +#endif /* LWIP_HDR_IP_H */ + + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4_addr.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4_addr.h new file mode 100644 index 000000000..f244c4f54 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4_addr.h @@ -0,0 +1,216 @@ +/** + * @file + * IPv4 address API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_IP4_ADDR_H +#define LWIP_HDR_IP4_ADDR_H + +#include "lwip/opt.h" +#include "lwip/def.h" + +#if LWIP_IPV4 + +#ifdef __cplusplus +extern "C" { +#endif + +/** This is the aligned version of ip4_addr_t, + used as local variable, on the stack, etc. */ +struct ip4_addr { + u32_t addr; +}; + +/** ip4_addr_t uses a struct for convenience only, so that the same defines can + * operate both on ip4_addr_t as well as on ip4_addr_p_t. */ +typedef struct ip4_addr ip4_addr_t; + +/* Forward declaration to not include netif.h */ +struct netif; + +/** 255.255.255.255 */ +#define IPADDR_NONE ((u32_t)0xffffffffUL) +/** 127.0.0.1 */ +#define IPADDR_LOOPBACK ((u32_t)0x7f000001UL) +/** 0.0.0.0 */ +#define IPADDR_ANY ((u32_t)0x00000000UL) +/** 255.255.255.255 */ +#define IPADDR_BROADCAST ((u32_t)0xffffffffUL) + +/* Definitions of the bits in an Internet address integer. + + On subnets, host and network parts are found according to + the subnet mask, not these masks. */ +#define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0) +#define IP_CLASSA_NET 0xff000000 +#define IP_CLASSA_NSHIFT 24 +#define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET) +#define IP_CLASSA_MAX 128 + +#define IP_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL) +#define IP_CLASSB_NET 0xffff0000 +#define IP_CLASSB_NSHIFT 16 +#define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET) +#define IP_CLASSB_MAX 65536 + +#define IP_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL) +#define IP_CLASSC_NET 0xffffff00 +#define IP_CLASSC_NSHIFT 8 +#define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET) + +#define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL) +#define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */ +#define IP_CLASSD_NSHIFT 28 /* net and host fields, but */ +#define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */ +#define IP_MULTICAST(a) IP_CLASSD(a) + +#define IP_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL) +#define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL) + +#define IP_LOOPBACKNET 127 /* official! */ + +/** Set an IP address given by the four byte-parts */ +#define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d)) + +/** Copy IP address - faster than ip4_addr_set: no NULL check */ +#define ip4_addr_copy(dest, src) ((dest).addr = (src).addr) +/** Safely copy one IP address to another (src may be NULL) */ +#define ip4_addr_set(dest, src) ((dest)->addr = \ + ((src) == NULL ? 0 : \ + (src)->addr)) +/** Set complete address to zero */ +#define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0) +/** Set address to IPADDR_ANY (no need for lwip_htonl()) */ +#define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY) +/** Set address to loopback address */ +#define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK)) +/** Check if an address is in the loopback region */ +#define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24)) +/** Safely copy one IP address to another and change byte order + * from host- to network-order. */ +#define ip4_addr_set_hton(dest, src) ((dest)->addr = \ + ((src) == NULL ? 0:\ + lwip_htonl((src)->addr))) +/** IPv4 only: set the IP address given as an u32_t */ +#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32)) +/** IPv4 only: get the IP address as an u32_t */ +#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr) + +/** Get the network address by combining host address with netmask */ +#define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0) + +/** + * Determine if two address are on the same network. + * + * @arg addr1 IP address 1 + * @arg addr2 IP address 2 + * @arg mask network identifier mask + * @return !0 if the network identifiers of both address match + */ +#define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ + (mask)->addr) == \ + ((addr2)->addr & \ + (mask)->addr)) +#define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr) + +#define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY) +#define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1))) + +#define ip4_addr_isbroadcast(addr1, netif) ip4_addr_isbroadcast_u32((addr1)->addr, netif) +u8_t ip4_addr_isbroadcast_u32(u32_t addr, const struct netif *netif); + +#define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr) +u8_t ip4_addr_netmask_valid(u32_t netmask); + +#define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL)) + +#define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL)) + +#define ip4_addr_debug_print_parts(debug, a, b, c, d) \ + LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d)) +#define ip4_addr_debug_print(debug, ipaddr) \ + ip4_addr_debug_print_parts(debug, \ + (u16_t)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0)) +#define ip4_addr_debug_print_val(debug, ipaddr) \ + ip4_addr_debug_print_parts(debug, \ + ip4_addr1_16_val(ipaddr), \ + ip4_addr2_16_val(ipaddr), \ + ip4_addr3_16_val(ipaddr), \ + ip4_addr4_16_val(ipaddr)) + +/* Get one byte from the 4-byte address */ +#define ip4_addr_get_byte(ipaddr, idx) (((const u8_t*)(&(ipaddr)->addr))[idx]) +#define ip4_addr1(ipaddr) ip4_addr_get_byte(ipaddr, 0) +#define ip4_addr2(ipaddr) ip4_addr_get_byte(ipaddr, 1) +#define ip4_addr3(ipaddr) ip4_addr_get_byte(ipaddr, 2) +#define ip4_addr4(ipaddr) ip4_addr_get_byte(ipaddr, 3) +/* Get one byte from the 4-byte address, but argument is 'ip4_addr_t', + * not a pointer */ +#define ip4_addr_get_byte_val(ipaddr, idx) ((u8_t)(((ipaddr).addr >> (idx * 8)) & 0xff)) +#define ip4_addr1_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 0) +#define ip4_addr2_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 1) +#define ip4_addr3_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 2) +#define ip4_addr4_val(ipaddr) ip4_addr_get_byte_val(ipaddr, 3) +/* These are cast to u16_t, with the intent that they are often arguments + * to printf using the U16_F format from cc.h. */ +#define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr)) +#define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr)) +#define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr)) +#define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr)) +#define ip4_addr1_16_val(ipaddr) ((u16_t)ip4_addr1_val(ipaddr)) +#define ip4_addr2_16_val(ipaddr) ((u16_t)ip4_addr2_val(ipaddr)) +#define ip4_addr3_16_val(ipaddr) ((u16_t)ip4_addr3_val(ipaddr)) +#define ip4_addr4_16_val(ipaddr) ((u16_t)ip4_addr4_val(ipaddr)) + +#define IP4ADDR_STRLEN_MAX 16 + +/** For backwards compatibility */ +#define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr) + +u32_t ipaddr_addr(const char *cp); +int ip4addr_aton(const char *cp, ip4_addr_t *addr); +/** returns ptr to static buffer; not reentrant! */ +char *ip4addr_ntoa(const ip4_addr_t *addr); +char *ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 */ + +#endif /* LWIP_HDR_IP_ADDR_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4_frag.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4_frag.h new file mode 100644 index 000000000..ed5bf14a3 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip4_frag.h @@ -0,0 +1,100 @@ +/** + * @file + * IP fragmentation/reassembly + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Jani Monoses + * + */ + +#ifndef LWIP_HDR_IP4_FRAG_H +#define LWIP_HDR_IP4_FRAG_H + +#include "lwip/opt.h" +#include "lwip/err.h" +#include "lwip/pbuf.h" +#include "lwip/netif.h" +#include "lwip/ip_addr.h" +#include "lwip/ip.h" + +#if LWIP_IPV4 + +#ifdef __cplusplus +extern "C" { +#endif + +#if IP_REASSEMBLY +/* The IP reassembly timer interval in milliseconds. */ +#define IP_TMR_INTERVAL 1000 + +/** IP reassembly helper struct. + * This is exported because memp needs to know the size. + */ +struct ip_reassdata { + struct ip_reassdata *next; + struct pbuf *p; + struct ip_hdr iphdr; + u16_t datagram_len; + u8_t flags; + u8_t timer; +}; + +void ip_reass_init(void); +void ip_reass_tmr(void); +struct pbuf * ip4_reass(struct pbuf *p); +#endif /* IP_REASSEMBLY */ + +#if IP_FRAG +#if !LWIP_NETIF_TX_SINGLE_PBUF +#ifndef LWIP_PBUF_CUSTOM_REF_DEFINED +#define LWIP_PBUF_CUSTOM_REF_DEFINED +/** A custom pbuf that holds a reference to another pbuf, which is freed + * when this custom pbuf is freed. This is used to create a custom PBUF_REF + * that points into the original pbuf. */ +struct pbuf_custom_ref { + /** 'base class' */ + struct pbuf_custom pc; + /** pointer to the original pbuf that is referenced */ + struct pbuf *original; +}; +#endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */ +#endif /* !LWIP_NETIF_TX_SINGLE_PBUF */ + +err_t ip4_frag(struct pbuf *p, struct netif *netif, const ip4_addr_t *dest); +#endif /* IP_FRAG */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV4 */ + +#endif /* LWIP_HDR_IP4_FRAG_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6.h new file mode 100644 index 000000000..f894e063e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6.h @@ -0,0 +1,93 @@ +/** + * @file + * + * IPv6 layer. + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ +#ifndef LWIP_HDR_IP6_H +#define LWIP_HDR_IP6_H + +#include "lwip/opt.h" + +#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/ip6_addr.h" +#include "lwip/prot/ip6.h" +#include "lwip/def.h" +#include "lwip/pbuf.h" +#include "lwip/netif.h" + +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct netif *ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest); +const ip_addr_t *ip6_select_source_address(struct netif *netif, const ip6_addr_t * dest); +err_t ip6_input(struct pbuf *p, struct netif *inp); +err_t ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, + u8_t hl, u8_t tc, u8_t nexth); +err_t ip6_output_if(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, + u8_t hl, u8_t tc, u8_t nexth, struct netif *netif); +err_t ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, + u8_t hl, u8_t tc, u8_t nexth, struct netif *netif); +#if LWIP_NETIF_USE_HINTS +err_t ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, + u8_t hl, u8_t tc, u8_t nexth, struct netif_hint *netif_hint); +#endif /* LWIP_NETIF_USE_HINTS */ +#if LWIP_IPV6_MLD +err_t ip6_options_add_hbh_ra(struct pbuf * p, u8_t nexth, u8_t value); +#endif /* LWIP_IPV6_MLD */ + +#define ip6_netif_get_local_ip(netif, dest) (((netif) != NULL) ? \ + ip6_select_source_address(netif, dest) : NULL) + +#if IP6_DEBUG +void ip6_debug_print(struct pbuf *p); +#else +#define ip6_debug_print(p) +#endif /* IP6_DEBUG */ + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 */ + +#endif /* LWIP_HDR_IP6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_addr.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_addr.h new file mode 100644 index 000000000..29c2a34d9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_addr.h @@ -0,0 +1,352 @@ +/** + * @file + * + * IPv6 addresses. + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * Structs and macros for handling IPv6 addresses. + * + * Please coordinate changes and requests with Ivan Delamer + * + */ +#ifndef LWIP_HDR_IP6_ADDR_H +#define LWIP_HDR_IP6_ADDR_H + +#include "lwip/opt.h" +#include "def.h" + +#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/ip6_zone.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** This is the aligned version of ip6_addr_t, + used as local variable, on the stack, etc. */ +struct ip6_addr { + u32_t addr[4]; +#if LWIP_IPV6_SCOPES + u8_t zone; +#endif /* LWIP_IPV6_SCOPES */ +}; + +/** IPv6 address */ +typedef struct ip6_addr ip6_addr_t; + +/** Set an IPv6 partial address given by byte-parts */ +#define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \ + (ip6addr)->addr[index] = PP_HTONL(LWIP_MAKEU32(a,b,c,d)) + +/** Set a full IPv6 address by passing the 4 u32_t indices in network byte order + (use PP_HTONL() for constants) */ +#define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) do { \ + (ip6addr)->addr[0] = idx0; \ + (ip6addr)->addr[1] = idx1; \ + (ip6addr)->addr[2] = idx2; \ + (ip6addr)->addr[3] = idx3; \ + ip6_addr_clear_zone(ip6addr); } while(0) + +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK1(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff)) +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK2(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0])) & 0xffff)) +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK3(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff)) +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK4(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1])) & 0xffff)) +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK5(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff)) +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK6(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2])) & 0xffff)) +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK7(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff)) +/** Access address in 16-bit block */ +#define IP6_ADDR_BLOCK8(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3])) & 0xffff)) + +/** Copy IPv6 address - faster than ip6_addr_set: no NULL check */ +#define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \ + (dest).addr[1] = (src).addr[1]; \ + (dest).addr[2] = (src).addr[2]; \ + (dest).addr[3] = (src).addr[3]; \ + ip6_addr_copy_zone((dest), (src)); }while(0) +/** Safely copy one IPv6 address to another (src may be NULL) */ +#define ip6_addr_set(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \ + (dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \ + (dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \ + (dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3]; \ + ip6_addr_set_zone((dest), (src) == NULL ? IP6_NO_ZONE : ip6_addr_zone(src)); }while(0) + +/** Copy packed IPv6 address to unpacked IPv6 address; zone is not set */ +#define ip6_addr_copy_from_packed(dest, src) do{(dest).addr[0] = (src).addr[0]; \ + (dest).addr[1] = (src).addr[1]; \ + (dest).addr[2] = (src).addr[2]; \ + (dest).addr[3] = (src).addr[3]; \ + ip6_addr_clear_zone(&dest); }while(0) + +/** Copy unpacked IPv6 address to packed IPv6 address; zone is lost */ +#define ip6_addr_copy_to_packed(dest, src) do{(dest).addr[0] = (src).addr[0]; \ + (dest).addr[1] = (src).addr[1]; \ + (dest).addr[2] = (src).addr[2]; \ + (dest).addr[3] = (src).addr[3]; }while(0) + +/** Set complete address to zero */ +#define ip6_addr_set_zero(ip6addr) do{(ip6addr)->addr[0] = 0; \ + (ip6addr)->addr[1] = 0; \ + (ip6addr)->addr[2] = 0; \ + (ip6addr)->addr[3] = 0; \ + ip6_addr_clear_zone(ip6addr);}while(0) + +/** Set address to ipv6 'any' (no need for lwip_htonl()) */ +#define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr) +/** Set address to ipv6 loopback address */ +#define ip6_addr_set_loopback(ip6addr) do{(ip6addr)->addr[0] = 0; \ + (ip6addr)->addr[1] = 0; \ + (ip6addr)->addr[2] = 0; \ + (ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \ + ip6_addr_clear_zone(ip6addr);}while(0) +/** Safely copy one IPv6 address to another and change byte order + * from host- to network-order. */ +#define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \ + (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \ + (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \ + (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]); \ + ip6_addr_set_zone((dest), (src) == NULL ? IP6_NO_ZONE : ip6_addr_zone(src));}while(0) + + +/** Compare IPv6 networks, ignoring zone information. To be used sparingly! */ +#define ip6_addr_netcmp_zoneless(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \ + ((addr1)->addr[1] == (addr2)->addr[1])) + +/** + * Determine if two IPv6 address are on the same network. + * + * @param addr1 IPv6 address 1 + * @param addr2 IPv6 address 2 + * @return 1 if the network identifiers of both address match, 0 if not + */ +#define ip6_addr_netcmp(addr1, addr2) (ip6_addr_netcmp_zoneless((addr1), (addr2)) && \ + ip6_addr_cmp_zone((addr1), (addr2))) + +/* Exact-host comparison *after* ip6_addr_netcmp() succeeded, for efficiency. */ +#define ip6_addr_nethostcmp(addr1, addr2) (((addr1)->addr[2] == (addr2)->addr[2]) && \ + ((addr1)->addr[3] == (addr2)->addr[3])) + +/** Compare IPv6 addresses, ignoring zone information. To be used sparingly! */ +#define ip6_addr_cmp_zoneless(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \ + ((addr1)->addr[1] == (addr2)->addr[1]) && \ + ((addr1)->addr[2] == (addr2)->addr[2]) && \ + ((addr1)->addr[3] == (addr2)->addr[3])) +/** + * Determine if two IPv6 addresses are the same. In particular, the address + * part of both must be the same, and the zone must be compatible. + * + * @param addr1 IPv6 address 1 + * @param addr2 IPv6 address 2 + * @return 1 if the addresses are considered equal, 0 if not + */ +#define ip6_addr_cmp(addr1, addr2) (ip6_addr_cmp_zoneless((addr1), (addr2)) && \ + ip6_addr_cmp_zone((addr1), (addr2))) + +/** Compare IPv6 address to packed address and zone */ +#define ip6_addr_cmp_packed(ip6addr, paddr, zone_idx) (((ip6addr)->addr[0] == (paddr)->addr[0]) && \ + ((ip6addr)->addr[1] == (paddr)->addr[1]) && \ + ((ip6addr)->addr[2] == (paddr)->addr[2]) && \ + ((ip6addr)->addr[3] == (paddr)->addr[3]) && \ + ip6_addr_equals_zone((ip6addr), (zone_idx))) + +#define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL) + +#define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \ + ((ip6addr).addr[1] == 0) && \ + ((ip6addr).addr[2] == 0) && \ + ((ip6addr).addr[3] == 0)) +#define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr))) + +#define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \ + ((ip6addr)->addr[1] == 0UL) && \ + ((ip6addr)->addr[2] == 0UL) && \ + ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL))) + +#define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL)) + +#define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL)) + +#define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL)) + +#define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL)) + +#define ip6_addr_isipv4mappedipv6(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL))) + +#define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)) +#define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL)) +#define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL)) +#define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL)) +#define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf) +#define IP6_MULTICAST_SCOPE_RESERVED 0x0 +#define IP6_MULTICAST_SCOPE_RESERVED0 0x0 +#define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1 +#define IP6_MULTICAST_SCOPE_LINK_LOCAL 0x2 +#define IP6_MULTICAST_SCOPE_RESERVED3 0x3 +#define IP6_MULTICAST_SCOPE_ADMIN_LOCAL 0x4 +#define IP6_MULTICAST_SCOPE_SITE_LOCAL 0x5 +#define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL 0x8 +#define IP6_MULTICAST_SCOPE_GLOBAL 0xe +#define IP6_MULTICAST_SCOPE_RESERVEDF 0xf +#define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL)) +#define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL)) +#define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL)) +#define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL)) +#define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL)) +#define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL)) + +/* Scoping note: while interface-local and link-local multicast addresses do + * have a scope (i.e., they are meaningful only in the context of a particular + * interface), the following functions are not assigning or comparing zone + * indices. The reason for this is backward compatibility. Any call site that + * produces a non-global multicast address must assign a multicast address as + * appropriate itself. */ + +#define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \ + ((ip6addr)->addr[1] == 0UL) && \ + ((ip6addr)->addr[2] == 0UL) && \ + ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL))) + +#define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \ + ((ip6addr)->addr[1] == 0UL) && \ + ((ip6addr)->addr[2] == 0UL) && \ + ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL))) +#define ip6_addr_set_allnodes_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \ + (ip6addr)->addr[1] = 0; \ + (ip6addr)->addr[2] = 0; \ + (ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \ + ip6_addr_clear_zone(ip6addr); }while(0) + +#define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \ + ((ip6addr)->addr[1] == 0UL) && \ + ((ip6addr)->addr[2] == 0UL) && \ + ((ip6addr)->addr[3] == PP_HTONL(0x00000002UL))) +#define ip6_addr_set_allrouters_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \ + (ip6addr)->addr[1] = 0; \ + (ip6addr)->addr[2] = 0; \ + (ip6addr)->addr[3] = PP_HTONL(0x00000002UL); \ + ip6_addr_clear_zone(ip6addr); }while(0) + +#define ip6_addr_issolicitednode(ip6addr) ( ((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \ + ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \ + (((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)) ) + +#define ip6_addr_set_solicitednode(ip6addr, if_id) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \ + (ip6addr)->addr[1] = 0; \ + (ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \ + (ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id)); \ + ip6_addr_clear_zone(ip6addr); }while(0) + +#define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \ + ((ip6addr)->addr[1] == 0) && \ + ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \ + ((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3]))) + +/* IPv6 address states. */ +#define IP6_ADDR_INVALID 0x00 +#define IP6_ADDR_TENTATIVE 0x08 +#define IP6_ADDR_TENTATIVE_1 0x09 /* 1 probe sent */ +#define IP6_ADDR_TENTATIVE_2 0x0a /* 2 probes sent */ +#define IP6_ADDR_TENTATIVE_3 0x0b /* 3 probes sent */ +#define IP6_ADDR_TENTATIVE_4 0x0c /* 4 probes sent */ +#define IP6_ADDR_TENTATIVE_5 0x0d /* 5 probes sent */ +#define IP6_ADDR_TENTATIVE_6 0x0e /* 6 probes sent */ +#define IP6_ADDR_TENTATIVE_7 0x0f /* 7 probes sent */ +#define IP6_ADDR_VALID 0x10 /* This bit marks an address as valid (preferred or deprecated) */ +#define IP6_ADDR_PREFERRED 0x30 +#define IP6_ADDR_DEPRECATED 0x10 /* Same as VALID (valid but not preferred) */ +#define IP6_ADDR_DUPLICATED 0x40 /* Failed DAD test, not valid */ + +#define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */ + +#define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID) +#define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE) +#define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */ +#define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED) +#define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED) +#define ip6_addr_isduplicated(addr_state) (addr_state == IP6_ADDR_DUPLICATED) + +#if LWIP_IPV6_ADDRESS_LIFETIMES +#define IP6_ADDR_LIFE_STATIC (0) +#define IP6_ADDR_LIFE_INFINITE (0xffffffffUL) +#define ip6_addr_life_isstatic(addr_life) ((addr_life) == IP6_ADDR_LIFE_STATIC) +#define ip6_addr_life_isinfinite(addr_life) ((addr_life) == IP6_ADDR_LIFE_INFINITE) +#endif /* LWIP_IPV6_ADDRESS_LIFETIMES */ + +#define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \ + LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \ + a, b, c, d, e, f, g, h)) +#define ip6_addr_debug_print(debug, ipaddr) \ + ip6_addr_debug_print_parts(debug, \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0)) +#define ip6_addr_debug_print_val(debug, ipaddr) \ + ip6_addr_debug_print_parts(debug, \ + IP6_ADDR_BLOCK1(&(ipaddr)), \ + IP6_ADDR_BLOCK2(&(ipaddr)), \ + IP6_ADDR_BLOCK3(&(ipaddr)), \ + IP6_ADDR_BLOCK4(&(ipaddr)), \ + IP6_ADDR_BLOCK5(&(ipaddr)), \ + IP6_ADDR_BLOCK6(&(ipaddr)), \ + IP6_ADDR_BLOCK7(&(ipaddr)), \ + IP6_ADDR_BLOCK8(&(ipaddr))) + +#define IP6ADDR_STRLEN_MAX 46 + +int ip6addr_aton(const char *cp, ip6_addr_t *addr); +/** returns ptr to static buffer; not reentrant! */ +char *ip6addr_ntoa(const ip6_addr_t *addr); +char *ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen); + + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 */ + +#endif /* LWIP_HDR_IP6_ADDR_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_frag.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_frag.h new file mode 100644 index 000000000..87e0e86a6 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_frag.h @@ -0,0 +1,144 @@ +/** + * @file + * + * IPv6 fragmentation and reassembly. + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ +#ifndef LWIP_HDR_IP6_FRAG_H +#define LWIP_HDR_IP6_FRAG_H + +#include "lwip/opt.h" +#include "lwip/pbuf.h" +#include "lwip/ip6_addr.h" +#include "lwip/ip6.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#if LWIP_IPV6 && LWIP_IPV6_REASS /* don't build if not configured for use in lwipopts.h */ + +/** The IPv6 reassembly timer interval in milliseconds. */ +#define IP6_REASS_TMR_INTERVAL 1000 + +/** IP6_FRAG_COPYHEADER==1: for platforms where sizeof(void*) > 4, "struct + * ip6_reass_helper" is too large to be stored in the IPv6 fragment header, and + * will bleed into the header before it, which may be the IPv6 header or an + * extension header. This means that for each first fragment packet, we need to + * 1) make a copy of some IPv6 header fields (src+dest) that we need later on, + * just in case we do overwrite part of the IPv6 header, and 2) make a copy of + * the header data that we overwrote, so that we can restore it before either + * completing reassembly or sending an ICMPv6 reply. The last part is true even + * if this setting is disabled, but if it is enabled, we need to save a bit + * more data (up to the size of a pointer) because we overwrite more. */ +#ifndef IPV6_FRAG_COPYHEADER +#define IPV6_FRAG_COPYHEADER 0 +#endif + +/* With IPV6_FRAG_COPYHEADER==1, a helper structure may (or, depending on the + * presence of extensions, may not) overwrite part of the IP header. Therefore, + * we copy the fields that we need from the IP header for as long as the helper + * structure may still be in place. This is easier than temporarily restoring + * those fields in the IP header each time we need to perform checks on them. */ +#if IPV6_FRAG_COPYHEADER +#define IPV6_FRAG_SRC(ipr) ((ipr)->src) +#define IPV6_FRAG_DEST(ipr) ((ipr)->dest) +#else /* IPV6_FRAG_COPYHEADER */ +#define IPV6_FRAG_SRC(ipr) ((ipr)->iphdr->src) +#define IPV6_FRAG_DEST(ipr) ((ipr)->iphdr->dest) +#endif /* IPV6_FRAG_COPYHEADER */ + +/** IPv6 reassembly helper struct. + * This is exported because memp needs to know the size. + */ +struct ip6_reassdata { + struct ip6_reassdata *next; + struct pbuf *p; + struct ip6_hdr *iphdr; /* pointer to the first (original) IPv6 header */ +#if IPV6_FRAG_COPYHEADER + ip6_addr_p_t src; /* copy of the source address in the IP header */ + ip6_addr_p_t dest; /* copy of the destination address in the IP header */ + /* This buffer (for the part of the original header that we overwrite) will + * be slightly oversized, but we cannot compute the exact size from here. */ + u8_t orig_hdr[sizeof(struct ip6_frag_hdr) + sizeof(void*)]; +#else /* IPV6_FRAG_COPYHEADER */ + /* In this case we still need the buffer, for sending ICMPv6 replies. */ + u8_t orig_hdr[sizeof(struct ip6_frag_hdr)]; +#endif /* IPV6_FRAG_COPYHEADER */ + u32_t identification; + u16_t datagram_len; + u8_t nexth; + u8_t timer; +#if LWIP_IPV6_SCOPES + u8_t src_zone; /* zone of original packet's source address */ + u8_t dest_zone; /* zone of original packet's destination address */ +#endif /* LWIP_IPV6_SCOPES */ +}; + +#define ip6_reass_init() /* Compatibility define */ +void ip6_reass_tmr(void); +struct pbuf *ip6_reass(struct pbuf *p); + +#endif /* LWIP_IPV6 && LWIP_IPV6_REASS */ + +#if LWIP_IPV6 && LWIP_IPV6_FRAG /* don't build if not configured for use in lwipopts.h */ + +#ifndef LWIP_PBUF_CUSTOM_REF_DEFINED +#define LWIP_PBUF_CUSTOM_REF_DEFINED +/** A custom pbuf that holds a reference to another pbuf, which is freed + * when this custom pbuf is freed. This is used to create a custom PBUF_REF + * that points into the original pbuf. */ +struct pbuf_custom_ref { + /** 'base class' */ + struct pbuf_custom pc; + /** pointer to the original pbuf that is referenced */ + struct pbuf *original; +}; +#endif /* LWIP_PBUF_CUSTOM_REF_DEFINED */ + +err_t ip6_frag(struct pbuf *p, struct netif *netif, const ip6_addr_t *dest); + +#endif /* LWIP_IPV6 && LWIP_IPV6_FRAG */ + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_IP6_FRAG_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_zone.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_zone.h new file mode 100644 index 000000000..525790e67 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip6_zone.h @@ -0,0 +1,304 @@ +/** + * @file + * + * IPv6 address scopes, zones, and scoping policy. + * + * This header provides the means to implement support for IPv6 address scopes, + * as per RFC 4007. An address scope can be either global or more constrained. + * In lwIP, we say that an address "has a scope" or "is scoped" when its scope + * is constrained, in which case the address is meaningful only in a specific + * "zone." For unicast addresses, only link-local addresses have a scope; in + * that case, the scope is the link. For multicast addresses, there are various + * scopes defined by RFC 4007 and others. For any constrained scope, a system + * must establish a (potentially one-to-many) mapping between zones and local + * interfaces. For example, a link-local address is valid on only one link (its + * zone). That link may be attached to one or more local interfaces. The + * decisions on which scopes are constrained and the mapping between zones and + * interfaces is together what we refer to as the "scoping policy" - more on + * this in a bit. + * + * In lwIP, each IPv6 address has an associated zone index. This zone index may + * be set to "no zone" (IP6_NO_ZONE, 0) or an actual zone. We say that an + * address "has a zone" or "is zoned" when its zone index is *not* set to "no + * zone." In lwIP, in principle, each address should be "properly zoned," which + * means that if the address has a zone if and only if has a scope. As such, it + * is a rule that an unscoped (e.g., global) address must never have a zone. + * Even though one could argue that there is always one zone even for global + * scopes, this rule exists for implementation simplicity. Violation of the + * rule will trigger assertions or otherwise result in undesired behavior. + * + * Backward compatibility prevents us from requiring that applications always + * provide properly zoned addresses. We do enforce the rule that the in the + * lwIP link layer (everything below netif->output_ip6() and in particular ND6) + * *all* addresses are properly zoned. Thus, on the output paths down the + * stack, various places deal with the case of addresses that lack a zone. + * Some of them are best-effort for efficiency (e.g. the PCB bind and connect + * API calls' attempts to add missing zones); ultimately the IPv6 output + * handler (@ref ip6_output_if_src) will set a zone if necessary. + * + * Aside from dealing with scoped addresses lacking a zone, a proper IPv6 + * implementation must also ensure that a packet with a scoped source and/or + * destination address does not leave its zone. This is currently implemented + * in the input and forward functions. However, for output, these checks are + * deliberately omitted in order to keep the implementation lightweight. The + * routing algorithm in @ref ip6_route will take decisions such that it will + * not cause zone violations unless the application sets bad addresses, though. + * + * In terms of scoping policy, lwIP implements the default policy from RFC 4007 + * using macros in this file. This policy considers link-local unicast + * addresses and (only) interface-local and link-local multicast addresses as + * having a scope. For all these addresses, the zone is equal to the interface. + * As shown below in this file, it is possible to implement a custom policy. + */ + +/* + * Copyright (c) 2017 The MINIX 3 Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: David van Moolenbroek + * + */ +#ifndef LWIP_HDR_IP6_ZONE_H +#define LWIP_HDR_IP6_ZONE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup ip6_zones IPv6 Zones + * @ingroup ip6 + * @{ + */ + +#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +/** Identifier for "no zone". */ +#define IP6_NO_ZONE 0 + +#if LWIP_IPV6_SCOPES + +/** Zone initializer for static IPv6 address initialization, including comma. */ +#define IPADDR6_ZONE_INIT , IP6_NO_ZONE + +/** Return the zone index of the given IPv6 address; possibly "no zone". */ +#define ip6_addr_zone(ip6addr) ((ip6addr)->zone) + +/** Does the given IPv6 address have a zone set? (0/1) */ +#define ip6_addr_has_zone(ip6addr) (ip6_addr_zone(ip6addr) != IP6_NO_ZONE) + +/** Set the zone field of an IPv6 address to a particular value. */ +#define ip6_addr_set_zone(ip6addr, zone_idx) ((ip6addr)->zone = (zone_idx)) + +/** Clear the zone field of an IPv6 address, setting it to "no zone". */ +#define ip6_addr_clear_zone(ip6addr) ((ip6addr)->zone = IP6_NO_ZONE) + +/** Copy the zone field from the second IPv6 address to the first one. */ +#define ip6_addr_copy_zone(ip6addr1, ip6addr2) ((ip6addr1).zone = (ip6addr2).zone) + +/** Is the zone field of the given IPv6 address equal to the given zone index? (0/1) */ +#define ip6_addr_equals_zone(ip6addr, zone_idx) ((ip6addr)->zone == (zone_idx)) + +/** Are the zone fields of the given IPv6 addresses equal? (0/1) + * This macro must only be used on IPv6 addresses of the same scope. */ +#define ip6_addr_cmp_zone(ip6addr1, ip6addr2) ((ip6addr1)->zone == (ip6addr2)->zone) + +/** Symbolic constants for the 'type' parameters in some of the macros. + * These exist for efficiency only, allowing the macros to avoid certain tests + * when the address is known not to be of a certain type. Dead code elimination + * will do the rest. IP6_MULTICAST is supported but currently not optimized. + * @see ip6_addr_has_scope, ip6_addr_assign_zone, ip6_addr_lacks_zone. + */ +enum lwip_ipv6_scope_type +{ + /** Unknown */ + IP6_UNKNOWN = 0, + /** Unicast */ + IP6_UNICAST = 1, + /** Multicast */ + IP6_MULTICAST = 2 +}; + +/** IPV6_CUSTOM_SCOPES: together, the following three macro definitions, + * @ref ip6_addr_has_scope, @ref ip6_addr_assign_zone, and + * @ref ip6_addr_test_zone, completely define the lwIP scoping policy. + * The definitions below implement the default policy from RFC 4007 Sec. 6. + * Should an implementation desire to implement a different policy, it can + * define IPV6_CUSTOM_SCOPES to 1 and supply its own definitions for the three + * macros instead. + */ +#ifndef IPV6_CUSTOM_SCOPES +#define IPV6_CUSTOM_SCOPES 0 +#endif /* !IPV6_CUSTOM_SCOPES */ + +#if !IPV6_CUSTOM_SCOPES + +/** + * Determine whether an IPv6 address has a constrained scope, and as such is + * meaningful only if accompanied by a zone index to identify the scope's zone. + * The given address type may be used to eliminate at compile time certain + * checks that will evaluate to false at run time anyway. + * + * This default implementation follows the default model of RFC 4007, where + * only interface-local and link-local scopes are defined. + * + * Even though the unicast loopback address does have an implied link-local + * scope, in this implementation it does not have an explicitly assigned zone + * index. As such it should not be tested for in this macro. + * + * @param ip6addr the IPv6 address (const); only its address part is examined. + * @param type address type; see @ref lwip_ipv6_scope_type. + * @return 1 if the address has a constrained scope, 0 if it does not. + */ +#define ip6_addr_has_scope(ip6addr, type) \ + (ip6_addr_islinklocal(ip6addr) || (((type) != IP6_UNICAST) && \ + (ip6_addr_ismulticast_iflocal(ip6addr) || \ + ip6_addr_ismulticast_linklocal(ip6addr)))) + +/** + * Assign a zone index to an IPv6 address, based on a network interface. If the + * given address has a scope, the assigned zone index is that scope's zone of + * the given netif; otherwise, the assigned zone index is "no zone". + * + * This default implementation follows the default model of RFC 4007, where + * only interface-local and link-local scopes are defined, and the zone index + * of both of those scopes always equals the index of the network interface. + * As such, this default implementation need not distinguish between different + * constrained scopes when assigning the zone. + * + * @param ip6addr the IPv6 address; its address part is examined, and its zone + * index is assigned. + * @param type address type; see @ref lwip_ipv6_scope_type. + * @param netif the network interface (const). + */ +#define ip6_addr_assign_zone(ip6addr, type, netif) \ + (ip6_addr_set_zone((ip6addr), \ + ip6_addr_has_scope((ip6addr), (type)) ? netif_get_index(netif) : 0)) + +/** + * Test whether an IPv6 address is "zone-compatible" with a network interface. + * That is, test whether the network interface is part of the zone associated + * with the address. For efficiency, this macro is only ever called if the + * given address is either scoped or zoned, and thus, it need not test this. + * If an address is scoped but not zoned, or zoned and not scoped, it is + * considered not zone-compatible with any netif. + * + * This default implementation follows the default model of RFC 4007, where + * only interface-local and link-local scopes are defined, and the zone index + * of both of those scopes always equals the index of the network interface. + * As such, there is always only one matching netif for a specific zone index, + * but all call sites of this macro currently support multiple matching netifs + * as well (at no additional expense in the common case). + * + * @param ip6addr the IPv6 address (const). + * @param netif the network interface (const). + * @return 1 if the address is scope-compatible with the netif, 0 if not. + */ +#define ip6_addr_test_zone(ip6addr, netif) \ + (ip6_addr_equals_zone((ip6addr), netif_get_index(netif))) + +#endif /* !IPV6_CUSTOM_SCOPES */ + +/** Does the given IPv6 address have a scope, and as such should also have a + * zone to be meaningful, but does not actually have a zone? (0/1) */ +#define ip6_addr_lacks_zone(ip6addr, type) \ + (!ip6_addr_has_zone(ip6addr) && ip6_addr_has_scope((ip6addr), (type))) + +/** + * Try to select a zone for a scoped address that does not yet have a zone. + * Called from PCB bind and connect routines, for two reasons: 1) to save on + * this (relatively expensive) selection for every individual packet route + * operation and 2) to allow the application to obtain the selected zone from + * the PCB as is customary for e.g. getsockname/getpeername BSD socket calls. + * + * Ideally, callers would always supply a properly zoned address, in which case + * this function would not be needed. It exists both for compatibility with the + * BSD socket API (which accepts zoneless destination addresses) and for + * backward compatibility with pre-scoping lwIP code. + * + * It may be impossible to select a zone, e.g. if there are no netifs. In that + * case, the address's zone field will be left as is. + * + * @param dest the IPv6 address for which to select and set a zone. + * @param src source IPv6 address (const); may be equal to dest. + */ +#define ip6_addr_select_zone(dest, src) do { struct netif *selected_netif; \ + selected_netif = ip6_route((src), (dest)); \ + if (selected_netif != NULL) { \ + ip6_addr_assign_zone((dest), IP6_UNKNOWN, selected_netif); \ + } } while (0) + +/** + * @} + */ + +#else /* LWIP_IPV6_SCOPES */ + +#define IPADDR6_ZONE_INIT +#define ip6_addr_zone(ip6addr) (IP6_NO_ZONE) +#define ip6_addr_has_zone(ip6addr) (0) +#define ip6_addr_set_zone(ip6addr, zone_idx) +#define ip6_addr_clear_zone(ip6addr) +#define ip6_addr_copy_zone(ip6addr1, ip6addr2) +#define ip6_addr_equals_zone(ip6addr, zone_idx) (1) +#define ip6_addr_cmp_zone(ip6addr1, ip6addr2) (1) +#define IPV6_CUSTOM_SCOPES 0 +#define ip6_addr_has_scope(ip6addr, type) (0) +#define ip6_addr_assign_zone(ip6addr, type, netif) +#define ip6_addr_test_zone(ip6addr, netif) (1) +#define ip6_addr_lacks_zone(ip6addr, type) (0) +#define ip6_addr_select_zone(ip6addr, src) + +#endif /* LWIP_IPV6_SCOPES */ + +#if LWIP_IPV6_SCOPES && LWIP_IPV6_SCOPES_DEBUG + +/** Verify that the given IPv6 address is properly zoned. */ +#define IP6_ADDR_ZONECHECK(ip6addr) LWIP_ASSERT("IPv6 zone check failed", \ + ip6_addr_has_scope(ip6addr, IP6_UNKNOWN) == ip6_addr_has_zone(ip6addr)) + +/** Verify that the given IPv6 address is properly zoned for the given netif. */ +#define IP6_ADDR_ZONECHECK_NETIF(ip6addr, netif) LWIP_ASSERT("IPv6 netif zone check failed", \ + ip6_addr_has_scope(ip6addr, IP6_UNKNOWN) ? \ + (ip6_addr_has_zone(ip6addr) && \ + (((netif) == NULL) || ip6_addr_test_zone((ip6addr), (netif)))) : \ + !ip6_addr_has_zone(ip6addr)) + +#else /* LWIP_IPV6_SCOPES && LWIP_IPV6_SCOPES_DEBUG */ + +#define IP6_ADDR_ZONECHECK(ip6addr) +#define IP6_ADDR_ZONECHECK_NETIF(ip6addr, netif) + +#endif /* LWIP_IPV6_SCOPES && LWIP_IPV6_SCOPES_DEBUG */ + +#endif /* LWIP_IPV6 */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_IP6_ZONE_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip_addr.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip_addr.h new file mode 100644 index 000000000..2f977709d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/ip_addr.h @@ -0,0 +1,438 @@ +/** + * @file + * IP address API (common IPv4 and IPv6) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_IP_ADDR_H +#define LWIP_HDR_IP_ADDR_H + +#include "lwip/opt.h" +#include "lwip/def.h" + +#include "lwip/ip4_addr.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @ingroup ipaddr + * IP address types for use in ip_addr_t.type member. + * @see tcp_new_ip_type(), udp_new_ip_type(), raw_new_ip_type(). + */ +enum lwip_ip_addr_type { + /** IPv4 */ + IPADDR_TYPE_V4 = 0U, + /** IPv6 */ + IPADDR_TYPE_V6 = 6U, + /** IPv4+IPv6 ("dual-stack") */ + IPADDR_TYPE_ANY = 46U +}; + +#if LWIP_IPV4 && LWIP_IPV6 +/** + * @ingroup ipaddr + * A union struct for both IP version's addresses. + * ATTENTION: watch out for its size when adding IPv6 address scope! + */ +typedef struct ip_addr { + union { + ip6_addr_t ip6; + ip4_addr_t ip4; + } u_addr; + /** @ref lwip_ip_addr_type */ + u8_t type; +} ip_addr_t; + +extern const ip_addr_t ip_addr_any_type; + +/** @ingroup ip4addr */ +#define IPADDR4_INIT(u32val) { { { { u32val, 0ul, 0ul, 0ul } IPADDR6_ZONE_INIT } }, IPADDR_TYPE_V4 } +/** @ingroup ip4addr */ +#define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d))) + +/** @ingroup ip6addr */ +#define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } IPADDR6_ZONE_INIT } }, IPADDR_TYPE_V6 } +/** @ingroup ip6addr */ +#define IPADDR6_INIT_HOST(a, b, c, d) { { { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } IPADDR6_ZONE_INIT } }, IPADDR_TYPE_V6 } + +/** @ingroup ipaddr */ +#define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY) +/** @ingroup ipaddr */ +#define IPADDR_ANY_TYPE_INIT { { { { 0ul, 0ul, 0ul, 0ul } IPADDR6_ZONE_INIT } }, IPADDR_TYPE_ANY } + +/** @ingroup ip4addr */ +#define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4) +/** @ingroup ip6addr */ +#define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6) +/** @ingroup ip4addr */ +#define IP_IS_V4(ipaddr) (((ipaddr) == NULL) || IP_IS_V4_VAL(*(ipaddr))) +/** @ingroup ip6addr */ +#define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr))) + +#define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0) +#define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0) +#define IP_GET_TYPE(ipaddr) ((ipaddr)->type) + +#define IP_ADDR_RAW_SIZE(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4 ? sizeof(ip4_addr_t) : sizeof(ip6_addr_t)) + +#define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) (IP_GET_TYPE(&pcb->local_ip) == IP_GET_TYPE(ipaddr)) +#define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (IP_IS_ANY_TYPE_VAL(pcb->local_ip) || IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)) + +/** @ingroup ip6addr + * Convert generic ip address to specific protocol version + */ +#define ip_2_ip6(ipaddr) (&((ipaddr)->u_addr.ip6)) +/** @ingroup ip4addr + * Convert generic ip address to specific protocol version + */ +#define ip_2_ip4(ipaddr) (&((ipaddr)->u_addr.ip4)) + +/** @ingroup ip4addr */ +#define IP_ADDR4(ipaddr,a,b,c,d) do { IP4_ADDR(ip_2_ip4(ipaddr),a,b,c,d); \ + IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V4); } while(0) +/** @ingroup ip6addr */ +#define IP_ADDR6(ipaddr,i0,i1,i2,i3) do { IP6_ADDR(ip_2_ip6(ipaddr),i0,i1,i2,i3); \ + IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); } while(0) +/** @ingroup ip6addr */ +#define IP_ADDR6_HOST(ipaddr,i0,i1,i2,i3) IP_ADDR6(ipaddr,PP_HTONL(i0),PP_HTONL(i1),PP_HTONL(i2),PP_HTONL(i3)) + +#define ip_clear_no4(ipaddr) do { ip_2_ip6(ipaddr)->addr[1] = \ + ip_2_ip6(ipaddr)->addr[2] = \ + ip_2_ip6(ipaddr)->addr[3] = 0; \ + ip6_addr_clear_zone(ip_2_ip6(ipaddr)); }while(0) + +/** @ingroup ipaddr */ +#define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \ + ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \ + ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); ip_clear_no4(&dest); }}while(0) +/** @ingroup ip6addr */ +#define ip_addr_copy_from_ip6(dest, src) do{ \ + ip6_addr_copy(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }while(0) +/** @ingroup ip6addr */ +#define ip_addr_copy_from_ip6_packed(dest, src) do{ \ + ip6_addr_copy_from_packed(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }while(0) +/** @ingroup ip4addr */ +#define ip_addr_copy_from_ip4(dest, src) do{ \ + ip4_addr_copy(*ip_2_ip4(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); ip_clear_no4(&dest); }while(0) +/** @ingroup ip4addr */ +#define ip_addr_set_ip4_u32(ipaddr, val) do{if(ipaddr){ip4_addr_set_u32(ip_2_ip4(ipaddr), val); \ + IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); ip_clear_no4(ipaddr); }}while(0) +/** @ingroup ip4addr */ +#define ip_addr_set_ip4_u32_val(ipaddr, val) do{ ip4_addr_set_u32(ip_2_ip4(&(ipaddr)), val); \ + IP_SET_TYPE_VAL(ipaddr, IPADDR_TYPE_V4); ip_clear_no4(&ipaddr); }while(0) +/** @ingroup ip4addr */ +#define ip_addr_get_ip4_u32(ipaddr) (((ipaddr) && IP_IS_V4(ipaddr)) ? \ + ip4_addr_get_u32(ip_2_ip4(ipaddr)) : 0) +/** @ingroup ipaddr */ +#define ip_addr_set(dest, src) do{ IP_SET_TYPE(dest, IP_GET_TYPE(src)); if(IP_IS_V6(src)){ \ + ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); }else{ \ + ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); ip_clear_no4(dest); }}while(0) +/** @ingroup ipaddr */ +#define ip_addr_set_ipaddr(dest, src) ip_addr_set(dest, src) +/** @ingroup ipaddr */ +#define ip_addr_set_zero(ipaddr) do{ \ + ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, 0); }while(0) +/** @ingroup ip5addr */ +#define ip_addr_set_zero_ip4(ipaddr) do{ \ + ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }while(0) +/** @ingroup ip6addr */ +#define ip_addr_set_zero_ip6(ipaddr) do{ \ + ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }while(0) +/** @ingroup ipaddr */ +#define ip_addr_set_any(is_ipv6, ipaddr) do{if(is_ipv6){ \ + ip6_addr_set_any(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \ + ip4_addr_set_any(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); ip_clear_no4(ipaddr); }}while(0) +/** @ingroup ipaddr */ +#define ip_addr_set_any_val(is_ipv6, ipaddr) do{if(is_ipv6){ \ + ip6_addr_set_any(ip_2_ip6(&(ipaddr))); IP_SET_TYPE_VAL(ipaddr, IPADDR_TYPE_V6); }else{ \ + ip4_addr_set_any(ip_2_ip4(&(ipaddr))); IP_SET_TYPE_VAL(ipaddr, IPADDR_TYPE_V4); ip_clear_no4(&ipaddr); }}while(0) +/** @ingroup ipaddr */ +#define ip_addr_set_loopback(is_ipv6, ipaddr) do{if(is_ipv6){ \ + ip6_addr_set_loopback(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \ + ip4_addr_set_loopback(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); ip_clear_no4(ipaddr); }}while(0) +/** @ingroup ipaddr */ +#define ip_addr_set_loopback_val(is_ipv6, ipaddr) do{if(is_ipv6){ \ + ip6_addr_set_loopback(ip_2_ip6(&(ipaddr))); IP_SET_TYPE_VAL(ipaddr, IPADDR_TYPE_V6); }else{ \ + ip4_addr_set_loopback(ip_2_ip4(&(ipaddr))); IP_SET_TYPE_VAL(ipaddr, IPADDR_TYPE_V4); ip_clear_no4(&ipaddr); }}while(0) +/** @ingroup ipaddr */ +#define ip_addr_set_hton(dest, src) do{if(IP_IS_V6(src)){ \ + ip6_addr_set_hton(ip_2_ip6(dest), ip_2_ip6(src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \ + ip4_addr_set_hton(ip_2_ip4(dest), ip_2_ip4(src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); ip_clear_no4(ipaddr); }}while(0) +/** @ingroup ipaddr */ +#define ip_addr_get_network(target, host, netmask) do{if(IP_IS_V6(host)){ \ + ip4_addr_set_zero(ip_2_ip4(target)); IP_SET_TYPE(target, IPADDR_TYPE_V6); } else { \ + ip4_addr_get_network(ip_2_ip4(target), ip_2_ip4(host), ip_2_ip4(netmask)); IP_SET_TYPE(target, IPADDR_TYPE_V4); }}while(0) +/** @ingroup ipaddr */ +#define ip_addr_netcmp(addr1, addr2, mask) ((IP_IS_V6(addr1) && IP_IS_V6(addr2)) ? \ + 0 : \ + ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask)) +/** @ingroup ipaddr */ +#define ip_addr_cmp(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? \ + ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \ + ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2)))) +/** @ingroup ipaddr */ +#define ip_addr_cmp_zoneless(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? \ + ip6_addr_cmp_zoneless(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \ + ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2)))) +/** @ingroup ipaddr */ +#define ip_addr_isany(ipaddr) (((ipaddr) == NULL) ? 1 : ((IP_IS_V6(ipaddr)) ? \ + ip6_addr_isany(ip_2_ip6(ipaddr)) : \ + ip4_addr_isany(ip_2_ip4(ipaddr)))) +/** @ingroup ipaddr */ +#define ip_addr_isany_val(ipaddr) ((IP_IS_V6_VAL(ipaddr)) ? \ + ip6_addr_isany_val(*ip_2_ip6(&(ipaddr))) : \ + ip4_addr_isany_val(*ip_2_ip4(&(ipaddr)))) +/** @ingroup ipaddr */ +#define ip_addr_isbroadcast(ipaddr, netif) ((IP_IS_V6(ipaddr)) ? \ + 0 : \ + ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif)) +/** @ingroup ipaddr */ +#define ip_addr_ismulticast(ipaddr) ((IP_IS_V6(ipaddr)) ? \ + ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \ + ip4_addr_ismulticast(ip_2_ip4(ipaddr))) +/** @ingroup ipaddr */ +#define ip_addr_isloopback(ipaddr) ((IP_IS_V6(ipaddr)) ? \ + ip6_addr_isloopback(ip_2_ip6(ipaddr)) : \ + ip4_addr_isloopback(ip_2_ip4(ipaddr))) +/** @ingroup ipaddr */ +#define ip_addr_islinklocal(ipaddr) ((IP_IS_V6(ipaddr)) ? \ + ip6_addr_islinklocal(ip_2_ip6(ipaddr)) : \ + ip4_addr_islinklocal(ip_2_ip4(ipaddr))) +#define ip_addr_debug_print(debug, ipaddr) do { if(IP_IS_V6(ipaddr)) { \ + ip6_addr_debug_print(debug, ip_2_ip6(ipaddr)); } else { \ + ip4_addr_debug_print(debug, ip_2_ip4(ipaddr)); }}while(0) +#define ip_addr_debug_print_val(debug, ipaddr) do { if(IP_IS_V6_VAL(ipaddr)) { \ + ip6_addr_debug_print_val(debug, *ip_2_ip6(&(ipaddr))); } else { \ + ip4_addr_debug_print_val(debug, *ip_2_ip4(&(ipaddr))); }}while(0) +char *ipaddr_ntoa(const ip_addr_t *addr); +char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen); +int ipaddr_aton(const char *cp, ip_addr_t *addr); + +/** @ingroup ipaddr */ +#define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX + +/** @ingroup ipaddr */ +#define ip4_2_ipv4_mapped_ipv6(ip6addr, ip4addr) do { \ + (ip6addr)->addr[3] = (ip4addr)->addr; \ + (ip6addr)->addr[2] = PP_HTONL(0x0000FFFFUL); \ + (ip6addr)->addr[1] = 0; \ + (ip6addr)->addr[0] = 0; \ + ip6_addr_clear_zone(ip6addr); } while(0); + +/** @ingroup ipaddr */ +#define unmap_ipv4_mapped_ipv6(ip4addr, ip6addr) \ + (ip4addr)->addr = (ip6addr)->addr[3]; + +#define IP46_ADDR_ANY(type) (((type) == IPADDR_TYPE_V6)? IP6_ADDR_ANY : IP4_ADDR_ANY) + +#else /* LWIP_IPV4 && LWIP_IPV6 */ + +#define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1 +#define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) 1 + +#define ip_addr_set_any_val(is_ipv6, ipaddr) ip_addr_set_any(is_ipv6, &(ipaddr)) +#define ip_addr_set_loopback_val(is_ipv6, ipaddr) ip_addr_set_loopback(is_ipv6, &(ipaddr)) + +#if LWIP_IPV4 + +typedef ip4_addr_t ip_addr_t; +#define IPADDR4_INIT(u32val) { u32val } +#define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d))) +#define IP_IS_V4_VAL(ipaddr) 1 +#define IP_IS_V6_VAL(ipaddr) 0 +#define IP_IS_V4(ipaddr) 1 +#define IP_IS_V6(ipaddr) 0 +#define IP_IS_ANY_TYPE_VAL(ipaddr) 0 +#define IP_SET_TYPE_VAL(ipaddr, iptype) +#define IP_SET_TYPE(ipaddr, iptype) +#define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4 +#define IP_ADDR_RAW_SIZE(ipaddr) sizeof(ip4_addr_t) +#define ip_2_ip4(ipaddr) (ipaddr) +#define IP_ADDR4(ipaddr,a,b,c,d) IP4_ADDR(ipaddr,a,b,c,d) + +#define ip_addr_copy(dest, src) ip4_addr_copy(dest, src) +#define ip_addr_copy_from_ip4(dest, src) ip4_addr_copy(dest, src) +#define ip_addr_set_ip4_u32(ipaddr, val) ip4_addr_set_u32(ip_2_ip4(ipaddr), val) +#define ip_addr_set_ip4_u32_val(ipaddr, val) ip_addr_set_ip4_u32(&(ipaddr), val) +#define ip_addr_get_ip4_u32(ipaddr) ip4_addr_get_u32(ip_2_ip4(ipaddr)) +#define ip_addr_set(dest, src) ip4_addr_set(dest, src) +#define ip_addr_set_ipaddr(dest, src) ip4_addr_set(dest, src) +#define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr) +#define ip_addr_set_zero_ip4(ipaddr) ip4_addr_set_zero(ipaddr) +#define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr) +#define ip_addr_set_loopback(is_ipv6, ipaddr) ip4_addr_set_loopback(ipaddr) +#define ip_addr_set_hton(dest, src) ip4_addr_set_hton(dest, src) +#define ip_addr_get_network(target, host, mask) ip4_addr_get_network(target, host, mask) +#define ip_addr_netcmp(addr1, addr2, mask) ip4_addr_netcmp(addr1, addr2, mask) +#define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2) +#define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr) +#define ip_addr_isany_val(ipaddr) ip4_addr_isany_val(ipaddr) +#define ip_addr_isloopback(ipaddr) ip4_addr_isloopback(ipaddr) +#define ip_addr_islinklocal(ipaddr) ip4_addr_islinklocal(ipaddr) +#define ip_addr_isbroadcast(addr, netif) ip4_addr_isbroadcast(addr, netif) +#define ip_addr_ismulticast(ipaddr) ip4_addr_ismulticast(ipaddr) +#define ip_addr_debug_print(debug, ipaddr) ip4_addr_debug_print(debug, ipaddr) +#define ip_addr_debug_print_val(debug, ipaddr) ip4_addr_debug_print_val(debug, ipaddr) +#define ipaddr_ntoa(ipaddr) ip4addr_ntoa(ipaddr) +#define ipaddr_ntoa_r(ipaddr, buf, buflen) ip4addr_ntoa_r(ipaddr, buf, buflen) +#define ipaddr_aton(cp, addr) ip4addr_aton(cp, addr) + +#define IPADDR_STRLEN_MAX IP4ADDR_STRLEN_MAX + +#define IP46_ADDR_ANY(type) (IP4_ADDR_ANY) + +#else /* LWIP_IPV4 */ + +typedef ip6_addr_t ip_addr_t; +#define IPADDR6_INIT(a, b, c, d) { { a, b, c, d } IPADDR6_ZONE_INIT } +#define IPADDR6_INIT_HOST(a, b, c, d) { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } IPADDR6_ZONE_INIT } +#define IP_IS_V4_VAL(ipaddr) 0 +#define IP_IS_V6_VAL(ipaddr) 1 +#define IP_IS_V4(ipaddr) 0 +#define IP_IS_V6(ipaddr) 1 +#define IP_IS_ANY_TYPE_VAL(ipaddr) 0 +#define IP_SET_TYPE_VAL(ipaddr, iptype) +#define IP_SET_TYPE(ipaddr, iptype) +#define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V6 +#define IP_ADDR_RAW_SIZE(ipaddr) sizeof(ip6_addr_t) +#define ip_2_ip6(ipaddr) (ipaddr) +#define IP_ADDR6(ipaddr,i0,i1,i2,i3) IP6_ADDR(ipaddr,i0,i1,i2,i3) +#define IP_ADDR6_HOST(ipaddr,i0,i1,i2,i3) IP_ADDR6(ipaddr,PP_HTONL(i0),PP_HTONL(i1),PP_HTONL(i2),PP_HTONL(i3)) + +#define ip_addr_copy(dest, src) ip6_addr_copy(dest, src) +#define ip_addr_copy_from_ip6(dest, src) ip6_addr_copy(dest, src) +#define ip_addr_copy_from_ip6_packed(dest, src) ip6_addr_copy_from_packed(dest, src) +#define ip_addr_set(dest, src) ip6_addr_set(dest, src) +#define ip_addr_set_ipaddr(dest, src) ip6_addr_set(dest, src) +#define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr) +#define ip_addr_set_zero_ip6(ipaddr) ip6_addr_set_zero(ipaddr) +#define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr) +#define ip_addr_set_loopback(is_ipv6, ipaddr) ip6_addr_set_loopback(ipaddr) +#define ip_addr_set_hton(dest, src) ip6_addr_set_hton(dest, src) +#define ip_addr_get_network(target, host, mask) ip6_addr_set_zero(target) +#define ip_addr_netcmp(addr1, addr2, mask) 0 +#define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2) +#define ip_addr_cmp_zoneless(addr1, addr2) ip6_addr_cmp_zoneless(addr1, addr2) +#define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr) +#define ip_addr_isany_val(ipaddr) ip6_addr_isany_val(ipaddr) +#define ip_addr_isloopback(ipaddr) ip6_addr_isloopback(ipaddr) +#define ip_addr_islinklocal(ipaddr) ip6_addr_islinklocal(ipaddr) +#define ip_addr_isbroadcast(addr, netif) 0 +#define ip_addr_ismulticast(ipaddr) ip6_addr_ismulticast(ipaddr) +#define ip_addr_debug_print(debug, ipaddr) ip6_addr_debug_print(debug, ipaddr) +#define ip_addr_debug_print_val(debug, ipaddr) ip6_addr_debug_print_val(debug, ipaddr) +#define ipaddr_ntoa(ipaddr) ip6addr_ntoa(ipaddr) +#define ipaddr_ntoa_r(ipaddr, buf, buflen) ip6addr_ntoa_r(ipaddr, buf, buflen) +#define ipaddr_aton(cp, addr) ip6addr_aton(cp, addr) + +#define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX + +#define IP46_ADDR_ANY(type) (IP6_ADDR_ANY) + +#endif /* LWIP_IPV4 */ +#endif /* LWIP_IPV4 && LWIP_IPV6 */ + +#if LWIP_IPV4 + +extern const ip_addr_t ip_addr_any; +extern const ip_addr_t ip_addr_broadcast; + +/** + * @ingroup ip4addr + * Can be used as a fixed/const ip_addr_t + * for the IP wildcard. + * Defined to @ref IP4_ADDR_ANY when IPv4 is enabled. + * Defined to @ref IP6_ADDR_ANY in IPv6 only systems. + * Use this if you can handle IPv4 _AND_ IPv6 addresses. + * Use @ref IP4_ADDR_ANY or @ref IP6_ADDR_ANY when the IP + * type matters. + */ +#define IP_ADDR_ANY IP4_ADDR_ANY +/** + * @ingroup ip4addr + * Can be used as a fixed/const ip_addr_t + * for the IPv4 wildcard and the broadcast address + */ +#define IP4_ADDR_ANY (&ip_addr_any) +/** + * @ingroup ip4addr + * Can be used as a fixed/const ip4_addr_t + * for the wildcard and the broadcast address + */ +#define IP4_ADDR_ANY4 (ip_2_ip4(&ip_addr_any)) + +/** @ingroup ip4addr */ +#define IP_ADDR_BROADCAST (&ip_addr_broadcast) +/** @ingroup ip4addr */ +#define IP4_ADDR_BROADCAST (ip_2_ip4(&ip_addr_broadcast)) + +#endif /* LWIP_IPV4*/ + +#if LWIP_IPV6 + +extern const ip_addr_t ip6_addr_any; + +/** + * @ingroup ip6addr + * IP6_ADDR_ANY can be used as a fixed ip_addr_t + * for the IPv6 wildcard address + */ +#define IP6_ADDR_ANY (&ip6_addr_any) +/** + * @ingroup ip6addr + * IP6_ADDR_ANY6 can be used as a fixed ip6_addr_t + * for the IPv6 wildcard address + */ +#define IP6_ADDR_ANY6 (ip_2_ip6(&ip6_addr_any)) + +#if !LWIP_IPV4 +/** IPv6-only configurations */ +#define IP_ADDR_ANY IP6_ADDR_ANY +#endif /* !LWIP_IPV4 */ + +#endif + +#if LWIP_IPV4 && LWIP_IPV6 +/** @ingroup ipaddr */ +#define IP_ANY_TYPE (&ip_addr_any_type) +#else +#define IP_ANY_TYPE IP_ADDR_ANY +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_IP_ADDR_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/mem.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/mem.h new file mode 100644 index 000000000..ff208d25c --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/mem.h @@ -0,0 +1,82 @@ +/** + * @file + * Heap API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_MEM_H +#define LWIP_HDR_MEM_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if MEM_LIBC_MALLOC + +#include "lwip/arch.h" + +typedef size_t mem_size_t; +#define MEM_SIZE_F SZT_F + +#elif MEM_USE_POOLS + +typedef u16_t mem_size_t; +#define MEM_SIZE_F U16_F + +#else + +/* MEM_SIZE would have to be aligned, but using 64000 here instead of + * 65535 leaves some room for alignment... + */ +#if MEM_SIZE > 64000L +typedef u32_t mem_size_t; +#define MEM_SIZE_F U32_F +#else +typedef u16_t mem_size_t; +#define MEM_SIZE_F U16_F +#endif /* MEM_SIZE > 64000 */ +#endif + +void mem_init(void); +void *mem_trim(void *mem, mem_size_t size); +void *mem_malloc(mem_size_t size); +void *mem_calloc(mem_size_t count, mem_size_t size); +void mem_free(void *mem); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_MEM_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/memp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/memp.h new file mode 100644 index 000000000..1630b26c2 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/memp.h @@ -0,0 +1,155 @@ +/** + * @file + * Memory pool API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +#ifndef LWIP_HDR_MEMP_H +#define LWIP_HDR_MEMP_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* run once with empty definition to handle all custom includes in lwippools.h */ +#define LWIP_MEMPOOL(name,num,size,desc) +#include "lwip/priv/memp_std.h" + +/** Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */ +typedef enum { +#define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name, +#include "lwip/priv/memp_std.h" + MEMP_MAX +} memp_t; + +#include "lwip/priv/memp_priv.h" +#include "lwip/stats.h" + +extern const struct memp_desc* const memp_pools[MEMP_MAX]; + +/** + * @ingroup mempool + * Declare prototype for private memory pool if it is used in multiple files + */ +#define LWIP_MEMPOOL_PROTOTYPE(name) extern const struct memp_desc memp_ ## name + +#if MEMP_MEM_MALLOC + +#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ + LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(memp_stats_ ## name) \ + const struct memp_desc memp_ ## name = { \ + DECLARE_LWIP_MEMPOOL_DESC(desc) \ + LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) \ + LWIP_MEM_ALIGN_SIZE(size) \ + }; + +#else /* MEMP_MEM_MALLOC */ + +/** + * @ingroup mempool + * Declare a private memory pool + * Private mempools example: + * .h: only when pool is used in multiple .c files: LWIP_MEMPOOL_PROTOTYPE(my_private_pool); + * .c: + * - in global variables section: LWIP_MEMPOOL_DECLARE(my_private_pool, 10, sizeof(foo), "Some description") + * - call ONCE before using pool (e.g. in some init() function): LWIP_MEMPOOL_INIT(my_private_pool); + * - allocate: void* my_new_mem = LWIP_MEMPOOL_ALLOC(my_private_pool); + * - free: LWIP_MEMPOOL_FREE(my_private_pool, my_new_mem); + * + * To relocate a pool, declare it as extern in cc.h. Example for GCC: + * extern u8_t \_\_attribute\_\_((section(".onchip_mem"))) memp_memory_my_private_pool_base[]; + */ +#define LWIP_MEMPOOL_DECLARE(name,num,size,desc) \ + LWIP_DECLARE_MEMORY_ALIGNED(memp_memory_ ## name ## _base, ((num) * (MEMP_SIZE + MEMP_ALIGN_SIZE(size)))); \ + \ + LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(memp_stats_ ## name) \ + \ + static struct memp *memp_tab_ ## name; \ + \ + const struct memp_desc memp_ ## name = { \ + DECLARE_LWIP_MEMPOOL_DESC(desc) \ + LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(memp_stats_ ## name) \ + LWIP_MEM_ALIGN_SIZE(size), \ + (num), \ + memp_memory_ ## name ## _base, \ + &memp_tab_ ## name \ + }; + +#endif /* MEMP_MEM_MALLOC */ + +/** + * @ingroup mempool + * Initialize a private memory pool + */ +#define LWIP_MEMPOOL_INIT(name) memp_init_pool(&memp_ ## name) +/** + * @ingroup mempool + * Allocate from a private memory pool + */ +#define LWIP_MEMPOOL_ALLOC(name) memp_malloc_pool(&memp_ ## name) +/** + * @ingroup mempool + * Free element from a private memory pool + */ +#define LWIP_MEMPOOL_FREE(name, x) memp_free_pool(&memp_ ## name, (x)) + +#if MEM_USE_POOLS +/** This structure is used to save the pool one element came from. + * This has to be defined here as it is required for pool size calculation. */ +struct memp_malloc_helper +{ + memp_t poolnr; +#if MEMP_OVERFLOW_CHECK || (LWIP_STATS && MEM_STATS) + u16_t size; +#endif /* MEMP_OVERFLOW_CHECK || (LWIP_STATS && MEM_STATS) */ +}; +#endif /* MEM_USE_POOLS */ + +void memp_init(void); + +#if MEMP_OVERFLOW_CHECK +void *memp_malloc_fn(memp_t type, const char* file, const int line); +#define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__) +#else +void *memp_malloc(memp_t type); +#endif +void memp_free(memp_t type, void *mem); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_MEMP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/mld6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/mld6.h new file mode 100644 index 000000000..7fa0797f2 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/mld6.h @@ -0,0 +1,99 @@ +/** + * @file + * + * Multicast listener discovery for IPv6. Aims to be compliant with RFC 2710. + * No support for MLDv2. + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ + +#ifndef LWIP_HDR_MLD6_H +#define LWIP_HDR_MLD6_H + +#include "lwip/opt.h" + +#if LWIP_IPV6_MLD && LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/pbuf.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** MLD group */ +struct mld_group { + /** next link */ + struct mld_group *next; + /** multicast address */ + ip6_addr_t group_address; + /** signifies we were the last person to report */ + u8_t last_reporter_flag; + /** current state of the group */ + u8_t group_state; + /** timer for reporting */ + u16_t timer; + /** counter of simultaneous uses */ + u8_t use; +}; + +#define MLD6_TMR_INTERVAL 100 /* Milliseconds */ + +err_t mld6_stop(struct netif *netif); +void mld6_report_groups(struct netif *netif); +void mld6_tmr(void); +struct mld_group *mld6_lookfor_group(struct netif *ifp, const ip6_addr_t *addr); +void mld6_input(struct pbuf *p, struct netif *inp); +err_t mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr); +err_t mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); +err_t mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr); +err_t mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr); + +/** @ingroup mld6 + * Get list head of MLD6 groups for netif. + * Note: The allnodes group IP is NOT in the list, since it must always + * be received for correct IPv6 operation. + * @see @ref netif_set_mld_mac_filter() + */ +#define netif_mld6_data(netif) ((struct mld_group *)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_MLD6)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6_MLD && LWIP_IPV6 */ + +#endif /* LWIP_HDR_MLD6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/nd6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/nd6.h new file mode 100644 index 000000000..c30e624f0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/nd6.h @@ -0,0 +1,90 @@ +/** + * @file + * + * Neighbor discovery and stateless address autoconfiguration for IPv6. + * Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862 + * (Address autoconfiguration). + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ + +#ifndef LWIP_HDR_ND6_H +#define LWIP_HDR_ND6_H + +#include "lwip/opt.h" + +#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/ip6_addr.h" +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** 1 second period */ +#define ND6_TMR_INTERVAL 1000 + +/** Router solicitations are sent in 4 second intervals (see RFC 4861, ch. 6.3.7) */ +#ifndef ND6_RTR_SOLICITATION_INTERVAL +#define ND6_RTR_SOLICITATION_INTERVAL 4000 +#endif + +struct pbuf; +struct netif; + +void nd6_tmr(void); +void nd6_input(struct pbuf *p, struct netif *inp); +void nd6_clear_destination_cache(void); +struct netif *nd6_find_route(const ip6_addr_t *ip6addr); +err_t nd6_get_next_hop_addr_or_queue(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr, const u8_t **hwaddrp); +u16_t nd6_get_destination_mtu(const ip6_addr_t *ip6addr, struct netif *netif); +#if LWIP_ND6_TCP_REACHABILITY_HINTS +void nd6_reachability_hint(const ip6_addr_t *ip6addr); +#endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */ +void nd6_cleanup_netif(struct netif *netif); +#if LWIP_IPV6_MLD +void nd6_adjust_mld_membership(struct netif *netif, s8_t addr_idx, u8_t new_state); +#endif /* LWIP_IPV6_MLD */ +void nd6_restart_netif(struct netif *netif); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 */ + +#endif /* LWIP_HDR_ND6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netbuf.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netbuf.h new file mode 100644 index 000000000..42a911bca --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netbuf.h @@ -0,0 +1,116 @@ +/** + * @file + * netbuf API (for netconn API) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_NETBUF_H +#define LWIP_HDR_NETBUF_H + +#include "lwip/opt.h" + +#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ +/* Note: Netconn API is always available when sockets are enabled - + * sockets are implemented on top of them */ + +#include "lwip/pbuf.h" +#include "lwip/ip_addr.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** This netbuf has dest-addr/port set */ +#define NETBUF_FLAG_DESTADDR 0x01 +/** This netbuf includes a checksum */ +#define NETBUF_FLAG_CHKSUM 0x02 + +/** "Network buffer" - contains data and addressing info */ +struct netbuf { + struct pbuf *p, *ptr; + ip_addr_t addr; + u16_t port; +#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY + u8_t flags; + u16_t toport_chksum; +#if LWIP_NETBUF_RECVINFO + ip_addr_t toaddr; +#endif /* LWIP_NETBUF_RECVINFO */ +#endif /* LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY */ +}; + +/* Network buffer functions: */ +struct netbuf * netbuf_new (void); +void netbuf_delete (struct netbuf *buf); +void * netbuf_alloc (struct netbuf *buf, u16_t size); +void netbuf_free (struct netbuf *buf); +err_t netbuf_ref (struct netbuf *buf, + const void *dataptr, u16_t size); +void netbuf_chain (struct netbuf *head, struct netbuf *tail); + +err_t netbuf_data (struct netbuf *buf, + void **dataptr, u16_t *len); +s8_t netbuf_next (struct netbuf *buf); +void netbuf_first (struct netbuf *buf); + + +#define netbuf_copy_partial(buf, dataptr, len, offset) \ + pbuf_copy_partial((buf)->p, (dataptr), (len), (offset)) +#define netbuf_copy(buf,dataptr,len) netbuf_copy_partial(buf, dataptr, len, 0) +#define netbuf_take(buf, dataptr, len) pbuf_take((buf)->p, dataptr, len) +#define netbuf_len(buf) ((buf)->p->tot_len) +#define netbuf_fromaddr(buf) (&((buf)->addr)) +#define netbuf_set_fromaddr(buf, fromaddr) ip_addr_set(&((buf)->addr), fromaddr) +#define netbuf_fromport(buf) ((buf)->port) +#if LWIP_NETBUF_RECVINFO +#define netbuf_destaddr(buf) (&((buf)->toaddr)) +#define netbuf_set_destaddr(buf, destaddr) ip_addr_set(&((buf)->toaddr), destaddr) +#if LWIP_CHECKSUM_ON_COPY +#define netbuf_destport(buf) (((buf)->flags & NETBUF_FLAG_DESTADDR) ? (buf)->toport_chksum : 0) +#else /* LWIP_CHECKSUM_ON_COPY */ +#define netbuf_destport(buf) ((buf)->toport_chksum) +#endif /* LWIP_CHECKSUM_ON_COPY */ +#endif /* LWIP_NETBUF_RECVINFO */ +#if LWIP_CHECKSUM_ON_COPY +#define netbuf_set_chksum(buf, chksum) do { (buf)->flags = NETBUF_FLAG_CHKSUM; \ + (buf)->toport_chksum = chksum; } while(0) +#endif /* LWIP_CHECKSUM_ON_COPY */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_NETCONN || LWIP_SOCKET */ + +#endif /* LWIP_HDR_NETBUF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netdb.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netdb.h new file mode 100644 index 000000000..d3d15dfac --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netdb.h @@ -0,0 +1,150 @@ +/** + * @file + * NETDB API (sockets) + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_NETDB_H +#define LWIP_HDR_NETDB_H + +#include "lwip/opt.h" + +#if LWIP_DNS && LWIP_SOCKET + +#include "lwip/arch.h" +#include "lwip/inet.h" +#include "lwip/sockets.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* some rarely used options */ +#ifndef LWIP_DNS_API_DECLARE_H_ERRNO +#define LWIP_DNS_API_DECLARE_H_ERRNO 1 +#endif + +#ifndef LWIP_DNS_API_DEFINE_ERRORS +#define LWIP_DNS_API_DEFINE_ERRORS 1 +#endif + +#ifndef LWIP_DNS_API_DEFINE_FLAGS +#define LWIP_DNS_API_DEFINE_FLAGS 1 +#endif + +#ifndef LWIP_DNS_API_DECLARE_STRUCTS +#define LWIP_DNS_API_DECLARE_STRUCTS 1 +#endif + +#if LWIP_DNS_API_DEFINE_ERRORS +/** Errors used by the DNS API functions, h_errno can be one of them */ +#define EAI_NONAME 200 +#define EAI_SERVICE 201 +#define EAI_FAIL 202 +#define EAI_MEMORY 203 +#define EAI_FAMILY 204 + +#define HOST_NOT_FOUND 210 +#define NO_DATA 211 +#define NO_RECOVERY 212 +#define TRY_AGAIN 213 +#endif /* LWIP_DNS_API_DEFINE_ERRORS */ + +#if LWIP_DNS_API_DEFINE_FLAGS +/* input flags for struct addrinfo */ +#define AI_PASSIVE 0x01 +#define AI_CANONNAME 0x02 +#define AI_NUMERICHOST 0x04 +#define AI_NUMERICSERV 0x08 +#define AI_V4MAPPED 0x10 +#define AI_ALL 0x20 +#define AI_ADDRCONFIG 0x40 +#endif /* LWIP_DNS_API_DEFINE_FLAGS */ + +#if LWIP_DNS_API_DECLARE_STRUCTS +struct hostent { + char *h_name; /* Official name of the host. */ + char **h_aliases; /* A pointer to an array of pointers to alternative host names, + terminated by a null pointer. */ + int h_addrtype; /* Address type. */ + int h_length; /* The length, in bytes, of the address. */ + char **h_addr_list; /* A pointer to an array of pointers to network addresses (in + network byte order) for the host, terminated by a null pointer. */ +#define h_addr h_addr_list[0] /* for backward compatibility */ +}; + +struct addrinfo { + int ai_flags; /* Input flags. */ + int ai_family; /* Address family of socket. */ + int ai_socktype; /* Socket type. */ + int ai_protocol; /* Protocol of socket. */ + socklen_t ai_addrlen; /* Length of socket address. */ + struct sockaddr *ai_addr; /* Socket address of socket. */ + char *ai_canonname; /* Canonical name of service location. */ + struct addrinfo *ai_next; /* Pointer to next in list. */ +}; +#endif /* LWIP_DNS_API_DECLARE_STRUCTS */ + +#define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1) + +#if LWIP_DNS_API_DECLARE_H_ERRNO +/* application accessible error code set by the DNS API functions */ +extern int h_errno; +#endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/ + +struct hostent *lwip_gethostbyname(const char *name); +int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf, + size_t buflen, struct hostent **result, int *h_errnop); +void lwip_freeaddrinfo(struct addrinfo *ai); +int lwip_getaddrinfo(const char *nodename, + const char *servname, + const struct addrinfo *hints, + struct addrinfo **res); + +#if LWIP_COMPAT_SOCKETS +/** @ingroup netdbapi */ +#define gethostbyname(name) lwip_gethostbyname(name) +/** @ingroup netdbapi */ +#define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \ + lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop) +/** @ingroup netdbapi */ +#define freeaddrinfo(addrinfo) lwip_freeaddrinfo(addrinfo) +/** @ingroup netdbapi */ +#define getaddrinfo(nodname, servname, hints, res) \ + lwip_getaddrinfo(nodname, servname, hints, res) +#endif /* LWIP_COMPAT_SOCKETS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_DNS && LWIP_SOCKET */ + +#endif /* LWIP_HDR_NETDB_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netif.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netif.h new file mode 100644 index 000000000..9a16deda2 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netif.h @@ -0,0 +1,673 @@ +/** + * @file + * netif API (to be used from TCPIP thread) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_NETIF_H +#define LWIP_HDR_NETIF_H + +#include "lwip/opt.h" + +#define ENABLE_LOOPBACK (LWIP_NETIF_LOOPBACK || LWIP_HAVE_LOOPIF) + +#include "lwip/err.h" + +#include "lwip/ip_addr.h" + +#include "lwip/def.h" +#include "lwip/pbuf.h" +#include "lwip/stats.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Throughout this file, IP addresses are expected to be in + * the same byte order as in IP_PCB. */ + +/** Must be the maximum of all used hardware address lengths + across all types of interfaces in use. + This does not have to be changed, normally. */ +#ifndef NETIF_MAX_HWADDR_LEN +#define NETIF_MAX_HWADDR_LEN 6U +#endif + +/** The size of a fully constructed netif name which the + * netif can be identified by in APIs. Composed of + * 2 chars, 3 (max) digits, and 1 \0 + */ +#define NETIF_NAMESIZE 6 + +/** + * @defgroup netif_flags Flags + * @ingroup netif + * @{ + */ + +/** Whether the network interface is 'up'. This is + * a software flag used to control whether this network + * interface is enabled and processes traffic. + * It must be set by the startup code before this netif can be used + * (also for dhcp/autoip). + */ +#define NETIF_FLAG_UP 0x01U +/** If set, the netif has broadcast capability. + * Set by the netif driver in its init function. */ +#define NETIF_FLAG_BROADCAST 0x02U +/** If set, the interface has an active link + * (set by the network interface driver). + * Either set by the netif driver in its init function (if the link + * is up at that time) or at a later point once the link comes up + * (if link detection is supported by the hardware). */ +#define NETIF_FLAG_LINK_UP 0x04U +/** If set, the netif is an ethernet device using ARP. + * Set by the netif driver in its init function. + * Used to check input packet types and use of DHCP. */ +#define NETIF_FLAG_ETHARP 0x08U +/** If set, the netif is an ethernet device. It might not use + * ARP or TCP/IP if it is used for PPPoE only. + */ +#define NETIF_FLAG_ETHERNET 0x10U +/** If set, the netif has IGMP capability. + * Set by the netif driver in its init function. */ +#define NETIF_FLAG_IGMP 0x20U +/** If set, the netif has MLD6 capability. + * Set by the netif driver in its init function. */ +#define NETIF_FLAG_MLD6 0x40U + +/** + * @} + */ + +enum lwip_internal_netif_client_data_index +{ +#if LWIP_IPV4 +#if LWIP_DHCP + LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, +#endif +#if LWIP_AUTOIP + LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP, +#endif +#if LWIP_IGMP + LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, +#endif +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 +#if LWIP_IPV6_DHCP6 + LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6, +#endif +#if LWIP_IPV6_MLD + LWIP_NETIF_CLIENT_DATA_INDEX_MLD6, +#endif +#endif /* LWIP_IPV6 */ + LWIP_NETIF_CLIENT_DATA_INDEX_MAX +}; + +#if LWIP_CHECKSUM_CTRL_PER_NETIF +#define NETIF_CHECKSUM_GEN_IP 0x0001 +#define NETIF_CHECKSUM_GEN_UDP 0x0002 +#define NETIF_CHECKSUM_GEN_TCP 0x0004 +#define NETIF_CHECKSUM_GEN_ICMP 0x0008 +#define NETIF_CHECKSUM_GEN_ICMP6 0x0010 +#define NETIF_CHECKSUM_CHECK_IP 0x0100 +#define NETIF_CHECKSUM_CHECK_UDP 0x0200 +#define NETIF_CHECKSUM_CHECK_TCP 0x0400 +#define NETIF_CHECKSUM_CHECK_ICMP 0x0800 +#define NETIF_CHECKSUM_CHECK_ICMP6 0x1000 +#define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF +#define NETIF_CHECKSUM_DISABLE_ALL 0x0000 +#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ + +struct netif; + +/** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or + * mld_mac_filter callback function. */ +enum netif_mac_filter_action { + /** Delete a filter entry */ + NETIF_DEL_MAC_FILTER = 0, + /** Add a filter entry */ + NETIF_ADD_MAC_FILTER = 1 +}; + +/** Function prototype for netif init functions. Set up flags and output/linkoutput + * callback functions in this function. + * + * @param netif The netif to initialize + */ +typedef err_t (*netif_init_fn)(struct netif *netif); +/** Function prototype for netif->input functions. This function is saved as 'input' + * callback function in the netif struct. Call it when a packet has been received. + * + * @param p The received packet, copied into a pbuf + * @param inp The netif which received the packet + * @return ERR_OK if the packet was handled + * != ERR_OK is the packet was NOT handled, in this case, the caller has + * to free the pbuf + */ +typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp); + +#if LWIP_IPV4 +/** Function prototype for netif->output functions. Called by lwIP when a packet + * shall be sent. For ethernet netif, set this to 'etharp_output' and set + * 'linkoutput'. + * + * @param netif The netif which shall send a packet + * @param p The packet to send (p->payload points to IP header) + * @param ipaddr The IP address to which the packet shall be sent + */ +typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p, + const ip4_addr_t *ipaddr); +#endif /* LWIP_IPV4*/ + +#if LWIP_IPV6 +/** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet + * shall be sent. For ethernet netif, set this to 'ethip6_output' and set + * 'linkoutput'. + * + * @param netif The netif which shall send a packet + * @param p The packet to send (p->payload points to IP header) + * @param ipaddr The IPv6 address to which the packet shall be sent + */ +typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p, + const ip6_addr_t *ipaddr); +#endif /* LWIP_IPV6 */ + +/** Function prototype for netif->linkoutput functions. Only used for ethernet + * netifs. This function is called by ARP when a packet shall be sent. + * + * @param netif The netif which shall send a packet + * @param p The packet to send (raw ethernet packet) + */ +typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p); +/** Function prototype for netif status- or link-callback functions. */ +typedef void (*netif_status_callback_fn)(struct netif *netif); +#if LWIP_IPV4 && LWIP_IGMP +/** Function prototype for netif igmp_mac_filter functions */ +typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif, + const ip4_addr_t *group, enum netif_mac_filter_action action); +#endif /* LWIP_IPV4 && LWIP_IGMP */ +#if LWIP_IPV6 && LWIP_IPV6_MLD +/** Function prototype for netif mld_mac_filter functions */ +typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif, + const ip6_addr_t *group, enum netif_mac_filter_action action); +#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ + +#if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || LWIP_IPV6_DHCP6 || (LWIP_NUM_NETIF_CLIENT_DATA > 0) +#if LWIP_NUM_NETIF_CLIENT_DATA > 0 +u8_t netif_alloc_client_data_id(void); +#endif +/** @ingroup netif_cd + * Set client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data) +/** @ingroup netif_cd + * Get client data. Obtain ID from netif_alloc_client_data_id(). + */ +#define netif_get_client_data(netif, id) (netif)->client_data[(id)] +#endif + +#if (LWIP_IPV4 && LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) || (LWIP_IPV6 && (LWIP_ND6_NUM_DESTINATIONS > 0x7f)) +typedef u16_t netif_addr_idx_t; +#define NETIF_ADDR_IDX_MAX 0x7FFF +#else +typedef u8_t netif_addr_idx_t; +#define NETIF_ADDR_IDX_MAX 0x7F +#endif + +#if LWIP_NETIF_HWADDRHINT +#define LWIP_NETIF_USE_HINTS 1 +struct netif_hint { + netif_addr_idx_t addr_hint; +}; +#else /* LWIP_NETIF_HWADDRHINT */ +#define LWIP_NETIF_USE_HINTS 0 +#endif /* LWIP_NETIF_HWADDRHINT */ + +/** Generic data structure used for all lwIP network interfaces. + * The following fields should be filled in by the initialization + * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ +struct netif { +#if !LWIP_SINGLE_NETIF + /** pointer to next in linked list */ + struct netif *next; +#endif + +#if LWIP_IPV4 + /** IP address configuration in network byte order */ + ip_addr_t ip_addr; + ip_addr_t netmask; + ip_addr_t gw; +#endif /* LWIP_IPV4 */ +#if LWIP_IPV6 + /** Array of IPv6 addresses for this netif. */ + ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; + /** The state of each IPv6 address (Tentative, Preferred, etc). + * @see ip6_addr.h */ + u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; +#if LWIP_IPV6_ADDRESS_LIFETIMES + /** Remaining valid and preferred lifetime of each IPv6 address, in seconds. + * For valid lifetimes, the special value of IP6_ADDR_LIFE_STATIC (0) + * indicates the address is static and has no lifetimes. */ + u32_t ip6_addr_valid_life[LWIP_IPV6_NUM_ADDRESSES]; + u32_t ip6_addr_pref_life[LWIP_IPV6_NUM_ADDRESSES]; +#endif /* LWIP_IPV6_ADDRESS_LIFETIMES */ +#endif /* LWIP_IPV6 */ + /** This function is called by the network device driver + * to pass a packet up the TCP/IP stack. */ + netif_input_fn input; +#if LWIP_IPV4 + /** This function is called by the IP module when it wants + * to send a packet on the interface. This function typically + * first resolves the hardware address, then sends the packet. + * For ethernet physical layer, this is usually etharp_output() */ + netif_output_fn output; +#endif /* LWIP_IPV4 */ + /** This function is called by ethernet_output() when it wants + * to send a packet on the interface. This function outputs + * the pbuf as-is on the link medium. */ + netif_linkoutput_fn linkoutput; +#if LWIP_IPV6 + /** This function is called by the IPv6 module when it wants + * to send a packet on the interface. This function typically + * first resolves the hardware address, then sends the packet. + * For ethernet physical layer, this is usually ethip6_output() */ + netif_output_ip6_fn output_ip6; +#endif /* LWIP_IPV6 */ +#if LWIP_NETIF_STATUS_CALLBACK + /** This function is called when the netif state is set to up or down + */ + netif_status_callback_fn status_callback; +#endif /* LWIP_NETIF_STATUS_CALLBACK */ +#if LWIP_NETIF_LINK_CALLBACK + /** This function is called when the netif link is set to up or down + */ + netif_status_callback_fn link_callback; +#endif /* LWIP_NETIF_LINK_CALLBACK */ +#if LWIP_NETIF_REMOVE_CALLBACK + /** This function is called when the netif has been removed */ + netif_status_callback_fn remove_callback; +#endif /* LWIP_NETIF_REMOVE_CALLBACK */ + /** This field can be set by the device driver and could point + * to state information for the device. */ + void *state; +#ifdef netif_get_client_data + void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA]; +#endif +#if LWIP_NETIF_HOSTNAME + /* the hostname for this netif, NULL is a valid value */ + const char* hostname; +#endif /* LWIP_NETIF_HOSTNAME */ +#if LWIP_CHECKSUM_CTRL_PER_NETIF + u16_t chksum_flags; +#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/ + /** maximum transfer unit (in bytes) */ + u16_t mtu; +#if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES + /** maximum transfer unit (in bytes), updated by RA */ + u16_t mtu6; +#endif /* LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES */ + /** link level hardware address of this interface */ + u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; + /** number of bytes used in hwaddr */ + u8_t hwaddr_len; + /** flags (@see @ref netif_flags) */ + u8_t flags; + /** descriptive abbreviation */ + char name[2]; + /** number of this interface. Used for @ref if_api and @ref netifapi_netif, + * as well as for IPv6 zones */ + u8_t num; +#if LWIP_IPV6_AUTOCONFIG + /** is this netif enabled for IPv6 autoconfiguration */ + u8_t ip6_autoconfig_enabled; +#endif /* LWIP_IPV6_AUTOCONFIG */ +#if LWIP_IPV6_SEND_ROUTER_SOLICIT + /** Number of Router Solicitation messages that remain to be sent. */ + u8_t rs_count; +#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */ +#if MIB2_STATS + /** link type (from "snmp_ifType" enum from snmp_mib2.h) */ + u8_t link_type; + /** (estimate) link speed */ + u32_t link_speed; + /** timestamp at last change made (up/down) */ + u32_t ts; + /** counters */ + struct stats_mib2_netif_ctrs mib2_counters; +#endif /* MIB2_STATS */ +#if LWIP_IPV4 && LWIP_IGMP + /** This function could be called to add or delete an entry in the multicast + filter table of the ethernet MAC.*/ + netif_igmp_mac_filter_fn igmp_mac_filter; +#endif /* LWIP_IPV4 && LWIP_IGMP */ +#if LWIP_IPV6 && LWIP_IPV6_MLD + /** This function could be called to add or delete an entry in the IPv6 multicast + filter table of the ethernet MAC. */ + netif_mld_mac_filter_fn mld_mac_filter; +#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ +#if LWIP_NETIF_USE_HINTS + struct netif_hint *hints; +#endif /* LWIP_NETIF_USE_HINTS */ +#if ENABLE_LOOPBACK + /* List of packets to be queued for ourselves. */ + struct pbuf *loop_first; + struct pbuf *loop_last; +#if LWIP_LOOPBACK_MAX_PBUFS + u16_t loop_cnt_current; +#endif /* LWIP_LOOPBACK_MAX_PBUFS */ +#if LWIP_NETIF_LOOPBACK_MULTITHREADING + /* Used if the original scheduling failed. */ + u8_t reschedule_poll; +#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ +#endif /* ENABLE_LOOPBACK */ +}; + +#if LWIP_CHECKSUM_CTRL_PER_NETIF +#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \ + (netif)->chksum_flags = chksumflags; } while(0) +#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0)) +#else /* LWIP_CHECKSUM_CTRL_PER_NETIF */ +#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) +#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) +#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */ + +#if LWIP_SINGLE_NETIF +#define NETIF_FOREACH(netif) if (((netif) = netif_default) != NULL) +#else /* LWIP_SINGLE_NETIF */ +/** The list of network interfaces. */ +extern struct netif *netif_list; +#define NETIF_FOREACH(netif) for ((netif) = netif_list; (netif) != NULL; (netif) = (netif)->next) +#endif /* LWIP_SINGLE_NETIF */ +/** The default network interface. */ +extern struct netif *netif_default; + +void netif_init(void); + +struct netif *netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); + +#if LWIP_IPV4 +struct netif *netif_add(struct netif *netif, + const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, + void *state, netif_init_fn init, netif_input_fn input); +void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, + const ip4_addr_t *gw); +#else /* LWIP_IPV4 */ +struct netif *netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input); +#endif /* LWIP_IPV4 */ +void netif_remove(struct netif * netif); + +/* Returns a network interface given its name. The name is of the form + "et0", where the first two letters are the "name" field in the + netif structure, and the digit is in the num field in the same + structure. */ +struct netif *netif_find(const char *name); + +void netif_set_default(struct netif *netif); + +#if LWIP_IPV4 +void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); +void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); +void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); +/** @ingroup netif_ip4 */ +#define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr))) +/** @ingroup netif_ip4 */ +#define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask))) +/** @ingroup netif_ip4 */ +#define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw))) +/** @ingroup netif_ip4 */ +#define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr)) +/** @ingroup netif_ip4 */ +#define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask)) +/** @ingroup netif_ip4 */ +#define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw)) +#endif /* LWIP_IPV4 */ + +#define netif_set_flags(netif, set_flags) do { (netif)->flags = (u8_t)((netif)->flags | (set_flags)); } while(0) +#define netif_clear_flags(netif, clr_flags) do { (netif)->flags = (u8_t)((netif)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0) +#define netif_is_flag_set(netif, flag) (((netif)->flags & (flag)) != 0) + +void netif_set_up(struct netif *netif); +void netif_set_down(struct netif *netif); +/** @ingroup netif + * Ask if an interface is up + */ +#define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8_t)1 : (u8_t)0) + +#if LWIP_NETIF_STATUS_CALLBACK +void netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback); +#endif /* LWIP_NETIF_STATUS_CALLBACK */ +#if LWIP_NETIF_REMOVE_CALLBACK +void netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback); +#endif /* LWIP_NETIF_REMOVE_CALLBACK */ + +void netif_set_link_up(struct netif *netif); +void netif_set_link_down(struct netif *netif); +/** Ask if a link is up */ +#define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8_t)1 : (u8_t)0) + +#if LWIP_NETIF_LINK_CALLBACK +void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback); +#endif /* LWIP_NETIF_LINK_CALLBACK */ + +#if LWIP_NETIF_HOSTNAME +/** @ingroup netif */ +#define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0) +/** @ingroup netif */ +#define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL) +#endif /* LWIP_NETIF_HOSTNAME */ + +#if LWIP_IGMP +/** @ingroup netif */ +#define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0) +#define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL) +#endif /* LWIP_IGMP */ + +#if LWIP_IPV6 && LWIP_IPV6_MLD +/** @ingroup netif */ +#define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0) +#define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL) +#define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0) +#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ + +#if ENABLE_LOOPBACK +err_t netif_loop_output(struct netif *netif, struct pbuf *p); +void netif_poll(struct netif *netif); +#if !LWIP_NETIF_LOOPBACK_MULTITHREADING +void netif_poll_all(void); +#endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ +#endif /* ENABLE_LOOPBACK */ + +err_t netif_input(struct pbuf *p, struct netif *inp); + +#if LWIP_IPV6 +/** @ingroup netif_ip6 */ +#define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i]))) +/** @ingroup netif_ip6 */ +#define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i]))) +void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6); +void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3); +#define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i]) +void netif_ip6_addr_set_state(struct netif* netif, s8_t addr_idx, u8_t state); +s8_t netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr); +void netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit); +err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx); +#define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0) +#if LWIP_IPV6_ADDRESS_LIFETIMES +#define netif_ip6_addr_valid_life(netif, i) \ + (((netif) != NULL) ? ((netif)->ip6_addr_valid_life[i]) : IP6_ADDR_LIFE_STATIC) +#define netif_ip6_addr_set_valid_life(netif, i, secs) \ + do { if (netif != NULL) { (netif)->ip6_addr_valid_life[i] = (secs); }} while (0) +#define netif_ip6_addr_pref_life(netif, i) \ + (((netif) != NULL) ? ((netif)->ip6_addr_pref_life[i]) : IP6_ADDR_LIFE_STATIC) +#define netif_ip6_addr_set_pref_life(netif, i, secs) \ + do { if (netif != NULL) { (netif)->ip6_addr_pref_life[i] = (secs); }} while (0) +#define netif_ip6_addr_isstatic(netif, i) \ + (netif_ip6_addr_valid_life((netif), (i)) == IP6_ADDR_LIFE_STATIC) +#else /* !LWIP_IPV6_ADDRESS_LIFETIMES */ +#define netif_ip6_addr_isstatic(netif, i) (1) /* all addresses are static */ +#endif /* !LWIP_IPV6_ADDRESS_LIFETIMES */ +#if LWIP_ND6_ALLOW_RA_UPDATES +#define netif_mtu6(netif) ((netif)->mtu6) +#else /* LWIP_ND6_ALLOW_RA_UPDATES */ +#define netif_mtu6(netif) ((netif)->mtu) +#endif /* LWIP_ND6_ALLOW_RA_UPDATES */ +#endif /* LWIP_IPV6 */ + +#if LWIP_NETIF_USE_HINTS +#define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint) +#define NETIF_RESET_HINTS(netif) (netif)->hints = NULL +#else /* LWIP_NETIF_USE_HINTS */ +#define NETIF_SET_HINTS(netif, netifhint) +#define NETIF_RESET_HINTS(netif) +#endif /* LWIP_NETIF_USE_HINTS */ + +u8_t netif_name_to_index(const char *name); +char * netif_index_to_name(u8_t idx, char *name); +struct netif* netif_get_by_index(u8_t idx); + +/* Interface indexes always start at 1 per RFC 3493, section 4, num starts at 0 (internal index is 0..254)*/ +#define netif_get_index(netif) ((u8_t)((netif)->num + 1)) +#define NETIF_NO_INDEX (0) + +/** + * @ingroup netif + * Extended netif status callback (NSC) reasons flags. + * May be extended in the future! + */ +typedef u16_t netif_nsc_reason_t; + +/* used for initialization only */ +#define LWIP_NSC_NONE 0x0000 +/** netif was added. arg: NULL. Called AFTER netif was added. */ +#define LWIP_NSC_NETIF_ADDED 0x0001 +/** netif was removed. arg: NULL. Called BEFORE netif is removed. */ +#define LWIP_NSC_NETIF_REMOVED 0x0002 +/** link changed */ +#define LWIP_NSC_LINK_CHANGED 0x0004 +/** netif administrative status changed.\n + * up is called AFTER netif is set up.\n + * down is called BEFORE the netif is actually set down. */ +#define LWIP_NSC_STATUS_CHANGED 0x0008 +/** IPv4 address has changed */ +#define LWIP_NSC_IPV4_ADDRESS_CHANGED 0x0010 +/** IPv4 gateway has changed */ +#define LWIP_NSC_IPV4_GATEWAY_CHANGED 0x0020 +/** IPv4 netmask has changed */ +#define LWIP_NSC_IPV4_NETMASK_CHANGED 0x0040 +/** called AFTER IPv4 address/gateway/netmask changes have been applied */ +#define LWIP_NSC_IPV4_SETTINGS_CHANGED 0x0080 +/** IPv6 address was added */ +#define LWIP_NSC_IPV6_SET 0x0100 +/** IPv6 address state has changed */ +#define LWIP_NSC_IPV6_ADDR_STATE_CHANGED 0x0200 + +/** @ingroup netif + * Argument supplied to netif_ext_callback_fn. + */ +typedef union +{ + /** Args to LWIP_NSC_LINK_CHANGED callback */ + struct link_changed_s + { + /** 1: up; 0: down */ + u8_t state; + } link_changed; + /** Args to LWIP_NSC_STATUS_CHANGED callback */ + struct status_changed_s + { + /** 1: up; 0: down */ + u8_t state; + } status_changed; + /** Args to LWIP_NSC_IPV4_ADDRESS_CHANGED|LWIP_NSC_IPV4_GATEWAY_CHANGED|LWIP_NSC_IPV4_NETMASK_CHANGED|LWIP_NSC_IPV4_SETTINGS_CHANGED callback */ + struct ipv4_changed_s + { + /** Old IPv4 address */ + const ip_addr_t* old_address; + const ip_addr_t* old_netmask; + const ip_addr_t* old_gw; + } ipv4_changed; + /** Args to LWIP_NSC_IPV6_SET callback */ + struct ipv6_set_s + { + /** Index of changed IPv6 address */ + s8_t addr_index; + /** Old IPv6 address */ + const ip_addr_t* old_address; + } ipv6_set; + /** Args to LWIP_NSC_IPV6_ADDR_STATE_CHANGED callback */ + struct ipv6_addr_state_changed_s + { + /** Index of affected IPv6 address */ + s8_t addr_index; + /** Old IPv6 address state */ + u8_t old_state; + /** Affected IPv6 address */ + const ip_addr_t* address; + } ipv6_addr_state_changed; +} netif_ext_callback_args_t; + +/** + * @ingroup netif + * Function used for extended netif status callbacks + * Note: When parsing reason argument, keep in mind that more reasons may be added in the future! + * @param netif netif that is affected by change + * @param reason change reason + * @param args depends on reason, see reason description + */ +typedef void (*netif_ext_callback_fn)(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); + +#if LWIP_NETIF_EXT_STATUS_CALLBACK +struct netif_ext_callback; +typedef struct netif_ext_callback +{ + netif_ext_callback_fn callback_fn; + struct netif_ext_callback* next; +} netif_ext_callback_t; + +#define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name; +void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn); +void netif_remove_ext_callback(netif_ext_callback_t* callback); +void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args); +#else +#define NETIF_DECLARE_EXT_CALLBACK(name) +#define netif_add_ext_callback(callback, fn) +#define netif_remove_ext_callback(callback) +#define netif_invoke_ext_callback(netif, reason, args) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_NETIF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netifapi.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netifapi.h new file mode 100644 index 000000000..e0631791b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/netifapi.h @@ -0,0 +1,161 @@ +/** + * @file + * netif API (to be used from non-TCPIP threads) + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ +#ifndef LWIP_HDR_NETIFAPI_H +#define LWIP_HDR_NETIFAPI_H + +#include "lwip/opt.h" + +#if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/sys.h" +#include "lwip/netif.h" +#include "lwip/dhcp.h" +#include "lwip/autoip.h" +#include "lwip/priv/tcpip_priv.h" +#include "lwip/priv/api_msg.h" +#include "lwip/prot/ethernet.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* API for application */ +#if LWIP_ARP && LWIP_IPV4 +/* Used for netfiapi_arp_* APIs */ +enum netifapi_arp_entry { + NETIFAPI_ARP_PERM /* Permanent entry */ + /* Other entry types can be added here */ +}; + +/** @ingroup netifapi_arp */ +err_t netifapi_arp_add(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, enum netifapi_arp_entry type); +/** @ingroup netifapi_arp */ +err_t netifapi_arp_remove(const ip4_addr_t *ipaddr, enum netifapi_arp_entry type); +#endif /* LWIP_ARP && LWIP_IPV4 */ + +err_t netifapi_netif_add(struct netif *netif, +#if LWIP_IPV4 + const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw, +#endif /* LWIP_IPV4 */ + void *state, netif_init_fn init, netif_input_fn input); + +#if LWIP_IPV4 +err_t netifapi_netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, + const ip4_addr_t *netmask, const ip4_addr_t *gw); +#endif /* LWIP_IPV4*/ + +err_t netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc, + netifapi_errt_fn errtfunc); + +/** @ingroup netifapi_netif */ +err_t netifapi_netif_name_to_index(const char *name, u8_t *index); +/** @ingroup netifapi_netif */ +err_t netifapi_netif_index_to_name(u8_t index, char *name); + +/** @ingroup netifapi_netif + * @see netif_remove() + */ +#define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL) +/** @ingroup netifapi_netif + * @see netif_set_up() + */ +#define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL) +/** @ingroup netifapi_netif + * @see netif_set_down() + */ +#define netifapi_netif_set_down(n) netifapi_netif_common(n, netif_set_down, NULL) +/** @ingroup netifapi_netif + * @see netif_set_default() + */ +#define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL) +/** @ingroup netifapi_netif + * @see netif_set_link_up() + */ +#define netifapi_netif_set_link_up(n) netifapi_netif_common(n, netif_set_link_up, NULL) +/** @ingroup netifapi_netif + * @see netif_set_link_down() + */ +#define netifapi_netif_set_link_down(n) netifapi_netif_common(n, netif_set_link_down, NULL) + +/** + * @defgroup netifapi_dhcp4 DHCPv4 + * @ingroup netifapi + * To be called from non-TCPIP threads + */ +/** @ingroup netifapi_dhcp4 + * @see dhcp_start() + */ +#define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start) +/** + * @ingroup netifapi_dhcp4 + * @deprecated Use netifapi_dhcp_release_and_stop() instead. + */ +#define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL) +/** @ingroup netifapi_dhcp4 + * @see dhcp_inform() + */ +#define netifapi_dhcp_inform(n) netifapi_netif_common(n, dhcp_inform, NULL) +/** @ingroup netifapi_dhcp4 + * @see dhcp_renew() + */ +#define netifapi_dhcp_renew(n) netifapi_netif_common(n, NULL, dhcp_renew) +/** + * @ingroup netifapi_dhcp4 + * @deprecated Use netifapi_dhcp_release_and_stop() instead. + */ +#define netifapi_dhcp_release(n) netifapi_netif_common(n, NULL, dhcp_release) +/** @ingroup netifapi_dhcp4 + * @see dhcp_release_and_stop() + */ +#define netifapi_dhcp_release_and_stop(n) netifapi_netif_common(n, dhcp_release_and_stop, NULL) + +/** + * @defgroup netifapi_autoip AUTOIP + * @ingroup netifapi + * To be called from non-TCPIP threads + */ +/** @ingroup netifapi_autoip + * @see autoip_start() + */ +#define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start) +/** @ingroup netifapi_autoip + * @see autoip_stop() + */ +#define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_NETIF_API */ + +#endif /* LWIP_HDR_NETIFAPI_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/opt.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/opt.h new file mode 100644 index 000000000..d8c82d156 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/opt.h @@ -0,0 +1,3526 @@ +/** + * @file + * + * lwIP Options Configuration + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +/* + * NOTE: || defined __DOXYGEN__ is a workaround for doxygen bug - + * without this, doxygen does not see the actual #define + */ + +#if !defined LWIP_HDR_OPT_H +#define LWIP_HDR_OPT_H + +/* + * Include user defined options first. Anything not defined in these files + * will be set to standard values. Override anything you don't like! + */ +#include "lwipopts.h" +#include "lwip/debug.h" + +/** + * @defgroup lwip_opts Options (lwipopts.h) + * @ingroup lwip + * + * @defgroup lwip_opts_debug Debugging + * @ingroup lwip_opts + * + * @defgroup lwip_opts_infrastructure Infrastructure + * @ingroup lwip_opts + * + * @defgroup lwip_opts_callback Callback-style APIs + * @ingroup lwip_opts + * + * @defgroup lwip_opts_threadsafe_apis Thread-safe APIs + * @ingroup lwip_opts + */ + + /* + ------------------------------------ + -------------- NO SYS -------------- + ------------------------------------ +*/ +/** + * @defgroup lwip_opts_nosys NO_SYS + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * NO_SYS==1: Use lwIP without OS-awareness (no thread, semaphores, mutexes or + * mboxes). This means threaded APIs cannot be used (socket, netconn, + * i.e. everything in the 'api' folder), only the callback-style raw API is + * available (and you have to watch out for yourself that you don't access + * lwIP functions/structures from more than one context at a time!) + */ +#if !defined NO_SYS || defined __DOXYGEN__ +#define NO_SYS 0 +#endif +/** + * @} + */ + +/** + * @defgroup lwip_opts_timers Timers + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * LWIP_TIMERS==0: Drop support for sys_timeout and lwip-internal cyclic timers. + * (the array of lwip-internal cyclic timers is still provided) + * (check NO_SYS_NO_TIMERS for compatibility to old versions) + */ +#if !defined LWIP_TIMERS || defined __DOXYGEN__ +#ifdef NO_SYS_NO_TIMERS +#define LWIP_TIMERS (!NO_SYS || (NO_SYS && !NO_SYS_NO_TIMERS)) +#else +#define LWIP_TIMERS 1 +#endif +#endif + +/** + * LWIP_TIMERS_CUSTOM==1: Provide your own timer implementation. + * Function prototypes in timeouts.h and the array of lwip-internal cyclic timers + * are still included, but the implementation is not. The following functions + * will be required: sys_timeouts_init(), sys_timeout(), sys_untimeout(), + * sys_timeouts_mbox_fetch() + */ +#if !defined LWIP_TIMERS_CUSTOM || defined __DOXYGEN__ +#define LWIP_TIMERS_CUSTOM 0 +#endif +/** + * @} + */ + +/** + * @defgroup lwip_opts_memcpy memcpy + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * MEMCPY: override this if you have a faster implementation at hand than the + * one included in your C library + */ +#if !defined MEMCPY || defined __DOXYGEN__ +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif + +/** + * SMEMCPY: override this with care! Some compilers (e.g. gcc) can inline a + * call to memcpy() if the length is known at compile time and is small. + */ +#if !defined SMEMCPY || defined __DOXYGEN__ +#define SMEMCPY(dst,src,len) memcpy(dst,src,len) +#endif + +/** + * MEMMOVE: override this if you have a faster implementation at hand than the + * one included in your C library. lwIP currently uses MEMMOVE only when IPv6 + * fragmentation support is enabled. + */ +#if !defined MEMMOVE || defined __DOXYGEN__ +#define MEMMOVE(dst,src,len) memmove(dst,src,len) +#endif +/** + * @} + */ + +/* + ------------------------------------ + ----------- Core locking ----------- + ------------------------------------ +*/ +/** + * @defgroup lwip_opts_lock Core locking and MPU + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * LWIP_MPU_COMPATIBLE: enables special memory management mechanism + * which makes lwip able to work on MPU (Memory Protection Unit) system + * by not passing stack-pointers to other threads + * (this decreases performance as memory is allocated from pools instead + * of keeping it on the stack) + */ +#if !defined LWIP_MPU_COMPATIBLE || defined __DOXYGEN__ +#define LWIP_MPU_COMPATIBLE 0 +#endif + +/** + * LWIP_TCPIP_CORE_LOCKING + * Creates a global mutex that is held during TCPIP thread operations. + * Can be locked by client code to perform lwIP operations without changing + * into TCPIP thread using callbacks. See LOCK_TCPIP_CORE() and + * UNLOCK_TCPIP_CORE(). + * Your system should provide mutexes supporting priority inversion to use this. + */ +#if !defined LWIP_TCPIP_CORE_LOCKING || defined __DOXYGEN__ +#define LWIP_TCPIP_CORE_LOCKING 1 +#endif + +/** + * LWIP_TCPIP_CORE_LOCKING_INPUT: when LWIP_TCPIP_CORE_LOCKING is enabled, + * this lets tcpip_input() grab the mutex for input packets as well, + * instead of allocating a message and passing it to tcpip_thread. + * + * ATTENTION: this does not work when tcpip_input() is called from + * interrupt context! + */ +#if !defined LWIP_TCPIP_CORE_LOCKING_INPUT || defined __DOXYGEN__ +#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 +#endif + +/** + * SYS_LIGHTWEIGHT_PROT==1: enable inter-task protection (and task-vs-interrupt + * protection) for certain critical regions during buffer allocation, deallocation + * and memory allocation and deallocation. + * ATTENTION: This is required when using lwIP from more than one context! If + * you disable this, you must be sure what you are doing! + */ +#if !defined SYS_LIGHTWEIGHT_PROT || defined __DOXYGEN__ +#define SYS_LIGHTWEIGHT_PROT 1 +#endif + +/** + * Macro/function to check whether lwIP's threading/locking + * requirements are satisfied during current function call. + * This macro usually calls a function that is implemented in the OS-dependent + * sys layer and performs the following checks: + * - Not in ISR (this should be checked for NO_SYS==1, too!) + * - If @ref LWIP_TCPIP_CORE_LOCKING = 1: TCPIP core lock is held + * - If @ref LWIP_TCPIP_CORE_LOCKING = 0: function is called from TCPIP thread + * @see @ref multithreading + */ +#if !defined LWIP_ASSERT_CORE_LOCKED || defined __DOXYGEN__ +#define LWIP_ASSERT_CORE_LOCKED() +#endif + +/** + * Called as first thing in the lwIP TCPIP thread. Can be used in conjunction + * with @ref LWIP_ASSERT_CORE_LOCKED to check core locking. + * @see @ref multithreading + */ +#if !defined LWIP_MARK_TCPIP_THREAD || defined __DOXYGEN__ +#define LWIP_MARK_TCPIP_THREAD() +#endif +/** + * @} + */ + +/* + ------------------------------------ + ---------- Memory options ---------- + ------------------------------------ +*/ +/** + * @defgroup lwip_opts_mem Heap and memory pools + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library + * instead of the lwip internal allocator. Can save code size if you + * already use it. + */ +#if !defined MEM_LIBC_MALLOC || defined __DOXYGEN__ +#define MEM_LIBC_MALLOC 0 +#endif + +/** + * MEMP_MEM_MALLOC==1: Use mem_malloc/mem_free instead of the lwip pool allocator. + * Especially useful with MEM_LIBC_MALLOC but handle with care regarding execution + * speed (heap alloc can be much slower than pool alloc) and usage from interrupts + * (especially if your netif driver allocates PBUF_POOL pbufs for received frames + * from interrupt)! + * ATTENTION: Currently, this uses the heap for ALL pools (also for private pools, + * not only for internal pools defined in memp_std.h)! + */ +#if !defined MEMP_MEM_MALLOC || defined __DOXYGEN__ +#define MEMP_MEM_MALLOC 0 +#endif + +/** + * MEMP_MEM_INIT==1: Force use of memset to initialize pool memory. + * Useful if pool are moved in uninitialized section of memory. This will ensure + * default values in pcbs struct are well initialized in all conditions. + */ +#if !defined MEMP_MEM_INIT || defined __DOXYGEN__ +#define MEMP_MEM_INIT 0 +#endif + +/** + * MEM_ALIGNMENT: should be set to the alignment of the CPU + * 4 byte alignment -> \#define MEM_ALIGNMENT 4 + * 2 byte alignment -> \#define MEM_ALIGNMENT 2 + */ +#if !defined MEM_ALIGNMENT || defined __DOXYGEN__ +#define MEM_ALIGNMENT 1 +#endif + +/** + * MEM_SIZE: the size of the heap memory. If the application will send + * a lot of data that needs to be copied, this should be set high. + */ +#if !defined MEM_SIZE || defined __DOXYGEN__ +#define MEM_SIZE 1600 +#endif + +/** + * MEMP_OVERFLOW_CHECK: memp overflow protection reserves a configurable + * amount of bytes before and after each memp element in every pool and fills + * it with a prominent default value. + * MEMP_OVERFLOW_CHECK == 0 no checking + * MEMP_OVERFLOW_CHECK == 1 checks each element when it is freed + * MEMP_OVERFLOW_CHECK >= 2 checks each element in every pool every time + * memp_malloc() or memp_free() is called (useful but slow!) + */ +#if !defined MEMP_OVERFLOW_CHECK || defined __DOXYGEN__ +#define MEMP_OVERFLOW_CHECK 0 +#endif + +/** + * MEMP_SANITY_CHECK==1: run a sanity check after each memp_free() to make + * sure that there are no cycles in the linked lists. + */ +#if !defined MEMP_SANITY_CHECK || defined __DOXYGEN__ +#define MEMP_SANITY_CHECK 0 +#endif + +/** + * MEM_OVERFLOW_CHECK: mem overflow protection reserves a configurable + * amount of bytes before and after each heap allocation chunk and fills + * it with a prominent default value. + * MEM_OVERFLOW_CHECK == 0 no checking + * MEM_OVERFLOW_CHECK == 1 checks each element when it is freed + * MEM_OVERFLOW_CHECK >= 2 checks all heap elements every time + * mem_malloc() or mem_free() is called (useful but slow!) + */ +#if !defined MEM_OVERFLOW_CHECK || defined __DOXYGEN__ +#define MEM_OVERFLOW_CHECK 0 +#endif + +/** + * MEM_SANITY_CHECK==1: run a sanity check after each mem_free() to make + * sure that the linked list of heap elements is not corrupted. + */ +#if !defined MEM_SANITY_CHECK || defined __DOXYGEN__ +#define MEM_SANITY_CHECK 0 +#endif + +/** + * MEM_USE_POOLS==1: Use an alternative to malloc() by allocating from a set + * of memory pools of various sizes. When mem_malloc is called, an element of + * the smallest pool that can provide the length needed is returned. + * To use this, MEMP_USE_CUSTOM_POOLS also has to be enabled. + */ +#if !defined MEM_USE_POOLS || defined __DOXYGEN__ +#define MEM_USE_POOLS 0 +#endif + +/** + * MEM_USE_POOLS_TRY_BIGGER_POOL==1: if one malloc-pool is empty, try the next + * bigger pool - WARNING: THIS MIGHT WASTE MEMORY but it can make a system more + * reliable. */ +#if !defined MEM_USE_POOLS_TRY_BIGGER_POOL || defined __DOXYGEN__ +#define MEM_USE_POOLS_TRY_BIGGER_POOL 0 +#endif + +/** + * MEMP_USE_CUSTOM_POOLS==1: whether to include a user file lwippools.h + * that defines additional pools beyond the "standard" ones required + * by lwIP. If you set this to 1, you must have lwippools.h in your + * include path somewhere. + */ +#if !defined MEMP_USE_CUSTOM_POOLS || defined __DOXYGEN__ +#define MEMP_USE_CUSTOM_POOLS 0 +#endif + +/** + * Set this to 1 if you want to free PBUF_RAM pbufs (or call mem_free()) from + * interrupt context (or another context that doesn't allow waiting for a + * semaphore). + * If set to 1, mem_malloc will be protected by a semaphore and SYS_ARCH_PROTECT, + * while mem_free will only use SYS_ARCH_PROTECT. mem_malloc SYS_ARCH_UNPROTECTs + * with each loop so that mem_free can run. + * + * ATTENTION: As you can see from the above description, this leads to dis-/ + * enabling interrupts often, which can be slow! Also, on low memory, mem_malloc + * can need longer. + * + * If you don't want that, at least for NO_SYS=0, you can still use the following + * functions to enqueue a deallocation call which then runs in the tcpip_thread + * context: + * - pbuf_free_callback(p); + * - mem_free_callback(m); + */ +#if !defined LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT || defined __DOXYGEN__ +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 0 +#endif +/** + * @} + */ + +/* + ------------------------------------------------ + ---------- Internal Memory Pool Sizes ---------- + ------------------------------------------------ +*/ +/** + * @defgroup lwip_opts_memp Internal memory pools + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF). + * If the application sends a lot of data out of ROM (or other static memory), + * this should be set high. + */ +#if !defined MEMP_NUM_PBUF || defined __DOXYGEN__ +#define MEMP_NUM_PBUF 16 +#endif + +/** + * MEMP_NUM_RAW_PCB: Number of raw connection PCBs + * (requires the LWIP_RAW option) + */ +#if !defined MEMP_NUM_RAW_PCB || defined __DOXYGEN__ +#define MEMP_NUM_RAW_PCB 4 +#endif + +/** + * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One + * per active UDP "connection". + * (requires the LWIP_UDP option) + */ +#if !defined MEMP_NUM_UDP_PCB || defined __DOXYGEN__ +#define MEMP_NUM_UDP_PCB 4 +#endif + +/** + * MEMP_NUM_TCP_PCB: the number of simultaneously active TCP connections. + * (requires the LWIP_TCP option) + */ +#if !defined MEMP_NUM_TCP_PCB || defined __DOXYGEN__ +#define MEMP_NUM_TCP_PCB 5 +#endif + +/** + * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections. + * (requires the LWIP_TCP option) + */ +#if !defined MEMP_NUM_TCP_PCB_LISTEN || defined __DOXYGEN__ +#define MEMP_NUM_TCP_PCB_LISTEN 8 +#endif + +/** + * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. + * (requires the LWIP_TCP option) + */ +#if !defined MEMP_NUM_TCP_SEG || defined __DOXYGEN__ +#define MEMP_NUM_TCP_SEG 16 +#endif + +/** + * MEMP_NUM_ALTCP_PCB: the number of simultaneously active altcp layer pcbs. + * (requires the LWIP_ALTCP option) + * Connections with multiple layers require more than one altcp_pcb (e.g. TLS + * over TCP requires 2 altcp_pcbs, one for TLS and one for TCP). + */ +#if !defined MEMP_NUM_ALTCP_PCB || defined __DOXYGEN__ +#define MEMP_NUM_ALTCP_PCB MEMP_NUM_TCP_PCB +#endif + +/** + * MEMP_NUM_REASSDATA: the number of IP packets simultaneously queued for + * reassembly (whole packets, not fragments!) + */ +#if !defined MEMP_NUM_REASSDATA || defined __DOXYGEN__ +#define MEMP_NUM_REASSDATA 5 +#endif + +/** + * MEMP_NUM_FRAG_PBUF: the number of IP fragments simultaneously sent + * (fragments, not whole packets!). + * This is only used with LWIP_NETIF_TX_SINGLE_PBUF==0 and only has to be > 1 + * with DMA-enabled MACs where the packet is not yet sent when netif->output + * returns. + */ +#if !defined MEMP_NUM_FRAG_PBUF || defined __DOXYGEN__ +#define MEMP_NUM_FRAG_PBUF 15 +#endif + +/** + * MEMP_NUM_ARP_QUEUE: the number of simultaneously queued outgoing + * packets (pbufs) that are waiting for an ARP request (to resolve + * their destination address) to finish. + * (requires the ARP_QUEUEING option) + */ +#if !defined MEMP_NUM_ARP_QUEUE || defined __DOXYGEN__ +#define MEMP_NUM_ARP_QUEUE 30 +#endif + +/** + * MEMP_NUM_IGMP_GROUP: The number of multicast groups whose network interfaces + * can be members at the same time (one per netif - allsystems group -, plus one + * per netif membership). + * (requires the LWIP_IGMP option) + */ +#if !defined MEMP_NUM_IGMP_GROUP || defined __DOXYGEN__ +#define MEMP_NUM_IGMP_GROUP 8 +#endif + +/** + * The number of sys timeouts used by the core stack (not apps) + * The default number of timeouts is calculated here for all enabled modules. + */ +#define LWIP_NUM_SYS_TIMEOUT_INTERNAL (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_NUM_TIMEOUTS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD))) + +/** + * MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts. + * The default number of timeouts is calculated here for all enabled modules. + * The formula expects settings to be either '0' or '1'. + */ +#if !defined MEMP_NUM_SYS_TIMEOUT || defined __DOXYGEN__ +#define MEMP_NUM_SYS_TIMEOUT LWIP_NUM_SYS_TIMEOUT_INTERNAL +#endif + +/** + * MEMP_NUM_NETBUF: the number of struct netbufs. + * (only needed if you use the sequential API, like api_lib.c) + */ +#if !defined MEMP_NUM_NETBUF || defined __DOXYGEN__ +#define MEMP_NUM_NETBUF 2 +#endif + +/** + * MEMP_NUM_NETCONN: the number of struct netconns. + * (only needed if you use the sequential API, like api_lib.c) + */ +#if !defined MEMP_NUM_NETCONN || defined __DOXYGEN__ +#define MEMP_NUM_NETCONN 4 +#endif + +/** + * MEMP_NUM_SELECT_CB: the number of struct lwip_select_cb. + * (Only needed if you have LWIP_MPU_COMPATIBLE==1 and use the socket API. + * In that case, you need one per thread calling lwip_select.) + */ +#if !defined MEMP_NUM_SELECT_CB || defined __DOXYGEN__ +#define MEMP_NUM_SELECT_CB 4 +#endif + +/** + * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used + * for callback/timeout API communication. + * (only needed if you use tcpip.c) + */ +#if !defined MEMP_NUM_TCPIP_MSG_API || defined __DOXYGEN__ +#define MEMP_NUM_TCPIP_MSG_API 8 +#endif + +/** + * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used + * for incoming packets. + * (only needed if you use tcpip.c) + */ +#if !defined MEMP_NUM_TCPIP_MSG_INPKT || defined __DOXYGEN__ +#define MEMP_NUM_TCPIP_MSG_INPKT 8 +#endif + +/** + * MEMP_NUM_NETDB: the number of concurrently running lwip_addrinfo() calls + * (before freeing the corresponding memory using lwip_freeaddrinfo()). + */ +#if !defined MEMP_NUM_NETDB || defined __DOXYGEN__ +#define MEMP_NUM_NETDB 1 +#endif + +/** + * MEMP_NUM_LOCALHOSTLIST: the number of host entries in the local host list + * if DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1. + */ +#if !defined MEMP_NUM_LOCALHOSTLIST || defined __DOXYGEN__ +#define MEMP_NUM_LOCALHOSTLIST 1 +#endif + +/** + * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. + */ +#if !defined PBUF_POOL_SIZE || defined __DOXYGEN__ +#define PBUF_POOL_SIZE 16 +#endif + +/** MEMP_NUM_API_MSG: the number of concurrently active calls to various + * socket, netconn, and tcpip functions + */ +#if !defined MEMP_NUM_API_MSG || defined __DOXYGEN__ +#define MEMP_NUM_API_MSG MEMP_NUM_TCPIP_MSG_API +#endif + +/** MEMP_NUM_DNS_API_MSG: the number of concurrently active calls to netconn_gethostbyname + */ +#if !defined MEMP_NUM_DNS_API_MSG || defined __DOXYGEN__ +#define MEMP_NUM_DNS_API_MSG MEMP_NUM_TCPIP_MSG_API +#endif + +/** MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA: the number of concurrently active calls + * to getsockopt/setsockopt + */ +#if !defined MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA || defined __DOXYGEN__ +#define MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA MEMP_NUM_TCPIP_MSG_API +#endif + +/** MEMP_NUM_NETIFAPI_MSG: the number of concurrently active calls to the + * netifapi functions + */ +#if !defined MEMP_NUM_NETIFAPI_MSG || defined __DOXYGEN__ +#define MEMP_NUM_NETIFAPI_MSG MEMP_NUM_TCPIP_MSG_API +#endif +/** + * @} + */ + +/* + --------------------------------- + ---------- ARP options ---------- + --------------------------------- +*/ +/** + * @defgroup lwip_opts_arp ARP + * @ingroup lwip_opts_ipv4 + * @{ + */ +/** + * LWIP_ARP==1: Enable ARP functionality. + */ +#if !defined LWIP_ARP || defined __DOXYGEN__ +#define LWIP_ARP 1 +#endif + +/** + * ARP_TABLE_SIZE: Number of active MAC-IP address pairs cached. + */ +#if !defined ARP_TABLE_SIZE || defined __DOXYGEN__ +#define ARP_TABLE_SIZE 10 +#endif + +/** the time an ARP entry stays valid after its last update, + * for ARP_TMR_INTERVAL = 1000, this is + * (60 * 5) seconds = 5 minutes. + */ +#if !defined ARP_MAXAGE || defined __DOXYGEN__ +#define ARP_MAXAGE 300 +#endif + +/** + * ARP_QUEUEING==1: Multiple outgoing packets are queued during hardware address + * resolution. By default, only the most recent packet is queued per IP address. + * This is sufficient for most protocols and mainly reduces TCP connection + * startup time. Set this to 1 if you know your application sends more than one + * packet in a row to an IP address that is not in the ARP cache. + */ +#if !defined ARP_QUEUEING || defined __DOXYGEN__ +#define ARP_QUEUEING 0 +#endif + +/** The maximum number of packets which may be queued for each + * unresolved address by other network layers. Defaults to 3, 0 means disabled. + * Old packets are dropped, new packets are queued. + */ +#if !defined ARP_QUEUE_LEN || defined __DOXYGEN__ +#define ARP_QUEUE_LEN 3 +#endif + +/** + * ETHARP_SUPPORT_VLAN==1: support receiving and sending ethernet packets with + * VLAN header. See the description of LWIP_HOOK_VLAN_CHECK and + * LWIP_HOOK_VLAN_SET hooks to check/set VLAN headers. + * Additionally, you can define ETHARP_VLAN_CHECK to an u16_t VLAN ID to check. + * If ETHARP_VLAN_CHECK is defined, only VLAN-traffic for this VLAN is accepted. + * If ETHARP_VLAN_CHECK is not defined, all traffic is accepted. + * Alternatively, define a function/define ETHARP_VLAN_CHECK_FN(eth_hdr, vlan) + * that returns 1 to accept a packet or 0 to drop a packet. + */ +#if !defined ETHARP_SUPPORT_VLAN || defined __DOXYGEN__ +#define ETHARP_SUPPORT_VLAN 0 +#endif + +/** LWIP_ETHERNET==1: enable ethernet support even though ARP might be disabled + */ +#if !defined LWIP_ETHERNET || defined __DOXYGEN__ +#define LWIP_ETHERNET LWIP_ARP +#endif + +/** ETH_PAD_SIZE: number of bytes added before the ethernet header to ensure + * alignment of payload after that header. Since the header is 14 bytes long, + * without this padding e.g. addresses in the IP header will not be aligned + * on a 32-bit boundary, so setting this to 2 can speed up 32-bit-platforms. + */ +#if !defined ETH_PAD_SIZE || defined __DOXYGEN__ +#define ETH_PAD_SIZE 0 +#endif + +/** ETHARP_SUPPORT_STATIC_ENTRIES==1: enable code to support static ARP table + * entries (using etharp_add_static_entry/etharp_remove_static_entry). + */ +#if !defined ETHARP_SUPPORT_STATIC_ENTRIES || defined __DOXYGEN__ +#define ETHARP_SUPPORT_STATIC_ENTRIES 0 +#endif + +/** ETHARP_TABLE_MATCH_NETIF==1: Match netif for ARP table entries. + * If disabled, duplicate IP address on multiple netifs are not supported + * (but this should only occur for AutoIP). + */ +#if !defined ETHARP_TABLE_MATCH_NETIF || defined __DOXYGEN__ +#define ETHARP_TABLE_MATCH_NETIF !LWIP_SINGLE_NETIF +#endif +/** + * @} + */ + +/* + -------------------------------- + ---------- IP options ---------- + -------------------------------- +*/ +/** + * @defgroup lwip_opts_ipv4 IPv4 + * @ingroup lwip_opts + * @{ + */ +/** + * LWIP_IPV4==1: Enable IPv4 + */ +#if !defined LWIP_IPV4 || defined __DOXYGEN__ +#define LWIP_IPV4 1 +#endif + +/** + * IP_FORWARD==1: Enables the ability to forward IP packets across network + * interfaces. If you are going to run lwIP on a device with only one network + * interface, define this to 0. + */ +#if !defined IP_FORWARD || defined __DOXYGEN__ +#define IP_FORWARD 0 +#endif + +/** + * IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that + * this option does not affect outgoing packet sizes, which can be controlled + * via IP_FRAG. + */ +#if !defined IP_REASSEMBLY || defined __DOXYGEN__ +#define IP_REASSEMBLY 1 +#endif + +/** + * IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note + * that this option does not affect incoming packet sizes, which can be + * controlled via IP_REASSEMBLY. + */ +#if !defined IP_FRAG || defined __DOXYGEN__ +#define IP_FRAG 1 +#endif + +#if !LWIP_IPV4 +/* disable IPv4 extensions when IPv4 is disabled */ +#undef IP_FORWARD +#define IP_FORWARD 0 +#undef IP_REASSEMBLY +#define IP_REASSEMBLY 0 +#undef IP_FRAG +#define IP_FRAG 0 +#endif /* !LWIP_IPV4 */ + +/** + * IP_OPTIONS_ALLOWED: Defines the behavior for IP options. + * IP_OPTIONS_ALLOWED==0: All packets with IP options are dropped. + * IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed). + */ +#if !defined IP_OPTIONS_ALLOWED || defined __DOXYGEN__ +#define IP_OPTIONS_ALLOWED 1 +#endif + +/** + * IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally) + * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived + * in this time, the whole packet is discarded. + */ +#if !defined IP_REASS_MAXAGE || defined __DOXYGEN__ +#define IP_REASS_MAXAGE 15 +#endif + +/** + * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled. + * Since the received pbufs are enqueued, be sure to configure + * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive + * packets even if the maximum amount of fragments is enqueued for reassembly! + * When IPv4 *and* IPv6 are enabled, this even changes to + * (PBUF_POOL_SIZE > 2 * IP_REASS_MAX_PBUFS)! + */ +#if !defined IP_REASS_MAX_PBUFS || defined __DOXYGEN__ +#define IP_REASS_MAX_PBUFS 10 +#endif + +/** + * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. + */ +#if !defined IP_DEFAULT_TTL || defined __DOXYGEN__ +#define IP_DEFAULT_TTL 255 +#endif + +/** + * IP_SOF_BROADCAST=1: Use the SOF_BROADCAST field to enable broadcast + * filter per pcb on udp and raw send operations. To enable broadcast filter + * on recv operations, you also have to set IP_SOF_BROADCAST_RECV=1. + */ +#if !defined IP_SOF_BROADCAST || defined __DOXYGEN__ +#define IP_SOF_BROADCAST 0 +#endif + +/** + * IP_SOF_BROADCAST_RECV (requires IP_SOF_BROADCAST=1) enable the broadcast + * filter on recv operations. + */ +#if !defined IP_SOF_BROADCAST_RECV || defined __DOXYGEN__ +#define IP_SOF_BROADCAST_RECV 0 +#endif + +/** + * IP_FORWARD_ALLOW_TX_ON_RX_NETIF==1: allow ip_forward() to send packets back + * out on the netif where it was received. This should only be used for + * wireless networks. + * ATTENTION: When this is 1, make sure your netif driver correctly marks incoming + * link-layer-broadcast/multicast packets as such using the corresponding pbuf flags! + */ +#if !defined IP_FORWARD_ALLOW_TX_ON_RX_NETIF || defined __DOXYGEN__ +#define IP_FORWARD_ALLOW_TX_ON_RX_NETIF 0 +#endif +/** + * @} + */ + +/* + ---------------------------------- + ---------- ICMP options ---------- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_icmp ICMP + * @ingroup lwip_opts_ipv4 + * @{ + */ +/** + * LWIP_ICMP==1: Enable ICMP module inside the IP stack. + * Be careful, disable that make your product non-compliant to RFC1122 + */ +#if !defined LWIP_ICMP || defined __DOXYGEN__ +#define LWIP_ICMP 1 +#endif + +/** + * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. + */ +#if !defined ICMP_TTL || defined __DOXYGEN__ +#define ICMP_TTL IP_DEFAULT_TTL +#endif + +/** + * LWIP_BROADCAST_PING==1: respond to broadcast pings (default is unicast only) + */ +#if !defined LWIP_BROADCAST_PING || defined __DOXYGEN__ +#define LWIP_BROADCAST_PING 0 +#endif + +/** + * LWIP_MULTICAST_PING==1: respond to multicast pings (default is unicast only) + */ +#if !defined LWIP_MULTICAST_PING || defined __DOXYGEN__ +#define LWIP_MULTICAST_PING 0 +#endif +/** + * @} + */ + +/* + --------------------------------- + ---------- RAW options ---------- + --------------------------------- +*/ +/** + * @defgroup lwip_opts_raw RAW + * @ingroup lwip_opts_callback + * @{ + */ +/** + * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. + */ +#if !defined LWIP_RAW || defined __DOXYGEN__ +#define LWIP_RAW 0 +#endif + +/** + * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. + */ +#if !defined RAW_TTL || defined __DOXYGEN__ +#define RAW_TTL IP_DEFAULT_TTL +#endif +/** + * @} + */ + +/* + ---------------------------------- + ---------- DHCP options ---------- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_dhcp DHCP + * @ingroup lwip_opts_ipv4 + * @{ + */ +/** + * LWIP_DHCP==1: Enable DHCP module. + */ +#if !defined LWIP_DHCP || defined __DOXYGEN__ +#define LWIP_DHCP 0 +#endif +#if !LWIP_IPV4 +/* disable DHCP when IPv4 is disabled */ +#undef LWIP_DHCP +#define LWIP_DHCP 0 +#endif /* !LWIP_IPV4 */ + +/** + * DHCP_DOES_ARP_CHECK==1: Do an ARP check on the offered address. + */ +#if !defined DHCP_DOES_ARP_CHECK || defined __DOXYGEN__ +#define DHCP_DOES_ARP_CHECK (LWIP_DHCP && LWIP_ARP) +#endif + +/** + * LWIP_DHCP_BOOTP_FILE==1: Store offered_si_addr and boot_file_name. + */ +#if !defined LWIP_DHCP_BOOTP_FILE || defined __DOXYGEN__ +#define LWIP_DHCP_BOOTP_FILE 0 +#endif + +/** + * LWIP_DHCP_GETS_NTP==1: Request NTP servers with discover/select. For each + * response packet, an callback is called, which has to be provided by the port: + * void dhcp_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs); +*/ +#if !defined LWIP_DHCP_GET_NTP_SRV || defined __DOXYGEN__ +#define LWIP_DHCP_GET_NTP_SRV 0 +#endif + +/** + * The maximum of NTP servers requested + */ +#if !defined LWIP_DHCP_MAX_NTP_SERVERS || defined __DOXYGEN__ +#define LWIP_DHCP_MAX_NTP_SERVERS 1 +#endif + +/** + * LWIP_DHCP_MAX_DNS_SERVERS > 0: Request DNS servers with discover/select. + * DNS servers received in the response are passed to DNS via @ref dns_setserver() + * (up to the maximum limit defined here). + */ +#if !defined LWIP_DHCP_MAX_DNS_SERVERS || defined __DOXYGEN__ +#define LWIP_DHCP_MAX_DNS_SERVERS DNS_MAX_SERVERS +#endif +/** + * @} + */ + +/* + ------------------------------------ + ---------- AUTOIP options ---------- + ------------------------------------ +*/ +/** + * @defgroup lwip_opts_autoip AUTOIP + * @ingroup lwip_opts_ipv4 + * @{ + */ +/** + * LWIP_AUTOIP==1: Enable AUTOIP module. + */ +#if !defined LWIP_AUTOIP || defined __DOXYGEN__ +#define LWIP_AUTOIP 0 +#endif +#if !LWIP_IPV4 +/* disable AUTOIP when IPv4 is disabled */ +#undef LWIP_AUTOIP +#define LWIP_AUTOIP 0 +#endif /* !LWIP_IPV4 */ + +/** + * LWIP_DHCP_AUTOIP_COOP==1: Allow DHCP and AUTOIP to be both enabled on + * the same interface at the same time. + */ +#if !defined LWIP_DHCP_AUTOIP_COOP || defined __DOXYGEN__ +#define LWIP_DHCP_AUTOIP_COOP 0 +#endif + +/** + * LWIP_DHCP_AUTOIP_COOP_TRIES: Set to the number of DHCP DISCOVER probes + * that should be sent before falling back on AUTOIP (the DHCP client keeps + * running in this case). This can be set as low as 1 to get an AutoIP address + * very quickly, but you should be prepared to handle a changing IP address + * when DHCP overrides AutoIP. + */ +#if !defined LWIP_DHCP_AUTOIP_COOP_TRIES || defined __DOXYGEN__ +#define LWIP_DHCP_AUTOIP_COOP_TRIES 9 +#endif +/** + * @} + */ + +/* + ---------------------------------- + ----- SNMP MIB2 support ----- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_mib2 SNMP MIB2 callbacks + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * LWIP_MIB2_CALLBACKS==1: Turn on SNMP MIB2 callbacks. + * Turn this on to get callbacks needed to implement MIB2. + * Usually MIB2_STATS should be enabled, too. + */ +#if !defined LWIP_MIB2_CALLBACKS || defined __DOXYGEN__ +#define LWIP_MIB2_CALLBACKS 0 +#endif +/** + * @} + */ + +/* + ---------------------------------- + -------- Multicast options ------- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_multicast Multicast + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * LWIP_MULTICAST_TX_OPTIONS==1: Enable multicast TX support like the socket options + * IP_MULTICAST_TTL/IP_MULTICAST_IF/IP_MULTICAST_LOOP, as well as (currently only) + * core support for the corresponding IPv6 options. + */ +#if !defined LWIP_MULTICAST_TX_OPTIONS || defined __DOXYGEN__ +#define LWIP_MULTICAST_TX_OPTIONS ((LWIP_IGMP || LWIP_IPV6_MLD) && (LWIP_UDP || LWIP_RAW)) +#endif +/** + * @} + */ + +/* + ---------------------------------- + ---------- IGMP options ---------- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_igmp IGMP + * @ingroup lwip_opts_ipv4 + * @{ + */ +/** + * LWIP_IGMP==1: Turn on IGMP module. + */ +#if !defined LWIP_IGMP || defined __DOXYGEN__ +#define LWIP_IGMP 0 +#endif +#if !LWIP_IPV4 +#undef LWIP_IGMP +#define LWIP_IGMP 0 +#endif +/** + * @} + */ + +/* + ---------------------------------- + ---------- DNS options ----------- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_dns DNS + * @ingroup lwip_opts_callback + * @{ + */ +/** + * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS + * transport. + */ +#if !defined LWIP_DNS || defined __DOXYGEN__ +#define LWIP_DNS 0 +#endif + +/** DNS maximum number of entries to maintain locally. */ +#if !defined DNS_TABLE_SIZE || defined __DOXYGEN__ +#define DNS_TABLE_SIZE 4 +#endif + +/** DNS maximum host name length supported in the name table. */ +#if !defined DNS_MAX_NAME_LENGTH || defined __DOXYGEN__ +#define DNS_MAX_NAME_LENGTH 256 +#endif + +/** The maximum of DNS servers + * The first server can be initialized automatically by defining + * DNS_SERVER_ADDRESS(ipaddr), where 'ipaddr' is an 'ip_addr_t*' + */ +#if !defined DNS_MAX_SERVERS || defined __DOXYGEN__ +#define DNS_MAX_SERVERS 2 +#endif + +/** DNS maximum number of retries when asking for a name, before "timeout". */ +#if !defined DNS_MAX_RETRIES || defined __DOXYGEN__ +#define DNS_MAX_RETRIES 4 +#endif + +/** DNS do a name checking between the query and the response. */ +#if !defined DNS_DOES_NAME_CHECK || defined __DOXYGEN__ +#define DNS_DOES_NAME_CHECK 1 +#endif + +/** LWIP_DNS_SECURE: controls the security level of the DNS implementation + * Use all DNS security features by default. + * This is overridable but should only be needed by very small targets + * or when using against non standard DNS servers. */ +#if !defined LWIP_DNS_SECURE || defined __DOXYGEN__ +#define LWIP_DNS_SECURE (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) +#endif + +/* A list of DNS security features follows */ +#define LWIP_DNS_SECURE_RAND_XID 1 +#define LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING 2 +#define LWIP_DNS_SECURE_RAND_SRC_PORT 4 + +/** DNS_LOCAL_HOSTLIST: Implements a local host-to-address list. If enabled, you have to define an initializer: + * \#define DNS_LOCAL_HOSTLIST_INIT {DNS_LOCAL_HOSTLIST_ELEM("host_ip4", IPADDR4_INIT_BYTES(1,2,3,4)), \ + * DNS_LOCAL_HOSTLIST_ELEM("host_ip6", IPADDR6_INIT_HOST(123, 234, 345, 456)} + * + * Instead, you can also use an external function: + * \#define DNS_LOOKUP_LOCAL_EXTERN(x) extern err_t my_lookup_function(const char *name, ip_addr_t *addr, u8_t dns_addrtype) + * that looks up the IP address and returns ERR_OK if found (LWIP_DNS_ADDRTYPE_xxx is passed in dns_addrtype). + */ +#if !defined DNS_LOCAL_HOSTLIST || defined __DOXYGEN__ +#define DNS_LOCAL_HOSTLIST 0 +#endif /* DNS_LOCAL_HOSTLIST */ + +/** If this is turned on, the local host-list can be dynamically changed + * at runtime. */ +#if !defined DNS_LOCAL_HOSTLIST_IS_DYNAMIC || defined __DOXYGEN__ +#define DNS_LOCAL_HOSTLIST_IS_DYNAMIC 0 +#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ + +/** Set this to 1 to enable querying ".local" names via mDNS + * using a One-Shot Multicast DNS Query */ +#if !defined LWIP_DNS_SUPPORT_MDNS_QUERIES || defined __DOXYGEN__ +#define LWIP_DNS_SUPPORT_MDNS_QUERIES 0 +#endif +/** + * @} + */ + +/* + --------------------------------- + ---------- UDP options ---------- + --------------------------------- +*/ +/** + * @defgroup lwip_opts_udp UDP + * @ingroup lwip_opts_callback + * @{ + */ +/** + * LWIP_UDP==1: Turn on UDP. + */ +#if !defined LWIP_UDP || defined __DOXYGEN__ +#define LWIP_UDP 1 +#endif + +/** + * LWIP_UDPLITE==1: Turn on UDP-Lite. (Requires LWIP_UDP) + */ +#if !defined LWIP_UDPLITE || defined __DOXYGEN__ +#define LWIP_UDPLITE 0 +#endif + +/** + * UDP_TTL: Default Time-To-Live value. + */ +#if !defined UDP_TTL || defined __DOXYGEN__ +#define UDP_TTL IP_DEFAULT_TTL +#endif + +/** + * LWIP_NETBUF_RECVINFO==1: append destination addr and port to every netbuf. + */ +#if !defined LWIP_NETBUF_RECVINFO || defined __DOXYGEN__ +#define LWIP_NETBUF_RECVINFO 0 +#endif +/** + * @} + */ + +/* + --------------------------------- + ---------- TCP options ---------- + --------------------------------- +*/ +/** + * @defgroup lwip_opts_tcp TCP + * @ingroup lwip_opts_callback + * @{ + */ +/** + * LWIP_TCP==1: Turn on TCP. + */ +#if !defined LWIP_TCP || defined __DOXYGEN__ +#define LWIP_TCP 1 +#endif + +/** + * TCP_TTL: Default Time-To-Live value. + */ +#if !defined TCP_TTL || defined __DOXYGEN__ +#define TCP_TTL IP_DEFAULT_TTL +#endif + +/** + * TCP_WND: The size of a TCP window. This must be at least + * (2 * TCP_MSS) for things to work well. + * ATTENTION: when using TCP_RCV_SCALE, TCP_WND is the total size + * with scaling applied. Maximum window value in the TCP header + * will be TCP_WND >> TCP_RCV_SCALE + */ +#if !defined TCP_WND || defined __DOXYGEN__ +#define TCP_WND (4 * TCP_MSS) +#endif + +/** + * TCP_MAXRTX: Maximum number of retransmissions of data segments. + */ +#if !defined TCP_MAXRTX || defined __DOXYGEN__ +#define TCP_MAXRTX 12 +#endif + +/** + * TCP_SYNMAXRTX: Maximum number of retransmissions of SYN segments. + */ +#if !defined TCP_SYNMAXRTX || defined __DOXYGEN__ +#define TCP_SYNMAXRTX 6 +#endif + +/** + * TCP_QUEUE_OOSEQ==1: TCP will queue segments that arrive out of order. + * Define to 0 if your device is low on memory. + */ +#if !defined TCP_QUEUE_OOSEQ || defined __DOXYGEN__ +#define TCP_QUEUE_OOSEQ LWIP_TCP +#endif + +/** + * LWIP_TCP_SACK_OUT==1: TCP will support sending selective acknowledgements (SACKs). + */ +#if !defined LWIP_TCP_SACK_OUT || defined __DOXYGEN__ +#define LWIP_TCP_SACK_OUT 0 +#endif + +/** + * LWIP_TCP_MAX_SACK_NUM: The maximum number of SACK values to include in TCP segments. + * Must be at least 1, but is only used if LWIP_TCP_SACK_OUT is enabled. + * NOTE: Even though we never send more than 3 or 4 SACK ranges in a single segment + * (depending on other options), setting this option to values greater than 4 is not pointless. + * This is basically the max number of SACK ranges we want to keep track of. + * As new data is delivered, some of the SACK ranges may be removed or merged. + * In that case some of those older SACK ranges may be used again. + * The amount of memory used to store SACK ranges is LWIP_TCP_MAX_SACK_NUM * 8 bytes for each TCP PCB. + */ +#if !defined LWIP_TCP_MAX_SACK_NUM || defined __DOXYGEN__ +#define LWIP_TCP_MAX_SACK_NUM 4 +#endif + +/** + * TCP_MSS: TCP Maximum segment size. (default is 536, a conservative default, + * you might want to increase this.) + * For the receive side, this MSS is advertised to the remote side + * when opening a connection. For the transmit size, this MSS sets + * an upper limit on the MSS advertised by the remote host. + */ +#if !defined TCP_MSS || defined __DOXYGEN__ +#define TCP_MSS 536 +#endif + +/** + * TCP_CALCULATE_EFF_SEND_MSS: "The maximum size of a segment that TCP really + * sends, the 'effective send MSS,' MUST be the smaller of the send MSS (which + * reflects the available reassembly buffer size at the remote host) and the + * largest size permitted by the IP layer" (RFC 1122) + * Setting this to 1 enables code that checks TCP_MSS against the MTU of the + * netif used for a connection and limits the MSS if it would be too big otherwise. + */ +#if !defined TCP_CALCULATE_EFF_SEND_MSS || defined __DOXYGEN__ +#define TCP_CALCULATE_EFF_SEND_MSS 1 +#endif + + +/** + * TCP_SND_BUF: TCP sender buffer space (bytes). + * To achieve good performance, this should be at least 2 * TCP_MSS. + */ +#if !defined TCP_SND_BUF || defined __DOXYGEN__ +#define TCP_SND_BUF (2 * TCP_MSS) +#endif + +/** + * TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least + * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. + */ +#if !defined TCP_SND_QUEUELEN || defined __DOXYGEN__ +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) +#endif + +/** + * TCP_SNDLOWAT: TCP writable space (bytes). This must be less than + * TCP_SND_BUF. It is the amount of space which must be available in the + * TCP snd_buf for select to return writable (combined with TCP_SNDQUEUELOWAT). + */ +#if !defined TCP_SNDLOWAT || defined __DOXYGEN__ +#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) +#endif + +/** + * TCP_SNDQUEUELOWAT: TCP writable bufs (pbuf count). This must be less + * than TCP_SND_QUEUELEN. If the number of pbufs queued on a pcb drops below + * this number, select returns writable (combined with TCP_SNDLOWAT). + */ +#if !defined TCP_SNDQUEUELOWAT || defined __DOXYGEN__ +#define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5) +#endif + +/** + * TCP_OOSEQ_MAX_BYTES: The default maximum number of bytes queued on ooseq per + * pcb if TCP_OOSEQ_BYTES_LIMIT is not defined. Default is 0 (no limit). + * Only valid for TCP_QUEUE_OOSEQ==1. + */ +#if !defined TCP_OOSEQ_MAX_BYTES || defined __DOXYGEN__ +#define TCP_OOSEQ_MAX_BYTES 0 +#endif + +/** + * TCP_OOSEQ_BYTES_LIMIT(pcb): Return the maximum number of bytes to be queued + * on ooseq per pcb, given the pcb. Only valid for TCP_QUEUE_OOSEQ==1 && + * TCP_OOSEQ_MAX_BYTES==1. + * Use this to override TCP_OOSEQ_MAX_BYTES to a dynamic value per pcb. + */ +#if !defined TCP_OOSEQ_BYTES_LIMIT +#if TCP_OOSEQ_MAX_BYTES +#define TCP_OOSEQ_BYTES_LIMIT(pcb) TCP_OOSEQ_MAX_BYTES +#elif defined __DOXYGEN__ +#define TCP_OOSEQ_BYTES_LIMIT(pcb) +#endif +#endif + +/** + * TCP_OOSEQ_MAX_PBUFS: The default maximum number of pbufs queued on ooseq per + * pcb if TCP_OOSEQ_BYTES_LIMIT is not defined. Default is 0 (no limit). + * Only valid for TCP_QUEUE_OOSEQ==1. + */ +#if !defined TCP_OOSEQ_MAX_PBUFS || defined __DOXYGEN__ +#define TCP_OOSEQ_MAX_PBUFS 0 +#endif + +/** + * TCP_OOSEQ_PBUFS_LIMIT(pcb): Return the maximum number of pbufs to be queued + * on ooseq per pcb, given the pcb. Only valid for TCP_QUEUE_OOSEQ==1 && + * TCP_OOSEQ_MAX_PBUFS==1. + * Use this to override TCP_OOSEQ_MAX_PBUFS to a dynamic value per pcb. + */ +#if !defined TCP_OOSEQ_PBUFS_LIMIT +#if TCP_OOSEQ_MAX_PBUFS +#define TCP_OOSEQ_PBUFS_LIMIT(pcb) TCP_OOSEQ_MAX_PBUFS +#elif defined __DOXYGEN__ +#define TCP_OOSEQ_PBUFS_LIMIT(pcb) +#endif +#endif + +/** + * TCP_LISTEN_BACKLOG: Enable the backlog option for tcp listen pcb. + */ +#if !defined TCP_LISTEN_BACKLOG || defined __DOXYGEN__ +#define TCP_LISTEN_BACKLOG 0 +#endif + +/** + * The maximum allowed backlog for TCP listen netconns. + * This backlog is used unless another is explicitly specified. + * 0xff is the maximum (u8_t). + */ +#if !defined TCP_DEFAULT_LISTEN_BACKLOG || defined __DOXYGEN__ +#define TCP_DEFAULT_LISTEN_BACKLOG 0xff +#endif + +/** + * TCP_OVERSIZE: The maximum number of bytes that tcp_write may + * allocate ahead of time in an attempt to create shorter pbuf chains + * for transmission. The meaningful range is 0 to TCP_MSS. Some + * suggested values are: + * + * 0: Disable oversized allocation. Each tcp_write() allocates a new + pbuf (old behaviour). + * 1: Allocate size-aligned pbufs with minimal excess. Use this if your + * scatter-gather DMA requires aligned fragments. + * 128: Limit the pbuf/memory overhead to 20%. + * TCP_MSS: Try to create unfragmented TCP packets. + * TCP_MSS/4: Try to create 4 fragments or less per TCP packet. + */ +#if !defined TCP_OVERSIZE || defined __DOXYGEN__ +#define TCP_OVERSIZE TCP_MSS +#endif + +/** + * LWIP_TCP_TIMESTAMPS==1: support the TCP timestamp option. + * The timestamp option is currently only used to help remote hosts, it is not + * really used locally. Therefore, it is only enabled when a TS option is + * received in the initial SYN packet from a remote host. + */ +#if !defined LWIP_TCP_TIMESTAMPS || defined __DOXYGEN__ +#define LWIP_TCP_TIMESTAMPS 0 +#endif + +/** + * TCP_WND_UPDATE_THRESHOLD: difference in window to trigger an + * explicit window update + */ +#if !defined TCP_WND_UPDATE_THRESHOLD || defined __DOXYGEN__ +#define TCP_WND_UPDATE_THRESHOLD LWIP_MIN((TCP_WND / 4), (TCP_MSS * 4)) +#endif + +/** + * LWIP_EVENT_API and LWIP_CALLBACK_API: Only one of these should be set to 1. + * LWIP_EVENT_API==1: The user defines lwip_tcp_event() to receive all + * events (accept, sent, etc) that happen in the system. + * LWIP_CALLBACK_API==1: The PCB callback function is called directly + * for the event. This is the default. + */ +#if !defined(LWIP_EVENT_API) && !defined(LWIP_CALLBACK_API) || defined __DOXYGEN__ +#define LWIP_EVENT_API 0 +#define LWIP_CALLBACK_API 1 +#else +#ifndef LWIP_EVENT_API +#define LWIP_EVENT_API 0 +#endif +#ifndef LWIP_CALLBACK_API +#define LWIP_CALLBACK_API 0 +#endif +#endif + +/** + * LWIP_WND_SCALE and TCP_RCV_SCALE: + * Set LWIP_WND_SCALE to 1 to enable window scaling. + * Set TCP_RCV_SCALE to the desired scaling factor (shift count in the + * range of [0..14]). + * When LWIP_WND_SCALE is enabled but TCP_RCV_SCALE is 0, we can use a large + * send window while having a small receive window only. + */ +#if !defined LWIP_WND_SCALE || defined __DOXYGEN__ +#define LWIP_WND_SCALE 0 +#define TCP_RCV_SCALE 0 +#endif + +/** + * LWIP_TCP_PCB_NUM_EXT_ARGS: + * When this is > 0, every tcp pcb (including listen pcb) includes a number of + * additional argument entries in an array (see tcp_ext_arg_alloc_id) + */ +#if !defined LWIP_TCP_PCB_NUM_EXT_ARGS || defined __DOXYGEN__ +#define LWIP_TCP_PCB_NUM_EXT_ARGS 0 +#endif + +/** LWIP_ALTCP==1: enable the altcp API. + * altcp is an abstraction layer that prevents applications linking against the + * tcp.h functions but provides the same functionality. It is used to e.g. add + * SSL/TLS or proxy-connect support to an application written for the tcp callback + * API without that application knowing the protocol details. + * + * With LWIP_ALTCP==0, applications written against the altcp API can still be + * compiled but are directly linked against the tcp.h callback API and then + * cannot use layered protocols. + * + * See @ref altcp_api + */ +#if !defined LWIP_ALTCP || defined __DOXYGEN__ +#define LWIP_ALTCP 0 +#endif + +/** LWIP_ALTCP_TLS==1: enable TLS support for altcp API. + * This needs a port of the functions in altcp_tls.h to a TLS library. + * A port to ARM mbedtls is provided with lwIP, see apps/altcp_tls/ directory + * and LWIP_ALTCP_TLS_MBEDTLS option. + */ +#if !defined LWIP_ALTCP_TLS || defined __DOXYGEN__ +#define LWIP_ALTCP_TLS 0 +#endif + +/** + * @} + */ + +/* + ---------------------------------- + ---------- Pbuf options ---------- + ---------------------------------- +*/ +/** + * @defgroup lwip_opts_pbuf PBUF + * @ingroup lwip_opts + * @{ + */ +/** + * PBUF_LINK_HLEN: the number of bytes that should be allocated for a + * link level header. The default is 14, the standard value for + * Ethernet. + */ +#if !defined PBUF_LINK_HLEN || defined __DOXYGEN__ +#if defined LWIP_HOOK_VLAN_SET && !defined __DOXYGEN__ +#define PBUF_LINK_HLEN (18 + ETH_PAD_SIZE) +#else /* LWIP_HOOK_VLAN_SET */ +#define PBUF_LINK_HLEN (14 + ETH_PAD_SIZE) +#endif /* LWIP_HOOK_VLAN_SET */ +#endif + +/** + * PBUF_LINK_ENCAPSULATION_HLEN: the number of bytes that should be allocated + * for an additional encapsulation header before ethernet headers (e.g. 802.11) + */ +#if !defined PBUF_LINK_ENCAPSULATION_HLEN || defined __DOXYGEN__ +#define PBUF_LINK_ENCAPSULATION_HLEN 0 +#endif + +/** + * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is + * designed to accommodate single full size TCP frame in one pbuf, including + * TCP_MSS, IP header, and link header. + */ +#if !defined PBUF_POOL_BUFSIZE || defined __DOXYGEN__ +#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+PBUF_IP_HLEN+PBUF_TRANSPORT_HLEN+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN) +#endif + +/** + * LWIP_PBUF_REF_T: Refcount type in pbuf. + * Default width of u8_t can be increased if 255 refs are not enough for you. + */ +#if !defined LWIP_PBUF_REF_T || defined __DOXYGEN__ +#define LWIP_PBUF_REF_T u8_t +#endif + +/** + * LWIP_PBUF_CUSTOM_DATA: Store private data on pbufs (e.g. timestamps) + * This extends struct pbuf so user can store custom data on every pbuf. + */ +#if !defined LWIP_PBUF_CUSTOM_DATA || defined __DOXYGEN__ +#define LWIP_PBUF_CUSTOM_DATA +#endif +/** + * @} + */ + +/* + ------------------------------------------------ + ---------- Network Interfaces options ---------- + ------------------------------------------------ +*/ +/** + * @defgroup lwip_opts_netif NETIF + * @ingroup lwip_opts + * @{ + */ +/** + * LWIP_SINGLE_NETIF==1: use a single netif only. This is the common case for + * small real-life targets. Some code like routing etc. can be left out. + */ +#if !defined LWIP_SINGLE_NETIF || defined __DOXYGEN__ +#define LWIP_SINGLE_NETIF 0 +#endif + +/** + * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname + * field. + */ +#if !defined LWIP_NETIF_HOSTNAME || defined __DOXYGEN__ +#define LWIP_NETIF_HOSTNAME 0 +#endif + +/** + * LWIP_NETIF_API==1: Support netif api (in netifapi.c) + */ +#if !defined LWIP_NETIF_API || defined __DOXYGEN__ +#define LWIP_NETIF_API 0 +#endif + +/** + * LWIP_NETIF_STATUS_CALLBACK==1: Support a callback function whenever an interface + * changes its up/down status (i.e., due to DHCP IP acquisition) + */ +#if !defined LWIP_NETIF_STATUS_CALLBACK || defined __DOXYGEN__ +#define LWIP_NETIF_STATUS_CALLBACK 0 +#endif + +/** + * LWIP_NETIF_EXT_STATUS_CALLBACK==1: Support an extended callback function + * for several netif related event that supports multiple subscribers. + * @see netif_ext_status_callback + */ +#if !defined LWIP_NETIF_EXT_STATUS_CALLBACK || defined __DOXYGEN__ +#define LWIP_NETIF_EXT_STATUS_CALLBACK 0 +#endif + +/** + * LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface + * whenever the link changes (i.e., link down) + */ +#if !defined LWIP_NETIF_LINK_CALLBACK || defined __DOXYGEN__ +#define LWIP_NETIF_LINK_CALLBACK 0 +#endif + +/** + * LWIP_NETIF_REMOVE_CALLBACK==1: Support a callback function that is called + * when a netif has been removed + */ +#if !defined LWIP_NETIF_REMOVE_CALLBACK || defined __DOXYGEN__ +#define LWIP_NETIF_REMOVE_CALLBACK 0 +#endif + +/** + * LWIP_NETIF_HWADDRHINT==1: Cache link-layer-address hints (e.g. table + * indices) in struct netif. TCP and UDP can make use of this to prevent + * scanning the ARP table for every sent packet. While this is faster for big + * ARP tables or many concurrent connections, it might be counterproductive + * if you have a tiny ARP table or if there never are concurrent connections. + */ +#if !defined LWIP_NETIF_HWADDRHINT || defined __DOXYGEN__ +#define LWIP_NETIF_HWADDRHINT 0 +#endif + +/** + * LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP *tries* to put all data + * to be sent into one single pbuf. This is for compatibility with DMA-enabled + * MACs that do not support scatter-gather. + * Beware that this might involve CPU-memcpy before transmitting that would not + * be needed without this flag! Use this only if you need to! + * + * ATTENTION: a driver should *NOT* rely on getting single pbufs but check TX + * pbufs for being in one piece. If not, @ref pbuf_clone can be used to get + * a single pbuf: + * if (p->next != NULL) { + * struct pbuf *q = pbuf_clone(PBUF_RAW, PBUF_RAM, p); + * if (q == NULL) { + * return ERR_MEM; + * } + * p = q; ATTENTION: do NOT free the old 'p' as the ref belongs to the caller! + * } + */ +#if !defined LWIP_NETIF_TX_SINGLE_PBUF || defined __DOXYGEN__ +#define LWIP_NETIF_TX_SINGLE_PBUF 0 +#endif /* LWIP_NETIF_TX_SINGLE_PBUF */ + +/** + * LWIP_NUM_NETIF_CLIENT_DATA: Number of clients that may store + * data in client_data member array of struct netif (max. 256). + */ +#if !defined LWIP_NUM_NETIF_CLIENT_DATA || defined __DOXYGEN__ +#define LWIP_NUM_NETIF_CLIENT_DATA 0 +#endif +/** + * @} + */ + +/* + ------------------------------------ + ---------- LOOPIF options ---------- + ------------------------------------ +*/ +/** + * @defgroup lwip_opts_loop Loopback interface + * @ingroup lwip_opts_netif + * @{ + */ +/** + * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1). + * This is only needed when no real netifs are available. If at least one other + * netif is available, loopback traffic uses this netif. + */ +#if !defined LWIP_HAVE_LOOPIF || defined __DOXYGEN__ +#define LWIP_HAVE_LOOPIF (LWIP_NETIF_LOOPBACK && !LWIP_SINGLE_NETIF) +#endif + +/** + * LWIP_LOOPIF_MULTICAST==1: Support multicast/IGMP on loop interface (127.0.0.1). + */ +#if !defined LWIP_LOOPIF_MULTICAST || defined __DOXYGEN__ +#define LWIP_LOOPIF_MULTICAST 0 +#endif + +/** + * LWIP_NETIF_LOOPBACK==1: Support sending packets with a destination IP + * address equal to the netif IP address, looping them back up the stack. + */ +#if !defined LWIP_NETIF_LOOPBACK || defined __DOXYGEN__ +#define LWIP_NETIF_LOOPBACK 0 +#endif + +/** + * LWIP_LOOPBACK_MAX_PBUFS: Maximum number of pbufs on queue for loopback + * sending for each netif (0 = disabled) + */ +#if !defined LWIP_LOOPBACK_MAX_PBUFS || defined __DOXYGEN__ +#define LWIP_LOOPBACK_MAX_PBUFS 0 +#endif + +/** + * LWIP_NETIF_LOOPBACK_MULTITHREADING: Indicates whether threading is enabled in + * the system, as netifs must change how they behave depending on this setting + * for the LWIP_NETIF_LOOPBACK option to work. + * Setting this is needed to avoid reentering non-reentrant functions like + * tcp_input(). + * LWIP_NETIF_LOOPBACK_MULTITHREADING==1: Indicates that the user is using a + * multithreaded environment like tcpip.c. In this case, netif->input() + * is called directly. + * LWIP_NETIF_LOOPBACK_MULTITHREADING==0: Indicates a polling (or NO_SYS) setup. + * The packets are put on a list and netif_poll() must be called in + * the main application loop. + */ +#if !defined LWIP_NETIF_LOOPBACK_MULTITHREADING || defined __DOXYGEN__ +#define LWIP_NETIF_LOOPBACK_MULTITHREADING (!NO_SYS) +#endif +/** + * @} + */ + +/* + ------------------------------------ + ---------- Thread options ---------- + ------------------------------------ +*/ +/** + * @defgroup lwip_opts_thread Threading + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * TCPIP_THREAD_NAME: The name assigned to the main tcpip thread. + */ +#if !defined TCPIP_THREAD_NAME || defined __DOXYGEN__ +#define TCPIP_THREAD_NAME "tcpip_thread" +#endif + +/** + * TCPIP_THREAD_STACKSIZE: The stack size used by the main tcpip thread. + * The stack size value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#if !defined TCPIP_THREAD_STACKSIZE || defined __DOXYGEN__ +#define TCPIP_THREAD_STACKSIZE 0 +#endif + +/** + * TCPIP_THREAD_PRIO: The priority assigned to the main tcpip thread. + * The priority value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#if !defined TCPIP_THREAD_PRIO || defined __DOXYGEN__ +#define TCPIP_THREAD_PRIO 1 +#endif + +/** + * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages + * The queue size value itself is platform-dependent, but is passed to + * sys_mbox_new() when tcpip_init is called. + */ +#if !defined TCPIP_MBOX_SIZE || defined __DOXYGEN__ +#define TCPIP_MBOX_SIZE 0 +#endif + +/** + * Define this to something that triggers a watchdog. This is called from + * tcpip_thread after processing a message. + */ +#if !defined LWIP_TCPIP_THREAD_ALIVE || defined __DOXYGEN__ +#define LWIP_TCPIP_THREAD_ALIVE() +#endif + +/** + * SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread. + */ +#if !defined SLIPIF_THREAD_NAME || defined __DOXYGEN__ +#define SLIPIF_THREAD_NAME "slipif_loop" +#endif + +/** + * SLIP_THREAD_STACKSIZE: The stack size used by the slipif_loop thread. + * The stack size value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#if !defined SLIPIF_THREAD_STACKSIZE || defined __DOXYGEN__ +#define SLIPIF_THREAD_STACKSIZE 0 +#endif + +/** + * SLIPIF_THREAD_PRIO: The priority assigned to the slipif_loop thread. + * The priority value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#if !defined SLIPIF_THREAD_PRIO || defined __DOXYGEN__ +#define SLIPIF_THREAD_PRIO 1 +#endif + +/** + * DEFAULT_THREAD_NAME: The name assigned to any other lwIP thread. + */ +#if !defined DEFAULT_THREAD_NAME || defined __DOXYGEN__ +#define DEFAULT_THREAD_NAME "lwIP" +#endif + +/** + * DEFAULT_THREAD_STACKSIZE: The stack size used by any other lwIP thread. + * The stack size value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#if !defined DEFAULT_THREAD_STACKSIZE || defined __DOXYGEN__ +#define DEFAULT_THREAD_STACKSIZE 0 +#endif + +/** + * DEFAULT_THREAD_PRIO: The priority assigned to any other lwIP thread. + * The priority value itself is platform-dependent, but is passed to + * sys_thread_new() when the thread is created. + */ +#if !defined DEFAULT_THREAD_PRIO || defined __DOXYGEN__ +#define DEFAULT_THREAD_PRIO 1 +#endif + +/** + * DEFAULT_RAW_RECVMBOX_SIZE: The mailbox size for the incoming packets on a + * NETCONN_RAW. The queue size value itself is platform-dependent, but is passed + * to sys_mbox_new() when the recvmbox is created. + */ +#if !defined DEFAULT_RAW_RECVMBOX_SIZE || defined __DOXYGEN__ +#define DEFAULT_RAW_RECVMBOX_SIZE 0 +#endif + +/** + * DEFAULT_UDP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a + * NETCONN_UDP. The queue size value itself is platform-dependent, but is passed + * to sys_mbox_new() when the recvmbox is created. + */ +#if !defined DEFAULT_UDP_RECVMBOX_SIZE || defined __DOXYGEN__ +#define DEFAULT_UDP_RECVMBOX_SIZE 0 +#endif + +/** + * DEFAULT_TCP_RECVMBOX_SIZE: The mailbox size for the incoming packets on a + * NETCONN_TCP. The queue size value itself is platform-dependent, but is passed + * to sys_mbox_new() when the recvmbox is created. + */ +#if !defined DEFAULT_TCP_RECVMBOX_SIZE || defined __DOXYGEN__ +#define DEFAULT_TCP_RECVMBOX_SIZE 0 +#endif + +/** + * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections. + * The queue size value itself is platform-dependent, but is passed to + * sys_mbox_new() when the acceptmbox is created. + */ +#if !defined DEFAULT_ACCEPTMBOX_SIZE || defined __DOXYGEN__ +#define DEFAULT_ACCEPTMBOX_SIZE 0 +#endif +/** + * @} + */ + +/* + ---------------------------------------------- + ---------- Sequential layer options ---------- + ---------------------------------------------- +*/ +/** + * @defgroup lwip_opts_netconn Netconn + * @ingroup lwip_opts_threadsafe_apis + * @{ + */ +/** + * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) + */ +#if !defined LWIP_NETCONN || defined __DOXYGEN__ +#define LWIP_NETCONN 1 +#endif + +/** LWIP_TCPIP_TIMEOUT==1: Enable tcpip_timeout/tcpip_untimeout to create + * timers running in tcpip_thread from another thread. + */ +#if !defined LWIP_TCPIP_TIMEOUT || defined __DOXYGEN__ +#define LWIP_TCPIP_TIMEOUT 0 +#endif + +/** LWIP_NETCONN_SEM_PER_THREAD==1: Use one (thread-local) semaphore per + * thread calling socket/netconn functions instead of allocating one + * semaphore per netconn (and per select etc.) + * ATTENTION: a thread-local semaphore for API calls is needed: + * - LWIP_NETCONN_THREAD_SEM_GET() returning a sys_sem_t* + * - LWIP_NETCONN_THREAD_SEM_ALLOC() creating the semaphore + * - LWIP_NETCONN_THREAD_SEM_FREE() freeing the semaphore + * The latter 2 can be invoked up by calling netconn_thread_init()/netconn_thread_cleanup(). + * Ports may call these for threads created with sys_thread_new(). + */ +#if !defined LWIP_NETCONN_SEM_PER_THREAD || defined __DOXYGEN__ +#define LWIP_NETCONN_SEM_PER_THREAD 0 +#endif + +/** LWIP_NETCONN_FULLDUPLEX==1: Enable code that allows reading from one thread, + * writing from a 2nd thread and closing from a 3rd thread at the same time. + * LWIP_NETCONN_SEM_PER_THREAD==1 is required to use one socket/netconn from + * multiple threads at once! + */ +#if !defined LWIP_NETCONN_FULLDUPLEX || defined __DOXYGEN__ +#define LWIP_NETCONN_FULLDUPLEX 0 +#endif +/** + * @} + */ + +/* + ------------------------------------ + ---------- Socket options ---------- + ------------------------------------ +*/ +/** + * @defgroup lwip_opts_socket Sockets + * @ingroup lwip_opts_threadsafe_apis + * @{ + */ +/** + * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) + */ +#if !defined LWIP_SOCKET || defined __DOXYGEN__ +#define LWIP_SOCKET 1 +#endif + +/** + * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names through defines. + * LWIP_COMPAT_SOCKETS==2: Same as ==1 but correctly named functions are created. + * While this helps code completion, it might conflict with existing libraries. + * (only used if you use sockets.c) + */ +#if !defined LWIP_COMPAT_SOCKETS || defined __DOXYGEN__ +#define LWIP_COMPAT_SOCKETS 1 +#endif + +/** + * LWIP_POSIX_SOCKETS_IO_NAMES==1: Enable POSIX-style sockets functions names. + * Disable this option if you use a POSIX operating system that uses the same + * names (read, write & close). (only used if you use sockets.c) + */ +#if !defined LWIP_POSIX_SOCKETS_IO_NAMES || defined __DOXYGEN__ +#define LWIP_POSIX_SOCKETS_IO_NAMES 1 +#endif + +/** + * LWIP_SOCKET_OFFSET==n: Increases the file descriptor number created by LwIP with n. + * This can be useful when there are multiple APIs which create file descriptors. + * When they all start with a different offset and you won't make them overlap you can + * re implement read/write/close/ioctl/fnctl to send the requested action to the right + * library (sharing select will need more work though). + */ +#if !defined LWIP_SOCKET_OFFSET || defined __DOXYGEN__ +#define LWIP_SOCKET_OFFSET 0 +#endif + +/** + * LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT + * options processing. Note that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set + * in seconds. (does not require sockets.c, and will affect tcp.c) + */ +#if !defined LWIP_TCP_KEEPALIVE || defined __DOXYGEN__ +#define LWIP_TCP_KEEPALIVE 0 +#endif + +/** + * LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and + * SO_SNDTIMEO processing. + */ +#if !defined LWIP_SO_SNDTIMEO || defined __DOXYGEN__ +#define LWIP_SO_SNDTIMEO 0 +#endif + +/** + * LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and + * SO_RCVTIMEO processing. + */ +#if !defined LWIP_SO_RCVTIMEO || defined __DOXYGEN__ +#define LWIP_SO_RCVTIMEO 0 +#endif + +/** + * LWIP_SO_SNDRCVTIMEO_NONSTANDARD==1: SO_RCVTIMEO/SO_SNDTIMEO take an int + * (milliseconds, much like winsock does) instead of a struct timeval (default). + */ +#if !defined LWIP_SO_SNDRCVTIMEO_NONSTANDARD || defined __DOXYGEN__ +#define LWIP_SO_SNDRCVTIMEO_NONSTANDARD 0 +#endif + +/** + * LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing. + */ +#if !defined LWIP_SO_RCVBUF || defined __DOXYGEN__ +#define LWIP_SO_RCVBUF 0 +#endif + +/** + * LWIP_SO_LINGER==1: Enable SO_LINGER processing. + */ +#if !defined LWIP_SO_LINGER || defined __DOXYGEN__ +#define LWIP_SO_LINGER 0 +#endif + +/** + * If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize. + */ +#if !defined RECV_BUFSIZE_DEFAULT || defined __DOXYGEN__ +#define RECV_BUFSIZE_DEFAULT INT_MAX +#endif + +/** + * By default, TCP socket/netconn close waits 20 seconds max to send the FIN + */ +#if !defined LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT || defined __DOXYGEN__ +#define LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT 20000 +#endif + +/** + * SO_REUSE==1: Enable SO_REUSEADDR option. + */ +#if !defined SO_REUSE || defined __DOXYGEN__ +#define SO_REUSE 0 +#endif + +/** + * SO_REUSE_RXTOALL==1: Pass a copy of incoming broadcast/multicast packets + * to all local matches if SO_REUSEADDR is turned on. + * WARNING: Adds a memcpy for every packet if passing to more than one pcb! + */ +#if !defined SO_REUSE_RXTOALL || defined __DOXYGEN__ +#define SO_REUSE_RXTOALL 0 +#endif + +/** + * LWIP_FIONREAD_LINUXMODE==0 (default): ioctl/FIONREAD returns the amount of + * pending data in the network buffer. This is the way windows does it. It's + * the default for lwIP since it is smaller. + * LWIP_FIONREAD_LINUXMODE==1: ioctl/FIONREAD returns the size of the next + * pending datagram in bytes. This is the way linux does it. This code is only + * here for compatibility. + */ +#if !defined LWIP_FIONREAD_LINUXMODE || defined __DOXYGEN__ +#define LWIP_FIONREAD_LINUXMODE 0 +#endif + +/** + * LWIP_SOCKET_SELECT==1 (default): enable select() for sockets (uses a netconn + * callback to keep track of events). + * This saves RAM (counters per socket) and code (netconn event callback), which + * should improve performance a bit). + */ +#if !defined LWIP_SOCKET_SELECT || defined __DOXYGEN__ +#define LWIP_SOCKET_SELECT 1 +#endif + +/** + * LWIP_SOCKET_POLL==1 (default): enable poll() for sockets (including + * struct pollfd, nfds_t, and constants) + */ +#if !defined LWIP_SOCKET_POLL || defined __DOXYGEN__ +#define LWIP_SOCKET_POLL 1 +#endif +/** + * @} + */ + +/* + ---------------------------------------- + ---------- Statistics options ---------- + ---------------------------------------- +*/ +/** + * @defgroup lwip_opts_stats Statistics + * @ingroup lwip_opts_debug + * @{ + */ +/** + * LWIP_STATS==1: Enable statistics collection in lwip_stats. + */ +#if !defined LWIP_STATS || defined __DOXYGEN__ +#define LWIP_STATS 1 +#endif + +#if LWIP_STATS + +/** + * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions. + */ +#if !defined LWIP_STATS_DISPLAY || defined __DOXYGEN__ +#define LWIP_STATS_DISPLAY 0 +#endif + +/** + * LINK_STATS==1: Enable link stats. + */ +#if !defined LINK_STATS || defined __DOXYGEN__ +#define LINK_STATS 1 +#endif + +/** + * ETHARP_STATS==1: Enable etharp stats. + */ +#if !defined ETHARP_STATS || defined __DOXYGEN__ +#define ETHARP_STATS (LWIP_ARP) +#endif + +/** + * IP_STATS==1: Enable IP stats. + */ +#if !defined IP_STATS || defined __DOXYGEN__ +#define IP_STATS 1 +#endif + +/** + * IPFRAG_STATS==1: Enable IP fragmentation stats. Default is + * on if using either frag or reass. + */ +#if !defined IPFRAG_STATS || defined __DOXYGEN__ +#define IPFRAG_STATS (IP_REASSEMBLY || IP_FRAG) +#endif + +/** + * ICMP_STATS==1: Enable ICMP stats. + */ +#if !defined ICMP_STATS || defined __DOXYGEN__ +#define ICMP_STATS 1 +#endif + +/** + * IGMP_STATS==1: Enable IGMP stats. + */ +#if !defined IGMP_STATS || defined __DOXYGEN__ +#define IGMP_STATS (LWIP_IGMP) +#endif + +/** + * UDP_STATS==1: Enable UDP stats. Default is on if + * UDP enabled, otherwise off. + */ +#if !defined UDP_STATS || defined __DOXYGEN__ +#define UDP_STATS (LWIP_UDP) +#endif + +/** + * TCP_STATS==1: Enable TCP stats. Default is on if TCP + * enabled, otherwise off. + */ +#if !defined TCP_STATS || defined __DOXYGEN__ +#define TCP_STATS (LWIP_TCP) +#endif + +/** + * MEM_STATS==1: Enable mem.c stats. + */ +#if !defined MEM_STATS || defined __DOXYGEN__ +#define MEM_STATS ((MEM_LIBC_MALLOC == 0) && (MEM_USE_POOLS == 0)) +#endif + +/** + * MEMP_STATS==1: Enable memp.c pool stats. + */ +#if !defined MEMP_STATS || defined __DOXYGEN__ +#define MEMP_STATS (MEMP_MEM_MALLOC == 0) +#endif + +/** + * SYS_STATS==1: Enable system stats (sem and mbox counts, etc). + */ +#if !defined SYS_STATS || defined __DOXYGEN__ +#define SYS_STATS (NO_SYS == 0) +#endif + +/** + * IP6_STATS==1: Enable IPv6 stats. + */ +#if !defined IP6_STATS || defined __DOXYGEN__ +#define IP6_STATS (LWIP_IPV6) +#endif + +/** + * ICMP6_STATS==1: Enable ICMP for IPv6 stats. + */ +#if !defined ICMP6_STATS || defined __DOXYGEN__ +#define ICMP6_STATS (LWIP_IPV6 && LWIP_ICMP6) +#endif + +/** + * IP6_FRAG_STATS==1: Enable IPv6 fragmentation stats. + */ +#if !defined IP6_FRAG_STATS || defined __DOXYGEN__ +#define IP6_FRAG_STATS (LWIP_IPV6 && (LWIP_IPV6_FRAG || LWIP_IPV6_REASS)) +#endif + +/** + * MLD6_STATS==1: Enable MLD for IPv6 stats. + */ +#if !defined MLD6_STATS || defined __DOXYGEN__ +#define MLD6_STATS (LWIP_IPV6 && LWIP_IPV6_MLD) +#endif + +/** + * ND6_STATS==1: Enable Neighbor discovery for IPv6 stats. + */ +#if !defined ND6_STATS || defined __DOXYGEN__ +#define ND6_STATS (LWIP_IPV6) +#endif + +/** + * MIB2_STATS==1: Stats for SNMP MIB2. + */ +#if !defined MIB2_STATS || defined __DOXYGEN__ +#define MIB2_STATS 0 +#endif + +#else + +#define LINK_STATS 0 +#define ETHARP_STATS 0 +#define IP_STATS 0 +#define IPFRAG_STATS 0 +#define ICMP_STATS 0 +#define IGMP_STATS 0 +#define UDP_STATS 0 +#define TCP_STATS 0 +#define MEM_STATS 0 +#define MEMP_STATS 0 +#define SYS_STATS 0 +#define LWIP_STATS_DISPLAY 0 +#define IP6_STATS 0 +#define ICMP6_STATS 0 +#define IP6_FRAG_STATS 0 +#define MLD6_STATS 0 +#define ND6_STATS 0 +#define MIB2_STATS 0 + +#endif /* LWIP_STATS */ +/** + * @} + */ + +/* + -------------------------------------- + ---------- Checksum options ---------- + -------------------------------------- +*/ +/** + * @defgroup lwip_opts_checksum Checksum + * @ingroup lwip_opts_infrastructure + * @{ + */ +/** + * LWIP_CHECKSUM_CTRL_PER_NETIF==1: Checksum generation/check can be enabled/disabled + * per netif. + * ATTENTION: if enabled, the CHECKSUM_GEN_* and CHECKSUM_CHECK_* defines must be enabled! + */ +#if !defined LWIP_CHECKSUM_CTRL_PER_NETIF || defined __DOXYGEN__ +#define LWIP_CHECKSUM_CTRL_PER_NETIF 0 +#endif + +/** + * CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets. + */ +#if !defined CHECKSUM_GEN_IP || defined __DOXYGEN__ +#define CHECKSUM_GEN_IP 1 +#endif + +/** + * CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets. + */ +#if !defined CHECKSUM_GEN_UDP || defined __DOXYGEN__ +#define CHECKSUM_GEN_UDP 1 +#endif + +/** + * CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets. + */ +#if !defined CHECKSUM_GEN_TCP || defined __DOXYGEN__ +#define CHECKSUM_GEN_TCP 1 +#endif + +/** + * CHECKSUM_GEN_ICMP==1: Generate checksums in software for outgoing ICMP packets. + */ +#if !defined CHECKSUM_GEN_ICMP || defined __DOXYGEN__ +#define CHECKSUM_GEN_ICMP 1 +#endif + +/** + * CHECKSUM_GEN_ICMP6==1: Generate checksums in software for outgoing ICMP6 packets. + */ +#if !defined CHECKSUM_GEN_ICMP6 || defined __DOXYGEN__ +#define CHECKSUM_GEN_ICMP6 1 +#endif + +/** + * CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets. + */ +#if !defined CHECKSUM_CHECK_IP || defined __DOXYGEN__ +#define CHECKSUM_CHECK_IP 1 +#endif + +/** + * CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets. + */ +#if !defined CHECKSUM_CHECK_UDP || defined __DOXYGEN__ +#define CHECKSUM_CHECK_UDP 1 +#endif + +/** + * CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets. + */ +#if !defined CHECKSUM_CHECK_TCP || defined __DOXYGEN__ +#define CHECKSUM_CHECK_TCP 1 +#endif + +/** + * CHECKSUM_CHECK_ICMP==1: Check checksums in software for incoming ICMP packets. + */ +#if !defined CHECKSUM_CHECK_ICMP || defined __DOXYGEN__ +#define CHECKSUM_CHECK_ICMP 1 +#endif + +/** + * CHECKSUM_CHECK_ICMP6==1: Check checksums in software for incoming ICMPv6 packets + */ +#if !defined CHECKSUM_CHECK_ICMP6 || defined __DOXYGEN__ +#define CHECKSUM_CHECK_ICMP6 1 +#endif + +/** + * LWIP_CHECKSUM_ON_COPY==1: Calculate checksum when copying data from + * application buffers to pbufs. + */ +#if !defined LWIP_CHECKSUM_ON_COPY || defined __DOXYGEN__ +#define LWIP_CHECKSUM_ON_COPY 0 +#endif +/** + * @} + */ + +/* + --------------------------------------- + ---------- IPv6 options --------------- + --------------------------------------- +*/ +/** + * @defgroup lwip_opts_ipv6 IPv6 + * @ingroup lwip_opts + * @{ + */ +/** + * LWIP_IPV6==1: Enable IPv6 + */ +#if !defined LWIP_IPV6 || defined __DOXYGEN__ +#define LWIP_IPV6 0 +#endif + +/** + * IPV6_REASS_MAXAGE: Maximum time (in multiples of IP6_REASS_TMR_INTERVAL - so seconds, normally) + * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived + * in this time, the whole packet is discarded. + */ +#if !defined IPV6_REASS_MAXAGE || defined __DOXYGEN__ +#define IPV6_REASS_MAXAGE 60 +#endif + +/** + * LWIP_IPV6_SCOPES==1: Enable support for IPv6 address scopes, ensuring that + * e.g. link-local addresses are really treated as link-local. Disable this + * setting only for single-interface configurations. + * All addresses that have a scope according to the default policy (link-local + * unicast addresses, interface-local and link-local multicast addresses) should + * now have a zone set on them before being passed to the core API, although + * lwIP will currently attempt to select a zone on the caller's behalf when + * necessary. Applications that directly assign IPv6 addresses to interfaces + * (which is NOT recommended) must now ensure that link-local addresses carry + * the netif's zone. See the new ip6_zone.h header file for more information and + * relevant macros. For now it is still possible to turn off scopes support + * through the new LWIP_IPV6_SCOPES option. When upgrading an implementation that + * uses the core API directly, it is highly recommended to enable + * LWIP_IPV6_SCOPES_DEBUG at least for a while, to ensure e.g. proper address + * initialization. + */ +#if !defined LWIP_IPV6_SCOPES || defined __DOXYGEN__ +#define LWIP_IPV6_SCOPES (LWIP_IPV6 && !LWIP_SINGLE_NETIF) +#endif + +/** + * LWIP_IPV6_SCOPES_DEBUG==1: Perform run-time checks to verify that addresses + * are properly zoned (see ip6_zone.h on what that means) where it matters. + * Enabling this setting is highly recommended when upgrading from an existing + * installation that is not yet scope-aware; otherwise it may be too expensive. + */ +#if !defined LWIP_IPV6_SCOPES_DEBUG || defined __DOXYGEN__ +#define LWIP_IPV6_SCOPES_DEBUG 0 +#endif + +/** + * LWIP_IPV6_NUM_ADDRESSES: Number of IPv6 addresses per netif. + */ +#if !defined LWIP_IPV6_NUM_ADDRESSES || defined __DOXYGEN__ +#define LWIP_IPV6_NUM_ADDRESSES 3 +#endif + +/** + * LWIP_IPV6_FORWARD==1: Forward IPv6 packets across netifs + */ +#if !defined LWIP_IPV6_FORWARD || defined __DOXYGEN__ +#define LWIP_IPV6_FORWARD 0 +#endif + +/** + * LWIP_IPV6_FRAG==1: Fragment outgoing IPv6 packets that are too big. + */ +#if !defined LWIP_IPV6_FRAG || defined __DOXYGEN__ +#define LWIP_IPV6_FRAG 1 +#endif + +/** + * LWIP_IPV6_REASS==1: reassemble incoming IPv6 packets that fragmented + */ +#if !defined LWIP_IPV6_REASS || defined __DOXYGEN__ +#define LWIP_IPV6_REASS LWIP_IPV6 +#endif + +/** + * LWIP_IPV6_SEND_ROUTER_SOLICIT==1: Send router solicitation messages during + * network startup. + */ +#if !defined LWIP_IPV6_SEND_ROUTER_SOLICIT || defined __DOXYGEN__ +#define LWIP_IPV6_SEND_ROUTER_SOLICIT LWIP_IPV6 +#endif + +/** + * LWIP_IPV6_AUTOCONFIG==1: Enable stateless address autoconfiguration as per RFC 4862. + */ +#if !defined LWIP_IPV6_AUTOCONFIG || defined __DOXYGEN__ +#define LWIP_IPV6_AUTOCONFIG LWIP_IPV6 +#endif + +/** + * LWIP_IPV6_ADDRESS_LIFETIMES==1: Keep valid and preferred lifetimes for each + * IPv6 address. Required for LWIP_IPV6_AUTOCONFIG. May still be enabled + * otherwise, in which case the application may assign address lifetimes with + * the appropriate macros. Addresses with no lifetime are assumed to be static. + * If this option is disabled, all addresses are assumed to be static. + */ +#if !defined LWIP_IPV6_ADDRESS_LIFETIMES || defined __DOXYGEN__ +#define LWIP_IPV6_ADDRESS_LIFETIMES LWIP_IPV6_AUTOCONFIG +#endif + +/** + * LWIP_IPV6_DUP_DETECT_ATTEMPTS=[0..7]: Number of duplicate address detection attempts. + */ +#if !defined LWIP_IPV6_DUP_DETECT_ATTEMPTS || defined __DOXYGEN__ +#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 1 +#endif +/** + * @} + */ + +/** + * @defgroup lwip_opts_icmp6 ICMP6 + * @ingroup lwip_opts_ipv6 + * @{ + */ +/** + * LWIP_ICMP6==1: Enable ICMPv6 (mandatory per RFC) + */ +#if !defined LWIP_ICMP6 || defined __DOXYGEN__ +#define LWIP_ICMP6 LWIP_IPV6 +#endif + +/** + * LWIP_ICMP6_DATASIZE: bytes from original packet to send back in + * ICMPv6 error messages (0 = default of IP6_MIN_MTU_LENGTH) + * ATTENTION: RFC4443 section 2.4 says IP6_MIN_MTU_LENGTH is a MUST, + * so override this only if you absolutely have to! + */ +#if !defined LWIP_ICMP6_DATASIZE || defined __DOXYGEN__ +#define LWIP_ICMP6_DATASIZE 0 +#endif + +/** + * LWIP_ICMP6_HL: default hop limit for ICMPv6 messages + */ +#if !defined LWIP_ICMP6_HL || defined __DOXYGEN__ +#define LWIP_ICMP6_HL 255 +#endif +/** + * @} + */ + +/** + * @defgroup lwip_opts_mld6 Multicast listener discovery + * @ingroup lwip_opts_ipv6 + * @{ + */ +/** + * LWIP_IPV6_MLD==1: Enable multicast listener discovery protocol. + * If LWIP_IPV6 is enabled but this setting is disabled, the MAC layer must + * indiscriminately pass all inbound IPv6 multicast traffic to lwIP. + */ +#if !defined LWIP_IPV6_MLD || defined __DOXYGEN__ +#define LWIP_IPV6_MLD LWIP_IPV6 +#endif + +/** + * MEMP_NUM_MLD6_GROUP: Max number of IPv6 multicast groups that can be joined. + * There must be enough groups so that each netif can join the solicited-node + * multicast group for each of its local addresses, plus one for MDNS if + * applicable, plus any number of groups to be joined on UDP sockets. + */ +#if !defined MEMP_NUM_MLD6_GROUP || defined __DOXYGEN__ +#define MEMP_NUM_MLD6_GROUP 4 +#endif +/** + * @} + */ + +/** + * @defgroup lwip_opts_nd6 Neighbor discovery + * @ingroup lwip_opts_ipv6 + * @{ + */ +/** + * LWIP_ND6_QUEUEING==1: queue outgoing IPv6 packets while MAC address + * is being resolved. + */ +#if !defined LWIP_ND6_QUEUEING || defined __DOXYGEN__ +#define LWIP_ND6_QUEUEING LWIP_IPV6 +#endif + +/** + * MEMP_NUM_ND6_QUEUE: Max number of IPv6 packets to queue during MAC resolution. + */ +#if !defined MEMP_NUM_ND6_QUEUE || defined __DOXYGEN__ +#define MEMP_NUM_ND6_QUEUE 20 +#endif + +/** + * LWIP_ND6_NUM_NEIGHBORS: Number of entries in IPv6 neighbor cache + */ +#if !defined LWIP_ND6_NUM_NEIGHBORS || defined __DOXYGEN__ +#define LWIP_ND6_NUM_NEIGHBORS 10 +#endif + +/** + * LWIP_ND6_NUM_DESTINATIONS: number of entries in IPv6 destination cache + */ +#if !defined LWIP_ND6_NUM_DESTINATIONS || defined __DOXYGEN__ +#define LWIP_ND6_NUM_DESTINATIONS 10 +#endif + +/** + * LWIP_ND6_NUM_PREFIXES: number of entries in IPv6 on-link prefixes cache + */ +#if !defined LWIP_ND6_NUM_PREFIXES || defined __DOXYGEN__ +#define LWIP_ND6_NUM_PREFIXES 5 +#endif + +/** + * LWIP_ND6_NUM_ROUTERS: number of entries in IPv6 default router cache + */ +#if !defined LWIP_ND6_NUM_ROUTERS || defined __DOXYGEN__ +#define LWIP_ND6_NUM_ROUTERS 3 +#endif + +/** + * LWIP_ND6_MAX_MULTICAST_SOLICIT: max number of multicast solicit messages to send + * (neighbor solicit and router solicit) + */ +#if !defined LWIP_ND6_MAX_MULTICAST_SOLICIT || defined __DOXYGEN__ +#define LWIP_ND6_MAX_MULTICAST_SOLICIT 3 +#endif + +/** + * LWIP_ND6_MAX_UNICAST_SOLICIT: max number of unicast neighbor solicitation messages + * to send during neighbor reachability detection. + */ +#if !defined LWIP_ND6_MAX_UNICAST_SOLICIT || defined __DOXYGEN__ +#define LWIP_ND6_MAX_UNICAST_SOLICIT 3 +#endif + +/** + * Unused: See ND RFC (time in milliseconds). + */ +#if !defined LWIP_ND6_MAX_ANYCAST_DELAY_TIME || defined __DOXYGEN__ +#define LWIP_ND6_MAX_ANYCAST_DELAY_TIME 1000 +#endif + +/** + * Unused: See ND RFC + */ +#if !defined LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT || defined __DOXYGEN__ +#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT 3 +#endif + +/** + * LWIP_ND6_REACHABLE_TIME: default neighbor reachable time (in milliseconds). + * May be updated by router advertisement messages. + */ +#if !defined LWIP_ND6_REACHABLE_TIME || defined __DOXYGEN__ +#define LWIP_ND6_REACHABLE_TIME 30000 +#endif + +/** + * LWIP_ND6_RETRANS_TIMER: default retransmission timer for solicitation messages + */ +#if !defined LWIP_ND6_RETRANS_TIMER || defined __DOXYGEN__ +#define LWIP_ND6_RETRANS_TIMER 1000 +#endif + +/** + * LWIP_ND6_DELAY_FIRST_PROBE_TIME: Delay before first unicast neighbor solicitation + * message is sent, during neighbor reachability detection. + */ +#if !defined LWIP_ND6_DELAY_FIRST_PROBE_TIME || defined __DOXYGEN__ +#define LWIP_ND6_DELAY_FIRST_PROBE_TIME 5000 +#endif + +/** + * LWIP_ND6_ALLOW_RA_UPDATES==1: Allow Router Advertisement messages to update + * Reachable time and retransmission timers, and netif MTU. + */ +#if !defined LWIP_ND6_ALLOW_RA_UPDATES || defined __DOXYGEN__ +#define LWIP_ND6_ALLOW_RA_UPDATES 1 +#endif + +/** + * LWIP_ND6_TCP_REACHABILITY_HINTS==1: Allow TCP to provide Neighbor Discovery + * with reachability hints for connected destinations. This helps avoid sending + * unicast neighbor solicitation messages. + */ +#if !defined LWIP_ND6_TCP_REACHABILITY_HINTS || defined __DOXYGEN__ +#define LWIP_ND6_TCP_REACHABILITY_HINTS 1 +#endif + +/** + * LWIP_ND6_RDNSS_MAX_DNS_SERVERS > 0: Use IPv6 Router Advertisement Recursive + * DNS Server Option (as per RFC 6106) to copy a defined maximum number of DNS + * servers to the DNS module. + */ +#if !defined LWIP_ND6_RDNSS_MAX_DNS_SERVERS || defined __DOXYGEN__ +#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS 0 +#endif +/** + * @} + */ + +/** + * @defgroup lwip_opts_dhcpv6 DHCPv6 + * @ingroup lwip_opts_ipv6 + * @{ + */ +/** + * LWIP_IPV6_DHCP6==1: enable DHCPv6 stateful/stateless address autoconfiguration. + */ +#if !defined LWIP_IPV6_DHCP6 || defined __DOXYGEN__ +#define LWIP_IPV6_DHCP6 0 +#endif + +/** + * LWIP_IPV6_DHCP6_STATEFUL==1: enable DHCPv6 stateful address autoconfiguration. + * (not supported, yet!) + */ +#if !defined LWIP_IPV6_DHCP6_STATEFUL || defined __DOXYGEN__ +#define LWIP_IPV6_DHCP6_STATEFUL 0 +#endif + +/** + * LWIP_IPV6_DHCP6_STATELESS==1: enable DHCPv6 stateless address autoconfiguration. + */ +#if !defined LWIP_IPV6_DHCP6_STATELESS || defined __DOXYGEN__ +#define LWIP_IPV6_DHCP6_STATELESS LWIP_IPV6_DHCP6 +#endif + +/** + * LWIP_DHCP6_GETS_NTP==1: Request NTP servers via DHCPv6. For each + * response packet, a callback is called, which has to be provided by the port: + * void dhcp6_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs); +*/ +#if !defined LWIP_DHCP6_GET_NTP_SRV || defined __DOXYGEN__ +#define LWIP_DHCP6_GET_NTP_SRV 0 +#endif + +/** + * The maximum of NTP servers requested + */ +#if !defined LWIP_DHCP6_MAX_NTP_SERVERS || defined __DOXYGEN__ +#define LWIP_DHCP6_MAX_NTP_SERVERS 1 +#endif + +/** + * LWIP_DHCP6_MAX_DNS_SERVERS > 0: Request DNS servers via DHCPv6. + * DNS servers received in the response are passed to DNS via @ref dns_setserver() + * (up to the maximum limit defined here). + */ +#if !defined LWIP_DHCP6_MAX_DNS_SERVERS || defined __DOXYGEN__ +#define LWIP_DHCP6_MAX_DNS_SERVERS DNS_MAX_SERVERS +#endif +/** + * @} + */ + +/* + --------------------------------------- + ---------- Hook options --------------- + --------------------------------------- +*/ + +/** + * @defgroup lwip_opts_hooks Hooks + * @ingroup lwip_opts_infrastructure + * Hooks are undefined by default, define them to a function if you need them. + * @{ + */ + +/** + * LWIP_HOOK_FILENAME: Custom filename to \#include in files that provide hooks. + * Declare your hook function prototypes in there, you may also \#include all headers + * providing data types that are need in this file. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_FILENAME "path/to/my/lwip_hooks.h" +#endif + +/** + * LWIP_HOOK_TCP_ISN: + * Hook for generation of the Initial Sequence Number (ISN) for a new TCP + * connection. The default lwIP ISN generation algorithm is very basic and may + * allow for TCP spoofing attacks. This hook provides the means to implement + * the standardized ISN generation algorithm from RFC 6528 (see contrib/adons/tcp_isn), + * or any other desired algorithm as a replacement. + * Called from tcp_connect() and tcp_listen_input() when an ISN is needed for + * a new TCP connection, if TCP support (@ref LWIP_TCP) is enabled.\n + * Signature:\code{.c} + * u32_t my_hook_tcp_isn(const ip_addr_t* local_ip, u16_t local_port, const ip_addr_t* remote_ip, u16_t remote_port); + * \endcode + * - it may be necessary to use "struct ip_addr" (ip4_addr, ip6_addr) instead of "ip_addr_t" in function declarations\n + * Arguments: + * - local_ip: pointer to the local IP address of the connection + * - local_port: local port number of the connection (host-byte order) + * - remote_ip: pointer to the remote IP address of the connection + * - remote_port: remote port number of the connection (host-byte order)\n + * Return value: + * - the 32-bit Initial Sequence Number to use for the new TCP connection. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_TCP_ISN(local_ip, local_port, remote_ip, remote_port) +#endif + +/** + * LWIP_HOOK_TCP_INPACKET_PCB: + * Hook for intercepting incoming packets before they are passed to a pcb. This + * allows updating some state or even dropping a packet. + * Signature:\code{.c} + * err_t my_hook_tcp_inpkt(struct tcp_pcb *pcb, struct tcp_hdr *hdr, u16_t optlen, u16_t opt1len, u8_t *opt2, struct pbuf *p); + * \endcode + * Arguments: + * - pcb: tcp_pcb selected for input of this packet (ATTENTION: this may be + * struct tcp_pcb_listen if pcb->state == LISTEN) + * - hdr: pointer to tcp header (ATTENTION: tcp options may not be in one piece!) + * - optlen: tcp option length + * - opt1len: tcp option length 1st part + * - opt2: if this is != NULL, tcp options are split among 2 pbufs. In that case, + * options start at right after the tcp header ('(u8_t*)(hdr + 1)') for + * the first 'opt1len' bytes and the rest starts at 'opt2'. opt2len can + * be simply calculated: 'opt2len = optlen - opt1len;' + * - p: input packet, p->payload points to application data (that's why tcp hdr + * and options are passed in seperately) + * Return value: + * - ERR_OK: continue input of this packet as normal + * - != ERR_OK: drop this packet for input (don't continue input processing) + * + * ATTENTION: don't call any tcp api functions that might change tcp state (pcb + * state or any pcb lists) from this callback! + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_TCP_INPACKET_PCB(pcb, hdr, optlen, opt1len, opt2, p) +#endif + +/** + * LWIP_HOOK_TCP_OUT_TCPOPT_LENGTH: + * Hook for increasing the size of the options allocated with a tcp header. + * Together with LWIP_HOOK_TCP_OUT_ADD_TCPOPTS, this can be used to add custom + * options to outgoing tcp segments. + * Signature:\code{.c} + * u8_t my_hook_tcp_out_tcpopt_length(const struct tcp_pcb *pcb, u8_t internal_option_length); + * \endcode + * Arguments: + * - pcb: tcp_pcb that transmits (ATTENTION: this may be NULL or + * struct tcp_pcb_listen if pcb->state == LISTEN) + * - internal_option_length: tcp option length used by the stack internally + * Return value: + * - a number of bytes to allocate for tcp options (internal_option_length <= ret <= 40) + * + * ATTENTION: don't call any tcp api functions that might change tcp state (pcb + * state or any pcb lists) from this callback! + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_TCP_OUT_TCPOPT_LENGTH(pcb, internal_len) +#endif + +/** + * LWIP_HOOK_TCP_OUT_ADD_TCPOPTS: + * Hook for adding custom options to outgoing tcp segments. + * Space for these custom options has to be reserved via LWIP_HOOK_TCP_OUT_TCPOPT_LENGTH. + * Signature:\code{.c} + * u32_t *my_hook_tcp_out_add_tcpopts(struct pbuf *p, struct tcp_hdr *hdr, const struct tcp_pcb *pcb, u32_t *opts); + * \endcode + * Arguments: + * - p: output packet, p->payload pointing to tcp header, data follows + * - hdr: tcp header + * - pcb: tcp_pcb that transmits (ATTENTION: this may be NULL or + * struct tcp_pcb_listen if pcb->state == LISTEN) + * - opts: pointer where to add the custom options (there may already be options + * between the header and these) + * Return value: + * - pointer pointing directly after the inserted options + * + * ATTENTION: don't call any tcp api functions that might change tcp state (pcb + * state or any pcb lists) from this callback! + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_TCP_OUT_ADD_TCPOPTS(p, hdr, pcb, opts) +#endif + +/** + * LWIP_HOOK_IP4_INPUT(pbuf, input_netif): + * Called from ip_input() (IPv4) + * Signature:\code{.c} + * int my_hook(struct pbuf *pbuf, struct netif *input_netif); + * \endcode + * Arguments: + * - pbuf: received struct pbuf passed to ip_input() + * - input_netif: struct netif on which the packet has been received + * Return values: + * - 0: Hook has not consumed the packet, packet is processed as normal + * - != 0: Hook has consumed the packet. + * If the hook consumed the packet, 'pbuf' is in the responsibility of the hook + * (i.e. free it when done). + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_IP4_INPUT(pbuf, input_netif) +#endif + +/** + * LWIP_HOOK_IP4_ROUTE(dest): + * Called from ip_route() (IPv4) + * Signature:\code{.c} + * struct netif *my_hook(const ip4_addr_t *dest); + * \endcode + * Arguments: + * - dest: destination IPv4 address + * Returns values: + * - the destination netif + * - NULL if no destination netif is found. In that case, ip_route() continues as normal. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_IP4_ROUTE() +#endif + +/** + * LWIP_HOOK_IP4_ROUTE_SRC(src, dest): + * Source-based routing for IPv4 - called from ip_route() (IPv4) + * Signature:\code{.c} + * struct netif *my_hook(const ip4_addr_t *src, const ip4_addr_t *dest); + * \endcode + * Arguments: + * - src: local/source IPv4 address + * - dest: destination IPv4 address + * Returns values: + * - the destination netif + * - NULL if no destination netif is found. In that case, ip_route() continues as normal. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_IP4_ROUTE_SRC(src, dest) +#endif + +/** + * LWIP_HOOK_IP4_CANFORWARD(src, dest): + * Check if an IPv4 can be forwarded - called from: + * ip4_input() -> ip4_forward() -> ip4_canforward() (IPv4) + * - source address is available via ip4_current_src_addr() + * - calling an output function in this context (e.g. multicast router) is allowed + * Signature:\code{.c} + * int my_hook(struct pbuf *p, u32_t dest_addr_hostorder); + * \endcode + * Arguments: + * - p: packet to forward + * - dest: destination IPv4 address + * Returns values: + * - 1: forward + * - 0: don't forward + * - -1: no decision. In that case, ip4_canforward() continues as normal. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_IP4_CANFORWARD(src, dest) +#endif + +/** + * LWIP_HOOK_ETHARP_GET_GW(netif, dest): + * Called from etharp_output() (IPv4) + * Signature:\code{.c} + * const ip4_addr_t *my_hook(struct netif *netif, const ip4_addr_t *dest); + * \endcode + * Arguments: + * - netif: the netif used for sending + * - dest: the destination IPv4 address + * Return values: + * - the IPv4 address of the gateway to handle the specified destination IPv4 address + * - NULL, in which case the netif's default gateway is used + * + * The returned address MUST be directly reachable on the specified netif! + * This function is meant to implement advanced IPv4 routing together with + * LWIP_HOOK_IP4_ROUTE(). The actual routing/gateway table implementation is + * not part of lwIP but can e.g. be hidden in the netif's state argument. +*/ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_ETHARP_GET_GW(netif, dest) +#endif + +/** + * LWIP_HOOK_IP6_INPUT(pbuf, input_netif): + * Called from ip6_input() (IPv6) + * Signature:\code{.c} + * int my_hook(struct pbuf *pbuf, struct netif *input_netif); + * \endcode + * Arguments: + * - pbuf: received struct pbuf passed to ip6_input() + * - input_netif: struct netif on which the packet has been received + * Return values: + * - 0: Hook has not consumed the packet, packet is processed as normal + * - != 0: Hook has consumed the packet. + * If the hook consumed the packet, 'pbuf' is in the responsibility of the hook + * (i.e. free it when done). + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_IP6_INPUT(pbuf, input_netif) +#endif + +/** + * LWIP_HOOK_IP6_ROUTE(src, dest): + * Called from ip_route() (IPv6) + * Signature:\code{.c} + * struct netif *my_hook(const ip6_addr_t *dest, const ip6_addr_t *src); + * \endcode + * Arguments: + * - src: source IPv6 address + * - dest: destination IPv6 address + * Return values: + * - the destination netif + * - NULL if no destination netif is found. In that case, ip6_route() continues as normal. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_IP6_ROUTE(src, dest) +#endif + +/** + * LWIP_HOOK_ND6_GET_GW(netif, dest): + * Called from nd6_get_next_hop_entry() (IPv6) + * Signature:\code{.c} + * const ip6_addr_t *my_hook(struct netif *netif, const ip6_addr_t *dest); + * \endcode + * Arguments: + * - netif: the netif used for sending + * - dest: the destination IPv6 address + * Return values: + * - the IPv6 address of the next hop to handle the specified destination IPv6 address + * - NULL, in which case a NDP-discovered router is used instead + * + * The returned address MUST be directly reachable on the specified netif! + * This function is meant to implement advanced IPv6 routing together with + * LWIP_HOOK_IP6_ROUTE(). The actual routing/gateway table implementation is + * not part of lwIP but can e.g. be hidden in the netif's state argument. +*/ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_ND6_GET_GW(netif, dest) +#endif + +/** + * LWIP_HOOK_VLAN_CHECK(netif, eth_hdr, vlan_hdr): + * Called from ethernet_input() if VLAN support is enabled + * Signature:\code{.c} + * int my_hook(struct netif *netif, struct eth_hdr *eth_hdr, struct eth_vlan_hdr *vlan_hdr); + * \endcode + * Arguments: + * - netif: struct netif on which the packet has been received + * - eth_hdr: struct eth_hdr of the packet + * - vlan_hdr: struct eth_vlan_hdr of the packet + * Return values: + * - 0: Packet must be dropped. + * - != 0: Packet must be accepted. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_VLAN_CHECK(netif, eth_hdr, vlan_hdr) +#endif + +/** + * LWIP_HOOK_VLAN_SET: + * Hook can be used to set prio_vid field of vlan_hdr. If you need to store data + * on per-netif basis to implement this callback, see @ref netif_cd. + * Called from ethernet_output() if VLAN support (@ref ETHARP_SUPPORT_VLAN) is enabled.\n + * Signature:\code{.c} + * s32_t my_hook_vlan_set(struct netif* netif, struct pbuf* pbuf, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);\n + * \endcode + * Arguments: + * - netif: struct netif that the packet will be sent through + * - p: struct pbuf packet to be sent + * - src: source eth address + * - dst: destination eth address + * - eth_type: ethernet type to packet to be sent\n + * + * + * Return values: + * - <0: Packet shall not contain VLAN header. + * - 0 <= return value <= 0xFFFF: Packet shall contain VLAN header. Return value is prio_vid in host byte order. + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type) +#endif + +/** + * LWIP_HOOK_MEMP_AVAILABLE(memp_t_type): + * Called from memp_free() when a memp pool was empty and an item is now available + * Signature:\code{.c} + * void my_hook(memp_t type); + * \endcode + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_MEMP_AVAILABLE(memp_t_type) +#endif + +/** + * LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif): + * Called from ethernet_input() when an unknown eth type is encountered. + * Signature:\code{.c} + * err_t my_hook(struct pbuf* pbuf, struct netif* netif); + * \endcode + * Arguments: + * - p: rx packet with unknown eth type + * - netif: netif on which the packet has been received + * Return values: + * - ERR_OK if packet is accepted (hook function now owns the pbuf) + * - any error code otherwise (pbuf is freed) + * + * Payload points to ethernet header! + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_UNKNOWN_ETH_PROTOCOL(pbuf, netif) +#endif + +/** + * LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, state, msg, msg_type, options_len_ptr): + * Called from various dhcp functions when sending a DHCP message. + * This hook is called just before the DHCP message trailer is added, so the + * options are at the end of a DHCP message. + * Signature:\code{.c} + * void my_hook(struct netif *netif, struct dhcp *dhcp, u8_t state, struct dhcp_msg *msg, + * u8_t msg_type, u16_t *options_len_ptr); + * \endcode + * Arguments: + * - netif: struct netif that the packet will be sent through + * - dhcp: struct dhcp on that netif + * - state: current dhcp state (dhcp_state_enum_t as an u8_t) + * - msg: struct dhcp_msg that will be sent + * - msg_type: dhcp message type to be sent (u8_t) + * - options_len_ptr: pointer to the current length of options in the dhcp_msg "msg" + * (must be increased when options are added!) + * + * Options need to appended like this: + * LWIP_ASSERT("dhcp option overflow", *options_len_ptr + option_len + 2 <= DHCP_OPTIONS_LEN); + * msg->options[(*options_len_ptr)++] = <option_number>; + * msg->options[(*options_len_ptr)++] = <option_len>; + * msg->options[(*options_len_ptr)++] = <option_bytes>; + * [...] + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, state, msg, msg_type, options_len_ptr) +#endif + +/** + * LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, option_value_offset): + * Called from dhcp_parse_reply when receiving a DHCP message. + * This hook is called for every option in the received message that is not handled internally. + * Signature:\code{.c} + * void my_hook(struct netif *netif, struct dhcp *dhcp, u8_t state, struct dhcp_msg *msg, + * u8_t msg_type, u8_t option, u8_t option_len, struct pbuf *pbuf, u16_t option_value_offset); + * \endcode + * Arguments: + * - netif: struct netif that the packet will be sent through + * - dhcp: struct dhcp on that netif + * - state: current dhcp state (dhcp_state_enum_t as an u8_t) + * - msg: struct dhcp_msg that was received + * - msg_type: dhcp message type received (u8_t, ATTENTION: only valid after + * the message type option has been parsed!) + * - option: option value (u8_t) + * - len: option data length (u8_t) + * - pbuf: pbuf where option data is contained + * - option_value_offset: offset in pbuf where option data begins + * + * A nice way to get the option contents is pbuf_get_contiguous(): + * u8_t buf[32]; + * u8_t *ptr = (u8_t*)pbuf_get_contiguous(p, buf, sizeof(buf), LWIP_MIN(option_len, sizeof(buf)), offset); + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) +#endif + +/** + * LWIP_HOOK_DHCP6_APPEND_OPTIONS(netif, dhcp6, state, msg, msg_type, options_len_ptr, max_len): + * Called from various dhcp6 functions when sending a DHCP6 message. + * This hook is called just before the DHCP6 message is sent, so the + * options are at the end of a DHCP6 message. + * Signature:\code{.c} + * void my_hook(struct netif *netif, struct dhcp6 *dhcp, u8_t state, struct dhcp6_msg *msg, + * u8_t msg_type, u16_t *options_len_ptr); + * \endcode + * Arguments: + * - netif: struct netif that the packet will be sent through + * - dhcp6: struct dhcp6 on that netif + * - state: current dhcp6 state (dhcp6_state_enum_t as an u8_t) + * - msg: struct dhcp6_msg that will be sent + * - msg_type: dhcp6 message type to be sent (u8_t) + * - options_len_ptr: pointer to the current length of options in the dhcp6_msg "msg" + * (must be increased when options are added!) + * + * Options need to appended like this: + * u8_t *options = (u8_t *)(msg + 1); + * LWIP_ASSERT("dhcp option overflow", sizeof(struct dhcp6_msg) + *options_len_ptr + newoptlen <= max_len); + * options[(*options_len_ptr)++] = <option_data>; + * [...] + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_DHCP6_APPEND_OPTIONS(netif, dhcp6, state, msg, msg_type, options_len_ptr, max_len) +#endif + +/** + * LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) + * Called from socket API to implement setsockopt() for options not provided by lwIP. + * Core lock is held when this hook is called. + * Signature:\code{.c} + * int my_hook(int s, struct lwip_sock *sock, int level, int optname, const void *optval, socklen_t optlen, int *err) + * \endcode + * Arguments: + * - s: socket file descriptor + * - sock: internal socket descriptor (see lwip/priv/sockets_priv.h) + * - level: protocol level at which the option resides + * - optname: option to set + * - optval: value to set + * - optlen: size of optval + * - err: output error + * Return values: + * - 0: Hook has not consumed the option, code continues as normal (to internal options) + * - != 0: Hook has consumed the option, 'err' is returned + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) +#endif + +/** + * LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err) + * Called from socket API to implement getsockopt() for options not provided by lwIP. + * Core lock is held when this hook is called. + * Signature:\code{.c} + * int my_hook(int s, struct lwip_sock *sock, int level, int optname, void *optval, socklen_t *optlen, int *err) + * \endcode + * Arguments: + * - s: socket file descriptor + * - sock: internal socket descriptor (see lwip/priv/sockets_priv.h) + * - level: protocol level at which the option resides + * - optname: option to get + * - optval: value to get + * - optlen: size of optval + * - err: output error + * Return values: + * - 0: Hook has not consumed the option, code continues as normal (to internal options) + * - != 0: Hook has consumed the option, 'err' is returned + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err) +#endif + +/** + * LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err) + * Called from netconn APIs (not usable with callback apps) allowing an + * external DNS resolver (which uses sequential API) to handle the query. + * Signature:\code{.c} + * int my_hook(const char *name, ip_addr_t *addr, u8_t addrtype, err_t *err) + * \endcode + * Arguments: + * - name: hostname to resolve + * - addr: output host address + * - addrtype: type of address to query + * - err: output error + * Return values: + * - 0: Hook has not consumed hostname query, query continues into DNS module + * - != 0: Hook has consumed the query + * + * err must also be checked to determine if the hook consumed the query, but + * the query failed + */ +#ifdef __DOXYGEN__ +#define LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err) +#endif +/** + * @} + */ + +/* + --------------------------------------- + ---------- Debugging options ---------- + --------------------------------------- +*/ +/** + * @defgroup lwip_opts_debugmsg Debug messages + * @ingroup lwip_opts_debug + * @{ + */ +/** + * LWIP_DBG_MIN_LEVEL: After masking, the value of the debug is + * compared against this value. If it is smaller, then debugging + * messages are written. + * @see debugging_levels + */ +#if !defined LWIP_DBG_MIN_LEVEL || defined __DOXYGEN__ +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#endif + +/** + * LWIP_DBG_TYPES_ON: A mask that can be used to globally enable/disable + * debug messages of certain types. + * @see debugging_levels + */ +#if !defined LWIP_DBG_TYPES_ON || defined __DOXYGEN__ +#define LWIP_DBG_TYPES_ON LWIP_DBG_ON +#endif + +/** + * ETHARP_DEBUG: Enable debugging in etharp.c. + */ +#if !defined ETHARP_DEBUG || defined __DOXYGEN__ +#define ETHARP_DEBUG LWIP_DBG_OFF +#endif + +/** + * NETIF_DEBUG: Enable debugging in netif.c. + */ +#if !defined NETIF_DEBUG || defined __DOXYGEN__ +#define NETIF_DEBUG LWIP_DBG_OFF +#endif + +/** + * PBUF_DEBUG: Enable debugging in pbuf.c. + */ +#if !defined PBUF_DEBUG || defined __DOXYGEN__ +#define PBUF_DEBUG LWIP_DBG_OFF +#endif + +/** + * API_LIB_DEBUG: Enable debugging in api_lib.c. + */ +#if !defined API_LIB_DEBUG || defined __DOXYGEN__ +#define API_LIB_DEBUG LWIP_DBG_OFF +#endif + +/** + * API_MSG_DEBUG: Enable debugging in api_msg.c. + */ +#if !defined API_MSG_DEBUG || defined __DOXYGEN__ +#define API_MSG_DEBUG LWIP_DBG_OFF +#endif + +/** + * SOCKETS_DEBUG: Enable debugging in sockets.c. + */ +#if !defined SOCKETS_DEBUG || defined __DOXYGEN__ +#define SOCKETS_DEBUG LWIP_DBG_OFF +#endif + +/** + * ICMP_DEBUG: Enable debugging in icmp.c. + */ +#if !defined ICMP_DEBUG || defined __DOXYGEN__ +#define ICMP_DEBUG LWIP_DBG_OFF +#endif + +/** + * IGMP_DEBUG: Enable debugging in igmp.c. + */ +#if !defined IGMP_DEBUG || defined __DOXYGEN__ +#define IGMP_DEBUG LWIP_DBG_OFF +#endif + +/** + * INET_DEBUG: Enable debugging in inet.c. + */ +#if !defined INET_DEBUG || defined __DOXYGEN__ +#define INET_DEBUG LWIP_DBG_OFF +#endif + +/** + * IP_DEBUG: Enable debugging for IP. + */ +#if !defined IP_DEBUG || defined __DOXYGEN__ +#define IP_DEBUG LWIP_DBG_OFF +#endif + +/** + * IP_REASS_DEBUG: Enable debugging in ip_frag.c for both frag & reass. + */ +#if !defined IP_REASS_DEBUG || defined __DOXYGEN__ +#define IP_REASS_DEBUG LWIP_DBG_OFF +#endif + +/** + * RAW_DEBUG: Enable debugging in raw.c. + */ +#if !defined RAW_DEBUG || defined __DOXYGEN__ +#define RAW_DEBUG LWIP_DBG_OFF +#endif + +/** + * MEM_DEBUG: Enable debugging in mem.c. + */ +#if !defined MEM_DEBUG || defined __DOXYGEN__ +#define MEM_DEBUG LWIP_DBG_OFF +#endif + +/** + * MEMP_DEBUG: Enable debugging in memp.c. + */ +#if !defined MEMP_DEBUG || defined __DOXYGEN__ +#define MEMP_DEBUG LWIP_DBG_OFF +#endif + +/** + * SYS_DEBUG: Enable debugging in sys.c. + */ +#if !defined SYS_DEBUG || defined __DOXYGEN__ +#define SYS_DEBUG LWIP_DBG_OFF +#endif + +/** + * TIMERS_DEBUG: Enable debugging in timers.c. + */ +#if !defined TIMERS_DEBUG || defined __DOXYGEN__ +#define TIMERS_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_DEBUG: Enable debugging for TCP. + */ +#if !defined TCP_DEBUG || defined __DOXYGEN__ +#define TCP_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_INPUT_DEBUG: Enable debugging in tcp_in.c for incoming debug. + */ +#if !defined TCP_INPUT_DEBUG || defined __DOXYGEN__ +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_FR_DEBUG: Enable debugging in tcp_in.c for fast retransmit. + */ +#if !defined TCP_FR_DEBUG || defined __DOXYGEN__ +#define TCP_FR_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_RTO_DEBUG: Enable debugging in TCP for retransmit + * timeout. + */ +#if !defined TCP_RTO_DEBUG || defined __DOXYGEN__ +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_CWND_DEBUG: Enable debugging for TCP congestion window. + */ +#if !defined TCP_CWND_DEBUG || defined __DOXYGEN__ +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_WND_DEBUG: Enable debugging in tcp_in.c for window updating. + */ +#if !defined TCP_WND_DEBUG || defined __DOXYGEN__ +#define TCP_WND_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_OUTPUT_DEBUG: Enable debugging in tcp_out.c output functions. + */ +#if !defined TCP_OUTPUT_DEBUG || defined __DOXYGEN__ +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_RST_DEBUG: Enable debugging for TCP with the RST message. + */ +#if !defined TCP_RST_DEBUG || defined __DOXYGEN__ +#define TCP_RST_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCP_QLEN_DEBUG: Enable debugging for TCP queue lengths. + */ +#if !defined TCP_QLEN_DEBUG || defined __DOXYGEN__ +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#endif + +/** + * UDP_DEBUG: Enable debugging in UDP. + */ +#if !defined UDP_DEBUG || defined __DOXYGEN__ +#define UDP_DEBUG LWIP_DBG_OFF +#endif + +/** + * TCPIP_DEBUG: Enable debugging in tcpip.c. + */ +#if !defined TCPIP_DEBUG || defined __DOXYGEN__ +#define TCPIP_DEBUG LWIP_DBG_OFF +#endif + +/** + * SLIP_DEBUG: Enable debugging in slipif.c. + */ +#if !defined SLIP_DEBUG || defined __DOXYGEN__ +#define SLIP_DEBUG LWIP_DBG_OFF +#endif + +/** + * DHCP_DEBUG: Enable debugging in dhcp.c. + */ +#if !defined DHCP_DEBUG || defined __DOXYGEN__ +#define DHCP_DEBUG LWIP_DBG_OFF +#endif + +/** + * AUTOIP_DEBUG: Enable debugging in autoip.c. + */ +#if !defined AUTOIP_DEBUG || defined __DOXYGEN__ +#define AUTOIP_DEBUG LWIP_DBG_OFF +#endif + +/** + * DNS_DEBUG: Enable debugging for DNS. + */ +#if !defined DNS_DEBUG || defined __DOXYGEN__ +#define DNS_DEBUG LWIP_DBG_OFF +#endif + +/** + * IP6_DEBUG: Enable debugging for IPv6. + */ +#if !defined IP6_DEBUG || defined __DOXYGEN__ +#define IP6_DEBUG LWIP_DBG_OFF +#endif + +/** + * DHCP6_DEBUG: Enable debugging in dhcp6.c. + */ +#if !defined DHCP6_DEBUG || defined __DOXYGEN__ +#define DHCP6_DEBUG LWIP_DBG_OFF +#endif +/** + * @} + */ + +/** + * LWIP_TESTMODE: Changes to make unit test possible + */ +#if !defined LWIP_TESTMODE +#define LWIP_TESTMODE 0 +#endif + +/* + -------------------------------------------------- + ---------- Performance tracking options ---------- + -------------------------------------------------- +*/ +/** + * @defgroup lwip_opts_perf Performance + * @ingroup lwip_opts_debug + * @{ + */ +/** + * LWIP_PERF: Enable performance testing for lwIP + * (if enabled, arch/perf.h is included) + */ +#if !defined LWIP_PERF || defined __DOXYGEN__ +#define LWIP_PERF 0 +#endif +/** + * @} + */ + +#endif /* LWIP_HDR_OPT_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/pbuf.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/pbuf.h new file mode 100644 index 000000000..e5daf968e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/pbuf.h @@ -0,0 +1,326 @@ +/** + * @file + * pbuf API + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +#ifndef LWIP_HDR_PBUF_H +#define LWIP_HDR_PBUF_H + +#include "lwip/opt.h" +#include "lwip/err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** LWIP_SUPPORT_CUSTOM_PBUF==1: Custom pbufs behave much like their pbuf type + * but they are allocated by external code (initialised by calling + * pbuf_alloced_custom()) and when pbuf_free gives up their last reference, they + * are freed by calling pbuf_custom->custom_free_function(). + * Currently, the pbuf_custom code is only needed for one specific configuration + * of IP_FRAG, unless required by external driver/application code. */ +#ifndef LWIP_SUPPORT_CUSTOM_PBUF +#define LWIP_SUPPORT_CUSTOM_PBUF ((IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG)) +#endif + +/** @ingroup pbuf + * PBUF_NEEDS_COPY(p): return a boolean value indicating whether the given + * pbuf needs to be copied in order to be kept around beyond the current call + * stack without risking being corrupted. The default setting provides safety: + * it will make a copy iof any pbuf chain that does not consist entirely of + * PBUF_ROM type pbufs. For setups with zero-copy support, it may be redefined + * to evaluate to true in all cases, for example. However, doing so also has an + * effect on the application side: any buffers that are *not* copied must also + * *not* be reused by the application after passing them to lwIP. For example, + * when setting PBUF_NEEDS_COPY to (0), after using udp_send() with a PBUF_RAM + * pbuf, the application must free the pbuf immediately, rather than reusing it + * for other purposes. For more background information on this, see tasks #6735 + * and #7896, and bugs #11400 and #49914. */ +#ifndef PBUF_NEEDS_COPY +#define PBUF_NEEDS_COPY(p) ((p)->type_internal & PBUF_TYPE_FLAG_DATA_VOLATILE) +#endif /* PBUF_NEEDS_COPY */ + +/* @todo: We need a mechanism to prevent wasting memory in every pbuf + (TCP vs. UDP, IPv4 vs. IPv6: UDP/IPv4 packets may waste up to 28 bytes) */ + +#define PBUF_TRANSPORT_HLEN 20 +#if LWIP_IPV6 +#define PBUF_IP_HLEN 40 +#else +#define PBUF_IP_HLEN 20 +#endif + +/** + * @ingroup pbuf + * Enumeration of pbuf layers + */ +typedef enum { + /** Includes spare room for transport layer header, e.g. UDP header. + * Use this if you intend to pass the pbuf to functions like udp_send(). + */ + PBUF_TRANSPORT = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN, + /** Includes spare room for IP header. + * Use this if you intend to pass the pbuf to functions like raw_send(). + */ + PBUF_IP = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN, + /** Includes spare room for link layer header (ethernet header). + * Use this if you intend to pass the pbuf to functions like ethernet_output(). + * @see PBUF_LINK_HLEN + */ + PBUF_LINK = PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN, + /** Includes spare room for additional encapsulation header before ethernet + * headers (e.g. 802.11). + * Use this if you intend to pass the pbuf to functions like netif->linkoutput(). + * @see PBUF_LINK_ENCAPSULATION_HLEN + */ + PBUF_RAW_TX = PBUF_LINK_ENCAPSULATION_HLEN, + /** Use this for input packets in a netif driver when calling netif->input() + * in the most common case - ethernet-layer netif driver. */ + PBUF_RAW = 0 +} pbuf_layer; + + +/* Base flags for pbuf_type definitions: */ + +/** Indicates that the payload directly follows the struct pbuf. + * This makes @ref pbuf_header work in both directions. */ +#define PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS 0x80 +/** Indicates the data stored in this pbuf can change. If this pbuf needs + * to be queued, it must be copied/duplicated. */ +#define PBUF_TYPE_FLAG_DATA_VOLATILE 0x40 +/** 4 bits are reserved for 16 allocation sources (e.g. heap, pool1, pool2, etc) + * Internally, we use: 0=heap, 1=MEMP_PBUF, 2=MEMP_PBUF_POOL -> 13 types free*/ +#define PBUF_TYPE_ALLOC_SRC_MASK 0x0F +/** Indicates this pbuf is used for RX (if not set, indicates use for TX). + * This information can be used to keep some spare RX buffers e.g. for + * receiving TCP ACKs to unblock a connection) */ +#define PBUF_ALLOC_FLAG_RX 0x0100 +/** Indicates the application needs the pbuf payload to be in one piece */ +#define PBUF_ALLOC_FLAG_DATA_CONTIGUOUS 0x0200 + +#define PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP 0x00 +#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF 0x01 +#define PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL 0x02 +/** First pbuf allocation type for applications */ +#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MIN 0x03 +/** Last pbuf allocation type for applications */ +#define PBUF_TYPE_ALLOC_SRC_MASK_APP_MAX PBUF_TYPE_ALLOC_SRC_MASK + +/** + * @ingroup pbuf + * Enumeration of pbuf types + */ +typedef enum { + /** pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload + are allocated in one piece of contiguous memory (so the first payload byte + can be calculated from struct pbuf). + pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might + change in future versions). + This should be used for all OUTGOING packets (TX).*/ + PBUF_RAM = (PBUF_ALLOC_FLAG_DATA_CONTIGUOUS | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_HEAP), + /** pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in + totally different memory areas. Since it points to ROM, payload does not + have to be copied when queued for transmission. */ + PBUF_ROM = PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF, + /** pbuf comes from the pbuf pool. Much like PBUF_ROM but payload might change + so it has to be duplicated when queued before transmitting, depending on + who has a 'ref' to it. */ + PBUF_REF = (PBUF_TYPE_FLAG_DATA_VOLATILE | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF), + /** pbuf payload refers to RAM. This one comes from a pool and should be used + for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct + pbuf and its payload are allocated in one piece of contiguous memory (so + the first payload byte can be calculated from struct pbuf). + Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing, + you are unable to receive TCP acks! */ + PBUF_POOL = (PBUF_ALLOC_FLAG_RX | PBUF_TYPE_FLAG_STRUCT_DATA_CONTIGUOUS | PBUF_TYPE_ALLOC_SRC_MASK_STD_MEMP_PBUF_POOL) +} pbuf_type; + + +/** indicates this packet's data should be immediately passed to the application */ +#define PBUF_FLAG_PUSH 0x01U +/** indicates this is a custom pbuf: pbuf_free calls pbuf_custom->custom_free_function() + when the last reference is released (plus custom PBUF_RAM cannot be trimmed) */ +#define PBUF_FLAG_IS_CUSTOM 0x02U +/** indicates this pbuf is UDP multicast to be looped back */ +#define PBUF_FLAG_MCASTLOOP 0x04U +/** indicates this pbuf was received as link-level broadcast */ +#define PBUF_FLAG_LLBCAST 0x08U +/** indicates this pbuf was received as link-level multicast */ +#define PBUF_FLAG_LLMCAST 0x10U +/** indicates this pbuf includes a TCP FIN flag */ +#define PBUF_FLAG_TCP_FIN 0x20U + +/** Main packet buffer struct */ +struct pbuf { + /** next pbuf in singly linked pbuf chain */ + struct pbuf *next; + + /** pointer to the actual data in the buffer */ + void *payload; + + /** + * total length of this buffer and all next buffers in chain + * belonging to the same packet. + * + * For non-queue packet chains this is the invariant: + * p->tot_len == p->len + (p->next? p->next->tot_len: 0) + */ + u16_t tot_len; + + /** length of this buffer */ + u16_t len; + + /** a bit field indicating pbuf type and allocation sources + (see PBUF_TYPE_FLAG_*, PBUF_ALLOC_FLAG_* and PBUF_TYPE_ALLOC_SRC_MASK) + */ + u8_t type_internal; + + /** misc flags */ + u8_t flags; + + /** + * the reference count always equals the number of pointers + * that refer to this pbuf. This can be pointers from an application, + * the stack itself, or pbuf->next pointers from a chain. + */ + LWIP_PBUF_REF_T ref; + + /** For incoming packets, this contains the input netif's index */ + u8_t if_idx; + + /** In case the user needs to store data custom data on a pbuf */ + LWIP_PBUF_CUSTOM_DATA +}; + + +/** Helper struct for const-correctness only. + * The only meaning of this one is to provide a const payload pointer + * for PBUF_ROM type. + */ +struct pbuf_rom { + /** next pbuf in singly linked pbuf chain */ + struct pbuf *next; + + /** pointer to the actual data in the buffer */ + const void *payload; +}; + +#if LWIP_SUPPORT_CUSTOM_PBUF +/** Prototype for a function to free a custom pbuf */ +typedef void (*pbuf_free_custom_fn)(struct pbuf *p); + +/** A custom pbuf: like a pbuf, but following a function pointer to free it. */ +struct pbuf_custom { + /** The actual pbuf */ + struct pbuf pbuf; + /** This function is called when pbuf_free deallocates this pbuf(_custom) */ + pbuf_free_custom_fn custom_free_function; +}; +#endif /* LWIP_SUPPORT_CUSTOM_PBUF */ + +/** Define this to 0 to prevent freeing ooseq pbufs when the PBUF_POOL is empty */ +#ifndef PBUF_POOL_FREE_OOSEQ +#define PBUF_POOL_FREE_OOSEQ 1 +#endif /* PBUF_POOL_FREE_OOSEQ */ +#if LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ +extern volatile u8_t pbuf_free_ooseq_pending; +void pbuf_free_ooseq(void); +/** When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ() + at regular intervals from main level to check if ooseq pbufs need to be + freed! */ +#define PBUF_CHECK_FREE_OOSEQ() do { if(pbuf_free_ooseq_pending) { \ + /* pbuf_alloc() reported PBUF_POOL to be empty -> try to free some \ + ooseq queued pbufs now */ \ + pbuf_free_ooseq(); }}while(0) +#else /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ */ + /* Otherwise declare an empty PBUF_CHECK_FREE_OOSEQ */ + #define PBUF_CHECK_FREE_OOSEQ() +#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && NO_SYS && PBUF_POOL_FREE_OOSEQ*/ + +/* Initializes the pbuf module. This call is empty for now, but may not be in future. */ +#define pbuf_init() + +struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type); +struct pbuf *pbuf_alloc_reference(void *payload, u16_t length, pbuf_type type); +#if LWIP_SUPPORT_CUSTOM_PBUF +struct pbuf *pbuf_alloced_custom(pbuf_layer l, u16_t length, pbuf_type type, + struct pbuf_custom *p, void *payload_mem, + u16_t payload_mem_len); +#endif /* LWIP_SUPPORT_CUSTOM_PBUF */ +void pbuf_realloc(struct pbuf *p, u16_t size); +#define pbuf_get_allocsrc(p) ((p)->type_internal & PBUF_TYPE_ALLOC_SRC_MASK) +#define pbuf_match_allocsrc(p, type) (pbuf_get_allocsrc(p) == ((type) & PBUF_TYPE_ALLOC_SRC_MASK)) +#define pbuf_match_type(p, type) pbuf_match_allocsrc(p, type) +u8_t pbuf_header(struct pbuf *p, s16_t header_size); +u8_t pbuf_header_force(struct pbuf *p, s16_t header_size); +u8_t pbuf_add_header(struct pbuf *p, size_t header_size_increment); +u8_t pbuf_add_header_force(struct pbuf *p, size_t header_size_increment); +u8_t pbuf_remove_header(struct pbuf *p, size_t header_size); +struct pbuf *pbuf_free_header(struct pbuf *q, u16_t size); +void pbuf_ref(struct pbuf *p); +u8_t pbuf_free(struct pbuf *p); +u16_t pbuf_clen(const struct pbuf *p); +void pbuf_cat(struct pbuf *head, struct pbuf *tail); +void pbuf_chain(struct pbuf *head, struct pbuf *tail); +struct pbuf *pbuf_dechain(struct pbuf *p); +err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from); +err_t pbuf_copy_partial_pbuf(struct pbuf *p_to, const struct pbuf *p_from, u16_t copy_len, u16_t offset); +u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset); +void *pbuf_get_contiguous(const struct pbuf *p, void *buffer, size_t bufsize, u16_t len, u16_t offset); +err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len); +err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset); +struct pbuf *pbuf_skip(struct pbuf* in, u16_t in_offset, u16_t* out_offset); +struct pbuf *pbuf_coalesce(struct pbuf *p, pbuf_layer layer); +struct pbuf *pbuf_clone(pbuf_layer l, pbuf_type type, struct pbuf *p); +#if LWIP_CHECKSUM_ON_COPY +err_t pbuf_fill_chksum(struct pbuf *p, u16_t start_offset, const void *dataptr, + u16_t len, u16_t *chksum); +#endif /* LWIP_CHECKSUM_ON_COPY */ +#if LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE +void pbuf_split_64k(struct pbuf *p, struct pbuf **rest); +#endif /* LWIP_TCP && TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */ + +u8_t pbuf_get_at(const struct pbuf* p, u16_t offset); +int pbuf_try_get_at(const struct pbuf* p, u16_t offset); +void pbuf_put_at(struct pbuf* p, u16_t offset, u8_t data); +u16_t pbuf_memcmp(const struct pbuf* p, u16_t offset, const void* s2, u16_t n); +u16_t pbuf_memfind(const struct pbuf* p, const void* mem, u16_t mem_len, u16_t start_offset); +u16_t pbuf_strstr(const struct pbuf* p, const char* substr); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PBUF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/altcp_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/altcp_priv.h new file mode 100644 index 000000000..d1de9b111 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/altcp_priv.h @@ -0,0 +1,159 @@ +/** + * @file + * Application layered TCP connection API (to be used from TCPIP thread)\n + * This interface mimics the tcp callback API to the application while preventing + * direct linking (much like virtual functions). + * This way, an application can make use of other application layer protocols + * on top of TCP without knowing the details (e.g. TLS, proxy connection). + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_ALTCP_PRIV_H +#define LWIP_HDR_ALTCP_PRIV_H + +#include "lwip/opt.h" + +#if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/altcp.h" +#include "lwip/ip_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct altcp_pcb *altcp_alloc(void); +void altcp_free(struct altcp_pcb *conn); + +/* Function prototypes for application layers */ +typedef void (*altcp_set_poll_fn)(struct altcp_pcb *conn, u8_t interval); +typedef void (*altcp_recved_fn)(struct altcp_pcb *conn, u16_t len); +typedef err_t (*altcp_bind_fn)(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port); +typedef err_t (*altcp_connect_fn)(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected); + +typedef struct altcp_pcb *(*altcp_listen_fn)(struct altcp_pcb *conn, u8_t backlog, err_t *err); + +typedef void (*altcp_abort_fn)(struct altcp_pcb *conn); +typedef err_t (*altcp_close_fn)(struct altcp_pcb *conn); +typedef err_t (*altcp_shutdown_fn)(struct altcp_pcb *conn, int shut_rx, int shut_tx); + +typedef err_t (*altcp_write_fn)(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags); +typedef err_t (*altcp_output_fn)(struct altcp_pcb *conn); + +typedef u16_t (*altcp_mss_fn)(struct altcp_pcb *conn); +typedef u16_t (*altcp_sndbuf_fn)(struct altcp_pcb *conn); +typedef u16_t (*altcp_sndqueuelen_fn)(struct altcp_pcb *conn); +typedef void (*altcp_nagle_disable_fn)(struct altcp_pcb *conn); +typedef void (*altcp_nagle_enable_fn)(struct altcp_pcb *conn); +typedef int (*altcp_nagle_disabled_fn)(struct altcp_pcb *conn); + +typedef void (*altcp_setprio_fn)(struct altcp_pcb *conn, u8_t prio); + +typedef void (*altcp_dealloc_fn)(struct altcp_pcb *conn); + +typedef err_t (*altcp_get_tcp_addrinfo_fn)(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port); +typedef ip_addr_t *(*altcp_get_ip_fn)(struct altcp_pcb *conn, int local); +typedef u16_t (*altcp_get_port_fn)(struct altcp_pcb *conn, int local); + +#if LWIP_TCP_KEEPALIVE +typedef void (*altcp_keepalive_disable_fn)(struct altcp_pcb *conn); +typedef void (*altcp_keepalive_enable_fn)(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count); +#endif + +#ifdef LWIP_DEBUG +typedef enum tcp_state (*altcp_dbg_get_tcp_state_fn)(struct altcp_pcb *conn); +#endif + +struct altcp_functions { + altcp_set_poll_fn set_poll; + altcp_recved_fn recved; + altcp_bind_fn bind; + altcp_connect_fn connect; + altcp_listen_fn listen; + altcp_abort_fn abort; + altcp_close_fn close; + altcp_shutdown_fn shutdown; + altcp_write_fn write; + altcp_output_fn output; + altcp_mss_fn mss; + altcp_sndbuf_fn sndbuf; + altcp_sndqueuelen_fn sndqueuelen; + altcp_nagle_disable_fn nagle_disable; + altcp_nagle_enable_fn nagle_enable; + altcp_nagle_disabled_fn nagle_disabled; + altcp_setprio_fn setprio; + altcp_dealloc_fn dealloc; + altcp_get_tcp_addrinfo_fn addrinfo; + altcp_get_ip_fn getip; + altcp_get_port_fn getport; +#if LWIP_TCP_KEEPALIVE + altcp_keepalive_disable_fn keepalive_disable; + altcp_keepalive_enable_fn keepalive_enable; +#endif +#ifdef LWIP_DEBUG + altcp_dbg_get_tcp_state_fn dbg_get_tcp_state; +#endif +}; + +void altcp_default_set_poll(struct altcp_pcb *conn, u8_t interval); +void altcp_default_recved(struct altcp_pcb *conn, u16_t len); +err_t altcp_default_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port); +err_t altcp_default_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx); +err_t altcp_default_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags); +err_t altcp_default_output(struct altcp_pcb *conn); +u16_t altcp_default_mss(struct altcp_pcb *conn); +u16_t altcp_default_sndbuf(struct altcp_pcb *conn); +u16_t altcp_default_sndqueuelen(struct altcp_pcb *conn); +void altcp_default_nagle_disable(struct altcp_pcb *conn); +void altcp_default_nagle_enable(struct altcp_pcb *conn); +int altcp_default_nagle_disabled(struct altcp_pcb *conn); +void altcp_default_setprio(struct altcp_pcb *conn, u8_t prio); +void altcp_default_dealloc(struct altcp_pcb *conn); +err_t altcp_default_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port); +ip_addr_t *altcp_default_get_ip(struct altcp_pcb *conn, int local); +u16_t altcp_default_get_port(struct altcp_pcb *conn, int local); +#if LWIP_TCP_KEEPALIVE +void altcp_default_keepalive_disable(struct altcp_pcb *conn); +void altcp_default_keepalive_enable(struct altcp_pcb *conn, u32_t idle, u32_t intvl, u32_t count); +#endif +#ifdef LWIP_DEBUG +enum tcp_state altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_ALTCP */ + +#endif /* LWIP_HDR_ALTCP_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/api_msg.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/api_msg.h new file mode 100644 index 000000000..9e8ffc9ea --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/api_msg.h @@ -0,0 +1,272 @@ +/** + * @file + * netconn API lwIP internal implementations (do not use in application code) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_API_MSG_H +#define LWIP_HDR_API_MSG_H + +#include "lwip/opt.h" + +#include "lwip/arch.h" +#include "lwip/ip_addr.h" +#include "lwip/err.h" +#include "lwip/sys.h" +#include "lwip/igmp.h" +#include "lwip/api.h" +#include "lwip/priv/tcpip_priv.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ +/* Note: Netconn API is always available when sockets are enabled - + * sockets are implemented on top of them */ + +#if LWIP_MPU_COMPATIBLE +#if LWIP_NETCONN_SEM_PER_THREAD +#define API_MSG_M_DEF_SEM(m) *m +#else +#define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m) +#endif +#else /* LWIP_MPU_COMPATIBLE */ +#define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m) +#endif /* LWIP_MPU_COMPATIBLE */ + +/* For the netconn API, these values are use as a bitmask! */ +#define NETCONN_SHUT_RD 1 +#define NETCONN_SHUT_WR 2 +#define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR) + +/* IP addresses and port numbers are expected to be in + * the same byte order as in the corresponding pcb. + */ +/** This struct includes everything that is necessary to execute a function + for a netconn in another thread context (mainly used to process netconns + in the tcpip_thread context to be thread safe). */ +struct api_msg { + /** The netconn which to process - always needed: it includes the semaphore + which is used to block the application thread until the function finished. */ + struct netconn *conn; + /** The return value of the function executed in tcpip_thread. */ + err_t err; + /** Depending on the executed function, one of these union members is used */ + union { + /** used for lwip_netconn_do_send */ + struct netbuf *b; + /** used for lwip_netconn_do_newconn */ + struct { + u8_t proto; + } n; + /** used for lwip_netconn_do_bind and lwip_netconn_do_connect */ + struct { + API_MSG_M_DEF_C(ip_addr_t, ipaddr); + u16_t port; + u8_t if_idx; + } bc; + /** used for lwip_netconn_do_getaddr */ + struct { + ip_addr_t API_MSG_M_DEF(ipaddr); + u16_t API_MSG_M_DEF(port); + u8_t local; + } ad; + /** used for lwip_netconn_do_write */ + struct { + /** current vector to write */ + const struct netvector *vector; + /** number of unwritten vectors */ + u16_t vector_cnt; + /** offset into current vector */ + size_t vector_off; + /** total length across vectors */ + size_t len; + /** offset into total length/output of bytes written when err == ERR_OK */ + size_t offset; + u8_t apiflags; +#if LWIP_SO_SNDTIMEO + u32_t time_started; +#endif /* LWIP_SO_SNDTIMEO */ + } w; + /** used for lwip_netconn_do_recv */ + struct { + size_t len; + } r; +#if LWIP_TCP + /** used for lwip_netconn_do_close (/shutdown) */ + struct { + u8_t shut; +#if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER + u32_t time_started; +#else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ + u8_t polls_left; +#endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */ + } sd; +#endif /* LWIP_TCP */ +#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) + /** used for lwip_netconn_do_join_leave_group */ + struct { + API_MSG_M_DEF_C(ip_addr_t, multiaddr); + API_MSG_M_DEF_C(ip_addr_t, netif_addr); + u8_t if_idx; + enum netconn_igmp join_or_leave; + } jl; +#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ +#if TCP_LISTEN_BACKLOG + struct { + u8_t backlog; + } lb; +#endif /* TCP_LISTEN_BACKLOG */ + } msg; +#if LWIP_NETCONN_SEM_PER_THREAD + sys_sem_t* op_completed_sem; +#endif /* LWIP_NETCONN_SEM_PER_THREAD */ +}; + +#if LWIP_NETCONN_SEM_PER_THREAD +#define LWIP_API_MSG_SEM(msg) ((msg)->op_completed_sem) +#else /* LWIP_NETCONN_SEM_PER_THREAD */ +#define LWIP_API_MSG_SEM(msg) (&(msg)->conn->op_completed) +#endif /* LWIP_NETCONN_SEM_PER_THREAD */ + + +#if LWIP_DNS +/** As lwip_netconn_do_gethostbyname requires more arguments but doesn't require a netconn, + it has its own struct (to avoid struct api_msg getting bigger than necessary). + lwip_netconn_do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg + (see netconn_gethostbyname). */ +struct dns_api_msg { + /** Hostname to query or dotted IP address string */ +#if LWIP_MPU_COMPATIBLE + char name[DNS_MAX_NAME_LENGTH]; +#else /* LWIP_MPU_COMPATIBLE */ + const char *name; +#endif /* LWIP_MPU_COMPATIBLE */ + /** The resolved address is stored here */ + ip_addr_t API_MSG_M_DEF(addr); +#if LWIP_IPV4 && LWIP_IPV6 + /** Type of resolve call */ + u8_t dns_addrtype; +#endif /* LWIP_IPV4 && LWIP_IPV6 */ + /** This semaphore is posted when the name is resolved, the application thread + should wait on it. */ + sys_sem_t API_MSG_M_DEF_SEM(sem); + /** Errors are given back here */ + err_t API_MSG_M_DEF(err); +}; +#endif /* LWIP_DNS */ + +#if LWIP_NETCONN_FULLDUPLEX +int lwip_netconn_is_deallocated_msg(void *msg); +#endif +int lwip_netconn_is_err_msg(void *msg, err_t *err); +void lwip_netconn_do_newconn (void *m); +void lwip_netconn_do_delconn (void *m); +void lwip_netconn_do_bind (void *m); +void lwip_netconn_do_bind_if (void *m); +void lwip_netconn_do_connect (void *m); +void lwip_netconn_do_disconnect (void *m); +void lwip_netconn_do_listen (void *m); +void lwip_netconn_do_send (void *m); +void lwip_netconn_do_recv (void *m); +#if TCP_LISTEN_BACKLOG +void lwip_netconn_do_accepted (void *m); +#endif /* TCP_LISTEN_BACKLOG */ +void lwip_netconn_do_write (void *m); +void lwip_netconn_do_getaddr (void *m); +void lwip_netconn_do_close (void *m); +void lwip_netconn_do_shutdown (void *m); +#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) +void lwip_netconn_do_join_leave_group(void *m); +void lwip_netconn_do_join_leave_group_netif(void *m); +#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ + +#if LWIP_DNS +void lwip_netconn_do_gethostbyname(void *arg); +#endif /* LWIP_DNS */ + +struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback); +void netconn_free(struct netconn *conn); + +#endif /* LWIP_NETCONN || LWIP_SOCKET */ + +#if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */ + +/* netifapi related lwIP internal definitions */ + +#if LWIP_MPU_COMPATIBLE +#define NETIFAPI_IPADDR_DEF(type, m) type m +#else /* LWIP_MPU_COMPATIBLE */ +#define NETIFAPI_IPADDR_DEF(type, m) const type * m +#endif /* LWIP_MPU_COMPATIBLE */ + +typedef void (*netifapi_void_fn)(struct netif *netif); +typedef err_t (*netifapi_errt_fn)(struct netif *netif); + +struct netifapi_msg { + struct tcpip_api_call_data call; + struct netif *netif; + union { + struct { +#if LWIP_IPV4 + NETIFAPI_IPADDR_DEF(ip4_addr_t, ipaddr); + NETIFAPI_IPADDR_DEF(ip4_addr_t, netmask); + NETIFAPI_IPADDR_DEF(ip4_addr_t, gw); +#endif /* LWIP_IPV4 */ + void *state; + netif_init_fn init; + netif_input_fn input; + } add; + struct { + netifapi_void_fn voidfunc; + netifapi_errt_fn errtfunc; + } common; + struct { +#if LWIP_MPU_COMPATIBLE + char name[NETIF_NAMESIZE]; +#else /* LWIP_MPU_COMPATIBLE */ + char *name; +#endif /* LWIP_MPU_COMPATIBLE */ + u8_t index; + } ifs; + } msg; +}; + +#endif /* LWIP_NETIF_API */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_API_MSG_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/mem_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/mem_priv.h new file mode 100644 index 000000000..8630d7541 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/mem_priv.h @@ -0,0 +1,84 @@ +/** + * @file + * lwIP internal memory implementations (do not use in application code) + */ + +/* + * Copyright (c) 2018 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ + +#ifndef LWIP_HDR_MEM_PRIV_H +#define LWIP_HDR_MEM_PRIV_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "lwip/mem.h" + +#if MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK +/* if MEM_OVERFLOW_CHECK or MEMP_OVERFLOW_CHECK is turned on, we reserve some + * bytes at the beginning and at the end of each element, initialize them as + * 0xcd and check them later. + * If MEM(P)_OVERFLOW_CHECK is >= 2, on every call to mem(p)_malloc or mem(p)_free, + * every single element in each pool/heap is checked! + * This is VERY SLOW but also very helpful. + * MEM_SANITY_REGION_BEFORE and MEM_SANITY_REGION_AFTER can be overridden in + * lwipopts.h to change the amount reserved for checking. */ +#ifndef MEM_SANITY_REGION_BEFORE +#define MEM_SANITY_REGION_BEFORE 16 +#endif /* MEM_SANITY_REGION_BEFORE*/ +#if MEM_SANITY_REGION_BEFORE > 0 +#define MEM_SANITY_REGION_BEFORE_ALIGNED LWIP_MEM_ALIGN_SIZE(MEM_SANITY_REGION_BEFORE) +#else +#define MEM_SANITY_REGION_BEFORE_ALIGNED 0 +#endif /* MEM_SANITY_REGION_BEFORE*/ +#ifndef MEM_SANITY_REGION_AFTER +#define MEM_SANITY_REGION_AFTER 16 +#endif /* MEM_SANITY_REGION_AFTER*/ +#if MEM_SANITY_REGION_AFTER > 0 +#define MEM_SANITY_REGION_AFTER_ALIGNED LWIP_MEM_ALIGN_SIZE(MEM_SANITY_REGION_AFTER) +#else +#define MEM_SANITY_REGION_AFTER_ALIGNED 0 +#endif /* MEM_SANITY_REGION_AFTER*/ + +void mem_overflow_init_raw(void *p, size_t size); +void mem_overflow_check_raw(void *p, size_t size, const char *descr1, const char *descr2); + +#endif /* MEM_OVERFLOW_CHECK || MEMP_OVERFLOW_CHECK */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_MEMP_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/memp_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/memp_priv.h new file mode 100644 index 000000000..1f14cb162 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/memp_priv.h @@ -0,0 +1,161 @@ +/** + * @file + * memory pools lwIP internal implementations (do not use in application code) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +#ifndef LWIP_HDR_MEMP_PRIV_H +#define LWIP_HDR_MEMP_PRIV_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "lwip/mem.h" +#include "lwip/priv/mem_priv.h" + +#if MEMP_OVERFLOW_CHECK + + +/* MEMP_SIZE: save space for struct memp and for sanity check */ +#define MEMP_SIZE (LWIP_MEM_ALIGN_SIZE(sizeof(struct memp)) + MEM_SANITY_REGION_BEFORE_ALIGNED) +#define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x) + MEM_SANITY_REGION_AFTER_ALIGNED) + +#else /* MEMP_OVERFLOW_CHECK */ + +/* No sanity checks + * We don't need to preserve the struct memp while not allocated, so we + * can save a little space and set MEMP_SIZE to 0. + */ +#define MEMP_SIZE 0 +#define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x)) + +#endif /* MEMP_OVERFLOW_CHECK */ + +#if !MEMP_MEM_MALLOC || MEMP_OVERFLOW_CHECK +struct memp { + struct memp *next; +#if MEMP_OVERFLOW_CHECK + const char *file; + int line; +#endif /* MEMP_OVERFLOW_CHECK */ +}; +#endif /* !MEMP_MEM_MALLOC || MEMP_OVERFLOW_CHECK */ + +#if MEM_USE_POOLS && MEMP_USE_CUSTOM_POOLS +/* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */ +typedef enum { + /* Get the first (via: + MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/ + MEMP_POOL_HELPER_FIRST = ((u8_t) +#define LWIP_MEMPOOL(name,num,size,desc) +#define LWIP_MALLOC_MEMPOOL_START 1 +#define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0 +#define LWIP_MALLOC_MEMPOOL_END +#include "lwip/priv/memp_std.h" + ) , + /* Get the last (via: + MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */ + MEMP_POOL_HELPER_LAST = ((u8_t) +#define LWIP_MEMPOOL(name,num,size,desc) +#define LWIP_MALLOC_MEMPOOL_START +#define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size * +#define LWIP_MALLOC_MEMPOOL_END 1 +#include "lwip/priv/memp_std.h" + ) +} memp_pool_helper_t; + +/* The actual start and stop values are here (cast them over) + We use this helper type and these defines so we can avoid using const memp_t values */ +#define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST) +#define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST) +#endif /* MEM_USE_POOLS && MEMP_USE_CUSTOM_POOLS */ + +/** Memory pool descriptor */ +struct memp_desc { +#if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY + /** Textual description */ + const char *desc; +#endif /* LWIP_DEBUG || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY */ +#if MEMP_STATS + /** Statistics */ + struct stats_mem *stats; +#endif + + /** Element size */ + u16_t size; + +#if !MEMP_MEM_MALLOC + /** Number of elements */ + u16_t num; + + /** Base address */ + u8_t *base; + + /** First free element of each pool. Elements form a linked list. */ + struct memp **tab; +#endif /* MEMP_MEM_MALLOC */ +}; + +#if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK || LWIP_STATS_DISPLAY +#define DECLARE_LWIP_MEMPOOL_DESC(desc) (desc), +#else +#define DECLARE_LWIP_MEMPOOL_DESC(desc) +#endif + +#if MEMP_STATS +#define LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(name) static struct stats_mem name; +#define LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(name) &name, +#else +#define LWIP_MEMPOOL_DECLARE_STATS_INSTANCE(name) +#define LWIP_MEMPOOL_DECLARE_STATS_REFERENCE(name) +#endif + +void memp_init_pool(const struct memp_desc *desc); + +#if MEMP_OVERFLOW_CHECK +void *memp_malloc_pool_fn(const struct memp_desc* desc, const char* file, const int line); +#define memp_malloc_pool(d) memp_malloc_pool_fn((d), __FILE__, __LINE__) +#else +void *memp_malloc_pool(const struct memp_desc *desc); +#endif +void memp_free_pool(const struct memp_desc* desc, void *mem); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_MEMP_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/memp_std.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/memp_std.h new file mode 100644 index 000000000..669ad4d7e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/memp_std.h @@ -0,0 +1,153 @@ +/** + * @file + * lwIP internal memory pools (do not use in application code) + * This file is deliberately included multiple times: once with empty + * definition of LWIP_MEMPOOL() to handle all includes and multiple times + * to build up various lists of mem pools. + */ + +/* + * SETUP: Make sure we define everything we will need. + * + * We have create three types of pools: + * 1) MEMPOOL - standard pools + * 2) MALLOC_MEMPOOL - to be used by mem_malloc in mem.c + * 3) PBUF_MEMPOOL - a mempool of pbuf's, so include space for the pbuf struct + * + * If the include'r doesn't require any special treatment of each of the types + * above, then will declare #2 & #3 to be just standard mempools. + */ +#ifndef LWIP_MALLOC_MEMPOOL +/* This treats "malloc pools" just like any other pool. + The pools are a little bigger to provide 'size' as the amount of user data. */ +#define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper))), "MALLOC_"#size) +#define LWIP_MALLOC_MEMPOOL_START +#define LWIP_MALLOC_MEMPOOL_END +#endif /* LWIP_MALLOC_MEMPOOL */ + +#ifndef LWIP_PBUF_MEMPOOL +/* This treats "pbuf pools" just like any other pool. + * Allocates buffers for a pbuf struct AND a payload size */ +#define LWIP_PBUF_MEMPOOL(name, num, payload, desc) LWIP_MEMPOOL(name, num, (LWIP_MEM_ALIGN_SIZE(sizeof(struct pbuf)) + LWIP_MEM_ALIGN_SIZE(payload)), desc) +#endif /* LWIP_PBUF_MEMPOOL */ + + +/* + * A list of internal pools used by LWIP. + * + * LWIP_MEMPOOL(pool_name, number_elements, element_size, pool_description) + * creates a pool name MEMP_pool_name. description is used in stats.c + */ +#if LWIP_RAW +LWIP_MEMPOOL(RAW_PCB, MEMP_NUM_RAW_PCB, sizeof(struct raw_pcb), "RAW_PCB") +#endif /* LWIP_RAW */ + +#if LWIP_UDP +LWIP_MEMPOOL(UDP_PCB, MEMP_NUM_UDP_PCB, sizeof(struct udp_pcb), "UDP_PCB") +#endif /* LWIP_UDP */ + +#if LWIP_TCP +LWIP_MEMPOOL(TCP_PCB, MEMP_NUM_TCP_PCB, sizeof(struct tcp_pcb), "TCP_PCB") +LWIP_MEMPOOL(TCP_PCB_LISTEN, MEMP_NUM_TCP_PCB_LISTEN, sizeof(struct tcp_pcb_listen), "TCP_PCB_LISTEN") +LWIP_MEMPOOL(TCP_SEG, MEMP_NUM_TCP_SEG, sizeof(struct tcp_seg), "TCP_SEG") +#endif /* LWIP_TCP */ + +#if LWIP_ALTCP && LWIP_TCP +LWIP_MEMPOOL(ALTCP_PCB, MEMP_NUM_ALTCP_PCB, sizeof(struct altcp_pcb), "ALTCP_PCB") +#endif /* LWIP_ALTCP && LWIP_TCP */ + +#if LWIP_IPV4 && IP_REASSEMBLY +LWIP_MEMPOOL(REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip_reassdata), "REASSDATA") +#endif /* LWIP_IPV4 && IP_REASSEMBLY */ +#if (IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF) || (LWIP_IPV6 && LWIP_IPV6_FRAG) +LWIP_MEMPOOL(FRAG_PBUF, MEMP_NUM_FRAG_PBUF, sizeof(struct pbuf_custom_ref),"FRAG_PBUF") +#endif /* IP_FRAG && !LWIP_NETIF_TX_SINGLE_PBUF || (LWIP_IPV6 && LWIP_IPV6_FRAG) */ + +#if LWIP_NETCONN || LWIP_SOCKET +LWIP_MEMPOOL(NETBUF, MEMP_NUM_NETBUF, sizeof(struct netbuf), "NETBUF") +LWIP_MEMPOOL(NETCONN, MEMP_NUM_NETCONN, sizeof(struct netconn), "NETCONN") +#endif /* LWIP_NETCONN || LWIP_SOCKET */ + +#if NO_SYS==0 +LWIP_MEMPOOL(TCPIP_MSG_API, MEMP_NUM_TCPIP_MSG_API, sizeof(struct tcpip_msg), "TCPIP_MSG_API") +#if LWIP_MPU_COMPATIBLE +LWIP_MEMPOOL(API_MSG, MEMP_NUM_API_MSG, sizeof(struct api_msg), "API_MSG") +#if LWIP_DNS +LWIP_MEMPOOL(DNS_API_MSG, MEMP_NUM_DNS_API_MSG, sizeof(struct dns_api_msg), "DNS_API_MSG") +#endif +#if LWIP_SOCKET && !LWIP_TCPIP_CORE_LOCKING +LWIP_MEMPOOL(SOCKET_SETGETSOCKOPT_DATA, MEMP_NUM_SOCKET_SETGETSOCKOPT_DATA, sizeof(struct lwip_setgetsockopt_data), "SOCKET_SETGETSOCKOPT_DATA") +#endif +#if LWIP_SOCKET && (LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL) +LWIP_MEMPOOL(SELECT_CB, MEMP_NUM_SELECT_CB, sizeof(struct lwip_select_cb), "SELECT_CB") +#endif /* LWIP_SOCKET && (LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL) */ +#if LWIP_NETIF_API +LWIP_MEMPOOL(NETIFAPI_MSG, MEMP_NUM_NETIFAPI_MSG, sizeof(struct netifapi_msg), "NETIFAPI_MSG") +#endif +#endif /* LWIP_MPU_COMPATIBLE */ +#if !LWIP_TCPIP_CORE_LOCKING_INPUT +LWIP_MEMPOOL(TCPIP_MSG_INPKT,MEMP_NUM_TCPIP_MSG_INPKT, sizeof(struct tcpip_msg), "TCPIP_MSG_INPKT") +#endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ +#endif /* NO_SYS==0 */ + +#if LWIP_IPV4 && LWIP_ARP && ARP_QUEUEING +LWIP_MEMPOOL(ARP_QUEUE, MEMP_NUM_ARP_QUEUE, sizeof(struct etharp_q_entry), "ARP_QUEUE") +#endif /* LWIP_IPV4 && LWIP_ARP && ARP_QUEUEING */ + +#if LWIP_IGMP +LWIP_MEMPOOL(IGMP_GROUP, MEMP_NUM_IGMP_GROUP, sizeof(struct igmp_group), "IGMP_GROUP") +#endif /* LWIP_IGMP */ + +#if LWIP_TIMERS && !LWIP_TIMERS_CUSTOM +LWIP_MEMPOOL(SYS_TIMEOUT, MEMP_NUM_SYS_TIMEOUT, sizeof(struct sys_timeo), "SYS_TIMEOUT") +#endif /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */ + +#if LWIP_DNS && LWIP_SOCKET +LWIP_MEMPOOL(NETDB, MEMP_NUM_NETDB, NETDB_ELEM_SIZE, "NETDB") +#endif /* LWIP_DNS && LWIP_SOCKET */ +#if LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC +LWIP_MEMPOOL(LOCALHOSTLIST, MEMP_NUM_LOCALHOSTLIST, LOCALHOSTLIST_ELEM_SIZE, "LOCALHOSTLIST") +#endif /* LWIP_DNS && DNS_LOCAL_HOSTLIST && DNS_LOCAL_HOSTLIST_IS_DYNAMIC */ + +#if LWIP_IPV6 && LWIP_ND6_QUEUEING +LWIP_MEMPOOL(ND6_QUEUE, MEMP_NUM_ND6_QUEUE, sizeof(struct nd6_q_entry), "ND6_QUEUE") +#endif /* LWIP_IPV6 && LWIP_ND6_QUEUEING */ + +#if LWIP_IPV6 && LWIP_IPV6_REASS +LWIP_MEMPOOL(IP6_REASSDATA, MEMP_NUM_REASSDATA, sizeof(struct ip6_reassdata), "IP6_REASSDATA") +#endif /* LWIP_IPV6 && LWIP_IPV6_REASS */ + +#if LWIP_IPV6 && LWIP_IPV6_MLD +LWIP_MEMPOOL(MLD6_GROUP, MEMP_NUM_MLD6_GROUP, sizeof(struct mld_group), "MLD6_GROUP") +#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ + + +/* + * A list of pools of pbuf's used by LWIP. + * + * LWIP_PBUF_MEMPOOL(pool_name, number_elements, pbuf_payload_size, pool_description) + * creates a pool name MEMP_pool_name. description is used in stats.c + * This allocates enough space for the pbuf struct and a payload. + * (Example: pbuf_payload_size=0 allocates only size for the struct) + */ +LWIP_MEMPOOL(PBUF, MEMP_NUM_PBUF, sizeof(struct pbuf), "PBUF_REF/ROM") +LWIP_PBUF_MEMPOOL(PBUF_POOL, PBUF_POOL_SIZE, PBUF_POOL_BUFSIZE, "PBUF_POOL") + + +/* + * Allow for user-defined pools; this must be explicitly set in lwipopts.h + * since the default is to NOT look for lwippools.h + */ +#if MEMP_USE_CUSTOM_POOLS +#include "lwippools.h" +#endif /* MEMP_USE_CUSTOM_POOLS */ + +/* + * REQUIRED CLEANUP: Clear up so we don't get "multiply defined" error later + * (#undef is ignored for something that is not defined) + */ +#undef LWIP_MEMPOOL +#undef LWIP_MALLOC_MEMPOOL +#undef LWIP_MALLOC_MEMPOOL_START +#undef LWIP_MALLOC_MEMPOOL_END +#undef LWIP_PBUF_MEMPOOL diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/nd6_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/nd6_priv.h new file mode 100644 index 000000000..cc3007d97 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/nd6_priv.h @@ -0,0 +1,142 @@ +/** + * @file + * + * Neighbor discovery and stateless address autoconfiguration for IPv6. + * Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862 + * (Address autoconfiguration). + */ + +/* + * Copyright (c) 2010 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ + +#ifndef LWIP_HDR_ND6_PRIV_H +#define LWIP_HDR_ND6_PRIV_H + +#include "lwip/opt.h" + +#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/pbuf.h" +#include "lwip/ip6_addr.h" +#include "lwip/netif.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_ND6_QUEUEING +/** struct for queueing outgoing packets for unknown address + * defined here to be accessed by memp.h + */ +struct nd6_q_entry { + struct nd6_q_entry *next; + struct pbuf *p; +}; +#endif /* LWIP_ND6_QUEUEING */ + +/** Struct for tables. */ +struct nd6_neighbor_cache_entry { + ip6_addr_t next_hop_address; + struct netif *netif; + u8_t lladdr[NETIF_MAX_HWADDR_LEN]; + /*u32_t pmtu;*/ +#if LWIP_ND6_QUEUEING + /** Pointer to queue of pending outgoing packets on this entry. */ + struct nd6_q_entry *q; +#else /* LWIP_ND6_QUEUEING */ + /** Pointer to a single pending outgoing packet on this entry. */ + struct pbuf *q; +#endif /* LWIP_ND6_QUEUEING */ + u8_t state; + u8_t isrouter; + union { + u32_t reachable_time; /* in seconds */ + u32_t delay_time; /* ticks (ND6_TMR_INTERVAL) */ + u32_t probes_sent; + u32_t stale_time; /* ticks (ND6_TMR_INTERVAL) */ + } counter; +}; + +struct nd6_destination_cache_entry { + ip6_addr_t destination_addr; + ip6_addr_t next_hop_addr; + u16_t pmtu; + u32_t age; +}; + +struct nd6_prefix_list_entry { + ip6_addr_t prefix; + struct netif *netif; + u32_t invalidation_timer; /* in seconds */ +}; + +struct nd6_router_list_entry { + struct nd6_neighbor_cache_entry *neighbor_entry; + u32_t invalidation_timer; /* in seconds */ + u8_t flags; +}; + +enum nd6_neighbor_cache_entry_state { + ND6_NO_ENTRY = 0, + ND6_INCOMPLETE, + ND6_REACHABLE, + ND6_STALE, + ND6_DELAY, + ND6_PROBE +}; + +#define ND6_HOPLIM 255 /* maximum hop limit, required in all ND packets */ + +#define ND6_2HRS 7200 /* two hours, expressed in number of seconds */ + +/* Router tables. */ +/* @todo make these static? and entries accessible through API? */ +extern struct nd6_neighbor_cache_entry neighbor_cache[]; +extern struct nd6_destination_cache_entry destination_cache[]; +extern struct nd6_prefix_list_entry prefix_list[]; +extern struct nd6_router_list_entry default_router_list[]; + +/* Default values, can be updated by a RA message. */ +extern u32_t reachable_time; +extern u32_t retrans_timer; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 */ + +#endif /* LWIP_HDR_ND6_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/raw_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/raw_priv.h new file mode 100644 index 000000000..d4561d4f3 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/raw_priv.h @@ -0,0 +1,69 @@ +/** + * @file + * raw API internal implementations (do not use in application code) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_RAW_PRIV_H +#define LWIP_HDR_RAW_PRIV_H + +#include "lwip/opt.h" + +#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/raw.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** return codes for raw_input */ +typedef enum raw_input_state +{ + RAW_INPUT_NONE = 0, /* pbuf did not match any pcbs */ + RAW_INPUT_EATEN, /* pbuf handed off and delivered to pcb */ + RAW_INPUT_DELIVERED /* pbuf only delivered to pcb (pbuf can still be referenced) */ +} raw_input_state_t; + +/* The following functions are the lower layer interface to RAW. */ +raw_input_state_t raw_input(struct pbuf *p, struct netif *inp); + +void raw_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_RAW */ + +#endif /* LWIP_HDR_RAW_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/sockets_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/sockets_priv.h new file mode 100644 index 000000000..d8f9904dc --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/sockets_priv.h @@ -0,0 +1,175 @@ +/** + * @file + * Sockets API internal implementations (do not use in application code) + */ + +/* + * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Joel Cunningham + * + */ +#ifndef LWIP_HDR_SOCKETS_PRIV_H +#define LWIP_HDR_SOCKETS_PRIV_H + +#include "lwip/opt.h" + +#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/err.h" +#include "lwip/sockets.h" +#include "lwip/sys.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NUM_SOCKETS MEMP_NUM_NETCONN + +/** This is overridable for the rare case where more than 255 threads + * select on the same socket... + */ +#ifndef SELWAIT_T +#define SELWAIT_T u8_t +#endif + +union lwip_sock_lastdata { + struct netbuf *netbuf; + struct pbuf *pbuf; +}; + +/** Contains all internal pointers and states used for a socket */ +struct lwip_sock { + /** sockets currently are built on netconns, each socket has one netconn */ + struct netconn *conn; + /** data that was left from the previous read */ + union lwip_sock_lastdata lastdata; +#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL + /** number of times data was received, set by event_callback(), + tested by the receive and select functions */ + s16_t rcvevent; + /** number of times data was ACKed (free send buffer), set by event_callback(), + tested by select */ + u16_t sendevent; + /** error happened for this socket, set by event_callback(), tested by select */ + u16_t errevent; + /** counter of how many threads are waiting for this socket using select */ + SELWAIT_T select_waiting; +#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ +#if LWIP_NETCONN_FULLDUPLEX + /* counter of how many threads are using a struct lwip_sock (not the 'int') */ + u8_t fd_used; + /* status of pending close/delete actions */ + u8_t fd_free_pending; +#define LWIP_SOCK_FD_FREE_TCP 1 +#define LWIP_SOCK_FD_FREE_FREE 2 +#endif +}; + +#ifndef set_errno +#define set_errno(err) do { if (err) { errno = (err); } } while(0) +#endif + +#if !LWIP_TCPIP_CORE_LOCKING +/** Maximum optlen used by setsockopt/getsockopt */ +#define LWIP_SETGETSOCKOPT_MAXOPTLEN LWIP_MAX(16, sizeof(struct ifreq)) + +/** This struct is used to pass data to the set/getsockopt_internal + * functions running in tcpip_thread context (only a void* is allowed) */ +struct lwip_setgetsockopt_data { + /** socket index for which to change options */ + int s; + /** level of the option to process */ + int level; + /** name of the option to process */ + int optname; + /** set: value to set the option to + * get: value of the option is stored here */ +#if LWIP_MPU_COMPATIBLE + u8_t optval[LWIP_SETGETSOCKOPT_MAXOPTLEN]; +#else + union { + void *p; + const void *pc; + } optval; +#endif + /** size of *optval */ + socklen_t optlen; + /** if an error occurs, it is temporarily stored here */ + int err; + /** semaphore to wake up the calling task */ + void* completed_sem; +}; +#endif /* !LWIP_TCPIP_CORE_LOCKING */ + +#ifdef __cplusplus +} +#endif + +struct lwip_sock* lwip_socket_dbg_get_socket(int fd); + +#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL + +#if LWIP_NETCONN_SEM_PER_THREAD +#define SELECT_SEM_T sys_sem_t* +#define SELECT_SEM_PTR(sem) (sem) +#else /* LWIP_NETCONN_SEM_PER_THREAD */ +#define SELECT_SEM_T sys_sem_t +#define SELECT_SEM_PTR(sem) (&(sem)) +#endif /* LWIP_NETCONN_SEM_PER_THREAD */ + +/** Description for a task waiting in select */ +struct lwip_select_cb { + /** Pointer to the next waiting task */ + struct lwip_select_cb *next; + /** Pointer to the previous waiting task */ + struct lwip_select_cb *prev; +#if LWIP_SOCKET_SELECT + /** readset passed to select */ + fd_set *readset; + /** writeset passed to select */ + fd_set *writeset; + /** unimplemented: exceptset passed to select */ + fd_set *exceptset; +#endif /* LWIP_SOCKET_SELECT */ +#if LWIP_SOCKET_POLL + /** fds passed to poll; NULL if select */ + struct pollfd *poll_fds; + /** nfds passed to poll; 0 if select */ + nfds_t poll_nfds; +#endif /* LWIP_SOCKET_POLL */ + /** don't signal the same semaphore twice: set to 1 when signalled */ + int sem_signalled; + /** semaphore to wake up a task waiting for select */ + SELECT_SEM_T sem; +}; +#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ + +#endif /* LWIP_SOCKET */ + +#endif /* LWIP_HDR_SOCKETS_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/tcp_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/tcp_priv.h new file mode 100644 index 000000000..72f9126d4 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/tcp_priv.h @@ -0,0 +1,523 @@ +/** + * @file + * TCP internal implementations (do not use in application code) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_TCP_PRIV_H +#define LWIP_HDR_TCP_PRIV_H + +#include "lwip/opt.h" + +#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/tcp.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/ip.h" +#include "lwip/icmp.h" +#include "lwip/err.h" +#include "lwip/ip6.h" +#include "lwip/ip6_addr.h" +#include "lwip/prot/tcp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Functions for interfacing with TCP: */ + +/* Lower layer interface to TCP: */ +void tcp_init (void); /* Initialize this module. */ +void tcp_tmr (void); /* Must be called every + TCP_TMR_INTERVAL + ms. (Typically 250 ms). */ +/* It is also possible to call these two functions at the right + intervals (instead of calling tcp_tmr()). */ +void tcp_slowtmr (void); +void tcp_fasttmr (void); + +/* Call this from a netif driver (watch out for threading issues!) that has + returned a memory error on transmit and now has free buffers to send more. + This iterates all active pcbs that had an error and tries to call + tcp_output, so use this with care as it might slow down the system. */ +void tcp_txnow (void); + +/* Only used by IP to pass a TCP segment to TCP: */ +void tcp_input (struct pbuf *p, struct netif *inp); +/* Used within the TCP code only: */ +struct tcp_pcb * tcp_alloc (u8_t prio); +void tcp_free (struct tcp_pcb *pcb); +void tcp_abandon (struct tcp_pcb *pcb, int reset); +err_t tcp_send_empty_ack(struct tcp_pcb *pcb); +err_t tcp_rexmit (struct tcp_pcb *pcb); +err_t tcp_rexmit_rto_prepare(struct tcp_pcb *pcb); +void tcp_rexmit_rto_commit(struct tcp_pcb *pcb); +void tcp_rexmit_rto (struct tcp_pcb *pcb); +void tcp_rexmit_fast (struct tcp_pcb *pcb); +u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb); +err_t tcp_process_refused_data(struct tcp_pcb *pcb); + +/** + * This is the Nagle algorithm: try to combine user data to send as few TCP + * segments as possible. Only send if + * - no previously transmitted data on the connection remains unacknowledged or + * - the TF_NODELAY flag is set (nagle algorithm turned off for this pcb) or + * - the only unsent segment is at least pcb->mss bytes long (or there is more + * than one unsent segment - with lwIP, this can happen although unsent->len < mss) + * - or if we are in fast-retransmit (TF_INFR) + */ +#define tcp_do_output_nagle(tpcb) ((((tpcb)->unacked == NULL) || \ + ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \ + (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \ + ((tpcb)->unsent->len >= (tpcb)->mss))) || \ + ((tcp_sndbuf(tpcb) == 0) || (tcp_sndqueuelen(tpcb) >= TCP_SND_QUEUELEN)) \ + ) ? 1 : 0) +#define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK) + + +#define TCP_SEQ_LT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) < 0) +#define TCP_SEQ_LEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) <= 0) +#define TCP_SEQ_GT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) > 0) +#define TCP_SEQ_GEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) >= 0) +/* is b<=a<=c? */ +#if 0 /* see bug #10548 */ +#define TCP_SEQ_BETWEEN(a,b,c) ((c)-(b) >= (a)-(b)) +#endif +#define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c)) + +#ifndef TCP_TMR_INTERVAL +#define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */ +#endif /* TCP_TMR_INTERVAL */ + +#ifndef TCP_FAST_INTERVAL +#define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */ +#endif /* TCP_FAST_INTERVAL */ + +#ifndef TCP_SLOW_INTERVAL +#define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */ +#endif /* TCP_SLOW_INTERVAL */ + +#define TCP_FIN_WAIT_TIMEOUT 20000 /* milliseconds */ +#define TCP_SYN_RCVD_TIMEOUT 20000 /* milliseconds */ + +#define TCP_OOSEQ_TIMEOUT 6U /* x RTO */ + +#ifndef TCP_MSL +#define TCP_MSL 60000UL /* The maximum segment lifetime in milliseconds */ +#endif + +/* Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing */ +#ifndef TCP_KEEPIDLE_DEFAULT +#define TCP_KEEPIDLE_DEFAULT 7200000UL /* Default KEEPALIVE timer in milliseconds */ +#endif + +#ifndef TCP_KEEPINTVL_DEFAULT +#define TCP_KEEPINTVL_DEFAULT 75000UL /* Default Time between KEEPALIVE probes in milliseconds */ +#endif + +#ifndef TCP_KEEPCNT_DEFAULT +#define TCP_KEEPCNT_DEFAULT 9U /* Default Counter for KEEPALIVE probes */ +#endif + +#define TCP_MAXIDLE TCP_KEEPCNT_DEFAULT * TCP_KEEPINTVL_DEFAULT /* Maximum KEEPALIVE probe time */ + +#define TCP_TCPLEN(seg) ((seg)->len + (((TCPH_FLAGS((seg)->tcphdr) & (TCP_FIN | TCP_SYN)) != 0) ? 1U : 0U)) + +/** Flags used on input processing, not on pcb->flags +*/ +#define TF_RESET (u8_t)0x08U /* Connection was reset. */ +#define TF_CLOSED (u8_t)0x10U /* Connection was successfully closed. */ +#define TF_GOT_FIN (u8_t)0x20U /* Connection was closed by the remote end. */ + + +#if LWIP_EVENT_API + +#define TCP_EVENT_ACCEPT(lpcb,pcb,arg,err,ret) ret = lwip_tcp_event(arg, (pcb),\ + LWIP_EVENT_ACCEPT, NULL, 0, err) +#define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ + LWIP_EVENT_SENT, NULL, space, ERR_OK) +#define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ + LWIP_EVENT_RECV, (p), 0, (err)) +#define TCP_EVENT_CLOSED(pcb,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ + LWIP_EVENT_RECV, NULL, 0, ERR_OK) +#define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\ + LWIP_EVENT_CONNECTED, NULL, 0, (err)) +#define TCP_EVENT_POLL(pcb,ret) do { if ((pcb)->state != SYN_RCVD) { \ + ret = lwip_tcp_event((pcb)->callback_arg, (pcb), LWIP_EVENT_POLL, NULL, 0, ERR_OK); \ + } else { \ + ret = ERR_ARG; } } while(0) +/* For event API, last state SYN_RCVD must be excluded here: the application + has not seen this pcb, yet! */ +#define TCP_EVENT_ERR(last_state,errf,arg,err) do { if (last_state != SYN_RCVD) { \ + lwip_tcp_event((arg), NULL, LWIP_EVENT_ERR, NULL, 0, (err)); } } while(0) + +#else /* LWIP_EVENT_API */ + +#define TCP_EVENT_ACCEPT(lpcb,pcb,arg,err,ret) \ + do { \ + if((lpcb)->accept != NULL) \ + (ret) = (lpcb)->accept((arg),(pcb),(err)); \ + else (ret) = ERR_ARG; \ + } while (0) + +#define TCP_EVENT_SENT(pcb,space,ret) \ + do { \ + if((pcb)->sent != NULL) \ + (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space)); \ + else (ret) = ERR_OK; \ + } while (0) + +#define TCP_EVENT_RECV(pcb,p,err,ret) \ + do { \ + if((pcb)->recv != NULL) { \ + (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err));\ + } else { \ + (ret) = tcp_recv_null(NULL, (pcb), (p), (err)); \ + } \ + } while (0) + +#define TCP_EVENT_CLOSED(pcb,ret) \ + do { \ + if(((pcb)->recv != NULL)) { \ + (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),NULL,ERR_OK);\ + } else { \ + (ret) = ERR_OK; \ + } \ + } while (0) + +#define TCP_EVENT_CONNECTED(pcb,err,ret) \ + do { \ + if((pcb)->connected != NULL) \ + (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \ + else (ret) = ERR_OK; \ + } while (0) + +#define TCP_EVENT_POLL(pcb,ret) \ + do { \ + if((pcb)->poll != NULL) \ + (ret) = (pcb)->poll((pcb)->callback_arg,(pcb)); \ + else (ret) = ERR_OK; \ + } while (0) + +#define TCP_EVENT_ERR(last_state,errf,arg,err) \ + do { \ + LWIP_UNUSED_ARG(last_state); \ + if((errf) != NULL) \ + (errf)((arg),(err)); \ + } while (0) + +#endif /* LWIP_EVENT_API */ + +/** Enabled extra-check for TCP_OVERSIZE if LWIP_DEBUG is enabled */ +#if TCP_OVERSIZE && defined(LWIP_DEBUG) +#define TCP_OVERSIZE_DBGCHECK 1 +#else +#define TCP_OVERSIZE_DBGCHECK 0 +#endif + +/** Don't generate checksum on copy if CHECKSUM_GEN_TCP is disabled */ +#define TCP_CHECKSUM_ON_COPY (LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_TCP) + +/* This structure represents a TCP segment on the unsent, unacked and ooseq queues */ +struct tcp_seg { + struct tcp_seg *next; /* used when putting segments on a queue */ + struct pbuf *p; /* buffer containing data + TCP header */ + u16_t len; /* the TCP length of this segment */ +#if TCP_OVERSIZE_DBGCHECK + u16_t oversize_left; /* Extra bytes available at the end of the last + pbuf in unsent (used for asserting vs. + tcp_pcb.unsent_oversize only) */ +#endif /* TCP_OVERSIZE_DBGCHECK */ +#if TCP_CHECKSUM_ON_COPY + u16_t chksum; + u8_t chksum_swapped; +#endif /* TCP_CHECKSUM_ON_COPY */ + u8_t flags; +#define TF_SEG_OPTS_MSS (u8_t)0x01U /* Include MSS option (only used in SYN segments) */ +#define TF_SEG_OPTS_TS (u8_t)0x02U /* Include timestamp option. */ +#define TF_SEG_DATA_CHECKSUMMED (u8_t)0x04U /* ALL data (not the header) is + checksummed into 'chksum' */ +#define TF_SEG_OPTS_WND_SCALE (u8_t)0x08U /* Include WND SCALE option (only used in SYN segments) */ +#define TF_SEG_OPTS_SACK_PERM (u8_t)0x10U /* Include SACK Permitted option (only used in SYN segments) */ + struct tcp_hdr *tcphdr; /* the TCP header */ +}; + +#define LWIP_TCP_OPT_EOL 0 +#define LWIP_TCP_OPT_NOP 1 +#define LWIP_TCP_OPT_MSS 2 +#define LWIP_TCP_OPT_WS 3 +#define LWIP_TCP_OPT_SACK_PERM 4 +#define LWIP_TCP_OPT_TS 8 + +#define LWIP_TCP_OPT_LEN_MSS 4 +#if LWIP_TCP_TIMESTAMPS +#define LWIP_TCP_OPT_LEN_TS 10 +#define LWIP_TCP_OPT_LEN_TS_OUT 12 /* aligned for output (includes NOP padding) */ +#else +#define LWIP_TCP_OPT_LEN_TS_OUT 0 +#endif +#if LWIP_WND_SCALE +#define LWIP_TCP_OPT_LEN_WS 3 +#define LWIP_TCP_OPT_LEN_WS_OUT 4 /* aligned for output (includes NOP padding) */ +#else +#define LWIP_TCP_OPT_LEN_WS_OUT 0 +#endif + +#if LWIP_TCP_SACK_OUT +#define LWIP_TCP_OPT_LEN_SACK_PERM 2 +#define LWIP_TCP_OPT_LEN_SACK_PERM_OUT 4 /* aligned for output (includes NOP padding) */ +#else +#define LWIP_TCP_OPT_LEN_SACK_PERM_OUT 0 +#endif + +#define LWIP_TCP_OPT_LENGTH(flags) \ + ((flags) & TF_SEG_OPTS_MSS ? LWIP_TCP_OPT_LEN_MSS : 0) + \ + ((flags) & TF_SEG_OPTS_TS ? LWIP_TCP_OPT_LEN_TS_OUT : 0) + \ + ((flags) & TF_SEG_OPTS_WND_SCALE ? LWIP_TCP_OPT_LEN_WS_OUT : 0) + \ + ((flags) & TF_SEG_OPTS_SACK_PERM ? LWIP_TCP_OPT_LEN_SACK_PERM_OUT : 0) + +/** This returns a TCP header option for MSS in an u32_t */ +#define TCP_BUILD_MSS_OPTION(mss) lwip_htonl(0x02040000 | ((mss) & 0xFFFF)) + +#if LWIP_WND_SCALE +#define TCPWNDSIZE_F U32_F +#define TCPWND_MAX 0xFFFFFFFFU +#define TCPWND_CHECK16(x) LWIP_ASSERT("window size > 0xFFFF", (x) <= 0xFFFF) +#define TCPWND_MIN16(x) ((u16_t)LWIP_MIN((x), 0xFFFF)) +#else /* LWIP_WND_SCALE */ +#define TCPWNDSIZE_F U16_F +#define TCPWND_MAX 0xFFFFU +#define TCPWND_CHECK16(x) +#define TCPWND_MIN16(x) x +#endif /* LWIP_WND_SCALE */ + +/* Global variables: */ +extern struct tcp_pcb *tcp_input_pcb; +extern u32_t tcp_ticks; +extern u8_t tcp_active_pcbs_changed; + +/* The TCP PCB lists. */ +union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */ + struct tcp_pcb_listen *listen_pcbs; + struct tcp_pcb *pcbs; +}; +extern struct tcp_pcb *tcp_bound_pcbs; +extern union tcp_listen_pcbs_t tcp_listen_pcbs; +extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a + state in which they accept or send + data. */ +extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. */ + +#define NUM_TCP_PCB_LISTS_NO_TIME_WAIT 3 +#define NUM_TCP_PCB_LISTS 4 +extern struct tcp_pcb ** const tcp_pcb_lists[NUM_TCP_PCB_LISTS]; + +/* Axioms about the above lists: + 1) Every TCP PCB that is not CLOSED is in one of the lists. + 2) A PCB is only in one of the lists. + 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state. + 4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state. +*/ +/* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB + with a PCB list or removes a PCB from a list, respectively. */ +#ifndef TCP_DEBUG_PCB_LISTS +#define TCP_DEBUG_PCB_LISTS 0 +#endif +#if TCP_DEBUG_PCB_LISTS +#define TCP_REG(pcbs, npcb) do {\ + struct tcp_pcb *tcp_tmp_pcb; \ + LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %"U16_F"\n", (void *)(npcb), (npcb)->local_port)); \ + for (tcp_tmp_pcb = *(pcbs); \ + tcp_tmp_pcb != NULL; \ + tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != (npcb)); \ + } \ + LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", ((pcbs) == &tcp_bound_pcbs) || ((npcb)->state != CLOSED)); \ + (npcb)->next = *(pcbs); \ + LWIP_ASSERT("TCP_REG: npcb->next != npcb", (npcb)->next != (npcb)); \ + *(pcbs) = (npcb); \ + LWIP_ASSERT("TCP_REG: tcp_pcbs sane", tcp_pcbs_sane()); \ + tcp_timer_needed(); \ + } while(0) +#define TCP_RMV(pcbs, npcb) do { \ + struct tcp_pcb *tcp_tmp_pcb; \ + LWIP_ASSERT("TCP_RMV: pcbs != NULL", *(pcbs) != NULL); \ + LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ + if(*(pcbs) == (npcb)) { \ + *(pcbs) = (*pcbs)->next; \ + } else for (tcp_tmp_pcb = *(pcbs); tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + if(tcp_tmp_pcb->next == (npcb)) { \ + tcp_tmp_pcb->next = (npcb)->next; \ + break; \ + } \ + } \ + (npcb)->next = NULL; \ + LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \ + LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", (void *)(npcb), (void *)(*(pcbs)))); \ + } while(0) + +#else /* LWIP_DEBUG */ + +#define TCP_REG(pcbs, npcb) \ + do { \ + (npcb)->next = *pcbs; \ + *(pcbs) = (npcb); \ + tcp_timer_needed(); \ + } while (0) + +#define TCP_RMV(pcbs, npcb) \ + do { \ + if(*(pcbs) == (npcb)) { \ + (*(pcbs)) = (*pcbs)->next; \ + } \ + else { \ + struct tcp_pcb *tcp_tmp_pcb; \ + for (tcp_tmp_pcb = *pcbs; \ + tcp_tmp_pcb != NULL; \ + tcp_tmp_pcb = tcp_tmp_pcb->next) { \ + if(tcp_tmp_pcb->next == (npcb)) { \ + tcp_tmp_pcb->next = (npcb)->next; \ + break; \ + } \ + } \ + } \ + (npcb)->next = NULL; \ + } while(0) + +#endif /* LWIP_DEBUG */ + +#define TCP_REG_ACTIVE(npcb) \ + do { \ + TCP_REG(&tcp_active_pcbs, npcb); \ + tcp_active_pcbs_changed = 1; \ + } while (0) + +#define TCP_RMV_ACTIVE(npcb) \ + do { \ + TCP_RMV(&tcp_active_pcbs, npcb); \ + tcp_active_pcbs_changed = 1; \ + } while (0) + +#define TCP_PCB_REMOVE_ACTIVE(pcb) \ + do { \ + tcp_pcb_remove(&tcp_active_pcbs, pcb); \ + tcp_active_pcbs_changed = 1; \ + } while (0) + + +/* Internal functions: */ +struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb); +void tcp_pcb_purge(struct tcp_pcb *pcb); +void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb); + +void tcp_segs_free(struct tcp_seg *seg); +void tcp_seg_free(struct tcp_seg *seg); +struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg); + +#define tcp_ack(pcb) \ + do { \ + if((pcb)->flags & TF_ACK_DELAY) { \ + tcp_clear_flags(pcb, TF_ACK_DELAY); \ + tcp_ack_now(pcb); \ + } \ + else { \ + tcp_set_flags(pcb, TF_ACK_DELAY); \ + } \ + } while (0) + +#define tcp_ack_now(pcb) \ + tcp_set_flags(pcb, TF_ACK_NOW) + +err_t tcp_send_fin(struct tcp_pcb *pcb); +err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags); + +void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg); + +void tcp_rst(const struct tcp_pcb* pcb, u32_t seqno, u32_t ackno, + const ip_addr_t *local_ip, const ip_addr_t *remote_ip, + u16_t local_port, u16_t remote_port); + +u32_t tcp_next_iss(struct tcp_pcb *pcb); + +err_t tcp_keepalive(struct tcp_pcb *pcb); +err_t tcp_split_unsent_seg(struct tcp_pcb *pcb, u16_t split); +err_t tcp_zero_window_probe(struct tcp_pcb *pcb); +void tcp_trigger_input_pcb_close(void); + +#if TCP_CALCULATE_EFF_SEND_MSS +u16_t tcp_eff_send_mss_netif(u16_t sendmss, struct netif *outif, + const ip_addr_t *dest); +#define tcp_eff_send_mss(sendmss, src, dest) \ + tcp_eff_send_mss_netif(sendmss, ip_route(src, dest), dest) +#endif /* TCP_CALCULATE_EFF_SEND_MSS */ + +#if LWIP_CALLBACK_API +err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err); +#endif /* LWIP_CALLBACK_API */ + +#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG +void tcp_debug_print(struct tcp_hdr *tcphdr); +void tcp_debug_print_flags(u8_t flags); +void tcp_debug_print_state(enum tcp_state s); +void tcp_debug_print_pcbs(void); +s16_t tcp_pcbs_sane(void); +#else +# define tcp_debug_print(tcphdr) +# define tcp_debug_print_flags(flags) +# define tcp_debug_print_state(s) +# define tcp_debug_print_pcbs() +# define tcp_pcbs_sane() 1 +#endif /* TCP_DEBUG */ + +/** External function (implemented in timers.c), called when TCP detects + * that a timer is needed (i.e. active- or time-wait-pcb found). */ +void tcp_timer_needed(void); + +void tcp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); + +#if TCP_QUEUE_OOSEQ +void tcp_free_ooseq(struct tcp_pcb *pcb); +#endif + +#if LWIP_TCP_PCB_NUM_EXT_ARGS +err_t tcp_ext_arg_invoke_callbacks_passive_open(struct tcp_pcb_listen *lpcb, struct tcp_pcb *cpcb); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_TCP */ + +#endif /* LWIP_HDR_TCP_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/tcpip_priv.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/tcpip_priv.h new file mode 100644 index 000000000..74be634be --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/priv/tcpip_priv.h @@ -0,0 +1,170 @@ +/** + * @file + * TCPIP API internal implementations (do not use in application code) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_TCPIP_PRIV_H +#define LWIP_HDR_TCPIP_PRIV_H + +#include "lwip/opt.h" + +#if !NO_SYS /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/tcpip.h" +#include "lwip/sys.h" +#include "lwip/timeouts.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct pbuf; +struct netif; + +#if LWIP_MPU_COMPATIBLE +#define API_VAR_REF(name) (*(name)) +#define API_VAR_DECLARE(type, name) type * name +#define API_VAR_ALLOC_EXT(type, pool, name, errorblock) do { \ + name = (type *)memp_malloc(pool); \ + if (name == NULL) { \ + errorblock; \ + } \ + } while(0) +#define API_VAR_ALLOC(type, pool, name, errorval) API_VAR_ALLOC_EXT(type, pool, name, return errorval) +#define API_VAR_ALLOC_POOL(type, pool, name, errorval) do { \ + name = (type *)LWIP_MEMPOOL_ALLOC(pool); \ + if (name == NULL) { \ + return errorval; \ + } \ + } while(0) +#define API_VAR_FREE(pool, name) memp_free(pool, name) +#define API_VAR_FREE_POOL(pool, name) LWIP_MEMPOOL_FREE(pool, name) +#define API_EXPR_REF(expr) (&(expr)) +#if LWIP_NETCONN_SEM_PER_THREAD +#define API_EXPR_REF_SEM(expr) (expr) +#else +#define API_EXPR_REF_SEM(expr) API_EXPR_REF(expr) +#endif +#define API_EXPR_DEREF(expr) expr +#define API_MSG_M_DEF(m) m +#define API_MSG_M_DEF_C(t, m) t m +#else /* LWIP_MPU_COMPATIBLE */ +#define API_VAR_REF(name) name +#define API_VAR_DECLARE(type, name) type name +#define API_VAR_ALLOC_EXT(type, pool, name, errorblock) +#define API_VAR_ALLOC(type, pool, name, errorval) +#define API_VAR_ALLOC_POOL(type, pool, name, errorval) +#define API_VAR_FREE(pool, name) +#define API_VAR_FREE_POOL(pool, name) +#define API_EXPR_REF(expr) expr +#define API_EXPR_REF_SEM(expr) API_EXPR_REF(expr) +#define API_EXPR_DEREF(expr) (*(expr)) +#define API_MSG_M_DEF(m) *m +#define API_MSG_M_DEF_C(t, m) const t * m +#endif /* LWIP_MPU_COMPATIBLE */ + +err_t tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem); + +struct tcpip_api_call_data +{ +#if !LWIP_TCPIP_CORE_LOCKING + err_t err; +#if !LWIP_NETCONN_SEM_PER_THREAD + sys_sem_t sem; +#endif /* LWIP_NETCONN_SEM_PER_THREAD */ +#else /* !LWIP_TCPIP_CORE_LOCKING */ + u8_t dummy; /* avoid empty struct :-( */ +#endif /* !LWIP_TCPIP_CORE_LOCKING */ +}; +typedef err_t (*tcpip_api_call_fn)(struct tcpip_api_call_data* call); +err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call); + +enum tcpip_msg_type { +#if !LWIP_TCPIP_CORE_LOCKING + TCPIP_MSG_API, + TCPIP_MSG_API_CALL, +#endif /* !LWIP_TCPIP_CORE_LOCKING */ +#if !LWIP_TCPIP_CORE_LOCKING_INPUT + TCPIP_MSG_INPKT, +#endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS + TCPIP_MSG_TIMEOUT, + TCPIP_MSG_UNTIMEOUT, +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ + TCPIP_MSG_CALLBACK, + TCPIP_MSG_CALLBACK_STATIC +}; + +struct tcpip_msg { + enum tcpip_msg_type type; + union { +#if !LWIP_TCPIP_CORE_LOCKING + struct { + tcpip_callback_fn function; + void* msg; + } api_msg; + struct { + tcpip_api_call_fn function; + struct tcpip_api_call_data *arg; + sys_sem_t *sem; + } api_call; +#endif /* LWIP_TCPIP_CORE_LOCKING */ +#if !LWIP_TCPIP_CORE_LOCKING_INPUT + struct { + struct pbuf *p; + struct netif *netif; + netif_input_fn input_fn; + } inp; +#endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ + struct { + tcpip_callback_fn function; + void *ctx; + } cb; +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS + struct { + u32_t msecs; + sys_timeout_handler h; + void *arg; + } tmo; +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ + } msg; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* !NO_SYS */ + +#endif /* LWIP_HDR_TCPIP_PRIV_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/autoip.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/autoip.h new file mode 100644 index 000000000..fd3af8a9f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/autoip.h @@ -0,0 +1,78 @@ +/** + * @file + * AutoIP protocol definitions + */ + +/* + * + * Copyright (c) 2007 Dominik Spies + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Dominik Spies + * + * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform + * with RFC 3927. + * + */ + +#ifndef LWIP_HDR_PROT_AUTOIP_H +#define LWIP_HDR_PROT_AUTOIP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* 169.254.0.0 */ +#define AUTOIP_NET 0xA9FE0000 +/* 169.254.1.0 */ +#define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100) +/* 169.254.254.255 */ +#define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF) + +/* RFC 3927 Constants */ +#define PROBE_WAIT 1 /* second (initial random delay) */ +#define PROBE_MIN 1 /* second (minimum delay till repeated probe) */ +#define PROBE_MAX 2 /* seconds (maximum delay till repeated probe) */ +#define PROBE_NUM 3 /* (number of probe packets) */ +#define ANNOUNCE_NUM 2 /* (number of announcement packets) */ +#define ANNOUNCE_INTERVAL 2 /* seconds (time between announcement packets) */ +#define ANNOUNCE_WAIT 2 /* seconds (delay before announcing) */ +#define MAX_CONFLICTS 10 /* (max conflicts before rate limiting) */ +#define RATE_LIMIT_INTERVAL 60 /* seconds (delay between successive attempts) */ +#define DEFEND_INTERVAL 10 /* seconds (min. wait between defensive ARPs) */ + +/* AutoIP client states */ +typedef enum { + AUTOIP_STATE_OFF = 0, + AUTOIP_STATE_PROBING = 1, + AUTOIP_STATE_ANNOUNCING = 2, + AUTOIP_STATE_BOUND = 3 +} autoip_state_enum_t; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_AUTOIP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dhcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dhcp.h new file mode 100644 index 000000000..ab18dca31 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dhcp.h @@ -0,0 +1,178 @@ +/** + * @file + * DHCP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Leon Woestenberg + * Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Leon Woestenberg + * + */ +#ifndef LWIP_HDR_PROT_DHCP_H +#define LWIP_HDR_PROT_DHCP_H + +#include "lwip/opt.h" +#include "lwip/arch.h" +#include "lwip/prot/ip4.h" + +#ifdef __cplusplus +extern "C" { +#endif + + /* DHCP message item offsets and length */ +#define DHCP_CHADDR_LEN 16U +#define DHCP_SNAME_OFS 44U +#define DHCP_SNAME_LEN 64U +#define DHCP_FILE_OFS 108U +#define DHCP_FILE_LEN 128U +#define DHCP_MSG_LEN 236U +#define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4U) /* 4 byte: cookie */ + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** minimum set of fields of any DHCP message */ +struct dhcp_msg +{ + PACK_STRUCT_FLD_8(u8_t op); + PACK_STRUCT_FLD_8(u8_t htype); + PACK_STRUCT_FLD_8(u8_t hlen); + PACK_STRUCT_FLD_8(u8_t hops); + PACK_STRUCT_FIELD(u32_t xid); + PACK_STRUCT_FIELD(u16_t secs); + PACK_STRUCT_FIELD(u16_t flags); + PACK_STRUCT_FLD_S(ip4_addr_p_t ciaddr); + PACK_STRUCT_FLD_S(ip4_addr_p_t yiaddr); + PACK_STRUCT_FLD_S(ip4_addr_p_t siaddr); + PACK_STRUCT_FLD_S(ip4_addr_p_t giaddr); + PACK_STRUCT_FLD_8(u8_t chaddr[DHCP_CHADDR_LEN]); + PACK_STRUCT_FLD_8(u8_t sname[DHCP_SNAME_LEN]); + PACK_STRUCT_FLD_8(u8_t file[DHCP_FILE_LEN]); + PACK_STRUCT_FIELD(u32_t cookie); +#define DHCP_MIN_OPTIONS_LEN 68U +/** make sure user does not configure this too small */ +#if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) +# undef DHCP_OPTIONS_LEN +#endif +/** allow this to be configured in lwipopts.h, but not too small */ +#if (!defined(DHCP_OPTIONS_LEN)) +/** set this to be sufficient for your options in outgoing DHCP msgs */ +# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN +#endif + PACK_STRUCT_FLD_8(u8_t options[DHCP_OPTIONS_LEN]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + + +/* DHCP client states */ +typedef enum { + DHCP_STATE_OFF = 0, + DHCP_STATE_REQUESTING = 1, + DHCP_STATE_INIT = 2, + DHCP_STATE_REBOOTING = 3, + DHCP_STATE_REBINDING = 4, + DHCP_STATE_RENEWING = 5, + DHCP_STATE_SELECTING = 6, + DHCP_STATE_INFORMING = 7, + DHCP_STATE_CHECKING = 8, + DHCP_STATE_PERMANENT = 9, /* not yet implemented */ + DHCP_STATE_BOUND = 10, + DHCP_STATE_RELEASING = 11, /* not yet implemented */ + DHCP_STATE_BACKING_OFF = 12 +} dhcp_state_enum_t; + +/* DHCP op codes */ +#define DHCP_BOOTREQUEST 1 +#define DHCP_BOOTREPLY 2 + +/* DHCP message types */ +#define DHCP_DISCOVER 1 +#define DHCP_OFFER 2 +#define DHCP_REQUEST 3 +#define DHCP_DECLINE 4 +#define DHCP_ACK 5 +#define DHCP_NAK 6 +#define DHCP_RELEASE 7 +#define DHCP_INFORM 8 + +#define DHCP_MAGIC_COOKIE 0x63825363UL + +/* This is a list of options for BOOTP and DHCP, see RFC 2132 for descriptions */ + +/* BootP options */ +#define DHCP_OPTION_PAD 0 +#define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */ +#define DHCP_OPTION_ROUTER 3 +#define DHCP_OPTION_DNS_SERVER 6 +#define DHCP_OPTION_HOSTNAME 12 +#define DHCP_OPTION_IP_TTL 23 +#define DHCP_OPTION_MTU 26 +#define DHCP_OPTION_BROADCAST 28 +#define DHCP_OPTION_TCP_TTL 37 +#define DHCP_OPTION_NTP 42 +#define DHCP_OPTION_END 255 + +/* DHCP options */ +#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */ +#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */ +#define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */ + +#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */ +#define DHCP_OPTION_MESSAGE_TYPE_LEN 1 + +#define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */ +#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */ + +#define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */ +#define DHCP_OPTION_MAX_MSG_SIZE_LEN 2 + +#define DHCP_OPTION_T1 58 /* T1 renewal time */ +#define DHCP_OPTION_T2 59 /* T2 rebinding time */ +#define DHCP_OPTION_US 60 +#define DHCP_OPTION_CLIENT_ID 61 +#define DHCP_OPTION_TFTP_SERVERNAME 66 +#define DHCP_OPTION_BOOTFILE 67 + +/* possible combinations of overloading the file and sname fields with options */ +#define DHCP_OVERLOAD_NONE 0 +#define DHCP_OVERLOAD_FILE 1 +#define DHCP_OVERLOAD_SNAME 2 +#define DHCP_OVERLOAD_SNAME_FILE 3 + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_DHCP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dhcp6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dhcp6.h new file mode 100644 index 000000000..0754c91b9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dhcp6.h @@ -0,0 +1,138 @@ +/** + * @file + * DHCPv6 protocol definitions + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_PROT_DHCP6_H +#define LWIP_HDR_PROT_DHCP6_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DHCP6_CLIENT_PORT 546 +#define DHCP6_SERVER_PORT 547 + + + /* DHCPv6 message item offsets and length */ +#define DHCP6_TRANSACTION_ID_LEN 3 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** minimum set of fields of any DHCPv6 message */ +struct dhcp6_msg +{ + PACK_STRUCT_FLD_8(u8_t msgtype); + PACK_STRUCT_FLD_8(u8_t transaction_id[DHCP6_TRANSACTION_ID_LEN]); + /* options follow */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + + +/* DHCP6 client states */ +typedef enum { + DHCP6_STATE_OFF = 0, + DHCP6_STATE_STATELESS_IDLE = 1, + DHCP6_STATE_REQUESTING_CONFIG = 2 +} dhcp6_state_enum_t; + +/* DHCPv6 message types */ +#define DHCP6_SOLICIT 1 +#define DHCP6_ADVERTISE 2 +#define DHCP6_REQUEST 3 +#define DHCP6_CONFIRM 4 +#define DHCP6_RENEW 5 +#define DHCP6_REBIND 6 +#define DHCP6_REPLY 7 +#define DHCP6_RELEASE 8 +#define DHCP6_DECLINE 9 +#define DHCP6_RECONFIGURE 10 +#define DHCP6_INFOREQUEST 11 +#define DHCP6_RELAYFORW 12 +#define DHCP6_RELAYREPL 13 +/* More message types see https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml */ + +/** DHCPv6 status codes */ +#define DHCP6_STATUS_SUCCESS 0 /* Success. */ +#define DHCP6_STATUS_UNSPECFAIL 1 /* Failure, reason unspecified; this status code is sent by either a client or a server to indicate a failure not explicitly specified in this document. */ +#define DHCP6_STATUS_NOADDRSAVAIL 2 /* Server has no addresses available to assign to the IA(s). */ +#define DHCP6_STATUS_NOBINDING 3 /* Client record (binding) unavailable. */ +#define DHCP6_STATUS_NOTONLINK 4 /* The prefix for the address is not appropriate for the link to which the client is attached. */ +#define DHCP6_STATUS_USEMULTICAST 5 /* Sent by a server to a client to force the client to send messages to the server using the All_DHCP_Relay_Agents_and_Servers address. */ +/* More status codes see https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml */ + +/** DHCPv6 DUID types */ +#define DHCP6_DUID_LLT 1 /* LLT: Link-layer Address Plus Time */ +#define DHCP6_DUID_EN 2 /* EN: Enterprise number */ +#define DHCP6_DUID_LL 3 /* LL: Link-layer Address */ +#define DHCP6_DUID_UUID 4 /* UUID (RFC 6355) */ + +/* DHCPv6 options */ +#define DHCP6_OPTION_CLIENTID 1 +#define DHCP6_OPTION_SERVERID 2 +#define DHCP6_OPTION_IA_NA 3 +#define DHCP6_OPTION_IA_TA 4 +#define DHCP6_OPTION_IAADDR 5 +#define DHCP6_OPTION_ORO 6 +#define DHCP6_OPTION_PREFERENCE 7 +#define DHCP6_OPTION_ELAPSED_TIME 8 +#define DHCP6_OPTION_RELAY_MSG 9 +#define DHCP6_OPTION_AUTH 11 +#define DHCP6_OPTION_UNICAST 12 +#define DHCP6_OPTION_STATUS_CODE 13 +#define DHCP6_OPTION_RAPID_COMMIT 14 +#define DHCP6_OPTION_USER_CLASS 15 +#define DHCP6_OPTION_VENDOR_CLASS 16 +#define DHCP6_OPTION_VENDOR_OPTS 17 +#define DHCP6_OPTION_INTERFACE_ID 18 +#define DHCP6_OPTION_RECONF_MSG 19 +#define DHCP6_OPTION_RECONF_ACCEPT 20 +/* More options see https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml */ +#define DHCP6_OPTION_DNS_SERVERS 23 /* RFC 3646 */ +#define DHCP6_OPTION_DOMAIN_LIST 24 /* RFC 3646 */ +#define DHCP6_OPTION_SNTP_SERVERS 31 /* RFC 4075 */ + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_DHCP6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dns.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dns.h new file mode 100644 index 000000000..94782d6e9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/dns.h @@ -0,0 +1,140 @@ +/** + * @file + * DNS - host name to IP address resolver. + */ + +/* + * Port to lwIP from uIP + * by Jim Pettinato April 2007 + * + * security fixes and more by Simon Goldschmidt + * + * uIP version Copyright (c) 2002-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LWIP_HDR_PROT_DNS_H +#define LWIP_HDR_PROT_DNS_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** DNS server port address */ +#ifndef DNS_SERVER_PORT +#define DNS_SERVER_PORT 53 +#endif + +/* DNS field TYPE used for "Resource Records" */ +#define DNS_RRTYPE_A 1 /* a host address */ +#define DNS_RRTYPE_NS 2 /* an authoritative name server */ +#define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */ +#define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */ +#define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */ +#define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */ +#define DNS_RRTYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */ +#define DNS_RRTYPE_MG 8 /* a mail group member (EXPERIMENTAL) */ +#define DNS_RRTYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */ +#define DNS_RRTYPE_NULL 10 /* a null RR (EXPERIMENTAL) */ +#define DNS_RRTYPE_WKS 11 /* a well known service description */ +#define DNS_RRTYPE_PTR 12 /* a domain name pointer */ +#define DNS_RRTYPE_HINFO 13 /* host information */ +#define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */ +#define DNS_RRTYPE_MX 15 /* mail exchange */ +#define DNS_RRTYPE_TXT 16 /* text strings */ +#define DNS_RRTYPE_AAAA 28 /* IPv6 address */ +#define DNS_RRTYPE_SRV 33 /* service location */ +#define DNS_RRTYPE_ANY 255 /* any type */ + +/* DNS field CLASS used for "Resource Records" */ +#define DNS_RRCLASS_IN 1 /* the Internet */ +#define DNS_RRCLASS_CS 2 /* the CSNET class (Obsolete - used only for examples in some obsolete RFCs) */ +#define DNS_RRCLASS_CH 3 /* the CHAOS class */ +#define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ +#define DNS_RRCLASS_ANY 255 /* any class */ +#define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ + +/* DNS protocol flags */ +#define DNS_FLAG1_RESPONSE 0x80 +#define DNS_FLAG1_OPCODE_STATUS 0x10 +#define DNS_FLAG1_OPCODE_INVERSE 0x08 +#define DNS_FLAG1_OPCODE_STANDARD 0x00 +#define DNS_FLAG1_AUTHORATIVE 0x04 +#define DNS_FLAG1_TRUNC 0x02 +#define DNS_FLAG1_RD 0x01 +#define DNS_FLAG2_RA 0x80 +#define DNS_FLAG2_ERR_MASK 0x0f +#define DNS_FLAG2_ERR_NONE 0x00 +#define DNS_FLAG2_ERR_NAME 0x03 + +#define DNS_HDR_GET_OPCODE(hdr) ((((hdr)->flags1) >> 3) & 0xF) + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** DNS message header */ +struct dns_hdr { + PACK_STRUCT_FIELD(u16_t id); + PACK_STRUCT_FLD_8(u8_t flags1); + PACK_STRUCT_FLD_8(u8_t flags2); + PACK_STRUCT_FIELD(u16_t numquestions); + PACK_STRUCT_FIELD(u16_t numanswers); + PACK_STRUCT_FIELD(u16_t numauthrr); + PACK_STRUCT_FIELD(u16_t numextrarr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define SIZEOF_DNS_HDR 12 + + +/* Multicast DNS definitions */ + +/** UDP port for multicast DNS queries */ +#ifndef DNS_MQUERY_PORT +#define DNS_MQUERY_PORT 5353 +#endif + +/* IPv4 group for multicast DNS queries: 224.0.0.251 */ +#ifndef DNS_MQUERY_IPV4_GROUP_INIT +#define DNS_MQUERY_IPV4_GROUP_INIT IPADDR4_INIT_BYTES(224,0,0,251) +#endif + +/* IPv6 group for multicast DNS queries: FF02::FB */ +#ifndef DNS_MQUERY_IPV6_GROUP_INIT +#define DNS_MQUERY_IPV6_GROUP_INIT IPADDR6_INIT_HOST(0xFF020000,0,0,0xFB) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_DNS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/etharp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/etharp.h new file mode 100644 index 000000000..811c22841 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/etharp.h @@ -0,0 +1,114 @@ +/** + * @file + * ARP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ETHARP_H +#define LWIP_HDR_PROT_ETHARP_H + +#include "lwip/arch.h" +#include "lwip/prot/ethernet.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ETHARP_HWADDR_LEN +#define ETHARP_HWADDR_LEN ETH_HWADDR_LEN +#endif + +/** + * struct ip4_addr_wordaligned is used in the definition of the ARP packet format in + * order to support compilers that don't have structure packing. + */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip4_addr_wordaligned { + PACK_STRUCT_FIELD(u16_t addrw[2]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** MEMCPY-like copying of IP addresses where addresses are known to be + * 16-bit-aligned if the port is correctly configured (so a port could define + * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */ +#ifndef IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T +#define IPADDR_WORDALIGNED_COPY_TO_IP4_ADDR_T(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t)) +#endif + + /** MEMCPY-like copying of IP addresses where addresses are known to be + * 16-bit-aligned if the port is correctly configured (so a port could define + * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */ +#ifndef IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T +#define IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t)) +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** the ARP message, see RFC 826 ("Packet format") */ +struct etharp_hdr { + PACK_STRUCT_FIELD(u16_t hwtype); + PACK_STRUCT_FIELD(u16_t proto); + PACK_STRUCT_FLD_8(u8_t hwlen); + PACK_STRUCT_FLD_8(u8_t protolen); + PACK_STRUCT_FIELD(u16_t opcode); + PACK_STRUCT_FLD_S(struct eth_addr shwaddr); + PACK_STRUCT_FLD_S(struct ip4_addr_wordaligned sipaddr); + PACK_STRUCT_FLD_S(struct eth_addr dhwaddr); + PACK_STRUCT_FLD_S(struct ip4_addr_wordaligned dipaddr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define SIZEOF_ETHARP_HDR 28 + +/* ARP message types (opcodes) */ +enum etharp_opcode { + ARP_REQUEST = 1, + ARP_REPLY = 2 +}; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ETHARP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ethernet.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ethernet.h new file mode 100644 index 000000000..309e57465 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ethernet.h @@ -0,0 +1,125 @@ +/** + * @file + * Ethernet protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ETHERNET_H +#define LWIP_HDR_PROT_ETHERNET_H + +#include "lwip/arch.h" +#include "lwip/prot/ieee.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ETH_HWADDR_LEN +#ifdef ETHARP_HWADDR_LEN +#define ETH_HWADDR_LEN ETHARP_HWADDR_LEN /* compatibility mode */ +#else +#define ETH_HWADDR_LEN 6 +#endif +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** An Ethernet MAC address */ +struct eth_addr { + PACK_STRUCT_FLD_8(u8_t addr[ETH_HWADDR_LEN]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Initialize a struct eth_addr with its 6 bytes (takes care of correct braces) */ +#define ETH_ADDR(b0, b1, b2, b3, b4, b5) {{b0, b1, b2, b3, b4, b5}} + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** Ethernet header */ +struct eth_hdr { +#if ETH_PAD_SIZE + PACK_STRUCT_FLD_8(u8_t padding[ETH_PAD_SIZE]); +#endif + PACK_STRUCT_FLD_S(struct eth_addr dest); + PACK_STRUCT_FLD_S(struct eth_addr src); + PACK_STRUCT_FIELD(u16_t type); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE) + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** VLAN header inserted between ethernet header and payload + * if 'type' in ethernet header is ETHTYPE_VLAN. + * See IEEE802.Q */ +struct eth_vlan_hdr { + PACK_STRUCT_FIELD(u16_t prio_vid); + PACK_STRUCT_FIELD(u16_t tpid); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define SIZEOF_VLAN_HDR 4 +#define VLAN_ID(vlan_hdr) (lwip_htons((vlan_hdr)->prio_vid) & 0xFFF) + +/** The 24-bit IANA IPv4-multicast OUI is 01-00-5e: */ +#define LL_IP4_MULTICAST_ADDR_0 0x01 +#define LL_IP4_MULTICAST_ADDR_1 0x00 +#define LL_IP4_MULTICAST_ADDR_2 0x5e + +/** IPv6 multicast uses this prefix */ +#define LL_IP6_MULTICAST_ADDR_0 0x33 +#define LL_IP6_MULTICAST_ADDR_1 0x33 + +#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETH_HWADDR_LEN) == 0) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ETHERNET_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/iana.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/iana.h new file mode 100644 index 000000000..32890cccd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/iana.h @@ -0,0 +1,97 @@ +/** + * @file + * IANA assigned numbers (RFC 1700 and successors) + * + * @defgroup iana IANA assigned numbers + * @ingroup infrastructure + */ + +/* + * Copyright (c) 2017 Dirk Ziegelmeier. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Dirk Ziegelmeier + * + */ + +#ifndef LWIP_HDR_PROT_IANA_H +#define LWIP_HDR_PROT_IANA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup iana + * Hardware types + */ +enum lwip_iana_hwtype { + /** Ethernet */ + LWIP_IANA_HWTYPE_ETHERNET = 1 +}; + +/** + * @ingroup iana + * Port numbers + * https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt + */ +enum lwip_iana_port_number { + /** SMTP */ + LWIP_IANA_PORT_SMTP = 25, + /** DHCP server */ + LWIP_IANA_PORT_DHCP_SERVER = 67, + /** DHCP client */ + LWIP_IANA_PORT_DHCP_CLIENT = 68, + /** TFTP */ + LWIP_IANA_PORT_TFTP = 69, + /** HTTP */ + LWIP_IANA_PORT_HTTP = 80, + /** SNTP */ + LWIP_IANA_PORT_SNTP = 123, + /** NETBIOS */ + LWIP_IANA_PORT_NETBIOS = 137, + /** SNMP */ + LWIP_IANA_PORT_SNMP = 161, + /** SNMP traps */ + LWIP_IANA_PORT_SNMP_TRAP = 162, + /** HTTPS */ + LWIP_IANA_PORT_HTTPS = 443, + /** SMTPS */ + LWIP_IANA_PORT_SMTPS = 465, + /** MQTT */ + LWIP_IANA_PORT_MQTT = 1883, + /** MDNS */ + LWIP_IANA_PORT_MDNS = 5353, + /** Secure MQTT */ + LWIP_IANA_PORT_SECURE_MQTT = 8883 +}; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IANA_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/icmp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/icmp.h new file mode 100644 index 000000000..7d19385c7 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/icmp.h @@ -0,0 +1,91 @@ +/** + * @file + * ICMP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ICMP_H +#define LWIP_HDR_PROT_ICMP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ICMP_ER 0 /* echo reply */ +#define ICMP_DUR 3 /* destination unreachable */ +#define ICMP_SQ 4 /* source quench */ +#define ICMP_RD 5 /* redirect */ +#define ICMP_ECHO 8 /* echo */ +#define ICMP_TE 11 /* time exceeded */ +#define ICMP_PP 12 /* parameter problem */ +#define ICMP_TS 13 /* timestamp */ +#define ICMP_TSR 14 /* timestamp reply */ +#define ICMP_IRQ 15 /* information request */ +#define ICMP_IR 16 /* information reply */ +#define ICMP_AM 17 /* address mask request */ +#define ICMP_AMR 18 /* address mask reply */ + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +/** This is the standard ICMP header only that the u32_t data + * is split to two u16_t like ICMP echo needs it. + * This header is also used for other ICMP types that do not + * use the data part. + */ +PACK_STRUCT_BEGIN +struct icmp_echo_hdr { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u16_t id); + PACK_STRUCT_FIELD(u16_t seqno); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/* Compatibility defines, old versions used to combine type and code to an u16_t */ +#define ICMPH_TYPE(hdr) ((hdr)->type) +#define ICMPH_CODE(hdr) ((hdr)->code) +#define ICMPH_TYPE_SET(hdr, t) ((hdr)->type = (t)) +#define ICMPH_CODE_SET(hdr, c) ((hdr)->code = (c)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ICMP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/icmp6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/icmp6.h new file mode 100644 index 000000000..36989f6b3 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/icmp6.h @@ -0,0 +1,172 @@ +/** + * @file + * ICMP6 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ICMP6_H +#define LWIP_HDR_PROT_ICMP6_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** ICMP type */ +enum icmp6_type { + /** Destination unreachable */ + ICMP6_TYPE_DUR = 1, + /** Packet too big */ + ICMP6_TYPE_PTB = 2, + /** Time exceeded */ + ICMP6_TYPE_TE = 3, + /** Parameter problem */ + ICMP6_TYPE_PP = 4, + /** Private experimentation */ + ICMP6_TYPE_PE1 = 100, + /** Private experimentation */ + ICMP6_TYPE_PE2 = 101, + /** Reserved for expansion of error messages */ + ICMP6_TYPE_RSV_ERR = 127, + + /** Echo request */ + ICMP6_TYPE_EREQ = 128, + /** Echo reply */ + ICMP6_TYPE_EREP = 129, + /** Multicast listener query */ + ICMP6_TYPE_MLQ = 130, + /** Multicast listener report */ + ICMP6_TYPE_MLR = 131, + /** Multicast listener done */ + ICMP6_TYPE_MLD = 132, + /** Router solicitation */ + ICMP6_TYPE_RS = 133, + /** Router advertisement */ + ICMP6_TYPE_RA = 134, + /** Neighbor solicitation */ + ICMP6_TYPE_NS = 135, + /** Neighbor advertisement */ + ICMP6_TYPE_NA = 136, + /** Redirect */ + ICMP6_TYPE_RD = 137, + /** Multicast router advertisement */ + ICMP6_TYPE_MRA = 151, + /** Multicast router solicitation */ + ICMP6_TYPE_MRS = 152, + /** Multicast router termination */ + ICMP6_TYPE_MRT = 153, + /** Private experimentation */ + ICMP6_TYPE_PE3 = 200, + /** Private experimentation */ + ICMP6_TYPE_PE4 = 201, + /** Reserved for expansion of informational messages */ + ICMP6_TYPE_RSV_INF = 255 +}; + +/** ICMP destination unreachable codes */ +enum icmp6_dur_code { + /** No route to destination */ + ICMP6_DUR_NO_ROUTE = 0, + /** Communication with destination administratively prohibited */ + ICMP6_DUR_PROHIBITED = 1, + /** Beyond scope of source address */ + ICMP6_DUR_SCOPE = 2, + /** Address unreachable */ + ICMP6_DUR_ADDRESS = 3, + /** Port unreachable */ + ICMP6_DUR_PORT = 4, + /** Source address failed ingress/egress policy */ + ICMP6_DUR_POLICY = 5, + /** Reject route to destination */ + ICMP6_DUR_REJECT_ROUTE = 6 +}; + +/** ICMP time exceeded codes */ +enum icmp6_te_code { + /** Hop limit exceeded in transit */ + ICMP6_TE_HL = 0, + /** Fragment reassembly time exceeded */ + ICMP6_TE_FRAG = 1 +}; + +/** ICMP parameter code */ +enum icmp6_pp_code { + /** Erroneous header field encountered */ + ICMP6_PP_FIELD = 0, + /** Unrecognized next header type encountered */ + ICMP6_PP_HEADER = 1, + /** Unrecognized IPv6 option encountered */ + ICMP6_PP_OPTION = 2 +}; + +/** This is the standard ICMP6 header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct icmp6_hdr { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t data); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define ICMP6_HLEN 8 + +/** This is the ICMP6 header adapted for echo req/resp. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct icmp6_echo_hdr { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u16_t id); + PACK_STRUCT_FIELD(u16_t seqno); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ICMP6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ieee.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ieee.h new file mode 100644 index 000000000..abbb9e31d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ieee.h @@ -0,0 +1,91 @@ +/** + * @file + * IEEE assigned numbers + * + * @defgroup ieee IEEE assigned numbers + * @ingroup infrastructure + */ + +/* + * Copyright (c) 2017 Dirk Ziegelmeier. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Dirk Ziegelmeier + * + */ + +#ifndef LWIP_HDR_PROT_IEEE_H +#define LWIP_HDR_PROT_IEEE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @ingroup ieee + * A list of often ethtypes (although lwIP does not use all of them). + */ +enum lwip_ieee_eth_type { + /** Internet protocol v4 */ + ETHTYPE_IP = 0x0800U, + /** Address resolution protocol */ + ETHTYPE_ARP = 0x0806U, + /** Wake on lan */ + ETHTYPE_WOL = 0x0842U, + /** RARP */ + ETHTYPE_RARP = 0x8035U, + /** Virtual local area network */ + ETHTYPE_VLAN = 0x8100U, + /** Internet protocol v6 */ + ETHTYPE_IPV6 = 0x86DDU, + /** PPP Over Ethernet Discovery Stage */ + ETHTYPE_PPPOEDISC = 0x8863U, + /** PPP Over Ethernet Session Stage */ + ETHTYPE_PPPOE = 0x8864U, + /** Jumbo Frames */ + ETHTYPE_JUMBO = 0x8870U, + /** Process field network */ + ETHTYPE_PROFINET = 0x8892U, + /** Ethernet for control automation technology */ + ETHTYPE_ETHERCAT = 0x88A4U, + /** Link layer discovery protocol */ + ETHTYPE_LLDP = 0x88CCU, + /** Serial real-time communication system */ + ETHTYPE_SERCOS = 0x88CDU, + /** Media redundancy protocol */ + ETHTYPE_MRP = 0x88E3U, + /** Precision time protocol */ + ETHTYPE_PTP = 0x88F7U, + /** Q-in-Q, 802.1ad */ + ETHTYPE_QINQ = 0x9100U +}; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IEEE_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/igmp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/igmp.h new file mode 100644 index 000000000..46b81a9dd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/igmp.h @@ -0,0 +1,90 @@ +/** + * @file + * IGMP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IGMP_H +#define LWIP_HDR_PROT_IGMP_H + +#include "lwip/arch.h" +#include "lwip/prot/ip4.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * IGMP constants + */ +#define IGMP_TTL 1 +#define IGMP_MINLEN 8 +#define ROUTER_ALERT 0x9404U +#define ROUTER_ALERTLEN 4 + +/* + * IGMP message types, including version number. + */ +#define IGMP_MEMB_QUERY 0x11 /* Membership query */ +#define IGMP_V1_MEMB_REPORT 0x12 /* Ver. 1 membership report */ +#define IGMP_V2_MEMB_REPORT 0x16 /* Ver. 2 membership report */ +#define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */ + +/* Group membership states */ +#define IGMP_GROUP_NON_MEMBER 0 +#define IGMP_GROUP_DELAYING_MEMBER 1 +#define IGMP_GROUP_IDLE_MEMBER 2 + +/** + * IGMP packet format. + */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct igmp_msg { + PACK_STRUCT_FLD_8(u8_t igmp_msgtype); + PACK_STRUCT_FLD_8(u8_t igmp_maxresp); + PACK_STRUCT_FIELD(u16_t igmp_checksum); + PACK_STRUCT_FLD_S(ip4_addr_p_t igmp_group_address); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IGMP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip.h new file mode 100644 index 000000000..223158f5a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip.h @@ -0,0 +1,59 @@ +/** + * @file + * IP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IP_H +#define LWIP_HDR_PROT_IP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define IP_PROTO_ICMP 1 +#define IP_PROTO_IGMP 2 +#define IP_PROTO_UDP 17 +#define IP_PROTO_UDPLITE 136 +#define IP_PROTO_TCP 6 + +/** This operates on a void* by loading the first byte */ +#define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip4.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip4.h new file mode 100644 index 000000000..eb18cf5ba --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip4.h @@ -0,0 +1,133 @@ +/** + * @file + * IPv4 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IP4_H +#define LWIP_HDR_PROT_IP4_H + +#include "lwip/arch.h" +#include "lwip/ip4_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** This is the packed version of ip4_addr_t, + used in network headers that are itself packed */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip4_addr_packed { + PACK_STRUCT_FIELD(u32_t addr); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +typedef struct ip4_addr_packed ip4_addr_p_t; + +/* Size of the IPv4 header. Same as 'sizeof(struct ip_hdr)'. */ +#define IP_HLEN 20 +/* Maximum size of the IPv4 header with options. */ +#define IP_HLEN_MAX 60 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/* The IPv4 header */ +struct ip_hdr { + /* version / header length */ + PACK_STRUCT_FLD_8(u8_t _v_hl); + /* type of service */ + PACK_STRUCT_FLD_8(u8_t _tos); + /* total length */ + PACK_STRUCT_FIELD(u16_t _len); + /* identification */ + PACK_STRUCT_FIELD(u16_t _id); + /* fragment offset field */ + PACK_STRUCT_FIELD(u16_t _offset); +#ifndef LWIP_SOCKET_STDINCLUDE +#define IP_RF 0x8000U /* reserved fragment flag */ +#define IP_DF 0x4000U /* don't fragment flag */ +#define IP_MF 0x2000U /* more fragments flag */ +#define IP_OFFMASK 0x1fffU /* mask for fragmenting bits */ +#endif /* LWIP_SOCKET_STDINCLUDE */ + /* time to live */ + PACK_STRUCT_FLD_8(u8_t _ttl); + /* protocol*/ + PACK_STRUCT_FLD_8(u8_t _proto); + /* checksum */ + PACK_STRUCT_FIELD(u16_t _chksum); + /* source and destination IP addresses */ + PACK_STRUCT_FLD_S(ip4_addr_p_t src); + PACK_STRUCT_FLD_S(ip4_addr_p_t dest); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/* Macros to get struct ip_hdr fields: */ +#define IPH_V(hdr) ((hdr)->_v_hl >> 4) +#define IPH_HL(hdr) ((hdr)->_v_hl & 0x0f) +#define IPH_HL_BYTES(hdr) ((u8_t)(IPH_HL(hdr) * 4)) +#define IPH_TOS(hdr) ((hdr)->_tos) +#define IPH_LEN(hdr) ((hdr)->_len) +#define IPH_ID(hdr) ((hdr)->_id) +#define IPH_OFFSET(hdr) ((hdr)->_offset) +#define IPH_OFFSET_BYTES(hdr) ((u16_t)((lwip_ntohs(IPH_OFFSET(hdr)) & IP_OFFMASK) * 8U)) +#define IPH_TTL(hdr) ((hdr)->_ttl) +#define IPH_PROTO(hdr) ((hdr)->_proto) +#define IPH_CHKSUM(hdr) ((hdr)->_chksum) + +/* Macros to set struct ip_hdr fields: */ +#define IPH_VHL_SET(hdr, v, hl) (hdr)->_v_hl = (u8_t)((((v) << 4) | (hl))) +#define IPH_TOS_SET(hdr, tos) (hdr)->_tos = (tos) +#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) +#define IPH_ID_SET(hdr, id) (hdr)->_id = (id) +#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) +#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl) +#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto) +#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IP4_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip6.h new file mode 100644 index 000000000..7df81edd6 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/ip6.h @@ -0,0 +1,235 @@ +/** + * @file + * IPv6 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_IP6_H +#define LWIP_HDR_PROT_IP6_H + +#include "lwip/arch.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define IP6_MIN_MTU_LENGTH 1280 + +/** This is the packed version of ip6_addr_t, + used in network headers that are itself packed */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_addr_packed { + PACK_STRUCT_FIELD(u32_t addr[4]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +typedef struct ip6_addr_packed ip6_addr_p_t; + +#define IP6_HLEN 40 + +#define IP6_NEXTH_HOPBYHOP 0 +#define IP6_NEXTH_TCP 6 +#define IP6_NEXTH_UDP 17 +#define IP6_NEXTH_ENCAPS 41 +#define IP6_NEXTH_ROUTING 43 +#define IP6_NEXTH_FRAGMENT 44 +#define IP6_NEXTH_ICMP6 58 +#define IP6_NEXTH_NONE 59 +#define IP6_NEXTH_DESTOPTS 60 +#define IP6_NEXTH_UDPLITE 136 + +/** The IPv6 header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_hdr { + /** version / traffic class / flow label */ + PACK_STRUCT_FIELD(u32_t _v_tc_fl); + /** payload length */ + PACK_STRUCT_FIELD(u16_t _plen); + /** next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /** hop limit */ + PACK_STRUCT_FLD_8(u8_t _hoplim); + /** source and destination IP addresses */ + PACK_STRUCT_FLD_S(ip6_addr_p_t src); + PACK_STRUCT_FLD_S(ip6_addr_p_t dest); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define IP6H_V(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f) +#define IP6H_TC(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 20) & 0xff) +#define IP6H_FL(hdr) (lwip_ntohl((hdr)->_v_tc_fl) & 0x000fffff) +#define IP6H_PLEN(hdr) (lwip_ntohs((hdr)->_plen)) +#define IP6H_NEXTH(hdr) ((hdr)->_nexth) +#define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6) +#define IP6H_HOPLIM(hdr) ((hdr)->_hoplim) +#define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (lwip_htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl))) +#define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = lwip_htons(plen) +#define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth) +#define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl) + +/* ipv6 extended options header */ +#define IP6_PAD1_OPTION 0 +#define IP6_PADN_OPTION 1 +#define IP6_ROUTER_ALERT_OPTION 5 +#define IP6_JUMBO_OPTION 194 +#define IP6_HOME_ADDRESS_OPTION 201 +#define IP6_ROUTER_ALERT_DLEN 2 +#define IP6_ROUTER_ALERT_VALUE_MLD 0 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_opt_hdr { + /* router alert option type */ + PACK_STRUCT_FLD_8(u8_t _opt_type); + /* router alert option data len */ + PACK_STRUCT_FLD_8(u8_t _opt_dlen); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define IP6_OPT_HLEN 2 +#define IP6_OPT_TYPE_ACTION(hdr) ((((hdr)->_opt_type) >> 6) & 0x3) +#define IP6_OPT_TYPE_CHANGE(hdr) ((((hdr)->_opt_type) >> 5) & 0x1) +#define IP6_OPT_TYPE(hdr) ((hdr)->_opt_type) +#define IP6_OPT_DLEN(hdr) ((hdr)->_opt_dlen) + +/* Hop-by-Hop header. */ +#define IP6_HBH_HLEN 2 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_hbh_hdr { + /* next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /* header length in 8-octet units */ + PACK_STRUCT_FLD_8(u8_t _hlen); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define IP6_HBH_NEXTH(hdr) ((hdr)->_nexth) + +/* Destination header. */ +#define IP6_DEST_HLEN 2 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_dest_hdr { + /* next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /* header length in 8-octet units */ + PACK_STRUCT_FLD_8(u8_t _hlen); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define IP6_DEST_NEXTH(hdr) ((hdr)->_nexth) + +/* Routing header */ +#define IP6_ROUT_TYPE2 2 +#define IP6_ROUT_RPL 3 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_rout_hdr { + /* next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /* reserved */ + PACK_STRUCT_FLD_8(u8_t _hlen); + /* fragment offset */ + PACK_STRUCT_FIELD(u8_t _routing_type); + /* fragmented packet identification */ + PACK_STRUCT_FIELD(u8_t _segments_left); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define IP6_ROUT_NEXTH(hdr) ((hdr)->_nexth) +#define IP6_ROUT_TYPE(hdr) ((hdr)->_routing_type) +#define IP6_ROUT_SEG_LEFT(hdr) ((hdr)->_segments_left) + +/* Fragment header. */ +#define IP6_FRAG_HLEN 8 +#define IP6_FRAG_OFFSET_MASK 0xfff8 +#define IP6_FRAG_MORE_FLAG 0x0001 + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ip6_frag_hdr { + /* next header */ + PACK_STRUCT_FLD_8(u8_t _nexth); + /* reserved */ + PACK_STRUCT_FLD_8(u8_t reserved); + /* fragment offset */ + PACK_STRUCT_FIELD(u16_t _fragment_offset); + /* fragmented packet identification */ + PACK_STRUCT_FIELD(u32_t _identification); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define IP6_FRAG_NEXTH(hdr) ((hdr)->_nexth) +#define IP6_FRAG_MBIT(hdr) (lwip_ntohs((hdr)->_fragment_offset) & 0x1) +#define IP6_FRAG_ID(hdr) (lwip_ntohl((hdr)->_identification)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_IP6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/mld6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/mld6.h new file mode 100644 index 000000000..71f1dcbdc --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/mld6.h @@ -0,0 +1,71 @@ +/** + * @file + * MLD6 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_MLD6_H +#define LWIP_HDR_PROT_MLD6_H + +#include "lwip/arch.h" +#include "lwip/prot/ip6.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MLD6_HBH_HLEN 8 +/** Multicast listener report/query/done message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct mld_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u16_t max_resp_delay); + PACK_STRUCT_FIELD(u16_t reserved); + PACK_STRUCT_FLD_S(ip6_addr_p_t multicast_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_MLD6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/nd6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/nd6.h new file mode 100644 index 000000000..c270d07c1 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/nd6.h @@ -0,0 +1,274 @@ +/** + * @file + * ND6 protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_ND6_H +#define LWIP_HDR_PROT_ND6_H + +#include "lwip/arch.h" +#include "lwip/ip6_addr.h" +#include "lwip/prot/ip6.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Neighbor solicitation message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ns_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t reserved); + PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Neighbor advertisement message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct na_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FLD_8(u8_t flags); + PACK_STRUCT_FLD_8(u8_t reserved[3]); + PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif +#define ND6_FLAG_ROUTER (0x80) +#define ND6_FLAG_SOLICITED (0x40) +#define ND6_FLAG_OVERRIDE (0x20) + +/** Router solicitation message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct rs_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t reserved); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Router advertisement message header. */ +#define ND6_RA_FLAG_MANAGED_ADDR_CONFIG (0x80) +#define ND6_RA_FLAG_OTHER_CONFIG (0x40) +#define ND6_RA_FLAG_HOME_AGENT (0x20) +#define ND6_RA_PREFERENCE_MASK (0x18) +#define ND6_RA_PREFERENCE_HIGH (0x08) +#define ND6_RA_PREFERENCE_MEDIUM (0x00) +#define ND6_RA_PREFERENCE_LOW (0x18) +#define ND6_RA_PREFERENCE_DISABLED (0x10) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct ra_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FLD_8(u8_t current_hop_limit); + PACK_STRUCT_FLD_8(u8_t flags); + PACK_STRUCT_FIELD(u16_t router_lifetime); + PACK_STRUCT_FIELD(u32_t reachable_time); + PACK_STRUCT_FIELD(u32_t retrans_timer); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Redirect message header. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct redirect_header { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u32_t reserved); + PACK_STRUCT_FLD_S(ip6_addr_p_t target_address); + PACK_STRUCT_FLD_S(ip6_addr_p_t destination_address); + /* Options follow. */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Link-layer address option. */ +#define ND6_OPTION_TYPE_SOURCE_LLADDR (0x01) +#define ND6_OPTION_TYPE_TARGET_LLADDR (0x02) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct lladdr_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t addr[NETIF_MAX_HWADDR_LEN]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Prefix information option. */ +#define ND6_OPTION_TYPE_PREFIX_INFO (0x03) +#define ND6_PREFIX_FLAG_ON_LINK (0x80) +#define ND6_PREFIX_FLAG_AUTONOMOUS (0x40) +#define ND6_PREFIX_FLAG_ROUTER_ADDRESS (0x20) +#define ND6_PREFIX_FLAG_SITE_PREFIX (0x10) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct prefix_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t prefix_length); + PACK_STRUCT_FLD_8(u8_t flags); + PACK_STRUCT_FIELD(u32_t valid_lifetime); + PACK_STRUCT_FIELD(u32_t preferred_lifetime); + PACK_STRUCT_FLD_8(u8_t reserved2[3]); + PACK_STRUCT_FLD_8(u8_t site_prefix_length); + PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Redirected header option. */ +#define ND6_OPTION_TYPE_REDIR_HDR (0x04) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct redirected_header_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t reserved[6]); + /* Portion of redirected packet follows. */ + /* PACK_STRUCT_FLD_8(u8_t redirected[8]); */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** MTU option. */ +#define ND6_OPTION_TYPE_MTU (0x05) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct mtu_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FIELD(u16_t reserved); + PACK_STRUCT_FIELD(u32_t mtu); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Route information option. */ +#define ND6_OPTION_TYPE_ROUTE_INFO (24) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct route_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FLD_8(u8_t prefix_length); + PACK_STRUCT_FLD_8(u8_t preference); + PACK_STRUCT_FIELD(u32_t route_lifetime); + PACK_STRUCT_FLD_S(ip6_addr_p_t prefix); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/** Recursive DNS Server Option. */ +#define ND6_OPTION_TYPE_RDNSS (25) +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct rdnss_option { + PACK_STRUCT_FLD_8(u8_t type); + PACK_STRUCT_FLD_8(u8_t length); + PACK_STRUCT_FIELD(u16_t reserved); + PACK_STRUCT_FIELD(u32_t lifetime); + PACK_STRUCT_FLD_S(ip6_addr_p_t rdnss_address[1]); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#define SIZEOF_RDNSS_OPTION_BASE 8 /* size without addresses */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_ND6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/tcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/tcp.h new file mode 100644 index 000000000..c1d7de1fa --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/tcp.h @@ -0,0 +1,100 @@ +/** + * @file + * TCP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_TCP_H +#define LWIP_HDR_PROT_TCP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Length of the TCP header, excluding options. */ +#define TCP_HLEN 20 + +/* Fields are (of course) in network byte order. + * Some fields are converted to host byte order in tcp_input(). + */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct tcp_hdr { + PACK_STRUCT_FIELD(u16_t src); + PACK_STRUCT_FIELD(u16_t dest); + PACK_STRUCT_FIELD(u32_t seqno); + PACK_STRUCT_FIELD(u32_t ackno); + PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags); + PACK_STRUCT_FIELD(u16_t wnd); + PACK_STRUCT_FIELD(u16_t chksum); + PACK_STRUCT_FIELD(u16_t urgp); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/* TCP header flags bits */ +#define TCP_FIN 0x01U +#define TCP_SYN 0x02U +#define TCP_RST 0x04U +#define TCP_PSH 0x08U +#define TCP_ACK 0x10U +#define TCP_URG 0x20U +#define TCP_ECE 0x40U +#define TCP_CWR 0x80U +/* Valid TCP header flags */ +#define TCP_FLAGS 0x3fU + +#define TCP_MAX_OPTION_BYTES 40 + +#define TCPH_HDRLEN(phdr) ((u16_t)(lwip_ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)) +#define TCPH_HDRLEN_BYTES(phdr) ((u8_t)(TCPH_HDRLEN(phdr) << 2)) +#define TCPH_FLAGS(phdr) ((u8_t)((lwip_ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS))) + +#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = lwip_htons(((len) << 12) | TCPH_FLAGS(phdr)) +#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | lwip_htons(flags)) +#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = (u16_t)(lwip_htons((u16_t)((len) << 12) | (flags))) + +#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | lwip_htons(flags)) +#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~lwip_htons(flags)) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_TCP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/udp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/udp.h new file mode 100644 index 000000000..664f19a3e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/prot/udp.h @@ -0,0 +1,68 @@ +/** + * @file + * UDP protocol definitions + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_PROT_UDP_H +#define LWIP_HDR_PROT_UDP_H + +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define UDP_HLEN 8 + +/* Fields are (of course) in network byte order. */ +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct udp_hdr { + PACK_STRUCT_FIELD(u16_t src); + PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ + PACK_STRUCT_FIELD(u16_t len); + PACK_STRUCT_FIELD(u16_t chksum); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_PROT_UDP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/raw.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/raw.h new file mode 100644 index 000000000..b129bd3b9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/raw.h @@ -0,0 +1,143 @@ +/** + * @file + * raw API (to be used from TCPIP thread)\n + * See also @ref raw_raw + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_RAW_H +#define LWIP_HDR_RAW_H + +#include "lwip/opt.h" + +#if LWIP_RAW /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/pbuf.h" +#include "lwip/def.h" +#include "lwip/ip.h" +#include "lwip/ip_addr.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define RAW_FLAGS_CONNECTED 0x01U +#define RAW_FLAGS_HDRINCL 0x02U +#define RAW_FLAGS_MULTICAST_LOOP 0x04U + +struct raw_pcb; + +/** Function prototype for raw pcb receive callback functions. + * @param arg user supplied argument (raw_pcb.recv_arg) + * @param pcb the raw_pcb which received data + * @param p the packet buffer that was received + * @param addr the remote IP address from which the packet was received + * @return 1 if the packet was 'eaten' (aka. deleted), + * 0 if the packet lives on + * If returning 1, the callback is responsible for freeing the pbuf + * if it's not used any more. + */ +typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p, + const ip_addr_t *addr); + +/** the RAW protocol control block */ +struct raw_pcb { + /* Common members of all PCB types */ + IP_PCB; + + struct raw_pcb *next; + + u8_t protocol; + u8_t flags; + +#if LWIP_MULTICAST_TX_OPTIONS + /** outgoing network interface for multicast packets, by interface index (if nonzero) */ + u8_t mcast_ifindex; + /** TTL for outgoing multicast packets */ + u8_t mcast_ttl; +#endif /* LWIP_MULTICAST_TX_OPTIONS */ + + /** receive callback function */ + raw_recv_fn recv; + /* user-supplied argument for the recv callback */ + void *recv_arg; +#if LWIP_IPV6 + /* fields for handling checksum computations as per RFC3542. */ + u16_t chksum_offset; + u8_t chksum_reqd; +#endif +}; + +/* The following functions is the application layer interface to the + RAW code. */ +struct raw_pcb * raw_new (u8_t proto); +struct raw_pcb * raw_new_ip_type(u8_t type, u8_t proto); +void raw_remove (struct raw_pcb *pcb); +err_t raw_bind (struct raw_pcb *pcb, const ip_addr_t *ipaddr); +void raw_bind_netif (struct raw_pcb *pcb, const struct netif *netif); +err_t raw_connect (struct raw_pcb *pcb, const ip_addr_t *ipaddr); +void raw_disconnect (struct raw_pcb *pcb); + +err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr); +err_t raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, struct netif *netif, const ip_addr_t *src_ip); +err_t raw_send (struct raw_pcb *pcb, struct pbuf *p); + +void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg); + +#define raw_flags(pcb) ((pcb)->flags) +#define raw_setflags(pcb,f) ((pcb)->flags = (f)) + +#define raw_set_flags(pcb, set_flags) do { (pcb)->flags = (u8_t)((pcb)->flags | (set_flags)); } while(0) +#define raw_clear_flags(pcb, clr_flags) do { (pcb)->flags = (u8_t)((pcb)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0) +#define raw_is_flag_set(pcb, flag) (((pcb)->flags & (flag)) != 0) + +#define raw_init() /* Compatibility define, no init needed. */ + +/* for compatibility with older implementation */ +#define raw_new_ip6(proto) raw_new_ip_type(IPADDR_TYPE_V6, proto) + +#if LWIP_MULTICAST_TX_OPTIONS +#define raw_set_multicast_netif_index(pcb, idx) ((pcb)->mcast_ifindex = (idx)) +#define raw_get_multicast_netif_index(pcb) ((pcb)->mcast_ifindex) +#define raw_set_multicast_ttl(pcb, value) ((pcb)->mcast_ttl = (value)) +#define raw_get_multicast_ttl(pcb) ((pcb)->mcast_ttl) +#endif /* LWIP_MULTICAST_TX_OPTIONS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_RAW */ + +#endif /* LWIP_HDR_RAW_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sio.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sio.h new file mode 100644 index 000000000..7643e1956 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sio.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + */ + +/* + * This is the interface to the platform specific serial IO module + * It needs to be implemented by those platforms which need SLIP or PPP + */ + +#ifndef SIO_H +#define SIO_H + +#include "lwip/arch.h" +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* If you want to define sio_fd_t elsewhere or differently, + define this in your cc.h file. */ +#ifndef __sio_fd_t_defined +typedef void * sio_fd_t; +#endif + +/* The following functions can be defined to something else in your cc.h file + or be implemented in your custom sio.c file. */ + +#ifndef sio_open +/** + * Opens a serial device for communication. + * + * @param devnum device number + * @return handle to serial device if successful, NULL otherwise + */ +sio_fd_t sio_open(u8_t devnum); +#endif + +#ifndef sio_send +/** + * Sends a single character to the serial device. + * + * @param c character to send + * @param fd serial device handle + * + * @note This function will block until the character can be sent. + */ +void sio_send(u8_t c, sio_fd_t fd); +#endif + +#ifndef sio_recv +/** + * Receives a single character from the serial device. + * + * @param fd serial device handle + * + * @note This function will block until a character is received. + */ +u8_t sio_recv(sio_fd_t fd); +#endif + +#ifndef sio_read +/** + * Reads from the serial device. + * + * @param fd serial device handle + * @param data pointer to data buffer for receiving + * @param len maximum length (in bytes) of data to receive + * @return number of bytes actually received - may be 0 if aborted by sio_read_abort + * + * @note This function will block until data can be received. The blocking + * can be cancelled by calling sio_read_abort(). + */ +u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len); +#endif + +#ifndef sio_tryread +/** + * Tries to read from the serial device. Same as sio_read but returns + * immediately if no data is available and never blocks. + * + * @param fd serial device handle + * @param data pointer to data buffer for receiving + * @param len maximum length (in bytes) of data to receive + * @return number of bytes actually received + */ +u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len); +#endif + +#ifndef sio_write +/** + * Writes to the serial device. + * + * @param fd serial device handle + * @param data pointer to data to send + * @param len length (in bytes) of data to send + * @return number of bytes actually sent + * + * @note This function will block until all data can be sent. + */ +u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len); +#endif + +#ifndef sio_read_abort +/** + * Aborts a blocking sio_read() call. + * + * @param fd serial device handle + */ +void sio_read_abort(sio_fd_t fd); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* SIO_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/snmp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/snmp.h new file mode 100644 index 000000000..8704d0b4d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/snmp.h @@ -0,0 +1,213 @@ +/** + * @file + * SNMP support API for implementing netifs and statitics for MIB2 + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Dirk Ziegelmeier + * + */ +#ifndef LWIP_HDR_SNMP_H +#define LWIP_HDR_SNMP_H + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct udp_pcb; +struct netif; + +/** + * @defgroup netif_mib2 MIB2 statistics + * @ingroup netif + */ + +/* MIB2 statistics functions */ +#if MIB2_STATS /* don't build if not configured for use in lwipopts.h */ +/** + * @ingroup netif_mib2 + * @see RFC1213, "MIB-II, 6. Definitions" + */ +enum snmp_ifType { + snmp_ifType_other=1, /* none of the following */ + snmp_ifType_regular1822, + snmp_ifType_hdh1822, + snmp_ifType_ddn_x25, + snmp_ifType_rfc877_x25, + snmp_ifType_ethernet_csmacd, + snmp_ifType_iso88023_csmacd, + snmp_ifType_iso88024_tokenBus, + snmp_ifType_iso88025_tokenRing, + snmp_ifType_iso88026_man, + snmp_ifType_starLan, + snmp_ifType_proteon_10Mbit, + snmp_ifType_proteon_80Mbit, + snmp_ifType_hyperchannel, + snmp_ifType_fddi, + snmp_ifType_lapb, + snmp_ifType_sdlc, + snmp_ifType_ds1, /* T-1 */ + snmp_ifType_e1, /* european equiv. of T-1 */ + snmp_ifType_basicISDN, + snmp_ifType_primaryISDN, /* proprietary serial */ + snmp_ifType_propPointToPointSerial, + snmp_ifType_ppp, + snmp_ifType_softwareLoopback, + snmp_ifType_eon, /* CLNP over IP [11] */ + snmp_ifType_ethernet_3Mbit, + snmp_ifType_nsip, /* XNS over IP */ + snmp_ifType_slip, /* generic SLIP */ + snmp_ifType_ultra, /* ULTRA technologies */ + snmp_ifType_ds3, /* T-3 */ + snmp_ifType_sip, /* SMDS */ + snmp_ifType_frame_relay +}; + +/** This macro has a precision of ~49 days because sys_now returns u32_t. \#define your own if you want ~490 days. */ +#ifndef MIB2_COPY_SYSUPTIME_TO +#define MIB2_COPY_SYSUPTIME_TO(ptrToVal) (*(ptrToVal) = (sys_now() / 10)) +#endif + +/** + * @ingroup netif_mib2 + * Increment stats member for SNMP MIB2 stats (struct stats_mib2_netif_ctrs) + */ +#define MIB2_STATS_NETIF_INC(n, x) do { ++(n)->mib2_counters.x; } while(0) +/** + * @ingroup netif_mib2 + * Add value to stats member for SNMP MIB2 stats (struct stats_mib2_netif_ctrs) + */ +#define MIB2_STATS_NETIF_ADD(n, x, val) do { (n)->mib2_counters.x += (val); } while(0) + +/** + * @ingroup netif_mib2 + * Init MIB2 statistic counters in netif + * @param netif Netif to init + * @param type one of enum @ref snmp_ifType + * @param speed your link speed here (units: bits per second) + */ +#define MIB2_INIT_NETIF(netif, type, speed) do { \ + (netif)->link_type = (type); \ + (netif)->link_speed = (speed);\ + (netif)->ts = 0; \ + (netif)->mib2_counters.ifinoctets = 0; \ + (netif)->mib2_counters.ifinucastpkts = 0; \ + (netif)->mib2_counters.ifinnucastpkts = 0; \ + (netif)->mib2_counters.ifindiscards = 0; \ + (netif)->mib2_counters.ifinerrors = 0; \ + (netif)->mib2_counters.ifinunknownprotos = 0; \ + (netif)->mib2_counters.ifoutoctets = 0; \ + (netif)->mib2_counters.ifoutucastpkts = 0; \ + (netif)->mib2_counters.ifoutnucastpkts = 0; \ + (netif)->mib2_counters.ifoutdiscards = 0; \ + (netif)->mib2_counters.ifouterrors = 0; } while(0) +#else /* MIB2_STATS */ +#ifndef MIB2_COPY_SYSUPTIME_TO +#define MIB2_COPY_SYSUPTIME_TO(ptrToVal) +#endif +#define MIB2_INIT_NETIF(netif, type, speed) +#define MIB2_STATS_NETIF_INC(n, x) +#define MIB2_STATS_NETIF_ADD(n, x, val) +#endif /* MIB2_STATS */ + +/* LWIP MIB2 callbacks */ +#if LWIP_MIB2_CALLBACKS /* don't build if not configured for use in lwipopts.h */ +/* network interface */ +void mib2_netif_added(struct netif *ni); +void mib2_netif_removed(struct netif *ni); + +#if LWIP_IPV4 && LWIP_ARP +/* ARP (for atTable and ipNetToMediaTable) */ +void mib2_add_arp_entry(struct netif *ni, ip4_addr_t *ip); +void mib2_remove_arp_entry(struct netif *ni, ip4_addr_t *ip); +#else /* LWIP_IPV4 && LWIP_ARP */ +#define mib2_add_arp_entry(ni,ip) +#define mib2_remove_arp_entry(ni,ip) +#endif /* LWIP_IPV4 && LWIP_ARP */ + +/* IP */ +#if LWIP_IPV4 +void mib2_add_ip4(struct netif *ni); +void mib2_remove_ip4(struct netif *ni); +void mib2_add_route_ip4(u8_t dflt, struct netif *ni); +void mib2_remove_route_ip4(u8_t dflt, struct netif *ni); +#endif /* LWIP_IPV4 */ + +/* UDP */ +#if LWIP_UDP +void mib2_udp_bind(struct udp_pcb *pcb); +void mib2_udp_unbind(struct udp_pcb *pcb); +#endif /* LWIP_UDP */ + +#else /* LWIP_MIB2_CALLBACKS */ +/* LWIP_MIB2_CALLBACKS support not available */ +/* define everything to be empty */ + +/* network interface */ +#define mib2_netif_added(ni) +#define mib2_netif_removed(ni) + +/* ARP */ +#define mib2_add_arp_entry(ni,ip) +#define mib2_remove_arp_entry(ni,ip) + +/* IP */ +#define mib2_add_ip4(ni) +#define mib2_remove_ip4(ni) +#define mib2_add_route_ip4(dflt, ni) +#define mib2_remove_route_ip4(dflt, ni) + +/* UDP */ +#define mib2_udp_bind(pcb) +#define mib2_udp_unbind(pcb) +#endif /* LWIP_MIB2_CALLBACKS */ + +/* for source-code compatibility reasons only, can be removed (not used internally) */ +#define NETIF_INIT_SNMP MIB2_INIT_NETIF +#define snmp_add_ifinoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifinoctets, value) +#define snmp_inc_ifinucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinucastpkts) +#define snmp_inc_ifinnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifinnucastpkts) +#define snmp_inc_ifindiscards(ni) MIB2_STATS_NETIF_INC(ni, ifindiscards) +#define snmp_inc_ifinerrors(ni) MIB2_STATS_NETIF_INC(ni, ifinerrors) +#define snmp_inc_ifinunknownprotos(ni) MIB2_STATS_NETIF_INC(ni, ifinunknownprotos) +#define snmp_add_ifoutoctets(ni,value) MIB2_STATS_NETIF_ADD(ni, ifoutoctets, value) +#define snmp_inc_ifoutucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutucastpkts) +#define snmp_inc_ifoutnucastpkts(ni) MIB2_STATS_NETIF_INC(ni, ifoutnucastpkts) +#define snmp_inc_ifoutdiscards(ni) MIB2_STATS_NETIF_INC(ni, ifoutdiscards) +#define snmp_inc_ifouterrors(ni) MIB2_STATS_NETIF_INC(ni, ifouterrors) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_SNMP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sockets.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sockets.h new file mode 100644 index 000000000..7d089b726 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sockets.h @@ -0,0 +1,707 @@ +/** + * @file + * Socket API (to be used from non-TCPIP threads) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + + +#ifndef LWIP_HDR_SOCKETS_H +#define LWIP_HDR_SOCKETS_H + +#include "lwip/opt.h" + +#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/ip_addr.h" +#include "lwip/netif.h" +#include "lwip/err.h" +#include "lwip/inet.h" +#include "lwip/errno.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif +#ifndef LWIP_SOCKET_STDINCLUDE +/* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED + to prevent this code from redefining it. */ +#if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED) +typedef u8_t sa_family_t; +#endif +/* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED + to prevent this code from redefining it. */ +#if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED) +typedef u16_t in_port_t; +#endif + +#if LWIP_IPV4 +/* members are in network byte order */ +struct sockaddr_in { + u8_t sin_len; + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; +#define SIN_ZERO_LEN 8 + char sin_zero[SIN_ZERO_LEN]; +}; +#endif /* LWIP_IPV4 */ + +#if LWIP_IPV6 +struct sockaddr_in6 { + u8_t sin6_len; /* length of this structure */ + sa_family_t sin6_family; /* AF_INET6 */ + in_port_t sin6_port; /* Transport layer port # */ + u32_t sin6_flowinfo; /* IPv6 flow information */ + struct in6_addr sin6_addr; /* IPv6 address */ + u32_t sin6_scope_id; /* Set of interfaces for scope */ +}; +#endif /* LWIP_IPV6 */ + +struct sockaddr { + u8_t sa_len; + sa_family_t sa_family; + char sa_data[14]; +}; + +struct sockaddr_storage { + u8_t s2_len; + sa_family_t ss_family; + char s2_data1[2]; + u32_t s2_data2[3]; +#if LWIP_IPV6 + u32_t s2_data3[3]; +#endif /* LWIP_IPV6 */ +}; + +/* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED + to prevent this code from redefining it. */ +#if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED) +typedef u32_t socklen_t; +#endif + +#if !defined IOV_MAX +#define IOV_MAX 0xFFFF +#elif IOV_MAX > 0xFFFF +#error "IOV_MAX larger than supported by LwIP" +#endif /* IOV_MAX */ + +#if !defined(iovec) +struct iovec { + void *iov_base; + size_t iov_len; +}; +#endif + +struct msghdr { + void *msg_name; + socklen_t msg_namelen; + struct iovec *msg_iov; + int msg_iovlen; + void *msg_control; + socklen_t msg_controllen; + int msg_flags; +}; + +/* struct msghdr->msg_flags bit field values */ +#define MSG_TRUNC 0x04 +#define MSG_CTRUNC 0x08 + +/* RFC 3542, Section 20: Ancillary Data */ +struct cmsghdr { + socklen_t cmsg_len; /* number of bytes, including header */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +}; +/* Data section follows header and possible padding, typically referred to as + unsigned char cmsg_data[]; */ + +/* cmsg header/data alignment. NOTE: we align to native word size (double word +size on 16-bit arch) so structures are not placed at an unaligned address. +16-bit arch needs double word to ensure 32-bit alignment because socklen_t +could be 32 bits. If we ever have cmsg data with a 64-bit variable, alignment +will need to increase long long */ +#define ALIGN_H(size) (((size) + sizeof(long) - 1U) & ~(sizeof(long)-1U)) +#define ALIGN_D(size) ALIGN_H(size) + +#define CMSG_FIRSTHDR(mhdr) \ + ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ + (struct cmsghdr *)(mhdr)->msg_control : \ + (struct cmsghdr *)NULL) + +#define CMSG_NXTHDR(mhdr, cmsg) \ + (((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \ + (((u8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) \ + + ALIGN_D(sizeof(struct cmsghdr)) > \ + (u8_t *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)NULL : \ + (struct cmsghdr *)((void*)((u8_t *)(cmsg) + \ + ALIGN_H((cmsg)->cmsg_len))))) + +#define CMSG_DATA(cmsg) ((void*)((u8_t *)(cmsg) + \ + ALIGN_D(sizeof(struct cmsghdr)))) + +#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ + ALIGN_H(length)) + +#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ + length) + +/* Set socket options argument */ +#define IFNAMSIZ NETIF_NAMESIZE +struct ifreq { + char ifr_name[IFNAMSIZ]; /* Interface name */ +}; + +/* Socket protocol types (TCP/UDP/RAW) */ +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 + +/* + * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) + */ +#define SO_REUSEADDR 0x0004 /* Allow local address reuse */ +#define SO_KEEPALIVE 0x0008 /* keep connections alive */ +#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ + + +/* + * Additional options, not kept in so_options. + */ +#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */ +#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ +#define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */ +#define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ +#define SO_LINGER 0x0080 /* linger on close if data present */ +#define SO_DONTLINGER ((int)(~SO_LINGER)) +#define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */ +#define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */ +#define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */ +#define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */ +#define SO_SNDTIMEO 0x1005 /* send timeout */ +#define SO_RCVTIMEO 0x1006 /* receive timeout */ +#define SO_ERROR 0x1007 /* get error status and clear */ +#define SO_TYPE 0x1008 /* get socket type */ +#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ +#define SO_NO_CHECK 0x100a /* don't create UDP checksum */ +#define SO_BINDTODEVICE 0x100b /* bind to device */ + +/* + * Structure used for manipulating linger option. + */ +struct linger { + int l_onoff; /* option on/off */ + int l_linger; /* linger time in seconds */ +}; + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 0xfff /* options for socket level */ + + +#define AF_UNSPEC 0 +#define AF_INET 2 +#if LWIP_IPV6 +#define AF_INET6 10 +#else /* LWIP_IPV6 */ +#define AF_INET6 AF_UNSPEC +#endif /* LWIP_IPV6 */ +#define PF_INET AF_INET +#define PF_INET6 AF_INET6 +#define PF_UNSPEC AF_UNSPEC + +#define IPPROTO_IP 0 +#define IPPROTO_ICMP 1 +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 +#if LWIP_IPV6 +#define IPPROTO_IPV6 41 +#define IPPROTO_ICMPV6 58 +#endif /* LWIP_IPV6 */ +#define IPPROTO_UDPLITE 136 +#define IPPROTO_RAW 255 + +/* Flags we can use with send and recv. */ +#define MSG_PEEK 0x01 /* Peeks at an incoming message */ +#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */ +#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */ +#define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ +#define MSG_MORE 0x10 /* Sender will send more */ +#define MSG_NOSIGNAL 0x20 /* Uninmplemented: Requests not to send the SIGPIPE signal if an attempt to send is made on a stream-oriented socket that is no longer connected. */ + + +/* + * Options for level IPPROTO_IP + */ +#define IP_TOS 1 +#define IP_TTL 2 +#define IP_PKTINFO 8 + +#if LWIP_TCP +/* + * Options for level IPPROTO_TCP + */ +#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ +#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ +#define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ +#define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ +#define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ +#endif /* LWIP_TCP */ + +#if LWIP_IPV6 +/* + * Options for level IPPROTO_IPV6 + */ +#define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */ +#define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */ +#endif /* LWIP_IPV6 */ + +#if LWIP_UDP && LWIP_UDPLITE +/* + * Options for level IPPROTO_UDPLITE + */ +#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ +#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ +#endif /* LWIP_UDP && LWIP_UDPLITE*/ + + +#if LWIP_MULTICAST_TX_OPTIONS +/* + * Options and types for UDP multicast traffic handling + */ +#define IP_MULTICAST_TTL 5 +#define IP_MULTICAST_IF 6 +#define IP_MULTICAST_LOOP 7 +#endif /* LWIP_MULTICAST_TX_OPTIONS */ + +#if LWIP_IGMP +/* + * Options and types related to multicast membership + */ +#define IP_ADD_MEMBERSHIP 3 +#define IP_DROP_MEMBERSHIP 4 + +typedef struct ip_mreq { + struct in_addr imr_multiaddr; /* IP multicast address of group */ + struct in_addr imr_interface; /* local IP address of interface */ +} ip_mreq; +#endif /* LWIP_IGMP */ + +#if LWIP_IPV4 +struct in_pktinfo { + unsigned int ipi_ifindex; /* Interface index */ + struct in_addr ipi_addr; /* Destination (from header) address */ +}; +#endif /* LWIP_IPV4 */ + +#if LWIP_IPV6_MLD +/* + * Options and types related to IPv6 multicast membership + */ +#define IPV6_JOIN_GROUP 12 +#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP +#define IPV6_LEAVE_GROUP 13 +#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP + +typedef struct ipv6_mreq { + struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ + unsigned int ipv6mr_interface; /* interface index, or 0 */ +} ipv6_mreq; +#endif /* LWIP_IPV6_MLD */ + +/* + * The Type of Service provides an indication of the abstract + * parameters of the quality of service desired. These parameters are + * to be used to guide the selection of the actual service parameters + * when transmitting a datagram through a particular network. Several + * networks offer service precedence, which somehow treats high + * precedence traffic as more important than other traffic (generally + * by accepting only traffic above a certain precedence at time of high + * load). The major choice is a three way tradeoff between low-delay, + * high-reliability, and high-throughput. + * The use of the Delay, Throughput, and Reliability indications may + * increase the cost (in some sense) of the service. In many networks + * better performance for one of these parameters is coupled with worse + * performance on another. Except for very unusual cases at most two + * of these three indications should be set. + */ +#define IPTOS_TOS_MASK 0x1E +#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 +#define IPTOS_LOWCOST 0x02 +#define IPTOS_MINCOST IPTOS_LOWCOST + +/* + * The Network Control precedence designation is intended to be used + * within a network only. The actual use and control of that + * designation is up to each network. The Internetwork Control + * designation is intended for use by gateway control originators only. + * If the actual use of these precedence designations is of concern to + * a particular network, it is the responsibility of that network to + * control the access to, and use of, those precedence designations. + */ +#define IPTOS_PREC_MASK 0xe0 +#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 + + +/* + * Commands for ioctlsocket(), taken from the BSD file fcntl.h. + * lwip_ioctl only supports FIONREAD and FIONBIO, for now + * + * Ioctl's have the command encoded in the lower word, + * and the size of any in or out parameters in the upper + * word. The high 2 bits of the upper word are used + * to encode the in/out status of the parameter; for now + * we restrict parameters to at most 128 bytes. + */ +#if !defined(FIONREAD) || !defined(FIONBIO) +#define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */ +#define IOC_VOID 0x20000000UL /* no parameters */ +#define IOC_OUT 0x40000000UL /* copy out parameters */ +#define IOC_IN 0x80000000UL /* copy in parameters */ +#define IOC_INOUT (IOC_IN|IOC_OUT) + /* 0x20000000 distinguishes new & + old ioctl's */ +#define _IO(x,y) ((long)(IOC_VOID|((x)<<8)|(y))) + +#define _IOR(x,y,t) ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) + +#define _IOW(x,y,t) ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))) +#endif /* !defined(FIONREAD) || !defined(FIONBIO) */ + +#ifndef FIONREAD +#define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */ +#endif +#ifndef FIONBIO +#define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */ +#endif + +/* Socket I/O Controls: unimplemented */ +#ifndef SIOCSHIWAT +#define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */ +#define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */ +#define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */ +#define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */ +#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */ +#endif + +/* commands for fnctl */ +#ifndef F_GETFL +#define F_GETFL 3 +#endif +#ifndef F_SETFL +#define F_SETFL 4 +#endif + +/* File status flags and file access modes for fnctl, + these are bits in an int. */ +#ifndef O_NONBLOCK +#define O_NONBLOCK 1 /* nonblocking I/O */ +#endif +#ifndef O_NDELAY +#define O_NDELAY O_NONBLOCK /* same as O_NONBLOCK, for compatibility */ +#endif +#ifndef O_RDONLY +#define O_RDONLY 2 +#endif +#ifndef O_WRONLY +#define O_WRONLY 4 +#endif +#ifndef O_RDWR +#define O_RDWR (O_RDONLY|O_WRONLY) +#endif + +#ifndef SHUT_RD + #define SHUT_RD 0 + #define SHUT_WR 1 + #define SHUT_RDWR 2 +#endif + +/* FD_SET used for lwip_select */ +#ifndef FD_SET +#undef FD_SETSIZE +/* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ +#define FD_SETSIZE MEMP_NUM_NETCONN +#define LWIP_SELECT_MAXNFDS (FD_SETSIZE + LWIP_SOCKET_OFFSET) +#define FDSETSAFESET(n, code) do { \ + if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \ + code; }} while(0) +#define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\ + (code) : 0) +#define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] | (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))) +#define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] = (u8_t)((p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))) +#define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7))) +#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) + +typedef struct fd_set +{ + unsigned char fd_bits [(FD_SETSIZE+7)/8]; +} fd_set; + +#elif FD_SETSIZE < (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) +#error "external FD_SETSIZE too small for number of sockets" +#else +#define LWIP_SELECT_MAXNFDS FD_SETSIZE +#endif /* FD_SET */ + +/* poll-related defines and types */ +/* @todo: find a better way to guard the definition of these defines and types if already defined */ +#if !defined(POLLIN) && !defined(POLLOUT) +#define POLLIN 0x1 +#define POLLOUT 0x2 +#define POLLERR 0x4 +#define POLLNVAL 0x8 +/* Below values are unimplemented */ +#define POLLRDNORM 0x10 +#define POLLRDBAND 0x20 +#define POLLPRI 0x40 +#define POLLWRNORM 0x80 +#define POLLWRBAND 0x100 +#define POLLHUP 0x200 +typedef unsigned int nfds_t; +struct pollfd +{ + int fd; + short events; + short revents; +}; +#endif + +/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided + * by your system, set this to 0 and include in cc.h */ +#ifndef LWIP_TIMEVAL_PRIVATE +#define LWIP_TIMEVAL_PRIVATE 1 +#endif + +#if LWIP_TIMEVAL_PRIVATE +struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ +}; +#endif /* LWIP_TIMEVAL_PRIVATE */ +#endif /* LWIP_SOCKET_STDINCLUDE */ +#define lwip_socket_init() /* Compatibility define, no init needed. */ +void lwip_socket_thread_init(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */ +void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */ + +#if LWIP_COMPAT_SOCKETS == 2 +/* This helps code parsers/code completion by not having the COMPAT functions as defines */ +#define lwip_accept accept +#define lwip_bind bind +#define lwip_shutdown shutdown +#define lwip_getpeername getpeername +#define lwip_getsockname getsockname +#define lwip_setsockopt setsockopt +#define lwip_getsockopt getsockopt +#define lwip_close closesocket +#define lwip_connect connect +#define lwip_listen listen +#define lwip_recv recv +#define lwip_recvmsg recvmsg +#define lwip_recvfrom recvfrom +#define lwip_send send +#define lwip_sendmsg sendmsg +#define lwip_sendto sendto +#define lwip_socket socket +#if LWIP_SOCKET_SELECT +#define lwip_select select +#endif +#if LWIP_SOCKET_POLL +#define lwip_poll poll +#endif +#define lwip_ioctl ioctlsocket +#define lwip_inet_ntop inet_ntop +#define lwip_inet_pton inet_pton + +#if LWIP_POSIX_SOCKETS_IO_NAMES +#define lwip_read read +#define lwip_readv readv +#define lwip_write write +#define lwip_writev writev +#undef lwip_close +#define lwip_close close +#define closesocket(s) close(s) +int fcntl(int s, int cmd, ...); +#undef lwip_ioctl +#define lwip_ioctl ioctl +#define ioctlsocket ioctl +#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ +#endif /* LWIP_COMPAT_SOCKETS == 2 */ + +int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); +int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); +int lwip_shutdown(int s, int how); +int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); +int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); +int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); +int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); + int lwip_close(int s); +int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); +int lwip_listen(int s, int backlog); +ssize_t lwip_recv(int s, void *mem, size_t len, int flags); +ssize_t lwip_read(int s, void *mem, size_t len); +ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); +ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen); +ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); +ssize_t lwip_send(int s, const void *dataptr, size_t size, int flags); +ssize_t lwip_sendmsg(int s, const struct msghdr *message, int flags); +ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen); +int lwip_socket(int domain, int type, int protocol); +ssize_t lwip_write(int s, const void *dataptr, size_t size); +ssize_t lwip_writev(int s, const struct iovec *iov, int iovcnt); +#if LWIP_SOCKET_SELECT +int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, + struct timeval *timeout); +#endif +#if LWIP_SOCKET_POLL +int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); +#endif +int lwip_ioctl(int s, long cmd, void *argp); +int lwip_fcntl(int s, int cmd, int val); +const char *lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size); +int lwip_inet_pton(int af, const char *src, void *dst); + +#if LWIP_ENABLE_DISTRIBUTED_NET + +int lwip_connect_internal(int s, const struct sockaddr *name, socklen_t namelen); + +int lwip_close_internal(int s); + +#if LWIP_USE_GET_HOST_BY_NAME_EXTERNAL +ssize_t lwip_sendto_internal(int s, const void *data, size_t size, int flags, const struct sockaddr *to, + socklen_t tolen); + +#if LWIP_DISTRIBUTED_NET_ENABLE_SENDMSG +ssize_t lwip_sendmsg_internal(int s, const struct msghdr *msg, int flags); +#endif + +ssize_t lwip_recvfrom_internal(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); +#endif /* LWIP_USE_GET_HOST_BY_NAME_EXTERNAL */ + +#endif + +#if LWIP_COMPAT_SOCKETS +#if LWIP_COMPAT_SOCKETS != 2 +/** @ingroup socket */ +#define accept(s,addr,addrlen) lwip_accept(s,addr,addrlen) +/** @ingroup socket */ +#define bind(s,name,namelen) lwip_bind(s,name,namelen) +/** @ingroup socket */ +#define shutdown(s,how) lwip_shutdown(s,how) +/** @ingroup socket */ +#define getpeername(s,name,namelen) lwip_getpeername(s,name,namelen) +/** @ingroup socket */ +#define getsockname(s,name,namelen) lwip_getsockname(s,name,namelen) +/** @ingroup socket */ +#define setsockopt(s,level,optname,opval,optlen) lwip_setsockopt(s,level,optname,opval,optlen) +/** @ingroup socket */ +#define getsockopt(s,level,optname,opval,optlen) lwip_getsockopt(s,level,optname,opval,optlen) +/** @ingroup socket */ +#define closesocket(s) lwip_close(s) +/** @ingroup socket */ +#define connect(s,name,namelen) lwip_connect(s,name,namelen) +/** @ingroup socket */ +#define listen(s,backlog) lwip_listen(s,backlog) +/** @ingroup socket */ +#define recv(s,mem,len,flags) lwip_recv(s,mem,len,flags) +/** @ingroup socket */ +#define recvmsg(s,message,flags) lwip_recvmsg(s,message,flags) +/** @ingroup socket */ +#define recvfrom(s,mem,len,flags,from,fromlen) lwip_recvfrom(s,mem,len,flags,from,fromlen) +/** @ingroup socket */ +#define send(s,dataptr,size,flags) lwip_send(s,dataptr,size,flags) +/** @ingroup socket */ +#define sendmsg(s,message,flags) lwip_sendmsg(s,message,flags) +/** @ingroup socket */ +#define sendto(s,dataptr,size,flags,to,tolen) lwip_sendto(s,dataptr,size,flags,to,tolen) +/** @ingroup socket */ +#define socket(domain,type,protocol) lwip_socket(domain,type,protocol) +#if LWIP_SOCKET_SELECT +/** @ingroup socket */ +#define select(maxfdp1,readset,writeset,exceptset,timeout) lwip_select(maxfdp1,readset,writeset,exceptset,timeout) +#endif +#if LWIP_SOCKET_POLL +/** @ingroup socket */ +#define poll(fds,nfds,timeout) lwip_poll(fds,nfds,timeout) +#endif +/** @ingroup socket */ +#define ioctlsocket(s,cmd,argp) lwip_ioctl(s,cmd,argp) +/** @ingroup socket */ +#define inet_ntop(af,src,dst,size) lwip_inet_ntop(af,src,dst,size) +/** @ingroup socket */ +#define inet_pton(af,src,dst) lwip_inet_pton(af,src,dst) + +#if LWIP_POSIX_SOCKETS_IO_NAMES +/** @ingroup socket */ +#define read(s,mem,len) lwip_read(s,mem,len) +/** @ingroup socket */ +#define readv(s,iov,iovcnt) lwip_readv(s,iov,iovcnt) +/** @ingroup socket */ +#define write(s,dataptr,len) lwip_write(s,dataptr,len) +/** @ingroup socket */ +#define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt) +/** @ingroup socket */ +#define close(s) lwip_close(s) +/** @ingroup socket */ +#define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val) +/** @ingroup socket */ +#define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp) +#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ +#endif /* LWIP_COMPAT_SOCKETS != 2 */ + +#endif /* LWIP_COMPAT_SOCKETS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_SOCKET */ + +#endif /* LWIP_HDR_SOCKETS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/stats.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/stats.h new file mode 100644 index 000000000..b570dbacf --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/stats.h @@ -0,0 +1,491 @@ +/** + * @file + * Statistics API (to be used from TCPIP thread) + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_STATS_H +#define LWIP_HDR_STATS_H + +#include "lwip/opt.h" + +#include "lwip/mem.h" +#include "lwip/memp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_STATS + +#ifndef LWIP_STATS_LARGE +#define LWIP_STATS_LARGE 0 +#endif + +#if LWIP_STATS_LARGE +#define STAT_COUNTER u32_t +#define STAT_COUNTER_F U32_F +#else +#define STAT_COUNTER u16_t +#define STAT_COUNTER_F U16_F +#endif + +/** Protocol related stats */ +struct stats_proto { + STAT_COUNTER xmit; /* Transmitted packets. */ + STAT_COUNTER recv; /* Received packets. */ + STAT_COUNTER fw; /* Forwarded packets. */ + STAT_COUNTER drop; /* Dropped packets. */ + STAT_COUNTER chkerr; /* Checksum error. */ + STAT_COUNTER lenerr; /* Invalid length error. */ + STAT_COUNTER memerr; /* Out of memory error. */ + STAT_COUNTER rterr; /* Routing error. */ + STAT_COUNTER proterr; /* Protocol error. */ + STAT_COUNTER opterr; /* Error in options. */ + STAT_COUNTER err; /* Misc error. */ + STAT_COUNTER cachehit; +}; + +/** IGMP stats */ +struct stats_igmp { + STAT_COUNTER xmit; /* Transmitted packets. */ + STAT_COUNTER recv; /* Received packets. */ + STAT_COUNTER drop; /* Dropped packets. */ + STAT_COUNTER chkerr; /* Checksum error. */ + STAT_COUNTER lenerr; /* Invalid length error. */ + STAT_COUNTER memerr; /* Out of memory error. */ + STAT_COUNTER proterr; /* Protocol error. */ + STAT_COUNTER rx_v1; /* Received v1 frames. */ + STAT_COUNTER rx_group; /* Received group-specific queries. */ + STAT_COUNTER rx_general; /* Received general queries. */ + STAT_COUNTER rx_report; /* Received reports. */ + STAT_COUNTER tx_join; /* Sent joins. */ + STAT_COUNTER tx_leave; /* Sent leaves. */ + STAT_COUNTER tx_report; /* Sent reports. */ +}; + +/** Memory stats */ +struct stats_mem { +#if defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY + const char *name; +#endif /* defined(LWIP_DEBUG) || LWIP_STATS_DISPLAY */ + STAT_COUNTER err; + mem_size_t avail; + mem_size_t used; + mem_size_t max; + STAT_COUNTER illegal; +}; + +/** System element stats */ +struct stats_syselem { + STAT_COUNTER used; + STAT_COUNTER max; + STAT_COUNTER err; +}; + +/** System stats */ +struct stats_sys { + struct stats_syselem sem; + struct stats_syselem mutex; + struct stats_syselem mbox; +}; + +/** SNMP MIB2 stats */ +struct stats_mib2 { + /* IP */ + u32_t ipinhdrerrors; + u32_t ipinaddrerrors; + u32_t ipinunknownprotos; + u32_t ipindiscards; + u32_t ipindelivers; + u32_t ipoutrequests; + u32_t ipoutdiscards; + u32_t ipoutnoroutes; + u32_t ipreasmoks; + u32_t ipreasmfails; + u32_t ipfragoks; + u32_t ipfragfails; + u32_t ipfragcreates; + u32_t ipreasmreqds; + u32_t ipforwdatagrams; + u32_t ipinreceives; + + /* TCP */ + u32_t tcpactiveopens; + u32_t tcppassiveopens; + u32_t tcpattemptfails; + u32_t tcpestabresets; + u32_t tcpoutsegs; + u32_t tcpretranssegs; + u32_t tcpinsegs; + u32_t tcpinerrs; + u32_t tcpoutrsts; + + /* UDP */ + u32_t udpindatagrams; + u32_t udpnoports; + u32_t udpinerrors; + u32_t udpoutdatagrams; + + /* ICMP */ + u32_t icmpinmsgs; + u32_t icmpinerrors; + u32_t icmpindestunreachs; + u32_t icmpintimeexcds; + u32_t icmpinparmprobs; + u32_t icmpinsrcquenchs; + u32_t icmpinredirects; + u32_t icmpinechos; + u32_t icmpinechoreps; + u32_t icmpintimestamps; + u32_t icmpintimestampreps; + u32_t icmpinaddrmasks; + u32_t icmpinaddrmaskreps; + u32_t icmpoutmsgs; + u32_t icmpouterrors; + u32_t icmpoutdestunreachs; + u32_t icmpouttimeexcds; + u32_t icmpoutechos; /* can be incremented by user application ('ping') */ + u32_t icmpoutechoreps; +}; + +/** + * @ingroup netif_mib2 + * SNMP MIB2 interface stats + */ +struct stats_mib2_netif_ctrs { + /** The total number of octets received on the interface, including framing characters */ + u32_t ifinoctets; + /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were + * not addressed to a multicast or broadcast address at this sub-layer */ + u32_t ifinucastpkts; + /** The number of packets, delivered by this sub-layer to a higher (sub-)layer, which were + * addressed to a multicast or broadcast address at this sub-layer */ + u32_t ifinnucastpkts; + /** The number of inbound packets which were chosen to be discarded even though no errors had + * been detected to prevent their being deliverable to a higher-layer protocol. One possible + * reason for discarding such a packet could be to free up buffer space */ + u32_t ifindiscards; + /** For packet-oriented interfaces, the number of inbound packets that contained errors + * preventing them from being deliverable to a higher-layer protocol. For character- + * oriented or fixed-length interfaces, the number of inbound transmission units that + * contained errors preventing them from being deliverable to a higher-layer protocol. */ + u32_t ifinerrors; + /** For packet-oriented interfaces, the number of packets received via the interface which + * were discarded because of an unknown or unsupported protocol. For character-oriented + * or fixed-length interfaces that support protocol multiplexing the number of transmission + * units received via the interface which were discarded because of an unknown or unsupported + * protocol. For any interface that does not support protocol multiplexing, this counter will + * always be 0 */ + u32_t ifinunknownprotos; + /** The total number of octets transmitted out of the interface, including framing characters. */ + u32_t ifoutoctets; + /** The total number of packets that higher-level protocols requested be transmitted, and + * which were not addressed to a multicast or broadcast address at this sub-layer, including + * those that were discarded or not sent. */ + u32_t ifoutucastpkts; + /** The total number of packets that higher-level protocols requested be transmitted, and which + * were addressed to a multicast or broadcast address at this sub-layer, including + * those that were discarded or not sent. */ + u32_t ifoutnucastpkts; + /** The number of outbound packets which were chosen to be discarded even though no errors had + * been detected to prevent their being transmitted. One possible reason for discarding + * such a packet could be to free up buffer space. */ + u32_t ifoutdiscards; + /** For packet-oriented interfaces, the number of outbound packets that could not be transmitted + * because of errors. For character-oriented or fixed-length interfaces, the number of outbound + * transmission units that could not be transmitted because of errors. */ + u32_t ifouterrors; +}; + +/** lwIP stats container */ +struct stats_ { +#if LINK_STATS + /** Link level */ + struct stats_proto link; +#endif +#if ETHARP_STATS + /** ARP */ + struct stats_proto etharp; +#endif +#if IPFRAG_STATS + /** Fragmentation */ + struct stats_proto ip_frag; +#endif +#if IP_STATS + /** IP */ + struct stats_proto ip; +#endif +#if ICMP_STATS + /** ICMP */ + struct stats_proto icmp; +#endif +#if IGMP_STATS + /** IGMP */ + struct stats_igmp igmp; +#endif +#if UDP_STATS + /** UDP */ + struct stats_proto udp; +#endif +#if TCP_STATS + /** TCP */ + struct stats_proto tcp; +#endif +#if MEM_STATS + /** Heap */ + struct stats_mem mem; +#endif +#if MEMP_STATS + /** Internal memory pools */ + struct stats_mem *memp[MEMP_MAX]; +#endif +#if SYS_STATS + /** System */ + struct stats_sys sys; +#endif +#if IP6_STATS + /** IPv6 */ + struct stats_proto ip6; +#endif +#if ICMP6_STATS + /** ICMP6 */ + struct stats_proto icmp6; +#endif +#if IP6_FRAG_STATS + /** IPv6 fragmentation */ + struct stats_proto ip6_frag; +#endif +#if MLD6_STATS + /** Multicast listener discovery */ + struct stats_igmp mld6; +#endif +#if ND6_STATS + /** Neighbor discovery */ + struct stats_proto nd6; +#endif +#if MIB2_STATS + /** SNMP MIB2 */ + struct stats_mib2 mib2; +#endif +}; + +/** Global variable containing lwIP internal statistics. Add this to your debugger's watchlist. */ +extern struct stats_ lwip_stats; + +/** Init statistics */ +void stats_init(void); + +#define STATS_INC(x) ++lwip_stats.x +#define STATS_DEC(x) --lwip_stats.x +#define STATS_INC_USED(x, y, type) do { lwip_stats.x.used = (type)(lwip_stats.x.used + y); \ + if (lwip_stats.x.max < lwip_stats.x.used) { \ + lwip_stats.x.max = lwip_stats.x.used; \ + } \ + } while(0) +#define STATS_GET(x) lwip_stats.x +#else /* LWIP_STATS */ +#define stats_init() +#define STATS_INC(x) +#define STATS_DEC(x) +#define STATS_INC_USED(x, y, type) +#endif /* LWIP_STATS */ + +#if TCP_STATS +#define TCP_STATS_INC(x) STATS_INC(x) +#define TCP_STATS_DISPLAY() stats_display_proto(&lwip_stats.tcp, "TCP") +#else +#define TCP_STATS_INC(x) +#define TCP_STATS_DISPLAY() +#endif + +#if UDP_STATS +#define UDP_STATS_INC(x) STATS_INC(x) +#define UDP_STATS_DISPLAY() stats_display_proto(&lwip_stats.udp, "UDP") +#else +#define UDP_STATS_INC(x) +#define UDP_STATS_DISPLAY() +#endif + +#if ICMP_STATS +#define ICMP_STATS_INC(x) STATS_INC(x) +#define ICMP_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp, "ICMP") +#else +#define ICMP_STATS_INC(x) +#define ICMP_STATS_DISPLAY() +#endif + +#if IGMP_STATS +#define IGMP_STATS_INC(x) STATS_INC(x) +#define IGMP_STATS_DISPLAY() stats_display_igmp(&lwip_stats.igmp, "IGMP") +#else +#define IGMP_STATS_INC(x) +#define IGMP_STATS_DISPLAY() +#endif + +#if IP_STATS +#define IP_STATS_INC(x) STATS_INC(x) +#define IP_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip, "IP") +#else +#define IP_STATS_INC(x) +#define IP_STATS_DISPLAY() +#endif + +#if IPFRAG_STATS +#define IPFRAG_STATS_INC(x) STATS_INC(x) +#define IPFRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG") +#else +#define IPFRAG_STATS_INC(x) +#define IPFRAG_STATS_DISPLAY() +#endif + +#if ETHARP_STATS +#define ETHARP_STATS_INC(x) STATS_INC(x) +#define ETHARP_STATS_DISPLAY() stats_display_proto(&lwip_stats.etharp, "ETHARP") +#else +#define ETHARP_STATS_INC(x) +#define ETHARP_STATS_DISPLAY() +#endif + +#if LINK_STATS +#define LINK_STATS_INC(x) STATS_INC(x) +#define LINK_STATS_DISPLAY() stats_display_proto(&lwip_stats.link, "LINK") +#else +#define LINK_STATS_INC(x) +#define LINK_STATS_DISPLAY() +#endif + +#if MEM_STATS +#define MEM_STATS_AVAIL(x, y) lwip_stats.mem.x = y +#define MEM_STATS_INC(x) STATS_INC(mem.x) +#define MEM_STATS_INC_USED(x, y) STATS_INC_USED(mem, y, mem_size_t) +#define MEM_STATS_DEC_USED(x, y) lwip_stats.mem.x = (mem_size_t)((lwip_stats.mem.x) - (y)) +#define MEM_STATS_DISPLAY() stats_display_mem(&lwip_stats.mem, "HEAP") +#else +#define MEM_STATS_AVAIL(x, y) +#define MEM_STATS_INC(x) +#define MEM_STATS_INC_USED(x, y) +#define MEM_STATS_DEC_USED(x, y) +#define MEM_STATS_DISPLAY() +#endif + + #if MEMP_STATS +#define MEMP_STATS_DEC(x, i) STATS_DEC(memp[i]->x) +#define MEMP_STATS_DISPLAY(i) stats_display_memp(lwip_stats.memp[i], i) +#define MEMP_STATS_GET(x, i) STATS_GET(memp[i]->x) + #else +#define MEMP_STATS_DEC(x, i) +#define MEMP_STATS_DISPLAY(i) +#define MEMP_STATS_GET(x, i) 0 +#endif + +#if SYS_STATS +#define SYS_STATS_INC(x) STATS_INC(sys.x) +#define SYS_STATS_DEC(x) STATS_DEC(sys.x) +#define SYS_STATS_INC_USED(x) STATS_INC_USED(sys.x, 1, STAT_COUNTER) +#define SYS_STATS_DISPLAY() stats_display_sys(&lwip_stats.sys) +#else +#define SYS_STATS_INC(x) +#define SYS_STATS_DEC(x) +#define SYS_STATS_INC_USED(x) +#define SYS_STATS_DISPLAY() +#endif + +#if IP6_STATS +#define IP6_STATS_INC(x) STATS_INC(x) +#define IP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6, "IPv6") +#else +#define IP6_STATS_INC(x) +#define IP6_STATS_DISPLAY() +#endif + +#if ICMP6_STATS +#define ICMP6_STATS_INC(x) STATS_INC(x) +#define ICMP6_STATS_DISPLAY() stats_display_proto(&lwip_stats.icmp6, "ICMPv6") +#else +#define ICMP6_STATS_INC(x) +#define ICMP6_STATS_DISPLAY() +#endif + +#if IP6_FRAG_STATS +#define IP6_FRAG_STATS_INC(x) STATS_INC(x) +#define IP6_FRAG_STATS_DISPLAY() stats_display_proto(&lwip_stats.ip6_frag, "IPv6 FRAG") +#else +#define IP6_FRAG_STATS_INC(x) +#define IP6_FRAG_STATS_DISPLAY() +#endif + +#if MLD6_STATS +#define MLD6_STATS_INC(x) STATS_INC(x) +#define MLD6_STATS_DISPLAY() stats_display_igmp(&lwip_stats.mld6, "MLDv1") +#else +#define MLD6_STATS_INC(x) +#define MLD6_STATS_DISPLAY() +#endif + +#if ND6_STATS +#define ND6_STATS_INC(x) STATS_INC(x) +#define ND6_STATS_DISPLAY() stats_display_proto(&lwip_stats.nd6, "ND") +#else +#define ND6_STATS_INC(x) +#define ND6_STATS_DISPLAY() +#endif + +#if MIB2_STATS +#define MIB2_STATS_INC(x) STATS_INC(x) +#else +#define MIB2_STATS_INC(x) +#endif + +/* Display of statistics */ +#if LWIP_STATS_DISPLAY +void stats_display(void); +void stats_display_proto(struct stats_proto *proto, const char *name); +void stats_display_igmp(struct stats_igmp *igmp, const char *name); +void stats_display_mem(struct stats_mem *mem, const char *name); +void stats_display_memp(struct stats_mem *mem, int index); +void stats_display_sys(struct stats_sys *sys); +#else /* LWIP_STATS_DISPLAY */ +#define stats_display() +#define stats_display_proto(proto, name) +#define stats_display_igmp(igmp, name) +#define stats_display_mem(mem, name) +#define stats_display_memp(mem, index) +#define stats_display_sys(sys) +#endif /* LWIP_STATS_DISPLAY */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_STATS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sys.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sys.h new file mode 100644 index 000000000..168e465ba --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/sys.h @@ -0,0 +1,560 @@ +/** + * @file + * OS abstraction layer + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + */ + +#ifndef LWIP_HDR_SYS_H +#define LWIP_HDR_SYS_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if NO_SYS + +/* For a totally minimal and standalone system, we provide null + definitions of the sys_ functions. */ +typedef u8_t sys_sem_t; +typedef u8_t sys_mutex_t; +typedef u8_t sys_mbox_t; + +#define sys_sem_new(s, c) ERR_OK +#define sys_sem_signal(s) +#define sys_sem_wait(s) +#define sys_arch_sem_wait(s,t) +#define sys_sem_free(s) +#define sys_sem_valid(s) 0 +#define sys_sem_valid_val(s) 0 +#define sys_sem_set_invalid(s) +#define sys_sem_set_invalid_val(s) +#define sys_mutex_new(mu) ERR_OK +#define sys_mutex_lock(mu) +#define sys_mutex_unlock(mu) +#define sys_mutex_free(mu) +#define sys_mutex_valid(mu) 0 +#define sys_mutex_set_invalid(mu) +#define sys_mbox_new(m, s) ERR_OK +#define sys_mbox_fetch(m,d) +#define sys_mbox_tryfetch(m,d) +#define sys_mbox_post(m,d) +#define sys_mbox_trypost(m,d) +#define sys_mbox_free(m) +#define sys_mbox_valid(m) +#define sys_mbox_valid_val(m) +#define sys_mbox_set_invalid(m) +#define sys_mbox_set_invalid_val(m) + +#define sys_thread_new(n,t,a,s,p) + +#define sys_msleep(t) + +#else /* NO_SYS */ + +/** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */ +#define SYS_ARCH_TIMEOUT 0xffffffffUL + +/** sys_mbox_tryfetch() returns SYS_MBOX_EMPTY if appropriate. + * For now we use the same magic value, but we allow this to change in future. + */ +#define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT + +#include "lwip/err.h" +#include "arch/sys_arch.h" + +/** Function prototype for thread functions */ +typedef void (*lwip_thread_fn)(void *arg); + +/* Function prototypes for functions to be implemented by platform ports + (in sys_arch.c) */ + +/* Mutex functions: */ + +/** Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores + should be used instead */ +#ifndef LWIP_COMPAT_MUTEX +#define LWIP_COMPAT_MUTEX 0 +#endif + +#if LWIP_COMPAT_MUTEX +/* for old ports that don't have mutexes: define them to binary semaphores */ +#define sys_mutex_t sys_sem_t +#define sys_mutex_new(mutex) sys_sem_new(mutex, 1) +#define sys_mutex_lock(mutex) sys_sem_wait(mutex) +#define sys_mutex_unlock(mutex) sys_sem_signal(mutex) +#define sys_mutex_free(mutex) sys_sem_free(mutex) +#define sys_mutex_valid(mutex) sys_sem_valid(mutex) +#define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex) + +#else /* LWIP_COMPAT_MUTEX */ + +/** + * @ingroup sys_mutex + * Create a new mutex. + * Note that mutexes are expected to not be taken recursively by the lwIP code, + * so both implementation types (recursive or non-recursive) should work. + * The mutex is allocated to the memory that 'mutex' + * points to (which can be both a pointer or the actual OS structure). + * If the mutex has been created, ERR_OK should be returned. Returning any + * other error will provide a hint what went wrong, but except for assertions, + * no real error handling is implemented. + * + * @param mutex pointer to the mutex to create + * @return ERR_OK if successful, another err_t otherwise + */ +err_t sys_mutex_new(sys_mutex_t *mutex); +/** + * @ingroup sys_mutex + * Blocks the thread until the mutex can be grabbed. + * @param mutex the mutex to lock + */ +void sys_mutex_lock(sys_mutex_t *mutex); +/** + * @ingroup sys_mutex + * Releases the mutex previously locked through 'sys_mutex_lock()'. + * @param mutex the mutex to unlock + */ +void sys_mutex_unlock(sys_mutex_t *mutex); +/** + * @ingroup sys_mutex + * Deallocates a mutex. + * @param mutex the mutex to delete + */ +void sys_mutex_free(sys_mutex_t *mutex); +#ifndef sys_mutex_valid +/** + * @ingroup sys_mutex + * Returns 1 if the mutes is valid, 0 if it is not valid. + * When using pointers, a simple way is to check the pointer for != NULL. + * When directly using OS structures, implementing this may be more complex. + * This may also be a define, in which case the function is not prototyped. + */ +int sys_mutex_valid(sys_mutex_t *mutex); +#endif +#ifndef sys_mutex_set_invalid +/** + * @ingroup sys_mutex + * Invalidate a mutex so that sys_mutex_valid() returns 0. + * ATTENTION: This does NOT mean that the mutex shall be deallocated: + * sys_mutex_free() is always called before calling this function! + * This may also be a define, in which case the function is not prototyped. + */ +void sys_mutex_set_invalid(sys_mutex_t *mutex); +#endif +#endif /* LWIP_COMPAT_MUTEX */ + +/* Semaphore functions: */ + +/** + * @ingroup sys_sem + * Create a new semaphore + * Creates a new semaphore. The semaphore is allocated to the memory that 'sem' + * points to (which can be both a pointer or the actual OS structure). + * The "count" argument specifies the initial state of the semaphore (which is + * either 0 or 1). + * If the semaphore has been created, ERR_OK should be returned. Returning any + * other error will provide a hint what went wrong, but except for assertions, + * no real error handling is implemented. + * + * @param sem pointer to the semaphore to create + * @param count initial count of the semaphore + * @return ERR_OK if successful, another err_t otherwise + */ +err_t sys_sem_new(sys_sem_t *sem, u8_t count); +/** + * @ingroup sys_sem + * Signals a semaphore + * @param sem the semaphore to signal + */ +void sys_sem_signal(sys_sem_t *sem); +/** + * @ingroup sys_sem + * Blocks the thread while waiting for the semaphore to be signaled. If the + * "timeout" argument is non-zero, the thread should only be blocked for the + * specified time (measured in milliseconds). If the "timeout" argument is zero, + * the thread should be blocked until the semaphore is signalled. + * + * The return value is SYS_ARCH_TIMEOUT if the semaphore wasn't signaled within + * the specified time or any other value if it was signaled (with or without + * waiting). + * Notice that lwIP implements a function with a similar name, + * sys_sem_wait(), that uses the sys_arch_sem_wait() function. + * + * @param sem the semaphore to wait for + * @param timeout timeout in milliseconds to wait (0 = wait forever) + * @return SYS_ARCH_TIMEOUT on timeout, any other value on success + */ +u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout); +/** + * @ingroup sys_sem + * Deallocates a semaphore. + * @param sem semaphore to delete + */ +void sys_sem_free(sys_sem_t *sem); +/** Wait for a semaphore - forever/no timeout */ +#define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0) +#ifndef sys_sem_valid +/** + * @ingroup sys_sem + * Returns 1 if the semaphore is valid, 0 if it is not valid. + * When using pointers, a simple way is to check the pointer for != NULL. + * When directly using OS structures, implementing this may be more complex. + * This may also be a define, in which case the function is not prototyped. + */ +int sys_sem_valid(sys_sem_t *sem); +#endif +#ifndef sys_sem_set_invalid +/** + * @ingroup sys_sem + * Invalidate a semaphore so that sys_sem_valid() returns 0. + * ATTENTION: This does NOT mean that the semaphore shall be deallocated: + * sys_sem_free() is always called before calling this function! + * This may also be a define, in which case the function is not prototyped. + */ +void sys_sem_set_invalid(sys_sem_t *sem); +#endif +#ifndef sys_sem_valid_val +/** + * Same as sys_sem_valid() but taking a value, not a pointer + */ +#define sys_sem_valid_val(sem) sys_sem_valid(&(sem)) +#endif +#ifndef sys_sem_set_invalid_val +/** + * Same as sys_sem_set_invalid() but taking a value, not a pointer + */ +#define sys_sem_set_invalid_val(sem) sys_sem_set_invalid(&(sem)) +#endif + +#ifndef sys_msleep +/** + * @ingroup sys_misc + * Sleep for specified number of ms + */ +void sys_msleep(u32_t ms); /* only has a (close to) 1 ms resolution. */ +#endif + +/* Mailbox functions. */ + +/** + * @ingroup sys_mbox + * Creates an empty mailbox for maximum "size" elements. Elements stored + * in mailboxes are pointers. You have to define macros "_MBOX_SIZE" + * in your lwipopts.h, or ignore this parameter in your implementation + * and use a default size. + * If the mailbox has been created, ERR_OK should be returned. Returning any + * other error will provide a hint what went wrong, but except for assertions, + * no real error handling is implemented. + * + * @param mbox pointer to the mbox to create + * @param size (minimum) number of messages in this mbox + * @return ERR_OK if successful, another err_t otherwise + */ +err_t sys_mbox_new(sys_mbox_t *mbox, int size); +/** + * @ingroup sys_mbox + * Post a message to an mbox - may not fail + * -> blocks if full, only to be used from tasks NOT from ISR! + * + * @param mbox mbox to posts the message + * @param msg message to post (ATTENTION: can be NULL) + */ +void sys_mbox_post(sys_mbox_t *mbox, void *msg); +/** + * @ingroup sys_mbox + * Try to post a message to an mbox - may fail if full. + * Can be used from ISR (if the sys arch layer allows this). + * Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted. + * + * @param mbox mbox to posts the message + * @param msg message to post (ATTENTION: can be NULL) + */ +err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg); +/** + * @ingroup sys_mbox + * Try to post a message to an mbox - may fail if full. + * To be be used from ISR. + * Returns ERR_MEM if it is full, else, ERR_OK if the "msg" is posted. + * + * @param mbox mbox to posts the message + * @param msg message to post (ATTENTION: can be NULL) + */ +err_t sys_mbox_trypost_fromisr(sys_mbox_t *mbox, void *msg); +/** + * @ingroup sys_mbox + * Blocks the thread until a message arrives in the mailbox, but does + * not block the thread longer than "timeout" milliseconds (similar to + * the sys_arch_sem_wait() function). If "timeout" is 0, the thread should + * be blocked until a message arrives. The "msg" argument is a result + * parameter that is set by the function (i.e., by doing "*msg = + * ptr"). The "msg" parameter maybe NULL to indicate that the message + * should be dropped. + * The return values are the same as for the sys_arch_sem_wait() function: + * SYS_ARCH_TIMEOUT if there was a timeout, any other value if a messages + * is received. + * + * Note that a function with a similar name, sys_mbox_fetch(), is + * implemented by lwIP. + * + * @param mbox mbox to get a message from + * @param msg pointer where the message is stored + * @param timeout maximum time (in milliseconds) to wait for a message (0 = wait forever) + * @return SYS_ARCH_TIMEOUT on timeout, any other value if a message has been received + */ +u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout); +/* Allow port to override with a macro, e.g. special timeout for sys_arch_mbox_fetch() */ +#ifndef sys_arch_mbox_tryfetch +/** + * @ingroup sys_mbox + * This is similar to sys_arch_mbox_fetch, however if a message is not + * present in the mailbox, it immediately returns with the code + * SYS_MBOX_EMPTY. On success 0 is returned. + * To allow for efficient implementations, this can be defined as a + * function-like macro in sys_arch.h instead of a normal function. For + * example, a naive implementation could be: + * \#define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1) + * although this would introduce unnecessary delays. + * + * @param mbox mbox to get a message from + * @param msg pointer where the message is stored + * @return 0 (milliseconds) if a message has been received + * or SYS_MBOX_EMPTY if the mailbox is empty + */ +u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg); +#endif +/** + * For now, we map straight to sys_arch implementation. + */ +#define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg) +/** + * @ingroup sys_mbox + * Deallocates a mailbox. If there are messages still present in the + * mailbox when the mailbox is deallocated, it is an indication of a + * programming error in lwIP and the developer should be notified. + * + * @param mbox mbox to delete + */ +void sys_mbox_free(sys_mbox_t *mbox); +#define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0) +#ifndef sys_mbox_valid +/** + * @ingroup sys_mbox + * Returns 1 if the mailbox is valid, 0 if it is not valid. + * When using pointers, a simple way is to check the pointer for != NULL. + * When directly using OS structures, implementing this may be more complex. + * This may also be a define, in which case the function is not prototyped. + */ +int sys_mbox_valid(sys_mbox_t *mbox); +#endif +#ifndef sys_mbox_set_invalid +/** + * @ingroup sys_mbox + * Invalidate a mailbox so that sys_mbox_valid() returns 0. + * ATTENTION: This does NOT mean that the mailbox shall be deallocated: + * sys_mbox_free() is always called before calling this function! + * This may also be a define, in which case the function is not prototyped. + */ +void sys_mbox_set_invalid(sys_mbox_t *mbox); +#endif +#ifndef sys_mbox_valid_val +/** + * Same as sys_mbox_valid() but taking a value, not a pointer + */ +#define sys_mbox_valid_val(mbox) sys_mbox_valid(&(mbox)) +#endif +#ifndef sys_mbox_set_invalid_val +/** + * Same as sys_mbox_set_invalid() but taking a value, not a pointer + */ +#define sys_mbox_set_invalid_val(mbox) sys_mbox_set_invalid(&(mbox)) +#endif + + +/** + * @ingroup sys_misc + * The only thread function: + * Starts a new thread named "name" with priority "prio" that will begin its + * execution in the function "thread()". The "arg" argument will be passed as an + * argument to the thread() function. The stack size to used for this thread is + * the "stacksize" parameter. The id of the new thread is returned. Both the id + * and the priority are system dependent. + * ATTENTION: although this function returns a value, it MUST NOT FAIL (ports have to assert this!) + * + * @param name human-readable name for the thread (used for debugging purposes) + * @param thread thread-function + * @param arg parameter passed to 'thread' + * @param stacksize stack size in bytes for the new thread (may be ignored by ports) + * @param prio priority of the new thread (may be ignored by ports) */ +sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio); + +#endif /* NO_SYS */ + +/** + * @ingroup sys_misc + * sys_init() must be called before anything else. + * Initialize the sys_arch layer. + */ +void sys_init(void); + +#ifndef sys_jiffies +/** + * Ticks/jiffies since power up. + */ +u32_t sys_jiffies(void); +#endif + +/** + * @ingroup sys_time + * Returns the current time in milliseconds, + * may be the same as sys_jiffies or at least based on it. + * Don't care for wraparound, this is only used for time diffs. + * Not implementing this function means you cannot use some modules (e.g. TCP + * timestamps, internal timeouts for NO_SYS==1). + */ +u32_t sys_now(void); + +/* Critical Region Protection */ +/* These functions must be implemented in the sys_arch.c file. + In some implementations they can provide a more light-weight protection + mechanism than using semaphores. Otherwise semaphores can be used for + implementation */ +#ifndef SYS_ARCH_PROTECT +/** SYS_LIGHTWEIGHT_PROT + * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection + * for certain critical regions during buffer allocation, deallocation and memory + * allocation and deallocation. + */ +#if SYS_LIGHTWEIGHT_PROT + +/** + * @ingroup sys_prot + * SYS_ARCH_DECL_PROTECT + * declare a protection variable. This macro will default to defining a variable of + * type sys_prot_t. If a particular port needs a different implementation, then + * this macro may be defined in sys_arch.h. + */ +#define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev +/** + * @ingroup sys_prot + * SYS_ARCH_PROTECT + * Perform a "fast" protect. This could be implemented by + * disabling interrupts for an embedded system or by using a semaphore or + * mutex. The implementation should allow calling SYS_ARCH_PROTECT when + * already protected. The old protection level is returned in the variable + * "lev". This macro will default to calling the sys_arch_protect() function + * which should be implemented in sys_arch.c. If a particular port needs a + * different implementation, then this macro may be defined in sys_arch.h + */ +#define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect() +/** + * @ingroup sys_prot + * SYS_ARCH_UNPROTECT + * Perform a "fast" set of the protection level to "lev". This could be + * implemented by setting the interrupt level to "lev" within the MACRO or by + * using a semaphore or mutex. This macro will default to calling the + * sys_arch_unprotect() function which should be implemented in + * sys_arch.c. If a particular port needs a different implementation, then + * this macro may be defined in sys_arch.h + */ +#define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev) +sys_prot_t sys_arch_protect(void); +void sys_arch_unprotect(sys_prot_t pval); + +#else + +#define SYS_ARCH_DECL_PROTECT(lev) +#define SYS_ARCH_PROTECT(lev) +#define SYS_ARCH_UNPROTECT(lev) + +#endif /* SYS_LIGHTWEIGHT_PROT */ + +#endif /* SYS_ARCH_PROTECT */ + +/* + * Macros to set/get and increase/decrease variables in a thread-safe way. + * Use these for accessing variable that are used from more than one thread. + */ + +#ifndef SYS_ARCH_INC +#define SYS_ARCH_INC(var, val) do { \ + SYS_ARCH_DECL_PROTECT(old_level); \ + SYS_ARCH_PROTECT(old_level); \ + var += val; \ + SYS_ARCH_UNPROTECT(old_level); \ + } while(0) +#endif /* SYS_ARCH_INC */ + +#ifndef SYS_ARCH_DEC +#define SYS_ARCH_DEC(var, val) do { \ + SYS_ARCH_DECL_PROTECT(old_level); \ + SYS_ARCH_PROTECT(old_level); \ + var -= val; \ + SYS_ARCH_UNPROTECT(old_level); \ + } while(0) +#endif /* SYS_ARCH_DEC */ + +#ifndef SYS_ARCH_GET +#define SYS_ARCH_GET(var, ret) do { \ + SYS_ARCH_DECL_PROTECT(old_level); \ + SYS_ARCH_PROTECT(old_level); \ + ret = var; \ + SYS_ARCH_UNPROTECT(old_level); \ + } while(0) +#endif /* SYS_ARCH_GET */ + +#ifndef SYS_ARCH_SET +#define SYS_ARCH_SET(var, val) do { \ + SYS_ARCH_DECL_PROTECT(old_level); \ + SYS_ARCH_PROTECT(old_level); \ + var = val; \ + SYS_ARCH_UNPROTECT(old_level); \ + } while(0) +#endif /* SYS_ARCH_SET */ + +#ifndef SYS_ARCH_LOCKED +#define SYS_ARCH_LOCKED(code) do { \ + SYS_ARCH_DECL_PROTECT(old_level); \ + SYS_ARCH_PROTECT(old_level); \ + code; \ + SYS_ARCH_UNPROTECT(old_level); \ + } while(0) +#endif /* SYS_ARCH_LOCKED */ + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_SYS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcp.h new file mode 100644 index 000000000..daf759946 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcp.h @@ -0,0 +1,500 @@ +/** + * @file + * TCP API (to be used from TCPIP thread)\n + * See also @ref tcp_raw + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_TCP_H +#define LWIP_HDR_TCP_H + +#include "lwip/opt.h" + +#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/tcpbase.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/ip.h" +#include "lwip/icmp.h" +#include "lwip/err.h" +#include "lwip/ip6.h" +#include "lwip/ip6_addr.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct tcp_pcb; +struct tcp_pcb_listen; + +/** Function prototype for tcp accept callback functions. Called when a new + * connection can be accepted on a listening pcb. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param newpcb The new connection pcb + * @param err An error code if there has been an error accepting. + * Only return ERR_ABRT if you have called tcp_abort from within the + * callback function! + */ +typedef err_t (*tcp_accept_fn)(void *arg, struct tcp_pcb *newpcb, err_t err); + +/** Function prototype for tcp receive callback functions. Called when data has + * been received. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb The connection pcb which received data + * @param p The received data (or NULL when the connection has been closed!) + * @param err An error code if there has been an error receiving + * Only return ERR_ABRT if you have called tcp_abort from within the + * callback function! + */ +typedef err_t (*tcp_recv_fn)(void *arg, struct tcp_pcb *tpcb, + struct pbuf *p, err_t err); + +/** Function prototype for tcp sent callback functions. Called when sent data has + * been acknowledged by the remote side. Use it to free corresponding resources. + * This also means that the pcb has now space available to send new data. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb The connection pcb for which data has been acknowledged + * @param len The amount of bytes acknowledged + * @return ERR_OK: try to send some data by calling tcp_output + * Only return ERR_ABRT if you have called tcp_abort from within the + * callback function! + */ +typedef err_t (*tcp_sent_fn)(void *arg, struct tcp_pcb *tpcb, + u16_t len); + +/** Function prototype for tcp poll callback functions. Called periodically as + * specified by @see tcp_poll. + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb tcp pcb + * @return ERR_OK: try to send some data by calling tcp_output + * Only return ERR_ABRT if you have called tcp_abort from within the + * callback function! + */ +typedef err_t (*tcp_poll_fn)(void *arg, struct tcp_pcb *tpcb); + +/** Function prototype for tcp error callback functions. Called when the pcb + * receives a RST or is unexpectedly closed for any other reason. + * + * @note The corresponding pcb is already freed when this callback is called! + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param err Error code to indicate why the pcb has been closed + * ERR_ABRT: aborted through tcp_abort or by a TCP timer + * ERR_RST: the connection was reset by the remote host + */ +typedef void (*tcp_err_fn)(void *arg, err_t err); + +/** Function prototype for tcp connected callback functions. Called when a pcb + * is connected to the remote side after initiating a connection attempt by + * calling tcp_connect(). + * + * @param arg Additional argument to pass to the callback function (@see tcp_arg()) + * @param tpcb The connection pcb which is connected + * @param err An unused error code, always ERR_OK currently ;-) @todo! + * Only return ERR_ABRT if you have called tcp_abort from within the + * callback function! + * + * @note When a connection attempt fails, the error callback is currently called! + */ +typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err); + +#if LWIP_WND_SCALE +#define RCV_WND_SCALE(pcb, wnd) (((wnd) >> (pcb)->rcv_scale)) +#define SND_WND_SCALE(pcb, wnd) (((wnd) << (pcb)->snd_scale)) +#define TCPWND16(x) ((u16_t)LWIP_MIN((x), 0xFFFF)) +#define TCP_WND_MAX(pcb) ((tcpwnd_size_t)(((pcb)->flags & TF_WND_SCALE) ? TCP_WND : TCPWND16(TCP_WND))) +#else +#define RCV_WND_SCALE(pcb, wnd) (wnd) +#define SND_WND_SCALE(pcb, wnd) (wnd) +#define TCPWND16(x) (x) +#define TCP_WND_MAX(pcb) TCP_WND +#endif +/* Increments a tcpwnd_size_t and holds at max value rather than rollover */ +#define TCP_WND_INC(wnd, inc) do { \ + if ((tcpwnd_size_t)(wnd + inc) >= wnd) { \ + wnd = (tcpwnd_size_t)(wnd + inc); \ + } else { \ + wnd = (tcpwnd_size_t)-1; \ + } \ + } while(0) + +#if LWIP_TCP_SACK_OUT +/** SACK ranges to include in ACK packets. + * SACK entry is invalid if left==right. */ +struct tcp_sack_range { + /** Left edge of the SACK: the first acknowledged sequence number. */ + u32_t left; + /** Right edge of the SACK: the last acknowledged sequence number +1 (so first NOT acknowledged). */ + u32_t right; +}; +#endif /* LWIP_TCP_SACK_OUT */ + +/** Function prototype for deallocation of arguments. Called *just before* the + * pcb is freed, so don't expect to be able to do anything with this pcb! + * + * @param id ext arg id (allocated via @ref tcp_ext_arg_alloc_id) + * @param data pointer to the data (set via @ref tcp_ext_arg_set before) + */ +typedef void (*tcp_extarg_callback_pcb_destroyed_fn)(u8_t id, void *data); + +/** Function prototype to transition arguments from a listening pcb to an accepted pcb + * + * @param id ext arg id (allocated via @ref tcp_ext_arg_alloc_id) + * @param lpcb the listening pcb accepting a connection + * @param cpcb the newly allocated connection pcb + * @return ERR_OK if OK, any error if connection should be dropped + */ +typedef err_t (*tcp_extarg_callback_passive_open_fn)(u8_t id, struct tcp_pcb_listen *lpcb, struct tcp_pcb *cpcb); + +/** A table of callback functions that is invoked for ext arguments */ +struct tcp_ext_arg_callbacks { + /** @ref tcp_extarg_callback_pcb_destroyed_fn */ + tcp_extarg_callback_pcb_destroyed_fn destroy; + /** @ref tcp_extarg_callback_passive_open_fn */ + tcp_extarg_callback_passive_open_fn passive_open; +}; + +#define LWIP_TCP_PCB_NUM_EXT_ARG_ID_INVALID 0xFF + +#if LWIP_TCP_PCB_NUM_EXT_ARGS +/* This is the structure for ext args in tcp pcbs (used as array) */ +struct tcp_pcb_ext_args { + const struct tcp_ext_arg_callbacks *callbacks; + void *data; +}; +/* This is a helper define to prevent zero size arrays if disabled */ +#define TCP_PCB_EXTARGS struct tcp_pcb_ext_args ext_args[LWIP_TCP_PCB_NUM_EXT_ARGS]; +#else +#define TCP_PCB_EXTARGS +#endif + +typedef u16_t tcpflags_t; +#define TCP_ALLFLAGS 0xffffU + +/** + * members common to struct tcp_pcb and struct tcp_listen_pcb + */ +#define TCP_PCB_COMMON(type) \ + type *next; /* for the linked list */ \ + void *callback_arg; \ + TCP_PCB_EXTARGS \ + enum tcp_state state; /* TCP state */ \ + u8_t prio; \ + /* ports are in host byte order */ \ + u16_t local_port + + +/** the TCP protocol control block for listening pcbs */ +struct tcp_pcb_listen { +/** Common members of all PCB types */ + IP_PCB; +/** Protocol specific PCB members */ + TCP_PCB_COMMON(struct tcp_pcb_listen); + +#if LWIP_CALLBACK_API + /* Function to call when a listener has been connected. */ + tcp_accept_fn accept; +#endif /* LWIP_CALLBACK_API */ + +#if TCP_LISTEN_BACKLOG + u8_t backlog; + u8_t accepts_pending; +#endif /* TCP_LISTEN_BACKLOG */ +}; + + +/** the TCP protocol control block */ +struct tcp_pcb { +/** common PCB members */ + IP_PCB; +/** protocol specific PCB members */ + TCP_PCB_COMMON(struct tcp_pcb); + + /* ports are in host byte order */ + u16_t remote_port; + + tcpflags_t flags; +#define TF_ACK_DELAY 0x01U /* Delayed ACK. */ +#define TF_ACK_NOW 0x02U /* Immediate ACK. */ +#define TF_INFR 0x04U /* In fast recovery. */ +#define TF_CLOSEPEND 0x08U /* If this is set, tcp_close failed to enqueue the FIN (retried in tcp_tmr) */ +#define TF_RXCLOSED 0x10U /* rx closed by tcp_shutdown */ +#define TF_FIN 0x20U /* Connection was closed locally (FIN segment enqueued). */ +#define TF_NODELAY 0x40U /* Disable Nagle algorithm */ +#define TF_NAGLEMEMERR 0x80U /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */ +#if LWIP_WND_SCALE +#define TF_WND_SCALE 0x0100U /* Window Scale option enabled */ +#endif +#if TCP_LISTEN_BACKLOG +#define TF_BACKLOGPEND 0x0200U /* If this is set, a connection pcb has increased the backlog on its listener */ +#endif +#if LWIP_TCP_TIMESTAMPS +#define TF_TIMESTAMP 0x0400U /* Timestamp option enabled */ +#endif +#define TF_RTO 0x0800U /* RTO timer has fired, in-flight data moved to unsent and being retransmitted */ +#if LWIP_TCP_SACK_OUT +#define TF_SACK 0x1000U /* Selective ACKs enabled */ +#endif + + /* the rest of the fields are in host byte order + as we have to do some math with them */ + + /* Timers */ + u8_t polltmr, pollinterval; + u8_t last_timer; + u32_t tmr; + + /* receiver variables */ + u32_t rcv_nxt; /* next seqno expected */ + tcpwnd_size_t rcv_wnd; /* receiver window available */ + tcpwnd_size_t rcv_ann_wnd; /* receiver window to announce */ + u32_t rcv_ann_right_edge; /* announced right edge of window */ + +#if LWIP_TCP_SACK_OUT + /* SACK ranges to include in ACK packets (entry is invalid if left==right) */ + struct tcp_sack_range rcv_sacks[LWIP_TCP_MAX_SACK_NUM]; +#define LWIP_TCP_SACK_VALID(pcb, idx) ((pcb)->rcv_sacks[idx].left != (pcb)->rcv_sacks[idx].right) +#endif /* LWIP_TCP_SACK_OUT */ + + /* Retransmission timer. */ + s16_t rtime; + + u16_t mss; /* maximum segment size */ + + /* RTT (round trip time) estimation variables */ + u32_t rttest; /* RTT estimate in 500ms ticks */ + u32_t rtseq; /* sequence number being timed */ + s16_t sa, sv; /* @see "Congestion Avoidance and Control" by Van Jacobson and Karels */ + + s16_t rto; /* retransmission time-out (in ticks of TCP_SLOW_INTERVAL) */ + u8_t nrtx; /* number of retransmissions */ + + /* fast retransmit/recovery */ + u8_t dupacks; + u32_t lastack; /* Highest acknowledged seqno. */ + + /* congestion avoidance/control variables */ + tcpwnd_size_t cwnd; + tcpwnd_size_t ssthresh; + + /* first byte following last rto byte */ + u32_t rto_end; + + /* sender variables */ + u32_t snd_nxt; /* next new seqno to be sent */ + u32_t snd_wl1, snd_wl2; /* Sequence and acknowledgement numbers of last + window update. */ + u32_t snd_lbb; /* Sequence number of next byte to be buffered. */ + tcpwnd_size_t snd_wnd; /* sender window */ + tcpwnd_size_t snd_wnd_max; /* the maximum sender window announced by the remote host */ + + tcpwnd_size_t snd_buf; /* Available buffer space for sending (in bytes). */ +#define TCP_SNDQUEUELEN_OVERFLOW (0xffffU-3) + u16_t snd_queuelen; /* Number of pbufs currently in the send buffer. */ + +#if TCP_OVERSIZE + /* Extra bytes available at the end of the last pbuf in unsent. */ + u16_t unsent_oversize; +#endif /* TCP_OVERSIZE */ + + tcpwnd_size_t bytes_acked; + + /* These are ordered by sequence number: */ + struct tcp_seg *unsent; /* Unsent (queued) segments. */ + struct tcp_seg *unacked; /* Sent but unacknowledged segments. */ +#if TCP_QUEUE_OOSEQ + struct tcp_seg *ooseq; /* Received out of sequence segments. */ +#endif /* TCP_QUEUE_OOSEQ */ + + struct pbuf *refused_data; /* Data previously received but not yet taken by upper layer */ + +#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG + struct tcp_pcb_listen* listener; +#endif /* LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG */ + +#if LWIP_CALLBACK_API + /* Function to be called when more send buffer space is available. */ + tcp_sent_fn sent; + /* Function to be called when (in-sequence) data has arrived. */ + tcp_recv_fn recv; + /* Function to be called when a connection has been set up. */ + tcp_connected_fn connected; + /* Function which is called periodically. */ + tcp_poll_fn poll; + /* Function to be called whenever a fatal error occurs. */ + tcp_err_fn errf; +#endif /* LWIP_CALLBACK_API */ + +#if LWIP_TCP_TIMESTAMPS + u32_t ts_lastacksent; + u32_t ts_recent; +#endif /* LWIP_TCP_TIMESTAMPS */ + + /* idle time before KEEPALIVE is sent */ + u32_t keep_idle; +#if LWIP_TCP_KEEPALIVE + u32_t keep_intvl; + u32_t keep_cnt; +#endif /* LWIP_TCP_KEEPALIVE */ + + /* Persist timer counter */ + u8_t persist_cnt; + /* Persist timer back-off */ + u8_t persist_backoff; + /* Number of persist probes */ + u8_t persist_probe; + + /* KEEPALIVE counter */ + u8_t keep_cnt_sent; + +#if LWIP_WND_SCALE + u8_t snd_scale; + u8_t rcv_scale; +#endif +}; + +#if LWIP_EVENT_API + +enum lwip_event { + LWIP_EVENT_ACCEPT, + LWIP_EVENT_SENT, + LWIP_EVENT_RECV, + LWIP_EVENT_CONNECTED, + LWIP_EVENT_POLL, + LWIP_EVENT_ERR +}; + +err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb, + enum lwip_event, + struct pbuf *p, + u16_t size, + err_t err); + +#endif /* LWIP_EVENT_API */ + +/* Application program's interface: */ +struct tcp_pcb * tcp_new (void); +struct tcp_pcb * tcp_new_ip_type (u8_t type); + +void tcp_arg (struct tcp_pcb *pcb, void *arg); +#if LWIP_CALLBACK_API +void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv); +void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent); +void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err); +void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept); +#endif /* LWIP_CALLBACK_API */ +void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval); + +#define tcp_set_flags(pcb, set_flags) do { (pcb)->flags = (tcpflags_t)((pcb)->flags | (set_flags)); } while(0) +#define tcp_clear_flags(pcb, clr_flags) do { (pcb)->flags = (tcpflags_t)((pcb)->flags & (tcpflags_t)(~(clr_flags) & TCP_ALLFLAGS)); } while(0) +#define tcp_is_flag_set(pcb, flag) (((pcb)->flags & (flag)) != 0) + +#if LWIP_TCP_TIMESTAMPS +#define tcp_mss(pcb) (((pcb)->flags & TF_TIMESTAMP) ? ((pcb)->mss - 12) : (pcb)->mss) +#else /* LWIP_TCP_TIMESTAMPS */ +/** @ingroup tcp_raw */ +#define tcp_mss(pcb) ((pcb)->mss) +#endif /* LWIP_TCP_TIMESTAMPS */ +/** @ingroup tcp_raw */ +#define tcp_sndbuf(pcb) (TCPWND16((pcb)->snd_buf)) +/** @ingroup tcp_raw */ +#define tcp_sndqueuelen(pcb) ((pcb)->snd_queuelen) +/** @ingroup tcp_raw */ +#define tcp_nagle_disable(pcb) tcp_set_flags(pcb, TF_NODELAY) +/** @ingroup tcp_raw */ +#define tcp_nagle_enable(pcb) tcp_clear_flags(pcb, TF_NODELAY) +/** @ingroup tcp_raw */ +#define tcp_nagle_disabled(pcb) tcp_is_flag_set(pcb, TF_NODELAY) + +#if TCP_LISTEN_BACKLOG +#define tcp_backlog_set(pcb, new_backlog) do { \ + LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", (pcb)->state == LISTEN); \ + ((struct tcp_pcb_listen *)(pcb))->backlog = ((new_backlog) ? (new_backlog) : 1); } while(0) +void tcp_backlog_delayed(struct tcp_pcb* pcb); +void tcp_backlog_accepted(struct tcp_pcb* pcb); +#else /* TCP_LISTEN_BACKLOG */ +#define tcp_backlog_set(pcb, new_backlog) +#define tcp_backlog_delayed(pcb) +#define tcp_backlog_accepted(pcb) +#endif /* TCP_LISTEN_BACKLOG */ +#define tcp_accepted(pcb) do { LWIP_UNUSED_ARG(pcb); } while(0) /* compatibility define, not needed any more */ + +void tcp_recved (struct tcp_pcb *pcb, u16_t len); +err_t tcp_bind (struct tcp_pcb *pcb, const ip_addr_t *ipaddr, + u16_t port); +void tcp_bind_netif(struct tcp_pcb *pcb, const struct netif *netif); +err_t tcp_connect (struct tcp_pcb *pcb, const ip_addr_t *ipaddr, + u16_t port, tcp_connected_fn connected); + +struct tcp_pcb * tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err); +struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog); +/** @ingroup tcp_raw */ +#define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG) + +void tcp_abort (struct tcp_pcb *pcb); +err_t tcp_close (struct tcp_pcb *pcb); +err_t tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx); + +err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len, + u8_t apiflags); + +void tcp_setprio (struct tcp_pcb *pcb, u8_t prio); + +err_t tcp_output (struct tcp_pcb *pcb); + +err_t tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t *port); + +#define tcp_dbg_get_tcp_state(pcb) ((pcb)->state) + +/* for compatibility with older implementation */ +#define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6) + +#if LWIP_TCP_PCB_NUM_EXT_ARGS +u8_t tcp_ext_arg_alloc_id(void); +void tcp_ext_arg_set_callbacks(struct tcp_pcb *pcb, uint8_t id, const struct tcp_ext_arg_callbacks * const callbacks); +void tcp_ext_arg_set(struct tcp_pcb *pcb, uint8_t id, void *arg); +void *tcp_ext_arg_get(const struct tcp_pcb *pcb, uint8_t id); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_TCP */ + +#endif /* LWIP_HDR_TCP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcpbase.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcpbase.h new file mode 100644 index 000000000..002307465 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcpbase.h @@ -0,0 +1,88 @@ +/** + * @file + * Base TCP API definitions shared by TCP and ALTCP\n + * See also @ref tcp_raw + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_TCPBASE_H +#define LWIP_HDR_TCPBASE_H + +#include "lwip/opt.h" + +#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#if LWIP_WND_SCALE +typedef u32_t tcpwnd_size_t; +#else +typedef u16_t tcpwnd_size_t; +#endif + +enum tcp_state { + CLOSED = 0, + LISTEN = 1, + SYN_SENT = 2, + SYN_RCVD = 3, + ESTABLISHED = 4, + FIN_WAIT_1 = 5, + FIN_WAIT_2 = 6, + CLOSE_WAIT = 7, + CLOSING = 8, + LAST_ACK = 9, + TIME_WAIT = 10 +}; +/* ATTENTION: this depends on state number ordering! */ +#define TCP_STATE_IS_CLOSING(state) ((state) >= FIN_WAIT_1) + +/* Flags for "apiflags" parameter in tcp_write */ +#define TCP_WRITE_FLAG_COPY 0x01 +#define TCP_WRITE_FLAG_MORE 0x02 + +#define TCP_PRIO_MIN 1 +#define TCP_PRIO_NORMAL 64 +#define TCP_PRIO_MAX 127 + +const char* tcp_debug_state_str(enum tcp_state s); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_TCP */ + +#endif /* LWIP_HDR_TCPBASE_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcpip.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcpip.h new file mode 100644 index 000000000..27300094d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/tcpip.h @@ -0,0 +1,113 @@ +/** + * @file + * Functions to sync with TCPIP thread + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_TCPIP_H +#define LWIP_HDR_TCPIP_H + +#include "lwip/opt.h" + +#if !NO_SYS /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/err.h" +#include "lwip/timeouts.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_TCPIP_CORE_LOCKING +/** The global semaphore to lock the stack. */ +extern sys_mutex_t lock_tcpip_core; +#if !defined LOCK_TCPIP_CORE || defined __DOXYGEN__ +/** Lock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ +#define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core) +/** Unlock lwIP core mutex (needs @ref LWIP_TCPIP_CORE_LOCKING 1) */ +#define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core) +#endif /* LOCK_TCPIP_CORE */ +#else /* LWIP_TCPIP_CORE_LOCKING */ +#define LOCK_TCPIP_CORE() +#define UNLOCK_TCPIP_CORE() +#endif /* LWIP_TCPIP_CORE_LOCKING */ + +struct pbuf; +struct netif; + +/** Function prototype for the init_done function passed to tcpip_init */ +typedef void (*tcpip_init_done_fn)(void *arg); +/** Function prototype for functions passed to tcpip_callback() */ +typedef void (*tcpip_callback_fn)(void *ctx); + +/* Forward declarations */ +struct tcpip_callback_msg; + +void tcpip_init(tcpip_init_done_fn tcpip_init_done, void *arg); + +err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn); +err_t tcpip_input(struct pbuf *p, struct netif *inp); + +err_t tcpip_try_callback(tcpip_callback_fn function, void *ctx); +err_t tcpip_callback(tcpip_callback_fn function, void *ctx); +/** @ingroup lwip_os + * @deprecated use tcpip_try_callback() or tcpip_callback() instead + */ +#define tcpip_callback_with_block(function, ctx, block) ((block != 0)? tcpip_callback(function, ctx) : tcpip_try_callback(function, ctx)) + +struct tcpip_callback_msg* tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx); +void tcpip_callbackmsg_delete(struct tcpip_callback_msg* msg); +err_t tcpip_callbackmsg_trycallback(struct tcpip_callback_msg* msg); +err_t tcpip_callbackmsg_trycallback_fromisr(struct tcpip_callback_msg* msg); + +/* free pbufs or heap memory from another context without blocking */ +err_t pbuf_free_callback(struct pbuf *p); +err_t mem_free_callback(void *m); +void* tcp_get_thread_id(void); +#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS +err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg); +err_t tcpip_untimeout(sys_timeout_handler h, void *arg); +#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ + +#ifdef TCPIP_THREAD_TEST +int tcpip_thread_poll_one(void); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* !NO_SYS */ + +#endif /* LWIP_HDR_TCPIP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/timeouts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/timeouts.h new file mode 100644 index 000000000..b601f9eb3 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/timeouts.h @@ -0,0 +1,128 @@ +/** + * @file + * Timer implementations + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_TIMEOUTS_H +#define LWIP_HDR_TIMEOUTS_H + +#include "lwip/opt.h" +#include "lwip/err.h" +#if !NO_SYS +#include "lwip/sys.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef LWIP_DEBUG_TIMERNAMES +#ifdef LWIP_DEBUG +#define LWIP_DEBUG_TIMERNAMES SYS_DEBUG +#else /* LWIP_DEBUG */ +#define LWIP_DEBUG_TIMERNAMES 0 +#endif /* LWIP_DEBUG*/ +#endif + +/** Returned by sys_timeouts_sleeptime() to indicate there is no timer, so we + * can sleep forever. + */ +#define SYS_TIMEOUTS_SLEEPTIME_INFINITE 0xFFFFFFFF + +/** Function prototype for a stack-internal timer function that has to be + * called at a defined interval */ +typedef void (* lwip_cyclic_timer_handler)(void); + +/** This struct contains information about a stack-internal timer function + that has to be called at a defined interval */ +struct lwip_cyclic_timer { + u32_t interval_ms; + lwip_cyclic_timer_handler handler; +#if LWIP_DEBUG_TIMERNAMES + const char* handler_name; +#endif /* LWIP_DEBUG_TIMERNAMES */ +}; + +/** This array contains all stack-internal cyclic timers. To get the number of + * timers, use lwip_num_cyclic_timers */ +extern const struct lwip_cyclic_timer lwip_cyclic_timers[]; +/** Array size of lwip_cyclic_timers[] */ +extern const int lwip_num_cyclic_timers; + +#if LWIP_TIMERS + +/** Function prototype for a timeout callback function. Register such a function + * using sys_timeout(). + * + * @param arg Additional argument to pass to the function - set up by sys_timeout() + */ +typedef void (* sys_timeout_handler)(void *arg); + +struct sys_timeo { + struct sys_timeo *next; + u32_t time; + sys_timeout_handler h; + void *arg; +#if LWIP_DEBUG_TIMERNAMES + const char* handler_name; +#endif /* LWIP_DEBUG_TIMERNAMES */ +}; + +void sys_timeouts_init(void); + +#if LWIP_DEBUG_TIMERNAMES +void sys_timeout_debug(u32_t msecs, sys_timeout_handler handler, void *arg, const char* handler_name); +#define sys_timeout(msecs, handler, arg) sys_timeout_debug(msecs, handler, arg, #handler) +#else /* LWIP_DEBUG_TIMERNAMES */ +void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg); +#endif /* LWIP_DEBUG_TIMERNAMES */ + +void sys_untimeout(sys_timeout_handler handler, void *arg); +void sys_restart_timeouts(void); +void sys_check_timeouts(void); +u32_t sys_timeouts_sleeptime(void); + +#if LWIP_TESTMODE +struct sys_timeo** sys_timeouts_get_next_timeout(void); +void lwip_cyclic_timer(void *arg); +#endif + +#endif /* LWIP_TIMERS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_TIMEOUTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/udp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/udp.h new file mode 100644 index 000000000..b1c78e58d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/lwip/udp.h @@ -0,0 +1,195 @@ +/** + * @file + * UDP API (to be used from TCPIP thread)\n + * See also @ref udp_raw + */ + +/* + * Copyright (c) 2001-2004 Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_UDP_H +#define LWIP_HDR_UDP_H + +#include "lwip/opt.h" + +#if LWIP_UDP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/pbuf.h" +#include "lwip/netif.h" +#include "lwip/ip_addr.h" +#include "lwip/ip.h" +#include "lwip/ip6_addr.h" +#include "lwip/prot/udp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define UDP_FLAGS_NOCHKSUM 0x01U +#define UDP_FLAGS_UDPLITE 0x02U +#define UDP_FLAGS_CONNECTED 0x04U +#define UDP_FLAGS_MULTICAST_LOOP 0x08U + +struct udp_pcb; + +/** Function prototype for udp pcb receive callback functions + * addr and port are in same byte order as in the pcb + * The callback is responsible for freeing the pbuf + * if it's not used any more. + * + * ATTENTION: Be aware that 'addr' might point into the pbuf 'p' so freeing this pbuf + * can make 'addr' invalid, too. + * + * @param arg user supplied argument (udp_pcb.recv_arg) + * @param pcb the udp_pcb which received data + * @param p the packet buffer that was received + * @param addr the remote IP address from which the packet was received + * @param port the remote port from which the packet was received + */ +typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p, + const ip_addr_t *addr, u16_t port); + +/** the UDP protocol control block */ +struct udp_pcb { +/** Common members of all PCB types */ + IP_PCB; + +/* Protocol specific PCB members */ + + struct udp_pcb *next; + + u8_t flags; + /** ports are in host byte order */ + u16_t local_port, remote_port; + +#if LWIP_MULTICAST_TX_OPTIONS +#if LWIP_IPV4 + /** outgoing network interface for multicast packets, by IPv4 address (if not 'any') */ + ip4_addr_t mcast_ip4; +#endif /* LWIP_IPV4 */ + /** outgoing network interface for multicast packets, by interface index (if nonzero) */ + u8_t mcast_ifindex; + /** TTL for outgoing multicast packets */ + u8_t mcast_ttl; +#endif /* LWIP_MULTICAST_TX_OPTIONS */ + +#if LWIP_UDPLITE + /** used for UDP_LITE only */ + u16_t chksum_len_rx, chksum_len_tx; +#endif /* LWIP_UDPLITE */ + + /** receive callback function */ + udp_recv_fn recv; + /** user-supplied argument for the recv callback */ + void *recv_arg; +}; +/* udp_pcbs export for external reference (e.g. SNMP agent) */ +extern struct udp_pcb *udp_pcbs; + +/* The following functions is the application layer interface to the + UDP code. */ +struct udp_pcb * udp_new (void); +struct udp_pcb * udp_new_ip_type(u8_t type); +void udp_remove (struct udp_pcb *pcb); +err_t udp_bind (struct udp_pcb *pcb, const ip_addr_t *ipaddr, + u16_t port); +void udp_bind_netif (struct udp_pcb *pcb, const struct netif* netif); +err_t udp_connect (struct udp_pcb *pcb, const ip_addr_t *ipaddr, + u16_t port); +void udp_disconnect (struct udp_pcb *pcb); +void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, + void *recv_arg); +err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, + const ip_addr_t *dst_ip, u16_t dst_port, + struct netif *netif); +err_t udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p, + const ip_addr_t *dst_ip, u16_t dst_port, + struct netif *netif, const ip_addr_t *src_ip); +err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, + const ip_addr_t *dst_ip, u16_t dst_port); +err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); + +#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP +err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, + const ip_addr_t *dst_ip, u16_t dst_port, + struct netif *netif, u8_t have_chksum, + u16_t chksum); +err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, + const ip_addr_t *dst_ip, u16_t dst_port, + u8_t have_chksum, u16_t chksum); +err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p, + u8_t have_chksum, u16_t chksum); +err_t udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, + const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, + u8_t have_chksum, u16_t chksum, const ip_addr_t *src_ip); +#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */ + +#define udp_flags(pcb) ((pcb)->flags) +#define udp_setflags(pcb, f) ((pcb)->flags = (f)) + +#define udp_set_flags(pcb, set_flags) do { (pcb)->flags = (u8_t)((pcb)->flags | (set_flags)); } while(0) +#define udp_clear_flags(pcb, clr_flags) do { (pcb)->flags = (u8_t)((pcb)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0) +#define udp_is_flag_set(pcb, flag) (((pcb)->flags & (flag)) != 0) + +/* The following functions are the lower layer interface to UDP. */ +void udp_input (struct pbuf *p, struct netif *inp); + +void udp_init (void); + +/* for compatibility with older implementation */ +#define udp_new_ip6() udp_new_ip_type(IPADDR_TYPE_V6) + +#if LWIP_MULTICAST_TX_OPTIONS +#if LWIP_IPV4 +#define udp_set_multicast_netif_addr(pcb, ip4addr) ip4_addr_copy((pcb)->mcast_ip4, *(ip4addr)) +#define udp_get_multicast_netif_addr(pcb) (&(pcb)->mcast_ip4) +#endif /* LWIP_IPV4 */ +#define udp_set_multicast_netif_index(pcb, idx) ((pcb)->mcast_ifindex = (idx)) +#define udp_get_multicast_netif_index(pcb) ((pcb)->mcast_ifindex) +#define udp_set_multicast_ttl(pcb, value) ((pcb)->mcast_ttl = (value)) +#define udp_get_multicast_ttl(pcb) ((pcb)->mcast_ttl) +#endif /* LWIP_MULTICAST_TX_OPTIONS */ + +#if UDP_DEBUG +void udp_debug_print(struct udp_hdr *udphdr); +#else +#define udp_debug_print(udphdr) +#endif + +void udp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_UDP */ + +#endif /* LWIP_HDR_UDP_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/bridgeif.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/bridgeif.h new file mode 100644 index 000000000..f4f8cf144 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/bridgeif.h @@ -0,0 +1,127 @@ +/** + * @file + * lwIP netif implementing an IEEE 802.1D MAC Bridge + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_NETIF_BRIDGEIF_H +#define LWIP_HDR_NETIF_BRIDGEIF_H + +#include "netif/bridgeif_opts.h" + +#include "lwip/err.h" +#include "lwip/prot/ethernet.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct netif; + +#if (BRIDGEIF_MAX_PORTS < 0) || (BRIDGEIF_MAX_PORTS >= 64) +#error BRIDGEIF_MAX_PORTS must be [1..63] +#elif BRIDGEIF_MAX_PORTS < 8 +typedef u8_t bridgeif_portmask_t; +#elif BRIDGEIF_MAX_PORTS < 16 +typedef u16_t bridgeif_portmask_t; +#elif BRIDGEIF_MAX_PORTS < 32 +typedef u32_t bridgeif_portmask_t; +#elif BRIDGEIF_MAX_PORTS < 64 +typedef u64_t bridgeif_portmask_t; +#endif + +#define BR_FLOOD ((bridgeif_portmask_t)-1) + +/** @ingroup bridgeif + * Initialisation data for @ref bridgeif_init. + * An instance of this type must be passed as parameter 'state' to @ref netif_add + * when the bridge is added. + */ +typedef struct bridgeif_initdata_s { + /** MAC address of the bridge (cannot use the netif's addresses) */ + struct eth_addr ethaddr; + /** Maximum number of ports in the bridge (ports are stored in an array, this + influences memory allocated for netif->state of the bridge netif). */ + u8_t max_ports; + /** Maximum number of dynamic/learning entries in the bridge's forwarding database. + In the default implementation, this controls memory consumption only. */ + u16_t max_fdb_dynamic_entries; + /** Maximum number of static forwarding entries. Influences memory consumption! */ + u16_t max_fdb_static_entries; +} bridgeif_initdata_t; + +/** @ingroup bridgeif + * Use this for constant initialization of a bridgeif_initdat_t + * (ethaddr must be passed as ETH_ADDR()) + */ +#define BRIDGEIF_INITDATA1(max_ports, max_fdb_dynamic_entries, max_fdb_static_entries, ethaddr) {ethaddr, max_ports, max_fdb_dynamic_entries, max_fdb_static_entries} +/** @ingroup bridgeif + * Use this for constant initialization of a bridgeif_initdat_t + * (each byte of ethaddr must be passed) + */ +#define BRIDGEIF_INITDATA2(max_ports, max_fdb_dynamic_entries, max_fdb_static_entries, e0, e1, e2, e3, e4, e5) {{e0, e1, e2, e3, e4, e5}, max_ports, max_fdb_dynamic_entries, max_fdb_static_entries} + +err_t bridgeif_init(struct netif *netif); +err_t bridgeif_add_port(struct netif *bridgeif, struct netif *portif); +err_t bridgeif_fdb_add(struct netif *bridgeif, const struct eth_addr *addr, bridgeif_portmask_t ports); +err_t bridgeif_fdb_remove(struct netif *bridgeif, const struct eth_addr *addr); + +/* FDB interface, can be replaced by own implementation */ +void bridgeif_fdb_update_src(void *fdb_ptr, struct eth_addr *src_addr, u8_t port_idx); +bridgeif_portmask_t bridgeif_fdb_get_dst_ports(void *fdb_ptr, struct eth_addr *dst_addr); +void* bridgeif_fdb_init(u16_t max_fdb_entries); + +#if BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT +#ifndef BRIDGEIF_DECL_PROTECT +/* define bridgeif protection to sys_arch_protect... */ +#include "lwip/sys.h" +#define BRIDGEIF_DECL_PROTECT(lev) SYS_ARCH_DECL_PROTECT(lev) +#define BRIDGEIF_READ_PROTECT(lev) SYS_ARCH_PROTECT(lev) +#define BRIDGEIF_READ_UNPROTECT(lev) SYS_ARCH_UNPROTECT(lev) +#define BRIDGEIF_WRITE_PROTECT(lev) +#define BRIDGEIF_WRITE_UNPROTECT(lev) +#endif +#else /* BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT */ +#include "lwip/tcpip.h" +#define BRIDGEIF_DECL_PROTECT(lev) +#define BRIDGEIF_READ_PROTECT(lev) +#define BRIDGEIF_READ_UNPROTECT(lev) +#define BRIDGEIF_WRITE_PROTECT(lev) +#define BRIDGEIF_WRITE_UNPROTECT(lev) +#endif /* BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_NETIF_BRIDGEIF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/bridgeif_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/bridgeif_opts.h new file mode 100644 index 000000000..b85c30174 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/bridgeif_opts.h @@ -0,0 +1,90 @@ +/** + * @file + * lwIP netif implementing an IEEE 802.1D MAC Bridge + */ + +/* + * Copyright (c) 2017 Simon Goldschmidt. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ + +#ifndef LWIP_HDR_NETIF_BRIDGEIF_OPTS_H +#define LWIP_HDR_NETIF_BRIDGEIF_OPTS_H + +#include "lwip/opt.h" + +/** + * @defgroup bridgeif_opts Options + * @ingroup bridgeif + * @{ + */ + +/** BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT==1: set port netif's 'input' function + * to call directly into bridgeif code and on top of that, directly call into + * the selected forwarding port's 'linkoutput' function. + * This means that the bridgeif input/output path is protected from concurrent access + * but as well, *all* bridge port netif's drivers must correctly handle concurrent access! + * == 0: get into tcpip_thread for every input packet (no multithreading) + * ATTENTION: as ==0 relies on tcpip.h, the default depends on NO_SYS setting + */ +#ifndef BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT +#define BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT NO_SYS +#endif + +/** BRIDGEIF_MAX_PORTS: this is used to create a typedef used for forwarding + * bit-fields: the number of bits required is this + 1 (for the internal/cpu port) + * (63 is the maximum, resulting in an u64_t for the bit mask) + * ATTENTION: this controls the maximum number of the implementation only! + * The max. number of ports per bridge must still be passed via netif_add parameter! + */ +#ifndef BRIDGEIF_MAX_PORTS +#define BRIDGEIF_MAX_PORTS 7 +#endif + +/** BRIDGEIF_DEBUG: Enable generic debugging in bridgeif.c. */ +#ifndef BRIDGEIF_DEBUG +#define BRIDGEIF_DEBUG LWIP_DBG_OFF +#endif + +/** BRIDGEIF_DEBUG: Enable FDB debugging in bridgeif.c. */ +#ifndef BRIDGEIF_FDB_DEBUG +#define BRIDGEIF_FDB_DEBUG LWIP_DBG_OFF +#endif + +/** BRIDGEIF_DEBUG: Enable forwarding debugging in bridgeif.c. */ +#ifndef BRIDGEIF_FW_DEBUG +#define BRIDGEIF_FW_DEBUG LWIP_DBG_OFF +#endif + +/** + * @} + */ + +#endif /* LWIP_HDR_NETIF_BRIDGEIF_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/etharp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/etharp.h new file mode 100644 index 000000000..b536fd280 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/etharp.h @@ -0,0 +1,3 @@ +/* ARP has been moved to core/ipv4, provide this #include for compatibility only */ +#include "lwip/etharp.h" +#include "netif/ethernet.h" diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ethernet.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ethernet.h new file mode 100644 index 000000000..49649cbf8 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ethernet.h @@ -0,0 +1,77 @@ +/** + * @file + * Ethernet input function - handles INCOMING ethernet level traffic + * To be used in most low-level netif implementations + */ + +/* + * Copyright (c) 2001-2003 Swedish Institute of Computer Science. + * Copyright (c) 2003-2004 Leon Woestenberg + * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ + +#ifndef LWIP_HDR_NETIF_ETHERNET_H +#define LWIP_HDR_NETIF_ETHERNET_H + +#include "lwip/opt.h" + +#include "lwip/pbuf.h" +#include "lwip/netif.h" +#include "lwip/prot/ethernet.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if LWIP_ARP || LWIP_ETHERNET + +/** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type) + * to a filter function that returns the correct netif when using multiple + * netifs on one hardware interface where the netif's low-level receive + * routine cannot decide for the correct netif (e.g. when mapping multiple + * IP addresses to one hardware interface). + */ +#ifndef LWIP_ARP_FILTER_NETIF +#define LWIP_ARP_FILTER_NETIF 0 +#endif + +err_t ethernet_input(struct pbuf *p, struct netif *netif); +err_t ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type); + +extern const struct eth_addr ethbroadcast, ethzero; + +#endif /* LWIP_ARP || LWIP_ETHERNET */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_NETIF_ETHERNET_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ieee802154.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ieee802154.h new file mode 100644 index 000000000..54e019fd0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ieee802154.h @@ -0,0 +1,112 @@ +/** + * @file + * Definitions for IEEE 802.15.4 MAC frames + */ + +/* + * Copyright (c) 2018 Simon Goldschmidt. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ +#ifndef LWIP_HDR_NETIF_IEEE802154_H +#define LWIP_HDR_NETIF_IEEE802154_H + +#include "lwip/opt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +/** General MAC frame format + * This shows the full featured header, mainly for documentation. + * Some fields are omitted or shortened to achieve frame compression. + */ +struct ieee_802154_hdr { + /** See IEEE_802154_FC_* defines */ + PACK_STRUCT_FIELD(u16_t frame_control); + /** Sequence number is omitted if IEEE_802154_FC_SEQNO_SUPPR is set in frame_control */ + PACK_STRUCT_FLD_8(u8_t sequence_number); + /** Destination PAN ID is omitted if Destination Addressing Mode is 0 */ + PACK_STRUCT_FIELD(u16_t destination_pan_id); + /** Destination Address is omitted if Destination Addressing Mode is 0 */ + PACK_STRUCT_FLD_8(u8_t destination_address[8]); + /** Source PAN ID is omitted if Source Addressing Mode is 0 + or if IEEE_802154_FC_PANID_COMPR is set in frame control*/ + PACK_STRUCT_FIELD(u16_t source_pan_id); + /** Source Address is omitted if Source Addressing Mode is 0 */ + PACK_STRUCT_FLD_8(u8_t source_address[8]); + /* The rest is variable */ +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +/* Addressing modes (2 bits) */ +#define IEEE_802154_ADDR_MODE_NO_ADDR 0x00 /* PAN ID and address fields are not present */ +#define IEEE_802154_ADDR_MODE_RESERVED 0x01 /* Reserved */ +#define IEEE_802154_ADDR_MODE_SHORT 0x02 /* Address field contains a short address (16 bit) */ +#define IEEE_802154_ADDR_MODE_EXT 0x03 /* Address field contains an extended address (64 bit) */ + +/* IEEE 802.15.4 Frame Control definitions (2 bytes; see IEEE 802.15.4-2015 ch. 7.2.1) */ +#define IEEE_802154_FC_FT_MASK 0x0007 /* bits 0..2: Frame Type */ +#define IEEE_802154_FC_FT_BEACON 0x00 +#define IEEE_802154_FC_FT_DATA 0x01 +#define IEEE_802154_FC_FT_ACK 0x02 +#define IEEE_802154_FC_FT_MAC_CMD 0x03 +#define IEEE_802154_FC_FT_RESERVED 0x04 +#define IEEE_802154_FC_FT_MULTIPURPOSE 0x05 +#define IEEE_802154_FC_FT_FRAG 0x06 +#define IEEE_802154_FC_FT_EXT 0x07 +#define IEEE_802154_FC_SEC_EN 0x0008 /* bit 3: Security Enabled */ +#define IEEE_802154_FC_FRAME_PEND 0x0010 /* bit 4: Frame Pending */ +#define IEEE_802154_FC_ACK_REQ 0x0020 /* bit 5: AR (ACK required) */ +#define IEEE_802154_FC_PANID_COMPR 0x0040 /* bit 6: PAN ID Compression (src and dst are equal, src PAN ID omitted) */ +#define IEEE_802154_FC_RESERVED 0x0080 +#define IEEE_802154_FC_SEQNO_SUPPR 0x0100 /* bit 8: Sequence Number Suppression */ +#define IEEE_802154_FC_IE_PRESENT 0x0200 /* bit 9: IE Present */ +#define IEEE_802154_FC_DST_ADDR_MODE_MASK 0x0c00 /* bits 10..11: Destination Addressing Mode */ +#define IEEE_802154_FC_DST_ADDR_MODE_NO_ADDR (IEEE_802154_ADDR_MODE_NO_ADDR << 10) +#define IEEE_802154_FC_DST_ADDR_MODE_SHORT (IEEE_802154_ADDR_MODE_SHORT << 10) +#define IEEE_802154_FC_DST_ADDR_MODE_EXT (IEEE_802154_ADDR_MODE_EXT << 10) +#define IEEE_802154_FC_FRAME_VERSION_MASK 0x3000 /* bits 12..13: Frame Version */ +#define IEEE_802154_FC_FRAME_VERSION_GET(x) (((x) & IEEE_802154_FC_FRAME_VERSION_MASK) >> 12) +#define IEEE_802154_FC_SRC_ADDR_MODE_MASK 0xc000 /* bits 14..15: Source Addressing Mode */ +#define IEEE_802154_FC_SRC_ADDR_MODE_SHORT (IEEE_802154_ADDR_MODE_SHORT << 14) +#define IEEE_802154_FC_SRC_ADDR_MODE_EXT (IEEE_802154_ADDR_MODE_EXT << 14) + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_NETIF_IEEE802154_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6.h new file mode 100644 index 000000000..ecff24ba6 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6.h @@ -0,0 +1,89 @@ +/** + * @file + * + * 6LowPAN output for IPv6. Uses ND tables for link-layer addressing. Fragments packets to 6LowPAN units. + */ + +/* + * Copyright (c) 2015 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ + +#ifndef LWIP_HDR_LOWPAN6_H +#define LWIP_HDR_LOWPAN6_H + +#include "netif/lowpan6_opts.h" + +#if LWIP_IPV6 + +#include "netif/lowpan6_common.h" +#include "lwip/pbuf.h" +#include "lwip/ip.h" +#include "lwip/ip_addr.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** 1 second period for reassembly */ +#define LOWPAN6_TMR_INTERVAL 1000 + +void lowpan6_tmr(void); + +err_t lowpan6_set_context(u8_t idx, const ip6_addr_t * context); +err_t lowpan6_set_short_addr(u8_t addr_high, u8_t addr_low); + +#if LWIP_IPV4 +err_t lowpan4_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr); +#endif /* LWIP_IPV4 */ +err_t lowpan6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr); +err_t lowpan6_input(struct pbuf * p, struct netif *netif); +err_t lowpan6_if_init(struct netif *netif); + +/* pan_id in network byte order. */ +err_t lowpan6_set_pan_id(u16_t pan_id); + +u16_t lowpan6_calc_crc(const void *buf, u16_t len); + +#if !NO_SYS +err_t tcpip_6lowpan_input(struct pbuf *p, struct netif *inp); +#endif /* !NO_SYS */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 */ + +#endif /* LWIP_HDR_LOWPAN6_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_ble.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_ble.h new file mode 100644 index 000000000..01896a7ff --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_ble.h @@ -0,0 +1,78 @@ +/** + * @file + * 6LowPAN over BLE for IPv6 (RFC7668). + */ + +/* + * Copyright (c) 2017 Benjamin Aigner + * Copyright (c) 2015 Inico Technologies Ltd. , Author: Ivan Delamer + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Benjamin Aigner + * + * Based on the original 6lowpan implementation of lwIP ( @see 6lowpan.c) + */ + +#ifndef LWIP_HDR_LOWPAN6_BLE_H +#define LWIP_HDR_LOWPAN6_BLE_H + +#include "netif/lowpan6_opts.h" + +#if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ + +#include "netif/lowpan6_common.h" +#include "lwip/pbuf.h" +#include "lwip/ip.h" +#include "lwip/ip_addr.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +err_t rfc7668_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr); +err_t rfc7668_input(struct pbuf * p, struct netif *netif); +err_t rfc7668_set_local_addr_eui64(struct netif *netif, const u8_t *local_addr, size_t local_addr_len); +err_t rfc7668_set_local_addr_mac48(struct netif *netif, const u8_t *local_addr, size_t local_addr_len, int is_public_addr); +err_t rfc7668_set_peer_addr_eui64(struct netif *netif, const u8_t *peer_addr, size_t peer_addr_len); +err_t rfc7668_set_peer_addr_mac48(struct netif *netif, const u8_t *peer_addr, size_t peer_addr_len, int is_public_addr); +err_t rfc7668_set_context(u8_t index, const ip6_addr_t * context); +err_t rfc7668_if_init(struct netif *netif); + +#if !NO_SYS +err_t tcpip_rfc7668_input(struct pbuf *p, struct netif *inp); +#endif + +void ble_addr_to_eui64(uint8_t *dst, const uint8_t *src, int public_addr); +void eui64_to_ble_addr(uint8_t *dst, const uint8_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 */ + +#endif /* LWIP_HDR_LOWPAN6_BLE_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_common.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_common.h new file mode 100644 index 000000000..0dc13ab5b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_common.h @@ -0,0 +1,82 @@ +/** + * @file + * + * Common 6LowPAN routines for IPv6. Uses ND tables for link-layer addressing. Fragments packets to 6LowPAN units. + */ + +/* + * Copyright (c) 2015 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ + +#ifndef LWIP_HDR_LOWPAN6_COMMON_H +#define LWIP_HDR_LOWPAN6_COMMON_H + +#include "netif/lowpan6_opts.h" + +#if LWIP_IPV6 /* don't build if IPv6 is disabled in lwipopts.h */ + +#include "lwip/pbuf.h" +#include "lwip/ip.h" +#include "lwip/ip6_addr.h" +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Helper define for a link layer address, which can be encoded as 0, 2 or 8 bytes */ +struct lowpan6_link_addr { + /* encoded length of the address */ + u8_t addr_len; + /* address bytes */ + u8_t addr[8]; +}; + +s8_t lowpan6_get_address_mode(const ip6_addr_t *ip6addr, const struct lowpan6_link_addr *mac_addr); + +#if LWIP_6LOWPAN_IPHC +err_t lowpan6_compress_headers(struct netif *netif, u8_t *inbuf, size_t inbuf_size, u8_t *outbuf, size_t outbuf_size, + u8_t *lowpan6_header_len_out, u8_t *hidden_header_len_out, ip6_addr_t *lowpan6_contexts, + const struct lowpan6_link_addr *src, const struct lowpan6_link_addr *dst); +struct pbuf *lowpan6_decompress(struct pbuf *p, u16_t datagram_size, ip6_addr_t *lowpan6_contexts, + struct lowpan6_link_addr *src, struct lowpan6_link_addr *dest); +#endif /* LWIP_6LOWPAN_IPHC */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 */ + +#endif /* LWIP_HDR_LOWPAN6_COMMON_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_opts.h new file mode 100644 index 000000000..17d46cdcc --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/lowpan6_opts.h @@ -0,0 +1,122 @@ +/** + * @file + * 6LowPAN options list + */ + +/* + * Copyright (c) 2015 Inico Technologies 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Ivan Delamer + * + * + * Please coordinate changes and requests with Ivan Delamer + * + */ + +#ifndef LWIP_HDR_LOWPAN6_OPTS_H +#define LWIP_HDR_LOWPAN6_OPTS_H + +#include "lwip/opt.h" + +/** LWIP_6LOWPAN_NUM_CONTEXTS: define the number of compression + * contexts per netif type + */ +#ifndef LWIP_6LOWPAN_NUM_CONTEXTS +#define LWIP_6LOWPAN_NUM_CONTEXTS 10 +#endif + +/** LWIP_6LOWPAN_INFER_SHORT_ADDRESS: set this to 0 to disable creating + * short addresses for matching addresses (debug only) + */ +#ifndef LWIP_6LOWPAN_INFER_SHORT_ADDRESS +#define LWIP_6LOWPAN_INFER_SHORT_ADDRESS 1 +#endif + +/** LWIP_6LOWPAN_IPHC: set this to 0 to disable IP header compression as per + * RFC 6282 (which is mandatory for BLE) + */ +#ifndef LWIP_6LOWPAN_IPHC +#define LWIP_6LOWPAN_IPHC 1 +#endif + +/** Set this to 1 if your IEEE 802.15.4 interface can calculate and check the + * CRC in hardware. This means TX packets get 2 zero bytes added on transmission + * which are to be filled with the CRC. + */ +#ifndef LWIP_6LOWPAN_802154_HW_CRC +#define LWIP_6LOWPAN_802154_HW_CRC 0 +#endif + +/** If LWIP_6LOWPAN_802154_HW_CRC==0, this can override the default slow + * implementation of the CRC used for 6LoWPAN over IEEE 802.15.4 (which uses + * a shift register). + */ +#ifndef LWIP_6LOWPAN_CALC_CRC +#define LWIP_6LOWPAN_CALC_CRC(buf, len) lowpan6_calc_crc(buf, len) +#endif + +/** Debug level for 6LoWPAN in general */ +#ifndef LWIP_LOWPAN6_DEBUG +#define LWIP_LOWPAN6_DEBUG LWIP_DBG_OFF +#endif + +/** Debug level for 6LoWPAN over IEEE 802.15.4 */ +#ifndef LWIP_LOWPAN6_802154_DEBUG +#define LWIP_LOWPAN6_802154_DEBUG LWIP_DBG_OFF +#endif + +/** LWIP_LOWPAN6_IP_COMPRESSED_DEBUG: enable compressed IP frame + * output debugging + */ +#ifndef LWIP_LOWPAN6_IP_COMPRESSED_DEBUG +#define LWIP_LOWPAN6_IP_COMPRESSED_DEBUG LWIP_DBG_OFF +#endif + +/** LWIP_LOWPAN6_DECOMPRESSION_DEBUG: enable decompression debug output + */ +#ifndef LWIP_LOWPAN6_DECOMPRESSION_DEBUG +#define LWIP_LOWPAN6_DECOMPRESSION_DEBUG LWIP_DBG_OFF +#endif + +/** LWIP_RFC7668_IP_UNCOMPRESSED_DEBUG: enable decompressed IP frame + * output debugging */ +#ifndef LWIP_RFC7668_IP_UNCOMPRESSED_DEBUG +#define LWIP_RFC7668_IP_UNCOMPRESSED_DEBUG LWIP_DBG_OFF +#endif + +/** LWIP_RFC7668_LINUX_WORKAROUND_PUBLIC_ADDRESS: + * Currently, the linux kernel driver for 6lowpan sets/clears a bit in + * the address, depending on the BD address (either public or not). + * Might not be RFC7668 conform, so you may select to do that (=1) or + * not (=0) */ +#ifndef LWIP_RFC7668_LINUX_WORKAROUND_PUBLIC_ADDRESS +#define LWIP_RFC7668_LINUX_WORKAROUND_PUBLIC_ADDRESS 1 +#endif + + +#endif /* LWIP_HDR_LOWPAN6_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ccp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ccp.h new file mode 100644 index 000000000..b2285228b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ccp.h @@ -0,0 +1,164 @@ +/* + * ccp.h - Definitions for PPP Compression Control Protocol. + * + * Copyright (c) 1994-2002 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 3. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: ccp.h,v 1.12 2004/11/04 10:02:26 paulus Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && CCP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef CCP_H +#define CCP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * CCP codes. + */ + +#define CCP_CONFREQ 1 +#define CCP_CONFACK 2 +#define CCP_TERMREQ 5 +#define CCP_TERMACK 6 +#define CCP_RESETREQ 14 +#define CCP_RESETACK 15 + +/* + * Max # bytes for a CCP option + */ + +#define CCP_MAX_OPTION_LENGTH 32 + +/* + * Parts of a CCP packet. + */ + +#define CCP_CODE(dp) ((dp)[0]) +#define CCP_ID(dp) ((dp)[1]) +#define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3]) +#define CCP_HDRLEN 4 + +#define CCP_OPT_CODE(dp) ((dp)[0]) +#define CCP_OPT_LENGTH(dp) ((dp)[1]) +#define CCP_OPT_MINLEN 2 + +#if BSDCOMPRESS_SUPPORT +/* + * Definitions for BSD-Compress. + */ + +#define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */ +#define CILEN_BSD_COMPRESS 3 /* length of config. option */ + +/* Macros for handling the 3rd byte of the BSD-Compress config option. */ +#define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */ +#define BSD_VERSION(x) ((x) >> 5) /* version of option format */ +#define BSD_CURRENT_VERSION 1 /* current version number */ +#define BSD_MAKE_OPT(v, n) (((v) << 5) | (n)) + +#define BSD_MIN_BITS 9 /* smallest code size supported */ +#define BSD_MAX_BITS 15 /* largest code size supported */ +#endif /* BSDCOMPRESS_SUPPORT */ + +#if DEFLATE_SUPPORT +/* + * Definitions for Deflate. + */ + +#define CI_DEFLATE 26 /* config option for Deflate */ +#define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */ +#define CILEN_DEFLATE 4 /* length of its config option */ + +#define DEFLATE_MIN_SIZE 9 +#define DEFLATE_MAX_SIZE 15 +#define DEFLATE_METHOD_VAL 8 +#define DEFLATE_SIZE(x) (((x) >> 4) + 8) +#define DEFLATE_METHOD(x) ((x) & 0x0F) +#define DEFLATE_MAKE_OPT(w) ((((w) - 8) << 4) + DEFLATE_METHOD_VAL) +#define DEFLATE_CHK_SEQUENCE 0 +#endif /* DEFLATE_SUPPORT */ + +#if MPPE_SUPPORT +/* + * Definitions for MPPE. + */ + +#define CI_MPPE 18 /* config option for MPPE */ +#define CILEN_MPPE 6 /* length of config option */ +#endif /* MPPE_SUPPORT */ + +#if PREDICTOR_SUPPORT +/* + * Definitions for other, as yet unsupported, compression methods. + */ + +#define CI_PREDICTOR_1 1 /* config option for Predictor-1 */ +#define CILEN_PREDICTOR_1 2 /* length of its config option */ +#define CI_PREDICTOR_2 2 /* config option for Predictor-2 */ +#define CILEN_PREDICTOR_2 2 /* length of its config option */ +#endif /* PREDICTOR_SUPPORT */ + +typedef struct ccp_options { +#if DEFLATE_SUPPORT + unsigned int deflate :1; /* do Deflate? */ + unsigned int deflate_correct :1; /* use correct code for deflate? */ + unsigned int deflate_draft :1; /* use draft RFC code for deflate? */ +#endif /* DEFLATE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT + unsigned int bsd_compress :1; /* do BSD Compress? */ +#endif /* BSDCOMPRESS_SUPPORT */ +#if PREDICTOR_SUPPORT + unsigned int predictor_1 :1; /* do Predictor-1? */ + unsigned int predictor_2 :1; /* do Predictor-2? */ +#endif /* PREDICTOR_SUPPORT */ + +#if MPPE_SUPPORT + u8_t mppe; /* MPPE bitfield */ +#endif /* MPPE_SUPPORT */ +#if BSDCOMPRESS_SUPPORT + u_short bsd_bits; /* # bits/code for BSD Compress */ +#endif /* BSDCOMPRESS_SUPPORT */ +#if DEFLATE_SUPPORT + u_short deflate_size; /* lg(window size) for Deflate */ +#endif /* DEFLATE_SUPPORT */ + u8_t method; /* code for chosen compression method */ +} ccp_options; + +extern const struct protent ccp_protent; + +void ccp_resetrequest(ppp_pcb *pcb); /* Issue a reset-request. */ + +#ifdef __cplusplus +} +#endif + +#endif /* CCP_H */ +#endif /* PPP_SUPPORT && CCP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap-md5.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap-md5.h new file mode 100644 index 000000000..eb0269fe5 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap-md5.h @@ -0,0 +1,36 @@ +/* + * chap-md5.h - New CHAP/MD5 implementation. + * + * Copyright (c) 2003 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 3. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +extern const struct chap_digest_type md5_digest; + +#endif /* PPP_SUPPORT && CHAP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap-new.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap-new.h new file mode 100644 index 000000000..2d8cd9ca9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap-new.h @@ -0,0 +1,200 @@ +/* + * chap-new.c - New CHAP implementation. + * + * Copyright (c) 2003 Paul Mackerras. 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. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 3. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef CHAP_H +#define CHAP_H + +#include "ppp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * CHAP packets begin with a standard header with code, id, len (2 bytes). + */ +#define CHAP_HDRLEN 4 + +/* + * Values for the code field. + */ +#define CHAP_CHALLENGE 1 +#define CHAP_RESPONSE 2 +#define CHAP_SUCCESS 3 +#define CHAP_FAILURE 4 + +/* + * CHAP digest codes. + */ +#define CHAP_MD5 5 +#if MSCHAP_SUPPORT +#define CHAP_MICROSOFT 0x80 +#define CHAP_MICROSOFT_V2 0x81 +#endif /* MSCHAP_SUPPORT */ + +/* + * Semi-arbitrary limits on challenge and response fields. + */ +#define MAX_CHALLENGE_LEN 64 +#define MAX_RESPONSE_LEN 64 + +/* + * These limits apply to challenge and response packets we send. + * The +4 is the +1 that we actually need rounded up. + */ +#define CHAL_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_CHALLENGE_LEN + MAXNAMELEN) +#define RESP_MAX_PKTLEN (PPP_HDRLEN + CHAP_HDRLEN + 4 + MAX_RESPONSE_LEN + MAXNAMELEN) + +/* bitmask of supported algorithms */ +#if MSCHAP_SUPPORT +#define MDTYPE_MICROSOFT_V2 0x1 +#define MDTYPE_MICROSOFT 0x2 +#endif /* MSCHAP_SUPPORT */ +#define MDTYPE_MD5 0x4 +#define MDTYPE_NONE 0 + +#if MSCHAP_SUPPORT +/* Return the digest alg. ID for the most preferred digest type. */ +#define CHAP_DIGEST(mdtype) \ + ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \ + ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \ + ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \ + 0 +#else /* !MSCHAP_SUPPORT */ +#define CHAP_DIGEST(mdtype) \ + ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \ + 0 +#endif /* MSCHAP_SUPPORT */ + +/* Return the bit flag (lsb set) for our most preferred digest type. */ +#define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype) + +/* Return the bit flag for a given digest algorithm ID. */ +#if MSCHAP_SUPPORT +#define CHAP_MDTYPE_D(digest) \ + ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \ + ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \ + ((digest) == CHAP_MD5)? MDTYPE_MD5: \ + 0 +#else /* !MSCHAP_SUPPORT */ +#define CHAP_MDTYPE_D(digest) \ + ((digest) == CHAP_MD5)? MDTYPE_MD5: \ + 0 +#endif /* MSCHAP_SUPPORT */ + +/* Can we do the requested digest? */ +#if MSCHAP_SUPPORT +#define CHAP_CANDIGEST(mdtype, digest) \ + ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \ + ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \ + ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \ + 0 +#else /* !MSCHAP_SUPPORT */ +#define CHAP_CANDIGEST(mdtype, digest) \ + ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \ + 0 +#endif /* MSCHAP_SUPPORT */ + +/* + * The code for each digest type has to supply one of these. + */ +struct chap_digest_type { + int code; + +#if PPP_SERVER + /* + * Note: challenge and response arguments below are formatted as + * a length byte followed by the actual challenge/response data. + */ + void (*generate_challenge)(ppp_pcb *pcb, unsigned char *challenge); + int (*verify_response)(ppp_pcb *pcb, int id, const char *name, + const unsigned char *secret, int secret_len, + const unsigned char *challenge, const unsigned char *response, + char *message, int message_space); +#endif /* PPP_SERVER */ + void (*make_response)(ppp_pcb *pcb, unsigned char *response, int id, const char *our_name, + const unsigned char *challenge, const char *secret, int secret_len, + unsigned char *priv); + int (*check_success)(ppp_pcb *pcb, unsigned char *pkt, int len, unsigned char *priv); + void (*handle_failure)(ppp_pcb *pcb, unsigned char *pkt, int len); +}; + +/* + * Each interface is described by chap structure. + */ +#if CHAP_SUPPORT +typedef struct chap_client_state { + u8_t flags; + const char *name; + const struct chap_digest_type *digest; + unsigned char priv[64]; /* private area for digest's use */ +} chap_client_state; + +#if PPP_SERVER +typedef struct chap_server_state { + u8_t flags; + u8_t id; + const char *name; + const struct chap_digest_type *digest; + int challenge_xmits; + int challenge_pktlen; + unsigned char challenge[CHAL_MAX_PKTLEN]; +} chap_server_state; +#endif /* PPP_SERVER */ +#endif /* CHAP_SUPPORT */ + +#if 0 /* UNUSED */ +/* Hook for a plugin to validate CHAP challenge */ +extern int (*chap_verify_hook)(char *name, char *ourname, int id, + const struct chap_digest_type *digest, + unsigned char *challenge, unsigned char *response, + char *message, int message_space); +#endif /* UNUSED */ + +#if PPP_SERVER +/* Called by authentication code to start authenticating the peer. */ +extern void chap_auth_peer(ppp_pcb *pcb, const char *our_name, int digest_code); +#endif /* PPP_SERVER */ + +/* Called by auth. code to start authenticating us to the peer. */ +extern void chap_auth_with_peer(ppp_pcb *pcb, const char *our_name, int digest_code); + +/* Represents the CHAP protocol to the main pppd code */ +extern const struct protent chap_protent; + +#ifdef __cplusplus +} +#endif + +#endif /* CHAP_H */ +#endif /* PPP_SUPPORT && CHAP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap_ms.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap_ms.h new file mode 100644 index 000000000..079529115 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/chap_ms.h @@ -0,0 +1,44 @@ +/* + * chap_ms.h - Challenge Handshake Authentication Protocol definitions. + * + * Copyright (c) 1995 Eric Rosenquist. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: chap_ms.h,v 1.13 2004/11/15 22:13:26 paulus Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef CHAPMS_INCLUDE +#define CHAPMS_INCLUDE + +extern const struct chap_digest_type chapms_digest; +extern const struct chap_digest_type chapms2_digest; + +#endif /* CHAPMS_INCLUDE */ + +#endif /* PPP_SUPPORT && MSCHAP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/eap.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/eap.h new file mode 100644 index 000000000..3ee9aaf81 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/eap.h @@ -0,0 +1,169 @@ +/* + * eap.h - Extensible Authentication Protocol for PPP (RFC 2284) + * + * Copyright (c) 2001 by Sun Microsystems, Inc. + * All rights reserved. + * + * Non-exclusive rights to redistribute, modify, translate, and use + * this software in source and binary forms, in whole or in part, is + * hereby granted, provided that the above copyright notice is + * duplicated in any source form, and that neither the name of the + * copyright holder nor the author is used to endorse or promote + * products derived from this software. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Original version by James Carlson + * + * $Id: eap.h,v 1.2 2003/06/11 23:56:26 paulus Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && EAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef PPP_EAP_H +#define PPP_EAP_H + +#include "ppp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Packet header = Code, id, length. + */ +#define EAP_HEADERLEN 4 + + +/* EAP message codes. */ +#define EAP_REQUEST 1 +#define EAP_RESPONSE 2 +#define EAP_SUCCESS 3 +#define EAP_FAILURE 4 + +/* EAP types */ +#define EAPT_IDENTITY 1 +#define EAPT_NOTIFICATION 2 +#define EAPT_NAK 3 /* (response only) */ +#define EAPT_MD5CHAP 4 +#define EAPT_OTP 5 /* One-Time Password; RFC 1938 */ +#define EAPT_TOKEN 6 /* Generic Token Card */ +/* 7 and 8 are unassigned. */ +#define EAPT_RSA 9 /* RSA Public Key Authentication */ +#define EAPT_DSS 10 /* DSS Unilateral */ +#define EAPT_KEA 11 /* KEA */ +#define EAPT_KEA_VALIDATE 12 /* KEA-VALIDATE */ +#define EAPT_TLS 13 /* EAP-TLS */ +#define EAPT_DEFENDER 14 /* Defender Token (AXENT) */ +#define EAPT_W2K 15 /* Windows 2000 EAP */ +#define EAPT_ARCOT 16 /* Arcot Systems */ +#define EAPT_CISCOWIRELESS 17 /* Cisco Wireless */ +#define EAPT_NOKIACARD 18 /* Nokia IP smart card */ +#define EAPT_SRP 19 /* Secure Remote Password */ +/* 20 is deprecated */ + +/* EAP SRP-SHA1 Subtypes */ +#define EAPSRP_CHALLENGE 1 /* Request 1 - Challenge */ +#define EAPSRP_CKEY 1 /* Response 1 - Client Key */ +#define EAPSRP_SKEY 2 /* Request 2 - Server Key */ +#define EAPSRP_CVALIDATOR 2 /* Response 2 - Client Validator */ +#define EAPSRP_SVALIDATOR 3 /* Request 3 - Server Validator */ +#define EAPSRP_ACK 3 /* Response 3 - final ack */ +#define EAPSRP_LWRECHALLENGE 4 /* Req/resp 4 - Lightweight rechal */ + +#define SRPVAL_EBIT 0x00000001 /* Use shared key for ECP */ + +#define SRP_PSEUDO_ID "pseudo_" +#define SRP_PSEUDO_LEN 7 + +#define MD5_SIGNATURE_SIZE 16 +#define EAP_MIN_CHALLENGE_LENGTH 17 +#define EAP_MAX_CHALLENGE_LENGTH 24 +#define EAP_MIN_MAX_POWER_OF_TWO_CHALLENGE_LENGTH 3 /* 2^3-1 = 7, 17+7 = 24 */ + +#define EAP_STATES \ + "Initial", "Pending", "Closed", "Listen", "Identify", \ + "SRP1", "SRP2", "SRP3", "MD5Chall", "Open", "SRP4", "BadAuth" + +#define eap_client_active(pcb) ((pcb)->eap.es_client.ea_state == eapListen) +#if PPP_SERVER +#define eap_server_active(pcb) \ + ((pcb)->eap.es_server.ea_state >= eapIdentify && \ + (pcb)->eap.es_server.ea_state <= eapMD5Chall) +#endif /* PPP_SERVER */ + +/* + * Complete EAP state for one PPP session. + */ +enum eap_state_code { + eapInitial = 0, /* No EAP authentication yet requested */ + eapPending, /* Waiting for LCP (no timer) */ + eapClosed, /* Authentication not in use */ + eapListen, /* Client ready (and timer running) */ + eapIdentify, /* EAP Identify sent */ + eapSRP1, /* Sent EAP SRP-SHA1 Subtype 1 */ + eapSRP2, /* Sent EAP SRP-SHA1 Subtype 2 */ + eapSRP3, /* Sent EAP SRP-SHA1 Subtype 3 */ + eapMD5Chall, /* Sent MD5-Challenge */ + eapOpen, /* Completed authentication */ + eapSRP4, /* Sent EAP SRP-SHA1 Subtype 4 */ + eapBadAuth /* Failed authentication */ +}; + +struct eap_auth { + const char *ea_name; /* Our name */ + char ea_peer[MAXNAMELEN +1]; /* Peer's name */ + void *ea_session; /* Authentication library linkage */ + u_char *ea_skey; /* Shared encryption key */ + u_short ea_namelen; /* Length of our name */ + u_short ea_peerlen; /* Length of peer's name */ + enum eap_state_code ea_state; + u_char ea_id; /* Current id */ + u_char ea_requests; /* Number of Requests sent/received */ + u_char ea_responses; /* Number of Responses */ + u_char ea_type; /* One of EAPT_* */ + u32_t ea_keyflags; /* SRP shared key usage flags */ +}; + +#ifndef EAP_MAX_CHALLENGE_LENGTH +#define EAP_MAX_CHALLENGE_LENGTH 24 +#endif +typedef struct eap_state { + struct eap_auth es_client; /* Client (authenticatee) data */ +#if PPP_SERVER + struct eap_auth es_server; /* Server (authenticator) data */ +#endif /* PPP_SERVER */ + int es_savedtime; /* Saved timeout */ + int es_rechallenge; /* EAP rechallenge interval */ + int es_lwrechallenge; /* SRP lightweight rechallenge inter */ + u8_t es_usepseudo; /* Use SRP Pseudonym if offered one */ + int es_usedpseudo; /* Set if we already sent PN */ + int es_challen; /* Length of challenge string */ + u_char es_challenge[EAP_MAX_CHALLENGE_LENGTH]; +} eap_state; + +/* + * Timeouts. + */ +#if 0 /* moved to ppp_opts.h */ +#define EAP_DEFTIMEOUT 3 /* Timeout (seconds) for rexmit */ +#define EAP_DEFTRANSMITS 10 /* max # times to transmit */ +#define EAP_DEFREQTIME 20 /* Time to wait for peer request */ +#define EAP_DEFALLOWREQ 20 /* max # times to accept requests */ +#endif /* moved to ppp_opts.h */ + +void eap_authwithpeer(ppp_pcb *pcb, const char *localname); +void eap_authpeer(ppp_pcb *pcb, const char *localname); + +extern const struct protent eap_protent; + +#ifdef __cplusplus +} +#endif + +#endif /* PPP_EAP_H */ + +#endif /* PPP_SUPPORT && EAP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ecp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ecp.h new file mode 100644 index 000000000..d8808c3ab --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ecp.h @@ -0,0 +1,62 @@ +/* + * ecp.h - Definitions for PPP Encryption Control Protocol. + * + * Copyright (c) 2002 Google, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: ecp.h,v 1.2 2003/01/10 07:12:36 fcusack Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef ECP_H +#define ECP_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ecp_options { + bool required; /* Is ECP required? */ + unsigned enctype; /* Encryption type */ +} ecp_options; + +extern fsm ecp_fsm[]; +extern ecp_options ecp_wantoptions[]; +extern ecp_options ecp_gotoptions[]; +extern ecp_options ecp_allowoptions[]; +extern ecp_options ecp_hisoptions[]; + +extern const struct protent ecp_protent; + +#ifdef __cplusplus +} +#endif + +#endif /* ECP_H */ +#endif /* PPP_SUPPORT && ECP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/eui64.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/eui64.h new file mode 100644 index 000000000..5adeb482a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/eui64.h @@ -0,0 +1,102 @@ +/* + * eui64.h - EUI64 routines for IPv6CP. + * + * Copyright (c) 1999 Tommi Komulainen. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Tommi Komulainen + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: eui64.h,v 1.6 2002/12/04 23:03:32 paulus Exp $ +*/ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef EUI64_H +#define EUI64_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * @todo: + * + * Maybe this should be done by processing struct in6_addr directly... + */ +typedef union +{ + u8_t e8[8]; + u16_t e16[4]; + u32_t e32[2]; +} eui64_t; + +#define eui64_iszero(e) (((e).e32[0] | (e).e32[1]) == 0) +#define eui64_equals(e, o) (((e).e32[0] == (o).e32[0]) && \ + ((e).e32[1] == (o).e32[1])) +#define eui64_zero(e) (e).e32[0] = (e).e32[1] = 0; + +#define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t)) + +#define eui64_magic(e) do { \ + (e).e32[0] = magic(); \ + (e).e32[1] = magic(); \ + (e).e8[0] &= ~2; \ + } while (0) +#define eui64_magic_nz(x) do { \ + eui64_magic(x); \ + } while (eui64_iszero(x)) +#define eui64_magic_ne(x, y) do { \ + eui64_magic(x); \ + } while (eui64_equals(x, y)) + +#define eui64_get(ll, cp) do { \ + eui64_copy((*cp), (ll)); \ + (cp) += sizeof(eui64_t); \ + } while (0) + +#define eui64_put(ll, cp) do { \ + eui64_copy((ll), (*cp)); \ + (cp) += sizeof(eui64_t); \ + } while (0) + +#define eui64_set32(e, l) do { \ + (e).e32[0] = 0; \ + (e).e32[1] = lwip_htonl(l); \ + } while (0) +#define eui64_setlo32(e, l) eui64_set32(e, l) + +char *eui64_ntoa(eui64_t); /* Returns ascii representation of id */ + +#ifdef __cplusplus +} +#endif + +#endif /* EUI64_H */ +#endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/fsm.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/fsm.h new file mode 100644 index 000000000..8dec700e0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/fsm.h @@ -0,0 +1,182 @@ +/* + * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef FSM_H +#define FSM_H + +#include "ppp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Packet header = Code, id, length. + */ +#define HEADERLEN 4 + + +/* + * CP (LCP, IPCP, etc.) codes. + */ +#define CONFREQ 1 /* Configuration Request */ +#define CONFACK 2 /* Configuration Ack */ +#define CONFNAK 3 /* Configuration Nak */ +#define CONFREJ 4 /* Configuration Reject */ +#define TERMREQ 5 /* Termination Request */ +#define TERMACK 6 /* Termination Ack */ +#define CODEREJ 7 /* Code Reject */ + + +/* + * Each FSM is described by an fsm structure and fsm callbacks. + */ +typedef struct fsm { + ppp_pcb *pcb; /* PPP Interface */ + const struct fsm_callbacks *callbacks; /* Callback routines */ + const char *term_reason; /* Reason for closing protocol */ + u8_t seen_ack; /* Have received valid Ack/Nak/Rej to Req */ + /* -- This is our only flag, we might use u_int :1 if we have more flags */ + u16_t protocol; /* Data Link Layer Protocol field value */ + u8_t state; /* State */ + u8_t flags; /* Contains option bits */ + u8_t id; /* Current id */ + u8_t reqid; /* Current request id */ + u8_t retransmits; /* Number of retransmissions left */ + u8_t nakloops; /* Number of nak loops since last ack */ + u8_t rnakloops; /* Number of naks received */ + u8_t maxnakloops; /* Maximum number of nak loops tolerated + (necessary because IPCP require a custom large max nak loops value) */ + u8_t term_reason_len; /* Length of term_reason */ +} fsm; + + +typedef struct fsm_callbacks { + void (*resetci) /* Reset our Configuration Information */ + (fsm *); + int (*cilen) /* Length of our Configuration Information */ + (fsm *); + void (*addci) /* Add our Configuration Information */ + (fsm *, u_char *, int *); + int (*ackci) /* ACK our Configuration Information */ + (fsm *, u_char *, int); + int (*nakci) /* NAK our Configuration Information */ + (fsm *, u_char *, int, int); + int (*rejci) /* Reject our Configuration Information */ + (fsm *, u_char *, int); + int (*reqci) /* Request peer's Configuration Information */ + (fsm *, u_char *, int *, int); + void (*up) /* Called when fsm reaches PPP_FSM_OPENED state */ + (fsm *); + void (*down) /* Called when fsm leaves PPP_FSM_OPENED state */ + (fsm *); + void (*starting) /* Called when we want the lower layer */ + (fsm *); + void (*finished) /* Called when we don't want the lower layer */ + (fsm *); + void (*protreject) /* Called when Protocol-Reject received */ + (int); + void (*retransmit) /* Retransmission is necessary */ + (fsm *); + int (*extcode) /* Called when unknown code received */ + (fsm *, int, int, u_char *, int); + const char *proto_name; /* String name for protocol (for messages) */ +} fsm_callbacks; + + +/* + * Link states. + */ +#define PPP_FSM_INITIAL 0 /* Down, hasn't been opened */ +#define PPP_FSM_STARTING 1 /* Down, been opened */ +#define PPP_FSM_CLOSED 2 /* Up, hasn't been opened */ +#define PPP_FSM_STOPPED 3 /* Open, waiting for down event */ +#define PPP_FSM_CLOSING 4 /* Terminating the connection, not open */ +#define PPP_FSM_STOPPING 5 /* Terminating, but open */ +#define PPP_FSM_REQSENT 6 /* We've sent a Config Request */ +#define PPP_FSM_ACKRCVD 7 /* We've received a Config Ack */ +#define PPP_FSM_ACKSENT 8 /* We've sent a Config Ack */ +#define PPP_FSM_OPENED 9 /* Connection available */ + + +/* + * Flags - indicate options controlling FSM operation + */ +#define OPT_PASSIVE 1 /* Don't die if we don't get a response */ +#define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ +#define OPT_SILENT 4 /* Wait for peer to speak first */ + + +/* + * Timeouts. + */ +#if 0 /* moved to ppp_opts.h */ +#define DEFTIMEOUT 3 /* Timeout time in seconds */ +#define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ +#define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ +#define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ +#endif /* moved to ppp_opts.h */ + + +/* + * Prototypes + */ +void fsm_init(fsm *f); +void fsm_lowerup(fsm *f); +void fsm_lowerdown(fsm *f); +void fsm_open(fsm *f); +void fsm_close(fsm *f, const char *reason); +void fsm_input(fsm *f, u_char *inpacket, int l); +void fsm_protreject(fsm *f); +void fsm_sdata(fsm *f, u_char code, u_char id, const u_char *data, int datalen); + +#ifdef __cplusplus +} +#endif + +#endif /* FSM_H */ +#endif /* PPP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ipcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ipcp.h new file mode 100644 index 000000000..32fdd1c64 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ipcp.h @@ -0,0 +1,134 @@ +/* + * ipcp.h - IP Control Protocol definitions. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: ipcp.h,v 1.14 2002/12/04 23:03:32 paulus Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && PPP_IPV4_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef IPCP_H +#define IPCP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Options. + */ +#define CI_ADDRS 1 /* IP Addresses */ +#if VJ_SUPPORT +#define CI_COMPRESSTYPE 2 /* Compression Type */ +#endif /* VJ_SUPPORT */ +#define CI_ADDR 3 + +#if LWIP_DNS +#define CI_MS_DNS1 129 /* Primary DNS value */ +#define CI_MS_DNS2 131 /* Secondary DNS value */ +#endif /* LWIP_DNS */ +#if 0 /* UNUSED - WINS */ +#define CI_MS_WINS1 130 /* Primary WINS value */ +#define CI_MS_WINS2 132 /* Secondary WINS value */ +#endif /* UNUSED - WINS */ + +#if VJ_SUPPORT +#define MAX_STATES 16 /* from slcompress.h */ + +#define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */ +#define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */ +#define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */ + /* maxslot and slot number compression) */ + +#define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/ +#define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */ + /* compression option*/ +#endif /* VJ_SUPPORT */ + +typedef struct ipcp_options { + unsigned int neg_addr :1; /* Negotiate IP Address? */ + unsigned int old_addrs :1; /* Use old (IP-Addresses) option? */ + unsigned int req_addr :1; /* Ask peer to send IP address? */ +#if 0 /* UNUSED */ + unsigned int default_route :1; /* Assign default route through interface? */ + unsigned int replace_default_route :1; /* Replace default route through interface? */ +#endif /* UNUSED */ +#if 0 /* UNUSED - PROXY ARP */ + unsigned int proxy_arp :1; /* Make proxy ARP entry for peer? */ +#endif /* UNUSED - PROXY ARP */ +#if VJ_SUPPORT + unsigned int neg_vj :1; /* Van Jacobson Compression? */ + unsigned int old_vj :1; /* use old (short) form of VJ option? */ + unsigned int cflag :1; +#endif /* VJ_SUPPORT */ + unsigned int accept_local :1; /* accept peer's value for ouraddr */ + unsigned int accept_remote :1; /* accept peer's value for hisaddr */ +#if LWIP_DNS + unsigned int req_dns1 :1; /* Ask peer to send primary DNS address? */ + unsigned int req_dns2 :1; /* Ask peer to send secondary DNS address? */ +#endif /* LWIP_DNS */ + + u32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */ +#if LWIP_DNS + u32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */ +#endif /* LWIP_DNS */ +#if 0 /* UNUSED - WINS */ + u32_t winsaddr[2]; /* Primary and secondary MS WINS entries */ +#endif /* UNUSED - WINS */ + +#if VJ_SUPPORT + u16_t vj_protocol; /* protocol value to use in VJ option */ + u8_t maxslotindex; /* values for RFC1332 VJ compression neg. */ +#endif /* VJ_SUPPORT */ +} ipcp_options; + +#if 0 /* UNUSED, already defined by lwIP */ +char *ip_ntoa (u32_t); +#endif /* UNUSED, already defined by lwIP */ + +extern const struct protent ipcp_protent; + +#ifdef __cplusplus +} +#endif + +#endif /* IPCP_H */ +#endif /* PPP_SUPPORT && PPP_IPV4_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ipv6cp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ipv6cp.h new file mode 100644 index 000000000..909997386 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ipv6cp.h @@ -0,0 +1,191 @@ +/* + * ipv6cp.h - PPP IPV6 Control Protocol. + * + * Copyright (c) 1999 Tommi Komulainen. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Tommi Komulainen + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +/* Original version, based on RFC2023 : + + Copyright (c) 1995, 1996, 1997 Francis.Dupont@inria.fr, INRIA Rocquencourt, + Alain.Durand@imag.fr, IMAG, + Jean-Luc.Richier@imag.fr, IMAG-LSR. + + Copyright (c) 1998, 1999 Francis.Dupont@inria.fr, GIE DYADE, + Alain.Durand@imag.fr, IMAG, + Jean-Luc.Richier@imag.fr, IMAG-LSR. + + Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt + Économique ayant pour membres BULL S.A. et l'INRIA). + + Ce logiciel informatique est disponible aux conditions + usuelles dans la recherche, c'est-à-dire qu'il peut + être utilisé, copié, modifié, distribué à l'unique + condition que ce texte soit conservé afin que + l'origine de ce logiciel soit reconnue. + + Le nom de l'Institut National de Recherche en Informatique + et en Automatique (INRIA), de l'IMAG, ou d'une personne morale + ou physique ayant participé à l'élaboration de ce logiciel ne peut + être utilisé sans son accord préalable explicite. + + Ce logiciel est fourni tel quel sans aucune garantie, + support ou responsabilité d'aucune sorte. + Ce logiciel est dérivé de sources d'origine + "University of California at Berkeley" et + "Digital Equipment Corporation" couvertes par des copyrights. + + L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG) + est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National + Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant + sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR). + + This work has been done in the context of GIE DYADE (joint R & D venture + between BULL S.A. and INRIA). + + This software is available with usual "research" terms + with the aim of retain credits of the software. + Permission to use, copy, modify and distribute this software for any + purpose and without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies, + and the name of INRIA, IMAG, or any contributor not be used in advertising + or publicity pertaining to this material without the prior explicit + permission. The software is provided "as is" without any + warranties, support or liabilities of any kind. + This software is derived from source code from + "University of California at Berkeley" and + "Digital Equipment Corporation" protected by copyrights. + + Grenoble's Institute of Computer Science and Applied Mathematics (IMAG) + is a federation of seven research units funded by the CNRS, National + Polytechnic Institute of Grenoble and University Joseph Fourier. + The research unit in Software, Systems, Networks (LSR) is member of IMAG. +*/ + +/* + * Derived from : + * + * + * ipcp.h - IP Control Protocol definitions. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: ipv6cp.h,v 1.7 2002/12/04 23:03:32 paulus Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef IPV6CP_H +#define IPV6CP_H + +#include "eui64.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Options. + */ +#define CI_IFACEID 1 /* Interface Identifier */ +#ifdef IPV6CP_COMP +#define CI_COMPRESSTYPE 2 /* Compression Type */ +#endif /* IPV6CP_COMP */ + +/* No compression types yet defined. + *#define IPV6CP_COMP 0x004f + */ +typedef struct ipv6cp_options { + unsigned int neg_ifaceid :1; /* Negotiate interface identifier? */ + unsigned int req_ifaceid :1; /* Ask peer to send interface identifier? */ + unsigned int accept_local :1; /* accept peer's value for iface id? */ + unsigned int opt_local :1; /* ourtoken set by option */ + unsigned int opt_remote :1; /* histoken set by option */ + unsigned int use_ip :1; /* use IP as interface identifier */ +#if 0 + unsigned int use_persistent :1; /* use uniquely persistent value for address */ +#endif +#ifdef IPV6CP_COMP + unsigned int neg_vj :1; /* Van Jacobson Compression? */ +#endif /* IPV6CP_COMP */ + +#ifdef IPV6CP_COMP + u_short vj_protocol; /* protocol value to use in VJ option */ +#endif /* IPV6CP_COMP */ + eui64_t ourid, hisid; /* Interface identifiers */ +} ipv6cp_options; + +extern const struct protent ipv6cp_protent; + +#ifdef __cplusplus +} +#endif + +#endif /* IPV6CP_H */ +#endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/lcp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/lcp.h new file mode 100644 index 000000000..18ad1cb23 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/lcp.h @@ -0,0 +1,179 @@ +/* + * lcp.h - Link Control Protocol definitions. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: lcp.h,v 1.20 2004/11/14 22:53:42 carlsonj Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef LCP_H +#define LCP_H + +#include "ppp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Options. + */ +#define CI_VENDOR 0 /* Vendor Specific */ +#define CI_MRU 1 /* Maximum Receive Unit */ +#define CI_ASYNCMAP 2 /* Async Control Character Map */ +#define CI_AUTHTYPE 3 /* Authentication Type */ +#define CI_QUALITY 4 /* Quality Protocol */ +#define CI_MAGICNUMBER 5 /* Magic Number */ +#define CI_PCOMPRESSION 7 /* Protocol Field Compression */ +#define CI_ACCOMPRESSION 8 /* Address/Control Field Compression */ +#define CI_FCSALTERN 9 /* FCS-Alternatives */ +#define CI_SDP 10 /* Self-Describing-Pad */ +#define CI_NUMBERED 11 /* Numbered-Mode */ +#define CI_CALLBACK 13 /* callback */ +#define CI_MRRU 17 /* max reconstructed receive unit; multilink */ +#define CI_SSNHF 18 /* short sequence numbers for multilink */ +#define CI_EPDISC 19 /* endpoint discriminator */ +#define CI_MPPLUS 22 /* Multi-Link-Plus-Procedure */ +#define CI_LDISC 23 /* Link-Discriminator */ +#define CI_LCPAUTH 24 /* LCP Authentication */ +#define CI_COBS 25 /* Consistent Overhead Byte Stuffing */ +#define CI_PREFELIS 26 /* Prefix Elision */ +#define CI_MPHDRFMT 27 /* MP Header Format */ +#define CI_I18N 28 /* Internationalization */ +#define CI_SDL 29 /* Simple Data Link */ + +/* + * LCP-specific packet types (code numbers). + */ +#define PROTREJ 8 /* Protocol Reject */ +#define ECHOREQ 9 /* Echo Request */ +#define ECHOREP 10 /* Echo Reply */ +#define DISCREQ 11 /* Discard Request */ +#define IDENTIF 12 /* Identification */ +#define TIMEREM 13 /* Time Remaining */ + +/* Value used as data for CI_CALLBACK option */ +#define CBCP_OPT 6 /* Use callback control protocol */ + +#if 0 /* moved to ppp_opts.h */ +#define DEFMRU 1500 /* Try for this */ +#define MINMRU 128 /* No MRUs below this */ +#define MAXMRU 16384 /* Normally limit MRU to this */ +#endif /* moved to ppp_opts.h */ + +/* An endpoint discriminator, used with multilink. */ +#define MAX_ENDP_LEN 20 /* maximum length of discriminator value */ +struct epdisc { + unsigned char class_; /* -- The word "class" is reserved in C++. */ + unsigned char length; + unsigned char value[MAX_ENDP_LEN]; +}; + +/* + * The state of options is described by an lcp_options structure. + */ +typedef struct lcp_options { + unsigned int passive :1; /* Don't die if we don't get a response */ + unsigned int silent :1; /* Wait for the other end to start first */ +#if 0 /* UNUSED */ + unsigned int restart :1; /* Restart vs. exit after close */ +#endif /* UNUSED */ + unsigned int neg_mru :1; /* Negotiate the MRU? */ + unsigned int neg_asyncmap :1; /* Negotiate the async map? */ +#if PAP_SUPPORT + unsigned int neg_upap :1; /* Ask for UPAP authentication? */ +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT + unsigned int neg_chap :1; /* Ask for CHAP authentication? */ +#endif /* CHAP_SUPPORT */ +#if EAP_SUPPORT + unsigned int neg_eap :1; /* Ask for EAP authentication? */ +#endif /* EAP_SUPPORT */ + unsigned int neg_magicnumber :1; /* Ask for magic number? */ + unsigned int neg_pcompression :1; /* HDLC Protocol Field Compression? */ + unsigned int neg_accompression :1; /* HDLC Address/Control Field Compression? */ +#if LQR_SUPPORT + unsigned int neg_lqr :1; /* Negotiate use of Link Quality Reports */ +#endif /* LQR_SUPPORT */ + unsigned int neg_cbcp :1; /* Negotiate use of CBCP */ +#ifdef HAVE_MULTILINK + unsigned int neg_mrru :1; /* negotiate multilink MRRU */ +#endif /* HAVE_MULTILINK */ + unsigned int neg_ssnhf :1; /* negotiate short sequence numbers */ + unsigned int neg_endpoint :1; /* negotiate endpoint discriminator */ + + u16_t mru; /* Value of MRU */ +#ifdef HAVE_MULTILINK + u16_t mrru; /* Value of MRRU, and multilink enable */ +#endif /* MULTILINK */ +#if CHAP_SUPPORT + u8_t chap_mdtype; /* which MD types (hashing algorithm) */ +#endif /* CHAP_SUPPORT */ + u32_t asyncmap; /* Value of async map */ + u32_t magicnumber; + u8_t numloops; /* Number of loops during magic number neg. */ +#if LQR_SUPPORT + u32_t lqr_period; /* Reporting period for LQR 1/100ths second */ +#endif /* LQR_SUPPORT */ + struct epdisc endpoint; /* endpoint discriminator */ +} lcp_options; + +void lcp_open(ppp_pcb *pcb); +void lcp_close(ppp_pcb *pcb, const char *reason); +void lcp_lowerup(ppp_pcb *pcb); +void lcp_lowerdown(ppp_pcb *pcb); +void lcp_sprotrej(ppp_pcb *pcb, u_char *p, int len); /* send protocol reject */ + +extern const struct protent lcp_protent; + +#if 0 /* moved to ppp_opts.h */ +/* Default number of times we receive our magic number from the peer + before deciding the link is looped-back. */ +#define DEFLOOPBACKFAIL 10 +#endif /* moved to ppp_opts.h */ + +#ifdef __cplusplus +} +#endif + +#endif /* LCP_H */ +#endif /* PPP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/magic.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/magic.h new file mode 100644 index 000000000..a165e18fa --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/magic.h @@ -0,0 +1,130 @@ +/* + * magic.h - PPP Magic Number definitions. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: magic.h,v 1.5 2003/06/11 23:56:26 paulus Exp $ + */ +/***************************************************************************** +* randm.h - Random number generator header file. +* +* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. +* Copyright (c) 1998 Global Election Systems Inc. +* +* The authors hereby grant permission to use, copy, modify, distribute, +* and license this software and its documentation for any purpose, provided +* that existing copyright notices are retained in all copies and that this +* notice and the following disclaimer are included verbatim in any +* distributions. No written agreement, license, or royalty fee is required +* for any of the authorized uses. +* +* THIS SOFTWARE IS PROVIDED BY THE 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 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. +* +****************************************************************************** +* REVISION HISTORY +* +* 03-01-01 Marc Boucher +* Ported to lwIP. +* 98-05-29 Guy Lancaster , Global Election Systems Inc. +* Extracted from avos. +*****************************************************************************/ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef MAGIC_H +#define MAGIC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*********************** +*** PUBLIC FUNCTIONS *** +***********************/ + +/* + * Initialize the random number generator. + */ +void magic_init(void); + +/* + * Randomize our random seed value. To be called for truely random events + * such as user operations and network traffic. + */ +void magic_randomize(void); + +/* + * Return a new random number. + */ +u32_t magic(void); /* Returns the next magic number */ + +/* + * Fill buffer with random bytes + * + * Use the random pool to generate random data. This degrades to pseudo + * random when used faster than randomness is supplied using magic_churnrand(). + * Thus it's important to make sure that the results of this are not + * published directly because one could predict the next result to at + * least some degree. Also, it's important to get a good seed before + * the first use. + */ +void magic_random_bytes(unsigned char *buf, u32_t buf_len); + +/* + * Return a new random number between 0 and (2^pow)-1 included. + */ +u32_t magic_pow(u8_t pow); + +#ifdef __cplusplus +} +#endif + +#endif /* MAGIC_H */ + +#endif /* PPP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/mppe.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/mppe.h new file mode 100644 index 000000000..5de112847 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/mppe.h @@ -0,0 +1,181 @@ +/* + * mppe.h - Definitions for MPPE + * + * Copyright (c) 2008 Paul Mackerras. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && MPPE_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef MPPE_H +#define MPPE_H + +#include "netif/ppp/pppcrypt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MPPE_PAD 4 /* MPPE growth per frame */ +#define MPPE_MAX_KEY_LEN 16 /* largest key length (128-bit) */ + +/* option bits for ccp_options.mppe */ +#define MPPE_OPT_40 0x01 /* 40 bit */ +#define MPPE_OPT_128 0x02 /* 128 bit */ +#define MPPE_OPT_STATEFUL 0x04 /* stateful mode */ +/* unsupported opts */ +#define MPPE_OPT_56 0x08 /* 56 bit */ +#define MPPE_OPT_MPPC 0x10 /* MPPC compression */ +#define MPPE_OPT_D 0x20 /* Unknown */ +#define MPPE_OPT_UNSUPPORTED (MPPE_OPT_56|MPPE_OPT_MPPC|MPPE_OPT_D) +#define MPPE_OPT_UNKNOWN 0x40 /* Bits !defined in RFC 3078 were set */ + +/* + * This is not nice ... the alternative is a bitfield struct though. + * And unfortunately, we cannot share the same bits for the option + * names above since C and H are the same bit. We could do a u_int32 + * but then we have to do a lwip_htonl() all the time and/or we still need + * to know which octet is which. + */ +#define MPPE_C_BIT 0x01 /* MPPC */ +#define MPPE_D_BIT 0x10 /* Obsolete, usage unknown */ +#define MPPE_L_BIT 0x20 /* 40-bit */ +#define MPPE_S_BIT 0x40 /* 128-bit */ +#define MPPE_M_BIT 0x80 /* 56-bit, not supported */ +#define MPPE_H_BIT 0x01 /* Stateless (in a different byte) */ + +/* Does not include H bit; used for least significant octet only. */ +#define MPPE_ALL_BITS (MPPE_D_BIT|MPPE_L_BIT|MPPE_S_BIT|MPPE_M_BIT|MPPE_H_BIT) + +/* Build a CI from mppe opts (see RFC 3078) */ +#define MPPE_OPTS_TO_CI(opts, ci) \ + do { \ + u_char *ptr = ci; /* u_char[4] */ \ + \ + /* H bit */ \ + if (opts & MPPE_OPT_STATEFUL) \ + *ptr++ = 0x0; \ + else \ + *ptr++ = MPPE_H_BIT; \ + *ptr++ = 0; \ + *ptr++ = 0; \ + \ + /* S,L bits */ \ + *ptr = 0; \ + if (opts & MPPE_OPT_128) \ + *ptr |= MPPE_S_BIT; \ + if (opts & MPPE_OPT_40) \ + *ptr |= MPPE_L_BIT; \ + /* M,D,C bits not supported */ \ + } while (/* CONSTCOND */ 0) + +/* The reverse of the above */ +#define MPPE_CI_TO_OPTS(ci, opts) \ + do { \ + const u_char *ptr = ci; /* u_char[4] */ \ + \ + opts = 0; \ + \ + /* H bit */ \ + if (!(ptr[0] & MPPE_H_BIT)) \ + opts |= MPPE_OPT_STATEFUL; \ + \ + /* S,L bits */ \ + if (ptr[3] & MPPE_S_BIT) \ + opts |= MPPE_OPT_128; \ + if (ptr[3] & MPPE_L_BIT) \ + opts |= MPPE_OPT_40; \ + \ + /* M,D,C bits */ \ + if (ptr[3] & MPPE_M_BIT) \ + opts |= MPPE_OPT_56; \ + if (ptr[3] & MPPE_D_BIT) \ + opts |= MPPE_OPT_D; \ + if (ptr[3] & MPPE_C_BIT) \ + opts |= MPPE_OPT_MPPC; \ + \ + /* Other bits */ \ + if (ptr[0] & ~MPPE_H_BIT) \ + opts |= MPPE_OPT_UNKNOWN; \ + if (ptr[1] || ptr[2]) \ + opts |= MPPE_OPT_UNKNOWN; \ + if (ptr[3] & ~MPPE_ALL_BITS) \ + opts |= MPPE_OPT_UNKNOWN; \ + } while (/* CONSTCOND */ 0) + +/* Shared MPPE padding between MSCHAP and MPPE */ +#define SHA1_PAD_SIZE 40 + +static const u8_t mppe_sha1_pad1[SHA1_PAD_SIZE] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +static const u8_t mppe_sha1_pad2[SHA1_PAD_SIZE] = { + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, + 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2 +}; + +/* + * State for an MPPE (de)compressor. + */ +typedef struct ppp_mppe_state { + lwip_arc4_context arc4; + u8_t master_key[MPPE_MAX_KEY_LEN]; + u8_t session_key[MPPE_MAX_KEY_LEN]; + u8_t keylen; /* key length in bytes */ + /* NB: 128-bit == 16, 40-bit == 8! + * If we want to support 56-bit, the unit has to change to bits + */ + u8_t bits; /* MPPE control bits */ + u16_t ccount; /* 12-bit coherency count (seqno) */ + u16_t sanity_errors; /* take down LCP if too many */ + unsigned int stateful :1; /* stateful mode flag */ + unsigned int discard :1; /* stateful mode packet loss flag */ +} ppp_mppe_state; + +void mppe_set_key(ppp_pcb *pcb, ppp_mppe_state *state, u8_t *key); +void mppe_init(ppp_pcb *pcb, ppp_mppe_state *state, u8_t options); +void mppe_comp_reset(ppp_pcb *pcb, ppp_mppe_state *state); +err_t mppe_compress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb, u16_t protocol); +void mppe_decomp_reset(ppp_pcb *pcb, ppp_mppe_state *state); +err_t mppe_decompress(ppp_pcb *pcb, ppp_mppe_state *state, struct pbuf **pb); + +#ifdef __cplusplus +} +#endif + +#endif /* MPPE_H */ +#endif /* PPP_SUPPORT && MPPE_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/arc4.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/arc4.h new file mode 100644 index 000000000..4af724cd9 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/arc4.h @@ -0,0 +1,81 @@ +/** + * \file arc4.h + * + * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine + * + * Copyright (C) 2009 Paul Bakker + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the names of PolarSSL or XySSL 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 + * OWNER 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 "netif/ppp/ppp_opts.h" +#if LWIP_INCLUDED_POLARSSL_ARC4 + +#ifndef LWIP_INCLUDED_POLARSSL_ARC4_H +#define LWIP_INCLUDED_POLARSSL_ARC4_H + +/** + * \brief ARC4 context structure + */ +typedef struct +{ + int x; /*!< permutation index */ + int y; /*!< permutation index */ + unsigned char m[256]; /*!< permutation table */ +} +arc4_context; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief ARC4 key schedule + * + * \param ctx ARC4 context to be initialized + * \param key the secret key + * \param keylen length of the key + */ +void arc4_setup( arc4_context *ctx, unsigned char *key, int keylen ); + +/** + * \brief ARC4 cipher function + * + * \param ctx ARC4 context + * \param buf buffer to be processed + * \param buflen amount of data in buf + */ +void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen ); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_INCLUDED_POLARSSL_ARC4_H */ + +#endif /* LWIP_INCLUDED_POLARSSL_ARC4 */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/des.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/des.h new file mode 100644 index 000000000..e893890ed --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/des.h @@ -0,0 +1,92 @@ +/** + * \file des.h + * + * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine + * + * Copyright (C) 2009 Paul Bakker + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the names of PolarSSL or XySSL 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 + * OWNER 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 "netif/ppp/ppp_opts.h" +#if LWIP_INCLUDED_POLARSSL_DES + +#ifndef LWIP_INCLUDED_POLARSSL_DES_H +#define LWIP_INCLUDED_POLARSSL_DES_H + +#define DES_ENCRYPT 1 +#define DES_DECRYPT 0 + +/** + * \brief DES context structure + */ +typedef struct +{ + int mode; /*!< encrypt/decrypt */ + unsigned long sk[32]; /*!< DES subkeys */ +} +des_context; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief DES key schedule (56-bit, encryption) + * + * \param ctx DES context to be initialized + * \param key 8-byte secret key + */ +void des_setkey_enc( des_context *ctx, unsigned char key[8] ); + +/** + * \brief DES key schedule (56-bit, decryption) + * + * \param ctx DES context to be initialized + * \param key 8-byte secret key + */ +void des_setkey_dec( des_context *ctx, unsigned char key[8] ); + +/** + * \brief DES-ECB block encryption/decryption + * + * \param ctx DES context + * \param input 64-bit input block + * \param output 64-bit output block + */ +void des_crypt_ecb( des_context *ctx, + const unsigned char input[8], + unsigned char output[8] ); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_INCLUDED_POLARSSL_DES_H */ + +#endif /* LWIP_INCLUDED_POLARSSL_DES */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/md4.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/md4.h new file mode 100644 index 000000000..570445687 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/md4.h @@ -0,0 +1,97 @@ +/** + * \file md4.h + * + * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine + * + * Copyright (C) 2009 Paul Bakker + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the names of PolarSSL or XySSL 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 + * OWNER 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 "netif/ppp/ppp_opts.h" +#if LWIP_INCLUDED_POLARSSL_MD4 + +#ifndef LWIP_INCLUDED_POLARSSL_MD4_H +#define LWIP_INCLUDED_POLARSSL_MD4_H + +/** + * \brief MD4 context structure + */ +typedef struct +{ + unsigned long total[2]; /*!< number of bytes processed */ + unsigned long state[4]; /*!< intermediate digest state */ + unsigned char buffer[64]; /*!< data block being processed */ +} +md4_context; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief MD4 context setup + * + * \param ctx context to be initialized + */ +void md4_starts( md4_context *ctx ); + +/** + * \brief MD4 process buffer + * + * \param ctx MD4 context + * \param input buffer holding the data + * \param ilen length of the input data + */ +void md4_update( md4_context *ctx, const unsigned char *input, int ilen ); + +/** + * \brief MD4 final digest + * + * \param ctx MD4 context + * \param output MD4 checksum result + */ +void md4_finish( md4_context *ctx, unsigned char output[16] ); + +/** + * \brief Output = MD4( input buffer ) + * + * \param input buffer holding the data + * \param ilen length of the input data + * \param output MD4 checksum result + */ +void md4( unsigned char *input, int ilen, unsigned char output[16] ); + + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_INCLUDED_POLARSSL_MD4_H */ + +#endif /* LWIP_INCLUDED_POLARSSL_MD4 */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/md5.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/md5.h new file mode 100644 index 000000000..124401189 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/md5.h @@ -0,0 +1,96 @@ +/** + * \file md5.h + * + * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine + * + * Copyright (C) 2009 Paul Bakker + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the names of PolarSSL or XySSL 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 + * OWNER 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 "netif/ppp/ppp_opts.h" +#if LWIP_INCLUDED_POLARSSL_MD5 + +#ifndef LWIP_INCLUDED_POLARSSL_MD5_H +#define LWIP_INCLUDED_POLARSSL_MD5_H + +/** + * \brief MD5 context structure + */ +typedef struct +{ + unsigned long total[2]; /*!< number of bytes processed */ + unsigned long state[4]; /*!< intermediate digest state */ + unsigned char buffer[64]; /*!< data block being processed */ +} +md5_context; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief MD5 context setup + * + * \param ctx context to be initialized + */ +void md5_starts( md5_context *ctx ); + +/** + * \brief MD5 process buffer + * + * \param ctx MD5 context + * \param input buffer holding the data + * \param ilen length of the input data + */ +void md5_update( md5_context *ctx, const unsigned char *input, int ilen ); + +/** + * \brief MD5 final digest + * + * \param ctx MD5 context + * \param output MD5 checksum result + */ +void md5_finish( md5_context *ctx, unsigned char output[16] ); + +/** + * \brief Output = MD5( input buffer ) + * + * \param input buffer holding the data + * \param ilen length of the input data + * \param output MD5 checksum result + */ +void md5( unsigned char *input, int ilen, unsigned char output[16] ); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_INCLUDED_POLARSSL_MD5_H */ + +#endif /* LWIP_INCLUDED_POLARSSL_MD5 */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/sha1.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/sha1.h new file mode 100644 index 000000000..a4c53e07c --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/polarssl/sha1.h @@ -0,0 +1,96 @@ +/** + * \file sha1.h + * + * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine + * + * Copyright (C) 2009 Paul Bakker + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the names of PolarSSL or XySSL 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 + * OWNER 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 "netif/ppp/ppp_opts.h" +#if LWIP_INCLUDED_POLARSSL_SHA1 + +#ifndef LWIP_INCLUDED_POLARSSL_SHA1_H +#define LWIP_INCLUDED_POLARSSL_SHA1_H + +/** + * \brief SHA-1 context structure + */ +typedef struct +{ + unsigned long total[2]; /*!< number of bytes processed */ + unsigned long state[5]; /*!< intermediate digest state */ + unsigned char buffer[64]; /*!< data block being processed */ +} +sha1_context; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief SHA-1 context setup + * + * \param ctx context to be initialized + */ +void sha1_starts( sha1_context *ctx ); + +/** + * \brief SHA-1 process buffer + * + * \param ctx SHA-1 context + * \param input buffer holding the data + * \param ilen length of the input data + */ +void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ); + +/** + * \brief SHA-1 final digest + * + * \param ctx SHA-1 context + * \param output SHA-1 checksum result + */ +void sha1_finish( sha1_context *ctx, unsigned char output[20] ); + +/** + * \brief Output = SHA-1( input buffer ) + * + * \param input buffer holding the data + * \param ilen length of the input data + * \param output SHA-1 checksum result + */ +void sha1( unsigned char *input, int ilen, unsigned char output[20] ); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_INCLUDED_POLARSSL_SHA1_H */ + +#endif /* LWIP_INCLUDED_POLARSSL_SHA1 */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp.h new file mode 100644 index 000000000..3d73c3657 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp.h @@ -0,0 +1,698 @@ +/***************************************************************************** +* ppp.h - Network Point to Point Protocol header file. +* +* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. +* portions Copyright (c) 1997 Global Election Systems Inc. +* +* The authors hereby grant permission to use, copy, modify, distribute, +* and license this software and its documentation for any purpose, provided +* that existing copyright notices are retained in all copies and that this +* notice and the following disclaimer are included verbatim in any +* distributions. No written agreement, license, or royalty fee is required +* for any of the authorized uses. +* +* THIS SOFTWARE IS PROVIDED BY THE 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 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. +* +****************************************************************************** +* REVISION HISTORY +* +* 03-01-01 Marc Boucher +* Ported to lwIP. +* 97-11-05 Guy Lancaster , Global Election Systems Inc. +* Original derived from BSD codes. +*****************************************************************************/ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef PPP_H +#define PPP_H + +#include "lwip/def.h" +#include "lwip/stats.h" +#include "lwip/mem.h" +#include "lwip/netif.h" +#include "lwip/sys.h" +#include "lwip/timeouts.h" +#if PPP_IPV6_SUPPORT +#include "lwip/ip6_addr.h" +#endif /* PPP_IPV6_SUPPORT */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Disable non-working or rarely used PPP feature, so rarely that we don't want to bloat ppp_opts.h with them */ +#ifndef PPP_OPTIONS +#define PPP_OPTIONS 0 +#endif + +#ifndef PPP_NOTIFY +#define PPP_NOTIFY 0 +#endif + +#ifndef PPP_REMOTENAME +#define PPP_REMOTENAME 0 +#endif + +#ifndef PPP_IDLETIMELIMIT +#define PPP_IDLETIMELIMIT 0 +#endif + +#ifndef PPP_LCP_ADAPTIVE +#define PPP_LCP_ADAPTIVE 0 +#endif + +#ifndef PPP_MAXCONNECT +#define PPP_MAXCONNECT 0 +#endif + +#ifndef PPP_ALLOWED_ADDRS +#define PPP_ALLOWED_ADDRS 0 +#endif + +#ifndef PPP_PROTOCOLNAME +#define PPP_PROTOCOLNAME 0 +#endif + +#ifndef PPP_STATS_SUPPORT +#define PPP_STATS_SUPPORT 0 +#endif + +#ifndef DEFLATE_SUPPORT +#define DEFLATE_SUPPORT 0 +#endif + +#ifndef BSDCOMPRESS_SUPPORT +#define BSDCOMPRESS_SUPPORT 0 +#endif + +#ifndef PREDICTOR_SUPPORT +#define PREDICTOR_SUPPORT 0 +#endif + +/************************* +*** PUBLIC DEFINITIONS *** +*************************/ + +/* + * The basic PPP frame. + */ +#define PPP_HDRLEN 4 /* octets for standard ppp header */ +#define PPP_FCSLEN 2 /* octets for FCS */ + +/* + * Values for phase. + */ +#define PPP_PHASE_DEAD 0 +#define PPP_PHASE_MASTER 1 +#define PPP_PHASE_HOLDOFF 2 +#define PPP_PHASE_INITIALIZE 3 +#define PPP_PHASE_SERIALCONN 4 +#define PPP_PHASE_DORMANT 5 +#define PPP_PHASE_ESTABLISH 6 +#define PPP_PHASE_AUTHENTICATE 7 +#define PPP_PHASE_CALLBACK 8 +#define PPP_PHASE_NETWORK 9 +#define PPP_PHASE_RUNNING 10 +#define PPP_PHASE_TERMINATE 11 +#define PPP_PHASE_DISCONNECT 12 + +/* Error codes. */ +#define PPPERR_NONE 0 /* No error. */ +#define PPPERR_PARAM 1 /* Invalid parameter. */ +#define PPPERR_OPEN 2 /* Unable to open PPP session. */ +#define PPPERR_DEVICE 3 /* Invalid I/O device for PPP. */ +#define PPPERR_ALLOC 4 /* Unable to allocate resources. */ +#define PPPERR_USER 5 /* User interrupt. */ +#define PPPERR_CONNECT 6 /* Connection lost. */ +#define PPPERR_AUTHFAIL 7 /* Failed authentication challenge. */ +#define PPPERR_PROTOCOL 8 /* Failed to meet protocol. */ +#define PPPERR_PEERDEAD 9 /* Connection timeout */ +#define PPPERR_IDLETIMEOUT 10 /* Idle Timeout */ +#define PPPERR_CONNECTTIME 11 /* Max connect time reached */ +#define PPPERR_LOOPBACK 12 /* Loopback detected */ + +/* Whether auth support is enabled at all */ +#define PPP_AUTH_SUPPORT (PAP_SUPPORT || CHAP_SUPPORT || EAP_SUPPORT) + +/************************ +*** PUBLIC DATA TYPES *** +************************/ + +/* + * Other headers require ppp_pcb definition for prototypes, but ppp_pcb + * require some structure definition from other headers as well, we are + * fixing the dependency loop here by declaring the ppp_pcb type then + * by including headers containing necessary struct definition for ppp_pcb + */ +typedef struct ppp_pcb_s ppp_pcb; + +/* Type definitions for BSD code. */ +#ifndef __u_char_defined +typedef unsigned long u_long; +typedef unsigned int u_int; +typedef unsigned short u_short; +typedef unsigned char u_char; +#endif + +#include "fsm.h" +#include "lcp.h" +#if CCP_SUPPORT +#include "ccp.h" +#endif /* CCP_SUPPORT */ +#if MPPE_SUPPORT +#include "mppe.h" +#endif /* MPPE_SUPPORT */ +#if PPP_IPV4_SUPPORT +#include "ipcp.h" +#endif /* PPP_IPV4_SUPPORT */ +#if PPP_IPV6_SUPPORT +#include "ipv6cp.h" +#endif /* PPP_IPV6_SUPPORT */ +#if PAP_SUPPORT +#include "upap.h" +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT +#include "chap-new.h" +#endif /* CHAP_SUPPORT */ +#if EAP_SUPPORT +#include "eap.h" +#endif /* EAP_SUPPORT */ +#if VJ_SUPPORT +#include "vj.h" +#endif /* VJ_SUPPORT */ + +/* Link status callback function prototype */ +typedef void (*ppp_link_status_cb_fn)(ppp_pcb *pcb, int err_code, void *ctx); + +/* + * PPP configuration. + */ +typedef struct ppp_settings_s { + +#if PPP_SERVER && PPP_AUTH_SUPPORT + unsigned int auth_required :1; /* Peer is required to authenticate */ + unsigned int null_login :1; /* Username of "" and a password of "" are acceptable */ +#endif /* PPP_SERVER && PPP_AUTH_SUPPORT */ +#if PPP_REMOTENAME + unsigned int explicit_remote :1; /* remote_name specified with remotename opt */ +#endif /* PPP_REMOTENAME */ +#if PAP_SUPPORT + unsigned int refuse_pap :1; /* Don't proceed auth. with PAP */ +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT + unsigned int refuse_chap :1; /* Don't proceed auth. with CHAP */ +#endif /* CHAP_SUPPORT */ +#if MSCHAP_SUPPORT + unsigned int refuse_mschap :1; /* Don't proceed auth. with MS-CHAP */ + unsigned int refuse_mschap_v2 :1; /* Don't proceed auth. with MS-CHAPv2 */ +#endif /* MSCHAP_SUPPORT */ +#if EAP_SUPPORT + unsigned int refuse_eap :1; /* Don't proceed auth. with EAP */ +#endif /* EAP_SUPPORT */ +#if LWIP_DNS + unsigned int usepeerdns :1; /* Ask peer for DNS adds */ +#endif /* LWIP_DNS */ + unsigned int persist :1; /* Persist mode, always try to open the connection */ +#if PRINTPKT_SUPPORT + unsigned int hide_password :1; /* Hide password in dumped packets */ +#endif /* PRINTPKT_SUPPORT */ + unsigned int noremoteip :1; /* Let him have no IP address */ + unsigned int lax_recv :1; /* accept control chars in asyncmap */ + unsigned int noendpoint :1; /* don't send/accept endpoint discriminator */ +#if PPP_LCP_ADAPTIVE + unsigned int lcp_echo_adaptive :1; /* request echo only if the link was idle */ +#endif /* PPP_LCP_ADAPTIVE */ +#if MPPE_SUPPORT + unsigned int require_mppe :1; /* Require MPPE (Microsoft Point to Point Encryption) */ + unsigned int refuse_mppe_40 :1; /* Allow MPPE 40-bit mode? */ + unsigned int refuse_mppe_128 :1; /* Allow MPPE 128-bit mode? */ + unsigned int refuse_mppe_stateful :1; /* Allow MPPE stateful mode? */ +#endif /* MPPE_SUPPORT */ + + u16_t listen_time; /* time to listen first (ms), waiting for peer to send LCP packet */ + +#if PPP_IDLETIMELIMIT + u16_t idle_time_limit; /* Disconnect if idle for this many seconds */ +#endif /* PPP_IDLETIMELIMIT */ +#if PPP_MAXCONNECT + u32_t maxconnect; /* Maximum connect time (seconds) */ +#endif /* PPP_MAXCONNECT */ + +#if PPP_AUTH_SUPPORT + /* auth data */ + const char *user; /* Username for PAP */ + const char *passwd; /* Password for PAP, secret for CHAP */ +#if PPP_REMOTENAME + char remote_name[MAXNAMELEN + 1]; /* Peer's name for authentication */ +#endif /* PPP_REMOTENAME */ + +#if PAP_SUPPORT + u8_t pap_timeout_time; /* Timeout (seconds) for auth-req retrans. */ + u8_t pap_max_transmits; /* Number of auth-reqs sent */ +#if PPP_SERVER + u8_t pap_req_timeout; /* Time to wait for auth-req from peer */ +#endif /* PPP_SERVER */ +#endif /* PAP_SUPPPORT */ + +#if CHAP_SUPPORT + u8_t chap_timeout_time; /* Timeout (seconds) for retransmitting req */ + u8_t chap_max_transmits; /* max # times to send challenge */ +#if PPP_SERVER + u8_t chap_rechallenge_time; /* Time to wait for auth-req from peer */ +#endif /* PPP_SERVER */ +#endif /* CHAP_SUPPPORT */ + +#if EAP_SUPPORT + u8_t eap_req_time; /* Time to wait (for retransmit/fail) */ + u8_t eap_allow_req; /* Max Requests allowed */ +#if PPP_SERVER + u8_t eap_timeout_time; /* Time to wait (for retransmit/fail) */ + u8_t eap_max_transmits; /* Max Requests allowed */ +#endif /* PPP_SERVER */ +#endif /* EAP_SUPPORT */ + +#endif /* PPP_AUTH_SUPPORT */ + + u8_t fsm_timeout_time; /* Timeout time in seconds */ + u8_t fsm_max_conf_req_transmits; /* Maximum Configure-Request transmissions */ + u8_t fsm_max_term_transmits; /* Maximum Terminate-Request transmissions */ + u8_t fsm_max_nak_loops; /* Maximum number of nak loops tolerated */ + + u8_t lcp_loopbackfail; /* Number of times we receive our magic number from the peer + before deciding the link is looped-back. */ + u8_t lcp_echo_interval; /* Interval between LCP echo-requests */ + u8_t lcp_echo_fails; /* Tolerance to unanswered echo-requests */ + +} ppp_settings; + +#if PPP_SERVER +struct ppp_addrs { +#if PPP_IPV4_SUPPORT + ip4_addr_t our_ipaddr, his_ipaddr, netmask; +#if LWIP_DNS + ip4_addr_t dns1, dns2; +#endif /* LWIP_DNS */ +#endif /* PPP_IPV4_SUPPORT */ +#if PPP_IPV6_SUPPORT + ip6_addr_t our6_ipaddr, his6_ipaddr; +#endif /* PPP_IPV6_SUPPORT */ +}; +#endif /* PPP_SERVER */ + +/* + * PPP interface control block. + */ +struct ppp_pcb_s { + ppp_settings settings; + const struct link_callbacks *link_cb; + void *link_ctx_cb; + void (*link_status_cb)(ppp_pcb *pcb, int err_code, void *ctx); /* Status change callback */ +#if PPP_NOTIFY_PHASE + void (*notify_phase_cb)(ppp_pcb *pcb, u8_t phase, void *ctx); /* Notify phase callback */ +#endif /* PPP_NOTIFY_PHASE */ + void *ctx_cb; /* Callbacks optional pointer */ + struct netif *netif; /* PPP interface */ + u8_t phase; /* where the link is at */ + u8_t err_code; /* Code indicating why interface is down. */ + + /* flags */ +#if PPP_IPV4_SUPPORT + unsigned int ask_for_local :1; /* request our address from peer */ + unsigned int ipcp_is_open :1; /* haven't called np_finished() */ + unsigned int ipcp_is_up :1; /* have called ipcp_up() */ + unsigned int if4_up :1; /* True when the IPv4 interface is up. */ +#if 0 /* UNUSED - PROXY ARP */ + unsigned int proxy_arp_set :1; /* Have created proxy arp entry */ +#endif /* UNUSED - PROXY ARP */ +#endif /* PPP_IPV4_SUPPORT */ +#if PPP_IPV6_SUPPORT + unsigned int ipv6cp_is_up :1; /* have called ip6cp_up() */ + unsigned int if6_up :1; /* True when the IPv6 interface is up. */ +#endif /* PPP_IPV6_SUPPORT */ + unsigned int lcp_echo_timer_running :1; /* set if a timer is running */ +#if VJ_SUPPORT + unsigned int vj_enabled :1; /* Flag indicating VJ compression enabled. */ +#endif /* VJ_SUPPORT */ +#if CCP_SUPPORT + unsigned int ccp_all_rejected :1; /* we rejected all peer's options */ +#endif /* CCP_SUPPORT */ +#if MPPE_SUPPORT + unsigned int mppe_keys_set :1; /* Have the MPPE keys been set? */ +#endif /* MPPE_SUPPORT */ + +#if PPP_AUTH_SUPPORT + /* auth data */ +#if PPP_SERVER && defined(HAVE_MULTILINK) + char peer_authname[MAXNAMELEN + 1]; /* The name by which the peer authenticated itself to us. */ +#endif /* PPP_SERVER && defined(HAVE_MULTILINK) */ + u16_t auth_pending; /* Records which authentication operations haven't completed yet. */ + u16_t auth_done; /* Records which authentication operations have been completed. */ + +#if PAP_SUPPORT + upap_state upap; /* PAP data */ +#endif /* PAP_SUPPORT */ + +#if CHAP_SUPPORT + chap_client_state chap_client; /* CHAP client data */ +#if PPP_SERVER + chap_server_state chap_server; /* CHAP server data */ +#endif /* PPP_SERVER */ +#endif /* CHAP_SUPPORT */ + +#if EAP_SUPPORT + eap_state eap; /* EAP data */ +#endif /* EAP_SUPPORT */ +#endif /* PPP_AUTH_SUPPORT */ + + fsm lcp_fsm; /* LCP fsm structure */ + lcp_options lcp_wantoptions; /* Options that we want to request */ + lcp_options lcp_gotoptions; /* Options that peer ack'd */ + lcp_options lcp_allowoptions; /* Options we allow peer to request */ + lcp_options lcp_hisoptions; /* Options that we ack'd */ + u16_t peer_mru; /* currently negotiated peer MRU */ + u8_t lcp_echos_pending; /* Number of outstanding echo msgs */ + u8_t lcp_echo_number; /* ID number of next echo frame */ + + u8_t num_np_open; /* Number of network protocols which we have opened. */ + u8_t num_np_up; /* Number of network protocols which have come up. */ + +#if VJ_SUPPORT + struct vjcompress vj_comp; /* Van Jacobson compression header. */ +#endif /* VJ_SUPPORT */ + +#if CCP_SUPPORT + fsm ccp_fsm; /* CCP fsm structure */ + ccp_options ccp_wantoptions; /* what to request the peer to use */ + ccp_options ccp_gotoptions; /* what the peer agreed to do */ + ccp_options ccp_allowoptions; /* what we'll agree to do */ + ccp_options ccp_hisoptions; /* what we agreed to do */ + u8_t ccp_localstate; /* Local state (mainly for handling reset-reqs and reset-acks). */ + u8_t ccp_receive_method; /* Method chosen on receive path */ + u8_t ccp_transmit_method; /* Method chosen on transmit path */ +#if MPPE_SUPPORT + ppp_mppe_state mppe_comp; /* MPPE "compressor" structure */ + ppp_mppe_state mppe_decomp; /* MPPE "decompressor" structure */ +#endif /* MPPE_SUPPORT */ +#endif /* CCP_SUPPORT */ + +#if PPP_IPV4_SUPPORT + fsm ipcp_fsm; /* IPCP fsm structure */ + ipcp_options ipcp_wantoptions; /* Options that we want to request */ + ipcp_options ipcp_gotoptions; /* Options that peer ack'd */ + ipcp_options ipcp_allowoptions; /* Options we allow peer to request */ + ipcp_options ipcp_hisoptions; /* Options that we ack'd */ +#endif /* PPP_IPV4_SUPPORT */ + +#if PPP_IPV6_SUPPORT + fsm ipv6cp_fsm; /* IPV6CP fsm structure */ + ipv6cp_options ipv6cp_wantoptions; /* Options that we want to request */ + ipv6cp_options ipv6cp_gotoptions; /* Options that peer ack'd */ + ipv6cp_options ipv6cp_allowoptions; /* Options we allow peer to request */ + ipv6cp_options ipv6cp_hisoptions; /* Options that we ack'd */ +#endif /* PPP_IPV6_SUPPORT */ +}; + +/************************ + *** PUBLIC FUNCTIONS *** + ************************/ + +/* + * WARNING: For multi-threads environment, all ppp_set_* functions most + * only be called while the PPP is in the dead phase (i.e. disconnected). + */ + +#if PPP_AUTH_SUPPORT +/* + * Set PPP authentication. + * + * Warning: Using PPPAUTHTYPE_ANY might have security consequences. + * RFC 1994 says: + * + * In practice, within or associated with each PPP server, there is a + * database which associates "user" names with authentication + * information ("secrets"). It is not anticipated that a particular + * named user would be authenticated by multiple methods. This would + * make the user vulnerable to attacks which negotiate the least secure + * method from among a set (such as PAP rather than CHAP). If the same + * secret was used, PAP would reveal the secret to be used later with + * CHAP. + * + * Instead, for each user name there should be an indication of exactly + * one method used to authenticate that user name. If a user needs to + * make use of different authentication methods under different + * circumstances, then distinct user names SHOULD be employed, each of + * which identifies exactly one authentication method. + * + * Default is none auth type, unset (NULL) user and passwd. + */ +#define PPPAUTHTYPE_NONE 0x00 +#define PPPAUTHTYPE_PAP 0x01 +#define PPPAUTHTYPE_CHAP 0x02 +#define PPPAUTHTYPE_MSCHAP 0x04 +#define PPPAUTHTYPE_MSCHAP_V2 0x08 +#define PPPAUTHTYPE_EAP 0x10 +#define PPPAUTHTYPE_ANY 0xff +void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd); + +/* + * If set, peer is required to authenticate. This is mostly necessary for PPP server support. + * + * Default is false. + */ +#define ppp_set_auth_required(ppp, boolval) (ppp->settings.auth_required = boolval) +#endif /* PPP_AUTH_SUPPORT */ + +#if PPP_IPV4_SUPPORT +/* + * Set PPP interface "our" and "his" IPv4 addresses. This is mostly necessary for PPP server + * support but it can also be used on a PPP link where each side choose its own IP address. + * + * Default is unset (0.0.0.0). + */ +#define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \ + ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0) +#define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr)) +#if LWIP_DNS +/* + * Set DNS server addresses that are sent if the peer asks for them. This is mostly necessary + * for PPP server support. + * + * Default is unset (0.0.0.0). + */ +#define ppp_set_ipcp_dnsaddr(ppp, index, addr) (ppp->ipcp_allowoptions.dnsaddr[index] = ip4_addr_get_u32(addr)) + +/* + * If set, we ask the peer for up to 2 DNS server addresses. Received DNS server addresses are + * registered using the dns_setserver() function. + * + * Default is false. + */ +#define ppp_set_usepeerdns(ppp, boolval) (ppp->settings.usepeerdns = boolval) +#endif /* LWIP_DNS */ +#endif /* PPP_IPV4_SUPPORT */ + +#if MPPE_SUPPORT +/* Disable MPPE (Microsoft Point to Point Encryption). This parameter is exclusive. */ +#define PPP_MPPE_DISABLE 0x00 +/* Require the use of MPPE (Microsoft Point to Point Encryption). */ +#define PPP_MPPE_ENABLE 0x01 +/* Allow MPPE to use stateful mode. Stateless mode is still attempted first. */ +#define PPP_MPPE_ALLOW_STATEFUL 0x02 +/* Refuse the use of MPPE with 40-bit encryption. Conflict with PPP_MPPE_REFUSE_128. */ +#define PPP_MPPE_REFUSE_40 0x04 +/* Refuse the use of MPPE with 128-bit encryption. Conflict with PPP_MPPE_REFUSE_40. */ +#define PPP_MPPE_REFUSE_128 0x08 +/* + * Set MPPE configuration + * + * Default is disabled. + */ +void ppp_set_mppe(ppp_pcb *pcb, u8_t flags); +#endif /* MPPE_SUPPORT */ + +/* + * Wait for up to intval milliseconds for a valid PPP packet from the peer. + * At the end of this time, or when a valid PPP packet is received from the + * peer, we commence negotiation by sending our first LCP packet. + * + * Default is 0. + */ +#define ppp_set_listen_time(ppp, intval) (ppp->settings.listen_time = intval) + +/* + * If set, we will attempt to initiate a connection but if no reply is received from + * the peer, we will then just wait passively for a valid LCP packet from the peer. + * + * Default is false. + */ +#define ppp_set_passive(ppp, boolval) (ppp->lcp_wantoptions.passive = boolval) + +/* + * If set, we will not transmit LCP packets to initiate a connection until a valid + * LCP packet is received from the peer. This is what we usually call the server mode. + * + * Default is false. + */ +#define ppp_set_silent(ppp, boolval) (ppp->lcp_wantoptions.silent = boolval) + +/* + * If set, enable protocol field compression negotiation in both the receive and + * the transmit direction. + * + * Default is true. + */ +#define ppp_set_neg_pcomp(ppp, boolval) (ppp->lcp_wantoptions.neg_pcompression = \ + ppp->lcp_allowoptions.neg_pcompression = boolval) + +/* + * If set, enable Address/Control compression in both the receive and the transmit + * direction. + * + * Default is true. + */ +#define ppp_set_neg_accomp(ppp, boolval) (ppp->lcp_wantoptions.neg_accompression = \ + ppp->lcp_allowoptions.neg_accompression = boolval) + +/* + * If set, enable asyncmap negotiation. Otherwise forcing all control characters to + * be escaped for both the transmit and the receive direction. + * + * Default is true. + */ +#define ppp_set_neg_asyncmap(ppp, boolval) (ppp->lcp_wantoptions.neg_asyncmap = \ + ppp->lcp_allowoptions.neg_asyncmap = boolval) + +/* + * This option sets the Async-Control-Character-Map (ACCM) for this end of the link. + * The ACCM is a set of 32 bits, one for each of the ASCII control characters with + * values from 0 to 31, where a 1 bit indicates that the corresponding control + * character should not be used in PPP packets sent to this system. The map is + * an unsigned 32 bits integer where the least significant bit (00000001) represents + * character 0 and the most significant bit (80000000) represents character 31. + * We will then ask the peer to send these characters as a 2-byte escape sequence. + * + * Default is 0. + */ +#define ppp_set_asyncmap(ppp, intval) (ppp->lcp_wantoptions.asyncmap = intval) + +/* + * Set a PPP interface as the default network interface + * (used to output all packets for which no specific route is found). + */ +#define ppp_set_default(ppp) netif_set_default(ppp->netif) + +#if PPP_NOTIFY_PHASE +/* + * Set a PPP notify phase callback. + * + * This can be used for example to set a LED pattern depending on the + * current phase of the PPP session. + */ +typedef void (*ppp_notify_phase_cb_fn)(ppp_pcb *pcb, u8_t phase, void *ctx); +void ppp_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb); +#endif /* PPP_NOTIFY_PHASE */ + +/* + * Initiate a PPP connection. + * + * This can only be called if PPP is in the dead phase. + * + * Holdoff is the time to wait (in seconds) before initiating + * the connection. + * + * If this port connects to a modem, the modem connection must be + * established before calling this. + */ +err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff); + +#if PPP_SERVER +/* + * Listen for an incoming PPP connection. + * + * This can only be called if PPP is in the dead phase. + * + * If this port connects to a modem, the modem connection must be + * established before calling this. + */ +err_t ppp_listen(ppp_pcb *pcb); +#endif /* PPP_SERVER */ + +/* + * Initiate the end of a PPP connection. + * Any outstanding packets in the queues are dropped. + * + * Setting nocarrier to 1 close the PPP connection without initiating the + * shutdown procedure. Always using nocarrier = 0 is still recommended, + * this is going to take a little longer time if your link is down, but + * is a safer choice for the PPP state machine. + * + * Return 0 on success, an error code on failure. + */ +err_t ppp_close(ppp_pcb *pcb, u8_t nocarrier); + +/* + * Release the control block. + * + * This can only be called if PPP is in the dead phase. + * + * You must use ppp_close() before if you wish to terminate + * an established PPP session. + * + * Return 0 on success, an error code on failure. + */ +err_t ppp_free(ppp_pcb *pcb); + +/* + * PPP IOCTL commands. + * + * Get the up status - 0 for down, non-zero for up. The argument must + * point to an int. + */ +#define PPPCTLG_UPSTATUS 0 + +/* + * Get the PPP error code. The argument must point to an int. + * Returns a PPPERR_* value. + */ +#define PPPCTLG_ERRCODE 1 + +/* + * Get the fd associated with a PPP over serial + */ +#define PPPCTLG_FD 2 + +/* + * Get and set parameters for the given connection. + * Return 0 on success, an error code on failure. + */ +err_t ppp_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg); + +/* Get the PPP netif interface */ +#define ppp_netif(ppp) (ppp->netif) + +/* Set an lwIP-style status-callback for the selected PPP device */ +#define ppp_set_netif_statuscallback(ppp, status_cb) \ + netif_set_status_callback(ppp->netif, status_cb); + +/* Set an lwIP-style link-callback for the selected PPP device */ +#define ppp_set_netif_linkcallback(ppp, link_cb) \ + netif_set_link_callback(ppp->netif, link_cb); + +#ifdef __cplusplus +} +#endif + +#endif /* PPP_H */ + +#endif /* PPP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp_impl.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp_impl.h new file mode 100644 index 000000000..40843d5a0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp_impl.h @@ -0,0 +1,722 @@ +/***************************************************************************** +* ppp.h - Network Point to Point Protocol header file. +* +* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. +* portions Copyright (c) 1997 Global Election Systems Inc. +* +* The authors hereby grant permission to use, copy, modify, distribute, +* and license this software and its documentation for any purpose, provided +* that existing copyright notices are retained in all copies and that this +* notice and the following disclaimer are included verbatim in any +* distributions. No written agreement, license, or royalty fee is required +* for any of the authorized uses. +* +* THIS SOFTWARE IS PROVIDED BY THE 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 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. +* +****************************************************************************** +* REVISION HISTORY +* +* 03-01-01 Marc Boucher +* Ported to lwIP. +* 97-11-05 Guy Lancaster , Global Election Systems Inc. +* Original derived from BSD codes. +*****************************************************************************/ +#ifndef LWIP_HDR_PPP_IMPL_H +#define LWIP_HDR_PPP_IMPL_H + +#include "netif/ppp/ppp_opts.h" + +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifdef PPP_INCLUDE_SETTINGS_HEADER +#include "ppp_settings.h" +#endif + +#include /* formats */ +#include +#include +#include /* strtol() */ + +#include "lwip/netif.h" +#include "lwip/def.h" +#include "lwip/timeouts.h" + +#include "ppp.h" +#include "pppdebug.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Memory used for control packets. + * + * PPP_CTRL_PBUF_MAX_SIZE is the amount of memory we allocate when we + * cannot figure out how much we are going to use before filling the buffer. + */ +#if PPP_USE_PBUF_RAM +#define PPP_CTRL_PBUF_TYPE PBUF_RAM +#define PPP_CTRL_PBUF_MAX_SIZE 512 +#else /* PPP_USE_PBUF_RAM */ +#define PPP_CTRL_PBUF_TYPE PBUF_POOL +#define PPP_CTRL_PBUF_MAX_SIZE PBUF_POOL_BUFSIZE +#endif /* PPP_USE_PBUF_RAM */ + +/* + * The basic PPP frame. + */ +#define PPP_ADDRESS(p) (((u_char *)(p))[0]) +#define PPP_CONTROL(p) (((u_char *)(p))[1]) +#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3]) + +/* + * Significant octet values. + */ +#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ +#define PPP_UI 0x03 /* Unnumbered Information */ +#define PPP_FLAG 0x7e /* Flag Sequence */ +#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */ +#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */ + +/* + * Protocol field values. + */ +#define PPP_IP 0x21 /* Internet Protocol */ +#if 0 /* UNUSED */ +#define PPP_AT 0x29 /* AppleTalk Protocol */ +#define PPP_IPX 0x2b /* IPX protocol */ +#endif /* UNUSED */ +#if VJ_SUPPORT +#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ +#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ +#endif /* VJ_SUPPORT */ +#if PPP_IPV6_SUPPORT +#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ +#endif /* PPP_IPV6_SUPPORT */ +#if CCP_SUPPORT +#define PPP_COMP 0xfd /* compressed packet */ +#endif /* CCP_SUPPORT */ +#define PPP_IPCP 0x8021 /* IP Control Protocol */ +#if 0 /* UNUSED */ +#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ +#define PPP_IPXCP 0x802b /* IPX Control Protocol */ +#endif /* UNUSED */ +#if PPP_IPV6_SUPPORT +#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ +#endif /* PPP_IPV6_SUPPORT */ +#if CCP_SUPPORT +#define PPP_CCP 0x80fd /* Compression Control Protocol */ +#endif /* CCP_SUPPORT */ +#if ECP_SUPPORT +#define PPP_ECP 0x8053 /* Encryption Control Protocol */ +#endif /* ECP_SUPPORT */ +#define PPP_LCP 0xc021 /* Link Control Protocol */ +#if PAP_SUPPORT +#define PPP_PAP 0xc023 /* Password Authentication Protocol */ +#endif /* PAP_SUPPORT */ +#if LQR_SUPPORT +#define PPP_LQR 0xc025 /* Link Quality Report protocol */ +#endif /* LQR_SUPPORT */ +#if CHAP_SUPPORT +#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ +#endif /* CHAP_SUPPORT */ +#if CBCP_SUPPORT +#define PPP_CBCP 0xc029 /* Callback Control Protocol */ +#endif /* CBCP_SUPPORT */ +#if EAP_SUPPORT +#define PPP_EAP 0xc227 /* Extensible Authentication Protocol */ +#endif /* EAP_SUPPORT */ + +/* + * The following struct gives the addresses of procedures to call + * for a particular lower link level protocol. + */ +struct link_callbacks { + /* Start a connection (e.g. Initiate discovery phase) */ + void (*connect) (ppp_pcb *pcb, void *ctx); +#if PPP_SERVER + /* Listen for an incoming connection (Passive mode) */ + void (*listen) (ppp_pcb *pcb, void *ctx); +#endif /* PPP_SERVER */ + /* End a connection (i.e. initiate disconnect phase) */ + void (*disconnect) (ppp_pcb *pcb, void *ctx); + /* Free lower protocol control block */ + err_t (*free) (ppp_pcb *pcb, void *ctx); + /* Write a pbuf to a ppp link, only used from PPP functions to send PPP packets. */ + err_t (*write)(ppp_pcb *pcb, void *ctx, struct pbuf *p); + /* Send a packet from lwIP core (IPv4 or IPv6) */ + err_t (*netif_output)(ppp_pcb *pcb, void *ctx, struct pbuf *p, u_short protocol); + /* configure the transmit-side characteristics of the PPP interface */ + void (*send_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp); + /* confire the receive-side characteristics of the PPP interface */ + void (*recv_config)(ppp_pcb *pcb, void *ctx, u32_t accm, int pcomp, int accomp); +}; + +/* + * What to do with network protocol (NP) packets. + */ +enum NPmode { + NPMODE_PASS, /* pass the packet through */ + NPMODE_DROP, /* silently drop the packet */ + NPMODE_ERROR, /* return an error */ + NPMODE_QUEUE /* save it up for later. */ +}; + +/* + * Statistics. + */ +#if PPP_STATS_SUPPORT +struct pppstat { + unsigned int ppp_ibytes; /* bytes received */ + unsigned int ppp_ipackets; /* packets received */ + unsigned int ppp_ierrors; /* receive errors */ + unsigned int ppp_obytes; /* bytes sent */ + unsigned int ppp_opackets; /* packets sent */ + unsigned int ppp_oerrors; /* transmit errors */ +}; + +#if VJ_SUPPORT +struct vjstat { + unsigned int vjs_packets; /* outbound packets */ + unsigned int vjs_compressed; /* outbound compressed packets */ + unsigned int vjs_searches; /* searches for connection state */ + unsigned int vjs_misses; /* times couldn't find conn. state */ + unsigned int vjs_uncompressedin; /* inbound uncompressed packets */ + unsigned int vjs_compressedin; /* inbound compressed packets */ + unsigned int vjs_errorin; /* inbound unknown type packets */ + unsigned int vjs_tossed; /* inbound packets tossed because of error */ +}; +#endif /* VJ_SUPPORT */ + +struct ppp_stats { + struct pppstat p; /* basic PPP statistics */ +#if VJ_SUPPORT + struct vjstat vj; /* VJ header compression statistics */ +#endif /* VJ_SUPPORT */ +}; + +#if CCP_SUPPORT +struct compstat { + unsigned int unc_bytes; /* total uncompressed bytes */ + unsigned int unc_packets; /* total uncompressed packets */ + unsigned int comp_bytes; /* compressed bytes */ + unsigned int comp_packets; /* compressed packets */ + unsigned int inc_bytes; /* incompressible bytes */ + unsigned int inc_packets; /* incompressible packets */ + unsigned int ratio; /* recent compression ratio << 8 */ +}; + +struct ppp_comp_stats { + struct compstat c; /* packet compression statistics */ + struct compstat d; /* packet decompression statistics */ +}; +#endif /* CCP_SUPPORT */ + +#endif /* PPP_STATS_SUPPORT */ + +#if PPP_IDLETIMELIMIT +/* + * The following structure records the time in seconds since + * the last NP packet was sent or received. + */ +struct ppp_idle { + time_t xmit_idle; /* time since last NP packet sent */ + time_t recv_idle; /* time since last NP packet received */ +}; +#endif /* PPP_IDLETIMELIMIT */ + +/* values for epdisc.class */ +#define EPD_NULL 0 /* null discriminator, no data */ +#define EPD_LOCAL 1 +#define EPD_IP 2 +#define EPD_MAC 3 +#define EPD_MAGIC 4 +#define EPD_PHONENUM 5 + +/* + * Global variables. + */ +#ifdef HAVE_MULTILINK +extern u8_t multilink; /* enable multilink operation */ +extern u8_t doing_multilink; +extern u8_t multilink_master; +extern u8_t bundle_eof; +extern u8_t bundle_terminating; +#endif + +#ifdef MAXOCTETS +extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */ +extern int maxoctets_dir; /* Direction : + 0 - in+out (default) + 1 - in + 2 - out + 3 - max(in,out) */ +extern int maxoctets_timeout; /* Timeout for check of octets limit */ +#define PPP_OCTETS_DIRECTION_SUM 0 +#define PPP_OCTETS_DIRECTION_IN 1 +#define PPP_OCTETS_DIRECTION_OUT 2 +#define PPP_OCTETS_DIRECTION_MAXOVERAL 3 +/* same as previos, but little different on RADIUS side */ +#define PPP_OCTETS_DIRECTION_MAXSESSION 4 +#endif + +/* Data input may be used by CCP and ECP, remove this entry + * from struct protent to save some flash + */ +#define PPP_DATAINPUT 0 + +/* + * The following struct gives the addresses of procedures to call + * for a particular protocol. + */ +struct protent { + u_short protocol; /* PPP protocol number */ + /* Initialization procedure */ + void (*init) (ppp_pcb *pcb); + /* Process a received packet */ + void (*input) (ppp_pcb *pcb, u_char *pkt, int len); + /* Process a received protocol-reject */ + void (*protrej) (ppp_pcb *pcb); + /* Lower layer has come up */ + void (*lowerup) (ppp_pcb *pcb); + /* Lower layer has gone down */ + void (*lowerdown) (ppp_pcb *pcb); + /* Open the protocol */ + void (*open) (ppp_pcb *pcb); + /* Close the protocol */ + void (*close) (ppp_pcb *pcb, const char *reason); +#if PRINTPKT_SUPPORT + /* Print a packet in readable form */ + int (*printpkt) (const u_char *pkt, int len, + void (*printer) (void *, const char *, ...), + void *arg); +#endif /* PRINTPKT_SUPPORT */ +#if PPP_DATAINPUT + /* Process a received data packet */ + void (*datainput) (ppp_pcb *pcb, u_char *pkt, int len); +#endif /* PPP_DATAINPUT */ +#if PRINTPKT_SUPPORT + const char *name; /* Text name of protocol */ + const char *data_name; /* Text name of corresponding data protocol */ +#endif /* PRINTPKT_SUPPORT */ +#if PPP_OPTIONS + option_t *options; /* List of command-line options */ + /* Check requested options, assign defaults */ + void (*check_options) (void); +#endif /* PPP_OPTIONS */ +#if DEMAND_SUPPORT + /* Configure interface for demand-dial */ + int (*demand_conf) (int unit); + /* Say whether to bring up link for this pkt */ + int (*active_pkt) (u_char *pkt, int len); +#endif /* DEMAND_SUPPORT */ +}; + +/* Table of pointers to supported protocols */ +extern const struct protent* const protocols[]; + + +/* Values for auth_pending, auth_done */ +#if PAP_SUPPORT +#define PAP_WITHPEER 0x1 +#define PAP_PEER 0x2 +#endif /* PAP_SUPPORT */ +#if CHAP_SUPPORT +#define CHAP_WITHPEER 0x4 +#define CHAP_PEER 0x8 +#endif /* CHAP_SUPPORT */ +#if EAP_SUPPORT +#define EAP_WITHPEER 0x10 +#define EAP_PEER 0x20 +#endif /* EAP_SUPPORT */ + +/* Values for auth_done only */ +#if CHAP_SUPPORT +#define CHAP_MD5_WITHPEER 0x40 +#define CHAP_MD5_PEER 0x80 +#if MSCHAP_SUPPORT +#define CHAP_MS_SHIFT 8 /* LSB position for MS auths */ +#define CHAP_MS_WITHPEER 0x100 +#define CHAP_MS_PEER 0x200 +#define CHAP_MS2_WITHPEER 0x400 +#define CHAP_MS2_PEER 0x800 +#endif /* MSCHAP_SUPPORT */ +#endif /* CHAP_SUPPORT */ + +/* Supported CHAP protocols */ +#if CHAP_SUPPORT + +#if MSCHAP_SUPPORT +#define CHAP_MDTYPE_SUPPORTED (MDTYPE_MICROSOFT_V2 | MDTYPE_MICROSOFT | MDTYPE_MD5) +#else /* MSCHAP_SUPPORT */ +#define CHAP_MDTYPE_SUPPORTED (MDTYPE_MD5) +#endif /* MSCHAP_SUPPORT */ + +#else /* CHAP_SUPPORT */ +#define CHAP_MDTYPE_SUPPORTED (MDTYPE_NONE) +#endif /* CHAP_SUPPORT */ + +#if PPP_STATS_SUPPORT +/* + * PPP statistics structure + */ +struct pppd_stats { + unsigned int bytes_in; + unsigned int bytes_out; + unsigned int pkts_in; + unsigned int pkts_out; +}; +#endif /* PPP_STATS_SUPPORT */ + + +/* + * PPP private functions + */ + + +/* + * Functions called from lwIP core. + */ + +/* initialize the PPP subsystem */ +int ppp_init(void); + +/* + * Functions called from PPP link protocols. + */ + +/* Create a new PPP control block */ +ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, void *link_ctx_cb, + ppp_link_status_cb_fn link_status_cb, void *ctx_cb); + +/* Initiate LCP open request */ +void ppp_start(ppp_pcb *pcb); + +/* Called when link failed to setup */ +void ppp_link_failed(ppp_pcb *pcb); + +/* Called when link is normally down (i.e. it was asked to end) */ +void ppp_link_end(ppp_pcb *pcb); + +/* function called to process input packet */ +void ppp_input(ppp_pcb *pcb, struct pbuf *pb); + + +/* + * Functions called by PPP protocols. + */ + +/* function called by all PPP subsystems to send packets */ +err_t ppp_write(ppp_pcb *pcb, struct pbuf *p); + +/* functions called by auth.c link_terminated() */ +void ppp_link_terminated(ppp_pcb *pcb); + +void new_phase(ppp_pcb *pcb, int p); + +int ppp_send_config(ppp_pcb *pcb, int mtu, u32_t accm, int pcomp, int accomp); +int ppp_recv_config(ppp_pcb *pcb, int mru, u32_t accm, int pcomp, int accomp); + +#if PPP_IPV4_SUPPORT +int sifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr, u32_t netmask); +int cifaddr(ppp_pcb *pcb, u32_t our_adr, u32_t his_adr); +#if 0 /* UNUSED - PROXY ARP */ +int sifproxyarp(ppp_pcb *pcb, u32_t his_adr); +int cifproxyarp(ppp_pcb *pcb, u32_t his_adr); +#endif /* UNUSED - PROXY ARP */ +#if LWIP_DNS +int sdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2); +int cdns(ppp_pcb *pcb, u32_t ns1, u32_t ns2); +#endif /* LWIP_DNS */ +#if VJ_SUPPORT +int sifvjcomp(ppp_pcb *pcb, int vjcomp, int cidcomp, int maxcid); +#endif /* VJ_SUPPORT */ +int sifup(ppp_pcb *pcb); +int sifdown (ppp_pcb *pcb); +u32_t get_mask(u32_t addr); +#endif /* PPP_IPV4_SUPPORT */ + +#if PPP_IPV6_SUPPORT +int sif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64); +int cif6addr(ppp_pcb *pcb, eui64_t our_eui64, eui64_t his_eui64); +int sif6up(ppp_pcb *pcb); +int sif6down (ppp_pcb *pcb); +#endif /* PPP_IPV6_SUPPORT */ + +#if DEMAND_SUPPORT +int sifnpmode(ppp_pcb *pcb, int proto, enum NPmode mode); +#endif /* DEMAND_SUPPORt */ + +void netif_set_mtu(ppp_pcb *pcb, int mtu); +int netif_get_mtu(ppp_pcb *pcb); + +#if CCP_SUPPORT +#if 0 /* unused */ +int ccp_test(ppp_pcb *pcb, u_char *opt_ptr, int opt_len, int for_transmit); +#endif /* unused */ +void ccp_set(ppp_pcb *pcb, u8_t isopen, u8_t isup, u8_t receive_method, u8_t transmit_method); +void ccp_reset_comp(ppp_pcb *pcb); +void ccp_reset_decomp(ppp_pcb *pcb); +#if 0 /* unused */ +int ccp_fatal_error(ppp_pcb *pcb); +#endif /* unused */ +#endif /* CCP_SUPPORT */ + +#if PPP_IDLETIMELIMIT +int get_idle_time(ppp_pcb *pcb, struct ppp_idle *ip); +#endif /* PPP_IDLETIMELIMIT */ + +#if DEMAND_SUPPORT +int get_loop_output(void); +#endif /* DEMAND_SUPPORT */ + +/* Optional protocol names list, to make our messages a little more informative. */ +#if PPP_PROTOCOLNAME +const char * protocol_name(int proto); +#endif /* PPP_PROTOCOLNAME */ + +/* Optional stats support, to get some statistics on the PPP interface */ +#if PPP_STATS_SUPPORT +void print_link_stats(void); /* Print stats, if available */ +void reset_link_stats(int u); /* Reset (init) stats when link goes up */ +void update_link_stats(int u); /* Get stats at link termination */ +#endif /* PPP_STATS_SUPPORT */ + + + +/* + * Inline versions of get/put char/short/long. + * Pointer is advanced; we assume that both arguments + * are lvalues and will already be in registers. + * cp MUST be u_char *. + */ +#define GETCHAR(c, cp) { \ + (c) = *(cp)++; \ +} +#define PUTCHAR(c, cp) { \ + *(cp)++ = (u_char) (c); \ +} +#define GETSHORT(s, cp) { \ + (s) = *(cp)++ << 8; \ + (s) |= *(cp)++; \ +} +#define PUTSHORT(s, cp) { \ + *(cp)++ = (u_char) ((s) >> 8); \ + *(cp)++ = (u_char) (s); \ +} +#define GETLONG(l, cp) { \ + (l) = *(cp)++ << 8; \ + (l) |= *(cp)++; (l) <<= 8; \ + (l) |= *(cp)++; (l) <<= 8; \ + (l) |= *(cp)++; \ +} +#define PUTLONG(l, cp) { \ + *(cp)++ = (u_char) ((l) >> 24); \ + *(cp)++ = (u_char) ((l) >> 16); \ + *(cp)++ = (u_char) ((l) >> 8); \ + *(cp)++ = (u_char) (l); \ +} + +#define INCPTR(n, cp) ((cp) += (n)) +#define DECPTR(n, cp) ((cp) -= (n)) + +/* + * System dependent definitions for user-level 4.3BSD UNIX implementation. + */ +#define TIMEOUT(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t)*1000, (f), (a)); } while(0) +#define TIMEOUTMS(f, a, t) do { sys_untimeout((f), (a)); sys_timeout((t), (f), (a)); } while(0) +#define UNTIMEOUT(f, a) sys_untimeout((f), (a)) + +#define BZERO(s, n) memset(s, 0, n) +#define BCMP(s1, s2, l) memcmp(s1, s2, l) + +#define PRINTMSG(m, l) { ppp_info("Remote message: %0.*v", l, m); } + +/* + * MAKEHEADER - Add Header fields to a packet. + */ +#define MAKEHEADER(p, t) { \ + PUTCHAR(PPP_ALLSTATIONS, p); \ + PUTCHAR(PPP_UI, p); \ + PUTSHORT(t, p); } + +/* Procedures exported from auth.c */ +void link_required(ppp_pcb *pcb); /* we are starting to use the link */ +void link_terminated(ppp_pcb *pcb); /* we are finished with the link */ +void link_down(ppp_pcb *pcb); /* the LCP layer has left the Opened state */ +void upper_layers_down(ppp_pcb *pcb); /* take all NCPs down */ +void link_established(ppp_pcb *pcb); /* the link is up; authenticate now */ +void start_networks(ppp_pcb *pcb); /* start all the network control protos */ +void continue_networks(ppp_pcb *pcb); /* start network [ip, etc] control protos */ +#if PPP_AUTH_SUPPORT +#if PPP_SERVER +int auth_check_passwd(ppp_pcb *pcb, char *auser, int userlen, char *apasswd, int passwdlen, const char **msg, int *msglen); + /* check the user name and passwd against configuration */ +void auth_peer_fail(ppp_pcb *pcb, int protocol); + /* peer failed to authenticate itself */ +void auth_peer_success(ppp_pcb *pcb, int protocol, int prot_flavor, const char *name, int namelen); + /* peer successfully authenticated itself */ +#endif /* PPP_SERVER */ +void auth_withpeer_fail(ppp_pcb *pcb, int protocol); + /* we failed to authenticate ourselves */ +void auth_withpeer_success(ppp_pcb *pcb, int protocol, int prot_flavor); + /* we successfully authenticated ourselves */ +#endif /* PPP_AUTH_SUPPORT */ +void np_up(ppp_pcb *pcb, int proto); /* a network protocol has come up */ +void np_down(ppp_pcb *pcb, int proto); /* a network protocol has gone down */ +void np_finished(ppp_pcb *pcb, int proto); /* a network protocol no longer needs link */ +#if PPP_AUTH_SUPPORT +int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secret, int *secret_len, int am_server); + /* get "secret" for chap */ +#endif /* PPP_AUTH_SUPPORT */ + +/* Procedures exported from ipcp.c */ +/* int parse_dotted_ip (char *, u32_t *); */ + +/* Procedures exported from demand.c */ +#if DEMAND_SUPPORT +void demand_conf (void); /* config interface(s) for demand-dial */ +void demand_block (void); /* set all NPs to queue up packets */ +void demand_unblock (void); /* set all NPs to pass packets */ +void demand_discard (void); /* set all NPs to discard packets */ +void demand_rexmit (int, u32_t); /* retransmit saved frames for an NP*/ +int loop_chars (unsigned char *, int); /* process chars from loopback */ +int loop_frame (unsigned char *, int); /* should we bring link up? */ +#endif /* DEMAND_SUPPORT */ + +/* Procedures exported from multilink.c */ +#ifdef HAVE_MULTILINK +void mp_check_options (void); /* Check multilink-related options */ +int mp_join_bundle (void); /* join our link to an appropriate bundle */ +void mp_exit_bundle (void); /* have disconnected our link from bundle */ +void mp_bundle_terminated (void); +char *epdisc_to_str (struct epdisc *); /* string from endpoint discrim. */ +int str_to_epdisc (struct epdisc *, char *); /* endpt disc. from str */ +#else +#define mp_bundle_terminated() /* nothing */ +#define mp_exit_bundle() /* nothing */ +#define doing_multilink 0 +#define multilink_master 0 +#endif + +/* Procedures exported from utils.c. */ +void ppp_print_string(const u_char *p, int len, void (*printer) (void *, const char *, ...), void *arg); /* Format a string for output */ +int ppp_slprintf(char *buf, int buflen, const char *fmt, ...); /* sprintf++ */ +int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args); /* vsprintf++ */ +size_t ppp_strlcpy(char *dest, const char *src, size_t len); /* safe strcpy */ +size_t ppp_strlcat(char *dest, const char *src, size_t len); /* safe strncpy */ +void ppp_dbglog(const char *fmt, ...); /* log a debug message */ +void ppp_info(const char *fmt, ...); /* log an informational message */ +void ppp_notice(const char *fmt, ...); /* log a notice-level message */ +void ppp_warn(const char *fmt, ...); /* log a warning message */ +void ppp_error(const char *fmt, ...); /* log an error message */ +void ppp_fatal(const char *fmt, ...); /* log an error message and die(1) */ +#if PRINTPKT_SUPPORT +void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len); + /* dump packet to debug log if interesting */ +#endif /* PRINTPKT_SUPPORT */ + +/* + * Number of necessary timers analysis. + * + * PPP use at least one timer per each of its protocol, but not all protocols are + * active at the same time, thus the number of necessary timeouts is actually + * lower than enabled protocols. Here is the actual necessary timeouts based + * on code analysis. + * + * Note that many features analysed here are not working at all and are only + * there for a comprehensive analysis of necessary timers in order to prevent + * having to redo that each time we add a feature. + * + * Timer list + * + * | holdoff timeout + * | low level protocol timeout (PPPoE or PPPoL2P) + * | LCP delayed UP + * | LCP retransmit (FSM) + * | LCP Echo timer + * .| PAP or CHAP or EAP authentication + * . | ECP retransmit (FSM) + * . | CCP retransmit (FSM) when MPPE is enabled + * . | CCP retransmit (FSM) when MPPE is NOT enabled + * . | IPCP retransmit (FSM) + * . .| IP6CP retransmit (FSM) + * . . | Idle time limit + * . . | Max connect time + * . . | Max octets + * . . | CCP RACK timeout + * . . . + * PPP_PHASE_DEAD + * PPP_PHASE_HOLDOFF + * | . . . + * PPP_PHASE_INITIALIZE + * | . . . + * PPP_PHASE_ESTABLISH + * | . . . + * |. . . + * | . . + * PPP_PHASE_AUTHENTICATE + * | . . + * || . . + * PPP_PHASE_NETWORK + * | || . . + * | ||| . + * PPP_PHASE_RUNNING + * | .||||| + * | . |||| + * PPP_PHASE_TERMINATE + * | . |||| + * PPP_PHASE_NETWORK + * |. . + * PPP_PHASE_ESTABLISH + * PPP_PHASE_DISCONNECT + * PPP_PHASE_DEAD + * + * Alright, PPP basic retransmission and LCP Echo consume one timer. + * 1 + * + * If authentication is enabled one timer is necessary during authentication. + * 1 + PPP_AUTH_SUPPORT + * + * If ECP is enabled one timer is necessary before IPCP and/or IP6CP, one more + * is necessary if CCP is enabled (only with MPPE support but we don't care much + * up to this detail level). + * 1 + ECP_SUPPORT + CCP_SUPPORT + * + * If CCP is enabled it might consume a timer during IPCP or IP6CP, thus + * we might use IPCP, IP6CP and CCP timers simultaneously. + * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT + * + * When entering running phase, IPCP or IP6CP is still running. If idle time limit + * is enabled one more timer is necessary. Same for max connect time and max + * octets features. Furthermore CCP RACK might be used past this point. + * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT + * + * IPv4 or IPv6 must be enabled, therefore we don't need to take care the authentication + * and the CCP + ECP case, thus reducing overall complexity. + * 1 + LWIP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS + CCP_SUPPORT) + * + * We don't support PPP_IDLETIMELIMIT + PPP_MAXCONNECT + MAXOCTETS features + * and adding those defines to ppp_opts.h just for having the value always + * defined to 0 isn't worth it. + * 1 + LWIP_MAX(PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT, PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT -1 + CCP_SUPPORT) + * + * Thus, the following is enough for now. + * 1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT + */ + +#ifdef __cplusplus +} +#endif + +#endif /* PPP_SUPPORT */ +#endif /* LWIP_HDR_PPP_IMPL_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp_opts.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp_opts.h new file mode 100644 index 000000000..479a006d1 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/ppp_opts.h @@ -0,0 +1,617 @@ +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#ifndef LWIP_PPP_OPTS_H +#define LWIP_PPP_OPTS_H + +#include "lwip/opt.h" + +/** + * PPP_SUPPORT==1: Enable PPP. + */ +#ifndef PPP_SUPPORT +#define PPP_SUPPORT 0 +#endif + +/** + * PPPOE_SUPPORT==1: Enable PPP Over Ethernet + */ +#ifndef PPPOE_SUPPORT +#define PPPOE_SUPPORT 0 +#endif + +/** + * PPPOE_SCNAME_SUPPORT==1: Enable PPP Over Ethernet Service Name and Concentrator Name support + */ +#ifndef PPPOE_SCNAME_SUPPORT +#define PPPOE_SCNAME_SUPPORT 0 +#endif + +/** + * PPPOL2TP_SUPPORT==1: Enable PPP Over L2TP + */ +#ifndef PPPOL2TP_SUPPORT +#define PPPOL2TP_SUPPORT 0 +#endif + +/** + * PPPOL2TP_AUTH_SUPPORT==1: Enable PPP Over L2TP Auth (enable MD5 support) + */ +#ifndef PPPOL2TP_AUTH_SUPPORT +#define PPPOL2TP_AUTH_SUPPORT PPPOL2TP_SUPPORT +#endif + +/** + * PPPOS_SUPPORT==1: Enable PPP Over Serial + */ +#ifndef PPPOS_SUPPORT +#define PPPOS_SUPPORT PPP_SUPPORT +#endif + +/** + * LWIP_PPP_API==1: Enable PPP API (in pppapi.c) + */ +#ifndef LWIP_PPP_API +#define LWIP_PPP_API (PPP_SUPPORT && (NO_SYS == 0)) +#endif + +#if PPP_SUPPORT + +/** + * MEMP_NUM_PPP_PCB: the number of simultaneously active PPP + * connections (requires the PPP_SUPPORT option) + */ +#ifndef MEMP_NUM_PPP_PCB +#define MEMP_NUM_PPP_PCB 1 +#endif + +/** + * PPP_NUM_TIMEOUTS_PER_PCB: the number of sys_timeouts running in parallel per + * ppp_pcb. See the detailed explanation at the end of ppp_impl.h about simultaneous + * timers analysis. + */ +#ifndef PPP_NUM_TIMEOUTS_PER_PCB +#define PPP_NUM_TIMEOUTS_PER_PCB (1 + PPP_IPV4_SUPPORT + PPP_IPV6_SUPPORT + CCP_SUPPORT) +#endif + +/* The number of sys_timeouts required for the PPP module */ +#define PPP_NUM_TIMEOUTS (PPP_SUPPORT * PPP_NUM_TIMEOUTS_PER_PCB * MEMP_NUM_PPP_PCB) + +/** + * MEMP_NUM_PPPOS_INTERFACES: the number of concurrently active PPPoS + * interfaces (only used with PPPOS_SUPPORT==1) + */ +#ifndef MEMP_NUM_PPPOS_INTERFACES +#define MEMP_NUM_PPPOS_INTERFACES MEMP_NUM_PPP_PCB +#endif + +/** + * MEMP_NUM_PPPOE_INTERFACES: the number of concurrently active PPPoE + * interfaces (only used with PPPOE_SUPPORT==1) + */ +#ifndef MEMP_NUM_PPPOE_INTERFACES +#define MEMP_NUM_PPPOE_INTERFACES 1 +#endif + +/** + * MEMP_NUM_PPPOL2TP_INTERFACES: the number of concurrently active PPPoL2TP + * interfaces (only used with PPPOL2TP_SUPPORT==1) + */ +#ifndef MEMP_NUM_PPPOL2TP_INTERFACES +#define MEMP_NUM_PPPOL2TP_INTERFACES 1 +#endif + +/** + * MEMP_NUM_PPP_API_MSG: Number of concurrent PPP API messages (in pppapi.c) + */ +#ifndef MEMP_NUM_PPP_API_MSG +#define MEMP_NUM_PPP_API_MSG 5 +#endif + +/** + * PPP_DEBUG: Enable debugging for PPP. + */ +#ifndef PPP_DEBUG +#define PPP_DEBUG LWIP_DBG_OFF +#endif + +/** + * PPP_INPROC_IRQ_SAFE==1 call pppos_input() using tcpip_callback(). + * + * Please read the "PPPoS input path" chapter in the PPP documentation about this option. + */ +#ifndef PPP_INPROC_IRQ_SAFE +#define PPP_INPROC_IRQ_SAFE 0 +#endif + +/** + * PRINTPKT_SUPPORT==1: Enable PPP print packet support + * + * Mandatory for debugging, it displays exchanged packet content in debug trace. + */ +#ifndef PRINTPKT_SUPPORT +#define PRINTPKT_SUPPORT 0 +#endif + +/** + * PPP_IPV4_SUPPORT==1: Enable PPP IPv4 support + */ +#ifndef PPP_IPV4_SUPPORT +#define PPP_IPV4_SUPPORT (LWIP_IPV4) +#endif + +/** + * PPP_IPV6_SUPPORT==1: Enable PPP IPv6 support + */ +#ifndef PPP_IPV6_SUPPORT +#define PPP_IPV6_SUPPORT (LWIP_IPV6) +#endif + +/** + * PPP_NOTIFY_PHASE==1: Support PPP notify phase support + * + * PPP notify phase support allows you to set a callback which is + * called on change of the internal PPP state machine. + * + * This can be used for example to set a LED pattern depending on the + * current phase of the PPP session. + */ +#ifndef PPP_NOTIFY_PHASE +#define PPP_NOTIFY_PHASE 0 +#endif + +/** + * pbuf_type PPP is using for LCP, PAP, CHAP, EAP, CCP, IPCP and IP6CP packets. + * + * Memory allocated must be single buffered for PPP to works, it requires pbuf + * that are not going to be chained when allocated. This requires setting + * PBUF_POOL_BUFSIZE to at least 512 bytes, which is quite huge for small systems. + * + * Setting PPP_USE_PBUF_RAM to 1 makes PPP use memory from heap where continuous + * buffers are required, allowing you to use a smaller PBUF_POOL_BUFSIZE. + */ +#ifndef PPP_USE_PBUF_RAM +#define PPP_USE_PBUF_RAM 0 +#endif + +/** + * PPP_FCS_TABLE: Keep a 256*2 byte table to speed up FCS calculation for PPPoS + */ +#ifndef PPP_FCS_TABLE +#define PPP_FCS_TABLE 1 +#endif + +/** + * PAP_SUPPORT==1: Support PAP. + */ +#ifndef PAP_SUPPORT +#define PAP_SUPPORT 0 +#endif + +/** + * CHAP_SUPPORT==1: Support CHAP. + */ +#ifndef CHAP_SUPPORT +#define CHAP_SUPPORT 0 +#endif + +/** + * MSCHAP_SUPPORT==1: Support MSCHAP. + */ +#ifndef MSCHAP_SUPPORT +#define MSCHAP_SUPPORT 0 +#endif +#if MSCHAP_SUPPORT +/* MSCHAP requires CHAP support */ +#undef CHAP_SUPPORT +#define CHAP_SUPPORT 1 +#endif /* MSCHAP_SUPPORT */ + +/** + * EAP_SUPPORT==1: Support EAP. + */ +#ifndef EAP_SUPPORT +#define EAP_SUPPORT 0 +#endif + +/** + * CCP_SUPPORT==1: Support CCP. + */ +#ifndef CCP_SUPPORT +#define CCP_SUPPORT 0 +#endif + +/** + * MPPE_SUPPORT==1: Support MPPE. + */ +#ifndef MPPE_SUPPORT +#define MPPE_SUPPORT 0 +#endif +#if MPPE_SUPPORT +/* MPPE requires CCP support */ +#undef CCP_SUPPORT +#define CCP_SUPPORT 1 +/* MPPE requires MSCHAP support */ +#undef MSCHAP_SUPPORT +#define MSCHAP_SUPPORT 1 +/* MSCHAP requires CHAP support */ +#undef CHAP_SUPPORT +#define CHAP_SUPPORT 1 +#endif /* MPPE_SUPPORT */ + +/** + * CBCP_SUPPORT==1: Support CBCP. CURRENTLY NOT SUPPORTED! DO NOT SET! + */ +#ifndef CBCP_SUPPORT +#define CBCP_SUPPORT 0 +#endif + +/** + * ECP_SUPPORT==1: Support ECP. CURRENTLY NOT SUPPORTED! DO NOT SET! + */ +#ifndef ECP_SUPPORT +#define ECP_SUPPORT 0 +#endif + +/** + * DEMAND_SUPPORT==1: Support dial on demand. CURRENTLY NOT SUPPORTED! DO NOT SET! + */ +#ifndef DEMAND_SUPPORT +#define DEMAND_SUPPORT 0 +#endif + +/** + * LQR_SUPPORT==1: Support Link Quality Report. Do nothing except exchanging some LCP packets. + */ +#ifndef LQR_SUPPORT +#define LQR_SUPPORT 0 +#endif + +/** + * PPP_SERVER==1: Enable PPP server support (waiting for incoming PPP session). + * + * Currently only supported for PPPoS. + */ +#ifndef PPP_SERVER +#define PPP_SERVER 0 +#endif + +#if PPP_SERVER +/* + * PPP_OUR_NAME: Our name for authentication purposes + */ +#ifndef PPP_OUR_NAME +#define PPP_OUR_NAME "lwIP" +#endif +#endif /* PPP_SERVER */ + +/** + * VJ_SUPPORT==1: Support VJ header compression. + */ +#ifndef VJ_SUPPORT +#define VJ_SUPPORT 1 +#endif +/* VJ compression is only supported for TCP over IPv4 over PPPoS. */ +#if !PPPOS_SUPPORT || !PPP_IPV4_SUPPORT || !LWIP_TCP +#undef VJ_SUPPORT +#define VJ_SUPPORT 0 +#endif /* !PPPOS_SUPPORT */ + +/** + * PPP_MD5_RANDM==1: Use MD5 for better randomness. + * Enabled by default if CHAP, EAP, or L2TP AUTH support is enabled. + */ +#ifndef PPP_MD5_RANDM +#define PPP_MD5_RANDM (CHAP_SUPPORT || EAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT) +#endif + +/** + * PolarSSL embedded library + * + * + * lwIP contains some files fetched from the latest BSD release of + * the PolarSSL project (PolarSSL 0.10.1-bsd) for ciphers and encryption + * methods we need for lwIP PPP support. + * + * The PolarSSL files were cleaned to contain only the necessary struct + * fields and functions needed for lwIP. + * + * The PolarSSL API was not changed at all, so if you are already using + * PolarSSL you can choose to skip the compilation of the included PolarSSL + * library into lwIP. + * + * If you are not using the embedded copy you must include external + * libraries into your arch/cc.h port file. + * + * Beware of the stack requirements which can be a lot larger if you are not + * using our cleaned PolarSSL library. + */ + +/** + * LWIP_USE_EXTERNAL_POLARSSL: Use external PolarSSL library + */ +#ifndef LWIP_USE_EXTERNAL_POLARSSL +#define LWIP_USE_EXTERNAL_POLARSSL 0 +#endif + +/** + * LWIP_USE_EXTERNAL_MBEDTLS: Use external mbed TLS library + */ +#ifndef LWIP_USE_EXTERNAL_MBEDTLS +#define LWIP_USE_EXTERNAL_MBEDTLS 0 +#endif + +/* + * PPP Timeouts + */ + +/** + * FSM_DEFTIMEOUT: Timeout time in seconds + */ +#ifndef FSM_DEFTIMEOUT +#define FSM_DEFTIMEOUT 6 +#endif + +/** + * FSM_DEFMAXTERMREQS: Maximum Terminate-Request transmissions + */ +#ifndef FSM_DEFMAXTERMREQS +#define FSM_DEFMAXTERMREQS 2 +#endif + +/** + * FSM_DEFMAXCONFREQS: Maximum Configure-Request transmissions + */ +#ifndef FSM_DEFMAXCONFREQS +#define FSM_DEFMAXCONFREQS 10 +#endif + +/** + * FSM_DEFMAXNAKLOOPS: Maximum number of nak loops + */ +#ifndef FSM_DEFMAXNAKLOOPS +#define FSM_DEFMAXNAKLOOPS 5 +#endif + +/** + * UPAP_DEFTIMEOUT: Timeout (seconds) for retransmitting req + */ +#ifndef UPAP_DEFTIMEOUT +#define UPAP_DEFTIMEOUT 6 +#endif + +/** + * UPAP_DEFTRANSMITS: Maximum number of auth-reqs to send + */ +#ifndef UPAP_DEFTRANSMITS +#define UPAP_DEFTRANSMITS 10 +#endif + +#if PPP_SERVER +/** + * UPAP_DEFREQTIME: Time to wait for auth-req from peer + */ +#ifndef UPAP_DEFREQTIME +#define UPAP_DEFREQTIME 30 +#endif +#endif /* PPP_SERVER */ + +/** + * CHAP_DEFTIMEOUT: Timeout (seconds) for retransmitting req + */ +#ifndef CHAP_DEFTIMEOUT +#define CHAP_DEFTIMEOUT 6 +#endif + +/** + * CHAP_DEFTRANSMITS: max # times to send challenge + */ +#ifndef CHAP_DEFTRANSMITS +#define CHAP_DEFTRANSMITS 10 +#endif + +#if PPP_SERVER +/** + * CHAP_DEFRECHALLENGETIME: If this option is > 0, rechallenge the peer every n seconds + */ +#ifndef CHAP_DEFRECHALLENGETIME +#define CHAP_DEFRECHALLENGETIME 0 +#endif +#endif /* PPP_SERVER */ + +/** + * EAP_DEFREQTIME: Time to wait for peer request + */ +#ifndef EAP_DEFREQTIME +#define EAP_DEFREQTIME 6 +#endif + +/** + * EAP_DEFALLOWREQ: max # times to accept requests + */ +#ifndef EAP_DEFALLOWREQ +#define EAP_DEFALLOWREQ 10 +#endif + +#if PPP_SERVER +/** + * EAP_DEFTIMEOUT: Timeout (seconds) for rexmit + */ +#ifndef EAP_DEFTIMEOUT +#define EAP_DEFTIMEOUT 6 +#endif + +/** + * EAP_DEFTRANSMITS: max # times to transmit + */ +#ifndef EAP_DEFTRANSMITS +#define EAP_DEFTRANSMITS 10 +#endif +#endif /* PPP_SERVER */ + +/** + * LCP_DEFLOOPBACKFAIL: Default number of times we receive our magic number from the peer + * before deciding the link is looped-back. + */ +#ifndef LCP_DEFLOOPBACKFAIL +#define LCP_DEFLOOPBACKFAIL 10 +#endif + +/** + * LCP_ECHOINTERVAL: Interval in seconds between keepalive echo requests, 0 to disable. + */ +#ifndef LCP_ECHOINTERVAL +#define LCP_ECHOINTERVAL 0 +#endif + +/** + * LCP_MAXECHOFAILS: Number of unanswered echo requests before failure. + */ +#ifndef LCP_MAXECHOFAILS +#define LCP_MAXECHOFAILS 3 +#endif + +/** + * PPP_MAXIDLEFLAG: Max Xmit idle time (in ms) before resend flag char. + */ +#ifndef PPP_MAXIDLEFLAG +#define PPP_MAXIDLEFLAG 100 +#endif + +/** + * PPP Packet sizes + */ + +/** + * PPP_MRU: Default MRU + */ +#ifndef PPP_MRU +#define PPP_MRU 1500 +#endif + +/** + * PPP_DEFMRU: Default MRU to try + */ +#ifndef PPP_DEFMRU +#define PPP_DEFMRU 1500 +#endif + +/** + * PPP_MAXMRU: Normally limit MRU to this (pppd default = 16384) + */ +#ifndef PPP_MAXMRU +#define PPP_MAXMRU 1500 +#endif + +/** + * PPP_MINMRU: No MRUs below this + */ +#ifndef PPP_MINMRU +#define PPP_MINMRU 128 +#endif + +/** + * PPPOL2TP_DEFMRU: Default MTU and MRU for L2TP + * Default = 1500 - PPPoE(6) - PPP Protocol(2) - IPv4 header(20) - UDP Header(8) + * - L2TP Header(6) - HDLC Header(2) - PPP Protocol(2) - MPPE Header(2) - PPP Protocol(2) + */ +#if PPPOL2TP_SUPPORT +#ifndef PPPOL2TP_DEFMRU +#define PPPOL2TP_DEFMRU 1450 +#endif +#endif /* PPPOL2TP_SUPPORT */ + +/** + * MAXNAMELEN: max length of hostname or name for auth + */ +#ifndef MAXNAMELEN +#define MAXNAMELEN 256 +#endif + +/** + * MAXSECRETLEN: max length of password or secret + */ +#ifndef MAXSECRETLEN +#define MAXSECRETLEN 256 +#endif + +/* ------------------------------------------------------------------------- */ + +/* + * Build triggers for embedded PolarSSL + */ +#if !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS + +/* CHAP, EAP, L2TP AUTH and MD5 Random require MD5 support */ +#if CHAP_SUPPORT || EAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT || PPP_MD5_RANDM +#define LWIP_INCLUDED_POLARSSL_MD5 1 +#endif /* CHAP_SUPPORT || EAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT || PPP_MD5_RANDM */ + +#if MSCHAP_SUPPORT + +/* MSCHAP require MD4 support */ +#define LWIP_INCLUDED_POLARSSL_MD4 1 +/* MSCHAP require SHA1 support */ +#define LWIP_INCLUDED_POLARSSL_SHA1 1 +/* MSCHAP require DES support */ +#define LWIP_INCLUDED_POLARSSL_DES 1 + +/* MS-CHAP support is required for MPPE */ +#if MPPE_SUPPORT +/* MPPE require ARC4 support */ +#define LWIP_INCLUDED_POLARSSL_ARC4 1 +#endif /* MPPE_SUPPORT */ + +#endif /* MSCHAP_SUPPORT */ + +#endif /* !LWIP_USE_EXTERNAL_POLARSSL && !LWIP_USE_EXTERNAL_MBEDTLS */ + +/* Default value if unset */ +#ifndef LWIP_INCLUDED_POLARSSL_MD4 +#define LWIP_INCLUDED_POLARSSL_MD4 0 +#endif /* LWIP_INCLUDED_POLARSSL_MD4 */ +#ifndef LWIP_INCLUDED_POLARSSL_MD5 +#define LWIP_INCLUDED_POLARSSL_MD5 0 +#endif /* LWIP_INCLUDED_POLARSSL_MD5 */ +#ifndef LWIP_INCLUDED_POLARSSL_SHA1 +#define LWIP_INCLUDED_POLARSSL_SHA1 0 +#endif /* LWIP_INCLUDED_POLARSSL_SHA1 */ +#ifndef LWIP_INCLUDED_POLARSSL_DES +#define LWIP_INCLUDED_POLARSSL_DES 0 +#endif /* LWIP_INCLUDED_POLARSSL_DES */ +#ifndef LWIP_INCLUDED_POLARSSL_ARC4 +#define LWIP_INCLUDED_POLARSSL_ARC4 0 +#endif /* LWIP_INCLUDED_POLARSSL_ARC4 */ + +#endif /* PPP_SUPPORT */ + +/* Default value if unset */ +#ifndef PPP_NUM_TIMEOUTS +#define PPP_NUM_TIMEOUTS 0 +#endif /* PPP_NUM_TIMEOUTS */ + +#endif /* LWIP_PPP_OPTS_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppapi.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppapi.h new file mode 100644 index 000000000..913d93f74 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppapi.h @@ -0,0 +1,137 @@ +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#ifndef LWIP_PPPAPI_H +#define LWIP_PPPAPI_H + +#include "netif/ppp/ppp_opts.h" + +#if LWIP_PPP_API /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/sys.h" +#include "lwip/netif.h" +#include "lwip/priv/tcpip_priv.h" +#include "netif/ppp/ppp.h" +#if PPPOS_SUPPORT +#include "netif/ppp/pppos.h" +#endif /* PPPOS_SUPPORT */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct pppapi_msg_msg { + ppp_pcb *ppp; + union { +#if PPP_NOTIFY_PHASE + struct { + ppp_notify_phase_cb_fn notify_phase_cb; + } setnotifyphasecb; +#endif /* PPP_NOTIFY_PHASE */ +#if PPPOS_SUPPORT + struct { + struct netif *pppif; + pppos_output_cb_fn output_cb; + ppp_link_status_cb_fn link_status_cb; + void *ctx_cb; + } serialcreate; +#endif /* PPPOS_SUPPORT */ +#if PPPOE_SUPPORT + struct { + struct netif *pppif; + struct netif *ethif; + const char *service_name; + const char *concentrator_name; + ppp_link_status_cb_fn link_status_cb; + void *ctx_cb; + } ethernetcreate; +#endif /* PPPOE_SUPPORT */ +#if PPPOL2TP_SUPPORT + struct { + struct netif *pppif; + struct netif *netif; + API_MSG_M_DEF_C(ip_addr_t, ipaddr); + u16_t port; +#if PPPOL2TP_AUTH_SUPPORT + const u8_t *secret; + u8_t secret_len; +#endif /* PPPOL2TP_AUTH_SUPPORT */ + ppp_link_status_cb_fn link_status_cb; + void *ctx_cb; + } l2tpcreate; +#endif /* PPPOL2TP_SUPPORT */ + struct { + u16_t holdoff; + } connect; + struct { + u8_t nocarrier; + } close; + struct { + u8_t cmd; + void *arg; + } ioctl; + } msg; +}; + +struct pppapi_msg { + struct tcpip_api_call_data call; + struct pppapi_msg_msg msg; +}; + +/* API for application */ +err_t pppapi_set_default(ppp_pcb *pcb); +#if PPP_NOTIFY_PHASE +err_t pppapi_set_notify_phase_callback(ppp_pcb *pcb, ppp_notify_phase_cb_fn notify_phase_cb); +#endif /* PPP_NOTIFY_PHASE */ +#if PPPOS_SUPPORT +ppp_pcb *pppapi_pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb, ppp_link_status_cb_fn link_status_cb, void *ctx_cb); +#endif /* PPPOS_SUPPORT */ +#if PPPOE_SUPPORT +ppp_pcb *pppapi_pppoe_create(struct netif *pppif, struct netif *ethif, const char *service_name, + const char *concentrator_name, ppp_link_status_cb_fn link_status_cb, + void *ctx_cb); +#endif /* PPPOE_SUPPORT */ +#if PPPOL2TP_SUPPORT +ppp_pcb *pppapi_pppol2tp_create(struct netif *pppif, struct netif *netif, ip_addr_t *ipaddr, u16_t port, + const u8_t *secret, u8_t secret_len, + ppp_link_status_cb_fn link_status_cb, void *ctx_cb); +#endif /* PPPOL2TP_SUPPORT */ +err_t pppapi_connect(ppp_pcb *pcb, u16_t holdoff); +#if PPP_SERVER +err_t pppapi_listen(ppp_pcb *pcb); +#endif /* PPP_SERVER */ +err_t pppapi_close(ppp_pcb *pcb, u8_t nocarrier); +err_t pppapi_free(ppp_pcb *pcb); +err_t pppapi_ioctl(ppp_pcb *pcb, u8_t cmd, void *arg); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_PPP_API */ + +#endif /* LWIP_PPPAPI_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppcrypt.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppcrypt.h new file mode 100644 index 000000000..c0230bbcb --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppcrypt.h @@ -0,0 +1,144 @@ +/* + * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1 + * + * Extracted from chap_ms.c by James Carlson. + * + * Copyright (c) 1995 Eric Rosenquist. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +/* This header file is included in all PPP modules needing hashes and/or ciphers */ + +#ifndef PPPCRYPT_H +#define PPPCRYPT_H + +/* + * If included PolarSSL copy is not used, user is expected to include + * external libraries in arch/cc.h (which is included by lwip/arch.h). + */ +#include "lwip/arch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Map hashes and ciphers functions to PolarSSL + */ +#if !LWIP_USE_EXTERNAL_MBEDTLS + +#include "netif/ppp/polarssl/md4.h" +#define lwip_md4_context md4_context +#define lwip_md4_init(context) +#define lwip_md4_starts md4_starts +#define lwip_md4_update md4_update +#define lwip_md4_finish md4_finish +#define lwip_md4_free(context) + +#include "netif/ppp/polarssl/md5.h" +#define lwip_md5_context md5_context +#define lwip_md5_init(context) +#define lwip_md5_starts md5_starts +#define lwip_md5_update md5_update +#define lwip_md5_finish md5_finish +#define lwip_md5_free(context) + +#include "netif/ppp/polarssl/sha1.h" +#define lwip_sha1_context sha1_context +#define lwip_sha1_init(context) +#define lwip_sha1_starts sha1_starts +#define lwip_sha1_update sha1_update +#define lwip_sha1_finish sha1_finish +#define lwip_sha1_free(context) + +#include "netif/ppp/polarssl/des.h" +#define lwip_des_context des_context +#define lwip_des_init(context) +#define lwip_des_setkey_enc des_setkey_enc +#define lwip_des_crypt_ecb des_crypt_ecb +#define lwip_des_free(context) + +#include "netif/ppp/polarssl/arc4.h" +#define lwip_arc4_context arc4_context +#define lwip_arc4_init(context) +#define lwip_arc4_setup arc4_setup +#define lwip_arc4_crypt arc4_crypt +#define lwip_arc4_free(context) + +#endif /* !LWIP_USE_EXTERNAL_MBEDTLS */ + +/* + * Map hashes and ciphers functions to mbed TLS + */ +#if LWIP_USE_EXTERNAL_MBEDTLS + +#define lwip_md4_context mbedtls_md4_context +#define lwip_md4_init mbedtls_md4_init +#define lwip_md4_starts mbedtls_md4_starts +#define lwip_md4_update mbedtls_md4_update +#define lwip_md4_finish mbedtls_md4_finish +#define lwip_md4_free mbedtls_md4_free + +#define lwip_md5_context mbedtls_md5_context +#define lwip_md5_init mbedtls_md5_init +#define lwip_md5_starts mbedtls_md5_starts +#define lwip_md5_update mbedtls_md5_update +#define lwip_md5_finish mbedtls_md5_finish +#define lwip_md5_free mbedtls_md5_free + +#define lwip_sha1_context mbedtls_sha1_context +#define lwip_sha1_init mbedtls_sha1_init +#define lwip_sha1_starts mbedtls_sha1_starts +#define lwip_sha1_update mbedtls_sha1_update +#define lwip_sha1_finish mbedtls_sha1_finish +#define lwip_sha1_free mbedtls_sha1_free + +#define lwip_des_context mbedtls_des_context +#define lwip_des_init mbedtls_des_init +#define lwip_des_setkey_enc mbedtls_des_setkey_enc +#define lwip_des_crypt_ecb mbedtls_des_crypt_ecb +#define lwip_des_free mbedtls_des_free + +#define lwip_arc4_context mbedtls_arc4_context +#define lwip_arc4_init mbedtls_arc4_init +#define lwip_arc4_setup mbedtls_arc4_setup +#define lwip_arc4_crypt(context, buffer, length) mbedtls_arc4_crypt(context, length, buffer, buffer) +#define lwip_arc4_free mbedtls_arc4_free + +#endif /* LWIP_USE_EXTERNAL_MBEDTLS */ + +void pppcrypt_56_to_64_bit_key(u_char *key, u_char *des_key); + +#ifdef __cplusplus +} +#endif + +#endif /* PPPCRYPT_H */ + +#endif /* PPP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppdebug.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppdebug.h new file mode 100644 index 000000000..36ee4f9bf --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppdebug.h @@ -0,0 +1,88 @@ +/***************************************************************************** +* pppdebug.h - System debugging utilities. +* +* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. +* portions Copyright (c) 1998 Global Election Systems Inc. +* portions Copyright (c) 2001 by Cognizant Pty Ltd. +* +* The authors hereby grant permission to use, copy, modify, distribute, +* and license this software and its documentation for any purpose, provided +* that existing copyright notices are retained in all copies and that this +* notice and the following disclaimer are included verbatim in any +* distributions. No written agreement, license, or royalty fee is required +* for any of the authorized uses. +* +* THIS SOFTWARE IS PROVIDED BY THE 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 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. +* +****************************************************************************** +* REVISION HISTORY (please don't use tabs!) +* +* 03-01-01 Marc Boucher +* Ported to lwIP. +* 98-07-29 Guy Lancaster , Global Election Systems Inc. +* Original. +* +***************************************************************************** +*/ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef PPPDEBUG_H +#define PPPDEBUG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Trace levels. */ +#define LOG_CRITICAL (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE) +#define LOG_ERR (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE) +#define LOG_NOTICE (PPP_DEBUG | LWIP_DBG_LEVEL_WARNING) +#define LOG_WARNING (PPP_DEBUG | LWIP_DBG_LEVEL_WARNING) +#define LOG_INFO (PPP_DEBUG) +#define LOG_DETAIL (PPP_DEBUG) +#define LOG_DEBUG (PPP_DEBUG) + +#if PPP_DEBUG + +#define MAINDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define SYSDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define FSMDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define LCPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define IPCPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define IPV6CPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define UPAPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define CHAPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a) +#define PPPDEBUG(a, b) LWIP_DEBUGF(a, b) + +#else /* PPP_DEBUG */ + +#define MAINDEBUG(a) +#define SYSDEBUG(a) +#define FSMDEBUG(a) +#define LCPDEBUG(a) +#define IPCPDEBUG(a) +#define IPV6CPDEBUG(a) +#define UPAPDEBUG(a) +#define CHAPDEBUG(a) +#define PPPDEBUG(a, b) + +#endif /* PPP_DEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* PPPDEBUG_H */ + +#endif /* PPP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppoe.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppoe.h new file mode 100644 index 000000000..8994d38c0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppoe.h @@ -0,0 +1,187 @@ +/***************************************************************************** +* pppoe.h - PPP Over Ethernet implementation for lwIP. +* +* Copyright (c) 2006 by Marc Boucher, Services Informatiques (MBSI) inc. +* +* The authors hereby grant permission to use, copy, modify, distribute, +* and license this software and its documentation for any purpose, provided +* that existing copyright notices are retained in all copies and that this +* notice and the following disclaimer are included verbatim in any +* distributions. No written agreement, license, or royalty fee is required +* for any of the authorized uses. +* +* THIS SOFTWARE IS PROVIDED BY THE 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 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. +* +****************************************************************************** +* REVISION HISTORY +* +* 06-01-01 Marc Boucher +* Ported to lwIP. +*****************************************************************************/ + + + +/* based on NetBSD: if_pppoe.c,v 1.64 2006/01/31 23:50:15 martin Exp */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Martin Husemann . + * + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && PPPOE_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef PPP_OE_H +#define PPP_OE_H + +#include "ppp.h" +#include "lwip/etharp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct pppoehdr { + PACK_STRUCT_FLD_8(u8_t vertype); + PACK_STRUCT_FLD_8(u8_t code); + PACK_STRUCT_FIELD(u16_t session); + PACK_STRUCT_FIELD(u16_t plen); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/bpstruct.h" +#endif +PACK_STRUCT_BEGIN +struct pppoetag { + PACK_STRUCT_FIELD(u16_t tag); + PACK_STRUCT_FIELD(u16_t len); +} PACK_STRUCT_STRUCT; +PACK_STRUCT_END +#ifdef PACK_STRUCT_USE_INCLUDES +# include "arch/epstruct.h" +#endif + + +#define PPPOE_STATE_INITIAL 0 +#define PPPOE_STATE_PADI_SENT 1 +#define PPPOE_STATE_PADR_SENT 2 +#define PPPOE_STATE_SESSION 3 +/* passive */ +#define PPPOE_STATE_PADO_SENT 1 + +#define PPPOE_HEADERLEN sizeof(struct pppoehdr) +#define PPPOE_VERTYPE 0x11 /* VER=1, TYPE = 1 */ + +#define PPPOE_TAG_EOL 0x0000 /* end of list */ +#define PPPOE_TAG_SNAME 0x0101 /* service name */ +#define PPPOE_TAG_ACNAME 0x0102 /* access concentrator name */ +#define PPPOE_TAG_HUNIQUE 0x0103 /* host unique */ +#define PPPOE_TAG_ACCOOKIE 0x0104 /* AC cookie */ +#define PPPOE_TAG_VENDOR 0x0105 /* vendor specific */ +#define PPPOE_TAG_RELAYSID 0x0110 /* relay session id */ +#define PPPOE_TAG_SNAME_ERR 0x0201 /* service name error */ +#define PPPOE_TAG_ACSYS_ERR 0x0202 /* AC system error */ +#define PPPOE_TAG_GENERIC_ERR 0x0203 /* gerneric error */ + +#define PPPOE_CODE_PADI 0x09 /* Active Discovery Initiation */ +#define PPPOE_CODE_PADO 0x07 /* Active Discovery Offer */ +#define PPPOE_CODE_PADR 0x19 /* Active Discovery Request */ +#define PPPOE_CODE_PADS 0x65 /* Active Discovery Session confirmation */ +#define PPPOE_CODE_PADT 0xA7 /* Active Discovery Terminate */ + +#ifndef PPPOE_MAX_AC_COOKIE_LEN +#define PPPOE_MAX_AC_COOKIE_LEN 64 +#endif + +struct pppoe_softc { + struct pppoe_softc *next; + struct netif *sc_ethif; /* ethernet interface we are using */ + ppp_pcb *pcb; /* PPP PCB */ + + struct eth_addr sc_dest; /* hardware address of concentrator */ + u16_t sc_session; /* PPPoE session id */ + u8_t sc_state; /* discovery phase or session connected */ + +#if PPPOE_SCNAME_SUPPORT + const char *sc_service_name; /* if != NULL: requested name of service */ + const char *sc_concentrator_name; /* if != NULL: requested concentrator id */ +#endif /* PPPOE_SCNAME_SUPPORT */ + u8_t sc_ac_cookie[PPPOE_MAX_AC_COOKIE_LEN]; /* content of AC cookie we must echo back */ + u8_t sc_ac_cookie_len; /* length of cookie data */ +#ifdef PPPOE_SERVER + u8_t *sc_hunique; /* content of host unique we must echo back */ + u8_t sc_hunique_len; /* length of host unique */ +#endif + u8_t sc_padi_retried; /* number of PADI retries already done */ + u8_t sc_padr_retried; /* number of PADR retries already done */ +}; + + +#define pppoe_init() /* compatibility define, no initialization needed */ + +ppp_pcb *pppoe_create(struct netif *pppif, + struct netif *ethif, + const char *service_name, const char *concentrator_name, + ppp_link_status_cb_fn link_status_cb, void *ctx_cb); + +/* + * Functions called from lwIP + * DO NOT CALL FROM lwIP USER APPLICATION. + */ +void pppoe_disc_input(struct netif *netif, struct pbuf *p); +void pppoe_data_input(struct netif *netif, struct pbuf *p); + +#ifdef __cplusplus +} +#endif + +#endif /* PPP_OE_H */ + +#endif /* PPP_SUPPORT && PPPOE_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppol2tp.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppol2tp.h new file mode 100644 index 000000000..1221ca15b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppol2tp.h @@ -0,0 +1,209 @@ +/** + * @file + * Network Point to Point Protocol over Layer 2 Tunneling Protocol header file. + * + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && PPPOL2TP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef PPPOL2TP_H +#define PPPOL2TP_H + +#include "ppp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Timeout */ +#define PPPOL2TP_CONTROL_TIMEOUT (5*1000) /* base for quick timeout calculation */ +#define PPPOL2TP_SLOW_RETRY (60*1000) /* persistent retry interval */ + +#define PPPOL2TP_MAXSCCRQ 4 /* retry SCCRQ four times (quickly) */ +#define PPPOL2TP_MAXICRQ 4 /* retry IRCQ four times */ +#define PPPOL2TP_MAXICCN 4 /* retry ICCN four times */ + +/* L2TP header flags */ +#define PPPOL2TP_HEADERFLAG_CONTROL 0x8000 +#define PPPOL2TP_HEADERFLAG_LENGTH 0x4000 +#define PPPOL2TP_HEADERFLAG_SEQUENCE 0x0800 +#define PPPOL2TP_HEADERFLAG_OFFSET 0x0200 +#define PPPOL2TP_HEADERFLAG_PRIORITY 0x0100 +#define PPPOL2TP_HEADERFLAG_VERSION 0x0002 + +/* Mandatory bits for control: Control, Length, Sequence, Version 2 */ +#define PPPOL2TP_HEADERFLAG_CONTROL_MANDATORY (PPPOL2TP_HEADERFLAG_CONTROL|PPPOL2TP_HEADERFLAG_LENGTH|PPPOL2TP_HEADERFLAG_SEQUENCE|PPPOL2TP_HEADERFLAG_VERSION) +/* Forbidden bits for control: Offset, Priority */ +#define PPPOL2TP_HEADERFLAG_CONTROL_FORBIDDEN (PPPOL2TP_HEADERFLAG_OFFSET|PPPOL2TP_HEADERFLAG_PRIORITY) + +/* Mandatory bits for data: Version 2 */ +#define PPPOL2TP_HEADERFLAG_DATA_MANDATORY (PPPOL2TP_HEADERFLAG_VERSION) + +/* AVP (Attribute Value Pair) header */ +#define PPPOL2TP_AVPHEADERFLAG_MANDATORY 0x8000 +#define PPPOL2TP_AVPHEADERFLAG_HIDDEN 0x4000 +#define PPPOL2TP_AVPHEADERFLAG_LENGTHMASK 0x03ff + +/* -- AVP - Message type */ +#define PPPOL2TP_AVPTYPE_MESSAGE 0 /* Message type */ + +/* Control Connection Management */ +#define PPPOL2TP_MESSAGETYPE_SCCRQ 1 /* Start Control Connection Request */ +#define PPPOL2TP_MESSAGETYPE_SCCRP 2 /* Start Control Connection Reply */ +#define PPPOL2TP_MESSAGETYPE_SCCCN 3 /* Start Control Connection Connected */ +#define PPPOL2TP_MESSAGETYPE_STOPCCN 4 /* Stop Control Connection Notification */ +#define PPPOL2TP_MESSAGETYPE_HELLO 6 /* Hello */ +/* Call Management */ +#define PPPOL2TP_MESSAGETYPE_OCRQ 7 /* Outgoing Call Request */ +#define PPPOL2TP_MESSAGETYPE_OCRP 8 /* Outgoing Call Reply */ +#define PPPOL2TP_MESSAGETYPE_OCCN 9 /* Outgoing Call Connected */ +#define PPPOL2TP_MESSAGETYPE_ICRQ 10 /* Incoming Call Request */ +#define PPPOL2TP_MESSAGETYPE_ICRP 11 /* Incoming Call Reply */ +#define PPPOL2TP_MESSAGETYPE_ICCN 12 /* Incoming Call Connected */ +#define PPPOL2TP_MESSAGETYPE_CDN 14 /* Call Disconnect Notify */ +/* Error reporting */ +#define PPPOL2TP_MESSAGETYPE_WEN 15 /* WAN Error Notify */ +/* PPP Session Control */ +#define PPPOL2TP_MESSAGETYPE_SLI 16 /* Set Link Info */ + +/* -- AVP - Result code */ +#define PPPOL2TP_AVPTYPE_RESULTCODE 1 /* Result code */ +#define PPPOL2TP_RESULTCODE 1 /* General request to clear control connection */ + +/* -- AVP - Protocol version (!= L2TP Header version) */ +#define PPPOL2TP_AVPTYPE_VERSION 2 +#define PPPOL2TP_VERSION 0x0100 /* L2TP Protocol version 1, revision 0 */ + +/* -- AVP - Framing capabilities */ +#define PPPOL2TP_AVPTYPE_FRAMINGCAPABILITIES 3 /* Bearer capabilities */ +#define PPPOL2TP_FRAMINGCAPABILITIES 0x00000003 /* Async + Sync framing */ + +/* -- AVP - Bearer capabilities */ +#define PPPOL2TP_AVPTYPE_BEARERCAPABILITIES 4 /* Bearer capabilities */ +#define PPPOL2TP_BEARERCAPABILITIES 0x00000003 /* Analog + Digital Access */ + +/* -- AVP - Tie breaker */ +#define PPPOL2TP_AVPTYPE_TIEBREAKER 5 + +/* -- AVP - Host name */ +#define PPPOL2TP_AVPTYPE_HOSTNAME 7 /* Host name */ +#define PPPOL2TP_HOSTNAME "lwIP" /* FIXME: make it configurable */ + +/* -- AVP - Vendor name */ +#define PPPOL2TP_AVPTYPE_VENDORNAME 8 /* Vendor name */ +#define PPPOL2TP_VENDORNAME "lwIP" /* FIXME: make it configurable */ + +/* -- AVP - Assign tunnel ID */ +#define PPPOL2TP_AVPTYPE_TUNNELID 9 /* Assign Tunnel ID */ + +/* -- AVP - Receive window size */ +#define PPPOL2TP_AVPTYPE_RECEIVEWINDOWSIZE 10 /* Receive window size */ +#define PPPOL2TP_RECEIVEWINDOWSIZE 8 /* FIXME: make it configurable */ + +/* -- AVP - Challenge */ +#define PPPOL2TP_AVPTYPE_CHALLENGE 11 /* Challenge */ + +/* -- AVP - Cause code */ +#define PPPOL2TP_AVPTYPE_CAUSECODE 12 /* Cause code*/ + +/* -- AVP - Challenge response */ +#define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE 13 /* Challenge response */ +#define PPPOL2TP_AVPTYPE_CHALLENGERESPONSE_SIZE 16 + +/* -- AVP - Assign session ID */ +#define PPPOL2TP_AVPTYPE_SESSIONID 14 /* Assign Session ID */ + +/* -- AVP - Call serial number */ +#define PPPOL2TP_AVPTYPE_CALLSERIALNUMBER 15 /* Call Serial Number */ + +/* -- AVP - Framing type */ +#define PPPOL2TP_AVPTYPE_FRAMINGTYPE 19 /* Framing Type */ +#define PPPOL2TP_FRAMINGTYPE 0x00000001 /* Sync framing */ + +/* -- AVP - TX Connect Speed */ +#define PPPOL2TP_AVPTYPE_TXCONNECTSPEED 24 /* TX Connect Speed */ +#define PPPOL2TP_TXCONNECTSPEED 100000000 /* Connect speed: 100 Mbits/s */ + +/* L2TP Session state */ +#define PPPOL2TP_STATE_INITIAL 0 +#define PPPOL2TP_STATE_SCCRQ_SENT 1 +#define PPPOL2TP_STATE_ICRQ_SENT 2 +#define PPPOL2TP_STATE_ICCN_SENT 3 +#define PPPOL2TP_STATE_DATA 4 + +#define PPPOL2TP_OUTPUT_DATA_HEADER_LEN 6 /* Our data header len */ + +/* + * PPPoL2TP interface control block. + */ +typedef struct pppol2tp_pcb_s pppol2tp_pcb; +struct pppol2tp_pcb_s { + ppp_pcb *ppp; /* PPP PCB */ + u8_t phase; /* L2TP phase */ + struct udp_pcb *udp; /* UDP L2TP Socket */ + struct netif *netif; /* Output interface, used as a default route */ + ip_addr_t remote_ip; /* LNS IP Address */ + u16_t remote_port; /* LNS port */ +#if PPPOL2TP_AUTH_SUPPORT + const u8_t *secret; /* Secret string */ + u8_t secret_len; /* Secret string length */ + u8_t secret_rv[16]; /* Random vector */ + u8_t challenge_hash[16]; /* Challenge response */ + u8_t send_challenge; /* Boolean whether the next sent packet should contains a challenge response */ +#endif /* PPPOL2TP_AUTH_SUPPORT */ + + u16_t tunnel_port; /* Tunnel port */ + u16_t our_ns; /* NS to peer */ + u16_t peer_nr; /* NR from peer */ + u16_t peer_ns; /* Expected NS from peer */ + u16_t source_tunnel_id; /* Tunnel ID assigned by peer */ + u16_t remote_tunnel_id; /* Tunnel ID assigned to peer */ + u16_t source_session_id; /* Session ID assigned by peer */ + u16_t remote_session_id; /* Session ID assigned to peer */ + + u8_t sccrq_retried; /* number of SCCRQ retries already done */ + u8_t icrq_retried; /* number of ICRQ retries already done */ + u8_t iccn_retried; /* number of ICCN retries already done */ +}; + + +/* Create a new L2TP session. */ +ppp_pcb *pppol2tp_create(struct netif *pppif, + struct netif *netif, const ip_addr_t *ipaddr, u16_t port, + const u8_t *secret, u8_t secret_len, + ppp_link_status_cb_fn link_status_cb, void *ctx_cb); + +#ifdef __cplusplus +} +#endif + +#endif /* PPPOL2TP_H */ +#endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppos.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppos.h new file mode 100644 index 000000000..380a965ce --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/pppos.h @@ -0,0 +1,126 @@ +/** + * @file + * Network Point to Point Protocol over Serial header file. + * + */ + +/* + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && PPPOS_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef PPPOS_H +#define PPPOS_H + +#include "lwip/sys.h" + +#include "ppp.h" +#include "vj.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* PPP packet parser states. Current state indicates operation yet to be + * completed. */ +enum { + PDIDLE = 0, /* Idle state - waiting. */ + PDSTART, /* Process start flag. */ + PDADDRESS, /* Process address field. */ + PDCONTROL, /* Process control field. */ + PDPROTOCOL1, /* Process protocol field 1. */ + PDPROTOCOL2, /* Process protocol field 2. */ + PDDATA /* Process data byte. */ +}; + +/* PPPoS serial output callback function prototype */ +typedef u32_t (*pppos_output_cb_fn)(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx); + +/* + * Extended asyncmap - allows any character to be escaped. + */ +typedef u8_t ext_accm[32]; + +/* + * PPPoS interface control block. + */ +typedef struct pppos_pcb_s pppos_pcb; +struct pppos_pcb_s { + /* -- below are data that will NOT be cleared between two sessions */ + ppp_pcb *ppp; /* PPP PCB */ + pppos_output_cb_fn output_cb; /* PPP serial output callback */ + + /* -- below are data that will be cleared between two sessions + * + * last_xmit must be the first member of cleared members, because it is + * used to know which part must not be cleared. + */ + u32_t last_xmit; /* Time of last transmission. */ + ext_accm out_accm; /* Async-Ctl-Char-Map for output. */ + + /* flags */ + unsigned int open :1; /* Set if PPPoS is open */ + unsigned int pcomp :1; /* Does peer accept protocol compression? */ + unsigned int accomp :1; /* Does peer accept addr/ctl compression? */ + + /* PPPoS rx */ + ext_accm in_accm; /* Async-Ctl-Char-Map for input. */ + struct pbuf *in_head, *in_tail; /* The input packet. */ + u16_t in_protocol; /* The input protocol code. */ + u16_t in_fcs; /* Input Frame Check Sequence value. */ + u8_t in_state; /* The input process state. */ + u8_t in_escaped; /* Escape next character. */ +}; + +/* Create a new PPPoS session. */ +ppp_pcb *pppos_create(struct netif *pppif, pppos_output_cb_fn output_cb, + ppp_link_status_cb_fn link_status_cb, void *ctx_cb); + +#if !NO_SYS && !PPP_INPROC_IRQ_SAFE +/* Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. */ +err_t pppos_input_tcpip(ppp_pcb *ppp, u8_t *s, int l); +#endif /* !NO_SYS && !PPP_INPROC_IRQ_SAFE */ + +/* PPP over Serial: this is the input function to be called for received data. */ +void pppos_input(ppp_pcb *ppp, u8_t* data, int len); + + +/* + * Functions called from lwIP + * DO NOT CALL FROM lwIP USER APPLICATION. + */ +#if !NO_SYS && !PPP_INPROC_IRQ_SAFE +err_t pppos_input_sys(struct pbuf *p, struct netif *inp); +#endif /* !NO_SYS && !PPP_INPROC_IRQ_SAFE */ + +#ifdef __cplusplus +} +#endif + +#endif /* PPPOS_H */ +#endif /* PPP_SUPPORT && PPPOL2TP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/upap.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/upap.h new file mode 100644 index 000000000..540d98149 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/upap.h @@ -0,0 +1,131 @@ +/* + * upap.h - User/Password Authentication Protocol definitions. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * $Id: upap.h,v 1.8 2002/12/04 23:03:33 paulus Exp $ + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && PAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef UPAP_H +#define UPAP_H + +#include "ppp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Packet header = Code, id, length. + */ +#define UPAP_HEADERLEN 4 + + +/* + * UPAP codes. + */ +#define UPAP_AUTHREQ 1 /* Authenticate-Request */ +#define UPAP_AUTHACK 2 /* Authenticate-Ack */ +#define UPAP_AUTHNAK 3 /* Authenticate-Nak */ + + +/* + * Client states. + */ +#define UPAPCS_INITIAL 0 /* Connection down */ +#define UPAPCS_CLOSED 1 /* Connection up, haven't requested auth */ +#define UPAPCS_PENDING 2 /* Connection down, have requested auth */ +#define UPAPCS_AUTHREQ 3 /* We've sent an Authenticate-Request */ +#define UPAPCS_OPEN 4 /* We've received an Ack */ +#define UPAPCS_BADAUTH 5 /* We've received a Nak */ + +/* + * Server states. + */ +#define UPAPSS_INITIAL 0 /* Connection down */ +#define UPAPSS_CLOSED 1 /* Connection up, haven't requested auth */ +#define UPAPSS_PENDING 2 /* Connection down, have requested auth */ +#define UPAPSS_LISTEN 3 /* Listening for an Authenticate */ +#define UPAPSS_OPEN 4 /* We've sent an Ack */ +#define UPAPSS_BADAUTH 5 /* We've sent a Nak */ + + +/* + * Timeouts. + */ +#if 0 /* moved to ppp_opts.h */ +#define UPAP_DEFTIMEOUT 3 /* Timeout (seconds) for retransmitting req */ +#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ +#endif /* moved to ppp_opts.h */ + +/* + * Each interface is described by upap structure. + */ +#if PAP_SUPPORT +typedef struct upap_state { + const char *us_user; /* User */ + u8_t us_userlen; /* User length */ + const char *us_passwd; /* Password */ + u8_t us_passwdlen; /* Password length */ + u8_t us_clientstate; /* Client state */ +#if PPP_SERVER + u8_t us_serverstate; /* Server state */ +#endif /* PPP_SERVER */ + u8_t us_id; /* Current id */ + u8_t us_transmits; /* Number of auth-reqs sent */ +} upap_state; +#endif /* PAP_SUPPORT */ + + +void upap_authwithpeer(ppp_pcb *pcb, const char *user, const char *password); +#if PPP_SERVER +void upap_authpeer(ppp_pcb *pcb); +#endif /* PPP_SERVER */ + +extern const struct protent pap_protent; + +#ifdef __cplusplus +} +#endif + +#endif /* UPAP_H */ +#endif /* PPP_SUPPORT && PAP_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/vj.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/vj.h new file mode 100644 index 000000000..77d9976c5 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/ppp/vj.h @@ -0,0 +1,169 @@ +/* + * Definitions for tcp compression routines. + * + * $Id: vj.h,v 1.7 2010/02/22 17:52:09 goldsimon Exp $ + * + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: + * - Initial distribution. + */ + +#include "netif/ppp/ppp_opts.h" +#if PPP_SUPPORT && VJ_SUPPORT /* don't build if not configured for use in lwipopts.h */ + +#ifndef VJ_H +#define VJ_H + +#include "lwip/ip.h" +#include "lwip/priv/tcp_priv.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_SLOTS 16 /* must be > 2 and < 256 */ +#define MAX_HDR 128 + +/* + * Compressed packet format: + * + * The first octet contains the packet type (top 3 bits), TCP + * 'push' bit, and flags that indicate which of the 4 TCP sequence + * numbers have changed (bottom 5 bits). The next octet is a + * conversation number that associates a saved IP/TCP header with + * the compressed packet. The next two octets are the TCP checksum + * from the original datagram. The next 0 to 15 octets are + * sequence number changes, one change per bit set in the header + * (there may be no changes and there are two special cases where + * the receiver implicitly knows what changed -- see below). + * + * There are 5 numbers which can change (they are always inserted + * in the following order): TCP urgent pointer, window, + * acknowlegement, sequence number and IP ID. (The urgent pointer + * is different from the others in that its value is sent, not the + * change in value.) Since typical use of SLIP links is biased + * toward small packets (see comments on MTU/MSS below), changes + * use a variable length coding with one octet for numbers in the + * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the + * range 256 - 65535 or 0. (If the change in sequence number or + * ack is more than 65535, an uncompressed packet is sent.) + */ + +/* + * Packet types (must not conflict with IP protocol version) + * + * The top nibble of the first octet is the packet type. There are + * three possible types: IP (not proto TCP or tcp with one of the + * control flags set); uncompressed TCP (a normal IP/TCP packet but + * with the 8-bit protocol field replaced by an 8-bit connection id -- + * this type of packet syncs the sender & receiver); and compressed + * TCP (described above). + * + * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and + * is logically part of the 4-bit "changes" field that follows. Top + * three bits are actual packet type. For backward compatibility + * and in the interest of conserving bits, numbers are chosen so the + * IP protocol version number (4) which normally appears in this nibble + * means "IP packet". + */ + +/* packet types */ +#define TYPE_IP 0x40 +#define TYPE_UNCOMPRESSED_TCP 0x70 +#define TYPE_COMPRESSED_TCP 0x80 +#define TYPE_ERROR 0x00 + +/* Bits in first octet of compressed packet */ +#define NEW_C 0x40 /* flag bits for what changed in a packet */ +#define NEW_I 0x20 +#define NEW_S 0x08 +#define NEW_A 0x04 +#define NEW_W 0x02 +#define NEW_U 0x01 + +/* reserved, special-case values of above */ +#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ +#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ +#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) + +#define TCP_PUSH_BIT 0x10 + + +/* + * "state" data for each active tcp conversation on the wire. This is + * basically a copy of the entire IP/TCP header from the last packet + * we saw from the conversation together with a small identifier + * the transmit & receive ends of the line use to locate saved header. + */ +struct cstate { + struct cstate *cs_next; /* next most recently used state (xmit only) */ + u16_t cs_hlen; /* size of hdr (receive only) */ + u8_t cs_id; /* connection # associated with this state */ + u8_t cs_filler; + union { + char csu_hdr[MAX_HDR]; + struct ip_hdr csu_ip; /* ip/tcp hdr from most recent packet */ + } vjcs_u; +}; +#define cs_ip vjcs_u.csu_ip +#define cs_hdr vjcs_u.csu_hdr + + +struct vjstat { + u32_t vjs_packets; /* outbound packets */ + u32_t vjs_compressed; /* outbound compressed packets */ + u32_t vjs_searches; /* searches for connection state */ + u32_t vjs_misses; /* times couldn't find conn. state */ + u32_t vjs_uncompressedin; /* inbound uncompressed packets */ + u32_t vjs_compressedin; /* inbound compressed packets */ + u32_t vjs_errorin; /* inbound unknown type packets */ + u32_t vjs_tossed; /* inbound packets tossed because of error */ +}; + +/* + * all the state data for one serial line (we need one of these per line). + */ +struct vjcompress { + struct cstate *last_cs; /* most recently used tstate */ + u8_t last_recv; /* last rcvd conn. id */ + u8_t last_xmit; /* last sent conn. id */ + u16_t flags; + u8_t maxSlotIndex; + u8_t compressSlot; /* Flag indicating OK to compress slot ID. */ +#if LINK_STATS + struct vjstat stats; +#endif + struct cstate tstate[MAX_SLOTS]; /* xmit connection states */ + struct cstate rstate[MAX_SLOTS]; /* receive connection states */ +}; + +/* flag values */ +#define VJF_TOSS 1U /* tossing rcvd frames because of input err */ + +extern void vj_compress_init (struct vjcompress *comp); +extern u8_t vj_compress_tcp (struct vjcompress *comp, struct pbuf **pb); +extern void vj_uncompress_err (struct vjcompress *comp); +extern int vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp); +extern int vj_uncompress_tcp (struct pbuf **nb, struct vjcompress *comp); + +#ifdef __cplusplus +} +#endif + +#endif /* VJ_H */ + +#endif /* PPP_SUPPORT && VJ_SUPPORT */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/slipif.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/slipif.h new file mode 100644 index 000000000..65ba31f83 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/slipif.h @@ -0,0 +1,87 @@ +/** + * @file + * + * SLIP netif API + */ + +/* + * Copyright (c) 2001, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Adam Dunkels + * + */ +#ifndef LWIP_HDR_NETIF_SLIPIF_H +#define LWIP_HDR_NETIF_SLIPIF_H + +#include "lwip/opt.h" +#include "lwip/netif.h" + +/** Set this to 1 to start a thread that blocks reading on the serial line + * (using sio_read()). + */ +#ifndef SLIP_USE_RX_THREAD +#define SLIP_USE_RX_THREAD !NO_SYS +#endif + +/** Set this to 1 to enable functions to pass in RX bytes from ISR context. + * If enabled, slipif_received_byte[s]() process incoming bytes and put assembled + * packets on a queue, which is fed into lwIP from slipif_poll(). + * If disabled, slipif_poll() polls the serial line (using sio_tryread()). + */ +#ifndef SLIP_RX_FROM_ISR +#define SLIP_RX_FROM_ISR 0 +#endif + +/** Set this to 1 (default for SLIP_RX_FROM_ISR) to queue incoming packets + * received by slipif_received_byte[s]() as long as PBUF_POOL pbufs are available. + * If disabled, packets will be dropped if more than one packet is received. + */ +#ifndef SLIP_RX_QUEUE +#define SLIP_RX_QUEUE SLIP_RX_FROM_ISR +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +err_t slipif_init(struct netif * netif); +void slipif_poll(struct netif *netif); +#if SLIP_RX_FROM_ISR +void slipif_process_rxqueue(struct netif *netif); +void slipif_received_byte(struct netif *netif, u8_t data); +void slipif_received_bytes(struct netif *netif, u8_t *data, u8_t len); +#endif /* SLIP_RX_FROM_ISR */ + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_HDR_NETIF_SLIPIF_H */ + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/zepif.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/zepif.h new file mode 100644 index 000000000..2a801b4c4 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/4gsdk/cat1Service/lwip/src/include/netif/zepif.h @@ -0,0 +1,81 @@ +/** + * @file + * + * A netif implementing the ZigBee Eencapsulation Protocol (ZEP). + * This is used to tunnel 6LowPAN over UDP. + */ + +/* + * Copyright (c) 2018 Simon Goldschmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * This file is part of the lwIP TCP/IP stack. + * + * Author: Simon Goldschmidt + * + */ + +#ifndef LWIP_HDR_ZEPIF_H +#define LWIP_HDR_ZEPIF_H + +#include "lwip/opt.h" +#include "netif/lowpan6.h" + +#if LWIP_IPV6 && LWIP_UDP /* don't build if not configured for use in lwipopts.h */ + +#include "lwip/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZEPIF_DEFAULT_UDP_PORT 17754 + +/** Pass this struct as 'state' to netif_add to control the behaviour + * of this netif. If NULL is passed, default behaviour is chosen */ +struct zepif_init { + /** The UDP port used to ZEP frames from (0 = default) */ + u16_t zep_src_udp_port; + /** The UDP port used to ZEP frames to (0 = default) */ + u16_t zep_dst_udp_port; + /** The IP address to sed ZEP frames from (NULL = ANY) */ + const ip_addr_t *zep_src_ip_addr; + /** The IP address to sed ZEP frames to (NULL = BROADCAST) */ + const ip_addr_t *zep_dst_ip_addr; + /** If != NULL, the udp pcb is bound to this netif */ + const struct netif *zep_netif; + /** MAC address of the 6LowPAN device */ + u8_t addr[6]; +}; + +err_t zepif_init(struct netif *netif); + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_IPV6 && LWIP_UDP */ + +#endif /* LWIP_HDR_ZEPIF_H */ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/CMakeLists.txt new file mode 100644 index 000000000..32a2b0399 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/CMakeLists.txt @@ -0,0 +1,13 @@ +add_subdirectory_if_exist(services) +add_subdirectory_if_exist(utils) +add_subdirectory_if_exist(utilscpp) +add_subdirectory_if_exist(drivers) +add_subdirectory_if_exist(config) +add_subdirectory_if_exist(UI) + +if("TEST_4G_SDK" IN_LIST DEFINES) + add_subdirectory_if_exist(4gsdk) +else() + add_subdirectory_if_exist(4g) +endif() +add_subdirectory_if_exist(4gTest) diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/CMakeLists.txt new file mode 100644 index 000000000..999c1598a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/CMakeLists.txt @@ -0,0 +1,12 @@ +#=============================================================================== +# @brief cmake make file +# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== +# add_subdirectory(hal ${PROJECT_BINARY_DIR}/hal) +add_subdirectory_if_exist(charger) +add_subdirectory_if_exist(gnss) +add_subdirectory_if_exist(battery) +add_subdirectory_if_exist(ble_service) +add_subdirectory_if_exist(factorytest_service) +add_subdirectory_if_exist(hid_service) + diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/CMakeLists.txt b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/CMakeLists.txt new file mode 100644 index 000000000..0fa6c1305 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/CMakeLists.txt @@ -0,0 +1,62 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== + +set(COMPONENT_NAME "batterry_service") + +set(PUBLIC_HEADER +${CMAKE_CURRENT_SOURCE_DIR}/hal +${CMAKE_CURRENT_SOURCE_DIR}/service +) + +set(PRIVATE_HEADER + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits + ${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include +) + +set(SOURCES +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -std=c++11 + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-c++11-narrowing + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES +SUPPORT_BATTERY_SERVICE +SUPPORT_AT_BATTERY +) + +set(PRIVATE_DEFINES +) + +if("SUPPORT_BATTERY_SERVICE" IN_LIST DEFINES) + find_library(LIB_PATH_BATTERY lib/libbatterry_service.a ${CMAKE_CURRENT_SOURCE_DIR}) + target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_BATTERY} PRIVATE -Wl,--whole-archive) +endif() +build_component() diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/hal/battery_hal.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/hal/battery_hal.h new file mode 100644 index 000000000..749061ac1 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/hal/battery_hal.h @@ -0,0 +1,54 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Test adc header \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-08-16, Create file. \n + */ + +#ifndef BATTERY_HAL_H__ +#define BATTERY_HAL_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "adc_porting.h" + +typedef struct { + float battery_voltage; + float battery_ntc_temp; + float pcb_ntc_temp; + bool usb_plugged; +} battery_info_t; + +#define ADC_CHANNEL_BAT_VOLTAGE ADC_CHANNEL_2 +#define ADC_CHANNEL_BAT_TEMP ADC_CHANNEL_0 +#define ADC_CHANNEL_PCB_TEMP ADC_CHANNEL_5 + + +uint8_t battery_get_battery_temp(float *temp); +uint8_t battery_get_pcb_temp(float *temp); +/** + * return 电池百分比 0~100 + * 参数指针返回 真实电压 voltage +*/ +uint8_t battery_get_voltage(float *voltage); + +/** + * return 0 not charged, 1 charging +*/ +uint8_t get_charge_stat(void); + +void battery_percent_init(uint8_t percent); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/lib/libbatterry_service.a b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/lib/libbatterry_service.a new file mode 100644 index 000000000..9757c9662 Binary files /dev/null and b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/lib/libbatterry_service.a differ diff --git a/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/service/battery_service.h b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/service/battery_service.h new file mode 100644 index 000000000..d536090a6 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_new/code/sdk/zhihui/services/battery/service/battery_service.h @@ -0,0 +1,69 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-10-25 14:42:28 + * @LastEditors: SnickerSun snickersun@163.com + * @LastEditTime: 2025-01-23 09:36:05 + * @FilePath: /FD230/code/sdk/application/battery/service/battery_service.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Test adc header \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-08-16, Create file. \n + */ + +#ifndef BATTERY_SERVICE_H__ +#define BATTERY_SERVICE_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + +#pragma pack(1) +typedef struct +{ + uint32_t tm; + float voltage; //电压 + uint8_t percent;// 电量 + uint8_t stat;// 充电状态 +}BATTERY_DATA_T; +#pragma pack() + + +#define BATTERY_CMD_SAVE_PERCENT 0x16 +#define BATTERY_CMD_START_AGING_TEST 0x17 +#define BATTERY_CMD_STOP_AGING_TEST 0x18 + +uint8_t batteryservice_get_battery_temp(float *temp); +uint8_t batteryservice_get_pcb_temp(float *temp); +uint8_t batteryservice_get_voltage(float *voltage); +errcode_t uapi_battery_init(void); +void uapi_battery_deinit(void); +void battery_service_resume(void); +void battery_service_suspend(void); +errcode_t low_power_play_toUI(uint8_t alarm_level); +void enable_02c(void); +void disable_02c(void); +void enable_charge(void); +void disable_charge(void); +void set_lowpower_show( uint8_t type,uint8_t data); +uint8_t battery_get_percent_onstart(void); +//0 停止充电 , 1 低电流充电, 2 正常电流充电 +int get_charge_current_status(void); +uint8_t get_02c_value(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/CMakeLists.txt b/sdk_release/v1.0/4gsdk_old/code/sdk/CMakeLists.txt new file mode 100644 index 000000000..5f36c9dce --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/CMakeLists.txt @@ -0,0 +1,109 @@ +#=============================================================================== +# @brief cmake entry +# Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== +cmake_minimum_required(VERSION 3.14.1) +set(CMAKE_SYSTEM_NAME "Generic") + +if(NOT DEFINED CHIP) + message(FATAL_ERROR "Chip is not defined ") +endif() + +set(Python3_EXECUTABLE ${PY_PATH}) +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) +endif(CCACHE_FOUND) + +# default hso module_name & AUTO_DEF_FILE_ID, redefine these var in sub cmake file will +# override these value just in sub directory but not others +set(MODULE_NAME "pf") +set(AUTO_DEF_FILE_ID TRUE) + +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) +get_filename_component(ROOT_DIR "${PROJECT_SOURCE_DIR}" ABSOLUTE) +set(CMAKE_DIR "${ROOT_DIR}/build/cmake") +set(BIN_DIR "${ROOT_DIR}/interim_binary") + +include("${CMAKE_DIR}/build_function.cmake") +include("${CMAKE_DIR}/global_variable.cmake") +include("${CMAKE_DIR}/build_script.cmake") +include("${CMAKE_DIR}/build_command.cmake") +include("${CMAKE_DIR}/build_hso_database.cmake") +include("${CMAKE_DIR}/build_component.cmake") +include("${CMAKE_DIR}/build_sdk.cmake") + +if(${BUILD_TYPE} STREQUAL "UT") + KCONFIG_GET_PARAMS("${ROOT_DIR}/build/menuconfig/test/platform/ut.config") + include("${CMAKE_DIR}/build_ut.cmake") + return() +endif() + +if(${BUILD_TYPE} STREQUAL "FUZZ") + KCONFIG_GET_PARAMS("${ROOT_DIR}/build/menuconfig/test/platform/ut.config") + include("${CMAKE_DIR}/build_fuzz.cmake") + return() +endif() + +project(${CHIP}_CFBB C ASM CXX) +set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "") + +if(EXISTS ${CMAKE_BINARY_DIR}/auto_gen_libfunc.lds) + file(REMOVE ${CMAKE_BINARY_DIR}/auto_gen_libfunc.lds) +endif() + +set(TARGET_COMPONENT "${RAM_COMPONENT}" "${ROM_COMPONENT}") +set(TARGET_NAME ${BIN_NAME}) +file(WRITE ${PROJECT_BINARY_DIR}/temp/__null___.c "int __null___(void) {return 0;}") +add_executable(${BIN_NAME} ${PROJECT_BINARY_DIR}/temp/__null___.c) +set_target_properties(${BIN_NAME} PROPERTIES RUNTIME_OUTPUT_NAME ${BIN_NAME}.elf) +target_compile_options(${BIN_NAME} PRIVATE "${CCFLAGS}") + +include("${CMAKE_DIR}/build_rom_callback.cmake") +if(${BUILD_ROM_CALLBACK}) + build_rom_callback() +endif() + +set(KCONFIG_PATH "${ROOT_DIR}/build/config/target_config/${CHIP}/menuconfig/${CORE}/${BUILD_TARGET_NAME}.config") +if(EXISTS ${KCONFIG_PATH}) + KCONFIG_GET_PARAMS(${KCONFIG_PATH}) + set(USE_KCONFIG True) +endif() + +add_subdirectory_if_exist(application) +add_subdirectory_if_exist(bt) +add_subdirectory_if_exist(bootloader) +add_subdirectory_if_exist(kernel) +add_subdirectory_if_exist(drivers) +add_subdirectory_if_exist(middleware) +add_subdirectory_if_exist(open_source) +add_subdirectory_if_exist(protocol) +add_subdirectory_if_exist(test) +add_subdirectory_if_exist(include) +add_subdirectory_if_exist(vendor) + +include("${CMAKE_DIR}/open_source.cmake") +include("${CMAKE_DIR}/build_linker.cmake") + +if (NOT DEFINED ROM_COMPONENT) +add_custom_target(GENERAT_BIN ALL + COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary -R .logstr -R .ARM -R .ARM ${TARGET_NAME}.elf ${TARGET_NAME}.bin + COMMENT "post_build:gen bin file" + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${TARGET_NAME} +) +else() +add_custom_target(GENERAT_BIN ALL + COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary -R .logstr -R .ARM.exidx -R .ARM.extab -R .*_romtext ${TARGET_NAME}.elf ${TARGET_NAME}.bin + COMMAND ${CMAKE_OBJCOPY} --gap-fill 0xFF -O binary -j .*_romtext ${TARGET_NAME}.elf ${TARGET_NAME}_rom.bin + COMMENT "post_build:gen rom and ram bin file" + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + DEPENDS ${TARGET_NAME} +) +endif() + +include("${CMAKE_DIR}/build_ssb.cmake") +include("${CMAKE_DIR}/build_elf_info.cmake") + +create_hso_db() +generate_project_file() diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/audio/vendor/CMakeLists.txt b/sdk_release/v1.0/4gsdk_old/code/sdk/application/audio/vendor/CMakeLists.txt new file mode 100644 index 000000000..e3152c2ca --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/audio/vendor/CMakeLists.txt @@ -0,0 +1,57 @@ +#[[ +Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. +Description: CMake audio sample module. +Author: audio +Create: 2023-06-09 +]] + +set(SAP_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../drivers/drivers/driver/audio/source) +#=================================================================================== +include(${SAP_TOP_DIR}/build/cmake/audio_config.cmake) +#=================================================================================== +set(COMPONENT_NAME audio_vendor) +set(MODULE_NAME "dsp") +set(AUTO_DEF_FILE_ID TRUE) +#=================================================================================== +set(COMPONENT_SRC ) +#=================================================================================== +set(COMPONENT_INC + ${SAP_UAPI_DIR} + ${SAP_TOP_DIR}/include + ${SAP_TOP_DIR}/drv/vendor + ${SAP_TOP_DIR}/drv/include + ${SAP_TOP_DIR}/drv/common/include + ${SAP_TOP_DIR}/drv/arch/include + ${SAP_TOP_DIR}/drv/arch/${CFG_SAP_CHIP_TYPE}/include + ${SAP_TOP_DIR}/core/include + ${SAP_TOP_DIR}/core/common/include + ${SAP_TOP_DIR}/core/arch/${CFG_SAP_CHIP_TYPE}/include + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/common +) +#=================================================================================== +if("${CFG_SAP_VENDOR_DRIVER_AW88262_SUPPORT}" STREQUAL "y") +set(COMPONENT_SRC ${COMPONENT_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/aw88262/aw88262.c +) +set(COMPONENT_INC ${COMPONENT_INC} + ${CMAKE_CURRENT_SOURCE_DIR}/aw88262 +) +endif() + +if("${CFG_SAP_VENDOR_DRIVER_ANC_CODEC_SUPPORT}" STREQUAL "y") +set(COMPONENT_SRC ${COMPONENT_SRC} + ${CMAKE_CURRENT_SOURCE_DIR}/anc_codec/anc_codec.c +) +set(COMPONENT_INC ${COMPONENT_INC} + ${CMAKE_CURRENT_SOURCE_DIR}/anc_codec + ${CMAKE_CURRENT_SOURCE_DIR}/anc_codec/sai01_dac_32.768k +) +endif() +#=================================================================================== +set(COMPONENT_DEF + "SAP_PROC_SUPPORT" +) +#=================================================================================== +include(${SAP_TOP_DIR}/build/cmake/audio_common.cmake) +install_sdk(${CMAKE_CURRENT_SOURCE_DIR}/aw88166 "*") diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/audio/vendor/aw88166/aw88166.c b/sdk_release/v1.0/4gsdk_old/code/sdk/application/audio/vendor/aw88166/aw88166.c new file mode 100644 index 000000000..d25e8db7f --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/audio/vendor/aw88166/aw88166.c @@ -0,0 +1,278 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved. + * Description: source file for aw88166 driver + */ + +#include +#include "soc_osal.h" +#include "audio_debug.h" +#include "gpio.h" +#include "hal_gpio.h" +#include "i2c.h" +#include "pinctrl.h" +#include "vendor_common.h" +#include "soc_uapi_vendor.h" + +#include "aw883xx_init.h" +#include "aw883xx.h" +#include "aw_params.h" + +static td_bool g_aw88166_i2c_inited = TD_FALSE; + +#define AW88166_PWR_ON_PIN S_MGPIO4 +#define AW88166_I2C_BUS_ID I2C_BUS_0 +#define AW88166_I2C_DEV_ADDR 0x34 + +static td_s32 aw_dev0_i2c_write_func(td_u16 dev_addr, td_u8 reg_addr, td_u8 *pdata, td_u16 len) +{ + td_s32 ret; + i2c_data_t data; + const td_u8 reg_addr_len = sizeof(reg_addr); /* data len of reg_addr */ + const td_u8 send_len = len + reg_addr_len; /* pdata bytes && reg_addr len */ + td_u8 *send_data = osal_kmalloc_align(send_len, 0, 8); /* 8 : Align up to 8 bytes */ + + if (send_data == TD_NULL) { + ret = -1; /* -1:FAILED ERR CODE */ + vendor_log_fun_err(malloc, ret); + return ret; + } + + /* pack reg addr & reg data */ + *send_data = reg_addr; /* reg_addr */ + ret = memcpy_s(send_data + reg_addr_len, (send_len - reg_addr_len), pdata, len); /* pdata */ + if (ret != EOK) { + vendor_log_fun_err(memcpy_s, ret); + goto out; + } + + data.send_buf = send_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; + ret = (td_s32)uapi_i2c_master_write(AW88166_I2C_BUS_ID, dev_addr, &data); + if (ret != ERRCODE_SUCC) { + vendor_log_fun_err(uapi_i2c_master_write, ret); + goto out; + } + +out: + if (send_data != TD_NULL) { + osal_kfree(send_data); + } + return ret; +} + +static td_s32 aw_dev0_i2c_read_func(td_u16 dev_addr, td_u8 reg_addr, td_u8 *pdata, td_u16 len) +{ + td_s32 ret; + + i2c_data_t data; + + data.send_buf = ®_addr; + data.send_len = sizeof(reg_addr); + data.receive_buf = pdata; + data.receive_len = len; + ret = (td_s32)uapi_i2c_master_writeread(AW88166_I2C_BUS_ID, dev_addr, &data); + if (ret != ERRCODE_SUCC) { + vendor_log_fun_err(uapi_i2c_master_writeread, ret); + return ret; + } + + return AUDIO_SUCCESS; +} + +static td_void aw_dev0_reset_gpio_ctl(bool state) +{ + uapi_gpio_set_val(AW88166_PWR_ON_PIN, state); +} + +static td_void aw88166_pwr_on_pin_init(td_void) +{ + uapi_gpio_set_dir(AW88166_PWR_ON_PIN, GPIO_DIRECTION_OUTPUT); +} + +static td_s32 aw88166_i2c_init(td_void) +{ + td_s32 ret; + audio_func_enter(); + + /* init i2c */ + vendor_trace_log_u32(AW88166_I2C_BUS_ID); + ret = (td_s32)uapi_i2c_master_init(AW88166_I2C_BUS_ID, I2C_BAUDRATE, I2C_HIGH_SPEED_CODE); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(uapi_i2c_master_init, ret); + return ret; + } + + vendor_printf("aw88166 i2c init success\n"); + audio_func_exit(); + return AUDIO_SUCCESS; +} + +static td_s32 aw88166_i2c_deinit(td_void) +{ + td_s32 ret; + audio_func_enter(); + + /* deinit i2c */ + vendor_trace_log_u32(AW88166_I2C_BUS_ID); + ret = (td_s32)uapi_i2c_deinit(AW88166_I2C_BUS_ID); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(uapi_i2c_deinit, ret); + return ret; + } + + vendor_printf("aw88166 i2c deinit success\n"); + audio_func_exit(); + return AUDIO_SUCCESS; +} + +td_s32 aw883xx_pid_2066_dev_init(td_void *aw883xx); + +struct aw_init_info init_info[] = { + { + .dev = AW_DEV_0, + .i2c_addr = AW88166_I2C_DEV_ADDR, + .re_min = 2000, /* awinic:If the re_min(ohms) and re_max(ohms) are not set, the default value is used */ + .re_max = 39000, + .mix_chip_count = AW_DEV0_MIX_CHIP_NUM, + .prof_info = g_dev0_prof_info, + .i2c_read_func = aw_dev0_i2c_read_func, + .i2c_write_func = aw_dev0_i2c_write_func, + .reset_gpio_ctl = aw_dev0_reset_gpio_ctl, + .dev_init_ops = {aw883xx_pid_2066_dev_init}, + } +}; + +static td_s32 audio_aw88166_configuration(const uapi_vendor_codec_attr *attr) +{ + td_s32 ret; + + /* awinic:Control interface of dev0 */ + /* awinic:initialization */ + ret = aw883xx_smartpa_init((td_void *)&init_info[AW_DEV_0]); + if (ret != AUDIO_SUCCESS) { + vendor_printf("aw883xx_smartpa_init already init\n"); + } + /* awinic:set mode "Music", "aw_params.h" contains id information */ + ret = aw883xx_set_profile_byname(AW_DEV_0, "Music"); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_set_profile_byname, ret); + } + + vendor_unused(attr); + return ret; +} + +static td_s32 audio_aw88166_deconfiguration(td_void) +{ + /* awinic:Free the requested memory when PA is not used */ + aw883xx_smartpa_deinit(AW_DEV_0); + + return AUDIO_SUCCESS; +} + +td_s32 audio_aw88166_init(const uapi_vendor_codec_attr *attr) +{ + td_s32 ret; + + audio_func_enter(); + + aw88166_pwr_on_pin_init(); + + if (g_aw88166_i2c_inited != TD_TRUE) { + ret = aw88166_i2c_init(); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw88166_i2c_init, ret); + return ret; + } + g_aw88166_i2c_inited = TD_TRUE; + } else { + ret = 0; + } + + ret = audio_aw88166_configuration(attr); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(audio_aw88166_configuration, ret); + } + + return AUDIO_SUCCESS; +} + +td_s32 audio_aw88166_deinit(td_void) +{ + td_s32 ret; + audio_func_enter(); + + ret = audio_aw88166_deconfiguration(); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(audio_aw88166_deconfiguration, ret); + } + + if (g_aw88166_i2c_inited != TD_FALSE) { + ret = aw88166_i2c_deinit(); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw88166_i2c_deinit, ret); + return ret; + } + g_aw88166_i2c_inited = TD_FALSE; + } else { + ret = AUDIO_SUCCESS; + } + + audio_func_exit(); + return ret; +} + +td_s32 audio_aw88166_start(const uapi_vendor_codec_attr *attr) +{ + td_s32 ret; + + audio_func_enter(); + + /* awinic:The platform needs to output I2s first, and then ctl start */ + ret = aw883xx_ctrl_state(AW_DEV_0, AW_START); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_ctrl_state, ret); + } + + vendor_unused(attr); + return ret; +} + +td_s32 audio_aw88166_stop(td_void) +{ + td_s32 ret; + audio_func_enter(); + + /* awinic:The platform needs to control the stop first and then stop I2S */ + ret = aw883xx_ctrl_state(AW_DEV_0, AW_STOP); + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_ctrl_state, ret); + } + audio_func_exit(); + return ret; +} + +td_s32 audio_aw88166_set_aef_profile(uapi_snd_aef_profile aef_profile) +{ + td_s32 ret; + + audio_func_enter(); + + /* awinic:set mode "Receiver"/"Music", "aw_params.h" contains id information */ + if (aef_profile == UAPI_SND_AEF_PROFILE_VOIP) { + /* awinic:set mode "Receiver" */ + ret = aw883xx_set_profile_byname(AW_DEV_0, "Receiver"); + } else { + /* awinic:set mode "Music" */ + ret = aw883xx_set_profile_byname(AW_DEV_0, "Music"); + } + + if (ret != AUDIO_SUCCESS) { + vendor_log_fun_err(aw883xx_set_profile_byname, ret); + } + + audio_func_exit(); + return ret; +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/service_init.c b/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/service_init.c new file mode 100644 index 000000000..5117abb9d --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/service_init.c @@ -0,0 +1,131 @@ + +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Application core board init function for standard + * Author: + * Create: + */ + +#ifdef __LITEOS__ +#include "partition.h" +#endif +#include "pm.h" +#include "cpu_utils.h" +#include "log_common.h" +#include "log_uart.h" +#include "exception.h" +#include "log_oml_exception.h" +#ifdef HSO_SUPPORT +#include "dfx_system_init.h" +#endif +#include "debug_print.h" +#ifdef SUPPORT_AT_GRAPHIC +#include "graphic_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_OHOSFWK +#include "ohosfwk_at_process.h" +#endif +#ifdef SUPPORT_AT_APP +#include "app_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_AUDIO +#include "audio_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_BT_MANAGER +#include "bt_manager_cmd_manager.h" +#endif +#ifdef SUPPORT_AT_MEDIA +#include "media_cmd_manager.h" +#endif +#include "log_file.h" +#ifdef CONFIG_OTA_UPDATE_SUPPORT +#include "upg.h" +#endif +static void register_at_service(void) +{ +#ifdef SUPPORT_AT_GRAPHIC + uint32_t graphic_cmd_count; + at_cmd_table_t *graphic_table = get_graphic_cmd_table(&graphic_cmd_count); + at_cmd_add_moudle(graphic_table, graphic_cmd_count); +#endif +#ifdef SUPPORT_AT_OHOSFWK +#ifdef JS_ENABLE + uint32_t ohosfwk_cmd_count; + at_cmd_table_t *ohosfwk_table = get_ohosfwk_cmd_table(&ohosfwk_cmd_count); + at_cmd_add_moudle(ohosfwk_table, ohosfwk_cmd_count); +#endif +#endif +#ifdef SUPPORT_AT_APP + uint32_t app_cmd_count; + at_cmd_table_t *app_table = get_app_cmd_table(&app_cmd_count); + at_cmd_add_moudle(app_table, app_cmd_count); +#endif +#ifdef SUPPORT_AT_AUDIO + uint32_t audio_cmd_count; + at_cmd_table_t *audio_table = get_audio_cmd_table(&audio_cmd_count); + at_cmd_add_moudle(audio_table, audio_cmd_count); +#endif +#ifdef SUPPORT_AT_BT_MANAGER + uint32_t bt_manager_cmd_count; + at_cmd_table_t *bt_manager_table = get_bt_manager_cmd_table(&bt_manager_cmd_count); + at_cmd_add_moudle(bt_manager_table, bt_manager_cmd_count); +#endif +#ifdef SUPPORT_AT_MEDIA + uint32_t media_cmd_count; + at_cmd_table_t *media_table = get_media_cmd_table(&media_cmd_count); + at_cmd_add_moudle(media_table, media_cmd_count); +#endif +} + +#ifdef CONFIG_OTA_UPDATE_SUPPORT +static void upg_putc(const char c) +{ + printf("%c", c); +} +#endif + +void service_init(void) +{ +#if defined(FREERTOS_TEST) + // freertos demo test + extern int main_full(void); + (void)main_full(); + for (;;) { + } +#endif + + /* dfx init step 1: log init */ + log_init(); + log_init_after_rtos(); + log_uart_init_after_rtos(); + + cpu_utils_init(); + hal_register_exception_dump_callback(log_exception_dump); + uapi_partition_init(); + PRINT("partition init success"NEWLINE); + +#ifdef CONFIG_OTA_UPDATE_SUPPORT + upg_func_t upg_func = {0}; + upg_func.malloc = malloc; + upg_func.free = free; + upg_func.serial_putc = upg_putc; + (void)uapi_upg_init(&upg_func); + PRINT("upg init success\r\n"); +#endif + + uapi_nv_init(); +#ifdef SUPPORT_AT_BT_MANAGER + set_calibration_from_nv(); +#endif + /* dfx init step 2: dfx init */ +#ifdef HSO_SUPPORT + dfx_system_init(); +#endif + /* power manager init */ + uapi_pm_init(); +#ifdef SUPPORT_POWER_MANAGER + uapi_power_display_init(); +#endif + + register_at_service(); +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/thread_init.c b/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/thread_init.c new file mode 100644 index 000000000..93eebd0e0 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/thread_init.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Application Core OS Initialize Interface for Standard + * Author: + * Create: 2021-03-09 + */ +#include "thread_init.h" +#include "tcxo.h" +#include "log_common.h" +#include "log_def.h" +#include "log_uart.h" +#include "log_file.h" +#ifdef __LITEOS__ +#include "los_status.h" +#endif +#include "pmu_interrupt.h" +#include "log_reg_dump.h" +#include "watchdog.h" +#include "preserve.h" +#include "hal_reboot.h" +#include "pinctrl_porting.h" +#include "pm_sleep.h" +#include "pm_lpc.h" +#include "pm_control.h" +#include "dfx_system_init.h" +#include "cpu_load.h" +#include "exception_dump.h" + +#ifdef SUPPORT_AT_CMD +#include "at_cmd_api.h" +#endif + +#ifdef SUPPORT_AT_GRAPHIC +#include "graphic_msg_manager.h" +#include "graphic_rx_process.h" +#endif + +#ifdef SUPPORT_AT_APP +#include "app_msg_manager.h" +#include "app_rx_process.h" +#endif + +#ifdef SUPPORT_AT_AUDIO +#include "audio_msg_manager.h" +#include "audio_rx_process.h" +#endif + +#ifdef SUPPORT_AT_BT_MANAGER +#include "bt_manager_msg_manager.h" +#include "bt_manager_rx_process.h" +#endif + +#ifdef SUPPORT_AT_MEDIA +#include "media_msg_manager.h" +#include "media_rx_process.h" +#endif + +#include "clocks_config.h" +#ifdef SUPPORT_POWER_MANAGER +#include "power_display_service.h" +#endif + +#if defined(__FREERTOS__) +#include "FreeRTOS.h" +#if defined(FREERTOS_DEBUG) +#include "debug_cmd.h" +#endif +#endif + +#ifdef SUPPORT_MEDIA_AUDIO_MANAGER +#include "audio_manager_c_wrapper.h" +#endif +#include "clocks_config.h" +#include "sys/time.h" +#include "time.h" +#include "log_panic.h" +#include "nandflash_config.h" +#ifdef SUPPORT_AUTO_OTA +#include "auto_ota_service.h" +#endif + +#define EMMC_BASE_ADDR 0x52062000 + +#define TASK_COMMON_APP_DELAY_MS 5000 + +#define TASK_PRIORITY_APP (osPriority_t)(17) +#define TASK_PRIORITY_LOG (osPriority_t)(18) +#define TASK_PRIORITY_CMD (osPriority_t)(17) +#define TASK_PRIORITY_BRANDY_APP (osPriority_t)(15) +#define TASK_PRIORITY_SDK (osPriority_t)(31) +#define TASK_PRIORITY_DFX_MSG (osPriority_t)(18) +#define TASK_PRIORITY_TRANSMIT (osPriority_t)(20) +#define TASK_PRIORITY_SAVE_FILE (osPriority_t)(36) +#define TASK_PRIORITY_AUTO_OTA (osPriority_t)(36) + +#define BTH_SDK_STACK_SIZE 0xC00 +#define AT_GRAPHIC_STACK_SIZE 0xC00 +#define AT_APP_STACK_SIZE 0x1000 +#define AT_AUDIO_STACK_SIZE 0x1000 +#define AT_BT_MANAGER_STACK_SIZE 0x1000 +#define AT_MEDIA_STACK_SIZE 0x1000 +#define DFX_MSG_STACK_SIZE 0x2000 +#define PM_DISPLAY_MSG_STACK_SIZE 0xc00 +#define AT_OHOSFWK_STACK_SIZE 0xC00 +#define APP_MAIN_STACK_SIZE 0xC00 +#define SAVE_FILE_STACK_SIZE 0xC00 +#define AUTO_OTA_STACK_SIZE 0xC00 + +#define TIME_MAX 64 +#define USEC_TO_MILLI 1000 +#define TCXO_TICKS_PER_MILLISECOND 32000 + +static void app_main(const void *unused); +void cmd_processor_entry(const void *args); +void cmd_main_add_functions(void); +void bt_acore_task_main(const void *pvParams); +int msg_process_thread(void *data); +errcode_t thread_msg_event_init(void); +int transmit_process_thread(void *data); +errcode_t transmit_thread_msg_init(void); +void system_time_cali(void); +#ifdef SUPPORT_32K_MEAS +void uapi_32k_systick_measurements(void); +#endif +osSemaphoreId_t g_semaphore_save = NULL; +void save_file_main(void); + +static uint32_t g_app_delay_ms = TASK_COMMON_APP_DELAY_MS; +app_task_definition_t g_app_tasks[] = { + { { "app", 0, NULL, 0, NULL, APP_MAIN_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)app_main, NULL, NULL, USE_DTCM_MEM }, +#if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == NO) + { { "log", 0, NULL, 0, NULL, (0xC00), TASK_PRIORITY_LOG, 0, 0 }, + (osThreadFunc_t)log_main, NULL, NULL, USE_DTCM_MEM }, +#endif + { { "bt_sdk", 0, NULL, 0, NULL, BTH_SDK_STACK_SIZE, TASK_PRIORITY_SDK, 0, 0 }, + (osThreadFunc_t)bt_acore_task_main, NULL, NULL, USE_DTCM_MEM }, +#ifdef SUPPORT_AT_CMD + { { "at_cmd", 0, NULL, 0, NULL, 0xC00, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)at_cmd_task_process_handler, NULL, + (CreateQueueFunction_t)at_cmd_task_queue_init, USE_DTCM_MEM }, +#endif +#if defined(SUPPORT_AT_GRAPHIC) + { { "at_graphic", 0, NULL, 0, NULL, AT_GRAPHIC_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)graphic_at_task_process_handler, NULL, + (CreateQueueFunction_t)graphic_at_task_queue_init, USE_EXTEND_MEM }, +#endif +#ifdef SUPPORT_AT_APP + { { "at_app", 0, NULL, 0, NULL, AT_APP_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)app_at_task_process_handler, NULL, + (CreateQueueFunction_t)app_at_task_queue_init, USE_EXTEND_MEM }, +#endif +#ifdef SUPPORT_AT_AUDIO + { { "at_audio", 0, NULL, 0, NULL, AT_AUDIO_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)audio_at_task_process_handler, NULL, + (CreateQueueFunction_t)audio_at_task_queue_init, USE_DTCM_MEM }, +#endif +#ifdef SUPPORT_AT_BT_MANAGER + { { "at_bt_manager", 0, NULL, 0, NULL, AT_BT_MANAGER_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)bt_manager_task_process_handler, NULL, + (CreateQueueFunction_t)bt_manager_at_task_queue_init, USE_DTCM_MEM }, +#endif +#ifdef SUPPORT_AT_MEDIA + { { "at_media", 0, NULL, 0, NULL, AT_MEDIA_STACK_SIZE, TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)media_at_task_process_handler, NULL, + (CreateQueueFunction_t)media_at_task_queue_init, USE_DTCM_MEM }, +#endif +#ifdef HSO_SUPPORT + { { "dfx_msg", 0, NULL, 0, NULL, DFX_MSG_STACK_SIZE, TASK_PRIORITY_DFX_MSG, 0, 0 }, + (osThreadFunc_t)msg_process_thread, NULL, + (CreateQueueFunction_t)thread_msg_event_init, USE_DTCM_MEM }, +#endif +#if (CONFIG_DFX_SUPPORT_TRANSMIT_FILE == DFX_YES && !defined(MEMORY_MINI)) + { { "transmit", 0, NULL, 0, NULL, DFX_MSG_STACK_SIZE, TASK_PRIORITY_TRANSMIT, 0, 0 }, + (osThreadFunc_t)transmit_process_thread, NULL, + (CreateQueueFunction_t)transmit_thread_msg_init, USE_DTCM_MEM }, +#endif +#if defined(SUPPORT_POWER_MANAGER) && !defined(SUPPORT_AT_OHOSFWK) + /* OHOS场景,pms不需要独立的队列和线程,事件由UI线程接管处理 */ + { { "power_display", 0, NULL, 0, NULL, PM_DISPLAY_MSG_STACK_SIZE, TASK_PRIORITY_TRANSMIT, 0, 0 }, + (osThreadFunc_t)power_display_msg_thread, NULL, + (CreateQueueFunction_t)power_display_task_init, USE_DTCM_MEM }, +#endif + { { "save_file", 0, NULL, 0, NULL, SAVE_FILE_STACK_SIZE, TASK_PRIORITY_SAVE_FILE, 0, 0 }, + (osThreadFunc_t)save_file_main, NULL, NULL, USE_EXTEND_MEM }, +#ifdef SUPPORT_AUTO_OTA + { { "auto_ota", 0, NULL, 0, NULL, AUTO_OTA_STACK_SIZE, TASK_PRIORITY_AUTO_OTA, 0, 0 }, + (osThreadFunc_t)auto_ota_task_main, NULL, NULL, USE_DTCM_MEM }, +#endif +}; + +osSemaphoreId_t get_save_file_semaphore(void) +{ + return g_semaphore_save; +} + +void save_file_main(void) +{ + if (osKernelGetState() == osKernelRunning) { + dump_norflash_trace_to_file(); + } + g_semaphore_save = osSemaphoreNew(1, 0, NULL); + if (!g_semaphore_save) { + panic(PANIC_LOG, LOG_PANIC_MUTEX_NOT_READY); + return; + } + for (;;) { + // If there has been log indicator get run again + if (osKernelGetState() == osKernelRunning) { + if (osSemaphoreAcquire(g_semaphore_save, osWaitForever) != osOK) { + panic(PANIC_LOG, LOG_PANIC_MUTEX_NOT_READY); + } + nand_driver_init(SPEED_SLOW); + set_trans_type(TRANS_BY_CPU_SINGLE_LINE); +#if defined SAVE_EXC_INFO + save_preserve_file_to_nand(); + save_btram_file_to_nand(); + save_btrace_file_to_nand(); +#endif + hal_reboot_chip(); + } + osDelay(1000); + } +} + +void set_app_delay_time(uint32_t time) +{ + g_app_delay_ms = time; +} + +void thread_init(void) +{ + /* Create queues before tasks in case they are used during initialisation. */ + for (uint8_t i = 0; i < (sizeof(g_app_tasks) / sizeof(app_task_definition_t)); i++) { + if (g_app_tasks[i].create_queue_handle) { + g_app_tasks[i].create_queue_handle(); + } + } + + /* Create tasks */ + for (uint8_t i = 0; i < (sizeof(g_app_tasks) / sizeof(app_task_definition_t)); i++) { + if (g_app_tasks[i].use_mem == USE_EXTEND_MEM) { + g_app_tasks[i].attr.stack_mem = memalign(16, g_app_tasks[i].attr.stack_size); // 16字节对齐 +#if defined(__FREERTOS__) + g_app_tasks[i].attr.cb_size = sizeof(StaticTask_t); + g_app_tasks[i].attr.cb_mem = memalign(16, sizeof(StaticTask_t)); // 16字节对齐 +#endif + } + g_app_tasks[i].task_handle = osThreadNew(g_app_tasks[i].func, NULL, &(g_app_tasks[i].attr)); + if (g_app_tasks[i].task_handle == NULL) { + panic(PANIC_TASK_CREATE_FAILED, i); + } + } +} + +static void print_system_sleep_info(void) +{ +#if ENABLE_LOW_POWER == YES + uint32_t deepsleep_time, lightsleep_time; + uint32_t deepsleep_cnt, lightsleep_cnt; + + sleep_info_t *sleep_info = pm_get_sleep_info(); + + deepsleep_time = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_DS].total_slp_time); + deepsleep_cnt = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_DS].total_slp_count); + + lightsleep_time = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_LS].total_slp_time); + lightsleep_cnt = (uint32_t)(sleep_info->sleep_history[PM_SLEEP_LS].total_slp_count); + + uint32_t sys_slp = readw(0x57004088); + PRINT("sys_slp: 0x%x\r\n", sys_slp); + reg16_setbit(0x57004088, 1); // clr slp history + reg16_setbit(0x57004088, 0); // clr slp history + + bool m_core_sleep = pmu_msystem_sleep_history(); + pmu_msystem_sleep_history_clear(); + PRINT("M core deepsleep time:%d, lightsleep time:%d, m sleep flag:%d"NEWLINE, + deepsleep_time, lightsleep_time, (uint8_t)m_core_sleep); + PRINT("M core deepsleep cnt:%d, lightsleep cnt:%d"NEWLINE, deepsleep_cnt, lightsleep_cnt); + PRINT("M core last veto id:%d, last veto count:%d"NEWLINE, sleep_info->sleep_veto.last_veto_id, + sleep_info->sleep_veto.last_veto_count); + + oml_pf_log_print1(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, "sys_slp: 0x%d", sys_slp); + oml_pf_log_print4(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, + "App run time:%d, app deepsleep time:%d, lightsleep time:%d, m sleep flag:%d", + (uint32_t)los_system_system_run_time(), deepsleep_time, lightsleep_time, (uint8_t)m_core_sleep); +#endif +} + +#ifdef SUPPORT_32K_MEAS +/* 使用32M tcxo 测量 systick的32K频率值 */ +void uapi_32k_systick_measurements(void) +{ + uint64_t cali_ms = 500; // 单次测量时长(ms) + uint64_t start_count = 0; + uint64_t total_count = 0; + uint64_t freq_32k = 0; + + uint32_t irq = osal_irq_lock(); + start_count = uapi_tcxo_get_count(); + uapi_systick_delay_ms(cali_ms); + total_count = uapi_tcxo_get_count() - start_count; + osal_irq_restore(irq); + + freq_32k = (STANDARD_32K_FREQUENCY * cali_ms * TCXO_TICKS_PER_MILLISECOND) / (total_count); + PRINT("32M_count = %llu, after calculation 32K freq = %llu."NEWLINE, total_count, freq_32k); + oml_pf_log_print2(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, + "32M_count = %llu, after calculation 32K freq = %llu.", total_count, freq_32k); + return; +} +#endif + +void system_time_cali(void) +{ + struct timeval tv = { 0 }; + + if (gettimeofday(&tv, NULL)) { + return; + } + return; +} + +static void app_main(const void *unused) +{ + unused(unused); + dfx_set_log_enable(); +#ifdef SUPPORT_MEDIA_AUDIO_MANAGER + bool success = AudioManagerInit(); + PRINT("audio manager init %s\r\n", success ? "ok" : "error"); +#endif + oml_pf_log_print0(LOG_BCORE_PLT, LOG_NUM_DEBUG, LOG_LEVEL_INFO, "App main"); +#if (USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG == NO) + log_exception_dump_reg_check(); +#endif + uapi_pm_request_mode(PM_ID_DEBUG, PM_MODE_LP); + PRINT("app_main run start."NEWLINE); + while (1) { //lint !e716 Main Loop + (void)osDelay(g_app_delay_ms); + uapi_watchdog_kick(); + uapi_logfile_fsync(STORE_DIAG); +#ifdef SUPPORT_32K_MEAS + uapi_32k_systick_measurements(); +#endif + system_time_cali(); +#ifndef XTS_SUPPORT + PRINT("app_main run start."NEWLINE); + print_system_sleep_info(); + oml_pf_log_print0(LOG_BCORE_PLT_DRIVER_REBOOT, LOG_NUM_DRIVER_LPC, LOG_LEVEL_INFO, "App run ok."); +#endif + } +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/thread_pri_init.c new file mode 100644 index 000000000..9b3bb03cd --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -0,0 +1,378 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Application Core OS Priority Initialize Interface for Standard + * Author: + * Create: 2022-12-03 + */ +#include "debug_print.h" +#include "thread_init.h" +#include "common_def.h" +#include "pm.h" +#include "watchdog.h" +#include "cpu_trace.h" +#include "non_os_reboot.h" +/* after reboot system emmc need write exc info to the file system from sector */ +#if defined(SAVE_EXC_INFO) && defined(CFG_DRIVERS_MMC) +#include "exception.h" +#endif +#ifdef CFG_DRIVERS_MMC +#ifdef __LITEOS__ +#include "soc/mmc.h" +#endif +#include "soc_mmc.h" +#endif +#include "soc_lcd_api.h" +#ifdef CFG_DRIVERS_NANDFLASH +#include "nandflash_config.h" +#include "yaffs_nand_drv.h" +#endif +#if defined(TPTYPE_TMA525B) +#include "tma525b_drv1.h" +#elif defined(TPTYPE_ZTW523) +#include "ztw523_touch1.h" +#else +#include "ztw523_touch1.h" +#endif +#include "thread_pri_init.h" +#if DSP_EXIST == YES +#include "soc_uapi_audio_sys.h" +#include "soc_uapi_vendor.h" +#include "soc_uapi_sound.h" +/* Audio codec vendor select according to hardware connection: + * define AUDIO_SMARTPA_AW88166 : macro to init smartpa aw88166; + * define AUDIO_SMARTPA_AW88166_I2S_ID UAPI_SND_OUT_PORT_I2S0 : macro to specify i2s id connecting to smartpa aw88166; + */ +#define AUDIO_SMARTPA_AW88262 +#define AUDIO_SMARTPA_AW88262_I2S_ID UAPI_SND_OUT_PORT_I2S2 + +#endif /* DSP_EXIST */ +#include "panic.h" +#include "board_init.h" +#include "kernel_init.h" +#ifdef SUPPORT_AT_OHOSFWK +#include "ohosfwk_startup.h" +#endif +#include "clocks_config.h" +#include "board_init.h" +#include "upg.h" +#include "upg_definitions.h" +#include "nv.h" +#include "nv_upg.h" + +#define EMMC_BASE_ADDR 0x52062000 +#define TASK_PRIORITY_APP (osPriority_t)(17) +#define TICK_TEN_MS (10U) +#define WAIT_BT_BOOTUP_TIME 200U +#define UPG_HEAD_MAGIC 0x55AA55AA +#define UPG_END_MAGIC 0xAA55AA55 +#define UPG_FLAG_MAGIC 0xFFFFFFFF + +static void thread_main(const void *unused); +void bt_acore_btc_ipc_receive_init(void); + +app_task_definition_t g_thread_pri = { { "thread_pri", 0, NULL, 0, NULL, (0x1000), TASK_PRIORITY_APP, 0, 0 }, + (osThreadFunc_t)thread_main, NULL, NULL, USE_DTCM_MEM }; +store_class g_store_init_select = STORE_CLASS_NAND; + +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) +static void sample_gfx_init(void) +{ +#if defined(TPTYPE_TMA525B) + tma525b_host_init_sample(); +#elif defined(TPTYPE_ZTW523) + ztw523_host_init_sample(); +#else + ztw523_host_init_sample(); +#endif + uapi_lcd_init(); +#ifdef SUPPORT_GPU_GMMU + drv_gmmu_module_init(); +#endif + uapi_vau_module_init(); + uapi_dpu_module_init(); +#ifdef SUPPORT_GPU_JPEG + uapi_jpeg_module_init(); +#endif +} +#endif + +#ifdef CFG_DRIVERS_MMC +static void emmc_init(void) +{ + /** + * FPGA解复位, 设置CMD_CONFLICT_CHECK + * 之后才能设置管脚 + */ + writew(EMMC_BASE_ADDR + 0x508, 0); + init_emmc_pinmux(); + int ret = emmc_drv_context_init(); + if (ret != ENOERR) { + PRINT("emmc init error:[%d]"NEWLINE, ret); + } + mmc_set_first_init_flag(true); + mmc_set_sleep_init_flag(true); + PRINT("emmc init success\r\n"); + +#if defined(SAVE_EXC_INFO) + if (emmc_exc_info_write() != ERRCODE_SUCC) { + PRINT("emmc_exc_info_write failed"NEWLINE); + } +#endif +} +#endif + +#ifdef CFG_SDIO_EMMC_COEXIST +static void sdio_init(void) +{ + init_sdio_pinmux(); + sdio_drv_context_init(); +} +#endif + +#ifdef CFG_DRIVERS_NANDFLASH +static void nandflash_init(void) +{ + int32_t ret = 0; + ret = nandflash_filesystem_init(); + if (ret != 0) { + PRINT("nandflash init error[%d]"NEWLINE, ret); + } + PRINT("nandflash init success\r\n"); +} +#endif + +static void board_version_class_print(void) +{ + PRINT("**********startup info**********\r\n"); + PRINT("os init class is %s."NEWLINE, (g_os_init_select == OS_CLASS_LITEOS) ? "liteos" : "freertos"); + PRINT("store init class is %s."NEWLINE, (g_store_init_select == STORE_CLASS_NAND) ? "nandflash" : "emmc"); + PRINT("display init class is %s."NEWLINE, (g_display_init_select == DISPLAY_CLASS_QSPI) ? "QSPI" : "MIPI"); + PRINT("board init class is %s."NEWLINE, (g_board_init_select == BOARD_CLASS_E0B2) ? "E0B2" : "E0B4"); +#ifdef CONFIG_PSRAM_SUPPORT + PRINT("psram density is %s."NEWLINE, (get_psram_density() == PSRAM_DENSITY_16M) ? "16MB" : "32MB"); +#endif + PRINT("**********startup info**********\r\n"); +} + +#if DSP_EXIST == YES +/** + * The sample code of the vendor, + * which will be implemented by the customer in the future + */ +#ifdef AUDIO_SMARTPA_AW88262 +td_s32 audio_aw88262_init(const uapi_vendor_codec_attr *attr); +td_s32 audio_aw88262_deinit(td_void); + +static uapi_vendor_driver g_aw88262_driver = { + .out_port = AUDIO_SMARTPA_AW88262_I2S_ID, + .init = audio_aw88262_init, + .deinit = audio_aw88262_deinit, + .set_aef_profile = TD_NULL, +}; + +static td_s32 audio_aw88262_register_driver(void) +{ + return uapi_audio_vendor_register(&g_aw88262_driver); +} +#endif /* AUDIO_SMARTPA_AW88262 */ + +#ifdef AUDIO_SMARTPA_AW88166 +td_s32 audio_aw88166_init(const uapi_vendor_codec_attr *attr); +td_s32 audio_aw88166_deinit(td_void); /* Call when device power off */ +td_s32 audio_aw88166_start(const uapi_vendor_codec_attr *attr); +td_s32 audio_aw88166_stop(td_void); +td_s32 audio_aw88166_set_aef_profile(uapi_snd_aef_profile aef_profile); + +static uapi_vendor_driver g_aw88166_driver = { + .out_port = AUDIO_SMARTPA_AW88166_I2S_ID, + .init = audio_aw88166_start, + .deinit = audio_aw88166_stop, + .set_aef_profile = audio_aw88166_set_aef_profile, +}; + +static td_s32 audio_aw88166_register_driver(void) +{ + const uapi_vendor_codec_attr attr = {}; + + audio_aw88166_init(&attr); /* Init aw88166 once when device power on */ + + return uapi_audio_vendor_register(&g_aw88166_driver); +} +#endif /* AUDIO_SMARTPA_AW88166 */ + +static void audio_smartpa_init(void) +{ + uint32_t ret; + +#ifdef AUDIO_SMARTPA_AW88262 + ret = (uint32_t)audio_aw88262_register_driver(); + if (ret != 0) { + PRINT("aw88262 register driver error\r\n"); + } +#endif /* AUDIO_SMARTPA_AW88262 */ + +#ifdef AUDIO_SMARTPA_AW88166 + ret = (uint32_t)audio_aw88166_register_driver(); + if (ret != 0) { + PRINT("aw88166 register driver error\r\n"); + } +#endif /* AUDIO_SMARTPA_AW88166 */ +} +#endif /* DSP_EXIST */ + +#if DSP_EXIST == YES +static void audio_init() +{ + (void)osDelay(TICK_TEN_MS); + uapi_watchdog_kick(); + + audio_smartpa_init(); + + uint32_t ret = (uint32_t)uapi_audio_init(); + if (ret != 0) { + PRINT("audio init error:[%d]\r\n", ret); + } else { + PRINT("audio init OK\r\n"); + } +} +#endif + +void rc_calibration_func_notify(void) +{ +#ifdef SUPPORT_RC_CALIBRATION + /* BT核用来通知MCU 32K校准值 */ + writew(GLB_CTL_D_RB_BASE + GLB_GP_D_REG3, 0x0); + /* 通知BTæ ¸ 32K时钟来源 */ + writew(GLB_CTL_D_RB_BASE + GLB_GP_D_REG2, CLOCK_SOURCE_RC); +#else + writew(GLB_CTL_D_RB_BASE + GLB_GP_D_REG2, CLOCK_SOURCE_XO); +#endif +} + +static void force_to_sleep(void) +{ + if (reg16_getbits(0x5702C010, 0x8, 0x8) == 0x5A) { // 特殊模式下,强制进入深睡中 + reg16_clrbits(0x5702C010, 0x8, 0x8); + uapi_tcxo_delay_ms(WAIT_BT_BOOTUP_TIME); + hal_pmu_cldo_enable_slp_bypass(HAL_PMU_CLDO1, TURN_OFF); + uapi_sys_force_mcu_only_deep_sleep_mode(0); + } +} + +#ifdef CONFIG_OTA_UPDATE_SUPPORT +static void upg_check_upgrade(void) +{ + uint32_t fota_address = 0; + errcode_t ret_val = (errcode_t)upg_get_upgrade_flag_flash_start_addr(&fota_address); + if (ret_val != ERRCODE_SUCC) { + return; + } + + fota_upgrade_flag_area_t upg_flag_info; + ret_val = (errcode_t)upg_flash_read(fota_address, sizeof(fota_upgrade_flag_area_t), (uint8_t *)(&upg_flag_info)); + if (ret_val != ERRCODE_SUCC) { + return; + } + + if (!(upg_flag_info.head_magic == UPG_HEAD_MAGIC && + upg_flag_info.head_end_magic == UPG_END_MAGIC && + upg_flag_info.complete_flag == UPG_FLAG_MAGIC)) { + /* 不需要升级直接返回 */ + PRINT("No need to upgrade...\r\n"); + return; + } + + PRINT("upgrading.......\r\n"); + ret_val = uapi_upg_start(); + if (ret_val != ERRCODE_SUCC) { + PRINT("upgrade failed, ret = 0x%x\r\n", ret_val); + } else { + PRINT("upgrade success\r\n"); + } + upg_reboot(); +} +#endif + +static void thread_main(const void *unused) +{ + PRINT("thread_main start "NEWLINE); + unused(unused); + rc_calibration_func_notify(); + bt_acore_btc_ipc_receive_init(); + uapi_pm_control(PM_BT_POWER_UP_AND_RUN); +#ifdef FORCE_TO_DEEP_SLEEP + force_to_sleep(); +#endif + los_vfs_init(); + uint32_t ret = dpal_driver_base_init(); + if (ret != 0) { + PRINT("dpal driver base init error"NEWLINE); + panic(PANIC_ASSERT, __LINE__); + } +#ifdef CFG_DRIVERS_MMC + emmc_init(); + g_store_init_select = STORE_CLASS_EMMC; + sdiom_internal_freq_handler_register(mmc_set_internal_clk); +#endif +#ifdef CFG_SDIO_EMMC_COEXIST + sdio_init(); +#endif +#ifdef CFG_DRIVERS_NANDFLASH + yaffs_nand_drv_checkptset(YAFFS_CHECKPT_SKIPED); + nandflash_init(); + g_store_init_select = STORE_CLASS_NAND; +#endif + + reboot_cause_t cause = get_cpu_utils_reset_cause(); + if ((cause != REBOOT_CAUSE_APPLICATION_STD_CHIP_WDT_FRST) && + (cause != REBOOT_CAUSE_APPLICATION_XIP_CTRL) && + (cause != REBOOT_CAUSE_APPLICATION_XIP_CACHE)) { + cpu_trace_enable_mcpu_repeat(); + } else { + PRINT("nmi reboot cause: 0x%x, reason: 0x%x"NEWLINE, cause, get_fault_reason()); + // save cputrace memory if chip watchdog reset + hal_cpu_trace_clock_enable(); + panic(PANIC_ASSERT, cause); + } + + uapi_pm_control(PM_DISPLAY_POWER_UP_AND_RUN); + (void)osDelay(TICK_TEN_MS); + +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) + sample_gfx_init(); +#else + uapi_pm_control(PM_DISPLAY_POWER_OFF); +#endif + +#if DSP_EXIST == YES + audio_init(); +#endif + board_version_class_print(); + uapi_watchdog_kick(); +#ifdef CONFIG_OTA_UPDATE_SUPPORT + upg_check_upgrade(); +#endif + /* nv init and file system init must be before nv_upg_upgrade_task_process */ + (void)nv_upg_upgrade_task_process(); + thread_init(); + button_app_init(); + uapi_calendar_init(); +#ifdef SUPPORT_AT_OHOSFWK + ohos_startup(); +#endif +#ifdef CONFIG_SYSTEM_VIEW + SEGGER_SYSVIEW_Conf(); + // 请在抓取systemview开始的地方调用SEGGER_SYSVIEW_Start接口 +#endif + uapi_pm_remove_sleep_veto(PM_ID_DEBUG); + set_startup_finish_flag(); +} + +void thread_pri_init(void) +{ + /* Create tasks */ + g_thread_pri.task_handle = osThreadNew(g_thread_pri.func, NULL, &(g_thread_pri.attr)); + if (g_thread_pri.task_handle == NULL) { + PRINT("create thread pri failed!"); + } +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp new file mode 100644 index 000000000..6fb226b6e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -0,0 +1,438 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainClockView + * Author: + * Create: 2021-08-14 + */ + +#include "MainClockView.h" +#include "MainPresenterSample.h" +#include "components/ui_label.h" +#include "wearable_log.h" +#include "ui_resource_image.h" +#include "common/image_cache_manager.h" +#include + +namespace OHOS { +static MainClockView *g_pMainClockView = nullptr; + +static constexpr uint16_t FONT_DEFAULT_SIZE = 25; +static constexpr uint16_t FONT_TEXT_SIZE = 24; +static constexpr uint16_t STEP_LABEL_X = 100; +static constexpr uint16_t STEP_LABEL_Y = 230; +static constexpr uint16_t BATTERYP_LABEL_X = 315; +static constexpr uint16_t BATTERYP_LABEL_Y = 230; +static constexpr uint16_t TEXT_WIDTH = 60; +static constexpr uint16_t TEXT_HEIGHT = 35; +static constexpr uint16_t POINT_POSITION_X = 202; +static constexpr uint16_t POINT_POSITION_Y = 16; +static constexpr uint16_t SECOND_POINT_POSITION_Y = 16; +static constexpr uint16_t POINT_CENTER_X = 25; +static constexpr uint16_t POINT_CENTER_Y = 211; +static constexpr uint16_t STEP_CHAR_NUM = 255; +static constexpr int16_t STEP_LABLE_WIDTH = 75; +static constexpr int16_t STEP_LABLE_SIZE = 35; +static constexpr uint16_t WEEKLABEL_POSITION_X = 247; +static constexpr uint16_t WEEKLABEL_POSITION_Y = 122; +static constexpr uint16_t HEARTRATELABEL_POSITION_X = 198; +static constexpr uint16_t HEARTRATELABEL_POSITION_Y = 330; +static constexpr uint16_t HEARTRATE_POSITION_X = 156; +static constexpr uint16_t HEARTRATE_POSITION_Y = 260; +static constexpr uint16_t PROGRESS_POSITION_X = 53; +static constexpr uint16_t PROGRESS_POSITION_Y = 54; +static constexpr uint16_t BIGCIRCLE_POSITION_X = 202; +static constexpr uint16_t BIGCIRCLE_POSITION_Y = 202; +static constexpr uint16_t MEDCIRCLE_POSITION_X = 202; +static constexpr uint16_t MEDCIRCLE_POSITION_Y = 202; +static constexpr uint16_t SMALLCIRCLE_POSITION_X = 202; +static constexpr uint16_t SMALLCIRCLE_POSITION_Y = 202; +static constexpr uint16_t WEEKDAY_POSITION_X = 193; +static constexpr uint16_t WEEKDAY_POSITION_Y = 127; +static constexpr int16_t SEC_TO_MILLI = 1000; +static constexpr int16_t USEC_TO_MILLI = 1000; +static constexpr int16_t MIN_TO_HOUR = 60; +static constexpr int16_t HOURLY_SYSTEM = 24; +static constexpr int16_t INTERVAL = 30; + +MainClockView::MainClockView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::MainClockView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pMainClockView = this; +} + +MainClockView::~MainClockView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::~MainClockView"); + if (viewiInitStatus) { + mainSweepClock->RemoveAll(); + delete curFace; + curFace = nullptr; + delete stepLabel; + stepLabel = nullptr; + delete batteryLabel; + batteryLabel = nullptr; + delete secondHand; + secondHand = nullptr; + delete minuteHand; + minuteHand = nullptr; + delete hourHand; + hourHand = nullptr; + delete weekLabel; + weekLabel = nullptr; + delete heartRateLabel; + heartRateLabel = nullptr; + delete heartRate; + heartRate = nullptr; + delete hand24Hour; + hand24Hour = nullptr; + delete weekDay; + weekDay = nullptr; + delete progress; + progress = nullptr; + delete bigCircle; + bigCircle = nullptr; + delete medCircle; + medCircle = nullptr; + delete smallCircle; + smallCircle = nullptr; + Remove(mainSweepClock); + delete mainSweepClock; + mainSweepClock = nullptr; + g_pMainClockView = nullptr; + } +} + +MainClockView *MainClockView::GetInstance(void) +{ + return g_pMainClockView; +} + +void MainClockView::InitStepValue() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue"); + uint32_t stepValue; + int weekToday = ActivityModel::GetInstance()->GetWeekToday(); + ActivityModel::GetInstance()->GetStepData((StepDataDistribute)weekToday, &stepValue); + char stepChar[STEP_CHAR_NUM] = {0}; + if (sprintf_s(stepChar, STEP_CHAR_NUM, "%d", stepValue) == -1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue error"); + return; + } + if (stepLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue nullptr"); + return; + } + stepLabel->SetText(stepChar); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); +} + +bool MainClockView::InitLabelView(void) +{ + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + stepLabel = new UILabelButton(); + if (stepLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stepLabel new fail"); + return false; + } + stepLabel->SetPosition(STEP_LABEL_X, STEP_LABEL_Y); + stepLabel->Resize(STEP_LABLE_WIDTH, STEP_LABLE_SIZE); + stepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + stepLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + stepLabel->SetViewId(MAIN_CLICK_ACTIVITY); + stepLabel->SetTouchable(true); + stepLabel->SetOnClickListener(clickListener); + InitStepValue(); + + batteryLabel = new UILabel(); + if (batteryLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail"); + return false; + } + batteryLabel->SetPosition(BATTERYP_LABEL_X, BATTERYP_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + batteryLabel->SetText("90%"); + batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + + heartRateLabel = new UILabel(); + if (heartRateLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateLabel new fail"); + return false; + } + heartRateLabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); + heartRateLabel->SetText("--"); + heartRateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + heartRateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + heartRateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + + weekLabel = new UILabel(); + if (weekLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekLabel new fail"); + return false; + } + weekLabel->SetPosition(WEEKLABEL_POSITION_X, WEEKLABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT); + weekLabel->SetText("2"); + weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); + weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + return true; +} + +bool MainClockView::InitCenterCircleView(void) +{ + bigCircle = new Image(); + if (bigCircle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bigCircle new fail"); + return false; + } + if (!LoadClockImage(bigCircle, CLOCK_BIGCIRCLE_IMAGE_PATH)) { + return false; + } + + medCircle = new Image(); + if (medCircle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "medCircle new fail"); + return false; + } + if (!LoadClockImage(medCircle, CLOCK_MEDCIRCLE_IMAGE_PATH)) { + return false; + } + + smallCircle = new Image(); + if (smallCircle == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "smallCircle new fail"); + return false; + } + if (!LoadClockImage(smallCircle, CLOCK_CIRCLE_IMAGE_PATH)) { + return false; + } + return true; +} + +bool MainClockView::InitHandView(void) +{ + secondHand = new Image(); + if (secondHand == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); + return false; + } + if (!LoadClockImage(secondHand, CLOCK_SECONDHAND)) { + return false; + } + + minuteHand = new Image(); + if (minuteHand == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "minuteHand new fail"); + return false; + } + if (!LoadClockImage(minuteHand, CLOCK_MINUTEHAND)) { + return false; + } + hourHand = new Image(); + if (hourHand == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hourHand new fail"); + return false; + } + if (!LoadClockImage(hourHand, CLOCK_HOURHAND)) { + return false; + } + + hand24Hour = new Image(); + if (hand24Hour == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hand24Hour new fail"); + return false; + } + if (!LoadClockImage(hand24Hour, CLOCK_HAND24HOUR_IMAGE_PATH)) { + return false; + } + return true; +} + +bool MainClockView::LoadClockImage(Image *view, uint32_t resId) +{ + std::string file = CLOCK_IAMGES; + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; +} + +bool MainClockView::LoadClockImage(UIImageView *view, uint32_t resId) +{ + std::string file = CLOCK_IAMGES; + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; +} + +bool MainClockView::InitSweepClock(void) +{ + curFace = new UIImageView(); + if (curFace == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail"); + return false; + } + curFace->SetPosition(0, 0); + + if (!LoadClockImage(curFace, CLOCK_MAIN_FACE_IMAGE)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace LoadClockImage CLOCK_MAIN_FACE_IMAGE fail"); + return false; + } + + if (!InitLabelView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelView() fail"); + return false; + } + if (!InitCenterCircleView()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitCenterCircleView() fail"); + return false; + } + heartRate = new UIImageView(); + if (heartRate == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRate new fail"); + return false; + } + heartRate->SetPosition(HEARTRATE_POSITION_X, HEARTRATE_POSITION_Y); + if (!LoadClockImage(heartRate, CLOCK_HEARTRATE_IMAGE_PATH)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRate LoadClockImage CLOCK_HEARTRATE_IMAGE_PATH fail"); + return false; + } + + progress = new UIImageView(); + if (progress == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress new fail"); + return false; + } + progress->SetPosition(PROGRESS_POSITION_X, PROGRESS_POSITION_Y); + if (!LoadClockImage(progress, CLOCK_PROGRESS_IMAGE_PATH)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress LoadClockImage CLOCK_PROGRESS_IMAGE_PATH fail"); + return false; + } + + InitHandView(); + weekDay = new UIImageView(); + if (weekDay == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekDay new fail"); + return false; + } + weekDay->SetPosition(WEEKDAY_POSITION_X, WEEKDAY_POSITION_Y); + if (!LoadClockImage(weekDay, CLOCK_THURSDAY_IMAGE_PATH)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekDay LoadClockImage CLOCK_THURSDAY_IMAGE_PATH fail"); + return false; + } + return true; +} + +void MainClockView::PreLoad(void) +{ + if (!viewiInitStatus) { + InitView(); + viewiInitStatus = true; + } +} + +void MainClockView::UnLoad(void) +{ + // Main clock view is commonly used page, so we do not release it's resources inner slice. +} + +bool MainClockView::InitView(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView"); + + mainSweepClock = new UISweepClock(); + if (mainSweepClock == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); + return false; + } + if (!InitSweepClock()) { + return false; + } + + mainSweepClock->Add(curFace); + mainSweepClock->Add(stepLabel); + mainSweepClock->Add(heartRate); + mainSweepClock->Add(weekLabel); + mainSweepClock->Add(heartRateLabel); + mainSweepClock->Add(weekDay); + mainSweepClock->Add(progress); + mainSweepClock->Add(batteryLabel); + Add(mainSweepClock); + + mainSweepClock->SetDragParentInstead(true); + mainSweepClock->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + // {214, 3}: position x, y {14, 223}: center x, y + mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand, + { POINT_POSITION_X, SECOND_POINT_POSITION_Y }, { POINT_CENTER_X, POINT_CENTER_Y }); + mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand, + { POINT_POSITION_X, POINT_POSITION_Y }, { POINT_CENTER_X, POINT_CENTER_Y }); + mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand, { POINT_POSITION_X, POINT_POSITION_Y }, + { POINT_CENTER_X, POINT_CENTER_Y }); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::SECOND_HAND, *smallCircle, + { SMALLCIRCLE_POSITION_X, SMALLCIRCLE_POSITION_Y }); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::MINUTE_HAND, *medCircle, + { MEDCIRCLE_POSITION_X, MEDCIRCLE_POSITION_Y }); + mainSweepClock->SetHandCircleImage(UISweepClock::HandType::HOUR_HAND, *bigCircle, + { BIGCIRCLE_POSITION_X, BIGCIRCLE_POSITION_Y }); + + mainSweepClock->SetInitTime24Hour(0, 0, 0); + mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL); + InitDateTime(); + SetCoverable(true); + return true; +} + +void MainClockView::RefreshStep(int step) +{ + char stepChar[STEP_CHAR_NUM] = {0}; + + (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step); + stepLabel->SetText(stepChar); +} + +void MainClockView::RefreshHeartRate(int value) +{ + if (value == 0) { + heartRateLabel->SetText("--"); + return; + } + char heartRateChar[STEP_CHAR_NUM] = {0}; + + (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value); + heartRateLabel->SetText(heartRateChar); +} + +void MainClockView::InitDateTime(void) +{ + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + mainSweepClock->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec); +} + +void MainClockView::UpdateTime(void) +{ + struct timeval tv; + gettimeofday(&tv, nullptr); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / MIN_TO_HOUR; + uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR); + uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); + uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); + uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * + SEC_TO_MILLI + uSecond / USEC_TO_MILLI); + mainSweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1); +} +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp new file mode 100644 index 000000000..34eb21de7 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -0,0 +1,330 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: WeekStep + * Author: + * Create: 2021-09-11 + */ + +#include "PullUpDownView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/screen.h" +#include "MainPresenterSample.h" +#include "ScreenModels.h" +#include "SettingModel.h" +#include "ui_resource_image.h" + +namespace OHOS { + +static PullUpDownView *g_pPullUpDownView = nullptr; + +constexpr int16_t DISTURB_IMG_X = 117; +constexpr int16_t DISTURB_IMG_Y = 50; +constexpr int16_t SCREEN_IMG_X = 251; +constexpr int16_t SCREEN_IMG_Y = 50; +constexpr int16_t PHONE_IMG_X = 49; +constexpr int16_t PHONE_IMG_Y = 184; +constexpr int16_t ALARM_IMG_X = 184; +constexpr int16_t ALARM_IMG_Y = 184; +constexpr int16_t SETTING_IMG_X = 319; +constexpr int16_t SETTING_IMG_Y = 184; + +constexpr int16_t BLUETOOTH_IMG_X = 145; +constexpr int16_t BLUETOOTH_IMG_Y = 335; +constexpr int16_t BATTERY_IMG_X = 195; +constexpr int16_t BATTERY_IMG_Y = 340; + +constexpr int16_t DISTURB_LABEL_X = 136; +constexpr int16_t DISTURB_LABEL_Y = 145; +constexpr int16_t SCREEN_LABEL_X = 270; +constexpr int16_t SCREEN_LABEL_Y = 145; +constexpr int16_t PHONE_LABEL_X = 68; +constexpr int16_t PHONE_LABEL_Y = 279; +constexpr int16_t ALARM_LABEL_X = 203; +constexpr int16_t ALARM_LABEL_Y = 279; +constexpr int16_t SETTING_LABEL_X = 338; +constexpr int16_t SETTING_LABEL_Y = 279; + +constexpr int16_t BATTERY_LABEL_X = 247; +constexpr int16_t BATTERY_LABEL_Y = 335; +constexpr int16_t DATE_LABEL_X = 173; +constexpr int16_t DATE_LABEL_Y = 374; + +constexpr int16_t FONT_DEFAULT_SIZE = 24; +constexpr int16_t TEXT_WIDTH = 86; +constexpr int16_t TEXT_HEIGHT = 30; + +constexpr int16_t NONOTICE_LABLE_X = 141; +constexpr int16_t NONOTICE_LABLE_Y = 212; + +PullUpDownView::PullUpDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::PullUpDownView"); + g_pPullUpDownView = this; +} + +PullUpDownView::~PullUpDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::~PullUpDownView"); + RemoveAll(); + delete dnotDisturb; + dnotDisturb = nullptr; + delete briScreen; + briScreen = nullptr; + delete finPhone; + finPhone = nullptr; + delete droAlarm; + droAlarm = nullptr; + delete droSetting; + droSetting = nullptr; + delete dnotDisturbLable; + dnotDisturbLable = nullptr; + delete briScreenLable; + briScreenLable = nullptr; + delete finPhoneLable; + finPhoneLable = nullptr; + delete droAlarmLable; + droAlarmLable = nullptr; + delete droSettingLable; + droSettingLable = nullptr; + delete bluetooth; + bluetooth = nullptr; + delete battery; + battery = nullptr; + delete batteryLable; + batteryLable = nullptr; + delete dateLable; + dateLable = nullptr; + g_pPullUpDownView = nullptr; +} + +PullUpDownView *PullUpDownView::GetInstance(void) +{ + return g_pPullUpDownView; +} + +void PullUpDownView::InitSubViewImg(void) +{ + if (HealthModel::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); + return; + } + + dnotDisturb = new UIImageView(); + if (dnotDisturb == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturb new fail"); + return; + } + dnotDisturb->SetPosition(DISTURB_IMG_X, DISTURB_IMG_Y); + if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dnotDisturb, DROPDOWN_DROPDOWN_DN_DISTURB_B); + } + dnotDisturb->SetViewId(DROPDOWN_CLICK_DONOTDISTURB); + dnotDisturb->SetTouchable(true); + dnotDisturb->SetOnClickListener(clickListener); // 进入勿扰模式 + + briScreen = new UIImageView(); + if (briScreen == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreen new fail"); + return; + } + briScreen->SetPosition(SCREEN_IMG_X, SCREEN_IMG_Y); + if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, briScreen, DROPDOWN_DROPDOWN_BRI_SCREEN_B); + } + briScreen->SetViewId(DROPDOWN_CLICK_BRIGHTENSCREEN); + briScreen->SetTouchable(true); + briScreen->SetOnClickListener(clickListener); // 进入亮屏模式 +} + +void PullUpDownView::InitViewImg(void) +{ + InitSubViewImg(); + + finPhone = new UIImageView(); + if (finPhone == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhone new fail"); + return; + } + finPhone->SetPosition(PHONE_IMG_X, PHONE_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, finPhone, DROPDOWN_DROPDOWN_FIND_PHONE); + finPhone->SetViewId(DROPDOWN_CLICK_FINDMYPHONE); // 找手机界面 DROP_DOWN_FIND_PHONE + finPhone->SetTouchable(true); + finPhone->SetOnClickListener(clickListener); + + droAlarm = new UIImageView(); + if (droAlarm == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droAlarm new fail"); + return; + } + droAlarm->SetPosition(ALARM_IMG_X, ALARM_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droAlarm, DROPDOWN_DROPDOWN_ALARM); + droAlarm->SetViewId(DROPDOWN_CLICK_ALARM); // 进入闹钟App DROP_DOWN_ALARM + droAlarm->SetTouchable(true); + droAlarm->SetOnClickListener(clickListener); + + droSetting = new UIImageView(); + if (droSetting == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSetting new fail"); + return; + } + droSetting->SetPosition(SETTING_IMG_X, SETTING_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, droSetting, DROPDOWN_DROPDOWN_SETTING); + droSetting->SetViewId(DROPDOWN_CLICK_SETTING); // 进入设置界面 DROP_DOWN_SETTING + droSetting->SetTouchable(true); + droSetting->SetOnClickListener(clickListener); +} + +void PullUpDownView::InitViewLable(void) +{ + dnotDisturbLable = new UILabel(); + if (dnotDisturbLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturbLable new fail"); + return; + } + dnotDisturbLable->SetPosition(DISTURB_LABEL_X, DISTURB_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + dnotDisturbLable->SetText("勿扰"); + dnotDisturbLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + dnotDisturbLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + briScreenLable = new UILabel(); + if (briScreenLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreenLable new fail"); + return; + } + briScreenLable->SetPosition(SCREEN_LABEL_X, SCREEN_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + briScreenLable->SetText("亮屏"); + briScreenLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + briScreenLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + finPhoneLable = new UILabel(); + if (finPhoneLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); + return; + } + finPhoneLable->SetPosition(PHONE_LABEL_X, PHONE_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + finPhoneLable->SetText("找手机"); + finPhoneLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + finPhoneLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + droAlarmLable = new UILabel(); + if (finPhoneLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); + return; + } + droAlarmLable->SetPosition(ALARM_LABEL_X, ALARM_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + droAlarmLable->SetText("闹钟"); + droAlarmLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + droAlarmLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + droSettingLable = new UILabel(); + if (droSettingLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSettingLable new fail"); + return; + } + droSettingLable->SetPosition(SETTING_LABEL_X, SETTING_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + droSettingLable->SetText("设置"); + droSettingLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + droSettingLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); +} + +void PullUpDownView::InitViewInfo(void) +{ + bluetooth = new UIImageView(); // 蓝牙状态显示 + if (bluetooth == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth new fail"); + return; + } + bluetooth->SetPosition(BLUETOOTH_IMG_X, BLUETOOTH_IMG_Y); + if (BluetoothModel::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth model nullptr"); + return; + } + + if (SettingModel::GetInstance().GetBlueToothConnectStatus()) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); + } + + battery = new UIImageView(); // 电量状态显示 + if (battery == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery new fail"); + return; + } + battery->SetPosition(BATTERY_IMG_X, BATTERY_IMG_Y); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, battery, DROPDOWN_DROPDOWN_BATTERY); + batteryLable = new UILabel(); + if (batteryLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLable new fail"); + return; + } + batteryLable->SetPosition(BATTERY_LABEL_X, BATTERY_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); + batteryLable->SetText("90%"); + batteryLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + batteryLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); + dateLable = new UILabel(); + if (dateLable == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dateLable new fail"); + return; + } + dateLable->SetPosition(DATE_LABEL_X, DATE_LABEL_Y, 192, TEXT_HEIGHT); // TEXT_WIDTH = 192 + dateLable->SetText("10/23 星期五"); + dateLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + dateLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); +} + +bool PullUpDownView::InitView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView"); + clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + + InitViewImg(); + InitViewLable(); + InitViewInfo(); + + Add(dnotDisturb); + Add(dnotDisturbLable); + Add(briScreen); + Add(briScreenLable); + Add(finPhone); + Add(finPhoneLable); + Add(droAlarm); + Add(droAlarmLable); + Add(droSetting); + Add(droSettingLable); + Add(bluetooth); + Add(battery); + Add(batteryLable); + Add(dateLable); + + SetTouchable(true); + SetIntercept(true); + + return true; +} + +void PullUpDownView::PreLoad(void) +{ + if (!viewiInitStatus) { + InitView(); + viewiInitStatus = true; + } +} + +void PullUpDownView::UpdateBlueToothStatus(int status) +{ + if (bluetooth == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth nullptr"); + return; + } + if (status == 1) { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH_B); + } else { + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, bluetooth, DROPDOWN_DROPDOWN_BLUETOOTH); + } + bluetooth->Invalidate(); + return; +} + +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp new file mode 100644 index 000000000..e0e1877d8 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelPower.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) CompanyNameMagicTag 2023. All rights reserved. + * Description: DialModelPower + * Author: + * Create: 2023-12 + */ + +#include "RegisterDialModel.h" +#include "DialModelPower.h" + +REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_POWER, OHOS::DialModelPower::GetInstance()); + +namespace OHOS { +bool DialModelPower::GetDialFloatData(DialDataType& type, float& out) +{ + (void)type; + out = power_; + return true; +} +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp new file mode 100644 index 000000000..7dcdf3238 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wearable/nativeapp/nativeui/rebootdevice/src/RebootPresenter.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Reboot Presenter + * Create: 2022-04-28 + */ + +#include "RebootPresenter.h" +#include "RebootView.h" +#include "RebootModel.h" +#include "drag_event.h" +#include "wearable_log.h" + +namespace OHOS { +static RebootPresenter *g_pRebootPresenter = nullptr; + +RebootPresenter::RebootPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::RebootPresenter"); + g_pRebootPresenter = this; +} + +RebootPresenter::~RebootPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::~RebootPresenter"); + g_pRebootPresenter = nullptr; +} + +RebootPresenter *RebootPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter GetInstance"); + return g_pRebootPresenter; +} + +void RebootPresenter::OnStart() +{ + Presenter::OnStart(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::On Start "); +} + +void RebootPresenter::OnPause(void) {} + +void RebootPresenter::OnResume(void) {} + +void RebootPresenter::OnStop(void) {} + +bool RebootPresenter::OnClick(UIView& view, const ClickEvent& event) +{ + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick OnClick"); + if (strcmp(view.GetViewId(), REBOOT_BUTTON) == 0) { + RebootView::GetInstance()->ChangeView(REBOOTVIEW, REBOOTDEVICEVIEW); + } else if (strcmp(view.GetViewId(), SHUTDOWN_BUTTON) == 0) { + RebootView::GetInstance()->ChangeView(REBOOTVIEW, SHUTDOWNDEVICEVIEW); + } else if (strcmp(view.GetViewId(), REBOOTDEVICE_BUTTON) == 0) { + // 重启 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "REBOOTDEVICE_BUTTON OnClick"); + } else if (strcmp(view.GetViewId(), SHUTDOWNDEVICE_BUTTON) == 0) { + // 关机 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SHUTDOWNDEVICE_BUTTON OnClick"); + } + return true; +} + +bool RebootPresenter::OnDrag(UIView& view, const DragEvent& event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::OnDrag"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + if (strcmp(view.GetViewId(), REBOOT_VIEW) == 0) { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } else if (strcmp(view.GetViewId(), REBOOTDEVICE_VIEW) == 0) { + if (RebootModel::GetInstance()->GetExitsView() == 0) { + RebootView::GetInstance()->ChangeView(REBOOTDEVICEVIEW, REBOOTVIEW); + } else { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + RebootModel::GetInstance()->SetExitsView(false); + } + } else if (strcmp(view.GetViewId(), SHUTDOWNDEVICE_VIEW) == 0) { + if (RebootModel::GetInstance()->GetExitsView() == 0) { + RebootView::GetInstance()->ChangeView(SHUTDOWNDEVICEVIEW, REBOOTVIEW); + } else { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + RebootModel::GetInstance()->SetExitsView(false); + } + } + } + return true; +} +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/application/wstp/at_service/app/app_at_process.c b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wstp/at_service/app/app_at_process.c new file mode 100644 index 000000000..02492f115 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/application/wstp/at_service/app/app_at_process.c @@ -0,0 +1,2786 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: Media task process + * Author: + * Create: + */ +#if defined(__LITEOS__) +#include "los_memory.h" +#include "los_memory_pri.h" +#ifdef CFG_DRIVERS_MMC +#include "soc/mmc.h" +#endif +#endif + +#ifdef CFG_DRIVERS_MMC +#include "hci.h" +#include "soc_mmc.h" +#endif + +#if defined(__FREERTOS__) +#ifdef FREERTOS_DEBUG +#include "xlt_memory_pri.h" +#include "task_debug.h" +#endif +#endif + +#include "debug_print.h" +#include "td_base.h" +#include "securec.h" +#include "log_file.h" +#include "dfx_adapt_layer.h" +#include "dirent.h" +#include "uart.h" +#include "uapi_crc.h" +#include "tcxo.h" +#include "cmsis_os2.h" +#include "lcd_bus.h" +#include "soc_vau_type.h" +#include "soc_dpu_type.h" +#include "soc_mipi_tx.h" +#include "touch_screen_def.h" +#include "nandflash.h" +#include "efuse.h" +#include "psram_drv.h" +#include "flash.h" +#include "adc.h" +#include "exception.h" +#include "fcntl.h" +#include +#include "common_def.h" +#include "unistd.h" +#include "watchdog.h" +#include "button_porting.h" +#include "hal_reboot.h" +#include "app_msg_manager.h" +#include "sys/statfs.h" +#include "asm/memmap_config.h" +#include "watchdog_porting.h" +#include "thread_init.h" + +#include "pm.h" +#include "pm_veto.h" +#include "pm_lp_stub.h" +#include "pm_definition.h" +#include "build_version.h" +#include "at_cmd_api.h" +#include "app_test_fs.h" +#include "app_common_api.h" +#include "app_tx_process.h" +#include "dfx_feature_config.h" +#include "app_at_process.h" +#include "pm_veto.h" +#include "input_app.h" +#include "lpc_core.h" +#include "diag_msg.h" +#include "pmu_ldo.h" +#include "soc_gmmu_api.h" +#include "pinctrl.h" +#include "non_os_reboot.h" +#include "km.h" +#include "cipher_api.h" +#include "key_deriv_porting.h" +#include "otp_map.h" +#ifdef CFG_DRIVERS_NANDFLASH +#include "nandflash_config.h" +#endif + +#if defined(SW_RTT_DEBUG) +#include "SEGGER_RTT.h" +#endif +#ifdef SUPPORT_POWER_MANAGER +#include "power_display_service.h" +#endif +#include "i2c.h" +#include "calendar.h" + +#ifdef SUPPORT_FILE_SPLIT_COMBINE +#include "msg_center_protocol.h" +#endif + +#ifdef SUPPORT_ALIPAY_SEC +#include "alipay_feature.h" +#endif + +#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) +#define DIAG_RES_LEN 4 +#define FF_VOLUMES_NUM 4 +#define ADC_AUTODATA_PRT_SIZE 4 +#define ADC_AUTODATA_PRT_INDEX1 1 +#define ADC_AUTODATA_PRT_INDEX2 2 +#define ADC_AUTODATA_PRT_INDEX3 3 +#define ADC_AUTODATA_PRT_INDEX4 4 +#define VER_STR_MAX 128 +#define FILE_MAX_NUM 32 +#define MAX_FILE_PATH_LEN 128 +#define TEST_MSG_MAX_SIZE 40 +#define LOG_FILE_ARG_NUM 6 +#define FS_NODE_INFO_SPACE 16 +#define MB_SIZE (1024 * 1024) +#define KB_SIZE (1024) +#define ONE_SECOND (1000000) +#define DTCM_RAM_OFF (400 * 1024) // dtcm偏移,从最后未使用的dtcm作为测试内存 +#define INVALID_HANDLE (0xFFFFFFFF) + +#ifdef CONFIG_PSRAM_SUPPORT +#define LCD_FILL_COLOR_ADDR 0x6D200000 +#else +#define LCD_FILL_COLOR_ADDR 0x60280000 +#endif + +#define POWER_KEY_PARAM_LEN 0x2 +#define CALENDAR_PARAM_LEN 0x6 +#ifdef CFG_DRIVERS_MMC +#define FS_VOLUMES_NUM 4 +#define FS_VOLUME_STRS "/system/", "/user/", "/update/", "/music/" +extern unsigned int mmc_set_clock_with_way2(struct hci_softc *sc, unsigned int cfg_clock); +uint32_t g_app_emmc_clk = SDIOM_SRC_CLK_FREQ_LVL_98M_VAL; +#endif + +#ifdef CFG_DRIVERS_NANDFLASH +#ifndef MEMORY_MINI +#define FS_VOLUMES_NUM 4 +#define FS_VOLUME_STRS "/system/", "/update/", "/music/", "/user/" +#else +#define FS_VOLUMES_NUM 1 +#define FS_VOLUME_STRS "/user/" +#endif +#endif + +#define AT_I2C_PARA_CNT 4 +#define AT_I2C_REG_ARRAY_LEN 8 + +#define AT_PARA_IDX2 2 +#define AT_PARA_IDX3 3 +#define AT_PARA_IDX4 4 +#define AT_PARA_IDX5 5 +#define AT_PARA_IDX6 6 +#define AT_PARA_IDX7 7 +#define AT_PARA_IDX8 8 + +#define OFFSET_8 8 +#define OFFSET_16 16 +#define OFFSET_24 24 + +#define AES_SALT_LENGTH 16 +#define AES_IV_LENGTH 16 +// AES_SAMPLE_TEST_LEN must be an integer multiple of 32 bytes. +#define AES_SAMPLE_TEST_LEN 64 +#define ALIPAY_EXIT_LPM_DELAY_LEN 100 + +#ifdef SUPPORT_FILE_SPLIT_COMBINE +/* 文件拆分合并测试 */ +#define ORIGIN_FILE_PATH "/user/test/ssb.bin" +#define FILE_LIST_PATH "/user/test/flist.txt" +#define COMBINE_FILE_PATH "/user/test/ssb_c.bin" +#endif + +#ifdef SUPPORT_AUTO_OTA +extern uint8_t g_auto_ota_upload_mode; +#ifndef ONE_ADDR_LEN +#define ONE_ADDR_LEN 2 +#endif +#ifndef ADDR_MAC_LEN +#define ADDR_MAC_LEN 6 +#endif +#endif + +const uint8_t g_decrypt_aes_salt[AES_SALT_LENGTH] = { 0x0 }; +const uint8_t g_decrypt_aes_iv[AES_IV_LENGTH] = { 0x0 }; +// The length of the GID must be 32 bytes and cannot be changed. +const uint8_t g_decrypt_aes_gid[OTP_SECURITY_KEY_GID_LEN] = { 0x0 }; +// This is the ASCII code of the string to be encrypted. +const uint8_t g_decrypt_aes_encryp[AES_SAMPLE_TEST_LEN] = {}; +// This is the ASCII code of the string to be decrypted. +const uint8_t g_decrypt_aes_decryp[AES_SAMPLE_TEST_LEN] = {0x15, 0x56, 0xa7, 0x38, 0x7f, 0xd3, 0x69, 0x72, 0x16, + 0x2, 0xda, 0x36, 0xf3, 0x99, 0xcd, 0xf7, 0x49, 0xf4, 0x2d, 0x15, 0x77, 0xd5, 0x4f, 0xdd, 0x14, 0xd1, 0xc3, + 0x7f, 0x41, 0xd6, 0x99, 0x47, 0x2f, 0xb1, 0x34, 0xdf, 0x87, 0xa0, 0x49, 0x53, 0x23, 0x43, 0xf0, 0x96, 0xed, + 0xbf, 0x5, 0x1d, 0x78, 0xc4, 0xa3, 0xfe, 0xf2, 0xa3, 0xb7, 0x8e, 0x29, 0xd9, 0xd0, 0x86, 0xc5, 0x5f, 0xc4, 0x8f}; + +static const char * const g_volume_names[FS_VOLUMES_NUM] = { FS_VOLUME_STRS }; + +#if DSP_L2RAM_AREA_SIZE == 8 +extern void *__l2m_dsp_data_end; +#else +extern void *__l2m_gpu_data_end; +#endif + +diag_ser_header_t g_mcu_diag_header; // 用于保存diag回复包头内容 +bool g_app_diag_flag = false; // 用于控制执行功能后是否回复diag消息 + +pm_id_t g_pm_req_mode_usr = PM_ID_DEBUG; +#ifdef CONFIG_LOW_POWER_TEST +static bool g_dpu_ready_flag = false; +#else +static bool g_dpu_ready_flag = true; +#endif + +void wstp_print(const char *str, ...) +{ + static uint8_t s[256]; // 256 means string max length. + va_list args; + int32_t str_len; + + if ((str == NULL) || (strlen(str) == 0)) { + return; + } + + va_start(args, str); + str_len = vsprintf_s((char *)s, sizeof(s), str, args); + va_end(args); + + if (str_len < 0) { + return; + } +#if defined(SW_RTT_DEBUG) + SEGGER_RTT_Write(0, (const char *)s, str_len); +#else + if (hal_uart_get_funcs(SW_DEBUG_UART_BUS) == NULL) { + return; + } + uapi_uart_write(SW_DEBUG_UART_BUS, (const void *)s, str_len, 0); +#endif +} + +void factory_test_print(const uint8_t return_code, const char *str, ...) +{ + static uint8_t s[256]; // 256 means string max length. + va_list args; + int32_t str_len; + + if ((str == NULL) || (strlen(str) == 0)) { + return; + } + + va_start(args, str); + str_len = vsprintf_s((char *)s, sizeof(s), str, args); + va_end(args); + + if (str_len <= 0) { + return; + } +#ifdef SW_UART_DEBUG + wstp_print("[Factory]|%s.\r\n", s); +#endif +#ifdef FT_BT_UART + at_cmd_send_abt_result_to_bt((const void *)s, str_len); +#endif +#ifdef FT_DONGLE + // 发送spp包 + uint8_t table_len = 2 + str_len; // return_code + str_len + payload + diag_ser_header_t header_temp = { + .ser_id = DIAG_SER_APP_TEST, + .cmd_id = FTDONGLERETURN, + .src = DIAG_FRAME_FID_MCU, // DIAG_FRAME_FID_MCU + .dst = DIAG_FRAME_FID_PHONE, // DIAG_FRAME_FID_PHONE + .crc_en = true, + .ack_en = false, + .length = 2 + table_len, // moduld + cmd + table_len + }; + factory_print_table *ft_table = (factory_print_table*)malloc(sizeof(factory_print_table)); + if (ft_table == NULL) { + return; + } + ft_table->return_code = return_code; + ft_table->payload_len = str_len; + if (memcpy_s(ft_table->payload, FT_PAYLOAD_LEN_MAX, s, str_len) != EOK) { + wstp_print("[Factory]|memcpy_s fail!\r\n"); + free(ft_table); + return; + } + send_spp_diag_msg(true, &header_temp, ft_table, table_len); + free(ft_table); +#endif +} + +void print_at_cmd_ret(int ret) +{ + uint32_t irq_sts = osal_irq_lock(); + if (ret == ERRCODE_SUCC) { + wstp_print("\r\nOK~\r\n"); + } else { + wstp_print("\r\nERR~\r\n"); + } + +#ifdef FT_BT_UART + if (ret == ERRCODE_SUCC) { + at_cmd_send_abt_result_to_bt((uint8_t *)"\r\nOK~\r\n", strlen("\r\nOK~\r\n")); + } else { + at_cmd_send_abt_result_to_bt((uint8_t *)"\r\nERR~\r\n", strlen("\r\nERR~\r\n")); + } +#endif + osal_irq_restore(irq_sts); +} + +/* Diag消息获取TLV中V值数据处理接口 */ +uint32_t parse_tlv_2value(uint8_t* data, uint16_t data_len, uint8_t** out, uint32_t *out_len) +{ + unused(data_len); + uint8_t num[WORD_WIDTH] = {0}; + uint8_t* ptr = data; + uint8_t len; + uint32_t length = 0; + int i; + + ptr++; + // 动态len运算,7bit为1代表剩下0-6bit为真实长度,7bit为0,0-6bit代表后面几个字节为真实长度。 + len = *(uint8_t*)ptr++; + if (((len & BIT7) >> 7) == 1) { + length = len & (~BIT7); + } else { + // 按照len数值,将真实长度数据小端保存到num中,默认最大长度四个字节,已够用 + for (i = 0; i < len; i++) { + num[i] = *ptr++; + } + length = *(uint32_t*)num; + } + *out = ptr; + *out_len = length; + return ERRCODE_SUCC; +} + +/* diag消息再封装转发app task接口 */ +uint32_t mcu_diag_cmd_process(diag_ser_data_t *data) +{ + app_msg_info_t* app_msg; + uint8_t* ptr; + uint32_t paylen; + diag_ser_frame_t* frame = (diag_ser_frame_t*)data->payload; + + if (data == NULL) { + return ERRCODE_FAIL; + } + + parse_tlv_2value(frame->tlv, data->header.length, &ptr, &paylen); + app_msg = (app_msg_info_t*)osal_kmalloc(sizeof(app_msg_info_t) + data->header.length, OSAL_GFP_KERNEL); + if (app_msg == NULL) { + wstp_print("mcu_diag_cmd_process malloc fail!!"NEWLINE); + return ERRCODE_FAIL; + } + (void)memset_s(app_msg, sizeof(app_msg_info_t) + data->header.length, 0, sizeof(app_msg_info_t) + data->header.length); + (void)memcpy_s(&g_mcu_diag_header, sizeof(diag_ser_header_t), &(data->header), sizeof(diag_ser_header_t)); + app_msg->id = data->header.cmd_id; + app_msg->payload_len = paylen; + if (app_msg->payload_len > 0 && data != NULL) { + if (memcpy_s(app_msg->payload, app_msg->payload_len, (const void *)ptr, paylen) != EOK) { + wstp_print("mcu_diag_cmd_process data memcpy error!"NEWLINE); + osal_kfree(app_msg); + return ERRCODE_FAIL; + } + } + g_app_diag_flag = true; + app_at_msg_send((uint8_t *)app_msg, sizeof(app_msg_info_t) + paylen); + osal_kfree(app_msg); + return ERRCODE_SUCC; +} + +/* 封装返回结果成Diag数据回发给BTH SPP +param descrip: + send: 用于控制是否做diag消息回复 + data: 用于传入diag包包头信息 + payload: 回复tlv数据 + pay_len: 回复tlv数据长度 +*/ +uint32_t send_spp_diag_msg(bool send, diag_ser_header_t *data, uint8_t* payload, uint32_t pay_len) +{ + uint8_t size; + diag_ser_data_t* diag_data; + diag_ser_frame_t* frame; + uint32_t result = ERRCODE_FAIL; + + // send为false,则直接返回 + if (send == false) { + return ERRCODE_SUCC; + } + + size = sizeof(diag_ser_data_t) + sizeof(diag_ser_frame_t) + pay_len; + diag_data = (diag_ser_data_t *)malloc(size); + if (diag_data == NULL) { + return ERRCODE_FAIL; + } + + (void)memcpy_s(&(diag_data->header), sizeof(diag_ser_header_t), data, sizeof(diag_ser_header_t)); + frame = (diag_ser_frame_t*)&(diag_data->payload); + frame->module_id = data->ser_id; + frame->cmd_id = data->cmd_id; + (void)memcpy_s(&(frame->tlv), pay_len, payload, pay_len); + diag_data->header.crc_en = 1; + diag_data->header.length = size - sizeof(diag_ser_data_t); + diag_data->header.dst = DIAG_FRAME_FID_PHONE; + diag_data->header.src = data->dst; + result = uapi_diag_service_send_data(diag_data); + free(diag_data); + return result; +} + +uint32_t mcu_os_sys_reset(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint8_t res[DIAG_RES_LEN] = {0x80, 0x82, 0x00, 0x00}; + + send_spp_diag_msg(g_app_diag_flag, &g_mcu_diag_header, res, DIAG_RES_LEN); + reset_deal_with_fs(); + + set_cpu_utils_reset_cause(REBOOT_CAUSE_APPLICATION_SYSRESETREQ); + hal_reboot_chip(); + return ERRCODE_SUCC; +} + +uint32_t mcu_fs_test(uint8_t *para, uint32_t para_len) +{ + test_file_system(para, para_len); + return ERRCODE_SUCC; +} + +uint32_t mcu_os_heap_info(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#if LOSCFG_MEM_TASK_STAT && defined __LITEOS__ + LosMemPoolInfo *heapMan = (LosMemPoolInfo*)OS_EXTEND_MEM_ADDR; + TSK_INFO_S task_info; + uint32_t taskId; + + wstp_print("\r\n"); + OsMemInfoPrint(OS_EXTEND_MEM_ADDR); + wstp_print("\n\t\tstack name task id used size peak size\n"); + for (taskId = 0; taskId <= LOSCFG_BASE_CORE_TSK_LIMIT; taskId++) { + if (0 != LOS_TaskInfoGet(taskId, &task_info)) { + // 过滤掉无用的task id + continue; + } + wstp_print("%22s %-5d 0x%-8x 0x%-8x\n", task_info.acName, taskId, + heapMan->stat.taskMemstats[taskId].memUsed, heapMan->stat.taskMemstats[taskId].memPeak); + } + wstp_print("\r\n\r\n"); + + heapMan = (LosMemPoolInfo*)OS_SYS_MEM_ADDR; + OsMemInfoPrint(OS_SYS_MEM_ADDR); + wstp_print("\n\t\tstack name task id used size peak size\n"); + for (taskId = 0; taskId <= LOSCFG_BASE_CORE_TSK_LIMIT; taskId++) { + if (0 != LOS_TaskInfoGet(taskId, &task_info)) { + // 过滤掉无用的task id + continue; + } + wstp_print("%22s %-5d 0x%-8x 0x%-8x\n", task_info.acName, taskId, + heapMan->stat.taskMemstats[taskId].memUsed, heapMan->stat.taskMemstats[taskId].memPeak); + } + wstp_print("\r\n"); + +#endif +#if defined __FREERTOS__ && defined FREERTOS_DEBUG + freertos_heap_print(); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_os_stack_info(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + +#if LOSCFG_MEM_TASK_STAT && defined __LITEOS__ + TSK_INFO_S task_info; + uint32_t taskId; + + wstp_print("\n stack name task id prio status stack addr total size used size peak size\n" + " -------------- ------- --- ------ --------- -------- -------- --------\n"); + for (taskId = 0; taskId <= LOSCFG_BASE_CORE_TSK_LIMIT; taskId++) { + if (0 != LOS_TaskInfoGet(taskId, &task_info)) { + continue; + } + wstp_print("%22s %-5d %-2d %-2d %-10p 0x%-8x 0x%-8x 0x%-8x\n", task_info.acName, + task_info.uwTaskID, task_info.usTaskPrio, task_info.usTaskStatus, task_info.uwTopOfStack, + task_info.uwStackSize, task_info.uwCurrUsed, task_info.uwPeakUsed); + } +#endif + +#if defined __FREERTOS__ && defined FREERTOS_DEBUG + vTaskInfoPrint(); +#endif + + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_format(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + int ret, i; + + /* 解决后台文件打开导致格式化失败的问题,先关闭可能打开的后台文件*/ + for (i = 0; i < FILE_MAX_NUM; i++) { + close(i); + } + /* 如果离线日志打开,则关闭离线日志 */ + uapi_zdiag_set_offline_log_enable(false); + +#ifdef CFG_DRIVERS_MMC + wstp_print("\r\nemmc format,wait a moment!\r\n"); + ret = emmc_drv_format(); + if (ret != ENOERR) { + ret = ERRCODE_FAIL; + } else { + ret = ERRCODE_SUCC; + } +#endif + +#ifdef CFG_DRIVERS_NANDFLASH + wstp_print("\r\nnandflash format,wait a moment!\r\n"); + nandflash_yaffs_format(); + ret = ERRCODE_SUCC; +#endif + + return ret; +} + +static uint32_t mcu_fs_rw_test(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t *ptr = NULL; + int ret; + char path[] = "/user/user_test.log"; + FILE *fp = NULL; + + fp = fopen(path, "w+"); + if (fp == NULL) { + wstp_print("open fail\r\n"); + return ERRCODE_FAIL; + } + ret = test_libc_rw(fp); + fclose(fp); + remove(path); + + return ret; +} + +static uint32_t mcu_fs_set_clk(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_MMC + char *ptr = (char*)para; + uint8_t mode = 0; + struct hci_softc *sc; + if (para == NULL) { + return ERRCODE_FAIL; + } + + mode = (uint8_t)strtoul(ptr, NULL, 0); + sc = get_mmc_resource(0); + if (mode == 0) { + wstp_print("set emmc clk to 98M!!!\r\n"); + mmc_set_clock_with_way2(sc, SDIOM_SRC_CLK_FREQ_LVL_98M_VAL); + g_app_emmc_clk = SDIOM_SRC_CLK_FREQ_LVL_98M_VAL; + } else if (mode == 1) { + wstp_print("set emmc clk to 32M!!!\r\n"); + mmc_set_clock_with_way2(sc, SDIOM_SRC_CLK_LOW_FREQ_VAL); + g_app_emmc_clk = SDIOM_SRC_CLK_LOW_FREQ_VAL; + } else { + wstp_print("Input para Error!!!\r\n"); + return ERRCODE_FAIL; + } +#endif + + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_read_clk(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_MMC + wstp_print("\r\nclock:%d", g_app_emmc_clk); +#endif + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_check(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t FileSize = 0; + uint32_t times; + uint32_t len; + char FilePath[MAX_FILE_PATH_SIZE] = "/user/"; + FILE *fp = NULL; + + if (para_len == 0) { + return ERRCODE_FAIL; + } + + ptr++; + if (memcpy_s(FilePath + strlen(FilePath), (MAX_FILE_PATH_SIZE - strlen(FilePath) - 1), ptr, + (strchr(ptr, '"') - ptr)) != EOK) { + wstp_print("memcpy ERR!,The file path is too long,\ + the total length of the file path should be less than %d\r\n", MAX_FILE_PATH_SIZE); + return ERRCODE_FAIL; + } + + ptr += (strchr(ptr, '"') - ptr); + ptr += TEST_PARA_2; + FileSize = strtoul(ptr, NULL, 0); + if (FileSize > FS_TEST_1M_BYTES) { FileSize = FS_TEST_1M_BYTES; } + times = (FileSize / BYTES_LEN_4K) ? (FileSize / BYTES_LEN_4K) : 1; + + fp = fopen(FilePath, "r"); + if (fp == NULL) { + wstp_print("open fail!path:%s\r\n", FilePath); + return ERRCODE_FAIL; + } + + len = test_libc_read(fp, times); + fclose(fp); + if (len == times * BYTES_LEN_4K) { + return ERRCODE_SUCC; + } else { + return ERRCODE_FAIL; + } +} + + +static int32_t rm_dir(const char *pathname) +{ + struct dirent *dirent = NULL; + struct stat stat_info; + DIR *d = NULL; + char *fullpath = NULL; + int ret; + + (void)memset_s(&stat_info, sizeof(stat_info), 0, sizeof(struct stat)); + if (stat(pathname, &stat_info) != 0) { + wstp_print("read file info fail! %s, err=%d\n", pathname, get_errno()); + return -1; + } + + if (S_ISREG(stat_info.st_mode)) { + wstp_print("rm path: %s \n", pathname); + return unlink(pathname); + } + d = opendir(pathname); + while (1) { + dirent = readdir(d); + if (dirent == NULL) { + break; + } + if (strcmp(dirent->d_name, "..") && strcmp(dirent->d_name, ".")) { + size_t fullpathBufSize = strlen(pathname) + strlen(dirent->d_name) + 2; // 2 is sep eof length + fullpath = (char *)malloc(fullpathBufSize); + if (fullpath == NULL) { + wstp_print("malloc failure!\n"); + (void)closedir(d); + return -1; + } + ret = snprintf_s(fullpath, fullpathBufSize, fullpathBufSize - 1, "%s/%s", pathname, dirent->d_name); + if (ret < 0) { + wstp_print("name is too long!\n"); + free(fullpath); + (void)closedir(d); + return -1; + } + (void)rm_dir(fullpath); + free(fullpath); + } + } + (void)closedir(d); + return rmdir(pathname); +} + +static uint32_t mcu_fs_rm(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + if (para_len == 0) { + return ERRCODE_FAIL; + } + + char *ptr = (char *)para; + char file_path[MAX_FILE_PATH_SIZE] = ""; + + ptr++; + if (memcpy_s(file_path + strlen(file_path), (MAX_FILE_PATH_SIZE - strlen(file_path) - 1), ptr, + (strchr(ptr, '"') - ptr)) != EOK) { + wstp_print("memcpy ERR!,The file path is %s, max len is %d\r\n", para, MAX_FILE_PATH_SIZE); + return ERRCODE_FAIL; + } + + wstp_print("excute rm path:%s\r\n", file_path); + if (rm_dir(file_path) >= 0) { + return ERRCODE_SUCC; + } else { + return ERRCODE_FAIL; + } +} + +static uint32_t mcu_get_wstp_version(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + char str[VER_STR_MAX]; +#if (defined BUILD_TIME) && (defined TARGET_NAME) + (void)sprintf_s(str, VER_STR_MAX, "\r\nVersion:%s %s %s\r\n", + get_version_string(), TARGET_NAME, BUILD_TIME); +#else + (void)sprintf_s(str, VER_STR_MAX, "\r\nVersion:%s\r\n", get_version_string()); +#endif + wstp_print(str); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_fs_write(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t FileSize = 0; + uint32_t times; + uint32_t len; + char FilePath[MAX_FILE_PATH_SIZE] = "/user/"; + + if (para_len == 0) { + return ERRCODE_FAIL; + } + + ptr++; + if (memcpy_s(FilePath + strlen(FilePath), (MAX_FILE_PATH_SIZE - strlen(FilePath) - 1), ptr, + (strchr(ptr, '"') - ptr)) != EOK) { + wstp_print("memcpy ERR!,The file path is too long,\ + the total length of the file path should be less than %d\r\n", MAX_FILE_PATH_SIZE); + return ERRCODE_FAIL; + } + ptr += (strchr(ptr, '"') - ptr); + ptr += TEST_PARA_2; + FileSize = strtoul(ptr, NULL, 0); + remove(FilePath); + if (FileSize > FS_TEST_1M_BYTES) { FileSize = FS_TEST_1M_BYTES; } + times = (FileSize / BYTES_LEN_4K) ? (FileSize / BYTES_LEN_4K) : 1; + + FILE *fp = NULL; + fp = fopen(FilePath, "w+"); + if (fp == NULL) { + wstp_print("open fail!path:%s\r\n", FilePath); + return ERRCODE_FAIL; + } + + len = test_libc_write(fp, times); + fclose(fp); + if (len == times * BYTES_LEN_4K) { + return ERRCODE_SUCC; + } else { + return ERRCODE_FAIL; + } +} + +#if (CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE == DFX_YES) +static uint32_t mcu_init_logfile(uint8_t *para, store_file_cfg_t *cfg, uint32_t *arr, uint32_t arr_len) +{ + char *ptr = (char *)para; + char *ptr_end = NULL; + + if (strtoul(ptr, &ptr_end, 0) <= 0) { + return ERRCODE_FAIL; + } + + for (uint32_t j = 0; j < arr_len; j++) { + arr[j] = strtoul(ptr, &ptr_end, 0); + ptr = ptr_end + 1; + } + + uint32_t clear_flag = 0; + uint32_t i = 0; + + cfg->mult_files = arr[i++]; + cfg->file_size = arr[i++]; + cfg->enable_cache = arr[i++]; + cfg->cache_size = arr[i++]; + i++; + clear_flag = arr[i]; + cfg->path = "/user/test/"; + cfg->name = "log_file_write_0222.bin"; + wstp_print("mult_files = %d, file_size = %d, enable_cache = %d, cache_size = %d clear_flag = %d\r\n", + cfg->mult_files, cfg->file_size, cfg->enable_cache, cfg->cache_size, clear_flag); + + errcode_t ret = uapi_logfile_init(); + if (ret != ERRCODE_SUCC) { + wstp_print("init logfile %s failed.\r\n", cfg->name); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +static uint32_t mcu_clear_logfile_dir(store_file_cfg_t *cfg) +{ + static uint8_t full_path[MAX_FILE_PATH_LEN] = {0}; + struct dirent *pdirent = NULL; + DIR *d = NULL; + uint32_t ret = ERRCODE_SUCC; + + d = opendir(cfg->path); + if (d == NULL) { + if (mkdir(cfg->path, S_IREAD | S_IWRITE) != 0) { + wstp_print("mkdir %s failed!\r\n", cfg->path); + ret = ERRCODE_FAIL; + } + } else { + do { + pdirent = readdir(d); + if (pdirent == NULL) { + break; + } + wstp_print("file_dir clear start!\r\n"); + if (strncpy_s((char *)full_path, MAX_FILE_PATH_LEN, cfg->path, strlen(cfg->path)) != EOK) { + ret = ERRCODE_FAIL; + break; + } + if (strcat_s((char *)full_path, MAX_FILE_PATH_LEN, pdirent->d_name) != EOK) { + ret = ERRCODE_FAIL; + break; + } + if (remove((char *)full_path) != 0) { + wstp_print("remove %s failed!\r\n", full_path); + ret = ERRCODE_FAIL; + break; + } + } while (pdirent != NULL); + } + (void)closedir(d); + return ret; +} +#endif /* CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE */ + +static uint32_t mcu_logfile_write(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#if (CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE == DFX_YES) + wstp_print("logfile test start!\r\n"); + char test_msg[TEST_MSG_MAX_SIZE] = {0}; + #define TEST_NUM_ID 4 + /* + arg[0] -- multi_num + arg[1] -- file_size + arg[2] -- enable_cache + arg[3] -- cache_size + arg[4] -- test timer + arg[5] -- clear flag + */ + uint32_t arg[LOG_FILE_ARG_NUM] = {0}; + store_file_cfg_t cfg = {0}; + + if (mcu_init_logfile(para, &cfg, arg, LOG_FILE_ARG_NUM) != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + + if (arg[LOG_FILE_ARG_NUM - 1] != 0) { /* arg[5] -- clear flag */ + if (mcu_clear_logfile_dir(&cfg) != ERRCODE_SUCC) { + wstp_print("clear file_dir error!\r\n"); + return ERRCODE_FAIL; + } + } + + errcode_t ret = uapi_logfile_open(STORE_DIAG, &cfg); + if (ret != ERRCODE_SUCC) { + wstp_print("open log_file %s failed.\r\n", cfg.name); + return ERRCODE_FAIL; + } + + for (uint32_t i = 0; i < arg[TEST_NUM_ID]; i++) { /* arg[2] -- test timer */ + (void)memset_s(test_msg, sizeof(test_msg), 0, sizeof(test_msg)); + if (sprintf_s(test_msg, sizeof(test_msg), "abcdef%10d", i + 1) < 0) { + wstp_print("sprintf_s failed.\r\n"); + return ERRCODE_FAIL; + } + ret = uapi_logfile_write(STORE_DIAG, 0, (uint8_t*)&test_msg, strlen(test_msg)); + if (ret != ERRCODE_SUCC) { + wstp_print("write logfile failed.\r\n"); + return ERRCODE_FAIL; + } + dfx_sleep(10); /* 10 : sleep 10ms */ + } + + ret = uapi_logfile_close(STORE_DIAG); + if (ret != ERRCODE_SUCC) { + wstp_print("close logfile %s failed.\r\n", cfg.name); + return ERRCODE_FAIL; + } +#endif /* CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE */ + return ERRCODE_SUCC; +} + +uint32_t mcu_test_dtcm_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + + char *test_buf = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, APP_DTCM_ORIGIN, BUFF_LEN_48K) != 0) { + wstp_print("[dctm mem test]dtcm read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time); + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[dctm mem test]dtcm read time:%dus bw:%dMB/s\r\n", total_time, bw); + + irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, APP_DTCM_ORIGIN, BUFF_LEN_48K) != 0) { + wstp_print("[dctm mem test]dtcm write memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time); + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[dctm mem test]dtcm write time:%dus bw:%dMB/s\r\n", total_time, bw); + return ERRCODE_SUCC; +} + +uint32_t mcu_test_l2m_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + +#if DSP_L2RAM_AREA_SIZE == 8 + char* l2m_ptr = (char*)(&__l2m_dsp_data_end); +#else + char* l2m_ptr = (char*)(&__l2m_gpu_data_end); +#endif + char *test_buf = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, l2m_ptr, BUFF_LEN_48K) != 0) { + wstp_print("[l2ram mem test]l2ram read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = end_time - start_time; + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[l2m mem test]l2m read time:%dus bw:%dMB/s\r\n", total_time, bw); + + irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(l2m_ptr, BUFF_LEN_48K, test_buf, BUFF_LEN_48K) != 0) { + wstp_print("[l2ram mem test]l2ram write memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = end_time - start_time; + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[l2m mem test]l2m write time:%dus bw:%dMB/s\r\n", total_time, bw); + + return ERRCODE_SUCC; +} + +uint32_t mcu_test_mmc_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_MMC + char* path = "/user/test_spped.bin"; + wstp_print("emmc fs bw test start!please wait...\r\n"); + fs_test_rw_speed(path, BYTES_LEN_128); + fs_test_rw_speed(path, BYTES_LEN_512); + fs_test_rw_speed(path, BYTES_LEN_1K); + fs_test_rw_speed(path, BYTES_LEN_4K); + fs_test_rw_speed(path, BYTES_LEN_8K); +#else + wstp_print("[emmc mem test]The current version does not support EMMC.\r\n"); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_test_psram_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + +#ifdef CONFIG_PSRAM_SUPPORT + char *test_buf = (char*)malloc(BUFF_LEN_48K); + if (test_buf == NULL) { + wstp_print("[psram mem test]buf malloc fail!\r\n"); + return ERRCODE_FAIL; + } + char *test_buf1 = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf1, BUFF_LEN_48K, test_buf, BUFF_LEN_48K) != 0) { + wstp_print("[psram mem test]psram read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time) - TCXO_ERROR; + bw = ONE_SECOND / total_time * BUFF_LEN_48K / MB_SIZE; + wstp_print("[psram mem test]psram read time:%dus bw:%dMB/s\r\n", total_time, bw); + + irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, test_buf1, BUFF_LEN_48K) != 0) { + wstp_print("[psram mem test]psram write memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time) - TCXO_ERROR; + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[psram mem test]psram write time:%dus bw:%dMB/s\r\n", total_time, bw); + free(test_buf); +#else + wstp_print("[psram mem test]The current version does not support PSRAM.\r\n"); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_test_norflash_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint64_t start_time, end_time; + uint32_t total_time; + uint32_t bw; + + char *test_buf = (char*)(APP_DTCM_ORIGIN + DTCM_RAM_OFF); + uint32_t irq_sts = osal_irq_lock(); + start_time = uapi_tcxo_get_us(); + if (memcpy_s(test_buf, BUFF_LEN_48K, FLASH_RESERVED_ADDR, BUFF_LEN_48K) != 0) { + wstp_print("[norflash mem test]norflash read memcpy_s fail.\r\n"); + } + end_time = uapi_tcxo_get_us(); + osal_irq_restore(irq_sts); + total_time = (uint32_t)(end_time - start_time); + bw = (ONE_SECOND / total_time) * BUFF_LEN_48K / (MB_SIZE); + wstp_print("[norflash mem test]nor flash read time:%dus bw:%dMB/s\r\n", total_time, bw); + + return ERRCODE_SUCC; +} + +uint32_t mcu_test_nandflash_baudwidth(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef CFG_DRIVERS_NANDFLASH + char* path = "/user/test_spped.bin"; + wstp_print("nandflash fs bw test start!please wait...\r\n"); + fs_test_rw_speed(path, BYTES_LEN_128); + fs_test_rw_speed(path, BYTES_LEN_512); + fs_test_rw_speed(path, BYTES_LEN_1K); + fs_test_rw_speed(path, BYTES_LEN_4K); + fs_test_rw_speed(path, BYTES_LEN_8K); +#else + wstp_print("[nandflash mem test]The current version does not support nandflash.\r\n"); +#endif + return ERRCODE_SUCC; +} + +uint32_t mcu_get_fs_info(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + int i; + struct statfs file_buf = {0}; + + for (i = 0; i < FS_VOLUMES_NUM; i++) { + /* 获取文件系统状态 */ + if (statfs(g_volume_names[i], &file_buf) != 0) { + return ERRCODE_FAIL; + } + + if (file_buf.f_bfree >= FS_NODE_INFO_SPACE) { + file_buf.f_bfree = file_buf.f_bfree - FS_NODE_INFO_SPACE; + } else { + file_buf.f_bfree = 0; + } + + wstp_print("[FS INFO]%s:\r\n", g_volume_names[i]); + wstp_print("[FS INFO]total size=%uKB used size=%uKB free size=%uKB\r\n", + ((uint32_t)(file_buf.f_blocks * file_buf.f_bsize) / KB_SIZE), + ((uint32_t)((file_buf.f_blocks - file_buf.f_bfree) * file_buf.f_bsize) / KB_SIZE), + ((uint32_t)(file_buf.f_bfree * file_buf.f_bsize) / KB_SIZE)); + } + + return ERRCODE_SUCC; +} + +static void pm_lcd_on_pre_handle(void) +{ + display_resume_power_on(); +#ifdef QSPI_DISPLAY + writew(0x5700c058, 0x0); // sagpio_l22 set gpio mode +#else + writew(0x5700c058, 0x1); // sagpio_l22 set te mode +#endif + writew(0x5700c658, 0x2); // sagpio_l22 open ie +#ifndef QSPI_DISPLAY + pmu_ldo_power_on(PMU_LDO_AUXLDO3, TURN_ON); +#endif +} + +uint32_t mcu_pm_lcd_on(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef SUPPORT_POWER_MANAGER + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + return display_api->turn_on_screen(); +#endif + uapi_pm_request_mode(PM_ID_VIDEO, PM_MODE_PERFORMACE); + + if (lcd_get_status()) { + wstp_print("\r\nLCD has benn on\r\n"); + return ERRCODE_SUCC; + } + pm_lcd_on_pre_handle(); + lcd_bus_api *bus_api = lcd_get_bus_api(); + ext_errno ret = bus_api->bus_resume(); + if (ret != 0) { + wstp_print("bus resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#ifndef QSPI_DISPLAY + if (g_dpu_ready_flag == false) { + ret = drv_dpu_resume(NULL); + if (ret != 0) { + wstp_print("drv dpu resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } + } +#endif +#ifdef SUPPORT_GPU_JPEG + (void)drv_jpeg_resume(NULL); +#endif + ret = drv_vau_resume(NULL); + if (ret != 0) { + wstp_print("drv vau resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#ifdef SUPPORT_GPU_GMMU + ret = drv_gmmu_resume(NULL); + if (ret != 0) { + wstp_print("drv gmmu resume error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#endif + ret = uapi_lcd_init(); + if (ret != 0 && ret != EXT_ERR_MIPI_ALREADY_INIT) { + wstp_print("LCD init error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) + NotifyScreenOn(); // Instruct the uikit to start the display operation. +#endif + if (g_dpu_ready_flag == false) { + touch_screen_resume(); // open touch + } +#ifdef CONFIG_CLDO1PD_SUPPORT + pmu_control_cldo1_sleep_bypass(TURN_ON); +#endif + lcd_set_status(true); + return ERRCODE_SUCC; +} +uint32_t mcu_pm_into_ship_mode(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uapi_sys_shipmode(0); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_into_force_ds_mode(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + set_cpu_utils_reset_cause(REBOOT_CAUSE_APPLICATION_SYSRESETREQ); + writew(0x5702C010, 0x5A5A); + hal_reboot_chip(); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_req_mode(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + + if (strcmp((char*)para, "lp") == 0) { + errcode_t ret = uapi_pm_request_mode(g_pm_req_mode_usr, PM_MODE_LP); + wstp_print("pm requst mode user 0x%x reuest mode lp, ret 0x%x.\r\n", g_pm_req_mode_usr, ret); + } else if (strcmp((char*)para, "performace") == 0) { + errcode_t ret = uapi_pm_request_mode(g_pm_req_mode_usr, PM_MODE_PERFORMACE); + wstp_print("pm requst mode user 0x%x reuest mode perfermance, ret 0x%x.\r\n", g_pm_req_mode_usr, ret); + } else if (strcmp((char*)para, "normal") == 0) { + errcode_t ret = uapi_pm_request_mode(g_pm_req_mode_usr, PM_MODE_NORMAL); + wstp_print("pm requst mode user 0x%x reuest mode normal, ret 0x%x.\r\n", g_pm_req_mode_usr, ret); + } else if (strcmp((char*)para, "clean") == 0) { + for (pm_id_t i = 0; i < PM_ID_MAX; i++) { + uapi_pm_request_mode(i, PM_MODE_LP); + } + wstp_print("pm mode back to lp mode for all users.\r\n"); + } else { + wstp_print("pm request mode is not supported.\r\n"); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +uint32_t mcu_set_pm_req_mode_usr(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + uint8_t pm_id = *(char*)para - '0'; + + if (pm_id >= PM_ID_MAX) { + wstp_print("pm requst mode user 0x%x check fail.\r\n", pm_id); + return ERRCODE_FAIL; + } + g_pm_req_mode_usr = (pm_id_t)pm_id; + + wstp_print("pm requst mode user 0x%x reuest mode.\r\n", g_pm_req_mode_usr); + return ERRCODE_SUCC; +} + +static void pm_print_veto_info(void) +{ + uint8_t i = 0; + pm_veto_t *pm_veto_ptr = pm_veto_get_info(); + wstp_print("last_veto_id=%d, last_veto_lr=%x, veto_timeout_timestamp=%llu, total_counts=%d\r\n", + pm_veto_ptr->last_veto_id, pm_veto_ptr->last_veto_lr, pm_veto_ptr->veto_timeout_timestamp, + pm_veto_ptr->veto_counts.total_counts); + for (i = 0; i < PM_ID_MAX; i++) { + wstp_print("sub_counts[%d] = %d\r\n", i, pm_veto_ptr->veto_counts.sub_counts[i]); + } +} + +static void lpc_print_veto_info(void) +{ + uint8_t i = 0; + volatile lpc_veto_type *lpc_veto_ptr = lpc_get_sys_sleep_veto(); + wstp_print("g_lpc_mcpu_i2c_sleep_vetos=%d\r\n", lpc_get_mcpu_i2c_sleep_veto()); + for (i = 0; i < LPC_ID_MAX; i++) { + wstp_print("i=%d, lpc_sleep_vetos=%d, lr_pointer=%x\r\n", + i, lpc_veto_ptr[i].lpc_sleep_vetos, lpc_veto_ptr[i].lr_pointer); + } +} + +uint32_t mcu_pm_dfx_mode(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uapi_get_current_pm_mode_info(); + pm_print_veto_info(); + lpc_print_veto_info(); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_cldo1_power_down(uint8_t *para, uint32_t para_len) +{ + unused(para); + + if (strcmp((char*)para, "yes") == 0) { + pmu_control_cldo1_sleep_bypass(TURN_OFF); + wstp_print("pm request cldo1 power down at sleep.\r\n"); + } else if (strcmp((char*)para, "no") == 0) { + pmu_control_cldo1_sleep_bypass(TURN_ON); + wstp_print("pm request cldo1 power on at sleep.\r\n"); + } else { + wstp_print("pm request cldo1 para is not supported.\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +static void mcu_aes_get_password(uint32_t keyslot) +{ + errcode_t ret; + uapi_drv_klad_attr_t test_klad_attr = { + .klad_cfg = { + .rootkey_type = UAPI_DRV_KDF_HARD_KEY_TYPE_ABRK_REE, + }, + .key_cfg = { + .engine = UAPI_DRV_KLAD_ENGINE_AES, + .decrypt_support = true, + .encrypt_support = true, + }, + }; + uapi_drv_klad_effective_key_t test_klad_key = { + .kdf_hard_alg = UAPI_DRV_KDF_HARD_ALG_SHA256, + .key_parity = false, + .key_size = 16, // 16 固定的密钥长度 + .salt = (uint8_t *)g_decrypt_aes_salt, + .salt_length = sizeof(g_decrypt_aes_salt), + }; + + uint32_t klad; + ret = uapi_drv_klad_create(&klad); + if (ret != ERRCODE_SUCC) { + return; + } + + ret = uapi_drv_klad_attach(klad, UAPI_DRV_KLAD_DEST_MCIPHER, keyslot); + if (ret != ERRCODE_SUCC) { + return; + } + + ret = uapi_drv_klad_set_attr(klad, &test_klad_attr); + if (ret != ERRCODE_SUCC) { + (void)uapi_drv_klad_destroy(klad); + return; + } + + ret = uapi_drv_klad_set_effective_key(klad, &test_klad_key); + if (ret != ERRCODE_SUCC) { + (void)uapi_drv_klad_destroy(klad); + return; + } + + ret = uapi_drv_klad_detach(klad, UAPI_DRV_KLAD_DEST_MCIPHER, keyslot); + if (ret != ERRCODE_SUCC) { + wstp_print("[ERR] %d, %s (%d)\n", ret, __FUNCTION__, __LINE__); + (void)uapi_drv_klad_destroy(klad); + return; + } + + (void)uapi_drv_klad_destroy(klad); +} + +static errcode_t mcu_test_crypto_cipher_create(uint32_t *cipher, uint32_t *keyslot) +{ + errcode_t ret; + uapi_drv_cipher_symc_attr_t cipher_attr = { + .symc_alg = UAPI_DRV_CIPHER_SYMC_ALG_AES, + .work_mode = UAPI_DRV_CIPHER_SYMC_WORK_MODE_CBC, + .symc_type = UAPI_DRV_CIPHER_SYMC_TYPE_NORMAL, + .is_long_term = true + }; + + ret = uapi_drv_cipher_symc_create(cipher, &cipher_attr); + if (ret != ERRCODE_SUCC) { + return ret; + } + + ret = uapi_drv_keyslot_create(keyslot, UAPI_DRV_KEYSLOT_TYPE_MCIPHER); + if (ret != ERRCODE_SUCC) { + goto cleanup0; + } + + ret = uapi_drv_cipher_symc_attach(*cipher, *keyslot); + if (ret != ERRCODE_SUCC) { + goto cleanup1; + } + + return ERRCODE_SUCC; + +cleanup1: + (void)uapi_drv_keyslot_destroy(*keyslot); +cleanup0: + (void)uapi_drv_cipher_symc_destroy(*cipher); + + return ret; +} + +static errcode_t mcu_aes_cipher_process(aes_cypto_t crypt, uint8_t *src, uint8_t *dst, uint32_t len) +{ + errcode_t ret = ERRCODE_SUCC; + uint32_t cipher = INVALID_HANDLE; + uint32_t keyslot = INVALID_HANDLE; + uapi_drv_cipher_buf_attr_t src_buf = { .phys_addr = src, .buf_sec = UAPI_DRV_CIPHER_BUF_NONSECURE, }; + uapi_drv_cipher_buf_attr_t dst_buf = { .phys_addr = dst, .buf_sec = UAPI_DRV_CIPHER_BUF_NONSECURE, }; + + uapi_drv_cipher_symc_ctrl_t ctrl = { + .symc_alg = UAPI_DRV_CIPHER_SYMC_ALG_AES, + .work_mode = UAPI_DRV_CIPHER_SYMC_WORK_MODE_CBC, + .symc_key_length = UAPI_DRV_CIPHER_SYMC_KEY_128BIT, + .symc_bit_width = UAPI_DRV_CIPHER_SYMC_BIT_WIDTH_128BIT, + .iv_change_flag = UAPI_DRV_CIPHER_SYMC_IV_CHANGE_ONE_PKG, + .iv_length = sizeof(g_decrypt_aes_iv), + }; + + (void)memcpy_s(ctrl.iv, sizeof(ctrl.iv), g_decrypt_aes_iv, sizeof(g_decrypt_aes_iv)); + + ret = mcu_test_crypto_cipher_create(&cipher, &keyslot); + if (ret != ERRCODE_SUCC) { + return ret; + } + + ret = uapi_drv_cipher_symc_set_config(cipher, &ctrl); + if (ret != ERRCODE_SUCC) { + return ret; + } + + mcu_aes_get_password(keyslot); + + if (crypt == AES_ENCRYPT_TEST) { + ret = uapi_drv_cipher_symc_encrypt(cipher, &src_buf, &dst_buf, len); + } else { + ret = uapi_drv_cipher_symc_decrypt(cipher, &src_buf, &dst_buf, len); + } + + (void)uapi_drv_cipher_symc_detach(cipher, keyslot); + (void)uapi_drv_keyslot_destroy(keyslot); + (void)uapi_drv_cipher_destroy(cipher); + return ret; +} + +uint32_t mcu_aes_decrypt_sample(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint32_t test_len = AES_SAMPLE_TEST_LEN; + uint8_t *test_src_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_src_addr == NULL) { + return ERRCODE_FAIL; + } + uint8_t *test_dst_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_dst_addr == NULL) { + free(test_src_addr); + return ERRCODE_FAIL; + } + + (void)memset_s(test_src_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + (void)memset_s(test_dst_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + + wstp_print("mcu aes decrypt sample start.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + test_src_addr[i] = g_decrypt_aes_decryp[i]; + } + mcu_aes_cipher_process(AES_DECRYPT_TEST, test_src_addr, test_dst_addr, AES_SAMPLE_TEST_LEN); + wstp_print("mcu aes decrypt result.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + wstp_print("i=0x%x, src=0x%02x, dst=0x%02x\r\n", i, test_src_addr[i], test_dst_addr[i]); + } + wstp_print("mcu aes decrypt sample end.\r\n"); + free(test_src_addr); + free(test_dst_addr); + return ERRCODE_SUCC; +} + +uint32_t mcu_aes_encrypt_sample(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint32_t test_len = AES_SAMPLE_TEST_LEN; + uint8_t *test_src_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_src_addr == NULL) { + return ERRCODE_FAIL; + } + uint8_t *test_dst_addr = (uint8_t*)malloc(sizeof(uint8_t) * AES_SAMPLE_TEST_LEN); + if (test_dst_addr == NULL) { + free(test_src_addr); + return ERRCODE_FAIL; + } + + (void)memset_s(test_src_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + (void)memset_s(test_dst_addr, AES_SAMPLE_TEST_LEN, 0, AES_SAMPLE_TEST_LEN); + + wstp_print("mcu aes encrypt sample start.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + test_src_addr[i] = g_decrypt_aes_encryp[i]; + } + mcu_aes_cipher_process(AES_ENCRYPT_TEST, test_src_addr, test_dst_addr, AES_SAMPLE_TEST_LEN); + wstp_print("mcu aes encrypt result.\r\n"); + for (uint32_t i = 0; i < AES_SAMPLE_TEST_LEN; i++) { + wstp_print("i=0x%x, src=0x%02x, dst=0x%02x\r\n", i, test_src_addr[i], test_dst_addr[i]); + } + wstp_print("mcu aes encrypt sample end.\r\n"); + free(test_src_addr); + free(test_dst_addr); + return ERRCODE_SUCC; +} + +uint32_t mcu_aes_set_gid(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t i; + uint8_t security_key = 0; + // After security_Key is set, GID cannot be configured and read. + (void)uapi_efuse_read_bit(&security_key, OTP_DEBUG_FUSED, OTP_DEBUG_FUSED_SECURIY_KEY_EN_ACCESS_BIT); + if (security_key == 0x1) { + wstp_print("gid forbit read, because security_key is closed.\r\n"); + return ERRCODE_FAIL; + } + + uint8_t *test_efuse_gid = (uint8_t*)malloc(sizeof(uint8_t) * OTP_SECURITY_KEY_GID_LEN); + if (test_efuse_gid == NULL) { + return ERRCODE_FAIL; + } + (void)memset_s(test_efuse_gid, OTP_SECURITY_KEY_GID_LEN, 0, OTP_SECURITY_KEY_GID_LEN); + (void)uapi_efuse_read_buffer(test_efuse_gid, OTP_SECURITY_KEY_GID, OTP_SECURITY_KEY_GID_LEN); + for (i = 0; i < OTP_SECURITY_KEY_GID_LEN; i++) { + wstp_print("current gid[0x%02x] val[0x%02x]\r\n", i, test_efuse_gid[i]); + } + wstp_print("start write into efuse gid.\r\n"); + (void)uapi_efuse_write_buffer(OTP_SECURITY_KEY_GID, g_decrypt_aes_gid, OTP_SECURITY_KEY_GID_LEN); + wstp_print("write into efuse gid completely.\r\n"); + (void)uapi_efuse_read_buffer(test_efuse_gid, OTP_SECURITY_KEY_GID, OTP_SECURITY_KEY_GID_LEN); + for (i = 0; i < OTP_SECURITY_KEY_GID_LEN; i++) { + wstp_print("write into gid[0x%02x] val[0x%02x]\r\n", i, test_efuse_gid[i]); + } + (void)uapi_efuse_write_bit(OTP_DEBUG_FUSED, OTP_DEBUG_FUSED_SECURIY_KEY_EN_ACCESS_BIT); + wstp_print("gid read locked.\r\n"); + free(test_efuse_gid); + return ERRCODE_SUCC; +} + +#if defined(CONFIG_ADC_SUPPORT_AUTO_SCAN) +#define ADC_SAMPLE_TIMES 10 +#define ADC_SAMPLE_DATA_LEN 10010 +uint32_t g_adc_sample_times = 0; +uint32_t g_save_adc_index = 0; +uint32_t *g_save_adc_data = NULL; +static uint32_t adc_auto_sample_show_data(uint8_t *para, uint32_t para_len) +{ + wstp_print("g_save_adc_index = %d\r\n", g_save_adc_index); + for (uint32_t i = 0; i < g_save_adc_index; i++) { + wstp_print("%d\r\n", g_save_adc_data[i]); + } + + g_save_adc_index = 0; + g_adc_sample_times = 0; + free(g_save_adc_data); + g_save_adc_data = NULL; + return ERRCODE_SUCC; +} + +static void adc_autosample_callback(uint8_t channel, uint32_t *buffer, uint32_t length, bool *next) +{ + unused(next); + if (g_adc_sample_times >= ADC_SAMPLE_TIMES) { + wstp_print("g_adc_sample_times = %d\r\n", g_adc_sample_times); + uapi_adc_auto_scan_ch_disable(channel); + return; + } + + memcpy_s(g_save_adc_data + g_save_adc_index, length * sizeof(uint32_t), buffer, length * sizeof(uint32_t)); + g_save_adc_index += length; + g_adc_sample_times++; + wstp_print("length = %d\r\n", length); + return; +} + +static uint32_t adc_auto_sample_by_diag(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + uint32_t channel = 0; + uint32_t freq = 0; + uint32_t sample_time = 0; + uint32_t idx = 0; + uint32_t tmp[ADC_AUTODATA_PRT_INDEX3] = {0}; + token = strtok_s((char*)ptr, ",", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 10); // 10: 十进制 + token = strtok_s(NULL, ",", &next_token); + } + channel = tmp[0]; + freq = tmp[ADC_AUTODATA_PRT_INDEX1]; + sample_time = tmp[ADC_AUTODATA_PRT_INDEX2]; + + adc_scan_config_t config = {0}; + config.freq = (uint8_t)freq; + config.long_sample_time = sample_time; + + g_save_adc_data = (uint32_t *)malloc(sizeof(uint32_t) * ADC_SAMPLE_DATA_LEN); + if (g_save_adc_data == NULL) { + wstp_print("malloc g_save_adc_data fail!\r\n"); + return ERRCODE_FAIL; + } + (void)uapi_adc_init(ADC_CLOCK_500KHZ); + (void)uapi_adc_power_en(AFE_SCAN_MODE_MAX_NUM, true); + return(uapi_adc_auto_scan_ch_enable((uint8_t)channel, config, adc_autosample_callback)); +} + +static uint32_t adc_auto_sample_disable(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + uint32_t ret = 0; + uint32_t channel = strtoul(ptr, NULL, 10); // 10: 十进制 + wstp_print("disable adc auto sample , channel = %x\r\n", channel); + + return(uapi_adc_auto_scan_ch_disable(channel)); +} +#endif + +static void pm_lcd_off_handle(void) +{ + writew(0x570000c0, 0x0); // display logic crg reset + writew(0x57004034, 0x100); // display close power +#ifndef QSPI_DISPLAY + pmu_ldo_power_on(PMU_LDO_AUXLDO3, TURN_OFF); + hal_pmu_auxldo_enable_high_resistance(HAL_PMU_AUXLDO3, TURN_ON); +#endif +#ifdef CONFIG_CLDO1PD_SUPPORT + pmu_control_cldo1_sleep_bypass(TURN_OFF); +#endif +} + +uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); +#ifdef SUPPORT_POWER_MANAGER + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + return display_api->turn_off_screen(); +#endif + if (!lcd_get_status()) { + wstp_print("\r\nLCD has benn off\r\n"); + return ERRCODE_SUCC; + } +#if defined(ENABLE_UIKIT) || defined(ENABLE_LVGL) + NotifyScreenOff(); // Instruct the uikit to close the display operation. +#endif + osDelay(100); // Wait 100ms for the uikit to complete display. + touch_screen_suspend(); // close touch + ext_errno ret = drv_vau_suspend(NULL); + if (ret != 0) { + wstp_print("drv vau suspend error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#ifdef SUPPORT_GPU_JPEG + (void)drv_jpeg_suspend(NULL); +#endif +#ifndef QSPI_DISPLAY + ret = drv_dpu_suspend(NULL); + if (ret != 0) { + wstp_print("drv dpu suspend error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#endif +#ifdef SUPPORT_GPU_GMMU + ret = drv_gmmu_suspend(NULL); + if (ret != 0) { + wstp_print("drv gmmu suspend error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } +#endif + ret = uapi_lcd_deinit(); + if (ret != 0) { + wstp_print("lcd deinit error ret=%x\r\n", ret); + return ERRCODE_FAIL; + } + pm_lcd_off_handle(); + lcd_set_status(false); + g_dpu_ready_flag = false; + display_suspend_power_off(); + uapi_pm_request_mode(PM_ID_VIDEO, PM_MODE_LP); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_add_vote(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_DEBUG); + if (cnt == 0) { + uapi_pm_add_sleep_veto(PM_ID_DEBUG); + } else { + wstp_print("MCU has got pm_id_debug vote\r\n"); + } + wstp_print("\r\nMCU WAKEUP SUCCESS\r\n"); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_remove_vote(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_DEBUG); + if (cnt == 1) { + uapi_pm_remove_sleep_veto(PM_ID_DEBUG); + } else { + wstp_print("MCU has delete pm_id_debug vote\r\n"); + } + wstp_print("\r\nMCU SLEEP SUCCESS\r\n"); + uapi_tcxo_delay_ms(5); // delay 5ms for print debug infor with uart + return ERRCODE_SUCC; +} + +uint32_t mcu_dfx_get_cur_second(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uint32_t cur_second = dfx_get_cur_second(); + + wstp_print("cur_second = %d\r\n", cur_second); + return ERRCODE_SUCC; +} + +uint32_t get_ids(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + uint16_t nandflash_id; + uapi_nandflash_read_id(&nandflash_id); + wstp_print("[nandflash id:] %x\r\n", nandflash_id); +#endif + flash_info_t norflash_id; + uapi_flash_get_info(0, &norflash_id); + wstp_print("[norflash id:] %x\r\n", norflash_id.flash_id); + wstp_print("[sdk id:]%s \r\n", uapi_sdk_read_id()); + uint8_t soc_id[20]; // 20 is soc id length + uapi_soc_read_id(soc_id, 20); // 20 is soc id length + wstp_print("[soc id:]\r\n"); + for (uint8_t i = 0; i < 20; i += 2) { // 20 is soc id length, 2 means use 16bits + wstp_print("0x%04X ", *((uint16_t *)&soc_id[i])); + if ((i + 2) % 8 == 0) { wstp_print("\r\n"); } // 2&8 will word wrap + } + wstp_print("\r\n"); + return ERRCODE_SUCC; +} + +uint32_t lcd_test_light(uint8_t *data, uint32_t data_len) +{ + char *ptr = (char *)data; + uint32_t light_input = strtoul(ptr, NULL, 16); + wstp_print("light = %x \r\n", light_input); + uapi_lcd_set_brightness(light_input); + return ERRCODE_SUCC; +} + +uint32_t at_nand_write_read(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t page = strtoul(ptr, NULL, 10); + wstp_print("page = %d \r\n", page); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (page >= freertos_nandflash_driver->pages_per_block * freertos_nandflash_driver->total_block) { + wstp_print("page error exceed max page = %d \r\n", page); + return ERRCODE_FAIL; + } + test_nand_flash_read_8(freertos_nandflash_driver, page); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_write_write(uint8_t *data, uint32_t data_len) +{ + PRINT("nand wite\r\n"); +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t page = strtoul(ptr, NULL, 10); + wstp_print("page = %d \r\n", page); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (page >= freertos_nandflash_driver->pages_per_block * freertos_nandflash_driver->total_block) { + wstp_print("page error exceed max page = %d \r\n", page); + return ERRCODE_FAIL; + } + test_nand_flash_write_width8(freertos_nandflash_driver, page); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_write_erase(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t block = strtoul(ptr, NULL, 10); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + wstp_print("block = %d total_block = %d\r\n", block, freertos_nandflash_driver->total_block); + if (block >= freertos_nandflash_driver->total_block) { + erase_all(freertos_nandflash_driver); + wstp_print("erase all block\r\n"); + return ERRCODE_SUCC; + } + freertos_nandflash_driver->erase_block(block); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_mark_bad(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t block = strtoul(ptr, NULL, 10); + wstp_print("mark block%d = %x is bad\r\n", block); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (block >= freertos_nandflash_driver->total_block) { + wstp_print("exceed max block = %d \r\n", block); + return ERRCODE_FAIL; + } + freertos_nandflash_driver->mark_bad_block(block); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_check_bad(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t block = strtoul(ptr, NULL, 10); + wstp_print("check block%d = %x is bad?\r\n", block); + struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + if (block >= freertos_nandflash_driver->total_block) { + wstp_print("exceed max block = %d \r\n", block); + return ERRCODE_FAIL; + } + uint32_t ret = freertos_nandflash_driver->check_bad_block(block); + wstp_print("is bad? ret = %d\r\n", ret); +#endif + return ERRCODE_SUCC; +} + +uint32_t at_nand_set_mode(uint8_t *data, uint32_t data_len) +{ +#ifdef CFG_DRIVERS_NANDFLASH + char *ptr = (char *)data; + uint32_t mode = strtoul(ptr, NULL, 10); + if (mode == 0) { + wstp_print("set mode to SPEED_HIGH DMA_FOUR_LINE\r\n", mode); + nand_driver_init(SPEED_HIGH); + set_trans_type(TRANS_BY_DMA_QUAD); + } else { + wstp_print("set mode to SPEED_SLOW CPU_SINGLE_LINE\r\n", mode); + nand_driver_init(SPEED_SLOW); + set_trans_type(TRANS_BY_CPU_SINGLE_LINE); + } +#endif + return ERRCODE_SUCC; +} + +uint32_t lcd_fill(uint8_t *data, uint32_t data_len) +{ + char *ptr = (char *)data; + uint32_t color_input = strtoul(ptr, NULL, 16); + wstp_print("color = %x \r\n", color_input); + + td_handle vau_handle; + ext_vau_surface src_surface = {0}; + + src_surface.width = 454; // 454 screen width + src_surface.height = 454; // 454 screen height + src_surface.phy_addr = LCD_FILL_COLOR_ADDR; + src_surface.vir_addr = (td_uchar *)src_surface.phy_addr; + src_surface.color_fmt = EXT_GFX_FMT_ARGB8888; + src_surface.compress_mode = EXT_GFX_COMPRESS_NONE; + src_surface.argb_order = EXT_GFX_FMT_ORDER_ARGB; + src_surface.rect.x = 0; + src_surface.rect.y = 0; + src_surface.rect.width = src_surface.width; + src_surface.rect.height = src_surface.height; + src_surface.stride = 1824; /* 454 * 32 / 8 = 1816 16字节对齐得1824 */ + src_surface.is_color_surface = TD_TRUE; + src_surface.color = color_input; + +#ifdef MIPI_ULPS_SUPPORT + uapi_mipi_tx_exit_ulps(); +#endif + + vau_handle = uapi_vau_create(); + uapi_vau_fill(vau_handle, &src_surface); + uapi_vau_submit(vau_handle, TD_FALSE, 1000); /* 1000 ms timeout */ + + td_handle dpu_handle; + ext_dpu_layer_info layer_info = {0}; + ext_dpu_surface dpu_surface = {0}; + + layer_info.width = src_surface.width; + layer_info.height = src_surface.height; + layer_info.layer_id = EXT_DPU_LAYER_ID1; + layer_info.layer_fmt = src_surface.color_fmt; + layer_info.compress_mode = src_surface.compress_mode; + layer_info.buf_mode = EXT_DPU_BUFFER_MODE_NORMAL; + + dpu_surface.width = src_surface.width; + dpu_surface.height = src_surface.height; + dpu_surface.stride = src_surface.stride; + dpu_surface.phy_addr = src_surface.phy_addr; + dpu_surface.vir_addr = src_surface.vir_addr; + dpu_surface.update_rect = TD_NULL; + dpu_surface.color_fmt = src_surface.color_fmt; + dpu_surface.compress_mode = src_surface.compress_mode; + + uapi_dpu_create_layer(&layer_info, &dpu_handle); + uapi_dpu_set_layer_vblank(dpu_handle, TD_TRUE); + uapi_dpu_set_layer_info(dpu_handle, &dpu_surface); + uapi_dpu_refresh_layers(); + + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_no_resume_touch(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *data = (char *)para; + if (data == NULL) { return ERRCODE_FAIL; } + uint8_t flag = strtoul(data, NULL, 0); + if (flag == 1) { + touch_screen_restart(); + } + set_touch_resume_flag(flag); + return ERRCODE_SUCC; +} + +uint32_t mcu_pm_set_mcu_dynamic_power(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *data = (char *)para; + if (data == NULL) { return ERRCODE_FAIL; } + uint8_t flag = strtoul(data, NULL, 0); + if (flag == 0) { + pm_set_mcu_dynamic_power_flag(0); + } else { + pm_set_mcu_dynamic_power_flag(1); + } + return ERRCODE_SUCC; +} + +static void button_callback_press(void) +{ + PRINT("power key press."NEWLINE); +} + +static void button_callback_click(void) +{ + PRINT("power key click."NEWLINE); +} + +static void button_callback_click_2(void) +{ + PRINT("power key click double."NEWLINE); +} + +static void button_callback1(void) +{ + PRINT("power key long press 1s."NEWLINE); +} + +static void button_callback2(void) +{ + PRINT("power key long press 2s."NEWLINE); +} + +static void button_callback3(void) +{ + PRINT("power key long press 3s."NEWLINE); +} + +static void button_callback4(void) +{ + PRINT("power key long press 4s."NEWLINE); +} + +static void button_callback5(void) +{ + PRINT("power key long press 5s."NEWLINE); +} + +static void button_callback6(void) +{ + PRINT("power key long press 6s."NEWLINE); +} + +static void button_callback7(void) +{ + PRINT("power key long press 7s."NEWLINE); +} + +static void button_callback8(void) +{ + PRINT("power key long press 8s."NEWLINE); +} + +static void button_callback9(void) +{ + PRINT("power key long press 9s."NEWLINE); +} + +static void button_callback_1_over(void) +{ + PRINT("power key long press 1s over."NEWLINE); +} + +static void button_callback_2_over(void) +{ + PRINT("power key long press 2s over."NEWLINE); +} + +static void button_callback_3_over(void) +{ + PRINT("power key long press 3s over."NEWLINE); +} + +static void button_callback_4_over(void) +{ + PRINT("power key long press 4s over."NEWLINE); +} + +static void button_callback_5_over(void) +{ + PRINT("power key long press 5s over."NEWLINE); +} + +static void button_callback_6_over(void) +{ + PRINT("power key long press 6s over."NEWLINE); +} + +static void button_callback_7_over(void) +{ + PRINT("power key long press 7s over."NEWLINE); +} + +static void button_callback_8_over(void) +{ + PRINT("power key long press 8s over."NEWLINE); +} + +static void button_callback_9_over(void) +{ + PRINT("power key long press 9s over."NEWLINE); +} + +uint32_t mcu_button_sample(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + + uapi_button_register_event_cb(button_callback_press, BUTTON_PWR_PRESS); + uapi_button_register_event_cb(button_callback_click, BUTTON_PWR_CLICKUP); + uapi_button_register_event_cb(button_callback_click_2, BUTTON_PWR_CLICKUP_2); + + uapi_button_register_event_cb(button_callback1, BUTTON_PWR_LONGPRESS_1S); + uapi_button_register_event_cb(button_callback2, BUTTON_PWR_LONGPRESS_2S); + uapi_button_register_event_cb(button_callback3, BUTTON_PWR_LONGPRESS_3S); + uapi_button_register_event_cb(button_callback4, BUTTON_PWR_LONGPRESS_4S); + uapi_button_register_event_cb(button_callback5, BUTTON_PWR_LONGPRESS_5S); + uapi_button_register_event_cb(button_callback6, BUTTON_PWR_LONGPRESS_6S); + uapi_button_register_event_cb(button_callback7, BUTTON_PWR_LONGPRESS_7S); + uapi_button_register_event_cb(button_callback8, BUTTON_PWR_LONGPRESS_8S); + uapi_button_register_event_cb(button_callback9, BUTTON_PWR_LONGPRESS_9S); + + uapi_button_register_event_cb(button_callback_1_over, BUTTON_PWR_LONGPRESS_1S_OVER); + uapi_button_register_event_cb(button_callback_2_over, BUTTON_PWR_LONGPRESS_2S_OVER); + uapi_button_register_event_cb(button_callback_3_over, BUTTON_PWR_LONGPRESS_3S_OVER); + uapi_button_register_event_cb(button_callback_4_over, BUTTON_PWR_LONGPRESS_4S_OVER); + uapi_button_register_event_cb(button_callback_5_over, BUTTON_PWR_LONGPRESS_5S_OVER); + uapi_button_register_event_cb(button_callback_6_over, BUTTON_PWR_LONGPRESS_6S_OVER); + uapi_button_register_event_cb(button_callback_7_over, BUTTON_PWR_LONGPRESS_7S_OVER); + uapi_button_register_event_cb(button_callback_8_over, BUTTON_PWR_LONGPRESS_8S_OVER); + uapi_button_register_event_cb(button_callback_9_over, BUTTON_PWR_LONGPRESS_9S_OVER); + return ERRCODE_SUCC; +} + +static uint32_t mcu_power_key_config(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + uint32_t power_level = 0; + uint32_t power_type = 0; + uint32_t idx = 0; + uint32_t tmp[POWER_KEY_PARAM_LEN] = {0}; + token = strtok_s((char*)ptr, " ", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 10); // 10: 十进制 + token = strtok_s(NULL, " ", &next_token); + } + power_type = tmp[0]; + power_level = tmp[1]; + printf("power type:%d power_level:%d \r\n", power_type, power_level); + if (uapi_power_set_mode(power_type) != ERRCODE_SUCC) { + printf("power type:%d error.", power_type); + } + if (uapi_power_time_mode(power_level) != ERRCODE_SUCC) { + printf("power level:%d error.", power_level); + } + + return ERRCODE_SUCC; +} + +static uint32_t mcu_calendar_set_date(uint8_t *para, uint32_t para_len) +{ + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + calendar_t date; + uint32_t idx = 0; + uint32_t tmp[CALENDAR_PARAM_LEN] = {0}; + token = strtok_s((char*)ptr, " ", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 10); // 10: 十进制 + token = strtok_s(NULL, " ", &next_token); + } + date.year = tmp[0]; + date.mon = tmp[1]; + date.day = tmp[2]; + date.hour = tmp[3]; + date.min = tmp[4]; + date.sec = tmp[5]; + + errcode_t ret = uapi_calendar_set_datetime(&date); + if (ret == ERRCODE_SUCC) { + printf("Set datetime success: %d-%d-%d %d:%d:%d\r\n", date.year, date.mon, date.day, date.hour, date.min, + date.sec); + return ERRCODE_SUCC; + } + printf("Set datetime failed, error code = %d \r\n", ret); + return ret; +} + +static uint32_t mcu_calendar_get_date(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + calendar_t date; + + errcode_t ret = uapi_calendar_get_datetime(&date); + if (ret == ERRCODE_SUCC) { + printf("Get datetime success: %d-%d-%d %d:%d:%d\r\n", date.year, date.mon, date.day, date.hour, date.min, + date.sec); + return ERRCODE_SUCC; + } + printf("Get datetime failed, error code = %d \r\n", ret); + + return ret; +} + +#ifdef SUPPROT_EXECUTE_CORMARK +static uint32_t mcu_coremark_test(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + uint32_t irq_sts = osal_irq_lock(); + watchdog_turnoff_clk(); + coremark_test(); + watchdog_turnon_clk(); + osal_irq_restore(irq_sts); + return ERRCODE_SUCC; +} +#endif + +static uint32_t mcu_set_app_delay_time(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t delay_time = strtoul(ptr, NULL, 0); + if (delay_time == 0) { + delay_time = 10000; // 10000 ms + } + wstp_print("app set delay_time = %d\r\n", delay_time); + set_app_delay_time(delay_time); + return ERRCODE_SUCC; +} + +static uint32_t mcu_set_cldo1_voltage(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint8_t cldo = strtoul(ptr, NULL, 0); + if (cldo > PMU_LDO_MAX) { cldo = 0; } + ptr++; + ptr++; + uint8_t voltage = strtoul(ptr, NULL, 0); + if (voltage > 15) { voltage = 14; } // the max voltage of cldo is 15, 14 is the default value. + wstp_print("app set cldo=%d voltage = %d\r\n", cldo, voltage); + pmu_ldo_power_on((pmu_ldo_t)cldo, 1); + if (((pmu_ldo_t)cldo == PMU_LDO_CLDO1) || ((pmu_ldo_t)cldo == PMU_LDO_CLDO1) || + ((pmu_ldo_t)cldo == PMU_LDO_CLDO1)) { + hal_pmu_cldo_enable_bypass((hal_pmu_cldo_t)cldo, 0); + } + pmu_ldo_power_vset((pmu_ldo_t)cldo, voltage); + return ERRCODE_SUCC; +} + +static uint32_t mcu_nand_aging_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); +#ifdef CFG_DRIVERS_NANDFLASH + return nandflash_aging_test((char*)para); +#else + return ERRCODE_SUCC; +#endif +} + +static uint32_t mcu_norflash_aging_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + return flash_aging_test((char*)para); +} + +static uint32_t mcu_set_pin_pull(uint8_t *para, uint32_t para_len) +{ + int ret; + uint32_t pin = 0; + uint32_t levl = 0; + char* ptr = (char*)para; + char* pos = strchr((char*)ptr, ','); + if (pos == NULL) { + return ERRCODE_FAIL; + } + *pos = '\0'; + + pin = strtoul(ptr, NULL, 0); + if (pin < 0) { + pin = 0; + } + ptr = pos + 1; + levl = strtoul(ptr, NULL, 0); + if ((pin_pull_t)levl > PIN_PULL_MAX) { + levl = 0; + } + uapi_pin_set_pull((pin_t)pin, (pin_pull_t)levl); + return ERRCODE_SUCC; +} + +static uint32_t mcu_get_pin_pull(uint8_t *para, uint32_t para_len) +{ + pin_t pin = 0; + pin_pull_t level = 0; + wstp_print("all pin levl:\r\n"); + for (uint16_t i = 0; i < PIN_NONE; i++) { + level = uapi_pin_get_pull((pin_t)i); + wstp_print("i=%d level=%d\r\n", i, level); + } + return ERRCODE_SUCC; +} + +static uint32_t mcu_set_time(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + return set_system_time((char*)para); +} + +static uint32_t mcu_get_time(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + return get_system_time(); +} + +#ifdef SUPPORT_POWER_MANAGER +static uint32_t mcu_pms_set_screenoff_time(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + uint32_t type; + uint32_t timeout; + char *pos; + char *ptr = (char *)para; + errcode_t ret = ERRCODE_SUCC; + pos = strchr((char *)ptr, ','); + if (pos == NULL) { + return ERRCODE_FAIL; + } + *pos = '\0'; + type = strtoul(ptr, NULL, 0); + pos++; + timeout = strtoul(pos, NULL, 0); + wstp_print("app set screen off: type = %u, timeut = %u.\r\n", type, timeout); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (type == 0) { + ret = display_api->set_screen_auto_off_timeout(timeout); + } else if (type == 1) { + ret = display_api->set_screen_set_keepon_timeout(timeout); + } else { + return ERRCODE_FAIL; + } + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + + +static uint32_t mcu_pms_set_screenoff_enable(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t inputpara = strtoul(ptr, NULL, 0); + bool enable = true; + if (inputpara == 0) { + enable = false; + } + wstp_print("app set screen off enable = %u, para = %u. \r\n", enable, inputpara); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + display_api->set_auto_timeout_function(enable); + return ERRCODE_SUCC; +} + +static uint32_t mcu_pms_set_screen_state(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + wstp_print("app set screen state :%s. \r\n", ptr); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (strcmp(ptr, "ON") == 0) { + display_api->turn_on_screen(); + } else if (strcmp(ptr, "OFF") == 0) { + display_api->turn_off_screen(); + } else { + wstp_print("app set screen input para err.\r\n"); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +static uint32_t mcu_pms_get_screen_state(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + screen_state_t state = display_api->get_screen_state(); + wstp_print("app get screen state = %u, on is %u, off is %u. \r\n", state, SCREEN_ON, SCREEN_OFF); + return ERRCODE_SUCC; +} +#endif + +#ifdef FT_DONGLE +uint32_t mcu_check_dongle_connected(uint8_t *para, uint32_t para_len) +{ + unused(para); + unused(para_len); + // 通过diag返回包作为factory_tools判断SPP的连接状态依据 + // 仅供factory_tools做判断用,此AT命令不对外用 + wstp_print("Received dongle check msg.\r\n"); + return ERRCODE_SUCC; +} +#endif + +uint32_t mcu_i2c_write_byte(i2c_bus_t bus, uint16_t slave_addr, uint32_t reg_addr, uint32_t reg_val) +{ + errcode_t ret; + i2c_data_t data; + + uint8_t send_buf[AT_I2C_REG_ARRAY_LEN] = { 0 }; + send_buf[0] = (reg_addr >> OFFSET_24) & 0xff; + send_buf[1] = (reg_addr >> OFFSET_16) & 0xff; + send_buf[AT_PARA_IDX2] = (reg_addr >> OFFSET_8) & 0xff; + send_buf[AT_PARA_IDX3] = reg_addr & 0xff; + send_buf[AT_PARA_IDX4] = reg_val & 0xff; + send_buf[AT_PARA_IDX5] = (reg_val >> OFFSET_8) & 0xff; + send_buf[AT_PARA_IDX6] = (reg_val >> OFFSET_16) & 0xff; + send_buf[AT_PARA_IDX7] = (reg_val >> OFFSET_24) & 0xff; + + data.send_buf = send_buf; + data.send_len = 8; // 8: 发送长度 + data.receive_buf = NULL; + data.receive_len = 0; + + ret = uapi_i2c_master_write(bus, slave_addr, &data); + if (ret != ERRCODE_SUCC) { + wstp_print("===== Error: mcu_i2c_write_byte: I2C write ret = 0x%x! =====\r\n", ret); + return ERRCODE_FAIL; + } + return ERRCODE_SUCC; +} + +int32_t mcu_i2c_read_byte(i2c_bus_t bus, uint16_t slave_addr, uint32_t read_addr, uint32_t *read_val) +{ + errcode_t ret; + i2c_data_t data; + + uint8_t reg_addr[4] = { 0 }; + reg_addr[0] = (read_addr >> OFFSET_24) & 0xff; + reg_addr[1] = (read_addr >> OFFSET_16) & 0xff; + reg_addr[AT_PARA_IDX2] = (read_addr >> OFFSET_8) & 0xff; + reg_addr[AT_PARA_IDX3] = read_addr & 0xff; + + data.send_buf = reg_addr; + data.send_len = 4; // 4: 发送长度 + data.receive_buf = (uint8_t *)read_val; + data.receive_len = 4; // 4: 接收长度 + + ret = uapi_i2c_master_write(bus, slave_addr, &data); + if (ret != ERRCODE_SUCC) { + wstp_print("===== Error: mcu_i2c_read_byte: I2C write ret = 0x%x! =====\r\n", ret); + return ERRCODE_FAIL; + } + + ret = uapi_i2c_master_read(bus, slave_addr, &data); + if (ret != ERRCODE_SUCC) { + wstp_print("===== Error: mcu_i2c_read_byte: I2C read ret = 0x%x! =====\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + +static uint32_t mcu_i2c_write(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + errcode_t ret; + + uint32_t idx = 0; + uint32_t bus = 0; + uint32_t slave_addr = 0; + uint32_t write_addr = 0; + uint32_t write_val = 0; + + uint32_t tmp[AT_I2C_PARA_CNT] = {0}; + token = strtok_s((char*)ptr, ",", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 16); // 16: 十六进制 + token = strtok_s(NULL, ",", &next_token); + } + + bus = tmp[0]; + slave_addr = tmp[1]; + write_addr = tmp[AT_PARA_IDX2]; + write_val = tmp[AT_PARA_IDX3]; + + return mcu_i2c_write_byte((i2c_bus_t)bus, slave_addr, write_addr, write_val); +} + +static uint32_t mcu_i2c_read(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + char *ptr = (char *)para; + char *token = NULL; + char *next_token = NULL; + errcode_t ret; + uint32_t read_val; + + uint32_t idx = 0; + uint32_t bus = 0; + uint32_t slave_addr = 0; + uint32_t read_addr = 0; + + uint32_t tmp[AT_I2C_PARA_CNT] = {0}; + token = strtok_s((char*)ptr, ",", &next_token); + while (token != NULL) { + tmp[idx++] = strtoul(token, NULL, 16); // 16: 十六进制 + token = strtok_s(NULL, ",", &next_token); + } + + bus = tmp[0]; + slave_addr = tmp[1]; + read_addr = tmp[AT_PARA_IDX2]; + + ret = mcu_i2c_read_byte((i2c_bus_t)bus, slave_addr, read_addr, &read_val); + if (ret == ERRCODE_SUCC) { + wstp_print("Read val: [ 0x%x ]\r\n", read_val); + } + + return ret; +} +#ifdef SUPPORT_ALIPAY_SEC +static uint32_t mcu_alipay_sec_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + wstp_print("mcu_alipay_sec_test start.\r\n"); + uapi_alipay_svr_init(); + const alipay_svr_api_t *alipay_api = alipay_svr_get_api(); + alipay_api->exit_lpm(); + osDelay(ALIPAY_EXIT_LPM_DELAY_LEN); + yunit_sdk_test(); + alipay_api->enter_lpm(); + wstp_print("mcu_alipay_sec_test end.\r\n"); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_alipay_debug(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + uapi_alipay_svr_init(); + svr_alipay_debug(); + return ERRCODE_SUCC; +} + +static uint32_t mcu_alipay_pl_verify(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + int32_t compat_ret = 0; + int32_t cert_ret = 0; + uapi_alipay_svr_init(); + const alipay_svr_api_t *alipay_api = alipay_svr_get_api(); + alipay_api->exit_lpm(); + osDelay(ALIPAY_EXIT_LPM_DELAY_LEN); + cert_ret = test_get_credential(); + wstp_print("get cert ret=%d.\r\n", cert_ret); + compat_ret = hal_hardware_compat_check(); + wstp_print("compat check ret=%d.\r\n", compat_ret); + alipay_api->enter_lpm(); + if (cert_ret == 0 && compat_ret == 0) { + return ERRCODE_SUCC; + } + return ERRCODE_FAIL; +} + +static uint32_t mcu_alipay_reset(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + (void)uapi_alipay_svr_reset(); + return ERRCODE_SUCC; +} +#endif + +#ifdef SUPPORT_FILE_SPLIT_COMBINE +static uint32_t mcu_file_spilt_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + wstp_print("mcu_file_spilt_test start.\r\n"); + msg_center_split_file(ORIGIN_FILE_PATH, FILE_SPILT_MAX_SIZE, FILE_LIST_PATH); + wstp_print("mcu_file_spilt_test end.\r\n"); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_file_combine_test(uint8_t *para, uint32_t para_len) +{ + unused(para_len); + unused(para); + wstp_print("mcu_file_combine_test start.\r\n"); + msg_center_combine_file(FILE_LIST_PATH, COMBINE_FILE_PATH); + wstp_print("mcu_file_combine_test end.\r\n"); + + return ERRCODE_SUCC; +} +#endif + +#ifdef JS_ENABLE +static uint32_t mcu_get_trans_channel_test(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + msg_center_get_trans_channel(); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_set_trans_channel_test(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + char *ptr = (char *)para; + uint32_t select = strtoul(ptr, NULL, 10); /* 10进制 */ + msg_center_set_trans_channel(select); + + return ERRCODE_SUCC; +} +#endif + +#ifdef SUPPORT_AUTO_OTA +static uint32_t mcu_auto_ota_block(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + g_auto_ota_upload_mode = 1;// 阻塞等待升级包上传 + wstp_print("auto_ota block!\r\n"); + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_run(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + g_auto_ota_upload_mode = 0; // 升级包上传完成后auto_ota继续执行 + wstp_print("auto_ota run!\r\n"); + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_del_mac(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + wstp_print("para = %s\r\n", para); + uint8_t addr[ADDR_MAC_LEN] = {0}; + char tmp[ONE_ADDR_LEN + 1] = {0}; + char *p = (char *)para; + + for (uint8_t i = 0; i < ADDR_MAC_LEN; i++) { + memcpy_s(tmp, ONE_ADDR_LEN + 1, p, ONE_ADDR_LEN); + tmp[ONE_ADDR_LEN] = '\0'; + addr[i] = strtol(tmp, NULL, 16); // 16进制 + p = p + ONE_ADDR_LEN; + } + + wstp_print("mcu_auto_ota_del_mac, mac = %02x%02x%02x%02x%02x%02x\r\n", addr[5], addr[4], addr[3], addr[2], addr[1], + addr[0]); + bool res = auto_ota_dev_del(addr); + wstp_print("auto_ota_dev_del, res = %d\r\n", res); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_add_mac(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + wstp_print("enter mcu_auto_ota_add_mac\r\n"); + wstp_print("para = %s\r\n", para); + uint8_t addr[ADDR_MAC_LEN] = {0}; + char tmp[ONE_ADDR_LEN + 1] = {0}; + char *p = (char *)para; + + for (uint8_t i = 0; i < ADDR_MAC_LEN; i++) { + memcpy_s(tmp, ONE_ADDR_LEN + 1, p, ONE_ADDR_LEN); + tmp[ONE_ADDR_LEN] = '\0'; + addr[i] = strtol(tmp, NULL, 16); // 16进制 + p = p + ONE_ADDR_LEN; + } + + wstp_print("mcu_auto_ota_add_mac, mac = %02x%02x%02x%02x%02x%02x\r\n", addr[5], addr[4], addr[3], addr[2], addr[1], + addr[0]); + auto_ota_dev_add(addr); + + return ERRCODE_SUCC; +} + +static uint32_t mcu_auto_ota_show_mac(uint8_t *para, uint32_t para_len, char *str_cmd) +{ + unused(para_len); + unused(para); + wstp_print("enter mcu_auto_ota_show_mac\r\n"); + + auto_ota_dev_show(); + + return ERRCODE_SUCC; +} +#endif + +static const app_process_table g_app_funcs[] = { + { RESET, mcu_os_sys_reset }, + { FSTEST, mcu_fs_test }, + { FSFORMAT, mcu_fs_format }, + { FSRWTEST, mcu_fs_rw_test }, + { FSSETCLK, mcu_fs_set_clk }, + { FSREADCLK, mcu_fs_read_clk }, + { FSWRITE, mcu_fs_write }, + { FSCHECK, mcu_fs_check }, + { FSRM, mcu_fs_rm }, + { GETWSTPVER, mcu_get_wstp_version }, + { LOGWRITE, mcu_logfile_write }, + { HEAPINFO, mcu_os_heap_info }, + { STACKINFO, mcu_os_stack_info }, + { TESTDTCMBW, mcu_test_dtcm_baudwidth }, + { TESTL2MBW, mcu_test_l2m_baudwidth }, + { TESTMMCBW, mcu_test_mmc_baudwidth }, + { TESTPSRAMBW, mcu_test_psram_baudwidth }, + { TESTNORFLASHBW, mcu_test_norflash_baudwidth }, + { TESTNANDFLASHBW, mcu_test_nandflash_baudwidth }, + { GETFSINFO, mcu_get_fs_info }, + { PMRMVOTE, mcu_pm_remove_vote }, + { PMADDVOTE, mcu_pm_add_vote }, + { LCDON, mcu_pm_lcd_on }, + { LCDOFF, mcu_pm_lcd_off }, + { SHIPMODE, mcu_pm_into_ship_mode }, + { FORCEDEEPSLEEP, mcu_pm_into_force_ds_mode }, + { PMMODESET, mcu_pm_req_mode }, + { PMMODEUSR, mcu_set_pm_req_mode_usr}, + { PMMODEGET, mcu_pm_dfx_mode }, + { GETCURSEC, mcu_dfx_get_cur_second}, + { LCDFILL, lcd_fill }, + { GETIDS, get_ids }, + { LCDLIGHT, lcd_test_light }, + { RESUMETOUCH, mcu_pm_no_resume_touch }, + { MCUDYMPW, mcu_pm_set_mcu_dynamic_power }, + { PMCLDO1PD, mcu_pm_cldo1_power_down }, + { AESDECRYPT, mcu_aes_decrypt_sample }, + { AESENCRYPT, mcu_aes_encrypt_sample }, + { AESSETGID, mcu_aes_set_gid }, + { SETCALENDAR, mcu_calendar_set_date }, + { GETCALENDAR, mcu_calendar_get_date }, +#if defined(CONFIG_ADC_SUPPORT_AUTO_SCAN) + { ADCAUTOSAMPLE, adc_auto_sample_by_diag }, + { ADCCLOSEAUTOSAMPLE, adc_auto_sample_disable }, + { ADCSHOWDATA, adc_auto_sample_show_data }, +#endif + { BUTTON, mcu_button_sample }, + { POWERKEY, mcu_power_key_config }, +#ifdef SUPPROT_EXECUTE_CORMARK + { COREMARKTEST, mcu_coremark_test }, +#endif + { NANDREAD, at_nand_write_read}, + { NANDWRITE, at_nand_write_write}, + { NANDERASE, at_nand_write_erase}, + { NANDMARK, at_nand_mark_bad}, + { NANDCHECK, at_nand_check_bad}, + { NANDSETMODE, at_nand_set_mode}, + { SETAPPDELAY, mcu_set_app_delay_time }, + { SETCLDO1VOL, mcu_set_cldo1_voltage }, + { NANDAGINGTEST, mcu_nand_aging_test }, + { FLASHAGINGTEST, mcu_norflash_aging_test }, + { SETPINPULL, mcu_set_pin_pull }, + { GETPINPULL, mcu_get_pin_pull }, + { TIMESET, mcu_set_time }, + { TIMEGET, mcu_get_time }, +#ifdef SUPPORT_POWER_MANAGER + { SETSCREENOFFTIME, mcu_pms_set_screenoff_time }, + { SETSCREENOFFFUNC, mcu_pms_set_screenoff_enable }, + { SETSCREENSTATE, mcu_pms_set_screen_state }, + { GETSCREENSTATE, mcu_pms_get_screen_state }, +#endif +#ifdef FT_DONGLE + { DONGLECONNECTED, mcu_check_dongle_connected }, +#endif + { I2CWRITE, mcu_i2c_write }, + { I2CREAD, mcu_i2c_read }, +#ifdef SUPPORT_ALIPAY_SEC + { ALIPAYSECTEST, mcu_alipay_sec_test }, + { ALIPAYDEBUG, mcu_alipay_debug }, + { ALIPAYVERIFY, mcu_alipay_pl_verify }, + { ALIPAYRESET, mcu_alipay_reset }, +#endif +#ifdef SUPPORT_FILE_SPLIT_COMBINE + { FILESPLIT, mcu_file_spilt_test }, + { FILECOMBINE, mcu_file_combine_test }, +#endif +#ifdef JS_ENABLE + { GETTRANSCHAN, mcu_get_trans_channel_test }, + { SETTRANSCHAN, mcu_set_trans_channel_test }, +#endif +#ifdef SUPPORT_AUTO_OTA + { AUTOOTABLOCK, mcu_auto_ota_block }, + { AUTOOTARUN, mcu_auto_ota_run }, + { AUTOOTADELMAC, mcu_auto_ota_del_mac }, + { AUTOOTAADDMAC, mcu_auto_ota_add_mac }, + { AUTOOTASHOWMAC, mcu_auto_ota_show_mac }, +#endif +}; + +void app_at_process(uint8_t *data, uint32_t data_len) +{ + unused(data_len); + if (data == NULL) { + return; + } + int32_t ret = ERRCODE_FAIL; + uint8_t reply_data[DIAG_RES_LEN] = {0}; + app_msg_info_t *msg = (app_msg_info_t *)(data); + + for (uint32_t i = 0; i < ARRAY_COUNT(g_app_funcs); i++) { + if (msg->id == g_app_funcs[i].id) { + ret = g_app_funcs[i].func(msg->payload, msg->payload_len); + } + } + print_at_cmd_ret(ret); + + // phone remote control, need reply to spp + if (g_app_diag_flag) { + reply_data[0x0] = 0x80; + reply_data[0x1] = 0x82; + reply_data[0x2] = 0; + reply_data[0x3] = (uint8_t)ret; + ret = send_spp_diag_msg(g_app_diag_flag, &g_mcu_diag_header, reply_data, DIAG_RES_LEN); + wstp_print("mcu_at_process send msg to spp %s.\r\n", (ret == ERRCODE_SUCC) ? "success" : "failure"); + } + + if (ret != ERRCODE_SUCC) { + wstp_print("app_at_process func fail! MsgID=0x%x ret=%d "NEWLINE, msg->id, ret); + } + g_app_diag_flag = false; +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/build/config/target_config/brandy/config.py b/sdk_release/v1.0/4gsdk_old/code/sdk/build/config/target_config/brandy/config.py new file mode 100644 index 000000000..2edac269a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/build/config/target_config/brandy/config.py @@ -0,0 +1,310 @@ +#!/usr/bin/env python3 +# encoding=utf-8 +# ============================================================================ +# @brief Target Definitions File +# Copyright CompanyNameMagicTag 2022-2022. All rights reserved. +# ============================================================================ + +target = { + #target1: liteos + lvgl + nandflash + mipi + no psram + mini_audio 典型单封LVGL版本 + 'brandy-target1': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'std_libs': [], + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_ZDIAG_NV_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'MEMORY_MINI', 'ENABLE_LVGL', 'SW_UART_DEBUG', "SAVE_EXC_INFO", + "CONFIG_LOW_POWER_TEST", 'MIPI_ULPS_SUPPORT', 'ENABLE_ECC', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'CONFIG_NV_SUPPORT_ASYNCHRONOUS_STORE=0'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc','fs_yaffs2', 'x_vfs_private', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', + 'audio_at_service', 'media_at_service', 'bt_manager_at_service', + "audio_proc", "audio_dump", "audio_probe", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media_mini', 'gpu', 'graphic_lvgl_mini', 'bgh_audio', 'dfx_set'], + 'image_analysis': True, + 'dsp_version': 'mini', + 'packet': True, + 'fs_image': False, + }, + #target3: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + 'brandy-target3': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'ENABLE_UIKIT', 'SUPPORT_GPU_JPEG', 'SUPPORT_GPU_GMMU', 'SUPPORT_GPU_OPENVG', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'HASH_MEM_COPY','MIPI_ULPS_SUPPORT', 'CONFIG_LOW_POWER_TEST', + 'ENABLE_ECC', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', + 'audio_at_service', 'media_at_service', 'bt_manager_at_service', + "audio_proc", "audio_dump", "audio_probe", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'graphic_test', 'bgh_audio', 'dfx_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False + }, + #target4: liteos + nandflash + psram + mini_audio + no gui 外设类版本 + 'brandy-target4': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'std_libs': ['c++', 'c++abi', 'unwind'], + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'I2C_SLAVE_REG_ADDR_4BYTE', 'SUPPORT_CXX', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'HASH_MEM_COPY', + 'CONFIG_ZDIAG_NV_SUPPORT', 'SUPPORT_BLE', 'SUPPORT_BREDR', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'CONFIG_PSRAM_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', + 'CONFIG_LOW_POWER_TEST', 'CONFIG_ADC_SUPPORT_AUTO_SCAN', + 'CONFIG_ADC_SUPPORT_LONG_SAMPLE', 'ENABLE_ECC', 'CONFIG_DIAG_GPU_PROC_SUPPORT', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'partition', 'partition_brandy', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc','fs_yaffs2', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'app_at_service', + 'audio_at_service', 'bt_manager_at_service', "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'gpu', 'media_target4', 'update_app', 'dfx_set', 'bgh_audio', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False, + }, + #target5: freertos + lvgl + nand + mipi + psram + audio + media 典型合封LVGL版本 + 'brandy-target5': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_freertos_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SUPPORT_BLE', "SUPPORT_BREDR", 'ENABLE_LVGL', "SUPPORT_GPU_JPEG", "SUPPORT_GPU_GMMU", "SUPPORT_GPU_OPENVG", + 'SW_UART_DEBUG', 'MEMORY_NO_CACHE', "SAVE_EXC_INFO", "HASH_MEM_COPY", 'MIPI_ULPS_SUPPORT', + 'CONFIG_LOW_POWER_TEST', 'ENABLE_ECC', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + 'lcd', 'qspi_display', 'partition', 'partition_brandy', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd','graphic_at_service', 'app_at_service', + 'audio_at_service', 'media_at_service', 'bt_manager_at_service', + "audio_proc", "audio_dump", "audio_probe", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_lvgl', 'bgh_audio', 'update_app', 'dfx_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False + }, + #native-js: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + #用户可参考user版本,删除reg/mem dump + 'brandy-native-js': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'ENABLE_UIKIT', 'SUPPORT_GPU_JPEG', 'SUPPORT_GPU_GMMU', 'SUPPORT_GPU_OPENVG', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'HASH_MEM_COPY', 'JS_ENABLE', 'CONFIG_LOW_POWER_TEST', + 'ENABLE_ECC', 'MIPI_ULPS_SUPPORT', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', 'bt_manager_at_service', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', 'x_vfs_private', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', 'ohosfwk_at_service', + "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc",'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False + }, + #native-js-user: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + #离线日志版本 + #删除reg/mem dump,写法如下:'-:DUMP_MEM_SUPPORT', '-:DUMP_REG_SUPPORT', '-:SUPPORT_DFX_EXCEPTION' + 'brandy-native-js-user': { + 'base_target_name': 'brandy-native-js', + 'defines': ['-:SW_UART_DEBUG', '-:DUMP_MEM_SUPPORT', '-:DUMP_REG_SUPPORT', '-:SUPPORT_DFX_EXCEPTION'], + }, + #auto-ota-server + 'brandy-auto-ota-ser': { + 'base_target_name': 'brandy-native-js', + 'defines': ['SUPPORT_AUTO_OTA_SERVER', 'CONFIG_DFX_SUPPORT_DIAG_UP_MACHINE=1'], + }, + #auto-ota-client + 'brandy-auto-ota-cli': { + 'base_target_name': 'brandy-native-js', + 'defines': ['SUPPORT_AUTO_OTA_SERVER', 'SUPPORT_AUTO_OTA', 'CONFIG_DFX_SUPPORT_DIAG_UP_MACHINE=1'], + 'ram_component': ['auto_ota'] + }, + #native-xts: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 + 'brandy-xts': { + 'board': 'evb', + 'base_target_name': 'target_standard_brandy_application_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', 'CONFIG_OTA_UPDATE_SUPPORT', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CONFIG_PSRAM_SUPPORT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'CFG_DRIVERS_NANDFLASH', 'CONFIG_ZDIAG_NV_SUPPORT', + 'CONFIG_ZDIAG_AUDIO_PROC_SUPPORT', 'CONFIG_ZDIAG_AUDIO_DUMP_SUPPORT', 'CONFIG_ZDIAG_AUDIO_PROBE_SUPPORT', 'CONFIG_SEA_PHS_SUPPORT', + 'SUPPORT_BLE', 'SUPPORT_BREDR', 'ENABLE_UIKIT', 'SUPPORT_GPU_JPEG', 'SUPPORT_GPU_GMMU', 'SUPPORT_GPU_OPENVG', 'CONFIG_DIAG_GPU_PROC_SUPPORT', + 'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'HASH_MEM_COPY', 'JS_ENABLE', 'CONFIG_LOW_POWER_TEST', + 'ENABLE_ECC', 'XTS_SUPPORT', 'SUPPORT_ALIPAY_SEC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", 'dfx_nv', "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'ulp_aon', 'hal_l2ram', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', 'x_vfs_private', + 'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', 'ohosfwk_at_service', + "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc", 'bts_header'], + 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'xts_set', 'xts_test_set', 'alipay_set'], + 'dsp_version': 'max', + 'packet': True, + 'fs_image': False + }, + + 'brandy-target1-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'MEMORY_MINI', 'SW_UART_DEBUG', + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-target3-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', "HASH_MEM_COPY", + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-target4-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', 'HASH_MEM_COPY', + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'pm_service', 'pm_brandy', + 'ulp_aon', 'hal_l2ram', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-target5-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_freertos_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", "__FREERTOS__", 'ENABLE_UIKIT', 'SW_UART_DEBUG', + "HASH_MEM_COPY", 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'pm_service', 'pm_brandy', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set', 'gpu'] + }, + 'brandy-native-js-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', "HASH_MEM_COPY", + 'ENABLE_ECC', 'SUPPORT_RECOVERY_DISPLAY'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set' ,'gpu'] + }, + 'brandy-xts-r': { + 'board': 'evb', + 'base_target_name': 'target_brandy_recovery_template', + 'defines': ['PRE_ASIC', 'BRANDY_PRODUCT_EVB4', 'VERSION_STANDARD', '__LITEOS__', + '_ALL_SOURCE', 'SUPPORT_CXX', 'I2C_SLAVE_REG_ADDR_4BYTE', 'CFG_DRIVERS_NANDFLASH', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'ENABLE_UIKIT', 'SW_UART_DEBUG', "HASH_MEM_COPY", + 'ENABLE_ECC'], + 'ram_component': ["algorithm", "dfx_port_brandy", "dfx_update", "osal", "arch_port", "-:testsuite", + "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation', + 'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'x_vfs_private', + 'ulp_aon', 'hal_l2ram', 'pm_service', 'pm_brandy', 'cmn_header'], + 'ram_component_set': ['pinctrl', 'dfx_set'] + }, + 'testsuite-brandy-sdk': { + 'base_target_name': 'target_brandy_testsuite_application', + 'board': 'evb', + 'defines': ['SW_UART_DEBUG', 'USE_CMSIS_OS', 'CFG_DRIVERS_NANDFLASH', + 'PRE_ASIC', 'BRANDY_PRODUCT_EVB4', + '_ALL_SOURCE', '__LITEOS__', 'SUPPORT_CXX', 'ENABLE_UIKIT', + "-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", 'MULTIPLEXING_UART', + 'CONFIG_SPI_SUPPORT_POLL_AND_DMA_AUTO_SWITCH', 'CONFIG_SPI_AUTO_SWITCH_DMA_THRESHOLD=0x8', + 'CONFIG_I2C_SUPPORT_POLL_AND_DMA_AUTO_SWITCH', 'CONFIG_I2C_POLL_AND_DMA_AUTO_SWITCH_THRESHOLD=0x8'], + 'ram_component': ["osal", "arch_port", "liteos_port", 'psram', 'pm_service', 'pm_brandy', + 'hal_mips', 'lcd', 'qspi_display', 'hal_dma_v100', "dfx_port_brandy", + 'dfx_log_brandy', 'hal_mipi', 'mipi_tx', 'non_os', 'touch', 'ulp_aon', + 'hal_l2ram', "test_security", "test_spi", 'dfx_file_operation', + "test_timer", "test_int", "test_pm", + "test_lcd", "test_qspi_display", "test_systick", "test_tcxo", "test_watchdog", + "test_vfs_emmc", "test_flash", "test_pwm", "test_i2c", "test_cmsis", + "test_xip", "test_mipi", "test_touch", 'algorithm', 'test_sdio', 'x_vfs_private', + 'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2' , 'nand_flash' , 'mtd_com', + 'cmn_header', 'test_calendar', 'test_gpio', 'test_pinctrl', 'test_dma', 'test_uart', + 'test_reboot', 'test_rtc_unified', + 'test_nandflash', 'test_adc', 'test_pmp', 'efuse', 'hal_efuse_v100', 'efuse_porting'], + 'ram_component_set': ['dfx_set', '-:gpu_test', 'rtc_unified'], + 'os': 'liteos', + }, + 'brandy-ssb': { + 'base_target_name': 'target_ssb_template_brandy', + 'board': 'evb', + 'defines': ["-:TARGET_CHIP_BRANDY=1", "-:BRANDY_CHIP_V100=1", "PRE_ASIC", "BRANDY_PRODUCT_EVB4", + "SSB_USE_PLL", "VERSION_STANDARD", "BUILD_APPLICATION_SSB", "LIBBOOTLOADER", "LIBCODELOADER", + "LIBCPU_UTILS", "LIBAPP_VERSION", "LIBPANIC", "LIBCONNECTIVITY", "LIBERROR_CODE", "LIBSEC_RANDOM", + "LIBCODELOADER_SSB", "LIBJLINK_LOAD", "LIBLIB_UTILS", "LIBBUILD_VERSION", + "NO_TIMEOUT", "CONFIG_UART_BAUD_RATE_DIV_8", 'SW_UART_DEBUG', 'LARGE_BUFFER'], + 'ram_component': ['arch_port', 'hal_l2ram', 'sec_boot', 'libboundscheck', + 'dfx_exception', 'error_code', 'psram', 'osal', 'cmn_header', 'boot_ulp', 'boot_nandflash', 'boot_emmc'], + 'ram_component_set': ['pinctrl'], + 'target': 'ssb', + } +} + +target_group = { + # ci protect target list + 'pack_brandy_target1': ['brandy-ssb', 'brandy-target1-r', 'brandy-target1'], + 'pack_brandy_target3': ['brandy-ssb', 'brandy-target3-r', 'brandy-target3'], + 'pack_brandy_target4': ['brandy-ssb', 'brandy-target4-r', 'brandy-target4'], + 'pack_brandy_target5': ['brandy-ssb', 'brandy-target5-r', 'brandy-target5'], + 'pack_brandy_native_js': ['brandy-ssb', 'brandy-native-js-r', 'brandy-native-js'], + 'pack_brandy_native_js_user': ['brandy-ssb', 'brandy-native-js-r', 'brandy-native-js-user'], + 'pack_brandy_xts': ['brandy-ssb', 'brandy-xts-r', 'brandy-xts'], + + 'brandy_all': ['brandy-ssb', + 'brandy-target1', 'brandy-target3', 'brandy-target4', 'brandy-target5', 'brandy-native-js', 'brandy-native-js-user', 'brandy-xts', + 'brandy-target1-r', 'brandy-target3-r', 'brandy-target4-r', 'brandy-target5-r', 'brandy-native-js-r', 'brandy-xts-r', + 'testsuite-brandy-sdk'] +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h new file mode 100644 index 000000000..eb3d405d1 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h @@ -0,0 +1,233 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2018-2021. All rights reserved. + * Description: brandy evb board config + * Author: @CompanyNameTag + * Create: 2020-02-19 + */ +#ifndef BOARD_EVB_CONFIG_H +#define BOARD_EVB_CONFIG_H + +#include "pinctrl_porting.h" +#include "gpio_porting.h" +#include "platform_types.h" + +/** + * @addtogroup connectivity_config_boards + * @{ + */ +/** + * @brief Global evb pio functions. + */ +const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO0 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO1 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO2 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO3 + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO4 clk + { HAL_PIO_FUNC_QSPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO5 cs + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_EGPIO6 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO7 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO8 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO9 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO10 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO11 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO12 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO13 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO14 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO15 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO16 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO17 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO18 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO19 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO20 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO21 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO22 clk + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_EGPIO23 ce + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO24 + { HAL_PIO_FUNC_OPI, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_EGPIO25 + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO0 sdio + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO2 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO3 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO4 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_HGPIO5 +#if (defined CFG_DRIVERS_NANDFLASH) + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_HGPIO6 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE }, // S_HGPIO7 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_HGPIO8 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_HGPIO9 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO10 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO11 cs0 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO12 cs1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO13 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO14 + { HAL_PIO_FUNC_QSPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO15 clk +#else + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO6 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO7 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO8 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO9 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO10 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO11 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO12 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO13 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_HGPIO14 + { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO15 emmc clk +#endif + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO0 + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO1 + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO2 + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO3 + +#if (defined BRANDY_PRODUCT_EVB4) + { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO4 +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO4 +#endif + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO5 + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO6 + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO7 +#if (defined BRANDY_PRODUCT_EVB4) + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO8 +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO8 E0B2 VCI_EN +#endif + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO9 + { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO10 + { HAL_PIO_FUNC_I2C0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO11 evb2 dsp i2c smartpa + { HAL_PIO_FUNC_I2C0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO12 + { HAL_PIO_FUNC_I2C1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO13 touch i2c + { HAL_PIO_FUNC_I2C1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO14 + { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO15 + { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO16 + { HAL_PIO_FUNC_I2C3_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO17 evb4 dsp i2c pa + { HAL_PIO_FUNC_I2C3_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO18 + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO19 uart1 tx + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO20 uart1 rx + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO21 + { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO22 + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO23 + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO24 + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO25 + { HAL_PIO_FUNC_SPI2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO26 +#if (defined QSPI_DISPLAY) + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO27 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO28 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO29 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO30 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO31 + { HAL_PIO_FUNC_QSPI2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO32 +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO27 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO28 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO29 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO30 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO31 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO32 +#endif + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO33 huart tx + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO34 huart rx + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO35 + { HAL_PIO_FUNC_UART_HS_UART, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO36 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO37 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO38 + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L0 + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L1 i2s1 + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L2 + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L3 + { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L4 + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L5 +#if (defined BRANDY_PRODUCT_EVB4) + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L6 E0B4 VCI_EN +#else + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L6 i2s0 +#endif + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L7 + { HAL_PIO_FUNC_I2S0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L8 +#if (defined FT_BT_UART) + { HAL_PIO_FUNC_UART2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L9 uart2 txd + { HAL_PIO_FUNC_UART2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_AGPIO_L10 uart2 rxd +#else + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L9 dsp uart + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L10 dsp uart +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L11 a+g int1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L12 a+g int2 + { HAL_PIO_FUNC_I2S2_M5, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L13 i2s2 + { HAL_PIO_FUNC_I2S2_M5, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L14 + { HAL_PIO_FUNC_I2S2_M5, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L15 + { HAL_PIO_FUNC_I2S2_M5, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L16 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L17 dsp i2c + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L18 dsp i2c + { HAL_PIO_FUNC_BT_FREQ, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L19 + { HAL_PIO_FUNC_BT_STATUS, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L20 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L21 +#ifdef QSPI_DISPLAY + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L22 QSPI TE +#else + { HAL_PIO_FUNC_TE, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L22 MIPI TE +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L23 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L24 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L25 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L26 emmc reset + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L27 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L28 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L29 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L30 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L31 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L32 + + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R0 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R1 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R3 lcd reset + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_AGPIO_R4 tp reset + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R5 touch int + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R6 als int + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R7 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R8 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R9 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R10 + +#if CORE == APPS + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO0 mode not config + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO1 mode not config + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO2 mode not config + { HAL_PIO_FUNC_INVALID, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO3 mode not config + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // ULP_GPIO4 + { HAL_PIO_FUNC_SWD, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // ULP_GPIO5 + { HAL_PIO_FUNC_SWD, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // ULP_GPIO6 +#endif +}; +/** + * @} + */ + + +/** + * @addtogroup connectivity_config_boards + * @{ + */ +/** + * @brief Global evb gpio functions. + */ +const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { + + // S_AGPIO_L17 + { + S_AGPIO_L17, + HAL_GPIO_DIRECTION_OUTPUT, + HAL_GPIO_LEVEL_HIGH, + 0, + NULL + }, + +}; +/** + * @} + */ +#endif diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/boards/brandy_evb/product/product_evb4_standard.h b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/boards/brandy_evb/product/product_evb4_standard.h new file mode 100644 index 000000000..2f97ef24b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/boards/brandy_evb/product/product_evb4_standard.h @@ -0,0 +1,230 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2020-2023. All rights reserved. + * Description: product EVB4 standard config + * Author: @CompanyNameTag + * Create: 2023-03-07 + */ +#ifndef PRODUCT_EVB4_STANDARD_CONFIG_H +#define PRODUCT_EVB4_STANDARD_CONFIG_H + +/** + * @defgroup connectivity_config_product PRODUCT + * @ingroup connectivity_config + * @{ + */ +/* Platform board config, need check if it support or not carefully. */ +#define BTH_WITH_SMART_WEAR YES +#define APP_WRITE_OTP_ENABLE NO +#define APP_HEAP_SIZE 0x18000 // the minimum APP heap size (96kB) +#define USE_FLASH_SUSPEND_AND_RESUME NO +#define WAIT_APPS_DUMP_FOREVER NO +#define TWS_MPU_XIP_PROTECT NO +#define SSB_IMAGE_PAGES 27 +#ifdef CONFIG_LOW_POWER_TEST +#define ENABLE_LOW_POWER YES +#else +#define ENABLE_LOW_POWER NO +#endif +#if defined(CFG_FLASH_SIZE) && (CFG_FLASH_SIZE == 16) +#define DTB_IMAGE_PAGES 0 +#define RECOVERY_IMAGE_PAGES 256 +#define RESERVE_IMAGE_PAGES 64 +#define BT_IMAGE_PAGES 112 +#define HIFI0_IMAGE_PAGES 192 +#define HIFI0_CODEC_PAGES 448 +#define APP_IMAGE_PAGES 2048 +#else +#define DTB_IMAGE_PAGES 0 +#define RECOVERY_IMAGE_PAGES 64 +#define RESERVE_IMAGE_PAGES 0 +#define BT_IMAGE_PAGES 112 +#define HIFI0_IMAGE_PAGES 112 +#define HIFI0_CODEC_PAGES 320 +#define APP_IMAGE_PAGES 1353 +#endif +#define NV_IMAGE_PAGES 4 +#define FOTA_IMAGE_PAGES 3 +#define FOTA_IMAGE_START 0x770000 +#define SSB_FOTA_OFFSET 0x0 +#define XO_CTRIM_VALUR_DEFAULT 0x56 +#define DSP1_IPC_ENABLE NO +#define APP_BTN_TASK_MONITOR_ENABLE NO +#define SSB_FOTA_MODE_TWS YES +#define DSP_EXTEND_OCRAM_SIZE 1310720 // Unit byte, = 1280 KB +#define OSC_EN_CALLBACK_BY_PLT YES +#define BT_MIPS_DEBUG NO +#define NON_OS_CRITICAL_RECORD NO +#define ENABLE_MASSDATA_RECORD NO +#define USE_COMPRESS_LOG_INSTEAD_OF_SDT_LOG NO +#define COMPRESS_LOG_TRIGGER_THRESHOLD 0 +#define COMPRESS_LOG_COUNT_THRESHOLD 0xFFFFFFFF +#define EXCEPTION_TEST_ENABLE NO +#define LOG_LEVEL_APP_DEFAULT_CONFIG 3 // Info level +#define LOG_LEVEL_BT_DEFAULT_CONFIG 3 // Info level +#define LOG_LEVEL_DSP_DEFAULT_CONFIG 3 // Info level +#define BCPU_HEAP_MININUM_SIZE 0xA000 // 40KB +#define SYS_DEBUG_MODE_ENABLE YES +#define PROMPT_TONE_REGION_LENGTH 0x2800 +#define AUDIO_DATA_STREAM_REGION_LENGTH 0x2000 +#define BT_MASSDATA_LENGTH 0x400 +#define APP_MASSDATA_LENGTH 0x800 +#define APP_LOGGING_LENGTH 0x1C00 +#define DSP_LOGGING_LENGTH 0x2000 +#define PSRAM_DENSITY_MB 32 +#define RC_CLOCK_ON NO +#define SMART_WATCH_BT_COEX_PIN_SWITCH NO // pinmux switch in the Coexistence of BT and WiFi of smart watch +#define CAP_SENSOR_BUFF_LEN 128 +#define BT_L2RAM_AREA_SIZE 3 // 384k, Reference the enum Value of hal_b_memory_share_config_t +#define DSP_L2RAM_AREA_TOTAL 10 +#define GPU_L2RAM_AREA_TOTAL 11 +#ifndef CONFIG_PSRAM_SUPPORT +#define DSP_L2RAM_AREA_SIZE 6 // 无PSRAM & 小型化场景分配给DSP 6块*128K=768KB 剩余512K系统使用 +#else +#if defined(CONFIG_SEA_PHS_SUPPORT) +#define DSP_L2RAM_AREA_SIZE 10 // 语音唤醒场景分配给DSP 10块*128K=1280KB DSP L2M不给系统使用 +#else +#define DSP_L2RAM_AREA_SIZE 8 // 正常场景分配给DSP 8块*128K=1024KB 剩余256K系统使用 +#endif /* CONFIG_SEA_PHS_SUPPORT */ +#endif /* CONFIG_PSRAM_SUPPORT */ +#define PUYA_FLASH_SUPPORT YES + +/********************display config********************/ +#define DOUBLE_BUFFER 1 +#if defined(QSPI_DISPLAY) +#define RESOLUTION_WIDTH 194 +#define RESOLUTION_HEIGHT 368 +#elif defined(MEMORY_MINI) +#define RESOLUTION_WIDTH 240 +#define RESOLUTION_HEIGHT 296 +#elif defined(SUPPORT_SOFT_SEND_FRM) +#define RESOLUTION_WIDTH 368 +#define RESOLUTION_HEIGHT 448 +#else +#define RESOLUTION_WIDTH 454 +#define RESOLUTION_HEIGHT 454 +#endif + +/********************Other module board config********************/ +#define BTC_SWITCH_COEX YES +#define BTC_SMART_WEAR_WLCOEX YES +#define BTC_WITH_SMART_WEAR YES +#define BTC_TWS_MONITOR YES +#define BTC_ICO_SUPPORT YES +#define BTC_DUAL_ANT_SWITCH_SUPPORT NO +#define BTC_GET_EMC_FROM_PLATFORM YES // 后续耳机产品通过HCI传递NV数据实现后,该选项需要置为NO +#define BTSNOOP_ENABLE NO +#define TWS_USER_CHR_RECORD NO +#define BTH_WEAR_ENABLE_AUDIO_SINK NO +#define BTH_WEAR_ENABLE_AUDIO_GATEWAY NO +#define BTH_WEAR_BREDR_DOUBLE_CONNECT NO +#define BTC_DFX_LOG_HELP_SUPPORT NO +#define FACTORY_CALI NO +#define BTH_WEAR_ENABLE_CONNECT_MANAGER NO +#define BTH_WEAR_ENABLE_BLE_FEATURES YES +#define BTH_WEAR_ENABLE_HFP_FEATURES NO +#define WEAR_USER_CONFIG NO +#define BTH_HIGH_POWER YES +#define MULTI_CONNECT YES +#define BTH_CONFIG_HDAP YES +#define DEVICE_MANAGE_FEATURE YES +#define BTH_CALL_LC3_32K YES +#define BTH_ENABLE_LC3_CODEC YES +#define ENABLE_CHANGE_DEVICE_NAME YES +#define BTH_DIP_PRODUCT_ID 0x4106 +#define BTH_ENABLE_L2HC_CODEC YES +#define ENABLE_BT_XO_16M NO +#define BTH_WSTP_CMD_SUPPORT YES +#define PRODUCT_SUPPORT_MODE_SWITCH YES +#define BT_MANAGER_DEPLOYED 2 +#define BT_CODEC_TID 2 +#define BTH_WEAR_ENABLE_AVRCP_TARGET NO +#define BTH_WEAR_ENABLE_AVRCP_CONTROLLER NO +#define BTH_WEAR_ENABLE_AUDIO_SOURCE NO +#define BTH_WEAR_ALLOW_INQUIRY_SCAN YES +#define BTH_WEAR_ENABLE_HALL_STATE NO + +// 音频内置输入设备 +#define BUILTIN_AI_PORT 0x50 // 参考 soc_uapi_ai.h 中 UAPI_AI_PORT_LPADC0 枚举 +#define BUILTIN_AI_PORT_ATTR_ADC_RX_TYPE 0 // 参考 soc_uapi_ai.h 中 UAPI_AI_RX_DEFAULT 枚举 +#define BUILTIN_AI_PCM_ATTR_AUDIO_CH 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_1 枚举 +#define BUILTIN_AI_PCM_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define BUILTIN_AI_PCM_ATTR_SAMPLE_RATE 16000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_16K 枚举 +#define BUILTIN_AI_PCM_ATTR_FRAME_PER_SEC 100 // 每秒帧数 + +// 音频内置输出设备 +#define BUILTIN_SND_OUT_PORT 0x12 // 参考 soc_uapi_sound.h 中 UAPI_SND_OUT_PORT_I2S2 枚举 +#define BUILTIN_SND_OUT_PORT_NUM 1 // 端口个数 +#define BUILTIN_SND_OUT_AUDIO_CH 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define BUILTIN_SND_OUT_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define BUILTIN_SND_OUT_SAMPLE_RATE 48000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_48K 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_BCLK 8 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_BCLK_8_DIV 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_AUDIO_CH 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_STD_MODE 0 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_STD_MODE 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_MASTER 1 // 1:主设备,0:从设备 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_MCLK 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_MCLK_256_FS 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_I2S_PCM_DELAY 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_PCM_1_DELAY 枚举 +#define BUILTIN_SND_OUT_I2S_ATTR_SAMPLE_RISE_EDGE 1 // 参考 soc_uapi_audio.h 中 pcm_sample_rise_edge 成员 + +// 音频外挂输入设备 +#define EXTERNAL_AI_PORT 1 // 参考 soc_uapi_ai.h 中 UAPI_AI_PORT_I2S1 枚举 +#define EXTERNAL_AI_I2S_ATTR_MASTER 1 // 1:主设备,0:从设备 +#define EXTERNAL_AI_I2S_ATTR_I2S_MODE 0 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_STD_MODE 枚举 +#define EXTERNAL_AI_I2S_ATTR_MCLK 4 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_MCLK_768_FS 枚举 +#define EXTERNAL_AI_I2S_ATTR_BCLK 24 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_BCLK_24_DIV 枚举 +#define EXTERNAL_AI_I2S_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_AI_I2S_ATTR_AUDIO_CH 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_AI_I2S_ATTR_SAMPLE_RISE_EDGE 1 // 参考 soc_uapi_audio.h 中 pcm_sample_rise_edge 成员 +#define EXTERNAL_AI_I2S_ATTR_PCM_DELAY_CYCLE 1 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_PCM_1_DELAY 枚举 +#define EXTERNAL_AI_PCM_ATTR_CHANNELS 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_AI_PCM_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_AI_PCM_ATTR_SAMPLE_RATE 16000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_16K 枚举 +#define EXTERNAL_AI_PCM_ATTR_FRAME_PER_SEC 100 // 每秒帧数 + +// 音频外挂输出设备 +#define EXTERNAL_SND_OUT_PORT 0x11 // 参考 soc_uapi_sound.h 中 UAPI_SND_OUT_PORT_I2S1 枚举 +#define EXTERNAL_SND_OUT_AUDIO_CHANNEL 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_SND_OUT_AUDIO_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_SND_OUT_AUDIO_SAMPLE_RATE 16000 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_SAMPLE_RATE_16K 枚举 +#define EXTERNAL_SND_OUT_PORT_NUM 1 // 端口个数 +#define EXTERNAL_SND_OUT_I2S_ATTR_BIT_DEPTH 16 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_BIT_DEPTH_16 枚举 +#define EXTERNAL_SND_OUT_I2S_ATTR_CHANNEL 2 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_CHANNEL_2 枚举 +#define EXTERNAL_SND_OUT_I2S_ATTR_I2S_MODE 0 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_STD_MODE 枚举 +#define EXTERNAL_SND_OUT_I2S_ATTR_MCLK 4 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_MCLK_768_FS 枚举 +#define EXTERNAL_SND_OUT_I2S_ATTR_MASTER 1 // 1:主设备,0:从设备 +#define EXTERNAL_SND_OUT_I2S_ATTR_SAMPLE_RISE_EDGE 1 // 参考 soc_uapi_audio.h 中 pcm_sample_rise_edge 成员 +#define EXTERNAL_SND_OUT_I2S_ATTR_BCLK 24 // 参考 soc_uapi_audio.h 中 UAPI_AUDIO_I2S_BCLK_24_DIV 枚举 + +// Sleep option +#define CONFIG_PM_TICKLESS_EN YES +#define CONFIG_PM_POWER_GATING_EN YES +#define CONFIG_PM_SLEEP_RECORD_EN YES +#define CONFIG_PM_VETO_TRACK_EN NO +#define CONFIG_PM_SLEEP_INT_EN NO + +// Double-click the key +#define CONFIG_SUPPORT_BUTTON_DOUBLE_CLICK NO + +// LCD VCI_EN +#define VCI_LCD_GPIO S_AGPIO_L6 +#define DISPLAY_TE_GPIO S_AGPIO_L22 +#define RESET_LCD_GPIO S_AGPIO_R3 + +// TP CONFIG +#define ZTW523_I2C_BUS I2C_BUS_1 +#define ZTW523_INT_GPIO S_AGPIO_R5 +#define ZTW523_RESET_GPIO S_AGPIO_R4 +#define TMA525B_I2C_BUS I2C_BUS_1 +#define TMA525B_INT_GPIO S_AGPIO_R5 +#define TMA525B_RESET_GPIO S_AGPIO_R4 + +// TRACK MODE +#define SND_TRACK_MODE_BT_MUSIC 0 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_STEREO 枚举 +#define SND_TRACK_MODE_BT_SCO 1 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_DOUBLE_MONO 枚举 +#define SND_TRACK_MODE_LOCAL_CAT1 1 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_DOUBLE_MONO 枚举 +#define SND_TRACK_MODE_BT_CAT1 0 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_STEREO 枚举 +#define SND_TRACK_MODE_LOCAL_MUSIC 1 // 参考 soc_uapi_sound.h 中 UAPI_SND_TRACK_DOUBLE_MONO 枚举 +/** + * @} + */ +#endif diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c new file mode 100644 index 000000000..5037787a2 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c @@ -0,0 +1,484 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: CLOCKS CONFIG PRIVATE SOURCE. + */ +#include "clocks_config_priv.h" +#include "product.h" + +#if !defined(BUILD_APPLICATION_ROM) +// FVCO : FREF *(FBDIV+FRAC/(2^24))/REFDIV ;CLK_PLL:FVCO/POSTDIV1/POSTDIV2 +static cmu_pll_config_t g_pll_cfg = { + PLL_FBDIV_NUM, + PLL_FRAC_H_NUM, + PLL_FRAC_L_NUM, + PLL_POSTDIV1_NUM, + PLL_POSTDIV2_NUM, +}; + +#ifdef BUILD_APPLICATION_SSB +static clocks_clk_cfg_t g_ssb_clk_cfg[CLOCKS_CCRG_MODULE_MAX] = { + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4 }, // CLOCKS_CCRG_MODULE_MCU_CORE + { CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8 }, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + { CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9 }, // CLOCKS_CCRG_MODULE_COM_BUS + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3 }, // CLOCKS_CCRG_MODULE_SDIOM + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5 }, // CLOCKS_CCRG_MODULE_MEM_BUS + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4 }, // CLOCKS_CCRG_MODULE_XIP_OPI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8 }, // CLOCKS_CCRG_MODULE_XIP_QSPI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6 }, // CLOCKS_CCRG_MODULE_GPU + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6 }, // CLOCKS_CCRG_MODULE_HIFI + { CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36 }, // CLOCKS_CCRG_MODULE_CODEC + { CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_PAD_OUT0 + { CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_PAD_OUT1 + { CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1 }, // CLOCKS_CCRG_MODULE_PAD_OUT2 +}; +#else +/************************** System clock Config ***********************/ +static const clocks_clk_cfg_t g_system_all_core_clocks[CLOCKS_CONFIG_MAX][CLOCKS_CCRG_MODULE_MAX] = { + /* All 32M */ + { + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + }, + /* All 64M */ + { + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, + /* PLL */ + { + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, + /* PLL 0.9v */ + { + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_10}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, + /* test */ + { + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_CORE + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_LS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_UART + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MCU_PERP_SPI + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_4}, // CLOCKS_CCRG_MODULE_COM_BUS + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_SDIOM + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_MEM_BUS + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_OPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_XIP_QSPI + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_GPU + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // CLOCKS_CCRG_MODULE_HIFI + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_36}, // CLOCKS_CCRG_MODULE_CODEC + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT0 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT1 + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // CLOCKS_CCRG_MODULE_PAD_OUT2 + }, +}; + +/************************** System core clock Config ******************/ +static const system_clocks_freq_config_t g_system_clocks_freq_config[CLOCKS_FREQ_MAX] = { + { // CLOCKS_M32_B32_D_0 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M32_B32_D_1 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M32_B32_D_2 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:98M + }, + { // CLOCKS_M32_B32_D_3 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M32_B32_D_4 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M32_B32_D_5 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M32_B64_D_0 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M32_B64_D_1 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M32_B64_D_2 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:98M + }, + { // CLOCKS_M32_B64_D_3 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M32_B64_D_4 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M32_B64_D_5 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu:32M + CLOCKS_CLK_SRC_TCXO_2X, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M64_B32_D_0 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M64_B32_D_1 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M64_B32_D_2 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:96.7M + }, + { // CLOCKS_M64_B32_D_3 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M64_B32_D_4 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M64_B32_D_5 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO, // bt:32M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M64_B64_D_0 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // dsp:32M + }, + { // CLOCKS_M64_B64_D_1 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // dsp:64M + }, + { // CLOCKS_M64_B64_D_2 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // dsp:96.7M + }, + { // CLOCKS_M64_B64_D_3 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_7}, // dsp:126M + }, + { // CLOCKS_M64_B64_D_4 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // dsp:176.9M + }, + { // CLOCKS_M64_B64_D_5 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu:64M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, + { // CLOCKS_M_H_B64_D_H + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // mcu:221M + CLOCKS_CLK_SRC_TCXO_2X, // bt:64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // dsp:294.9M + }, +}; + +static const system_display_freq_config_t g_system_display_freq_config[CLOCKS_DISPLAY_FREQ_MAX] = { + { // CLOCKS_DISPLAY_FREQ_0 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // opi:32M -> psram:16M + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // gpu:closed + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // membus:follow mcu_clk/2 + }, + { // CLOCKS_DISPLAY_FREQ_1 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // opi:64M -> psram:32M + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // gpu:closed + {CLOCKS_CLK_SRC_MAX, CLOCK_DIV_1}, // membus:follow mcu_clk/2 + }, + { // CLOCKS_DISPLAY_FREQ_2 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // psram:147M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // gpu:110M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // membus:110M + }, + { // CLOCKS_DISPLAY_FREQ_3 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // psram:133M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // gpu:159.6M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // membus:199.5M + }, + { // CLOCKS_DISPLAY_FREQ_4 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // psram:159M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // gpu:190.8M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // membus:190.8M + }, +}; + +/************************** MCU core clock Config *********************/ +static const system_mcu_core_clk_cfg_t g_system_mcu_freq_config[CLOCKS_MCU_FREQ_MAX] = { + { // CLOCKS_M_H16 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_2}, // mcu_clk:16M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // psram_clk:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_2}, // membus:16M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // flash: norflash & nandflash:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // sdiom:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // gpu:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // spi:32M + }, + { // CLOCKS_M32 + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // mcu_clk:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // psram_clk:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // membus:32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // flash: norflash & nandflash 32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // sdiom: 32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // gpu: 32M + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // spi: 32M + }, + { // CLOCKS_RC + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // mcu_clk:49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // psram_clk:49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // membus:49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // flash: norflash & nandflash 49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // sdiom: 49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // gpu: 49.152M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // spi: 49.152M + }, + { // CLOCKS_M64 + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // mcu_clk:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // psram_clk:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // membus:64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // flash: norflash & nandflash 64M +#if defined (CFG_DRIVERS_MMC) + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // sdiom: 64M +#else + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // sdiom: 64M +#endif + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // gpu: 64M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // spi: 64M + }, + { // CLOCKS_M_H0 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // mcu_clk:110M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // psram_clk:225M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_8}, // membus:110M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // flash: norflash & nandflash: 176M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // sdiom:295M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // gpu:147M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_9}, // spi:98M + }, + { // CLOCKS_M_H1 + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_4}, // mcu_clk:221M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // psram_clk:295M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // membus:177M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_5}, // flash: norflash & nandflash:177M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // sdiom:295M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_6}, // gpu:147M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_10}, // spi:88M + }, +}; + +static const clocks_clk_cfg_t g_system_sdio_freq_config[CLOCKS_SDIO_FREQ_MAX] = { + {CLOCKS_CLK_SRC_TCXO, CLOCK_DIV_1}, // 32M + {CLOCKS_CLK_SRC_RC, CLOCK_DIV_1}, // 50M + {CLOCKS_CLK_SRC_TCXO_2X, CLOCK_DIV_1}, // 64M + {CLOCKS_CLK_SRC_PLL, CLOCK_DIV_3}, // 294.912M +}; + +/************************** MCU core all perips clock Config *********************/ +static const system_mcu_perip_clk_t g_system_mcu_perp_clk_set_config[] = { + /* Clocks M_CLKEN0 region */ + {HAL_CLOCKS_APP_SEC_CLK, TURN_ON}, // sec clock + {HAL_CLOCKS_APP_DIAG_CLK, TURN_ON}, // diag clock + {HAL_CLOCKS_APP_PWM_CLK, TURN_OFF}, // pwm clock + {HAL_CLOCKS_APP_X2H_MEM_BUS_CLK, TURN_ON}, // x2h_mem_bus clock + + /* Clocks M_CLKEN1 region */ + {HAL_CLOCKS_APP_TIMER_CLK, TURN_ON}, // timer clock + {HAL_CLOCKS_APP_SPI0_M_CLK, TURN_OFF}, // spi0 clock + {HAL_CLOCKS_APP_SPI1_MS_CLK, TURN_OFF}, // spi1 clock + {HAL_CLOCKS_APP_SPI2_MS_CLK, TURN_OFF}, // spi2 clock + {HAL_CLOCKS_APP_UART_H0_CLK, TURN_ON}, // uart h0 clock + {HAL_CLOCKS_APP_UART_H1_CLK, TURN_ON}, // uart h1 clock + {HAL_CLOCKS_APP_I2C0_CLK, TURN_OFF}, // i2c0 clock + {HAL_CLOCKS_APP_I2C1_CLK, TURN_ON}, // i2c1 clock + {HAL_CLOCKS_APP_I2C2_CLK, TURN_OFF}, // i2c2 clock + {HAL_CLOCKS_APP_I2C3_CLK, TURN_ON}, // i2c3 clock + {HAL_CLOCKS_APP_QSPI_1CS_CLK, TURN_ON}, // qspi clock + {HAL_CLOCKS_APP_XIP_BUS_CLK, TURN_ON}, // xip bus clock + {HAL_CLOCKS_APP_COM_BUS_DSP_CLK, TURN_ON}, // com bus dsp clock + {HAL_CLOCKS_APP_BT_TGTWS_CLK, TURN_ON}, // bt tgws clock no closed will affect bt call + + /* Clocks M_CLKEN2 region */ + {HAL_CLOCKS_APP_PULSE_CAPTURE_CLK, TURN_OFF}, // pulse_capture_clken clock + {HAL_CLOCKS_APP_M_DAP_CLK, TURN_ON}, // m_dap_clken clock + {HAL_CLOCKS_APP_RC_CLK, TURN_ON}, // rc clock + {HAL_CLOCKS_APP_XO_CLK, TURN_ON}, // xo clock +}; +#endif + +/*********************** clk cg config **********************************/ +#if (CLK_AUTO_CG_ENABLE == YES) +static const system_clk_cg_t g_system_clkcg_config[] = { + {HAL_CLOCKS_MODULE_AUTO_CG_COM_BUS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_CACHE, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MEM_AHB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AON, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_BT, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_MAIN, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_SDIO_M, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SDIO_CFG, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DISPLAY, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_CFG, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MAIN_AXI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DISPLAY_AXI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_PERP_AXI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_OPI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_FCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_TCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_SDIO, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_BSUB_FCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_EH2H_BSUB_TCOM, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_APB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AH2H_MCU_SUB_TAON, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AH2H_MCU_SUB_SEC, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_AH2H_SH2H_MCU_SUB_MFSH2H, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SH2H_MCU_SUB_SFH2H, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MCU_PERP_AXI_GLB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SDMA_MTOP_SDMA, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DMA_MTOP_SDMA, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_BTOP_DMA_SDMA, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_OPI, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_QSPI2, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_QSPI1, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_QSPI0, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SPI2_2CS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SPI1_3CS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_SPI0_3CS, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_CACHE_H2H, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_CACHE, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_MAIN_AXI_GLB, TURN_OFF}, + {HAL_CLOCKS_MODULE_AUTO_CG_DSP_SHARE, TURN_OFF}, +}; +#endif + +cmu_pll_config_t clocks_pll_cfg_get(void) +{ + return g_pll_cfg; +} + +#ifdef BUILD_APPLICATION_SSB +clocks_clk_cfg_t const *clocks_ssb_clk_cfg_get(void) +{ + return g_ssb_clk_cfg; +} +#else +clocks_clk_cfg_t const *clocks_system_all_clocks_get(system_clocks_config_t clk_level) +{ + return g_system_all_core_clocks[clk_level]; +} + +system_clocks_freq_config_t clocks_system_freq_cfg_get(system_clocks_freq_t clk_level) +{ + return g_system_clocks_freq_config[clk_level]; +} + +system_display_freq_config_t clocks_system_display_freq_get(system_display_freq_t clk_level) +{ + return g_system_display_freq_config[clk_level]; +} + +system_mcu_core_clk_cfg_t clocks_system_mcu_freq_get(system_mcu_freq_t clk_level) +{ + return g_system_mcu_freq_config[clk_level]; +} + +clocks_clk_cfg_t clocks_system_sdio_freq_get(system_sdio_freq_t clk_level) +{ + return g_system_sdio_freq_config[clk_level]; +} + +system_mcu_perip_clk_t *clocks_system_mcu_perip_clock_config_get(uint32_t *length) +{ + *length = sizeof(g_system_mcu_perp_clk_set_config) / sizeof(system_mcu_perip_clk_t); + return g_system_mcu_perp_clk_set_config; +} + +#if (CLK_AUTO_CG_ENABLE == YES) +system_clk_cg_t const *clock_system_cg_config_get(uint32_t *length) +{ + *length = sizeof(g_system_clkcg_config) / sizeof(system_clk_cg_t); + return g_system_clkcg_config; +} +#endif +#endif +#endif \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/config/pmp_config.c b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/config/pmp_config.c new file mode 100644 index 000000000..d709c7e14 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/config/pmp_config.c @@ -0,0 +1,193 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. + * Description: chip pmp init config file. + */ +#include "pmp_config.h" +#include "stdbool.h" +#include "drv_pmp.h" +#include "memory_config.h" + +#define L2MEM_DSP_ADDR_START 0x60100000 +#define L2MEM_DSP_ADDR_LEN 0x100000 + +#define L2MEM_GPU_ADDR_START 0x60240000 +#define L2MEM_GPU_ADDR_LEN 0x20000 + +#if PSRAM_DENSITY_MB == 16 +#define PSRAM_ADDR_START 0x6C000000 +#define PSRAM_ADDR_LEN 0x800000 +#define PSRAM_SECOND_ADDR_START 0x6C800000 +#define PSRAM_SECOND_ADDR_LEN 0x800000 +#else /* PSRAM_DENSITY_MB == 32 */ +#define PSRAM_ADDR_START 0x6C000000 +#define PSRAM_ADDR_LEN 0x1000000 +#define PSRAM_SECOND_ADDR_START 0x6D000000 +#define PSRAM_SECOND_ADDR_LEN 0x1000000 +#endif + +#define NOR_FLASH_ADDR_START FLASH_START +#define NOR_FLASH_ADDR_LEN FLASH_LENGTH + +#define BOOTROM_PMP_LENGTH 0x10000 +#define ITCM_PMP_LENGTH 0x10000 +#define ITCM_PMP_SECOND_LENGTH 0x20000 +#define DTCM_PMP_LENGTH 0x80000 + +typedef enum { + BOOTROM_IDX = 0, + ITCM_IDX = 1, + ITCM_SECOND_IDX = 2, + DTCM_IDX = 3, + L2RAM_IDX = 4, + SHARE_MEM_IDX = 5, + BT_RAM_APP_MAPPING_IDX = 6, + REG_ADDR_0_IDX = 7, /* reg 0x5x */ + REG_ADDR_1_IDX = 8, /* reg 0xa3 */ + CPU_ADDR_IDX = 9, /* reg 0xa3 */ +#ifdef CONFIG_PSRAM_SUPPORT + PSRAM_IDX, + PSRAM_SECOND_IDX, +#endif + NOR_FLASH_IDX, + BACKGROUND_IDX = 15, + MAX_REGION_NUM +} region_index_t; + +pmp_conf_t g_region_attr[MAX_REGION_NUM]; + +static void pmp_init_config(void) +{ + /* bootrom 可读不可写不可执行 */ + g_region_attr[BOOTROM_IDX].idx = BOOTROM_IDX; + g_region_attr[BOOTROM_IDX].addr = ROM_START; + g_region_attr[BOOTROM_IDX].size = 0x100; + g_region_attr[BOOTROM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[BOOTROM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_NEXECUTE; + g_region_attr[BOOTROM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[BOOTROM_IDX].conf.lock = true; + + /* ITCM 第一段 可读可执行不可写 */ + g_region_attr[ITCM_IDX].idx = ITCM_IDX; + g_region_attr[ITCM_IDX].addr = APP_ITCM_ORIGIN; + g_region_attr[ITCM_IDX].size = ITCM_PMP_LENGTH; + g_region_attr[ITCM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[ITCM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_EXECUTE; + g_region_attr[ITCM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[ITCM_IDX].conf.lock = true; + + /* ITCM 第二段 可读可执行不可写 */ + g_region_attr[ITCM_SECOND_IDX].idx = ITCM_SECOND_IDX; + g_region_attr[ITCM_SECOND_IDX].addr = (APP_ITCM_ORIGIN + ITCM_PMP_LENGTH); + g_region_attr[ITCM_SECOND_IDX].size = ITCM_PMP_SECOND_LENGTH; + g_region_attr[ITCM_SECOND_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[ITCM_SECOND_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_EXECUTE; + g_region_attr[ITCM_SECOND_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[ITCM_SECOND_IDX].conf.lock = true; + + /* DTCM 可读可写不可执行 */ + g_region_attr[DTCM_IDX].idx = DTCM_IDX; + g_region_attr[DTCM_IDX].addr = APP_DTCM_ORIGIN; + g_region_attr[DTCM_IDX].size = DTCM_PMP_LENGTH; + g_region_attr[DTCM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[DTCM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[DTCM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[DTCM_IDX].conf.lock = true; + + /* L2MEM 可读可执行可写 no cache属性 */ + g_region_attr[L2RAM_IDX].idx = L2RAM_IDX; + g_region_attr[L2RAM_IDX].addr = 0x60000000; + g_region_attr[L2RAM_IDX].size = 0x2000000; + g_region_attr[L2RAM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[L2RAM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_EXECUTE; + g_region_attr[L2RAM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[L2RAM_IDX].conf.lock = true; + + /* SHARE_MEM_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[SHARE_MEM_IDX].idx = SHARE_MEM_IDX; + g_region_attr[SHARE_MEM_IDX].addr = 0x87000000; + g_region_attr[SHARE_MEM_IDX].size = 0x20000; + g_region_attr[SHARE_MEM_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[SHARE_MEM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_EXECUTE; + g_region_attr[SHARE_MEM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[SHARE_MEM_IDX].conf.lock = true; + + /* BT_RAM_APP_MAPPING_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[BT_RAM_APP_MAPPING_IDX].idx = BT_RAM_APP_MAPPING_IDX; + g_region_attr[BT_RAM_APP_MAPPING_IDX].addr = 0xA6000000; + g_region_attr[BT_RAM_APP_MAPPING_IDX].size = 0x200000; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[BT_RAM_APP_MAPPING_IDX].conf.lock = true; + + /* REG_ADDR_0_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[REG_ADDR_0_IDX].idx = REG_ADDR_0_IDX; + g_region_attr[REG_ADDR_0_IDX].addr = 0x50000000; + g_region_attr[REG_ADDR_0_IDX].size = 0x10000000; + g_region_attr[REG_ADDR_0_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[REG_ADDR_0_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[REG_ADDR_0_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[REG_ADDR_0_IDX].conf.lock = true; + + /* REG_ADDR_1_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[REG_ADDR_1_IDX].idx = REG_ADDR_1_IDX; + g_region_attr[REG_ADDR_1_IDX].addr = 0xA3000000; + g_region_attr[REG_ADDR_1_IDX].size = 0x10000; + g_region_attr[REG_ADDR_1_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[REG_ADDR_1_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[REG_ADDR_1_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[REG_ADDR_1_IDX].conf.lock = true; + + /* CPU_ADDR_IDX 可读可写不可执行 不打开cache属性 */ + g_region_attr[CPU_ADDR_IDX].idx = CPU_ADDR_IDX; + g_region_attr[CPU_ADDR_IDX].addr = 0xB0000000; + g_region_attr[CPU_ADDR_IDX].size = 0x10000000; + g_region_attr[CPU_ADDR_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[CPU_ADDR_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[CPU_ADDR_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[CPU_ADDR_IDX].conf.lock = true; + +#ifdef CONFIG_PSRAM_SUPPORT + /* PSRAM 第一段 可读可写不可执行 打开cache属性 */ + g_region_attr[PSRAM_IDX].idx = PSRAM_IDX; + g_region_attr[PSRAM_IDX].addr = PSRAM_ADDR_START; + g_region_attr[PSRAM_IDX].size = PSRAM_ADDR_LEN; + g_region_attr[PSRAM_IDX].conf.pmp_attr = PMP_ATTR_WRITEBACK_RWALLOCATE; + g_region_attr[PSRAM_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[PSRAM_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[PSRAM_IDX].conf.lock = true; + + /* PSRAM 第二段 可读可写不可执行 关闭cache属性 */ + g_region_attr[PSRAM_SECOND_IDX].idx = PSRAM_SECOND_IDX; + g_region_attr[PSRAM_SECOND_IDX].addr = PSRAM_SECOND_ADDR_START; + g_region_attr[PSRAM_SECOND_IDX].size = PSRAM_SECOND_ADDR_LEN; + g_region_attr[PSRAM_SECOND_IDX].conf.pmp_attr = PMP_ATTR_NO_BUFFERABLE_AND_NO_CACHEABLE; + g_region_attr[PSRAM_SECOND_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_RW_NEXECUTE; + g_region_attr[PSRAM_SECOND_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[PSRAM_SECOND_IDX].conf.lock = true; +#endif + + /* Flash 可读不可写可执行 打开cache属性 */ + g_region_attr[NOR_FLASH_IDX].idx = NOR_FLASH_IDX; + g_region_attr[NOR_FLASH_IDX].addr = NOR_FLASH_ADDR_START; + g_region_attr[NOR_FLASH_IDX].size = NOR_FLASH_ADDR_LEN; + g_region_attr[NOR_FLASH_IDX].conf.pmp_attr = PMP_ATTR_WRITEBACK_RWALLOCATE; + g_region_attr[NOR_FLASH_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_READ_ONLY_EXECUTE; + g_region_attr[NOR_FLASH_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[NOR_FLASH_IDX].conf.lock = true; + + /* BACKGROUND_IDX 不可读不可写不可执行 */ + g_region_attr[BACKGROUND_IDX].idx = BACKGROUND_IDX; + g_region_attr[BACKGROUND_IDX].addr = 0x0; + g_region_attr[BACKGROUND_IDX].size = 0xFFFFFFFF; /* 4GB */ + g_region_attr[BACKGROUND_IDX].conf.pmp_attr = PMP_ATTR_DEVICE_NO_BUFFERABLE; + g_region_attr[BACKGROUND_IDX].conf.rwx_permission = (rwx_permission_t)PMPCFG_NO_ACCESS; + g_region_attr[BACKGROUND_IDX].conf.addr_match = PMPCFG_ADDR_MATCH_NAPOT; + g_region_attr[BACKGROUND_IDX].conf.lock = true; +} + +void pmp_init(void) +{ + pmp_init_config(); + uapi_pmp_config(g_region_attr, MAX_REGION_NUM); +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c new file mode 100644 index 000000000..b6f409070 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c @@ -0,0 +1,475 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides uart port template \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-06-06, Create file. \n + */ +#include +#include "dma_porting.h" +#include "debug_print.h" +#include "hal_uart_v120.h" +#include "uart_porting.h" +#ifdef SUPPORT_HAL_PINCTRL +#include "pinctrl_porting.h" +#include "pinctrl.h" +#endif +#include "uart.h" +#include "oal_interface.h" +#include "platform_core.h" +#include "securec.h" +#include "soc_osal.h" +#ifdef SUPPORT_CLOCKS_CORE +#include "clocks_core_common.h" +#endif +#if defined(SUPPORT_TEST_COMMON) +#include "test_suite_uart.h" +#endif +#if defined(SUPPORT_AT_CMD) +#include "at_cmd_api.h" +#endif +#ifndef BUILD_APPLICATION_SSB +#include "log_uart.h" +#include "cmsis_os.h" +#endif +#if defined(SW_RTT_DEBUG) +#include "SEGGER_RTT.h" +#endif + +#ifdef BUILD_APPLICATION_SSB +#define UART_RX_BUFFER_SIZE 1 +#else +#define UART_RX_BUFFER_SIZE 56 +#endif + +#define AT_BLE_HEADER_LENGTH 49 +#define AT_CMD_BUFSIZE_MAX 256 +#define UARTILPR 0x20 +#define UARTIBRD 0x24 +#define UARTFBRD 0x28 +#define UARTLCRH 0x2c +#define UARTCR 0x30 +#define UARTIFLS 0x34 +#define UARTIMSC 0x38 +#define UARTDMACR 0x48 +#define UARTRESET (M_CTL_RB_BASE + 0x0168) +#define UARTBUS0 0x1 +#define UARTBUS1 0x0 +typedef struct { + pin_mode_t tx_pin_mode; + pin_mode_t rx_pin_mode; + pin_mode_t cts_pin_mode; + pin_mode_t rts_pin_mode; +} uart_pin_mode_t; + +typedef struct uart_config { + uart_pin_config_t pin; + uart_pin_mode_t pin_mode; + core_irq_t irq_num; + osal_irq_handler irq_func; + uart_rx_callback_t rx_callback; + uart_attr_t line_config; + uart_buffer_config_t buffer_config; +#ifndef BUILD_APPLICATION_SSB + osal_mutex uart_mutex; + bool support_mutex; +#endif +} uart_config_t; + +const uintptr_t g_uart_base_addrs[UART_BUS_MAX_NUM] = { + (uintptr_t)UART0_BASE, + (uintptr_t)UART1_BASE, +}; + +uintptr_t uart_porting_base_addr_get(uart_bus_t bus) +{ + return g_uart_base_addrs[bus]; +} + +static bool g_sw_debug_uart_enabled = false; +uint8_t g_uart0_rx_buffer[UART_RX_BUFFER_SIZE]; +uint8_t g_uart1_rx_buffer[UART_RX_BUFFER_SIZE]; +#if defined(SUPPORT_AT_CMD) +static void at_cmd_uart_rx_callback(const void *buf, uint16_t buf_len, bool remaining); +#endif + +void log_factory_at_callback(const void *buffer, uint16_t length, bool remaining); + +static uart_config_t g_uart_config[UART_BUS_MAX_NUMBER] = { +#ifdef BUILD_APPLICATION_SSB + /* UART_BUS_0 for debug print */ + { + { + .tx_pin = S_MGPIO19, + .rx_pin = S_MGPIO20, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX + }, + UART_0_IRQN, + (osal_irq_handler)irq_uart0_handler, + NULL, + { + .baud_rate = 115200, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart0_rx_buffer, + } + }, + /* UART_BUS_1 for codeloader */ + { + { + .tx_pin = S_MGPIO33, + .rx_pin = S_MGPIO34, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + }, + UART_1_IRQN, + (osal_irq_handler)irq_uart1_handler, + NULL, + { + .baud_rate = 115200, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart1_rx_buffer, + } + } +#else + /** UART_BUS_0, which is used to at cmd and debug print in wstp version, + * and which is used to testustie and debug print in testsuite version + */ + { + { + .tx_pin = S_MGPIO19, + .rx_pin = S_MGPIO20, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART1, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX + }, + UART_0_IRQN, + (osal_irq_handler)irq_uart0_handler, +#if defined(SUPPORT_TEST_COMMON) + test_suite_uart_rx_callback, +#elif defined(SUPPORT_AT_CMD) + at_cmd_uart_rx_callback, +#else + NULL, +#endif + { + .baud_rate = 115200, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart0_rx_buffer, + }, + NULL, +#if defined(SUPPORT_TEST_COMMON) + false, +#else + true, +#endif + }, + /* UART_BUS_1 is used to hso uart */ + { + { + .tx_pin = S_MGPIO33, + .rx_pin = S_MGPIO34, + .cts_pin = PIN_NONE, + .rts_pin = PIN_NONE + }, + { + .tx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .rx_pin_mode = (pin_mode_t)HAL_PIO_FUNC_UART_HS_UART, + .cts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX, + .rts_pin_mode = (pin_mode_t)HAL_PIO_FUNC_MAX + }, + UART_1_IRQN, + (osal_irq_handler)irq_uart1_handler, +#ifndef FT_SINGLE_UART +#if SYS_DEBUG_MODE_ENABLE == YES + log_uart_rx_callback, +#endif +#else + log_factory_at_callback, +#endif + { + .baud_rate = 500000, + .data_bits = UART_DATA_BIT_8, + .parity = UART_PARITY_NONE, + .stop_bits = UART_STOP_BIT_1, + }, + { + .rx_buffer_size = UART_RX_BUFFER_SIZE, + .rx_buffer = g_uart1_rx_buffer, + }, + NULL, + false + } +#endif +}; +static uart_recovery_regs_t g_uart_recovery_reg[UART_BUS_MAX_NUMBER] = { 0 }; + +#ifdef FT_SINGLE_UART +void log_factory_at_callback(const void *buffer, uint16_t length, bool remaining) +{ + log_uart_rx_callback(buffer, length, remaining); + if (zdiag_is_enable() == false) { + at_cmd_msg_receive_handler((uint8_t *)buffer, length); + hal_uart_clear_pending(UART_BUS_1); + } +} +#endif + +void uart_port_register_hal_funcs(uart_bus_t bus) +{ + hal_uart_register_funcs(bus, hal_uart_v120_funcs_get()); +} + +void uart_port_unregister_hal_funcs(uart_bus_t bus) +{ + hal_uart_unregister_funcs(bus); +} + +uint32_t uart_port_get_clock_value(uart_bus_t bus) +{ + return uart_get_clock_value(bus); +} + +void uart_port_config_pinmux(uart_bus_t bus) +{ + UNUSED(bus); + uapi_pin_set_mode(g_uart_config[UART_BUS_1].pin.tx_pin, g_uart_config[UART_BUS_1].pin_mode.tx_pin_mode); + uapi_pin_set_mode(g_uart_config[UART_BUS_1].pin.rx_pin, g_uart_config[UART_BUS_1].pin_mode.rx_pin_mode); + uapi_pin_set_mode(g_uart_config[UART_BUS_0].pin.tx_pin, g_uart_config[UART_BUS_0].pin_mode.tx_pin_mode); + uapi_pin_set_mode(g_uart_config[UART_BUS_0].pin.rx_pin, g_uart_config[UART_BUS_0].pin_mode.rx_pin_mode); +} + +void uart_port_register_irq(uart_bus_t bus) +{ + osal_irq_request(g_uart_config[bus].irq_num, g_uart_config[bus].irq_func, NULL, NULL, NULL); + osal_irq_set_priority(g_uart_config[bus].irq_num, irq_prio(g_uart_config[bus].irq_num)); + osal_irq_enable(g_uart_config[bus].irq_num); +} + +void uart_port_unregister_irq(uart_bus_t bus) +{ + osal_irq_disable(g_uart_config[bus].irq_num); +} + +void irq_uart0_handler(void) +{ + hal_uart_irq_handler(UART_BUS_0); +} + +void irq_uart1_handler(void) +{ + hal_uart_irq_handler(UART_BUS_1); +} + +#ifdef SUPPORT_AT_CMD +static void at_cmd_uart_rx_callback(const void *buf, uint16_t buf_len, bool remaining) +{ + unused(remaining); + at_cmd_msg_receive_handler((uint8_t *)buf, buf_len); + hal_uart_clear_pending(SW_DEBUG_UART_BUS); +} +#endif + +void uart_config_init(void) +{ + for (uint8_t i = 0; i < UART_BUS_MAX_NUM; i++) { + if ((g_uart_config[i].pin.tx_pin != PIN_NONE) || (g_uart_config[i].pin.rx_pin != PIN_NONE)) { + uapi_uart_init(i, &(g_uart_config[i].pin), &(g_uart_config[i].line_config), NULL, + &(g_uart_config[i].buffer_config)); + } + if (g_uart_config[i].rx_callback != NULL) { + uapi_uart_register_rx_callback(i, UART_RX_CONDITION_FULL_OR_SUFFICIENT_DATA_OR_IDLE, + (uint32_t)(g_uart_config[i].buffer_config.rx_buffer_size), + g_uart_config[i].rx_callback); + } + +#ifndef BUILD_APPLICATION_SSB + if (g_uart_config[i].support_mutex == true) { + osal_mutex_init(&(g_uart_config[i].uart_mutex)); + } +#endif + } +} + +#if (defined SW_UART_DEBUG)||(defined FT_SINGLE_UART) +void sw_debug_uart_deinit(void) +{ + uapi_uart_deinit(SW_DEBUG_UART_BUS); +} + +void sw_debug_uart_init(uint32_t baud_rate) +{ + g_uart_config[SW_DEBUG_UART_BUS].line_config.baud_rate = baud_rate; + uapi_uart_init(SW_DEBUG_UART_BUS, &(g_uart_config[SW_DEBUG_UART_BUS].pin), + &(g_uart_config[SW_DEBUG_UART_BUS].line_config), NULL, + &(g_uart_config[SW_DEBUG_UART_BUS].buffer_config)); +} + +void sw_debug_uart_reset_baund(void) +{ + while (uapi_uart_has_pending_transmissions(SW_DEBUG_UART_BUS)) { } + uapi_uart_set_attr(SW_DEBUG_UART_BUS, &g_uart_config[SW_DEBUG_UART_BUS].line_config); +} +#endif + +void print_str(const char *str, ...) +{ + static uint8_t s[1024]; // 1024 means string max length. + va_list args; + int32_t str_len; + + if ((str == NULL) || (strlen(str) == 0)) { + return; + } + + va_start(args, str); + str_len = vsprintf_s((char *)s, sizeof(s), str, args); + va_end(args); + + if (str_len < 0) { + return; + } +#if defined(SW_RTT_DEBUG) + SEGGER_RTT_Write(0, (const char *)s, str_len); +#elif defined(SW_UART_DEBUG) + if (hal_uart_get_funcs(SW_DEBUG_UART_BUS) == NULL) { + return; + } + uapi_uart_write(SW_DEBUG_UART_BUS, (const void *)s, (uint32_t)str_len, 0); +#else +#endif +} + +void hal_uart_clear_pending(uart_bus_t uart) +{ + switch (uart) { + case UART_BUS_0: + int_clear_pending_irq(UART_0_IRQN); + break; + case UART_BUS_1: + int_clear_pending_irq(UART_1_IRQN); + break; + default: + break; + } +} + +#if defined(CONFIG_UART_SUPPORT_DMA) +uint8_t uart_port_get_dma_trans_dest_handshaking(uart_bus_t bus) +{ + switch (bus) { + case UART_BUS_0: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_L_TX; + case UART_BUS_1: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_H0_TX; + default: + return (uint8_t)HAL_DMA_HANDSHAKING_MAX_NUM; + } +} + +uint8_t uart_port_get_dma_trans_src_handshaking(uart_bus_t bus) +{ + switch (bus) { + case UART_BUS_0: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_L_RX; + case UART_BUS_1: + return (uint8_t)HAL_DMA_HANDSHAKING_UART_H0_RX; + default: + return (uint8_t)HAL_DMA_HANDSHAKING_MAX_NUM; + } +} +#endif /* CONFIG_UART_SUPPORT_DMA */ + +uint32_t uart_porting_lock(uart_bus_t bus) +{ +#ifndef BUILD_APPLICATION_SSB + if ((g_uart_config[bus].support_mutex == true) && (osKernelGetState() == osKernelRunning) && + (osal_in_interrupt() == 0)) { + return (uint32_t)osal_mutex_lock_timeout(&(g_uart_config[bus].uart_mutex), OSAL_MUTEX_WAIT_FOREVER); + } +#else + UNUSED(bus); +#endif + return ERRCODE_SUCC; +} + +void uart_porting_unlock(uart_bus_t bus, uint32_t irq_sts) +{ +#ifndef BUILD_APPLICATION_SSB + unused(irq_sts); + if ((g_uart_config[bus].support_mutex == true) && (osKernelGetState() == osKernelRunning) && + (osal_in_interrupt() == 0)) { + osal_mutex_unlock(&(g_uart_config[bus].uart_mutex)); + } +#else + UNUSED(bus); + UNUSED(irq_sts); +#endif +} + +void uart_save_reg(uart_bus_t bus) +{ + uint32_t base = uart_porting_base_addr_get(bus); + g_uart_recovery_reg[bus].uartilpr = readw(base + UARTILPR); + g_uart_recovery_reg[bus].uartibrd = readw(base + UARTIBRD); + g_uart_recovery_reg[bus].uartfbrd = readw(base + UARTFBRD); + g_uart_recovery_reg[bus].uartlcr_h = readw(base + UARTLCRH); + g_uart_recovery_reg[bus].uartcr = readw(base + UARTCR); + g_uart_recovery_reg[bus].uartifls = readw(base + UARTIFLS); + g_uart_recovery_reg[bus].uartimsc = readw(base + UARTIMSC); + g_uart_recovery_reg[bus].uartdmacr = readw(base + UARTDMACR); +} + +void uart_recovery_reg(uart_bus_t bus) +{ + uint16_t uart_bit = UARTBUS0; + if (bus == UART_BUS_0) { + uart_bit = UARTBUS0; + } else if (bus == UART_BUS_1) { + uart_bit = UARTBUS1; + } + reg16_clrbit(UARTRESET, uart_bit); + reg16_setbit(UARTRESET, uart_bit); + uint32_t base = uart_porting_base_addr_get(bus); + writew(base + UARTILPR, g_uart_recovery_reg[bus].uartilpr); + writew(base + UARTIBRD, g_uart_recovery_reg[bus].uartibrd); + writew(base + UARTFBRD, g_uart_recovery_reg[bus].uartfbrd); + writew(base + UARTLCRH, g_uart_recovery_reg[bus].uartlcr_h); + writew(base + UARTCR, g_uart_recovery_reg[bus].uartcr); + writew(base + UARTIFLS, g_uart_recovery_reg[bus].uartifls); + writew(base + UARTIMSC, g_uart_recovery_reg[bus].uartimsc); + writew(base + UARTDMACR, g_uart_recovery_reg[bus].uartdmacr); +} \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/lcd_config.c b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/lcd_config.c new file mode 100644 index 000000000..54950d78a --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/lcd_config.c @@ -0,0 +1,359 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Lcd driver configuration. + * Author: @CompanyNameTag + * Create: 2022-03-05 + */ + +#include +#include "common_def.h" +#include "lcd_config.h" + +#define LCD_EDO_454X454_SCREEN_ID 0xf00 +#define LCD_BOE_454X454_SCREEN_ID 0x500 +#define LCD_SH_240X296_SCREEN_ID 0x101 +#define LCD_BOE_194X368_SCREEN_ID 0x4a00 + +const combo_dev_cfg_t g_panel_454x454_60_config = { + .devno = 0, + .lane_id = {0, -1}, + .out_mode = OUT_MODE_DSI_CMD, + .out_format = OUT_FORMAT_RGB_24BIT, + .sync_info = { + .hsa_pixels = 10, // hsa 10 pixels + .hbp_pixels = 10, // hbp 10 pixels + .hact_pixels = 454, // hact 454 pixels + .hfp_pixels = 10, // hfp 10 pixels + .vsa_lines = 4, // vsa 4 lines + .vbp_lines = 12, // vbp 12 lines + .vact_lines = 454, // vact 454 lines + .vfp_lines = 10, // vfp 10 lines + }, + .phy_data_rate = 480, // 480Mbps + .pixel_clk = 20000, // 20000KHz +}; + +const combo_dev_cfg_t g_panel_240x296_60_config = { + .devno = 0, + .lane_id = {0, -1}, + .out_mode = OUT_MODE_DSI_CMD, + .out_format = OUT_FORMAT_RGB_24BIT, + .sync_info = { + .hsa_pixels = 4, // hsa 14 pixels hpw + .hbp_pixels = 11, // hbp 11 pixels HBP + .hact_pixels = 368, // hact 240 pixels HPX + .hfp_pixels = 14, // hfp 14 pixels hfp + .vsa_lines = 2, // vsa 2 lines vpw + .vbp_lines = 6, // vbp 6 lines vbp + .vact_lines = 448, // vact 296 lines vpx + .vfp_lines = 8, // vfp 8 lines vfp + }, + .phy_data_rate = 480, // 480Mbps + .pixel_clk = 20000, // 20000KHz +}; + +const combo_dev_cfg_t g_panel_194x368_qspi_config = { + .out_format = OUT_FORMAT_RGB_24BIT, + .sync_info = { + .hact_pixels = 194, // hact 368 pixels + .vact_lines = 368, // vact 368 lines + }, +}; + +/* display off sequence for common lcd */ +const lcd_cmd_sequ g_common_cmd_display_off[] = { + {1, 2, {0xfe, 0x00}, 0}, /* select default cmd page */ + {1, 1, {0x28}, 0}, /* display off */ + {1, 1, {0x10}, 120}, /* sleep in */ +}; + +/* sleep in sequence for common lcd */ +const lcd_cmd_sequ g_common_cmd_sleep_in[] = { + {1, 2, {0xfe, 0x00}, 0}, /* select default cmd page */ + {1, 1, {0x28}, 0}, /* display off */ + {1, 1, {0x10}, 120}, /* sleep in */ +}; + +/* sleep in sequence for common lcd */ +const lcd_cmd_sequ g_common_cmd_sleep_out[] = { + {1, 2, {0xfe, 0x00}, 0}, /* select default cmd page */ + {1, 1, {0x11}, 120}, /* sleep out */ + {1, 1, {0x29}, 0}, /* display on */ +}; + +/* idle in sequence for EDO and BOE 454*454 lcd */ +lcd_cmd_sequ g_common_cmd_idle_in[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x39}, 0}, +}; + +/* idle out sequence for EDO and BOE 454*454 lcd */ +const lcd_cmd_sequ g_common_cmd_idle_out[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x38}, 0}, +}; + +/* te on sequence for EDO and BOE 454*454 lcd */ +const lcd_cmd_sequ g_common_cmd_te_on[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x35}, 0}, +}; + +/* te off sequence for EDO and BOE 454*454 lcd */ +const lcd_cmd_sequ g_common_cmd_te_off[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 1, {0x34}, 0}, +}; + +/* set brightness sequence for EDO and BOE 454*454 lcd */ +lcd_cmd_sequ g_common_cmd_brightness[] = { + {1, 2, {0xfe, 0x00}, 0}, + {1, 2, {0x51, 0xff}, 0}, +}; + +/* init sequence for EDO 454*454 lcd */ +const lcd_cmd_sequ g_edo_454x454_screen_init_on[] = { + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x30, 0x43}, 0}, /* set LCD frequency to 15HZ */ + {1, 2, {0xfe, 0x00}, 0}, + {1, 2, {0x3a, 0x77}, 0}, + {1, 2, {0x53, 0x20}, 0}, + {1, 2, {0x51, 0xff}, 0}, + {0, 5, {0x2a, 0x00, 0x0e, 0x01, 0xd3}, 0}, + {0, 5, {0x2b, 0x00, 0x00, 0x01, 0xc5}, 0}, + {1, 3, {0x44, 0x01, 0xc5}, 0}, + {1, 2, {0x35, 0x00}, 0}, + {1, 1, {0x11}, 120}, + {1, 1, {0x29}, 0}, +}; + +/* init sequence for BOE 454*454 lcd */ +const lcd_cmd_sequ g_boe_454x454_screen_init_on[] = { + {1, 2, {0xfe, 0x0d}, 0}, + {1, 2, {0x01, 0x00}, 0}, + {1, 2, {0x03, 0x00}, 0}, + {1, 2, {0x1b, 0x00}, 0}, + {1, 2, {0x1d, 0x00}, 0}, + {1, 2, {0x37, 0x00}, 0}, + {1, 2, {0x39, 0x00}, 0}, + {1, 2, {0x52, 0x58}, 0}, + {1, 2, {0x53, 0x00}, 0}, + + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x72, 0x05}, 0}, + {1, 2, {0x73, 0x16}, 0}, + {1, 2, {0x74, 0x0c}, 0}, + + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x18, 0x55}, 0}, + {1, 2, {0xc5, 0x10}, 0}, + {1, 2, {0x72, 0x0e}, 0}, + {1, 2, {0x73, 0x1c}, 0}, + + {1, 2, {0xfe, 0x07}, 0}, + {1, 2, {0x15, 0x04}, 0}, + {1, 2, {0xfe, 0x01}, 0}, + {1, 2, {0x0a, 0xf8}, 0}, + + {1, 2, {0xfe, 0x00}, 0}, + {1, 2, {0x51, 0xff}, 0}, + {1, 2, {0x35, 0x00}, 0}, + {0, 5, {0x2a, 0x00, 0x0c, 0x01, 0xd1}, 0}, + {0, 5, {0x2b, 0x00, 0x00, 0x01, 0xc5}, 0}, + {1, 2, {0x53, 0x20}, 0}, + {1, 1, {0x11}, 120}, + {1, 1, {0x29}, 0}, +}; + +const lcd_cmd_sequ g_sh_240x296_screen_init_on[] = { + {1, 1, {0x11}, 5}, + {1, 5, {0x2a, 0x00, 0x00, 0x01, 0x6f}, 1}, + {1, 5, {0x2b, 0x00, 0x00, 0x01, 0xbf}, 1}, + {1, 3, {0x44, 0x01, 0xbf}, 1}, + {1, 2, {0x35, 0x00}, 1}, + {1, 2, {0x3a, 0x77}, 1}, + {1, 2, {0x53, 0x20}, 80}, + {1, 1, {0x29}, 0}, +}; + +const lcd_cmd_sequ g_boe_194x368_screen_init_on[] = { + {0, 2, {0xfe, 0x00}, 0}, + {0, 3, {0x44, 0x00, 0xB7}, 0}, + {0, 2, {0x3a, 0x77}, 0}, + {0, 2, {0x51, 0x80}, 0}, + {0, 2, {0x35, 0x0}, 0}, + {0, 5, {0x2a, 0x00, 0x00, 0x00, 0xc1}, 0}, + {0, 1, {0x11}, 120}, + {0, 1, {0x29}, 100}, + {0, 1, {0x39}, 0}, +}; + +const lcd_cmds_sequ g_display_off_cmds = { + .cmd = g_common_cmd_display_off, + .cmd_cnt = array_size(g_common_cmd_display_off), +}; + +const lcd_cmds_sequ g_idle_in_cmds = { + .cmd = g_common_cmd_idle_in, + .cmd_cnt = array_size(g_common_cmd_idle_in), +}; + +const lcd_cmds_sequ g_idle_out_cmds = { + .cmd = g_common_cmd_idle_out, + .cmd_cnt = array_size(g_common_cmd_idle_out), +}; + +const lcd_cmds_sequ g_te_on_cmds = { + .cmd = g_common_cmd_te_on, + .cmd_cnt = array_size(g_common_cmd_te_on), +}; + +const lcd_cmds_sequ g_te_off_cmds = { + .cmd = g_common_cmd_te_off, + .cmd_cnt = array_size(g_common_cmd_te_off), +}; + +const lcd_cmds_sequ g_brightness_cmds = { + .cmd = g_common_cmd_brightness, + .cmd_cnt = array_size(g_common_cmd_brightness), +}; + +const lcd_cmds_sequ g_edo_454x454_screen_init_on_cmds = { + .cmd = g_edo_454x454_screen_init_on, + .cmd_cnt = array_size(g_edo_454x454_screen_init_on), +}; + +const lcd_cmds_sequ g_boe_454x454_screen_init_on_cmds = { + .cmd = g_boe_454x454_screen_init_on, + .cmd_cnt = array_size(g_boe_454x454_screen_init_on), +}; + +const lcd_cmds_sequ g_sh_240x296_screen_init_on_cmds = { + .cmd = g_sh_240x296_screen_init_on, + .cmd_cnt = array_size(g_sh_240x296_screen_init_on), +}; + +const lcd_cmds_sequ g_boe_194x368_screen_init_on_cmds = { + .cmd = g_boe_194x368_screen_init_on, + .cmd_cnt = array_size(g_boe_194x368_screen_init_on), +}; + +const lcd_cmds_sequ g_sleep_in_cmds = { + .cmd = g_common_cmd_sleep_in, + .cmd_cnt = array_size(g_common_cmd_sleep_in), +}; + +const lcd_cmds_sequ g_sleep_out_cmds = { + .cmd = g_common_cmd_sleep_out, + .cmd_cnt = array_size(g_common_cmd_sleep_out), +}; + +const lcd_drv_cfg g_lcd_driver_ops[] = { + { + .bus_type = BUS_DISPLAY_MIPI, + .bus_cfg = &g_panel_454x454_60_config, + .x_start = 0xe, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_EDO_454X454_SCREEN_ID, + .display_on_cmds = &g_edo_454x454_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0x04, + .lcd_id_info.read_len = 3, + }, + { + .bus_type = BUS_DISPLAY_MIPI, + .bus_cfg = &g_panel_454x454_60_config, + .x_start = 0xc, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_BOE_454X454_SCREEN_ID, + .display_on_cmds = &g_boe_454x454_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0x04, + .lcd_id_info.read_len = 3, + }, + { + .bus_type = BUS_DISPLAY_MIPI, + .bus_cfg = &g_panel_240x296_60_config, + .x_start = 0, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_SH_240X296_SCREEN_ID, + .display_on_cmds = &g_sh_240x296_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0xda, + .lcd_id_info.read_len = 3, + }, + { + .bus_type = BUS_DISPLAY_QSPI, + .bus_cfg = &g_panel_194x368_qspi_config, + .x_start = 0, + .y_start = 0, + .fps = 60, + .lcd_id = LCD_BOE_194X368_SCREEN_ID, + .display_on_cmds = &g_boe_194x368_screen_init_on_cmds, + .display_off_cmds = &g_display_off_cmds, + .enter_idle_cmds = &g_idle_in_cmds, + .exit_idle_cmds = &g_idle_out_cmds, + .te_on_cmds = &g_te_on_cmds, + .te_off_cmds = &g_te_off_cmds, + .set_brightnes_cmds = &g_brightness_cmds, + .sleep_in_cmds = &g_sleep_in_cmds, + .sleep_out_cmds = &g_sleep_out_cmds, + .lcd_id_info.reg_addr = 0x04, + .lcd_id_info.read_len = 3, + } +}; + +lcd_drv_cfg *lcd_get_driver_ops(void) +{ + return g_lcd_driver_ops; +} + +uint32_t lcd_get_ops_num(void) +{ + return array_size(g_lcd_driver_ops); +} + +combo_dev_cfg_t *lcd_get_bus_escape_config(void) +{ + return g_lcd_driver_ops[0].bus_cfg; +} + +lcd_drv_cfg *lcd_get_driver_config(uint32_t id) +{ + uint32_t i; + if (id == 0) { + return NULL; + } + + for (i = 0; i < array_size(g_lcd_driver_ops); i++) { + if (g_lcd_driver_ops[i].lcd_id == id) { + return &(g_lcd_driver_ops[i]); + } + } + + return NULL; +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/lcd_private.c b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/lcd_private.c new file mode 100644 index 000000000..039f45c48 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/lcd_private.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Lcd private interface. + * Author: @CompanyNameTag + * Create: 2022-03-05 + */ + +#include "lcd_private.h" +#include "tcxo.h" +#include "chip_io.h" +#include "platform_core.h" +#include "gpio.h" +#include "pinctrl_porting.h" +#include "product.h" + +static void lcd_drv_power_on(void) +{ +#ifndef QSPI_DISPLAY + uapi_gpio_set_dir(VCI_LCD_GPIO, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(VCI_LCD_GPIO, GPIO_LEVEL_HIGH); +#endif + uapi_gpio_set_dir(RESET_LCD_GPIO, GPIO_DIRECTION_OUTPUT); + + uapi_gpio_set_val(RESET_LCD_GPIO, GPIO_LEVEL_LOW); + uapi_tcxo_delay_ms(10); /* delay 10 ms */ + + uapi_gpio_set_val(RESET_LCD_GPIO, GPIO_LEVEL_HIGH); + uapi_tcxo_delay_ms(10); /* delay 10 ms */ +} + +static void lcd_drv_power_off(void) +{ + uapi_gpio_set_val(RESET_LCD_GPIO, GPIO_LEVEL_LOW); + uapi_gpio_set_dir(RESET_LCD_GPIO, GPIO_DIRECTION_INPUT); +#ifndef QSPI_DISPLAY + uapi_gpio_set_val(VCI_LCD_GPIO, GPIO_LEVEL_LOW); + uapi_gpio_set_dir(VCI_LCD_GPIO, GPIO_DIRECTION_INPUT); +#endif + uapi_tcxo_delay_ms(10); /* delay 10 ms */ +} + +static lcd_drv_private g_lcd_private_api = { + .power_on = lcd_drv_power_on, + .power_off = lcd_drv_power_off, +}; + +lcd_drv_private *lcd_drv_get_private_api(void) +{ + return &g_lcd_private_api; +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/soc_lcd_api.c b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/soc_lcd_api.c new file mode 100644 index 000000000..b535f5555 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/lcd/soc_lcd_api.c @@ -0,0 +1,766 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Lcd driver. + * Author: @CompanyNameTag + * Create: 2022-03-05 + */ + +#include "soc_lcd_api.h" +#include +#include "soc_errno.h" +#include "soc_osal.h" +#include "soc_mipi_tx.h" +#include "lcd_config.h" +#include "lcd_bus.h" +#include "lcd_mipi.h" +#include "lcd_qspi.h" +#include "lcd_common.h" +#include "lcd_private.h" +#include "pinctrl_porting.h" + +typedef struct lcd_attr { + bool info_register; /* 注册指定屏幕组件标志 */ + bool is_inited; /* LCD组件初始化标志 */ + lcd_type screen_type; /* LCD屏类型 */ + uint32_t lcd_id; /* LCD ID号 */ + lcd_drv_cfg *lcd_cfg; /* LCD参数 */ + uint8_t brightness; /* 显示亮度参数 */ + ext_lcd_status status; /* LCD状态标志 */ + osal_mutex lcd_mutex; /* LCD驱动多线程调用保护信号量 */ + lcd_bus_api *bus_api; /* 总线接口 */ + lcd_drv_common *common_api; /* LCD公共接口 */ + lcd_drv_private *private_api; /* LCD差异化接口 */ +} lcd_attr; + +lcd_attr g_lcd_info = {0}; +volatile bool g_idle_before_sleep = false; /* false: normal display, true: idle mode */ +static bool g_lcd_on_flag = false; + +bool lcd_get_status(void) +{ + return g_lcd_on_flag; +} + +void lcd_set_status(bool lcd_on) +{ + g_lcd_on_flag = lcd_on; +} + +static ext_errno lcd_lock_init(void) +{ + ext_errno ret; + if (g_lcd_info.lcd_mutex.mutex != NULL) { + return EXT_ERR_SUCCESS; + } + + ret = osal_mutex_init(&(g_lcd_info.lcd_mutex)); + if (ret != EXT_ERR_SUCCESS) { + g_lcd_info.lcd_mutex.mutex = NULL; + return ret; + } + if (g_lcd_info.lcd_mutex.mutex == NULL) { + return EXT_ERR_LCD_MUTEX_INIT_FAIL; + } + return EXT_ERR_SUCCESS; +} + +static void lcd_lock_deinit(void) +{ + if (g_lcd_info.lcd_mutex.mutex != NULL) { + osal_mutex_destroy(&(g_lcd_info.lcd_mutex)); + } + + g_lcd_info.lcd_mutex.mutex = NULL; +} + +static void lcd_lock(void) +{ + if (g_lcd_info.lcd_mutex.mutex == NULL) { + return; + } + osal_mutex_lock(&(g_lcd_info.lcd_mutex)); +} + +static void lcd_unlock(void) +{ + if (g_lcd_info.lcd_mutex.mutex == NULL) { + return; + } + osal_mutex_unlock(&(g_lcd_info.lcd_mutex)); +} + +static void lcd_set_display_info(void) +{ + if (g_lcd_info.bus_api->bus_register_panel_info != NULL) { + g_lcd_info.bus_api->bus_register_panel_info(g_lcd_info.lcd_cfg->x_start, g_lcd_info.lcd_cfg->y_start, + g_lcd_info.lcd_cfg->fps); + } +} + +static ext_errno lcd_auto_adapt_init_prepare(void) +{ + ext_errno ret; + combo_dev_cfg_t *escape_config = lcd_get_bus_escape_config(); + + /* init with default parameter */ + ret = g_lcd_info.bus_api->bus_init(escape_config); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("default bus_init fail, ret = %X\r\n", ret); + return ret; + } + + ret = g_lcd_info.common_api->get_chip_id(&g_lcd_info.lcd_id); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("get_chip_id fail, ret = %X\r\n", ret); + } + + if (g_lcd_info.bus_api->bus_deinit() != EXT_ERR_SUCCESS) { + lcd_err("bus deinit fail\r\n"); + } + + return ret; +} + +static ext_errno lcd_assigned_id_check(void) +{ + if (g_lcd_info.common_api->chip_id_check == NULL) { + return EXT_ERR_LCD_INVALID_NULL_POINTER; + } + + return g_lcd_info.common_api->chip_id_check(); +} + +static ext_errno lcd_get_ops(void) +{ + ext_errno ret = 0; + g_lcd_info.bus_api = lcd_get_bus_api(); + g_lcd_info.common_api = lcd_drv_get_common_api(); + g_lcd_info.private_api = lcd_drv_get_private_api(); + + if (g_lcd_info.bus_api == NULL || g_lcd_info.common_api == NULL || g_lcd_info.private_api == NULL) { + return EXT_ERR_LCD_GET_ATTR_FAIL; + } + + if (g_lcd_info.private_api->power_on == NULL) { + return EXT_ERR_LCD_GET_ATTR_FAIL; + } + g_lcd_info.private_api->power_on(); + + if (!g_lcd_info.info_register) { + ret = lcd_auto_adapt_init_prepare(); + if (ret != EXT_ERR_SUCCESS) { + goto fail; + } + } + + g_lcd_info.lcd_cfg = g_lcd_info.common_api->get_lcd_config(); + if (g_lcd_info.lcd_cfg == NULL) { + lcd_err("lcd_cfg empty!\r\n"); + goto fail; + } + ret = g_lcd_info.bus_api->bus_init(g_lcd_info.lcd_cfg->bus_cfg); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_init fail, ret = %X\r\n", ret); + return ret; + } + + if (g_lcd_info.info_register) { + ret = lcd_assigned_id_check(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("chip id check error, ret = 0x%x\r\n", ret); + g_lcd_info.bus_api->bus_deinit(); + goto fail; + } + } + + g_lcd_info.brightness = DEFAULT_BRIGHTNESS; + + return EXT_ERR_SUCCESS; +fail: + + if (g_lcd_info.private_api->power_off != NULL) { + g_lcd_info.private_api->power_off(); + } + g_lcd_info.bus_api = NULL; + g_lcd_info.common_api = NULL; + g_lcd_info.private_api = NULL; + return ret; +} + +ext_lcd_status uapi_lcd_get_status(void) +{ + return g_lcd_info.status; +} + +bool uapi_is_lcd_connect(void) +{ + return g_lcd_info.is_inited; +} + +static ext_errno lcd_display_on(void) +{ + ext_errno ret; + uint32_t retry_count = 3; + lcd_lock(); + + for (; retry_count > 0; retry_count--) { + ret = g_lcd_info.common_api->display_on(g_lcd_info.brightness); + if (ret == EXT_ERR_SUCCESS) { + ret = g_lcd_info.bus_api->bus_enable(); + if (ret == EXT_ERR_SUCCESS) { + break; + } + } + + g_lcd_info.private_api->power_off(); + g_lcd_info.private_api->power_on(); + + g_lcd_info.bus_api->bus_deinit(); + ret = g_lcd_info.bus_api->bus_init(g_lcd_info.lcd_cfg->bus_cfg); + if (ret != EXT_ERR_SUCCESS) { + g_lcd_info.private_api->power_off(); + continue; + } + } + if (retry_count > 0) { + g_lcd_info.status.disp_status = LCD_NORMAL_DISPLAY; + g_lcd_info.status.te_status = LCD_TE_ON; + } + + lcd_unlock(); + + return ret; +} + +ext_errno uapi_lcd_display_on(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_NORMAL_DISPLAY) { + return EXT_ERR_SUCCESS; + } + + ret = lcd_display_on(); + + return ret; +} + +ext_errno uapi_lcd_display_off(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_DISPLAY_OFF) { + return EXT_ERR_SUCCESS; + } + + ret = g_lcd_info.common_api->display_off(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("display_off fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + ret = g_lcd_info.bus_api->bus_disable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_disable fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + + g_lcd_info.status.disp_status = LCD_DISPLAY_OFF; + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_enter_sleep_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_SLEEP_MODE) { + return EXT_ERR_SUCCESS; + } else if (g_lcd_info.status.disp_status == LCD_DISPLAY_OFF) { + return EXT_ERR_LCD_NOT_SUPPORT_OFF_TO_SLEEP; + } + + if (g_lcd_info.status.disp_status == LCD_IDLE_MODE) { + g_idle_before_sleep = true; + } else { + g_idle_before_sleep = false; + } + + ret = g_lcd_info.common_api->enter_sleep_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("enter sleep mode fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + ret = g_lcd_info.bus_api->bus_disable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_disable fail, ret = %X\r\n", ret); + return ret; + } + g_lcd_info.status.disp_status = LCD_SLEEP_MODE; + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_exit_sleep_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status != LCD_SLEEP_MODE) { + return EXT_ERR_LCD_NOT_IN_SLEEP_MODE; + } + + ret = g_lcd_info.common_api->exit_sleep_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("exit sleep mode fail, ret = %X\r\n", ret); + return ret; + } + + lcd_lock(); + ret = g_lcd_info.bus_api->bus_enable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("enable bus fail when exit sleep, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + + if (g_idle_before_sleep) { + g_lcd_info.status.disp_status = LCD_IDLE_MODE; + } else { + g_lcd_info.status.disp_status = LCD_NORMAL_DISPLAY; + } + + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_enter_idle_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status == LCD_IDLE_MODE) { + return EXT_ERR_SUCCESS; + } + if (g_lcd_info.status.disp_status != LCD_NORMAL_DISPLAY) { + return EXT_ERR_LCD_NOT_SUPPORT_CUR_TO_IDLE; + } + + lcd_lock(); + ret = g_lcd_info.common_api->enter_idle_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("enter_idle_mode fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.disp_status = LCD_IDLE_MODE; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_exit_idle_mode(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status != LCD_IDLE_MODE) { + return EXT_ERR_LCD_NOT_IN_IDLE_MODE; + } + + lcd_lock(); + ret = g_lcd_info.common_api->exit_idle_mode(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("exit_idle_mode fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.disp_status = LCD_NORMAL_DISPLAY; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +static ext_errno lcd_te_param_check(void) +{ + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.screen_type == VIDEO_LCD) { + return EXT_ERR_LCD_VIDEO_SCREEN_NOT_SUPPORT_TE; + } + if (g_lcd_info.status.disp_status != LCD_NORMAL_DISPLAY && g_lcd_info.status.disp_status != LCD_IDLE_MODE) { + return EXT_ERR_LCD_INVALID_TE_ON_MODE; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_te_on(void) +{ + ext_errno ret = lcd_te_param_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + if (g_lcd_info.status.te_status == LCD_TE_ON) { + return EXT_ERR_SUCCESS; + } + + lcd_lock(); + ret = g_lcd_info.common_api->te_on(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("te_on fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.te_status = LCD_TE_ON; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_te_off(void) +{ + ext_errno ret = lcd_te_param_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + if (g_lcd_info.status.te_status == LCD_TE_OFF) { + return EXT_ERR_SUCCESS; + } + + lcd_lock(); + ret = g_lcd_info.common_api->te_off(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("te_off fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.status.te_status = LCD_TE_OFF; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_set_brightness(uint16_t value) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status > LCD_IDLE_MODE) { + return EXT_ERR_LCD_IN_DISPLAY_OFF_STATE; + } + + lcd_lock(); + ret = g_lcd_info.common_api->set_brightness(value); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("set_brightness fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + g_lcd_info.brightness = (uint8_t)value; + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_get_brightness(uint16_t *value) +{ + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + *value = g_lcd_info.brightness; + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_write_reg(lcd_cmd_sequ *cmds, uint32_t cmd_count) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + + if (cmds == NULL || cmd_count == 0) { + return EXT_ERR_LCD_INVALID_WRITE_CMD; + } + lcd_lock(); + ret = g_lcd_info.common_api->write(cmds, cmd_count); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("write reg fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_read_reg(uint8_t cmd, uint8_t *buff, uint8_t buff_len) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + if (g_lcd_info.status.disp_status > LCD_SLEEP_MODE) { + return EXT_ERR_LCD_IN_DISPLAY_OFF_STATE; + } + if (buff == NULL || buff_len == 0) { + return EXT_ERR_LCD_INVALID_READ_CMD; + } + lcd_lock(); + ret = g_lcd_info.common_api->read(cmd, buff, buff_len); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("read reg fail, ret = %X\r\n", ret); + lcd_unlock(); + return ret; + } + lcd_unlock(); + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_init(void) +{ + if (g_lcd_info.is_inited) { + return EXT_ERR_SUCCESS; + } + + ext_errno ret = lcd_get_ops(); + if (ret != EXT_ERR_SUCCESS && ret != EXT_ERR_MIPI_ALREADY_INIT) { + lcd_err("lcd_get_ops fail, ret = %X\r\n", ret); + return ret; + } + + ret = lcd_lock_init(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("lcd_lock_init fail, ret = %X\r\n", ret); + return ret; + } + + lcd_set_display_info(); + + ret = lcd_display_on(); + if (ret != EXT_ERR_SUCCESS) { + g_lcd_info.bus_api->bus_deinit(); + lcd_lock_deinit(); + lcd_err("lcd_display_on fail, ret = %X\r\n", ret); + return ret; + } + + g_lcd_info.is_inited = true; + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_deinit(void) +{ + ext_errno ret; + if (!g_lcd_info.is_inited) { + return EXT_ERR_SUCCESS; + } + + if (g_lcd_info.status.disp_status != LCD_DISPLAY_OFF) { + ret = g_lcd_info.common_api->display_off(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("display_off fail, ret = %X\r\n", ret); + } + + ret = g_lcd_info.bus_api->bus_disable(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_disable fail, ret = %X\r\n", ret); + } + } + lcd_lock(); + ret = g_lcd_info.bus_api->bus_deinit(); + if (ret != EXT_ERR_SUCCESS) { + lcd_err("bus_deinit fail, ret = %X\r\n", ret); + } + g_lcd_info.private_api->power_off(); + + g_lcd_info.status.disp_status = LCD_DISPLAY_OFF; + g_lcd_info.is_inited = false; + lcd_unlock(); + + lcd_lock_deinit(); + + return EXT_ERR_SUCCESS; +} + +static ext_errno lcd_lp_ctrl_check(void) +{ + if (!g_lcd_info.is_inited) { + return EXT_ERR_LCD_NOT_INIT; + } + + if (g_lcd_info.bus_api == NULL) { + return EXT_ERR_LCD_GET_ATTR_FAIL; + } + + if (g_lcd_info.bus_api->bus_lp_ctrl == NULL) { + return EXT_ERR_LCD_NOT_SUPPORT_FUNC; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_enter_sdlp(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_ENTER_SDLP); +} + +ext_errno uapi_lcd_exit_sdlp(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_EXIT_SDLP); +} + +ext_errno uapi_lcd_exit_ulps(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_EXIT_ULPS); +} + +ext_errno uapi_lcd_clear_exit_ulps(void) +{ + ext_errno ret; + + ret = lcd_lp_ctrl_check(); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + return g_lcd_info.bus_api->bus_lp_ctrl(LP_CTRL_CLEAR_EXIT_ULPS); +} + +static void lcd_register_qspi_bus(void) +{ + lcd_bus_api qspi_bus_api = {0}; + + qspi_bus_api.bus_init = lcd_qspi_init; + qspi_bus_api.bus_deinit = lcd_qspi_deinit; + qspi_bus_api.bus_enable = lcd_qspi_enable; + qspi_bus_api.bus_disable = lcd_qspi_disable; + qspi_bus_api.bus_write_cmd = lcd_qspi_write_cmd; + qspi_bus_api.bus_read_cmd = lcd_qspi_read_cmd; + qspi_bus_api.bus_send_frame = lcd_qspi_send_frame; + qspi_bus_api.bus_suspend = lcd_qspi_suspend; + qspi_bus_api.bus_resume = lcd_qspi_resume; + qspi_bus_api.bus_register_te_isr = lcd_qspi_register_te_isr; + + lcd_bus_register_api(&qspi_bus_api, BUS_DISPLAY_QSPI); +} + +static void lcd_register_mipi_bus(void) +{ + lcd_bus_api mipi_bus_api = {0}; + + mipi_bus_api.bus_init = mipi_bus_init, + mipi_bus_api.bus_deinit = mipi_bus_deinit, + mipi_bus_api.bus_enable = mipi_bus_enable, + mipi_bus_api.bus_disable = mipi_bus_disable, + mipi_bus_api.bus_write_cmd = mipi_bus_write, + mipi_bus_api.bus_read_cmd = mipi_bus_read, + mipi_bus_api.bus_lp_ctrl = mipi_bus_lp_ctrl, + mipi_bus_api.bus_register_panel_info = mipi_bus_register_panel_info, + mipi_bus_api.bus_get_panel_timing = mipi_bus_get_panel_timing, + mipi_bus_api.bus_get_partial_display_cmd = mipi_bus_get_partial_display_cmd, + mipi_bus_api.bus_update_panel = mipi_bus_update_panel, + mipi_bus_api.bus_refresh_area = mipi_bus_refresh_area, + mipi_bus_api.bus_suspend = mipi_bus_suspend, + mipi_bus_api.bus_resume = mipi_bus_resume, + lcd_bus_register_api(&mipi_bus_api, BUS_DISPLAY_MIPI); +} + +static ext_errno lcd_info_check(const lcd_drv_cfg *info) +{ + if (info == NULL) { + return EXT_ERR_LCD_INVALID_NULL_POINTER; + } + + if ((info->bus_type != BUS_DISPLAY_MIPI) && (info->bus_type != BUS_DISPLAY_QSPI)) { + return EXT_ERR_LCD_INVALID_SCREEN_OPS; + } + + if (info->lcd_id == 0) { + return EXT_ERR_LCD_INVALID_CHIP_ID; + } + + if ((info->display_on_cmds == NULL) || (info->display_off_cmds == NULL)) { + return EXT_ERR_LCD_INVALID_WRITE_CMD; + } + + if (info->lcd_id_info.read_len == 0) { + return EXT_ERR_LCD_INVALID_READ_CMD; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno uapi_lcd_info_register(lcd_drv_cfg *info) +{ + ext_errno ret; + + ret = lcd_info_check(info); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + if (g_lcd_info.is_inited) { + return EXT_ERR_LCD_INIT_ALREADY; + } + + if (g_lcd_info.common_api == NULL) { + g_lcd_info.common_api = lcd_drv_get_common_api(); + } + + if (g_lcd_info.common_api->set_lcd_config == NULL) { + return EXT_ERR_LCD_NOT_SUPPORT_FUNC; + } + + ret = g_lcd_info.common_api->set_lcd_config(info); + if (ret != EXT_ERR_SUCCESS) { + return ret; + } + + if (info->bus_type == BUS_DISPLAY_MIPI) { + lcd_register_mipi_bus(); + } else { + lcd_register_qspi_bus(); + } + + g_lcd_info.info_register = true; + + return EXT_ERR_SUCCESS; +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/touch/CMakeLists.txt b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/touch/CMakeLists.txt new file mode 100644 index 000000000..6782d9cc1 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/touch/CMakeLists.txt @@ -0,0 +1,80 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. +#=============================================================================== +set(COMPONENT_NAME "touch") + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_drv.c + ${CMAKE_CURRENT_SOURCE_DIR}/touch_screen_queue1.c +) + +if("TPTYPE_TMA525B" IN_LIST DEFINES) +set(SOURCES ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch/tma525b_ctrl.c + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch/tma525b_drv1.c + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch/tma525b_touch1.c +) +elseif("TPTYPE_ZTW523" IN_LIST DEFINES) +set(SOURCES ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_ctrl.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_drv1.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_touch1.c +) +else() +set(SOURCES ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_ctrl.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_drv1.c + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch/ztw523_touch1.c +) +endif() + +if("TPTYPE_TMA525B" IN_LIST DEFINES) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/tma525b_touch + ${ROOT_DIR}/middleware/services/gui/hal/input/include +) +elseif("TPTYPE_ZTW523" IN_LIST DEFINES) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch + ${ROOT_DIR}/middleware/services/gui/hal/input/include +) +else() +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/ztw523_touch + ${ROOT_DIR}/middleware/services/gui/hal/input/include +) +endif() + +set(PRIVATE_HEADER +) + +set(PRIVATE_DEFINES +) + +set(PUBLIC_DEFINES +) + +# use this when you want to add ccflags like -include xxx +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -Wno-incompatible-function-pointer-types + -Wno-unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +build_component() + +install_sdk(${CMAKE_CURRENT_SOURCE_DIR} "*") diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c new file mode 100644 index 000000000..56ca1561b --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c @@ -0,0 +1,469 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: touch screen driver. + * Author: @CompanyNameTag + * Create: 2022-04-12 + */ + +#include "touch_screen_drv.h" +#include "tcxo.h" +#include "i2c.h" +#include "common_def.h" +#include "soc_osal.h" +#include "touch_screen_def.h" +#include "input_app.h" +#if defined(TPTYPE_TMA525B) +#include "tma525b_drv1.h" +#include "tma525b_ctrl.h" +#elif defined(TPTYPE_ZTW523) +#include "ztw523_drv1.h" +#include "ztw523_ctrl.h" +#else +#include "ztw523_drv1.h" +#include "ztw523_ctrl.h" +#endif + +#if defined(TPTYPE_TMA525B) +#define TOUCH_I2C_BUS TMA525B_I2C_BUS +#define TOUCH_INT_GPIO TMA525B_INT_GPIO +#define TOUCH_RESET_GPIO TMA525B_RESET_GPIO +#elif defined(TPTYPE_ZTW523) +#define TOUCH_I2C_BUS ZTW523_I2C_BUS +#define TOUCH_INT_GPIO ZTW523_INT_GPIO +#define TOUCH_RESET_GPIO ZTW523_RESET_GPIO +#else +#define TOUCH_I2C_BUS ZTW523_I2C_BUS +#define TOUCH_INT_GPIO ZTW523_INT_GPIO +#define TOUCH_RESET_GPIO ZTW523_RESET_GPIO +#endif + +#define TOUCH_SCREEN_DEV_NAME_LEN 16 +#define TOUCH_SCREEN_DEVNAME "input/event" +#define TOUCH_SCREEN_DYNAMIC_MINOR 65 +#define TOUCH_SCREEN_CMDID_MAX 16 + +#define TOUCH_SCREEN_TASK_PRIO 5 +#define TOUCH_SCREEN_TASK_SIZE 0x800 +#define TOUCH_SCREEN_QUEUE_MAX_SIZE 60 +#define TOUCH_SCREEN_READY_EVENT (1 << 0) + +struct ts_driver_data g_touch_drv = {0}; +struct ts_driver_data *g_attr = NULL; + +report_event_cb g_report_event_cb = NULL; + +#if defined(SUPPORT_POWER_MANAGER) +event_callback_func g_power_manager_cb = NULL; +#endif + +static struct ts_driver_data *touch_screen_get_driver_data(void) +{ + return &g_touch_drv; +} + +static uint32_t touch_screen_get_state(struct ts_driver_data *tsdd) +{ + if (tsdd != NULL && tsdd->queue != NULL) { + return (uint32_t)ts_queue_is_empty(tsdd->queue); + } + + if (tsdd == NULL) { + tp_err("tsdd is null!"); + return EXT_ERR_FAILURE; + } + if (tsdd->queue == NULL) { + tp_err("tsdd queue is null!"); + } + + return EXT_ERR_FAILURE; +} + +static void convert_touch_info(input_dev_data_t* data, input_event_info* touch_info) +{ + data->x = (int16_t)touch_info->tp_event_info.x_axis[0]; + data->y = (int16_t)touch_info->tp_event_info.y_axis[0]; + data->type = INDEV_TYPE_TOUCH; + data->timestamp = (uint32_t)touch_info->tv_usec; + if ((touch_info->tp_event == MC_TP_PRESS) || (touch_info->tp_event == MC_TP_MOVE)) { + data->state = INDEV_STATE_PRESS; + } else if (touch_info->tp_event == MC_TP_RELEASE) { + data->state = INDEV_STATE_RELEASE; + } else { + data->state = INDEV_STATE_UNKNOWN; + } +} + +static void report_or_enqueue_event(input_event_info* touch_info, struct ts_driver_data *tsdd) +{ + if (g_report_event_cb != NULL) { + input_dev_data_t data; + convert_touch_info(&data, touch_info); + if (data.state == INDEV_STATE_UNKNOWN) { + return; + } + g_report_event_cb(&data); + } else { + int32_t ret = ts_en_queue(tsdd->queue, touch_info); + if (ret != EXT_ERR_SUCCESS) { + tp_err("Failed to enqueue ts queue! ret=0x%x", ret); + } + } +} +#if defined(SUPPORT_POWER_MANAGER) +static void report_event_to_power_manager(input_event_info *touch_info) +{ + if (g_power_manager_cb != NULL) { + g_power_manager_cb(touch_info->tp_event, 0); + } + return; +} + +uint32_t ts_register_power_manager_cb(event_callback_func callback) +{ + if (g_power_manager_cb != NULL) { + return EXT_ERR_FAILURE; + } + g_power_manager_cb = callback; + return EXT_ERR_SUCCESS; +} +#endif +ext_errno touch_info_process(void) +{ + struct ts_driver_data *tsdd = touch_screen_get_driver_data(); + input_event_info touch_info; + int32_t ret = 0; + + if (tsdd->touch_api->touch_get_tpinfo != NULL) { + ret = tsdd->touch_api->touch_get_tpinfo((uint8_t *)(&touch_info), sizeof(input_event_info)); + if (ret != EXT_ERR_SUCCESS) { + tp_err("get touch info fail! ret=0x%x", ret); + return ret; + } + + report_or_enqueue_event(&touch_info, tsdd); +#if defined(SUPPORT_POWER_MANAGER) + report_event_to_power_manager(&touch_info); +#endif + } + + return EXT_ERR_SUCCESS; +} + +static void ts_callback_func(void) +{ + ext_errno ret; + if (g_attr != NULL) { + common_notify_mail_t mail = {0}; + mail.comm.app = APP_TOUCH; + ret = osal_msg_queue_write_copy(get_app_queue_id(), (void *)&mail, + sizeof(common_notify_mail_t), 0); + if (ret != OSAL_SUCCESS) { + tp_err("touch app msg send failed! err=0x%x! \r\n", ret); + } + } +} + +static ext_errno ts_register_callback(struct ts_driver_data *attr) +{ + ext_errno ret = EXT_ERR_FAILURE; + g_attr = attr; + + if (attr->touch_api->register_callback != NULL) { + ret = attr->touch_api->register_callback(attr->private_data, ts_callback_func); + if (ret != EXT_ERR_SUCCESS) { + tp_err("register touch screen callback fail! ret=0x%x", ret); + return ret; + } + } else { + tp_err("touch screen callback register func is empty!"); + } + + return ret; +} + +static ext_errno ts_unregister_callback(struct ts_driver_data *attr) +{ + ext_errno ret = EXT_ERR_FAILURE; + + if (attr->touch_api->unregister_callback != NULL) { + ret = attr->touch_api->unregister_callback(attr->private_data); + if (ret != EXT_ERR_SUCCESS) { + tp_err("unregister touch screen callback fail! ret=0x%x", ret); + return ret; + } + g_attr = NULL; + } else { + tp_err("touch screen callback unregister func is empty!"); + } + + return ret; +} + +static int32_t ts_dev_open(const void *private_data) +{ + int32_t ret; + struct ts_driver_data *tsdd = NULL; + if (private_data == NULL) { + tp_err("ts_open: invalid dev or driver_data!\n"); + return EXT_ERR_FAILURE; + } + + // todo: get tsdd from private_data + tsdd = touch_screen_get_driver_data(); + tsdd->queue = ts_init_queue(TOUCH_SCREEN_QUEUE_MAX_SIZE); + if (tsdd->queue == NULL) { + tp_err("create touch screen queue fail!\r\n"); + return EXT_ERR_FAILURE; + } + ret = osal_event_init(&(tsdd->event)); + if (ret != EXT_ERR_SUCCESS) { + tp_err("touch osal_event_init fail! ret=0x%x\r\n", ret); + return ret; + } + + tsdd->task_handle = osal_kthread_create((osal_kthread_handler)touch_info_process, + (void *)touch_screen_get_driver_data(), + "touch_screen", TOUCH_SCREEN_TASK_SIZE); + if (tsdd->task_handle == NULL) { + tp_err("create touch screen thread fail!\r\n"); + return EXT_ERR_FAILURE; + } + osal_kthread_set_priority(tsdd->task_handle, TOUCH_SCREEN_TASK_PRIO); + + if (tsdd->touch_api->touch_init != NULL) { + ret = tsdd->touch_api->touch_init(tsdd->private_data); + if (ret != EXT_ERR_SUCCESS) { + tp_err("touch_init fail! ret=0x%x\r\n", ret); + return ret; + } + } + + ret = ts_register_callback(tsdd); + if (ret != EXT_ERR_SUCCESS) { + tp_err("register callback fail! ret=0x%x\r\n", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +static int32_t ts_dev_release(const void *private_data) +{ + int32_t ret; + struct ts_driver_data *tsdd = NULL; + if (private_data == NULL) { + tp_err("ts_dev_release: invalid dev or driver_data!\n"); + return EXT_ERR_FAILURE; + } + + // todo: get tsdd from private_data + tsdd = touch_screen_get_driver_data(); + ret = ts_unregister_callback(tsdd); + if (ret != EXT_ERR_SUCCESS) { + tp_err("unregister callback fail! ret=0x%x\r\n", ret); + return ret; + } + return EXT_ERR_SUCCESS; +} + +static uint32_t ts_dev_poll(const osal_poll *osal_poll, const void *private_data) +{ + unused(osal_poll); + unused(private_data); + // todo: get tsdd from private_data + struct ts_driver_data *tsdd = NULL; + tsdd = touch_screen_get_driver_data(); + if (tsdd == NULL) { + tp_err("ts_driver_data is NULL"); + return EXT_ERR_FAILURE; + } + + if (tsdd->ops->priv_operator != NULL && tsdd->ops->priv_operator(tsdd) == 0) { + return OSAL_POLLIN | OSAL_POLLRDNORM; + } + + return EXT_ERR_SUCCESS; +} + +static int32_t ts_ioctl_read_touch_info(uint32_t cmd, void *arg, const void *private_data) +{ + unused(cmd); + ext_errno ret; + struct ts_driver_data *tsdd = NULL; + input_event_info *touch_info = (input_event_info *)arg; + + if (private_data == NULL) { + tp_err("invalid dev or driver_data!"); + return EXT_ERR_FAILURE; + } + + // todo: get tsdd from private_data + tsdd = touch_screen_get_driver_data(); + if (tsdd->queue == NULL) { + tp_err("invalid touch screen queue!"); + return EXT_ERR_FAILURE; + } + + ret = ts_de_queue(tsdd->queue, touch_info); + if (ret != EXT_ERR_SUCCESS) { + tp_err("get touch info fail! ret=0x%x", ret); + return ret; + } + + return EXT_ERR_SUCCESS; +} + +static osal_ioctl_cmd g_ts_cmd_list[TOUCH_SCREEN_CMDID_MAX] = { + {TOUCH_SCREEN_GET_EVENT, ts_ioctl_read_touch_info}, +}; + +static osal_dev *g_ts_dev = NULL; +static osal_fileops g_ts_ops = { + .open = ts_dev_open, + .release = ts_dev_release, + .poll = ts_dev_poll, + .cmd_list = g_ts_cmd_list, + .cmd_cnt = sizeof(g_ts_cmd_list) / sizeof(g_ts_cmd_list[0]), +}; + +struct ts_ops g_ts_status_ops = { + .priv_operator = touch_screen_get_state, +}; + +static ext_errno touch_screen_register_device(void) +{ + ext_errno ret; + + g_touch_drv.private_data = touch_screen_get_peri_attr(); + g_touch_drv.touch_api = touch_screen_get_api(); + g_touch_drv.ops = &g_ts_status_ops; + g_ts_dev = osal_dev_create(TOUCH_SCREEN_DEVNAME); + g_ts_dev->minor = TOUCH_SCREEN_DYNAMIC_MINOR; + g_ts_dev->fops = &g_ts_ops; + + ret = osal_dev_register(g_ts_dev); + if (ret != 0) { + tp_err("touch screen osal_dev_register --------failed! ret=0x%x\n", ret); + return EXT_ERR_FAILURE; + } + + return EXT_ERR_SUCCESS; +} + +ext_errno touch_screen_module_init(void) +{ + ext_errno ret; + + ret = touch_screen_register_device(); + if (ret != EXT_ERR_SUCCESS) { + tp_err("touch_screen_register_device ----------failed! ret=0x%x\n", ret); + } + tp_err("touch_screen_register_device ----------succ!!!\n"); + + return EXT_ERR_SUCCESS; +} + +ext_errno touch_screen_module_deinit(void) +{ + return EXT_ERR_SUCCESS; +} + +uint32_t ts_register_report_event_cb(report_event_cb callback) +{ + if (g_report_event_cb != NULL) { + return EXT_ERR_FAILURE; + } + g_report_event_cb = callback; + return EXT_ERR_SUCCESS; +} + +uint32_t ts_unregister_report_event_cb(void) +{ + g_report_event_cb = NULL; + return EXT_ERR_SUCCESS; +} + +uint32_t ts_init(void) +{ + int32_t ret; + struct ts_driver_data *tsdd = NULL; + + g_touch_drv.private_data = touch_screen_get_peri_attr(); + g_touch_drv.touch_api = touch_screen_get_api(); + g_touch_drv.ops = &g_ts_status_ops; + tsdd = touch_screen_get_driver_data(); + tsdd->queue = ts_init_queue(TOUCH_SCREEN_QUEUE_MAX_SIZE); + if (tsdd->queue == NULL) { + tp_err("create touch screen queue fail!\r\n"); + return EXT_ERR_FAILURE; + } + + ret = ts_register_callback(tsdd); + if (ret != EXT_ERR_SUCCESS) { + tp_err("register callback fail! ret=0x%x\r\n", ret); + return EXT_ERR_FAILURE; + } + + return EXT_ERR_SUCCESS; +} + +uint32_t ts_read(const input_dev_data_t* data) +{ + unused(data); + return EXT_ERR_SUCCESS; +} + +uint32_t ts_close(void) +{ + return EXT_ERR_SUCCESS; +} + +void touch_screen_suspend(void) +{ + touch_peripheral_api *touch_ptr = touch_screen_get_api(); + ext_errno ret = touch_ptr->touch_sleep(); + if (ret != EXT_ERR_SUCCESS) { tp_err("touch sleep ret=0x%x", ret); } + i2c_save_reg(TOUCH_I2C_BUS); + uapi_gpio_disable_interrupt(TOUCH_INT_GPIO); // close tp_int gpio interrupt +} + +void touch_screen_resume(void) +{ + uapi_gpio_disable_interrupt(TOUCH_INT_GPIO); // close tp_int gpio interrupt + i2c_recovery_reg(TOUCH_I2C_BUS); +#if defined(TPTYPE_TMA525B) + tma525b_init(); + touch_peripheral_api *touch_ptr = (touch_peripheral_api*)touch_screen_get_api(); + ext_errno ret = touch_ptr->touch_resume(); + if (ret != EXT_ERR_SUCCESS) { tp_err("touch resume ret=0x%x", ret); } +#elif defined(TPTYPE_ZTW523) + ztw523_resume(); +#else + ztw523_resume(); +#endif + uapi_gpio_enable_interrupt(TOUCH_INT_GPIO); // open tp_int gpio interrupt +} + +void touch_suspend_for_i2c(void) +{ + i2c_save_reg(TOUCH_I2C_BUS); +} + +void touch_resume_for_i2c(void) +{ + i2c_recovery_reg(TOUCH_I2C_BUS); +} + +void touch_screen_restart(void) +{ + uapi_i2c_deinit(TOUCH_I2C_BUS); + uapi_i2c_master_init(TOUCH_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ +#if defined(TPTYPE_TMA525B) + tma525b_resume(); +#elif defined(TPTYPE_ZTW523) + ztw523_resume(); +#else + ztw523_resume(); +#endif + uapi_gpio_enable_interrupt(TOUCH_INT_GPIO); // open tp_int gpio interrupt +} \ No newline at end of file diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h b/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h new file mode 100644 index 000000000..05e318244 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/include/pm_definition.h @@ -0,0 +1,436 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: PM definitions header file + */ + +#ifndef LIB_PM_DEFINITION_H +#define LIB_PM_DEFINITION_H + +#include "chip_io.h" + +/** + * @defgroup middleware_utils_pm_api PM + * @ingroup middleware_utils + * @{ + */ + +/** + * @if Eng + * @brief PM module Id. + * @else + * @brief PM 模块 ID + * @endif + */ +typedef enum { + PM_ID_BSP, + PM_ID_SYS, + PM_ID_BTH, + PM_ID_BTC, + PM_ID_AUDIO, + PM_ID_VIDEO, + PM_ID_DMA, + PM_ID_DPU, + PM_ID_VAU, + PM_ID_BUTTON, + PM_ID_DEBUG, + PM_ID_ADC, + PM_ID_DFX, + PM_ID_SCREEN, + PM_ID_STORAGE, + PM_ID_TOUCH, + PM_ID_JPEG, + PM_ID_JS, + PM_ID_MSGCENTER, + PM_ID_SPI_DMA, + PM_ID_I2C_DMA, + PM_ID_UART_DMA, + PM_ID_MAX, +} pm_id_t; + +/** + * @if Eng + * @brief Key running status of the system. + * @else + * @brief 系统关键运行状态 + * @endif + */ +typedef enum { + PM_STATE_LIGHT_SLEEP, /*!< @if Eng Light Sleep state + @else 浅睡状态 @endif */ + PM_STATE_DEEP_SLEEP, /*!< @if Eng Deep sleep state + @else 深睡状态 @endif */ + PM_STATE_WKUP_FROM_LIGHT_SLEEP, /*!< @if Eng Wakeup from LightSleep + @else 浅睡唤醒 @endif */ + PM_STATE_WKUP_FROM_DEEP_SLEEP, /*!< @if Eng Wakeup from DeepSleep + @else 深睡唤醒 @endif */ + PM_STATE_POWER_ON, /*!< @if Eng Power ON state + @else 上电模式 @endif */ + PM_STATE_POWER_OFF, /*!< @if Eng Power off state + @else 下电模式 @endif */ + PM_STATE_WORK, /*!< @if Eng Working On state + @else 工作模式 @endif */ + PM_STATE_MAX, +} pm_states_t; + +typedef enum { + PM_MODE_NONE, + PM_MODE_LP, + PM_MODE_NORMAL, + PM_MODE_PERFORMACE, + PM_MODE_RESET, + PM_MODE_MAX, +} pm_mode_t; + +typedef enum { + PM_DEV_NONE, + PM_DEV_M_MGPIO, + PM_DEV_M_TIMER, + PM_DEV_M_RTC, + PM_DEV_M_CWDT, + PM_DEV_M_I2C0, + PM_DEV_M_I2C1, + PM_DEV_M_I2C2, + PM_DEV_M_I2C3, + PM_DEV_M_MDMA, + PM_DEV_M_MSDMA, + PM_DEV_M_SPI0, + PM_DEV_M_SPI1, + PM_DEV_M_SPI2, + PM_DEV_M_QSPI2, + PM_DEV_M_UART_H0, + PM_DEV_M_UART_H1, + + PM_DEV_HS_SDIO, + PM_DEV_HS_QSPI1, + PM_DEV_HS_HGPIO, + + PM_DEV_MEM_XIP, + PM_DEV_MEM_QSPI0, + PM_DEV_MEM_OPI, + PM_DEV_MEM_EGPIO, + + PM_DEV_B_WDT, + PM_DEV_B_TIMER, + PM_DEV_B_UART_L1, + + PM_DEV_DISPLAY, + + PM_DEV_AUDIO, + PM_DEV_MAX, +} pm_dev_id_t; + +typedef enum { + /* sys sub region. */ + PMU_ID_SUB_B_SOC = 0, + PMU_ID_SUB_BT_CBB, + PMU_ID_SUB_B_MEM, + PMU_ID_SUB_BT_EM, + PMU_ID_SUB_MCU_HS, + PMU_ID_SUB_DISPLAY, + PMU_ID_SUB_AUDIO, + PMU_ID_SUB_S_EGPIO, + PMU_ID_SUB_BT_RF, + PMU_ID_SUB_MCU, + PMU_ID_SUB_MEM, + PMU_ID_SUB_COM, + PMU_ID_SUB_L2M_GMMU, + PMU_ID_SUB_L2M_DSP, + PMU_ID_SUB_XIP_MEM, + PMU_ID_SUB_BMEM_RAM, + + /* ldo region. */ + PMU_ID_LDO_CLDO1, + PMU_ID_LDO_CLDO2, + PMU_ID_LDO_CLDO3, + PMU_ID_LDO_XLDO, + PMU_ID_LDO_CMU_LDO, + PMU_ID_LDO_INTLDO1, + PMU_ID_LDO_INTLDO2, + PMU_ID_LDO_AUXLDO0, + PMU_ID_LDO_AUXLDO1, + PMU_ID_LDO_AUXLDO2, + PMU_ID_LDO_AUXLDO3, + PMU_ID_LDO_IOLDO, + + /* simo region. */ + PMU_ID_SIMO_VDD0P8, + PMU_ID_SIMO_VDD1P9, + PMU_ID_SIMO_VDD1P0, + PMU_ID_SIMO_VDD1P3, + PMU_ID_SIMO_VDD0P8_BCORE, + PMU_ID_SIMO_MAX, + PMU_ID_MAX, +} pmu_id_t; + +typedef enum { + PMU_CLDO_LEVEL_0P400V = 0, + PMU_CLDO_LEVEL_0P425V = 1, + PMU_CLDO_LEVEL_0P450V = 2, + PMU_CLDO_LEVEL_0P475V = 3, + PMU_CLDO_LEVEL_0P500V = 4, + PMU_CLDO_LEVEL_0P525V = 5, + PMU_CLDO_LEVEL_0P550V = 6, + PMU_CLDO_LEVEL_0P575V = 7, + PMU_CLDO_LEVEL_0P600V = 8, + PMU_CLDO_LEVEL_0P625V = 9, + PMU_CLDO_LEVEL_0P650V = 10, + PMU_CLDO_LEVEL_0P675V = 11, + PMU_CLDO_LEVEL_0P700V = 12, + PMU_CLDO_LEVEL_0P750V = 13, + PMU_CLDO_LEVEL_0P800V = 14, + PMU_CLDO_LEVEL_0P850V = 15, +} pmu_cldo_level_t; + +typedef enum { + PMU_AUXLDO_LEVEL_1P600V = 0, + PMU_AUXLDO_LEVEL_1P625V = 1, + PMU_AUXLDO_LEVEL_1P650V = 2, + PMU_AUXLDO_LEVEL_1P675V = 3, + PMU_AUXLDO_LEVEL_1P700V = 4, + PMU_AUXLDO_LEVEL_1P725V = 5, + PMU_AUXLDO_LEVEL_1P750V = 6, + PMU_AUXLDO_LEVEL_1P775V = 7, + PMU_AUXLDO_LEVEL_1P800V = 8, + PMU_AUXLDO_LEVEL_1P825V = 9, + PMU_AUXLDO_LEVEL_1P850V = 10, + PMU_AUXLDO_LEVEL_1P875V = 11, + PMU_AUXLDO_LEVEL_1P900V = 12, + PMU_AUXLDO_LEVEL_1P925V = 13, + PMU_AUXLDO_LEVEL_1P950V = 14, + PMU_AUXLDO_LEVEL_1P975V = 15, +} pmu_auxldo_level_t; + +typedef enum { + PMU_IOLDO_LEVEL_1P600V = 0, + PMU_IOLDO_LEVEL_1P625V = 1, + PMU_IOLDO_LEVEL_1P650V = 2, + PMU_IOLDO_LEVEL_1P675V = 3, + PMU_IOLDO_LEVEL_1P700V = 4, + PMU_IOLDO_LEVEL_1P725V = 5, + PMU_IOLDO_LEVEL_1P750V = 6, + PMU_IOLDO_LEVEL_1P775V = 7, + PMU_IOLDO_LEVEL_1P800V = 8, + PMU_IOLDO_LEVEL_1P825V = 9, + PMU_IOLDO_LEVEL_1P850V = 10, + PMU_IOLDO_LEVEL_1P875V = 11, + PMU_IOLDO_LEVEL_1P900V = 12, + PMU_IOLDO_LEVEL_1P925V = 13, + PMU_IOLDO_LEVEL_1P950V = 14, + PMU_IOLDO_LEVEL_1P975V = 15, +} pmu_ioldo_level_t; + +typedef enum { + PMU_INTLDO1_LEVEL_1P80V = 0, + PMU_INTLDO1_LEVEL_1P78V = 1, + PMU_INTLDO1_LEVEL_1P82V = 2, + PMU_INTLDO1_LEVEL_1P84V = 3, + PMU_INTLDO1_LEVEL_1P86V = 4, + PMU_INTLDO1_LEVEL_1P88V = 5, + PMU_INTLDO1_LEVEL_1P90V = 6, + PMU_INTLDO1_LEVEL_1P92V = 7, +} pmu_intldo1_level_type_t; + +typedef enum { + PMU_INTLDO2_LEVEL_1P78V = 0, + PMU_INTLDO2_LEVEL_1P80V = 1, + PMU_INTLDO2_LEVEL_1P82V = 2, + PMU_INTLDO2_LEVEL_1P84V = 3, + PMU_INTLDO2_LEVEL_1P86V = 4, + PMU_INTLDO2_LEVEL_1P88V = 5, + PMU_INTLDO2_LEVEL_1P90V = 6, + PMU_INTLDO2_LEVEL_1P92V = 7, +} pmu_intldo2_level_type_t; + +typedef enum { + PMU_XLDO_LEVEL_1P600V = 0, + PMU_XLDO_LEVEL_1P625V = 1, + PMU_XLDO_LEVEL_1P650V = 2, + PMU_XLDO_LEVEL_1P675V = 3, + PMU_XLDO_LEVEL_1P700V = 4, + PMU_XLDO_LEVEL_1P725V = 5, + PMU_XLDO_LEVEL_1P750V = 6, + PMU_XLDO_LEVEL_1P775V = 7, + PMU_XLDO_LEVEL_1P800V = 8, + PMU_XLDO_LEVEL_1P825V = 9, + PMU_XLDO_LEVEL_1P850V = 10, +} pmu_xldo_level_type_t; + +typedef enum { + PMU_CMU_LDO_LEVEL_0P720V = 0, + PMU_CMU_LDO_LEVEL_0P740V = 1, + PMU_CMU_LDO_LEVEL_0P760V = 2, + PMU_CMU_LDO_LEVEL_0P780V = 3, + PMU_CMU_LDO_LEVEL_0P800V = 4, + PMU_CMU_LDO_LEVEL_0P820V = 5, + PMU_CMU_LDO_LEVEL_0P840V = 6, + PMU_CMU_LDO_LEVEL_0P860V = 7, + PMU_CMU_LDO_LEVEL_0P880V = 8, + PMU_CMU_LDO_LEVEL_0P900V = 9, + PMU_CMU_LDO_LEVEL_0P920V = 10, + PMU_CMU_LDO_LEVEL_0P940V = 11, + PMU_CMU_LDO_LEVEL_0P960V = 12, + PMU_CMU_LDO_LEVEL_0P980V = 13, + PMU_CMU_LDO_LEVEL_1P000V = 14, + PMU_CMU_LDO_LEVEL_1P020V = 15, +} pmu_cmu_ldo_level_type_t; + +/* simo1_vo2&simo2_vo2 */ +typedef enum { + PMU_VDD0P8_1P0_0P600V = 0, + PMU_VDD0P8_1P0_0P625V = 1, + PMU_VDD0P8_1P0_0P650V = 2, + PMU_VDD0P8_1P0_0P675V = 3, + PMU_VDD0P8_1P0_0P700V = 4, + PMU_VDD0P8_1P0_0P725V = 5, + PMU_VDD0P8_1P0_0P750V = 6, + PMU_VDD0P8_1P0_0P775V = 7, + PMU_VDD0P8_1P0_0P800V = 8, + PMU_VDD0P8_1P0_0P825V = 9, + PMU_VDD0P8_1P0_0P850V = 10, + PMU_VDD0P8_1P0_0P875V = 11, + PMU_VDD0P8_1P0_0P900V = 12, + PMU_VDD0P8_1P0_0P925V = 13, + PMU_VDD0P8_1P0_0P950V = 14, + PMU_VDD0P8_1P0_0P975V = 15, + PMU_VDD0P8_1P0_1P000V = 16, + PMU_VDD0P8_1P0_1P025V = 17, + PMU_VDD0P8_1P0_1P050V = 18, + PMU_VDD0P8_1P0_1P075V = 19, + PMU_VDD0P8_1P0_1P100V = 20, +} pmu_vdd0p8_level_t; + +/* simo1_vo1&simo2_vo1 */ +typedef enum { + PMU_VDD1P9_1P3_0P800V = 0, + PMU_VDD1P9_1P3_0P850V = 2, + PMU_VDD1P9_1P3_0P900V = 4, + PMU_VDD1P9_1P3_0P950V = 6, + PMU_VDD1P9_1P3_1P000V = 8, + PMU_VDD1P9_1P3_1P050V = 10, + PMU_VDD1P9_1P3_1P100V = 12, + PMU_VDD1P9_1P3_1P150V = 14, + PMU_VDD1P9_1P3_1P200V = 16, + PMU_VDD1P9_1P3_1P250V = 18, + PMU_VDD1P9_1P3_1P300V = 20, + PMU_VDD1P9_1P3_1P350V = 22, + PMU_VDD1P9_1P3_1P400V = 24, + PMU_VDD1P9_1P3_1P450V = 26, + PMU_VDD1P9_1P3_1P500V = 28, + PMU_VDD1P9_1P3_1P550V = 30, + PMU_VDD1P9_1P3_1P600V = 32, + PMU_VDD1P9_1P3_1P650V = 34, + PMU_VDD1P9_1P3_1P700V = 36, + PMU_VDD1P9_1P3_1P750V = 38, + PMU_VDD1P9_1P3_1P800V = 40, + PMU_VDD1P9_1P3_1P850V = 42, + PMU_VDD1P9_1P3_1P900V = 44, + PMU_VDD1P9_1P3_1P950V = 46, + PMU_VDD1P9_1P3_2P000V = 48, +} pmu_vdd1p9_level_t; + +typedef enum { + // MSUB Perip & BUS + CLOCKS_ID_M_TIMER, + CLOCKS_ID_M_SMDMA, + CLOCKS_ID_M_MDMA, + CLOCKS_ID_M_I2C0, + CLOCKS_ID_M_I2C1, + CLOCKS_ID_M_I2C2, + CLOCKS_ID_M_I2C3, + CLOCKS_ID_M_SPI0, + CLOCKS_ID_M_SPI1, + CLOCKS_ID_M_SPI2, + CLOCKS_ID_M_UART_H0, + CLOCKS_ID_M_UART_H1, + CLOCKS_ID_M_EMMC, + CLOCKS_ID_M_SDIO, + CLOCKS_ID_M_PWM, + // BSUB Perip & BUS + CLOCKS_ID_B_UART, + CLOCKS_ID_B_TRNG, + CLOCKS_ID_B_DIAG, + CLOCKS_ID_B_CPU_TRACE, + CLOCKS_ID_B_TIMER, + CLOCKS_ID_B_WDT, + CLOCKS_ID_B_TSENSOR, + // AON + CLOCKS_ID_AON_GPIO0, + CLOCKS_ID_AON_GPIO1, + CLOCKS_ID_AON_GPIO2, + CLOCKS_ID_AON_GPIO3, + CLOCKS_ID_AON_GPIO4, + CLOCKS_ID_AON_RTC, + CLOCKS_ID_AON_CWDT, + // MEM SUB + CLOCKS_ID_MEM_QSPI0, + CLOCKS_ID_MEM_OPI, + // DAON SUB + CLOCKS_ID_DAON_GPIO, + + // Module + CLOCKS_ID_SOC_MCU_CORE, + CLOCKS_ID_SOC_MCU_PERP_LS, + CLOCKS_ID_SOC_MCU_PERP_UART, + CLOCKS_ID_SOC_MCU_PERP_SPI, + CLOCKS_ID_SOC_COM_BUS, + CLOCKS_ID_SOC_SDIOM, + CLOCKS_ID_SOC_MEM_BUS, + CLOCKS_ID_SOC_XIP_OPI, + CLOCKS_ID_SOC_XIP_QSPI, + CLOCKS_ID_SOC_GPU, + CLOCKS_ID_SOC_HIFI, + CLOCKS_ID_SOC_CODEC, + CLOCKS_ID_SOC_BT_CORE, + CLOCKS_ID_SOC_MAX, + CLOCKS_ID_MAX, +} clocks_id_t; + +typedef enum { + CLOCKS_SRC_RC = 0, + CLOCKS_SRC_TCXO = 1, + CLOCKS_SRC_TCXO_2X = 2, + CLOCKS_SRC_PLL = 3, + CLOCKS_SRC_32K = 4, + CLOCKS_SRC_PAD_CLKIN = 5, + CLOCKS_SRC_MAX, +} clocks_src_t; + +typedef struct { + uint8_t *data; + uint32_t len; + uint32_t (*handler)(uint8_t *data, uint32_t len); +} pm_fsm_content_t; + +/** + * @if Eng + * @brief Operating functions of peripheral devices. + * @else + * @brief 外设的设备处理函数 + * @endif + */ +typedef struct { + uint32_t (*suspend)(void); + uint32_t (*resume)(void); + uint32_t (*ioctl)(uint8_t type, uint8_t *data, uint32_t len); +} pm_dev_ops_t; + +/** + * @if Eng + * @brief The global list of device functions is filled by the driver and + bus and registered with the PM module.Supports single-point registration with the PM module in services. + * @else + * @brief 设备函数全局列表,由驱动、总线填充,统一注册到pm模块;同时支持在业务中单点注册至pm模块 + * @endif + */ +#define PM_ALL_DEV { \ + {PM_DEV_M_TIMER, {NULL, NULL, pm_dev_ostimer_ioctl}}, \ + {PM_DEV_M_CWDT, {NULL, NULL, pm_dev_wdt_ioctl}}, \ + {PM_DEV_M_RTC, {NULL, NULL, pm_dev_rtc_ioctl}}, \ + {PM_DEV_M_UART_H0, {NULL, NULL, NULL}}, \ +} + +/** + * @} + */ + +#endif diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/pm.c b/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/pm.c new file mode 100644 index 000000000..ae3d61093 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/pm.c @@ -0,0 +1,210 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: pm dev operations code + */ + +#include "pm.h" +#include "pm_sleep.h" +#include "pm_veto.h" +#include "pm_dev.h" +#include "pm_fsm.h" +#include "clocks_core.h" +#include "chip_io.h" +#include "rtc.h" +#include "watchdog.h" +#include "watchdog_porting.h" +#include "securec.h" +#include "pmu_interrupt.h" + +typedef struct { + uint32_t slp_ms; + uint32_t handle; + rtc_callback_t cb; +} pm_rtc_timer_t; + +typedef struct { + pm_dev_id_t dev_id; + pm_dev_ops_t dev_ops; +} pm_dev_t; + +#if CORE == MASTER_BY_ALL +static clocks_clk_cfg_t g_cpu_cfg; +#endif + +#define PM_SHIPMODE_DELAY_SLEEP_MS 100 + +// ostimer +static uint32_t pm_dev_ostimer_ioctl(uint8_t type, uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); + switch (type) { + case DEV_OSTIMER_ENABLE: + pm_os_timer_enable(); + break; + case DEV_OSTIMER_DISABLE: + pm_os_timer_disable(); + break; + default: + break; + } + return 0; +} + +// rtc +static uint32_t rtc_start_wkup_timer(uint8_t *data, uint32_t len) +{ + if (len != sizeof(pm_rtc_timer_t)) { + return (uint32_t)ERRCODE_PM_ERROR; + } + + pm_rtc_timer_t *timer = (pm_rtc_timer_t *)data; + uint32_t wakeup_time = timer->slp_ms; + rtc_handle_t *handle = (rtc_handle_t)(timer->handle); + if (handle == NULL) { + return (uint32_t)ERRCODE_PM_ERROR; + } + if (*handle == NULL) { + uapi_rtc_create(RTC_0, handle); + uapi_rtc_start(*handle, wakeup_time, (rtc_callback_t)timer->cb, 0); + } else { + uapi_rtc_start(*handle, wakeup_time, (rtc_callback_t)timer->cb, 0); + } + return (uint32_t)ERRCODE_SUCC; +} + +static uint32_t pm_dev_rtc_ioctl(uint8_t type, uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); + switch (type) { + case DEV_RTC_START: + return rtc_start_wkup_timer(data, len); + default: + break; + } + return 0; +} + +static uint32_t pm_dev_wdt_ioctl(uint8_t type, uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); + switch (type) { + case DEV_WDT_ENABLE: + watchdog_turnon_clk(); + uapi_watchdog_set_time(watchdog_get_conifgtime); + uapi_watchdog_enable(WDT_MODE_INTERRUPT); + break; + case DEV_WDT_DISABLE: + watchdog_turnon_clk(); + uapi_watchdog_disable(); + watchdog_turnoff_clk(); + break; + default: + break; + } + return 0; +} + +static void pm_dev_register_sleep_ops(void) +{ + pm_dev_t all_devs[] = PM_ALL_DEV; + + for (uint8_t i = 0; i < sizeof(all_devs) / sizeof(pm_dev_t); i++) { + uapi_pm_register_dev_ops(all_devs[i].dev_id, &(all_devs[i].dev_ops)); + } +} + +static uint32_t core_crg_switch(uint8_t *data, uint32_t len) +{ + UNUSED(data); + UNUSED(len); +#if CORE == MASTER_BY_ALL + if (data == NULL) { + return 0; + } + + if (data[0] == PM_STATE_DEEP_SLEEP) { + // todo + } else if (data[0] == PM_STATE_WKUP_FROM_DEEP_SLEEP) { + // todo + } +#endif + return 0; +} + +static void pm_fsm_register_sleep_handler(void) +{ + uint8_t state = PM_STATE_DEEP_SLEEP; + pm_fsm_content_t content = {&state, 1, core_crg_switch}; + uapi_pm_register_fsm_handler(PM_ID_SYS, PM_STATE_DEEP_SLEEP, &content); + + state = PM_STATE_WKUP_FROM_DEEP_SLEEP; + uapi_pm_register_fsm_handler(PM_ID_SYS, PM_STATE_WKUP_FROM_DEEP_SLEEP, &content); +} + +void uapi_pm_init(void) +{ + pm_veto_init(); + pm_dev_register_sleep_ops(); + pm_fsm_register_sleep_handler(); +#if ENABLE_LOW_POWER == YES +#ifdef __LITEOS__ + LOS_LowpowerHookReg(uapi_pm_enter_sleep); +#endif + uapi_pm_add_sleep_veto(PM_ID_DEBUG); +#endif +} + +void uapi_sys_force_mcu_only_deep_sleep_mode(uint32_t arg) +{ + UNUSED(arg); + uint32_t irq = osal_irq_lock(); + + reg16_clrbit(0x57000168, 0x2); // close watchdog clock + pm_enter_deep_sleep_only_ulp_wakeup(); + osal_irq_restore(irq); +} + +void uapi_sys_shipmode(uint32_t arg) +{ + UNUSED(arg); + uint32_t irq = osal_irq_lock(); + uapi_pm_control(PM_BT_POWER_OFF); + uapi_pm_control(PM_DSP_POWER_OFF); + uapi_pm_control(PM_DISPLAY_POWER_OFF); + + /* clr ulp int and event */ + writel(0x5702C1E4, 0x3F); + writel(0x5702C1EC, 0x3F); + uapi_tcxo_delay_us(PM_SHIPMODE_DELAY_SLEEP_MS); + + reg16_clrbit(0x5702c508, POS_14); + writew(0x5700450c, 0x100); + + // gpio + writew(0x5702C200, 0x0); + writew(0x5702C204, 0x0); + writew(0x5702C208, 0x0); + writew(0x5702C20c, 0x0); + writew(0x5702C210, 0x0); + + writew(0x5702c200, 0x7); + writew(0x57030004, 0x0); + writew(0x57030038, 0x1); + writew(0x5703003c, 0x1); + writew(0x57030034, 0x0); + writew(0x57030030, 0x1); + + writew(0x570040d8, 0xc000); + writew(0x5702c028, 0x0); + writew(0x5702c024, 0x3); + writew(0x5702c1d0, 0x1); + writew(0x5702C038, 0x0); + writew(0x5702C1F0, 0x1C); + writew(0x5702C110, 0x101); + writew(0x570040d0, 0x1); + writew(0x570040e0, 0x1); + osal_irq_restore(irq); +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/service/pm_sleep.c b/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/service/pm_sleep.c new file mode 100644 index 000000000..d4fc8a307 --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/middleware/chips/brandy/pm/service/pm_sleep.c @@ -0,0 +1,361 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: pm sleep manage code + */ + +#include "pm_sleep.h" +#include "pm.h" +#include "pm_definition.h" +#include "errcode.h" +#include "pm_os.h" +#include "pm_veto.h" +#include "pm_dev.h" +#include "pm_fsm.h" +#include "pm_lpc.h" +#include "pm_core.h" +#include "pm_clocks.h" +#include "clocks_config.h" +#include "arch_encoding.h" +#include "arch_barrier.h" +#include "debug_print.h" +#include "pmu_interrupt.h" +#if CONFIG_PM_TICKLESS_EN == YES +#include "pm_tickless.h" +#endif +#include "non_os_reboot.h" + +#define PM_SLEEP_THRESHOLD_WFI_ONLY_MS 10 +#define PM_SLEEP_THRESHOLD_DEEPSLEEP_MS 20 +#define PM_SLEEP_SEL_TRACE 0x5700041c +#define PM_SLEEP_TRACE_SEL_TAG(val) (writew(PM_SLEEP_SEL_TRACE, val)) +#define PM_SLEEP_SEL_EVENT 0x777 +#define PM_SLEEP_TRACE_DEF_VAL 0x5a5a +#define PM_OS_US_TO_MS 1000 +#define RTC_TIMER_INT_STATUS 0x57024010 +#define PM_RTC_LOAD_COUNT_REG 0x57024000 +#define PM_RTC_CUR_ALERT_US 64000000 +#define PM_RTC_LOAD_THRESHOLD_MS (CLOCK_32K_CALI_FREQ / 50) + +enum { + PM_SLEEP_STATE_IDLE, + PM_SLEEP_STATE_GOTO_DS, + PM_SLEEP_STATE_WKUP_PRE, +}; + +typedef enum { + SLP_INFO_TIME_BASE = 0, + SLP_INFO_LIGHTSLEEP, + SLP_INFO_DEEPSLEEP, + SLP_INFO_VETO, + SLP_INFO_MAX, +} slp_record_info_t; + +static sleep_info_t g_sleep_info = {0}; + +#if CONFIG_PM_POWER_GATING_EN == YES +static uint8_t g_pm_stop_state = 0; +#endif + +static uint16_t g_pm_sleep_threshold = PM_SLEEP_THRESHOLD_DEEPSLEEP_MS; +static uint8_t g_pm_mcu_dynamic_power_flag = 0; + +static void pm_enter_deepsleep_set_flag(void) +{ + writew(GLB_CTL_B_RB_BASE + 0x18, 0x5a5a); +} + +static void pm_enter_deepsleep_cancel_flag(void) +{ + writew(GLB_CTL_B_RB_BASE + 0x18, 0xa5a5); +} + +static void pm_sleep_info_record(slp_record_info_t info) +{ +#if CONFIG_PM_SLEEP_RECORD_EN == YES + if (info == SLP_INFO_TIME_BASE) { + g_sleep_info.sleep_base_time = pm_core_get_current_ms(); + } else if (info == SLP_INFO_LIGHTSLEEP) { + g_sleep_info.sleep_history[PM_SLEEP_LS].total_slp_count++; + g_sleep_info.sleep_history[PM_SLEEP_LS].total_slp_time += + (pm_core_get_current_ms() - g_sleep_info.sleep_base_time); + } else if (info == SLP_INFO_DEEPSLEEP) { + g_sleep_info.sleep_history[PM_SLEEP_DS].total_slp_count++; + g_sleep_info.sleep_history[PM_SLEEP_DS].total_slp_time += + (pm_core_get_current_ms() - g_sleep_info.sleep_base_time); + } else if (info == SLP_INFO_VETO) { + g_sleep_info.sleep_veto.last_veto_count = pm_veto_get_info()->veto_counts.total_counts; + g_sleep_info.sleep_veto.last_veto_id = pm_veto_get_info()->last_veto_id; + } + g_sleep_info.event.slp_event = lpc_sleep_get_all_status(LPC_EVT_ACTION); + g_sleep_info.event.wkup_event = lpc_wakeup_get_all_status(LPC_EVT_ACTION); +#else + UNUSED(info); +#endif +} + +static void pm_sleep_prepare(uint8_t sleep_type) +{ + pm_states_t state; + if (sleep_type == PM_SLEEP_LS) { + state = PM_STATE_LIGHT_SLEEP; + lpc_lightsleep_config(); + } else if (sleep_type == PM_SLEEP_DS) { + state = PM_STATE_DEEP_SLEEP; + lpc_deepsleep_config(); + } + + for (pm_id_t id = 0; id < PM_ID_MAX; id++) { + pm_process_fsm_handler(id, state); + } +} + +static void pm_wkup_prepare(uint8_t sleep_type) +{ + pm_states_t state; + lpc_sleep_all_status_clear(LPC_EVT_ACTION); + lpc_wakeup_all_status_clear(LPC_EVT_ACTION); + + if (sleep_type == PM_SLEEP_LS) { + state = PM_STATE_WKUP_FROM_LIGHT_SLEEP; + } else if (sleep_type == PM_SLEEP_DS) { + state = PM_STATE_WKUP_FROM_DEEP_SLEEP; + } + + for (pm_id_t id = 0; id < PM_ID_MAX; id++) { + pm_process_fsm_handler(id, state); + } +} + +static inline void pm_enter_wfi(void) +{ + reg16_setbits(0x57004704, 0x1, 0x1, 0x0); + while (reg16_getbits(0x57004708, 0x1, 0x1) != 0) { + reg16_setbits(0x57004700, 0x1, 0x1, 0x1); + } + lpc_wfi(); +} + +static void pm_enter_light_sleep(void) +{ + pm_sleep_prepare(PM_SLEEP_LS); + // 进入wfi + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + pm_wkup_prepare(PM_SLEEP_LS); +} + +static void pm_enter_lock_irq(void) +{ + clear_custom_csr(0x300, 0x3); +} + +static void pm_enter_unlock_irq(void) +{ + set_custom_csr(0x300, 0x3); +} + +static void pm_enter_enable_irq(uint32_t irq) +{ + reg8_write(CLIC_BASE_REG + sys_clic_intie(irq), 0x1); +} + +static void pm_enter_disable_irq(uint32_t irq) +{ + reg8_write(CLIC_BASE_REG + sys_clic_intie(irq), 0x0); +} + +void pm_enter_deep_sleep_wfi(void) +{ + wfi(); + pm_enter_lock_irq(); + // wait soc aon low power ready + while (reg16_getbits(0x52000D00, 0x0, 0x4) != 0) { + } + lowpower_cpu_resume(); +} + +void pm_wkup_event_by_ulp_callback(void) +{ + set_cpu_utils_reset_cause(REBOOT_CAUSE_APPLICATION_SYSRESETREQ); + hal_reboot_chip(); +} + +void pm_enter_deep_sleep_only_ulp_wakeup(void) +{ + reg16_clrbit(0x520003e4, 0x3); // close mdam clock in deepsleep + if (pm_dev_suspend() != ERRCODE_SUCC) { + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + return; + } + g_pm_stop_state = PM_SLEEP_STATE_GOTO_DS; + pm_sleep_prepare(PM_SLEEP_DS); + pm_core_suspend_min(); + + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_TRACE_DEF_VAL); + if (g_pm_stop_state == PM_SLEEP_STATE_GOTO_DS) { + g_pm_stop_state = PM_SLEEP_STATE_WKUP_PRE; + pm_core_close_all_irq(); + pm_enter_enable_irq(M_WAKEUP_IRQN); + lpc_allow_deepsleep(); + pm_enter_unlock_irq(); + if (pmu_mcpu_allow_to_sleep_status() == TURN_ON) { + dsb(); + pm_enter_deepsleep_cancel_flag(); + writew(0x57004684, 0x2000); // only open ulp wakeup event + writew(0x57004728, 0x0); + writew(0x57004694, 0x2000); // only open ulp wakeup interrupt + writew(0x5702c1f0, 0x8); // only open ulp wakeup powerkey interrupt + pm_enter_deep_sleep_wfi(); + } + pm_enter_lock_irq(); + } else if (g_pm_stop_state == PM_SLEEP_STATE_WKUP_PRE) { + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_SEL_EVENT); + pm_enter_disable_irq(M_WAKEUP_IRQN); + lpc_forbid_deepsleep(); + pm_core_resume_min(); + pm_dev_resume(); + } + uint16_t status = pmu_lpm_wakeup_get_status(LPM_EVT_ACTION, PMU_LPM_MCPU_ULP_WAKEUP); + pm_wkup_prepare(PM_SLEEP_DS); + pm_sleep_info_record(SLP_INFO_DEEPSLEEP); + reg16_setbit(0x520003e4, 0x3); // open mdam clock after deepsleep + if (status != 0) { + pm_wkup_event_by_ulp_callback(); + } +} + +void pm_wkup_event_by_uart_callback(void) +{ + uapi_pm_add_sleep_veto(PM_ID_DEBUG); +} + +static void pm_enter_deep_sleep(void) +{ + reg16_clrbit(0x520003e4, 0x3); // close mdam clock in deepsleep +#if CONFIG_PM_POWER_GATING_EN == YES + if (pm_dev_suspend() != ERRCODE_SUCC) { + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + return; + } + g_pm_stop_state = PM_SLEEP_STATE_GOTO_DS; + pm_sleep_prepare(PM_SLEEP_DS); + pm_core_suspend(); + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_TRACE_DEF_VAL); + if (g_pm_stop_state == PM_SLEEP_STATE_GOTO_DS) { + g_pm_stop_state = PM_SLEEP_STATE_WKUP_PRE; + pm_core_close_all_irq(); + pm_enter_enable_irq(M_WAKEUP_IRQN); + lpc_allow_deepsleep(); + pm_enter_unlock_irq(); + if (pmu_mcpu_allow_to_sleep_status() == TURN_ON) { + dsb(); + pm_enter_deepsleep_cancel_flag(); + pm_enter_deep_sleep_wfi(); + } + pm_enter_lock_irq(); + } else if (g_pm_stop_state == PM_SLEEP_STATE_WKUP_PRE) { + PM_SLEEP_TRACE_SEL_TAG(PM_SLEEP_SEL_EVENT); + pm_enter_disable_irq(M_WAKEUP_IRQN); + lpc_forbid_deepsleep(); + pm_core_resume(); + pm_dev_resume(); + } +#else + pm_sleep_prepare(PM_SLEEP_DS); + lpc_allow_deepsleep(); + pm_enter_wfi(); + lpc_forbid_deepsleep(); +#endif +#ifndef FT_SINGLE_UART + uint16_t status = pmu_lpm_wakeup_get_status(LPM_EVT_ACTION, PMU_LPM_MCPU_UART_H1_RX_WAKEUP); +#else + uint16_t status = pmu_lpm_wakeup_get_status(LPM_EVT_ACTION, PMU_LPM_MCPU_UART_H0_RX_WAKEUP); +#endif + if (status != 0) { + pm_wkup_event_by_uart_callback(); + } + pm_wkup_prepare(PM_SLEEP_DS); + pm_sleep_info_record(SLP_INFO_DEEPSLEEP); + reg16_setbit(0x520003e4, 0x3); // open mdam clock after deepsleep +} + +sleep_info_t *pm_get_sleep_info(void) +{ + return &g_sleep_info; +} + +void pm_enter_sleep(uint32_t sleep_ms_val) +{ + uint32_t status; + uint32_t sleep_ms = sleep_ms_val; + uint32_t rtc_times = 0; + uint32_t rtc_times_alert = 0; + if ((g_pm_mcu_dynamic_power_flag == 1) || hal_ipc_get_core_clr_sts(CORES_BT_CORE)) { + return; + } + if (sleep_ms == 0) { + return; + } + uapi_rtc_get_current_time_us(0, &rtc_times); + if (rtc_times > PM_RTC_CUR_ALERT_US) { + rtc_times_alert = rtc_times; + rtc_times = rtc_porting_cycle_2_us(readl(PM_RTC_LOAD_COUNT_REG)); + } + if (rtc_times < PM_OS_US_TO_MS && rtc_times > 0) { + return; + } + rtc_times /= PM_OS_US_TO_MS; + if (sleep_ms > rtc_times && rtc_times != 0) { + sleep_ms = rtc_times; + } + if (sleep_ms <= PM_SLEEP_THRESHOLD_WFI_ONLY_MS || pm_get_sleep_veto()) { + status = pm_os_irq_lock(); + pm_sleep_info_record(SLP_INFO_TIME_BASE); + pm_enter_wfi(); + pm_sleep_info_record(SLP_INFO_LIGHTSLEEP); + pm_os_irq_restore(status); + return; + } + + pm_sleep_info_record(SLP_INFO_TIME_BASE); + pm_sleep_info_record(SLP_INFO_VETO); + + pm_enter_deepsleep_set_flag(); + status = pm_os_irq_lock(); + if ((sleep_ms <= g_pm_sleep_threshold) || pm_get_sleep_veto() || readl(RTC_TIMER_INT_STATUS) == 1 || + ((readl(PM_RTC_LOAD_COUNT_REG) < PM_RTC_LOAD_THRESHOLD_MS) && (rtc_times_alert > PM_RTC_CUR_ALERT_US))) { + pm_enter_deepsleep_cancel_flag(); + pm_enter_light_sleep(); + } else { +#if CONFIG_PM_TICKLESS_EN == YES + pm_tickless_start(sleep_ms); +#endif + pm_enter_deep_sleep(); +#if CONFIG_PM_TICKLESS_EN == YES + pm_tickless_stop(sleep_ms); +#endif + } + pm_os_irq_restore(status); + pm_enter_deepsleep_cancel_flag(); +} + +void pm_set_sleep_threshold(uint16_t ms) +{ + if (ms < PM_SLEEP_THRESHOLD_WFI_ONLY_MS) { + return ; + } + g_pm_sleep_threshold = ms; +} + +void pm_set_mcu_dynamic_power_flag(uint8_t flag) +{ + g_pm_mcu_dynamic_power_flag = flag; +} + +void uapi_pm_enter_sleep(void) +{ + uint32_t sleep_ms = pm_os_get_sleep_ms(); + pm_enter_sleep(sleep_ms); +} diff --git a/sdk_release/v1.0/4gsdk_old/code/sdk/tools/pkg/chip_packet/brandy/packet.py b/sdk_release/v1.0/4gsdk_old/code/sdk/tools/pkg/chip_packet/brandy/packet.py new file mode 100644 index 000000000..e6ced840e --- /dev/null +++ b/sdk_release/v1.0/4gsdk_old/code/sdk/tools/pkg/chip_packet/brandy/packet.py @@ -0,0 +1,221 @@ +#!/usr/bin/env python3 +# encoding=utf-8 +# ============================================================================ +# @brief packet files +# ============================================================================ + +import os +import sys + +PY_PATH = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(PY_PATH) +PKG_DIR = os.path.dirname(PY_PATH) +PKG_DIR = os.path.dirname(PKG_DIR) +from packet_create import create_sha_file +from packet_create import packet_bin + +TOOLS_DIR = os.path.dirname(PKG_DIR) +SDK_DIR = os.path.dirname(TOOLS_DIR) +sys.path.append(os.path.join(SDK_DIR, "build", "script")) +sys.path.append(os.path.join(SDK_DIR, 'build', 'config')) +sys.path.append(os.path.join(SDK_DIR, "build", "script", "nv")) +from enviroment import TargetEnvironment +from param_packet import gen_flash_part_bin +from nv_binary import nv_begin + +# brandy packet +def build_brandy_other_bin(pack_style_str, flash_size): + ''' build brandy partition and nv ''' + chip_dir = os.path.join(SDK_DIR, "build", "config", "target_config", "brandy") + # 分区配置文件路径 + partition_cfg = os.path.join(chip_dir, "param_sector") + if flash_size.endswith("0x1000000"): + partition_cfg = os.path.join(partition_cfg, "param_sector_16M.json") + else: + partition_cfg = os.path.join(partition_cfg, "param_sector.json") + + partition_bin = os.path.join(SDK_DIR, "output", "brandy", "partition_table.bin") + # nv配置文件路径 + nv_config_json = os.path.join(chip_dir, "nv_bin_cfg") + if pack_style_str.endswith("-user"): + nv_config_json = os.path.join(nv_config_json, "mk_nv_bin_cfg_user.json") + else: + nv_config_json = os.path.join(nv_config_json, "mk_nv_bin_cfg_eng.json") + targets = ["acore"] + # 输出路径 + nv_output_path = os.path.join(SDK_DIR, "output", "brandy", "nv_bin") + + if not os.path.exists(nv_output_path): + os.makedirs(nv_output_path) + + gen_flash_part_bin(partition_cfg, partition_bin) + nv_begin(nv_config_json, targets, 0) + +def make_all_in_one_packet_8M(pack_style_str): + # make all in one packet + bin_dir = os.path.join(PKG_DIR, "bin", "brandy") + application_dir = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + pack_style_str) + recovery_target = "%s-r" % pack_style_str + recovery_target = recovery_target.replace('-user', '') + recovery_bin = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + recovery_target, + "recovery.bin") + recovery_bx = recovery_bin + "|0x70050000|0x40000|100" + + upload_app_fwpkg = os.path.join(PKG_DIR, "fwpkg", "brandy", "upload_app.fwpkg") + + ssb = os.path.join(SDK_DIR, "output", "brandy", "acore", "brandy-ssb", "ssb.bin") + if not os.path.exists(ssb): + ssb = os.path.join(bin_dir, "ssb.bin") + print("ssb_path: ", ssb) + ssb_bx = ssb + "|0x70000000|0x20000|0" + + partition = os.path.join(SDK_DIR, "output", "brandy", "partition_table.bin") + partition_bx = partition + "|0x7004F000|0x1000|100" + nv = os.path.join(SDK_DIR, "output", "brandy", "nv_bin", "brandy_all_nv.bin") + nv_bx = nv + "|0x707F9000|0x4000|100" + + app = os.path.join(application_dir, "application.bin") + app_bx = app + "|0x702B0000|0x549000|18" + + bt = os.path.join(bin_dir, "bt.bin") + bt_bx = bt + "|0x70090000|0x70000|20" + + target_env = TargetEnvironment(pack_style_str) + dsp_version = target_env.get("dsp_version") + dsp_main = os.path.join(bin_dir, "dsp", dsp_version, "dsp_main.bin") + dsp_main_bx = dsp_main + "|0x70100000|0x70000|22" + dsp_overlay = os.path.join(bin_dir, "dsp", dsp_version, "dsp_overlay.bin") + dsp_overlay_bx = dsp_overlay + "|0x70170000|0x140000|26" + + fs = os.path.join(application_dir, "file.bin") + fs_bx = fs + "|0xFFFFFFFF|0xFFFFFFFF|101" + + try: + packet_post_agvs = list() + packet_post_agvs.append(ssb_bx) + packet_post_agvs.append(partition_bx) + packet_post_agvs.append(app_bx) + packet_post_agvs.append(recovery_bx) + packet_post_agvs.append(bt_bx) + packet_post_agvs.append(dsp_main_bx) + packet_post_agvs.append(dsp_overlay_bx) + packet_post_agvs.append(nv_bx) + packet_post_agvs.append(fs_bx) + packet_bin(upload_app_fwpkg, packet_post_agvs) + except Exception as e: + print(e) + exit(-1) + +def make_all_in_one_packet_16M(pack_style_str): + # make all in one packet + bin_dir = os.path.join(PKG_DIR, "bin", "brandy") + application_dir = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + pack_style_str) + recovery_target = "%s-r" % pack_style_str + recovery_target = recovery_target.replace('-user', '') + recovery_bin = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + recovery_target, + "recovery.bin") + recovery_bx = recovery_bin + "|0x70B80000|0x100000|100" + + upload_app_fwpkg = os.path.join(PKG_DIR, "fwpkg", "brandy", "upload_app.fwpkg") + + ssb = os.path.join(SDK_DIR, "output", "brandy", "acore", "brandy-ssb", "ssb.bin") + if not os.path.exists(ssb): + ssb = os.path.join(bin_dir, "ssb.bin") + print("ssb_path: ", ssb) + ssb_bx = ssb + "|0x70000000|0x20000|0" + + partition = os.path.join(SDK_DIR, "output", "brandy", "partition_table.bin") + partition_bx = partition + "|0x7004F000|0x1000|100" + nv = os.path.join(SDK_DIR, "output", "brandy", "nv_bin", "brandy_all_nv.bin") + nv_bx = nv + "|0x70C80000|0x4000|100" + + app = os.path.join(application_dir, "application.bin") + app_bx = app + "|0x70380000|0x800000|18" + + bt = os.path.join(bin_dir, "bt.bin") + bt_bx = bt + "|0x70090000|0x70000|20" + + target_env = TargetEnvironment(pack_style_str) + dsp_version = target_env.get("dsp_version") + dsp_main = os.path.join(bin_dir, "dsp", dsp_version, "dsp_main.bin") + dsp_main_bx = dsp_main + "|0x70100000|0xC0000|22" + dsp_overlay = os.path.join(bin_dir, "dsp", dsp_version, "dsp_overlay.bin") + dsp_overlay_bx = dsp_overlay + "|0x701C0000|0x1C0000|26" + + fs = os.path.join(application_dir, "file.bin") + fs_bx = fs + "|0xFFFFFFFF|0xFFFFFFFF|101" + + try: + packet_post_agvs = list() + packet_post_agvs.append(ssb_bx) + packet_post_agvs.append(partition_bx) + packet_post_agvs.append(app_bx) + packet_post_agvs.append(recovery_bx) + packet_post_agvs.append(bt_bx) + packet_post_agvs.append(dsp_main_bx) + packet_post_agvs.append(dsp_overlay_bx) + packet_post_agvs.append(nv_bx) + packet_post_agvs.append(fs_bx) + packet_bin(upload_app_fwpkg, packet_post_agvs) + except Exception as e: + print(e) + exit(-1) + + +def make_all_in_one_packet(pack_style_str, flash_size): + # make all in one packet + build_brandy_other_bin(pack_style_str, flash_size) + if flash_size.endswith("0x1000000"): + make_all_in_one_packet_16M(pack_style_str) + else: + make_all_in_one_packet_8M(pack_style_str) + +def is_packing_files_exist(soc, pack_style_str): + """ + 判断打包文件是否存在 + :return: + """ + packing_files = get_packing_files(soc, pack_style_str) + lost_files = list() + for f_path in packing_files: + if not os.path.isfile(f_path): + lost_files.append(f_path) + return lost_files + +def get_packing_files(soc, pack_style_str): + """ + 直接添加需要打包的文件路径 + :return: + """ + packing_files = list() + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "ssb.bin")) + application_path = os.path.join(SDK_DIR, + "output", + "brandy", + "acore", + pack_style_str, + "application.bin") + packing_files.append(application_path) + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "bt.bin")) + + target_env = TargetEnvironment(pack_style_str) + dsp_version = target_env.get("dsp_version") + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "dsp", dsp_version, "dsp_main.bin")) + packing_files.append(os.path.join(PKG_DIR, "bin", "brandy", "dsp", dsp_version, "dsp_overlay.bin")) + return packing_files