Skip to content

Commit acea556

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 a1820fc commit acea556

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
@@ -325,8 +325,11 @@ static int ppp_start(void)
325325
struct ppp_context *const ctx = net_if_l2_data(ppp_iface);
326326

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

332335
ppp_state = PPP_STATE_STARTING;
@@ -715,6 +718,77 @@ static int handle_at_ppp(enum at_parser_cmd_type cmd_type, struct at_parser *par
715718
return -SILENT_AT_COMMAND_RET;
716719
}
717720

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