Android 系统使RNDIS网卡上网
背景说明:
一位台湾客户需要采购一批SIMCOM SIM6600CE模组用于Tinker board2s,需要适配Debain系统和Android系统。
主要修改点:
1、defconfig 增加RNDIS HOST驱动
2、在option.c中屏蔽interface 0、1两个cdc接口
3、修改usbnet.c,使rndis网卡的名称从usb0变成eth0。因为Android默认只挂载eth网卡,所以为了提高Android系统兼容性并减少修改难度,直接在驱动层入手。
diff --git a/arch/arm64/configs/tinker_board_2_defconfig b/arch/arm64/configs/tinker_board_2_defconfig index 5e0f2a8..ddd4a07 100755 --- a/arch/arm64/configs/tinker_board_2_defconfig +++ b/arch/arm64/configs/tinker_board_2_defconfig @@ -794,7 +794,7 @@ CONFIG_USB_GADGET_VBUS_DRAW=500 CONFIG_USB_CONFIGFS=y CONFIG_USB_CONFIGFS_UEVENT=y CONFIG_USB_CONFIGFS_ACM=y -CONFIG_USB_CONFIGFS_RNDIS=y +# CONFIG_USB_CONFIGFS_RNDIS=y CONFIG_USB_CONFIGFS_MASS_STORAGE=y CONFIG_USB_CONFIGFS_F_FS=y CONFIG_USB_CONFIGFS_F_ACC=y @@ -949,6 +949,7 @@ CONFIG_CRYPTO_DEV_ROCKCHIP=y CONFIG_PRINTK_TIME=y CONFIG_DEBUG_INFO=y CONFIG_DEBUG_FS=y +CONFIG_DYNAMIC_DEBUG=y CONFIG_MAGIC_SYSRQ=y CONFIG_SOFTLOCKUP_DETECTOR=y CONFIG_DEFAULT_HUNG_TASK_TIMEOUT=10 diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c index d3f79a4..3edb1fe 100644 --- a/drivers/net/usb/rndis_host.c +++ b/drivers/net/usb/rndis_host.c @@ -15,6 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#define DEBUG // error path messages, extra info +#define VERBOSE // more; success messages + #include <linux/module.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index adab6e2..8bf5de2 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -1771,6 +1771,10 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) if ((dev->driver_info->flags & FLAG_NOARP) != 0) net->flags |= IFF_NOARP; + if (strncmp("RNDIS device", dev->driver_info->description, + sizeof("RNDIS device") - 1) == 0) + strcpy(net->name, "eth%d"); + /* maybe the remote can't receive an Ethernet MTU */ if (net->mtu > (dev->hard_mtu - net->hard_header_len)) net->mtu = dev->hard_mtu - net->hard_header_len; diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 3a66f1e..25175c0 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c @@ -526,6 +526,7 @@ static void option_instat_callback(struct urb *urb); #define MEDIATEK_PRODUCT_FP_2COM 0x0023 #define MEDIATEK_PRODUCT_FPDC_1COM 0x0043 #define MEDIATEK_PRODUCT_FPDC_2COM 0x0033 +#define MEDIATEK_PRODUCT_SIM6600 0x2010 /* Cellient products */ #define CELLIENT_VENDOR_ID 0x2692 @@ -2001,6 +2002,8 @@ static const struct usb_device_id option_ids[] = { { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_7106_2COM, 0x02, 0x02, 0x01) }, { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_DC_4COM2, 0xff, 0x02, 0x01) }, { USB_DEVICE_AND_INTERFACE_INFO(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_DC_4COM2, 0xff, 0x00, 0x00) }, + { USB_DEVICE(MEDIATEK_VENDOR_ID, MEDIATEK_PRODUCT_SIM6600), + .driver_info = RSVD(0) | RSVD(1) }, { USB_DEVICE(CELLIENT_VENDOR_ID, CELLIENT_PRODUCT_MEN200) }, { USB_DEVICE(CELLIENT_VENDOR_ID, CELLIENT_PRODUCT_MPL200), .driver_info = RSVD(1) | RSVD(4) },
USB连接SIM6600CE后,使用ifconfig命令出现了eth1,此时可以发现Android系统已经自动给eth1分配了ip,系统状态栏出现以太网图标。注意,如果在framework层修改默认挂载网卡位usb0也可以解决上网问题,但是eth网卡就不能上网了,这会对开发板自带的以太网网卡以及后续可能会挂载的usb网卡造成影响。