VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetFlt/win/ndis6/VBoxNetAdp-win.cpp@ 56262

Last change on this file since 56262 was 53624, checked in by vboxsync, 10 years ago

scm automatic cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.2 KB
Line 
1/* $Id: VBoxNetAdp-win.cpp 53624 2014-12-31 14:59:44Z vboxsync $ */
2/** @file
3 * VBoxNetAdp-win.cpp - NDIS6 Host-only Networking Driver, Windows-specific code.
4 */
5/*
6 * Copyright (C) 2014 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#define LOG_GROUP LOG_GROUP_NET_ADP_DRV
18
19#include <VBox/log.h>
20#include <VBox/version.h>
21#include <VBox/err.h>
22#include <iprt/initterm.h>
23#include <iprt/assert.h>
24
25RT_C_DECLS_BEGIN
26#include <ndis.h>
27RT_C_DECLS_END
28
29#include "VBoxNetAdp-win.h"
30#include "VBoxNetCmn-win.h"
31
32/* Forward declarations */
33MINIPORT_INITIALIZE vboxNetAdpWinInitializeEx;
34MINIPORT_HALT vboxNetAdpWinHaltEx;
35MINIPORT_UNLOAD vboxNetAdpWinUnload;
36MINIPORT_PAUSE vboxNetAdpWinPause;
37MINIPORT_RESTART vboxNetAdpWinRestart;
38MINIPORT_OID_REQUEST vboxNetAdpWinOidRequest;
39MINIPORT_SEND_NET_BUFFER_LISTS vboxNetAdpWinSendNetBufferLists;
40MINIPORT_RETURN_NET_BUFFER_LISTS vboxNetAdpWinReturnNetBufferLists;
41MINIPORT_CANCEL_SEND vboxNetAdpWinCancelSend;
42MINIPORT_CHECK_FOR_HANG vboxNetAdpWinCheckForHangEx;
43MINIPORT_RESET vboxNetAdpWinResetEx;
44MINIPORT_DEVICE_PNP_EVENT_NOTIFY vboxNetAdpWinDevicePnPEventNotify;
45MINIPORT_SHUTDOWN vboxNetAdpWinShutdownEx;
46MINIPORT_CANCEL_OID_REQUEST vboxNetAdpWinCancelOidRequest;
47
48
49typedef struct _VBOXNETADPGLOBALS
50{
51 /** ndis device */
52 NDIS_HANDLE hDevice;
53 /** device object */
54 PDEVICE_OBJECT pDevObj;
55 /** our miniport driver handle */
56 NDIS_HANDLE hMiniportDriver;
57 /** power management capabilities, shared by all instances, do not change after init */
58 NDIS_PNP_CAPABILITIES PMCaps;
59} VBOXNETADPGLOBALS, *PVBOXNETADPGLOBALS;
60
61/* win-specific global data */
62VBOXNETADPGLOBALS g_VBoxNetAdpGlobals;
63
64
65typedef struct _VBOXNETADP_ADAPTER {
66 NDIS_HANDLE hAdapter;
67 PVBOXNETADPGLOBALS pGlobals;
68 RTMAC MacAddr;
69} VBOXNETADP_ADAPTER;
70typedef VBOXNETADP_ADAPTER *PVBOXNETADP_ADAPTER;
71
72
73static NTSTATUS vboxNetAdpWinDevDispatch(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
74{
75 PIO_STACK_LOCATION pIrpSl = IoGetCurrentIrpStackLocation(pIrp);;
76 NTSTATUS Status = STATUS_SUCCESS;
77
78 switch (pIrpSl->MajorFunction)
79 {
80 case IRP_MJ_DEVICE_CONTROL:
81 Status = STATUS_NOT_SUPPORTED; // TODO: add/remove ioctls
82 break;
83 case IRP_MJ_CREATE:
84 case IRP_MJ_CLEANUP:
85 case IRP_MJ_CLOSE:
86 break;
87 default:
88 Assert(0);
89 break;
90 }
91
92 pIrp->IoStatus.Status = Status;
93 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
94
95 return Status;
96}
97
98static NDIS_STATUS vboxNetAdpWinDevCreate(PVBOXNETADPGLOBALS pGlobals)
99{
100 NDIS_STRING DevName, LinkName;
101 PDRIVER_DISPATCH aMajorFunctions[IRP_MJ_MAXIMUM_FUNCTION+1];
102 NdisInitUnicodeString(&DevName, VBOXNETADP_NAME_DEVICE);
103 NdisInitUnicodeString(&LinkName, VBOXNETADP_NAME_LINK);
104
105 Assert(!pGlobals->hDevice);
106 Assert(!pGlobals->pDevObj);
107 NdisZeroMemory(aMajorFunctions, sizeof (aMajorFunctions));
108 aMajorFunctions[IRP_MJ_CREATE] = vboxNetAdpWinDevDispatch;
109 aMajorFunctions[IRP_MJ_CLEANUP] = vboxNetAdpWinDevDispatch;
110 aMajorFunctions[IRP_MJ_CLOSE] = vboxNetAdpWinDevDispatch;
111 aMajorFunctions[IRP_MJ_DEVICE_CONTROL] = vboxNetAdpWinDevDispatch;
112
113 NDIS_DEVICE_OBJECT_ATTRIBUTES DeviceAttributes;
114 NdisZeroMemory(&DeviceAttributes, sizeof(DeviceAttributes));
115 DeviceAttributes.Header.Type = NDIS_OBJECT_TYPE_DEVICE_OBJECT_ATTRIBUTES;
116 DeviceAttributes.Header.Revision = NDIS_DEVICE_OBJECT_ATTRIBUTES_REVISION_1;
117 DeviceAttributes.Header.Size = sizeof(DeviceAttributes);
118 DeviceAttributes.DeviceName = &DevName;
119 DeviceAttributes.SymbolicName = &LinkName;
120 DeviceAttributes.MajorFunctions = aMajorFunctions;
121
122 NDIS_STATUS Status = NdisRegisterDeviceEx(pGlobals->hMiniportDriver,
123 &DeviceAttributes,
124 &pGlobals->pDevObj,
125 &pGlobals->hDevice);
126 Log(("vboxNetAdpWinDevCreate: NdisRegisterDeviceEx returned 0x%x\n", Status));
127 Assert(Status == NDIS_STATUS_SUCCESS);
128 return Status;
129}
130
131static void vboxNetAdpWinDevDestroy(PVBOXNETADPGLOBALS pGlobals)
132{
133 Assert(pGlobals->hDevice);
134 Assert(pGlobals->pDevObj);
135 NdisDeregisterDeviceEx(pGlobals->hDevice);
136 pGlobals->hDevice = NULL;
137 pGlobals->pDevObj = NULL;
138}
139
140
141
142
143
144NDIS_OID g_SupportedOids[] =
145{
146 OID_GEN_CURRENT_LOOKAHEAD,
147 OID_GEN_CURRENT_PACKET_FILTER,
148 OID_GEN_INTERRUPT_MODERATION,
149 OID_GEN_LINK_PARAMETERS,
150 OID_GEN_MAXIMUM_TOTAL_SIZE,
151 OID_GEN_RCV_OK,
152 OID_GEN_RECEIVE_BLOCK_SIZE,
153 OID_GEN_RECEIVE_BUFFER_SPACE,
154 OID_GEN_STATISTICS,
155 OID_GEN_TRANSMIT_BLOCK_SIZE,
156 OID_GEN_TRANSMIT_BUFFER_SPACE,
157 OID_GEN_VENDOR_DESCRIPTION,
158 OID_GEN_VENDOR_DRIVER_VERSION,
159 OID_GEN_VENDOR_ID,
160 OID_GEN_XMIT_OK,
161 OID_802_3_PERMANENT_ADDRESS,
162 OID_802_3_CURRENT_ADDRESS,
163 OID_802_3_MULTICAST_LIST,
164 OID_802_3_MAXIMUM_LIST_SIZE,
165 OID_PNP_CAPABILITIES,
166 OID_PNP_QUERY_POWER,
167 OID_PNP_SET_POWER
168};
169
170DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinAllocAdapter(NDIS_HANDLE hAdapter, PVBOXNETADP_ADAPTER *ppAdapter, ULONG64 NetLuid)
171{
172 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
173 PVBOXNETADP_ADAPTER pAdapter = NULL;
174
175 LogFlow(("==>"__FUNCTION__": adapter handle=%p\n", hAdapter));
176
177 *ppAdapter = NULL;
178
179 pAdapter = (PVBOXNETADP_ADAPTER)NdisAllocateMemoryWithTagPriority(g_VBoxNetAdpGlobals.hMiniportDriver,
180 sizeof(VBOXNETADP_ADAPTER),
181 VBOXNETADPWIN_TAG,
182 NormalPoolPriority);
183 if (!pAdapter)
184 {
185 Status = NDIS_STATUS_RESOURCES;
186 Log((__FUNCTION__": Out of memory while allocating adapter context (size=%d)\n", sizeof(VBOXNETADP_ADAPTER)));
187 }
188 else
189 {
190 NdisZeroMemory(pAdapter, sizeof(VBOXNETADP_ADAPTER));
191 pAdapter->hAdapter = hAdapter;
192 pAdapter->pGlobals = &g_VBoxNetAdpGlobals;
193 // TODO: Use netadp structure instead!
194 /* Use a locally administered version of the OUI we use for the guest NICs. */
195 pAdapter->MacAddr.au8[0] = 0x08 | 2;
196 pAdapter->MacAddr.au8[1] = 0x00;
197 pAdapter->MacAddr.au8[2] = 0x27;
198
199 pAdapter->MacAddr.au8[3] = (NetLuid >> 16) & 0xFF;
200 pAdapter->MacAddr.au8[4] = (NetLuid >> 8) & 0xFF;
201 pAdapter->MacAddr.au8[5] = NetLuid & 0xFF;
202
203 //TODO: Statistics?
204
205 *ppAdapter = pAdapter;
206 }
207 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
208 return Status;
209}
210
211DECLHIDDEN(void) vboxNetAdpWinFreeAdapter(PVBOXNETADP_ADAPTER pAdapter)
212{
213 NdisFreeMemory(pAdapter, 0, 0);
214}
215
216DECLINLINE(NDIS_MEDIA_CONNECT_STATE) vboxNetAdpWinGetConnectState(PVBOXNETADP_ADAPTER pAdapter)
217{
218 return MediaConnectStateConnected;
219}
220
221
222DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinInitializeEx(IN NDIS_HANDLE NdisMiniportHandle,
223 IN NDIS_HANDLE MiniportDriverContext,
224 IN PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters)
225{
226 PVBOXNETADP_ADAPTER pAdapter = NULL;
227 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
228
229 LogFlow(("==>"__FUNCTION__": miniport=0x%x\n", NdisMiniportHandle));
230
231 do
232 {
233 NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES RAttrs = {0};
234 NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES GAttrs = {0};
235
236 Status = vboxNetAdpWinAllocAdapter(NdisMiniportHandle, &pAdapter, MiniportInitParameters->NetLuid.Value);
237 if (Status != NDIS_STATUS_SUCCESS)
238 {
239 Log((__FUNCTION__": Failed to allocate the adapter context with 0x%x\n", Status));
240 break;
241 }
242
243 RAttrs.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;
244 RAttrs.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
245 RAttrs.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
246 RAttrs.MiniportAdapterContext = pAdapter;
247 RAttrs.AttributeFlags = VBOXNETADPWIN_ATTR_FLAGS; // NDIS_MINIPORT_ATTRIBUTES_NDIS_WDM
248 RAttrs.CheckForHangTimeInSeconds = VBOXNETADPWIN_HANG_CHECK_TIME;
249 RAttrs.InterfaceType = NdisInterfaceInternal;
250
251 Status = NdisMSetMiniportAttributes(NdisMiniportHandle,
252 (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&RAttrs);
253 if (Status != NDIS_STATUS_SUCCESS)
254 {
255 Log((__FUNCTION__": NdisMSetMiniportAttributes(registration) failed with 0x%x\n", Status));
256 break;
257 }
258
259 // TODO: Registry?
260
261 // TODO: WDM stack?
262
263 // TODO: DPC?
264
265 GAttrs.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
266 GAttrs.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
267 GAttrs.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
268
269 GAttrs.MediaType = NdisMedium802_3;
270 GAttrs.PhysicalMediumType = NdisPhysicalMediumUnspecified;
271 GAttrs.MtuSize = 1500; //TODO
272 GAttrs.MaxXmitLinkSpeed = 1000000000ULL;
273 GAttrs.XmitLinkSpeed = 1000000000ULL;
274 GAttrs.MaxRcvLinkSpeed = 1000000000ULL;
275 GAttrs.RcvLinkSpeed = 1000000000ULL;
276 GAttrs.MediaConnectState = vboxNetAdpWinGetConnectState(pAdapter);
277 GAttrs.MediaDuplexState = MediaDuplexStateFull;
278 GAttrs.LookaheadSize = 1500; //TODO
279 GAttrs.MacOptions = VBOXNETADP_MAC_OPTIONS;
280 GAttrs.SupportedPacketFilters = VBOXNETADP_SUPPORTED_FILTERS;
281 GAttrs.MaxMulticastListSize = 32; //TODO
282
283 GAttrs.MacAddressLength = ETH_LENGTH_OF_ADDRESS;
284 Assert(GAttrs.MacAddressLength == sizeof(pAdapter->MacAddr));
285 memcpy(GAttrs.PermanentMacAddress, pAdapter->MacAddr.au8, GAttrs.MacAddressLength);
286 memcpy(GAttrs.CurrentMacAddress, pAdapter->MacAddr.au8, GAttrs.MacAddressLength);
287
288 GAttrs.RecvScaleCapabilities = NULL;
289 GAttrs.AccessType = NET_IF_ACCESS_BROADCAST;
290 GAttrs.DirectionType = NET_IF_DIRECTION_SENDRECEIVE;
291 GAttrs.ConnectionType = NET_IF_CONNECTION_DEDICATED;
292 GAttrs.IfType = IF_TYPE_ETHERNET_CSMACD;
293 GAttrs.IfConnectorPresent = false;
294 GAttrs.SupportedStatistics = VBOXNETADPWIN_SUPPORTED_STATISTICS;
295 GAttrs.SupportedPauseFunctions = NdisPauseFunctionsUnsupported;
296 GAttrs.DataBackFillSize = 0;
297 GAttrs.ContextBackFillSize = 0;
298 GAttrs.SupportedOidList = g_SupportedOids;
299 GAttrs.SupportedOidListLength = sizeof(g_SupportedOids);
300 GAttrs.AutoNegotiationFlags = NDIS_LINK_STATE_DUPLEX_AUTO_NEGOTIATED;
301 GAttrs.PowerManagementCapabilities = &g_VBoxNetAdpGlobals.PMCaps;
302
303 Status = NdisMSetMiniportAttributes(NdisMiniportHandle,
304 (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&GAttrs);
305 if (Status != NDIS_STATUS_SUCCESS)
306 {
307 Log((__FUNCTION__": NdisMSetMiniportAttributes(general) failed with 0x%x\n", Status));
308 break;
309 }
310 } while (false);
311
312 if (Status != NDIS_STATUS_SUCCESS)
313 {
314 if (pAdapter)
315 vboxNetAdpWinFreeAdapter(pAdapter);
316 }
317
318 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
319 return Status;
320}
321
322DECLHIDDEN(VOID) vboxNetAdpWinHaltEx(IN NDIS_HANDLE MiniportAdapterContext,
323 IN NDIS_HALT_ACTION HaltAction)
324{
325 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
326 LogFlow(("==>"__FUNCTION__"\n"));
327 // TODO: Stop something?
328 LogFlow(("<=="__FUNCTION__"\n"));
329}
330
331DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinPause(IN NDIS_HANDLE MiniportAdapterContext,
332 IN PNDIS_MINIPORT_PAUSE_PARAMETERS MiniportPauseParameters)
333{
334 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
335 LogFlow(("==>"__FUNCTION__"\n"));
336 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
337 return Status;
338}
339
340DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinRestart(IN NDIS_HANDLE MiniportAdapterContext,
341 IN PNDIS_MINIPORT_RESTART_PARAMETERS MiniportRestartParameters)
342{
343 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
344 LogFlow(("==>"__FUNCTION__"\n"));
345 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
346 return Status;
347}
348
349DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinOidRqQuery(PVBOXNETADP_ADAPTER pAdapter,
350 PNDIS_OID_REQUEST pRequest)
351{
352 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
353 struct _NDIS_OID_REQUEST::_REQUEST_DATA::_QUERY *pQuery = &pRequest->DATA.QUERY_INFORMATION;
354
355 LogFlow(("==>"__FUNCTION__"\n"));
356
357 uint64_t u64Tmp = 0;
358 ULONG ulTmp = 0;
359 PVOID pInfo = &ulTmp;
360 ULONG cbInfo = sizeof(ulTmp);
361
362 switch (pQuery->Oid)
363 {
364 case OID_GEN_INTERRUPT_MODERATION:
365 {
366 PNDIS_INTERRUPT_MODERATION_PARAMETERS pParams =
367 (PNDIS_INTERRUPT_MODERATION_PARAMETERS)pQuery->InformationBuffer;
368 cbInfo = NDIS_SIZEOF_INTERRUPT_MODERATION_PARAMETERS_REVISION_1;
369 if (cbInfo > pQuery->InformationBufferLength)
370 break;
371 pParams->Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
372 pParams->Header.Revision = NDIS_INTERRUPT_MODERATION_PARAMETERS_REVISION_1;
373 pParams->Header.Size = NDIS_SIZEOF_INTERRUPT_MODERATION_PARAMETERS_REVISION_1;
374 pParams->Flags = 0;
375 pParams->InterruptModeration = NdisInterruptModerationNotSupported;
376 pInfo = NULL; /* Do not copy */
377 break;
378 }
379 case OID_GEN_MAXIMUM_TOTAL_SIZE:
380 case OID_GEN_RECEIVE_BLOCK_SIZE:
381 case OID_GEN_TRANSMIT_BLOCK_SIZE:
382 ulTmp = VBOXNETADP_MAX_FRAME_SIZE;
383 break;
384 case OID_GEN_RCV_OK:
385 case OID_GEN_XMIT_OK:
386 u64Tmp = 0;
387 pInfo = &u64Tmp;
388 cbInfo = sizeof(u64Tmp);
389 break;
390 case OID_GEN_RECEIVE_BUFFER_SPACE:
391 case OID_GEN_TRANSMIT_BUFFER_SPACE:
392 // TODO: Make configurable
393 ulTmp = VBOXNETADP_MAX_FRAME_SIZE * 40;
394 break;
395 case OID_GEN_STATISTICS:
396 {
397 PNDIS_STATISTICS_INFO pStats =
398 (PNDIS_STATISTICS_INFO)pQuery->InformationBuffer;
399 cbInfo = NDIS_SIZEOF_STATISTICS_INFO_REVISION_1;
400 if (cbInfo > pQuery->InformationBufferLength)
401 break;
402 pInfo = NULL; /* Do not copy */
403 memset(pStats, 0, cbInfo);
404 pStats->Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
405 pStats->Header.Revision = NDIS_STATISTICS_INFO_REVISION_1;
406 pStats->Header.Size = NDIS_SIZEOF_STATISTICS_INFO_REVISION_1;
407 // TODO: We need some stats, don't we?
408 break;
409 }
410 case OID_GEN_VENDOR_DESCRIPTION:
411 pInfo = VBOXNETADP_VENDOR_NAME;
412 cbInfo = sizeof(VBOXNETADP_VENDOR_NAME);
413 break;
414 case OID_GEN_VENDOR_DRIVER_VERSION:
415 ulTmp = (VBOXNETADP_VERSION_NDIS_MAJOR << 16) | VBOXNETADP_VERSION_NDIS_MINOR;
416 break;
417 case OID_GEN_VENDOR_ID:
418 ulTmp = VBOXNETADP_VENDOR_ID;
419 break;
420 case OID_802_3_PERMANENT_ADDRESS:
421 case OID_802_3_CURRENT_ADDRESS:
422 pInfo = &pAdapter->MacAddr;
423 cbInfo = sizeof(pAdapter->MacAddr);
424 break;
425 //case OID_802_3_MULTICAST_LIST:
426 case OID_802_3_MAXIMUM_LIST_SIZE:
427 ulTmp = VBOXNETADP_MCAST_LIST_SIZE;
428 break;
429 case OID_PNP_CAPABILITIES:
430 pInfo = &pAdapter->pGlobals->PMCaps;
431 cbInfo = sizeof(pAdapter->pGlobals->PMCaps);
432 break;
433 case OID_PNP_QUERY_POWER:
434 pInfo = NULL; /* Do not copy */
435 cbInfo = 0;
436 break;
437 default:
438 Status = NDIS_STATUS_NOT_SUPPORTED;
439 break;
440 }
441
442 if (Status == NDIS_STATUS_SUCCESS)
443 {
444 if (cbInfo > pQuery->InformationBufferLength)
445 {
446 pQuery->BytesNeeded = cbInfo;
447 Status = NDIS_STATUS_BUFFER_TOO_SHORT;
448 }
449 else
450 {
451 if (pInfo)
452 NdisMoveMemory(pQuery->InformationBuffer, pInfo, cbInfo);
453 pQuery->BytesWritten = cbInfo;
454 }
455 }
456
457 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
458 return Status;
459}
460
461DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinOidRqSet(PVBOXNETADP_ADAPTER pAdapter,
462 PNDIS_OID_REQUEST pRequest)
463{
464 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
465 struct _NDIS_OID_REQUEST::_REQUEST_DATA::_SET *pSet = &pRequest->DATA.SET_INFORMATION;
466
467 LogFlow(("==>"__FUNCTION__"\n"));
468
469 switch (pSet->Oid)
470 {
471 case OID_GEN_CURRENT_LOOKAHEAD:
472 if (pSet->InformationBufferLength != sizeof(ULONG))
473 {
474 pSet->BytesNeeded = sizeof(ULONG);
475 Status = NDIS_STATUS_INVALID_LENGTH;
476 break;
477 }
478 // TODO: For the time being we simply ignore lookahead settings.
479 pSet->BytesRead = sizeof(ULONG);
480 Status = NDIS_STATUS_SUCCESS;
481 break;
482
483 case OID_GEN_CURRENT_PACKET_FILTER:
484 if (pSet->InformationBufferLength != sizeof(ULONG))
485 {
486 pSet->BytesNeeded = sizeof(ULONG);
487 Status = NDIS_STATUS_INVALID_LENGTH;
488 break;
489 }
490 // TODO: For the time being we simply ignore packet filter settings.
491 pSet->BytesRead = pSet->InformationBufferLength;
492 Status = NDIS_STATUS_SUCCESS;
493 break;
494
495 case OID_GEN_INTERRUPT_MODERATION:
496 pSet->BytesNeeded = 0;
497 pSet->BytesRead = 0;
498 Status = NDIS_STATUS_INVALID_DATA;
499 break;
500
501 case OID_PNP_SET_POWER:
502 if (pSet->InformationBufferLength < sizeof(NDIS_DEVICE_POWER_STATE))
503 {
504 Status = NDIS_STATUS_INVALID_LENGTH;
505 break;
506 }
507 pSet->BytesRead = sizeof(NDIS_DEVICE_POWER_STATE);
508 Status = NDIS_STATUS_SUCCESS;
509 break;
510
511 default:
512 Status = NDIS_STATUS_NOT_SUPPORTED;
513 break;
514 }
515
516 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
517 return Status;
518}
519
520DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinOidRequest(IN NDIS_HANDLE MiniportAdapterContext,
521 IN PNDIS_OID_REQUEST NdisRequest)
522{
523 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
524 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
525 LogFlow(("==>"__FUNCTION__"\n"));
526 vboxNetCmnWinDumpOidRequest(__FUNCTION__, NdisRequest);
527
528 switch (NdisRequest->RequestType)
529 {
530#if 0
531 case NdisRequestMethod:
532 Status = vboxNetAdpWinOidRqMethod(pAdapter, NdisRequest);
533 break;
534#endif
535
536 case NdisRequestSetInformation:
537 Status = vboxNetAdpWinOidRqSet(pAdapter, NdisRequest);
538 break;
539
540 case NdisRequestQueryInformation:
541 case NdisRequestQueryStatistics:
542 Status = vboxNetAdpWinOidRqQuery(pAdapter, NdisRequest);
543 break;
544
545 default:
546 Status = NDIS_STATUS_NOT_SUPPORTED;
547 break;
548 }
549 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
550 return Status;
551}
552
553DECLHIDDEN(VOID) vboxNetAdpWinSendNetBufferLists(IN NDIS_HANDLE MiniportAdapterContext,
554 IN PNET_BUFFER_LIST NetBufferLists,
555 IN NDIS_PORT_NUMBER PortNumber,
556 IN ULONG SendFlags)
557{
558 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
559 LogFlow(("==>"__FUNCTION__"\n"));
560 PNET_BUFFER_LIST pNbl = NetBufferLists;
561 for (pNbl = NetBufferLists; pNbl; pNbl = NET_BUFFER_LIST_NEXT_NBL(pNbl))
562 NET_BUFFER_LIST_STATUS(pNbl) = NDIS_STATUS_SUCCESS;
563 NdisMSendNetBufferListsComplete(pAdapter->hAdapter, NetBufferLists,
564 (SendFlags & NDIS_SEND_FLAGS_DISPATCH_LEVEL) ?
565 NDIS_SEND_COMPLETE_FLAGS_DISPATCH_LEVEL : 0);
566 LogFlow(("<=="__FUNCTION__"\n"));
567}
568
569DECLHIDDEN(VOID) vboxNetAdpWinReturnNetBufferLists(IN NDIS_HANDLE MiniportAdapterContext,
570 IN PNET_BUFFER_LIST NetBufferLists,
571 IN ULONG ReturnFlags)
572{
573 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
574 LogFlow(("==>"__FUNCTION__"\n"));
575 Log((__FUNCTION__": We should not be here!\n"));
576 LogFlow(("<=="__FUNCTION__"\n"));
577}
578
579DECLHIDDEN(VOID) vboxNetAdpWinCancelSend(IN NDIS_HANDLE MiniportAdapterContext,
580 IN PVOID CancelId)
581{
582 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
583 LogFlow(("==>"__FUNCTION__"\n"));
584 Log((__FUNCTION__": We should not be here!\n"));
585 LogFlow(("<=="__FUNCTION__"\n"));
586}
587
588
589DECLHIDDEN(BOOLEAN) vboxNetAdpWinCheckForHangEx(IN NDIS_HANDLE MiniportAdapterContext)
590{
591 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
592 LogFlow(("==>"__FUNCTION__"\n"));
593 LogFlow(("<=="__FUNCTION__" return false\n"));
594 return FALSE;
595}
596
597DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinResetEx(IN NDIS_HANDLE MiniportAdapterContext,
598 OUT PBOOLEAN AddressingReset)
599{
600 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
601 LogFlow(("==>"__FUNCTION__"\n"));
602 LogFlow(("<=="__FUNCTION__": status=0x%x\n", Status));
603 return Status;
604}
605
606DECLHIDDEN(VOID) vboxNetAdpWinDevicePnPEventNotify(IN NDIS_HANDLE MiniportAdapterContext,
607 IN PNET_DEVICE_PNP_EVENT NetDevicePnPEvent)
608{
609 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
610 LogFlow(("==>"__FUNCTION__"\n"));
611 Log((__FUNCTION__": PnP event=%d\n", NetDevicePnPEvent->DevicePnPEvent));
612 LogFlow(("<=="__FUNCTION__"\n"));
613}
614
615
616DECLHIDDEN(VOID) vboxNetAdpWinShutdownEx(IN NDIS_HANDLE MiniportAdapterContext,
617 IN NDIS_SHUTDOWN_ACTION ShutdownAction)
618{
619 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
620 LogFlow(("==>"__FUNCTION__"\n"));
621 Log((__FUNCTION__": action=%d\n", ShutdownAction));
622 LogFlow(("<=="__FUNCTION__"\n"));
623}
624
625DECLHIDDEN(VOID) vboxNetAdpWinCancelOidRequest(IN NDIS_HANDLE MiniportAdapterContext,
626 IN PVOID RequestId)
627{
628 PVBOXNETADP_ADAPTER pAdapter = (PVBOXNETADP_ADAPTER)MiniportAdapterContext;
629 LogFlow(("==>"__FUNCTION__"\n"));
630 Log((__FUNCTION__": req id=%p\n", RequestId));
631 LogFlow(("<=="__FUNCTION__"\n"));
632}
633
634
635
636DECLHIDDEN(VOID) vboxNetAdpWinUnload(IN PDRIVER_OBJECT DriverObject)
637{
638 LogFlow(("==>"__FUNCTION__"\n"));
639 //vboxNetAdpWinDevDestroy(&g_VBoxNetAdpGlobals);
640 if (g_VBoxNetAdpGlobals.hMiniportDriver)
641 NdisMDeregisterMiniportDriver(g_VBoxNetAdpGlobals.hMiniportDriver);
642 //NdisFreeSpinLock(&g_VBoxNetAdpGlobals.Lock);
643 LogFlow(("<=="__FUNCTION__"\n"));
644 RTR0Term();
645}
646
647
648/**
649 * register the miniport driver
650 */
651DECLHIDDEN(NDIS_STATUS) vboxNetAdpWinRegister(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPathStr)
652{
653 NDIS_MINIPORT_DRIVER_CHARACTERISTICS MChars;
654
655 NdisZeroMemory(&MChars, sizeof (MChars));
656
657 MChars.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_DRIVER_CHARACTERISTICS;
658 MChars.Header.Size = sizeof(NDIS_MINIPORT_DRIVER_CHARACTERISTICS);
659 MChars.Header.Revision = NDIS_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_1;
660
661 MChars.MajorNdisVersion = VBOXNETADP_VERSION_NDIS_MAJOR;
662 MChars.MinorNdisVersion = VBOXNETADP_VERSION_NDIS_MINOR;
663
664 MChars.MajorDriverVersion = VBOXNETADP_VERSION_MAJOR;
665 MChars.MinorDriverVersion = VBOXNETADP_VERSION_MINOR;
666
667 MChars.InitializeHandlerEx = vboxNetAdpWinInitializeEx;
668 MChars.HaltHandlerEx = vboxNetAdpWinHaltEx;
669 MChars.UnloadHandler = vboxNetAdpWinUnload;
670 MChars.PauseHandler = vboxNetAdpWinPause;
671 MChars.RestartHandler = vboxNetAdpWinRestart;
672 MChars.OidRequestHandler = vboxNetAdpWinOidRequest;
673 MChars.SendNetBufferListsHandler = vboxNetAdpWinSendNetBufferLists;
674 MChars.ReturnNetBufferListsHandler = vboxNetAdpWinReturnNetBufferLists;
675 MChars.CancelSendHandler = vboxNetAdpWinCancelSend;
676 MChars.CheckForHangHandlerEx = vboxNetAdpWinCheckForHangEx;
677 MChars.ResetHandlerEx = vboxNetAdpWinResetEx;
678 MChars.DevicePnPEventNotifyHandler = vboxNetAdpWinDevicePnPEventNotify;
679 MChars.ShutdownHandlerEx = vboxNetAdpWinShutdownEx;
680 MChars.CancelOidRequestHandler = vboxNetAdpWinCancelOidRequest;
681
682 NDIS_STATUS Status;
683 g_VBoxNetAdpGlobals.hMiniportDriver = NULL;
684 Log(("vboxNetAdpWinRegister: registering miniport driver...\n"));
685 Status = NdisMRegisterMiniportDriver(pDriverObject,
686 pRegistryPathStr,
687 (NDIS_HANDLE)&g_VBoxNetAdpGlobals,
688 &MChars,
689 &g_VBoxNetAdpGlobals.hMiniportDriver);
690 Assert(Status == STATUS_SUCCESS);
691 if (Status == STATUS_SUCCESS)
692 {
693 Log(("vboxNetAdpWinRegister: successfully registered miniport driver; registering device...\n"));
694 //Status = vboxNetAdpWinDevCreate(&g_VBoxNetAdpGlobals);
695 //Assert(Status == STATUS_SUCCESS);
696 //Log(("vboxNetAdpWinRegister: vboxNetAdpWinDevCreate() returned 0x%x\n", Status));
697 }
698 else
699 {
700 Log(("ERROR! vboxNetAdpWinRegister: failed to register miniport driver, status=0x%x", Status));
701 }
702 return Status;
703}
704
705
706RT_C_DECLS_BEGIN
707
708NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegistryPath);
709
710RT_C_DECLS_END
711
712NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegistryPath)
713{
714 NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
715 int rc;
716
717
718 rc = RTR0Init(0);
719 AssertRC(rc);
720 if (RT_SUCCESS(rc))
721 {
722 NdisZeroMemory(&g_VBoxNetAdpGlobals, sizeof (g_VBoxNetAdpGlobals));
723 //NdisAllocateSpinLock(&g_VBoxNetAdpGlobals.Lock);
724 //g_VBoxNetAdpGlobals.PMCaps.WakeUpCapabilities.Flags = NDIS_DEVICE_WAKE_UP_ENABLE;
725 g_VBoxNetAdpGlobals.PMCaps.WakeUpCapabilities.MinMagicPacketWakeUp = NdisDeviceStateUnspecified;
726 g_VBoxNetAdpGlobals.PMCaps.WakeUpCapabilities.MinPatternWakeUp = NdisDeviceStateUnspecified;
727
728 Status = vboxNetAdpWinRegister(pDriverObject, pRegistryPath);
729 Assert(Status == STATUS_SUCCESS);
730 if (Status == NDIS_STATUS_SUCCESS)
731 {
732 Log(("NETADP: started successfully\n"));
733 return STATUS_SUCCESS;
734 }
735 //NdisFreeSpinLock(&g_VBoxNetAdpGlobals.Lock);
736 RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
737 RTLogDestroy(RTLogSetDefaultInstance(NULL));
738
739 RTR0Term();
740 }
741 else
742 {
743 Status = NDIS_STATUS_FAILURE;
744 }
745
746 return Status;
747}
748
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette