Ubuntu16.04 系统加载 Air720H 全网通4G模块上网

Ubuntu16.04 系统加载 Air720H 全网通4G模块上网

一、编译系统内核

对Linux内核驱动修改,让操作系统支持Air720

Air720模块Linux USB驱动

在Ubuntu16.04系统下,如何修改usb驱动支持合宙 Air720模块

Air720正常启动后,通过USB连接到linux设备上,驱动正常加载后会产生如下设备:

1.查看当前系统原码版本

$ apt-cache search linux-source
linux-source – Linux kernel source with Ubuntu patches
linux-source-5.3 – Linux kernel source for version 5.3 with Ubuntu patches

2.下载源码
$ sudo apt-get install linux-source-5.3

sudo apt-get install libncurses5-dev

 sudo apt-get install bison
sudo apt-get install flex

sudo apt-get install libssl-dev

下载完成后,在/usr/src目录中,可以看到压缩包
$ ls
linux-headers-2.6.35-22 linux-source-5.3
linux-headers-2.6.35-22-generic linux-source-5.3.tar.bz2

3.编译
$ sudo tar -xjvf linux-source-5.3.tar.bz2

sudo make mrproper

sudo make clean

$ sudo make menuconfig

    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 Air720
.reset_resume      = usb_wwan_resume,
//-add by airm2m for Air720

#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 -j4

sudo make modules_install

sudo make install

sudo mkinitramfs o /boot/initrd.img-5.3.18

sudo updateinitramfs c k 5.3.18

sudo updategrub

sudo shutdown r now

uname a

lsusb

Bus 001 Device 009: ID 1286:4e3d Marvell Semiconductor, Inc.

 6.模块测试

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

 

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

 

 

 

 

 

  • 让04 系统支持RNDIS网络

增加rndis设备驱动(配置内核)

对于较老版本或者嵌入式设备默认可能关闭了RNDIS驱动,我们以linux-3.13为例,描述如何打开linux自带的RNDIS驱动:

step 1:

    1. cd <your kernel directory>

step 2:

    1. make menuconfig

step 3: ENALBE USB_NET_RNDIS_HOST

make

将编译好的内核重新下载到设备

  • 配置终端

(硬件环境:pi3B+)

双网卡基本情况如下:

Eth0网卡 ->负责内网: ip 192.168.24.26 netmask 255.255.255.0 gateway: 192.168.24.1

Eth1(rdnis)网卡 ->负责外网: ip 192.168.0.100 netmask 255.255.255.0 gateway:192.168.0.1

配置双网卡

=========================begin\|/================================

开始配置双网卡:

1.修改 /etc/network/interfaces文件,只能设置一个系统默认的网关.本人将eno2外网的网关设为默认网关,

这个文件中双网卡只能设置一个默认网关(本例为eth1外网),另外一个(内网eth0内网)需要通过命令添加.

auto lo
iface lo inet loopback

#local负责内网
auto eth0
iface eth0 inet static
address 192.168.24.26
netmask 255.255.255.0

#out net负责外网
auto eth1
iface eno2 inet static
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1 #设置的默认网关为外网eth1

dns-nameservers 211.140.13.188 #根据需要配置(这里是移动4G )
up route add -net 192.168.24.0/24  gw 192.168.24.1 dev eth0 #通过手动命令设置eth0内网的网关//含义是 只要是192.168.24.0网段的包,都经过eth0网卡,发送给网关192.168.24.1, 24表示掩码是255.255.255.0//

# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init’s
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
addresses: [192.168.24.28/24]
# dhcp4: false
# gateway4: 192.168.24.1
# nameservers:
# addresses: [60.191.244.5]
optional: true
eth1:
dhcp4: false
addresses: [192.168.0.100/24]
gateway4: 192.168.24.1
nameservers:
addresses: [60.191.244.5]
optional: true
version: 2

具体格式参照镜像系统网络配制文件

2.重启网卡服务,如不行则重启系统!

重启网卡服务命令:1. sudo service networking restart 或者 sudo /etc/init.d/networking restart

重启系统命令:1. sudo shutdown -r now 或者 sudo reboot

3.修改完毕.进行测试.命令行终端: