static int wince_set_interface_altsetting( struct libusb_device_handle *handle, int interface_number, int altsetting) { struct wince_device_priv *priv = _device_priv(handle->dev); if (!UkwSetInterfaceAlternateSetting(priv->dev, interface_number, altsetting)) { return translate_driver_error(GetLastError()); } return LIBUSB_SUCCESS; }
static int wince_release_interface( struct libusb_device_handle *handle, int interface_number) { struct wince_device_priv *priv = _device_priv(handle->dev); if (!UkwSetInterfaceAlternateSetting(priv->dev, interface_number, 0)) { return translate_driver_error(GetLastError()); } if (!UkwReleaseInterface(priv->dev, interface_number)) { return translate_driver_error(GetLastError()); } return LIBUSB_SUCCESS; }
static void performInterfaceOperation(char line[]) { switch(line[0]) { case 'c': case 'r': { // Claiming and releasing interfaces is almost the same, so // handle it with common code BOOL claiming = line[0] == 'c'; const char* opStr = claiming ? "claiming" : "releasing"; ++line; DWORD devIdx = 0; line = parseNumber(line, devIdx); if (!line) { printf("Please provide a decimal device number following the command\n"); return; } if (devIdx >= gDeviceListSize || devIdx < 0) { printf("Invalid device index '%d' provided\n", devIdx); return; } // Parse the interface number DWORD interfaceNumber = 0; line = parseNumber(line, interfaceNumber); if (!line) { printf("Please provide a decimal interface number following the device number"); return; } // All parameters decoded, perform the operation UKW_DEVICE device = gDeviceList[devIdx]; BOOL status = FALSE; if (claiming) status = UkwClaimInterface(device, interfaceNumber); else status = UkwReleaseInterface(device, interfaceNumber); if (status) { printf("Success when %s interface %d\n", opStr, interfaceNumber); } else { printf("Failure when attempting %s of interface %d: %d\n", opStr, interfaceNumber, GetLastError()); } break; } case 'a': { ++line; DWORD devIdx = 0; line = parseNumber(line, devIdx); if (!line) { printf("Please provide a decimal device number following the command\n"); return; } if (devIdx >= gDeviceListSize || devIdx < 0) { printf("Invalid device index '%d' provided\n", devIdx); return; } // Parse the interface number DWORD interfaceNumber = 0; line = parseNumber(line, interfaceNumber); if (!line) { printf("Please provide a decimal interface number following the device number"); return; } // Parse the alternate setting number DWORD altSetting = 0; line = parseNumber(line, altSetting); if (!line) { printf("Please provide a decimal alternate setting number following the interface number"); return; } // All parameters decoded, perform the operation UKW_DEVICE device = gDeviceList[devIdx]; if (UkwSetInterfaceAlternateSetting(device, interfaceNumber, altSetting)) { printf("Successfully set interface %d to alternate setting %d\n", interfaceNumber, altSetting); } else { printf("Failed to set interface %d to alternate setting %d: %d\n", interfaceNumber, altSetting, GetLastError()); } break; } default: printf("Unknown interface operation requested, not doing anything\n"); break; } }