blob: a5d91126a8f7110b4dd86b2286842127adc0ff4b [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
80Additional Documentation
81------------------------
82More practical details on the protocol and how it's supported by industrial
83modems can be found in the following documents :
84http://www.telit.com/module/infopool/download.php?id=616
85http://www.u-blox.com/images/downloads/Product_Docs/LEON-G100-G200-MuxImplementation_ApplicationNote_%28GSM%20G1-CS-10002%29.pdf
86http://www.sierrawireless.com/Support/Downloads/AirPrime/WMP_Series/~/media/Support_Downloads/AirPrime/Application_notes/CMUX_Feature_Application_Note-Rev004.ashx
87http://wm.sim.com/sim/News/photo/2010721161442.pdf
88
8911-03-08 - Eric Bénard - <eric@eukrea.com>