I am working on an own libusb implementation using declares. So far, basic device retrieval/connection is working nicely, including hot plug callbacks.
Getting deeper into device communication, I have issues defining the next steps to get the endpoints.
The first part of the Config Descriptor looks quite ok:
Following MaxPower in the structure is an ptr to an array of libusb__interface structures, if I read the docs correctly, and looking into the contents of the config descriptor there could indeed be an address starting at byte 16:
But if I take the address at 907D0000 and try to fetch the memory contents,which should be a ptr to an array of libUSB interface descriptors (one in this case), there’s no valid data here. All zero.
Any ideas where my fault lies?
windows/mac/linux 32/64/arm ?
Theoretically, all. Practically macOS currently.
Oh, and btw, the memory content above is the active config descriptor. get_config_descriptor(0) returns something different, fully without any signs of an address.
Make sure your structures are aligned correctly. For 64bit try StructureAlignment 8
in (there could be others):
libusb_config_descriptor
libusb_endpoint_descriptor
libusb_interface_descriptor
Basically, anywhere you have a Ptr in a structure, make sure its offset is on an even number divisible by 8
You might even get away with StructureAlignment 0
so it chooses based on your platform, but honestly, I wouldn’t trust that.
Thank you! I wasn’t aware structure alignment was moved to the attributes field, but that’s why I am addressing the ptr(16) in my example code, where that address reveals no data. Must be something different …
And I wonder why in the upper example TotalLength of the descriptor is 39 bytes. Taking alignment into considerations, libusb_interface is bytes 16-23, followed by the extra ptr bytes 24-31. 32–33 should be ExtraLength, so size should be 34 or 35 if ended with a zero byte, not 39 …
Here you go, quick and dirty test, terrible variable names etc. Let me know if you have any questions:
[LINK REMOVED PER OP REQUEST]
Tested and runs in windows on 32 and 64
2 Likes
Thanks a lot for taking the time, Julian!
I did not find time to import the code into own project, and I could swear it must have looked a lot like this at some time. But who am I to tell?
Highly appreciated!
1 Like