Skip to content

Commit a1820fc

Browse files
committed
app: Add partial implementation of standard AT+CMUX command
Only following commands are supported: AT+CMUX=0 AT+CMUX=0,0 AT+CMUX? AT+CMUX=? Baud rate switch is not supported. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 96b0ee9 commit a1820fc

File tree

2 files changed

+159
-7
lines changed

2 files changed

+159
-7
lines changed

app/src/sm_cmux.c

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ static int cmux_start(void)
264264
return 0;
265265
}
266266

267-
SM_AT_CMD_CUSTOM(xcmux, "AT#XCMUX", handle_at_cmux);
268-
static int handle_at_cmux(enum at_parser_cmd_type cmd_type, struct at_parser *parser,
267+
SM_AT_CMD_CUSTOM(xcmux, "AT#XCMUX", handle_at_xcmux);
268+
static int handle_at_xcmux(enum at_parser_cmd_type cmd_type, struct at_parser *parser,
269269
uint32_t param_count)
270270
{
271271
unsigned int at_dlci;
@@ -320,8 +320,8 @@ static int handle_at_cmux(enum at_parser_cmd_type cmd_type, struct at_parser *pa
320320
return ret;
321321
}
322322

323-
SM_AT_CMD_CUSTOM(xcmuxcld, "AT#XCMUXCLD", handle_at_cmuxcld);
324-
static int handle_at_cmuxcld(enum at_parser_cmd_type cmd_type, struct at_parser *parser,
323+
SM_AT_CMD_CUSTOM(xcmuxcld, "AT#XCMUXCLD", handle_at_xcmuxcld);
324+
static int handle_at_xcmuxcld(enum at_parser_cmd_type cmd_type, struct at_parser *parser,
325325
uint32_t param_count)
326326
{
327327
if (cmd_type != AT_PARSER_CMD_TYPE_SET || param_count != 1) {
@@ -339,3 +339,67 @@ static int handle_at_cmuxcld(enum at_parser_cmd_type cmd_type, struct at_parser
339339

340340
return -SILENT_AT_COMMAND_RET;
341341
}
342+
343+
SM_AT_CMD_CUSTOM(atcmux, "AT+CMUX", handle_at_cmux);
344+
static int handle_at_cmux(enum at_parser_cmd_type cmd_type, struct at_parser *parser,
345+
uint32_t param_count)
346+
{
347+
/* AT+CMUX follows the 3GPP TS 27.010 specification.
348+
*
349+
* Only following commands are supported:
350+
* AT+CMUX=0 (basic mode)
351+
* AT+CMUX=0,0 (basic mode, subset 0)
352+
* AT+CMUX? (read current configuration)
353+
* AT+CMUX=? (list supported parameter ranges)
354+
* All other parameter combinations are rejected with an error response.
355+
*/
356+
unsigned int mode;
357+
unsigned int subset;
358+
int ret;
359+
360+
switch (cmd_type) {
361+
case AT_PARSER_CMD_TYPE_TEST:
362+
/* Report supported ranges: only mode 0, subset 0 */
363+
rsp_send("\r\n+CMUX: (0),(0)\r\n");
364+
return 0;
365+
366+
case AT_PARSER_CMD_TYPE_READ:
367+
/* Report current (and only) configuration */
368+
rsp_send("\r\n+CMUX: 0,0\r\n");
369+
return 0;
370+
371+
case AT_PARSER_CMD_TYPE_SET:
372+
if (param_count < 2 || param_count > 3) {
373+
return -EINVAL;
374+
}
375+
376+
ret = at_parser_num_get(parser, 1, &mode);
377+
if (ret || mode != 0) {
378+
return -EINVAL;
379+
}
380+
381+
if (param_count == 3) {
382+
ret = at_parser_num_get(parser, 2, &subset);
383+
if (ret || subset != 0) {
384+
return -EINVAL;
385+
}
386+
}
387+
388+
if (sm_cmux_is_started()) {
389+
return -EALREADY;
390+
}
391+
392+
/* Respond before starting CMUX. */
393+
rsp_send_ok();
394+
ret = cmux_start();
395+
if (ret) {
396+
LOG_ERR("Failed to start CMUX. (%d)", ret);
397+
} else {
398+
ret = -SILENT_AT_COMMAND_RET;
399+
}
400+
return ret;
401+
402+
default:
403+
return -EINVAL;
404+
}
405+
}

doc/app/at_cmux.rst

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,102 @@ See the :ref:`sm_config_files` section for more information.
2323

2424
.. note::
2525

26-
|SM| does not have an equivalent to the ``AT+CMUX`` command described in `3GPP TS 27.007`_.
27-
Here is how |SM|'s implementation of CMUX relates to the standard command's parameters:
28-
2926
* Only basic mode (mode 0) is supported.
3027
* Only UIH frames are used.
3128
* The speed used is the configured baud rate of |SM|'s UART.
3229
* No system parameters (N1, T1, T2, T3, k, m) are configurable.
3330

31+
CMUX setup +CMUX
32+
================
33+
34+
The ``AT+CMUX`` command starts the CMUX multiplexer.
35+
It is defined in `3GPP TS 27.007`_ (section 5.7) and the underlying protocol is specified in `3GPP TS 27.010`_.
36+
37+
Only basic mode (``<mode>=0``) with subset ``0`` is supported.
38+
All other parameter values are rejected.
39+
40+
Set command
41+
-----------
42+
43+
The set command allows you to start the CMUX multiplexer.
44+
45+
An ``OK`` response is sent before CMUX is started, after which only CMUX framing is accepted on the serial link.
46+
47+
Syntax
48+
~~~~~~
49+
50+
::
51+
52+
AT+CMUX=<mode>[,<subset>]
53+
54+
* The ``<mode>`` parameter selects the operation mode. Only ``0`` (basic mode) is supported.
55+
* The ``<subset>`` parameter selects the subset of mode 0. Only ``0`` is supported. Optional; defaults to ``0``.
56+
57+
Read command
58+
------------
59+
60+
The read command returns the current multiplexer configuration.
61+
62+
Syntax
63+
~~~~~~
64+
65+
::
66+
67+
AT+CMUX?
68+
69+
Response syntax
70+
~~~~~~~~~~~~~~~
71+
72+
::
73+
74+
+CMUX: <mode>,<subset>
75+
76+
* The ``<mode>`` parameter is always ``0`` (basic mode).
77+
* The ``<subset>`` parameter is always ``0``.
78+
79+
Test command
80+
------------
81+
82+
The test command returns the supported parameter ranges.
83+
84+
Syntax
85+
~~~~~~
86+
87+
::
88+
89+
AT+CMUX=?
90+
91+
Response syntax
92+
~~~~~~~~~~~~~~~
93+
94+
::
95+
96+
+CMUX: (0),(0)
97+
98+
Example
99+
-------
100+
101+
::
102+
103+
AT+CMUX=?
104+
105+
+CMUX: (0),(0)
106+
107+
OK
108+
AT+CMUX?
109+
110+
+CMUX: 0,0
111+
112+
OK
113+
AT+CMUX=0
114+
115+
OK
116+
// CMUX is now started. Open the CMUX channels to continue communication.
117+
AT+CMUX=0,0
118+
119+
OK
120+
// Equivalent to AT+CMUX=0.
121+
34122
CMUX setup #XCMUX
35123
=================
36124

0 commit comments

Comments
 (0)