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

Develop sever usb #70

Open
wants to merge 13 commits into
base: develop_server
Choose a base branch
from
Open

Develop sever usb #70

wants to merge 13 commits into from

Conversation

TheMutta
Copy link

Added support for using the USB EPs from FunctionFS.

@TheMutta TheMutta requested a review from themarpe July 19, 2023 12:27
@TheMutta TheMutta self-assigned this Jul 19, 2023
@TheMutta TheMutta changed the base branch from master to develop_server July 19, 2023 12:27
Copy link
Collaborator

@themarpe themarpe left a comment

Choose a reason for hiding this comment

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

USB_EP for "client" should not exist.

USB_EP is specialization ONLY for Server part of USB Device capability

Eg usb_host_ep.cpp now contains exactly the same thing as USB_VSC server does.

It should only contain USB_EP

Comment on lines 28 to 30
deviceDesc_t deviceDesc;
strcpy(deviceDesc.name, "usbdev");
deviceDesc.protocol = X_LINK_USB_EP;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be USB_VSC

Copy link
Author

Choose a reason for hiding this comment

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

USB_VSC will use EPs 81 and 1 to communicate, but those aren't the ones that are present in our gadget.
That's because in our gadget we create first the NCM function, then the XLink function, and after the ADB function.
I'll first modify the gadget and test it if it works.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then lets move the specialization for custom EP to usb vsc, and well then pick the right one afterwards. (Eg using state, or some other attributes of the device. We'll have to make the device discovery as well)

Comment on lines 35 to 45
char outPath[256];
strcpy(outPath, devPathWrite);
strcat(outPath, "/ep1");

char inPath[256];
strcpy(inPath, devPathWrite);
strcat(inPath, "/ep2");

int outfd = open(outPath, O_RDWR);
int infd = open(inPath, O_RDWR);

Copy link
Collaborator

Choose a reason for hiding this comment

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

c++ std::string instead

+add a special case where devPathREAD is supplied as well and then don't do any "auto /ep1&2 assumptions" but just directly open outPath & open inPath and use that as FD's

Comment on lines 60 to 76
int usbEpPlatformClose(void *fdKey)
{
int error;

#if defined(_WIN32)
return X_LINK_ERROR;
#else
if (usbFdRead != -1){
close(usbFdRead);
usbFdRead = -1;
}

if (usbFdWrite != -1){
close(usbFdWrite);
usbFdWrite = -1;
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should come from fdKeys while we are working on this. Remove global static usbFdRead/Write.

You'll have to tweak static std::unordered_map<std::uintptr_t, void*> map; to take a struct instead with two FDs, default api can return still just first FD, but add API to be able to query both FDs

@@ -938,6 +939,8 @@ int usb_read(libusb_device_handle *f, void *data, size_t size)

int usb_write(libusb_device_handle *f, const void *data, size_t size)
{
int bt, ss = (int)size;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Required?

}


int usbEpPlatformClose(void *fdKey)
{
fdPair *pair;
getPlatformDeviceFdFromKey(fdKey, (void**)&pair);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if ret val good & pair != nullptr


return EXIT_SUCCESS;
}

int usbEpPlatformRead(void *fdKey, void *data, int size)
{
fdPair *pair;
getPlatformDeviceFdFromKey(fdKey, (void**)&pair);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if ret val good & pair != nullptr

Comment on lines +97 to +98
fdPair *pair;
getPlatformDeviceFdFromKey(fdKey, (void**)&pair);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if ret val good & pair != nullptr

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

2 participants