Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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