Skip to content

usb: device_next: usbd_cdc_ncm: correct net_if_carrier use#104379

Open
maass-hamburg wants to merge 1 commit intozephyrproject-rtos:mainfrom
maass-hamburg:usb--device_next--usbd_cdc_ncm--correct-net_if_carrier-use
Open

usb: device_next: usbd_cdc_ncm: correct net_if_carrier use#104379
maass-hamburg wants to merge 1 commit intozephyrproject-rtos:mainfrom
maass-hamburg:usb--device_next--usbd_cdc_ncm--correct-net_if_carrier-use

Conversation

@maass-hamburg
Copy link
Copy Markdown
Member

net_if_carrier is to be used independently of the
administrative state (start and stop of the ethernet_api).

This way we are able to detect a "reconnect" of the USB cable, unfortunatly we can't detect a disconnection on it's own, but we can detect a reconnection and thus trigger the carrier state change. And therefore we can trigger the DHCP client to get a new IP address.

Split from #100809

net_if_carrier is to be used independently of the
administrative state (start and stop of the ethernet_api).

This way we are able to detect a "reconnect" of the USB cable,
unfortunatly we can't detect a disconnection on it's own, but we
can detect a reconnection and thus trigger the carrier state change.
And therefore we can trigger the DHCP client to get a new IP address.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
@sonarqubecloud
Copy link
Copy Markdown

@maass-hamburg maass-hamburg marked this pull request as ready for review February 23, 2026 08:43
@zephyrbot zephyrbot added the area: USB Universal Serial Bus label Feb 23, 2026
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions Bot added the Stale label Apr 26, 2026
Copy link
Copy Markdown
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

I'm not super familiar with CDC NCM.

I just had a few questions to make sure things are as intended.

AFAIU, this PR gives the final decision of making the interface up or down to the host, rather than to the application.

Or maybe one step further than this: after this change, an interface is up when both Zephyr and the host enabled it?

Thank you for the changes.

Comment on lines 637 to +638
LOG_INF("Connection status sent");
net_if_carrier_on(data->iface);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The log says "sent", should net_if_carrier_on() be placed before?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should there also be a atomic_set_bit(&data->state, CDC_NCM_IFACE_UP); like cdc_ncm_iface_start() is doing?


static void usbd_cdc_ncm_enable(struct usbd_class_data *const c_data)
{
LOG_INF("Enabled %s", c_data->name);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should there be a matching net_if_carrier_on()?

I think not needed: it up to the host to re-enable it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: USB Universal Serial Bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants