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

Implement setInterface(alt) for usb net driver #345

Merged
merged 7 commits into from
Apr 16, 2020
Merged

Implement setInterface(alt) for usb net driver #345

merged 7 commits into from
Apr 16, 2020

Conversation

hathach
Copy link
Owner

@hathach hathach commented Apr 15, 2020

  • mostly forward these request (recipient = interface) to class driver.
  • also slightly update the lwip example descriptor

follow up to #342 and #344 (merging these first make bisecting easier)
related to #320 #317

@hathach hathach requested review from majbthrd and pigrew April 15, 2020 11:10
@pigrew
Copy link
Collaborator

pigrew commented Apr 15, 2020

I believe that GET_INTERFACE must be always implemented?

I think that either it needs to be handled in usbd (as in #317 and #320), or a handler must be added to all classes' control request callback

// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{
return (0 == index) ? main_configuration : alt_configuration;
return configuration_arr[index];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should there be bound checking? The advantage of the old approach was a valid pointer configuration descriptor would always be returned.

Copy link
Owner Author

Choose a reason for hiding this comment

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

yeah right, I am too focused on the usbd. Just fixed it in the new commit. Also slightly changed the CONFIG_NUM to CONFIG_ID. Let's me know if you want to keep the NUM convention more.

also add configuration array bound check.
don't return false with STD request get/setInterface() or targeted Data
Interface (itfnum +1)
@hathach
Copy link
Owner Author

hathach commented Apr 15, 2020

I believe that GET_INTERFACE must be always implemented?

I think that either it needs to be handled in usbd (as in #317 and #320), or a handler must be added to all classes' control request callback

Yeah, you are right, macOS does sometime send out that request. I think it will just send that request toward CDC class. Just fixed in the new commit.

Copy link
Collaborator

@majbthrd majbthrd left a comment

Choose a reason for hiding this comment

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

The revised tud_descriptor_configuration_cb() in examples/device/net_lwip_webserver/src/usb_descriptors.c causes me some heartburn, but it isn't that big a deal.

One of the tests I did was to hack up usbd.c to support multiple configurations and use a DCD API that can reset non-control endpoints. That allows repeatedly switching between RNDIS and ECM, which is a good way to torture test operation.

Thanks, @hathach!

@hathach
Copy link
Owner Author

hathach commented Apr 15, 2020

The revised tud_descriptor_configuration_cb() in examples/device/net_lwip_webserver/src/usb_descriptors.c causes me some heartburn, but it isn't that big a deal.

Why is that, I am open to all suggestion.

One of the tests I did was to hack up usbd.c to support multiple configurations and use a DCD API that can reset non-control endpoints. That allows repeatedly switching between RNDIS and ECM, which is a good way to torture test operation.

Thanks, @hathach!

Yeah, dynamic switching configuration require an close all endpoints. We will get there with dcd_edpt_close(), but I am not rush to do that. Since we solve all the problems for usb-net (multiple configuration + setInterface()). Although we don't close the Data's endpoints. Host won't actually try to read/write to those endpoints anyway (since we trick it to think so :D ) . So it is rather safe in this class driver.

When adding Audio or UVC (video) class driver, a proper edpt_close is needed, hopefully this buys us enough of time.

PS: btw, please review other pr as well. I try to break this into 3 PRs for easy reviewing (hopefully).

@majbthrd
Copy link
Collaborator

The revised tud_descriptor_configuration_cb() in examples/device/net_lwip_webserver/src/usb_descriptors.c causes me some heartburn, but it isn't that big a deal.

Why is that, I am open to all suggestion.

Sorry, I was referring to the older implementation without bounds-checking. I submitted the review about the same time you pushed the latest commits.

@hathach
Copy link
Owner Author

hathach commented Apr 15, 2020

The revised tud_descriptor_configuration_cb() in examples/device/net_lwip_webserver/src/usb_descriptors.c causes me some heartburn, but it isn't that big a deal.

Why is that, I am open to all suggestion.

Sorry, I was referring to the older implementation without bounds-checking. I submitted the review about the same time you pushed the latest commits.

yeah, It is hard to get that though :D since host won't attempt to set an invalid config number. But right, better to be safe.

@pigrew
Copy link
Collaborator

pigrew commented Apr 15, 2020

@hathach,

I'm finding it hard to go through all these changes at once.

Could you change this PR to be against the 'enhance-itf-assoc' branch or merge 'class-driver-id' so it's more clear exactly what this PR is?

I'm trying to go through the PR in order of application to 'master' right now.

@hathach
Copy link
Owner Author

hathach commented Apr 15, 2020

@hathach,

I'm finding it hard to go through all these changes at once.

Could you change this PR to be against the 'enhance-itf-assoc' branch or merge 'class-driver-id' so it's more clear exactly what this PR is?

I'm trying to go through the PR in order of application to 'master' right now.

Yeah, it is a bit confusing, Basically they share same commit path, I made an PR #342 then branch from that to make PR #344 then make a branch and to this PR. I those PR is merged in order, it will make it easier to follow.

@hathach hathach changed the base branch from master to enhance-itf-assoc April 15, 2020 17:19
@hathach hathach changed the base branch from enhance-itf-assoc to master April 15, 2020 17:19
@hathach
Copy link
Owner Author

hathach commented Apr 15, 2020

gh tips: change target base to another, then back to master to get file changes updated :D

Copy link
Collaborator

@pigrew pigrew left a comment

Choose a reason for hiding this comment

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

I read the code (but have not tested it). In general, it's an improvement.

I'd suggest waiting to merge this until there is an edpt_close() function available, so that we don't worry about hacks in master.

src/class/net/net_device.c Show resolved Hide resolved
src/class/net/net_device.c Outdated Show resolved Hide resolved
src/class/net/net_device.c Outdated Show resolved Hide resolved
src/class/net/net_device.c Show resolved Hide resolved
src/device/usbd.c Outdated Show resolved Hide resolved
@hathach hathach requested a review from pigrew April 16, 2020 04:59
Copy link
Collaborator

@pigrew pigrew left a comment

Choose a reason for hiding this comment

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

Seems good to me based on a read-through. You could try adding a "stall" then "unstall" to the bulk EP to reset DTOG in the SET_INTERFACE handler.

tud_network_init_cb();
can_xmit = true; // we are ready to transmit a packet
tud_network_recv_renew(); // prepare for incoming packets
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps another hack could be to do a "stall" and then an "unstall" on the two bulk EP, in order to reset their DTOGs, in the case that the EP are already open. But, not necessary, since it's hacky anyway.

Copy link
Owner Author

@hathach hathach Apr 16, 2020

Choose a reason for hiding this comment

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

that is a good hack, though let's just leave it this way, to make sure we got an actual error and have motivation to fix it :)

@hathach hathach merged commit bfec3b4 into master Apr 16, 2020
@hathach hathach deleted the add-alt-itf branch April 16, 2020 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants