ReactOS  0.4.14-dev-608-gd495a4f
miniport.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS NDIS library
4  * FILE: ndis/miniport.c
5  * PURPOSE: Routines used by NDIS miniport drivers
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * Vizzini (vizzini@plasmic.com)
8  * REVISIONS:
9  * CSH 01/08-2000 Created
10  * 20 Aug 2003 vizzini - DMA support
11  * 3 Oct 2003 vizzini - SendPackets support
12  */
13 
14 #include "ndissys.h"
15 
16 #include <ndisguid.h>
17 
18 /*
19  * Define to 1 to get a debugger breakpoint at the end of NdisInitializeWrapper
20  * for each new miniport starting up
21  */
22 #define BREAK_ON_MINIPORT_INIT 0
23 
24 /*
25  * This has to be big enough to hold the results of querying the Route value
26  * from the Linkage key. Please re-code me to determine this dynamically.
27  */
28 #define ROUTE_DATA_SIZE 256
29 
30 /* Number of media we know */
31 #define MEDIA_ARRAY_SIZE 15
32 
34 {
50 };
51 
52 /* global list and lock of Miniports NDIS has registered */
55 
56 /* global list and lock of adapters NDIS has registered */
59 
60 #if DBG
61 VOID
62 MiniDisplayPacket(
64  PCSTR Reason)
65 {
66  ULONG i, Length;
67  UCHAR Buffer[64];
68  if ((DebugTraceLevel & DEBUG_PACKET) > 0) {
70  Buffer,
71  Packet,
72  0,
73  64);
74 
75  DbgPrint("*** %s PACKET START (%p) ***\n", Reason, Packet);
76 
77  for (i = 0; i < Length; i++) {
78  if (i % 16 == 0)
79  DbgPrint("\n%04X ", i);
80  DbgPrint("%02X ", Buffer[i]);
81  }
82 
83  DbgPrint("\n*** %s PACKET STOP ***\n", Reason);
84  }
85 }
86 
87 static
88 VOID
89 MiniDisplayPacket2(
90  PVOID HeaderBuffer,
91  UINT HeaderBufferSize,
92  PVOID LookaheadBuffer,
93  UINT LookaheadBufferSize)
94 {
95  if ((DebugTraceLevel & DEBUG_PACKET) > 0) {
96  ULONG i, Length;
97  PUCHAR p;
98 
99  DbgPrint("*** RECEIVE PACKET START ***\n");
100  DbgPrint("HEADER:");
101  p = HeaderBuffer;
102  for (i = 0; i < HeaderBufferSize; i++) {
103  if (i % 16 == 0)
104  DbgPrint("\n%04X ", i);
105  DbgPrint("%02X ", *p++);
106  }
107 
108  DbgPrint("\nFRAME:");
109 
110  p = LookaheadBuffer;
111  Length = (LookaheadBufferSize < 64)? LookaheadBufferSize : 64;
112  for (i = 0; i < Length; i++) {
113  if (i % 16 == 0)
114  DbgPrint("\n%04X ", i);
115  DbgPrint("%02X ", *p++);
116  }
117 
118  DbgPrint("\n*** RECEIVE PACKET STOP ***\n");
119  }
120 }
121 #endif /* DBG */
122 
125  PLOGICAL_ADAPTER Adapter,
127 {
128  PNDIS_MINIPORT_WORK_ITEM CurrentEntry = Adapter->WorkQueueHead;
129 
130  while (CurrentEntry)
131  {
132  if (CurrentEntry->WorkItemType == Type || Type == NdisMaxWorkItems)
133  return CurrentEntry;
134 
135  CurrentEntry = (PNDIS_MINIPORT_WORK_ITEM)CurrentEntry->Link.Next;
136  }
137 
138  return NULL;
139 }
140 
141 BOOLEAN
143  PLOGICAL_ADAPTER Adapter,
145 {
146  BOOLEAN Busy = FALSE;
147  KIRQL OldIrql;
148 
150 
151  if (MiniGetFirstWorkItem(Adapter, Type))
152  {
153  Busy = TRUE;
154  }
156  {
157  Busy = TRUE;
158  }
160  {
161  Busy = TRUE;
162  }
163  else if (Type == NdisWorkItemResetRequested &&
165  {
166  Busy = TRUE;
167  }
168 
170 
171  return Busy;
172 }
173 
174 VOID
176  PLOGICAL_ADAPTER Adapter,
177  NDIS_HANDLE MacReceiveContext,
178  PVOID HeaderBuffer,
179  UINT HeaderBufferSize,
180  PVOID LookaheadBuffer,
181  UINT LookaheadBufferSize,
183 /*
184  * FUNCTION: Indicate received data to bound protocols
185  * ARGUMENTS:
186  * Adapter = Pointer to logical adapter
187  * MacReceiveContext = MAC receive context handle
188  * HeaderBuffer = Pointer to header buffer
189  * HeaderBufferSize = Size of header buffer
190  * LookaheadBuffer = Pointer to lookahead buffer
191  * LookaheadBufferSize = Size of lookahead buffer
192  * PacketSize = Total size of received packet
193  */
194 {
195  KIRQL OldIrql;
196  PLIST_ENTRY CurrentEntry;
197  PADAPTER_BINDING AdapterBinding;
198 
199  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called. Adapter (0x%X) HeaderBuffer (0x%X) "
200  "HeaderBufferSize (0x%X) LookaheadBuffer (0x%X) LookaheadBufferSize (0x%X).\n",
201  Adapter, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize));
202 
203 #if DBG
204  MiniDisplayPacket2(HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize);
205 #endif
206 
207  NDIS_DbgPrint(MAX_TRACE, ("acquiring miniport block lock\n"));
209  {
210  CurrentEntry = Adapter->ProtocolListHead.Flink;
211  NDIS_DbgPrint(DEBUG_MINIPORT, ("CurrentEntry = %x\n", CurrentEntry));
212 
213  if (CurrentEntry == &Adapter->ProtocolListHead)
214  {
215  NDIS_DbgPrint(MIN_TRACE, ("WARNING: No upper protocol layer.\n"));
216  }
217 
218  while (CurrentEntry != &Adapter->ProtocolListHead)
219  {
220  AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);
221  NDIS_DbgPrint(DEBUG_MINIPORT, ("AdapterBinding = %x\n", AdapterBinding));
222 
224  (MID_TRACE,
225  ("XXX (%x) %x %x %x %x %x %x %x XXX\n",
226  *AdapterBinding->ProtocolBinding->Chars.ReceiveHandler,
227  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
228  MacReceiveContext,
229  HeaderBuffer,
230  HeaderBufferSize,
231  LookaheadBuffer,
232  LookaheadBufferSize,
233  PacketSize));
234 
235  /* call the receive handler */
236  (*AdapterBinding->ProtocolBinding->Chars.ReceiveHandler)(
237  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
238  MacReceiveContext,
239  HeaderBuffer,
240  HeaderBufferSize,
241  LookaheadBuffer,
242  LookaheadBufferSize,
243  PacketSize);
244 
245  CurrentEntry = CurrentEntry->Flink;
246  }
247  }
249 
250  NDIS_DbgPrint(MAX_TRACE, ("Leaving.\n"));
251 }
252 
253 /*
254  * @implemented
255  */
256 VOID
257 EXPORT
259  IN PNDIS_PACKET *PacketsToReturn,
261 /*
262  * FUNCTION: Releases ownership of one or more packets
263  * ARGUMENTS:
264  * PacketsToReturn = Pointer to an array of pointers to packet descriptors
265  * NumberOfPackets = Number of pointers in descriptor pointer array
266  */
267 {
268  UINT i;
269  PLOGICAL_ADAPTER Adapter;
270  KIRQL OldIrql;
271 
272  NDIS_DbgPrint(MID_TRACE, ("Returning %d packets\n", NumberOfPackets));
273 
274  for (i = 0; i < NumberOfPackets; i++)
275  {
276  PacketsToReturn[i]->WrapperReserved[0]--;
277  if (PacketsToReturn[i]->WrapperReserved[0] == 0)
278  {
279  Adapter = (PVOID)(ULONG_PTR)PacketsToReturn[i]->Reserved[1];
280 
281  NDIS_DbgPrint(MAX_TRACE, ("Freeing packet %d (adapter = 0x%p)\n", i, Adapter));
282 
284  Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.ReturnPacketHandler(
286  PacketsToReturn[i]);
288  }
289  }
290 }
291 
292 VOID NTAPI
297 /*
298  * FUNCTION: receives miniport packet array indications
299  * ARGUMENTS:
300  * MiniportAdapterHandle: Miniport handle for the adapter
301  * PacketArray: pointer to a list of packet pointers to indicate
302  * NumberOfPackets: number of packets to indicate
303  *
304  */
305 {
307  PLIST_ENTRY CurrentEntry;
308  PADAPTER_BINDING AdapterBinding;
309  KIRQL OldIrql;
310  UINT i;
311 
313 
314  CurrentEntry = Adapter->ProtocolListHead.Flink;
315 
316  while (CurrentEntry != &Adapter->ProtocolListHead)
317  {
318  AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);
319 
320  for (i = 0; i < NumberOfPackets; i++)
321  {
322  /* Store the indicating miniport in the packet */
323  PacketArray[i]->Reserved[1] = (ULONG_PTR)Adapter;
324 
325  if (AdapterBinding->ProtocolBinding->Chars.ReceivePacketHandler &&
327  {
328  NDIS_DbgPrint(MID_TRACE, ("Indicating packet to protocol's ReceivePacket handler\n"));
330  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
331  PacketArray[i]);
332  NDIS_DbgPrint(MID_TRACE, ("Protocol is holding %d references to the packet\n", PacketArray[i]->WrapperReserved[0]));
333  }
334  else
335  {
336  UINT FirstBufferLength, TotalBufferLength, LookAheadSize, HeaderSize;
337  PNDIS_BUFFER NdisBuffer;
338  PVOID NdisBufferVA, LookAheadBuffer;
339 
341  &NdisBuffer,
342  &NdisBufferVA,
343  &FirstBufferLength,
344  &TotalBufferLength);
345 
347 
348  LookAheadSize = TotalBufferLength - HeaderSize;
349 
350  LookAheadBuffer = ExAllocatePool(NonPagedPool, LookAheadSize);
351  if (!LookAheadBuffer)
352  {
353  NDIS_DbgPrint(MIN_TRACE, ("Failed to allocate lookahead buffer!\n"));
355  return;
356  }
357 
358  CopyBufferChainToBuffer(LookAheadBuffer,
359  NdisBuffer,
360  HeaderSize,
361  LookAheadSize);
362 
363  NDIS_DbgPrint(MID_TRACE, ("Indicating packet to protocol's legacy Receive handler\n"));
364  (*AdapterBinding->ProtocolBinding->Chars.ReceiveHandler)(
365  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
366  AdapterBinding->NdisOpenBlock.MacHandle,
367  NdisBufferVA,
368  HeaderSize,
369  LookAheadBuffer,
370  LookAheadSize,
371  TotalBufferLength - HeaderSize);
372 
373  ExFreePool(LookAheadBuffer);
374  }
375  }
376 
377  CurrentEntry = CurrentEntry->Flink;
378  }
379 
380  /* Loop the packet array to get everything
381  * set up for return the packets to the miniport */
382  for (i = 0; i < NumberOfPackets; i++)
383  {
384  /* First, check the initial packet status */
386  {
387  /* The miniport driver gets it back immediately so nothing to do here */
388  NDIS_DbgPrint(MID_TRACE, ("Miniport needs the packet back immediately\n"));
389  continue;
390  }
391 
392  /* Different behavior depending on whether it's serialized or not */
394  {
395  /* We need to check the reference count */
396  if (PacketArray[i]->WrapperReserved[0] == 0)
397  {
398  /* NOTE: Unlike serialized miniports, this is REQUIRED to be called for each
399  * packet received that can be reused immediately, it is not implied! */
400  Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.ReturnPacketHandler(
402  PacketArray[i]);
403  NDIS_DbgPrint(MID_TRACE, ("Packet has been returned to miniport (Deserialized)\n"));
404  }
405  else
406  {
407  /* Packet will be returned by the protocol's call to NdisReturnPackets */
408  NDIS_DbgPrint(MID_TRACE, ("Packet will be returned to miniport later (Deserialized)\n"));
409  }
410  }
411  else
412  {
413  /* Check the reference count */
414  if (PacketArray[i]->WrapperReserved[0] == 0)
415  {
416  /* NDIS_STATUS_SUCCESS means the miniport can have the packet back immediately */
418 
419  NDIS_DbgPrint(MID_TRACE, ("Packet has been returned to miniport (Serialized)\n"));
420  }
421  else
422  {
423  /* NDIS_STATUS_PENDING means the miniport needs to wait for MiniportReturnPacket */
425 
426  NDIS_DbgPrint(MID_TRACE, ("Packet will be returned to miniport later (Serialized)\n"));
427  }
428  }
429  }
430 
432 }
433 
434 VOID NTAPI
438  IN BOOLEAN AddressingReset)
439 {
441  PLIST_ENTRY CurrentEntry;
442  PADAPTER_BINDING AdapterBinding;
443  KIRQL OldIrql;
444 
445  if (AddressingReset)
446  MiniDoAddressingReset(Adapter);
447 
450 
452 
454  {
455  KeBugCheckEx(BUGCODE_ID_DRIVER,
457  (ULONG_PTR)Status,
458  (ULONG_PTR)AddressingReset,
459  0);
460  }
461 
463 
464  CurrentEntry = Adapter->ProtocolListHead.Flink;
465 
466  while (CurrentEntry != &Adapter->ProtocolListHead)
467  {
468  AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);
469 
470  (*AdapterBinding->ProtocolBinding->Chars.ResetCompleteHandler)(
471  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
472  Status);
473 
474  CurrentEntry = CurrentEntry->Flink;
475  }
476 
478 }
479 
480 VOID NTAPI
484 {
487  PNDIS_REQUEST_MAC_BLOCK MacBlock;
488  KIRQL OldIrql;
489 
490  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
491 
493 
497 
498  MacBlock = (PNDIS_REQUEST_MAC_BLOCK)Request->MacReserved;
499 
500  /* We may or may not be doing this request on behalf of an adapter binding */
501  if (MacBlock->Binding != NULL)
502  {
503  /* We are, so invoke its request complete handler */
504  if (MacBlock->Binding->RequestCompleteHandler != NULL)
505  {
506  (*MacBlock->Binding->RequestCompleteHandler)(
507  MacBlock->Binding->ProtocolBindingContext,
508  Request,
509  Status);
510  }
511  }
512  else
513  {
514  /* We are doing this internally, so we'll signal this event we've stashed in the MacBlock */
515  ASSERT(MacBlock->Unknown1 != NULL);
516  ASSERT(MacBlock->Unknown3 == NULL);
517  MacBlock->Unknown3 = UlongToPtr(Status);
519  }
520 
525 
527 }
528 
529 VOID NTAPI
534 /*
535  * FUNCTION: Forwards a message to the initiating protocol saying
536  * that a packet was handled
537  * ARGUMENTS:
538  * NdisAdapterHandle = Handle input to MiniportInitialize
539  * Packet = Pointer to NDIS packet that was sent
540  * Status = Status of send operation
541  */
542 {
544  PADAPTER_BINDING AdapterBinding;
545  KIRQL OldIrql;
546  PSCATTER_GATHER_LIST SGList;
547 
548  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
549 
550  AdapterBinding = (PADAPTER_BINDING)Packet->Reserved[1];
551 
553 
554  if (Adapter->NdisMiniportBlock.ScatterGatherListSize != 0)
555  {
556  NDIS_DbgPrint(MAX_TRACE, ("Freeing Scatter/Gather list\n"));
557 
560 
561  Adapter->NdisMiniportBlock.SystemAdapterObject->
562  DmaOperations->PutScatterGatherList(
563  Adapter->NdisMiniportBlock.SystemAdapterObject,
564  SGList,
565  TRUE);
566 
569  }
570 
571  (*AdapterBinding->ProtocolBinding->Chars.SendCompleteHandler)(
572  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
573  Packet,
574  Status);
575 
577 
579 }
580 
581 
582 VOID NTAPI
585 {
586  /* Run the work if anything is waiting */
588 }
589 
590 
591 VOID NTAPI
596  IN UINT BytesTransferred)
597 {
598  PADAPTER_BINDING AdapterBinding;
599  KIRQL OldIrql;
600 
601  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
602 
603  AdapterBinding = (PADAPTER_BINDING)Packet->Reserved[1];
604 
607  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
608  Packet,
609  Status,
610  BytesTransferred);
612 }
613 
614 
615 BOOLEAN
617  PLOGICAL_ADAPTER Adapter,
619 /*
620  * FUNCTION: Determines whether a packet has the same destination address as an adapter
621  * ARGUMENTS:
622  * Adapter = Pointer to logical adapter object
623  * Packet = Pointer to NDIS packet
624  * RETURNS:
625  * TRUE if the destination address is that of the adapter, FALSE if not
626  */
627 {
628  UINT Length;
629  PUCHAR PacketAddress;
630  PUCHAR AdapterAddress;
631  PNDIS_BUFFER NdisBuffer;
633 
634  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
635 
636 #if DBG
637  if(!Adapter)
638  {
639  NDIS_DbgPrint(MIN_TRACE, ("Adapter object was null\n"));
640  return FALSE;
641  }
642 
643  if(!Packet)
644  {
645  NDIS_DbgPrint(MIN_TRACE, ("Packet was null\n"));
646  return FALSE;
647  }
648 #endif
649 
650  NdisQueryPacket(Packet, NULL, NULL, &NdisBuffer, NULL);
651 
652  if (!NdisBuffer)
653  {
654  NDIS_DbgPrint(MIN_TRACE, ("Packet contains no buffers.\n"));
655  return FALSE;
656  }
657 
658  NdisQueryBuffer(NdisBuffer, (PVOID)&PacketAddress, &BufferLength);
659 
660  /* FIXME: Should handle fragmented packets */
661 
662  switch (Adapter->NdisMiniportBlock.MediaType)
663  {
664  case NdisMedium802_3:
666  /* Destination address is the first field */
667  break;
668 
669  default:
670  NDIS_DbgPrint(MIN_TRACE, ("Adapter has unsupported media type (0x%X).\n", Adapter->NdisMiniportBlock.MediaType));
671  return FALSE;
672  }
673 
674  if (BufferLength < Length)
675  {
676  NDIS_DbgPrint(MIN_TRACE, ("Buffer is too small.\n"));
677  return FALSE;
678  }
679 
680  AdapterAddress = (PUCHAR)&Adapter->Address;
681  NDIS_DbgPrint(MAX_TRACE, ("packet address: %x:%x:%x:%x:%x:%x adapter address: %x:%x:%x:%x:%x:%x\n",
682  *(PacketAddress), *(PacketAddress+1), *(PacketAddress+2), *(PacketAddress+3), *(PacketAddress+4), *(PacketAddress+5),
683  *(AdapterAddress), *(AdapterAddress+1), *(AdapterAddress+2), *(AdapterAddress+3), *(AdapterAddress+4), *(AdapterAddress+5)));
684 
685  return (RtlCompareMemory(PacketAddress, AdapterAddress, Length) == Length);
686 }
687 
688 
692 /*
693  * FUNCTION: Finds an adapter object by name
694  * ARGUMENTS:
695  * AdapterName = Pointer to name of adapter
696  * RETURNS:
697  * Pointer to logical adapter object, or NULL if none was found.
698  * If found, the adapter is referenced for the caller. The caller
699  * is responsible for dereferencing after use
700  */
701 {
702  KIRQL OldIrql;
703  PLIST_ENTRY CurrentEntry;
704  PLOGICAL_ADAPTER Adapter = 0;
705 
707 
708  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
709 
711  {
712  NDIS_DbgPrint(MIN_TRACE, ("No registered miniports for protocol to bind to\n"));
713  return NULL;
714  }
715 
716  NDIS_DbgPrint(DEBUG_MINIPORT, ("AdapterName = %wZ\n", AdapterName));
717 
719  {
720  CurrentEntry = AdapterListHead.Flink;
721 
722  while (CurrentEntry != &AdapterListHead)
723  {
724  Adapter = CONTAINING_RECORD(CurrentEntry, LOGICAL_ADAPTER, ListEntry);
725 
726  ASSERT(Adapter);
727 
728  NDIS_DbgPrint(DEBUG_MINIPORT, ("Examining adapter 0x%lx\n", Adapter));
729 
730  /* We're technically not allowed to call this above PASSIVE_LEVEL, but it doesn't break
731  * right now and I'd rather use a working API than reimplement it here */
733  {
734  break;
735  }
736 
737  Adapter = NULL;
738  CurrentEntry = CurrentEntry->Flink;
739  }
740  }
742 
743  if(Adapter)
744  {
745  NDIS_DbgPrint(DEBUG_MINIPORT, ("Leaving. Adapter found at 0x%x\n", Adapter));
746  }
747  else
748  {
749  NDIS_DbgPrint(MIN_TRACE, ("Leaving (adapter not found for %wZ).\n", AdapterName));
750  }
751 
752  return Adapter;
753 }
754 
757  PLOGICAL_ADAPTER Adapter,
758  NDIS_OID Oid,
759  ULONG Size,
760  PVOID Buffer,
762 {
763  NDIS_STATUS NdisStatus;
765  KEVENT Event;
766  PNDIS_REQUEST_MAC_BLOCK MacBlock;
767 
768  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
769 
771  if (!NdisRequest) {
772  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
773  return NDIS_STATUS_RESOURCES;
774  }
775 
777 
778  NdisRequest->RequestType = NdisRequestSetInformation;
779  NdisRequest->DATA.SET_INFORMATION.Oid = Oid;
780  NdisRequest->DATA.SET_INFORMATION.InformationBuffer = Buffer;
781  NdisRequest->DATA.SET_INFORMATION.InformationBufferLength = Size;
782 
783  /* We'll need to give the completion routine some way of letting us know
784  * when it's finished. We'll stash a pointer to an event in the MacBlock */
786  MacBlock = (PNDIS_REQUEST_MAC_BLOCK)NdisRequest->MacReserved;
787  MacBlock->Unknown1 = &Event;
788 
789  NdisStatus = MiniDoRequest(Adapter, NdisRequest);
790 
791  if (NdisStatus == NDIS_STATUS_PENDING)
792  {
794  NdisStatus = PtrToUlong(MacBlock->Unknown3);
795  }
796 
797  *BytesRead = NdisRequest->DATA.SET_INFORMATION.BytesRead;
798 
800 
801  return NdisStatus;
802 }
803 
806  PLOGICAL_ADAPTER Adapter,
807  NDIS_OID Oid,
808  ULONG Size,
809  PVOID Buffer,
811 /*
812  * FUNCTION: Queries a logical adapter for properties
813  * ARGUMENTS:
814  * Adapter = Pointer to the logical adapter object to query
815  * Oid = Specifies the Object ID to query for
816  * Size = Size of the passed buffer
817  * Buffer = Buffer for the output
818  * BytesWritten = Address of buffer to place number of bytes written
819  * RETURNS:
820  * Status of operation
821  */
822 {
823  NDIS_STATUS NdisStatus;
825  KEVENT Event;
826  PNDIS_REQUEST_MAC_BLOCK MacBlock;
827 
828  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
829 
831  if (!NdisRequest) {
832  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
833  return NDIS_STATUS_RESOURCES;
834  }
835 
837 
839  NdisRequest->DATA.QUERY_INFORMATION.Oid = Oid;
840  NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer = Buffer;
841  NdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength = Size;
842 
843  /* We'll need to give the completion routine some way of letting us know
844  * when it's finished. We'll stash a pointer to an event in the MacBlock */
846  MacBlock = (PNDIS_REQUEST_MAC_BLOCK)NdisRequest->MacReserved;
847  MacBlock->Unknown1 = &Event;
848 
849  NdisStatus = MiniDoRequest(Adapter, NdisRequest);
850 
851  if (NdisStatus == NDIS_STATUS_PENDING)
852  {
854  NdisStatus = PtrToUlong(MacBlock->Unknown3);
855  }
856 
857  *BytesWritten = NdisRequest->DATA.QUERY_INFORMATION.BytesWritten;
858 
860 
861  return NdisStatus;
862 }
863 
864 BOOLEAN
866 /*
867  * FUNCTION: Checks to see if the miniport is hung
868  * ARGUMENTS:
869  * Adapter = Pointer to the logical adapter object
870  * RETURNS:
871  * TRUE if the miniport is hung
872  * FALSE if the miniport is not hung
873  */
874 {
875  BOOLEAN Ret = FALSE;
876  KIRQL OldIrql;
877 
879  if (Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CheckForHangHandler)
880  Ret = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CheckForHangHandler)(
883 
884  return Ret;
885 }
886 
887 VOID
889 {
891 
892  MiniSetInformation(Adapter,
894  sizeof(ULONG),
896  &BytesRead);
897 
898  /* FIXME: Set more stuff */
899 }
900 
903  PLOGICAL_ADAPTER Adapter)
904 /*
905  * FUNCTION: Resets the miniport
906  * ARGUMENTS:
907  * Adapter = Pointer to the logical adapter object
908  * RETURNS:
909  * Status of the operation
910  */
911 {
913  KIRQL OldIrql;
914  BOOLEAN AddressingReset = TRUE;
915 
916  if (MiniIsBusy(Adapter, NdisWorkItemResetRequested)) {
918  return NDIS_STATUS_PENDING;
919  }
920 
923 
925  Status = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.ResetHandler)(
926  &AddressingReset,
928 
932 
934 
935  if (Status != NDIS_STATUS_PENDING) {
936  if (AddressingReset)
937  MiniDoAddressingReset(Adapter);
938 
941 
943  }
944 
945  return Status;
946 }
947 
948 VOID NTAPI
950  PKDPC Dpc,
954 {
956 
957  if (MiniCheckForHang(Adapter)) {
958  NDIS_DbgPrint(MIN_TRACE, ("Miniport detected adapter hang\n"));
959  MiniReset(Adapter);
960  }
961 }
962 
963 VOID
965  PLOGICAL_ADAPTER Adapter,
966  NDIS_WORK_ITEM_TYPE WorkItemType)
967 {
969 
970  /* Check if there's anything queued to run after this work item */
971  if (!MiniIsBusy(Adapter, WorkItemType))
972  return;
973 
974  /* There is, so fire the worker */
976  if (IoWorkItem)
978 }
979 
980 VOID
981 FASTCALL
983  PLOGICAL_ADAPTER Adapter,
984  NDIS_WORK_ITEM_TYPE WorkItemType,
985  PVOID WorkItemContext,
986  BOOLEAN Top)
987 /*
988  * FUNCTION: Queues a work item for execution at a later time
989  * ARGUMENTS:
990  * Adapter = Pointer to the logical adapter object to queue work item on
991  * WorkItemType = Type of work item to queue
992  * WorkItemContext = Pointer to context information for work item
993  * RETURNS:
994  * Status of operation
995  */
996 {
997  PNDIS_MINIPORT_WORK_ITEM MiniportWorkItem;
998  KIRQL OldIrql;
999 
1000  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1001 
1002  ASSERT(Adapter);
1003 
1005  if (Top)
1006  {
1007  if (WorkItemType == NdisWorkItemSend)
1008  {
1009  NDIS_DbgPrint(MIN_TRACE, ("Requeuing failed packet (%x).\n", WorkItemContext));
1010  Adapter->NdisMiniportBlock.FirstPendingPacket = WorkItemContext;
1011  }
1012  else
1013  {
1014  //This should never happen
1015  ASSERT(FALSE);
1016  }
1017  }
1018  else
1019  {
1020  MiniportWorkItem = ExAllocatePool(NonPagedPool, sizeof(NDIS_MINIPORT_WORK_ITEM));
1021  if (!MiniportWorkItem)
1022  {
1024  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1025  return;
1026  }
1027 
1028  MiniportWorkItem->WorkItemType = WorkItemType;
1029  MiniportWorkItem->WorkItemContext = WorkItemContext;
1030 
1031  /* safe due to adapter lock held */
1032  MiniportWorkItem->Link.Next = NULL;
1033  if (!Adapter->WorkQueueHead)
1034  {
1035  Adapter->WorkQueueHead = MiniportWorkItem;
1036  Adapter->WorkQueueTail = MiniportWorkItem;
1037  }
1038  else
1039  {
1040  Adapter->WorkQueueTail->Link.Next = (PSINGLE_LIST_ENTRY)MiniportWorkItem;
1041  Adapter->WorkQueueTail = MiniportWorkItem;
1042  }
1043  }
1044 
1046 }
1047 
1049 FASTCALL
1051  PLOGICAL_ADAPTER Adapter,
1052  NDIS_WORK_ITEM_TYPE *WorkItemType,
1053  PVOID *WorkItemContext)
1054 /*
1055  * FUNCTION: Dequeues a work item from the work queue of a logical adapter
1056  * ARGUMENTS:
1057  * Adapter = Pointer to the logical adapter object to dequeue work item from
1058  * AdapterBinding = Address of buffer for adapter binding for this request
1059  * WorkItemType = Address of buffer for work item type
1060  * WorkItemContext = Address of buffer for pointer to context information
1061  * NOTES:
1062  * Adapter lock must be held when called
1063  * RETURNS:
1064  * Status of operation
1065  */
1066 {
1067  PNDIS_MINIPORT_WORK_ITEM MiniportWorkItem;
1069 
1070  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1071 
1072  MiniportWorkItem = Adapter->WorkQueueHead;
1073 
1074  if ((Packet = Adapter->NdisMiniportBlock.FirstPendingPacket))
1075  {
1077 
1078  *WorkItemType = NdisWorkItemSend;
1079  *WorkItemContext = Packet;
1080 
1081  return NDIS_STATUS_SUCCESS;
1082  }
1083  else if (MiniportWorkItem)
1084  {
1085  /* safe due to adapter lock held */
1086  Adapter->WorkQueueHead = (PNDIS_MINIPORT_WORK_ITEM)MiniportWorkItem->Link.Next;
1087 
1088  if (MiniportWorkItem == Adapter->WorkQueueTail)
1089  Adapter->WorkQueueTail = NULL;
1090 
1091  *WorkItemType = MiniportWorkItem->WorkItemType;
1092  *WorkItemContext = MiniportWorkItem->WorkItemContext;
1093 
1094  ExFreePool(MiniportWorkItem);
1095 
1096  return NDIS_STATUS_SUCCESS;
1097  }
1098  else
1099  {
1100  NDIS_DbgPrint(MIN_TRACE, ("No work item to dequeue\n"));
1101 
1102  return NDIS_STATUS_FAILURE;
1103  }
1104 }
1105 
1108  PLOGICAL_ADAPTER Adapter,
1110 /*
1111  * FUNCTION: Sends a request to a miniport
1112  * ARGUMENTS:
1113  * AdapterBinding = Pointer to binding used in the request
1114  * NdisRequest = Pointer to NDIS request structure describing request
1115  * RETURNS:
1116  * Status of operation
1117  */
1118 {
1120  KIRQL OldIrql;
1121  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
1122 
1124 
1128 
1129  if (!Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CoRequestHandler)
1130  {
1131  switch (NdisRequest->RequestType)
1132  {
1134  Status = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.QueryInformationHandler)(
1136  NdisRequest->DATA.QUERY_INFORMATION.Oid,
1137  NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer,
1138  NdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength,
1139  (PULONG)&NdisRequest->DATA.QUERY_INFORMATION.BytesWritten,
1140  (PULONG)&NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded);
1141  break;
1142 
1144  Status = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SetInformationHandler)(
1146  NdisRequest->DATA.SET_INFORMATION.Oid,
1147  NdisRequest->DATA.SET_INFORMATION.InformationBuffer,
1148  NdisRequest->DATA.SET_INFORMATION.InformationBufferLength,
1149  (PULONG)&NdisRequest->DATA.SET_INFORMATION.BytesRead,
1150  (PULONG)&NdisRequest->DATA.SET_INFORMATION.BytesNeeded);
1151  break;
1152 
1153  default:
1154  NDIS_DbgPrint(MIN_TRACE, ("Bad request type\n"));
1156  }
1157  }
1158  else
1159  {
1160  Status = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CoRequestHandler)(
1162  NULL, /* FIXME */
1163  NdisRequest);
1164  }
1165 
1166  if (Status != NDIS_STATUS_PENDING) {
1170  }
1171 
1173 
1174  if (Status != NDIS_STATUS_PENDING) {
1176  }
1177 
1178  return Status;
1179 }
1180 
1181 /*
1182  * @implemented
1183  */
1184 #undef NdisMSetInformationComplete
1185 VOID
1186 EXPORT
1190 {
1191  PLOGICAL_ADAPTER Adapter =
1193  KIRQL OldIrql;
1194  ASSERT(Adapter);
1199 }
1200 
1201 /*
1202  * @implemented
1203  */
1204 #undef NdisMQueryInformationComplete
1205 VOID
1206 EXPORT
1210 {
1211  PLOGICAL_ADAPTER Adapter =
1213  KIRQL OldIrql;
1214  ASSERT(Adapter);
1219 }
1220 
1221 VOID
1222 NTAPI
1224 {
1226  KIRQL OldIrql, RaiseOldIrql;
1227  NDIS_STATUS NdisStatus;
1228  PVOID WorkItemContext;
1229  NDIS_WORK_ITEM_TYPE WorkItemType;
1230  BOOLEAN AddressingReset;
1231 
1233 
1235 
1236  NdisStatus =
1238  (Adapter, &WorkItemType, &WorkItemContext);
1239 
1241 
1242  if (NdisStatus == NDIS_STATUS_SUCCESS)
1243  {
1244  switch (WorkItemType)
1245  {
1246  case NdisWorkItemSend:
1247  /*
1248  * called by ProSend when protocols want to send packets to the miniport
1249  */
1250 
1251  if(Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)
1252  {
1254  {
1255  NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets handler\n"));
1256  (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
1257  Adapter->NdisMiniportBlock.MiniportAdapterContext, (PPNDIS_PACKET)&WorkItemContext, 1);
1258  NdisStatus = NDIS_STATUS_PENDING;
1259  }
1260  else
1261  {
1262  /* SendPackets is called at DISPATCH_LEVEL for all serialized miniports */
1263  KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
1264  {
1265  NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's SendPackets handler\n"));
1266  (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendPacketsHandler)(
1267  Adapter->NdisMiniportBlock.MiniportAdapterContext, (PPNDIS_PACKET)&WorkItemContext, 1);
1268  }
1269  KeLowerIrql(RaiseOldIrql);
1270 
1271  NdisStatus = NDIS_GET_PACKET_STATUS((PNDIS_PACKET)WorkItemContext);
1272  if( NdisStatus == NDIS_STATUS_RESOURCES ) {
1273  MiniQueueWorkItem(Adapter, WorkItemType, WorkItemContext, TRUE);
1274  break;
1275  }
1276  }
1277  }
1278  else
1279  {
1281  {
1282  NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send handler\n"));
1283  NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
1284  Adapter->NdisMiniportBlock.MiniportAdapterContext, (PNDIS_PACKET)WorkItemContext,
1285  ((PNDIS_PACKET)WorkItemContext)->Private.Flags);
1286  NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send handler\n"));
1287  }
1288  else
1289  {
1290  /* Send is called at DISPATCH_LEVEL for all serialized miniports */
1291  KeRaiseIrql(DISPATCH_LEVEL, &RaiseOldIrql);
1292  NDIS_DbgPrint(MAX_TRACE, ("Calling miniport's Send handler\n"));
1293  NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.SendHandler)(
1294  Adapter->NdisMiniportBlock.MiniportAdapterContext, (PNDIS_PACKET)WorkItemContext,
1295  ((PNDIS_PACKET)WorkItemContext)->Private.Flags);
1296  NDIS_DbgPrint(MAX_TRACE, ("back from miniport's send handler\n"));
1297  KeLowerIrql(RaiseOldIrql);
1298  if( NdisStatus == NDIS_STATUS_RESOURCES ) {
1299  MiniQueueWorkItem(Adapter, WorkItemType, WorkItemContext, TRUE);
1300  break;
1301  }
1302  }
1303  }
1304 
1305  if( NdisStatus != NDIS_STATUS_PENDING ) {
1307  ( Adapter, (PNDIS_PACKET)WorkItemContext, NdisStatus );
1308  }
1309  break;
1310 
1312  /*
1313  * called by ProSend when protocols want to send loopback packets
1314  */
1315  /* XXX atm ProIndicatePacket sends a packet up via the loopback adapter only */
1316  NdisStatus = ProIndicatePacket(Adapter, (PNDIS_PACKET)WorkItemContext);
1317 
1318  if( NdisStatus != NDIS_STATUS_PENDING )
1319  MiniSendComplete((NDIS_HANDLE)Adapter, (PNDIS_PACKET)WorkItemContext, NdisStatus);
1320  break;
1321 
1323  break;
1324 
1327  NdisMIndicateStatusComplete(Adapter);
1328 
1330  NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.ResetHandler)(
1331  &AddressingReset,
1332  Adapter->NdisMiniportBlock.MiniportAdapterContext);
1333 
1334  KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
1335  Adapter->NdisMiniportBlock.ResetStatus = NdisStatus;
1336  KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
1337 
1339 
1340  if (NdisStatus != NDIS_STATUS_PENDING)
1341  MiniResetComplete(Adapter, NdisStatus, AddressingReset);
1342  break;
1343 
1345  break;
1346 
1348  break;
1349 
1350  case NdisWorkItemRequest:
1351  NdisStatus = MiniDoRequest(Adapter, (PNDIS_REQUEST)WorkItemContext);
1352 
1353  if (NdisStatus == NDIS_STATUS_PENDING)
1354  break;
1355 
1356  Adapter->NdisMiniportBlock.PendingRequest = (PNDIS_REQUEST)WorkItemContext;
1357  switch (((PNDIS_REQUEST)WorkItemContext)->RequestType)
1358  {
1360  NdisMQueryInformationComplete((NDIS_HANDLE)Adapter, NdisStatus);
1361  break;
1362 
1364  NdisMSetInformationComplete((NDIS_HANDLE)Adapter, NdisStatus);
1365  break;
1366 
1367  default:
1368  NDIS_DbgPrint(MIN_TRACE, ("Unknown NDIS request type.\n"));
1369  break;
1370  }
1371  Adapter->NdisMiniportBlock.PendingRequest = NULL;
1372  break;
1373 
1374  default:
1375  NDIS_DbgPrint(MIN_TRACE, ("Unknown NDIS work item type (%d).\n", WorkItemType));
1376  break;
1377  }
1378  }
1379 }
1380 
1381 
1382 VOID
1383 NTAPI
1385  IN NDIS_HANDLE MiniportHandle,
1389 {
1390  PLOGICAL_ADAPTER Adapter = MiniportHandle;
1391  PLIST_ENTRY CurrentEntry;
1392  PADAPTER_BINDING AdapterBinding;
1393  KIRQL OldIrql;
1394 
1396 
1397  CurrentEntry = Adapter->ProtocolListHead.Flink;
1398 
1399  while (CurrentEntry != &Adapter->ProtocolListHead)
1400  {
1401  AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);
1402 
1403  (*AdapterBinding->ProtocolBinding->Chars.StatusHandler)(
1404  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
1405  GeneralStatus,
1406  StatusBuffer,
1408 
1409  CurrentEntry = CurrentEntry->Flink;
1410  }
1411 
1413 }
1414 
1415 VOID
1416 NTAPI
1419 {
1421  PLIST_ENTRY CurrentEntry;
1422  PADAPTER_BINDING AdapterBinding;
1423  KIRQL OldIrql;
1424 
1426 
1427  CurrentEntry = Adapter->ProtocolListHead.Flink;
1428 
1429  while (CurrentEntry != &Adapter->ProtocolListHead)
1430  {
1431  AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);
1432 
1433  (*AdapterBinding->ProtocolBinding->Chars.StatusCompleteHandler)(
1434  AdapterBinding->NdisOpenBlock.ProtocolBindingContext);
1435 
1436  CurrentEntry = CurrentEntry->Flink;
1437  }
1438 
1440 }
1441 
1442 /*
1443  * @implemented
1444  */
1445 VOID
1446 EXPORT
1449 {
1450  PNDIS_LOG Log = (PNDIS_LOG)LogHandle;
1451  PNDIS_MINIPORT_BLOCK Miniport = Log->Miniport;
1452  KIRQL OldIrql;
1453 
1454  NDIS_DbgPrint(MAX_TRACE, ("called: LogHandle 0x%x\n", LogHandle));
1455 
1456  KeAcquireSpinLock(&(Miniport)->Lock, &OldIrql);
1457  Miniport->Log = NULL;
1458  KeReleaseSpinLock(&(Miniport)->Lock, OldIrql);
1459 
1460  ExFreePool(Log);
1461 }
1462 
1463 /*
1464  * @implemented
1465  */
1467 EXPORT
1470  IN UINT Size,
1472 {
1474  PNDIS_LOG Log;
1475  KIRQL OldIrql;
1476 
1477  NDIS_DbgPrint(MAX_TRACE, ("called: MiniportAdapterHandle 0x%x, Size %ld\n", MiniportAdapterHandle, Size));
1478 
1480 
1481  if (Adapter->NdisMiniportBlock.Log)
1482  {
1483  *LogHandle = NULL;
1484  return NDIS_STATUS_FAILURE;
1485  }
1486 
1487  Log = ExAllocatePool(NonPagedPool, Size + sizeof(NDIS_LOG));
1488  if (!Log)
1489  {
1490  *LogHandle = NULL;
1491  return NDIS_STATUS_RESOURCES;
1492  }
1493 
1494  Adapter->NdisMiniportBlock.Log = Log;
1495 
1497 
1498  Log->Miniport = &Adapter->NdisMiniportBlock;
1499  Log->TotalSize = Size;
1500  Log->CurrentSize = 0;
1501  Log->OutPtr = 0;
1502  Log->InPtr = 0;
1503  Log->Irp = NULL;
1504 
1505  *LogHandle = Log;
1506 
1508 
1509  return NDIS_STATUS_SUCCESS;
1510 }
1511 
1512 /*
1513  * @implemented
1514  */
1515 VOID
1516 EXPORT
1518  IN NDIS_HANDLE MiniportHandle)
1519 /*
1520  * FUNCTION: de-registers a shutdown handler
1521  * ARGUMENTS: MiniportHandle: Handle passed into MiniportInitialize
1522  */
1523 {
1524  PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportHandle;
1525 
1526  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
1527 
1528  if(Adapter->BugcheckContext->ShutdownHandler) {
1531  }
1532 }
1533 
1534 /*
1535  * @implemented
1536  */
1537 VOID
1538 EXPORT
1541 {
1542  PNDIS_LOG Log = (PNDIS_LOG) LogHandle;
1543  KIRQL OldIrql;
1544 
1545  NDIS_DbgPrint(MAX_TRACE, ("called: LogHandle 0x%x\n", LogHandle));
1546 
1547  /* Lock object */
1549 
1550  /* Set buffers size */
1551  Log->CurrentSize = 0;
1552  Log->OutPtr = 0;
1553  Log->InPtr = 0;
1554 
1555  /* Unlock object */
1557 }
1558 
1559 /*
1560  * @implemented
1561  */
1562 #undef NdisMIndicateStatus
1563 VOID
1564 EXPORT
1570 {
1572 }
1573 
1574 /*
1575  * @implemented
1576  */
1577 #undef NdisMIndicateStatusComplete
1578 VOID
1579 EXPORT
1582 {
1584 }
1585 
1586 /*
1587  * @implemented
1588  */
1589 VOID
1590 EXPORT
1592  OUT PNDIS_HANDLE NdisWrapperHandle,
1593  IN PVOID SystemSpecific1,
1596 /*
1597  * FUNCTION: Notifies the NDIS library that a new miniport is initializing
1598  * ARGUMENTS:
1599  * NdisWrapperHandle = Address of buffer to place NDIS wrapper handle
1600  * SystemSpecific1 = Pointer to the driver's driver object
1601  * SystemSpecific2 = Pointer to the driver's registry path
1602  * SystemSpecific3 = Always NULL
1603  * NOTES:
1604  * - SystemSpecific2 goes invalid so we copy it
1605  */
1606 {
1607  PNDIS_M_DRIVER_BLOCK Miniport;
1609  WCHAR *RegistryBuffer;
1610 
1611  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1612 
1613  ASSERT(NdisWrapperHandle);
1614 
1615  *NdisWrapperHandle = NULL;
1616 
1617 #if BREAK_ON_MINIPORT_INIT
1618  DbgBreakPoint();
1619 #endif
1620 
1621  Miniport = ExAllocatePool(NonPagedPool, sizeof(NDIS_M_DRIVER_BLOCK));
1622 
1623  if (!Miniport)
1624  {
1625  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1626  return;
1627  }
1628 
1629  RtlZeroMemory(Miniport, sizeof(NDIS_M_DRIVER_BLOCK));
1630 
1631  KeInitializeSpinLock(&Miniport->Lock);
1632 
1633  Miniport->DriverObject = (PDRIVER_OBJECT)SystemSpecific1;
1634 
1635  /* set the miniport's driver registry path */
1637  if(!RegistryPath)
1638  {
1639  ExFreePool(Miniport);
1640  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1641  return;
1642  }
1643 
1645  RegistryPath->MaximumLength = RegistryPath->Length + sizeof(WCHAR); /* room for 0-term */
1646 
1647  RegistryBuffer = ExAllocatePool(PagedPool, RegistryPath->MaximumLength);
1648  if(!RegistryBuffer)
1649  {
1650  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1651  ExFreePool(Miniport);
1653  return;
1654  }
1655 
1657  RegistryBuffer[RegistryPath->Length/sizeof(WCHAR)] = 0;
1658 
1659  RegistryPath->Buffer = RegistryBuffer;
1660  Miniport->RegistryPath = RegistryPath;
1661 
1662  InitializeListHead(&Miniport->DeviceList);
1663 
1664  /* Put miniport in global miniport list */
1666 
1667  *NdisWrapperHandle = Miniport;
1668 }
1669 
1671  IN PVOID Buffer,
1672  IN ULONG Length)
1673 /*
1674  * FUNCTION: Internal callback for handling bugchecks - calls adapter's shutdown handler
1675  * ARGUMENTS:
1676  * Buffer: Pointer to a bugcheck callback context
1677  * Length: Unused
1678  */
1679 {
1682 
1683  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
1684 
1685  if(sh)
1686  sh(Context->DriverContext);
1687 }
1688 
1689 /*
1690  * @implemented
1691  */
1692 VOID
1693 EXPORT
1695  IN NDIS_HANDLE MiniportHandle,
1696  IN PVOID ShutdownContext,
1698 /*
1699  * FUNCTION: Register a shutdown handler for an adapter
1700  * ARGUMENTS:
1701  * MiniportHandle: Handle originally passed into MiniportInitialize
1702  * ShutdownContext: Pre-initialized bugcheck context
1703  * ShutdownHandler: Function to call to handle the bugcheck
1704  * NOTES:
1705  * - I'm not sure about ShutdownContext
1706  */
1707 {
1708  PLOGICAL_ADAPTER Adapter = (PLOGICAL_ADAPTER)MiniportHandle;
1709  PMINIPORT_BUGCHECK_CONTEXT BugcheckContext;
1710 
1711  NDIS_DbgPrint(DEBUG_MINIPORT, ("Called.\n"));
1712 
1713  if (Adapter->BugcheckContext != NULL)
1714  {
1715  NDIS_DbgPrint(MIN_TRACE, ("Attempted to register again for a shutdown callback\n"));
1716  return;
1717  }
1718 
1719  BugcheckContext = ExAllocatePool(NonPagedPool, sizeof(MINIPORT_BUGCHECK_CONTEXT));
1720  if(!BugcheckContext)
1721  {
1722  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1723  return;
1724  }
1725 
1726  BugcheckContext->ShutdownHandler = ShutdownHandler;
1727  BugcheckContext->DriverContext = ShutdownContext;
1728 
1730  if (!BugcheckContext->CallbackRecord) {
1731  ExFreePool(BugcheckContext);
1732  return;
1733  }
1734 
1735  Adapter->BugcheckContext = BugcheckContext;
1736 
1737  KeInitializeCallbackRecord(BugcheckContext->CallbackRecord);
1738 
1740  BugcheckContext, sizeof(*BugcheckContext), (PUCHAR)"Ndis Miniport");
1741 
1743 }
1744 
1747  PLOGICAL_ADAPTER Adapter,
1748  NDIS_OID AddressOID)
1749 /*
1750  * FUNCTION: Queries miniport for information
1751  * ARGUMENTS:
1752  * Adapter = Pointer to logical adapter
1753  * AddressOID = OID to use to query for current address
1754  * RETURNS:
1755  * Status of operation
1756  */
1757 {
1759  NDIS_STATUS NdisStatus;
1760 
1761  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1762 
1763  /* Get MAC options for adapter */
1764  NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MAC_OPTIONS, sizeof(UINT),
1765  &Adapter->NdisMiniportBlock.MacOptions,
1766  &BytesWritten);
1767 
1768  if (NdisStatus != NDIS_STATUS_SUCCESS)
1769  {
1770  NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_MAC_OPTIONS failed. NdisStatus (0x%X).\n", NdisStatus));
1771  return NdisStatus;
1772  }
1773 
1774  NDIS_DbgPrint(DEBUG_MINIPORT, ("MacOptions (0x%X).\n", Adapter->NdisMiniportBlock.MacOptions));
1775 
1776  /* Get current hardware address of adapter */
1777  NdisStatus = MiniQueryInformation(Adapter, AddressOID, Adapter->AddressLength,
1778  &Adapter->Address, &BytesWritten);
1779 
1780  if (NdisStatus != NDIS_STATUS_SUCCESS)
1781  {
1782  NDIS_DbgPrint(MIN_TRACE, ("Address OID (0x%X) failed. NdisStatus (0x%X).\n", AddressOID, NdisStatus));
1783  return NdisStatus;
1784  }
1785 
1786 #if DBG
1787  {
1788  /* 802.3 only */
1789 
1790  PUCHAR A = (PUCHAR)&Adapter->Address.Type.Medium802_3;
1791 
1792  NDIS_DbgPrint(MAX_TRACE, ("Adapter address is (%02X %02X %02X %02X %02X %02X).\n", A[0], A[1], A[2], A[3], A[4], A[5]));
1793  }
1794 #endif /* DBG */
1795 
1796  /* Get maximum lookahead buffer size of adapter */
1797  NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MAXIMUM_LOOKAHEAD, sizeof(ULONG),
1799 
1800  if (NdisStatus != NDIS_STATUS_SUCCESS)
1801  {
1802  NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_MAXIMUM_LOOKAHEAD failed. NdisStatus (0x%X).\n", NdisStatus));
1803  return NdisStatus;
1804  }
1805 
1806  NDIS_DbgPrint(DEBUG_MINIPORT, ("MaxLookaheadLength (0x%X).\n", Adapter->NdisMiniportBlock.MaximumLookahead));
1807 
1808  /* Get current lookahead buffer size of adapter */
1809  NdisStatus = MiniQueryInformation(Adapter, OID_GEN_CURRENT_LOOKAHEAD, sizeof(ULONG),
1811 
1812  if (NdisStatus != NDIS_STATUS_SUCCESS)
1813  {
1814  NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_CURRENT_LOOKAHEAD failed. NdisStatus (0x%X).\n", NdisStatus));
1815  return NdisStatus;
1816  }
1817 
1818  NdisStatus = MiniQueryInformation(Adapter, OID_GEN_MAXIMUM_SEND_PACKETS, sizeof(ULONG),
1820 
1821  if (NdisStatus != NDIS_STATUS_SUCCESS)
1822  {
1823  NDIS_DbgPrint(MIN_TRACE, ("OID_GEN_MAXIMUM_SEND_PACKETS failed. NdisStatus (0x%X).\n", NdisStatus));
1824 
1825  /* Set it to 1 if it fails because some drivers don't support this (?)*/
1826  Adapter->NdisMiniportBlock.MaxSendPackets = 1;
1827  }
1828 
1829  NDIS_DbgPrint(DEBUG_MINIPORT, ("CurLookaheadLength (0x%X).\n", Adapter->NdisMiniportBlock.CurrentLookahead));
1830 
1831  return STATUS_SUCCESS;
1832 }
1833 
1834 NTSTATUS
1835 NTAPI
1837  PDEVICE_OBJECT Fdo,
1838  PIRP Irp,
1839  PVOID Context)
1840 {
1841  PKEVENT Event = Context;
1842 
1843  if (Irp->PendingReturned)
1845 
1847 }
1848 
1849 NTSTATUS
1850 NTAPI
1852 {
1853  KEVENT Event;
1854  NTSTATUS Status;
1855 
1859  TRUE, TRUE, TRUE);
1861  if (Status == STATUS_PENDING)
1862  {
1864  Status = Irp->IoStatus.Status;
1865  }
1866  return Status;
1867 }
1868 
1869 NTSTATUS
1870 NTAPI
1873  IN PIRP Irp)
1874 {
1875  Irp->IoStatus.Status = STATUS_SUCCESS;
1876  Irp->IoStatus.Information = 0;
1877 
1879 
1880  return STATUS_SUCCESS;
1881 }
1882 
1883 NTSTATUS
1884 NTAPI
1887  PIRP Irp)
1888 /*
1889  * FUNCTION: Handle the PnP start device event
1890  * ARGUMENTS:
1891  * DeviceObject = Functional Device Object
1892  * Irp = IRP_MN_START_DEVICE I/O request packet
1893  * RETURNS:
1894  * Status of operation
1895  */
1896 {
1899  NDIS_WRAPPER_CONTEXT WrapperContext;
1900  NDIS_STATUS NdisStatus;
1902  NTSTATUS Status;
1904  NDIS_OID AddressOID;
1905  BOOLEAN Success = FALSE;
1907  ULONG ResourceListSize;
1908  UNICODE_STRING ParamName;
1909  PNDIS_CONFIGURATION_PARAMETER ConfigParam;
1910  NDIS_HANDLE ConfigHandle;
1911  ULONG Size;
1913  UINT MaxMulticastAddresses;
1915  PLIST_ENTRY CurrentEntry;
1916  PPROTOCOL_BINDING ProtocolBinding;
1917 
1918  /*
1919  * Prepare wrapper context used by HW and configuration routines.
1920  */
1921 
1922  NDIS_DbgPrint(DEBUG_MINIPORT, ("Start Device %wZ\n", &Adapter->NdisMiniportBlock.MiniportName));
1923 
1924  NDIS_DbgPrint(MAX_TRACE, ("Inserting adapter 0x%x into adapter list\n", Adapter));
1925 
1926  /* Put adapter in global adapter list */
1928 
1931  KEY_ALL_ACCESS, &WrapperContext.RegistryHandle);
1932  if (!NT_SUCCESS(Status))
1933  {
1934  NDIS_DbgPrint(MIN_TRACE,("failed to open adapter-specific reg key\n"));
1936  return Status;
1937  }
1938 
1939  NDIS_DbgPrint(MAX_TRACE, ("opened device reg key\n"));
1940 
1941  WrapperContext.DeviceObject = Adapter->NdisMiniportBlock.DeviceObject;
1942 
1943  /*
1944  * Store the adapter resources used by HW routines such as
1945  * NdisMQueryAdapterResources.
1946  */
1947 
1948  if (Stack->Parameters.StartDevice.AllocatedResources != NULL)
1949  {
1950  ResourceCount = Stack->Parameters.StartDevice.AllocatedResources->List[0].
1951  PartialResourceList.Count;
1952  ResourceListSize =
1953  FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.
1954  PartialDescriptors[ResourceCount]);
1955 
1956  Adapter->NdisMiniportBlock.AllocatedResources =
1957  ExAllocatePool(PagedPool, ResourceListSize);
1958  if (Adapter->NdisMiniportBlock.AllocatedResources == NULL)
1959  {
1960  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
1963  }
1964 
1965  Adapter->NdisMiniportBlock.Resources =
1966  ExAllocatePool(PagedPool, ResourceListSize);
1967  if (!Adapter->NdisMiniportBlock.Resources)
1968  {
1969  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
1970  ExFreePool(Adapter->NdisMiniportBlock.AllocatedResources);
1973  }
1974 
1976  Stack->Parameters.StartDevice.AllocatedResources,
1977  ResourceListSize);
1978 
1979  RtlCopyMemory(Adapter->NdisMiniportBlock.AllocatedResources,
1980  Stack->Parameters.StartDevice.AllocatedResources,
1981  ResourceListSize);
1982  }
1983 
1984  if (Stack->Parameters.StartDevice.AllocatedResourcesTranslated != NULL)
1985  {
1986  ResourceCount = Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].
1987  PartialResourceList.Count;
1988  ResourceListSize =
1989  FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.
1990  PartialDescriptors[ResourceCount]);
1991 
1992  Adapter->NdisMiniportBlock.AllocatedResourcesTranslated =
1993  ExAllocatePool(PagedPool, ResourceListSize);
1994  if (Adapter->NdisMiniportBlock.AllocatedResourcesTranslated == NULL)
1995  {
1996  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
1999  }
2000 
2001  RtlCopyMemory(Adapter->NdisMiniportBlock.AllocatedResourcesTranslated,
2002  Stack->Parameters.StartDevice.AllocatedResourcesTranslated,
2003  ResourceListSize);
2004  }
2005 
2006  /*
2007  * Store the Bus Type, Bus Number and Slot information. It's used by
2008  * the hardware routines then.
2009  */
2010 
2011  NdisOpenConfiguration(&NdisStatus, &ConfigHandle, (NDIS_HANDLE)&WrapperContext);
2012  if (NdisStatus != NDIS_STATUS_SUCCESS)
2013  {
2014  NDIS_DbgPrint(MIN_TRACE, ("Failed to open configuration key\n"));
2016  return NdisStatus;
2017  }
2018 
2019  Size = sizeof(ULONG);
2022  &Adapter->NdisMiniportBlock.BusType, &Size);
2024  {
2025  NdisInitUnicodeString(&ParamName, L"BusType");
2026  NdisReadConfiguration(&NdisStatus, &ConfigParam, ConfigHandle,
2027  &ParamName, NdisParameterInteger);
2028  if (NdisStatus == NDIS_STATUS_SUCCESS)
2029  Adapter->NdisMiniportBlock.BusType = ConfigParam->ParameterData.IntegerData;
2030  else
2031  Adapter->NdisMiniportBlock.BusType = Isa;
2032  }
2033 
2036  &Adapter->NdisMiniportBlock.BusNumber, &Size);
2037  if (!NT_SUCCESS(Status) || Adapter->NdisMiniportBlock.BusNumber == 0xFFFFFFF0)
2038  {
2039  NdisInitUnicodeString(&ParamName, L"BusNumber");
2040  NdisReadConfiguration(&NdisStatus, &ConfigParam, ConfigHandle,
2041  &ParamName, NdisParameterInteger);
2042  if (NdisStatus == NDIS_STATUS_SUCCESS)
2043  Adapter->NdisMiniportBlock.BusNumber = ConfigParam->ParameterData.IntegerData;
2044  else
2045  Adapter->NdisMiniportBlock.BusNumber = 0;
2046  }
2047  WrapperContext.BusNumber = Adapter->NdisMiniportBlock.BusNumber;
2048 
2051  &Adapter->NdisMiniportBlock.SlotNumber, &Size);
2052  if (!NT_SUCCESS(Status) || Adapter->NdisMiniportBlock.SlotNumber == (NDIS_INTERFACE_TYPE)-1)
2053  {
2054  NdisInitUnicodeString(&ParamName, L"SlotNumber");
2055  NdisReadConfiguration(&NdisStatus, &ConfigParam, ConfigHandle,
2056  &ParamName, NdisParameterInteger);
2057  if (NdisStatus == NDIS_STATUS_SUCCESS)
2058  Adapter->NdisMiniportBlock.SlotNumber = ConfigParam->ParameterData.IntegerData;
2059  else
2060  Adapter->NdisMiniportBlock.SlotNumber = 0;
2061  }
2062  else
2063  {
2064  /* Convert slotnumber to PCI_SLOT_NUMBER */
2065  ULONG PciSlotNumber = Adapter->NdisMiniportBlock.SlotNumber;
2067 
2068  SlotNumber.u.AsULONG = 0;
2069  SlotNumber.u.bits.DeviceNumber = (PciSlotNumber >> 16) & 0xFFFF;
2070  SlotNumber.u.bits.FunctionNumber = PciSlotNumber & 0xFFFF;
2071 
2072  Adapter->NdisMiniportBlock.SlotNumber = SlotNumber.u.AsULONG;
2073  }
2074  WrapperContext.SlotNumber = Adapter->NdisMiniportBlock.SlotNumber;
2075 
2076  NdisCloseConfiguration(ConfigHandle);
2077 
2078  /* Set handlers (some NDIS macros require these) */
2091 
2092  /*
2093  * Call MiniportInitialize.
2094  */
2095 
2096  NDIS_DbgPrint(MID_TRACE, ("calling MiniportInitialize\n"));
2097  NdisStatus = (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.InitializeHandler)(
2099  MEDIA_ARRAY_SIZE, Adapter, (NDIS_HANDLE)&WrapperContext);
2100 
2101  ZwClose(WrapperContext.RegistryHandle);
2102 
2103  if (NdisStatus != NDIS_STATUS_SUCCESS)
2104  {
2105  NDIS_DbgPrint(MIN_TRACE, ("MiniportInitialize() failed for an adapter (%lx).\n", NdisStatus));
2107  if (Adapter->NdisMiniportBlock.Interrupt)
2108  {
2109  KeBugCheckEx(BUGCODE_ID_DRIVER,
2110  (ULONG_PTR)Adapter,
2112  (ULONG_PTR)Adapter->NdisMiniportBlock.TimerQueue,
2113  1);
2114  }
2115  if (Adapter->NdisMiniportBlock.TimerQueue)
2116  {
2117  KeBugCheckEx(BUGCODE_ID_DRIVER,
2118  (ULONG_PTR)Adapter,
2120  (ULONG_PTR)Adapter->NdisMiniportBlock.TimerQueue,
2121  1);
2122  }
2123  return NdisStatus;
2124  }
2125 
2127  {
2128  NDIS_DbgPrint(MIN_TRACE, ("MiniportInitialize() selected a bad index\n"));
2131  }
2132 
2134 
2135  switch (Adapter->NdisMiniportBlock.MediaType)
2136  {
2137  case NdisMedium802_3:
2138  Adapter->MediumHeaderSize = 14; /* XXX figure out what to do about LLC */
2139  AddressOID = OID_802_3_CURRENT_ADDRESS;
2141  NdisStatus = DoQueries(Adapter, AddressOID);
2142  if (NdisStatus == NDIS_STATUS_SUCCESS)
2143  {
2144  NdisStatus = MiniQueryInformation(Adapter, OID_802_3_MAXIMUM_LIST_SIZE, sizeof(UINT),
2145  &MaxMulticastAddresses, &BytesWritten);
2146 
2147  if (NdisStatus != NDIS_STATUS_SUCCESS)
2148  {
2150  NDIS_DbgPrint(MIN_TRACE, ("MiniQueryInformation failed (%x)\n", NdisStatus));
2151  return NdisStatus;
2152  }
2153 
2154  Success = EthCreateFilter(MaxMulticastAddresses,
2155  Adapter->Address.Type.Medium802_3,
2156  &Adapter->NdisMiniportBlock.EthDB);
2157  if (Success)
2158  ((PETHI_FILTER)Adapter->NdisMiniportBlock.EthDB)->Miniport = (PNDIS_MINIPORT_BLOCK)Adapter;
2159  else
2160  NdisStatus = NDIS_STATUS_RESOURCES;
2161  }
2162  break;
2163 
2164  default:
2165  /* FIXME: Support other types of media */
2166  NDIS_DbgPrint(MIN_TRACE, ("error: unsupported media\n"));
2167  ASSERT(FALSE);
2169  return STATUS_UNSUCCESSFUL;
2170  }
2171 
2172  if (NdisStatus != NDIS_STATUS_SUCCESS)
2173  {
2174  NDIS_DbgPrint(MIN_TRACE, ("couldn't create filter (%x)\n", NdisStatus));
2175  return NdisStatus;
2176  }
2177 
2178  /* Check for a hang every two seconds if it wasn't set in MiniportInitialize */
2179  if (Adapter->NdisMiniportBlock.CheckForHangSeconds == 0)
2181 
2182  Adapter->NdisMiniportBlock.OldPnPDeviceState = Adapter->NdisMiniportBlock.PnPDeviceState;
2183  Adapter->NdisMiniportBlock.PnPDeviceState = NdisPnPDeviceStarted;
2184 
2186 
2187  Timeout.QuadPart = Int32x32To64(Adapter->NdisMiniportBlock.CheckForHangSeconds, -1000000);
2189  Adapter->NdisMiniportBlock.CheckForHangSeconds * 1000,
2191 
2192  /* Put adapter in adapter list for this miniport */
2194 
2195  /* Refresh bindings for all protocols */
2196  CurrentEntry = ProtocolListHead.Flink;
2197  while (CurrentEntry != &ProtocolListHead)
2198  {
2199  ProtocolBinding = CONTAINING_RECORD(CurrentEntry, PROTOCOL_BINDING, ListEntry);
2200 
2201  ndisBindMiniportsToProtocol(&NdisStatus, ProtocolBinding);
2202 
2203  CurrentEntry = CurrentEntry->Flink;
2204  }
2205 
2206  return STATUS_SUCCESS;
2207 }
2208 
2209 NTSTATUS
2210 NTAPI
2213  PIRP Irp)
2214 /*
2215  * FUNCTION: Handle the PnP stop device event
2216  * ARGUMENTS:
2217  * DeviceObject = Functional Device Object
2218  * Irp = IRP_MN_STOP_DEVICE I/O request packet
2219  * RETURNS:
2220  * Status of operation
2221  */
2222 {
2224 
2225  /* Remove adapter from adapter list for this miniport */
2227 
2228  /* Remove adapter from global adapter list */
2230 
2232 
2233  /* Set this here so MiniportISR will be forced to run for interrupts generated in MiniportHalt */
2234  Adapter->NdisMiniportBlock.OldPnPDeviceState = Adapter->NdisMiniportBlock.PnPDeviceState;
2235  Adapter->NdisMiniportBlock.PnPDeviceState = NdisPnPDeviceStopped;
2236 
2237  (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.HaltHandler)(Adapter);
2238 
2240 
2241  if (Adapter->NdisMiniportBlock.AllocatedResources)
2242  {
2243  ExFreePool(Adapter->NdisMiniportBlock.AllocatedResources);
2244  Adapter->NdisMiniportBlock.AllocatedResources = NULL;
2245  }
2246  if (Adapter->NdisMiniportBlock.AllocatedResourcesTranslated)
2247  {
2248  ExFreePool(Adapter->NdisMiniportBlock.AllocatedResourcesTranslated);
2249  Adapter->NdisMiniportBlock.AllocatedResourcesTranslated = NULL;
2250  }
2251 
2252  if (Adapter->NdisMiniportBlock.Resources)
2253  {
2255  Adapter->NdisMiniportBlock.Resources = NULL;
2256  }
2257 
2258  if (Adapter->NdisMiniportBlock.EthDB)
2259  {
2260  EthDeleteFilter(Adapter->NdisMiniportBlock.EthDB);
2261  Adapter->NdisMiniportBlock.EthDB = NULL;
2262  }
2263 
2264  return STATUS_SUCCESS;
2265 }
2266 
2267 NTSTATUS
2268 NTAPI
2271  PIRP Irp)
2272 {
2276 
2278 
2279  ShutdownHandler(Context->DriverContext);
2280 
2281  Irp->IoStatus.Status = STATUS_SUCCESS;
2282  Irp->IoStatus.Information = 0;
2283 
2285 
2286  return STATUS_SUCCESS;
2287 }
2288 
2289 NTSTATUS
2290 NTAPI
2293  PIRP Irp)
2294 {
2299  ULONG Written;
2300 
2301  Irp->IoStatus.Information = 0;
2302 
2303  ASSERT(Adapter);
2304 
2305  ControlCode = Stack->Parameters.DeviceIoControl.IoControlCode;
2306  switch (ControlCode)
2307  {
2309  Status = MiniQueryInformation(Adapter,
2310  *(PNDIS_OID)Irp->AssociatedIrp.SystemBuffer,
2311  Stack->Parameters.DeviceIoControl.OutputBufferLength,
2312  MmGetSystemAddressForMdl(Irp->MdlAddress),
2313  &Written);
2314  Irp->IoStatus.Information = Written;
2315  break;
2316 
2317  default:
2318  NDIS_DbgPrint(MIN_TRACE, ("NdisIDeviceIoControl: unsupported control code 0x%lx\n", ControlCode));
2319  break;
2320  }
2321 
2322  if (Status != NDIS_STATUS_PENDING)
2323  {
2324  Irp->IoStatus.Status = Status;
2326  }
2327  else
2329 
2330  return Status;
2331 }
2332 
2333 NTSTATUS
2334 NTAPI
2337  PIRP Irp)
2338 {
2341  NTSTATUS Status;
2342 
2343  switch (Stack->MinorFunction)
2344  {
2345  case IRP_MN_START_DEVICE:
2346  Status = NdisIForwardIrpAndWait(Adapter, Irp);
2347  if (NT_SUCCESS(Status) && NT_SUCCESS(Irp->IoStatus.Status))
2348  {
2350  }
2351  else
2352  NDIS_DbgPrint(MIN_TRACE, ("Lower driver failed device start\n"));
2353  Irp->IoStatus.Status = Status;
2355  return Status;
2356 
2357  case IRP_MN_STOP_DEVICE:
2359  if (!NT_SUCCESS(Status))
2360  NDIS_DbgPrint(MIN_TRACE, ("WARNING: Ignoring halt device failure! Passing the IRP down anyway\n"));
2361  Irp->IoStatus.Status = STATUS_SUCCESS;
2362  break;
2363 
2367  Irp->IoStatus.Status = Status;
2368  if (Status != STATUS_SUCCESS)
2369  {
2371  NDIS_DbgPrint(MIN_TRACE, ("Failing miniport halt request\n"));
2372  return Status;
2373  }
2374  break;
2375 
2378  Status = NdisIForwardIrpAndWait(Adapter, Irp);
2379  if (NT_SUCCESS(Status) && NT_SUCCESS(Irp->IoStatus.Status))
2380  {
2382  }
2383  else
2384  {
2385  NDIS_DbgPrint(MIN_TRACE, ("Lower driver failed cancel stop/remove request\n"));
2386  }
2387  Irp->IoStatus.Status = Status;
2389  return Status;
2390 
2393  Irp->IoStatus.Status = Status;
2394  Irp->IoStatus.Information |= Adapter->NdisMiniportBlock.PnPFlags;
2395  break;
2396 
2397  default:
2398  break;
2399  }
2400 
2403 }
2404 
2405 NTSTATUS
2406 NTAPI
2409  _In_ PIRP Irp)
2410 {
2412 
2416 }
2417 
2418 NTSTATUS
2419 NTAPI
2423 /*
2424  * FUNCTION: Create a device for an adapter found using PnP
2425  * ARGUMENTS:
2426  * DriverObject = Pointer to the miniport driver object
2427  * PhysicalDeviceObject = Pointer to the PDO for our adapter
2428  */
2429 {
2430  static const WCHAR ClassKeyName[] = {'C','l','a','s','s','\\'};
2431  static const WCHAR LinkageKeyName[] = {'\\','L','i','n','k','a','g','e',0};
2432  PNDIS_M_DRIVER_BLOCK Miniport;
2433  PNDIS_M_DRIVER_BLOCK *MiniportPtr;
2434  WCHAR *LinkageKeyBuffer;
2435  ULONG DriverKeyLength;
2437  UNICODE_STRING ExportName;
2439  PLOGICAL_ADAPTER Adapter;
2440  NTSTATUS Status;
2441 
2442  /*
2443  * Gain the access to the miniport data structure first.
2444  */
2445 
2446  MiniportPtr = IoGetDriverObjectExtension(DriverObject, (PVOID)'NMID');
2447  if (MiniportPtr == NULL)
2448  {
2449  NDIS_DbgPrint(MIN_TRACE, ("Can't get driver object extension.\n"));
2450  return NDIS_STATUS_FAILURE;
2451  }
2452  Miniport = *MiniportPtr;
2453 
2454  /*
2455  * Get name of the Linkage registry key for our adapter. It's located under
2456  * the driver key for our driver and so we have basicly two ways to do it.
2457  * Either we can use IoOpenDriverRegistryKey or compose it using information
2458  * gathered by IoGetDeviceProperty. I chose the second because
2459  * IoOpenDriverRegistryKey wasn't implemented at the time of writing.
2460  */
2461 
2463  0, NULL, &DriverKeyLength);
2465  {
2466  NDIS_DbgPrint(MIN_TRACE, ("Can't get miniport driver key length.\n"));
2467  return Status;
2468  }
2469 
2470  LinkageKeyBuffer = ExAllocatePool(PagedPool, DriverKeyLength +
2471  sizeof(ClassKeyName) + sizeof(LinkageKeyName));
2472  if (LinkageKeyBuffer == NULL)
2473  {
2474  NDIS_DbgPrint(MIN_TRACE, ("Can't allocate memory for driver key name.\n"));
2476  }
2477 
2479  DriverKeyLength, LinkageKeyBuffer +
2480  (sizeof(ClassKeyName) / sizeof(WCHAR)),
2481  &DriverKeyLength);
2482  if (!NT_SUCCESS(Status))
2483  {
2484  NDIS_DbgPrint(MIN_TRACE, ("Can't get miniport driver key.\n"));
2485  ExFreePool(LinkageKeyBuffer);
2486  return Status;
2487  }
2488 
2489  /* Compose the linkage key name. */
2490  RtlCopyMemory(LinkageKeyBuffer, ClassKeyName, sizeof(ClassKeyName));
2491  RtlCopyMemory(LinkageKeyBuffer + ((sizeof(ClassKeyName) + DriverKeyLength) /
2492  sizeof(WCHAR)) - 1, LinkageKeyName, sizeof(LinkageKeyName));
2493 
2494  NDIS_DbgPrint(DEBUG_MINIPORT, ("LinkageKey: %S.\n", LinkageKeyBuffer));
2495 
2496  /*
2497  * Now open the linkage key and read the "Export" and "RootDevice" values
2498  * which contains device name and root service respectively.
2499  */
2500 
2502  RtlInitUnicodeString(&ExportName, NULL);
2504  QueryTable[0].Name = L"Export";
2505  QueryTable[0].EntryContext = &ExportName;
2506 
2508  QueryTable, NULL, NULL);
2509  ExFreePool(LinkageKeyBuffer);
2510  if (!NT_SUCCESS(Status))
2511  {
2512  NDIS_DbgPrint(MIN_TRACE, ("Can't get miniport device name. (%x)\n", Status));
2513  return Status;
2514  }
2515 
2516  /*
2517  * Create the device object.
2518  */
2519 
2520  NDIS_DbgPrint(MAX_TRACE, ("creating device %wZ\n", &ExportName));
2521 
2522  Status = IoCreateDevice(Miniport->DriverObject, sizeof(LOGICAL_ADAPTER),
2523  &ExportName, FILE_DEVICE_PHYSICAL_NETCARD,
2524  0, FALSE, &DeviceObject);
2525  if (!NT_SUCCESS(Status))
2526  {
2527  NDIS_DbgPrint(MIN_TRACE, ("Could not create device object.\n"));
2528  RtlFreeUnicodeString(&ExportName);
2529  return Status;
2530  }
2531 
2532  /*
2533  * Initialize the adapter structure.
2534  */
2535 
2539 
2541  &GUID_DEVINTERFACE_NET,
2542  NULL,
2544 
2545  if (!NT_SUCCESS(Status))
2546  {
2547  NDIS_DbgPrint(MIN_TRACE, ("Could not create device interface.\n"));
2549  RtlFreeUnicodeString(&ExportName);
2550  return Status;
2551  }
2552 
2553  Adapter->NdisMiniportBlock.DriverHandle = Miniport;
2554  Adapter->NdisMiniportBlock.MiniportName = ExportName;
2560 
2561  Adapter->NdisMiniportBlock.OldPnPDeviceState = 0;
2562  Adapter->NdisMiniportBlock.PnPDeviceState = NdisPnPDeviceAdded;
2563 
2566 
2568 
2569  return STATUS_SUCCESS;
2570 }
2571 
2572 NTSTATUS
2573 NTAPI
2576  IN PIRP Irp)
2577 {
2579 
2580  /* Use the characteristics to classify the device */
2581  if (DeviceObject->DeviceType == FILE_DEVICE_PHYSICAL_NETCARD)
2582  {
2583  if ((IrpSp->MajorFunction == IRP_MJ_CREATE) ||
2586  {
2588  }
2589  else if (IrpSp->MajorFunction == IRP_MJ_PNP)
2590  {
2592  }
2593  else if (IrpSp->MajorFunction == IRP_MJ_SHUTDOWN)
2594  {
2595  return NdisIShutdown(DeviceObject, Irp);
2596  }
2598  {
2600  }
2601  else if (IrpSp->MajorFunction == IRP_MJ_POWER)
2602  {
2603  return NdisIPower(DeviceObject, Irp);
2604  }
2605  NDIS_DbgPrint(MIN_TRACE, ("Unexpected IRP MajorFunction 0x%x\n", IrpSp->MajorFunction));
2606  ASSERT(FALSE);
2607  }
2608  else if (DeviceObject->DeviceType == FILE_DEVICE_NETWORK)
2609  {
2611 
2612  ASSERT(DeviceBlock->DeviceObject == DeviceObject);
2613 
2614  if (DeviceBlock->MajorFunction[IrpSp->MajorFunction] != NULL)
2615  {
2616  return DeviceBlock->MajorFunction[IrpSp->MajorFunction](DeviceObject, Irp);
2617  }
2618  }
2619  else
2620  {
2621  ASSERT(FALSE);
2622  }
2623 
2624  Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
2625  Irp->IoStatus.Information = 0;
2626 
2628 
2630 }
2631 
2632 /*
2633  * @implemented
2634  */
2636 EXPORT
2638  IN NDIS_HANDLE NdisWrapperHandle,
2639  IN PNDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics,
2641 /*
2642  * FUNCTION: Registers a miniport's MiniportXxx entry points with the NDIS library
2643  * ARGUMENTS:
2644  * NdisWrapperHandle = Pointer to handle returned by NdisMInitializeWrapper
2645  * MiniportCharacteristics = Pointer to a buffer with miniport characteristics
2646  * CharacteristicsLength = Number of bytes in characteristics buffer
2647  * RETURNS:
2648  * Status of operation
2649  */
2650 {
2651  UINT MinSize;
2652  PNDIS_M_DRIVER_BLOCK Miniport = GET_MINIPORT_DRIVER(NdisWrapperHandle);
2653  PNDIS_M_DRIVER_BLOCK *MiniportPtr;
2654  NTSTATUS Status;
2655  ULONG i;
2656 
2657  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
2658 
2659  switch (MiniportCharacteristics->MajorNdisVersion)
2660  {
2661  case 0x03:
2662  MinSize = sizeof(NDIS30_MINIPORT_CHARACTERISTICS);
2663  break;
2664 
2665  case 0x04:
2666  MinSize = sizeof(NDIS40_MINIPORT_CHARACTERISTICS);
2667  break;
2668 
2669  case 0x05:
2670  switch (MiniportCharacteristics->MinorNdisVersion)
2671  {
2672  case 0x00:
2673  MinSize = sizeof(NDIS50_MINIPORT_CHARACTERISTICS);
2674  break;
2675 
2676  case 0x01:
2677  MinSize = sizeof(NDIS51_MINIPORT_CHARACTERISTICS);
2678  break;
2679 
2680  default:
2681  NDIS_DbgPrint(MIN_TRACE, ("Bad 5.x minor characteristics version.\n"));
2682  return NDIS_STATUS_BAD_VERSION;
2683  }
2684  break;
2685 
2686  default:
2687  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics version.\n"));
2688  return NDIS_STATUS_BAD_VERSION;
2689  }
2690 
2691  NDIS_DbgPrint(MID_TRACE, ("Initializing an NDIS %u.%u miniport\n",
2692  MiniportCharacteristics->MajorNdisVersion,
2693  MiniportCharacteristics->MinorNdisVersion));
2694 
2695  if (CharacteristicsLength < MinSize)
2696  {
2697  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics length.\n"));
2699  }
2700 
2701  /* Check if mandatory MiniportXxx functions are specified */
2702  if ((!MiniportCharacteristics->HaltHandler) ||
2703  (!MiniportCharacteristics->InitializeHandler)||
2704  (!MiniportCharacteristics->ResetHandler))
2705  {
2706  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics.\n"));
2708  }
2709 
2710  if (MiniportCharacteristics->MajorNdisVersion < 0x05)
2711  {
2712  if ((!MiniportCharacteristics->QueryInformationHandler) ||
2713  (!MiniportCharacteristics->SetInformationHandler))
2714  {
2715  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics. (Set/Query)\n"));
2717  }
2718  }
2719  else
2720  {
2721  if (((!MiniportCharacteristics->QueryInformationHandler) ||
2722  (!MiniportCharacteristics->SetInformationHandler)) &&
2723  (!MiniportCharacteristics->CoRequestHandler))
2724  {
2725  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics. (Set/Query)\n"));
2727  }
2728  }
2729 
2730  if (MiniportCharacteristics->MajorNdisVersion == 0x03)
2731  {
2732  if (!MiniportCharacteristics->SendHandler)
2733  {
2734  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics. (NDIS 3.0)\n"));
2736  }
2737  }
2738  else if (MiniportCharacteristics->MajorNdisVersion == 0x04)
2739  {
2740  /* NDIS 4.0 */
2741  if ((!MiniportCharacteristics->SendHandler) &&
2742  (!MiniportCharacteristics->SendPacketsHandler))
2743  {
2744  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics. (NDIS 4.0)\n"));
2746  }
2747  }
2748  else if (MiniportCharacteristics->MajorNdisVersion == 0x05)
2749  {
2750  /* TODO: Add more checks here */
2751 
2752  if ((!MiniportCharacteristics->SendHandler) &&
2753  (!MiniportCharacteristics->SendPacketsHandler) &&
2754  (!MiniportCharacteristics->CoSendPacketsHandler))
2755  {
2756  NDIS_DbgPrint(MIN_TRACE, ("Bad miniport characteristics. (NDIS 5.0)\n"));
2758  }
2759  }
2760 
2761  RtlCopyMemory(&Miniport->MiniportCharacteristics, MiniportCharacteristics, MinSize);
2762 
2763  /*
2764  * NOTE: This is VERY unoptimal! Should we store the NDIS_M_DRIVER_BLOCK
2765  * structure in the driver extension or what?
2766  */
2767 
2769  sizeof(PNDIS_M_DRIVER_BLOCK), (PVOID*)&MiniportPtr);
2770  if (!NT_SUCCESS(Status))
2771  {
2772  NDIS_DbgPrint(MIN_TRACE, ("Can't allocate driver object extension.\n"));
2773  return NDIS_STATUS_RESOURCES;
2774  }
2775 
2776  *MiniportPtr = Miniport;
2777 
2778  /* We have to register for all of these so handler registered in NdisMRegisterDevice work */
2779  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
2780  {
2782  }
2783 
2785 
2786  return NDIS_STATUS_SUCCESS;
2787 }
2788 
2789 /*
2790  * @implemented
2791  */
2792 #undef NdisMResetComplete
2793 VOID
2794 EXPORT
2798  IN BOOLEAN AddressingReset)
2799 {
2800  MiniResetComplete(MiniportAdapterHandle, Status, AddressingReset);
2801 }
2802 
2803 /*
2804  * @implemented
2805  */
2806 #undef NdisMSendComplete
2807 VOID
2808 EXPORT
2813 /*
2814  * FUNCTION: Forwards a message to the initiating protocol saying
2815  * that a packet was handled
2816  * ARGUMENTS:
2817  * NdisAdapterHandle = Handle input to MiniportInitialize
2818  * Packet = Pointer to NDIS packet that was sent
2819  * Status = Status of send operation
2820  */
2821 {
2823 }
2824 
2825 /*
2826  * @implemented
2827  */
2828 #undef NdisMSendResourcesAvailable
2829 VOID
2830 EXPORT
2833 {
2835 }
2836 
2837 /*
2838  * @implemented
2839  */
2840 #undef NdisMTransferDataComplete
2841 VOID
2842 EXPORT
2847  IN UINT BytesTransferred)
2848 {
2850 }
2851 
2852 /*
2853  * @implemented
2854  */
2855 #undef NdisMSetAttributes
2856 VOID
2857 EXPORT
2860  IN NDIS_HANDLE MiniportAdapterContext,
2861  IN BOOLEAN BusMaster,
2863 /*
2864  * FUNCTION: Informs the NDIS library of significant features of the caller's NIC
2865  * ARGUMENTS:
2866  * MiniportAdapterHandle = Handle input to MiniportInitialize
2867  * MiniportAdapterContext = Pointer to context information
2868  * BusMaster = Specifies TRUE if the caller's NIC is a busmaster DMA device
2869  * AdapterType = Specifies the I/O bus interface of the caller's NIC
2870  */
2871 {
2872  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
2873  NdisMSetAttributesEx(MiniportAdapterHandle, MiniportAdapterContext, 0,
2874  BusMaster ? NDIS_ATTRIBUTE_BUS_MASTER : 0,
2875  AdapterType);
2876 }
2877 
2878 /*
2879  * @implemented
2880  */
2881 VOID
2882 EXPORT
2885  IN NDIS_HANDLE MiniportAdapterContext,
2886  IN UINT CheckForHangTimeInSeconds OPTIONAL,
2887  IN ULONG AttributeFlags,
2889 /*
2890  * FUNCTION: Informs the NDIS library of significant features of the caller's NIC
2891  * ARGUMENTS:
2892  * MiniportAdapterHandle = Handle input to MiniportInitialize
2893  * MiniportAdapterContext = Pointer to context information
2894  * CheckForHangTimeInSeconds = Specifies interval in seconds at which
2895  * MiniportCheckForHang should be called
2896  * AttributeFlags = Bitmask that indicates specific attributes
2897  * AdapterType = Specifies the I/O bus interface of the caller's NIC
2898  */
2899 {
2901 
2902  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
2903 
2904  Adapter->NdisMiniportBlock.MiniportAdapterContext = MiniportAdapterContext;
2905  Adapter->NdisMiniportBlock.Flags = AttributeFlags;
2907  if (CheckForHangTimeInSeconds > 0)
2908  Adapter->NdisMiniportBlock.CheckForHangSeconds = CheckForHangTimeInSeconds;
2909  if (AttributeFlags & NDIS_ATTRIBUTE_INTERMEDIATE_DRIVER)
2910  NDIS_DbgPrint(MIN_TRACE, ("Intermediate drivers not supported yet.\n"));
2911 
2912  NDIS_DbgPrint(MID_TRACE, ("Miniport attribute flags: 0x%x\n", AttributeFlags));
2913 
2914  if (Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.AdapterShutdownHandler)
2915  {
2916  NDIS_DbgPrint(MAX_TRACE, ("Miniport set AdapterShutdownHandler in MiniportCharacteristics\n"));
2919  Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.AdapterShutdownHandler);
2920  }
2921 }
2922 
2923 /*
2924  * @implemented
2925  */
2926 VOID
2927 EXPORT
2929  IN ULONG MicrosecondsToSleep)
2930 /*
2931  * FUNCTION: delay the thread's execution for MicrosecondsToSleep
2932  * ARGUMENTS:
2933  * MicrosecondsToSleep: duh...
2934  * NOTES:
2935  * - Because this is a blocking call, current IRQL must be < DISPATCH_LEVEL
2936  */
2937 {
2938  KTIMER Timer;
2940 
2941  PAGED_CODE();
2942 
2943  DueTime.QuadPart = (-1) * 10 * MicrosecondsToSleep;
2944 
2946  KeSetTimer(&Timer, DueTime, 0);
2948 }
2949 
2950 /*
2951  * @implemented
2952  */
2953 BOOLEAN
2954 EXPORT
2956  IN PNDIS_MINIPORT_INTERRUPT Interrupt,
2957  IN PVOID SynchronizeFunction,
2959 {
2960  return(KeSynchronizeExecution(Interrupt->InterruptObject,
2961  (PKSYNCHRONIZE_ROUTINE)SynchronizeFunction,
2963 }
2964 
2965 /*
2966  * @unimplemented
2967  */
2969 EXPORT
2972  IN PVOID LogBuffer,
2974 {
2975  PUCHAR Buffer = LogBuffer;
2976  UINT i, j, idx;
2977 
2978  UNIMPLEMENTED;
2979  for (i = 0; i < LogBufferSize; i += 16)
2980  {
2981  DbgPrint("%08x |", i);
2982  for (j = 0; j < 16; j++)
2983  {
2984  idx = i + j;
2985  if (idx < LogBufferSize)
2986  DbgPrint(" %02x", Buffer[idx]);
2987  else
2988  DbgPrint(" ");
2989  }
2990  DbgPrint(" | ");
2991  for (j = 0; j < 16; j++)
2992  {
2993  idx = i + j;
2994  if (idx == LogBufferSize)
2995  break;
2996  if (Buffer[idx] >= ' ') /* FIXME: not portable! replace by if (isprint(Buffer[idx])) ? */
2997  DbgPrint("%c", Buffer[idx]);
2998  else
2999  DbgPrint(".");
3000  }
3001  DbgPrint("\n");
3002  }
3003 
3004  return NDIS_STATUS_FAILURE;
3005 }
3006 
3007 /*
3008  * @implemented
3009  */
3010 VOID
3011 EXPORT
3013  IN NDIS_HANDLE NdisWrapperHandle,
3015 /*
3016  * FUNCTION: Releases resources allocated by a call to NdisInitializeWrapper
3017  * ARGUMENTS:
3018  * NdisWrapperHandle = Handle returned by NdisInitializeWrapper (NDIS_M_DRIVER_BLOCK)
3019  * SystemSpecific = Always NULL
3020  */
3021 {
3022  PNDIS_M_DRIVER_BLOCK Miniport = GET_MINIPORT_DRIVER(NdisWrapperHandle);
3023 
3024  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
3025 
3026  ExFreePool(Miniport->RegistryPath->Buffer);
3027  ExFreePool(Miniport->RegistryPath);
3029  ExFreePool(Miniport);
3030 }
3031 
3032 
3033 /*
3034  * @implemented
3035  */
3037 EXPORT
3039  OUT PNDIS_STRING AdapterInstanceName,
3041 /*
3042  * FUNCTION:
3043  * ARGUMENTS:
3044  * NOTES:
3045  * NDIS 5.0
3046  */
3047 {
3050 
3051  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
3052 
3053  AdapterName.Length = 0;
3054  AdapterName.MaximumLength = Adapter->NdisMiniportBlock.MiniportName.MaximumLength;
3055  AdapterName.Buffer = ExAllocatePool(PagedPool, AdapterName.MaximumLength);
3056  if (!AdapterName.Buffer) {
3057  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
3058  return NDIS_STATUS_RESOURCES;
3059  }
3060 
3062 
3063  *AdapterInstanceName = AdapterName;
3064 
3065  return NDIS_STATUS_SUCCESS;
3066 }
3067 
3068 /*
3069  * @implemented
3070  */
3071 VOID
3072 EXPORT
3074  IN NDIS_HANDLE NdisAdapterHandle)
3075 /*
3076  * FUNCTION:
3077  * ARGUMENTS:
3078  * NOTES:
3079  * NDIS 4.0
3080  */
3081 {
3082  NdisMDeregisterAdapterShutdownHandler(NdisAdapterHandle);
3083 }
3084 
3085 
3086 /*
3087  * @implemented
3088  */
3089 VOID
3090 EXPORT
3092  IN NDIS_HANDLE NdisAdapterHandle,
3093  IN PVOID ShutdownContext,
3095 /*
3096  * FUNCTION:
3097  * ARGUMENTS:
3098  * NOTES:
3099  * NDIS 4.0
3100  */
3101 {
3102  NdisMRegisterAdapterShutdownHandler(NdisAdapterHandle,
3103  ShutdownContext,
3104  ShutdownHandler);
3105 }
3106 
3107 /*
3108  * @implemented
3109  */
3110 VOID
3111 EXPORT
3119 /*
3120  * FUNCTION:
3121  * ARGUMENTS:
3122  * NOTES:
3123  * NDIS 5.0
3124  */
3125 {
3127 
3128  NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
3129 
3130  if (PhysicalDeviceObject != NULL)
3132 
3135 
3136  if (NextDeviceObject != NULL)
3138 
3139  if (AllocatedResources != NULL)
3140  *AllocatedResources = Adapter->NdisMiniportBlock.AllocatedResources;
3141 
3143  *AllocatedResourcesTranslated = Adapter->NdisMiniportBlock.AllocatedResourcesTranslated;
3144 }
3145 
3146 /*
3147  * @implemented
3148  */
3149 VOID
3150 EXPORT
3152  IN NDIS_HANDLE NdisWrapperHandle,
3154 /*
3155  * FUNCTION:
3156  * ARGUMENTS:
3157  * NOTES:
3158  * NDIS 5.0
3159  */
3160 {
3161  PNDIS_M_DRIVER_BLOCK DriverBlock = NdisWrapperHandle;
3162 
3163  NDIS_DbgPrint(MAX_TRACE, ("Miniport registered unload handler\n"));
3164 
3165  DriverBlock->DriverObject->DriverUnload = UnloadHandler;
3166 }
3167 
3168 /*
3169  * @implemented
3170  */
3172 EXPORT
3174  IN NDIS_HANDLE NdisWrapperHandle,
3177  IN PDRIVER_DISPATCH MajorFunctions[],
3180 /*
3181  * FUNCTION:
3182  * ARGUMENTS:
3183  * NOTES:
3184  * NDIS 5.0
3185  */
3186 {
3187  PNDIS_M_DRIVER_BLOCK DriverBlock = NdisWrapperHandle;
3188  PNDIS_M_DEVICE_BLOCK DeviceBlock;
3191  UINT i;
3192 
3193  NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
3194 
3195  Status = IoCreateDevice(DriverBlock->DriverObject,
3196  sizeof(NDIS_M_DEVICE_BLOCK),
3197  DeviceName,
3199  0,
3200  FALSE,
3201  &DeviceObject);
3202 
3203  if (!NT_SUCCESS(Status))
3204  {
3205  NDIS_DbgPrint(MIN_TRACE, ("IoCreateDevice failed (%x)\n", Status));
3206  return Status;
3207  }
3208 
3210 
3211  if (!NT_SUCCESS(Status))
3212  {
3213  NDIS_DbgPrint(MIN_TRACE, ("IoCreateSymbolicLink failed (%x)\n", Status));
3215  return Status;
3216  }
3217 
3218  DeviceBlock = DeviceObject->DeviceExtension;
3219 
3220  if (!DeviceBlock)
3221  {
3222  NDIS_DbgPrint(MIN_TRACE, ("Insufficient resources\n"));
3225  return NDIS_STATUS_RESOURCES;
3226  }
3227 
3228  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
3229  DeviceBlock->MajorFunction[i] = MajorFunctions[i];
3230 
3231  DeviceBlock->DeviceObject = DeviceObject;
3232  DeviceBlock->SymbolicName = SymbolicName;
3233 
3235  *NdisDeviceHandle = DeviceBlock;
3236 
3237  return NDIS_STATUS_SUCCESS;
3238 }
3239 
3240 /*
3241  * @implemented
3242  */
3244 EXPORT
3247 /*
3248  * FUNCTION:
3249  * ARGUMENTS:
3250  * NOTES:
3251  * NDIS 5.0
3252  */
3253 {
3254  PNDIS_M_DEVICE_BLOCK DeviceBlock = NdisDeviceHandle;
3255 
3256  IoDeleteDevice(DeviceBlock->DeviceObject);
3257 
3258  IoDeleteSymbolicLink(DeviceBlock->SymbolicName);
3259 
3260  return NDIS_STATUS_SUCCESS;
3261 }
3262 
3263 /*
3264  * @implemented
3265  */
3267 EXPORT
3269  OUT PNDIS_STRING AdapterInstanceName,
3271 /*
3272  * FUNCTION:
3273  * ARGUMENTS:
3274  * NOTES:
3275  * NDIS 5.0
3276  */
3277 {
3278  PADAPTER_BINDING AdapterBinding = NdisBindingHandle;
3279  PLOGICAL_ADAPTER Adapter = AdapterBinding->Adapter;
3280 
3281  return NdisMQueryAdapterInstanceName(AdapterInstanceName,
3282  Adapter);
3283 }
3284 
3285 /*
3286  * @implemented
3287  */
3288 VOID
3289 EXPORT
3294 /*
3295  * FUNCTION:
3296  * ARGUMENTS:
3297  * NOTES:
3298  * NDIS 5.0
3299  */
3300 {
3301  PIRP Irp = (PIRP)NetPnPEvent->NdisReserved[0];
3302  PLIST_ENTRY CurrentEntry = (PLIST_ENTRY)NetPnPEvent->NdisReserved[1];
3303  PADAPTER_BINDING AdapterBinding = NdisBindingHandle;
3304  PLOGICAL_ADAPTER Adapter = AdapterBinding->Adapter;
3305  NDIS_STATUS NdisStatus;
3306 
3307  if (Status != NDIS_STATUS_SUCCESS)
3308  {
3309  if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
3311  Irp->IoStatus.Status = Status;
3313  return;
3314  }
3315 
3316  while (CurrentEntry != &Adapter->ProtocolListHead)
3317  {
3318  AdapterBinding = CONTAINING_RECORD(CurrentEntry, ADAPTER_BINDING, AdapterListEntry);
3319 
3320  NdisStatus = (*AdapterBinding->ProtocolBinding->Chars.PnPEventHandler)(
3321  AdapterBinding->NdisOpenBlock.ProtocolBindingContext,
3322  NetPnPEvent);
3323 
3324  if (NdisStatus == NDIS_STATUS_PENDING)
3325  {
3326  NetPnPEvent->NdisReserved[1] = (ULONG_PTR)CurrentEntry->Flink;
3327  return;
3328  }
3329  else if (NdisStatus != NDIS_STATUS_SUCCESS)
3330  {
3331  if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
3333  Irp->IoStatus.Status = NdisStatus;
3335  return;
3336  }
3337 
3338  CurrentEntry = CurrentEntry->Flink;
3339  }
3340 
3341  if (NetPnPEvent->Buffer) ExFreePool(NetPnPEvent->Buffer);
3343 
3344  Irp->IoStatus.Status = NDIS_STATUS_SUCCESS;
3346 }
3347 
3348 /*
3349  * @implemented
3350  */
3351 VOID
3352 EXPORT
3355  IN PVOID CancelId)
3356 {
3357  PADAPTER_BINDING AdapterBinding = NdisBindingHandle;
3358  PLOGICAL_ADAPTER Adapter = AdapterBinding->Adapter;
3359 
3360  NDIS_DbgPrint(MAX_TRACE, ("Called for ID %x.\n", CancelId));
3361 
3362  if (Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CancelSendPacketsHandler)
3363  {
3364  (*Adapter->NdisMiniportBlock.DriverHandle->MiniportCharacteristics.CancelSendPacketsHandler)(
3366  CancelId);
3367  }
3368 }
3369 
3370 
3371 /*
3372  * @implemented
3373  */
3375 EXPORT
3378 /*
3379  * FUNCTION:
3380  * ARGUMENTS:
3381  * NOTES:
3382  * NDIS 5.0
3383  */
3384 {
3385  PADAPTER_BINDING AdapterBinding = NdisBindingHandle;
3386  PLOGICAL_ADAPTER Adapter = AdapterBinding->Adapter;
3387 
3388  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
3389 
3390  return Adapter->NdisMiniportBlock.DeviceContext;
3391 }
3392 
3393 
3394 /*
3395  * @implemented
3396  */
3398 EXPORT
3401 /*
3402  * FUNCTION:
3403  * ARGUMENTS:
3404  * NOTES:
3405  * NDIS 5.0
3406  */
3407 {
3409 
3410  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
3411 
3412  return Adapter->NdisMiniportBlock.DeviceContext;
3413 }
3414 
3415 /* EOF */
_In_ PPNDIS_PACKET _In_ UINT NumberOfPackets
Definition: ndis.h:5120
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
LIST_ENTRY DeviceList
Definition: miniport.h:25
PKBUGCHECK_CALLBACK_RECORD CallbackRecord
Definition: miniport.h:60
LIST_ENTRY MiniportListEntry
Definition: miniport.h:93
#define IRP_MN_CANCEL_REMOVE_DEVICE
NDIS_M_REQ_COMPLETE_HANDLER QueryCompleteHandler
Definition: ndis.h:2585
VOID EXPORT NdisMSendComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status)
Definition: miniport.c:2809
UINT MaximumLookahead
Definition: ndis.h:2570
NDIS_M_TD_COMPLETE_HANDLER TDCompleteHandler
Definition: ndis.h:2584
VOID EXPORT NdisMSetInformationComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_STATUS Status)
Definition: miniport.c:1187
#define ExInterlockedRemoveEntryList(_List, _Lock)
Definition: ndissys.h:37
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4004
#define IN
Definition: typedefs.h:38
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
ADAPTER_SHUTDOWN_HANDLER ShutdownHandler
Definition: miniport.h:59
NTSTATUS NTAPI NdisIAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: miniport.c:2420
PDEVICE_OBJECT PhysicalDeviceObject
Definition: ndis.h:2553
struct _NDIS51_MINIPORT_CHARACTERISTICS NDIS51_MINIPORT_CHARACTERISTICS
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
_In_opt_ NDIS_HANDLE _In_opt_ NDIS_HANDLE _Inout_ PNDIS_REQUEST NdisRequest
Definition: ndis.h:1571
PLOGICAL_ADAPTER MiniLocateDevice(PNDIS_STRING AdapterName)
Definition: miniport.c:690
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID MiniWorkItemComplete(PLOGICAL_ADAPTER Adapter, NDIS_WORK_ITEM_TYPE WorkItemType)
Definition: miniport.c:964
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
#define MID_TRACE
Definition: debug.h:15
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics
Definition: miniport.h:22
NDIS_OPEN_BLOCK NdisOpenBlock
Definition: protocol.h:22
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
PNDIS_MINIPORT_TIMER TimerQueue
Definition: ndis.h:2564
enum _INTERFACE_TYPE INTERFACE_TYPE
PMINIPORT_BUGCHECK_CONTEXT BugcheckContext
Definition: miniport.h:98
NTSTATUS NTAPI NdisIPnPQueryStopDevice(IN PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: protocol.c:154
NDIS_STATUS DoQueries(PLOGICAL_ADAPTER Adapter, NDIS_OID AddressOID)
Definition: miniport.c:1746
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:6008
#define FILE_DEVICE_NETWORK
Definition: winioctl.h:123
Type
Definition: Type.h:6
VOID EXPORT NdisMResetComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_STATUS Status, IN BOOLEAN AddressingReset)
Definition: miniport.c:2795
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI EthFilterDprIndicateReceiveComplete(IN PETH_FILTER Filter)
Definition: efilter.c:113
#define IOCTL_NDIS_QUERY_GLOBAL_STATS
Definition: ntddndis.h:439
NDIS_INTERFACE_TYPE AdapterType
Definition: ndis.h:2551
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1764
enum _NDIS_MEDIUM NDIS_MEDIUM
#define DbgPrint
Definition: loader.c:25
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define NDIS_ATTRIBUTE_DESERIALIZE
Definition: ndis.h:588
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
NDIS_STATUS ResetStatus
Definition: ndis.h:2541
VOID EXPORT NdisMCloseLog(IN NDIS_HANDLE LogHandle)
Definition: miniport.c:1447
VOID EXPORT NdisMDeregisterAdapterShutdownHandler(IN NDIS_HANDLE MiniportHandle)
Definition: miniport.c:1517
#define IRP_MJ_SHUTDOWN
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4640
UINT CurrentSize
Definition: ndis.h:2479
_In_ PIRP Irp
Definition: csq.h:116
struct _MINIPORT_BUGCHECK_CONTEXT * PMINIPORT_BUGCHECK_CONTEXT
LIST_ENTRY ProtocolListHead
Definition: protocol.c:19
PNDIS_MINIPORT_WORK_ITEM WorkQueueHead
Definition: miniport.h:90
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
VOID EXPORT NdisOpenConfiguration(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE ConfigurationHandle, IN NDIS_HANDLE WrapperConfigurationContext)
Definition: config.c:197
MDL * PNDIS_BUFFER
Definition: ndis.h:343
NTSTATUS NTAPI NdisIForwardIrpAndWaitCompletionRoutine(PDEVICE_OBJECT Fdo, PIRP Irp, PVOID Context)
Definition: miniport.c:1836
_In_opt_ PVOID SystemSpecific
Definition: ndis.h:5840
NTSTATUS NTAPI NdisIPnPStopDevice(IN PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: miniport.c:2211
unsigned char * PUCHAR
Definition: retypes.h:3
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
VOID EXPORT NdisMTransferDataComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status, IN UINT BytesTransferred)
Definition: miniport.c:2843
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PNDIS_STRING _In_ PNDIS_STRING SymbolicName
Definition: ndis.h:4676
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
#define OID_GEN_MAC_OPTIONS
Definition: ntddndis.h:251
VOID MiniDoAddressingReset(PLOGICAL_ADAPTER Adapter)
Definition: miniport.c:888
#define IRP_MJ_MAXIMUM_FUNCTION
LONG NTSTATUS
Definition: precomp.h:26
#define KeInitializeCallbackRecord(CallbackRecord)
Definition: kefuncs.h:1479
ULONG NDIS_OID
Definition: ntddndis.h:230
_In_ NDIS_HANDLE MiniportAdapterHandle
Definition: ndis.h:4668
#define NDIS_STATUS_RESET_START
Definition: ndis.h:354
PNDIS_MINIPORT_WORK_ITEM MiniGetFirstWorkItem(PLOGICAL_ADAPTER Adapter, NDIS_WORK_ITEM_TYPE Type)
Definition: miniport.c:124
_In_ PVOID _In_ PVOID _In_ PVOID SystemSpecific3
Definition: ndis.h:637
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _NDIS_REQUEST * PNDIS_REQUEST
_In_opt_ PVOID _In_ PIO_WORKITEM IoWorkItem
Definition: iotypes.h:488
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS GeneralStatus
Definition: ndis.h:1555
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT SelectedMediumIndex
Definition: ndis.h:6008
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define NDIS_STATUS_UNSUPPORTED_MEDIA
Definition: ndis.h:490
#define DEBUG_MINIPORT
Definition: debug.h:17
PIRP Irp
Definition: ndis.h:2477
NDIS_M_REQ_COMPLETE_HANDLER SetCompleteHandler
Definition: ndis.h:2586
void DbgBreakPoint()
Definition: mach.c:553
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NDIS_HANDLE EXPORT NdisIMGetDeviceContext(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:3399
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FASTCALL
Definition: nt_native.h:50
LONG CancelId
Definition: main.c:23
KSPIN_LOCK LogLock
Definition: ndis.h:2476
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
NDIS_STATUS EXPORT NdisMCreateLog(IN NDIS_HANDLE MiniportAdapterHandle, IN UINT Size, OUT PNDIS_HANDLE LogHandle)
Definition: miniport.c:1468
_In_ NDIS_HANDLE _In_ PNET_PNP_EVENT NetPnPEvent
Definition: ndis.h:6081
#define PAGED_CODE()
Definition: video.h:57
VOID EXPORT NdisInitializeWrapper(OUT PNDIS_HANDLE NdisWrapperHandle, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2, IN PVOID SystemSpecific3)
Definition: miniport.c:1591
STATUS_HANDLER StatusHandler
Definition: ndis.h:1893
VOID NTAPI EthFilterDprIndicateReceive(IN PETH_FILTER Filter, IN NDIS_HANDLE MacReceiveContext, IN PCHAR Address, IN PVOID HeaderBuffer, IN UINT HeaderBufferSize, IN PVOID LookaheadBuffer, IN UINT LookaheadBufferSize, IN UINT PacketSize)
Definition: efilter.c:69
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
VOID EXPORT NdisMRegisterUnloadHandler(IN NDIS_HANDLE NdisWrapperHandle, IN PDRIVER_UNLOAD UnloadHandler)
Definition: miniport.c:3151
DRIVER_UNLOAD * PDRIVER_UNLOAD
Definition: iotypes.h:2145
int NDIS_STATUS
Definition: ntddndis.h:471
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
enum _NDIS_WORK_ITEM_TYPE NDIS_WORK_ITEM_TYPE
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define GET_LOGICAL_ADAPTER(Handle)
Definition: miniport.h:101
HARDWARE_ADDRESS Address
Definition: miniport.h:96
NTSTATUS NTAPI NdisICreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: miniport.c:1871
NTSTATUS NTAPI NdisGenericIrpHandler(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: miniport.c:2574
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
FILTERDBS_S FILTER_PACKET_INDICATION_HANDLER PacketIndicateHandler
Definition: ndis.h:2544
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
UCHAR KIRQL
Definition: env_spec_w32.h:591
NDIS_STATUS FASTCALL MiniDequeueWorkItem(PLOGICAL_ADAPTER Adapter, NDIS_WORK_ITEM_TYPE *WorkItemType, PVOID *WorkItemContext)
Definition: miniport.c:1050
NDIS_WORK_ITEM_TYPE WorkItemType
Definition: ndis.h:2310
#define OID_802_3_MAXIMUM_LIST_SIZE
Definition: ntddndis.h:305
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID EXPORT NdisMFlushLog(IN NDIS_HANDLE LogHandle)
Definition: miniport.c:1539
#define MEDIA_ARRAY_SIZE
Definition: miniport.c:31
ETH_RCV_COMPLETE_HANDLER EthRxCompleteHandler
Definition: ndis.h:2579
VOID NTAPI MiniResetComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_STATUS Status, IN BOOLEAN AddressingReset)
Definition: miniport.c:435
VOID EXPORT NdisReadConfiguration(OUT PNDIS_STATUS Status, OUT PNDIS_CONFIGURATION_PARAMETER *ParameterValue, IN NDIS_HANDLE ConfigurationHandle, IN PNDIS_STRING Keyword, IN NDIS_PARAMETER_TYPE ParameterType)
Definition: config.c:414
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ PPNDIS_PACKET PacketArray
Definition: ndis.h:5120
#define IRP_MN_QUERY_REMOVE_DEVICE
NDIS_STATUS MiniSetInformation(PLOGICAL_ADAPTER Adapter, NDIS_OID Oid, ULONG Size, PVOID Buffer, PULONG BytesRead)
Definition: miniport.c:756
_In_ PDRIVER_UNLOAD UnloadHandler
Definition: ndis.h:4688
VOID NTAPI MiniTransferDataComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status, IN UINT BytesTransferred)
Definition: miniport.c:592
_In_ ULONG BufferLength
Definition: usbdlib.h:225
NDIS_HANDLE MiniportAdapterContext
Definition: ndis.h:2510
PNDIS_MINIPORT_BLOCK Miniport
Definition: ndis.h:2475
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
UINT TotalSize
Definition: ndis.h:2478
LIST_ENTRY MiniportListHead
Definition: miniport.c:53
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResourcesTranslated
Definition: ndis.h:4640
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
#define OID_GEN_MAXIMUM_LOOKAHEAD
Definition: ntddndis.h:237
VOID NTAPI MiniStatus(IN NDIS_HANDLE MiniportHandle, IN NDIS_STATUS GeneralStatus, IN PVOID StatusBuffer, IN UINT StatusBufferSize)
Definition: miniport.c:1384
unsigned int idx
Definition: utils.c:41
PNDIS_MINIPORT_INTERRUPT Interrupt
Definition: ndis.h:2522
W_SEND_PACKETS_HANDLER SendPacketsHandler
Definition: ndis.h:2574
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
struct _NDIS_LOG * PNDIS_LOG
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
NDIS_M_SEND_RESOURCES_HANDLER SendResourcesHandler
Definition: ndis.h:2546
BOOLEAN MiniIsBusy(PLOGICAL_ADAPTER Adapter, NDIS_WORK_ITEM_TYPE Type)
Definition: miniport.c:142
smooth NULL
Definition: ftsmooth.c:416
KSYNCHRONIZE_ROUTINE * PKSYNCHRONIZE_ROUTINE
Definition: ketypes.h:863
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
NTSTATUS NTAPI NdisIShutdown(IN PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: miniport.c:2269
VOID EXPORT NdisMGetDeviceProperty(IN NDIS_HANDLE MiniportAdapterHandle, IN OUT PDEVICE_OBJECT *PhysicalDeviceObject OPTIONAL, IN OUT PDEVICE_OBJECT *FunctionalDeviceObject OPTIONAL, IN OUT PDEVICE_OBJECT *NextDeviceObject OPTIONAL, IN OUT PCM_RESOURCE_LIST *AllocatedResources OPTIONAL, IN OUT PCM_RESOURCE_LIST *AllocatedResourcesTranslated OPTIONAL)
Definition: miniport.c:3112
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:4228
VOID EXPORT NdisCancelSendPackets(IN NDIS_HANDLE NdisBindingHandle, IN PVOID CancelId)
Definition: miniport.c:3353
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
Definition: bufpool.h:45
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define GET_MINIPORT_DRIVER(Handle)
Definition: miniport.h:84
switch(r->id)
Definition: btrfs.c:2904
RESET_COMPLETE_HANDLER ResetCompleteHandler
Definition: ndis.h:1886
#define FILE_DEVICE_PHYSICAL_NETCARD
Definition: winioctl.h:128
void * PVOID
Definition: retypes.h:9
ULONG AddressLength
Definition: miniport.h:97
NTSTATUS NTAPI NdisIPnPCancelStopDevice(IN PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: protocol.c:172
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID EXPORT NdisGetFirstBufferFromPacket(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
Definition: buffer.c:871
#define UlongToPtr(u)
Definition: config.h:106
#define PtrToUlong(u)
Definition: config.h:107
VOID EXPORT NdisMIndicateStatusComplete(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:1580
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
VOID EXPORT NdisCloseConfiguration(IN NDIS_HANDLE ConfigurationHandle)
Definition: config.c:136
VOID EXPORT NdisMSetAttributes(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_HANDLE MiniportAdapterContext, IN BOOLEAN BusMaster, IN NDIS_INTERFACE_TYPE AdapterType)
Definition: miniport.c:2858
#define IRP_MN_QUERY_STOP_DEVICE
ULONG DebugTraceLevel
Definition: ndis.c:13
VOID EXPORT NdisRegisterAdapterShutdownHandler(IN NDIS_HANDLE NdisAdapterHandle, IN PVOID ShutdownContext, IN ADAPTER_SHUTDOWN_HANDLER ShutdownHandler)
Definition: miniport.c:3091
PPROTOCOL_BINDING ProtocolBinding
Definition: protocol.h:28
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
BOOLEAN MiniAdapterHasAddress(PLOGICAL_ADAPTER Adapter, PNDIS_PACKET Packet)
Definition: miniport.c:616
NTSTATUS NTAPI NdisIPower(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: miniport.c:2407
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
ULONG * PNDIS_OID
Definition: ntddndis.h:230
VOID NTAPI MiniRequestComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_STATUS Status)
Definition: miniport.c:481
union _HARDWARE_ADDRESS::@989 Type
_In_ LARGE_INTEGER _In_opt_ PKDPC Dpc
Definition: kefuncs.h:524
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
VOID EXPORT NdisTerminateWrapper(IN NDIS_HANDLE NdisWrapperHandle, IN PVOID SystemSpecific)
Definition: miniport.c:3012
#define NDIS_GET_PACKET_STATUS(_Packet)
Definition: ndis.h:3436
VOID(NTAPI * ADAPTER_SHUTDOWN_HANDLER)(_In_ PVOID ShutdownContext)
Definition: ndis.h:2025
NDIS_MEDIUM MediaType
Definition: ndis.h:2548
VOID NTAPI MiniIndicateReceivePacket(IN NDIS_HANDLE MiniportAdapterHandle, IN PPNDIS_PACKET PacketArray, IN UINT NumberOfPackets)
Definition: miniport.c:293
#define IRP_MN_STOP_DEVICE
#define NDIS_ATTRIBUTE_BUS_MASTER
Definition: ndis.h:586
LIST_ENTRY List
Definition: psmgr.c:57
TRANSFER_DATA_COMPLETE_HANDLER TransferDataCompleteHandler
Definition: ndis.h:1883
if(!(yy_init))
Definition: macro.lex.yy.c:714
NDIS_STATUS MiniDoRequest(PLOGICAL_ADAPTER Adapter, PNDIS_REQUEST NdisRequest)
Definition: miniport.c:1107
NDIS_MINIPORT_BLOCK NdisMiniportBlock
Definition: miniport.h:89
__wchar_t WCHAR
Definition: xmlstorage.h:180
VOID NTAPI MiniportHangDpc(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
Definition: miniport.c:949
PDEVICE_OBJECT NextDeviceObject
Definition: ndis.h:2554
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
KDPC Dpc
Definition: ndis.h:644
VOID NTAPI MiniSendResourcesAvailable(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:583
ULONG CheckForHangSeconds
Definition: ndis.h:2538
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define IRP_MN_START_DEVICE
USHORT MaxSendPackets
Definition: ndis.h:2560
NDIS_M_STS_COMPLETE_HANDLER StatusCompleteHandler
Definition: ndis.h:2583
struct _NDIS30_MINIPORT_CHARACTERISTICS NDIS30_MINIPORT_CHARACTERISTICS
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1725
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
RECEIVE_PACKET_HANDLER ReceivePacketHandler
Definition: ndis.h:1896
PNDIS_PACKET FirstPendingPacket
Definition: ndis.h:2526
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
LIST_ENTRY ListEntry
Definition: miniport.h:92
VOID NTAPI NdisIBugcheckCallback(IN PVOID Buffer, IN ULONG Length)
Definition: miniport.c:1670
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID EXPORT NdisReturnPackets(IN PNDIS_PACKET *PacketsToReturn, IN UINT NumberOfPackets)
Definition: miniport.c:258
KSPIN_LOCK MiniportListLock
Definition: miniport.c:54
struct _NDIS_REQUEST_MAC_BLOCK * PNDIS_REQUEST_MAC_BLOCK
STATUS_COMPLETE_HANDLER StatusCompleteHandler
Definition: ndis.h:1894
KSPIN_LOCK Lock
Definition: miniport.h:21
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
PLOGICAL_ADAPTER Adapter
Definition: protocol.h:29
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
ULONG_PTR Reserved[2]
Definition: ndis.h:749
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
static ULONG ResourceCount
Definition: inbv.c:95
LIST_ENTRY ProtocolListHead
Definition: miniport.h:94
PNDIS_OPEN_BLOCK Binding
Definition: protocol.h:34
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:636
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * NextDeviceObject
Definition: ndis.h:4640
PCM_RESOURCE_LIST Resources
Definition: ndis.h:2534
#define IRP_MJ_POWER
Definition: ttei1.cpp:12
UCHAR WrapperReserved[2 *sizeof(PVOID)]
Definition: ndis.h:739
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
VOID NTAPI MiniSendComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN PNDIS_PACKET Packet, IN NDIS_STATUS Status)
Definition: miniport.c:530
VOID EXPORT NdisInitUnicodeString(IN OUT PNDIS_STRING DestinationString, IN PCWSTR SourceString)
Definition: string.c:130
VOID NTAPI MiniStatusComplete(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:1417
#define NDIS_GET_PACKET_HEADER_SIZE(_Packet)
Definition: ndis.h:3427
static const WCHAR L[]
Definition: oid.c:1250
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: ketypes.h:687
struct _LOGICAL_ADAPTER * PLOGICAL_ADAPTER
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
#define NDIS_SET_PACKET_STATUS(_Packet, _Status)
Definition: ndis.h:3509
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
RECEIVE_HANDLER ReceiveHandler
Definition: ndis.h:1889
VOID NTAPI ProSendPackets(IN NDIS_HANDLE NdisBindingHandle, IN PPNDIS_PACKET PacketArray, IN UINT NumberOfPackets)
Definition: protocol.c:577
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1842
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
NTSTATUS NTAPI NdisIDispatchPnp(IN PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: miniport.c:2335
_In_ PVOID _In_ PVOID SystemSpecific2
Definition: ndis.h:637
UNICODE_STRING MiniportName
Definition: ndis.h:2511
Definition: typedefs.h:117
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
struct _NDIS_MINIPORT_BLOCK * PNDIS_MINIPORT_BLOCK
Definition: ndis.h:319
BOOLEAN NTAPI KeDeregisterBugCheckCallback(IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
Definition: bug.c:1284
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
BOOLEAN NTAPI EthCreateFilter(IN UINT MaximumMulticastAddresses, IN PUCHAR AdapterAddress, OUT PETH_FILTER *Filter)
Definition: efilter.c:16
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: miniport.h:37
NDIS_HANDLE DeviceContext
Definition: ndis.h:2515
UINT InPtr
Definition: ndis.h:2480
struct _NDIS40_MINIPORT_CHARACTERISTICS NDIS40_MINIPORT_CHARACTERISTICS
VOID EXPORT NdisDeregisterAdapterShutdownHandler(IN NDIS_HANDLE NdisAdapterHandle)
Definition: miniport.c:3073
NDIS_STATUS MiniQueryInformation(PLOGICAL_ADAPTER Adapter, NDIS_OID Oid, ULONG Size, PVOID Buffer, PULONG BytesWritten)
Definition: miniport.c:805
KSPIN_LOCK AdapterListLock
Definition: miniport.c:58
Status
Definition: gdiplustypes.h:24
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
struct _NDIS_MINIPORT_WORK_ITEM * PNDIS_MINIPORT_WORK_ITEM
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
short sh
Definition: format.c:272
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
_In_ PKSYNCHRONIZE_ROUTINE _In_opt_ __drv_aliasesMem PVOID SynchronizeContext
Definition: kefuncs.h:549
VOID NTAPI EthDeleteFilter(IN PETH_FILTER Filter)
Definition: efilter.c:57
PNDIS_REQUEST PendingRequest
Definition: ndis.h:2566
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
SEND_COMPLETE_HANDLER SendCompleteHandler
Definition: ndis.h:1879
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
UINT CopyBufferChainToBuffer(PUCHAR DstData, PNDIS_BUFFER SrcBuffer, UINT SrcOffset, UINT Length)
Definition: buffer.c:111
struct _SINGLE_LIST_ENTRY * PSINGLE_LIST_ENTRY
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2154
VOID NTAPI ndisBindMiniportsToProtocol(OUT PNDIS_STATUS Status, IN PPROTOCOL_BINDING Protocol)
Definition: protocol.c:908
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:253
BOOLEAN EXPORT NdisMSynchronizeWithInterrupt(IN PNDIS_MINIPORT_INTERRUPT Interrupt, IN PVOID SynchronizeFunction, IN PVOID SynchronizeContext)
Definition: miniport.c:2955
UINT Timer
Definition: capclock.c:11
static ULONG Timeout
Definition: ping.c:61
KTIMER Timer
Definition: ndis.h:643
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
UINT CurrentLookahead
Definition: ndis.h:2569
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS _In_ PVOID _In_ UINT StatusBufferSize
Definition: ndis.h:1555
_Out_ PNDIS_HANDLE _In_ PNDIS_PROTOCOL_CHARACTERISTICS _In_ UINT CharacteristicsLength
Definition: ndis.h:6134
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define MAX_TRACE
Definition: debug.h:16
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
VOID EXPORT NdisMSleep(IN ULONG MicrosecondsToSleep)
Definition: miniport.c:2928
_In_ USHORT PacketSize
Definition: iofuncs.h:1056
struct _NDIS50_MINIPORT_CHARACTERISTICS NDIS50_MINIPORT_CHARACTERISTICS
VOID MiniIndicateData(PLOGICAL_ADAPTER Adapter, NDIS_HANDLE MacReceiveContext, PVOID HeaderBuffer, UINT HeaderBufferSize, PVOID LookaheadBuffer, UINT LookaheadBufferSize, UINT PacketSize)
Definition: miniport.c:175
UINT CopyPacketToBuffer(PUCHAR DstData, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
Definition: buffer.c:170
VOID EXPORT NdisMSendResourcesAvailable(IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:2831
PNDIS_MINIPORT_WORK_ITEM WorkQueueTail
Definition: miniport.h:91
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define NDIS_STATUS_RESET_END
Definition: ndis.h:355
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT * FunctionalDeviceObject
Definition: ndis.h:4640
PDEVICE_OBJECT DeviceObject
Definition: ndis.h:2552
PUNICODE_STRING RegistryPath
Definition: miniport.h:26
LIST_ENTRY ListEntry
Definition: miniport.h:20
KSPIN_LOCK Lock
Definition: ndis.h:2520
unsigned int * PULONG
Definition: retypes.h:1
#define ETH_LENGTH_OF_ADDRESS
Definition: efilter.h:16
unsigned int UINT
Definition: ndis.h:50
NTSTATUS NTAPI NdisIDeviceIoControl(IN PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: miniport.c:2291
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
NDIS_M_SEND_COMPLETE_HANDLER SendCompleteHandler
Definition: ndis.h:2545
VOID EXPORT NdisCompletePnPEvent(IN NDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNET_PNP_EVENT NetPnPEvent)
Definition: miniport.c:3290
struct _ADAPTER_BINDING * PADAPTER_BINDING
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
SINGLE_LIST_ENTRY Link
Definition: ndis.h:2309
#define NDIS_STATUS_BAD_VERSION
Definition: ndis.h:468
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS _In_ PVOID StatusBuffer
Definition: ndis.h:1555
UNICODE_STRING * PUNICODE_STRING
Definition: env_spec_w32.h:373
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:4586
NDIS_STATUS EXPORT NdisMDeregisterDevice(IN NDIS_HANDLE NdisDeviceHandle)
Definition: miniport.c:3245
#define NDIS_ATTRIBUTE_INTERMEDIATE_DRIVER
Definition: ndis.h:587
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
NTSTATUS NTAPI NdisIForwardIrpAndWait(PLOGICAL_ADAPTER Adapter, PIRP Irp)
Definition: miniport.c:1851
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
NDIS_M_RESET_COMPLETE_HANDLER ResetCompleteHandler
Definition: ndis.h:2547
enum _NDIS_INTERFACE_TYPE NDIS_INTERFACE_TYPE
_In_ UINT LogBufferSize
Definition: ndis.h:5822
NTSTATUS NTAPI IoRegisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1694
struct _NDIS_PACKET * PNDIS_PACKET
PDEVICE_OBJECT DeviceObject
Definition: miniport.h:35
NDIS_TIMER WakeUpDpcTimer
Definition: ndis.h:2535
BOOLEAN NTAPI KeRegisterBugCheckCallback(IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord, IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Buffer, IN ULONG Length, IN PUCHAR Component)
Definition: bug.c:1339
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT _Out_ NDIS_HANDLE * NdisDeviceHandle
Definition: ndis.h:4679
#define IRP_MJ_CLEANUP
#define DEBUG_PACKET
Definition: debug.h:19
NDIS_STATUS EXPORT NdisMQueryAdapterInstanceName(OUT PNDIS_STRING AdapterInstanceName, IN NDIS_HANDLE MiniportAdapterHandle)
Definition: miniport.c:3038
#define OUT
Definition: typedefs.h:39
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
UNICODE_STRING SymbolicLinkName
Definition: ndis.h:2537
PVOID PIRP
Definition: usb.h:38
struct _SCATTER_GATHER_LIST * PSCATTER_GATHER_LIST
Definition: iotypes.h:2096
struct tagContext Context
Definition: acpixf.h:1030
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
PDRIVER_OBJECT DriverObject
Definition: miniport.h:24
VOID EXPORT NdisMRegisterAdapterShutdownHandler(IN NDIS_HANDLE MiniportHandle, IN PVOID ShutdownContext, IN ADAPTER_SHUTDOWN_HANDLER ShutdownHandler)
Definition: miniport.c:1694
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNIMPLEMENTED
Definition: debug.h:114
#define MmGetSystemAddressForMdl(Mdl)
LIST_ENTRY AdapterListHead
Definition: miniport.c:57
ETH_RCV_INDICATE_HANDLER EthRxIndicateHandler
Definition: ndis.h:2576
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
#define ULONG_PTR
Definition: config.h:101
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
BOOLEAN NTAPI KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL)
Definition: interrupt.c:142
BOOLEAN MiniCheckForHang(PLOGICAL_ADAPTER Adapter)
Definition: miniport.c:865
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:303
UINT OutPtr
Definition: ndis.h:2481
NDIS_STATUS EXPORT NdisMRegisterDevice(IN NDIS_HANDLE NdisWrapperHandle, IN PNDIS_STRING DeviceName, IN PNDIS_STRING SymbolicName, IN PDRIVER_DISPATCH MajorFunctions[], OUT PDEVICE_OBJECT *pDeviceObject, OUT NDIS_HANDLE *NdisDeviceHandle)
Definition: miniport.c:3173
const char * PCSTR
Definition: typedefs.h:51
#define IRP_MN_CANCEL_STOP_DEVICE
NDIS_STATUS EXPORT NdisMWriteLogData(IN NDIS_HANDLE LogHandle, IN PVOID LogBuffer, IN UINT LogBufferSize)
Definition: miniport.c:2970
_In_ UINT _Out_ PNDIS_HANDLE LogHandle
Definition: ndis.h:5381
GLfloat GLfloat p
Definition: glext.h:8902
VOID FASTCALL MiniQueueWorkItem(PLOGICAL_ADAPTER Adapter, NDIS_WORK_ITEM_TYPE WorkItemType, PVOID WorkItemContext, BOOLEAN Top)
Definition: miniport.c:982
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
NDIS_STATUS EXPORT NdisMRegisterMiniport(IN NDIS_HANDLE NdisWrapperHandle, IN PNDIS_MINIPORT_CHARACTERISTICS MiniportCharacteristics, IN UINT CharacteristicsLength)
Definition: miniport.c:2637
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT _In_ NDIS_HANDLE _In_ NDIS_HANDLE _In_ PNDIS_STRING AdapterName
Definition: ndis.h:6013
#define NDIS_STATUS_BAD_CHARACTERISTICS
Definition: ndis.h:469
ULONG MediumHeaderSize
Definition: miniport.h:95
NDIS_STATUS EXPORT NdisQueryAdapterInstanceName(OUT PNDIS_STRING AdapterInstanceName, IN NDIS_HANDLE NdisBindingHandle)
Definition: miniport.c:3268
NTSTATUS NTAPI NdisIPnPStartDevice(IN PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: miniport.c:1885
return STATUS_SUCCESS
Definition: btrfs.c:2938
_Must_inspect_result_ _In_ NDIS_HANDLE NdisBindingHandle
Definition: ndis.h:4735
IoMarkIrpPending(Irp)
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:45
#define RTL_QUERY_REGISTRY_REQUIRED
Definition: nt_native.h:132
PNDIS_M_DRIVER_BLOCK DriverHandle
Definition: ndis.h:2509
NDIS_INTERFACE_TYPE BusType
Definition: ndis.h:2550
static LPHIST_ENTRY Top
Definition: history.c:53
#define NDIS_PER_PACKET_INFO_FROM_PACKET(Packet, InfoType)
Definition: ndis.h:1351
UCHAR Medium802_3[ETH_LENGTH_OF_ADDRESS]
Definition: miniport.h:14
VOID EXPORT NdisMIndicateStatus(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_STATUS GeneralStatus, IN PVOID StatusBuffer, IN UINT StatusBufferSize)
Definition: miniport.c:1565
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:247
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define Int32x32To64(a, b)
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
VOID EXPORT NdisMSetAttributesEx(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_HANDLE MiniportAdapterContext, IN UINT CheckForHangTimeInSeconds OPTIONAL, IN ULONG AttributeFlags, IN NDIS_INTERFACE_TYPE AdapterType)
Definition: miniport.c:2883
struct _DRIVER_OBJECT * PDRIVER_OBJECT
NDIS_STATUS MiniReset(PLOGICAL_ADAPTER Adapter)
Definition: miniport.c:902
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
static NDIS_MEDIUM MediaArray[MEDIA_ARRAY_SIZE]
Definition: miniport.c:33
PNP_EVENT_HANDLER PnPEventHandler
Definition: ndis.h:1899
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
VOID EXPORT NdisMQueryInformationComplete(IN NDIS_HANDLE MiniportAdapterHandle, IN NDIS_STATUS Status)
Definition: miniport.c:1207
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
LONGLONG QuadPart
Definition: typedefs.h:112
NDIS_PROTOCOL_CHARACTERISTICS Chars
Definition: protocol.h:13
NDIS_HANDLE EXPORT NdisIMGetBindingContext(IN NDIS_HANDLE NdisBindingHandle)
Definition: miniport.c:3376
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
struct ETHI_FILTER * PETHI_FILTER
VOID NTAPI MiniportWorker(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
Definition: miniport.c:1223
NDIS_M_STATUS_HANDLER StatusHandler
Definition: ndis.h:2582
NDIS_STATUS ProIndicatePacket(PLOGICAL_ADAPTER Adapter, PNDIS_PACKET Packet)
Definition: protocol.c:243
PNDIS_STRING SymbolicName
Definition: miniport.h:36
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675