blob: 875361bb7cb4646d6edf5d47ccdb676c27dbbee5 [file] [log] [blame]
Eric Bénard323e8412011-03-09 19:24:48 +01001n_gsm.c GSM 0710 tty multiplexor HOWTO
2===================================================
3
4This line discipline implements the GSM 07.10 multiplexing protocol
5detailed in the following 3GPP document :
6http://www.3gpp.org/ftp/Specs/archive/07_series/07.10/0710-720.zip
7
8This document give some hints on how to use this driver with GPRS and 3G
9modems connected to a physical serial port.
10
11How to use it
12-------------
131- initialize the modem in 0710 mux mode (usually AT+CMUX= command) through
14its serial port. Depending on the modem used, you can pass more or less
15parameters to this command,
162- switch the serial line to using the n_gsm line discipline by using
17TIOCSETD ioctl,
183- configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl,
19
20Major parts of the initialization program :
21(a good starting point is util-linux-ng/sys-utils/ldattach.c)
22#include <linux/gsmmux.h>
23#define N_GSM0710 21 /* GSM 0710 Mux */
24#define DEFAULT_SPEED B115200
25#define SERIAL_PORT /dev/ttyS0
26
27 int ldisc = N_GSM0710;
28 struct gsm_config c;
29 struct termios configuration;
30
31 /* open the serial port connected to the modem */
32 fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
33
34 /* configure the serial port : speed, flow control ... */
35
36 /* send the AT commands to switch the modem to CMUX mode
Lucas De Marchi25985ed2011-03-30 22:57:33 -030037 and check that it's successful (should return OK) */
Eric Bénard323e8412011-03-09 19:24:48 +010038 write(fd, "AT+CMUX=0\r", 10);
39
40 /* experience showed that some modems need some time before
41 being able to answer to the first MUX packet so a delay
42 may be needed here in some case */
43 sleep(3);
44
45 /* use n_gsm line discipline */
46 ioctl(fd, TIOCSETD, &ldisc);
47
48 /* get n_gsm configuration */
49 ioctl(fd, GSMIOC_GETCONF, &c);
50 /* we are initiator and need encoding 0 (basic) */
51 c.initiator = 1;
52 c.encapsulation = 0;
53 /* our modem defaults to a maximum size of 127 bytes */
54 c.mru = 127;
55 c.mtu = 127;
56 /* set the new configuration */
57 ioctl(fd, GSMIOC_SETCONF, &c);
58
59 /* and wait for ever to keep the line discipline enabled */
60 daemon(0,0);
61 pause();
62
634- create the devices corresponding to the "virtual" serial ports (take care,
64each modem has its configuration and some DLC have dedicated functions,
65for example GPS), starting with minor 1 (DLC0 is reserved for the management
66of the mux)
67
68MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}`
69for i in `seq 1 4`; do
70 mknod /dev/ttygsm$i c $MAJOR $i
71done
72
735- use these devices as plain serial ports.
74for example, it's possible :
75- and to use gnokii to send / receive SMS on ttygsm1
76- to use ppp to establish a datalink on ttygsm2
77
786- first close all virtual ports before closing the physical port.
79
Sascha Hauer71e07792017-05-31 08:19:05 +020080Note that after closing the physical port the modem is still in multiplexing
81mode. This may prevent a successful re-opening of the port later. To avoid
82this situation either reset the modem if your hardware allows that or send
83a disconnect command frame manually before initializing the multiplexing mode
84for the second time. The byte sequence for the disconnect command frame is:
850xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9.
86
Eric Bénard323e8412011-03-09 19:24:48 +010087Additional Documentation
88------------------------
89More practical details on the protocol and how it's supported by industrial
90modems can be found in the following documents :
91http://www.telit.com/module/infopool/download.php?id=616
92http://www.u-blox.com/images/downloads/Product_Docs/LEON-G100-G200-MuxImplementation_ApplicationNote_%28GSM%20G1-CS-10002%29.pdf
93http://www.sierrawireless.com/Support/Downloads/AirPrime/WMP_Series/~/media/Support_Downloads/AirPrime/Application_notes/CMUX_Feature_Application_Note-Rev004.ashx
94http://wm.sim.com/sim/News/photo/2010721161442.pdf
95
9611-03-08 - Eric Bénard - <eric@eukrea.com>