Bug 254345 - cdce erroneously attaches to a combined RNDIS/CDCE Ethernet gadget
Summary: cdce erroneously attaches to a combined RNDIS/CDCE Ethernet gadget
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Hans Petter Selasky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-16 19:12 UTC by Martin Birgmeier
Modified: 2021-05-10 14:33 UTC (History)
3 users (show)

See Also:


Attachments
files mentioned in the bug report (2.67 KB, application/gzip)
2021-03-16 19:12 UTC, Martin Birgmeier
no flags Details
part of devd.log showing RNDIS gadget attach and detach (8.12 KB, text/plain)
2021-03-16 19:20 UTC, Martin Birgmeier
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Birgmeier 2021-03-16 19:12:57 UTC
Created attachment 223335 [details]
files mentioned in the bug report

Scenario:
- Raspberry Pi B+
- FreeBSD main at 51dfae383bf6298af9e6d816a78b92b6f34d68be
- (Physically) attaching a combined RNDIS/CDCE Ethernet gadget: configuration 0 supports RNDIS, configuration 1 supports CDCE (see the attached output of "usbconfig dump_all_desc"
- The current configuration is 0, see the attached output of "usbconfig dump_curr_config_desc"
- devd with a default configuration plus a special configuration for a Huawei 4G modem is running; the special configuration matches this device (although it really should not, but this is not the point of this PR); the special devd configuration file is attached ("e3372.conf")

Result:
- Two ue interfaces are created, one attached to interface 0 of the RNDIS device, the other to interface 1; see the attached output of "devinfo -rv"

Expected result:
- Since configuration 0 is active, only one network interface for the RNDIS device should be created; this network interface must make use of the two USB interfaces (0, 1, see above) of USB configuration 0 of the device, see https://docs.microsoft.com/de-at/windows-hardware/drivers/network/overview
- The CDCE driver should not attach at all to this device as long as it is in USB configuration 0.

Notes:
- I am not an expert here so my analysis may be wrong. :-)
- It is important not to mix the notions of "USB interface" and "network interface" when checking this PR.
- There is a major issue with devd and the ue USB Ethernet interfaces because the available information does not allow devd to determine which device it is really dealing with. In this case, with e3372.conf a DHCP client is started on all ue devices; but this is useless for the Ethernet gadget of this PR because that needs to have a fixed IP address assigned which is impossible to achieve with devd rules as long as the real E3372 offers a DHCP service.
- FreeBSD needs a way to distinguish interfaces by some hardware ID; most likely the best way would be to create the device as ue-<HW Ethernet address>. But this is not the main issue of this bug report; this bug report is about CDCE erroneously attaching to the data interface of a USB RNDIS device.

-- Martin
Comment 1 Martin Birgmeier 2021-03-16 19:15:45 UTC
Some additional info:

- On attach, devd loads both the if_urndis and the if_cdce drivers. This is also strange given that only configuration 0 (RNDIS) should be active.
- When attached, it is possible to use the ue interface attached to if_urndis, but not the one attached to if_cdce.

-- Martin
Comment 2 Martin Birgmeier 2021-03-16 19:20:23 UTC
Created attachment 223338 [details]
part of devd.log showing RNDIS gadget attach and detach

For additional info attached is a part of /var/log/devd.log showing the actions taken when attaching and (5 minutes later) detaching the device.

-- Martin
Comment 3 Hans Petter Selasky freebsd_committer 2021-03-16 19:30:13 UTC
Hi,

It is because of these values that CDCE attaches:

  idVendor = 0x0525 
  idProduct = 0xa4a2 

I think the vendor forgot to patch/update those values.

Probably we can revert this patch from 2005:

https://svnweb.freebsd.org/base/head/sys/dev/usb/if_cdce.c?r1=150700&r2=150701&pathrev=171005&

-_HPS
Comment 4 Hans Petter Selasky freebsd_committer 2021-03-30 13:55:49 UTC
Ping - any updates?

--HPS
Comment 5 Martin Birgmeier 2021-03-30 14:27:27 UTC
By whom - given the "we" in comment #3 and the assignee being "freebsd-usb (Nobody)"? ;-)

-- Martin
Comment 6 Hans Petter Selasky freebsd_committer 2021-03-30 14:29:16 UTC
Did you try to revert the mentioned patch?

--HPS
Comment 7 Martin Birgmeier 2021-03-30 15:09:54 UTC
After deleting this line cdce.ko does not attach to the device anymore. RNDIS still attaches and works o.k.

-- Martin
Comment 8 Hans Petter Selasky freebsd_committer 2021-04-14 14:24:55 UTC
OK, I'll try to get the patch upstreamed.

--HPS
Comment 9 commit-hook freebsd_committer 2021-04-22 10:27:33 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d2c87140648f61a6f139a2ecdf831e6a08cc4de2

commit d2c87140648f61a6f139a2ecdf831e6a08cc4de2
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-04-22 10:22:39 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-04-22 10:23:36 +0000

    Remove USB device ID added by SVN r150701 in the CDC USB ethernet driver.
    Since then, the FreeBSD USB stack has got proper USB RNDIS support.

    PR:             254345
    MFC after:      1 week
    Sponsored by:   Mellanox Technologies // NVIDIA Networking

 sys/dev/usb/net/if_cdce.c | 1 -
 1 file changed, 1 deletion(-)
Comment 10 commit-hook freebsd_committer 2021-05-10 14:33:04 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0d1e6e9413e9913c296d829d2712a07f816e3ce0

commit 0d1e6e9413e9913c296d829d2712a07f816e3ce0
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-04-22 10:22:39 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-05-10 14:11:19 +0000

    Remove USB device ID added by SVN r150701 in the CDC USB ethernet driver.
    Since then, the FreeBSD USB stack has got proper USB RNDIS support.

    PR:             254345
    Sponsored by:   Mellanox Technologies // NVIDIA Networking

    (cherry picked from commit d2c87140648f61a6f139a2ecdf831e6a08cc4de2)

 sys/dev/usb/net/if_cdce.c | 1 -
 1 file changed, 1 deletion(-)