Eric Bénard | 323e841 | 2011-03-09 19:24:48 +0100 | [diff] [blame] | 1 | n_gsm.c GSM 0710 tty multiplexor HOWTO |
| 2 | =================================================== |
| 3 | |
| 4 | This line discipline implements the GSM 07.10 multiplexing protocol |
| 5 | detailed in the following 3GPP document : |
| 6 | http://www.3gpp.org/ftp/Specs/archive/07_series/07.10/0710-720.zip |
| 7 | |
| 8 | This document give some hints on how to use this driver with GPRS and 3G |
| 9 | modems connected to a physical serial port. |
| 10 | |
| 11 | How to use it |
| 12 | ------------- |
| 13 | 1- initialize the modem in 0710 mux mode (usually AT+CMUX= command) through |
| 14 | its serial port. Depending on the modem used, you can pass more or less |
| 15 | parameters to this command, |
| 16 | 2- switch the serial line to using the n_gsm line discipline by using |
| 17 | TIOCSETD ioctl, |
| 18 | 3- configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl, |
| 19 | |
| 20 | Major 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 Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 37 | and check that it's successful (should return OK) */ |
Eric Bénard | 323e841 | 2011-03-09 19:24:48 +0100 | [diff] [blame] | 38 | 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 | |
| 63 | 4- create the devices corresponding to the "virtual" serial ports (take care, |
| 64 | each modem has its configuration and some DLC have dedicated functions, |
| 65 | for example GPS), starting with minor 1 (DLC0 is reserved for the management |
| 66 | of the mux) |
| 67 | |
| 68 | MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}` |
| 69 | for i in `seq 1 4`; do |
| 70 | mknod /dev/ttygsm$i c $MAJOR $i |
| 71 | done |
| 72 | |
| 73 | 5- use these devices as plain serial ports. |
| 74 | for 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 | |
| 78 | 6- first close all virtual ports before closing the physical port. |
| 79 | |
Sascha Hauer | 71e0779 | 2017-05-31 08:19:05 +0200 | [diff] [blame] | 80 | Note that after closing the physical port the modem is still in multiplexing |
| 81 | mode. This may prevent a successful re-opening of the port later. To avoid |
| 82 | this situation either reset the modem if your hardware allows that or send |
| 83 | a disconnect command frame manually before initializing the multiplexing mode |
| 84 | for the second time. The byte sequence for the disconnect command frame is: |
| 85 | 0xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9. |
| 86 | |
Eric Bénard | 323e841 | 2011-03-09 19:24:48 +0100 | [diff] [blame] | 87 | Additional Documentation |
| 88 | ------------------------ |
| 89 | More practical details on the protocol and how it's supported by industrial |
| 90 | modems can be found in the following documents : |
| 91 | http://www.telit.com/module/infopool/download.php?id=616 |
| 92 | http://www.u-blox.com/images/downloads/Product_Docs/LEON-G100-G200-MuxImplementation_ApplicationNote_%28GSM%20G1-CS-10002%29.pdf |
| 93 | http://www.sierrawireless.com/Support/Downloads/AirPrime/WMP_Series/~/media/Support_Downloads/AirPrime/Application_notes/CMUX_Feature_Application_Note-Rev004.ashx |
| 94 | http://wm.sim.com/sim/News/photo/2010721161442.pdf |
| 95 | |
| 96 | 11-03-08 - Eric Bénard - <eric@eukrea.com> |