ReactOS  0.4.14-dev-49-gfb4591c
lan.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ETH_HEADER
 
struct  _LAN_ADDRESS_C
 
struct  LAN_ADAPTER
 
struct  _LAN_PACKET
 
struct  _LAN_PROTOCOL
 
struct  _LAN_DEVICE_EXT
 

Macros

#define NDIS_VERSION_MAJOR   4
 
#define NDIS_VERSION_MINOR   0
 
#define MIN(value1, value2)   ((value1 < value2)? value1 : value2)
 
#define MAX(value1, value2)   ((value1 > value2)? value1 : value2)
 
#define NDIS_BUFFER_TAG   FOURCC('n','b','u','f')
 
#define NDIS_PACKET_TAG   FOURCC('n','p','k','t')
 
#define MEDIA_ETH   0
 
#define MAX_MEDIA   1
 
#define IEEE_802_ADDR_LENGTH   6
 
#define MAX_MEDIA_ETH   sizeof(ETH_HEADER)
 
#define BCAST_ETH_MASK   0x01
 
#define BCAST_ETH_CHECK   0x01
 
#define BCAST_ETH_OFFSET   0x00
 
#define LAN_STATE_OPENING   0
 
#define LAN_STATE_RESETTING   1
 
#define LAN_STATE_STARTED   2
 
#define LAN_STATE_STOPPED   3
 
#define LOOKAHEAD_SIZE   128
 
#define ETYPE_IPv4   WH2N(0x0800)
 
#define ETYPE_IPv6   WH2N(0x86DD)
 
#define ETYPE_ARP   WH2N(0x0806)
 
#define LAN_PROTO_IPv4   0x0000 /* Internet Protocol version 4 */
 
#define LAN_PROTO_IPv6   0x0001 /* Internet Protocol version 6 */
 
#define LAN_PROTO_ARP   0x0002 /* Address Resolution Protocol */
 

Typedefs

typedef struct ETH_HEADER ETH_HEADER
 
typedef struct ETH_HEADERPETH_HEADER
 
typedef struct _LAN_ADDRESS_C LAN_ADDRESS_C
 
typedef struct _LAN_ADDRESS_CPLAN_ADDRESS_C
 
typedef struct LAN_ADAPTER LAN_ADAPTER
 
typedef struct LAN_ADAPTERPLAN_ADAPTER
 
typedef struct _LAN_PACKET LAN_PACKET
 
typedef struct _LAN_PACKETPLAN_PACKET
 
typedef struct _LAN_PROTOCOL LAN_PROTOCOL
 
typedef struct _LAN_PROTOCOLPLAN_PROTOCOL
 
typedef struct _LAN_DEVICE_EXT LAN_DEVICE_EXT
 
typedef struct _LAN_DEVICE_EXTPLAN_DEVICE_EXT
 

Functions

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...
 
NDIS_STATUS NDISCall (PLAN_ADAPTER Adapter, NDIS_REQUEST_TYPE Type, NDIS_OID OID, PVOID Buffer, UINT Length)
 Send a request to NDIS. More...
 
void GetDataPtr (PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
 
NDIS_STATUS AllocatePacketWithBufferX (PNDIS_PACKET *NdisPacket, PCHAR Data, UINT Len, PCHAR File, UINT Line)
 
VOID FreeNdisPacketX (PNDIS_PACKET Packet, PCHAR File, UINT Line)
 
NDIS_STATUS InitNdisPools (VOID)
 
VOID CloseNdisPools (VOID)
 
PLAN_ADAPTER FindAdapterByIndex (PLAN_DEVICE_EXT DeviceExt, UINT Index)
 

Macro Definition Documentation

◆ BCAST_ETH_CHECK

#define BCAST_ETH_CHECK   0x01

Definition at line 45 of file lan.h.

◆ BCAST_ETH_MASK

#define BCAST_ETH_MASK   0x01

Definition at line 42 of file lan.h.

◆ BCAST_ETH_OFFSET

#define BCAST_ETH_OFFSET   0x00

Definition at line 48 of file lan.h.

◆ ETYPE_ARP

#define ETYPE_ARP   WH2N(0x0806)

Definition at line 123 of file lan.h.

◆ ETYPE_IPv4

#define ETYPE_IPv4   WH2N(0x0800)

Definition at line 121 of file lan.h.

◆ ETYPE_IPv6

#define ETYPE_IPv6   WH2N(0x86DD)

Definition at line 122 of file lan.h.

◆ IEEE_802_ADDR_LENGTH

#define IEEE_802_ADDR_LENGTH   6

Definition at line 30 of file lan.h.

◆ LAN_PROTO_ARP

#define LAN_PROTO_ARP   0x0002 /* Address Resolution Protocol */

Definition at line 128 of file lan.h.

◆ LAN_PROTO_IPv4

#define LAN_PROTO_IPv4   0x0000 /* Internet Protocol version 4 */

Definition at line 126 of file lan.h.

◆ LAN_PROTO_IPv6

#define LAN_PROTO_IPv6   0x0001 /* Internet Protocol version 6 */

Definition at line 127 of file lan.h.

◆ LAN_STATE_OPENING

#define LAN_STATE_OPENING   0

Definition at line 111 of file lan.h.

◆ LAN_STATE_RESETTING

#define LAN_STATE_RESETTING   1

Definition at line 112 of file lan.h.

◆ LAN_STATE_STARTED

#define LAN_STATE_STARTED   2

Definition at line 113 of file lan.h.

◆ LAN_STATE_STOPPED

#define LAN_STATE_STOPPED   3

Definition at line 114 of file lan.h.

◆ LOOKAHEAD_SIZE

#define LOOKAHEAD_SIZE   128

Definition at line 117 of file lan.h.

◆ MAX

#define MAX (   value1,
  value2 
)    ((value1 > value2)? value1 : value2)

Definition at line 19 of file lan.h.

◆ MAX_MEDIA

#define MAX_MEDIA   1

Definition at line 28 of file lan.h.

◆ MAX_MEDIA_ETH

#define MAX_MEDIA_ETH   sizeof(ETH_HEADER)

Definition at line 39 of file lan.h.

◆ MEDIA_ETH

#define MEDIA_ETH   0

Definition at line 26 of file lan.h.

◆ MIN

#define MIN (   value1,
  value2 
)    ((value1 < value2)? value1 : value2)

Definition at line 16 of file lan.h.

◆ NDIS_BUFFER_TAG

#define NDIS_BUFFER_TAG   FOURCC('n','b','u','f')

Definition at line 22 of file lan.h.

◆ NDIS_PACKET_TAG

#define NDIS_PACKET_TAG   FOURCC('n','p','k','t')

Definition at line 23 of file lan.h.

◆ NDIS_VERSION_MAJOR

#define NDIS_VERSION_MAJOR   4

Definition at line 11 of file lan.h.

◆ NDIS_VERSION_MINOR

#define NDIS_VERSION_MINOR   0

Definition at line 12 of file lan.h.

Typedef Documentation

◆ ETH_HEADER

◆ LAN_ADAPTER

◆ LAN_ADDRESS_C

◆ LAN_DEVICE_EXT

◆ LAN_PACKET

◆ LAN_PROTOCOL

◆ PETH_HEADER

◆ PLAN_ADAPTER

◆ PLAN_ADDRESS_C

◆ PLAN_DEVICE_EXT

◆ PLAN_PACKET

◆ PLAN_PROTOCOL

Function Documentation

◆ AllocatePacketWithBufferX()

NDIS_STATUS AllocatePacketWithBufferX ( PNDIS_PACKET NdisPacket,
PCHAR  Data,
UINT  Len,
PCHAR  File,
UINT  Line 
)

Definition at line 82 of file routines.c.

