From 7f574210a73e5fb44f3323b7ba875958de4de5d0 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:01:18 +0900 Subject: [PATCH] drivers:alt1250: Correspond to shutdown ALT1250 driver to support shutdown. --- drivers/modem/alt1250/altcom_cmd_sock.h | 8 ++++++ drivers/modem/alt1250/altcom_hdlr.c | 2 ++ drivers/modem/alt1250/altcom_hdlr_socket.c | 31 ++++++++++++++++++++++ drivers/modem/alt1250/altcom_hdlr_socket.h | 4 +++ 4 files changed, 45 insertions(+) diff --git a/drivers/modem/alt1250/altcom_cmd_sock.h b/drivers/modem/alt1250/altcom_cmd_sock.h index 5f115aacfe799..5b2c02ee31f50 100644 --- a/drivers/modem/alt1250/altcom_cmd_sock.h +++ b/drivers/modem/alt1250/altcom_cmd_sock.h @@ -159,6 +159,14 @@ #define ALTCOM_IPV6_V6ONLY 27 /* Refer to IPV6_V6ONLY on lwIP */ +/* Options for level ALTCOM_SHUT + * Referenced from sockets.h of lwIP-v2.02 + */ + +#define ALTCOM_SHUT_RD 0 /* Refer to SHUT_RD on lwIP */ +#define ALTCOM_SHUT_WR 1 /* Refer to SHUT_WR on lwIP */ +#define ALTCOM_SHUT_RDWR 2 /* Refer to SHUT_RDWR on lwIP */ + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/drivers/modem/alt1250/altcom_hdlr.c b/drivers/modem/alt1250/altcom_hdlr.c index 453d44739943f..e55e844d6ced2 100644 --- a/drivers/modem/alt1250/altcom_hdlr.c +++ b/drivers/modem/alt1250/altcom_hdlr.c @@ -124,6 +124,7 @@ static compose_inst_t g_composehdlrs[] = CTABLE_CONTENT(RECVFROM, altcom_recvfrom), CTABLE_CONTENT(SELECT, altcom_select), CTABLE_CONTENT(SENDTO, altcom_sendto), + CTABLE_CONTENT(SHUTDOWN, altcom_shutdown), CTABLE_CONTENT(SOCKET, altcom_socket), CTABLE_CONTENT(SETSOCKOPT, altcom_setsockopt), CTABLE_CONTENT(SENDATCMD, altcom_sendatcmd), @@ -199,6 +200,7 @@ static parse_inst_t g_parsehdlrs[] = PTABLE_CONTENT(SOCK_RECVFROM, altcom_recvfrom), PTABLE_CONTENT(SOCK_SELECT, altcom_select), PTABLE_CONTENT(SOCK_SENDTO, altcom_sockcomm), + PTABLE_CONTENT(SOCK_SHUTDOWN, altcom_sockcomm), PTABLE_CONTENT(SOCK_SOCKET, altcom_sockcomm), PTABLE_CONTENT(SOCK_SETSOCKOPT, altcom_sockcomm), PTABLE_CONTENT(SEND_ATCMD, altcom_sendatcmd), diff --git a/drivers/modem/alt1250/altcom_hdlr_socket.c b/drivers/modem/alt1250/altcom_hdlr_socket.c index 6556733662eff..438aa68990ba1 100644 --- a/drivers/modem/alt1250/altcom_hdlr_socket.c +++ b/drivers/modem/alt1250/altcom_hdlr_socket.c @@ -1069,6 +1069,37 @@ int32_t altcom_select_pkt_compose(FAR void **arg, size_t arglen, return size; } +int32_t altcom_shutdown_pkt_compose(FAR void **arg, size_t arglen, + uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR int32_t sockfd = *((FAR int32_t *)arg[0]); + FAR int32_t how = *((FAR int32_t *)arg[1]); + FAR struct apicmd_shutdown_s *out = + (FAR struct apicmd_shutdown_s *)pktbuf; + + switch (how) + { + case SHUT_RD: + how = ALTCOM_SHUT_RD; + break; + case SHUT_WR: + how = ALTCOM_SHUT_WR; + break; + case SHUT_RDWR: + how = ALTCOM_SHUT_RDWR; + break; + default: + return -EINVAL; + } + + out->sockfd = htonl(sockfd); + out->how = htonl(how); + *altcid = APICMDID_SOCK_SHUTDOWN; + + return sizeof(struct apicmd_shutdown_s); +} + int32_t altcom_sockcomm_pkt_parse(FAR struct alt1250_dev_s *dev, FAR uint8_t *pktbuf, size_t pktsz, uint8_t altver, FAR void **arg, diff --git a/drivers/modem/alt1250/altcom_hdlr_socket.h b/drivers/modem/alt1250/altcom_hdlr_socket.h index a40987894802a..cb159e47cb0bb 100644 --- a/drivers/modem/alt1250/altcom_hdlr_socket.h +++ b/drivers/modem/alt1250/altcom_hdlr_socket.h @@ -77,6 +77,10 @@ int32_t altcom_setsockopt_pkt_compose(FAR void **arg, size_t arglen, int32_t altcom_select_pkt_compose(FAR void **arg, size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, const size_t pktsz, FAR uint16_t *altcid); +int32_t altcom_shutdown_pkt_compose(FAR void **arg, size_t arglen, + uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, + FAR uint16_t *altcid); int32_t altcom_sockcomm_pkt_parse(FAR struct alt1250_dev_s *dev, FAR uint8_t *pktbuf, size_t pktsz, uint8_t altver, FAR void **arg,