2019-04-22 10:27:22 -03:00
==============================
GSM 0710 tty multiplexor HOWTO
==============================
2022-04-11 13:01:43 +02:00
.. contents :: :local:
2019-04-22 10:27:22 -03:00
This line discipline implements the GSM 07.10 multiplexing protocol
detailed in the following 3GPP document:
2020-07-18 15:34:52 +02:00
https://www.3gpp.org/ftp/Specs/archive/07_series/07.10/0710-720.zip
2019-04-22 10:27:22 -03:00
This document give some hints on how to use this driver with GPRS and 3G
modems connected to a physical serial port.
How to use it
2022-04-11 13:01:43 +02:00
=============
2021-08-20 20:17:45 +08:00
2022-04-11 13:01:43 +02:00
Config Initiator
----------------
2021-12-09 17:24:39 +08:00
2022-04-11 13:01:43 +02:00
#. Initialize the modem in 0710 mux mode (usually `` AT+CMUX= `` command) through
its serial port. Depending on the modem used, you can pass more or less
parameters to this command.
2021-12-09 17:24:39 +08:00
2022-04-11 13:01:43 +02:00
#. Switch the serial line to using the n_gsm line discipline by using
`` TIOCSETD `` ioctl.
2021-12-09 17:24:39 +08:00
2022-04-11 13:01:43 +02:00
#. Configure the mux using `` GSMIOC_GETCONF `` /`` GSMIOC_SETCONF `` ioctl.
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
#. Obtain base gsmtty number for the used serial port.
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
Major parts of the initialization program
(a good starting point is util-linux-ng/sys-utils/ldattach.c)::
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
#include <stdio.h>
#include <stdint.h>
#include <linux/gsmmux.h>
#include <linux/tty.h>
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
#define DEFAULT_SPEED B115200
#define SERIAL_PORT /dev/ttyS0
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
int ldisc = N_GSM0710;
struct gsm_config c;
struct termios configuration;
uint32_t first;
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
/* open the serial port connected to the modem * /
fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
/* configure the serial port : speed, flow control ... * /
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
/* send the AT commands to switch the modem to CMUX mode
and check that it's successful (should return OK) */
write(fd, "AT+CMUX=0\r", 10);
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
/* experience showed that some modems need some time before
being able to answer to the first MUX packet so a delay
may be needed here in some case */
sleep(3);
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
/* use n_gsm line discipline * /
ioctl(fd, TIOCSETD, &ldisc);
/* get n_gsm configuration * /
ioctl(fd, GSMIOC_GETCONF, &c);
/* we are initiator and need encoding 0 (basic) * /
c.initiator = 1;
c.encapsulation = 0;
/* our modem defaults to a maximum size of 127 bytes * /
c.mru = 127;
c.mtu = 127;
/* set the new configuration * /
ioctl(fd, GSMIOC_SETCONF, &c);
/* get first gsmtty device node * /
ioctl(fd, GSMIOC_GETFIRST, &first);
printf("first muxed line: /dev/gsmtty%i\n", first);
/* and wait for ever to keep the line discipline enabled * /
daemon(0,0);
pause();
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
#. Use these devices as plain serial ports.
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
For example, it's possible:
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
- to use *gnokii* to send / receive SMS on `` ttygsm1 ``
- to use *ppp* to establish a datalink on `` ttygsm2 ``
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
#. First close all virtual ports before closing the physical port.
2019-04-22 10:27:22 -03:00
Note that after closing the physical port the modem is still in multiplexing
mode. This may prevent a successful re-opening of the port later. To avoid
this situation either reset the modem if your hardware allows that or send
a disconnect command frame manually before initializing the multiplexing mode
for the second time. The byte sequence for the disconnect command frame is::
2022-04-11 13:01:43 +02:00
0xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9
2019-04-22 10:27:22 -03:00
2022-04-11 13:01:43 +02:00
Config Requester
----------------
2021-08-20 20:17:45 +08:00
2022-04-11 13:01:43 +02:00
#. Receive `` AT+CMUX= `` command through its serial port, initialize mux mode
config.
2021-12-09 17:24:39 +08:00
2022-04-11 13:01:43 +02:00
#. Switch the serial line to using the *n_gsm* line discipline by using
`` TIOCSETD `` ioctl.
2021-12-09 17:24:39 +08:00
2022-04-11 13:01:43 +02:00
#. Configure the mux using `` GSMIOC_GETCONF `` /`` GSMIOC_SETCONF `` ioctl.
2021-12-09 17:24:39 +08:00
2022-04-11 13:01:43 +02:00
#. Obtain base gsmtty number for the used serial port::
2021-08-20 20:17:45 +08:00
2022-04-11 13:01:43 +02:00
#include <stdio.h>
#include <stdint.h>
#include <linux/gsmmux.h>
#include <linux/tty.h>
#define DEFAULT_SPEED B115200
#define SERIAL_PORT /dev/ttyS0
2021-08-20 20:17:45 +08:00
int ldisc = N_GSM0710;
struct gsm_config c;
struct termios configuration;
uint32_t first;
/* open the serial port * /
fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
/* configure the serial port : speed, flow control ... * /
/* get serial data and check "AT+CMUX=command" parameter ... * /
/* use n_gsm line discipline * /
ioctl(fd, TIOCSETD, &ldisc);
/* get n_gsm configuration * /
ioctl(fd, GSMIOC_GETCONF, &c);
/* we are requester and need encoding 0 (basic) * /
c.initiator = 0;
c.encapsulation = 0;
/* our modem defaults to a maximum size of 127 bytes * /
c.mru = 127;
c.mtu = 127;
/* set the new configuration * /
ioctl(fd, GSMIOC_SETCONF, &c);
/* get first gsmtty device node * /
ioctl(fd, GSMIOC_GETFIRST, &first);
printf("first muxed line: /dev/gsmtty%i\n", first);
/* and wait for ever to keep the line discipline enabled * /
daemon(0,0);
pause();
2019-04-22 10:27:22 -03:00
11-03-08 - Eric Bénard - <eric@eukrea.com>