ReactOS  0.4.13-dev-99-g7e18b6d
lan.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS TCP/IP protocol driver
4  * FILE: datalink/lan.c
5  * PURPOSE: Local Area Network media routines
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * REVISIONS:
8  * CSH 01/08-2000 Created
9  * arty -- Separate service 09/2004
10  */
11 
12 #include "precomp.h"
13 
14 ULONG DebugTraceLevel = 0x7ffffff;
16 
30  PLAN_ADAPTER Adapter,
32  NDIS_OID OID,
33  PVOID Buffer,
34  UINT Length)
35 {
37  NDIS_STATUS NdisStatus;
38 
39  Request.RequestType = Type;
41  {
42  Request.DATA.SET_INFORMATION.Oid = OID;
43  Request.DATA.SET_INFORMATION.InformationBuffer = Buffer;
44  Request.DATA.SET_INFORMATION.InformationBufferLength = Length;
45  }
46  else
47  {
48  Request.DATA.QUERY_INFORMATION.Oid = OID;
49  Request.DATA.QUERY_INFORMATION.InformationBuffer = Buffer;
50  Request.DATA.QUERY_INFORMATION.InformationBufferLength = Length;
51  }
52 
53  if (Adapter->State != LAN_STATE_RESETTING)
54  {
55  NdisRequest(&NdisStatus, Adapter->NdisHandle, &Request);
56  }
57  else
58  {
59  NdisStatus = NDIS_STATUS_NOT_ACCEPTED;
60  }
61 
62  /* Wait for NDIS to complete the request */
63  if (NdisStatus == NDIS_STATUS_PENDING)
64  {
65  KeWaitForSingleObject(&Adapter->Event,
67  KernelMode,
68  FALSE,
69  NULL);
70  NdisStatus = Adapter->NdisStatus;
71  }
72 
73  return NdisStatus;
74 }
75 
76 
82 VOID
84  PLAN_ADAPTER Adapter)
85 {
86  exFreePool(Adapter);
87 }
88 
89 
97 VOID
98 NTAPI
100  NDIS_HANDLE BindingContext,
103 {
104  PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
105 
106  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
107 
108  KeSetEvent(&Adapter->Event, 0, FALSE);
109 }
110 
111 
118 VOID
119 NTAPI
121  NDIS_HANDLE BindingContext,
123 {
124  PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
125 
126  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
127 
128  Adapter->NdisStatus = Status;
129 
130  KeSetEvent(&Adapter->Event, 0, FALSE);
131 }
132 
133 
140 VOID
141 NTAPI
143  NDIS_HANDLE BindingContext,
145 {
146  LA_DbgPrint(MID_TRACE, ("Called.\n"));
147 }
148 
149 
157 VOID
158 NTAPI
160  NDIS_HANDLE BindingContext,
163 {
164  PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
165 
166  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
167 
168  /* Save status of request and signal an event */
169  Adapter->NdisStatus = Status;
170 
171  KeSetEvent(&Adapter->Event, 0, FALSE);
172 }
173 
174 
182 VOID
183 NTAPI
185  NDIS_HANDLE BindingContext,
188 {
189  /*PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;*/
190 
191  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
192  /*(*PC(Packet)->DLComplete)(Adapter->Context, Packet, Status);*/
193  LA_DbgPrint(DEBUG_DATALINK, ("Finished\n"));
194 }
195 
196 
208 VOID
209 NTAPI
211  NDIS_HANDLE BindingContext,
214  UINT BytesTransferred)
215 {
216  PLIST_ENTRY ListEntry, ReadListEntry;
217  PLAN_PROTOCOL Proto;
220  UINT i;
221  UINT PacketType;
222  UINT ContigSize;
223  PIRP ReadIrp;
224  KIRQL OldIrql;
225  LAN_PACKET LPPacket;
226  PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
227 
228  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
229 
230  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
231 
233  {
234  PNDIS_BUFFER NdisBuffer;
235 
237  &NdisBuffer,
238  &LPPacket.EthHeader,
239  &ContigSize,
240  &LPPacket.TotalSize);
241 
242  LPPacket.TotalSize = BytesTransferred;
243 
244  /* Determine which upper layer protocol that should receive
245  this packet and pass it to the correct receive handler */
246 
247  /*OskitDumpBuffer(IPPacket.Header, BytesTransferred);*/
248 
249  PacketType = LPPacket.EthHeader->EType;
250 
252  ("Ether Type = %x Total = %d Packet %x Payload %x\n",
253  PacketType, LPPacket.TotalSize, LPPacket.EthHeader,
254  LPPacket.EthHeader + 1));
255 
256  NdisBuffer->Next = NULL;
257 
258  for (ListEntry = DeviceExt->ProtocolListHead.Flink;
259  ListEntry != &DeviceExt->ProtocolListHead;
260  ListEntry = ListEntry->Flink)
261  {
262  Proto = CONTAINING_RECORD(ListEntry, LAN_PROTOCOL, ListEntry);
263  LA_DbgPrint(MID_TRACE,("Examining protocol %x\n", Proto));
264 
265  for (i = 0; i < Proto->NumEtherTypes; i++)
266  {
267  LA_DbgPrint(MID_TRACE,(".Accepts proto %x\n",
268  Proto->EtherType[i]));
269 
270  if (Proto->EtherType[i] == PacketType &&
271  !IsListEmpty(&Proto->ReadIrpListHead))
272  {
273  ReadListEntry = RemoveHeadList(&Proto->ReadIrpListHead);
274  ReadIrp = CONTAINING_RECORD(ReadListEntry,
275  IRP,
276  Tail.Overlay.ListEntry);
277  LA_DbgPrint(MID_TRACE,("..Irp %x\n", ReadIrp));
278 
279  _SEH2_TRY
280  {
281  Header = ReadIrp->AssociatedIrp.SystemBuffer;
283  ("Writing packet at %x\n", Header));
284 
285  Header->Fixed.Adapter = Adapter->Index;
286  Header->Fixed.AddressType = Adapter->Media;
287  Header->Fixed.AddressLen = IEEE_802_ADDR_LENGTH;
288  Header->Fixed.PacketType = PacketType;
289 
290  RtlCopyMemory(Header->Address,
291  LPPacket.EthHeader->SrcAddr,
293 
294  if (Proto->Buffered)
295  {
296  LA_DbgPrint(MID_TRACE,("Buffered copy\n"));
298  LPPacket.EthHeader + 1,
299  LPPacket.TotalSize -
300  sizeof(*LPPacket.EthHeader) );
301  Header->Fixed.Mdl = NULL;
302  }
303  else
304  Header->Fixed.Mdl = NdisBuffer;
305 
306  ReadIrp->IoStatus.Status = 0;
307  ReadIrp->IoStatus.Information =
308  (Header->Address + IEEE_802_ADDR_LENGTH +
309  LPPacket.TotalSize -
310  sizeof(*LPPacket.EthHeader)) -
311  (PCHAR)Header;
312 
313  LA_DbgPrint(MID_TRACE,("Bytes returned %d\n",
314  ReadIrp->IoStatus.Information));
315 
316  #error move this out of SEH!
318  }
320  {
322  ("Failed write to packet in client\n"));
323  ReadIrp->IoStatus.Status = STATUS_ACCESS_VIOLATION;
324  ReadIrp->IoStatus.Information = 0;
326  }
327  _SEH2_END;
328  break;
329  }
330  }
331  }
332  }
333 
334  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
335 
337 }
338 
339 
354 NTAPI
356  NDIS_HANDLE BindingContext,
357  NDIS_HANDLE MacReceiveContext,
358  PVOID HeaderBuffer,
359  UINT HeaderBufferSize,
360  PVOID LookaheadBuffer,
361  UINT LookaheadBufferSize,
363 {
364  USHORT EType;
365  UINT PacketType, BytesTransferred;
366  PCHAR BufferData;
367  NDIS_STATUS NdisStatus;
368  PNDIS_PACKET NdisPacket;
369  PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
370 
371  LA_DbgPrint(DEBUG_DATALINK, ("Called. (packetsize %d)\n",PacketSize));
372 
373  if (Adapter->State != LAN_STATE_STARTED)
374  {
375  LA_DbgPrint(DEBUG_DATALINK, ("Adapter is stopped.\n"));
377  }
378 
379  if (HeaderBufferSize < Adapter->HeaderSize)
380  {
381  LA_DbgPrint(DEBUG_DATALINK, ("Runt frame received.\n"));
383  }
384 
385  PacketType = EType;
386 
387  /* Get a transfer data packet */
389  NdisStatus = AllocatePacketWithBuffer(&NdisPacket, NULL, Adapter->MTU);
390  if (NdisStatus != NDIS_STATUS_SUCCESS)
391  {
394  }
395 
397  ("pretransfer LookaheadBufferSize %d packsize %d\n",
398  LookaheadBufferSize,PacketSize));
399 
400  {
401  UINT temp;
402  temp = PacketSize;
403  GetDataPtr(NdisPacket, 0, &BufferData, &temp);
404  }
405 
407  ("pretransfer LookaheadBufferSize %d HeaderBufferSize %d packsize %d\n",
408  LookaheadBufferSize,HeaderBufferSize,PacketSize));
409 
410  /* Get the data */
411  NdisTransferData(&NdisStatus,
412  Adapter->NdisHandle,
413  MacReceiveContext,
414  0,
415  PacketSize + HeaderBufferSize,
416  NdisPacket,
417  &BytesTransferred);
418 
419  LA_DbgPrint(DEBUG_DATALINK, ("Calling complete\n"));
420 
421  if (NdisStatus != NDIS_STATUS_PENDING)
422  {
423  ProtocolTransferDataComplete(BindingContext,
424  NdisPacket,
425  NdisStatus,
426  PacketSize + HeaderBufferSize);
427  }
428 
429  /* Release the packet descriptor */
431  LA_DbgPrint(DEBUG_DATALINK, ("leaving\n"));
432 
433  return NDIS_STATUS_SUCCESS;
434 }
435 
436 
442 VOID
443 NTAPI
445  NDIS_HANDLE BindingContext)
446 {
447  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
448 }
449 
450 
459 VOID
460 NTAPI
462  NDIS_HANDLE BindingContext,
463  NDIS_STATUS GenerelStatus,
466 {
467  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
468 }
469 
470 
476 VOID
477 NTAPI
479  NDIS_HANDLE NdisBindingContext)
480 {
481  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
482 }
483 
495 VOID
496 NTAPI
499  IN NDIS_HANDLE BindContext,
501  IN PVOID SystemSpecific1,
503 {
504  /* XXX confirm that this is still true, or re-word the following comment */
505  /* we get to ignore BindContext because we will never pend an operation with NDIS */
506  LA_DbgPrint(DEBUG_DATALINK, ("Called with registry path %wZ\n", SystemSpecific1));
507  *Status = LANRegisterAdapter(DeviceName, SystemSpecific1);
508 }
509 
510 
519 VOID
521  PLAN_ADAPTER Adapter,
522  PNDIS_PACKET NdisPacket,
523  PVOID LinkAddress,
524  USHORT Type)
525 {
526  NDIS_STATUS NdisStatus;
527 
528  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
529 
530  if (Adapter->State == LAN_STATE_STARTED)
531  {
532  NdisSend(&NdisStatus, Adapter->NdisHandle, NdisPacket);
533  if (NdisStatus != NDIS_STATUS_PENDING)
534  ProtocolSendComplete((NDIS_HANDLE)Adapter, NdisPacket, NdisStatus);
535  }
536  else
537  {
538  ProtocolSendComplete((NDIS_HANDLE)Adapter, NdisPacket, NDIS_STATUS_CLOSED);
539  }
540 }
541 
542 /* For use internally */
543 UINT
545 {
546  NDIS_STATUS NdisStatus;
548  PLAN_ADAPTER Adapter;
549  PETH_HEADER EthHeader;
550  KIRQL OldIrql;
551  PNDIS_PACKET NdisPacket;
552  UINT Size, PayloadSize = OverallLength -
553  ((ToWrite->Address + ToWrite->Fixed.AddressLen) - (PCHAR)ToWrite);
554 
555  NdisStatus = AllocatePacketWithBuffer(&NdisPacket, NULL,
556  PayloadSize + sizeof(ETH_HEADER));
557 
558  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
559 
560  if (!NT_SUCCESS(NdisStatus)) goto end;
561 
562  Adapter = FindAdapterByIndex(DeviceExt, ToWrite->Fixed.Adapter);
563 
564  if (!Adapter) goto end;
565 
566  GetDataPtr(NdisPacket, 0, (PCHAR *)&EthHeader, &Size);
567  if (!EthHeader) goto end;
568 
569  LA_DbgPrint(MID_TRACE,("Writing %d bytes of Dst\n",
570  ToWrite->Fixed.AddressLen));
571 
572  /* Handle broadcast for other media types here */
573  if (ToWrite->Fixed.AddressLen)
574  {
575  RtlCopyMemory(EthHeader->DstAddr,
576  ToWrite->Address,
577  ToWrite->Fixed.AddressLen);
578  }
579  else
580  memset(EthHeader->DstAddr, -1, sizeof(EthHeader->DstAddr));
581 
583  ("Writing %d bytes of Src\n", Adapter->HWAddressLength));
584 
585  RtlCopyMemory(EthHeader->SrcAddr,
586  Adapter->HWAddress,
587  Adapter->HWAddressLength);
588 
590  ("Writing %d bytes of payload\n", PayloadSize));
591 
592  EthHeader->EType = ToWrite->Fixed.PacketType;
593  RtlCopyMemory(EthHeader + 1,
594  ToWrite->Address + ToWrite->Fixed.AddressLen,
595  PayloadSize);
596 
597  LANTransmit(Adapter,
598  NdisPacket,
599  ToWrite->Address,
600  ToWrite->Fixed.PacketType);
601 
602 end:
603  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
604 
605  return OverallLength;
606 }
607 
616 VOID
618 {
619  /*NDIS_STATUS NdisStatus;*/
620  /*ULONG Lookahead = LOOKAHEAD_SIZE;*/
621  /*NTSTATUS Status;*/
622  /*HANDLE RegHandle = 0;*/
623 
624  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
625 
626 }
627 
640 {
641  PLAN_ADAPTER Adapter;
643  NDIS_STATUS NdisStatus;
645  UINT MediaIndex;
646  UINT AddressOID;
647  UINT Speed;
649 
650  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
651 
652  Adapter = exAllocatePool(NonPagedPool, sizeof(LAN_ADAPTER));
653  if (!Adapter)
654  {
655  LA_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
656  return NDIS_STATUS_RESOURCES;
657  }
658 
659  RtlZeroMemory(Adapter, sizeof(LAN_ADAPTER));
660 
661  /* Put adapter in stopped state */
662  Adapter->State = LAN_STATE_STOPPED;
663  Adapter->Index = DeviceExt->AdapterId++;
664 
665  InitializeListHead(&Adapter->AddressList);
666  InitializeListHead(&Adapter->ForeignList);
667 
668  /* Initialize protecting spin lock */
669  KeInitializeSpinLock(&Adapter->Lock);
670 
672 
673  /* Initialize array with media IDs we support */
675 
676  LA_DbgPrint(DEBUG_DATALINK,("opening adapter %wZ\n", AdapterName));
677 
678  /* Open the adapter. */
679  NdisOpenAdapter(&NdisStatus,
680  &OpenStatus,
681  &Adapter->NdisHandle,
682  &MediaIndex,
683  MediaArray,
684  MAX_MEDIA,
685  DeviceExt->NdisProtocolHandle,
686  Adapter,
687  AdapterName,
688  0,
689  NULL);
690 
691  /* Wait until the adapter is opened */
692  if (NdisStatus == NDIS_STATUS_PENDING)
694  else if (NdisStatus != NDIS_STATUS_SUCCESS)
695  {
696  exFreePool(Adapter);
697  return NdisStatus;
698  }
699 
700  Adapter->Media = MediaArray[MediaIndex];
701 
702  /* Fill LAN_ADAPTER structure with some adapter specific information */
703  switch (Adapter->Media)
704  {
705  case NdisMedium802_3:
707  Adapter->BCastMask = BCAST_ETH_MASK;
708  Adapter->BCastCheck = BCAST_ETH_CHECK;
709  Adapter->BCastOffset = BCAST_ETH_OFFSET;
710  Adapter->HeaderSize = sizeof(ETH_HEADER);
711  Adapter->MinFrameSize = 60;
712  AddressOID = OID_802_3_CURRENT_ADDRESS;
713  Adapter->PacketFilter =
717  break;
718 
719  default:
720  /* Unsupported media */
721  LA_DbgPrint(MIN_TRACE, ("Unsupported media.\n"));
722  exFreePool(Adapter);
724  }
725 
726  /* Get maximum frame size */
727  NdisStatus = NDISCall(Adapter,
730  &Adapter->MTU,
731  sizeof(UINT));
732  if (NdisStatus != NDIS_STATUS_SUCCESS)
733  {
734  exFreePool(Adapter);
735  return NdisStatus;
736  }
737 
738  /* Get maximum packet size */
739  NdisStatus = NDISCall(Adapter,
742  &Adapter->MaxPacketSize,
743  sizeof(UINT));
744  if (NdisStatus != NDIS_STATUS_SUCCESS)
745  {
746  LA_DbgPrint(MIN_TRACE, ("Query for maximum packet size failed.\n"));
747  exFreePool(Adapter);
748  return NdisStatus;
749  }
750 
751  /* Get maximum number of packets we can pass to NdisSend(Packets) at one time */
752  NdisStatus = NDISCall(Adapter,
755  &Adapter->MaxSendPackets,
756  sizeof(UINT));
757  if (NdisStatus != NDIS_STATUS_SUCCESS)
758  {
759  /* Legacy NIC drivers may not support this query, if it fails we
760  assume it can send at least one packet per call to NdisSend(Packets) */
761  Adapter->MaxSendPackets = 1;
762  }
763 
764  /* Get current hardware address */
765  NdisStatus = NDISCall(Adapter,
767  AddressOID,
768  Adapter->HWAddress,
769  Adapter->HWAddressLength);
770  if (NdisStatus != NDIS_STATUS_SUCCESS)
771  {
772  LA_DbgPrint(MIN_TRACE, ("Query for current hardware address failed.\n"));
773  exFreePool(Adapter);
774  return NdisStatus;
775  }
776 
777  /* Get maximum link speed */
778  NdisStatus = NDISCall(Adapter,
781  &Speed,
782  sizeof(UINT));
783  if (NdisStatus != NDIS_STATUS_SUCCESS)
784  {
785  LA_DbgPrint(MIN_TRACE, ("Query for maximum link speed failed.\n"));
786  exFreePool(Adapter);
787  return NdisStatus;
788  }
789 
790  /* Convert returned link speed to bps (it is in 100bps increments) */
791  Adapter->Speed = Speed * 100L;
792 
793  /* Add adapter to the adapter list */
795  &Adapter->ListEntry,
796  &DeviceExt->Lock);
797 
798  Adapter->RegistryPath.Buffer =
800  if (!Adapter->RegistryPath.Buffer)
801  return NDIS_STATUS_RESOURCES;
802 
804 
805  NdisStatus = NDISCall(Adapter,
808  &Adapter->Lookahead,
809  sizeof(ULONG));
810  if (NdisStatus != NDIS_STATUS_SUCCESS)
811  {
813  ("Could not set lookahead buffer size (0x%X).\n",
814  NdisStatus));
815  return NdisStatus;
816  }
817 
818  /* Set packet filter so we can send and receive packets */
819  NdisStatus = NDISCall(Adapter,
822  &Adapter->PacketFilter,
823  sizeof(UINT));
824  if (NdisStatus != NDIS_STATUS_SUCCESS)
825  {
826  LA_DbgPrint(MID_TRACE, ("Could not set packet filter (0x%X).\n",
827  NdisStatus));
828  return NdisStatus;
829  }
830 
831  Adapter->State = LAN_STATE_STARTED;
832 
833  LA_DbgPrint(DEBUG_DATALINK, ("Leaving.\n"));
834 
835  return NDIS_STATUS_SUCCESS;
836 }
837 
838 
848  PLAN_ADAPTER Adapter)
849 {
850  KIRQL OldIrql;
851  NDIS_HANDLE NdisHandle;
852  NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
853 
854  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
855 
856  /* Unlink the adapter from the list */
857  RemoveEntryList(&Adapter->ListEntry);
858 
859  KeAcquireSpinLock(&Adapter->Lock, &OldIrql);
860  NdisHandle = Adapter->NdisHandle;
861  if (NdisHandle)
862  {
863  Adapter->NdisHandle = NULL;
864  KeReleaseSpinLock(&Adapter->Lock, OldIrql);
865 
866  NdisCloseAdapter(&NdisStatus, NdisHandle);
867  if (NdisStatus == NDIS_STATUS_PENDING)
868  {
869  KeWaitForSingleObject(&Adapter->Event,
870  UserRequest,
871  KernelMode,
872  FALSE,
873  NULL);
874  NdisStatus = Adapter->NdisStatus;
875  }
876  }
877  else
878  KeReleaseSpinLock(&Adapter->Lock, OldIrql);
879 
880  FreeAdapter(Adapter);
881 
882  return NDIS_STATUS_SUCCESS;
883 }
884 
892 NTSTATUS
894 {
895  NDIS_STATUS NdisStatus;
898 
899  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
900 
901  InitializeListHead(&DeviceExt->AdapterListHead);
903 
904  /* Set up protocol characteristics */
905  RtlZeroMemory(&ProtChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
908  ProtChars.Name.Length = Name->Length;
909  ProtChars.Name.Buffer = Name->Buffer;
910  ProtChars.Name.MaximumLength = Name->MaximumLength;
917  ProtChars.ReceiveHandler = ProtocolReceive;
919  ProtChars.StatusHandler = ProtocolStatus;
922 
923  /* Try to register protocol */
924  NdisRegisterProtocol(&NdisStatus,
925  &DeviceExt->NdisProtocolHandle,
926  &ProtChars,
928  if (NdisStatus != NDIS_STATUS_SUCCESS)
929  {
930  LA_DbgPrint(MID_TRACE, ("NdisRegisterProtocol failed, status 0x%x\n", NdisStatus));
931  return (NTSTATUS)NdisStatus;
932  }
933 
934  return STATUS_SUCCESS;
935 }
936 
937 
942 VOID
944 {
946 
947  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
948 
949  NDIS_STATUS NdisStatus;
950  PLIST_ENTRY CurrentEntry;
951  PLIST_ENTRY NextEntry;
952  PLAN_ADAPTER Current;
953  KIRQL OldIrql;
954 
955  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
956 
957  /* Search the list and remove every adapter we find */
958  CurrentEntry = DeviceExt->AdapterListHead.Flink;
959  while (CurrentEntry != &DeviceExt->AdapterListHead)
960  {
961  NextEntry = CurrentEntry->Flink;
962  Current = CONTAINING_RECORD(CurrentEntry, LAN_ADAPTER, ListEntry);
963  /* Unregister it */
964  LANUnregisterAdapter(Current);
965  CurrentEntry = NextEntry;
966  }
967 
968  NdisDeregisterProtocol(&NdisStatus, DeviceExt->NdisProtocolHandle);
969 }
970 
971 NTSTATUS
972 NTAPI
975  PIRP Irp,
977 {
978  PLAN_PROTOCOL Proto;
982  PCHAR ProtoNumbersToMatch;
983  UINT Size = sizeof(*Proto);
985 
986  EaInfo = Irp->AssociatedIrp.SystemBuffer;
987  Size += EaInfo->EaValueLength;
988  Proto = ExAllocatePool(NonPagedPool, Size);
989 
990  if (!Proto)
991  {
992  Status = Irp->IoStatus.Status = STATUS_NO_MEMORY;
994  return Status;
995  }
996 
997  RtlZeroMemory(Proto, Size);
998 
999  Proto->Id = DeviceExt->ProtoId++;
1000  Proto->NumEtherTypes = EaInfo->EaValueLength / sizeof(USHORT);
1001  ProtoNumbersToMatch = EaInfo->EaName + EaInfo->EaNameLength + 1;
1002 
1003  LA_DbgPrint(MID_TRACE,("NumEtherTypes: %d\n", Proto->NumEtherTypes));
1004 
1005  RtlCopyMemory(Proto->EtherType,
1006  ProtoNumbersToMatch,
1007  sizeof(USHORT) * Proto->NumEtherTypes);
1008 
1010 
1011  FileObject->FsContext = Proto;
1012 
1013  LA_DbgPrint(MID_TRACE,("DeviceExt: %x, Proto %x\n", DeviceExt, Proto));
1014 
1016  &Proto->ListEntry,
1017  &DeviceExt->Lock);
1018 
1019  Irp->IoStatus.Information = 0;
1020  Irp->IoStatus.Status = STATUS_SUCCESS;
1021 
1022  LA_DbgPrint(MID_TRACE,("Status %x\n", Irp->IoStatus.Status));
1023 
1025  return STATUS_SUCCESS;
1026 }
1027 
1028 NTSTATUS
1029 NTAPI
1032  PIRP Irp,
1034 {
1037  PLAN_PROTOCOL Proto = FileObject->FsContext;
1038  KIRQL OldIrql;
1039  PLIST_ENTRY ReadIrpListEntry;
1040  PIRP ReadIrp;
1041  NTSTATUS Status;
1042 
1043  LA_DbgPrint(MID_TRACE,("Called\n"));
1044 
1045  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
1046 
1047  while (!IsListEmpty(&Proto->ReadIrpListHead))
1048  {
1049  ReadIrpListEntry = RemoveHeadList(&Proto->ReadIrpListHead);
1050 
1051  ReadIrp = CONTAINING_RECORD(ReadIrpListEntry,
1052  IRP,
1053  Tail.Overlay.ListEntry);
1054  ReadIrp->IoStatus.Information = 0;
1055  ReadIrp->IoStatus.Status = STATUS_UNSUCCESSFUL;
1057  }
1058 
1059  RemoveEntryList(&Proto->ListEntry);
1060 
1061  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1062 
1063  LA_DbgPrint(MID_TRACE,("Deleting %x\n"));
1064 
1065  ExFreePool(Proto);
1066 
1067  Status = Irp->IoStatus.Status = STATUS_SUCCESS;
1069  return Status;
1070 }
1071 
1074  PLAN_DEVICE_EXT DeviceExt,
1075  UINT Index)
1076 {
1077  PLIST_ENTRY ListEntry;
1078  PLAN_ADAPTER Current, Target = NULL;
1079 
1080  for (ListEntry = DeviceExt->AdapterListHead.Flink;
1081  ListEntry != &DeviceExt->AdapterListHead;
1082  ListEntry = ListEntry->Flink)
1083  {
1084  Current = CONTAINING_RECORD(ListEntry, LAN_ADAPTER, ListEntry);
1085  if (Current->Index == Index)
1086  {
1087  Target = Current;
1088  break;
1089  }
1090  }
1091 
1092  return Target;
1093 }
1094 
1095 /* Write data to an adapter:
1096  * |<- 16 >| |<-- variable ... -->|
1097  * [indx] [addrtype] [addrlen ] [ptype] [packet-data ...]
1098  */
1099 NTSTATUS
1100 NTAPI
1103  PIRP Irp,
1105 {
1106  PLAN_PACKET_HEADER ToWrite = Irp->AssociatedIrp.SystemBuffer;
1108 
1109  LA_DbgPrint(MID_TRACE,("Called\n"));
1110 
1111  Irp->IoStatus.Information =
1112  LANTransmitInternal(ToWrite, IrpSp->Parameters.Write.Length);
1113  Irp->IoStatus.Status = Status;
1114 
1116  return Status;
1117 }
1118 
1119 NTSTATUS
1120 NTAPI
1123  PIRP Irp,
1125 {
1126  PLAN_DEVICE_EXT DeviceExt =
1129  PLAN_PROTOCOL Proto = FileObject->FsContext;
1130 
1131  LA_DbgPrint(MID_TRACE,("Called on %x (%x)\n", Proto, Irp));
1132 
1133  ExInterlockedInsertTailList(&Proto->ReadIrpListHead,
1134  &Irp->Tail.Overlay.ListEntry,
1135  &DeviceExt->Lock);
1136 
1137  LA_DbgPrint(MID_TRACE,("List: %x %x\n",
1138  Proto->ReadIrpListHead.Flink,
1139  Irp->Tail.Overlay.ListEntry.Flink));
1140 
1142  return STATUS_PENDING;
1143 }
1144 
1145 NTSTATUS
1146 NTAPI
1149  PIRP Irp,
1151 {
1152  PLIST_ENTRY ListEntry;
1155  PLAN_ADAPTER Adapter;
1156  UINT AdapterCount = 0;
1157  PUINT Output = Irp->AssociatedIrp.SystemBuffer;
1158  KIRQL OldIrql;
1159 
1160  LA_DbgPrint(MID_TRACE,("Called\n"));
1161 
1162  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
1163 
1164  for (ListEntry = DeviceExt->AdapterListHead.Flink;
1165  ListEntry != &DeviceExt->AdapterListHead;
1166  ListEntry = ListEntry->Flink)
1167  {
1168  AdapterCount++;
1169  }
1170 
1171  if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >=
1172  AdapterCount * sizeof(UINT))
1173  {
1174  for (ListEntry = DeviceExt->AdapterListHead.Flink;
1175  ListEntry != &DeviceExt->AdapterListHead;
1176  ListEntry = ListEntry->Flink)
1177  {
1178  Adapter = CONTAINING_RECORD(ListEntry, LAN_ADAPTER, ListEntry);
1179  *Output++ = Adapter->Index;
1180  }
1181  }
1182  else
1184 
1185  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1186 
1187  LA_DbgPrint(MID_TRACE,("Ending\n"));
1188 
1189  Irp->IoStatus.Status = Status;
1190  Irp->IoStatus.Information = (PCHAR)Output -
1191  (PCHAR)Irp->AssociatedIrp.SystemBuffer;
1192 
1194 
1195  return Status;
1196 }
1197 
1198 NTSTATUS
1199 NTAPI
1202  PIRP Irp,
1204 {
1205  PLAN_DEVICE_EXT DeviceExt =
1207  PLAN_ADAPTER Adapter;
1209  PUINT AdapterIndexPtr = Irp->AssociatedIrp.SystemBuffer;
1210  PLIST_ENTRY ListEntry;
1211  UINT BytesNeeded = sizeof(LAN_ADAPTER_INFO), AddrSize;
1213  PCHAR Writing = Irp->AssociatedIrp.SystemBuffer;
1215  KIRQL OldIrql;
1216 
1217  LA_DbgPrint(MID_TRACE,("Called\n"));
1218 
1219  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
1220 
1221  if (IrpSp->Parameters.DeviceIoControl.InputBufferLength <
1222  sizeof(*AdapterIndexPtr))
1223  Adapter = NULL;
1224  else
1225  Adapter = FindAdapterByIndex(DeviceExt, *AdapterIndexPtr);
1226 
1227  if (Adapter)
1228  {
1229  /* Local Addresses */
1230  for (ListEntry = Adapter->AddressList.Flink;
1231  ListEntry != &Adapter->AddressList;
1232  ListEntry = ListEntry->Flink)
1233  {
1234  Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, ListEntry);
1235  BytesNeeded += LAN_ADDR_SIZE(Address->ClientPart.AddressLen,
1236  Address->ClientPart.HWAddressLen);
1237  }
1238 
1239  /* Foreign Addresses */
1240  for (ListEntry = Adapter->ForeignList.Flink;
1241  ListEntry != &Adapter->ForeignList;
1242  ListEntry = ListEntry->Flink)
1243  {
1244  Address = CONTAINING_RECORD(ListEntry, LAN_ADDRESS_C, ListEntry);
1245  BytesNeeded += LAN_ADDR_SIZE(Address->ClientPart.AddressLen,
1246  Address->ClientPart.HWAddressLen);
1247  }
1248  BytesNeeded += Adapter->RegistryPath.Length;
1249 
1250  if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >=
1251  BytesNeeded)
1252  {
1253  /* Write common info */
1254  Info = (PLAN_ADAPTER_INFO_S)Writing;
1255  Info->Index = Adapter->Index;
1256  Info->Media = Adapter->Media;
1257  Info->Speed = Adapter->Speed;
1258  /* Ethernet specific XXX */
1259  Info->AddressLen = IEEE_802_ADDR_LENGTH;
1260  Info->Overhead = Adapter->HeaderSize;
1261  Info->MTU = Adapter->MTU;
1262  Info->RegKeySize = Adapter->RegistryPath.Length;
1263 
1264  /* Copy the name */
1265  Writing += sizeof(*Info);
1266  RtlCopyMemory(Adapter->RegistryPath.Buffer,
1267  Writing,
1268  Adapter->RegistryPath.Length);
1269 
1270  /* Write the address info */
1271  Writing += Adapter->RegistryPath.Length;
1272 
1273  for (ListEntry = Adapter->AddressList.Flink;
1274  ListEntry != &Adapter->AddressList;
1275  ListEntry = ListEntry->Flink)
1276  {
1278  ListEntry);
1279  AddrSize = LAN_ADDR_SIZE(Address->ClientPart.AddressLen,
1280  Address->ClientPart.HWAddressLen);
1281  RtlCopyMemory(Writing, &Address->ClientPart, AddrSize);
1282  Writing += AddrSize;
1283  }
1284 
1285  for (ListEntry = Adapter->ForeignList.Flink;
1286  ListEntry != &Adapter->ForeignList;
1287  ListEntry = ListEntry->Flink)
1288  {
1289  Address = CONTAINING_RECORD(ListEntry,
1290  LAN_ADDRESS_C,
1291  ListEntry);
1292  AddrSize = LAN_ADDR_SIZE(Address->ClientPart.AddressLen,
1293  Address->ClientPart.HWAddressLen);
1294  RtlCopyMemory(Writing, &Address->ClientPart, AddrSize);
1295  Writing += AddrSize;
1296  }
1297 
1298  ASSERT(BytesNeeded == Writing - Irp->AssociatedIrp.SystemBuffer);
1299  }
1301  }
1303 
1304  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1305 
1306  LA_DbgPrint(MID_TRACE,("Ending (%d bytes)\n", BytesNeeded));
1307 
1308  Irp->IoStatus.Status = Status;
1309  Irp->IoStatus.Information = BytesNeeded;
1310 
1312 
1313  return Status;
1314 }
1315 
1316 NTSTATUS
1317 NTAPI
1320  PIRP Irp,
1322 {
1325  PLAN_PROTOCOL Proto = FileObject->FsContext;
1327  KIRQL OldIrql;
1328 
1329  LA_DbgPrint(MID_TRACE,("Called %x\n", Proto));
1330 
1331  KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
1332 
1333  if (IrpSp->Parameters.DeviceIoControl.InputBufferLength >=
1334  sizeof(Proto->Buffered))
1335  RtlCopyMemory(&Proto->Buffered,
1336  Irp->AssociatedIrp.SystemBuffer,
1337  sizeof(Proto->Buffered));
1338  else
1340 
1341  KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
1342 
1343  LA_DbgPrint(MID_TRACE,("Set buffered for %x to %d\n", Proto->Buffered));
1344 
1345  Status = Irp->IoStatus.Status = Status;
1346  Irp->IoStatus.Information = 0;
1347 
1349  return Status;
1350 }
1351 
1352 NTSTATUS
1353 NTAPI
1356  PIRP Irp)
1357 {
1360 
1361  LA_DbgPrint(MID_TRACE,("LanDispatch: %d\n", IrpSp->MajorFunction));
1363  {
1364  LA_DbgPrint(MID_TRACE,("FO %x, IrpSp->FO %x\n",
1367  }
1368 
1369  switch (IrpSp->MajorFunction)
1370  {
1371  /* opening and closing handles to the device */
1372  case IRP_MJ_CREATE:
1373  /* Mostly borrowed from the named pipe file system */
1375 
1376  case IRP_MJ_CLOSE:
1377  /* Ditto the borrowing */
1379 
1380  /* write data */
1381  case IRP_MJ_WRITE:
1382  return LanWriteData(DeviceObject, Irp, IrpSp);
1383 
1384  /* read data */
1385  case IRP_MJ_READ:
1386  return LanReadData(DeviceObject, Irp, IrpSp);
1387 
1388  case IRP_MJ_DEVICE_CONTROL:
1389  {
1390  LA_DbgPrint(MID_TRACE,("DeviceIoControl: %x\n",
1391  IrpSp->Parameters.DeviceIoControl.
1392  IoControlCode));
1393  switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
1394  {
1397 
1400 
1401  case IOCTL_IF_ADAPTER_INFO:
1403 
1404  default:
1406  Irp->IoStatus.Information = 0;
1407  LA_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%x)\n",
1408  IrpSp->Parameters.DeviceIoControl.
1409  IoControlCode));
1410  break;
1411  }
1412  break;
1413  }
1414 
1415  /* unsupported operations */
1416  default:
1419  ("Irp: Unknown Major code was %x\n",
1420  IrpSp->MajorFunction));
1421  break;
1422  }
1423 
1424  LA_DbgPrint(MID_TRACE, ("Returning %x\n", Status));
1425  Irp->IoStatus.Status = Status;
1427 
1428  return (Status);
1429 }
1430 
1431 /* Do i need a global here? I think i need to do this a different way XXX */
1432 VOID
1433 NTAPI
1436 {
1438  CloseNdisPools();
1439 }
1440 
1441 NTSTATUS
1442 NTAPI
1445  PUNICODE_STRING RegsitryPath)
1446 {
1448  PLAN_DEVICE_EXT DeviceExt;
1449  UNICODE_STRING wstrDeviceName = RTL_CONSTANT_STRING(L"\\Device\\Lan");
1450  UNICODE_STRING LanString = RTL_CONSTANT_STRING(L"LAN");
1451  NTSTATUS Status;
1452 
1453  InitNdisPools();
1454 
1455  /* register driver routines */
1462 
1463  /* create lan device */
1465  sizeof(LAN_DEVICE_EXT),
1466  &wstrDeviceName,
1468  0,
1469  FALSE,
1470  &DeviceObject);
1471 
1472  /* failure */
1473  if (!NT_SUCCESS(Status))
1474  {
1475  return (Status);
1476  }
1477 
1479  DeviceExt = DeviceObject->DeviceExtension;
1480  RtlZeroMemory(DeviceExt, sizeof(*DeviceExt));
1481  InitializeListHead(&DeviceExt->AdapterListHead);
1482  InitializeListHead(&DeviceExt->ProtocolListHead);
1483  KeInitializeSpinLock(&DeviceExt->Lock);
1484 
1485  LANRegisterProtocol(&LanString);
1486 
1488 
1489  LA_DbgPrint(MID_TRACE,("Device created: object %x ext %x\n",
1490  DeviceObject, DeviceExt));
1491 
1492  return (Status);
1493 }
1494 
1495 /* EOF */
UNICODE_STRING RegistryPath
Definition: lan.h:82
signed char * PCHAR
Definition: retypes.h:7
UINT PacketFilter
Definition: lan.h:80
KSPIN_LOCK Lock
Definition: lan.h:103
#define IN
Definition: typedefs.h:38
_In_opt_ NDIS_HANDLE _In_opt_ NDIS_HANDLE _Inout_ PNDIS_REQUEST NdisRequest
Definition: ndis.h:1553
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
VOID NTAPI ProtocolStatusComplete(NDIS_HANDLE NdisBindingContext)
Called by NDIS when a status-change has occurred.
Definition: lan.c:478
#define MID_TRACE
Definition: debug.h:15
#define NDIS_STATUS_CLOSED
Definition: ndis.h:357
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:5990
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
Type
Definition: Type.h:6
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1530
NDIS_STATUS LANRegisterAdapter(PNDIS_STRING AdapterName, PNDIS_STRING RegistryPath)
Registers protocol with an NDIS adapter.
Definition: lan.c:637
VOID NTAPI ProtocolResetComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status)
Called by NDIS to complete resetting an adapter.
Definition: lan.c:142
enum _NDIS_MEDIUM NDIS_MEDIUM
#define NDIS_VERSION_MAJOR
Definition: lan.h:11
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define IOCTL_IF_ADAPTER_INFO
Definition: net_lan.h:17
VOID NTAPI ProtocolSendComplete(NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
Called by NDIS to complete sending process.
Definition: lan.c:184
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
NDIS_HANDLE NdisProtocolHandle
Definition: lan.h:102
UINT AdapterId
Definition: lan.h:106
REQUEST_COMPLETE_HANDLER RequestCompleteHandler
Definition: ndis.h:1869
VOID EXPORT NdisRegisterProtocol(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisProtocolHandle, IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics, IN UINT CharacteristicsLength)
Definition: protocol.c:1113
LIST_ENTRY ForeignList
Definition: lan.h:59
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ NDIS_STATUS _In_ NDIS_STATUS OpenStatus
Definition: ndis.h:6016
LAN_PACKET_HEADER_T Fixed
Definition: net_lan.h:29
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define DEBUG_DATALINK
Definition: debug.h:24
NTSTATUS NTAPI LanAdapterInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1200
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:122
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LIST_ENTRY AdapterListHead
Definition: lan.h:104
UCHAR BCastOffset
Definition: lan.h:72
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ProtocolCloseAdapterComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status)
Called by NDIS to complete closing an adapter.
Definition: lan.c:120
* PNDIS_STATUS
Definition: ndis.h:45
ULONG NDIS_OID
Definition: ntddndis.h:204
VOID FreeAdapter(PLAN_ADAPTER Adapter)
Frees memory for a LAN_ADAPTER structure.
Definition: lan.c:83
#define OID_GEN_CURRENT_PACKET_FILTER
Definition: ntddndis.h:220
VOID EXPORT NdisDeregisterProtocol(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisProtocolHandle)
Definition: protocol.c:732
UINT Speed
Definition: lan.h:79
#define FreeNdisPacket(x)
Definition: memtrack.h:8
UINT HWAddressLength
Definition: lan.h:69
CLOSE_ADAPTER_COMPLETE_HANDLER CloseAdapterCompleteHandler
Definition: ndis.h:1859
GLuint GLuint end
Definition: gl.h:1545
PETH_HEADER EthHeader
Definition: lan.h:87
UINT MinFrameSize
Definition: lan.h:75
IRP
Definition: iotypes.h:2462
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define exFreePool(x)
Definition: memtrack.h:18
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
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
RECEIVE_COMPLETE_HANDLER ReceiveCompleteHandler
Definition: ndis.h:1874
#define LAN_STATE_STOPPED
Definition: lan.h:114
NDIS_STATUS NDISCall(PLAN_ADAPTER Adapter, NDIS_REQUEST_TYPE Type, NDIS_OID OID, PVOID Buffer, UINT Length)
Send a request to NDIS.
Definition: lan.c:29
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID NTAPI ProtocolBindAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindContext, IN PNDIS_STRING DeviceName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2)
Called by NDIS during NdisRegisterProtocol to set up initial bindings, and periodically thereafter as...
Definition: lan.c:497
VOID LANUnregisterProtocol(VOID)
Unregisters this protocol driver with NDIS.
Definition: lan.c:943
struct TraceInfo Info
STATUS_HANDLER StatusHandler
Definition: ndis.h:1875
VOID LANTransmit(PLAN_ADAPTER Adapter, PNDIS_PACKET NdisPacket, PVOID LinkAddress, USHORT Type)
Transmits a packet ARGUMENTS:
Definition: lan.c:520
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_SEH2_TRY
Definition: create.c:4250
int NDIS_STATUS
Definition: ntddndis.h:380
LIST_ENTRY ProtocolListHead
Definition: lan.h:105
UINT Lookahead
Definition: lan.h:81
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5155
LIST_ENTRY AddressList
Definition: lan.h:58
#define NDIS_VERSION_MINOR
Definition: lan.h:12
UCHAR KIRQL
Definition: env_spec_w32.h:591
NDIS_STATUS NTAPI ProtocolReceive(NDIS_HANDLE BindingContext, NDIS_HANDLE MacReceiveContext, PVOID HeaderBuffer, UINT HeaderBufferSize, PVOID LookaheadBuffer, UINT LookaheadBufferSize, UINT PacketSize)
Called by NDIS when a packet has been received on the physical link.
Definition: lan.c:355
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
LIST_ENTRY ListEntry
Definition: lan.h:57
UINT Buffered
Definition: lan.h:96
USHORT EtherType[1]
Definition: lan.h:98
VOID NTAPI ProtocolStatus(NDIS_HANDLE BindingContext, NDIS_STATUS GenerelStatus, PVOID StatusBuffer, UINT StatusBufferSize)
Called by NDIS when the underlying driver has changed state.
Definition: lan.c:461
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
Definition: lan.h:33
Definition: Header.h:8
NTSTATUS NTAPI LanCreateProtocol(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:973
NDIS_STATUS LANUnregisterAdapter(PLAN_ADAPTER Adapter)
Unregisters protocol with NDIS adapter.
Definition: lan.c:847
UCHAR BCastCheck
Definition: lan.h:71
NTSTATUS NTAPI LanEnumAdapters(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1147
UINT ProtoId
Definition: lan.h:107
USHORT MTU
Definition: lan.h:74
UCHAR BCastMask
Definition: lan.h:70
#define LAN_ADDR_SIZE(AddrLen, HWAddrLen)
Definition: net_lan.h:60
NDIS_STATUS NdisStatus
Definition: lan.h:66
#define IOCTL_IF_ENUM_ADAPTERS
Definition: net_lan.h:13
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
VOID EXPORT NdisSend(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_PACKET Packet)
Definition: protocol.c:1270
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
LIST_ENTRY ListEntry
Definition: lan.h:92
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UINT Index
Definition: lan.h:61
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
BIND_HANDLER BindAdapterHandler
Definition: ndis.h:1879
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
VOID CloseNdisPools(VOID)
#define IOCTL_IF_BUFFERED_MODE
Definition: net_lan.h:15
#define MEDIA_ETH
Definition: lan.h:26
NTSTATUS NTAPI LanDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: lan.c:1354
Definition: bufpool.h:45
RESET_COMPLETE_HANDLER ResetCompleteHandler
Definition: ndis.h:1868
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
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 IO_NETWORK_INCREMENT
Definition: tcpip.h:43
OPEN_ADAPTER_COMPLETE_HANDLER OpenAdapterCompleteHandler
Definition: ndis.h:1858
NTSTATUS NTAPI LanWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1101
#define PCHAR
Definition: match.c:90
NTSTATUS LANRegisterProtocol(PNDIS_STRING Name)
Registers this protocol driver with NDIS.
Definition: lan.c:893
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
NTSTATUS NTAPI LanCloseProtocol(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1030
#define LAN_ADAPTER_INFO
Definition: net_lan.h:11
#define LAN_STATE_RESETTING
Definition: lan.h:112
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct LAN_ADAPTER * PLAN_ADAPTER
NDIS_MEDIUM Media
Definition: lan.h:67
#define OID_GEN_MAXIMUM_FRAME_SIZE
Definition: ntddndis.h:212
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
TRANSFER_DATA_COMPLETE_HANDLER TransferDataCompleteHandler
Definition: ndis.h:1865
struct _ETH_HEADER ETH_HEADER
#define OID_GEN_MAXIMUM_TOTAL_SIZE
Definition: ntddndis.h:223
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
KSPIN_LOCK Lock
Definition: lan.h:60
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
static const UCHAR Index[8]
Definition: usbohci.c:18
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
UCHAR HeaderSize
Definition: lan.h:73
VOID NTAPI LanUnload(PDRIVER_OBJECT DriverObject)
Definition: lan.c:1434
#define NDIS_PACKET_TYPE_MULTICAST
Definition: ndis.h:664
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
UINT64 OID
Definition: marshal.c:88
NTSTATUS NTAPI LanReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1121
PLAN_ADAPTER FindAdapterByIndex(PLAN_DEVICE_EXT DeviceExt, UINT Index)
Definition: lan.c:1073
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1067
* PFILE_OBJECT
Definition: iotypes.h:1954
STATUS_COMPLETE_HANDLER StatusCompleteHandler
Definition: ndis.h:1876
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define BCAST_ETH_CHECK
Definition: lan.h:45
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
#define BCAST_ETH_MASK
Definition: lan.h:42
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
Definition: arc.h:85
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
RECEIVE_HANDLER ReceiveHandler
Definition: ndis.h:1871
_In_ PVOID _In_ PVOID SystemSpecific2
Definition: ndis.h:637
#define exAllocatePool(x, y)
Definition: memtrack.h:17
Definition: typedefs.h:117
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
NDIS_HANDLE NdisHandle
Definition: lan.h:65
ULONG DebugTraceLevel
Definition: lan.c:14
VOID BindAdapter(PLAN_ADAPTER Adapter, PNDIS_STRING RegistryPath)
Binds a LAN adapter to IP layer.
Definition: lan.c:617
VOID NTAPI ProtocolRequestComplete(NDIS_HANDLE BindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
Called by NDIS to complete a request.
Definition: lan.c:159
Status
Definition: gdiplustypes.h:24
#define OID_GEN_LINK_SPEED
Definition: ntddndis.h:213
NDIS_STATUS InitNdisPools(VOID)
UCHAR HWAddress[IEEE_802_ADDR_LENGTH]
Definition: lan.h:68
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
KEVENT Event
Definition: lan.h:63
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
SEND_COMPLETE_HANDLER SendCompleteHandler
Definition: ndis.h:1861
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_SEH2_END
Definition: create.c:4424
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:227
enum _NDIS_REQUEST_TYPE NDIS_REQUEST_TYPE
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS _In_ PVOID _In_ UINT StatusBufferSize
Definition: ndis.h:1537
_In_ USHORT PacketSize
Definition: iofuncs.h:1056
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
unsigned short USHORT
Definition: pedump.c:61
static calc_node_t temp
Definition: rpn_ieee.c:38
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
UCHAR State
Definition: lan.h:62
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
VOID EXPORT NdisOpenAdapter(OUT PNDIS_STATUS Status, OUT PNDIS_STATUS OpenErrorStatus, OUT PNDIS_HANDLE NdisBindingHandle, OUT PUINT SelectedMediumIndex, IN PNDIS_MEDIUM MediumArray, IN UINT MediumArraySize, IN NDIS_HANDLE NdisProtocolHandle, IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_STRING AdapterName, IN UINT OpenOptions, IN PSTRING AddressingInformation OPTIONAL)
Definition: protocol.c:762
#define BCAST_ETH_OFFSET
Definition: lan.h:48
unsigned int UINT
Definition: ndis.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS _In_ PVOID StatusBuffer
Definition: ndis.h:1537
#define IRP_MJ_READ
Definition: rdpdr.c:46
NTSTATUS NTAPI LanSetBufferedMode(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1318
VOID EXPORT NdisCloseAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle)
Definition: protocol.c:701
#define OUT
Definition: typedefs.h:39
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegsitryPath)
Definition: lan.c:1443
UINT Id
Definition: lan.h:94
UINT MaxSendPackets
Definition: lan.h:77
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
UINT TotalSize
Definition: lan.h:88
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:277
VOID NTAPI ProtocolOpenAdapterComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status, NDIS_STATUS OpenErrorStatus)
Called by NDIS to complete opening of an adapter.
Definition: lan.c:99
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define LAN_STATE_STARTED
Definition: lan.h:113
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
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:5995
struct _LAN_ADAPTER_INFO_S * PLAN_ADAPTER_INFO_S
return STATUS_SUCCESS
Definition: btrfs.c:2725
UINT NumEtherTypes
Definition: lan.h:97
IoMarkIrpPending(Irp)
#define memset(x, y, z)
Definition: compat.h:39
VOID NTAPI ProtocolReceiveComplete(NDIS_HANDLE BindingContext)
Called by NDIS when we're done receiving data.
Definition: lan.c:444
VOID EXPORT NdisTransferData(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN NDIS_HANDLE MacReceiveContext, IN UINT ByteOffset, IN UINT BytesToTransfer, IN OUT PNDIS_PACKET Packet, OUT PUINT BytesTransferred)
Definition: protocol.c:1305
CHAR Address[1]
Definition: net_lan.h:30
#define MAX_MEDIA
Definition: lan.h:28
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:221
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
VOID NTAPI ProtocolTransferDataComplete(NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status, UINT BytesTransferred)
Called by NDIS to complete reception of data.
Definition: lan.c:210
static NDIS_MEDIUM MediaArray[MEDIA_ARRAY_SIZE]
Definition: miniport.c:33
unsigned int * PUINT
Definition: ndis.h:50
LIST_ENTRY ReadIrpListHead
Definition: lan.h:93
#define NDIS_PACKET_TYPE_DIRECTED
Definition: ndis.h:663
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
UINT MaxPacketSize
Definition: lan.h:76
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
UINT LANTransmitInternal(PLAN_PACKET_HEADER ToWrite, UINT OverallLength)
Definition: lan.c:544