Connecting to the Internet over USB GSM Modem Print

 

This application note explains how to connect to the Internet from the NXP i.MX RT1050 EVK running Linux using a USB GSM modem.

The Linux PPP daemon and its shell scripts are used to initiate the connection, receive the networking parameters from the cell (IP, routing, DNS etc) and configure the system networking according to the received parameters. The pppd package integrated by Emcraft into the NXP i.MX RT1050 EVK BSP was obtained from http://www.uclinux.org/pub/uClinux/dist, release 20140504.

The functionality described below is available from the rootfs.uImage project provided by Emcraft for NXP i.MX RT1050 EVK. The generic Linux kernel device driver driver for the USB Modems (CONFIG_USB_ACM) is used in this configuration. Emcraft tested the functionality documented below using the MTD-H5-2.0 HSPA+ USB Cellular Modem from MultiTech Systems.


Cellular Network Configuration

For starting and terminating the PPP connection, the standard scripts from the PPP Daemon package are provided in the rootfs projects. The scripts as follows:

  • pon <provider> - starts the PPP daemon with a specified configuraton in /etc/ppp/peers/. Without arguments, the /etc/ppp/peers/provider configuration is used.
  • poff - stops the PPP daemon and terminates the connection.

The following PPP configuration files are provided with the rootfs project:

  • /etc/ppp/peers/provider - contains the default PPP daemon configuration.
  • /etc/ppp/options-mobile - contains the general PPP daemon configuration options (see man pppd). Among others, there are two options enabled for debugging (dump and logfile /dev/console).
  • /etc/ppp/chatscripts/mobile-modem.chat - contains modem commands to establish connection with the network.
  • /etc/ppp/chatscripts/apn - contains the modem command to configure the Access Point Name specific to the provider.
  • /etc/ppp/chatscripts/pin - contains the modem command to configure the SIM-card PIN code, if required. Preconfigured for no PIN in the project.

