ReactOS  0.4.15-dev-439-g292f67a
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 
12 DWORD
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 
24  ZeroMemory(&overlapped, sizeof(OVERLAPPED));
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 
55 DWORD
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 
133 DWORD
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);
172  if (hKey != INVALID_HANDLE_VALUE)
173  {
174  RegCloseKey(hKey);
175  }
176  return ERROR_SUCCESS;
177 }
178 
179 
180 VOID
181 WINAPI
183  IN HINSTANCE hinst,
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 CreateEvent
Definition: winbase.h:3588
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:407
#define IOCTL_SWENUM_INSTALL_INTERFACE
Definition: swenum.h:6
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define ERROR_SUCCESS
Definition: deptool.c:10
WCHAR DevicePath[ANYSIZE_ARRAY]
Definition: setupapi.h:850
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2297
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
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:3016
_Check_return_ _CRTIMP wchar_t *__cdecl wcstok(_Inout_opt_z_ wchar_t *_Str, _In_z_ const wchar_t *_Delim)
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1648
HKEY WINAPI SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, DWORD Reserved, REGSAM samDesired, HINF InfHandle, PCWSTR InfSectionName)
Definition: devinst.c:2618
DWORD InstallSoftwareDeviceInterface(IN LPGUID DeviceId, IN LPGUID InterfaceId, IN LPWSTR ReferenceString)
Definition: streamci.c:56
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
#define ERROR_IO_PENDING
Definition: dderror.h:15
STRSAFEAPI StringCbCopyExW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:210
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
DWORD InstallSoftwareDeviceInterfaceInf(IN LPWSTR InfName, IN LPWSTR SectionName)
Definition: streamci.c:134
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
VOID WINAPI StreamingDeviceSetupW(IN HWND hwnd, IN HINSTANCE hinst, IN LPWSTR lpszCmdLine, IN int nCmdShow)
Definition: streamci.c:182
#define GENERIC_WRITE
Definition: nt_native.h:90
_In_ CONST GUID _In_opt_ PUNICODE_STRING ReferenceString
Definition: iofuncs.h:1134
struct _SWENUM_INSTALL_INTERFACE * PSWENUM_INSTALL_INTERFACE
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:435
WCHAR ReferenceString[1]
Definition: swenum.h:18
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
HRESULT WINAPI IIDFromString(LPCOLESTR s, IID *iid)
Definition: compobj.c:2374
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:6
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W * PSP_DEVICE_INTERFACE_DETAIL_DATA_W
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:82
#define S_OK
Definition: intsafe.h:59
#define STATIC_BUSID_SoftwareDeviceEnumerator
Definition: swenum.h:25
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 KEY_ALL_ACCESS
Definition: nt_native.h:1041
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
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
#define CreateFileW
Definition: compat.h:409
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
#define STRSAFE_NULL_ON_FAILURE
Definition: ntstrsafe.h:34
#define OUT
Definition: typedefs.h:40
uint32_t * LPDWORD
Definition: typedefs.h:58
struct _SP_DEVICE_INTERFACE_DATA SP_DEVICE_INTERFACE_DATA
static HINSTANCE hinst
Definition: edit.c:551
struct _SWENUM_INSTALL_INTERFACE SWENUM_INSTALL_INTERFACE
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:403
#define DIGCF_PRESENT
Definition: setupapi.h:171