Skip to content

Commit f14b49f

Browse files
junqingzourlubos
authored andcommitted
application: serial_lte_modem: support CID in TCP/UDP client
Add support of PDP Context CID in TCP/UDP client, for .Non-zero initial PDN connection .Secondary PDN connection Updated AT commands, AT#XTCPCLI and AT#XUDPCLI Signed-off-by: Jun Qing Zou <[email protected]>
1 parent b0241fc commit f14b49f

File tree

4 files changed

+81
-30
lines changed

4 files changed

+81
-30
lines changed

applications/serial_lte_modem/doc/TCPUDP_AT_commands.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Syntax
174174

175175
::
176176

177-
#XTCPCLI=<op>[,<url>,<port>[,sec_tag[,peer_verify[,hostname_verify]]]]
177+
#XTCPCLI=<op>[,<url>,<port>[,sec_tag[,peer_verify[,hostname_verify,[cid]]]]]
178178

179179
* The ``<op>`` parameter can accept one of the following values:
180180

@@ -207,6 +207,10 @@ Syntax
207207

208208
See :ref:`nRF socket options <nrfxlib:nrf_sockets>` ``peer_verify`` and ``tls_hostname`` for more information on ``<peer_verify>`` and ``<hostname_verify>``.
209209

210+
* The ``<cid>`` parameter is an integer indicating the used PDN connection.
211+
It represents ``cid`` in the ``+CGDCONT`` command.
212+
Its default value is ``0``.
213+
210214
Response syntax
211215
~~~~~~~~~~~~~~~
212216

@@ -275,7 +279,7 @@ Response syntax
275279

276280
::
277281

278-
#XTCPCLI: <list of ops>,<url>,<port>,<sec_tag>,<peer_verify>,<hostname_verify>
282+
#XTCPCLI: <list of ops>,<url>,<port>,<sec_tag>,<peer_verify>,<hostname_verify>,<cid>
279283

280284
Examples
281285
~~~~~~~~
@@ -552,7 +556,7 @@ Syntax
552556

553557
::
554558

555-
#XUDPCLI=<op>[,<url>,<port>[,<sec_tag>[,<use_dtls_cid>[,peer_verify[,hostname_verify]]]]]
559+
#XUDPCLI=<op>[,<url>,<port>[,<sec_tag>[,<use_dtls_cid>[,peer_verify[,hostname_verify,[cid]]]]]]
556560

557561
* The ``<op>`` parameter can accept one of the following values:
558562

@@ -589,6 +593,10 @@ Syntax
589593

590594
See :ref:`nRF socket options <nrfxlib:nrf_sockets>` ``peer_verify`` and ``tls_hostname`` for more information on ``<peer_verify>`` and ``<hostname_verify>``.
591595

596+
* The ``<cid>`` parameter is an integer indicating the used PDN connection.
597+
It represents ``cid`` in the ``+CGDCONT`` command.
598+
Its default value is ``0``.
599+
592600
Response syntax
593601
~~~~~~~~~~~~~~~
594602

@@ -650,7 +658,7 @@ Syntax
650658

651659
::
652660

653-
#XUDPCLI: <list of ops>,<url>,<port>,<sec_tag>,<use_dtls_cid>,<peer_verify>,<hostname_verify>
661+
#XUDPCLI: <list of ops>,<url>,<port>,<sec_tag>,<use_dtls_cid>,<peer_verify>,<hostname_verify>,<cid>
654662

655663
Examples
656664
~~~~~~~~

applications/serial_lte_modem/src/slm_at_tcp_proxy.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int do_tcp_proxy_close(void)
192192
return ret;
193193
}
194194

195-
static int do_tcp_client_connect(const char *url, uint16_t port)
195+
static int do_tcp_client_connect(const char *url, uint16_t port, uint16_t cid)
196196
{
197197
int ret;
198198
struct sockaddr sa;
@@ -254,6 +254,18 @@ static int do_tcp_client_connect(const char *url, uint16_t port)
254254
}
255255
}
256256

257+
/* Explicitly bind to a PDP context if necessary */
258+
if (cid > 0) {
259+
int cid_int = cid;
260+
261+
ret = zsock_setsockopt(proxy.sock, SOL_SOCKET, SO_BINDTOPDN,
262+
&cid_int, sizeof(int));
263+
if (ret < 0) {
264+
LOG_ERR("zsock_setsockopt(SO_BINDTOPDN) error: %d", -errno);
265+
goto exit_cli;
266+
}
267+
}
268+
257269
/* Connect to remote host */
258270
ret = util_resolve_host(0, url, port, proxy.family, &sa);
259271
if (ret) {
@@ -718,6 +730,7 @@ static int handle_at_tcp_client(enum at_parser_cmd_type cmd_type, struct at_pars
718730
uint16_t port;
719731
char url[SLM_MAX_URL];
720732
int size = SLM_MAX_URL;
733+
uint16_t cid = 0; /* CID0 for initial PDN connection */
721734

722735
if (proxy.sock != INVALID_SOCKET || proxy.efd != INVALID_SOCKET) {
723736
LOG_ERR("Proxy is running.");
@@ -731,33 +744,41 @@ static int handle_at_tcp_client(enum at_parser_cmd_type cmd_type, struct at_pars
731744
return -EINVAL;
732745
}
733746
proxy.sec_tag = INVALID_SEC_TAG;
734-
if (param_count > 4) {
735-
if (at_parser_num_get(parser, 4, &proxy.sec_tag)) {
747+
if (param_count > 4) { /* optional param */
748+
err = at_parser_num_get(parser, 4, &proxy.sec_tag);
749+
if (err != 0 && err != -EOPNOTSUPP) {
736750
return -EINVAL;
737751
}
738752
}
739753
proxy.peer_verify = TLS_PEER_VERIFY_REQUIRED;
740-
if (param_count > 5) {
741-
if (at_parser_num_get(parser, 5, &proxy.peer_verify) ||
754+
if (param_count > 5) { /* optional param */
755+
err = at_parser_num_get(parser, 5, &proxy.peer_verify);
756+
if ((err != 0 && err != -EOPNOTSUPP) ||
742757
(proxy.peer_verify != TLS_PEER_VERIFY_NONE &&
743758
proxy.peer_verify != TLS_PEER_VERIFY_OPTIONAL &&
744759
proxy.peer_verify != TLS_PEER_VERIFY_REQUIRED)) {
745760
return -EINVAL;
746761
}
747762
}
748763
proxy.hostname_verify = true;
749-
if (param_count > 6) {
750-
uint16_t hostname_verify;
764+
if (param_count > 6) { /* optional param */
765+
uint16_t hostname_verify = 0;
751766

752-
if (at_parser_num_get(parser, 6, &hostname_verify) ||
767+
err = at_parser_num_get(parser, 6, &hostname_verify);
768+
if ((err != 0 && err != -EOPNOTSUPP) ||
753769
(hostname_verify != 0 && hostname_verify != 1)) {
754770
return -EINVAL;
755771
}
756772
proxy.hostname_verify = (bool)hostname_verify;
757773
}
774+
if (param_count > 7) { /* optional param, last */
775+
if (at_parser_num_get(parser, 7, &cid)) {
776+
return -EINVAL;
777+
}
778+
}
758779

759780
proxy.family = (op == CLIENT_CONNECT) ? AF_INET : AF_INET6;
760-
err = do_tcp_client_connect(url, port);
781+
err = do_tcp_client_connect(url, port, cid);
761782
} else if (op == CLIENT_DISCONNECT) {
762783
err = do_tcp_proxy_close();
763784
} break;
@@ -769,7 +790,7 @@ static int handle_at_tcp_client(enum at_parser_cmd_type cmd_type, struct at_pars
769790

770791
case AT_PARSER_CMD_TYPE_TEST:
771792
rsp_send("\r\n#XTCPCLI: (%d,%d,%d),<url>,<port>,"
772-
"<sec_tag>,<peer_verify>,<hostname_verify>\r\n",
793+
"<sec_tag>,<peer_verify>,<hostname_verify>,<cid>\r\n",
773794
CLIENT_DISCONNECT, CLIENT_CONNECT, CLIENT_CONNECT6);
774795
err = 0;
775796
break;

applications/serial_lte_modem/src/slm_at_udp_proxy.c

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static int do_udp_proxy_close(void)
184184
return ret;
185185
}
186186

187-
static int do_udp_client_connect(const char *url, uint16_t port)
187+
static int do_udp_client_connect(const char *url, uint16_t port, uint16_t cid)
188188
{
189189
int ret;
190190
struct sockaddr sa;
@@ -267,6 +267,18 @@ static int do_udp_client_connect(const char *url, uint16_t port)
267267
}
268268
}
269269

270+
/* Explicitly bind to a PDP context if necessary */
271+
if (cid > 0) {
272+
int cid_int = cid;
273+
274+
ret = zsock_setsockopt(proxy.sock, SOL_SOCKET, SO_BINDTOPDN,
275+
&cid_int, sizeof(int));
276+
if (ret < 0) {
277+
LOG_ERR("zsock_setsockopt(SO_BINDTOPDN) error: %d", -errno);
278+
goto cli_exit;
279+
}
280+
}
281+
270282
/* Connect to remote host */
271283
ret = util_resolve_host(0, url, port, proxy.family, &sa);
272284
if (ret) {
@@ -579,6 +591,7 @@ static int handle_at_udp_client(enum at_parser_cmd_type cmd_type, struct at_pars
579591
uint16_t port;
580592
char url[SLM_MAX_URL];
581593
int size = SLM_MAX_URL;
594+
uint16_t cid = 0; /* CID0 for initial PDN connection */
582595

583596
if (socket_is_in_use()) {
584597
return -EINVAL;
@@ -592,43 +605,51 @@ static int handle_at_udp_client(enum at_parser_cmd_type cmd_type, struct at_pars
592605
return err;
593606
}
594607
proxy.sec_tag = INVALID_SEC_TAG;
595-
596-
if (param_count > 4) {
597-
if (at_parser_num_get(parser, 4, &proxy.sec_tag)
598-
|| proxy.sec_tag == INVALID_SEC_TAG || proxy.sec_tag < 0) {
608+
if (param_count > 4) { /* optional param */
609+
err = at_parser_num_get(parser, 4, &proxy.sec_tag);
610+
if ((err != 0 && err != -EOPNOTSUPP)) {
599611
return -EINVAL;
600612
}
601613
}
602-
proxy.dtls_cid = INVALID_DTLS_CID;
603-
if (param_count > 5) {
604-
if (at_parser_num_get(parser, 5, &proxy.dtls_cid)
614+
proxy.dtls_cid = TLS_DTLS_CID_DISABLED;
615+
if (param_count > 5) { /* optional param */
616+
err = at_parser_num_get(parser, 5, &proxy.dtls_cid);
617+
if ((err != 0 && err != -EOPNOTSUPP)
605618
|| !(proxy.dtls_cid == TLS_DTLS_CID_DISABLED
606-
|| proxy.dtls_cid == TLS_DTLS_CID_SUPPORTED
607-
|| proxy.dtls_cid == TLS_DTLS_CID_ENABLED)) {
619+
|| proxy.dtls_cid == TLS_DTLS_CID_SUPPORTED
620+
|| proxy.dtls_cid == TLS_DTLS_CID_ENABLED)) {
608621
return -EINVAL;
609622
}
610623
}
611624
proxy.peer_verify = TLS_PEER_VERIFY_REQUIRED;
612-
if (param_count > 6) {
613-
if (at_parser_num_get(parser, 6, &proxy.peer_verify) ||
625+
if (param_count > 6) { /* optional param */
626+
err = at_parser_num_get(parser, 6, &proxy.peer_verify);
627+
if ((err != 0 && err != -EOPNOTSUPP) ||
614628
(proxy.peer_verify != TLS_PEER_VERIFY_NONE &&
615629
proxy.peer_verify != TLS_PEER_VERIFY_OPTIONAL &&
616630
proxy.peer_verify != TLS_PEER_VERIFY_REQUIRED)) {
617631
return -EINVAL;
618632
}
619633
}
620634
proxy.hostname_verify = true;
621-
if (param_count > 7) {
622-
uint16_t hostname_verify;
635+
if (param_count > 7) { /* optional param */
636+
uint16_t hostname_verify = 0;
623637

624-
if (at_parser_num_get(parser, 7, &hostname_verify) ||
638+
err = at_parser_num_get(parser, 7, &hostname_verify);
639+
if ((err != 0 && err != -EOPNOTSUPP) ||
625640
(hostname_verify != 0 && hostname_verify != 1)) {
626641
return -EINVAL;
627642
}
628643
proxy.hostname_verify = (bool)hostname_verify;
629644
}
645+
if (param_count > 8) { /* optional param, last */
646+
if (at_parser_num_get(parser, 8, &cid)) {
647+
return -EINVAL;
648+
}
649+
}
650+
630651
proxy.family = (op == CLIENT_CONNECT) ? AF_INET : AF_INET6;
631-
err = do_udp_client_connect(url, port);
652+
err = do_udp_client_connect(url, port, cid);
632653
} else if (op == CLIENT_DISCONNECT) {
633654
err = do_udp_proxy_close();
634655
} break;

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Serial LTE modem
243243
This occurs sometimes especially during development.
244244
* The initialization of the application to send "INIT ERROR" over to UART and show clear error log to indicate that the application is not operational in case of failing initialization.
245245
* The PPP downlink data to trigger the indicate pin when SLM is in idle.
246+
* The ``AT#XTCPCLI`` and the ``AT#XUDPCLI`` commands to support CID of the PDN connection.
246247

247248
Thingy:53: Matter weather station
248249
---------------------------------

0 commit comments

Comments
 (0)