c1ed6601840ed7abe9f8cf1c3307db7a4f0f23af
[reactos.git] / reactos / drivers / net / wshtcpip / wshtcpip.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock Helper DLL for TCP/IP
4 * FILE: wshtcpip.c
5 * PURPOSE: DLL entry
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/09-2000 Created
9 */
10 #include <wshtcpip.h>
11
12 #ifdef DBG
13
14 /* See debug.h for debug/trace constants */
15 DWORD DebugTraceLevel = MAX_TRACE;
16
17 #endif /* DBG */
18
19 /* To make the linker happy */
20 VOID STDCALL KeBugCheck (ULONG BugCheckCode) {}
21
22
23 BOOL
24 EXPORT
25 DllMain(HANDLE hInstDll,
26 ULONG dwReason,
27 PVOID Reserved)
28 {
29 WSH_DbgPrint(MIN_TRACE, ("DllMain of wshtcpip.dll\n"));
30
31 switch (dwReason) {
32 case DLL_PROCESS_ATTACH:
33 /* Don't need thread attach notifications
34 so disable them to improve performance */
35 DisableThreadLibraryCalls(hInstDll);
36 break;
37
38 case DLL_THREAD_ATTACH:
39 break;
40
41 case DLL_THREAD_DETACH:
42 break;
43
44 case DLL_PROCESS_DETACH:
45 break;
46 }
47 return TRUE;
48 }
49
50
51 INT
52 EXPORT
53 WSHAddressToString(
54 IN LPSOCKADDR Address,
55 IN INT AddressLength,
56 IN LPWSAPROTOCOL_INFOW ProtocolInfo OPTIONAL,
57 OUT LPWSTR AddressString,
58 IN OUT LPDWORD AddressStringLength)
59 {
60 UNIMPLEMENTED
61
62 return 0;
63 }
64
65
66 INT
67 EXPORT
68 WSHEnumProtocols(
69 IN LPINT lpiProtocols OPTIONAL,
70 IN LPWSTR lpTransportKeyName,
71 IN OUT LPVOID lpProtocolBuffer,
72 IN OUT LPDWORD lpdwBufferLength)
73 {
74 UNIMPLEMENTED
75
76 return 0;
77 }
78
79
80 INT
81 EXPORT
82 WSHGetBroadcastSockaddr(
83 IN PVOID HelperDllSocketContext,
84 OUT PSOCKADDR Sockaddr,
85 OUT PINT SockaddrLength)
86 {
87 UNIMPLEMENTED
88
89 return 0;
90 }
91
92
93 INT
94 EXPORT
95 WSHGetProviderGuid(
96 IN LPWSTR ProviderName,
97 OUT LPGUID ProviderGuid)
98 {
99 UNIMPLEMENTED
100
101 return 0;
102 }
103
104
105 INT
106 EXPORT
107 WSHGetSockaddrType(
108 IN PSOCKADDR Sockaddr,
109 IN DWORD SockaddrLength,
110 OUT PSOCKADDR_INFO SockaddrInfo)
111 {
112 UNIMPLEMENTED
113
114 return 0;
115 }
116
117
118 INT
119 EXPORT
120 WSHGetSocketInformation(
121 IN PVOID HelperDllSocketContext,
122 IN SOCKET SocketHandle,
123 IN HANDLE TdiAddressObjectHandle,
124 IN HANDLE TdiConnectionObjectHandle,
125 IN INT Level,
126 IN INT OptionName,
127 OUT PCHAR OptionValue,
128 OUT INT OptionLength)
129 {
130 UNIMPLEMENTED
131
132 return 0;
133 }
134
135
136 INT
137 EXPORT
138 WSHGetWildcardSockaddr(
139 IN PVOID HelperDllSocketContext,
140 OUT PSOCKADDR Sockaddr,
141 OUT PINT SockaddrLength)
142 {
143 RtlZeroMemory((PVOID)Sockaddr, *SockaddrLength);
144 Sockaddr->sa_family = AF_INET;
145 return 0;
146 }
147
148
149 DWORD
150 EXPORT
151 WSHGetWinsockMapping(
152 OUT PWINSOCK_MAPPING Mapping,
153 IN DWORD MappingLength)
154 {
155 UNIMPLEMENTED
156
157 return 0;
158 }
159
160
161 INT
162 EXPORT
163 WSHGetWSAProtocolInfo(
164 IN LPWSTR ProviderName,
165 OUT LPWSAPROTOCOL_INFOW *ProtocolInfo,
166 OUT LPDWORD ProtocolInfoEntries)
167 {
168 UNIMPLEMENTED
169
170 return 0;
171 }
172
173
174 INT
175 EXPORT
176 WSHIoctl(
177 IN PVOID HelperDllSocketContext,
178 IN SOCKET SocketHandle,
179 IN HANDLE TdiAddressObjectHandle,
180 IN HANDLE TdiConnectionObjectHandle,
181 IN DWORD IoControlCode,
182 IN LPVOID InputBuffer,
183 IN DWORD InputBufferLength,
184 IN LPVOID OutputBuffer,
185 IN DWORD OutputBufferLength,
186 OUT LPDWORD NumberOfBytesReturned,
187 IN LPWSAOVERLAPPED Overlapped,
188 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine,
189 OUT LPBOOL NeedsCompletion)
190 {
191 UNIMPLEMENTED
192
193 return 0;
194 }
195
196
197 INT
198 EXPORT
199 WSHJoinLeaf(
200 IN PVOID HelperDllSocketContext,
201 IN SOCKET SocketHandle,
202 IN HANDLE TdiAddressObjectHandle,
203 IN HANDLE TdiConnectionObjectHandle,
204 IN PVOID LeafHelperDllSocketContext,
205 IN SOCKET LeafSocketHandle,
206 IN PSOCKADDR Sockaddr,
207 IN DWORD SockaddrLength,
208 IN LPWSABUF CallerData,
209 IN LPWSABUF CalleeData,
210 IN LPQOS SocketQOS,
211 IN LPQOS GroupQOS,
212 IN DWORD Flags)
213 {
214 UNIMPLEMENTED
215
216 return 0;
217 }
218
219
220 INT
221 EXPORT
222 WSHNotify(
223 IN PVOID HelperDllSocketContext,
224 IN SOCKET SocketHandle,
225 IN HANDLE TdiAddressObjectHandle,
226 IN HANDLE TdiConnectionObjectHandle,
227 IN DWORD NotifyEvent)
228 {
229 UNIMPLEMENTED
230
231 return 0;
232 }
233
234
235 INT
236 EXPORT
237 WSHOpenSocket(
238 IN OUT PINT AddressFamily,
239 IN OUT PINT SocketType,
240 IN OUT PINT Protocol,
241 OUT PUNICODE_STRING TransportDeviceName,
242 OUT PVOID HelperDllSocketContext,
243 OUT PDWORD NotificationEvents)
244 /*
245 * FUNCTION: Opens a socket
246 */
247 {
248 return WSHOpenSocket2(AddressFamily,
249 SocketType,
250 Protocol,
251 0,
252 0,
253 TransportDeviceName,
254 HelperDllSocketContext,
255 NotificationEvents);
256 }
257
258
259 INT
260 EXPORT
261 WSHOpenSocket2(
262 OUT PINT AddressFamily,
263 IN OUT PINT SocketType,
264 IN OUT PINT Protocol,
265 IN GROUP Group,
266 IN DWORD Flags,
267 OUT PUNICODE_STRING TransportDeviceName,
268 OUT PVOID *HelperDllSocketContext,
269 OUT PDWORD NotificationEvents)
270 /*
271 * FUNCTION: Opens a socket
272 * ARGUMENTS:
273 * AddressFamily = Address of buffer with address family (updated)
274 * SocketType = Address of buffer with type of socket (updated)
275 * Protocol = Address of buffer with protocol number (updated)
276 * Group = Socket group
277 * Flags = Socket flags
278 * TransportDeviceName = Address of buffer to place name of transport device
279 * HelperDllSocketContext = Address of buffer to place socket context pointer
280 * NotificationEvents = Address of buffer to place flags for event notification
281 * RETURNS:
282 * Status of operation
283 * NOTES:
284 * Mapping tripple is returned in an canonicalized form
285 */
286 {
287 PSOCKET_CONTEXT Context;
288 UNICODE_STRING String;
289 UNICODE_STRING TcpDeviceName = RTL_CONSTANT_STRING(DD_TCP_DEVICE_NAME);
290 UNICODE_STRING UdpDeviceName = RTL_CONSTANT_STRING(DD_UDP_DEVICE_NAME);
291 UNICODE_STRING RawDeviceName = RTL_CONSTANT_STRING(DD_RAW_IP_DEVICE_NAME);
292 NTSTATUS Status;
293
294 WSH_DbgPrint(MAX_TRACE, ("\n"));
295
296 switch (*SocketType) {
297 case SOCK_STREAM:
298 String = TcpDeviceName;
299 break;
300
301 case SOCK_DGRAM:
302 String = UdpDeviceName;
303 break;
304
305 case SOCK_RAW:
306 if ((*Protocol < 0) || (*Protocol > 255))
307 return WSAEINVAL;
308
309 String = RawDeviceName;
310 break;
311
312 default:
313 return WSAEINVAL;
314 }
315
316 RtlInitUnicodeString(TransportDeviceName, NULL);
317
318 TransportDeviceName->MaximumLength = String.Length + /* Transport device name */
319 (4 * sizeof(WCHAR) + /* Separator and protocol */
320 sizeof(UNICODE_NULL)); /* Terminating null */
321
322 TransportDeviceName->Buffer = HeapAlloc(
323 GetProcessHeap(),
324 0,
325 TransportDeviceName->MaximumLength);
326
327 if (!TransportDeviceName->Buffer)
328 return WSAENOBUFS;
329
330 /* Append the transport device name */
331 Status = RtlAppendUnicodeStringToString(TransportDeviceName, &String);
332
333 if (*SocketType == SOCK_RAW) {
334 /* Append a separator */
335 TransportDeviceName->Buffer[TransportDeviceName->Length / sizeof(WCHAR)] = OBJ_NAME_PATH_SEPARATOR;
336 TransportDeviceName->Length += sizeof(WCHAR);
337 TransportDeviceName->Buffer[TransportDeviceName->Length / sizeof(WCHAR)] = UNICODE_NULL;
338
339 /* Append the protocol number */
340 String.Buffer = TransportDeviceName->Buffer + (TransportDeviceName->Length / sizeof(WCHAR));
341 String.Length = 0;
342 String.MaximumLength = TransportDeviceName->MaximumLength - TransportDeviceName->Length;
343
344 Status = RtlIntegerToUnicodeString((ULONG)*Protocol, 10, &String);
345
346 TransportDeviceName->Length += String.Length;
347 }
348
349 /* Setup a socket context area */
350
351 Context = HeapAlloc(GetProcessHeap(), 0, sizeof(SOCKET_CONTEXT));
352 if (!Context) {
353 RtlFreeUnicodeString(TransportDeviceName);
354 return WSAENOBUFS;
355 }
356
357 Context->AddressFamily = *AddressFamily;
358 Context->SocketType = *SocketType;
359 Context->Protocol = *Protocol;
360 Context->Flags = Flags;
361
362 *HelperDllSocketContext = Context;
363
364 return NO_ERROR;
365 }
366
367
368 INT
369 EXPORT
370 WSHSetSocketInformation(
371 IN PVOID HelperDllSocketContext,
372 IN SOCKET SocketHandle,
373 IN HANDLE TdiAddressObjectHandle,
374 IN HANDLE TdiConnectionObjectHandle,
375 IN INT Level,
376 IN INT OptionName,
377 IN PCHAR OptionValue,
378 IN INT OptionLength)
379 {
380 UNIMPLEMENTED
381
382 return 0;
383 }
384
385
386 INT
387 EXPORT
388 WSHStringToAddress(
389 IN LPWSTR AddressString,
390 IN DWORD AddressFamily,
391 IN LPWSAPROTOCOL_INFOW ProtocolInfo OPTIONAL,
392 OUT LPSOCKADDR Address,
393 IN OUT LPDWORD AddressStringLength)
394 {
395 UNIMPLEMENTED
396
397 return 0;
398 }
399
400 /* EOF */