setupapi: Add DrvInfoDetailData.IsCompatible() to simplify HID detection
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
069016bbc4
commit
73df1c0871
@ -206,10 +206,22 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
|
|||||||
selectedDriverData = driverData
|
selectedDriverData = driverData
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = devInfoList.GetDriverInfoDetail(deviceData, driverData)
|
driverDetailData, err := devInfoList.GetDriverInfoDetail(deviceData, driverData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error calling SetupDiGetDriverInfoDetail: %s", err.Error())
|
t.Errorf("Error calling SetupDiGetDriverInfoDetail: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if driverDetailData.IsCompatible("foobar-aab6e3a4-144e-4786-88d3-6cec361e1edd") {
|
||||||
|
t.Error("Invalid HWID compatibitlity reported")
|
||||||
|
}
|
||||||
|
if !driverDetailData.IsCompatible(strings.ToUpper(driverDetailData.HardwareID)) {
|
||||||
|
t.Error("HWID compatibitlity missed")
|
||||||
|
}
|
||||||
|
for k := range driverDetailData.CompatIDs {
|
||||||
|
if !driverDetailData.IsCompatible(strings.ToUpper(driverDetailData.CompatIDs[k])) {
|
||||||
|
t.Error("HWID compatibitlity missed")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedDriverData2, err := devInfoList.GetSelectedDriver(deviceData)
|
selectedDriverData2, err := devInfoList.GetSelectedDriver(deviceData)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package setupapi
|
package setupapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -447,6 +448,21 @@ type DrvInfoDetailData struct {
|
|||||||
CompatIDs []string
|
CompatIDs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsCompatible method tests if given hardware ID matches the driver or is listed on the compatible ID list.
|
||||||
|
func (DriverInfoDetailData DrvInfoDetailData) IsCompatible(hwid string) bool {
|
||||||
|
hwidLC := strings.ToLower(hwid)
|
||||||
|
if strings.ToLower(DriverInfoDetailData.HardwareID) == hwidLC {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for i := range DriverInfoDetailData.CompatIDs {
|
||||||
|
if strings.ToLower(DriverInfoDetailData.CompatIDs[i]) == hwidLC {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// DICD flags control SetupDiCreateDeviceInfo
|
// DICD flags control SetupDiCreateDeviceInfo
|
||||||
type DICD uint32
|
type DICD uint32
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user