1、内核menuconfig添加如下配置项
Kernel modules
-->USB Support
--> kmod-usb-net
--> kmod-usb-net-cdc-ether
--> kmod-usb-serial
--> kmod-usb-serial-option
2、修改驱动代码
drivers\usb\serial\option.c
在option_ids列表中添加me909s-821模块,这样驱动就自动probe到 ttyUSB0 ~ ttyUSB4 设备
/*add HUAWEI ME909S-821*/
{ USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, 0x02, 0x06, 0x10) },
{ USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, 0x0a, 0x06, 0x11) },
{ USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, 0xff, 0x06, 0x10) },
{ USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, 0xff, 0x06, 0x13) },
{ USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, 0xff, 0x06, 0x12) },
{ USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, 0xff, 0x06, 0x06) },
{ USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, 0xff, 0x06, 0x1b) },
\drivers\net\usb\cdc_ether.c
看了代码,由于在products列表中WHITELIST就可以匹配到此模块,因此无需修改也可以probe到设备,如果probe成功,就会生成一个usb0的网络设备,通过ifconfig usb0可以查看此设备;如果ifconfig看不到usb0,那就是没有probe到,就在products列表中按照BLACKLIST添加此模块的product ID和vendor ID即可。
3、拨号脚本
在驱动正常加载,并且生成了usb0以后,就可以在/etc/init.d/目录下添加拨号脚本了。与pppd进程拨号不一样,使用ndis上网,可以使4G有更高的速率,其实也就是把4G模块虚拟成一个网卡,就是上面驱动已经probe到的usb0。
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
START=99
STOP=98
start() {
# commands to launch application
if [ -f /sys/devices/platform/rt3xxx-ehci/usb1/1-1/1-1.2/idProduct ]; then
idProduct=`sed -n 1p /sys/devices/platform/rt3xxx-ehci/usb1/1-1/1-1.2/idProduct`
idVendor=`sed -n 1p /sys/devices/platform/rt3xxx-ehci/usb1/1-1/1-1.2/idVendor`
if [ $? -eq 0 -a -n "$idProduct" -a "$idProduct" == "15c1" -a -n "$idVendor" -a "$idVendor" == "12d1" ]; then
ifup 4g
sleep 1
echo -en "AT^SYSCFGEX=\"030201\",3FFFFFFF,0,2,7FFFFFFFFFFFFFFF,,\r\n" > /dev/ttyUSB2
sleep 1
echo -en "AT+CGDCONT=1,\"IPV4V6\",\"\"\r\n" > /dev/ttyUSB2
sleep 1
echo -en 'AT^NDISDUP=1,1\r\n' > /dev/ttyUSB2
fi
fi
}
stop() {
if [ -f /sys/devices/platform/rt3xxx-ehci/usb1/1-1/1-1.2/idProduct ]; then
idProduct=`sed -n 1p /sys/devices/platform/rt3xxx-ehci/usb1/1-1/1-1.2/idProduct`
idVendor=`sed -n 1p /sys/devices/platform/rt3xxx-ehci/usb1/1-1/1-1.2/idVendor`
if [ $? -eq 0 -a -n "$idProduct" -a "$idProduct" == "15c1" -a -n "$idVendor" -a "$idVendor" == "12d1" ]; then
echo -en 'AT^NDISDUP=1,0\r\n' > /dev/ttyUSB2
sleep 1
ifdown 4g
fi
fi
}
执行拨号以后脚本以后,执行udhcpc -i usb0,ifconfig usb0就可以看到已经获取到IP:
usb0 Link encap:Ethernet HWaddr 02:1E:10:1F:00:00
inet addr:170.0.18.173 Bcast:170.0.18.175 Mask:255.255.255.252
inet6 addr: fe80::1e:10ff:fe1f:0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:682 (682.0 B) TX bytes:2513 (2.4 KiB)
然后就可以通过usb0上网了