前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >安卓系统如何添加USB网络共享功能

安卓系统如何添加USB网络共享功能

原创
作者头像
kaicer
发布2023-07-01 11:46:05
1.1K0
发布2023-07-01 11:46:05
举报
文章被收录于专栏:软件技术交流

有些客户需求添加USB网络共享功能,安卓本身是支持USB网络共享的,但需要我们配置才有。目前USB网络共享功能主要用于将车机网络共享给手机或平板使用,手机平板使用的操作系统一般也是安卓或者IOS,那我们需要添加两种配置。安卓系统USB网络共享需要驱动支持rndis host,而苹果USB网络共享需要驱动支持ipheth,可以分如下步骤添加USB网络共享功能:

1,驱动支持USB网络共享

在linux内核配置中增加CONFIG_USB_NET_RNDIS_HOST=m和CONFIG_USB_IPHETH=m两个定义编译出rndis_host.ko和ipheth.ko两个驱动文件

2,设置中增加网络共享开关,init.rc中增加是否启动USB网络共享如下:

#add for usb net

on property:persist.tw.ipheth=0

stop usbnet

exec /system/bin/rmmod ipheth

exec /system/bin/rmmod rndis_host

on property:persist.tw.ipheth=1

insmod /vendor/modules/ipheth.ko

insmod /vendor/modules/rndis_host.ko

start usbnet

service usbnet /system/bin/usbmuxd

disabled

seclabel u:r:shell:s0

在设置中打开USB网络共享则可以设置属性property:persist.tw.ipheth为1,关闭USB网络共享则将属性设置为0,打开网络共享时分别加载rndis_host.ko和ipheth.ko两个驱动,关闭时卸载驱动

需要注意的时苹果手机USB网络共享需要执行usbmuxd,这个服务主要用于在USB协议上实现TCP连接,将USB通信转化为TCP通信,这个服务执行需要依赖一些库,从网上下载usbmuxd包编译成so库放到system/lib下,分别打包如下库:

libimobiledevice.so

libinternalcommon_imobile.so

libinternalcommon.so

libusbmuxd.so

libplist++.so

libcnary.so

libplist.so

3,有些苹果的IOS版本会连不上USB网络共享,需要将ipheth.ko驱动中的IPHETH_BUF_SIZE 修改一下,如下

#define IPHETH_BUF_SIZE 1514//1516

4,有些安卓手机会连不上USB网络共享,需要在cdc_ether.c中添加如下:

rndis = (is_rndis(&intf->cur_altsetting->desc) ||

is_activesync(&intf->cur_altsetting->desc) ||

is_wireless_rndis(&intf->cur_altsetting->desc) ||

is_novatel_rndis(&intf->cur_altsetting->desc));

#define is_novatel_rndis(desc) 0

static int is_novatel_rndis(struct usb_interface_descriptor *desc)

{

return (desc->bInterfaceClass == USB_CLASS_MISC &&

desc->bInterfaceSubClass == 4 &&

desc->bInterfaceProtocol == 1);

}

在rndis_host.c中添加如下:

}, {

/* Novatel Verizon USB730L */

USB_INTERFACE_INFO(USB_CLASS_MISC, 4, 1),

.driver_info = (unsigned long) &rndis_info,

},

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档