n_gsm.txt 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. n_gsm.c GSM 0710 tty multiplexor HOWTO
  2. ===================================================
  3. This line discipline implements the GSM 07.10 multiplexing protocol
  4. detailed in the following 3GPP document :
  5. http://www.3gpp.org/ftp/Specs/archive/07_series/07.10/0710-720.zip
  6. This document give some hints on how to use this driver with GPRS and 3G
  7. modems connected to a physical serial port.
  8. How to use it
  9. -------------
  10. 1- initialize the modem in 0710 mux mode (usually AT+CMUX= command) through
  11. its serial port. Depending on the modem used, you can pass more or less
  12. parameters to this command,
  13. 2- switch the serial line to using the n_gsm line discipline by using
  14. TIOCSETD ioctl,
  15. 3- configure the mux using GSMIOC_GETCONF / GSMIOC_SETCONF ioctl,
  16. Major parts of the initialization program :
  17. (a good starting point is util-linux-ng/sys-utils/ldattach.c)
  18. #include <linux/gsmmux.h>
  19. #define N_GSM0710 21 /* GSM 0710 Mux */
  20. #define DEFAULT_SPEED B115200
  21. #define SERIAL_PORT /dev/ttyS0
  22. int ldisc = N_GSM0710;
  23. struct gsm_config c;
  24. struct termios configuration;
  25. /* open the serial port connected to the modem */
  26. fd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
  27. /* configure the serial port : speed, flow control ... */
  28. /* send the AT commands to switch the modem to CMUX mode
  29. and check that it's successful (should return OK) */
  30. write(fd, "AT+CMUX=0\r", 10);
  31. /* experience showed that some modems need some time before
  32. being able to answer to the first MUX packet so a delay
  33. may be needed here in some case */
  34. sleep(3);
  35. /* use n_gsm line discipline */
  36. ioctl(fd, TIOCSETD, &ldisc);
  37. /* get n_gsm configuration */
  38. ioctl(fd, GSMIOC_GETCONF, &c);
  39. /* we are initiator and need encoding 0 (basic) */
  40. c.initiator = 1;
  41. c.encapsulation = 0;
  42. /* our modem defaults to a maximum size of 127 bytes */
  43. c.mru = 127;
  44. c.mtu = 127;
  45. /* set the new configuration */
  46. ioctl(fd, GSMIOC_SETCONF, &c);
  47. /* and wait for ever to keep the line discipline enabled */
  48. daemon(0,0);
  49. pause();
  50. 4- create the devices corresponding to the "virtual" serial ports (take care,
  51. each modem has its configuration and some DLC have dedicated functions,
  52. for example GPS), starting with minor 1 (DLC0 is reserved for the management
  53. of the mux)
  54. MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}`
  55. for i in `seq 1 4`; do
  56. mknod /dev/ttygsm$i c $MAJOR $i
  57. done
  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. Additional Documentation
  64. ------------------------
  65. More practical details on the protocol and how it's supported by industrial
  66. modems can be found in the following documents :
  67. http://www.telit.com/module/infopool/download.php?id=616
  68. http://www.u-blox.com/images/downloads/Product_Docs/LEON-G100-G200-MuxImplementation_ApplicationNote_%28GSM%20G1-CS-10002%29.pdf
  69. http://www.sierrawireless.com/Support/Downloads/AirPrime/WMP_Series/~/media/Support_Downloads/AirPrime/Application_notes/CMUX_Feature_Application_Note-Rev004.ashx
  70. http://wm.sim.com/sim/News/photo/2010721161442.pdf
  71. 11-03-08 - Eric Bénard - <eric@eukrea.com>