Air720系列4G模块Linux USB驱动以及PPP拨号说明

秦鹏 合宙Luat 昨天



本文介绍了在Linux系统下,如何修改USB驱动支持合宙 Air720模块,以及使用Air720进行PPP拨号上网流程。


Air720正常启动后,通过USB连接到Linux设备上,驱动正常加载后会产生如下设备(请点击放大查看):


以下代码相关内容建议横屏查看,或在PC端打开本文链接。






   一、修改驱动   

   
首先需要对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

Step 4:Configure Kernel to Support PPP

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

5.编译内核

  make    

将编译好的内核下载到开发板。

    



   二、模块测试   


将重新编译好的内核下载到开发板之后,待系统重新启动,如果是带RNDIS网卡的驱动,在/dev/目录下会出现如下设备节点:

Air726的AT端口是/dev/ttyUSB2,现在你可以使用UART端口工具如“minicom”或“busybox microcom”测试AT功能,结果如下:




   三、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>/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>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 &

如果拨号成功会有以下信息打印出来:

此时通过ifconfig命令查看网卡就有一个ppp0网卡出现,这时可以禁用其他网卡,就可以用Air720模块连接到互联网了。


以上就是Linux系统下修改USB驱动以及使用Air720进行PPP拨号上网的详细流程,如有相关问题不清楚的,欢迎留言交流~


为感谢大家对合宙Luat的关注与支持,合宙商城活动持续进行中,多样福利等你来领取,点击本公众号菜单“合宙商城”或识别下图二维码即可直达商城:





更多福利,敬请期待



Luat相关教程文章:
Luat系列官方教程1:下载调试工具LuaTools的使用指南
Luat系列官方教程2:控制LED小灯

Luat系列官方教程3:Luat程序的基本时序

Luat系列官方教程4:学会使用并看懂Luatools的trace信息

Luat系列官方教程5:Socket代码详解
Luat系列官方教程6:MQTT代码详解



Luat小企业系列原创文章:

小企业怎么寻找生意的蓝海?

小企业2B新产品怎样定价?

小企业的2B业务怎么获客(一)?

合宙Luat将陆续推出小企业系列原创作品,敬请关注!




 ▼
Luat热文推荐

>小企业怎么寻找生意的蓝海?

>NB-IoT,未来的物联网脊梁,还是扶不起的阿斗?

>2019年最值得工作和落户的几个城市,有你的家乡吗?

>为什么说『 物联网通信模块业务』没有前途?

>4G模块价格进入2位数时代,合宙Air720模块正式量产发货


>NB向左,GPRS向右,谁会率先突破百亿连接数?

>GPRS模块为什么会低至十几元?我所经历的物联网模块国产化过程

    已同步到看一看