[update] misc update

* update fatfs buffer to align64
* update usb cdc and hid callback api
* fix shell arg num
* update libc for snprintf & sprintf
* update mbedtls demo to use hw acc
* update wifi demo, add https and mqtt demo
This commit is contained in:
jzlv 2023-06-14 15:55:48 +08:00
parent eb2e935c71
commit ad08280d1c
82 changed files with 3758 additions and 552 deletions

View File

@ -105,7 +105,7 @@ __attribute__((section(".fw_header"))) struct bootheader_t fw_header = {
.boot_cfg.bval.aes_region_lock = 0x0, /* [11] aes region lock */
.boot_cfg.bval.cache_way_disable = 0x3, /* [15: 12] cache way disable info*/
.boot_cfg.bval.crc_ignore = 0x1, /* [16] ignore crc */
.boot_cfg.bval.hash_ignore = 0x1, /* [17] hash crc */
.boot_cfg.bval.hash_ignore = 0x0, /* [17] hash crc */
.boot_cfg.bval.halt_ap = 0x0, /* [18] halt ap */
.boot_cfg.bval.rsvd19_31 = 0x0, /* [31:19] rsvd */

View File

@ -272,7 +272,10 @@ void board_init(void)
#if (defined(CONFIG_LUA) || defined(CONFIG_BFLOG) || defined(CONFIG_FATFS))
rtc = bflb_device_get_by_name("rtc");
#endif
#ifdef CONFIG_MBEDTLS
extern void bflb_sec_mutex_init(void);
bflb_sec_mutex_init();
#endif
bflb_irq_restore(flag);
}
@ -577,4 +580,5 @@ static void reboot_cmd(int argc, char **argv)
GLB_SW_POR_Reset();
}
SHELL_CMD_EXPORT_ALIAS(reboot_cmd, reboot, reboot);
#endif

View File

@ -53,6 +53,15 @@
#define LCD_COLOR_DEPTH ILI9341_DBI_COLOR_DEPTH
#define _LCD_FUNC_DEFINE(_func, ...) ili9341_dbi_##_func(__VA_ARGS__)
#elif defined LCD_DBI_NT35510
#include "mipi_dbi/nt35510_dbi.h"
#define LCD_INTERFACE_TYPE LCD_INTERFACE_DBI
#define LCD_W NT35510_DBI_W
#define LCD_H NT35510_DBI_H
#define LCD_COLOR_DEPTH NT35510_DBI_COLOR_DEPTH
#define _LCD_FUNC_DEFINE(_func, ...) nt35510_dbi_##_func(__VA_ARGS__)
#elif defined LCD_DISP_QSPI_GC9C01
#include "disp_qspi/gc9c01_disp_qspi.h"
@ -143,7 +152,7 @@
#define LCD_COLOR_DEPTH ST7789V_SPI_COLOR_DEPTH
#define _LCD_FUNC_DEFINE(_func, ...) st7789v_spi_##_func(__VA_ARGS__)
#elif
#else
#error "Please select a screen type"
#endif

View File

@ -16,6 +16,8 @@
mipi dbi interface
LCD_DBI_ILI9488
LCD_DBI_ILI9341
LCD_DBI_NT35510
mipi dpi (RGB) interface
LCD_DPI_ILI9488
@ -101,6 +103,40 @@
*/
#define ILI9341_DBI_COLOR_REVERSAL 0
/* dbi ili9341 config */
#elif defined LCD_DBI_NT35510
/* Selecting interface type, more configuration of peripherals comes later
1: DBI peripheral, supported functions: typeB-x8(8080); (support chips: bl616, bl606p, bl808),
*/
#define LCD_DBI_INTERFACE_TYPE 1
/* enable the lcd reset function
0: Does not care about lcd hard reset
1: use gpio to reset the lcd
*/
#define LCD_RESET_EN 1
/* Selecting pixel format
1: rgb565 (16-bit, output rgb565)
2: nrgb8888 (32-bit, output rgb888)
*/
#define NT35510_DBI_PIXEL_FORMAT 2
/* NT35510 LCD width and height */
#define NT35510_DBI_W 480
#define NT35510_DBI_H 800
/* The offset of the area can be displayed */
#define NT35510_DBI_OFFSET_X 0
#define NT35510_DBI_OFFSET_Y 0
/* Color reversal, Some screens are required
0: disable
1: enable
*/
#define NT35510_DBI_COLOR_REVERSAL 0
#endif
/* dpi gc9503v config */

View File

@ -132,27 +132,27 @@ int st7789v_spi_set_dir(uint8_t dir, uint8_t mir_flag)
switch (dir) {
case 0:
if (!mir_flag)
param = 0x08;
param = 0x00;
else
param = 0x48;
param = 0x40;
break;
case 1:
if (!mir_flag)
param = 0x28;
param = 0x20;
else
param = 0xA8;
param = 0xA0;
break;
case 2:
if (!mir_flag)
param = 0x88;
param = 0x80;
else
param = 0xC8;
param = 0xC0;
break;
case 3:
if (!mir_flag)
param = 0xE8;
param = 0xE0;
else
param = 0x68;
param = 0x60;
break;
default:

View File

@ -1,2 +1,3 @@
sdk_add_subdirectory_ifdef(CONFIG_FATFS fatfs)
sdk_add_subdirectory_ifdef(CONFIG_LITTLEFS littlefs)
sdk_add_subdirectory_ifdef(CONFIG_ROMFS romfs)

View File

@ -160,8 +160,8 @@ typedef struct {
#if FF_FS_EXFAT
LBA_t bitbase; /* Allocation bitmap base sector */
#endif
LBA_t winsect; /* Current sector appearing in the win[] */
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
LBA_t winsect; /* Current sector appearing in the win[] */
BYTE __attribute__((aligned(64))) win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
} FATFS;
/* Object ID and allocation information (FFOBJID) */
@ -202,7 +202,7 @@ typedef struct {
DWORD *cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
#endif
#if !FF_FS_TINY
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
BYTE __attribute__((aligned(64))) buf[FF_MAX_SS]; /* File private data read/write window */
#endif
} FIL;
@ -367,27 +367,27 @@ void ff_mutex_give(int vol); /* Unlock sync object */
#define FA_OPEN_APPEND 0x30
/* Fast seek controls (2nd argument of f_lseek) */
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
/* Format options (2nd argument of f_mkfs) */
#define FM_FAT 0x01
#define FM_FAT32 0x02
#define FM_EXFAT 0x04
#define FM_ANY 0x07
#define FM_SFD 0x08
#define FM_FAT 0x01
#define FM_FAT32 0x02
#define FM_EXFAT 0x04
#define FM_ANY 0x07
#define FM_SFD 0x08
/* Filesystem type (FATFS.fs_type) */
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
#define FS_EXFAT 4
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
#define FS_EXFAT 4
/* File attribute bits for directory entry (FILINFO.fattrib) */
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
#ifdef __cplusplus
}

View File

@ -62,8 +62,15 @@ int MMC_disk_read(BYTE *buff, LBA_t sector, UINT count)
int MMC_disk_write(const BYTE *buff, LBA_t sector, UINT count)
{
if (SD_OK == SDH_WriteMultiBlocks((uint8_t *)buff, sector, gSDCardInfo.blockSize, count)) {
status_t ret;
_retry:
ret = SDH_WriteMultiBlocks((uint8_t *)buff, sector, gSDCardInfo.blockSize, count);
if (Status_Success == ret) {
return 0;
} else if (Status_Timeout == ret) {
goto _retry;
} else {
return -1;
}

View File

@ -93,6 +93,8 @@ sdk_library_add_sources(snprintf.c)
sdk_library_add_sources(sprintf.c)
sdk_library_add_sources(vsprintf.c)
sdk_library_add_sources(printf.c)
sdk_add_link_options(-Wl,-wrap,snprintf -Wl,-wrap,sprintf)
endif()
# vsnprintf %f %F

View File

@ -14,7 +14,7 @@
*
* @return The number of characters actually written to buffer.
*/
int snprintf(char *__restrict buf, size_t size, const char *__restrict fmt, ...)
int __wrap_snprintf(char *__restrict buf, size_t size, const char *__restrict fmt, ...)
{
int n;
va_list args;

View File

@ -12,7 +12,7 @@
*
* @return The number of characters actually written to buffer.
*/
int sprintf(char *buf, const char *format, ...)
int __wrap_sprintf(char *buf, const char *format, ...)
{
int32_t n;
va_list arg_ptr;

View File

@ -183,6 +183,24 @@ void *calloc(size_t size, size_t len)
return bflb_calloc(PMEM_HEAP, size, len);
}
/****************************************************************************
* Name: kcalloc
*
* Description:
* Allocate and zero memory from the user heap.
*
* Input Parameters:
* size - Size (in bytes) of the memory region to be allocated.
*
* Returned Value:
* The address of the allocated memory (NULL on failure to allocate)
*
****************************************************************************/
void *kcalloc(size_t size, size_t len)
{
return bflb_calloc(KMEM_HEAP, size, len);
}
/****************************************************************************
* Name: memalign
*

View File

@ -97,6 +97,7 @@ EXTERN struct mem_heap_s g_pmemheap;
void kmem_init(void *heapstart, size_t heapsize);
void *kmalloc(size_t size);
void *kcalloc(size_t size, size_t len);
void kfree(void *addr);
uint32_t kfree_size(void);

View File

@ -3,9 +3,10 @@
#include "semphr.h"
#include "ring_buffer.h"
#include "bflb_uart.h"
#include "mem.h"
static int shell_exec_argc;
static char *shell_exec_argv[SHELL_ARG_NUM];
static char *shell_exec_argv[SHELL_ARG_NUM+1];
static char shell_exec_line[SHELL_CMD_SIZE];
static ptrdiff_t shell_exec_line_diff;
TaskHandle_t shell_exec_handle;
@ -48,6 +49,7 @@ int shell_start_exec(cmd_function_t func, int argc, char *argv[])
for (uint8_t i = 0; i < argc; i++) {
shell_exec_argv[i] = argv[i] + shell_exec_line_diff;
}
shell_exec_argv[argc] = NULL;
__ASM volatile("fence");
xReturned = xTaskCreate(shell_exec_task, (char *)"shell_exec_task", SHELL_EXEC_THREAD_STACK_SIZE, func, SHELL_EXEC_THREAD_PRIO, &shell_exec_handle);
@ -77,7 +79,7 @@ void shell_release_sem(void)
}
}
static struct bflb_device_s *uart_shell;
struct bflb_device_s *uart_shell;
void uart_shell_isr(int irq, void *arg)
{
@ -155,6 +157,7 @@ static void ps_cmd(int argc, char **argv)
}
strcpy(pcWriteBuffer, pcHeader);
vTaskList(pcWriteBuffer + strlen(pcHeader));
printf("\r\n");
printf(info);
free(info);

View File

@ -334,7 +334,7 @@ struct cdc_ecm_descriptor {
0x04, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \
0x02, /* bmCapabilities */ \
0x06, /* bmCapabilities */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \

View File

@ -46,10 +46,11 @@ static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setu
line_coding.bDataBits,
parity_name[line_coding.bParityType],
stop_name[line_coding.bCharFormat]);
usbd_cdc_acm_set_line_coding(intf_num, &line_coding);
break;
case CDC_REQUEST_SET_CONTROL_LINE_STATE: {
case CDC_REQUEST_SET_CONTROL_LINE_STATE:
dtr = (setup->wValue & 0x0001);
rts = (setup->wValue & 0x0002);
USB_LOG_DBG("Set intf:%d DTR 0x%x,RTS 0x%x\r\n",
@ -58,7 +59,7 @@ static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setu
rts);
usbd_cdc_acm_set_dtr(intf_num, dtr);
usbd_cdc_acm_set_rts(intf_num, rts);
} break;
break;
case CDC_REQUEST_GET_LINE_CODING:
usbd_cdc_acm_get_line_coding(intf_num, &line_coding);
@ -71,7 +72,9 @@ static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setu
line_coding.bParityType,
line_coding.bDataBits);
break;
case CDC_REQUEST_SEND_BREAK:
USB_LOG_DBG("send break\r\n");
break;
default:
USB_LOG_WRN("Unhandled CDC Class bRequest 0x%02x\r\n", setup->bRequest);
return -1;

View File

@ -17,7 +17,7 @@ static int hid_class_interface_request_handler(struct usb_setup_packet *setup, u
switch (setup->bRequest) {
case HID_REQUEST_GET_REPORT:
/* report id ,report type */
usbh_hid_get_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), data, len);
usbh_hid_get_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), data, len);
break;
case HID_REQUEST_GET_IDLE:
(*data)[0] = usbh_hid_get_idle(intf_num, LO_BYTE(setup->wValue));
@ -60,9 +60,10 @@ struct usbd_interface *usbd_hid_init_intf(struct usbd_interface *intf, const uin
return intf;
}
__WEAK uint8_t usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **report, uint32_t *len)
__WEAK void usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len)
{
return 0;
(*data[0]) = 0;
*len = 1;
}
__WEAK uint8_t usbh_hid_get_idle(uint8_t intf, uint8_t report_id)
@ -75,7 +76,7 @@ __WEAK uint8_t usbh_hid_get_protocol(uint8_t intf)
return 0;
}
__WEAK void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint16_t report_len)
__WEAK void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len)
{
}

View File

@ -20,10 +20,10 @@ void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc);
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len);
/* Setup request command callback api */
uint8_t usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **report, uint32_t *len);
void usbh_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len);
uint8_t usbh_hid_get_idle(uint8_t intf, uint8_t report_id);
uint8_t usbh_hid_get_protocol(uint8_t intf);
void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint16_t report_len);
void usbh_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len);
void usbh_hid_set_idle(uint8_t intf, uint8_t report_id, uint8_t duration);
void usbh_hid_set_protocol(uint8_t intf, uint8_t protocol);

View File

@ -39,7 +39,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_cfg_priv {
uint16_t scsi_blk_size;
uint32_t scsi_blk_nbr;
uint8_t block_buffer[CONFIG_USBDEV_MSC_BLOCK_SIZE];
USB_MEM_ALIGNX uint8_t block_buffer[CONFIG_USBDEV_MSC_BLOCK_SIZE];
} usbd_msc_cfg;
static void usbd_msc_reset(void)

View File

