ReactOS  0.4.14-dev-57-g333b8f1
lan.c File Reference
#include "precomp.h"
Include dependency graph for lan.c:

Go to the source code of this file.

Functions

NDIS_STATUS NDISCall (PLAN_ADAPTER Adapter, NDIS_REQUEST_TYPE Type, NDIS_OID OID, PVOID Buffer, UINT Length)
 Send a request to NDIS. More...
 
VOID FreeAdapter (PLAN_ADAPTER Adapter)
 Frees memory for a LAN_ADAPTER structure. More...
 
VOID NTAPI ProtocolOpenAdapterComplete (NDIS_HANDLE BindingContext, NDIS_STATUS Status, NDIS_STATUS OpenErrorStatus)
 Called by NDIS to complete opening of an adapter. More...
 
VOID NTAPI ProtocolCloseAdapterComplete (NDIS_HANDLE BindingContext, NDIS_STATUS Status)
 Called by NDIS to complete closing an adapter. More...
 
VOID NTAPI ProtocolResetComplete (NDIS_HANDLE BindingContext, NDIS_STATUS Status)
 Called by NDIS to complete resetting an adapter. More...
 
VOID NTAPI ProtocolRequestComplete (NDIS_HANDLE BindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
 Called by NDIS to complete a request. More...
 
VOID NTAPI ProtocolSendComplete (NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
 Called by NDIS to complete sending process. More...
 
VOID NTAPI ProtocolTransferDataComplete (NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status, UINT BytesTransferred)
 Called by NDIS to complete reception of data. More...
 
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. More...
 
VOID NTAPI ProtocolReceiveComplete (NDIS_HANDLE BindingContext)
 Called by NDIS when we're done receiving data. More...
 
VOID NTAPI ProtocolStatus (NDIS_HANDLE BindingContext, NDIS_STATUS GenerelStatus, PVOID StatusBuffer, UINT StatusBufferSize)
 Called by NDIS when the underlying driver has changed state. More...
 
VOID NTAPI ProtocolStatusComplete (NDIS_HANDLE NdisBindingContext)
 Called by NDIS when a status-change has occurred. More...
 
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 new adapters come online. More...
 
VOID LANTransmit (PLAN_ADAPTER Adapter, PNDIS_PACKET NdisPacket, PVOID LinkAddress, USHORT Type)
 Transmits a packet ARGUMENTS: More...
 
UINT LANTransmitInternal (PLAN_PACKET_HEADER ToWrite, UINT OverallLength)
 
VOID BindAdapter (PLAN_ADAPTER Adapter, PNDIS_STRING RegistryPath)
 Binds a LAN adapter to IP layer. More...
 
NDIS_STATUS LANRegisterAdapter (PNDIS_STRING AdapterName, PNDIS_STRING RegistryPath)
 Registers protocol with an NDIS adapter. More...
 
NDIS_STATUS LANUnregisterAdapter (PLAN_ADAPTER Adapter)
 Unregisters protocol with NDIS adapter. More...
 
NTSTATUS LANRegisterProtocol (PNDIS_STRING Name)
 Registers this protocol driver with NDIS. More...
 
VOID LANUnregisterProtocol (VOID)
 Unregisters this protocol driver with NDIS. More...
 
NTSTATUS NTAPI LanCreateProtocol (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI LanCloseProtocol (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
PLAN_ADAPTER FindAdapterByIndex (PLAN_DEVICE_EXT DeviceExt, UINT Index)
 
NTSTATUS NTAPI LanWriteData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI LanReadData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI LanEnumAdapters (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI LanAdapterInfo (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI LanSetBufferedMode (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI LanDispatch (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
VOID NTAPI LanUnload (PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegsitryPath)
 

Variables

ULONG DebugTraceLevel = 0x7ffffff
 
PDEVICE_OBJECT LanDeviceObject = NULL
 

Function Documentation

◆ BindAdapter()

VOID BindAdapter ( PLAN_ADAPTER  Adapter,
PNDIS_STRING  RegistryPath 
)

Binds a LAN adapter to IP layer.

Parameters
Adapter= Pointer to LAN_ADAPTER structure
Note
We set the lookahead buffer size, set the packet filter and bind the adapter to IP layer

Definition at line 617 of file lan.c.

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 }
#define DEBUG_DATALINK
Definition: debug.h:24
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66

Referenced by LANRegisterAdapter().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegsitryPath 
)

Definition at line 1443 of file lan.c.

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 }
KSPIN_LOCK Lock
Definition: lan.h:103
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define MID_TRACE
Definition: debug.h:15
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:122
LIST_ENTRY AdapterListHead
Definition: lan.h:104
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY ProtocolListHead
Definition: lan.h:105
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI LanDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: lan.c:1354
NTSTATUS LANRegisterProtocol(PNDIS_STRING Name)
Registers this protocol driver with NDIS.
Definition: lan.c:893
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
VOID NTAPI LanUnload(PDRIVER_OBJECT DriverObject)
Definition: lan.c:1434
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
Status
Definition: gdiplustypes.h:24
NDIS_STATUS InitNdisPools(VOID)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define IRP_MJ_READ
Definition: rdpdr.c:46
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
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 IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ FindAdapterByIndex()

PLAN_ADAPTER FindAdapterByIndex ( PLAN_DEVICE_EXT  DeviceExt,
UINT  Index 
)

Definition at line 1073 of file lan.c.

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 }
LIST_ENTRY AdapterListHead
Definition: lan.h:104
UINT Index
Definition: lan.h:61
smooth NULL
Definition: ftsmooth.c:416
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
static const UCHAR Index[8]
Definition: usbohci.c:18
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
Definition: typedefs.h:117

Referenced by LanAdapterInfo(), and LANTransmitInternal().

◆ FreeAdapter()

VOID FreeAdapter ( PLAN_ADAPTER  Adapter)

Frees memory for a LAN_ADAPTER structure.

Parameters
Adapter= Pointer to LAN_ADAPTER structure to free

Definition at line 83 of file lan.c.

85 {
86  exFreePool(Adapter);
87 }
#define exFreePool(x)
Definition: memtrack.h:18

Referenced by LANUnregisterAdapter().

◆ LanAdapterInfo()

NTSTATUS NTAPI LanAdapterInfo ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1200 of file lan.c.

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 }
signed char * PCHAR
Definition: retypes.h:7
KSPIN_LOCK Lock
Definition: lan.h:103
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
struct TraceInfo Info
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define LAN_ADDR_SIZE(AddrLen, HWAddrLen)
Definition: net_lan.h:60
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
#define IoCompleteRequest
Definition: irp.c:1240
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
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
#define LAN_ADAPTER_INFO
Definition: net_lan.h:11
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PLAN_ADAPTER FindAdapterByIndex(PLAN_DEVICE_EXT DeviceExt, UINT Index)
Definition: lan.c:1073
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
unsigned int UINT
Definition: ndis.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
struct _LAN_ADAPTER_INFO_S * PLAN_ADAPTER_INFO_S
return STATUS_SUCCESS
Definition: btrfs.c:2966
unsigned int * PUINT
Definition: ndis.h:50

Referenced by LanDispatch().

◆ LanCloseProtocol()

NTSTATUS NTAPI LanCloseProtocol ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1030 of file lan.c.

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 }
KSPIN_LOCK Lock
Definition: lan.h:103
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
IRP
Definition: iotypes.h:2463
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
_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
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
* PFILE_OBJECT
Definition: iotypes.h:1955
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by LanDispatch().

◆ LanCreateProtocol()

NTSTATUS NTAPI LanCreateProtocol ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 973 of file lan.c.

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 }
signed char * PCHAR
Definition: retypes.h:7
KSPIN_LOCK Lock
Definition: lan.h:103
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY ProtocolListHead
Definition: lan.h:105
USHORT EtherType[1]
Definition: lan.h:98
UINT ProtoId
Definition: lan.h:107
LIST_ENTRY ListEntry
Definition: lan.h:92
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
* PFILE_OBJECT
Definition: iotypes.h:1955
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
UINT Id
Definition: lan.h:94
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
UINT NumEtherTypes
Definition: lan.h:97
return STATUS_SUCCESS
Definition: btrfs.c:2966
LIST_ENTRY ReadIrpListHead
Definition: lan.h:93

Referenced by LanDispatch().

◆ LanDispatch()

NTSTATUS NTAPI LanDispatch ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 1354 of file lan.c.

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 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define MID_TRACE
Definition: debug.h:15
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define IOCTL_IF_ADAPTER_INFO
Definition: net_lan.h:17
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI LanAdapterInfo(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1200
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI LanCreateProtocol(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:973
NTSTATUS NTAPI LanEnumAdapters(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1147
#define IOCTL_IF_ENUM_ADAPTERS
Definition: net_lan.h:13
#define IoCompleteRequest
Definition: irp.c:1240
#define IOCTL_IF_BUFFERED_MODE
Definition: net_lan.h:15
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS NTAPI LanWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1101
#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
NTSTATUS NTAPI LanReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1121
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IRP_MJ_READ
Definition: rdpdr.c:46
NTSTATUS NTAPI LanSetBufferedMode(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lan.c:1318
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define MIN_TRACE
Definition: debug.h:14
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Referenced by DriverEntry().

◆ LanEnumAdapters()

NTSTATUS NTAPI LanEnumAdapters ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1147 of file lan.c.

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 }
signed char * PCHAR
Definition: retypes.h:7
KSPIN_LOCK Lock
Definition: lan.h:103
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
LIST_ENTRY AdapterListHead
Definition: lan.h:104
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
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
#define PCHAR
Definition: match.c:90
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: arc.h:85
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
unsigned int UINT
Definition: ndis.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
unsigned int * PUINT
Definition: ndis.h:50

Referenced by LanDispatch().

◆ LanReadData()

NTSTATUS NTAPI LanReadData ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1121 of file lan.c.

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 }
KSPIN_LOCK Lock
Definition: lan.h:103
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
PVOID DeviceExtension
Definition: env_spec_w32.h:418
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
#define STATUS_PENDING
Definition: ntstatus.h:82
* PFILE_OBJECT
Definition: iotypes.h:1955
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
IoMarkIrpPending(Irp)

Referenced by LanDispatch().

◆ LANRegisterAdapter()

NDIS_STATUS LANRegisterAdapter ( PNDIS_STRING  AdapterName,
PNDIS_STRING  RegistryPath 
)

Registers protocol with an NDIS adapter.

Parameters
AdapterName= Pointer to string with name of adapter to register
Adapter= Address of pointer to a LAN_ADAPTER structure
Returns
Status of operation

Definition at line 637 of file lan.c.

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 }
UNICODE_STRING RegistryPath
Definition: lan.h:82
UINT PacketFilter
Definition: lan.h:80
KSPIN_LOCK Lock
Definition: lan.h:103
#define MID_TRACE
Definition: debug.h:15
enum _NDIS_MEDIUM NDIS_MEDIUM
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
LIST_ENTRY ForeignList
Definition: lan.h:59
_In_ NDIS_STATUS _In_ NDIS_STATUS OpenStatus
Definition: ndis.h:6034
#define DEBUG_DATALINK
Definition: debug.h:24
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
#define OID_GEN_CURRENT_PACKET_FILTER
Definition: ntddndis.h:246
UINT Speed
Definition: lan.h:79
UINT HWAddressLength
Definition: lan.h:69
UINT MinFrameSize
Definition: lan.h:75
#define exFreePool(x)
Definition: memtrack.h:18
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define 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
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
int NDIS_STATUS
Definition: ntddndis.h:471
UINT Lookahead
Definition: lan.h:81
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
LIST_ENTRY AddressList
Definition: lan.h:58
LIST_ENTRY ListEntry
Definition: lan.h:57
UCHAR BCastCheck
Definition: lan.h:71
USHORT MTU
Definition: lan.h:74
UCHAR BCastMask
Definition: lan.h:70
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UINT Index
Definition: lan.h:61
smooth NULL
Definition: ftsmooth.c:416
#define MEDIA_ETH
Definition: lan.h:26
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
NDIS_MEDIUM Media
Definition: lan.h:67
#define OID_GEN_MAXIMUM_FRAME_SIZE
Definition: ntddndis.h:238
struct _ETH_HEADER ETH_HEADER
#define OID_GEN_MAXIMUM_TOTAL_SIZE
Definition: ntddndis.h:249
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
KSPIN_LOCK Lock
Definition: lan.h:60
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
UCHAR HeaderSize
Definition: lan.h:73
#define NDIS_PACKET_TYPE_MULTICAST
Definition: ndis.h:664
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define BCAST_ETH_CHECK
Definition: lan.h:45
static const WCHAR L[]
Definition: oid.c:1250
#define BCAST_ETH_MASK
Definition: lan.h:42
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define exAllocatePool(x, y)
Definition: memtrack.h:17
NDIS_HANDLE NdisHandle
Definition: lan.h:65
#define OID_GEN_LINK_SPEED
Definition: ntddndis.h:239
UCHAR HWAddress[IEEE_802_ADDR_LENGTH]
Definition: lan.h:68
KEVENT Event
Definition: lan.h:63
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:253
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
UCHAR State
Definition: lan.h:62
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
#define BCAST_ETH_OFFSET
Definition: lan.h:48
unsigned int UINT
Definition: ndis.h:50
UINT MaxSendPackets
Definition: lan.h:77
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:303
#define LAN_STATE_STARTED
Definition: lan.h:113
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT _In_ NDIS_HANDLE _In_ NDIS_HANDLE _In_ PNDIS_STRING AdapterName
Definition: ndis.h:6013
#define MAX_MEDIA
Definition: lan.h:28
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:247
static NDIS_MEDIUM MediaArray[MEDIA_ARRAY_SIZE]
Definition: miniport.c:33
#define NDIS_PACKET_TYPE_DIRECTED
Definition: ndis.h:663
UINT MaxPacketSize
Definition: lan.h:76
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666

Referenced by ProtocolBindAdapter().

◆ LANRegisterProtocol()

NTSTATUS LANRegisterProtocol ( PNDIS_STRING  Name)

Registers this protocol driver with NDIS.

Parameters
Name= Name of this protocol driver
Returns
Status of operation

Definition at line 893 of file lan.c.

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 }
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
VOID NTAPI ProtocolResetComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status)
Called by NDIS to complete resetting an adapter.
Definition: lan.c:142
#define NDIS_VERSION_MAJOR
Definition: lan.h:11
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
NDIS_HANDLE NdisProtocolHandle
Definition: lan.h:102
REQUEST_COMPLETE_HANDLER RequestCompleteHandler
Definition: ndis.h:1887
VOID EXPORT NdisRegisterProtocol(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisProtocolHandle, IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics, IN UINT CharacteristicsLength)
Definition: protocol.c:1115
#define DEBUG_DATALINK
Definition: debug.h:24
LIST_ENTRY AdapterListHead
Definition: lan.h:104
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
CLOSE_ADAPTER_COMPLETE_HANDLER CloseAdapterCompleteHandler
Definition: ndis.h:1877
RECEIVE_COMPLETE_HANDLER ReceiveCompleteHandler
Definition: ndis.h:1892
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
STATUS_HANDLER StatusHandler
Definition: ndis.h:1893
int NDIS_STATUS
Definition: ntddndis.h:471
LIST_ENTRY ProtocolListHead
Definition: lan.h:105
#define NDIS_VERSION_MINOR
Definition: lan.h:12
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 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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
BIND_HANDLER BindAdapterHandler
Definition: ndis.h:1897
RESET_COMPLETE_HANDLER ResetCompleteHandler
Definition: ndis.h:1886
OPEN_ADAPTER_COMPLETE_HANDLER OpenAdapterCompleteHandler
Definition: ndis.h:1876
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
TRANSFER_DATA_COMPLETE_HANDLER TransferDataCompleteHandler
Definition: ndis.h:1883
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
STATUS_COMPLETE_HANDLER StatusCompleteHandler
Definition: ndis.h:1894
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
RECEIVE_HANDLER ReceiveHandler
Definition: ndis.h:1889
VOID NTAPI ProtocolRequestComplete(NDIS_HANDLE BindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
Called by NDIS to complete a request.
Definition: lan.c:159
SEND_COMPLETE_HANDLER SendCompleteHandler
Definition: ndis.h:1879
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
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
return STATUS_SUCCESS
Definition: btrfs.c:2966
VOID NTAPI ProtocolReceiveComplete(NDIS_HANDLE BindingContext)
Called by NDIS when we're done receiving data.
Definition: lan.c:444
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

Referenced by DriverEntry().

◆ LanSetBufferedMode()

NTSTATUS NTAPI LanSetBufferedMode ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1318 of file lan.c.

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 }
KSPIN_LOCK Lock
Definition: lan.h:103
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
* PFILE_OBJECT
Definition: iotypes.h:1955
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
struct _LAN_DEVICE_EXT * PLAN_DEVICE_EXT
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by LanDispatch().

◆ LANTransmit()

VOID LANTransmit ( PLAN_ADAPTER  Adapter,
PNDIS_PACKET  NdisPacket,
PVOID  LinkAddress,
USHORT  Type 
)

Transmits a packet ARGUMENTS:

Parameters
Context= Pointer to context information (LAN_ADAPTER)
NdisPacket= Pointer to NDIS packet to send
LinkAddress= Pointer to link address of destination (NULL = broadcast)
Type= LAN protocol type (LAN_PROTO_*)

Definition at line 520 of file lan.c.

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 }
#define NDIS_STATUS_CLOSED
Definition: ndis.h:357
VOID NTAPI ProtocolSendComplete(NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
Called by NDIS to complete sending process.
Definition: lan.c:184
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
#define DEBUG_DATALINK
Definition: debug.h:24
int NDIS_STATUS
Definition: ntddndis.h:471
VOID EXPORT NdisSend(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_PACKET Packet)
Definition: protocol.c:1272
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
NDIS_HANDLE NdisHandle
Definition: lan.h:65
UCHAR State
Definition: lan.h:62
#define LAN_STATE_STARTED
Definition: lan.h:113

Referenced by BindAdapter(), and LANTransmitInternal().

◆ LANTransmitInternal()

UINT LANTransmitInternal ( PLAN_PACKET_HEADER  ToWrite,
UINT  OverallLength 
)

Definition at line 544 of file lan.c.

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 }
signed char * PCHAR
Definition: retypes.h:7
KSPIN_LOCK Lock
Definition: lan.h:103
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
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
UINT HWAddressLength
Definition: lan.h:69
GLuint GLuint end
Definition: gl.h:1545
VOID LANTransmit(PLAN_ADAPTER Adapter, PNDIS_PACKET NdisPacket, PVOID LinkAddress, USHORT Type)
Transmits a packet ARGUMENTS:
Definition: lan.c:520
int NDIS_STATUS
Definition: ntddndis.h:471
UCHAR KIRQL
Definition: env_spec_w32.h:591
Definition: lan.h:33
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
PLAN_ADAPTER FindAdapterByIndex(PLAN_DEVICE_EXT DeviceExt, UINT Index)
Definition: lan.c:1073
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
UCHAR HWAddress[IEEE_802_ADDR_LENGTH]
Definition: lan.h:68
unsigned int UINT
Definition: ndis.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define memset(x, y, z)
Definition: compat.h:39
CHAR Address[1]
Definition: net_lan.h:30

Referenced by LanWriteData().

◆ LanUnload()

VOID NTAPI LanUnload ( PDRIVER_OBJECT  DriverObject)

Definition at line 1434 of file lan.c.

1436 {
1438  CloseNdisPools();
1439 }
VOID LANUnregisterProtocol(VOID)
Unregisters this protocol driver with NDIS.
Definition: lan.c:943
VOID CloseNdisPools(VOID)

Referenced by DriverEntry().

◆ LANUnregisterAdapter()

NDIS_STATUS LANUnregisterAdapter ( PLAN_ADAPTER  Adapter)

Unregisters protocol with NDIS adapter.

Parameters
Adapter= Pointer to a LAN_ADAPTER structure
Returns
Status of operation

Definition at line 847 of file lan.c.

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 }
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
#define DEBUG_DATALINK
Definition: debug.h:24
VOID FreeAdapter(PLAN_ADAPTER Adapter)
Frees memory for a LAN_ADAPTER structure.
Definition: lan.c:83
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
int NDIS_STATUS
Definition: ntddndis.h:471
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
LIST_ENTRY ListEntry
Definition: lan.h:57
NDIS_STATUS NdisStatus
Definition: lan.h:66
smooth NULL
Definition: ftsmooth.c:416
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
KSPIN_LOCK Lock
Definition: lan.h:60
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
NDIS_HANDLE NdisHandle
Definition: lan.h:65
KEVENT Event
Definition: lan.h:63
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
VOID EXPORT NdisCloseAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle)
Definition: protocol.c:703

Referenced by LANUnregisterProtocol(), and ProtocolUnbindAdapter().

◆ LANUnregisterProtocol()

VOID LANUnregisterProtocol ( VOID  )

Unregisters this protocol driver with NDIS.

Note
Does not care wether we are already registered

Definition at line 943 of file lan.c.

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 }
KSPIN_LOCK Lock
Definition: lan.h:103
NDIS_HANDLE NdisProtocolHandle
Definition: lan.h:102
#define DEBUG_DATALINK
Definition: debug.h:24
LIST_ENTRY AdapterListHead
Definition: lan.h:104
VOID EXPORT NdisDeregisterProtocol(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisProtocolHandle)
Definition: protocol.c:734
int NDIS_STATUS
Definition: ntddndis.h:471
UCHAR KIRQL
Definition: env_spec_w32.h:591
NDIS_STATUS LANUnregisterAdapter(PLAN_ADAPTER Adapter)
Unregisters protocol with NDIS adapter.
Definition: lan.c:847
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117

Referenced by LANRegisterProtocol(), and LanUnload().

◆ LanWriteData()

NTSTATUS NTAPI LanWriteData ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 1101 of file lan.c.

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 }
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
Status
Definition: gdiplustypes.h:24
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
UINT LANTransmitInternal(PLAN_PACKET_HEADER ToWrite, UINT OverallLength)
Definition: lan.c:544

Referenced by LanDispatch().

◆ NDISCall()

NDIS_STATUS NDISCall ( PLAN_ADAPTER  Adapter,
NDIS_REQUEST_TYPE  Type,
NDIS_OID  OID,
PVOID  Buffer,
UINT  Length 
)

Send a request to NDIS.

Parameters
Adapter= Pointer to a LAN_ADAPTER structure
Type= Type of request (Set or Query)
OID= Value to be set/queried for
Buffer= Pointer to a buffer to use
Length= Number of bytes in Buffer
Returns
Status of operation

Definition at line 29 of file lan.c.

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 }
_In_opt_ NDIS_HANDLE _In_opt_ NDIS_HANDLE _Inout_ PNDIS_REQUEST NdisRequest
Definition: ndis.h:1571
Type
Definition: Type.h:6
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
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
int NDIS_STATUS
Definition: ntddndis.h:471
_In_ NDIS_HANDLE _In_ PNDIS_REQUEST Request
Definition: ndis.h:5173
NDIS_STATUS NdisStatus
Definition: lan.h:66
smooth NULL
Definition: ftsmooth.c:416
#define LAN_STATE_RESETTING
Definition: lan.h:112
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
UINT64 OID
Definition: marshal.c:88
NDIS_HANDLE NdisHandle
Definition: lan.h:65
KEVENT Event
Definition: lan.h:63
UCHAR State
Definition: lan.h:62
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by BindAdapter(), LANRegisterAdapter(), ReconfigureAdapter(), and TcpipLanGetDwordOid().

◆ ProtocolBindAdapter()

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 new adapters come online.

Parameters
Status- Return value to NDIS
BindContext- Handle provided by NDIS to track pending binding operations
DeviceName- Name of the miniport device to bind to
SystemSpecific1- Pointer to a registry path with protocol-specific configuration information
SystemSpecific2- Unused & must not be touched

Definition at line 497 of file lan.c.

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 }
NDIS_STATUS LANRegisterAdapter(PNDIS_STRING AdapterName, PNDIS_STRING RegistryPath)
Registers protocol with an NDIS adapter.
Definition: lan.c:637
#define DEBUG_DATALINK
Definition: debug.h:24
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
Status
Definition: gdiplustypes.h:24

Referenced by LANRegisterProtocol().

◆ ProtocolCloseAdapterComplete()

VOID NTAPI ProtocolCloseAdapterComplete ( NDIS_HANDLE  BindingContext,
NDIS_STATUS  Status 
)

Called by NDIS to complete closing an adapter.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
Status= Status of the operation

Definition at line 120 of file lan.c.

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 }
#define DEBUG_DATALINK
Definition: debug.h:24
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NDIS_STATUS NdisStatus
Definition: lan.h:66
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
struct LAN_ADAPTER * PLAN_ADAPTER
Status
Definition: gdiplustypes.h:24
KEVENT Event
Definition: lan.h:63

Referenced by LANRegisterProtocol().

◆ ProtocolOpenAdapterComplete()

VOID NTAPI ProtocolOpenAdapterComplete ( NDIS_HANDLE  BindingContext,
NDIS_STATUS  Status,
NDIS_STATUS  OpenErrorStatus 
)

Called by NDIS to complete opening of an adapter.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
Status= Status of the operation
OpenErrorStatus= Additional status information

Definition at line 99 of file lan.c.

103 {
104  PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
105 
106  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
107 
108  KeSetEvent(&Adapter->Event, 0, FALSE);
109 }
#define DEBUG_DATALINK
Definition: debug.h:24
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
struct LAN_ADAPTER * PLAN_ADAPTER
KEVENT Event
Definition: lan.h:63

Referenced by LANRegisterProtocol().

◆ ProtocolReceive()

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.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
MacReceiveContext= Handle used by underlying NIC driver
HeaderBuffer= Pointer to a buffer containing the packet header
HeaderBufferSize= Number of bytes in HeaderBuffer
LookaheadBuffer= Pointer to a buffer containing buffered packet data
LookaheadBufferSize= Size of LookaheadBuffer. May be less than asked for
PacketSize= Overall size of the packet (not including header)
Returns
Status of operation

Definition at line 355 of file lan.c.

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 }
signed char * PCHAR
Definition: retypes.h:7
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
#define DEBUG_DATALINK
Definition: debug.h:24
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
int NDIS_STATUS
Definition: ntddndis.h:471
USHORT MTU
Definition: lan.h:74
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
smooth NULL
Definition: ftsmooth.c:416
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
struct LAN_ADAPTER * PLAN_ADAPTER
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
KSPIN_LOCK Lock
Definition: lan.h:60
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
NDIS_HANDLE NdisHandle
Definition: lan.h:65
_In_ USHORT PacketSize
Definition: iofuncs.h:1056
unsigned short USHORT
Definition: pedump.c:61
static calc_node_t temp
Definition: rpn_ieee.c:38
UCHAR State
Definition: lan.h:62
unsigned int UINT
Definition: ndis.h:50
#define LAN_STATE_STARTED
Definition: lan.h:113
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 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

Referenced by LANRegisterProtocol().

◆ ProtocolReceiveComplete()

VOID NTAPI ProtocolReceiveComplete ( NDIS_HANDLE  BindingContext)

Called by NDIS when we're done receiving data.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)

Definition at line 444 of file lan.c.

446 {
447  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
448 }
#define DEBUG_DATALINK
Definition: debug.h:24
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66

Referenced by LANRegisterProtocol().

◆ ProtocolRequestComplete()

VOID NTAPI ProtocolRequestComplete ( NDIS_HANDLE  BindingContext,
PNDIS_REQUEST  NdisRequest,
NDIS_STATUS  Status 
)

Called by NDIS to complete a request.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
NdisRequest= Pointer to an object describing the request
Status= Status of the operation

Definition at line 159 of file lan.c.

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 }
#define DEBUG_DATALINK
Definition: debug.h:24
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NDIS_STATUS NdisStatus
Definition: lan.h:66
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
struct LAN_ADAPTER * PLAN_ADAPTER
Status
Definition: gdiplustypes.h:24
KEVENT Event
Definition: lan.h:63

Referenced by LANRegisterProtocol().

◆ ProtocolResetComplete()

VOID NTAPI ProtocolResetComplete ( NDIS_HANDLE  BindingContext,
NDIS_STATUS  Status 
)

