Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions Tools/ComponentFirmwareUpdateStandAloneToolSample/FwUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,32 @@ Return Value:
NTSTATUS status;
HRESULT hr = S_OK;
device.hDevice = INVALID_HANDLE_VALUE;

// Check that the VID/PID matches.
wchar_t vidPidFilterString[256] = { 0 };
memset(&VerReport, 0, sizeof(VerReport));
HIDD_ATTRIBUTES attr = { 0 };

// Open a handle to the device.
device.hDevice = CreateFileW(
DevicePath,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (device.hDevice == INVALID_HANDLE_VALUE)
{
wprintf(L"INVALID_HANDLE_VALUE %s", DevicePath);
hr = HRESULT_FROM_WIN32(GetLastError());
goto Exit;
}

if (!HidD_GetAttributes(device.hDevice, &attr)) {
hr = HRESULT_FROM_WIN32(GetLastError());
goto Exit;
}
// Filter on both if both set
if (ProtocolSettings.Vid && ProtocolSettings.Pid)
if (ProtocolSettings.Vid && ProtocolSettings.Pid)
{
swprintf(vidPidFilterString, 256, L"VID_%04X&PID_%04X",
ProtocolSettings.Vid, ProtocolSettings.Pid);
if (!wcsstr(DevicePath, vidPidFilterString))
if ((attr.VendorID != ProtocolSettings.Vid) || (attr.ProductID != ProtocolSettings.Pid))
{
// The device found doesn't match the vid and pid
//wprintf(L"The device found does not match the VID/PID\n");
Expand All @@ -205,31 +219,14 @@ Return Value:
// Filter on vid only (vid is mandatory)
else
{
swprintf(vidPidFilterString, 256, L"VID_%04X", ProtocolSettings.Vid);
if (!wcsstr(DevicePath, vidPidFilterString))
if (attr.VendorID != ProtocolSettings.Vid)
{
// The device found doesn't match the vid
hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
goto Exit;
}
}

// Open a handle to the device.
device.hDevice = CreateFileW(
DevicePath,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (device.hDevice == INVALID_HANDLE_VALUE)
{
wprintf(L"INVALID_HANDLE_VALUE %s", DevicePath);
hr = HRESULT_FROM_WIN32(GetLastError());
goto Exit;
}

// Try to get the device's preparsed HID data.
if (!HidD_GetPreparsedData(device.hDevice, &device.PreparsedData))
{
Expand Down