ReactOS 0.4.15-dev-7788-g1ad9096
streamci.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Configuration of network devices
4 * FILE: dll/win32/streamci/streamci.c
5 * PURPOSE: Streaming device class installer
6 *
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
8 */
9
10#include "precomp.h"
11
14 IN DWORD dwCtlCode,
15 IN LPVOID lpBufferIn,
16 IN DWORD dwBufferSizeIn,
17 OUT LPVOID lpBufferOut,
18 OUT DWORD dwBufferSizeOut,
19 OUT LPDWORD lpNumberBytes)
20{
22 DWORD dwResult;
23
26 if (!overlapped.hEvent)
27 {
28 // failed to init event
29 return GetLastError();
30 }
31
32 if (DeviceIoControl(hDevice, dwCtlCode, lpBufferIn, dwBufferSizeIn, lpBufferOut, dwBufferSizeOut, lpNumberBytes, &overlapped))
33 {
34 dwResult = ERROR_SUCCESS;
35 }
36 else if (GetLastError() == ERROR_IO_PENDING)
37 {
38 if (GetOverlappedResult(hDevice, &overlapped, lpNumberBytes, TRUE))
39 {
40 dwResult = ERROR_SUCCESS;
41 }
42 else
43 {
44 dwResult = GetLastError();
45 }
46 }
47 else
48 {
49 dwResult = GetLastError();
50 }
51 CloseHandle(overlapped.hEvent);
52 return dwResult;
53}
54
57 IN LPGUID InterfaceId,
59{
60 HDEVINFO hDevInfo;
61 SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
63 PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData;
64 HANDLE hDevice;
65 PSWENUM_INSTALL_INTERFACE InstallInterface;
66 DWORD dwResult;
67
69 if (!hDevInfo)
70 {
71 // failed
72 return GetLastError();
73 }
74
75 DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
76 if (!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &SWBusGuid, 0, &DeviceInterfaceData))
77 {
78 // failed
80 return GetLastError();
81 }
82
84 if (!DeviceInterfaceDetailData)
85 {
86 // failed
88 return GetLastError();
89 }
90
91 DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
92 if (!SetupDiGetDeviceInterfaceDetailW(hDevInfo, &DeviceInterfaceData, DeviceInterfaceDetailData,MAX_PATH * sizeof(WCHAR) + sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W), NULL, NULL))
93 {
94 // failed
95 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
97 return GetLastError();
98 }
99
101 if (hDevice == INVALID_HANDLE_VALUE)
102 {
103 // failed
104 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
106 return GetLastError();
107 }
108
110 if (!InstallInterface)
111 {
112 // failed
113 CloseHandle(hDevice);
114 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
116 return GetLastError();
117 }
118
119 // init install interface param
120 InstallInterface->DeviceId = *DeviceId;
121 InstallInterface->InterfaceId = *InterfaceId;
122 wcscpy(InstallInterface->ReferenceString, ReferenceString);
123
124 PerformIO(hDevice, IOCTL_SWENUM_INSTALL_INTERFACE, InstallInterface, sizeof(SWENUM_INSTALL_INTERFACE) + wcslen(ReferenceString) * sizeof(WCHAR), NULL, 0, NULL);
125 dwResult = HeapFree(GetProcessHeap(), 0, InstallInterface);
126
127 CloseHandle(hDevice);
128 HeapFree(GetProcessHeap(), 0, DeviceInterfaceDetailData);
130 return dwResult;
131}
132
133DWORD
135 IN LPWSTR SectionName)
136{
137 HDEVINFO hDevInfo;
138 HINF hInf;
139 HKEY hKey;
140 SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
142
143 hDevInfo = SetupDiGetClassDevsW(&SWBusGuid, NULL, NULL, 0);
144 if (!hDevInfo)
145 {
146 // failed
147 return GetLastError();
148 }
149
150 DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
151 if (!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &SWBusGuid, 0, &DeviceInterfaceData))
152 {
153 // failed
154 return GetLastError();
155 }
156
157 hInf = SetupOpenInfFileW(InfName, NULL, INF_STYLE_WIN4, NULL);
158 if (hInf == INVALID_HANDLE_VALUE)
159 {
161 return GetLastError();
162 }
163
164 //
165 // FIXME check if interface is already installed
166 //
167
168 hKey = SetupDiCreateDeviceInterfaceRegKeyW(hDevInfo, &DeviceInterfaceData, 0, KEY_ALL_ACCESS, hInf, SectionName);
169
170 SetupCloseInfFile(hInf);
173 {
175 }
176 return ERROR_SUCCESS;
177}
178
179
180VOID
181WINAPI
184 IN LPWSTR lpszCmdLine,
185 IN int nCmdShow)
186{
187 DWORD Length, dwResult;
188 LPWSTR pCmdLine;
189 LPWSTR pStr;
190 GUID Guids[2];
191 WCHAR DevicePath[MAX_PATH];
192 HRESULT hResult;
193 DWORD Index;
194
195 Length = (wcslen(lpszCmdLine) + 1) * sizeof(WCHAR);
196
198 if (pCmdLine == NULL)
199 {
200 // no memory
201 return;
202 }
203
204 hResult = StringCbCopyExW(pCmdLine, Length, lpszCmdLine, NULL, NULL, STRSAFE_NULL_ON_FAILURE);
205 if (hResult != S_OK)
206 {
207 // failed
208 HeapFree(GetProcessHeap(), 0, pCmdLine);
209 return;
210 }
211
212 pStr = wcstok(pCmdLine, L",\t\"");
213 Index = 0;
214 do
215 {
216 if (pStr == NULL)
217 {
218 // invalid parameter
219 HeapFree(GetProcessHeap(), 0, pCmdLine);
220 return;
221 }
222
223 hResult = IIDFromString(pStr, &Guids[Index]);
224 if (hResult != S_OK)
225 {
226 // invalid parameter
227 HeapFree(GetProcessHeap(), 0, pCmdLine);
228 return;
229 }
230
231 Index++;
232 pStr = wcstok(NULL, L",\t\"");
233
234
235 }while(Index < 2);
236
237
238 dwResult = InstallSoftwareDeviceInterface(&Guids[0], &Guids[1], pStr);
239 if (dwResult == ERROR_SUCCESS)
240 {
241 pStr = wcstok(NULL, L",\t\"");
242 if (pStr != NULL)
243 {
244 wcscpy(DevicePath, pStr);
245 pStr = wcstok(NULL, L",\t\"");
246 if (pStr != NULL)
247 {
248 dwResult = InstallSoftwareDeviceInterfaceInf(DevicePath, pStr);
249 }
250 }
251 }
252}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HRESULT WINAPI IIDFromString(LPCOLESTR s, IID *iid)
Definition: compobj.c:2374
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2780
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2292
HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, DWORD Reserved, REGSAM samDesired, HINF InfHandle, PCWSTR InfSectionName)
Definition: devinst.c:2613
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, DWORD DeviceInterfaceDetailDataSize, PDWORD RequiredSize, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:3011
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define S_OK
Definition: intsafe.h:52
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:221
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
static HINSTANCE hinst
Definition: edit.c:551
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define GENERIC_WRITE
Definition: nt_native.h:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STRSAFE_NULL_ON_FAILURE
Definition: ntstrsafe.h:34
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_Check_return_ _CRTIMP wchar_t *__cdecl wcstok(_Inout_opt_z_ wchar_t *_Str, _In_z_ const wchar_t *_Delim)
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
#define DIGCF_PRESENT
Definition: setupapi.h:171
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W * PSP_DEVICE_INTERFACE_DETAIL_DATA_W
struct _SP_DEVICE_INTERFACE_DATA SP_DEVICE_INTERFACE_DATA
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:81
VOID WINAPI StreamingDeviceSetupW(IN HWND hwnd, IN HINSTANCE hinst, IN LPWSTR lpszCmdLine, IN int nCmdShow)
Definition: streamci.c:182
DWORD InstallSoftwareDeviceInterfaceInf(IN LPWSTR InfName, IN LPWSTR SectionName)
Definition: streamci.c:134
DWORD InstallSoftwareDeviceInterface(IN LPGUID DeviceId, IN LPGUID InterfaceId, IN LPWSTR ReferenceString)
Definition: streamci.c:56
DWORD PerformIO(IN HANDLE hDevice, IN DWORD dwCtlCode, IN LPVOID lpBufferIn, IN DWORD dwBufferSizeIn, OUT LPVOID lpBufferOut, OUT DWORD dwBufferSizeOut, OUT LPDWORD lpNumberBytes)
Definition: streamci.c:13
STRSAFEAPI StringCbCopyExW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:210
WCHAR DevicePath[ANYSIZE_ARRAY]
Definition: setupapi.h:855
WCHAR ReferenceString[1]
Definition: swenum.h:18
#define STATIC_BUSID_SoftwareDeviceEnumerator
Definition: swenum.h:25
#define IOCTL_SWENUM_INSTALL_INTERFACE
Definition: swenum.h:6
struct _SWENUM_INSTALL_INTERFACE * PSWENUM_INSTALL_INTERFACE
struct _SWENUM_INSTALL_INTERFACE SWENUM_INSTALL_INTERFACE
uint32_t * LPDWORD
Definition: typedefs.h:59
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ CONST GUID _In_opt_ PCUNICODE_STRING ReferenceString
Definition: wdfdevice.h:3630
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateEvent
Definition: winbase.h:3683
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184