@ -24,6 +24,10 @@
#ifndef _BFLB_BLOCK_POOL_H
#define _BFLB_BLOCK_POOL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#define BFLB_BLOCK_POOL_ALIGN_1 0x00
@ -61,4 +65,8 @@ extern int bflb_block_pool_free(bflb_block_pool_t *blk_pool, void *addr);
extern void bflb_block_pool_info_get(bflb_block_pool_t *blk_pool, uint32_t *total_blk, uint32_t *free_blk);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -152,7 +152,16 @@
/**
* @}
*/
#if defined(CONFIG_LOG_NCOLOR) && CONFIG_LOG_NCOLOR
static char *bflog_color_strings[6] = {
"",
"",
"",
"",
"",
""
};
#else
static char *bflog_color_strings[6] = {
BFLOG_COLOR_START BFLOG_COLOR_RESET BFLOG_COLOR_FATAL BFLOG_COLOR_END,
BFLOG_COLOR_START BFLOG_COLOR_RESET BFLOG_COLOR_ERROR BFLOG_COLOR_END,
@ -161,6 +170,7 @@ static char *bflog_color_strings[6] = {
BFLOG_COLOR_START BFLOG_COLOR_RESET BFLOG_COLOR_DEBUG BFLOG_COLOR_END,
BFLOG_COLOR_START BFLOG_COLOR_RESET BFLOG_COLOR_TRACE BFLOG_COLOR_END
};
#endif
static char *bflog_level_strings[6] = {
BFLOG_LEVEL_FATAL_STRING,

View File

@ -147,21 +147,6 @@
#define BFLOG_COLOR_TRACE BFLOG_COLOR_FG_WHITE BFLOG_COLOR_BG_NONE BFLOG_SGR_FAINT
#endif
#if defined(CONFIG_LOG_NCOLOR) && CONFIG_LOG_NCOLOR
#undef BFLOG_COLOR_FATAL
#undef BFLOG_COLOR_ERROR
#undef BFLOG_COLOR_WARN
#undef BFLOG_COLOR_INFO
#undef BFLOG_COLOR_DEBUG
#undef BFLOG_COLOR_TRACE
#define BFLOG_COLOR_FATAL BFLOG_COLOR_FG_NONE BFLOG_COLOR_BG_NONE BFLOG_COLOR_DEFAULT
#define BFLOG_COLOR_ERROR BFLOG_COLOR_FG_NONE BFLOG_COLOR_BG_NONE BFLOG_COLOR_DEFAULT
#define BFLOG_COLOR_WARN BFLOG_COLOR_FG_NONE BFLOG_COLOR_BG_NONE BFLOG_COLOR_DEFAULT
#define BFLOG_COLOR_INFO BFLOG_COLOR_FG_NONE BFLOG_COLOR_BG_NONE BFLOG_COLOR_DEFAULT
#define BFLOG_COLOR_DEBUG BFLOG_COLOR_FG_NONE BFLOG_COLOR_BG_NONE BFLOG_COLOR_DEFAULT
#define BFLOG_COLOR_TRACE BFLOG_COLOR_FG_NONE BFLOG_COLOR_BG_NONE BFLOG_COLOR_DEFAULT
#endif
/**
* @}
*/
@ -408,7 +393,7 @@ struct _bflog_msg {
};
};
uint32_t time; /*!< rtc timestamp */
uint32_t time; /*!< rtc timestamp */
union {
uint64_t clk; /*!< cpu clock tick */
struct

View File

@ -12,6 +12,14 @@ BFLOG_DEFINE_TAG(SVC_LOG, DBG_TAG, true);
#undef BFLOG_TAG
#define BFLOG_TAG BFLOG_GET_TAG(SVC_LOG)
#ifndef LOG_THREAD_PRIO
#define LOG_THREAD_PRIO 3
#endif
#ifndef LOG_THREAD_STACK_SIZE
#define LOG_THREAD_STACK_SIZE 1024
#endif
/* flush notice ------------------------------------------------------------------*/
static EventGroupHandle_t event_group_server_log_flush_notice;
@ -151,10 +159,10 @@ void log_restart(void)
/*!< create flush task */
_ASSERT_FUNC(pdPASS == xTaskCreate(
/*!< task function */ task_function_log,
/*!< task name */ "LOG",
/*!< stack size */ 4096,
/*!< task name */ DBG_TAG,
/*!< stack size */ LOG_THREAD_STACK_SIZE,
/*!< task param */ NULL,
/*!< task priority */ 8,
/*!< task priority */ LOG_THREAD_PRIO,
/*!< task handle */ &task_log));
LOG_I("log restart success\r\n");

View File

@ -254,7 +254,7 @@ if("${CHIP}" STREQUAL "bl702l")
endif()
# ifeq ($(CONFIG_CHIP_NAME),BL616)
if("${CHIP}" STREQUAL "bl616")
if(("${CHIP}" STREQUAL "bl616") OR ("${CHIP}" STREQUAL "bl808"))
# ifeq ($(PRIV_CONFIG_GEN_BLE),ble1m0s1bredr0)
# CONFIG_BT_BREDR := 0
# CONFIG_EM_SIZE := 32
@ -592,6 +592,9 @@ endif()
# CONFIG_LONG_RANG ?= 1
# CONFIG_LE_PWR_CTRL ?= 1
# CONFIG_CTE ?= 1
# CONFIG_PHY_UPDATE ?= 1
# CONFIG_CLK_ACC ?= 1
# CONFIG_LE_PING ?= 1
# CONFIG_BLE_ACT_MAX ?= 5
sdk_ifndef(CONFIG_BT 1)
sdk_ifndef(CONFIG_SCO_ESCO 1)
@ -611,6 +614,9 @@ sdk_ifndef(CONFIG_BIS 1)
sdk_ifndef(CONFIG_LONG_RANG 1)
sdk_ifndef(CONFIG_LE_PWR_CTRL 1)
sdk_ifndef(CONFIG_CTE 1)
sdk_ifndef(CONFIG_PHY_UPDATE 1)
sdk_ifndef(CONFIG_LE_PING 1)
sdk_ifndef(CONFIG_CLK_ACC 1)
sdk_ifndef(CONFIG_BLE_ACT_MAX 5)
# ADD

View File

@ -362,6 +362,9 @@ CONFIG_BIS ?= 1
CONFIG_LONG_RANG ?= 1
CONFIG_LE_PWR_CTRL ?= 1
CONFIG_CTE ?= 1
CONFIG_PHY_UPDATE ?= 1
CONFIG_CLK_ACC ?= 1
CONFIG_LE_PING ?= 1
#Update le adv data and scan rsp data when LE adertising is active, sw need 4 adv buffer at least.
CONFIG_BLE_ACT_MAX ?= 7

View File

@ -74,7 +74,7 @@ static struct {
.dst = BT_MESH_ADDR_UNASSIGNED,
};
#if defined(BL602) || defined(BL702) || defined(BL606P) || defined(BL616)
#if defined(BL602) || defined(BL702) || defined(BL606P) || defined(BL616) || defined(BL808)
#define vOutputString(...) printf(__VA_ARGS__)
#else
#define vOutputString(...) bl_print(SYSTEM_UART_ID, PRINT_MODULE_CLI, __VA_ARGS__)

View File

@ -51,7 +51,7 @@ sdk_add_include_directories(
src/common/include
src/common/include/zephyr
src/common/include/misc
src/common/include/toolchain
# src/common/include/toolchain
src/common/tinycrypt/include/tinycrypt
src/hci_onchip
src/bl_hci_wrapper

View File

@ -4,11 +4,18 @@ sdk_add_static_library(lib/libwifi6.a)
add_subdirectory(bl6_os_adapter)
sdk_add_compile_definitions(-DPLATFORM_PRIVDE_ERRNO)
# Enable common section for wifi6
sdk_add_compile_options(-fcommon)
# disable undef warning
sdk_add_compile_options(-Wno-undef)
set(CONFIG_VIF_MAX 2)
set(CONFIG_STA_MAX 4)
set(CONFIG_MAC_TXQ_DEPTH 16)
set(CONFIG_MAC_RXQ_DEPTH 12)
sdk_add_compile_definitions(-DCONFIG_VIF_MAX=${CONFIG_VIF_MAX})
sdk_add_compile_definitions(-DCONFIG_STA_MAX=${CONFIG_STA_MAX})
sdk_add_compile_definitions(-DCONFIG_MAC_TXQ_DEPTH=${CONFIG_MAC_TXQ_DEPTH})
sdk_add_compile_definitions(-DCONFIG_MAC_RXQ_DEPTH=${CONFIG_MAC_RXQ_DEPTH})

View File

@ -11,4 +11,5 @@ set(CONFIG_BFLOG 0)
#set(CONFIG_LOG_DISABLE 0)
#set(CONFIG_ASSERT_DISABLE 0)
#set(CONFIG_LOG_LEVEL 3)
#set(CONFIG_LOG_POOL_SIZE 1024)
#set(CONFIG_LOG_POOL_SIZE 1024)
#set(CONFIG_LOG_NCOLOR 0)

View File

@ -4,17 +4,421 @@
#include "mbedtls/sha1.h"
#include "mbedtls/sha256.h"
#include "mbedtls/sha512.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/platform.h"
#include "mbedtls/ecdsa.h"
#include "mbedtls/ecdh.h"
const uint8_t key[32] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
};
uint8_t aes_iv[16] = { 0 };
__attribute__((aligned(32))) uint8_t aes_input_buf[16 * 1024];
__attribute__((aligned(32))) uint8_t aes_enc_buf[16 * 1024];
__attribute__((aligned(32))) uint8_t aes_dec_buf[16 * 1024];
__attribute__((aligned(32))) uint8_t sha_input_buf[16 * 1024]; /* input addr must be align 32 */
uint8_t sha_output_buf[128];
void mbedtls_check(uint32_t j)
{
for (uint32_t i = 0; i < 16 * j; i++) {
if (aes_dec_buf[i] != aes_input_buf[i]) {
printf("mbedtls test fail\r\n");
while (1) {
}
}
}
}
#define assert_exit(cond, ret) \
do { \
if (!(cond)) { \
printf(" !. assert: failed [line: %d, error: -0x%04X]\n", __LINE__, -ret); \
goto cleanup; \
} \
} while (0)
/*
static int entropy_source(void *data, uint8_t *output, size_t len, size_t *olen)
{
uint32_t seed;
seed = sys_rand32_get();
if (len > sizeof(seed)) {
len = sizeof(seed);
}
memcpy(output, &seed, len);
*olen = len;
return 0;
}*/
static void dump_buf(char *info, uint8_t *buf, uint32_t len)
{
mbedtls_printf("%s", info);
for (int i = 0; i < len; i++) {
mbedtls_printf("%s%02X%s", i % 16 == 0 ? "\n " : " ",
buf[i], i == len - 1 ? "\n" : "");
}
}
void mbedtls_ecdh_test(void)
{
int ret = 0;
size_t olen;
uint8_t buf[65];
mbedtls_ecp_group grp;
mbedtls_mpi cli_secret, srv_secret;
mbedtls_mpi cli_pri, srv_pri;
mbedtls_ecp_point cli_pub, srv_pub;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
const char *pers = "simple_ecdh";
uint32_t start_time;
mbedtls_mpi_init(&cli_pri); //
mbedtls_mpi_init(&srv_pri);
mbedtls_mpi_init(&cli_secret);
mbedtls_mpi_init(&srv_secret);
mbedtls_ecp_group_init(&grp); //初始化椭圆曲线群结构体
mbedtls_ecp_point_init(&cli_pub); //初始化椭圆曲线点结构体 cli
mbedtls_ecp_point_init(&srv_pub); //初始化椭圆曲线点结构体 srv
mbedtls_entropy_init(&entropy); //初始化熵结构体
mbedtls_ctr_drbg_init(&ctr_drbg); //初始化随机数结构体
/*
mbedtls_entropy_add_source(&entropy, entropy_source, NULL,
MBEDTLS_ENTROPY_MAX_GATHER, MBEDTLS_ENTROPY_SOURCE_STRONG);*/
mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
pers, strlen(pers));
mbedtls_printf("setup rng ... ok\r\n");
//加载椭圆曲线选择SECP256R1
ret = mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_SECP256R1);
mbedtls_printf("select ecp group SECP256R1 ... ok\r\n");
//cli生成公开参数
start_time = bflb_mtimer_get_time_ms();
ret = mbedtls_ecdh_gen_public(&grp, //椭圆曲线结构体
&cli_pri, //输出cli私密参数d
&cli_pub, //输出cli公开参数Q
mbedtls_ctr_drbg_random, &ctr_drbg);
assert_exit(ret == 0, ret);
printf("Get public key time=%dms\r\n", (unsigned int)(bflb_mtimer_get_time_ms() - start_time));
mbedtls_ecp_point_write_binary(&grp, &cli_pub, //把cli的公开参数到处到buf中
MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf, sizeof(buf));
dump_buf("1. ecdh client generate public parameter:", buf, olen);
//srv生成公开参数
ret = mbedtls_ecdh_gen_public(&grp, //椭圆曲线结构体
&srv_pri, //输出srv私密参数d
&srv_pub, //输出srv公开参数Q
mbedtls_ctr_drbg_random, &ctr_drbg);
assert_exit(ret == 0, ret);
mbedtls_ecp_point_write_binary(&grp, &srv_pub, //把srv的公开参数导出到buf中
MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, buf, sizeof(buf));
dump_buf("2. ecdh server generate public parameter:", buf, olen);
//cli计算共享密钥
start_time = bflb_mtimer_get_time_ms();
ret = mbedtls_ecdh_compute_shared(&grp, //椭圆曲线结构体
&cli_secret, //cli计算出的共享密钥
&srv_pub, //输入srv公开参数Q
&cli_pri, //输入cli本身的私密参数d
mbedtls_ctr_drbg_random, &ctr_drbg);
assert_exit(ret == 0, ret);
printf("Get share key time=%dms\r\n", (unsigned int)(bflb_mtimer_get_time_ms() - start_time));
//把cli计算出的共享密钥导出buf中
mbedtls_mpi_write_binary(&cli_secret, buf, mbedtls_mpi_size(&cli_secret));
dump_buf("3. ecdh client generate secret:", buf, mbedtls_mpi_size(&cli_secret));
//srv计算共享密钥
ret = mbedtls_ecdh_compute_shared(&grp, //椭圆曲线结构体
&srv_secret, //srv计算出的共享密钥
&cli_pub, //输入cli公开参数Q
&srv_pri, //输入srv本身的私密参数d
mbedtls_ctr_drbg_random, &ctr_drbg);
assert_exit(ret == 0, ret);
//把srv计算出的共享密钥导出buf中
mbedtls_mpi_write_binary(&srv_secret, buf, mbedtls_mpi_size(&srv_secret));
dump_buf("4. ecdh server generate secret:", buf, mbedtls_mpi_size(&srv_secret));
//比较2个大数是否相等
ret = mbedtls_mpi_cmp_mpi(&cli_secret, &srv_secret);
assert_exit(ret == 0, ret);
mbedtls_printf(" 5. ecdh checking secrets ... ok\n");
cleanup:
mbedtls_mpi_free(&cli_pri);
mbedtls_mpi_free(&srv_pri);
mbedtls_mpi_free(&cli_secret);
mbedtls_mpi_free(&srv_secret);
mbedtls_ecp_group_free(&grp);
mbedtls_ecp_point_free(&cli_pub);
mbedtls_ecp_point_free(&srv_pub);
mbedtls_entropy_free(&entropy);
mbedtls_ctr_drbg_free(&ctr_drbg);
}
void mbedtls_ecdsa_test()
{
int ret = 0;
char buf[97];
uint8_t hash[32], msg[100];
uint8_t *pers = "simple_ecdsa";
size_t rlen, slen, qlen, dlen;
uint32_t start_time;
memset(msg, 0x12, sizeof(msg));
mbedtls_mpi r, s;
mbedtls_ecdsa_context ctx;
mbedtls_md_context_t md_ctx;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_mpi_init(&r);
mbedtls_mpi_init(&s);
mbedtls_ecdsa_init(&ctx); //初始化ECDSA结构体
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
/*
mbedtls_entropy_add_source(&entropy, entropy_source, NULL,
MBEDTLS_ENTROPY_MAX_GATHER, MBEDTLS_ENTROPY_SOURCE_STRONG);*/
ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
(const uint8_t *)pers, strlen(pers));
assert_exit(ret == 0, ret);
mbedtls_printf("setup rng ... ok\r\n");
mbedtls_md_init(&md_ctx);
mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), msg, sizeof(msg), hash);
mbedtls_printf("1. hash msg ... ok\n"); //计算出msg的hash值
//产生ECDSA密钥对
ret = mbedtls_ecdsa_genkey(&ctx, MBEDTLS_ECP_DP_SECP256R1, //选择SECP256R1
mbedtls_ctr_drbg_random, &ctr_drbg);
assert_exit(ret == 0, ret);
mbedtls_ecp_point_write_binary(&ctx.grp, &ctx.Q,
MBEDTLS_ECP_PF_UNCOMPRESSED, &qlen, buf, sizeof(buf));
dlen = mbedtls_mpi_size(&ctx.d);
mbedtls_mpi_write_binary(&ctx.d, buf + qlen, dlen);
dump_buf("2. ecdsa generate keypair:", buf, qlen + dlen);
//ECDSA签名得到r , s
start_time = bflb_mtimer_get_time_ms();
ret = mbedtls_ecdsa_sign(&ctx.grp, &r, &s, &ctx.d,
hash, sizeof(hash), mbedtls_ctr_drbg_random, &ctr_drbg);
assert_exit(ret == 0, ret);
printf("ECDSA sign time=%dms\r\n", (unsigned int)bflb_mtimer_get_time_ms() - start_time);
rlen = mbedtls_mpi_size(&r);
slen = mbedtls_mpi_size(&s);
mbedtls_mpi_write_binary(&r, buf, rlen);
mbedtls_mpi_write_binary(&s, buf + rlen, slen);
dump_buf("3. ecdsa generate signature:", buf, rlen + slen);
//ECDSA验签返回0表示验证成功
start_time = bflb_mtimer_get_time_ms();
ret = mbedtls_ecdsa_verify(&ctx.grp, hash, sizeof(hash), &ctx.Q, &r, &s);
assert_exit(ret == 0, ret);
printf("ECDSA verify time=%dms\r\n", (unsigned int)bflb_mtimer_get_time_ms() - start_time);
mbedtls_printf("4. ecdsa verify signature ... ok\r\n");
cleanup:
mbedtls_mpi_free(&r);
mbedtls_mpi_free(&s);
mbedtls_md_free(&md_ctx);
mbedtls_ecdsa_free(&ctx);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
}
void mbedtls_aes_test()
{
mbedtls_aes_context ctx;
uint64_t start_time;
size_t offset;
unsigned char stream_block[16];
for (uint32_t i = 0; i < 16 * 1024; i++) {
aes_input_buf[i] = i & 0xff;
}
mbedtls_aes_init(&ctx);
for (uint32_t i = 1; i <= 1; i++) {
printf("test aes ecb 128 \r\n");
mbedtls_aes_setkey_enc(&ctx, key, 128);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, aes_input_buf, aes_enc_buf);
printf("aes ecb 128 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_aes_setkey_dec(&ctx, key, 128);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_DECRYPT, aes_enc_buf, aes_dec_buf);
printf("aes ecb 128 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
printf("test aes ecb 192 \r\n");
mbedtls_aes_setkey_enc(&ctx, key, 192);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, aes_input_buf, aes_enc_buf);
printf("aes ecb 192 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_aes_setkey_dec(&ctx, key, 192);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_DECRYPT, aes_enc_buf, aes_dec_buf);
printf("aes ecb 192 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
printf("test aes ecb 256 \r\n");
mbedtls_aes_setkey_enc(&ctx, key, 256);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, aes_input_buf, aes_enc_buf);
printf("aes ecb 256 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_aes_setkey_dec(&ctx, key, 256);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_DECRYPT, aes_enc_buf, aes_dec_buf);
printf("aes ecb 256 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
}
for (uint32_t i = 1000; i <= 1000; i++) {
printf("test aes cbc 128 \r\n");
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 128);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 16 * i, aes_iv, aes_input_buf, aes_enc_buf);
printf("aes cbc 128 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_dec(&ctx, key, 128);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, 16 * i, aes_iv, aes_enc_buf, aes_dec_buf);
printf("aes cbc 128 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
printf("test aes cbc 192 \r\n");
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 192);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 16 * i, aes_iv, aes_input_buf, aes_enc_buf);
printf("aes cbc 192 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_dec(&ctx, key, 192);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, 16 * i, aes_iv, aes_enc_buf, aes_dec_buf);
printf("aes cbc 192 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
printf("test aes cbc 256 \r\n");
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 256);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, 16 * i, aes_iv, aes_input_buf, aes_enc_buf);
printf("aes cbc 256 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_dec(&ctx, key, 256);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, 16 * i, aes_iv, aes_enc_buf, aes_dec_buf);
printf("aes cbc 256 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
}
for (uint32_t i = 1000; i <= 1000; i++) {
printf("test aes ctr 128 \r\n");
offset = 0;
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 128);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ctr(&ctx, 16 * i, &offset, aes_iv, stream_block, aes_input_buf, aes_enc_buf);
printf("aes ctr 128 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
offset = 0;
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 128);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ctr(&ctx, 16 * i, &offset, aes_iv, stream_block, aes_enc_buf, aes_dec_buf);
printf("aes ctr 128 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
printf("test aes ctr 192 \r\n");
offset = 0;
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 192);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ctr(&ctx, 16 * i, &offset, aes_iv, stream_block, aes_input_buf, aes_enc_buf);
printf("aes ctr 192 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
offset = 0;
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 192);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ctr(&ctx, 16 * i, &offset, aes_iv, stream_block, aes_enc_buf, aes_dec_buf);
printf("aes ctr 192 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
printf("test aes ctr 256 \r\n");
offset = 0;
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 256);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ctr(&ctx, 16 * i, &offset, aes_iv, stream_block, aes_input_buf, aes_enc_buf);
printf("aes ctr 256 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
offset = 0;
memset(aes_iv, 0, 16);
mbedtls_aes_setkey_enc(&ctx, key, 256);
start_time = bflb_mtimer_get_time_us();
mbedtls_aes_crypt_ctr(&ctx, 16 * i, &offset, aes_iv, stream_block, aes_enc_buf, aes_dec_buf);
printf("aes ctr 256 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
mbedtls_check(i);
}
}
void mbedtls_sha_test()
{
uint64_t start_time;
for (uint32_t i = 0; i < 16 * 1024; i++) {
sha_input_buf[i] = i & 0xff;
}
for (uint32_t i = 1000; i <= 1000; i++) {
start_time = bflb_mtimer_get_time_us();
mbedtls_sha1(sha_input_buf, 16 * i, sha_output_buf);
printf("sha1 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
}
for (uint32_t i = 1000; i <= 1000; i++) {
start_time = bflb_mtimer_get_time_us();
mbedtls_sha256(sha_input_buf, 16 * i, sha_output_buf, 0);
printf("sha256 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
}
for (uint32_t i = 1000; i <= 1000; i++) {
start_time = bflb_mtimer_get_time_us();
mbedtls_sha512(sha_input_buf, 16 * i, sha_output_buf, 0);
printf("sha512 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
}
printf("mbedtls test success\r\n");
}
int main(void)
{
board_init();
mbedtls_aes_self_test(1);
mbedtls_sha1_self_test(1);
mbedtls_sha256_self_test(1);
mbedtls_sha512_self_test(1);
// mbedtls_aes_self_test(1);
// mbedtls_sha1_self_test(1);
// mbedtls_sha256_self_test(1);
// mbedtls_sha512_self_test(1);
printf("\r\n=========== ecdh test ================\r\n");
mbedtls_ecdh_test();
printf("\r\n=========== ecdsa test ================\r\n");
mbedtls_ecdsa_test();
printf("\r\n=========== aes test ================\r\n");
mbedtls_aes_test();
printf("\r\n=========== sha test ================\r\n");
mbedtls_sha_test();
printf("mbedtls test success\r\n");
while (1) {
bflb_mtimer_delay_ms(1000);
}

View File

@ -1,2 +1,9 @@
set(CONFIG_MBEDTLS 1)
set(CONFIG_MBEDTLS_SELF_TEST 1)
set(CONFIG_MBEDTLS_AES_USE_HW 1)
set(CONFIG_MBEDTLS_SHA1_USE_HW 1)
set(CONFIG_MBEDTLS_SHA256_USE_HW 1)
set(CONFIG_MBEDTLS_SHA512_USE_HW 1)
set(CONFIG_MBEDTLS_ECC_USE_HW 1)
set(CONFIG_MBEDTLS_BIGNUM_USE_HW 1)

View File

@ -11,7 +11,7 @@ static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src3_buffer[DMA_BUFFER_LENGTH];
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t dst1_buffer[DMA_BUFFER_LENGTH];
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t dst2_buffer[DMA_BUFFER_LENGTH];
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t dst3_buffer[DMA_BUFFER_LENGTH];
static uint8_t dma_tc_flag0 = 0;
static volatile uint8_t dma_tc_flag0 = 0;
struct bflb_device_s *dma0_ch0;

View File

@ -52,6 +52,9 @@ int bflb_spi_poll_test(uint32_t data_width)
/* send data */
for (uint16_t i = 0; i < BUFF_LEN / 4; i++) {
p_rx[i] = bflb_spi_poll_send(spi0, p_tx[i]);
#if (SPI_CASE_SELECT == SPI_MASTER_CASE)
bflb_mtimer_delay_us(10); /* delay for slave device prepare ok */
#endif
}
/* check data */

View File

@ -3,9 +3,8 @@
#include "board.h"
struct bflb_device_s *uartx;
static uint8_t uart_txbuf[128] = { 0 };
static uint8_t lse_int_flag = 0;
static volatile uint8_t lse_int_flag = 0;
void uart_isr(int irq, void *arg)
{
@ -35,17 +34,17 @@ int main(void)
cfg.tx_fifo_threshold = 7;
cfg.rx_fifo_threshold = 7;
bflb_uart_errint_mask(uartx, false);
bflb_irq_attach(uartx->irq_num, uart_isr, NULL);
bflb_irq_enable(uartx->irq_num);
/* lin config must enable before uart enable */
bflb_uart_feature_control(uartx, UART_CMD_SET_BREAK_VALUE, 4);
bflb_uart_feature_control(uartx, UART_CMD_SET_TX_LIN_VALUE, 1);
bflb_uart_feature_control(uartx, UART_CMD_SET_RX_LIN_VALUE, 1);
bflb_uart_init(uartx, &cfg);
bflb_uart_errint_mask(uartx, false);
bflb_irq_attach(uartx->irq_num, uart_isr, NULL);
bflb_irq_enable(uartx->irq_num);
bflb_uart_putchar(uartx, 0xff);
bflb_uart_putchar(uartx, 0x1);

View File

@ -1,22 +0,0 @@
# wifi6
## Support CHIP
| CHIP | Remark |
|:----------------:|:------:|
|BL616/BL618 | |
## Compile
- BL616/BL618
```
make CHIP=bl616 BOARD=bl616dk
```
## Flash
```
make flash COMX=xxx ## xxx is your com name
```

View File

@ -1,23 +0,0 @@
# Components
set(CONFIG_BFLOG 0)
set(CONFIG_FREERTOS 1)
set(CONFIG_POSIX 1)
set(CONFIG_TLSF 1)
set(CONFIG_SHELL 1)
set(CONFIG_LWIP 1)
set(CONFIG_WIFI6 1)
set(CONFIG_RF 1)
set(CONFIG_MBEDTLS 1)
# set(CONFIG_PSRAM 1)
set(CONFIG_DHCPD 1)
set(CONFIG_PING 1)
set(CONFIG_MQTT 1)
# Config
## mbedtls
set(CONFIG_MBEDTLS_AES_USE_HW 0)
set(CONFIG_MBEDTLS_BIGNUM_USE_HW 0)
set(CONFIG_MBEDTLS_ECC_USE_HW 0)
set(CONFIG_MBEDTLS_SHA1_USE_HW 0)
set(CONFIG_MBEDTLS_SHA256_USE_HW 0)
set(CONFIG_MBEDTLS_SHA512_USE_HW 0)

View File

@ -4,15 +4,14 @@ include(proj.conf)
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
# Define
# User
sdk_add_compile_definitions(-DCONFIG_CLI_CMD_ENABLE)
#sdk_add_compile_definitions(-DWIFI_DEMO_TEST)
#sdk_add_compile_definitions(-DBL616_DHCP_DEBUG)
target_sources(app PRIVATE
wifi_http_client.c
target_sources(app PRIVATE
wifi_http_client.c
)
sdk_add_include_directories(.)
sdk_set_main_file(main.c)

View File

@ -32,10 +32,6 @@
#ifndef LWIP_HDR_LWIPOPTS_H__
#define LWIP_HDR_LWIPOPTS_H__
#define RX_BUF_CNT 4
#define MAC_TXQ_DEPTH 16
#define MAC_RXQ_DEPTH 12
#define LWIP_NETIF_API 1
#define LWIP_DEBUG 1
#define LWIP_STATS_DISPLAY 1
@ -70,52 +66,31 @@
#define PBUF_LINK_ENCAPSULATION_HLEN 388
#define IP_REASS_MAX_PBUFS (RX_BUF_CNT - 2)
#define IP_REASS_MAX_PBUFS (2 * CONFIG_MAC_RXQ_DEPTH - 2)
#define MEMP_NUM_NETBUF 32
#define MEMP_NUM_NETCONN 16
#define MEMP_NUM_UDP_PCB 16
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define MAC_TXQ_DEPTH CONFIG_MAC_TXQ_DEPTH
#define MAC_RXQ_DEPTH CONFIG_MAC_RXQ_DEPTH
#if NX_BEACONING
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#else
#define TCP_SND_BUF (2 * MAC_TXQ_DEPTH * TCP_MSS)
#endif
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), \
(2 * TCP_MSS) + 1), \
(TCP_SND_BUF)-1)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1)
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#if NX_TG
#define MEM_MIN_TG 16384
#else
#define MEM_MIN_TG 0
#endif
#if MEM_MIN_TCP > MEM_MIN_TG
#define MEM_MIN MEM_MIN_TCP
#else
#define MEM_MIN MEM_MIN_TG
#endif
#define MEM_ALIGNMENT 4
#if defined(CFG_SDIOWIFI)
#undef MEM_MIN
#ifdef LP_APP
#define MEM_MIN (14 * 1024)
#else
#define MEM_MIN (48 * 1024)
#endif
#endif
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#define MEM_MIN MEM_MIN_TCP
#define MEM_ALIGNMENT 4
#ifdef LWIP_HEAP_SIZE
#define MEM_SIZE LWIP_HEAP_SIZE
@ -135,54 +110,19 @@
#define LWIP_TIMEVAL_PRIVATE 0 // use sys/time.h for struct timeval
//#define LWIP_PROVIDE_ERRNO
#ifndef PLATFORM_PRIVDE_ERRNO
#define LWIP_PROVIDE_ERRNO 1
#endif
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
extern int *__errno(void);
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#if 0
/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */
#define NO_SYS 0
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define SYS_LIGHTWEIGHT_PROT 0
#define LWIP_IPV6 1
#define IPV6_FRAG_COPYHEADER 1
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
/* Turn off checksum verification of fuzzed data */
#define CHECKSUM_CHECK_IP 0
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_TCP 0
#define CHECKSUM_CHECK_ICMP 0
#define CHECKSUM_CHECK_ICMP6 0
/* Minimal changes to opt.h required for tcp unit tests: */
#define MEM_SIZE 16000
#define TCP_SND_QUEUELEN 40
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#define TCP_SND_BUF (12 * TCP_MSS)
#define TCP_WND (10 * TCP_MSS)
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 0
#define PBUF_POOL_SIZE 400 /* pbuf tests need ~200KByte */
/* Minimal changes to opt.h required for etharp unit tests: */
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#endif
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
@ -193,6 +133,6 @@ extern int *__errno(void);
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#endif
#define LWIP_RAND() ((u32_t)random())
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__ ((section("SHAREDRAM")))
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM")))
#endif /* LWIP_HDR_LWIPOPTS_H__ */

View File

@ -24,6 +24,7 @@
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "mem.h"
#include <lwip/tcpip.h>
#include <lwip/sockets.h>
@ -132,6 +133,7 @@ void wifi_event_handler(uint32_t code)
} break;
case CODE_WIFI_ON_GOT_IP: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP\r\n", __func__);
LOG_I("[SYS] Memory left is %d Bytes\r\n", kfree_size());
} break;
case CODE_WIFI_ON_DISCONNECT: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT\r\n", __func__);

View File

@ -11,7 +11,7 @@ set(CONFIG_MBEDTLS 1)
# set(CONFIG_PSRAM 1)
set(CONFIG_DHCPD 1)
set(CONFIG_PING 1)
set(CONFIG_MQTT 1)
# set(CONFIG_MQTT 1)
set(CONFIG_VSNPRINTF_FLOAT 1)
set(CONFIG_VSNPRINTF_FLOAT_EX 1)
@ -25,3 +25,9 @@ set(CONFIG_MBEDTLS_ECC_USE_HW 0)
set(CONFIG_MBEDTLS_SHA1_USE_HW 0)
set(CONFIG_MBEDTLS_SHA256_USE_HW 0)
set(CONFIG_MBEDTLS_SHA512_USE_HW 0)
# wifi
set(CONFIG_VIF_MAX 2)
set(CONFIG_STA_MAX 4)
set(CONFIG_MAC_TXQ_DEPTH 32)
set(CONFIG_MAC_RXQ_DEPTH 12)

View File

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.15)
include(proj.conf)
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
# User
sdk_add_compile_definitions(-DCONFIG_CLI_CMD_ENABLE)
sdk_add_compile_definitions(-DBL_VERIFY)
#sdk_add_compile_definitions(-DBL616_DHCP_DEBUG)
target_sources(app PRIVATE
https/src/https.c
https/src/bl_https.c
)
sdk_add_include_directories(.)
sdk_add_include_directories(./https/include)
sdk_set_main_file(main.c)
project(wifi_https)

View File

@ -1,5 +1,5 @@
SDK_DEMO_PATH ?= .
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../..
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
export BL_SDK_BASE

View File

@ -0,0 +1,53 @@
# wifi6
## Support CHIP
| CHIP | Remark |
|:----------------:|:------:|
|BL616/BL618 | |
## Compile
- BL616/BL618
```
make CHIP=bl616 BOARD=bl616dk
```
## Flash
```
make flash COMX=xxx ## xxx is your com name
```
## How use wifi https test
### https test get a page
On BL616 board, using <wifi_sta_connect> command connect your WiFi router
```bash
bouffalolab />wifi_sta_connect BL_TEST 12345678
bouffalolab />wifi_https_test
bouffalolab />dst_addr is F23265B4
[I: 52207293][bl_https.c:126] HTTP/S> bl connect fd = 0xa800ee60
[I: 52221230][bl_https.c:136] HTTP/S> ret = -28
[I: 54080149][bl_https.c:156] HTTP/S> ret = 0
[I: 54080658][bl_https.c:160] HTTP/S> total time:1884447 us
[I: 54095499][bl_https.c:168] HTTP/S> rcv_ret = 1179
[I: 54096043][bl_https.c:172] HTTP/S> proc_head_r 0, status_code 200, body_start_off 400
[I: 54096479][bl_https.c:180] HTTP/S> Copy to resp @off 0, len 779, 1st char 3C
blTcpSslDisconnect end
[I: 54104728][bl_https.c:264] HTTP/S> total time:1908498 us
[I: 54105226][bl_https.c:265] HTTP/S> test_1: status_code 200, resp_len 779
[I: 54105654][bl_https.c:267] HTTP/S> resp body: <!DOCTYPE html>
......
```
### http post
TODO

View File

@ -0,0 +1,19 @@
[cfg]
# 0: no erase, 1:programmed section erase, 2: chip erase
erase = 1
# skip mode set first para is skip addr, second para is skip len, multi-segment region with ; separated
skip_mode = 0x0, 0x0
# 0: not use isp mode, #1: isp mode
boot2_isp_mode = 0
[boot2]
filedir = ./build/build_out/boot2_*.bin
address = 0x000000
[partition]
filedir = ./build/build_out/partition*.bin
address = 0xE000
[FW]
filedir = ./build/build_out/wifi*_$(CHIPNAME)*.bin
address = @partition

View File

@ -0,0 +1,20 @@
#ifndef __BL_ERROR_H__
#define __BL_ERROR_H__
#define BL_TCP_NO_ERROR (0) /**< 无错误 */
#define BL_TCP_ARG_INVALID (-2) /**< 无效的参数 */
#define BL_TCP_CREATE_CONNECT_ERR (-21) /**< 创建TCP连接错误 */
#define BL_TCP_SEND_ERR (-23) /**< TCP发送失败 */
#define BL_TCP_READ_ERR (-25) /**< TCP读取失败 */
#define BL_TCP_CONNECT_TIMEOUT (-26) /**< TCP连接超时 */
#define BL_TCP_CONNECT_ERR (-27) /**< TCP连接失败 */
#define BL_TCP_CONNECTING (-28) /**< TCP连接中 */
#define BL_TCP_READ_INCOMPLETED (-29) /**< TCP读包不完整 */
#define BL_TCP_CREATE_SERVER_ERR (-31) /**< 创建TCP服务错误 */
#define BL_TCP_SERVER_WAIT_CONNECT (-32) /**< tcp等待客户端连接 */
#define BL_TCP_DNS_PARSING (-35) /**< DNS解析中 */
#define BL_TCP_DNS_PARSE_ERR (-36) /**< DNS解析失败 */
#define BL_TCP_DNS_PARSE_TIMEOUT (-37) /**< DNS解析超时 */
#endif /* #ifndef __BL_ERROR_H__ */

View File

@ -0,0 +1,18 @@
#ifndef __BL_TEST_H__
#define __BL_TEST_H__
#include <stdint.h>
#define BL_HTTPS_RET_TIMEOUT (5000) /* 5000 ms */
#define BL_HTTPSC_OK (0)
#define BL_HTTPSC_RET_TIMEOUT (-1) /* request timeout */
#define BL_HTTPSC_RET_ERR (-2)
#define BL_HTTPSC_RET_ERR_MEM (-3)
#define BL_HTTPSC_RET_HTTP_ERR (-4) /* response do not look like http */
#define BL_HTTPSC_RET_ERR_BUF_TOO_SMALL (-5)
#define BL_HTTPSC_HEAD_END_NOT_FOUND (-6)
int cmd_https_test(int argc, char **argv);
#endif

View File

@ -0,0 +1,76 @@
#ifndef __HTTPS_H__
#define __HTTPS_H__
#include <stdint.h>
/**
* @brief tcp连接
*
* @par :
* tcp连接
*
* @param dst [IN] ip地址
* @param port [IN]
*
* @retval BL_TCP_ARG_INVALID dst为空
* @retval BL_TCP_CREATE_CONNECT_ERR
* @retval 0 ,tcp套接字使blTcpSslState判断连接是否完全建立
*/
int32_t blTcpSslConnect(const char* dst, uint16_t port);
/**
* @brief tcp连接状态
*
* @par :
* tcp连接状态
*
* @param fd [IN] tcp套接字
*
* @retval blTcpErrorCode bl tcp错误码
* @see blTcpErrorCode
*/
int32_t blTcpSslState(int32_t fd);
/**
* @brief tcp连接
*
* @par :
* tcp连接
*
* @param fd [IN] blTcpSslConnect创建的套接字
*
* @retval
*/
void blTcpSslDisconnect(int32_t fd);
/**
* @brief tcp数据
*
* @par :
* tcp数据
*
* @param fd [IN] tcp套接字
* @param buf [IN]
* @param len [IN] [0512)
*
* @retval blTcpErrorCode bl tcp错误码
* @see blTcpErrorCode
*/
int32_t blTcpSslSend(int32_t fd, const uint8_t* buf, uint16_t len);
/**
* @brief tcp数据
*
* @par :
* tcp数据
*
* @param fd [IN] tcp套接字
* @param buf [IN]
* @param len [IN] [0512)
*
* @retval blTcpErrorCode bl tcp错误码
* @see blTcpErrorCode
*/
int32_t blTcpSslRead(int32_t fd, uint8_t* buf, uint16_t len);
#endif

View File

@ -0,0 +1,361 @@
#include <stdio.h>
#include <FreeRTOS.h>
#include <task.h>
// #include <aos/kernel.h>
#include <stdlib.h>
#include <string.h>
// #include <cli.h>
// #include <utils_log.h>
#include "https.h"
#include "bl_error.h"
#include "bl_https.h"
#include "mbedtls/ssl.h"
#include "bflb_mtimer.h"
#define DBG_TAG "HTTP/S"
#include "log.h"
void *memmem(const void *haystack, size_t n, const void *needle, size_t m);
void *memmem(const void *haystack, size_t n, const void *needle, size_t m)
{
const unsigned char *y = (const unsigned char *)haystack;
const unsigned char *x = (const unsigned char *)needle;
size_t j, k, l;
if (m > n || !m || !n)
return NULL;
if (1 != m) {
if (x[0] == x[1]) {
k = 2;
l = 1;
} else {
k = 1;
l = 2;
}
j = 0;
while (j <= n - m) {
if (x[1] != y[j + 1]) {
j += k;
} else {
if (!memcmp(x + 2, y + j + 2, m - 2)
&& x[0] == y[j])
return (void *)&y[j];
j += l;
}
}
} else
do {
if (*y == *x)
return (void *)y;
y++;
} while (--n);
return NULL;
}
static int isdigit_c(int c)
{
return c >= '0' && c <= '9';
}
static int proc_http_head(const uint8_t *buf, int buf_len, int *status_code, int *body_start_off)
{
char status_code_buf[4] = { '\0', '\0', '\0', '\0' };
void *head_end_pos = NULL;
if (buf_len < 16) { // "HTTP/1.1 XYZ\r\n\r\n"
return BL_HTTPSC_RET_HTTP_ERR;
}
if (!((memcmp(buf, "HTTP/1.0 ", 9) == 0) || (0 == memcmp(buf, "HTTP/1.1 ", 9)))) {
return BL_HTTPSC_RET_HTTP_ERR;
}
memcpy(status_code_buf, buf + 9, 3);
if (!(isdigit_c(status_code_buf[0]) && isdigit_c(status_code_buf[1]) && isdigit_c(status_code_buf[2]))) {
return BL_HTTPSC_RET_HTTP_ERR;
}
*status_code = atoi(status_code_buf);
if ((head_end_pos = memmem(buf, buf_len, "\r\n\r\n", 4)) == NULL) {
return BL_HTTPSC_HEAD_END_NOT_FOUND;
}
*body_start_off = (uint8_t *)head_end_pos - buf + 4;
return BL_HTTPSC_OK;
}
/* parm server(in): hostname or ip address of https server
* parm port(in): https server port
* parm request(in): https request
* parm req_len(in): https request len(excluding '\0')
* parm response(out): https response(excluding http header)
* parm res_len(in, out): pass in addr of A, A stores capacity of buffer response
* pass out https response body length(ie no http header)
* out: HTTP status code or BL_HTTPSC error code
*/
int https_request(const char *server, uint16_t port, const uint8_t *request, int req_len, uint8_t *response, int *res_len)
{
int count = 0;
int ret_val = BL_HTTPSC_OK;
uint8_t *rcv_buf = NULL;
int buf_sz = 16*1024;
int32_t fd, ret, send_ret, rcv_ret;
int resp_write_off = 0;
int http_head_proced = 0;
int status_code = BL_HTTPSC_RET_ERR;
int write_len;
rcv_buf = malloc(buf_sz);
if (rcv_buf == NULL) {
free(rcv_buf);
LOG_E("rcv_buf do not have space\r\n");
return BL_HTTPSC_RET_ERR_MEM;
}
memset(rcv_buf, 0, sizeof(rcv_buf));
uint32_t start_time = 0, stop_time = 0;
start_time = bflb_mtimer_get_time_us();
fd = blTcpSslConnect(server, port);
LOG_I("bl connect fd = 0x%08lx\r\n", fd);
if (fd == BL_TCP_CREATE_CONNECT_ERR) {
LOG_E("ssl connect error\r\n");
ret_val = BL_HTTPSC_RET_ERR;
goto exit;
} else {
ret = blTcpSslState(fd);
}
LOG_I("ret = %ld\r\n", ret);
while (ret != BL_TCP_NO_ERROR)
{
count += 100;
usleep(100000);
if (ret == BL_TCP_CONNECTING) {
ret = blTcpSslState(fd);
} else if(ret == BL_TCP_CONNECT_ERR) {
LOG_E("ssl tcp connect failed\r\n");
ret_val = BL_HTTPSC_RET_ERR;
goto exit;
}
if (BL_HTTPS_RET_TIMEOUT < count) {
LOG_E("ssl tcp connect timeout\r\n");
ret_val = BL_HTTPSC_RET_TIMEOUT;
goto exit;
}
}
LOG_I("ret = %ld\r\n", ret);
stop_time = bflb_mtimer_get_time_us();
LOG_I("total time:%d us\r\n", (stop_time - start_time));
if (ret == BL_TCP_NO_ERROR) {
send_ret = blTcpSslSend(fd, request, req_len);
if (send_ret > 0) {
while(1) {
rcv_ret = blTcpSslRead(fd, rcv_buf, buf_sz);
if (rcv_ret > 0) {
LOG_I("rcv_ret = %ld\r\n", rcv_ret);
if (!http_head_proced) {
int body_start_off = -1;
int proc_head_r = proc_http_head(rcv_buf, rcv_ret, &status_code, &body_start_off);
LOG_I("proc_head_r %d, status_code %d, body_start_off %d\r\n", proc_head_r, status_code, body_start_off);
if (proc_head_r == BL_HTTPSC_OK) {
write_len = rcv_ret - body_start_off;
if (write_len + resp_write_off > *res_len) {
ret_val = BL_HTTPSC_RET_ERR_BUF_TOO_SMALL;
break;
}
http_head_proced = 1;
LOG_I("Copy to resp @off %d, len %d, 1st char %02X\r\n", resp_write_off, write_len, *(rcv_buf + body_start_off));
memcpy(response, rcv_buf + body_start_off, write_len);
resp_write_off += write_len;
}
} else {
write_len = rcv_ret;
if (write_len + resp_write_off > *res_len) {
ret_val = BL_HTTPSC_RET_ERR_BUF_TOO_SMALL;
break;
}
LOG_I("Copy to resp @off %d, len %d, 1st char %02X\r\n", resp_write_off, write_len, *rcv_buf);
memcpy(response + resp_write_off, rcv_buf, write_len);
resp_write_off += write_len;
}
ret_val = status_code;
break;
} else if (rcv_ret < 0) {
LOG_I("rcv_ret = %ld\r\n", rcv_ret);
ret_val = BL_HTTPSC_RET_ERR;
break;
} // rcv_ret>0
} // while(1)
} else {
LOG_E("ssl tcp send data failed\r\n");
}
}
exit:
blTcpSslDisconnect(fd);
*res_len = resp_write_off;
free(rcv_buf);
return ret_val;
}
void test_0(void)
{
const char *host = "10.89.110.120";
const uint8_t send_buf[] = "GET /1M HTTP/1.1\r\n"
//"Host: httpbin.org\r\n"
"User-Agent: curl/7.58.0\r\n"
//"accept: application/json\r\n\r\n";
"\r\n";
uint8_t *buf;
int resp_len;
int status_code;
buf = malloc(16 * 1024);
if (NULL == buf) {
LOG_E("malloc\r\n");
return;
}
resp_len = 16 * 1024;
status_code = https_request(host, 443, send_buf, sizeof(send_buf) - 1, buf, &resp_len);
LOG_I("test_0: status_code %d, resp_len %d\r\n", status_code, resp_len);
free(buf);
}
static void test_1(void)
{
const char *host = "www.baidu.com";
const uint8_t send_buf[] = "GET / HTTP/1.1\r\n"
"Host: www.baidu.com\r\n"
"User-Agent: curl/7.58.0\r\n"
"accept: application/json\r\n"
"\r\n";
uint8_t *buf;
int resp_len;
int status_code;
buf = malloc(16 * 1024);
if (NULL == buf) {
LOG_E("malloc\r\n");
return;
}
resp_len = 16 * 1024;
uint32_t start_time = 0, stop_time = 0;
start_time = bflb_mtimer_get_time_us();
status_code = https_request(host, 443, send_buf, sizeof(send_buf) - 1, buf, &resp_len);
stop_time = bflb_mtimer_get_time_us();
LOG_I("total time:%d us\r\n", (stop_time - start_time));
LOG_I("test_1: status_code %d, resp_len %d\r\n", status_code, resp_len);
buf[resp_len] = '\0';
LOG_I("resp body: %s\r\n", buf);
free(buf);
}
#if 0
static void test_2(void)
{
const char *host = "10.89.110.120";
const uint8_t send_buf[] = "GET /403 HTTP/1.1\r\n"
"\r\n";
uint8_t *buf;
int resp_len;
int status_code;
buf = malloc(16 * 1024);
if (NULL == buf) {
LOG_E("malloc\r\n");
return;
}
resp_len = 16 * 1024;
status_code = https_request(host, 443, send_buf, sizeof(send_buf) - 1, buf, &resp_len);
LOG_I("test_2: status_code %d, resp_len %d\r\n", status_code, resp_len);
free(buf);
}
static void test_3(void)
{
const char *host = "10.89.110.120";
const uint8_t send_buf[] = "GET / HTTP/1.1\r\n"
"\r\n";
uint8_t *buf;
int resp_len;
int status_code;
buf = malloc(16 * 1024);
if (NULL == buf) {
LOG_E("malloc\r\n");
return;
}
resp_len = 16 * 1024;
status_code = https_request(host, 443, send_buf, sizeof(send_buf) - 1, buf, &resp_len);
LOG_I("test_3: status_code %d, resp_len %d\r\n", status_code, resp_len);
free(buf);
}
#endif
static void test_https_entry(void *arg)
{
//test_0();
test_1();
//test_2();
//test_3();
vTaskDelete(NULL);
}
#ifdef CONFIG_SHELL
#include <shell.h>
extern uint32_t wifi_state;
static int check_wifi_state(void)
{
if (wifi_state == 1)
{
return 0;
} else {
return 1;
}
}
int cmd_https_test(int argc, char **argv)
{
uint32_t ret = 0;
ret = check_wifi_state();
if (ret != 0) {
printf("your wifi not connected!\r\n");
return 0;
}
xTaskCreate(test_https_entry,(char*)"test_https", 8192, NULL, 10, NULL);
return 0;
}
SHELL_CMD_EXPORT_ALIAS(cmd_https_test, wifi_https_test, wifi https client test);
#endif

View File

@ -0,0 +1,380 @@
#include <stdio.h>
#include <string.h>
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <timers.h>
#include <lwip/sockets.h>
#include <lwip/tcp.h>
#include <lwip/err.h>
#include <lwip/dns.h>
#include <lwip/netdb.h>
#include <mbedtls/net.h>
#include <mbedtls/debug.h>
#include <mbedtls/ssl.h>
#include <mbedtls/entropy.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/error.h>
#include <mbedtls/certs.h>
#include "bl_error.h"
#include "https.h"
#define DBG_TAG "HTTP/S"
#include "log.h"
//#define BL_VERIFY
#if 0
#if defined(BL_VERIFY)
const char bl_test_cli_key_rsa[] =
"-----BEGIN CERTIFICATE-----\r\n"
"MIIDjTCCAnUCFBjPxIX+hViDcOzz3QE1u250j+a5MA0GCSqGSIb3DQEBCwUAMIGC\r\n"
"MQswCQYDVQQGEwJDTjEQMA4GA1UECAwHamlhbmdzdTEQMA4GA1UEBwwHbmFuamlu\r\n"
"ZzEPMA0GA1UECgwGbmp0ZWNoMQwwCgYDVQQLDANDU1QxDzANBgNVBAMMBnlpbWlu\r\n"
"ZzEfMB0GCSqGSIb3DQEJARYQODc2NzExMDIyQHFxLmNvbTAeFw0xOTA3MzAwODMx\r\n"
"NDNaFw0yMDA3MjkwODMxNDNaMIGCMQswCQYDVQQGEwJDTjEQMA4GA1UECAwHamlh\r\n"
"bmdzdTEQMA4GA1UEBwwHbmFuamluZzEPMA0GA1UECgwGbmp0ZWNoMQwwCgYDVQQL\r\n"
"DANDU1QxDzANBgNVBAMMBnlpbWluZzEfMB0GCSqGSIb3DQEJARYQODc2NzExMDIy\r\n"
"QHFxLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKLcS3nEivyQ\r\n"
"rU1ehmr2uDSEf/PvRxmEjlff+S39nbtvxc/Ed1wUGSVmAee9bqjj9bEej/UGnZLN\r\n"
"4onfW6MC6WoDUmvVyq00Tcyq1hzpzRPhl8nCz9BI7hizsmlh3L10Mff+Jd6xzCk2\r\n"
"StKQXWbmpLOdqsZDIdumHDb8EGSQrv/J2o8JKCxyQ4gP9td48Z9bjeLIZPmhK8Lm\r\n"
"LVgGR2s87MaVfjCde4mefgJA+mkavB2/weNi5s+LxaYQ2T53NO39t/2yZ32VQyb7\r\n"
"6/NKf2jWniaKd01BFPLYpuVj8uR1eCn8SzVc84CP4TG96NdPgTT8fnHJHPxUQFMt\r\n"
"jNuJCWpxKOsCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAhvDTyNz0rZrgVSrtVE3B\r\n"
"zTo1t+8xFgWgsHJ5VT2s4O9W5RX+RpjaOp33cLFjSCM2jhxUZQSJTbZEnV3vlMOI\r\n"
"LLhCl7kWHaZt71oMgNeb32qRgTW197ogZnvkp7f+7RObxGAWJ1J3F11+sBT711HB\r\n"
"XARFQSdYfq8j1hxnlLR3rMntW8BIEk/1iz+qhYMXiwkTHQhTgX1308TLID2XtaEh\r\n"
"drTFzUuEJ0OGv3BWVyEtBM2xwX/5Xsjy2snAus66gI4OJEaBcJoDogNiFQm/PwvU\r\n"
"siFwHDQaP4athzbf2NvR0RVzWWyXP3Pj8puH0CJRjFddexdcd4NgrZojU3f7aZfs\r\n"
"eA==\r\n"
"-----END CERTIFICATE-----\r\n";
const int32_t bl_test_cas_pem_len = sizeof(bl_test_cli_key_rsa);
#endif
#endif
#if defined(BL_VERIFY)
// baidu.com root key
const char bl_test_cli_key_rsa[] =
"-----BEGIN CERTIFICATE-----\r\n"
"MIIDXzCCAkegAwIBAgILBAAAAAABIVhTCKIwDQYJKoZIhvcNAQELBQAwTDEgMB4G\r\n"
"A1UECxMXR2xvYmFsU2lnbiBSb290IENBIC0gUjMxEzARBgNVBAoTCkdsb2JhbFNp\r\n"
"Z24xEzARBgNVBAMTCkdsb2JhbFNpZ24wHhcNMDkwMzE4MTAwMDAwWhcNMjkwMzE4\r\n"
"MTAwMDAwWjBMMSAwHgYDVQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEG\r\n"
"A1UEChMKR2xvYmFsU2lnbjETMBEGA1UEAxMKR2xvYmFsU2lnbjCCASIwDQYJKoZI\r\n"
"hvcNAQEBBQADggEPADCCAQoCggEBAMwldpB5BngiFvXAg7aEyiie/QV2EcWtiHL8\r\n"
"RgJDx7KKnQRfJMsuS+FggkbhUqsMgUdwbN1k0ev1LKMPgj0MK66X17YUhhB5uzsT\r\n"
"gHeMCOFJ0mpiLx9e+pZo34knlTifBtc+ycsmWQ1z3rDI6SYOgxXG71uL0gRgykmm\r\n"
"KPZpO/bLyCiR5Z2KYVc3rHQU3HTgOu5yLy6c+9C7v/U9AOEGM+iCK65TpjoWc4zd\r\n"
"QQ4gOsC0p6Hpsk+QLjJg6VfLuQSSaGjlOCZgdbKfd/+RFO+uIEn8rUAVSNECMWEZ\r\n"
"XriX7613t2Saer9fwRPvm2L7DWzgVGkWqQPabumDk3F2xmmFghcCAwEAAaNCMEAw\r\n"
"DgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFI/wS3+o\r\n"
"LkUkrk1Q+mOai97i3Ru8MA0GCSqGSIb3DQEBCwUAA4IBAQBLQNvAUKr+yAzv95ZU\r\n"
"RUm7lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMp\r\n"
"jjM5RcOO5LlXbKr8EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK\r\n"
"6fBdRoyV3XpYKBovHd7NADdBj+1EbddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQX\r\n"
"mcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18YIvDQVETI53O9zJrlAGomecs\r\n"
"Mx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7rkpeDMdmztcpH\r\n"
"WD9f\r\n"
"-----END CERTIFICATE-----\r\n";
const int32_t bl_test_cas_pem_len = sizeof(bl_test_cli_key_rsa);
#endif
typedef struct _https_context {
mbedtls_ssl_context ssl;
mbedtls_ssl_config conf;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_net_context server_fd;
#if defined(BL_VERIFY)
mbedtls_x509_crt cacert;
#endif
} https_context_t;
https_context_t *bl_hsbuf = NULL;
static void bl_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{
((void) level);
LOG_I("%s:%04d: %s\r\n", file, line, str);
}
static int is_valid_ip_address(const char *ipAddress)
{
struct sockaddr_in sa;
int result = inet_pton(AF_INET, ipAddress, &(sa.sin_addr));
return result != 0;
}
int32_t blTcpSslConnect(const char *dst, uint16_t port)
{
in_addr_t dst_addr;
int ret;
struct sockaddr_in servaddr;
int flags;
int reuse = 1;
if (NULL != bl_hsbuf) {
return -1;
}
bl_hsbuf = malloc(sizeof(https_context_t));
if (NULL == bl_hsbuf) {
return -1;
}
if (NULL == dst) {
return BL_TCP_ARG_INVALID;
}
if (is_valid_ip_address(dst)) {
dst_addr = inet_addr(dst);
} else {
struct hostent *hostinfo = gethostbyname(dst);
if (!hostinfo) {
return -1;
}
dst_addr = ((struct in_addr *) hostinfo->h_addr)->s_addr;
printf("dst_addr is %08lX\n", *(uint32_t *)&dst_addr);
}
mbedtls_ssl_init(&bl_hsbuf->ssl);
#if defined(BL_VERIFY)
mbedtls_x509_crt_init( &bl_hsbuf->cacert );
#endif
mbedtls_ctr_drbg_init(&bl_hsbuf->ctr_drbg);
mbedtls_ssl_config_init(&bl_hsbuf->conf);
mbedtls_entropy_init(&bl_hsbuf->entropy);
if ((ret = mbedtls_ctr_drbg_seed(&bl_hsbuf->ctr_drbg, mbedtls_entropy_func, &bl_hsbuf->entropy,
NULL, 0)) != 0) {
return BL_TCP_CREATE_CONNECT_ERR;
}
#if defined(BL_VERIFY)
ret = mbedtls_x509_crt_parse( &bl_hsbuf->cacert, (const unsigned char *)bl_test_cli_key_rsa,
bl_test_cas_pem_len );
if (ret < 0) {
printf("\r\n mbedtls_x509_crt_parse returned -0x%x\r\n", -ret);
}
#endif
if ((ret = mbedtls_ssl_config_defaults(&bl_hsbuf->conf,
MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
printf("mbedtls_ssl_config_defaults returned %d", ret);
return BL_TCP_CREATE_CONNECT_ERR;
}
#if defined(BL_VERIFY)
mbedtls_ssl_conf_authmode(&bl_hsbuf->conf, MBEDTLS_SSL_VERIFY_REQUIRED/*MBEDTLS_SSL_VERIFY_OPTIONAL*/);
mbedtls_ssl_conf_ca_chain( &bl_hsbuf->conf, &bl_hsbuf->cacert, NULL );
#else
mbedtls_ssl_conf_authmode(&bl_hsbuf->conf, MBEDTLS_SSL_VERIFY_NONE);
#endif
mbedtls_ssl_conf_rng(&bl_hsbuf->conf, mbedtls_ctr_drbg_random, &bl_hsbuf->ctr_drbg);
//todo
mbedtls_ssl_conf_read_timeout(&bl_hsbuf->conf, 0);
//mbedtls_ssl_set_timer_cb(&ssl, &ssl_timer, f_set_timer, f_get_timer);
mbedtls_ssl_conf_dbg( &bl_hsbuf->conf, bl_debug, stdout );
#if defined(MBEDTLS_DEBUG_C)
// mbedtls_debug_set_threshold(4);
#endif
if ((ret = mbedtls_ssl_setup(&bl_hsbuf->ssl, &bl_hsbuf->conf)) != 0) {
printf("mbedtls_ssl_setup returned -0x%x\r\n", -ret);
return BL_TCP_CREATE_CONNECT_ERR;
}
mbedtls_net_init(&bl_hsbuf->server_fd);
bl_hsbuf->server_fd.fd = socket(AF_INET, SOCK_STREAM, 0);
if (bl_hsbuf->server_fd.fd < 0) {
printf("ssl creat socket fd failed\r\n");
return BL_TCP_CREATE_CONNECT_ERR;
}
flags = fcntl(bl_hsbuf->server_fd.fd, F_GETFL, 0);
if (flags < 0 || fcntl(bl_hsbuf->server_fd.fd, F_SETFL, flags | O_NONBLOCK) < 0) {
printf("ssl fcntl: %s\r\n", strerror(errno));
close(bl_hsbuf->server_fd.fd);
return BL_TCP_CREATE_CONNECT_ERR;
}
if (setsockopt(bl_hsbuf->server_fd.fd, SOL_SOCKET, SO_REUSEADDR,
(const char*) &reuse, sizeof(reuse)) != 0) {
close(bl_hsbuf->server_fd.fd);
printf("ssl set SO_REUSEADDR failed\r\n");
return BL_TCP_CREATE_CONNECT_ERR;
}
memset(&servaddr, 0, sizeof(struct sockaddr_in));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = dst_addr;
servaddr.sin_port = htons(port);
if (connect(bl_hsbuf->server_fd.fd, (struct sockaddr*)&servaddr, sizeof(struct sockaddr_in)) == 0) {
//printf("ssl dst %s errno %d\r\n", dst, errno);
} else {
//printf("ssl dst %s errno %d\r\n", dst, errno);
if (errno == EINPROGRESS) {
//printf("ssl tcp conncet noblock\r\n");
} else {
close(bl_hsbuf->server_fd.fd);
return BL_TCP_CREATE_CONNECT_ERR;
}
}
//todo
//mbedtls_ssl_set_bio(&bl_hsbuf->ssl, &bl_hsbuf->server_fd, mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout); //noblock
mbedtls_ssl_set_bio(&bl_hsbuf->ssl, &bl_hsbuf->server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);
return (int32_t)&bl_hsbuf->ssl;
}
void blTcpSslDisconnect(int32_t fd)
{
mbedtls_ssl_context *pssl = (mbedtls_ssl_context *)fd;
if (NULL == pssl) {
printf("blTcpSslDisconnect\r\n");
}
mbedtls_ssl_close_notify(pssl);
mbedtls_net_free((mbedtls_net_context*)(pssl->p_bio));
#if defined(BL_VERIFY)
mbedtls_x509_crt_free( &bl_hsbuf->cacert );
#endif
mbedtls_ssl_free( pssl );
mbedtls_ssl_config_free( &bl_hsbuf->conf );
mbedtls_ctr_drbg_free( &bl_hsbuf->ctr_drbg );
mbedtls_entropy_free( &bl_hsbuf->entropy );
free(bl_hsbuf);
bl_hsbuf = NULL;
printf("blTcpSslDisconnect end\r\n");
}
int32_t blTcpSslState(int32_t fd)
{
//printf("blTcpSslState start\r\n");
int errcode = BL_TCP_NO_ERROR;
mbedtls_ssl_context *pssl = (mbedtls_ssl_context *)fd;
int tcp_fd = ((mbedtls_net_context*)(pssl->p_bio))->fd;
int ret;
fd_set rset, wset;
int ready_n;
struct timeval timeout;
socklen_t len = sizeof(int);
if (tcp_fd < 0 || NULL == pssl) {
return BL_TCP_ARG_INVALID;
}
FD_ZERO(&rset);
FD_ZERO(&wset);
FD_CLR(tcp_fd, &rset);
FD_CLR(tcp_fd, &wset);
FD_SET(tcp_fd, &rset);
FD_SET(tcp_fd, &wset);
timeout.tv_sec = 2;
timeout.tv_usec = 0;
ready_n = select(tcp_fd + 1, &rset, &wset, NULL, &timeout);
if (0 == ready_n) {
errcode = BL_TCP_CONNECTING;
} else if (ready_n < 0) {
errcode = BL_TCP_CONNECT_ERR;
} else {
if (FD_ISSET(tcp_fd, &wset) != 0) {
errcode = BL_TCP_CONNECTING;
if(pssl->state != MBEDTLS_SSL_HANDSHAKE_OVER) {
ret = mbedtls_ssl_handshake_step( pssl );
// printf("mbedtls_ssl_handshake_step return = 0X%X\r\n", -ret);
if ((0 != ret) && (MBEDTLS_ERR_SSL_WANT_READ != ret)) {
errcode = BL_TCP_CONNECT_ERR;
}
} else {
errcode = BL_TCP_NO_ERROR;
}
} else {
if (0 != getsockopt(tcp_fd, SOL_SOCKET, SO_ERROR, &ret, &len)) {
errcode = BL_TCP_CONNECT_ERR;
}
if (0 != ret) {
errcode = BL_TCP_CONNECT_ERR;
}
errcode = BL_TCP_CONNECT_ERR;
}
}
return errcode;
}
int32_t blTcpSslSend(int32_t fd, const uint8_t* buf, uint16_t len)
{
//puts("blTcpSslSend start\r\n");
int ret = 0;
mbedtls_ssl_context *pssl = (mbedtls_ssl_context *)fd;
if (NULL == buf || NULL == pssl) {
return BL_TCP_ARG_INVALID;
}
ret = mbedtls_ssl_write(pssl, buf, len);
if(ret > 0) {
return ret;
} else {
printf("blTcpSslsend error ret = 0X%X\r\n", -ret);
return BL_TCP_SEND_ERR;
}
return ret;
}
int32_t blTcpSslRead(int32_t fd, uint8_t* buf, uint16_t len)
{
int ret = 0;
mbedtls_ssl_context *pssl = (mbedtls_ssl_context *)fd;
if (NULL == buf || NULL == pssl) {
return BL_TCP_ARG_INVALID;
}
ret = mbedtls_ssl_read(pssl, buf, len);
if(ret > 0) {
return ret;
} else if(MBEDTLS_ERR_SSL_WANT_READ == ret) {
return 0;
} else {
printf("blTcpSslRead ret = 0X%X\r\n", ret);
return BL_TCP_READ_ERR;
}
}

View File

@ -32,10 +32,6 @@
#ifndef LWIP_HDR_LWIPOPTS_H__
#define LWIP_HDR_LWIPOPTS_H__
#define RX_BUF_CNT 4
#define MAC_TXQ_DEPTH 16
#define MAC_RXQ_DEPTH 12
#define LWIP_NETIF_API 1
#define LWIP_DEBUG 1
#define LWIP_STATS_DISPLAY 1
@ -70,52 +66,31 @@
#define PBUF_LINK_ENCAPSULATION_HLEN 388
#define IP_REASS_MAX_PBUFS (RX_BUF_CNT - 2)
#define IP_REASS_MAX_PBUFS (2 * CONFIG_MAC_RXQ_DEPTH - 2)
#define MEMP_NUM_NETBUF 32
#define MEMP_NUM_NETCONN 16
#define MEMP_NUM_UDP_PCB 16
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define MAC_TXQ_DEPTH CONFIG_MAC_TXQ_DEPTH
#define MAC_RXQ_DEPTH CONFIG_MAC_RXQ_DEPTH
#if NX_BEACONING
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#else
#define TCP_SND_BUF (2 * MAC_TXQ_DEPTH * TCP_MSS)
#endif
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), \
(2 * TCP_MSS) + 1), \
(TCP_SND_BUF)-1)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1)
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#if NX_TG
#define MEM_MIN_TG 16384
#else
#define MEM_MIN_TG 0
#endif
#if MEM_MIN_TCP > MEM_MIN_TG
#define MEM_MIN MEM_MIN_TCP
#else
#define MEM_MIN MEM_MIN_TG
#endif
#define MEM_ALIGNMENT 4
#if defined(CFG_SDIOWIFI)
#undef MEM_MIN
#ifdef LP_APP
#define MEM_MIN (14 * 1024)
#else
#define MEM_MIN (48 * 1024)
#endif
#endif
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#define MEM_MIN MEM_MIN_TCP
#define MEM_ALIGNMENT 4
#ifdef LWIP_HEAP_SIZE
#define MEM_SIZE LWIP_HEAP_SIZE
@ -135,54 +110,19 @@
#define LWIP_TIMEVAL_PRIVATE 0 // use sys/time.h for struct timeval
//#define LWIP_PROVIDE_ERRNO
#ifndef PLATFORM_PRIVDE_ERRNO
#define LWIP_PROVIDE_ERRNO 1
#endif
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
extern int *__errno(void);
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#if 0
/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */
#define NO_SYS 0
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define SYS_LIGHTWEIGHT_PROT 0
#define LWIP_IPV6 1
#define IPV6_FRAG_COPYHEADER 1
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
/* Turn off checksum verification of fuzzed data */
#define CHECKSUM_CHECK_IP 0
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_TCP 0
#define CHECKSUM_CHECK_ICMP 0
#define CHECKSUM_CHECK_ICMP6 0
/* Minimal changes to opt.h required for tcp unit tests: */
#define MEM_SIZE 16000
#define TCP_SND_QUEUELEN 40
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#define TCP_SND_BUF (12 * TCP_MSS)
#define TCP_WND (10 * TCP_MSS)
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 0
#define PBUF_POOL_SIZE 400 /* pbuf tests need ~200KByte */
/* Minimal changes to opt.h required for etharp unit tests: */
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#endif
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
@ -193,6 +133,6 @@ extern int *__errno(void);
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#endif
#define LWIP_RAND() ((u32_t)random())
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__ ((section("SHAREDRAM")))
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM")))
#endif /* LWIP_HDR_LWIPOPTS_H__ */

View File

@ -24,6 +24,7 @@
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "mem.h"
#include <lwip/tcpip.h>
#include <lwip/sockets.h>
@ -45,13 +46,14 @@
#define DBG_TAG "MAIN"
#include "log.h"
struct bflb_device_s *gpio;
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define WIFI_STACK_SIZE (1536)
#define TASK_PRIORITY_FW (16)
#define WIFI_STACK_SIZE (1536)
#define TASK_PRIORITY_FW (16)
/****************************************************************************
* Private Types
@ -65,8 +67,7 @@ static struct bflb_device_s *uart0;
static TaskHandle_t wifi_fw_task;
static wifi_conf_t conf =
{
static wifi_conf_t conf = {
.country_code = "CN",
};
@ -111,71 +112,53 @@ int wifi_start_firmware_task(void)
return 0;
}
volatile uint32_t wifi_state = 0;
void wifi_event_handler(uint32_t code)
{
switch (code) {
case CODE_WIFI_ON_INIT_DONE:
{
case CODE_WIFI_ON_INIT_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_INIT_DONE\r\n", __func__);
wifi_mgmr_init(&conf);
}
break;
case CODE_WIFI_ON_MGMR_DONE:
{
} break;
case CODE_WIFI_ON_MGMR_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_MGMR_DONE\r\n", __func__);
}
break;
case CODE_WIFI_ON_SCAN_DONE:
{
} break;
case CODE_WIFI_ON_SCAN_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_SCAN_DONE\r\n", __func__);
wifi_mgmr_sta_scanlist();
}
break;
case CODE_WIFI_ON_CONNECTED:
{
} break;
case CODE_WIFI_ON_CONNECTED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_CONNECTED\r\n", __func__);
void mm_sec_keydump();
mm_sec_keydump();
}
break;
case CODE_WIFI_ON_GOT_IP:
{
} break;
case CODE_WIFI_ON_GOT_IP: {
wifi_state = 1;
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP\r\n", __func__);
}
break;
case CODE_WIFI_ON_DISCONNECT:
{
LOG_I("[SYS] Memory left is %d Bytes\r\n", kfree_size());
} break;
case CODE_WIFI_ON_DISCONNECT: {
wifi_state = 0;
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT\r\n", __func__);
}
break;
case CODE_WIFI_ON_AP_STARTED:
{
} break;
case CODE_WIFI_ON_AP_STARTED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STARTED\r\n", __func__);
}
break;
case CODE_WIFI_ON_AP_STOPPED:
{
} break;
case CODE_WIFI_ON_AP_STOPPED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STOPPED\r\n", __func__);
}
break;
case CODE_WIFI_ON_AP_STA_ADD:
{
} break;
case CODE_WIFI_ON_AP_STA_ADD: {
LOG_I("[APP] [EVT] [AP] [ADD] %lld\r\n", xTaskGetTickCount());
}
break;
case CODE_WIFI_ON_AP_STA_DEL:
{
} break;
case CODE_WIFI_ON_AP_STA_DEL: {
LOG_I("[APP] [EVT] [AP] [DEL] %lld\r\n", xTaskGetTickCount());
}
break;
default:
{
} break;
default: {
LOG_I("[APP] [EVT] Unknown code %u \r\n", code);
}
}
}
int main(void)
{
board_init();
@ -191,4 +174,3 @@ int main(void)
while (1) {
}
}

View File

@ -0,0 +1,33 @@
# Components
set(CONFIG_BFLOG 1)
set(CONFIG_FREERTOS 1)
set(CONFIG_POSIX 1)
set(CONFIG_TLSF 1)
set(CONFIG_SHELL 1)
set(CONFIG_LWIP 1)
set(CONFIG_WIFI6 1)
set(CONFIG_RF 1)
set(CONFIG_MBEDTLS 1)
set(CONFIG_PSRAM 1)
set(CONFIG_DHCPD 1)
set(CONFIG_PING 1)
# set(CONFIG_MQTT 1)
set(CONFIG_VSNPRINTF_FLOAT 1)
set(CONFIG_VSNPRINTF_FLOAT_EX 1)
set(CONFIG_VSNPRINTF_LONG_LONG 1)
# Config
## mbedtls
# set(CONFIG_MBEDTLS_AES_USE_HW 1)
# set(CONFIG_MBEDTLS_BIGNUM_USE_HW 1)
# set(CONFIG_MBEDTLS_ECC_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA1_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA256_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA512_USE_HW 1)
# wifi
set(CONFIG_VIF_MAX 2)
set(CONFIG_STA_MAX 4)
set(CONFIG_MAC_TXQ_DEPTH 32)
set(CONFIG_MAC_RXQ_DEPTH 12)

View File

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.15)
include(proj.conf)
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
# User
sdk_add_compile_definitions(-DCONFIG_CLI_CMD_ENABLE)
# sdk_add_compile_options(-DMQTT_USE_CUSTOM_SOCKET_HANDLE)
# sdk_add_compile_definitions(-DMBEDTLS_PK_PARSE_C)
# sdk_add_compile_definitions(-DBL616_DHCP_DEBUG)
target_sources(app PRIVATE
wifi_mqtt_pub.c)
sdk_add_include_directories(.)
sdk_set_main_file(main.c)
project(wifi_mqtt_publisher)

View File

@ -0,0 +1,128 @@
/*
* FreeRTOS Kernel V10.2.1
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#include "stdio.h"
#ifdef BL702
#define configMTIME_BASE_ADDRESS (0x02000000UL + 0xBFF8UL)
#define configMTIMECMP_BASE_ADDRESS (0x02000000UL + 0x4000UL)
#else
#define configMTIME_BASE_ADDRESS (0xE0000000UL + 0xBFF8UL)
#define configMTIMECMP_BASE_ADDRESS (0xE0000000UL + 0x4000UL)
#endif
#define configSUPPORT_STATIC_ALLOCATION 1
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ((uint32_t)(1 * 1000 * 1000))
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (32)
#define configMINIMAL_STACK_SIZE ((unsigned short)128) /* Only needs to be this high as some demo tasks also use this constant. In production only the idle task would use this. */
#define configTOTAL_HEAP_SIZE ((size_t)100 * 1024)
#define configMAX_TASK_NAME_LEN (16)
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 0
#define configUSE_POSIX_ERRNO 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES (2)
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)
#define configTIMER_QUEUE_LENGTH 4
#define configTIMER_TASK_STACK_DEPTH (1024)
/* Task priorities. Allow these to be overridden. */
#ifndef uartPRIMARY_PRIORITY
#define uartPRIMARY_PRIORITY (configMAX_PRIORITIES - 3)
#endif
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
void vApplicationMallocFailedHook(void);
void vAssertCalled(void);
#define configASSERT(x) \
if ((x) == 0) { \
printf("file [%s]\r\n", __FILE__); \
printf("func [%s]\r\n", __FUNCTION__); \
printf("line [%d]\r\n", __LINE__); \
printf("%s\r\n", (const char *)(#x)); \
vAssertCalled(); \
}
#if (configUSE_TICKLESS_IDLE != 0)
void vApplicationSleep(uint32_t xExpectedIdleTime);
#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vApplicationSleep(xExpectedIdleTime)
#endif
// #define portUSING_MPU_WRAPPERS
#endif /* FREERTOS_CONFIG_H */

View File

@ -0,0 +1,13 @@
SDK_DEMO_PATH ?= .
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
export BL_SDK_BASE
CHIP ?= bl616
BOARD ?= bl616dk
CROSS_COMPILE ?= riscv64-unknown-elf-
# add custom cmake definition
#cmake_definition+=-Dxxx=sss
include $(BL_SDK_BASE)/project.build

View File

@ -0,0 +1,48 @@
# wifi6 tcp case
## Support CHIP
| CHIP | Remark |
|:----------------:|:------:|
|BL616/BL618 | |
## Compile
- BL616/BL618
```bash
make CHIP=bl616 BOARD=bl616dk
```
## Flash
```bash
make flash COMX=xxx ## xxx is your com name
```
## How use wifi mqtt pub test
1. Find some mqtt server or your deployed a mqtt server first. This case default used `test.mosquitto.org:1883` server test; or used EMQX mqtt public server test.
2. Use mqtt client to test if the server is working. You can install `MQTTBox` on windows for testing, you can install it from Microsoft Store. Or use EMQX's online mqtt client for testing.
3. If the server works fine, then you can continue with the next test.
4. connect your WiFi.
5. connect MQTT server. command like `mqtt_pub` or `mqtt_pub <server domain name or server ip> <server port> <topic>`.
6. If the command is executed successfully, a message will be uploaded every 3 seconds.
Log:
```bash
bouffalolab />wifi_sta_connect BL_TEST 12345678
bouffalolab />mqtt_pub
bouffalolab />mqtt_pub is ready to begin publishing the time.
Press ENTER to publish the current time.
Press CTRL-C to exit.
mqtt_pub published : "{"hello mqtt by bl616/8 !"}
Now time is 2023-06-16 00:00:00"
mqtt_pub published : "{"hello mqtt by bl616/8 !"}
Now time is 2023-06-16 00:00:03"
mqtt_pub stop publish to test.mosquitto.org
^C
```

View File

@ -15,9 +15,6 @@ filedir = ./build/build_out/partition*.bin
address = 0xE000
[FW]
filedir = ./build/build_out/mqtt_$(CHIPNAME).bin
filedir = ./build/build_out/wifi*_$(CHIPNAME)*.bin
address = @partition
# [mfg]
# filedir = ./build/build_out/mfg*.bin
# address = @partition

View File

@ -0,0 +1,138 @@
/*
* 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: Simon Goldschmidt
*
*/
#ifndef LWIP_HDR_LWIPOPTS_H__
#define LWIP_HDR_LWIPOPTS_H__
#define LWIP_NETIF_API 1
#define LWIP_DEBUG 1
#define LWIP_STATS_DISPLAY 1
#define SOCKETS_DEBUG LWIP_DBG_OFF
#ifdef BL616_DHCP_DEBUG
#define DHCP_DEBUG LWIP_DBG_ON
#else
#define DHCP_DEBUG LWIP_DBG_OFF
#endif
#define ICMP_DEBUG LWIP_DBG_OFF
#define ETHARP_DEBUG LWIP_DBG_OFF
#define LWIP_MULTICAST_PING 1
#define LWIP_BROADCAST_PING 1
#define TCPIP_MBOX_SIZE 64
#define TCPIP_THREAD_STACKSIZE 1024
#define TCPIP_THREAD_PRIO 28
#define DEFAULT_THREAD_STACKSIZE 1024
#define DEFAULT_THREAD_PRIO 1
#define DEFAULT_RAW_RECVMBOX_SIZE 32
#define DEFAULT_UDP_RECVMBOX_SIZE 64
#define DEFAULT_TCP_RECVMBOX_SIZE 64
#define DEFAULT_ACCEPTMBOX_SIZE 32
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_HAVE_LOOPIF 1
#define LWIP_LOOPBACK_MAX_PBUFS 0
#define LWIP_CHKSUM_ALGORITHM 3
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
#define PBUF_LINK_ENCAPSULATION_HLEN 388
#define IP_REASS_MAX_PBUFS (2 * CONFIG_MAC_RXQ_DEPTH - 2)
#define MEMP_NUM_NETBUF 32
#define MEMP_NUM_NETCONN 16
#define MEMP_NUM_UDP_PCB 16
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)
#define MAC_TXQ_DEPTH CONFIG_MAC_TXQ_DEPTH
#define MAC_RXQ_DEPTH CONFIG_MAC_RXQ_DEPTH
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1)
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#define MEM_MIN MEM_MIN_TCP
#define MEM_ALIGNMENT 4
#ifdef LWIP_HEAP_SIZE
#define MEM_SIZE LWIP_HEAP_SIZE
#else
#if MEM_MIN > 8192
#define MEM_SIZE MEM_MIN
#else
#define MEM_SIZE 8192
#endif
#endif
#define LWIP_HOOK_FILENAME "lwiphooks.h"
#define LWIP_RAW 1
#define LWIP_MULTICAST_TX_OPTIONS 1
#define LWIP_TIMEVAL_PRIVATE 0 // use sys/time.h for struct timeval
//#define LWIP_PROVIDE_ERRNO
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
extern int *__errno(void);
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define LWIP_SUPPORT_CUSTOM_PBUF 1
#ifdef HIGH_PERFORMANCE_PBUF
#define LWIP_NETIF_TX_SINGLE_PBUF 0
#else
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#endif
#define LWIP_RAND() ((u32_t)random())
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM")))
#endif /* LWIP_HDR_LWIPOPTS_H__ */

View File

@ -0,0 +1,176 @@
/****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "mem.h"
#include <lwip/tcpip.h>
#include <lwip/sockets.h>
#include <lwip/netdb.h>
#include "bl_fw_api.h"
#include "wifi_mgmr_ext.h"
#include "wifi_mgmr.h"
#include "bflb_irq.h"
#include "bflb_uart.h"
#include "bl616_glb.h"
#include "rfparam_adapter.h"
#include "board.h"
#include "shell.h"
#define DBG_TAG "MAIN"
#include "log.h"
struct bflb_device_s *gpio;
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define WIFI_STACK_SIZE (1536)
#define TASK_PRIORITY_FW (16)
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static struct bflb_device_s *uart0;
static TaskHandle_t wifi_fw_task;
static wifi_conf_t conf = {
.country_code = "CN",
};
extern void shell_init_with_task(struct bflb_device_s *shell);
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Functions
****************************************************************************/
int wifi_start_firmware_task(void)
{
LOG_I("Starting wifi ...\r\n");
/* enable wifi clock */
GLB_PER_Clock_UnGate(GLB_AHB_CLOCK_IP_WIFI_PHY | GLB_AHB_CLOCK_IP_WIFI_MAC_PHY | GLB_AHB_CLOCK_IP_WIFI_PLATFORM);
GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_WIFI);
/* set ble controller EM Size */
GLB_Set_EM_Sel(GLB_WRAM160KB_EM0KB);
if (0 != rfparam_init(0, NULL, 0)) {
LOG_I("PHY RF init failed!\r\n");
return 0;
}
LOG_I("PHY RF init success!\r\n");
/* Enable wifi irq */
extern void interrupt0_handler(void);
bflb_irq_attach(WIFI_IRQn, (irq_callback)interrupt0_handler, NULL);
bflb_irq_enable(WIFI_IRQn);
xTaskCreate(wifi_main, (char *)"fw", WIFI_STACK_SIZE, NULL, TASK_PRIORITY_FW, &wifi_fw_task);
return 0;
}
volatile uint32_t wifi_state = 0;
void wifi_event_handler(uint32_t code)
{
switch (code) {
case CODE_WIFI_ON_INIT_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_INIT_DONE\r\n", __func__);
wifi_mgmr_init(&conf);
} break;
case CODE_WIFI_ON_MGMR_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_MGMR_DONE\r\n", __func__);
} break;
case CODE_WIFI_ON_SCAN_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_SCAN_DONE\r\n", __func__);
wifi_mgmr_sta_scanlist();
} break;
case CODE_WIFI_ON_CONNECTED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_CONNECTED\r\n", __func__);
void mm_sec_keydump();
mm_sec_keydump();
} break;
case CODE_WIFI_ON_GOT_IP: {
wifi_state = 1;
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP\r\n", __func__);
LOG_I("[SYS] Memory left is %d Bytes\r\n", kfree_size());
} break;
case CODE_WIFI_ON_DISCONNECT: {
wifi_state = 0;
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT\r\n", __func__);
} break;
case CODE_WIFI_ON_AP_STARTED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STARTED\r\n", __func__);
} break;
case CODE_WIFI_ON_AP_STOPPED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STOPPED\r\n", __func__);
} break;
case CODE_WIFI_ON_AP_STA_ADD: {
LOG_I("[APP] [EVT] [AP] [ADD] %lld\r\n", xTaskGetTickCount());
} break;
case CODE_WIFI_ON_AP_STA_DEL: {
LOG_I("[APP] [EVT] [AP] [DEL] %lld\r\n", xTaskGetTickCount());
} break;
default: {
LOG_I("[APP] [EVT] Unknown code %u \r\n", code);
}
}
}
int main(void)
{
board_init();
uart0 = bflb_device_get_by_name("uart0");
shell_init_with_task(uart0);
tcpip_init(NULL, NULL);
wifi_start_firmware_task();
vTaskStartScheduler();
while (1) {
}
}

View File

@ -0,0 +1,175 @@
/**
* \file config.h
*
* \brief Configuration options (set of defines)
*
* This set of compile-time options may be used to enable
* or disable features selectively, and reduce the global
* memory footprint.
*/
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_CIPHER_MODE_CTR
#define MBEDTLS_CIPHER_PADDING_PKCS7
#define MBEDTLS_CIPHER_PADDING_ZEROS
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
#define MBEDTLS_REMOVE_3DES_CIPHERSUITES
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECDSA_C
//#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
//#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
//#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
//#define MBEDTLS_ECP_DP_BP256R1_ENABLED
//#define MBEDTLS_ECP_DP_BP384R1_ENABLED
//#define MBEDTLS_ECP_DP_BP512R1_ENABLED
//#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
//#define MBEDTLS_ECP_DP_CURVE448_ENABLED
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
//XXX TODO remove bl606p
#if defined(CFG_CHIP_BL606P) || defined(CFG_CHIP_BL808)
#define MBEDTLS_PKCS5_C
#endif
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_PKCS1_V21
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_ALPN
#define MBEDTLS_SSL_SESSION_TICKETS
#define MBEDTLS_SSL_SERVER_NAME_INDICATION
#define MBEDTLS_X509_CHECK_KEY_USAGE
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
#define MBEDTLS_AES_C
#define MBEDTLS_AES_ROM_TABLES
#define MBEDTLS_BASE64_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_DEBUG_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_ERROR_C
#define MBEDTLS_GCM_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
#define MBEDTLS_OID_C
#define MBEDTLS_PEM_PARSE_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_GENPRIME
#define MBEDTLS_RSA_C
#define MBEDTLS_DHM_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA512_C
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CRT_PARSE_C
//#define MBEDTLS_NET_C
//#define MBEDTLS_FS_IO
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#define MBEDTLS_PLATFORM_STD_MEM_HDR "mbedtls_port_bouffalo_sdk.h"
// Define BL_MPI_LARGE_NUM_SOFTWARE_MPI to allow operate on very big bignums
/* #define BL_MPI_LARGE_NUM_SOFTWARE_MPI */
// Hash HW
#ifdef CONFIG_MBEDTLS_SHA1_USE_HW
#define MBEDTLS_SHA1_ALT
#endif
#ifdef CONFIG_MBEDTLS_SHA256_USE_HW
#define MBEDTLS_SHA256_ALT
#endif
#ifdef CONFIG_MBEDTLS_SHA512_USE_HW
#define MBEDTLS_SHA512_ALT
#endif
// AES HW
#ifdef CONFIG_MBEDTLS_AES_USE_HW
#define MBEDTLS_AES_ALT
#endif
// ECC HW
#ifdef CONFIG_MBEDTLS_ECC_USE_HW
#define MBEDTLS_ECP_ALT
#endif
#if defined(CONFIG_MBEDTLS_ECC_USE_HW) && defined(MBEDTLS_ECP_RESTARTABLE)
#error "ECP Restartable is not implemented with ECP HW acceleration!"
#endif
/* Target and application specific configurations
*
* Allow user to override any previous default.
*
*/
#if defined(MBEDTLS_USER_CONFIG_FILE)
#include MBEDTLS_USER_CONFIG_FILE
#endif
#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
#include "mbedtls/config_psa.h"
#endif
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */

View File

@ -0,0 +1,35 @@
# Components
set(CONFIG_BFLOG 0)
set(CONFIG_FREERTOS 1)
set(CONFIG_POSIX 1)
set(CONFIG_TLSF 1)
set(CONFIG_SHELL 1)
set(CONFIG_LWIP 1)
set(CONFIG_WIFI6 1)
set(CONFIG_RF 1)
set(CONFIG_MBEDTLS 1)
set(CONFIG_PSRAM 1)
set(CONFIG_DHCPD 1)
set(CONFIG_PING 1)
set(CONFIG_MQTT 1)
set(CONFIG_VSNPRINTF_FLOAT 1)
set(CONFIG_VSNPRINTF_FLOAT_EX 1)
set(CONFIG_VSNPRINTF_LONG_LONG 1)
# Config
## mbedtls
# set(CONFIG_MBEDTLS_SELF_TEST 1)
# set(CONFIG_MBEDTLS_AES_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA1_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA256_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA512_USE_HW 1)
# set(CONFIG_MBEDTLS_ECC_USE_HW 1)
# set(CONFIG_MBEDTLS_BIGNUM_USE_HW 1)
# wifi
set(CONFIG_VIF_MAX 2)
set(CONFIG_STA_MAX 4)
set(CONFIG_MAC_TXQ_DEPTH 32)
set(CONFIG_MAC_RXQ_DEPTH 12)

