简体   繁体   English

USB Android 设备上的 Ethe.net

[英]USB Ethernet on Android devices

I have an embedded Linux system that uses the USB Gadget framework to appear as an Ethe.net class device (ACM Ethe.net, using the g_ether kernel driver.) All is well using this with an Ubuntu system to connect to the device.我有一个嵌入式 Linux 系统,它使用 USB Gadget 框架显示为 Ethe.net class 设备(ACM Ethe.net,使用 g_ether kernel 驱动程序。)使用 Ubuntu 系统连接到设备时一切正常。 I can either get the device to issue DHCP leases to the Ubuntu system or set up a static IP configuration in Ubuntu and on the embedded system, and.network traffic passes just fine.我可以让设备向 Ubuntu 系统发出 DHCP 租约,或者在 Ubuntu 和嵌入式系统上设置 static IP 配置,并且网络流量通过得很好。 On the Ubuntu system this appears as a usb0 .network interface (regular Ethe.net ports appearing as eth0 , etc.)在 Ubuntu 系统上,这显示为usb0 .network 接口(常规 Ethe.net 端口显示为eth0等)

Now, I want this to work with an Android device.现在,我希望它能与 Android 设备一起使用。 Specifically, a Samsung Galaxy S20 and a Galaxy Tab A, but wide support for other devices would be good too.具体来说,三星 Galaxy S20 和 Galaxy Tab A,但对其他设备的广泛支持也很好。

We already have an application working with this phone and tablet which uses a USB Serial Gadget to communicate with the embedded system.我们已经有一个与这款手机和平板电脑配合使用的应用程序,它使用 USB 串行小工具与嵌入式系统进行通信。

I note that when I connect a USB Ethe.net dongle to the Android tablet, I can actually access the inte.net through this device, once the setting is enabled in the "More connection settings" page.我注意到,当我将 USB Ethe.net 加密狗连接到 Android 平板电脑时,一旦在“更多连接设置”页面中启用该设置,我实际上可以通过此设备访问 inte.net。

However, if we connect our gadget USB device to the Android tablet, the option to enable Ethe.net remains disabled.但是,如果我们将我们的小工具 USB 设备连接到 Android 平板电脑,启用 Ethe.net 的选项将保持禁用状态。

My suspicion is that this is because Android is either filtering by VID/PID (a whitelist of devices?), or it only enables this option if it detects an eth0 device.我怀疑这是因为 Android 要么通过 VID/PID(设备白名单?)进行过滤,要么仅在检测到eth0设备时才启用此选项。

So my question is two fold:所以我的问题有两个:

  • Is it possible, without rooting or modifying stock Android, to make a usb0 device accessible from the user-accessible.network settings page?是否可以在不生根或修改 stock Android 的情况下,使usb0设备可从 user-accessible.network 设置页面访问?

  • Failing that, what are the conditions for Android/Linux in distinguishing between usb0 and eth0 as names for devices?如果做不到这一点,Android/Linux 区分usb0eth0作为设备名称的条件是什么? (Assuming Android is not using a whitelist to further filter acceptable devices: I can find no confirmation or denial of this.) I have quite a lot of control over how the Gadget advertises itself, for instance I can add descriptors, change IDs, version numbers and so on. (假设 Android 没有使用白名单来进一步过滤可接受的设备:我找不到对此的确认或拒绝。)我对 Gadget 如何宣传自己有很多控制权,例如我可以添加描述符、更改 ID、版本数字等等。 What does not work is simply changing the VID/PID to emulate an existing chipset eg RTL8153.不起作用的是简单地更改 VID/PID 以模拟现有的芯片组,例如 RTL8153。 Linux does in fact recognise the device as an x8153 if I do this, however it still remains as usb0 .如果我这样做,Linux 实际上会将设备识别为 x8153,但它仍然是usb0 It breaks usb0 too;它也破坏了usb0 whilst it enumerates correctly and will accept a.netmask and address, no.network traffic passes.虽然它正确枚举并接受网络掩码和地址,但没有网络流量通过。 I would guess that the RTL8153 and similar drivers want to write register maps that definitely do not exist on the Gadget and so end up endlessly waiting for something to happen.我猜想 RTL8153 和类似的驱动程序想要编写 Gadget 上绝对不存在的寄存器映射,因此最终会无休止地等待某些事情发生。 Even if it did not break things, it would be a horrid, non-USB-compliant way to do things, so it is not the way I want to go.即使它没有破坏东西,它也会是一种可怕的、不符合 USB 标准的做事方式,所以这不是我想要的方式 go。

I have a bit of data: Another product we are aware of does, in fact, require an application which uses a rooted device and su to configure the Linux routing table manually to achieve USB Ethe.net.我有一点数据:我们知道的另一个产品实际上需要一个使用 root 设备和su的应用程序来手动配置 Linux 路由表以实现 USB Ethe.net。 We are trying to avoid the need to do this, but it does seem that may not be possible.我们正在努力避免这样做的必要性,但看起来确实不可能。 Alarmingly, this product has a secure usage profile, so it seems a bit at odds with needing to root the phone.令人担忧的是,该产品具有安全的使用配置文件,因此它似乎与需要对手机进行 root 操作有些矛盾。

I have tried, incidentally, this with an RNDIS gadget driver (Linux supports both) and the behaviour is identical.顺便说一句,我已经尝试过使用 RNDIS 小工具驱动程序(Linux 支持两者)并且行为是相同的。

The problem is solved.问题已经解决了。 It is all down to the MAC address that the USB Gadget advertises.这完全取决于 USB 小工具公布的 MAC 地址。 You need to advertise a universal address (U/L bit is clear) for the udev rules in Linux (on the Android side) to associate an eth0 device instead of usb0 .您需要为 Linux(在 Android 端)中的 udev 规则通告一个通用地址(U/L 位是明确的)以关联eth0设备而不是usb0 Once this is done, Android will connect to the device as normal from the settings page, even if it is a composite USB device.完成此操作后,Android 将从设置页面正常连接到设备,即使它是复合 USB 设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM