n_gsm.rst 3.5 KB

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