View File

@ -0,0 +1,258 @@
#include "FreeRTOS_POSIX.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <lwip/errno.h>
#include <netdb.h>
#include "utils_getopt.h"
#include "mqtt.h"
#include "shell.h"
#include "bflb_rtc.h"
uint8_t sendbuf[2048]; /* sendbuf should be large enough to hold multiple whole mqtt messages */
uint8_t recvbuf[1024]; /* recvbuf should be large enough any whole mqtt message expected to be received */
shell_sig_func_ptr abort_exec;
static TaskHandle_t client_daemon;
int test_sockfd;
const char* addr;
/*
A template for opening a non-blocking POSIX socket.
*/
static int open_nb_socket(const char* addr, const char* port);
static int open_nb_socket(const char* addr, const char* port) {
struct addrinfo hints = {0};
hints.ai_family = AF_UNSPEC; /* IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* Must be TCP */
int sockfd = -1;
int rv;
struct addrinfo *p, *servinfo;
/* get address information */
rv = getaddrinfo(addr, port, &hints, &servinfo);
if(rv != 0) {
printf("Failed to open socket (getaddrinfo): %s\r\n", rv);
return -1;
}
/* open the first possible socket */
for(p = servinfo; p != NULL; p = p->ai_next) {
sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
if (sockfd == -1) continue;
/* connect to server */
rv = connect(sockfd, p->ai_addr, p->ai_addrlen);
if(rv == -1) {
close(sockfd);
sockfd = -1;
continue;
}
break;
}
/* free servinfo */
freeaddrinfo(servinfo);
/* make non-blocking */
if (sockfd != -1) {
int iMode = 1;
ioctlsocket(sockfd, FIONBIO, &iMode);
}
return sockfd;
}
/**
* @brief The function will be called whenever a PUBLISH message is received.
*/
static void publish_callback_1(void** unused, struct mqtt_response_publish *published);
/**
* @brief The client's refresher. This function triggers back-end routines to
* handle ingress/egress traffic to the broker.
*
* @note All this function needs to do is call \ref __mqtt_recv and
* \ref __mqtt_send every so often. I've picked 100 ms meaning that
* client ingress/egress traffic will be handled every 100 ms.
*/
static void client_refresher(void* client);
/**
* @brief Safelty closes the \p sockfd and cancels the \p client_daemon before \c exit.
*/
static void test_close(int sig)
{
if (test_sockfd)
{
close(test_sockfd);
}
printf("mqtt_pub stop publish to %s\r\n", addr);
abort_exec(sig);
vTaskDelete(client_daemon);
}
static int example_mqtt(int argc, const char *argv[])
{
const char* port;
const char* topic;
int ret = 0;
// int argc = 0;
abort_exec = shell_signal(1, test_close);
struct bflb_device_s *rtc;
rtc = bflb_device_get_by_name("rtc");
bflb_rtc_set_time(rtc, 0);
/* our build utc time 1686873600 2023-06-16 00:00:00 */
time_t time_stamp = 1686873600;
/* get address (argv[1] if present) */
if (argc > 1) {
addr = argv[1];
} else {
addr = "test.mosquitto.org";
}
/* get port number (argv[2] if present) */
if (argc > 2) {
port = argv[2];
} else {
port = "1883";
}
/* get the topic name to publish */
if (argc > 3) {
topic = argv[3];
} else {
topic = "bl618";
}
/* open the non-blocking TCP socket (connecting to the broker) */
test_sockfd = open_nb_socket(addr, port);
if (test_sockfd < 0) {
printf("Failed to open socket: %d\r\n", test_sockfd);
test_close(SHELL_SIGINT);
}
/* setup a client */
struct mqtt_client client;
mqtt_init(&client, test_sockfd, sendbuf, sizeof(sendbuf), recvbuf, sizeof(recvbuf), publish_callback_1);
/* Create an anonymous session */
const char* client_id = NULL;
/* Ensure we have a clean session */
uint8_t connect_flags = MQTT_CONNECT_CLEAN_SESSION;
/* Send connection request to the broker. */
ret = mqtt_connect(&client, client_id, NULL, NULL, 0, NULL, NULL, connect_flags, 400);
if (ret != MQTT_OK)
{
printf("fail \r\n");
}
/* check that we don't have any errors */
if (client.error != MQTT_OK) {
printf("error: %s\r\n", mqtt_error_str(client.error));
test_close(SHELL_SIGINT);
}
/* start a thread to refresh the client (handle egress and ingree client traffic) */
xTaskCreate(client_refresher, (char*)"client_ref", 1024, &client, 10, &client_daemon);
/* start publishing the time */
printf("%s is ready to begin publishing the time.\r\n", argv[0]);
printf("Press ENTER to publish the current time.\r\n");
printf("Press CTRL-C to exit.\r\n");
/* block wait CTRL-C exit */
while(1) {
/* get the current time */
time_t time = (BFLB_RTC_TIME2SEC(bflb_rtc_get_time(rtc)) + time_stamp);
struct tm *gmt = gmtime(&time);
char time_buf[26];
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", gmt);
// printf("%s\r\n", time_buf);
/* print a message */
char application_message[256] = {"{\"hello mqtt by bl616/8 !\"}\r\n"};
sprintf(&application_message[strlen(application_message)], "Now time is %s", time_buf);
printf("%s published : \"%s\"\r\n", argv[0], application_message);
/* publish the time */
mqtt_publish(&client, topic, application_message, strlen(application_message) + 1, MQTT_PUBLISH_QOS_0);
/* check for errors */
if (client.error != MQTT_OK) {
printf("error: %s\r\n", mqtt_error_str(client.error));
test_close(SHELL_SIGINT);
}
vTaskDelay(3000);
}
/* disconnect */
/* exit */
test_close(SHELL_SIGINT);
}
static void publish_callback_1(void** unused, struct mqtt_response_publish *published)
{
/* not used in this example */
}
static void client_refresher(void* client)
{
while(1)
{
mqtt_sync((struct mqtt_client*) client);
vTaskDelay(100);
}
}
#ifdef CONFIG_SHELL
#include <shell.h>
extern uint32_t wifi_state;
static int check_wifi_state(void)
{
if (wifi_state == 1)
{
return 0;
} else {
return 1;
}
}
int cmd_mqtt_publisher(int argc, const char **argv)
{
uint32_t ret = 0;
ret = check_wifi_state();
if (ret != 0) {
printf("your wifi not connected!\r\n");
return 0;
}
// xTaskCreate(example_mqtt,(char*)"test_mqtt", 8192, argv, 10, NULL);
example_mqtt(argc, argv);
return 0;
}
SHELL_CMD_EXPORT_ALIAS(cmd_mqtt_publisher, mqtt_pub, mqtt publisher);
#endif

View File

@ -4,13 +4,17 @@ include(proj.conf)
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
# Define
# User
sdk_add_compile_definitions(-DCONFIG_CLI_CMD_ENABLE)
#sdk_add_compile_definitions(-DWIFI_DEMO_TEST)
# sdk_add_compile_options(-DMQTT_USE_CUSTOM_SOCKET_HANDLE)
# sdk_add_compile_definitions(-DMBEDTLS_PK_PARSE_C)
#sdk_add_compile_definitions(-DBL616_DHCP_DEBUG)
target_sources(app PRIVATE
wifi_mqtt_sub.c)
sdk_add_include_directories(.)
sdk_set_main_file(main.c)
project(mqtt)
project(wifi_mqtt_sub)

View File

@ -0,0 +1,128 @@
/*
* FreeRTOS Kernel V10.2.1
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#include "stdio.h"
#ifdef BL702
#define configMTIME_BASE_ADDRESS (0x02000000UL + 0xBFF8UL)
#define configMTIMECMP_BASE_ADDRESS (0x02000000UL + 0x4000UL)
#else
#define configMTIME_BASE_ADDRESS (0xE0000000UL + 0xBFF8UL)
#define configMTIMECMP_BASE_ADDRESS (0xE0000000UL + 0x4000UL)
#endif
#define configSUPPORT_STATIC_ALLOCATION 1
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ((uint32_t)(1 * 1000 * 1000))
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (32)
#define configMINIMAL_STACK_SIZE ((unsigned short)128) /* Only needs to be this high as some demo tasks also use this constant. In production only the idle task would use this. */
#define configTOTAL_HEAP_SIZE ((size_t)100 * 1024)
#define configMAX_TASK_NAME_LEN (16)
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 0
#define configUSE_POSIX_ERRNO 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES (2)
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)
#define configTIMER_QUEUE_LENGTH 4
#define configTIMER_TASK_STACK_DEPTH (1024)
/* Task priorities. Allow these to be overridden. */
#ifndef uartPRIMARY_PRIORITY
#define uartPRIMARY_PRIORITY (configMAX_PRIORITIES - 3)
#endif
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
void vApplicationMallocFailedHook(void);
void vAssertCalled(void);
#define configASSERT(x) \
if ((x) == 0) { \
printf("file [%s]\r\n", __FILE__); \
printf("func [%s]\r\n", __FUNCTION__); \
printf("line [%d]\r\n", __LINE__); \
printf("%s\r\n", (const char *)(#x)); \
vAssertCalled(); \
}
#if (configUSE_TICKLESS_IDLE != 0)
void vApplicationSleep(uint32_t xExpectedIdleTime);
#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vApplicationSleep(xExpectedIdleTime)
#endif
// #define portUSING_MPU_WRAPPERS
#endif /* FREERTOS_CONFIG_H */

View File

@ -0,0 +1,13 @@
SDK_DEMO_PATH ?= .
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
export BL_SDK_BASE
CHIP ?= bl616
BOARD ?= bl616dk
CROSS_COMPILE ?= riscv64-unknown-elf-
# add custom cmake definition
#cmake_definition+=-Dxxx=sss
include $(BL_SDK_BASE)/project.build

View File

@ -0,0 +1,57 @@
# wifi6 tcp case
## Support CHIP
| CHIP | Remark |
|:----------------:|:------:|
|BL616/BL618 | |
## Compile
- BL616/BL618
```bash
make CHIP=bl616 BOARD=bl616dk
```
## Flash
```bash
make flash COMX=xxx ## xxx is your com name
```
## How use wifi mqtt sub test
1. Find some mqtt server or your deployed a mqtt server first. This case default used `test.mosquitto.org:1883` server test; or used EMQX mqtt public server test.
2. Use mqtt client to test if the server is working. You can install `MQTTBox` on windows for testing, you can install it from Microsoft Store. Or use EMQX's online mqtt client for testing.
3. If the server works fine, then you can continue with the next test.
4. connect your WiFi.
5. connect MQTT server. command like `mqtt_sub` or `mqtt_sub <server domain name or server ip> <server port> <topic>`
Log:
```bash
bouffalolab />wifi_sta_connect BL_TEST 12345678
bouffalolab />mqtt_sub
bouffalolab />mqtt_sub listening for 'bl618' messages.
Press CTRL-C to exit.
Received publish('bl618'): {"hello mqtt"}
Received publish('bl618'): {"hello mqtt"}
Received publish('bl618'): {"hello mqtt"}
mqtt_sub disconnecting from test.mosquitto.org
^C
```
use broker.emqx.io mqtt public server test log:
```bash
bouffalolab />wifi_sta_connect BL_TEST 12345678
bouffalolab />mqtt_sub broker.emqx.io 1883 bl618
bouffalolab />mqtt_sub listening for 'bl618' messages.
Press CTRL-C to exit.
Received publish('bl618'): {"hello mqtt"}
Received publish('bl618'): {"hello mqtt"}
mqtt_sub disconnecting from broker.emqx.io
^C
```

View File

@ -0,0 +1,20 @@
[cfg]
# 0: no erase, 1:programmed section erase, 2: chip erase
erase = 1
# skip mode set first para is skip addr, second para is skip len, multi-segment region with ; separated
skip_mode = 0x0, 0x0
# 0: not use isp mode, #1: isp mode
boot2_isp_mode = 0
[boot2]
filedir = ./build/build_out/boot2_*.bin
address = 0x000000
[partition]
filedir = ./build/build_out/partition*.bin
address = 0xE000
[FW]
filedir = ./build/build_out/wifi*_$(CHIPNAME)*.bin
address = @partition

View File

@ -0,0 +1,138 @@
/*
* 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: Simon Goldschmidt
*
*/
#ifndef LWIP_HDR_LWIPOPTS_H__
#define LWIP_HDR_LWIPOPTS_H__
#define LWIP_NETIF_API 1
#define LWIP_DEBUG 1
#define LWIP_STATS_DISPLAY 1
#define SOCKETS_DEBUG LWIP_DBG_OFF
#ifdef BL616_DHCP_DEBUG
#define DHCP_DEBUG LWIP_DBG_ON
#else
#define DHCP_DEBUG LWIP_DBG_OFF
#endif
#define ICMP_DEBUG LWIP_DBG_OFF
#define ETHARP_DEBUG LWIP_DBG_OFF
#define LWIP_MULTICAST_PING 1
#define LWIP_BROADCAST_PING 1
#define TCPIP_MBOX_SIZE 64
#define TCPIP_THREAD_STACKSIZE 1024
#define TCPIP_THREAD_PRIO 28
#define DEFAULT_THREAD_STACKSIZE 1024
#define DEFAULT_THREAD_PRIO 1
#define DEFAULT_RAW_RECVMBOX_SIZE 32
#define DEFAULT_UDP_RECVMBOX_SIZE 64
#define DEFAULT_TCP_RECVMBOX_SIZE 64
#define DEFAULT_ACCEPTMBOX_SIZE 32
#define LWIP_NETIF_LOOPBACK 1
#define LWIP_HAVE_LOOPIF 1
#define LWIP_LOOPBACK_MAX_PBUFS 0
#define LWIP_CHKSUM_ALGORITHM 3
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
#define PBUF_LINK_ENCAPSULATION_HLEN 388
#define IP_REASS_MAX_PBUFS (2 * CONFIG_MAC_RXQ_DEPTH - 2)
#define MEMP_NUM_NETBUF 32
#define MEMP_NUM_NETCONN 16
#define MEMP_NUM_UDP_PCB 16
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)
#define MAC_TXQ_DEPTH CONFIG_MAC_TXQ_DEPTH
#define MAC_RXQ_DEPTH CONFIG_MAC_RXQ_DEPTH
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1)
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#define MEM_MIN MEM_MIN_TCP
#define MEM_ALIGNMENT 4
#ifdef LWIP_HEAP_SIZE
#define MEM_SIZE LWIP_HEAP_SIZE
#else
#if MEM_MIN > 8192
#define MEM_SIZE MEM_MIN
#else
#define MEM_SIZE 8192
#endif
#endif
#define LWIP_HOOK_FILENAME "lwiphooks.h"
#define LWIP_RAW 1
#define LWIP_MULTICAST_TX_OPTIONS 1
#define LWIP_TIMEVAL_PRIVATE 0 // use sys/time.h for struct timeval
//#define LWIP_PROVIDE_ERRNO
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
extern int *__errno(void);
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define LWIP_SUPPORT_CUSTOM_PBUF 1
#ifdef HIGH_PERFORMANCE_PBUF
#define LWIP_NETIF_TX_SINGLE_PBUF 0
#else
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#endif
#define LWIP_RAND() ((u32_t)random())
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM")))
#endif /* LWIP_HDR_LWIPOPTS_H__ */

View File

@ -0,0 +1,176 @@
/****************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "mem.h"
#include <lwip/tcpip.h>
#include <lwip/sockets.h>
#include <lwip/netdb.h>
#include "bl_fw_api.h"
#include "wifi_mgmr_ext.h"
#include "wifi_mgmr.h"
#include "bflb_irq.h"
#include "bflb_uart.h"
#include "bl616_glb.h"
#include "rfparam_adapter.h"
#include "board.h"
#include "shell.h"
#define DBG_TAG "MAIN"
#include "log.h"
struct bflb_device_s *gpio;
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define WIFI_STACK_SIZE (1536)
#define TASK_PRIORITY_FW (16)
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static struct bflb_device_s *uart0;
static TaskHandle_t wifi_fw_task;
static wifi_conf_t conf = {
.country_code = "CN",
};
extern void shell_init_with_task(struct bflb_device_s *shell);
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Functions
****************************************************************************/
int wifi_start_firmware_task(void)
{
LOG_I("Starting wifi ...\r\n");
/* enable wifi clock */
GLB_PER_Clock_UnGate(GLB_AHB_CLOCK_IP_WIFI_PHY | GLB_AHB_CLOCK_IP_WIFI_MAC_PHY | GLB_AHB_CLOCK_IP_WIFI_PLATFORM);
GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_WIFI);
/* set ble controller EM Size */
GLB_Set_EM_Sel(GLB_WRAM160KB_EM0KB);
if (0 != rfparam_init(0, NULL, 0)) {
LOG_I("PHY RF init failed!\r\n");
return 0;
}
LOG_I("PHY RF init success!\r\n");
/* Enable wifi irq */
extern void interrupt0_handler(void);
bflb_irq_attach(WIFI_IRQn, (irq_callback)interrupt0_handler, NULL);
bflb_irq_enable(WIFI_IRQn);
xTaskCreate(wifi_main, (char *)"fw", WIFI_STACK_SIZE, NULL, TASK_PRIORITY_FW, &wifi_fw_task);
return 0;
}
volatile uint32_t wifi_state = 0;
void wifi_event_handler(uint32_t code)
{
switch (code) {
case CODE_WIFI_ON_INIT_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_INIT_DONE\r\n", __func__);
wifi_mgmr_init(&conf);
} break;
case CODE_WIFI_ON_MGMR_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_MGMR_DONE\r\n", __func__);
} break;
case CODE_WIFI_ON_SCAN_DONE: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_SCAN_DONE\r\n", __func__);
wifi_mgmr_sta_scanlist();
} break;
case CODE_WIFI_ON_CONNECTED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_CONNECTED\r\n", __func__);
void mm_sec_keydump();
mm_sec_keydump();
} break;
case CODE_WIFI_ON_GOT_IP: {
wifi_state = 1;
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP\r\n", __func__);
LOG_I("[SYS] Memory left is %d Bytes\r\n", kfree_size());
} break;
case CODE_WIFI_ON_DISCONNECT: {
wifi_state = 0;
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT\r\n", __func__);
} break;
case CODE_WIFI_ON_AP_STARTED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STARTED\r\n", __func__);
} break;
case CODE_WIFI_ON_AP_STOPPED: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_AP_STOPPED\r\n", __func__);
} break;
case CODE_WIFI_ON_AP_STA_ADD: {
LOG_I("[APP] [EVT] [AP] [ADD] %lld\r\n", xTaskGetTickCount());
} break;
case CODE_WIFI_ON_AP_STA_DEL: {
LOG_I("[APP] [EVT] [AP] [DEL] %lld\r\n", xTaskGetTickCount());
} break;
default: {
LOG_I("[APP] [EVT] Unknown code %u \r\n", code);
}
}
}
int main(void)
{
board_init();
uart0 = bflb_device_get_by_name("uart0");
shell_init_with_task(uart0);
tcpip_init(NULL, NULL);
wifi_start_firmware_task();
vTaskStartScheduler();
while (1) {
}
}

View File

@ -0,0 +1,175 @@
/**
* \file config.h
*
* \brief Configuration options (set of defines)
*
* This set of compile-time options may be used to enable
* or disable features selectively, and reduce the global
* memory footprint.
*/
/*
* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBEDTLS_CONFIG_H
#define MBEDTLS_CONFIG_H
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_CIPHER_MODE_CBC
#define MBEDTLS_CIPHER_MODE_CTR
#define MBEDTLS_CIPHER_PADDING_PKCS7
#define MBEDTLS_CIPHER_PADDING_ZEROS
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
#define MBEDTLS_REMOVE_3DES_CIPHERSUITES
#define MBEDTLS_ECDH_C
#define MBEDTLS_ECDSA_C
//#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
//#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
//#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
//#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
//#define MBEDTLS_ECP_DP_BP256R1_ENABLED
//#define MBEDTLS_ECP_DP_BP384R1_ENABLED
//#define MBEDTLS_ECP_DP_BP512R1_ENABLED
//#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
//#define MBEDTLS_ECP_DP_CURVE448_ENABLED
#define MBEDTLS_ECP_NIST_OPTIM
#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
//XXX TODO remove bl606p
#if defined(CFG_CHIP_BL606P) || defined(CFG_CHIP_BL808)
#define MBEDTLS_PKCS5_C
#endif
#define MBEDTLS_PKCS1_V15
#define MBEDTLS_PKCS1_V21
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
#define MBEDTLS_SSL_PROTO_TLS1_2
#define MBEDTLS_SSL_ALPN
#define MBEDTLS_SSL_SESSION_TICKETS
#define MBEDTLS_SSL_SERVER_NAME_INDICATION
#define MBEDTLS_X509_CHECK_KEY_USAGE
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
#define MBEDTLS_AES_C
#define MBEDTLS_AES_ROM_TABLES
#define MBEDTLS_BASE64_C
#define MBEDTLS_ASN1_PARSE_C
#define MBEDTLS_ASN1_WRITE_C
#define MBEDTLS_BIGNUM_C
#define MBEDTLS_CIPHER_C
#define MBEDTLS_CTR_DRBG_C
#define MBEDTLS_DEBUG_C
#define MBEDTLS_ECP_C
#define MBEDTLS_ENTROPY_C
#define MBEDTLS_ERROR_C
#define MBEDTLS_GCM_C
#define MBEDTLS_MD_C
#define MBEDTLS_MD5_C
#define MBEDTLS_OID_C
#define MBEDTLS_PEM_PARSE_C
#define MBEDTLS_PK_C
#define MBEDTLS_PK_PARSE_C
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_GENPRIME
#define MBEDTLS_RSA_C
#define MBEDTLS_DHM_C
#define MBEDTLS_SHA1_C
#define MBEDTLS_SHA256_C
#define MBEDTLS_SHA512_C
#define MBEDTLS_SSL_COOKIE_C
#define MBEDTLS_SSL_CLI_C
#define MBEDTLS_SSL_TLS_C
#define MBEDTLS_X509_USE_C
#define MBEDTLS_X509_CRT_PARSE_C
//#define MBEDTLS_NET_C
//#define MBEDTLS_FS_IO
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#define MBEDTLS_PLATFORM_STD_MEM_HDR "mbedtls_port_bouffalo_sdk.h"
// Define BL_MPI_LARGE_NUM_SOFTWARE_MPI to allow operate on very big bignums
/* #define BL_MPI_LARGE_NUM_SOFTWARE_MPI */
// Hash HW
#ifdef CONFIG_MBEDTLS_SHA1_USE_HW
#define MBEDTLS_SHA1_ALT
#endif
#ifdef CONFIG_MBEDTLS_SHA256_USE_HW
#define MBEDTLS_SHA256_ALT
#endif
#ifdef CONFIG_MBEDTLS_SHA512_USE_HW
#define MBEDTLS_SHA512_ALT
#endif
// AES HW
#ifdef CONFIG_MBEDTLS_AES_USE_HW
#define MBEDTLS_AES_ALT
#endif
// ECC HW
#ifdef CONFIG_MBEDTLS_ECC_USE_HW
#define MBEDTLS_ECP_ALT
#endif
#if defined(CONFIG_MBEDTLS_ECC_USE_HW) && defined(MBEDTLS_ECP_RESTARTABLE)
#error "ECP Restartable is not implemented with ECP HW acceleration!"
#endif
/* Target and application specific configurations
*
* Allow user to override any previous default.
*
*/
#if defined(MBEDTLS_USER_CONFIG_FILE)
#include MBEDTLS_USER_CONFIG_FILE
#endif
#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
#include "mbedtls/config_psa.h"
#endif
#include "mbedtls/check_config.h"
#endif /* MBEDTLS_CONFIG_H */

View File

@ -0,0 +1,35 @@
# Components
set(CONFIG_BFLOG 0)
set(CONFIG_FREERTOS 1)
set(CONFIG_POSIX 1)
set(CONFIG_TLSF 1)
set(CONFIG_SHELL 1)
set(CONFIG_LWIP 1)
set(CONFIG_WIFI6 1)
set(CONFIG_RF 1)
set(CONFIG_MBEDTLS 1)
set(CONFIG_PSRAM 1)
set(CONFIG_DHCPD 1)
set(CONFIG_PING 1)
set(CONFIG_MQTT 1)
set(CONFIG_VSNPRINTF_FLOAT 1)
set(CONFIG_VSNPRINTF_FLOAT_EX 1)
set(CONFIG_VSNPRINTF_LONG_LONG 1)
# Config
## mbedtls
# set(CONFIG_MBEDTLS_SELF_TEST 1)
# set(CONFIG_MBEDTLS_AES_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA1_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA256_USE_HW 1)
# set(CONFIG_MBEDTLS_SHA512_USE_HW 1)
# set(CONFIG_MBEDTLS_ECC_USE_HW 1)
# set(CONFIG_MBEDTLS_BIGNUM_USE_HW 1)
# wifi
set(CONFIG_VIF_MAX 2)
set(CONFIG_STA_MAX 4)
set(CONFIG_MAC_TXQ_DEPTH 32)
set(CONFIG_MAC_RXQ_DEPTH 12)