84  {
88  PCHAR NewData;
89 
90  NewData = exAllocatePool( NonPagedPool, Len );
91  if( !NewData ) return NDIS_STATUS_NOT_ACCEPTED; // XXX
92 
93  if( Data )
94  RtlCopyMemory(NewData, Data, Len);
95 
97  if( Status != NDIS_STATUS_SUCCESS ) {
98  exFreePool( NewData );
99  return Status;
100  }
102 
104  if( Status != NDIS_STATUS_SUCCESS ) {
105  exFreePool( NewData );
107  }
109 
111  *NdisPacket = Packet;
112 
113  return NDIS_STATUS_SUCCESS;
114 }
signed char * PCHAR
Definition: retypes.h:7
VOID EXPORT NdisAllocatePacket(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:392
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define FreeNdisPacket(x)
Definition: memtrack.h:8
#define exFreePool(x)
Definition: memtrack.h:18
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
#define NDIS_BUFFER_TAG
Definition: lan.h:22
int NDIS_STATUS
Definition: ntddndis.h:471
Definition: bufpool.h:45
VOID EXPORT NdisAllocateBuffer(OUT PNDIS_STATUS Status, OUT PNDIS_BUFFER *Buffer, IN NDIS_HANDLE PoolHandle, IN PVOID VirtualAddress, IN UINT Length)
Definition: buffer.c:334
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define Len
Definition: deflate.h:82
Definition: ncftp.h:79
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define TrackWithTag(w, x, y, z)
Definition: memtrack.h:19
#define exAllocatePool(x, y)
Definition: memtrack.h:17
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
Status
Definition: gdiplustypes.h:24
#define NDIS_PACKET_TAG
Definition: lan.h:23
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3
Definition: File.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ CloseNdisPools()

VOID CloseNdisPools ( VOID  )

Referenced by LanUnload().

◆ 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().

◆ FreeNdisPacketX()

VOID FreeNdisPacketX ( PNDIS_PACKET  Packet,
PCHAR  File,
UINT  Line 
)

Definition at line 118 of file routines.c.

126 {
127  PNDIS_BUFFER Buffer, NextBuffer;
128 
129  LA_DbgPrint(DEBUG_PBUFFER, ("Packet (0x%X)\n", Packet));
130 
131  /* Free all the buffers in the packet first */
133  for (; Buffer != NULL; Buffer = NextBuffer) {
134  PVOID Data;
135  UINT Length;
136 
137  NdisGetNextBuffer(Buffer, &NextBuffer);
141  exFreePool(Data);
142  }
143 
144  /* Finally free the NDIS packet descriptor */
147 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
VOID EXPORT NdisFreeBuffer(IN PNDIS_BUFFER Buffer)
Definition: buffer.c:809
#define exFreePool(x)
Definition: memtrack.h:18
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
#define UntrackFL(x, y, z)
Definition: memtrack.h:20
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
Definition: bufpool.h:45
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
VOID EXPORT NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:826
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
Definition: ncftp.h:79
unsigned int UINT
Definition: ndis.h:50
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
Definition: File.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ GetDataPtr()

void GetDataPtr ( PNDIS_PACKET  Packet,
UINT  Offset,
PCHAR DataOut,
PUINT  Size 
)

Definition at line 65 of file routines.c.

68  {
70 
72  if( !Buffer ) return;
73  SkipToOffset( Buffer, Offset, DataOut, Size );
74 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: routines.c:24
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by AddGenericHeaderIPv4(), LANTransmit(), LANTransmitInternal(), LoopTransmit(), PrepareARPPacket(), PrepareICMPPacket(), ProtocolReceive(), SendFragments(), SendPacket(), and TCPSendDataCallback().

◆ InitNdisPools()

NDIS_STATUS InitNdisPools ( VOID  )

Referenced by DriverEntry().

◆ 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

◆ 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().

◆ 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

◆ 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 TiUnload().

◆ 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 InfoTdiQueryGetInterfaceMIB().