Skip to content

Commit 6fcc268

Browse files
author
Liam Staskawicz
committed
winusb: implement claim/release interface
1 parent cdbf8fe commit 6fcc268

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/platform/winusb.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,42 @@ int winusbGetEndpointDescriptor(UsbusDevice *d, unsigned intfIndex, unsigned ep,
264264

265265
int winusbClaimInterface(UsbusDevice *d, unsigned index)
266266
{
267-
return UsbusErrUnknown;
267+
struct WinUSBDevice *wd = &d->winusb;
268+
269+
if (index >= MAX_WINUSB_INTERFACE_HANDLES) {
270+
logdebug("winusbClaimInterface(): interface index %d is too high\n", index);
271+
return -1;
272+
}
273+
274+
if (wd->winusbHandles[index] != NULL) {
275+
// already claimed
276+
return UsbusOK;
277+
}
278+
279+
if (!WinUsb_GetAssociatedInterface(wd->winusbHandles[0], index, &wd->winusbHandles[index])) {
280+
logdebug("winusbClaimInterface() WinUsb_GetAssociatedInterface: %s",
281+
win32ErrorString(GetLastError()));
282+
return -1;
283+
}
284+
285+
return UsbusOK;
268286
}
269287

270288
int winusbReleaseInterface(UsbusDevice *d, unsigned index)
271289
{
272-
return UsbusErrUnknown;
290+
struct WinUSBDevice *wd = &d->winusb;
291+
292+
if (index >= MAX_WINUSB_INTERFACE_HANDLES) {
293+
logdebug("winusbGetEndpointDescriptor(): interface index %d is too high\n", index);
294+
return -1;
295+
}
296+
297+
if (wd->winusbHandles[index] != NULL) {
298+
WinUsb_Free(wd->winusbHandles[index]);
299+
wd->winusbHandles[index] = NULL;
300+
}
301+
302+
return UsbusOK;
273303
}
274304

275305
int winusbGetConfiguration(UsbusDevice *device, uint8_t *config)

0 commit comments

Comments
 (0)