View File

@ -0,0 +1,247 @@
/**
* @file
* A simple program that subscribes to a topic.
*/
#include "FreeRTOS_POSIX.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <lwip/errno.h>
#include <netdb.h>
#include "utils_getopt.h"
#include "mqtt.h"
#include "shell.h"
uint8_t sendbuf[2048]; /* sendbuf should be large enough to hold multiple whole mqtt messages */
uint8_t recvbuf[1024]; /* recvbuf should be large enough any whole mqtt message expected to be received */
shell_sig_func_ptr abort_exec;
static TaskHandle_t client_daemon;
int test_sockfd;
const char* addr;
/*
A template for opening a non-blocking POSIX socket.
*/
static int open_nb_socket(const char* addr, const char* port);
static int open_nb_socket(const char* addr, const char* port) {
struct addrinfo hints = {0};
hints.ai_family = AF_UNSPEC; /* IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* Must be TCP */
int sockfd = -1;
int rv;
struct addrinfo *p, *servinfo;
/* get address information */
rv = getaddrinfo(addr, port, &hints, &servinfo);
if(rv != 0) {
printf("Failed to open socket (getaddrinfo): %s\r\n", rv);
return -1;
}
/* open the first possible socket */
for(p = servinfo; p != NULL; p = p->ai_next) {
sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
if (sockfd == -1) continue;
/* connect to server */
rv = connect(sockfd, p->ai_addr, p->ai_addrlen);
if(rv == -1) {
close(sockfd);
sockfd = -1;
continue;
}
break;
}
/* free servinfo */
freeaddrinfo(servinfo);
/* make non-blocking */
if (sockfd != -1) {
int iMode = 1;
ioctlsocket(sockfd, FIONBIO, &iMode);
}
return sockfd;
}
/**
* @brief The function will be called whenever a PUBLISH message is received.
*/
static void publish_callback_1(void** unused, struct mqtt_response_publish *published);
/**
* @brief The client's refresher. This function triggers back-end routines to
* handle ingress/egress traffic to the broker.
*
* @note All this function needs to do is call \ref __mqtt_recv and
* \ref __mqtt_send every so often. I've picked 100 ms meaning that
* client ingress/egress traffic will be handled every 100 ms.
*/
static void client_refresher(void* client);
/**
* @brief Safelty closes the \p sockfd and cancels the \p client_daemon before \c exit.
*/
static void test_close(int sig)
{
if (test_sockfd)
{
close(test_sockfd);
}
printf("mqtt_sub disconnecting from %s\r\n", addr);
abort_exec(sig);
vTaskDelete(client_daemon);
}
static int example_mqtt(int argc, const char *argv[])
{
const char* port;
const char* topic;
int ret = 0;
// int argc = 0;
abort_exec = shell_signal(1, test_close);
/* get address (argv[1] if present) */
if (argc > 1) {
addr = argv[1];
} else {
addr = "test.mosquitto.org";
}
/* get port number (argv[2] if present) */
if (argc > 2) {
port = argv[2];
} else {
port = "1883";
}
/* get the topic name to publish */
if (argc > 3) {
topic = argv[3];
} else {
topic = "bl618";
}
/* open the non-blocking TCP socket (connecting to the broker) */
test_sockfd = open_nb_socket(addr, port);
if (test_sockfd < 0) {
printf("Failed to open socket: %d\r\n", test_sockfd);
test_close(SHELL_SIGINT);
}
/* setup a client */
struct mqtt_client client;
mqtt_init(&client, test_sockfd, sendbuf, sizeof(sendbuf), recvbuf, sizeof(recvbuf), publish_callback_1);
/* Create an anonymous session */
const char* client_id = NULL;
/* Ensure we have a clean session */
uint8_t connect_flags = MQTT_CONNECT_CLEAN_SESSION;
/* Send connection request to the broker. */
ret = mqtt_connect(&client, client_id, NULL, NULL, 0, NULL, NULL, connect_flags, 400);
if (ret != MQTT_OK)
{
printf("fail \r\n");
}
/* check that we don't have any errors */
if (client.error != MQTT_OK) {
printf("error: %s\r\n", mqtt_error_str(client.error));
test_close(SHELL_SIGINT);
}
/* start a thread to refresh the client (handle egress and ingree client traffic) */
xTaskCreate(client_refresher, (char*)"client_ref", 1024, &client, 10, &client_daemon);
/* subscribe */
mqtt_subscribe(&client, topic, 0);
/* start publishing the time */
printf("%s listening for '%s' messages.\r\n", argv[0], topic);
printf("Press CTRL-C to exit.\r\n");
/* block wait CTRL-C exit */
while(1) {
vTaskDelay(100);
}
/* disconnect */
/* exit */
test_close(SHELL_SIGINT);
}
static void publish_callback_1(void** unused, struct mqtt_response_publish *published)
{
/* note that published->topic_name is NOT null-terminated (here we'll change it to a c-string) */
char* topic_name = (char*) malloc(published->topic_name_size + 1);
memcpy(topic_name, published->topic_name, published->topic_name_size);
topic_name[published->topic_name_size] = '\0';
char* topic_msg = (char*) malloc(published->application_message_size + 1);
memcpy(topic_msg, published->application_message, published->application_message_size);
topic_msg[published->application_message_size] = '\0';
printf("Received publish('%s'): %s\r\n", topic_name, topic_msg);
free(topic_name);
free(topic_msg);
}
static void client_refresher(void* client)
{
while(1)
{
mqtt_sync((struct mqtt_client*) client);
vTaskDelay(100);
}
}
#ifdef CONFIG_SHELL
#include <shell.h>
extern uint32_t wifi_state;
static int check_wifi_state(void)
{
if (wifi_state == 1)
{
return 0;
} else {
return 1;
}
}
int cmd_mqtt_subscribe(int argc, const char **argv)
{
uint32_t ret = 0;
ret = check_wifi_state();
if (ret != 0) {
printf("your wifi not connected!\r\n");
return 0;
}
// xTaskCreate(example_mqtt,(char*)"test_mqtt", 8192, argv, 10, NULL);
example_mqtt(argc, argv);
return 0;
}
SHELL_CMD_EXPORT_ALIAS(cmd_mqtt_subscribe, mqtt_sub, mqtt subscribe);
#endif

View File

@ -4,15 +4,14 @@ include(proj.conf)
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
# Define
# User
sdk_add_compile_definitions(-DCONFIG_CLI_CMD_ENABLE)
#sdk_add_compile_definitions(-DWIFI_DEMO_TEST)
#sdk_add_compile_definitions(-DBL616_DHCP_DEBUG)
target_sources(app PRIVATE
wifi_tcp_client.c
target_sources(app PRIVATE
wifi_tcp_client.c
wifi_tcp_server.c)
sdk_add_include_directories(.)
sdk_set_main_file(main.c)

View File

@ -32,10 +32,6 @@
#ifndef LWIP_HDR_LWIPOPTS_H__
#define LWIP_HDR_LWIPOPTS_H__
#define RX_BUF_CNT 4
#define MAC_TXQ_DEPTH 16
#define MAC_RXQ_DEPTH 12
#define LWIP_NETIF_API 1
#define LWIP_DEBUG 1
#define LWIP_STATS_DISPLAY 1
@ -70,52 +66,31 @@
#define PBUF_LINK_ENCAPSULATION_HLEN 388
#define IP_REASS_MAX_PBUFS (RX_BUF_CNT - 2)
#define IP_REASS_MAX_PBUFS (2 * CONFIG_MAC_RXQ_DEPTH - 2)
#define MEMP_NUM_NETBUF 32
#define MEMP_NUM_NETCONN 16
#define MEMP_NUM_UDP_PCB 16
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define MAC_TXQ_DEPTH CONFIG_MAC_TXQ_DEPTH
#define MAC_RXQ_DEPTH CONFIG_MAC_RXQ_DEPTH
#if NX_BEACONING
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#else
#define TCP_SND_BUF (2 * MAC_TXQ_DEPTH * TCP_MSS)
#endif
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), \
(2 * TCP_MSS) + 1), \
(TCP_SND_BUF)-1)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1)
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#if NX_TG
#define MEM_MIN_TG 16384
#else
#define MEM_MIN_TG 0
#endif
#if MEM_MIN_TCP > MEM_MIN_TG
#define MEM_MIN MEM_MIN_TCP
#else
#define MEM_MIN MEM_MIN_TG
#endif
#define MEM_ALIGNMENT 4
#if defined(CFG_SDIOWIFI)
#undef MEM_MIN
#ifdef LP_APP
#define MEM_MIN (14 * 1024)
#else
#define MEM_MIN (48 * 1024)
#endif
#endif
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#define MEM_MIN MEM_MIN_TCP
#define MEM_ALIGNMENT 4
#ifdef LWIP_HEAP_SIZE
#define MEM_SIZE LWIP_HEAP_SIZE
@ -135,54 +110,19 @@
#define LWIP_TIMEVAL_PRIVATE 0 // use sys/time.h for struct timeval
//#define LWIP_PROVIDE_ERRNO
#ifndef PLATFORM_PRIVDE_ERRNO
#define LWIP_PROVIDE_ERRNO 1
#endif
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
extern int *__errno(void);
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#if 0
/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */
#define NO_SYS 0
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define SYS_LIGHTWEIGHT_PROT 0
#define LWIP_IPV6 1
#define IPV6_FRAG_COPYHEADER 1
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
/* Turn off checksum verification of fuzzed data */
#define CHECKSUM_CHECK_IP 0
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_TCP 0
#define CHECKSUM_CHECK_ICMP 0
#define CHECKSUM_CHECK_ICMP6 0
/* Minimal changes to opt.h required for tcp unit tests: */
#define MEM_SIZE 16000
#define TCP_SND_QUEUELEN 40
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#define TCP_SND_BUF (12 * TCP_MSS)
#define TCP_WND (10 * TCP_MSS)
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 0
#define PBUF_POOL_SIZE 400 /* pbuf tests need ~200KByte */
/* Minimal changes to opt.h required for etharp unit tests: */
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#endif
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
@ -193,6 +133,6 @@ extern int *__errno(void);
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#endif
#define LWIP_RAND() ((u32_t)random())
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__ ((section("SHAREDRAM")))
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM")))
#endif /* LWIP_HDR_LWIPOPTS_H__ */

View File

@ -24,6 +24,7 @@
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "mem.h"
#include <lwip/tcpip.h>
#include <lwip/sockets.h>
@ -132,6 +133,7 @@ void wifi_event_handler(uint32_t code)
} break;
case CODE_WIFI_ON_GOT_IP: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP\r\n", __func__);
LOG_I("[SYS] Memory left is %d Bytes\r\n", kfree_size());
} break;
case CODE_WIFI_ON_DISCONNECT: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT\r\n", __func__);

View File

@ -11,7 +11,7 @@ set(CONFIG_MBEDTLS 1)
# set(CONFIG_PSRAM 1)
set(CONFIG_DHCPD 1)
set(CONFIG_PING 1)
set(CONFIG_MQTT 1)
# set(CONFIG_MQTT 1)
set(CONFIG_VSNPRINTF_FLOAT 1)
set(CONFIG_VSNPRINTF_FLOAT_EX 1)
@ -25,3 +25,9 @@ set(CONFIG_MBEDTLS_ECC_USE_HW 0)
set(CONFIG_MBEDTLS_SHA1_USE_HW 0)
set(CONFIG_MBEDTLS_SHA256_USE_HW 0)
set(CONFIG_MBEDTLS_SHA512_USE_HW 0)
# wifi
set(CONFIG_VIF_MAX 2)
set(CONFIG_STA_MAX 4)
set(CONFIG_MAC_TXQ_DEPTH 32)
set(CONFIG_MAC_RXQ_DEPTH 12)

View File

@ -4,14 +4,13 @@ include(proj.conf)
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
# Define
# User
sdk_add_compile_definitions(-DCONFIG_CLI_CMD_ENABLE)
#sdk_add_compile_definitions(-DWIFI_DEMO_TEST)
#sdk_add_compile_definitions(-DBL616_DHCP_DEBUG)
target_sources(app PRIVATE
target_sources(app PRIVATE
wifi_udp_echo.c)
sdk_add_include_directories(.)
sdk_set_main_file(main.c)

View File

@ -32,10 +32,6 @@
#ifndef LWIP_HDR_LWIPOPTS_H__
#define LWIP_HDR_LWIPOPTS_H__
#define RX_BUF_CNT 4
#define MAC_TXQ_DEPTH 16
#define MAC_RXQ_DEPTH 12
#define LWIP_NETIF_API 1
#define LWIP_DEBUG 1
#define LWIP_STATS_DISPLAY 1
@ -70,52 +66,31 @@
#define PBUF_LINK_ENCAPSULATION_HLEN 388
#define IP_REASS_MAX_PBUFS (RX_BUF_CNT - 2)
#define IP_REASS_MAX_PBUFS (2 * CONFIG_MAC_RXQ_DEPTH - 2)
#define MEMP_NUM_NETBUF 32
#define MEMP_NUM_NETCONN 16
#define MEMP_NUM_UDP_PCB 16
#define MEMP_NUM_REASSDATA LWIP_MIN((IP_REASS_MAX_PBUFS), 5)
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define MAC_TXQ_DEPTH CONFIG_MAC_TXQ_DEPTH
#define MAC_RXQ_DEPTH CONFIG_MAC_RXQ_DEPTH
#if NX_BEACONING
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#else
#define TCP_SND_BUF (2 * MAC_TXQ_DEPTH * TCP_MSS)
#endif
#define TCP_MSS 1360
#define TCP_WND (2 * MAC_RXQ_DEPTH * TCP_MSS)
#define TCP_SND_BUF (4 * MAC_TXQ_DEPTH * TCP_MSS)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), \
(2 * TCP_MSS) + 1), \
(TCP_SND_BUF)-1)
#define TCP_QUEUE_OOSEQ 1
#define MEMP_NUM_TCP_SEG ((4 * TCP_SND_BUF) / TCP_MSS)
#define MEMP_NUM_PBUF (TCP_SND_BUF / TCP_MSS)
#define PBUF_POOL_SIZE 0
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 2
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 4), (2 * TCP_MSS) + 1), (TCP_SND_BUF)-1)
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#if NX_TG
#define MEM_MIN_TG 16384
#else
#define MEM_MIN_TG 0
#endif
#if MEM_MIN_TCP > MEM_MIN_TG
#define MEM_MIN MEM_MIN_TCP
#else
#define MEM_MIN MEM_MIN_TG
#endif
#define MEM_ALIGNMENT 4
#if defined(CFG_SDIOWIFI)
#undef MEM_MIN
#ifdef LP_APP
#define MEM_MIN (14 * 1024)
#else
#define MEM_MIN (48 * 1024)
#endif
#endif
#define MEM_MIN_TCP (2300 + MEMP_NUM_PBUF * (100 + PBUF_LINK_ENCAPSULATION_HLEN))
#define MEM_MIN MEM_MIN_TCP
#define MEM_ALIGNMENT 4
#ifdef LWIP_HEAP_SIZE
#define MEM_SIZE LWIP_HEAP_SIZE
@ -135,54 +110,19 @@
#define LWIP_TIMEVAL_PRIVATE 0 // use sys/time.h for struct timeval
//#define LWIP_PROVIDE_ERRNO
#ifndef PLATFORM_PRIVDE_ERRNO
#define LWIP_PROVIDE_ERRNO 1
#endif
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_IGMP 0
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define SO_REUSE 1
#define LWIP_TCP_KEEPALIVE 1
extern int *__errno(void);
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#if 0
/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */
#define NO_SYS 0
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define SYS_LIGHTWEIGHT_PROT 0
#define LWIP_IPV6 1
#define IPV6_FRAG_COPYHEADER 1
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
/* Turn off checksum verification of fuzzed data */
#define CHECKSUM_CHECK_IP 0
#define CHECKSUM_CHECK_UDP 0
#define CHECKSUM_CHECK_TCP 0
#define CHECKSUM_CHECK_ICMP 0
#define CHECKSUM_CHECK_ICMP6 0
/* Minimal changes to opt.h required for tcp unit tests: */
#define MEM_SIZE 16000
#define TCP_SND_QUEUELEN 40
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#define TCP_SND_BUF (12 * TCP_MSS)
#define TCP_WND (10 * TCP_MSS)
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 0
#define PBUF_POOL_SIZE 400 /* pbuf tests need ~200KByte */
/* Minimal changes to opt.h required for etharp unit tests: */
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#endif
#define errno (*__errno())
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_API 1
#define ETHARP_SUPPORT_STATIC_ENTRIES 1
@ -193,6 +133,6 @@ extern int *__errno(void);
#define LWIP_NETIF_TX_SINGLE_PBUF 1
#endif
#define LWIP_RAND() ((u32_t)random())
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__ ((section("SHAREDRAM")))
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) __attribute__((section("SHAREDRAM")))
#endif /* LWIP_HDR_LWIPOPTS_H__ */

View File

@ -24,6 +24,7 @@
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "mem.h"
#include <lwip/tcpip.h>
#include <lwip/sockets.h>
@ -132,6 +133,7 @@ void wifi_event_handler(uint32_t code)
} break;
case CODE_WIFI_ON_GOT_IP: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_GOT_IP\r\n", __func__);
LOG_I("[SYS] Memory left is %d Bytes\r\n", kfree_size());
} break;
case CODE_WIFI_ON_DISCONNECT: {
LOG_I("[APP] [EVT] %s, CODE_WIFI_ON_DISCONNECT\r\n", __func__);

View File

@ -11,8 +11,7 @@ set(CONFIG_MBEDTLS 1)
# set(CONFIG_PSRAM 1)
set(CONFIG_DHCPD 1)
set(CONFIG_PING 1)
set(CONFIG_MQTT 1)
# set(CONFIG_IPERF 1)
# set(CONFIG_MQTT 1)
set(CONFIG_VSNPRINTF_FLOAT 1)
set(CONFIG_VSNPRINTF_FLOAT_EX 1)
@ -26,3 +25,9 @@ set(CONFIG_MBEDTLS_ECC_USE_HW 0)
set(CONFIG_MBEDTLS_SHA1_USE_HW 0)
set(CONFIG_MBEDTLS_SHA256_USE_HW 0)
set(CONFIG_MBEDTLS_SHA512_USE_HW 0)
# wifi
set(CONFIG_VIF_MAX 2)
set(CONFIG_STA_MAX 4)
set(CONFIG_MAC_TXQ_DEPTH 32)
set(CONFIG_MAC_RXQ_DEPTH 12)