For a US GSM network operator (AT&T, T-Mobile, Rogers, Bell, Telus, see in http://www.multitech.com/datasheets/86002162.pdf), the current configuration should work, after setting up an appropriate Access Point Name in /etc/ppp/chatscripts/apn and cell account information in /etc/ppp/peers/provider.

For a US CDMA network operator (Verizon, Sprint, Aeris), the modem model Multitech MTD-EV3 should be used. The project provides sample configurations /etc/ppp/peers/verizon and /etc/ppp/chatscripts/verizon.chat, which supposedly should work with Verizon.

To reconfigure the rootfs project for your SIM operator typically you will need:

  • Edit the etc/ppp/chatscripts/apn file in projects/rootfs, and change the APN settings appropriately.
  • Edit the etc/ppp/peers/provider file in projects/rootfs, and change the account information appropriately.
  • Build project/rootfs (Building Linux), and install it to the target (Installing Linux Images to SD Card).

TCP/IP Connectivity Over PPP

Plug-in a USB GSM Modem device to the USB1 J9 or USB2 J10 port of NXP i.MX RT1050 EVK. The system will print the appropriate messages to console about the hardware detected:

ci_hdrc ci_hdrc.0: EHCI Host Controller
ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 2
ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 1 port detected
usb 2-1: new high-speed USB device number 2 using ci_hdrc
usb 2-1: config 1 interface 0 altsetting 0 endpoint 0x81 has an invalid bInterval 255, changing to 11
usb 2-1: USB disconnect, device number 2
usb 2-1: new high-speed USB device number 3 using ci_hdrc
cdc_acm 2-1:1.0: ttyACM0: USB ACM device
cdc_acm 2-1:1.2: ttyACM1: USB ACM device
cdc_acm: probe of 2-1:1.4 failed with error -12
cdc_acm 2-1:1.5: Zero length descriptor references
cdc_acm: probe of 2-1:1.5 failed with error -22
cdc_acm: probe of 2-1:1.6 failed with error -12
cdc_acm 2-1:1.7: Zero length descriptor references
cdc_acm: probe of 2-1:1.7 failed with error -22
cdc_acm: probe of 2-1:1.8 failed with error -12
cdc_acm 2-1:1.9: Zero length descriptor references
cdc_acm: probe of 2-1:1.9 failed with error -22
cdc_acm: probe of 2-1:1.10 failed with error -12
cdc_acm 2-1:1.11: Zero length descriptor references
cdc_acm: probe of 2-1:1.11 failed with error -22

  • Shutdown the eth0 network interface:
  • / # ifconfig eth0 down

    Initiate connection with the cellular network:

    / # pon / # pppd options in effect: debug # (from /etc/ppp/options-mobile) holdoff 10 # (from /etc/ppp/options-mobile) persist # (from /etc/ppp/options-mobile) logfile /dev/console # (from /etc/ppp/options-mobile) maxfail 0 # (from /etc/ppp/options-mobile) dump # (from /etc/ppp/options-mobile) noauth # (from /etc/ppp/options-mobile) user gdata # (from /etc/ppp/peers/provider) password ?????? # (from /etc/ppp/peers/provider) /dev/ttyACM0 # (from /etc/ppp/options-mobile) 115200 # (from /etc/ppp/options-mobile) lock # (from /etc/ppp/options-mobile) connect /usr/sbin/chat -v -t15 -f /etc/ppp/chatscripts/mobile-modem.chat # (from /etc/ppp/peers/provider) crtscts # (from /etc/ppp/options-mobile) modem # (from /etc/ppp/options-mobile) passive # (from /etc/ppp/options-mobile) hide-password # (from /etc/ppp/options-mobile) novj # (from /etc/ppp/options-mobile) noipdefault # (from /etc/ppp/options-mobile) defaultroute # (from /etc/ppp/options-mobile) usepeerdns # (from /etc/ppp/options-mobile) Serial connection established. using channel 1 Using interface ppp0 Connect: ppp0 <--> /dev/ttyACM0 rcvd [LCP ConfReq id=0x1 <asyncmap 0x0> <auth pap> <magic 0x96a24aa4> <pcomp> <accomp>] sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x81e93b7f> <pcomp> <accomp>] sent [LCP ConfAck id=0x1 <asyncmap 0x0> <auth pap> <magic 0x96a24aa4> <pcomp> <accomp>] rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x81e93b7f> <pcomp> <accomp>] sent [PAP AuthReq id=0x1 user="gdata" password=<hidden>] rcvd [PAP AuthAck id=0x1 ""] PAP authentication succeeded sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>] sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>] rcvd [LCP ProtRej id=0x2 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15] Protocol-Reject for 'Compression Control Protocol' (0x80fd) received sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>] rcvd [IPCP ConfReq id=0x1] sent [IPCP ConfNak id=0x1 <addr 0.0.0.0>] rcvd [IPCP ConfNak id=0x1 <addr 100.112.91.33> <ms-dns1 10.152.222.140> <ms-dns2 10.152.222.133>] sent [IPCP ConfReq id=0x2 <addr 100.112.91.33> <ms-dns1 10.152.222.140> <ms-dns2 10.152.222.133>] rcvd [IPCP ConfReq id=0x2 <addr 100.112.91.33>] sent [IPCP ConfAck id=0x2 <addr 100.112.91.33>] rcvd [IPCP ConfAck id=0x2 <addr 100.112.91.33> <ms-dns1 10.152.222.140> <ms-dns2 10.152.222.133>] ioctl(SIOCDELRT): No such process(3) local IP address 100.112.91.33 remote IP address 100.112.91.33 primary DNS address 10.152.222.140 secondary DNS address 10.152.222.133 Script /etc/ppp/ip-up started (pid 101) Script /etc/ppp/ip-up finished (pid 101), status = 0x0

    Verify that the connection is established (depending on the cellular network, the link may take up to 10 seconds to get established):

    / # ifconfig ppp0 ppp0 Link encap:Point-to-Point Protocol inet addr:100.112.91.33 P-t-P:100.112.91.33 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:3 RX bytes:58 (58.0 B) TX bytes:101 (101.0 B)

    Check that the TCP/IP connection to the Internet over PPP has been configured:

    / # netstat -rn
    Kernel IP routing table
    Destination Gateway Genmask Flags MSS Window irtt Iface
    0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp0
    100.112.91.33 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0

    Ping a remote host to check that network is set up correctly:

    / # ping google.com -c 3
    PING google.com (74.125.131.102): 56 data bytes
    64 bytes from 74.125.131.102: seq=0 ttl=106 time=509.508 ms
    64 bytes from 74.125.131.102: seq=1 ttl=106 time=441.719 ms
    64 bytes from 74.125.131.102: seq=2 ttl=106 time=451.702 ms

    --- google.com ping statistics ---
    3 packets transmitted, 3 packets received, 0% packet loss
    round-trip min/avg/max = 441.719/467.643/509.508 ms

    Download a file from a remote host:

    / # wget ftp://ftp.gnu.org/README
    Connecting to ftp.gnu.org (209.51.188.20:21)
    saving to 'README'
    README 100% |********************************| 2748 0:00:00 ETA
    'README' saved

    Close the TCP/IP connection:

    / # poff
    Terminating on signal 15
    Connect time 5.0 minutes.
    Sent 1441 bytes, received 5723 bytes.
    / # Script /etc/ppp/ip-down started (pid 117)
    sent [LCP TermReq id=0x2 "User request"]
    rcvd [LCP TermAck id=0x2]
    Connection terminated.
    Script /etc/ppp/ip-down finished (pid 117), status = 0x0