Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdcecm: early exit on inactive usb interface #12534

Merged

Conversation

bergzand
Copy link
Member

@bergzand bergzand commented Oct 21, 2019

Contribution description

This adds an early exit when the usb interface with the data endpoints
is not activated. This prevents the cdc_ecm_netdev code from attempting
to send the PDU when the USB device is not yet initialized or activated
by a host.

Also prevents an null pointer access when the netdev code happens to initialize before the usbus code.

Testing procedure

  1. Enable DEBUG in sys/usb/usbus/cdc/ecm/cdc_ecm.c.
  2. flash examples/usbus_cdc_ecm on a supported board.
  3. From the RIOT shell: ping6 ff02::1%5
  4. Verify that this and this debug logging from sys/usb/usbus/cdc/ecm/cdc_ecm.c is not triggered.
  5. Attach to a host with support for CDC ECM
  6. repeat the ping and verify that it triggers debug logging.

Issues/PRs references

None, but maybe test this together with #12533

@bergzand bergzand added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: USB Area: Universal Serial Bus labels Oct 21, 2019
@bergzand
Copy link
Member Author

To clarify the test instructions a bit, there is debug logging in cdc_ecm.c to show transmissions (device perspective) to the USB host here and here. With this PR those should not be triggered if the device is booted without USB connected during boot and during step 1..4 of the test.

/* interface with alternative function ID 1 is the interface containing the
* data endpoints, no sense trying to transmit data if it is not active */
if (cdcecm->active_iface != 1) {
return -EBUSY;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is -EBUSY the correct error code here? @miri64 Do you have an opinion on this? What should a _send() call return when the interface is unable to transmit a PDU?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhhh... -EBUSY was introduced in #11264 to signal the device is busy (even though I abandoned that idea for now for at86rf2xx at least). Is that the case here as well? How about -ENXIO (No such device or address)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case here is that either the 'cable' is not connected or the other end of the 'cable' is not configured.

'cable': the point-to-point network data stream over the USB endpoints.

-EBUSY is probably wrong in that case, -ENXIO is a better match, -ENOTCONN could also work and based on a quick look the Linux kernel also seems to use it for the USB gadget framework.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced -EBUSY with -ENOTCONN

@dylad dylad added this to the Release 2020.01 milestone Oct 22, 2019
@dylad dylad added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines labels Oct 22, 2019
Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided testing procedure is OK
Changes look good.
Please squash !

This adds an early exit when the usb interface with the data endpoints
is not activated. This prevents the cdc_ecm_netdev code from attempting
to send the PDU when the USB device is not yet initialized or activated
by a host.
@bergzand bergzand force-pushed the pr/usbus/cdcecm_early_exit_on_inactive branch from dc0e52e to 4574557 Compare October 23, 2019 07:41
@bergzand
Copy link
Member Author

Squashed!

@dylad
Copy link
Member

dylad commented Oct 23, 2019

Here we go !

@dylad dylad merged commit 0bbb114 into RIOT-OS:master Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: USB Area: Universal Serial Bus CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants