ReactOS 0.4.16-dev-91-g764881a
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
16
30 PLAN_ADAPTER Adapter,
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 {
68 FALSE,
69 NULL);
70 NdisStatus = Adapter->NdisStatus;
71 }
72
73 return NdisStatus;
74}
75
76
82VOID
84 PLAN_ADAPTER Adapter)
85{
86 exFreePool(Adapter);
87}
88
89
97VOID
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
118VOID
119NTAPI
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
140VOID
141NTAPI
143 NDIS_HANDLE BindingContext,
145{
146 LA_DbgPrint(MID_TRACE, ("Called.\n"));
147}
148
149
157VOID
158NTAPI
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
182VOID
183NTAPI
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
208VOID
209NTAPI
211 NDIS_HANDLE BindingContext,
215{
216 PLIST_ENTRY ListEntry, ReadListEntry;
217 PLAN_PROTOCOL Proto;
220 UINT i;
221 UINT PacketType;
222 UINT ContigSize;
223 PIRP ReadIrp;
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 &&
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
280 {
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"));
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
354NTAPI
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;
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,
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
442VOID
443NTAPI
445 NDIS_HANDLE BindingContext)
446{
447 LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
448}
449
450
459VOID
460NTAPI
462 NDIS_HANDLE BindingContext,
463 NDIS_STATUS GenerelStatus,
466{
467 LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
468}
469
470
476VOID
477NTAPI
479 NDIS_HANDLE NdisBindingContext)
480{
481 LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
482}
483
495VOID
496NTAPI
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
519VOID
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 {
539 }
540}
541
542/* For use internally */
543UINT
545{
546 NDIS_STATUS NdisStatus;
548 PLAN_ADAPTER Adapter;
549 PETH_HEADER EthHeader;
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
602end:
603 KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
604
605 return OverallLength;
606}
607
616VOID
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"));
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
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,
684 MAX_MEDIA,
685 DeviceExt->NdisProtocolHandle,
686 Adapter,
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)
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{
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 {
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
894{
895 NDIS_STATUS NdisStatus;
898
899 LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
900
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;
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
942VOID
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;
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
972NTAPI
975 PIRP Irp,
977{
978 PLAN_PROTOCOL Proto;
980 PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension;
982 PCHAR ProtoNumbersToMatch;
983 UINT Size = sizeof(*Proto);
985
986 EaInfo = Irp->AssociatedIrp.SystemBuffer;
987 Size += EaInfo->EaValueLength;
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
1029NTAPI
1032 PIRP Irp,
1034{
1035 PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension;
1037 PLAN_PROTOCOL Proto = FileObject->FsContext;
1038 KIRQL OldIrql;
1039 PLIST_ENTRY ReadIrpListEntry;
1040 PIRP ReadIrp;
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 */
1100NTAPI
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
1120NTAPI
1123 PIRP Irp,
1125{
1126 PLAN_DEVICE_EXT DeviceExt =
1127 (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension;
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
1146NTAPI
1149 PIRP Irp,
1151{
1152 PLIST_ENTRY ListEntry;
1153 PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension;
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
1199NTAPI
1202 PIRP Irp,
1204{
1205 PLAN_DEVICE_EXT DeviceExt =
1206 (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension;
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,
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
1317NTAPI
1320 PIRP Irp,
1322{
1323 PLAN_DEVICE_EXT DeviceExt = (PLAN_DEVICE_EXT)DeviceObject->DeviceExtension;
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
1353NTAPI
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:
1383
1384 /* read data */
1385 case IRP_MJ_READ:
1387
1389 {
1390 LA_DbgPrint(MID_TRACE,("DeviceIoControl: %x\n",
1392 IoControlCode));
1393 switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
1394 {
1397
1400
1403
1404 default:
1406 Irp->IoStatus.Information = 0;
1407 LA_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%x)\n",
1409 IoControlCode));
1410 break;
1411 }
1412 break;
1413 }
1414
1415 /* unsupported operations */
1416 default:
1419 ("Irp: Unknown Major code was %x\n",
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 */
1432VOID
1433NTAPI
1436{
1439}
1440
1442NTAPI
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");
1452
1453 InitNdisPools();
1454
1455 /* register driver routines */
1456 DriverObject->MajorFunction[IRP_MJ_CLOSE] = LanDispatch;
1457 DriverObject->MajorFunction[IRP_MJ_CREATE] = LanDispatch;
1458 DriverObject->MajorFunction[IRP_MJ_WRITE] = LanDispatch;
1459 DriverObject->MajorFunction[IRP_MJ_READ] = LanDispatch;
1461 DriverObject->DriverUnload = LanUnload;
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));
1483 KeInitializeSpinLock(&DeviceExt->Lock);
1484
1485 LANRegisterProtocol(&LanString);
1486
1487 DeviceObject->Flags |= DO_BUFFERED_IO;
1488
1489 LA_DbgPrint(MID_TRACE,("Device created: object %x ext %x\n",
1490 DeviceObject, DeviceExt));
1491
1492 return (Status);
1493}
1494
1495/* EOF */
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
Type
Definition: Type.h:7
LONG NTSTATUS
Definition: precomp.h:26
#define MIN_TRACE
Definition: debug.h:14
#define MID_TRACE
Definition: debug.h:15
Definition: bufpool.h:45
Definition: Header.h:9
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
#define DEBUG_DATALINK
Definition: debug.h:24
VOID EXPORT NdisGetFirstBufferFromPacket(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
Definition: buffer.c:873
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:764
VOID EXPORT NdisDeregisterProtocol(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisProtocolHandle)
Definition: protocol.c:734
VOID EXPORT NdisSend(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_PACKET Packet)
Definition: protocol.c:1272
VOID EXPORT NdisCloseAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle)
Definition: protocol.c:703
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:1307
VOID EXPORT NdisRegisterProtocol(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisProtocolHandle, IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics, IN UINT CharacteristicsLength)
Definition: protocol.c:1115
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
Status
Definition: gdiplustypes.h:25
GLuint GLuint end
Definition: gl.h:1545
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
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
IoMarkIrpPending(Irp)
#define MAX_MEDIA
Definition: lan.h:28
#define BCAST_ETH_OFFSET
Definition: lan.h:48
#define NDIS_VERSION_MAJOR
Definition: lan.h:11
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
#define MEDIA_ETH
Definition: lan.h:26
#define LAN_STATE_STOPPED
Definition: lan.h:114
#define NDIS_VERSION_MINOR
Definition: lan.h:12
#define BCAST_ETH_CHECK
Definition: lan.h:45
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
#define LAN_STATE_STARTED
Definition: lan.h:113
struct LAN_ADAPTER * PLAN_ADAPTER
#define LAN_STATE_RESETTING
Definition: lan.h:112
#define BCAST_ETH_MASK
Definition: lan.h:42
VOID NTAPI LanUnload(PDRIVER_OBJECT DriverObject)
Definition: lan.c:1434
VOID NTAPI ProtocolCloseAdapterComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status)
Called by NDIS to complete closing an adapter.
Definition: lan.c:120
NTSTATUS NTAPI LanCloseProtocol(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1030
VOID BindAdapter(PLAN_ADAPTER Adapter, PNDIS_STRING RegistryPath)
Binds a LAN adapter to IP layer.
Definition: lan.c:617
NTSTATUS NTAPI LanEnumAdapters(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1147
UINT LANTransmitInternal(PLAN_PACKET_HEADER ToWrite, UINT OverallLength)
Definition: lan.c:544
ULONG DebugTraceLevel
Definition: lan.c:14
VOID NTAPI ProtocolStatusComplete(NDIS_HANDLE NdisBindingContext)
Called by NDIS when a status-change has occurred.
Definition: lan.c:478
NTSTATUS NTAPI LanSetBufferedMode(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1318
NTSTATUS NTAPI LanDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: lan.c:1354
VOID NTAPI ProtocolRequestComplete(NDIS_HANDLE BindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
Called by NDIS to complete a request.
Definition: lan.c:159
VOID NTAPI ProtocolReceiveComplete(NDIS_HANDLE BindingContext)
Called by NDIS when we're done receiving data.
Definition: lan.c:444
PLAN_ADAPTER FindAdapterByIndex(PLAN_DEVICE_EXT DeviceExt, UINT Index)
Definition: lan.c:1073
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
NTSTATUS NTAPI LanReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1121
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
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
VOID LANTransmit(PLAN_ADAPTER Adapter, PNDIS_PACKET NdisPacket, PVOID LinkAddress, USHORT Type)
Transmits a packet ARGUMENTS:
Definition: lan.c:520
VOID LANUnregisterProtocol(VOID)
Unregisters this protocol driver with NDIS.
Definition: lan.c:943
VOID NTAPI ProtocolResetComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status)
Called by NDIS to complete resetting an adapter.
Definition: lan.c:142
NDIS_STATUS LANRegisterAdapter(PNDIS_STRING AdapterName, PNDIS_STRING RegistryPath)
Registers protocol with an NDIS adapter.
Definition: lan.c:637
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 LanCreateProtocol(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:973
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
NTSTATUS NTAPI LanWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1101
NDIS_STATUS LANUnregisterAdapter(PLAN_ADAPTER Adapter)
Unregisters protocol with NDIS adapter.
Definition: lan.c:847
VOID FreeAdapter(PLAN_ADAPTER Adapter)
Frees memory for a LAN_ADAPTER structure.
Definition: lan.c:83
NTSTATUS NTAPI LanAdapterInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1200
NTSTATUS LANRegisterProtocol(PNDIS_STRING Name)
Registers this protocol driver with NDIS.
Definition: lan.c:893
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
VOID NTAPI ProtocolSendComplete(NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
Called by NDIS to complete sending process.
Definition: lan.c:184
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
NDIS_STATUS InitNdisPools()
Definition: routines.c:6
VOID CloseNdisPools()
Definition: routines.c:19
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
#define exAllocatePool(x, y)
Definition: memtrack.h:17
#define exFreePool(x)
Definition: memtrack.h:18
#define FreeNdisPacket(x)
Definition: memtrack.h:8
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
UINT64 OID
Definition: marshal.c:88
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
_In_ PVOID _In_ PVOID SystemSpecific2
Definition: ndis.h:638
#define NDIS_STATUS_CLOSED
Definition: ndis.h:357
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS _In_ PVOID _In_ UINT StatusBufferSize
Definition: ndis.h:1558
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
MDL * PNDIS_BUFFER
Definition: ndis.h:343
enum _NDIS_REQUEST_TYPE NDIS_REQUEST_TYPE
#define NDIS_PACKET_TYPE_MULTICAST
Definition: ndis.h:664
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define NDIS_PACKET_TYPE_DIRECTED
Definition: ndis.h:663
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS OpenErrorStatus
Definition: ndis.h:6009
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS _In_ PVOID StatusBuffer
Definition: ndis.h:1557
* PNDIS_STATUS
Definition: ndis.h:45
_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:6016
_In_opt_ NDIS_HANDLE _In_opt_ NDIS_HANDLE _Inout_ PNDIS_REQUEST NdisRequest
Definition: ndis.h:1573
_In_ NDIS_STATUS _In_ NDIS_STATUS OpenStatus
Definition: ndis.h:6035
@ NdisRequestQueryInformation
Definition: ndis.h:790
@ NdisRequestSetInformation
Definition: ndis.h:791
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define KernelMode
Definition: asm.h:34
#define IOCTL_IF_ADAPTER_INFO
Definition: net_lan.h:17
#define IOCTL_IF_ENUM_ADAPTERS
Definition: net_lan.h:13
#define LAN_ADAPTER_INFO
Definition: net_lan.h:11
#define LAN_ADDR_SIZE(AddrLen, HWAddrLen)
Definition: net_lan.h:60
#define IOCTL_IF_BUFFERED_MODE
Definition: net_lan.h:15
struct _LAN_ADAPTER_INFO_S * PLAN_ADAPTER_INFO_S
static NDIS_MEDIUM MediaArray[MEDIA_ARRAY_SIZE]
Definition: miniport.c:33
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
enum _NDIS_MEDIUM NDIS_MEDIUM
#define OID_GEN_MAXIMUM_TOTAL_SIZE
Definition: ntddndis.h:249
#define OID_GEN_LINK_SPEED
Definition: ntddndis.h:239
#define OID_GEN_CURRENT_PACKET_FILTER
Definition: ntddndis.h:246
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:303
@ NdisMedium802_3
Definition: ntddndis.h:188
#define OID_GEN_MAXIMUM_FRAME_SIZE
Definition: ntddndis.h:238
int NDIS_STATUS
Definition: ntddndis.h:475
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:247
ULONG NDIS_OID
Definition: ntddndis.h:230
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:253
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ SynchronizationEvent
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 IoCompleteRequest
Definition: irp.c:1240
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
static WCHAR Address[46]
Definition: ping.c:68
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:62
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
static calc_node_t temp
Definition: rpn_ieee.c:38
@ Output
Definition: arc.h:85
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
Definition: lan.h:33
UCHAR SrcAddr[IEEE_802_ADDR_LENGTH]
Definition: lan.h:35
USHORT EType
Definition: lan.h:36
UINT PacketFilter
Definition: lan.h:80
LIST_ENTRY ForeignList
Definition: lan.h:59
UINT MinFrameSize
Definition: lan.h:75
UCHAR HWAddress[IEEE_802_ADDR_LENGTH]
Definition: lan.h:68
UNICODE_STRING RegistryPath
Definition: lan.h:82
KSPIN_LOCK Lock
Definition: lan.h:60
LIST_ENTRY AddressList
Definition: lan.h:58
UCHAR HeaderSize
Definition: lan.h:73
USHORT MTU
Definition: lan.h:74
KEVENT Event
Definition: lan.h:63
UCHAR State
Definition: lan.h:62
NDIS_STATUS NdisStatus
Definition: lan.h:66
UINT Index
Definition: lan.h:61
UINT HWAddressLength
Definition: lan.h:69
UINT Lookahead
Definition: lan.h:81
LIST_ENTRY ListEntry
Definition: lan.h:57
NDIS_HANDLE NdisHandle
Definition: lan.h:65
UINT MaxSendPackets
Definition: lan.h:77
UCHAR BCastMask
Definition: lan.h:70
UCHAR BCastCheck
Definition: lan.h:71
NDIS_MEDIUM Media
Definition: lan.h:67
UCHAR BCastOffset
Definition: lan.h:72
UINT Speed
Definition: lan.h:79
UINT MaxPacketSize
Definition: lan.h:76
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UCHAR SrcAddr[ETH_LENGTH_OF_ADDRESS]
Definition: ethernetutils.h:48
UCHAR DstAddr[ETH_LENGTH_OF_ADDRESS]
Definition: ethernetutils.h:47
struct _IO_STACK_LOCATION::@3974::@3979 Write
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
union _IRP::@1577 AssociatedIrp
PVOID SystemBuffer
IO_STATUS_BLOCK IoStatus
UINT ProtoId
Definition: lan.h:107
LIST_ENTRY AdapterListHead
Definition: lan.h:104
NDIS_HANDLE NdisProtocolHandle
Definition: lan.h:102
KSPIN_LOCK Lock
Definition: lan.h:103
UINT AdapterId
Definition: lan.h:106
LIST_ENTRY ProtocolListHead
Definition: lan.h:105
CHAR Address[1]
Definition: net_lan.h:30
LAN_PACKET_HEADER_T Fixed
Definition: net_lan.h:29
UINT TotalSize
Definition: lan.h:88
PETH_HEADER EthHeader
Definition: lan.h:87
UINT Buffered
Definition: lan.h:96
LIST_ENTRY ReadIrpListHead
Definition: lan.h:93
UINT Id
Definition: lan.h:94
UINT NumEtherTypes
Definition: lan.h:97
USHORT EtherType[1]
Definition: lan.h:98
LIST_ENTRY ListEntry
Definition: lan.h:92
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
STATUS_COMPLETE_HANDLER StatusCompleteHandler
Definition: ndis.h:1894
TRANSFER_DATA_COMPLETE_HANDLER TransferDataCompleteHandler
Definition: ndis.h:1883
RECEIVE_COMPLETE_HANDLER ReceiveCompleteHandler
Definition: ndis.h:1892
REQUEST_COMPLETE_HANDLER RequestCompleteHandler
Definition: ndis.h:1887
SEND_COMPLETE_HANDLER SendCompleteHandler
Definition: ndis.h:1879
RECEIVE_HANDLER ReceiveHandler
Definition: ndis.h:1889
BIND_HANDLER BindAdapterHandler
Definition: ndis.h:1897
RESET_COMPLETE_HANDLER ResetCompleteHandler
Definition: ndis.h:1886
STATUS_HANDLER StatusHandler
Definition: ndis.h:1893
OPEN_ADAPTER_COMPLETE_HANDLER OpenAdapterCompleteHandler
Definition: ndis.h:1876
CLOSE_ADAPTER_COMPLETE_HANDLER CloseAdapterCompleteHandler
Definition: ndis.h:1877
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR _Out_opt_ PULONG BytesTransferred
Definition: wdfusb.h:1342
_In_ USHORT PacketSize
Definition: iofuncs.h:1058
#define IO_NO_INCREMENT
Definition: iotypes.h:598
* PFILE_OBJECT
Definition: iotypes.h:1998
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
@ UserRequest
Definition: ketypes.h:421