Teltonika ModemPCI/G10 under FreeBSD

From MyWiki

Jump to: navigation, search

I needed an SMS modem under FreeBSD 7-stable, so I looked around and found Teltonika modems that come in PCI, USB and serial versions. I saw that someone was able to run USB model with uftdi driver, but nothing about PCI model. So, I asked Mykolas from Teltonika and he confirmed that all three based on the same chipset, but they have not tested it under FreeBSD. But he kindly sent me Linux configuration instructions and I took it from there.

So, I bought two modems USB and PCI one and went to work :-)

USB was easy. All I needed to add to my kernel configuration was:

device		uftdi
device 		ucom

The modem was detected without a problem. But that didn't help with PCI one. Reading the manual revealed that I need the following two lines in my kernel configuration file:

device		puc
options 	COM_MULTIPORT

The last one was an educated guess after reading the Linux pdf file that Mykolas sent me and my prior experience of setting up Huawei modem under Linux. Since I was getting two extra serial ports COM_MULTIPORT was a logical thing to add. Besides, I came across a post that the option adds stability to serial multiport cards, so why not try? :-)

I added the lines and rebuilt kernel. Reboot, but no extra serial ports. But I can see the card there with lspci:

 01:06.0 Serial controller: NetMos Technology PCI 9820 Multi-I/O Controller (rev 01) (prog-if 02 [16550])
	Subsystem: LSI Logic / Symbios Logic Device 0001
	Flags: medium devsel, IRQ 10
	I/O ports at dc00
	I/O ports at d880
	I/O ports at d800
	I/O ports at d480
	I/O ports at d400
	I/O ports at d080

Back to reading man puc and here it comes right into my face:

    The list of supported devices is in sys/dev/puc/pucdata.c.  Support for
    new cards should be added there.

Examining /usr/src/sys/dev/puc/pucdata.c revealed that I need details to populate the following structure from /usr/src/sys/dev/puc/pucdata.h:

struct puc_cfg {
  uint16_t vendor;
  uint16_t device;
  uint16_t subvendor;
  uint16_t subdevice;
  const char  *desc;
  int      clock;
  int8_t      ports;
  int8_t      rid;     /* Rid of first port */
  int8_t      d_rid;      /* Delta rid of next ports */
  int8_t      d_ofs;      /* Delta offset of next ports */
  puc_config_f   *config_function;
};

So, I run lspci once again with -vn option to get numbers instead names from vendor, device, etc.:

 01:06.0 0700: 9710:9820 (rev 01) (prog-if 02 [16550])
	Subsystem: 1000:0001
	Flags: medium devsel, IRQ 10
	I/O ports at dc00
	I/O ports at d880
	I/O ports at d800
	I/O ports at d480
	I/O ports at d400
	I/O ports at d080

After comparing the above to what was already in /usr/src/sys/dev/puc/pucdata.c, I came up with the following lines for Teltonika ModemPCI/G10:

  {   0x9710, 0x9820, 0x1000, 1,
      "NetMos NM9820 Multi-I/O controller",
      DEFAULT_RCLK,
      PUC_PORT_2S, 0x10, 4, 0,
  },

Added the lines to /usr/src/sys/dev/puc/pucdata.c, rebuilt the kernel and it worked! :-) After reboot I had the following in my /var/run/dmesg.boot:

puc0: <NetMos NM9820 Multi-I/O controller> port 0xdc00-0xdc07,0xd880-0xd887,0xd800-0xd807,0xd480-0xd487,0xd400-0xd407,0xd080-0xd08f irq 10 at device 6.0 on pci1
puc0: [FILTER]
uart0: <Non-standard ns8250 class UART with FIFOs> on puc0
uart0: [FILTER]
uart1: <Non-standard ns8250 class UART with FIFOs> on puc0
uart1: [FILTER]

And I had two new serial ports to work with /dev/cuau0 and /dev/cuau1. I couldn't wait to try it now :-). Took SIM card from one of my mobile phones and using instructions from SMS Tutorial I tried to send SMS to myself:

# cu -l/dev/cuau0 -s115200
Connected
AT
OK
AT+CPIN="0616"
OK
AT+CMGF=1
OK
AT+CMGW="+35386XXXXXXX"
>Hello from Teltonika, Alex!
+CMGW: 1
OK
AT+CMSS=1
+CMSS: 7
OK

And a second later I had the inbound SMS on my mobile :-) (Note: "+35386XXXXXXX" in the above is obfuscated mobile number and "0616" is not really my PIN, but you get the idea how to enter it).

Now it was time to send the patch in and that's when it turned out that I had it slightly wrong.

Initially I had PUC_PORT_2S in my structure in /usr/src/sys/dev/puc/pucdata.c, but it was pointed out to me by Gavin Atkinson of FreeBSD team that the chipset has only one serial port and it really would have to be PUC_PORT_1S there and he asked to try and change it and see if it's still working for me. Although when I changed it to 1 port, it stopped working. puc(4) didn't pick up anything and no serial ports were there. So, I was back to searching the Net for answers, when I came across this post. In short it said that puc(4) shouldn't pickup any of the 1-port serial cards and one should add cards id into /usr/src/sys/dev/uart/uart_bus_pci.c. And so I did.

This one is for /usr/src/sys/dev/puc/pucdata.c:

*** /usr/src/sys/dev/puc/pucdata.c	Thu Dec 10 06:24:16 2009
- --- pucdata.c	Fri Feb 26 15:56:51 2010
***************
*** 743,748 ****
- --- 743,760 ----
 	    PUC_PORT_2P, 0x10, 8, 0,
 	},

+    /*
+     * This is added to _prevent_ puc from claiming this single
+     * port card (Teltonika ModemPCI/G10)
+ 	 *
+ 	 * uart(4) will claim this device.
+     */
+    {   0x9710, 0x9820, 0x1000, 1,
+        "NetMos NM9820 based 1-port GSM modem",
+        DEFAULT_RCLK,
+        PUC_PORT_1S, 0x10, 4, 0,
+    },
+
 	/*
 	 * This is more specific than the generic NM9835 entry that follows, and
 	 * is placed here to _prevent_ puc from claiming this single port card.

And here is the one for /usr/src/sys/dev/uart/uart_bus_pci.c:

*** /usr/src/sys/dev/uart/uart_bus_pci.c	Thu Dec 10 06:24:16 2009
- --- uart_bus_pci.c	Fri Feb 26 15:55:47 2010
***************
*** 109,114 ****
- --- 109,115 ----
 { 0x1415, 0x950b, 0xffff, 0, "Oxford Semiconductor OXCB950 Cardbus 16950 UART",
 	0x10, 16384000 },
 { 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 },
+ { 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 },
 { 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 },
 { 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 },
 { 0xdeaf, 0x9051, 0xffff, 0, "Middle Digital PC Weasel Serial Port", 0x10 },

This is all tested and works for me with the GSM modem today's 7.2-stable. Submitted the patch and hope it will be committed soon :-).

There is another useful site about AT commands.

Now I can add SMS notification to my email one in Nagios. :-)

Personal tools