首頁 > 軟體

在ARM Linux上實現4G模組PPP撥號上網

2020-06-16 17:44:28

在ARM平台上實現4G模組的PPP撥號上網,參考網上的資料和自己的理解,從一無所知到開發完成花了一週多。最後看到ARM板ping通www.linuxidc.com時甚是高興,現將此過程整理如下。當然,除此之外要做的工作還有很多。

4G模組使用的SIMTECH 的SIM7100C,SIM7100C帶有UART和USB介面,在考慮速度上我們使用USB介面和ARM進行通訊。所以向linux核心新增3G模組的驅動(USB轉串列埠驅動)和PPP協定的支援,然後編譯核心並下載到開發板。

1. 編譯核心

大容量儲存驅動

> Device Drivers > USB support

make ARCH=arm menuconfig設定USB驅動:

<*>    USB Mass Storage support

[*]      USB Mass Storage verbose debug

<*>      Realtek Card Reader support

[*]        Realtek Card Reader autosuspend support

<*>      Datafab Compact Flash Reader support

◇ USB驅動

> Device Drivers > USB support

<*>  Inventra Highspeed Dual Role Controller (TI, ADI, ...)   

            MUSB Mode Selection (Dual Role mode)  --->            

    <*>    Platform Glue Layer (TI DSPS platforms)  --->         

        MUSB DMA mode (Disable DMA (always use PIO))  --->

<*>  USB Serial Converter support  --->

[*]      USBGeneric Serial Driver 

<*>     USBdriver for GSM and CDMA modems

◇ PPP驅動

> Device Drivers > Network device support

  <*>  PPP (point-to-point protocol) support         

    <*>    PPP BSD-Compress compression                         

    <*>    PPP Deflate compression                             

    [*]    PPP filtering                                           

    <*>    PPP MPPE compression (encryption)                         

     [*]    PPP multilink support                 

    <*>    PPP over Ethernet               

    <*>    PPP support for async serial ports   

    <*>    PPP support for sync tty ports     

<*>  SLIP (serial line) support     

[*]  CSLIP compressed headers

2. 交叉編譯libusb

下載usblib庫和libusb-compat

https://sourceforge.net/projects/libusb/files/

root@linuxidc:/opt/usb-tools/libusb-1.0.20# mkdir install

configure: error: "udev support requested but libudev not installed"(解決:新增--disable-udev)

root@linuxidc:/opt/usb-tools/libusb-1.0.20# ./configure --host=arm-none-linux-gnueabi --prefix=/opt/usb-tools/libusb-1.0.20/install --disable-udev

root@linuxidc:/opt/usb-tools/libusb-1.0.20# make

root@linuxidc:/opt/usb-tools/libusb-1.0.20# make install

新增環境變數 http://www.linuxidc.com/Linux/2011-03/33432.htm(PKG_CONFIG_PATH設定)

root@linuxidc:/opt/usb-tools/libusb-1.0.20# export PKG_CONFIG_PATH=/opt/usb-tools/libusb-1.0.20/install/lib/pkgconfig:$PKG_CONFIG_PATH

root@linuxidc:/opt/usb-tools/libusb-1.0.20# echo $PKG_CONFIG_PATH

編譯libusb-compat:

root@linuxidc:/opt/usb-tools/libusb-compat-0.1.5# ./configure --host=arm-none-linux-gnueabi --prefix=/opt/usb-tools/libusb-compat-0.1.5/install

root@linuxidc:/opt/usb-tools/libusb-compat-0.1.5# make

root@linuxidc:/opt/usb-tools/libusb-compat-0.1.5# make install

將生成的libusb-1.0.20和libusb-compat-0.1.5下的庫檔案複製到ARM板上的linux的/lib下面即可。

3. 交叉編譯4G模組驅動

交叉編譯GobiSerial.c(ARCH=arm CC=arm-none-linux-gnueabi-gcc),得到GobiSerial.ko。複製到ARM板安裝驅動

#insmod GobiSerial.ko

4. 檢視驅動執行狀況

插上4G模組,虛擬出6個ttyUSB,它們分別是:

root@am335x-evm:/# ls /dev/ttyUSB*

