-
Notifications
You must be signed in to change notification settings - Fork 985
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
Conversation
mostly forward these request (recipient = interface) to class driver.
// 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]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
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. |
There was a problem hiding this 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!
Why is that, I am open to all suggestion.
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). |
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. |
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. |
gh tips: change target base to another, then back to master to get file changes updated :D |
There was a problem hiding this 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
.
There was a problem hiding this 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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
follow up to #342 and #344 (merging these first make bisecting easier)
related to #320 #317