Skip to content

Commit

Permalink
Working on #374
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Jul 17, 2024
1 parent 2d3af56 commit 9e99fb7
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 8 deletions.
10 changes: 10 additions & 0 deletions sys/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ typedef struct _DEVICE_CONTEXT

} RumbleControlState;

//
// Instance ID of this device
//
WDFMEMORY InstanceId;

//
// TRUE if the mode property didn't match the configuration provided one
//
BOOLEAN HidModeMismatch;

} DEVICE_CONTEXT, * PDEVICE_CONTEXT;

//
Expand Down
72 changes: 70 additions & 2 deletions sys/DsHidMiniDrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,81 @@ DMF_DsHidMini_Open(
const WDFDEVICE device = DMF_ParentDeviceGet(DmfModule);
const PDEVICE_CONTEXT pDevCtx = DeviceGetContext(device);
DMF_CONFIG_VirtualHidMini* pHidCfg = DMF_ModuleConfigGet(moduleContext->DmfModuleVirtualHidMini);
const DS_HID_DEVICE_MODE startupHidMode = pDevCtx->Configuration.HidDeviceMode;

WDF_DEVICE_PROPERTY_DATA propertyData;
ULONG requiredSize = 0;
DEVPROPTYPE propType = DEVPROP_TYPE_EMPTY;

//
// Load settings
//
ConfigLoadForDevice(pDevCtx, FALSE);

const DS_HID_DEVICE_MODE configHidMode = pDevCtx->Configuration.HidDeviceMode;

//
// The property value on device creation differs from what is specified in the configuration
// This will cause issues if igfilter is enabled on non-XI-modes so we restart ourself here
//
if (startupHidMode != configHidMode)
{
TraceVerbose(
TRACE_DSHIDMINIDRV,
"HID Device Mode mismatch; got %hs but should be %hs",
G_HID_DEVICE_MODE_NAMES[startupHidMode],
G_HID_DEVICE_MODE_NAMES[configHidMode]
);

WDF_DEVICE_PROPERTY_DATA_INIT(&propertyData, &DEVPKEY_DsHidMini_RW_HidDeviceMode);
propertyData.Flags |= PLUGPLAY_PROPERTY_PERSISTENT;
propertyData.Lcid = LOCALE_NEUTRAL;

//
// Sync mode up with value from configuration
//
status = WdfDeviceAssignProperty(
device,
&propertyData,
DEVPROP_TYPE_BYTE,
sizeof(BYTE),
&pDevCtx->Configuration.HidDeviceMode
);

if (!NT_SUCCESS(status))
goto exit;

WDF_DEVICE_PROPERTY_DATA_INIT(&propertyData, &DEVPKEY_Device_InstanceId);
propertyData.Flags |= PLUGPLAY_PROPERTY_PERSISTENT;
propertyData.Lcid = LOCALE_NEUTRAL;

//
// Grab our instance ID
//
if (!NT_SUCCESS(status = WdfDeviceAllocAndQueryPropertyEx(
device,
&propertyData,
DS3_POOL_TAG,
WDF_NO_OBJECT_ATTRIBUTES,
&pDevCtx->InstanceId,
&propType
)))
{
TraceError(
TRACE_DSHIDMINIDRV,
"WdfDeviceAllocAndQueryPropertyEx failed with status %!STATUS!",
status
);
EventWriteFailedWithNTStatus(__FUNCTION__, L"WdfDeviceAllocAndQueryPropertyEx", status);

// TODO: what else to do here?
}
else
{
pDevCtx->HidModeMismatch = TRUE;
}
}

pHidCfg->VendorId = pDevCtx->VendorId;
pHidCfg->ProductId = pDevCtx->ProductId;
pHidCfg->VersionNumber = pDevCtx->VersionNumber;
Expand Down Expand Up @@ -457,8 +526,7 @@ DMF_DsHidMini_Open(
//
// Set currently used HID mode
//

WDF_DEVICE_PROPERTY_DATA propertyData;

WDF_DEVICE_PROPERTY_DATA_INIT(&propertyData, &DEVPKEY_DsHidMini_RW_HidDeviceMode);
propertyData.Flags |= PLUGPLAY_PROPERTY_PERSISTENT;
propertyData.Lcid = LOCALE_NEUTRAL;
Expand Down
13 changes: 7 additions & 6 deletions sys/DsUsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,9 @@ USB_CyclePort(

if (hubFound)
{
ULONG interfaceListSize = 0;
ULONG interfaceListCchSize = 0;
ret = CM_Get_Device_Interface_List_SizeW(
&interfaceListSize,
&interfaceListCchSize,
(LPGUID)&GUID_DEVINTERFACE_USB_HUB,
hubInstanceId,
CM_GET_DEVICE_INTERFACE_LIST_PRESENT
Expand All @@ -895,13 +895,14 @@ USB_CyclePort(
goto exit;
}

interfaceList = LocalAlloc(LPTR, interfaceListSize);
const ULONG interfaceListByteSize = interfaceListCchSize * sizeof(WCHAR);
interfaceList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, interfaceListByteSize);

ret = CM_Get_Device_Interface_ListW(
(LPGUID)&GUID_DEVINTERFACE_USB_HUB,
hubInstanceId,
interfaceList,
interfaceListSize,
interfaceListCchSize,
CM_GET_DEVICE_INTERFACE_LIST_PRESENT
);

Expand All @@ -928,7 +929,7 @@ USB_CyclePort(
}

USB_CYCLE_PORT_PARAMS cycleParams = {
connectionIndex, 0
connectionIndex, STATUS_SUCCESS
};

const BOOL success = DeviceIoControl(
Expand All @@ -951,7 +952,7 @@ USB_CyclePort(
CloseHandle(hubHandle);

if (interfaceList)
LocalFree(interfaceList);
HeapFree(GetProcessHeap(), 0, interfaceList);

return result;
}

0 comments on commit 9e99fb7

Please sign in to comment.