summaryrefslogtreecommitdiffhomepage
path: root/setupapi
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-06 20:18:44 +0100
committerSimon Rozman <simon@rozman.si>2019-02-06 20:18:44 +0100
commit73df1c08719960c7002e521ce7466d1cc9e93ca6 (patch)
tree488e7f9c619b0ad3af0aeae849706580b4c99203 /setupapi
parent069016bbc4fac01260f2addd70b67bce5ebeac70 (diff)
setupapi: Add DrvInfoDetailData.IsCompatible() to simplify HID detection
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'setupapi')
-rw-r--r--setupapi/setupapi_windows_test.go14
-rw-r--r--setupapi/types_windows.go16
2 files changed, 29 insertions, 1 deletions
diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go
index 9f45a6f..2325164 100644
--- a/setupapi/setupapi_windows_test.go
+++ b/setupapi/setupapi_windows_test.go
@@ -206,10 +206,22 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
selectedDriverData = driverData
}
- _, err = devInfoList.GetDriverInfoDetail(deviceData, driverData)
+ driverDetailData, err := devInfoList.GetDriverInfoDetail(deviceData, driverData)
if err != nil {
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)
diff --git a/setupapi/types_windows.go b/setupapi/types_windows.go
index 2dfcb70..db2f8ce 100644
--- a/setupapi/types_windows.go
+++ b/setupapi/types_windows.go
@@ -6,6 +6,7 @@
package setupapi
import (
+ "strings"
"syscall"
"unsafe"
@@ -447,6 +448,21 @@ type DrvInfoDetailData struct {
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
type DICD uint32