]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Add support for setupapi.SetupDi(Get|Set)ClassInstallParams()
authorSimon Rozman <simon@rozman.si>
Fri, 1 Feb 2019 13:58:59 +0000 (14:58 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 5 Feb 2019 11:59:42 +0000 (12:59 +0100)
Signed-off-by: Simon Rozman <simon@rozman.si>
setupapi/setupapi_windows.go
setupapi/types_windows.go
setupapi/zsetupapi_windows.go

index 3fa0cbbe548232272a8ddc1f95c20596b5723cda..89fb3e4a7f0dc28d53f31a8181e2a5ac524d8799 100644 (file)
@@ -20,6 +20,8 @@ import (
 //sys  setupDiOpenDevRegKey(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, Scope DICS_FLAG, HwProfile uint32, KeyType DIREG, samDesired uint32) (key windows.Handle, err error) [failretval==windows.InvalidHandle] = setupapi.SetupDiOpenDevRegKey
 //sys  setupDiGetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) = setupapi.SetupDiGetDeviceInstallParamsW
 //sys  setupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) = setupapi.SetupDiSetDeviceInstallParamsW
+//sys  SetupDiGetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32, RequiredSize *uint32) (err error) = setupapi.SetupDiGetClassInstallParamsW
+//sys  SetupDiSetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32) (err error) = setupapi.SetupDiSetClassInstallParamsW
 
 // SetupDiGetClassDevsEx function returns a handle to a device information set that contains requested device information elements for a local or a remote computer.
 func SetupDiGetClassDevsEx(ClassGUID *windows.GUID, Enumerator string, hwndParent uintptr, Flags DIGCF, DeviceInfoSet DevInfo, MachineName string) (handle DevInfo, err error) {
index e8fe65009d4fef45f306a0456461ac62c5af1c9f..e2617a45e6bd8c1845d612c824d490598c623874 100644 (file)
@@ -208,3 +208,55 @@ type DevInstallParams struct {
        FileQueue                HSPFILEQ
        DriverPath               string
 }
+
+// DI_FUNCTION is function type for device installer
+type DI_FUNCTION uint32
+
+const (
+       DIF_SELECTDEVICE                   DI_FUNCTION = 0x00000001
+       DIF_INSTALLDEVICE                  DI_FUNCTION = 0x00000002
+       DIF_ASSIGNRESOURCES                DI_FUNCTION = 0x00000003
+       DIF_PROPERTIES                     DI_FUNCTION = 0x00000004
+       DIF_REMOVE                         DI_FUNCTION = 0x00000005
+       DIF_FIRSTTIMESETUP                 DI_FUNCTION = 0x00000006
+       DIF_FOUNDDEVICE                    DI_FUNCTION = 0x00000007
+       DIF_SELECTCLASSDRIVERS             DI_FUNCTION = 0x00000008
+       DIF_VALIDATECLASSDRIVERS           DI_FUNCTION = 0x00000009
+       DIF_INSTALLCLASSDRIVERS            DI_FUNCTION = 0x0000000A
+       DIF_CALCDISKSPACE                  DI_FUNCTION = 0x0000000B
+       DIF_DESTROYPRIVATEDATA             DI_FUNCTION = 0x0000000C
+       DIF_VALIDATEDRIVER                 DI_FUNCTION = 0x0000000D
+       DIF_DETECT                         DI_FUNCTION = 0x0000000F
+       DIF_INSTALLWIZARD                  DI_FUNCTION = 0x00000010
+       DIF_DESTROYWIZARDDATA              DI_FUNCTION = 0x00000011
+       DIF_PROPERTYCHANGE                 DI_FUNCTION = 0x00000012
+       DIF_ENABLECLASS                    DI_FUNCTION = 0x00000013
+       DIF_DETECTVERIFY                   DI_FUNCTION = 0x00000014
+       DIF_INSTALLDEVICEFILES             DI_FUNCTION = 0x00000015
+       DIF_UNREMOVE                       DI_FUNCTION = 0x00000016
+       DIF_SELECTBESTCOMPATDRV            DI_FUNCTION = 0x00000017
+       DIF_ALLOW_INSTALL                  DI_FUNCTION = 0x00000018
+       DIF_REGISTERDEVICE                 DI_FUNCTION = 0x00000019
+       DIF_NEWDEVICEWIZARD_PRESELECT      DI_FUNCTION = 0x0000001A
+       DIF_NEWDEVICEWIZARD_SELECT         DI_FUNCTION = 0x0000001B
+       DIF_NEWDEVICEWIZARD_PREANALYZE     DI_FUNCTION = 0x0000001C
+       DIF_NEWDEVICEWIZARD_POSTANALYZE    DI_FUNCTION = 0x0000001D
+       DIF_NEWDEVICEWIZARD_FINISHINSTALL  DI_FUNCTION = 0x0000001E
+       DIF_UNUSED1                        DI_FUNCTION = 0x0000001F
+       DIF_INSTALLINTERFACES              DI_FUNCTION = 0x00000020
+       DIF_DETECTCANCEL                   DI_FUNCTION = 0x00000021
+       DIF_REGISTER_COINSTALLERS          DI_FUNCTION = 0x00000022
+       DIF_ADDPROPERTYPAGE_ADVANCED       DI_FUNCTION = 0x00000023
+       DIF_ADDPROPERTYPAGE_BASIC          DI_FUNCTION = 0x00000024
+       DIF_TROUBLESHOOTER                 DI_FUNCTION = 0x00000026
+       DIF_POWERMESSAGEWAKE               DI_FUNCTION = 0x00000027
+       DIF_ADDREMOTEPROPERTYPAGE_ADVANCED DI_FUNCTION = 0x00000028
+       DIF_UPDATEDRIVER_UI                DI_FUNCTION = 0x00000029
+       DIF_FINISHINSTALL_ACTION           DI_FUNCTION = 0x0000002A
+)
+
+// SP_CLASSINSTALL_HEADER is the first member of any class install parameters structure. It contains the device installation request code that defines the format of the rest of the install parameters structure.
+type SP_CLASSINSTALL_HEADER struct {
+       Size            uint32
+       InstallFunction DI_FUNCTION
+}
index a569219287d21536aaef8ab539bdba467c79905a..d09c8ddef9ee4e3a9c99268598c99d3f6a531fac 100644 (file)
@@ -46,6 +46,8 @@ var (
        procSetupDiOpenDevRegKey            = modsetupapi.NewProc("SetupDiOpenDevRegKey")
        procSetupDiGetDeviceInstallParamsW  = modsetupapi.NewProc("SetupDiGetDeviceInstallParamsW")
        procSetupDiSetDeviceInstallParamsW  = modsetupapi.NewProc("SetupDiSetDeviceInstallParamsW")
+       procSetupDiGetClassInstallParamsW   = modsetupapi.NewProc("SetupDiGetClassInstallParamsW")
+       procSetupDiSetClassInstallParamsW   = modsetupapi.NewProc("SetupDiSetClassInstallParamsW")
 )
 
 func setupDiGetClassDevsEx(ClassGUID *windows.GUID, Enumerator *uint16, hwndParent uintptr, Flags DIGCF, DeviceInfoSet DevInfo, MachineName *uint16, reserved uintptr) (handle DevInfo, err error) {
@@ -133,3 +135,27 @@ func setupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEV
        }
        return
 }
+
+func SetupDiGetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32, RequiredSize *uint32) (err error) {
+       r1, _, e1 := syscall.Syscall6(procSetupDiGetClassInstallParamsW.Addr(), 5, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)), uintptr(unsafe.Pointer(ClassInstallParams)), uintptr(ClassInstallParamsSize), uintptr(unsafe.Pointer(RequiredSize)), 0)
+       if r1 == 0 {
+               if e1 != 0 {
+                       err = errnoErr(e1)
+               } else {
+                       err = syscall.EINVAL
+               }
+       }
+       return
+}
+
+func SetupDiSetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32) (err error) {
+       r1, _, e1 := syscall.Syscall6(procSetupDiSetClassInstallParamsW.Addr(), 4, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)), uintptr(unsafe.Pointer(ClassInstallParams)), uintptr(ClassInstallParamsSize), 0, 0)
+       if r1 == 0 {
+               if e1 != 0 {
+                       err = errnoErr(e1)
+               } else {
+                       err = syscall.EINVAL
+               }
+       }
+       return
+}