Air720模塊Linux USB驅動以及PPP撥號說明

 http://ask.openluat.com/article/37

本文章介紹了在linux系統下,如何修改usb驅動支持合宙 Air720模塊,以及使用Air720進行ppp撥號上網流程     Air720正常啓動後,通過USB連接到linux設備上,驅動正常加載後會在/dev/下產...

    本文章介紹了在linux系統下,如何修改usb驅動支持合宙 Air720模塊,以及使用Air720進行ppp撥號上網流程

 

    Air720正常啓動後,通過USB連接到linux設備上,驅動正常加載後會產生如下設備:


 

一、修改驅動

   

    首先需要對Linux內核驅動做一定的修改,使操作系統能夠支持Air720

 

    1.Add VID add PID

    File: [KERNEL]/drivers/usb/serial/option.c

static const struct usb_device_id option_ids[] = {
    //+add by airm2m for Air72x
    { USB_DEVICE(0x1286, 0x4e3d) },
     //-add by airm2m for Air72x
   { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD_LIGHT) },   

    

    2. Add the Zero Packet Mechanism   

    ⦁For linux Kernel Version newer than 2.6.34:

     File: [KERNEL]/drivers/usb/serial/usb_wwan.c

static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
                      int endpoint,                                                              
                      int dir, void *ctx, char *buf, int len,
                      void (*callback) (struct urb *))
{
    struct usb_serial *serial = port->serial;
    struct urb *urb;
    urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
    if (!urb)
        return NULL;
    usb_fill_bulk_urb(urb, serial->dev,
              usb_sndbulkpipe(serial->dev, endpoint) | dir,
              buf, len, callback, ctx);
    //+add by airm2m for Air72x
    if(dir == USB_DIR_OUT){
        struct usb_device_descriptor *desc = &serial->dev->descriptor;
        if(desc->idVendor == cpu_to_le16(0x1286) && desc->idProduct == cpu_to_le16(0x4e3d))
        {
            urb->transfer_flags |= URB_ZERO_PACKET;
        }
    }
    //-add by airm2m for Air72x
    return urb;
}

 

    ⦁For linux Kernel Version older than 2.6.35:

    File: [KERNEL]/drivers/usb/serial/option.c

static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
int dir, void *ctx, char *buf, int len,
void (*callback)(struct urb *))
{
......
/* Fill URB using supplied data. */
usb_fill_bulk_urb(urb, serial->dev,
      usb_sndbulkpipe(serial->dev, endpoint) | dir,
      buf, len, callback, ctx);
//+add by airm2m for Air72x
if(dir == USB_DIR_OUT)
{
        struct usb_device_descriptor *desc = &serial->dev->descriptor;
        if(desc->idVendor == cpu_to_le16(0x1286) && desc->idProduct == cpu_to_le16(0x4e3d))
        {
            urb->transfer_flags |= URB_ZERO_PACKET;
        }
}
//-add by airm2m for Air72x
return urb;
}

 

     3. Add Reset Resume

    ⦁For linux Kernel Version newer than 3.4:

       File: [KERNEL]/drivers/usb/serial/option.c

static struct usb_serial_driver option_1port_device = {
    .driver = {                                                                                                  
        .owner =    THIS_MODULE,
        .name =     "option1",
    },   
    ....
#ifdef CONFIG_PM
    .suspend           = usb_wwan_suspend,
    .resume            = usb_wwan_resume,
    //+add by airm2m for Air726
    .reset_resume      = usb_wwan_resume,
    //-add by airm2m for Air726

#endif

};

 

    ⦁For linux Kernel Version older than 3.5:

    File: [kernel]/drivers/usb/serial/usb-serial.c

/* Driver structure we register with the USB core */
static struct usb_driver usb_serial_driver = {
.name ="usbserial",
.probe =usb_serial_probe,
.disconnect =usb_serial_disconnect,
.suspend =usb_serial_suspend,
.resume =usb_serial_resume,
 //+add by airm2m for Air72x
          .reset_resume      = usb_serial_resume,
          //-add by airm2m for Air72x
.no_dynamic_id = 1,
};

 

    4. Modify Kernel Configuration

    Step 1:

    cd <your kernel directory>

    Step 2:

    make menuconfig

    Step 3:Enable CONFIG_USB_SERIAL_OPTION