/dev/ttyUSB0  /dev/ttyUSB1  /dev/ttyUSB2  /dev/ttyUSB3  /dev/ttyUSB4  /dev/ttyUSB5

1) /dev/ttyUSB0-diag port for output developing messages

2) /dev/ttyUSB1- NMEA port for GPS NMEA data output

3) /dev/ttyUSB2-AT port for AT commands

4) /dev/ttyUSB3-Modem port for ppp-dial

5) /dev/ttyUSB4-audio port

6) /dev/ttyUSB5-Virtual Net card

插上U盤,提示裝置執行:

[75097.986054] usb 2-1: New USB device found, idVendor=058f, idProduct=6387

[75097.993167] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3

[75098.000689] usb 2-1: Product: Mass Storage

[75098.004995] usb 2-1: Manufacturer: Generic

[75098.009342] usb 2-1: SerialNumber: AC3DF2EE

[75098.024341] usb-storage 2-1:1.0: USB Mass Storage device detected

[75098.049922] scsi0 : usb-storage 2-1:1.0

lsusb命令檢視結果:

Bus 001 Device 002: ID 1e0e:9001

Bus 002 Device 002: ID 058f:6387

Bus 001 Device 001: ID 1d6b:0002

Bus 002 Device 001: ID 1d6b:0002

5. 交叉編譯PPP

參見: http://www.linuxidc.com/Linux/2016-03/129580.htm

6. 撥號指令碼設定

root@am335x-evm:/etc/ppp# vi gprs-connect-chat

#Chat script for China Mobile, used SIMCOM sim4100 TD module.

TIMEOUT 15

ABORT "DELAYED"

ABORT "BUSY"

ABORT "ERROR"

ABORT "NO DIALTONE"

ABORT "NO CARRIER"

TIMEOUT 40

'' rAT

OK ATS0=0

OK ATE0V1

OK AT+CGDCONT=1,"IP","CMNET"

OK AT+CGEQREQ=1,2,128,384,,,0,,,,,,

OK ATDT*99*1#

CONNECT

root@am335x-evm:/etc/ppp/peers# vi gprsdial

#/etc/ppp/peers/gprsdial

# This is pppd script for China Mobile, used SIMCOM SIM7100 Module

# Usage: root>pppd call gprs

#Interface should be used is the interface which connects physics interface of S

/dev/ttyUSB3

115200

crtscts

modem

#noauth

debug

nodetach

#hide-password

usepeerdns

noipdefault

defaultroute

user "cmnet"

0.0.0.0:0.0.0.0

#ipcp-accept-local

#ipcp-accept-remote

#lcp-echo-failure 12

#lcp-echo-interval 3

#noccp

#novj

#novjccomp

#persist

connect '/usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat'

#disconnect '/bin/chat -v -f /etc/ppp/gprs-disconnect-chat'

6. 撥號

root@am335x-evm: pppd call gprsdial

6. 測試

撥號之後進行測試,發現可以ping通ip但是無法ping通域名。這需要設定/etc/resolv.conf來新增DNS解析伺服器的地址

檔案/etc/resolv.conf設定DNS客戶,它包含了主機的域名搜尋順序和DNS伺服器的地址,每一行應包含一個關鍵字和一個或多個的由空格隔開的引數。下面是一個例子檔案: 

domain test.com

search www.test.com test.com

nameserver 202.96.128.86

nameserver 202.96.128.166

nameserver  #定義DNS伺服器的IP地址

domain      #定義本地域名

search      #定義域名的搜尋列表

sortlist    #對返回的域名進行排序

主要是nameserver關鍵字,如果沒指定nameserver就找不到DNS伺服器,其它關鍵字是可選的。

我這裡只設定了兩個DNS,如下:

ameserver 114.114.114.114

nameserver 8.8.8.8

參考文件

http://www.linuxidc.com/Linux/2016-03/129579.htm

http://www.linuxidc.com/Linux/2011-03/33430p2.htm

http://www.linuxidc.com/Linux/2011-03/33430.htm

本文永久更新連結地址http://www.linuxidc.com/Linux/2016-03/129581.htm


IT145.com E-mail:sddin#qq.com