Skip to content

Commit

Permalink
Fix potential connection issue with mismatch between CIPSTATUS and lo…
Browse files Browse the repository at this point in the history
…cal data
  • Loading branch information
MaJerle committed Jul 9, 2023
1 parent bec5710 commit 290280d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 23 deletions.
5 changes: 3 additions & 2 deletions dev/lwesp_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#define LWESP_CFG_ESP8266 1
#define LWESP_CFG_ESP32_C3 1

#define LWESP_CFG_CONN_MAX_DATA_LEN 2048
#define LWESP_CFG_CONN_MAX_DATA_LEN 8192
#define LWESP_CFG_INPUT_USE_PROCESS 1
#define LWESP_CFG_AT_ECHO 0

Expand All @@ -84,7 +84,8 @@
#define LWESP_CFG_FLASH 1

#define LWESP_CFG_RESET_ON_INIT 1
#define LWESP_CFG_CONN_MANUAL_TCP_RECEIVE 0
#define LWESP_CFG_RESTORE_ON_INIT 0
#define LWESP_CFG_CONN_MANUAL_TCP_RECEIVE 1

#define LWESP_CFG_ACCESS_POINT_STRUCT_FULL_FIELDS 1
#define LWESP_CFG_LIST_CMD 1
Expand Down
1 change: 0 additions & 1 deletion lwesp/src/api/lwesp_netconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ netconn_evt(lwesp_evt_t* evt) {
++nc->mbox_receive_entries;
}
}

break;
}
default: return lwespERR;
Expand Down
29 changes: 15 additions & 14 deletions lwesp/src/include/lwesp/lwesp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ typedef struct {
uint8_t hidden; /*!< broadcast the SSID, 0 -- No, 1 -- Yes */
} lwesp_ap_conf_t;

/**
* \ingroup LWESP_TYPES
* \brief Simple helper structure for application purpose
*
* User can define array of structure objects and set its
* preferred WIFI options, then trying to iterate through
* all and connect to first available
*
* \note This structure is not used by the LwESP library
*/
typedef struct {
const char* ssid; /*!< SSID to connect to */
const char* pass; /*!< Password for SSID */
} lwesp_sta_ssid_pass_pair_t;

/**
* \ingroup LWESP_STA
* \brief Station data structure
Expand All @@ -304,20 +319,6 @@ typedef struct {
lwesp_mac_t mac; /*!< MAC address of connected station */
} lwesp_sta_t;

/**
* \ingroup LWESP_TYPES
* \brief Date and time structure
*/
typedef struct {
uint8_t date; /*!< Day in a month, from 1 to up to 31 */
uint8_t month; /*!< Month in a year, from 1 to 12 */
uint16_t year; /*!< Year */
uint8_t day; /*!< Day in a week, from 1 to 7 */
uint8_t hours; /*!< Hours in a day, from 0 to 23 */
uint8_t minutes; /*!< Minutes in a hour, from 0 to 59 */
uint8_t seconds; /*!< Seconds in a minute, from 0 to 59 */
} lwesp_datetime_t;

/**
* \brief List of possible flash operations
*
Expand Down
2 changes: 1 addition & 1 deletion lwesp/src/include/system/port/cmsis_os/lwesp_sys_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef osPriority_t lwesp_sys_thread_prio_t;
#define LWESP_SYS_MBOX_NULL ((lwesp_sys_mbox_t)0)
#define LWESP_SYS_TIMEOUT ((uint32_t)osWaitForever)
#define LWESP_SYS_THREAD_PRIO (osPriorityNormal)
#define LWESP_SYS_THREAD_SS (512)
#define LWESP_SYS_THREAD_SS (1536)

#endif /* LWESP_CFG_OS && !__DOXYGEN__ */

Expand Down
5 changes: 5 additions & 0 deletions lwesp/src/lwesp/lwesp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,12 @@ lwespi_process_sub_cmd(lwesp_msg_t* msg, lwesp_status_flags_t* stat) {
if (stat->is_ok) { /* Did we join successfully? */
SET_NEW_CMD(LWESP_CMD_WIFI_CWDHCP_GET); /* Check IP address status */
} else {
esp.m.sta.f.has_ip = 0; /* Has NO IP */
esp.m.sta.f.is_connected = 0; /* Force disconnected status */
#if LWESP_CFG_IPV6
esp.m.sta.f.has_ipv6_ll = 0;
esp.m.sta.f.has_ipv6_gl = 0;
#endif /* LWESP_CFG_IPV6 */
/*
* Parse received error message,
* if final result was error, decide what type
Expand Down
13 changes: 11 additions & 2 deletions lwesp/src/lwesp/lwesp_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,17 @@ lwespr_t
lwespi_parse_cipstatus_cipstate(const char* str) {
uint8_t cn_num = 0;

cn_num = lwespi_parse_number(&str); /* Parse connection number */
esp.m.active_conns |= 1 << cn_num; /* Set flag as active */
cn_num = lwespi_parse_number(&str); /* Parse connection number */
esp.m.active_conns |= 1 << cn_num; /* Set flag as active */

/*
* If connection looks "alive" in the
* cipstatus result, but not alive in internal
* structure, then force connection close ASAP
*/
if (!esp.m.conns[cn_num].status.f.active) {
lwesp_conn_close(&esp.m.conns[cn_num], 0);
}

lwespi_parse_string(&str, NULL, 0, 1); /* Parse string and ignore result */
lwespi_parse_ip(&str, &esp.m.conns[cn_num].remote_ip);
Expand Down
6 changes: 3 additions & 3 deletions lwesp/src/system/lwesp_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#endif /* !defined(LWESP_USART_DMA_RX_BUFF_SIZE) */

#if !defined(LWESP_MEM_SIZE)
#define LWESP_MEM_SIZE 0x1000
#define LWESP_MEM_SIZE 0x4000
#endif /* !defined(LWESP_MEM_SIZE) */

#if !defined(LWESP_USART_RDR_NAME)
Expand Down Expand Up @@ -217,7 +217,7 @@ prv_configure_uart(uint32_t baudrate) {
is_running = 0;
#if defined(LWESP_USART_DMA_RX_STREAM)
LL_DMA_DeInit(LWESP_USART_DMA, LWESP_USART_DMA_RX_STREAM);
dma_init.Channel = LWESP_USART_DMA_RX_CH;
dma_init.PeriphRequest = LWESP_USART_DMA_RX_REQ_NUM;
#else
LL_DMA_DeInit(LWESP_USART_DMA, LWESP_USART_DMA_RX_CH);
dma_init.PeriphRequest = LWESP_USART_DMA_RX_REQ_NUM;
Expand Down Expand Up @@ -278,7 +278,7 @@ prv_configure_uart(uint32_t baudrate) {
usart_ll_mbox_id = osMessageQueueNew(10, sizeof(void*), NULL);
}
if (usart_ll_thread_id == NULL) {
const osThreadAttr_t attr = {.stack_size = 1024};
const osThreadAttr_t attr = {.stack_size = 1536};
usart_ll_thread_id = osThreadNew(usart_ll_thread, usart_ll_mbox_id, &attr);
}
}
Expand Down

2 comments on commit 290280d

@Tizio1234
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editing line 220 on lwesp_ll_stm32.c broke the driver for stm32f4 series, there is no such field as PeriphRequest in the stm32f4 ll drivers, I've found it in the h7 ll drivers, should I just replace that line with the old one?

@MaJerle
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can. Good catch, thanks.

Please sign in to comment.