Called by NDIS to complete resetting an adapter.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
Status= Status of the operation

Definition at line 142 of file lan.c.

145 {
146  LA_DbgPrint(MID_TRACE, ("Called.\n"));
147 }
#define MID_TRACE
Definition: debug.h:15
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66

Referenced by LANRegisterProtocol().

◆ ProtocolSendComplete()

VOID NTAPI ProtocolSendComplete ( NDIS_HANDLE  BindingContext,
PNDIS_PACKET  Packet,
NDIS_STATUS  Status 
)

Called by NDIS to complete sending process.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
Packet= Pointer to a packet descriptor
Status= Status of the operation

Definition at line 184 of file lan.c.

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 }
#define DEBUG_DATALINK
Definition: debug.h:24
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66

Referenced by LANRegisterProtocol(), and LANTransmit().

◆ ProtocolStatus()

VOID NTAPI ProtocolStatus ( NDIS_HANDLE  BindingContext,
NDIS_STATUS  GenerelStatus,
PVOID  StatusBuffer,
UINT  StatusBufferSize 
)

Called by NDIS when the underlying driver has changed state.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
GenerelStatus= A generel status code
StatusBuffer= Pointer to a buffer with medium-specific data
StatusBufferSize= Number of bytes in StatusBuffer

Definition at line 461 of file lan.c.

466 {
467  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
468 }
#define DEBUG_DATALINK
Definition: debug.h:24
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66

Referenced by BindAdapter(), DoChangePassword(), LANRegisterProtocol(), LsaApCallPackage(), LsaApCallPackageUntrusted(), LsaCallAuthenticationPackage(), and NetUserChangePassword().

◆ ProtocolStatusComplete()

VOID NTAPI ProtocolStatusComplete ( NDIS_HANDLE  NdisBindingContext)

Called by NDIS when a status-change has occurred.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)

Definition at line 478 of file lan.c.

480 {
481  LA_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
482 }
#define DEBUG_DATALINK
Definition: debug.h:24
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66

Referenced by LANRegisterProtocol().

◆ ProtocolTransferDataComplete()

VOID NTAPI ProtocolTransferDataComplete ( NDIS_HANDLE  BindingContext,
PNDIS_PACKET  Packet,
NDIS_STATUS  Status,
UINT  BytesTransferred 
)

Called by NDIS to complete reception of data.

Parameters
BindingContext= Pointer to a device context (LAN_ADAPTER)
Packet= Pointer to a packet descriptor
Status= Status of the operation
BytesTransferred= Number of bytes transferred
Note
If the packet was successfully received, determine the protocol type and pass it to the correct receive handler

Definition at line 210 of file lan.c.

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 }
KSPIN_LOCK Lock
Definition: lan.h:103
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define DEBUG_DATALINK
Definition: debug.h:24
#define FreeNdisPacket(x)
Definition: memtrack.h:8
PETH_HEADER EthHeader
Definition: lan.h:87
IRP
Definition: iotypes.h:2463
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
_SEH2_TRY
Definition: create.c:4250
LIST_ENTRY ProtocolListHead
Definition: lan.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
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
UINT Buffered
Definition: lan.h:96
USHORT EtherType[1]
Definition: lan.h:98
Definition: Header.h:8
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UINT Index
Definition: lan.h:61
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
#define PCHAR
Definition: match.c:90
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct LAN_ADAPTER * PLAN_ADAPTER
NDIS_MEDIUM Media
Definition: lan.h:67
#define IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PDEVICE_OBJECT LanDeviceObject
Definition: lan.c:15
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
unsigned int UINT
Definition: ndis.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define MIN_TRACE
Definition: debug.h:14
UINT TotalSize
Definition: lan.h:88
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
UINT NumEtherTypes
Definition: lan.h:97
LIST_ENTRY ReadIrpListHead
Definition: lan.h:93

Referenced by LANRegisterProtocol(), and ProtocolReceive().

Variable Documentation

◆ DebugTraceLevel

ULONG DebugTraceLevel = 0x7ffffff

Definition at line 14 of file lan.c.

◆ LanDeviceObject