From ac5ea38615f7e44ee3cdbd7529e25d0cefe9c1ed Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Sat, 21 Feb 2015 10:09:36 +0000 Subject: [PATCH] [STREAMCI] - start implement streaming device class installer svn path=/trunk/; revision=66379 --- reactos/dll/win32/CMakeLists.txt | 1 + reactos/dll/win32/streamci/CMakeLists.txt | 20 +++ reactos/dll/win32/streamci/precomp.h | 28 ++++ reactos/dll/win32/streamci/streamci.c | 187 ++++++++++++++++++++++ reactos/dll/win32/streamci/streamci.rc | 18 +++ reactos/dll/win32/streamci/streamci.spec | 1 + 6 files changed, 255 insertions(+) create mode 100644 reactos/dll/win32/streamci/CMakeLists.txt create mode 100644 reactos/dll/win32/streamci/precomp.h create mode 100644 reactos/dll/win32/streamci/streamci.c create mode 100644 reactos/dll/win32/streamci/streamci.rc create mode 100644 reactos/dll/win32/streamci/streamci.spec diff --git a/reactos/dll/win32/CMakeLists.txt b/reactos/dll/win32/CMakeLists.txt index 4434f44549f..2371886500b 100644 --- a/reactos/dll/win32/CMakeLists.txt +++ b/reactos/dll/win32/CMakeLists.txt @@ -196,6 +196,7 @@ add_subdirectory(srclient) add_subdirectory(stdole2.tlb) add_subdirectory(stdole32.tlb) add_subdirectory(sti) +add_subdirectory(streamci) add_subdirectory(sxs) add_subdirectory(syssetup) add_subdirectory(t2embed) diff --git a/reactos/dll/win32/streamci/CMakeLists.txt b/reactos/dll/win32/streamci/CMakeLists.txt new file mode 100644 index 00000000000..c0c903b7525 --- /dev/null +++ b/reactos/dll/win32/streamci/CMakeLists.txt @@ -0,0 +1,20 @@ + +remove_definitions(-D_WIN32_WINNT=0x502) +add_definitions(-D_WIN32_WINNT=0x600) + +spec2def(streamci.dll streamci.spec) + +list(APPEND SOURCE + streamci.c + precomp.h) + +add_library(streamci SHARED + ${SOURCE} + streamci.rc + ${CMAKE_CURRENT_BINARY_DIR}/streamci.def) + +set_module_type(streamci win32dll) +target_link_libraries(streamci uuid wine) +add_importlibs(streamci rpcrt4 setupapi advapi32 iphlpapi dhcpcsvc ole32 user32 comctl32 ws2_32 msvcrt kernel32 ntdll) +add_pch(streamci precomp.h SOURCE) +add_cd_file(TARGET streamci DESTINATION reactos/system32 FOR all) diff --git a/reactos/dll/win32/streamci/precomp.h b/reactos/dll/win32/streamci/precomp.h new file mode 100644 index 00000000000..94af8c49a6e --- /dev/null +++ b/reactos/dll/win32/streamci/precomp.h @@ -0,0 +1,28 @@ +#ifndef PRECOMP_H__ +#define PRECOMP_H__ + +#include + +#define WIN32_NO_STATUS +#define _INC_WINDOWS +#define COM_NO_WINDOWS_H + +#define COBJMACROS +#define NONAMELESSUNION +#define NONAMELESSSTRUCT + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* EOF */ + diff --git a/reactos/dll/win32/streamci/streamci.c b/reactos/dll/win32/streamci/streamci.c new file mode 100644 index 00000000000..3230c400904 --- /dev/null +++ b/reactos/dll/win32/streamci/streamci.c @@ -0,0 +1,187 @@ +#include "precomp.h" + +DWORD +PerformIO(IN HANDLE hDevice, + IN DWORD dwCtlCode, + IN LPVOID lpBufferIn, + IN DWORD dwBufferSizeIn, + OUT LPVOID lpBufferOut, + OUT DWORD dwBufferSizeOut, + OUT LPDWORD lpNumberBytes) +{ + OVERLAPPED overlapped; + DWORD dwResult; + + ZeroMemory(&overlapped, sizeof(OVERLAPPED)); + overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!overlapped.hEvent) + { + // failed to init event + return GetLastError(); + } + + if (DeviceIoControl(hDevice, dwCtlCode, lpBufferIn, dwBufferSizeIn, lpBufferOut, dwBufferSizeOut, lpNumberBytes, &overlapped)) + { + dwResult = ERROR_SUCCESS; + } + else if (GetLastError() == ERROR_IO_PENDING) + { + if (GetOverlappedResult(hDevice, &overlapped, lpNumberBytes, TRUE)) + { + dwResult = ERROR_SUCCESS; + } + else + { + dwResult = GetLastError(); + } + } + else + { + dwResult = GetLastError(); + } + CloseHandle(overlapped.hEvent); + return dwResult; +} + +DWORD +InstallSoftwareDeviceInterface(IN LPGUID DeviceId, + IN LPGUID InterfaceId, + IN LPWSTR ReferenceString) +{ + HDEVINFO hDevInfo; + SP_DEVICE_INTERFACE_DATA DeviceInterfaceData; + GUID SWBusGuid = {STATIC_BUSID_SoftwareDeviceEnumerator}; + PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData; + HANDLE hDevice; + PSWENUM_INSTALL_INTERFACE InstallInterface; + DWORD dwResult; + + hDevInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_SYSTEM, NULL, NULL, DIGCF_DEVICEINTERFACE| DIGCF_PRESENT); + if (!hDevInfo) + { + // failed + return GetLastError(); + } + + DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); + if (!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &SWBusGuid, 0, &DeviceInterfaceData)) + { + // failed + SetupDiDestroyDeviceInfoList(hDevInfo); + return GetLastError(); + } + + DeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA_W)HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR) + sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W)); + if (!DeviceInterfaceDetailData) + { + // failed + SetupDiDestroyDeviceInfoList(hDevInfo); + return GetLastError(); + } + + if (!SetupDiGetDeviceInterfaceDetailW(hDevInfo, &DeviceInterfaceData, DeviceInterfaceDetailData,MAX_PATH * sizeof(WCHAR) + sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W), NULL, NULL)) + { + // failed + HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData); + SetupDiDestroyDeviceInfoList(hDevInfo); + return GetLastError(); + } + + + hDevice = CreateFileW(DeviceInterfaceDetailData->DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED|FILE_ATTRIBUTE_NORMAL, NULL); + if (hDevice == INVALID_HANDLE_VALUE) + { + // failed + HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData); + SetupDiDestroyDeviceInfoList(hDevInfo); + return GetLastError(); + } + + InstallInterface = (PSWENUM_INSTALL_INTERFACE)HeapAlloc(GetProcessHeap(), 0, sizeof(SWENUM_INSTALL_INTERFACE) + wcslen(ReferenceString) * sizeof(WCHAR)); + if (!InstallInterface) + { + // failed + CloseHandle(hDevice); + HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData); + SetupDiDestroyDeviceInfoList(hDevInfo); + return GetLastError(); + } + + // init install interface param + InstallInterface->DeviceId = *DeviceId; + InstallInterface->InterfaceId = *InterfaceId; + wcscpy(InstallInterface->ReferenceString, ReferenceString); + + PerformIO(hDevice, IOCTL_SWENUM_INSTALL_INTERFACE, InstallInterface, sizeof(SWENUM_INSTALL_INTERFACE) + wcslen(ReferenceString) * sizeof(WCHAR), NULL, 0, NULL); + dwResult = HeapFree(GetProcessHeap(), 0, InstallInterface); + + CloseHandle(hDevice); + HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData); + SetupDiDestroyDeviceInfoList(hDevInfo); + return dwResult; +} + +VOID +WINAPI +StreamingDeviceSetupW(IN HWND hwnd, + IN HINSTANCE hinst, + IN LPWSTR lpszCmdLine, + IN int nCmdShow) +{ + DWORD Length; + LPWSTR pCmdLine; + LPWSTR pStr; + GUID Guids[2]; + //WCHAR DevicePath[MAX_PATH]; + HRESULT hResult; + DWORD Index; + + Length = (wcslen(lpszCmdLine) + 1) * sizeof(WCHAR); + + pCmdLine = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Length); + if (pCmdLine == NULL) + { + // no memory + return; + } + + hResult = StringCbCopyExW(pCmdLine, Length, lpszCmdLine, NULL, NULL, STRSAFE_NULL_ON_FAILURE); + if (hResult != S_OK) + { + // failed + HeapFree(GetProcessHeap(), 0, pCmdLine); + return; + } + + pStr = wcstok(pCmdLine, L",\t\""); + Index = 0; + do + { + if (pStr == NULL) + { + // invalid parameter + HeapFree(GetProcessHeap(), 0, pCmdLine); + return; + } + + hResult = IIDFromString(pStr, &Guids[Index]); + if (hResult != S_OK) + { + // invalid parameter + HeapFree(GetProcessHeap(), 0, pCmdLine); + return; + } + + Index++; + pStr = wcstok(NULL, L",\t\""); + + + }while(Index < 2); + + + hResult = InstallSoftwareDeviceInterface(&Guids[0], &Guids[1], pStr); + + // FIXME + // install inf section + +} \ No newline at end of file diff --git a/reactos/dll/win32/streamci/streamci.rc b/reactos/dll/win32/streamci/streamci.rc new file mode 100644 index 00000000000..384ce29be3a --- /dev/null +++ b/reactos/dll/win32/streamci/streamci.rc @@ -0,0 +1,18 @@ +#define WIN32_NO_STATUS +#include +#include +#include + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + +#define REACTOS_VERSION_DLL +#define REACTOS_STR_FILE_DESCRIPTION "Streaming Device Class Installer" +#define REACTOS_STR_INTERNAL_NAME "streamci.dll" +#define REACTOS_STR_ORIGINAL_FILENAME "streamci.dll" +#define REACTOS_STR_PRODUCT_VERSION "5.1.2600.3264" +#define REACTOS_STR_FILE_VERSION "5.1.2600.3264" +#include + +/* UTF-8 */ +#pragma code_page(65001) + diff --git a/reactos/dll/win32/streamci/streamci.spec b/reactos/dll/win32/streamci/streamci.spec new file mode 100644 index 00000000000..06e7868c857 --- /dev/null +++ b/reactos/dll/win32/streamci/streamci.spec @@ -0,0 +1 @@ +7 stdcall StreamingDeviceSetupW(ptr ptr ptr long)