xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/serial/n_gsm.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun==============================
2*4882a593SmuzhiyunGSM 0710 tty multiplexor HOWTO
3*4882a593Smuzhiyun==============================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunThis line discipline implements the GSM 07.10 multiplexing protocol
6*4882a593Smuzhiyundetailed in the following 3GPP document:
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun	https://www.3gpp.org/ftp/Specs/archive/07_series/07.10/0710-720.zip
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunThis document give some hints on how to use this driver with GPRS and 3G
11*4882a593Smuzhiyunmodems connected to a physical serial port.
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunHow to use it
14*4882a593Smuzhiyun-------------
15*4882a593Smuzhiyun1. initialize the modem in 0710 mux mode (usually AT+CMUX= command) through
16*4882a593Smuzhiyun   its serial port. Depending on the modem used, you can pass more or less
17*4882a593Smuzhiyun   parameters to this command,
18*4882a593Smuzhiyun2. switch the serial line to using the n_gsm line discipline by using
19*4882a593Smuzhiyun   TIOCSETD ioctl,
20*4882a593Smuzhiyun3. configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl,
21*4882a593Smuzhiyun4. obtain base gsmtty number for the used serial port,
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunMajor parts of the initialization program :
24*4882a593Smuzhiyun(a good starting point is util-linux-ng/sys-utils/ldattach.c)::
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun  #include <stdio.h>
27*4882a593Smuzhiyun  #include <stdint.h>
28*4882a593Smuzhiyun  #include <linux/gsmmux.h>
29*4882a593Smuzhiyun  #include <linux/tty.h>
30*4882a593Smuzhiyun  #define DEFAULT_SPEED	B115200
31*4882a593Smuzhiyun  #define SERIAL_PORT	/dev/ttyS0
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun	int ldisc = N_GSM0710;
34*4882a593Smuzhiyun	struct gsm_config c;
35*4882a593Smuzhiyun	struct termios configuration;
36*4882a593Smuzhiyun	uint32_t first;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun	/* open the serial port connected to the modem */
39*4882a593Smuzhiyun	fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun	/* configure the serial port : speed, flow control ... */
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun	/* send the AT commands to switch the modem to CMUX mode
44*4882a593Smuzhiyun	   and check that it's successful (should return OK) */
45*4882a593Smuzhiyun	write(fd, "AT+CMUX=0\r", 10);
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun	/* experience showed that some modems need some time before
48*4882a593Smuzhiyun	   being able to answer to the first MUX packet so a delay
49*4882a593Smuzhiyun	   may be needed here in some case */
50*4882a593Smuzhiyun	sleep(3);
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun	/* use n_gsm line discipline */
53*4882a593Smuzhiyun	ioctl(fd, TIOCSETD, &ldisc);
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun	/* get n_gsm configuration */
56*4882a593Smuzhiyun	ioctl(fd, GSMIOC_GETCONF, &c);
57*4882a593Smuzhiyun	/* we are initiator and need encoding 0 (basic) */
58*4882a593Smuzhiyun	c.initiator = 1;
59*4882a593Smuzhiyun	c.encapsulation = 0;
60*4882a593Smuzhiyun	/* our modem defaults to a maximum size of 127 bytes */
61*4882a593Smuzhiyun	c.mru = 127;
62*4882a593Smuzhiyun	c.mtu = 127;
63*4882a593Smuzhiyun	/* set the new configuration */
64*4882a593Smuzhiyun	ioctl(fd, GSMIOC_SETCONF, &c);
65*4882a593Smuzhiyun	/* get first gsmtty device node */
66*4882a593Smuzhiyun	ioctl(fd, GSMIOC_GETFIRST, &first);
67*4882a593Smuzhiyun	printf("first muxed line: /dev/gsmtty%i\n", first);
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun	/* and wait for ever to keep the line discipline enabled */
70*4882a593Smuzhiyun	daemon(0,0);
71*4882a593Smuzhiyun	pause();
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun5. use these devices as plain serial ports.
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun   for example, it's possible:
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun   - and to use gnokii to send / receive SMS on ttygsm1
78*4882a593Smuzhiyun   - to use ppp to establish a datalink on ttygsm2
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun6. first close all virtual ports before closing the physical port.
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun   Note that after closing the physical port the modem is still in multiplexing
83*4882a593Smuzhiyun   mode. This may prevent a successful re-opening of the port later. To avoid
84*4882a593Smuzhiyun   this situation either reset the modem if your hardware allows that or send
85*4882a593Smuzhiyun   a disconnect command frame manually before initializing the multiplexing mode
86*4882a593Smuzhiyun   for the second time. The byte sequence for the disconnect command frame is::
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun      0xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9.
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunAdditional Documentation
91*4882a593Smuzhiyun------------------------
92*4882a593SmuzhiyunMore practical details on the protocol and how it's supported by industrial
93*4882a593Smuzhiyunmodems can be found in the following documents :
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun- http://www.telit.com/module/infopool/download.php?id=616
96*4882a593Smuzhiyun- http://www.u-blox.com/images/downloads/Product_Docs/LEON-G100-G200-MuxImplementation_ApplicationNote_%28GSM%20G1-CS-10002%29.pdf
97*4882a593Smuzhiyun- http://www.sierrawireless.com/Support/Downloads/AirPrime/WMP_Series/~/media/Support_Downloads/AirPrime/Application_notes/CMUX_Feature_Application_Note-Rev004.ashx
98*4882a593Smuzhiyun- http://wm.sim.com/sim/News/photo/2010721161442.pdf
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun11-03-08 - Eric Bénard - <eric@eukrea.com>
101