Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: tty: n_gsm, use power of ReST

Reformat the whole document, so that automatic numbering and TOC is
properly generated.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20220411110143.10019-7-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby and committed by
Greg Kroah-Hartman
7fb4028f e937eb43

+74 -70
+74 -70
Documentation/driver-api/tty/n_gsm.rst
··· 2 2 GSM 0710 tty multiplexor HOWTO 3 3 ============================== 4 4 5 + .. contents:: :local: 6 + 5 7 This line discipline implements the GSM 07.10 multiplexing protocol 6 8 detailed in the following 3GPP document: 7 9 ··· 13 11 modems connected to a physical serial port. 14 12 15 13 How to use it 16 - ------------- 17 - 1. config initiator 18 - ^^^^^^^^^^^^^^^^^^^^^ 14 + ============= 19 15 20 - 1.1 initialize the modem in 0710 mux mode (usually AT+CMUX= command) through 21 - its serial port. Depending on the modem used, you can pass more or less 22 - parameters to this command. 16 + Config Initiator 17 + ---------------- 23 18 24 - 1.2 switch the serial line to using the n_gsm line discipline by using 25 - TIOCSETD ioctl. 19 + #. Initialize the modem in 0710 mux mode (usually ``AT+CMUX=`` command) through 20 + its serial port. Depending on the modem used, you can pass more or less 21 + parameters to this command. 26 22 27 - 1.3 configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl. 23 + #. Switch the serial line to using the n_gsm line discipline by using 24 + ``TIOCSETD`` ioctl. 28 25 29 - 1.4 obtain base gsmtty number for the used serial port. 26 + #. Configure the mux using ``GSMIOC_GETCONF``/``GSMIOC_SETCONF`` ioctl. 30 27 31 - Major parts of the initialization program : 32 - (a good starting point is util-linux-ng/sys-utils/ldattach.c):: 28 + #. Obtain base gsmtty number for the used serial port. 33 29 34 - #include <stdio.h> 35 - #include <stdint.h> 36 - #include <linux/gsmmux.h> 37 - #include <linux/tty.h> 38 - #define DEFAULT_SPEED B115200 39 - #define SERIAL_PORT /dev/ttyS0 30 + Major parts of the initialization program 31 + (a good starting point is util-linux-ng/sys-utils/ldattach.c):: 40 32 41 - int ldisc = N_GSM0710; 42 - struct gsm_config c; 43 - struct termios configuration; 44 - uint32_t first; 33 + #include <stdio.h> 34 + #include <stdint.h> 35 + #include <linux/gsmmux.h> 36 + #include <linux/tty.h> 45 37 46 - /* open the serial port connected to the modem */ 47 - fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY); 38 + #define DEFAULT_SPEED B115200 39 + #define SERIAL_PORT /dev/ttyS0 48 40 49 - /* configure the serial port : speed, flow control ... */ 41 + int ldisc = N_GSM0710; 42 + struct gsm_config c; 43 + struct termios configuration; 44 + uint32_t first; 50 45 51 - /* send the AT commands to switch the modem to CMUX mode 52 - and check that it's successful (should return OK) */ 53 - write(fd, "AT+CMUX=0\r", 10); 46 + /* open the serial port connected to the modem */ 47 + fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY); 54 48 55 - /* experience showed that some modems need some time before 56 - being able to answer to the first MUX packet so a delay 57 - may be needed here in some case */ 58 - sleep(3); 49 + /* configure the serial port : speed, flow control ... */ 59 50 60 - /* use n_gsm line discipline */ 61 - ioctl(fd, TIOCSETD, &ldisc); 51 + /* send the AT commands to switch the modem to CMUX mode 52 + and check that it's successful (should return OK) */ 53 + write(fd, "AT+CMUX=0\r", 10); 62 54 63 - /* get n_gsm configuration */ 64 - ioctl(fd, GSMIOC_GETCONF, &c); 65 - /* we are initiator and need encoding 0 (basic) */ 66 - c.initiator = 1; 67 - c.encapsulation = 0; 68 - /* our modem defaults to a maximum size of 127 bytes */ 69 - c.mru = 127; 70 - c.mtu = 127; 71 - /* set the new configuration */ 72 - ioctl(fd, GSMIOC_SETCONF, &c); 73 - /* get first gsmtty device node */ 74 - ioctl(fd, GSMIOC_GETFIRST, &first); 75 - printf("first muxed line: /dev/gsmtty%i\n", first); 55 + /* experience showed that some modems need some time before 56 + being able to answer to the first MUX packet so a delay 57 + may be needed here in some case */ 58 + sleep(3); 76 59 77 - /* and wait for ever to keep the line discipline enabled */ 78 - daemon(0,0); 79 - pause(); 60 + /* use n_gsm line discipline */ 61 + ioctl(fd, TIOCSETD, &ldisc); 80 62 81 - 1.5 use these devices as plain serial ports. 63 + /* get n_gsm configuration */ 64 + ioctl(fd, GSMIOC_GETCONF, &c); 65 + /* we are initiator and need encoding 0 (basic) */ 66 + c.initiator = 1; 67 + c.encapsulation = 0; 68 + /* our modem defaults to a maximum size of 127 bytes */ 69 + c.mru = 127; 70 + c.mtu = 127; 71 + /* set the new configuration */ 72 + ioctl(fd, GSMIOC_SETCONF, &c); 73 + /* get first gsmtty device node */ 74 + ioctl(fd, GSMIOC_GETFIRST, &first); 75 + printf("first muxed line: /dev/gsmtty%i\n", first); 82 76 83 - for example, it's possible: 77 + /* and wait for ever to keep the line discipline enabled */ 78 + daemon(0,0); 79 + pause(); 84 80 85 - - and to use gnokii to send / receive SMS on ttygsm1 86 - - to use ppp to establish a datalink on ttygsm2 81 + #. Use these devices as plain serial ports. 87 82 88 - 1.6 first close all virtual ports before closing the physical port. 83 + For example, it's possible: 84 + 85 + - to use *gnokii* to send / receive SMS on ``ttygsm1`` 86 + - to use *ppp* to establish a datalink on ``ttygsm2`` 87 + 88 + #. First close all virtual ports before closing the physical port. 89 89 90 90 Note that after closing the physical port the modem is still in multiplexing 91 91 mode. This may prevent a successful re-opening of the port later. To avoid ··· 95 91 a disconnect command frame manually before initializing the multiplexing mode 96 92 for the second time. The byte sequence for the disconnect command frame is:: 97 93 98 - 0xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9. 94 + 0xf9, 0x03, 0xef, 0x03, 0xc3, 0x16, 0xf9 99 95 100 - 2. config requester 101 - ^^^^^^^^^^^^^^^^^^^^^ 96 + Config Requester 97 + ---------------- 102 98 103 - 2.1 receive string "AT+CMUX= command" through its serial port,initialize 104 - mux mode config 99 + #. Receive ``AT+CMUX=`` command through its serial port, initialize mux mode 100 + config. 105 101 106 - 2.2 switch the serial line to using the n_gsm line discipline by using 107 - TIOCSETD ioctl. 102 + #. Switch the serial line to using the *n_gsm* line discipline by using 103 + ``TIOCSETD`` ioctl. 108 104 109 - 2.3 configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl. 105 + #. Configure the mux using ``GSMIOC_GETCONF``/``GSMIOC_SETCONF`` ioctl. 110 106 111 - 2.4 obtain base gsmtty number for the used serial port:: 107 + #. Obtain base gsmtty number for the used serial port:: 112 108 113 - #include <stdio.h> 114 - #include <stdint.h> 115 - #include <linux/gsmmux.h> 116 - #include <linux/tty.h> 117 - #define DEFAULT_SPEED B115200 118 - #define SERIAL_PORT /dev/ttyS0 109 + #include <stdio.h> 110 + #include <stdint.h> 111 + #include <linux/gsmmux.h> 112 + #include <linux/tty.h> 113 + #define DEFAULT_SPEED B115200 114 + #define SERIAL_PORT /dev/ttyS0 119 115 120 116 int ldisc = N_GSM0710; 121 117 struct gsm_config c;