[*] Device Drivers →
  [*] USB Support →
    [*] USB Serial Converter support →
      [*] USB driver for GSM and CDMA modems

 

attachments-2018-09-UvLI6qjo5b8b7c3fabe04.png

    Step 4:Configure Kernel to Support PPP

[*] Device Drivers →
  [*] Network device support →
    [*] PPP (point-to-point protocol) support

 

attachments-2018-09-0MkDlKPS5b8b7cde500a3.png

 

   5.編譯內核

    make    

    將編譯好的內核下載到開發板。

    

 二、模塊測試

    將重新編譯好的內核下載到開發板之後,待系統重新啓動,如果是帶RNDIS網卡的驅動,在/dev/目錄下會出現如下設備節點:


 

Air726的AT端口是/dev/ttyUSB2,現在你可以使用UART端口工具如“minicom”或“busybox microcom”測試AT功能,結果如下:

attachments-2018-09-VciAwk855b8b81601e624.png

 

 

 

三、PPP撥號

    通過幾個不同的配置文件,在撥號的時候選擇相應的配置文件,現將配置文件列舉如下: 

    /etc/ppp/peers/air720-ppp

# /etc/ppp/peers/air720-pppd                                                                      # Usage:root>pppd call air720-pppd
#Modem path, like /dev/ttyUSB3,/dev/ttyACM0, depend on your module, default path is /dev/ttyUSB3
/dev/ttyUSB3 115200
#Insert the username and password for authentication, default user and password are test
user "" password ""
# The chat script, customize your APN in this file
connect 'chat -s -v -f /etc/ppp/peers/air720-chat-connect'
# The close script
disconnect 'chat -s -v -f /etc/ppp/peers/air720-chat-disconnect'
# Hide password in debug messages
hide-password
# The phone is not required to authenticate
noauth
# Debug info from pppd
debug
# If you want to use the HSDPA link as your gateway
defaultroute
# pppd must not propose any IP address to the peer
noipdefault
# No ppp compression
novj
novjccomp
noccp
ipcp-accept-local
ipcp-accept-remote
local
# For sanity, keep a lock on the serial line
lock
modem
dump
nodetach
# Hardware flow control
nocrtscts
remotename 3gppp
ipparam 3gppp
ipcp-max-failure 10
# Ask the peer for up to 2 DNS server addresses
usepeerdns

 

    /etc/ppp/peers/air720-chat-connect

#/etc/ppp/peers/air720-chat-connect                                                
ABORT "BUSY"
ABORT "NO CARRIER"
ABORT "ERROR"
#ABORT "NO ANSWER"
TIMEOUT 10
"" AT
"OK-+++\c-OK" ATH0
OK ATE0
OK ATI;+CESQ;+CPIN?;+COPS?;+CEREG?;+CGREG?;&D2
#china unicom's apn is 3gnet
#OK AT+CGDCONT=1,"IP","3gnet",,0,0
#OK ATD*99#
#China mobile APN
OK AT+CGDCONT=1,"IP","cmnet"
#OK ATDT*99***1#
OK ATD*99#
CONNECT ""

 

    /etc/ppp/peers/air720-chat-disconnect           

#/etc/ppp/peers/air720-chat-disconnect            
TIMEOUT 5
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
#SAY "\nSending break to the modem\n"
"" "+++\c"
OK "ATH0"
SAY "\nGoodbay\n"

 

    編輯好這幾個文件之後,便可以通過pppd進行撥號:

    # pppd call air720-ppp &

   如果撥號成功會有以下信息打印出來:

attachments-2018-09-IlJCjHPz5b8b8a394bfdf.png

attachments-2018-09-fFu9jAXX5b8b8a7160164.png

此時通過ifconfig命令查看網卡就有一個ppp0網卡出現,這時可以禁用其他網卡,就可以用Air720模塊連接到互聯網了。

attachments-2018-09-GGlDY8xC5b8b8aa468bb5.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章