Skip to content

Commit

Permalink
Add missing UDP-V6 connection type
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jul 30, 2022
1 parent e38a406 commit 52b5366
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"string.h": "c",
"lwevt_opt.h": "c",
"cli.h": "c",
"windows.h": "c"
"windows.h": "c",
"lwesp_private.h": "c"
},
"esbonio.sphinx.confDir": ""
}
10 changes: 6 additions & 4 deletions lwesp/src/api/lwesp_netconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@

/* Check for IP status */
#if LWESP_CFG_IPV6
#define NETCONN_IS_TCP(nc) (nc->type == LWESP_NETCONN_TYPE_TCP || nc->type == LWESP_NETCONN_TYPE_TCPV6)
#define NETCONN_IS_SSL(nc) (nc->type == LWESP_NETCONN_TYPE_SSL || nc->type == LWESP_NETCONN_TYPE_SSLV6)
#define NETCONN_IS_TCP(nc) ((nc)->type == LWESP_NETCONN_TYPE_TCP || (nc)->type == LWESP_NETCONN_TYPE_TCPV6)
#define NETCONN_IS_SSL(nc) ((nc)->type == LWESP_NETCONN_TYPE_SSL || (nc)->type == LWESP_NETCONN_TYPE_SSLV6)
#define NETCONN_IS_UDP(nc) ((nc)->type == LWESP_NETCONN_TYPE_UDP || (nc)->type == LWESP_NETCONN_TYPE_UDPV6)
#else
#define NETCONN_IS_TCP(nc) (nc->type == LWESP_NETCONN_TYPE_TCP)
#define NETCONN_IS_SSL(nc) (nc->type == LWESP_NETCONN_TYPE_SSL)
#define NETCONN_IS_TCP(nc) ((nc)->type == LWESP_NETCONN_TYPE_TCP)
#define NETCONN_IS_SSL(nc) ((nc)->type == LWESP_NETCONN_TYPE_SSL)
#define NETCONN_IS_UDP(nc) ((nc)->type == LWESP_NETCONN_TYPE_UDP)
#endif /* LWESP_CFG_IPV6 */

/**
Expand Down
1 change: 1 addition & 0 deletions lwesp/src/include/lwesp/lwesp_netconn.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef enum {
#if LWESP_CFG_IPV6 || __DOXYGEN__
LWESP_NETCONN_TYPE_TCPV6 = LWESP_CONN_TYPE_TCPV6, /*!< TCP connection over IPv6 */
LWESP_NETCONN_TYPE_SSLV6 = LWESP_CONN_TYPE_SSLV6, /*!< SSL connection over IPv6 */
LWESP_NETCONN_TYPE_UDPV6 = LWESP_CONN_TYPE_UDPV6, /*!< UDP connection over IPv6 */
#endif /* LWESP_CFG_IPV6 || __DOXYGEN__ */
} lwesp_netconn_type_t;

Expand Down
13 changes: 12 additions & 1 deletion lwesp/src/include/lwesp/lwesp_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,18 @@ extern lwesp_t esp;
#define CRLF "\r\n"
#define CRLF_LEN 2

#define LWESP_PORT2NUM(port) ((uint32_t)(port))
#define LWESP_PORT2NUM(port) ((uint32_t)(port))

/* Define macros to check if connection is any (either V4 or V6) of the type */
#if LWESP_CFG_IPV6
#define CONN_IS_TCP_V4_OR_V6(contype) ((contype) == LWESP_CONN_TYPE_TCP || (contype) == LWESP_CONN_TYPE_TCPV6)
#define CONN_IS_SSL_V4_OR_V6(contype) ((contype) == LWESP_CONN_TYPE_SSL || (contype) == LWESP_CONN_TYPE_SSLV6)
#define CONN_IS_UDP_V4_OR_V6(contype) ((contype) == LWESP_CONN_TYPE_UDP || (contype) == LWESP_CONN_TYPE_UDPV6)
#else
#define CONN_IS_TCP_V4_OR_V6(contype) ((contype) == LWESP_CONN_TYPE_TCP)
#define CONN_IS_SSL_V4_OR_V6(contype) ((contype) == LWESP_CONN_TYPE_SSL)
#define CONN_IS_UDP_V4_OR_V6(contype) ((contype) == LWESP_CONN_TYPE_UDP)
#endif

const char* lwespi_dbg_msg_to_string(lwesp_cmd_t cmd);
lwespr_t lwespi_process(const void* data, size_t len);
Expand Down
5 changes: 3 additions & 2 deletions lwesp/src/include/lwesp/lwesp_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ typedef enum {
LWESP_CONN_TYPE_UDP, /*!< Connection type is UDP */
LWESP_CONN_TYPE_SSL, /*!< Connection type is SSL */
#if LWESP_CFG_IPV6 || __DOXYGEN__
LWESP_CONN_TYPE_TCPV6, /*!< Connection type is TCP over IPV6 */
LWESP_CONN_TYPE_SSLV6, /*!< Connection type is SSL over IPV6 */
LWESP_CONN_TYPE_TCPV6, /*!< Connection type is TCP over IPv6 */
LWESP_CONN_TYPE_UDPV6, /*!< Connection type is UDP over IPv6 */
LWESP_CONN_TYPE_SSLV6, /*!< Connection type is SSL over IPv6 */
#endif /* LWESP_CFG_IPV6 || __DOXYGEN__ */
} lwesp_conn_type_t;

Expand Down
4 changes: 2 additions & 2 deletions lwesp/src/lwesp/lwesp_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ prv_conn_send(lwesp_conn_p conn, const lwesp_ip_t* const ip, lwesp_port_t port,
*
* Limit up to maximum buffer allowed by ESP
*/
if (conn->type == LWESP_CONN_TYPE_UDP) {
if (CONN_IS_UDP_V4_OR_V6(conn->type)) {
LWESP_ASSERT("USD: len < max_len", btw <= LWESP_CFG_CONN_MAX_DATA_LEN);
}
#endif /* !LWESP_CFG_CONN_ALLOW_FRAGMENTED_UDP_SEND */
Expand Down Expand Up @@ -346,7 +346,7 @@ lwesp_conn_startex(lwesp_conn_p* conn, lwesp_conn_start_t* start_struct,
LWESP_MSG_VAR_REF(msg).msg.conn_start.arg = arg;

/* Add connection type specific features */
if (start_struct->type != LWESP_CONN_TYPE_UDP) {
if (!CONN_IS_UDP_V4_OR_V6(start_struct->type)) {
LWESP_MSG_VAR_REF(msg).msg.conn_start.tcp_ssl_keep_alive = start_struct->ext.tcp_ssl.keep_alive;
} else {
LWESP_MSG_VAR_REF(msg).msg.conn_start.udp_local_port = start_struct->ext.udp.local_port;
Expand Down
43 changes: 21 additions & 22 deletions lwesp/src/lwesp/lwesp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ lwespi_tcpip_process_send_data(void) {
lwespi_send_number(LWESP_U32(esp.msg->msg.conn_send.sent), 0, 1); /* Send length number */

/* On UDP connections, IP address and port may be included */
if (c->type == LWESP_CONN_TYPE_UDP
if (CONN_IS_UDP_V4_OR_V6(c->type)
&& esp.msg->msg.conn_send.remote_ip != NULL && esp.msg->msg.conn_send.remote_port) {
lwespi_send_ip(esp.msg->msg.conn_send.remote_ip, 1, 1); /* Send IP address including quotes */
lwespi_send_port(esp.msg->msg.conn_send.remote_port, 0, 1); /* Send length number */
Expand Down Expand Up @@ -1591,21 +1591,16 @@ lwespi_process_sub_cmd(lwesp_msg_t* msg, uint8_t* is_ok, uint8_t* is_error, uint
* if final result was error, decide what type
* of error should be returned for user
*/
switch (msg->msg.sta_join.error_num) {
case 1:
esp.evt.evt.sta_join_ap.res = lwespERRCONNTIMEOUT;
break;
case 2:
esp.evt.evt.sta_join_ap.res = lwespERRPASS;
break;
case 3:
esp.evt.evt.sta_join_ap.res = lwespERRNOAP;
break;
case 4:
esp.evt.evt.sta_join_ap.res = lwespERRCONNFAIL;
break;
default:
esp.evt.evt.sta_join_ap.res = lwespERR;
if (msg->msg.sta_join.error_num == 1) {
esp.evt.evt.sta_join_ap.res = lwespERRCONNTIMEOUT;
} else if (msg->msg.sta_join.error_num == 2) {
esp.evt.evt.sta_join_ap.res = lwespERRPASS;
} else if (msg->msg.sta_join.error_num == 3) {
esp.evt.evt.sta_join_ap.res = lwespERRNOAP;
} else if (msg->msg.sta_join.error_num == 4) {
esp.evt.evt.sta_join_ap.res = lwespERRCONNFAIL;
} else {
esp.evt.evt.sta_join_ap.res = lwespERR;
}
}
} else if (CMD_IS_CUR(LWESP_CMD_WIFI_CWDHCP_GET)) {
Expand Down Expand Up @@ -1762,7 +1757,7 @@ lwespi_process_sub_cmd(lwesp_msg_t* msg, uint8_t* is_ok, uint8_t* is_error, uint
/* This one is optional, to check for more data just at the end */
SET_NEW_CMD(LWESP_CMD_TCPIP_CIPRECVLEN);/* Inquiry for latest status on data */
msg->msg.ciprecvdata.is_last_check = 1;
} else if (CMD_IS_CUR(LWESP_CMD_TCPIP_CIPRECVLEN) && msg->msg.ciprecvdata.is_last_check == 0) {
} else if (CMD_IS_CUR(LWESP_CMD_TCPIP_CIPRECVLEN) && msg->msg.ciprecvdata.is_last_check == 1) {
/* Do nothing */
if (*is_error) {
*is_error = 0;
Expand Down Expand Up @@ -2248,29 +2243,33 @@ lwespi_initiate_cmd(lwesp_msg_t* msg) {

AT_PORT_SEND_BEGIN_AT();
AT_PORT_SEND_CONST_STR("+CIPSTARTEX=");
if (msg->msg.conn_start.type == LWESP_CONN_TYPE_SSL) {
conn_type_str = "SSL";
} else if (msg->msg.conn_start.type == LWESP_CONN_TYPE_TCP) {
if (msg->msg.conn_start.type == LWESP_CONN_TYPE_TCP) {
conn_type_str = "TCP";
} else if (msg->msg.conn_start.type == LWESP_CONN_TYPE_UDP) {
conn_type_str = "UDP";
} else if (msg->msg.conn_start.type == LWESP_CONN_TYPE_SSL) {
conn_type_str = "SSL";
#if LWESP_CFG_IPV6
} else if (msg->msg.conn_start.type == LWESP_CONN_TYPE_TCPV6) {
conn_type_str = "TCPV6";
} else if (msg->msg.conn_start.type == LWESP_CONN_TYPE_UDPV6) {
conn_type_str = "UDPV6";
} else if (msg->msg.conn_start.type == LWESP_CONN_TYPE_SSLV6) {
conn_type_str = "SSLV6";
#endif /* LWESP_CFG_IPV6 */
} else {
conn_type_str = "unknonw";
conn_type_str = "unknown";
}
lwespi_send_string(conn_type_str, 0, 1, 0);
lwespi_send_string(msg->msg.conn_start.remote_host, 0, 1, 1);
lwespi_send_port(msg->msg.conn_start.remote_port, 0, 1);

/* Connection-type specific features */
if (msg->msg.conn_start.type != LWESP_CONN_TYPE_UDP) {
if (!CONN_IS_UDP_V4_OR_V6(msg->msg.conn_start.type)) {
/* TCP or SSL */
lwespi_send_number(LWESP_U32(msg->msg.conn_start.tcp_ssl_keep_alive), 0, 1);
} else {
/* UDP */
if (msg->msg.conn_start.udp_local_port > 0) {
lwespi_send_port(msg->msg.conn_start.udp_local_port, 0, 1);
} else {
Expand Down
9 changes: 8 additions & 1 deletion lwesp/src/lwesp/lwesp_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,27 @@ lwespi_parse_link_conn(const char* str) {
esp.m.link_conn.num = lwespi_parse_number(&str);
if (!strncmp(str, "\"TCP\"", 5)) {
esp.m.link_conn.type = LWESP_CONN_TYPE_TCP;
str += 6;
} else if (!strncmp(str, "\"UDP\"", 5)) {
esp.m.link_conn.type = LWESP_CONN_TYPE_UDP;
str += 6;
} else if (!strncmp(str, "\"SSL\"", 5)) {
esp.m.link_conn.type = LWESP_CONN_TYPE_SSL;
str += 6;
#if LWESP_CFG_IPV6
} else if (!strncmp(str, "\"TCPv6\"", 7)) {
esp.m.link_conn.type = LWESP_CONN_TYPE_TCPV6;
str += 8;
} else if (!strncmp(str, "\"UDPv6\"", 7)) {
esp.m.link_conn.type = LWESP_CONN_TYPE_UDPV6;
str += 8;
} else if (!strncmp(str, "\"SSLv6\"", 7)) {
esp.m.link_conn.type = LWESP_CONN_TYPE_SSLV6;
str += 8;
#endif /* LWESP_CFG_IPV6 */
} else {
return 0;
}
str += 6;
esp.m.link_conn.is_server = lwespi_parse_number(&str);
lwespi_parse_ip(&str, &esp.m.link_conn.remote_ip);
esp.m.link_conn.remote_port = lwespi_parse_port(&str);
Expand Down

0 comments on commit 52b5366

Please sign in to comment.