Skip to content

Commit 110fe70

Browse files
committed
app: Implement AT+CGDATA command to attach PPP
AT+CGDATA per 3GPP TS 27.007 section 10.1.12. Supported forms: AT+CGDATA - Start PPP with default CID AT+CGDATA="PPP" - Start PPP with default CID (L2P must be "PPP") AT+CGDATA="PPP",<cid> - Start PPP with specified CID AT+CGDATA=? - Report supported L2P values Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent d4a4d70 commit 110fe70

File tree

2 files changed

+156
-2
lines changed

2 files changed

+156
-2
lines changed

app/src/sm_ppp.c

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ static int ppp_start(void)
324324
struct ppp_context *const ctx = net_if_l2_data(ppp_iface);
325325

326326
if (!configure_ppp_link_ip_addresses(ctx)) {
327-
ret = -EADDRNOTAVAIL;
328-
goto error;
327+
return -EADDRNOTAVAIL;
328+
}
329+
330+
if (!ppp_pipe) {
331+
return -EINVAL;
329332
}
330333

331334
ppp_state = PPP_STATE_STARTING;
@@ -709,6 +712,77 @@ static int handle_at_ppp(enum at_parser_cmd_type cmd_type, struct at_parser *par
709712
return -SILENT_AT_COMMAND_RET;
710713
}
711714

715+
SM_AT_CMD_CUSTOM(cgdata, "AT+CGDATA", handle_at_cgdata);
716+
static int handle_at_cgdata(enum at_parser_cmd_type cmd_type, struct at_parser *parser,
717+
uint32_t param_count)
718+
{
719+
/* AT+CGDATA per 3GPP TS 27.007 section 10.1.12.
720+
*
721+
* Supported forms:
722+
* AT+CGDATA - Start PPP with default CID
723+
* AT+CGDATA="PPP" - Start PPP with default CID (L2P must be "PPP")
724+
* AT+CGDATA="PPP",<cid> - Start PPP with specified CID
725+
* AT+CGDATA=? - Report supported L2P values
726+
*/
727+
int ret;
728+
729+
if (cmd_type == AT_PARSER_CMD_TYPE_TEST) {
730+
rsp_send("\r\n+CGDATA: (\"PPP\")\r\n");
731+
return 0;
732+
}
733+
734+
if (cmd_type != AT_PARSER_CMD_TYPE_SET || param_count > 3) {
735+
return -EINVAL;
736+
}
737+
738+
/* Default CID (0 = default PDP context). */
739+
unsigned int cid = 0;
740+
741+
if (param_count >= 2) {
742+
/* Parse and validate the L2P string parameter. */
743+
char l2p[8];
744+
size_t l2p_len = sizeof(l2p);
745+
746+
ret = util_string_get(parser, 1, l2p, &l2p_len);
747+
if (ret || strcasecmp(l2p, "PPP") != 0) {
748+
return -EINVAL;
749+
}
750+
}
751+
752+
if (param_count == 3) {
753+
ret = at_parser_num_get(parser, 2, &cid);
754+
if (ret) {
755+
return -EINVAL;
756+
}
757+
}
758+
759+
if (ppp_state != PPP_STATE_STOPPED) {
760+
LOG_ERR("PPP already running");
761+
return -EALREADY;
762+
}
763+
764+
if (ppp_pipe) {
765+
sm_ppp_detach();
766+
}
767+
768+
struct sm_at_host_ctx *ctx = sm_at_host_get_current();
769+
struct modem_pipe *pipe = ctx ? sm_at_host_get_pipe(ctx) : NULL;
770+
771+
if (!ctx || !pipe) {
772+
LOG_ERR("No pipe available for PPP.");
773+
return -ENODEV;
774+
}
775+
ppp_pipe = pipe;
776+
sm_ppp_keep_pipe_attached = false;
777+
ppp_pdn_cid = cid;
778+
rsp_send("\r\nCONNECT\r\n");
779+
sm_at_host_release(ctx);
780+
modem_ppp_attach(&ppp_module, ppp_pipe);
781+
sm_ppp_set_auto_start(true);
782+
delegate_ppp_event(PPP_START, PPP_REASON_CMD);
783+
return -SILENT_AT_COMMAND_RET;
784+
}
785+
712786
static void ppp_data_passing_thread(void*, void*, void*)
713787
{
714788
struct zsock_pollfd fds[PPP_FDS_COUNT];

doc/app/at_ppp.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,86 @@ This page describes AT commands related to the Point-to-Point Protocol (PPP).
1212
PPP is enabled in |SM| by compiling it with the appropriate configuration files, depending on your use case (with or without CMUX).
1313
See the :ref:`sm_config_files` section for more information.
1414

15+
Enter data state +CGDATA
16+
========================
17+
18+
The ``AT+CGDATA`` command enters data state and starts PPP, as specified in `3GPP TS 27.007`_ (section 10.1.12).
19+
20+
Set command
21+
-----------
22+
23+
The set command starts PPP on the current channel, optionally specifying the layer 2 protocol and PDN connection.
24+
25+
Syntax
26+
~~~~~~
27+
28+
::
29+
30+
AT+CGDATA[=<L2P>[,<cid>]]
31+
32+
* The ``<L2P>`` parameter is a string specifying the layer 2 protocol to use.
33+
The only supported value is ``"PPP"``.
34+
If omitted, ``"PPP"`` is assumed.
35+
36+
* The ``<cid>`` parameter is an integer indicating the PDN connection to use.
37+
Its default value is ``0``, which represents the default PDN connection.
38+
39+
Response syntax
40+
~~~~~~~~~~~~~~~
41+
42+
::
43+
44+
CONNECT
45+
46+
Examples
47+
~~~~~~~~
48+
49+
With default parameters:
50+
51+
::
52+
53+
AT+CGDATA
54+
55+
CONNECT
56+
57+
Request PPP to use specified PDN connection:
58+
59+
::
60+
61+
AT+CGDATA="PPP",1
62+
63+
CONNECT
64+
65+
Test command
66+
------------
67+
68+
The test command lists the supported layer 2 protocols.
69+
70+
Syntax
71+
~~~~~~
72+
73+
::
74+
75+
AT+CGDATA=?
76+
77+
Response syntax
78+
~~~~~~~~~~~~~~~
79+
80+
::
81+
82+
+CGDATA: (<L2P_values>)
83+
84+
Example
85+
~~~~~~~
86+
87+
::
88+
89+
AT+CGDATA=?
90+
91+
+CGDATA: ("PPP")
92+
93+
OK
94+
1595
Control PPP #XPPP
1696
=================
1797

0 commit comments

Comments
 (0)