From 02b08590a1de7a04e04543506c7059a2361eaf60 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Fri, 9 Oct 2020 21:14:36 +0900 Subject: [PATCH] drivers: wireless: Fix to handle UDP connect() with bind() in gs2200m.c Summary: - This commit fixes to handle UDP connect() with bind() to a local port. Impact: - All UDP cases which use connect() with gs2200m - Need to update apps/wireless/gs2200m as well Testing: - Tested with spresense:wifi - Create a UDP socket and bind() to a local port. - Then connect() to remote address with port and send() Signed-off-by: Masayuki Ishikawa --- drivers/wireless/gs2200m.c | 28 ++++++++++++++++++++-------- include/nuttx/wireless/gs2200m.h | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/wireless/gs2200m.c b/drivers/wireless/gs2200m.c index 2e0cb4c3c2..551be8f6ea 100644 --- a/drivers/wireless/gs2200m.c +++ b/drivers/wireless/gs2200m.c @@ -1778,9 +1778,10 @@ errout: * NOTE: See 7.5.1.1 Create TCP Clients and 7.5.1.2 Create UDP Client ****************************************************************************/ -static enum pkt_type_e gs2200m_create_clnt(FAR struct gs2200m_dev_s *dev, - FAR char *address, FAR char *port, - int type, FAR char *cid) +static enum pkt_type_e +gs2200m_create_clnt(FAR struct gs2200m_dev_s *dev, + FAR struct gs2200m_connect_msg *msg, + FAR char *cid) { enum pkt_type_e r; struct pkt_dat_s pkt_dat; @@ -1790,13 +1791,24 @@ static enum pkt_type_e gs2200m_create_clnt(FAR struct gs2200m_dev_s *dev, *cid = 'z'; /* Invalidate cid */ - if (SOCK_STREAM == type) + if (SOCK_STREAM == msg->type) { - snprintf(cmd, sizeof(cmd), "AT+NCTCP=%s,%s\r\n", address, port); + snprintf(cmd, sizeof(cmd), "AT+NCTCP=%s,%s\r\n", + msg->addr, msg->port); } - else if (SOCK_DGRAM == type) + else if (SOCK_DGRAM == msg->type) { - snprintf(cmd, sizeof(cmd), "AT+NCUDP=%s,%s\r\n", address, port); + if (0 == msg->lport) + { + snprintf(cmd, sizeof(cmd), "AT+NCUDP=%s,%s\r\n", + msg->addr, msg->port); + } + + else + { + snprintf(cmd, sizeof(cmd), "AT+NCUDP=%s,%s,%d\r\n", + msg->addr, msg->port, msg->lport); + } } else { @@ -2220,7 +2232,7 @@ static int gs2200m_ioctl_connect(FAR struct gs2200m_dev_s *dev, /* Create TCP or UDP connection */ - type = gs2200m_create_clnt(dev, msg->addr, msg->port, msg->type, &cid); + type = gs2200m_create_clnt(dev, msg, &cid); msg->type = type; diff --git a/include/nuttx/wireless/gs2200m.h b/include/nuttx/wireless/gs2200m.h index b92c2562ee..c1b9f14345 100644 --- a/include/nuttx/wireless/gs2200m.h +++ b/include/nuttx/wireless/gs2200m.h @@ -79,6 +79,7 @@ struct gs2200m_connect_msg { char cid; uint8_t type; + uint16_t lport; char addr[17]; char port[6]; };