n_gsm.rst 4.6 KB

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