ReactOS 0.4.15-dev-7113-g9ea2222
lan.c File Reference
#include "precomp.h"
#include <ntifs.h>
#include <receive.h>
#include <wait.h>
Include dependency graph for lan.c:

Go to the source code of this file.

Classes

struct  _LAN_WQ_ITEM
 
struct  _RECONFIGURE_CONTEXT
 

Macros

#define CCS_ROOT   L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet"
 
#define TCPIP_GUID   L"{4D36E972-E325-11CE-BFC1-08002BE10318}"
 

Typedefs

typedef struct _LAN_WQ_ITEM LAN_WQ_ITEM
 
typedef struct _LAN_WQ_ITEMPLAN_WQ_ITEM
 
typedef struct _RECONFIGURE_CONTEXT RECONFIGURE_CONTEXT
 
typedef struct _RECONFIGURE_CONTEXTPRECONFIGURE_CONTEXT
 

Functions

NDIS_STATUS NDISCall (PLAN_ADAPTER Adapter, NDIS_REQUEST_TYPE Type, NDIS_OID OID, PVOID Buffer, UINT Length)
 Send a request to NDIS.
 
NDIS_STATUS GetPacketTypeFromHeaderBuffer (PLAN_ADAPTER Adapter, PVOID HeaderBuffer, ULONG HeaderBufferSize, PULONG PacketType)
 
NDIS_STATUS GetPacketTypeFromNdisPacket (PLAN_ADAPTER Adapter, PNDIS_PACKET NdisPacket, PULONG PacketType)
 
VOID FreeAdapter (PLAN_ADAPTER Adapter)
 
NTSTATUS TcpipLanGetDwordOid (PIP_INTERFACE Interface, NDIS_OID Oid, PULONG Result)
 
VOID NTAPI ProtocolOpenAdapterComplete (NDIS_HANDLE BindingContext, NDIS_STATUS Status, NDIS_STATUS OpenErrorStatus)
 
VOID NTAPI ProtocolCloseAdapterComplete (NDIS_HANDLE BindingContext, NDIS_STATUS Status)
 
VOID NTAPI ProtocolResetComplete (NDIS_HANDLE BindingContext, NDIS_STATUS Status)
 
VOID NTAPI ProtocolRequestComplete (NDIS_HANDLE BindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
 
VOID NTAPI ProtocolSendComplete (NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
 
VOID LanReceiveWorker (PVOID Context)
 
VOID LanSubmitReceiveWork (NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, UINT BytesTransferred, BOOLEAN LegacyReceive)
 
VOID NTAPI ProtocolTransferDataComplete (NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status, UINT BytesTransferred)
 
INT NTAPI ProtocolReceivePacket (NDIS_HANDLE BindingContext, PNDIS_PACKET NdisPacket)
 
NDIS_STATUS NTAPI ProtocolReceive (NDIS_HANDLE BindingContext, NDIS_HANDLE MacReceiveContext, PVOID HeaderBuffer, UINT HeaderBufferSize, PVOID LookaheadBuffer, UINT LookaheadBufferSize, UINT PacketSize)
 
VOID NTAPI ProtocolReceiveComplete (NDIS_HANDLE BindingContext)
 
BOOLEAN ReadIpConfiguration (PIP_INTERFACE Interface)
 
BOOLEAN ReconfigureAdapter (PRECONFIGURE_CONTEXT Context)
 
VOID ReconfigureAdapterWorker (PVOID Context)
 
VOID NTAPI ProtocolStatus (NDIS_HANDLE BindingContext, NDIS_STATUS GeneralStatus, PVOID StatusBuffer, UINT StatusBufferSize)
 
VOID NTAPI ProtocolStatusComplete (NDIS_HANDLE NdisBindingContext)
 
NDIS_STATUS NTAPI ProtocolPnPEvent (NDIS_HANDLE NdisBindingContext, PNET_PNP_EVENT PnPEvent)
 
VOID NTAPI ProtocolBindAdapter (OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindContext, IN PNDIS_STRING DeviceName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2)
 
VOID LANTransmit (PVOID Context, PNDIS_PACKET NdisPacket, UINT Offset, PVOID LinkAddress, USHORT Type)
 
static NTSTATUS OpenRegistryKey (PNDIS_STRING RegistryPath, PHANDLE RegHandle)
 
static NTSTATUS ReadStringFromRegistry (HANDLE RegHandle, PWCHAR RegistryValue, PUNICODE_STRING String)
 
NTSTATUS NTAPI AppendUnicodeString (PUNICODE_STRING ResultFirst, PUNICODE_STRING Second, BOOLEAN Deallocate)
 
static NTSTATUS CheckForDeviceDesc (PUNICODE_STRING EnumKeyName, PUNICODE_STRING TargetKeyName, PUNICODE_STRING Name, PUNICODE_STRING DeviceDesc)
 
static NTSTATUS FindDeviceDescForAdapter (PUNICODE_STRING Name, PUNICODE_STRING DeviceDesc)
 
VOID GetName (PUNICODE_STRING RegistryKey, PUNICODE_STRING OutName)
 
BOOLEAN BindAdapter (PLAN_ADAPTER Adapter, PNDIS_STRING RegistryPath)
 
VOID UnbindAdapter (PLAN_ADAPTER Adapter)
 
NDIS_STATUS LANRegisterAdapter (PNDIS_STRING AdapterName, PNDIS_STRING RegistryPath)
 Registers protocol with an NDIS adapter.
 
NDIS_STATUS LANUnregisterAdapter (PLAN_ADAPTER Adapter)
 Unregisters protocol with NDIS adapter.
 
VOID NTAPI LANUnregisterProtocol (VOID)
 Unregisters this protocol driver with NDIS.
 
VOID NTAPI ProtocolUnbindAdapter (PNDIS_STATUS Status, NDIS_HANDLE ProtocolBindingContext, NDIS_HANDLE UnbindContext)
 
NTSTATUS LANRegisterProtocol (PNDIS_STRING Name)
 Registers this protocol driver with NDIS.
 

Variables

UINT TransferDataCalled = 0
 
UINT TransferDataCompleteCalled = 0
 
NDIS_HANDLE NdisProtocolHandle = (NDIS_HANDLE)NULL
 
BOOLEAN ProtocolRegistered = FALSE
 
LIST_ENTRY AdapterListHead
 
KSPIN_LOCK AdapterListLock
 

Macro Definition Documentation

◆ CCS_ROOT

#define CCS_ROOT   L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet"

Definition at line 20 of file lan.c.

◆ TCPIP_GUID

#define TCPIP_GUID   L"{4D36E972-E325-11CE-BFC1-08002BE10318}"

Definition at line 21 of file lan.c.

Typedef Documentation

◆ LAN_WQ_ITEM

◆ PLAN_WQ_ITEM

◆ PRECONFIGURE_CONTEXT

◆ RECONFIGURE_CONTEXT

Function Documentation

◆ AppendUnicodeString()

NTSTATUS NTAPI AppendUnicodeString ( PUNICODE_STRING  ResultFirst,
PUNICODE_STRING  Second,
BOOLEAN  Deallocate 
)

Definition at line 1145 of file lan.c.

1147 {
1149 UNICODE_STRING Ustr = *ResultFirst;
1150 PWSTR new_string = ExAllocatePoolWithTag
1151 (PagedPool,
1152 (ResultFirst->Length + Second->Length + sizeof(WCHAR)), TEMP_STRING_TAG);
1153 if( !new_string ) {
1154 return STATUS_NO_MEMORY;
1155 }
1156 memcpy( new_string, ResultFirst->Buffer, ResultFirst->Length );
1157 memcpy( new_string + ResultFirst->Length / sizeof(WCHAR),
1158 Second->Buffer, Second->Length );
1159 if( Deallocate ) RtlFreeUnicodeString(ResultFirst);
1160 ResultFirst->Length = Ustr.Length + Second->Length;
1161 ResultFirst->MaximumLength = ResultFirst->Length;
1162 new_string[ResultFirst->Length / sizeof(WCHAR)] = 0;
1163 Status = RtlCreateUnicodeString(ResultFirst,new_string) ?
1166 return Status;
1167}
WCHAR Second[]
Definition: FormatMessage.c:12
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define TEMP_STRING_TAG
Definition: tags.h:42
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CheckForDeviceDesc(), and GetName().

◆ BindAdapter()

BOOLEAN BindAdapter ( PLAN_ADAPTER  Adapter,
PNDIS_STRING  RegistryPath 
)

Definition at line 1312 of file lan.c.

1323{
1324 PIP_INTERFACE IF;
1325 NDIS_STATUS NdisStatus;
1326 LLIP_BIND_INFO BindInfo;
1327 ULONG Lookahead = LOOKAHEAD_SIZE;
1329 NDIS_MEDIA_STATE MediaState;
1330
1331 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
1332
1333 Adapter->State = LAN_STATE_OPENING;
1334
1335 NdisStatus = NDISCall(Adapter,
1338 &Lookahead,
1339 sizeof(ULONG));
1340 if (NdisStatus != NDIS_STATUS_SUCCESS) {
1341 TI_DbgPrint(DEBUG_DATALINK, ("Could not set lookahead buffer size (0x%X).\n", NdisStatus));
1342 return FALSE;
1343 }
1344
1345 /* Bind the adapter to IP layer */
1346 BindInfo.Context = Adapter;
1347 BindInfo.HeaderSize = Adapter->HeaderSize;
1348 BindInfo.MinFrameSize = Adapter->MinFrameSize;
1349 BindInfo.Address = (PUCHAR)&Adapter->HWAddress;
1350 BindInfo.AddressLength = Adapter->HWAddressLength;
1351 BindInfo.Transmit = LANTransmit;
1352
1353 IF = IPCreateInterface(&BindInfo);
1354
1355 if (!IF) {
1356 TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1357 return FALSE;
1358 }
1359
1360 /*
1361 * Query per-adapter configuration from the registry
1362 * In case anyone is curious: there *is* an Ndis configuration api
1363 * for this sort of thing, but it doesn't really support things like
1364 * REG_MULTI_SZ very well, and there is a note in the DDK that says that
1365 * protocol drivers developed for win2k and above just use the native
1366 * services (ZwOpenKey, etc).
1367 */
1368
1369 GetName( RegistryPath, &IF->Name );
1370
1372 if (!NT_SUCCESS(Status)) {
1373 TI_DbgPrint(MIN_TRACE, ("Failed to get device description.\n"));
1375 return FALSE;
1376 }
1377
1378 TI_DbgPrint(DEBUG_DATALINK,("Adapter Description: %wZ\n",
1379 &IF->Description));
1380
1381 /* Get maximum link speed */
1382 NdisStatus = NDISCall(Adapter,
1385 &IF->Speed,
1386 sizeof(UINT));
1387
1388 if (!NT_SUCCESS(NdisStatus))
1390
1391 Adapter->Speed = IF->Speed * 100L;
1392
1393 /* Get maximum frame size */
1394 NdisStatus = NDISCall(Adapter,
1397 &Adapter->MTU,
1398 sizeof(UINT));
1399 if (NdisStatus != NDIS_STATUS_SUCCESS)
1400 return FALSE;
1401
1402 IF->MTU = Adapter->MTU;
1403
1404 /* Get maximum packet size */
1405 NdisStatus = NDISCall(Adapter,
1408 &Adapter->MaxPacketSize,
1409 sizeof(UINT));
1410 if (NdisStatus != NDIS_STATUS_SUCCESS)
1411 return FALSE;
1412
1413 /* Register interface with IP layer */
1415
1416 /* Store adapter context */
1417 Adapter->Context = IF;
1418
1419 /* Get the media state */
1420 NdisStatus = NDISCall(Adapter,
1423 &MediaState,
1424 sizeof(MediaState));
1425 if (NdisStatus != NDIS_STATUS_SUCCESS) {
1426 TI_DbgPrint(DEBUG_DATALINK, ("Could not query media status (0x%X).\n", NdisStatus));
1429 return FALSE;
1430 }
1431
1432 /* Indicate the current media state */
1433 ProtocolStatus(Adapter,
1435 NULL, 0);
1436
1437 /* Set packet filter so we can send and receive packets */
1438 NdisStatus = NDISCall(Adapter,
1441 &Adapter->PacketFilter,
1442 sizeof(UINT));
1443
1444 if (NdisStatus != NDIS_STATUS_SUCCESS) {
1445 TI_DbgPrint(DEBUG_DATALINK, ("Could not set packet filter (0x%X).\n", NdisStatus));
1448 return FALSE;
1449 }
1450
1451 return TRUE;
1452}
#define MIN_TRACE
Definition: debug.h:14
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DEBUG_DATALINK
Definition: debug.h:24
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define IP_DEFAULT_LINK_SPEED
Definition: ip.h:201
VOID IPDestroyInterface(PIP_INTERFACE IF)
Definition: ip.c:244
VOID IPUnregisterInterface(PIP_INTERFACE IF)
Definition: ip.c:349
BOOLEAN IPRegisterInterface(PIP_INTERFACE IF)
Definition: ip.c:289
PIP_INTERFACE IPCreateInterface(PLLIP_BIND_INFO BindInfo)
Definition: ip.c:182
#define LAN_STATE_OPENING
Definition: lan.h:111
#define LOOKAHEAD_SIZE
Definition: lan.h:117
VOID LANTransmit(PLAN_ADAPTER Adapter, PNDIS_PACKET NdisPacket, PVOID LinkAddress, USHORT Type)
Transmits a packet ARGUMENTS:
Definition: lan.c:520
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
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
#define NDIS_STATUS_MEDIA_CONNECT
Definition: ndis.h:361
unsigned int UINT
Definition: ndis.h:50
#define NDIS_STATUS_MEDIA_DISCONNECT
Definition: ndis.h:362
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
@ NdisRequestQueryInformation
Definition: ndis.h:790
@ NdisRequestSetInformation
Definition: ndis.h:791
#define OID_GEN_MAXIMUM_TOTAL_SIZE
Definition: ntddndis.h:249
#define OID_GEN_LINK_SPEED
Definition: ntddndis.h:239
#define OID_GEN_CURRENT_PACKET_FILTER
Definition: ntddndis.h:246
@ NdisMediaStateConnected
Definition: ntddndis.h:470
enum _NDIS_MEDIA_STATE NDIS_MEDIA_STATE
#define OID_GEN_MAXIMUM_FRAME_SIZE
Definition: ntddndis.h:238
#define OID_GEN_MEDIA_CONNECT_STATUS
Definition: ntddndis.h:252
int NDIS_STATUS
Definition: ntddndis.h:475
#define OID_GEN_CURRENT_LOOKAHEAD
Definition: ntddndis.h:247
UINT PacketFilter
Definition: lan.h:80
PVOID Context
Definition: lan.h:64
UINT MinFrameSize
Definition: lan.h:75
UCHAR HWAddress[IEEE_802_ADDR_LENGTH]
Definition: lan.h:68
UCHAR HeaderSize
Definition: lan.h:73
USHORT MTU
Definition: lan.h:74
UCHAR State
Definition: lan.h:62
UINT HWAddressLength
Definition: lan.h:69
UINT Speed
Definition: lan.h:79
UINT MaxPacketSize
Definition: lan.h:76
UNICODE_STRING Description
Definition: ip.h:164
UINT Speed
Definition: ip.h:158
UNICODE_STRING Name
Definition: ip.h:163
UINT MTU
Definition: ip.h:157
PUCHAR Address
Definition: ip.h:130
UINT MinFrameSize
Definition: ip.h:129
PVOID Context
Definition: ip.h:127
UINT HeaderSize
Definition: ip.h:128
UINT AddressLength
Definition: ip.h:131
LL_TRANSMIT_ROUTINE Transmit
Definition: ip.h:132
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215

◆ CheckForDeviceDesc()

static NTSTATUS CheckForDeviceDesc ( PUNICODE_STRING  EnumKeyName,
PUNICODE_STRING  TargetKeyName,
PUNICODE_STRING  Name,
PUNICODE_STRING  DeviceDesc 
)
static

Definition at line 1169 of file lan.c.

1172 {
1173 UNICODE_STRING RootDevice = { 0, 0, NULL }, LinkageKeyName = { 0, 0, NULL };
1174 UNICODE_STRING DescKeyName = { 0, 0, NULL }, Linkage = { 0, 0, NULL };
1175 UNICODE_STRING BackSlash = { 0, 0, NULL };
1176 HANDLE DescKey = NULL, LinkageKey = NULL;
1178
1179 TI_DbgPrint(DEBUG_DATALINK,("EnumKeyName %wZ\n", EnumKeyName));
1180
1182 RtlInitUnicodeString(&Linkage, L"\\Linkage");
1183
1184 RtlInitUnicodeString(&DescKeyName, L"");
1185 AppendUnicodeString( &DescKeyName, EnumKeyName, FALSE );
1186 AppendUnicodeString( &DescKeyName, &BackSlash, TRUE );
1187 AppendUnicodeString( &DescKeyName, TargetKeyName, TRUE );
1188
1189 RtlInitUnicodeString(&LinkageKeyName, L"");
1190 AppendUnicodeString( &LinkageKeyName, &DescKeyName, FALSE );
1191 AppendUnicodeString( &LinkageKeyName, &Linkage, TRUE );
1192
1193 Status = OpenRegistryKey( &LinkageKeyName, &LinkageKey );
1194 if( !NT_SUCCESS(Status) ) goto cleanup;
1195
1196 Status = ReadStringFromRegistry( LinkageKey, L"RootDevice", &RootDevice );
1197 if( !NT_SUCCESS(Status) ) goto cleanup;
1198
1199 if( RtlCompareUnicodeString( &RootDevice, Name, TRUE ) == 0 ) {
1200 Status = OpenRegistryKey( &DescKeyName, &DescKey );
1201 if( !NT_SUCCESS(Status) ) goto cleanup;
1202
1203 Status = ReadStringFromRegistry( DescKey, L"DriverDesc", DeviceDesc );
1204 if( !NT_SUCCESS(Status) ) goto cleanup;
1205
1206 TI_DbgPrint(DEBUG_DATALINK,("ADAPTER DESC: %wZ\n", DeviceDesc));
1207 } else Status = STATUS_UNSUCCESSFUL;
1208
1209cleanup:
1210 RtlFreeUnicodeString( &RootDevice );
1211 RtlFreeUnicodeString( &LinkageKeyName );
1212 RtlFreeUnicodeString( &DescKeyName );
1213 if( LinkageKey ) ZwClose( LinkageKey );
1214 if( DescKey ) ZwClose( DescKey );
1215
1216 TI_DbgPrint(DEBUG_DATALINK,("Returning %x\n", Status));
1217
1218 return Status;
1219}
static void cleanup(void)
Definition: main.c:1335
static const WCHAR BackSlash[]
Definition: devclass.c:29
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define L(x)
Definition: ntvdm.h:50
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by FindDeviceDescForAdapter().

◆ FindDeviceDescForAdapter()

static NTSTATUS FindDeviceDescForAdapter ( PUNICODE_STRING  Name,
PUNICODE_STRING  DeviceDesc 
)
static

Definition at line 1221 of file lan.c.

1222 {
1223 UNICODE_STRING EnumKeyName, TargetKeyName;
1226 ULONG i;
1227 KEY_BASIC_INFORMATION *Kbio =
1229 ULONG KbioLength = sizeof(KEY_BASIC_INFORMATION), ResultLength;
1230
1231 RtlInitUnicodeString( DeviceDesc, NULL );
1232
1233 if( !Kbio ) return STATUS_INSUFFICIENT_RESOURCES;
1234
1236 (&EnumKeyName, CCS_ROOT L"\\Control\\Class\\" TCPIP_GUID);
1237
1238 Status = OpenRegistryKey( &EnumKeyName, &EnumKey );
1239
1240 if( !NT_SUCCESS(Status) ) {
1241 TI_DbgPrint(DEBUG_DATALINK,("Couldn't open Enum key %wZ: %x\n",
1242 &EnumKeyName, Status));
1243 ExFreePoolWithTag( Kbio, KBIO_TAG );
1244 return Status;
1245 }
1246
1247 for( i = 0; NT_SUCCESS(Status); i++ ) {
1248 Status = ZwEnumerateKey( EnumKey, i, KeyBasicInformation,
1249 Kbio, KbioLength, &ResultLength );
1250
1252 ExFreePoolWithTag( Kbio, KBIO_TAG );
1253 KbioLength = ResultLength;
1254 Kbio = ExAllocatePoolWithTag( NonPagedPool, KbioLength, KBIO_TAG );
1255 if( !Kbio ) {
1256 TI_DbgPrint(DEBUG_DATALINK,("Failed to allocate memory\n"));
1257 ZwClose( EnumKey );
1258 return STATUS_NO_MEMORY;
1259 }
1260
1261 Status = ZwEnumerateKey( EnumKey, i, KeyBasicInformation,
1262 Kbio, KbioLength, &ResultLength );
1263
1264 if( !NT_SUCCESS(Status) ) {
1265 TI_DbgPrint(DEBUG_DATALINK,("Couldn't enum key child %d\n", i));
1266 ZwClose( EnumKey );
1267 ExFreePoolWithTag( Kbio, KBIO_TAG );
1268 return Status;
1269 }
1270 }
1271
1272 if( NT_SUCCESS(Status) ) {
1273 TargetKeyName.Length = TargetKeyName.MaximumLength =
1274 Kbio->NameLength;
1275 TargetKeyName.Buffer = Kbio->Name;
1276
1278 ( &EnumKeyName, &TargetKeyName, Name, DeviceDesc );
1279 if( NT_SUCCESS(Status) ) {
1280 ZwClose( EnumKey );
1281 ExFreePoolWithTag( Kbio, KBIO_TAG );
1282 return Status;
1283 } else Status = STATUS_SUCCESS;
1284 }
1285 }
1286
1287 ZwClose( EnumKey );
1288 ExFreePoolWithTag( Kbio, KBIO_TAG );
1289 return STATUS_UNSUCCESSFUL;
1290}
#define KBIO_TAG
Definition: tags.h:41
#define NonPagedPool
Definition: env_spec_w32.h:307
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
static LONG WINAPI EnumKey(HANDLE hcKey, DWORD dwIndex, LPWSTR pszName, PDWORD pcchName, PFILETIME pftLastWriteTime, HANDLE hSpooler)
Definition: localmon.c:169
@ KeyBasicInformation
Definition: nt_native.h:1131
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776

Referenced by BindAdapter().

◆ FreeAdapter()

VOID FreeAdapter ( PLAN_ADAPTER  Adapter)

Definition at line 171 of file lan.c.

178{
180}
#define LAN_ADAPTER_TAG
Definition: tags.h:36

◆ GetName()

VOID GetName ( PUNICODE_STRING  RegistryKey,
PUNICODE_STRING  OutName 
)

Definition at line 1292 of file lan.c.

1293 {
1294 PWCHAR Ptr;
1295 UNICODE_STRING PartialRegistryKey;
1296
1297 PartialRegistryKey.Buffer =
1298 RegistryKey->Buffer + wcslen(CCS_ROOT L"\\Services\\");
1299 Ptr = PartialRegistryKey.Buffer;
1300
1301 while( *Ptr != L'\\' &&
1302 ((PCHAR)Ptr) < ((PCHAR)RegistryKey->Buffer) + RegistryKey->Length )
1303 Ptr++;
1304
1305 PartialRegistryKey.Length = PartialRegistryKey.MaximumLength =
1306 (Ptr - PartialRegistryKey.Buffer) * sizeof(WCHAR);
1307
1308 RtlInitUnicodeString( OutName, L"" );
1309 AppendUnicodeString( OutName, &PartialRegistryKey, FALSE );
1310}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
uint16_t * PWCHAR
Definition: typedefs.h:56
char * PCHAR
Definition: typedefs.h:51

Referenced by BindAdapter().

◆ GetPacketTypeFromHeaderBuffer()

NDIS_STATUS GetPacketTypeFromHeaderBuffer ( PLAN_ADAPTER  Adapter,
PVOID  HeaderBuffer,
ULONG  HeaderBufferSize,
PULONG  PacketType 
)

Definition at line 94 of file lan.c.

98{
99 PETH_HEADER EthHeader = HeaderBuffer;
100
101 if (HeaderBufferSize < Adapter->HeaderSize)
102 {
103 TI_DbgPrint(DEBUG_DATALINK, ("Runt frame (size %d).\n", HeaderBufferSize));
105 }
106
107 switch (Adapter->Media)
108 {
109 case NdisMedium802_3:
110 /* Ethernet and IEEE 802.3 frames can be distinguished by
111 looking at the IEEE 802.3 length field. This field is
112 less than or equal to 1500 for a valid IEEE 802.3 frame
113 and larger than 1500 is it's a valid EtherType value.
114 See RFC 1122, section 2.3.3 for more information */
115
116 *PacketType = EthHeader->EType;
117 break;
118
119 default:
120 TI_DbgPrint(MIN_TRACE, ("Unsupported media.\n"));
121
122 /* FIXME: Support other medias */
124 }
125
126 TI_DbgPrint(DEBUG_DATALINK, ("EtherType (0x%X).\n", *PacketType));
127
128 return NDIS_STATUS_SUCCESS;
129}
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
@ NdisMedium802_3
Definition: ntddndis.h:188
NDIS_MEDIUM Media
Definition: lan.h:67

Referenced by GetPacketTypeFromNdisPacket(), and ProtocolReceive().

◆ GetPacketTypeFromNdisPacket()

NDIS_STATUS GetPacketTypeFromNdisPacket ( PLAN_ADAPTER  Adapter,
PNDIS_PACKET  NdisPacket,
PULONG  PacketType 
)

Definition at line 133 of file lan.c.

136{
137 PVOID HeaderBuffer;
140
141 HeaderBuffer = ExAllocatePoolWithTag(NonPagedPool,
142 Adapter->HeaderSize,
143 HEADER_TAG);
144 if (!HeaderBuffer)
146
147 /* Copy the media header */
148 BytesCopied = CopyPacketToBuffer(HeaderBuffer,
149 NdisPacket,
150 0,
151 Adapter->HeaderSize);
152 if (BytesCopied != Adapter->HeaderSize)
153 {
154 /* Runt frame */
155 ExFreePoolWithTag(HeaderBuffer, HEADER_TAG);
156 TI_DbgPrint(DEBUG_DATALINK, ("Runt frame (size %d).\n", BytesCopied));
158 }
159
161 HeaderBuffer,
163 PacketType);
164
165 ExFreePoolWithTag(HeaderBuffer, HEADER_TAG);
166
167 return Status;
168}
UINT CopyPacketToBuffer(PUCHAR DstData, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
Definition: buffer.c:172
#define HEADER_TAG
Definition: tags.h:45
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3171
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466

Referenced by LanReceiveWorker().

◆ LanReceiveWorker()

VOID LanReceiveWorker ( PVOID  Context)

Definition at line 307 of file lan.c.

307 {
308 ULONG PacketType;
311 PLAN_ADAPTER Adapter;
313 IP_PACKET IPPacket;
314 BOOLEAN LegacyReceive;
316
317 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
318
319 Packet = WorkItem->Packet;
320 Adapter = WorkItem->Adapter;
321 BytesTransferred = WorkItem->BytesTransferred;
322 LegacyReceive = WorkItem->LegacyReceive;
323
325
326 Interface = Adapter->Context;
327
328 IPInitializePacket(&IPPacket, 0);
329
330 IPPacket.NdisPacket = Packet;
331 IPPacket.ReturnPacket = !LegacyReceive;
332
333 if (LegacyReceive)
334 {
335 /* Packet type is precomputed */
336 PacketType = PC(IPPacket.NdisPacket)->PacketType;
337
338 /* Data is at position 0 */
339 IPPacket.Position = 0;
340
341 /* Packet size is determined by bytes transferred */
342 IPPacket.TotalSize = BytesTransferred;
343 }
344 else
345 {
346 /* Determine packet type from media header */
347 if (GetPacketTypeFromNdisPacket(Adapter,
348 IPPacket.NdisPacket,
349 &PacketType) != NDIS_STATUS_SUCCESS)
350 {
351 /* Bad packet */
352 IPPacket.Free(&IPPacket);
353 return;
354 }
355
356 /* Data is at the end of the media header */
357 IPPacket.Position = Adapter->HeaderSize;
358
359 /* Calculate packet size (excluding media header) */
360 NdisQueryPacketLength(IPPacket.NdisPacket, &IPPacket.TotalSize);
361 }
362
365 ("Ether Type = %x Total = %d\n",
366 PacketType, IPPacket.TotalSize));
367
368 /* Update interface stats */
369 Interface->Stats.InBytes += IPPacket.TotalSize + Adapter->HeaderSize;
370
371 /* NDIS packet is freed in all of these cases */
372 switch (PacketType) {
373 case ETYPE_IPv4:
374 case ETYPE_IPv6:
375 TI_DbgPrint(MID_TRACE,("Received IP Packet\n"));
376 IPReceive(Adapter->Context, &IPPacket);
377 break;
378 case ETYPE_ARP:
379 TI_DbgPrint(MID_TRACE,("Received ARP Packet\n"));
380 ARPReceive(Adapter->Context, &IPPacket);
381 break;
382 default:
383 IPPacket.Free(&IPPacket);
384 break;
385 }
386}
unsigned char BOOLEAN
VOID ARPReceive(PVOID Context, PIP_PACKET Packet)
Definition: arp.c:175
#define MID_TRACE
Definition: debug.h:15
#define PC(Packet)
Definition: ip.h:106
PIP_PACKET IPInitializePacket(PIP_PACKET IPPacket, ULONG Type)
Definition: ip.c:92
#define WQ_CONTEXT_TAG
Definition: tags.h:37
#define ETYPE_IPv4
Definition: lan.h:121
#define ETYPE_ARP
Definition: lan.h:123
#define ETYPE_IPv6
Definition: lan.h:122
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NdisQueryPacketLength(_Packet, _TotalPacketLength)
Definition: ndis.h:3645
VOID IPReceive(PIP_INTERFACE IF, PIP_PACKET IPPacket)
Definition: receive.c:638
Definition: ip.h:77
OBJECT_FREE_ROUTINE Free
Definition: ip.h:78
BOOLEAN ReturnPacket
Definition: ip.h:82
UINT Position
Definition: ip.h:87
PNDIS_PACKET NdisPacket
Definition: ip.h:88
UINT TotalSize
Definition: ip.h:86
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR _Out_opt_ PULONG BytesTransferred
Definition: wdfusb.h:1342
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115

Referenced by LanSubmitReceiveWork().

◆ 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 1475 of file lan.c.

1486{
1487 PLAN_ADAPTER IF;
1488 NDIS_STATUS NdisStatus;
1490 UINT MediaIndex;
1492 UINT AddressOID;
1493
1494 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
1495
1497 if (!IF) {
1498 TI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
1499 return NDIS_STATUS_RESOURCES;
1500 }
1501
1502 RtlZeroMemory(IF, sizeof(LAN_ADAPTER));
1503
1504 /* Put adapter in stopped state */
1506
1507 /* Initialize protecting spin lock */
1509
1511
1512 /* Initialize array with media IDs we support */
1514
1515 TI_DbgPrint(DEBUG_DATALINK,("opening adapter %wZ\n", AdapterName));
1516 /* Open the adapter. */
1517 NdisOpenAdapter(&NdisStatus,
1518 &OpenStatus,
1519 &IF->NdisHandle,
1520 &MediaIndex,
1521 MediaArray,
1522 MAX_MEDIA,
1524 IF,
1526 0,
1527 NULL);
1528
1529 /* Wait until the adapter is opened */
1530 if (NdisStatus == NDIS_STATUS_PENDING)
1532 else if (NdisStatus != NDIS_STATUS_SUCCESS) {
1533 TI_DbgPrint(DEBUG_DATALINK,("denying adapter %wZ\n", AdapterName));
1535 return NdisStatus;
1536 }
1537
1538 IF->Media = MediaArray[MediaIndex];
1539
1540 /* Fill LAN_ADAPTER structure with some adapter specific information */
1541 switch (IF->Media) {
1542 case NdisMedium802_3:
1547 IF->HeaderSize = sizeof(ETH_HEADER);
1548 IF->MinFrameSize = 60;
1549 AddressOID = OID_802_3_CURRENT_ADDRESS;
1550 IF->PacketFilter =
1554 break;
1555
1556 default:
1557 /* Unsupported media */
1558 TI_DbgPrint(MIN_TRACE, ("Unsupported media.\n"));
1561 }
1562
1563 /* Get maximum number of packets we can pass to NdisSend(Packets) at one time */
1564 NdisStatus = NDISCall(IF,
1567 &IF->MaxSendPackets,
1568 sizeof(UINT));
1569 if (NdisStatus != NDIS_STATUS_SUCCESS)
1570 /* Legacy NIC drivers may not support this query, if it fails we
1571 assume it can send at least one packet per call to NdisSend(Packets) */
1572 IF->MaxSendPackets = 1;
1573
1574 /* Get current hardware address */
1575 NdisStatus = NDISCall(IF,
1577 AddressOID,
1578 &IF->HWAddress,
1579 IF->HWAddressLength);
1580 if (NdisStatus != NDIS_STATUS_SUCCESS) {
1581 TI_DbgPrint(MIN_TRACE, ("Query for current hardware address failed.\n"));
1583 return NdisStatus;
1584 }
1585
1586 /* Bind adapter to IP layer */
1587 if( !BindAdapter(IF, RegistryPath) ) {
1588 TI_DbgPrint(DEBUG_DATALINK,("denying adapter %wZ (BindAdapter)\n", AdapterName));
1591 }
1592
1593 /* Add adapter to the adapter list */
1595 &IF->ListEntry,
1597
1598 TI_DbgPrint(DEBUG_DATALINK, ("Leaving.\n"));
1599
1600 return NDIS_STATUS_SUCCESS;
1601}
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 IEEE_802_ADDR_LENGTH
Definition: e1000hw.h:11
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define MAX_MEDIA
Definition: lan.h:28
#define BCAST_ETH_OFFSET
Definition: lan.h:48
#define MEDIA_ETH
Definition: lan.h:26
#define LAN_STATE_STOPPED
Definition: lan.h:114
#define BCAST_ETH_CHECK
Definition: lan.h:45
#define BCAST_ETH_MASK
Definition: lan.h:42
#define NDIS_STATUS_PENDING
Definition: ndis.h:347
#define NDIS_STATUS_NOT_SUPPORTED
Definition: ndis.h:479
#define NDIS_PACKET_TYPE_BROADCAST
Definition: ndis.h:666
#define NDIS_PACKET_TYPE_MULTICAST
Definition: ndis.h:664
#define NDIS_PACKET_TYPE_DIRECTED
Definition: ndis.h:663
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT _In_ NDIS_HANDLE _In_ NDIS_HANDLE _In_ PNDIS_STRING AdapterName
Definition: ndis.h:6016
_In_ NDIS_STATUS _In_ NDIS_STATUS OpenStatus
Definition: ndis.h:6035
#define KernelMode
Definition: asm.h:34
static NDIS_MEDIUM MediaArray[MEDIA_ARRAY_SIZE]
Definition: miniport.c:33
enum _NDIS_MEDIUM NDIS_MEDIUM
#define OID_802_3_CURRENT_ADDRESS
Definition: ntddndis.h:303
#define OID_GEN_MAXIMUM_SEND_PACKETS
Definition: ntddndis.h:253
@ SynchronizationEvent
Definition: lan.h:33
KSPIN_LOCK Lock
Definition: lan.h:60
KEVENT Event
Definition: lan.h:63
LIST_ENTRY ListEntry
Definition: lan.h:57
NDIS_HANDLE NdisHandle
Definition: lan.h:65
UINT MaxSendPackets
Definition: lan.h:77
UCHAR BCastMask
Definition: lan.h:70
UCHAR BCastCheck
Definition: lan.h:71
UCHAR BCastOffset
Definition: lan.h:72
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
@ UserRequest
Definition: ketypes.h:421

◆ 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 1696 of file lan.c.

1705{
1706 NDIS_STATUS NdisStatus;
1708
1709 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
1710
1713
1714 /* Set up protocol characteristics */
1715 RtlZeroMemory(&ProtChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
1718 ProtChars.Name.Length = Name->Length;
1719 ProtChars.Name.Buffer = Name->Buffer;
1720 ProtChars.Name.MaximumLength = Name->MaximumLength;
1728 ProtChars.ReceiveHandler = ProtocolReceive;
1730 ProtChars.StatusHandler = ProtocolStatus;
1736
1737 /* Try to register protocol */
1738 NdisRegisterProtocol(&NdisStatus,
1740 &ProtChars,
1742 if (NdisStatus != NDIS_STATUS_SUCCESS)
1743 {
1744 TI_DbgPrint(DEBUG_DATALINK, ("NdisRegisterProtocol failed, status 0x%x\n", NdisStatus));
1745 return (NTSTATUS)NdisStatus;
1746 }
1747
1749
1750 return STATUS_SUCCESS;
1751}
VOID EXPORT NdisRegisterProtocol(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE NdisProtocolHandle, IN PNDIS_PROTOCOL_CHARACTERISTICS ProtocolCharacteristics, IN UINT CharacteristicsLength)
Definition: protocol.c:1115
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NDIS_VERSION_MAJOR
Definition: lan.h:11
#define NDIS_VERSION_MINOR
Definition: lan.h:12
VOID NTAPI ProtocolCloseAdapterComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status)
Called by NDIS to complete closing an adapter.
Definition: lan.c:120
VOID NTAPI ProtocolStatusComplete(NDIS_HANDLE NdisBindingContext)
Called by NDIS when a status-change has occurred.
Definition: lan.c:478
VOID NTAPI ProtocolRequestComplete(NDIS_HANDLE BindingContext, PNDIS_REQUEST NdisRequest, NDIS_STATUS Status)
Called by NDIS to complete a request.
Definition: lan.c:159
VOID NTAPI ProtocolReceiveComplete(NDIS_HANDLE BindingContext)
Called by NDIS when we're done receiving data.
Definition: lan.c:444
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
NDIS_STATUS NTAPI ProtocolReceive(NDIS_HANDLE BindingContext, NDIS_HANDLE MacReceiveContext, PVOID HeaderBuffer, UINT HeaderBufferSize, PVOID LookaheadBuffer, UINT LookaheadBufferSize, UINT PacketSize)
Called by NDIS when a packet has been received on the physical link.
Definition: lan.c:355
VOID NTAPI ProtocolTransferDataComplete(NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status, UINT BytesTransferred)
Called by NDIS to complete reception of data.
Definition: lan.c:210
VOID LANUnregisterProtocol(VOID)
Unregisters this protocol driver with NDIS.
Definition: lan.c:943
VOID NTAPI ProtocolResetComplete(NDIS_HANDLE BindingContext, NDIS_STATUS Status)
Called by NDIS to complete resetting an adapter.
Definition: lan.c:142
VOID NTAPI ProtocolBindAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindContext, IN PNDIS_STRING DeviceName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2)
Called by NDIS during NdisRegisterProtocol to set up initial bindings, and periodically thereafter as...
Definition: lan.c:497
VOID NTAPI ProtocolSendComplete(NDIS_HANDLE BindingContext, PNDIS_PACKET Packet, NDIS_STATUS Status)
Called by NDIS to complete sending process.
Definition: lan.c:184
STATUS_COMPLETE_HANDLER StatusCompleteHandler
Definition: ndis.h:1894
TRANSFER_DATA_COMPLETE_HANDLER TransferDataCompleteHandler
Definition: ndis.h:1883
RECEIVE_COMPLETE_HANDLER ReceiveCompleteHandler
Definition: ndis.h:1892
PNP_EVENT_HANDLER PnPEventHandler
Definition: ndis.h:1899
REQUEST_COMPLETE_HANDLER RequestCompleteHandler
Definition: ndis.h:1887
SEND_COMPLETE_HANDLER SendCompleteHandler
Definition: ndis.h:1879
RECEIVE_HANDLER ReceiveHandler
Definition: ndis.h:1889
BIND_HANDLER BindAdapterHandler
Definition: ndis.h:1897
RESET_COMPLETE_HANDLER ResetCompleteHandler
Definition: ndis.h:1886
RECEIVE_PACKET_HANDLER ReceivePacketHandler
Definition: ndis.h:1896
STATUS_HANDLER StatusHandler
Definition: ndis.h:1893
UNBIND_HANDLER UnbindAdapterHandler
Definition: ndis.h:1898
OPEN_ADAPTER_COMPLETE_HANDLER OpenAdapterCompleteHandler
Definition: ndis.h:1876
CLOSE_ADAPTER_COMPLETE_HANDLER CloseAdapterCompleteHandler
Definition: ndis.h:1877
UNLOAD_PROTOCOL_HANDLER UnloadHandler
Definition: ndis.h:1900

Referenced by DriverEntry().

◆ LanSubmitReceiveWork()

VOID LanSubmitReceiveWork ( NDIS_HANDLE  BindingContext,
PNDIS_PACKET  Packet,
UINT  BytesTransferred,
BOOLEAN  LegacyReceive 
)

Definition at line 388 of file lan.c.

392 {
395 PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
396
397 TI_DbgPrint(DEBUG_DATALINK,("called\n"));
398
399 if (!WQItem) return;
400
401 WQItem->Packet = Packet;
402 WQItem->Adapter = Adapter;
404 WQItem->LegacyReceive = LegacyReceive;
405
406 if (!ChewCreate( LanReceiveWorker, WQItem ))
408}
struct LAN_ADAPTER * PLAN_ADAPTER
PLAN_ADAPTER Adapter
Definition: lan.c:26
PNDIS_PACKET Packet
Definition: lan.c:25
BOOLEAN LegacyReceive
Definition: lan.c:28
UINT BytesTransferred
Definition: lan.c:27
BOOLEAN ChewCreate(VOID(*Worker)(PVOID), PVOID WorkerContext)
Definition: workqueue.c:61

Referenced by ProtocolReceivePacket(), and ProtocolTransferDataComplete().

◆ LANTransmit()

VOID LANTransmit ( PVOID  Context,
PNDIS_PACKET  NdisPacket,
UINT  Offset,
PVOID  LinkAddress,
USHORT  Type 
)

Definition at line 954 of file lan.c.

969{
970 NDIS_STATUS NdisStatus;
971 PETH_HEADER EHeader;
972 PCHAR Data, OldData;
973 UINT Size, OldSize;
976 PNDIS_PACKET XmitPacket;
978
980 ("Called( NdisPacket %x, Offset %d, Adapter %x )\n",
981 NdisPacket, Offset, Adapter));
982
983 if (Adapter->State != LAN_STATE_STARTED) {
984 (*PC(NdisPacket)->DLComplete)(PC(NdisPacket)->Context, NdisPacket, NDIS_STATUS_NOT_ACCEPTED);
985 return;
986 }
987
989 ("Adapter Address [%02x %02x %02x %02x %02x %02x]\n",
990 Adapter->HWAddress[0] & 0xff,
991 Adapter->HWAddress[1] & 0xff,
992 Adapter->HWAddress[2] & 0xff,
993 Adapter->HWAddress[3] & 0xff,
994 Adapter->HWAddress[4] & 0xff,
995 Adapter->HWAddress[5] & 0xff));
996
997 GetDataPtr( NdisPacket, 0, &OldData, &OldSize );
998
999 NdisStatus = AllocatePacketWithBuffer(&XmitPacket, NULL, OldSize + Adapter->HeaderSize);
1000 if (NdisStatus != NDIS_STATUS_SUCCESS) {
1001 (*PC(NdisPacket)->DLComplete)(PC(NdisPacket)->Context, NdisPacket, NDIS_STATUS_RESOURCES);
1002 return;
1003 }
1004
1005 GetDataPtr(XmitPacket, 0, &Data, &Size);
1006
1007 RtlCopyMemory(Data + Adapter->HeaderSize, OldData, OldSize);
1008
1009 (*PC(NdisPacket)->DLComplete)(PC(NdisPacket)->Context, NdisPacket, NDIS_STATUS_SUCCESS);
1010
1011 switch (Adapter->Media) {
1012 case NdisMedium802_3:
1013 EHeader = (PETH_HEADER)Data;
1014
1015 if (LinkAddress) {
1016 /* Unicast address */
1017 RtlCopyMemory(EHeader->DstAddr, LinkAddress, IEEE_802_ADDR_LENGTH);
1018 } else {
1019 /* Broadcast address */
1021 }
1022
1024
1025 switch (Type) {
1026 case LAN_PROTO_IPv4:
1027 EHeader->EType = ETYPE_IPv4;
1028 break;
1029 case LAN_PROTO_ARP:
1030 EHeader->EType = ETYPE_ARP;
1031 break;
1032 case LAN_PROTO_IPv6:
1033 EHeader->EType = ETYPE_IPv6;
1034 break;
1035 default:
1036 ASSERT(FALSE);
1037 return;
1038 }
1039 break;
1040
1041 default:
1042 /* FIXME: Support other medias */
1043 break;
1044 }
1045
1046 TI_DbgPrint( MID_TRACE, ("LinkAddress: %x\n", LinkAddress));
1047 if( LinkAddress ) {
1049 ( MID_TRACE,
1050 ("Link Address [%02x %02x %02x %02x %02x %02x]\n",
1051 ((PCHAR)LinkAddress)[0] & 0xff,
1052 ((PCHAR)LinkAddress)[1] & 0xff,
1053 ((PCHAR)LinkAddress)[2] & 0xff,
1054 ((PCHAR)LinkAddress)[3] & 0xff,
1055 ((PCHAR)LinkAddress)[4] & 0xff,
1056 ((PCHAR)LinkAddress)[5] & 0xff));
1057 }
1058
1059 if (Adapter->MTU < Size) {
1060 /* This is NOT a pointer. MSDN explicitly says so. */
1062 TcpLargeSendPacketInfo) = (PVOID)((ULONG_PTR)Adapter->MTU);
1063 }
1064
1065 /* Update interface stats */
1066 Interface->Stats.OutBytes += Size;
1067
1068 TcpipAcquireSpinLock( &Adapter->Lock, &OldIrql );
1069 TI_DbgPrint(MID_TRACE, ("NdisSend\n"));
1070 NdisSend(&NdisStatus, Adapter->NdisHandle, XmitPacket);
1071 TI_DbgPrint(MID_TRACE, ("NdisSend %s\n",
1072 NdisStatus == NDIS_STATUS_PENDING ?
1073 "Pending" : "Complete"));
1074 TcpipReleaseSpinLock( &Adapter->Lock, OldIrql );
1075
1076 /* I had a talk with vizzini: these really ought to be here.
1077 * we're supposed to see these completed by ndis *only* when
1078 * status_pending is returned. Note that this is different from
1079 * the situation with IRPs. */
1080 if (NdisStatus != NDIS_STATUS_PENDING)
1081 ProtocolSendComplete((NDIS_HANDLE)Context, XmitPacket, NdisStatus);
1082}
Type
Definition: Type.h:7
struct _ETH_HEADER * PETH_HEADER
VOID EXPORT NdisSend(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle, IN PNDIS_PACKET Packet)
Definition: protocol.c:1272
VOID TcpipReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL Irql)
Definition: lock.c:26
VOID TcpipAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL Irql)
Definition: lock.c:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
#define LAN_PROTO_IPv4
Definition: lan.h:126
#define LAN_PROTO_ARP
Definition: lan.h:128
#define LAN_STATE_STARTED
Definition: lan.h:113
#define LAN_PROTO_IPv6
Definition: lan.h:127
#define AllocatePacketWithBuffer(x, y, z)
Definition: memtrack.h:7
#define ASSERT(a)
Definition: mode.c:44
#define NDIS_PER_PACKET_INFO_FROM_PACKET(Packet, InfoType)
Definition: ndis.h:1351
@ TcpLargeSendPacketInfo
Definition: ndis.h:1180
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
UCHAR SrcAddr[ETH_LENGTH_OF_ADDRESS]
Definition: ethernetutils.h:48
UCHAR DstAddr[ETH_LENGTH_OF_ADDRESS]
Definition: ethernetutils.h:47
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792

◆ 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 1604 of file lan.c.

1613{
1614 KIRQL OldIrql;
1615 NDIS_HANDLE NdisHandle;
1616 NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
1617
1618 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
1619
1620 /* Unlink the adapter from the list */
1621 RemoveEntryList(&Adapter->ListEntry);
1622
1623 /* Unbind adapter from IP layer */
1624 UnbindAdapter(Adapter);
1625
1626 TcpipAcquireSpinLock(&Adapter->Lock, &OldIrql);
1627 NdisHandle = Adapter->NdisHandle;
1628 if (NdisHandle) {
1629 Adapter->NdisHandle = NULL;
1630 TcpipReleaseSpinLock(&Adapter->Lock, OldIrql);
1631
1632 NdisCloseAdapter(&NdisStatus, NdisHandle);
1633 if (NdisStatus == NDIS_STATUS_PENDING) {
1636 KernelMode,
1637 FALSE,
1638 NULL);
1639 NdisStatus = Adapter->NdisStatus;
1640 }
1641 } else
1642 TcpipReleaseSpinLock(&Adapter->Lock, OldIrql);
1643
1644 FreeAdapter(Adapter);
1645
1646 return NdisStatus;
1647}
VOID EXPORT NdisCloseAdapter(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisBindingHandle)
Definition: protocol.c:703
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
VOID FreeAdapter(PLAN_ADAPTER Adapter)
Frees memory for a LAN_ADAPTER structure.
Definition: lan.c:83
NDIS_STATUS NdisStatus
Definition: lan.h:66
NTSTATUS TcpipWaitForSingleObject(PVOID Object, KWAIT_REASON Reason, KPROCESSOR_MODE WaitMode, BOOLEAN Alertable, PLARGE_INTEGER Timeout)
Definition: mockwait.c:12

◆ LANUnregisterProtocol()

VOID NTAPI LANUnregisterProtocol ( VOID  )

Unregisters this protocol driver with NDIS.

Note
Does not care wether we are already registered

Definition at line 1651 of file lan.c.

1656{
1657 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
1658
1659 if (ProtocolRegistered) {
1660 NDIS_STATUS NdisStatus;
1661 PLIST_ENTRY CurrentEntry;
1662 PLIST_ENTRY NextEntry;
1663 PLAN_ADAPTER Current;
1664 KIRQL OldIrql;
1665
1667
1668 /* Search the list and remove every adapter we find */
1669 CurrentEntry = AdapterListHead.Flink;
1670 while (CurrentEntry != &AdapterListHead) {
1671 NextEntry = CurrentEntry->Flink;
1672 Current = CONTAINING_RECORD(CurrentEntry, LAN_ADAPTER, ListEntry);
1673 /* Unregister it */
1674 LANUnregisterAdapter(Current);
1675 CurrentEntry = NextEntry;
1676 }
1677
1679
1682 }
1683}
VOID EXPORT NdisDeregisterProtocol(OUT PNDIS_STATUS Status, IN NDIS_HANDLE NdisProtocolHandle)
Definition: protocol.c:734
NDIS_STATUS LANUnregisterAdapter(PLAN_ADAPTER Adapter)
Unregisters protocol with NDIS adapter.
Definition: lan.c:847
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

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 41 of file lan.c.

58{
60 NDIS_STATUS NdisStatus;
61
62 Request.RequestType = Type;
64 Request.DATA.SET_INFORMATION.Oid = OID;
65 Request.DATA.SET_INFORMATION.InformationBuffer = Buffer;
66 Request.DATA.SET_INFORMATION.InformationBufferLength = Length;
67 } else {
68 Request.DATA.QUERY_INFORMATION.Oid = OID;
69 Request.DATA.QUERY_INFORMATION.InformationBuffer = Buffer;
70 Request.DATA.QUERY_INFORMATION.InformationBufferLength = Length;
71 }
72
73 if (Adapter->State != LAN_STATE_RESETTING) {
74 NdisRequest(&NdisStatus, Adapter->NdisHandle, &Request);
75 } else {
76 NdisStatus = NDIS_STATUS_NOT_ACCEPTED;
77 }
78
79 /* Wait for NDIS to complete the request */
80 if (NdisStatus == NDIS_STATUS_PENDING) {
84 FALSE,
85 NULL);
86 NdisStatus = Adapter->NdisStatus;
87 }
88
89 return NdisStatus;
90}
Definition: bufpool.h:45
#define LAN_STATE_RESETTING
Definition: lan.h:112
UINT64 OID
Definition: marshal.c:88
_In_opt_ NDIS_HANDLE _In_opt_ NDIS_HANDLE _Inout_ PNDIS_REQUEST NdisRequest
Definition: ndis.h:1573
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

Referenced by InfoTdiQueryGetInterfaceMIB().

◆ OpenRegistryKey()

static NTSTATUS OpenRegistryKey ( PNDIS_STRING  RegistryPath,
PHANDLE  RegHandle 
)
static

Definition at line 1085 of file lan.c.

1085 {
1088
1090 Status = ZwOpenKey(RegHandle, KEY_ALL_ACCESS, &Attributes);
1091 return Status;
1092}
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:78

Referenced by CheckForDeviceDesc(), and FindDeviceDescForAdapter().

◆ ProtocolBindAdapter()

VOID NTAPI ProtocolBindAdapter ( OUT PNDIS_STATUS  Status,
IN NDIS_HANDLE  BindContext,
IN PNDIS_STRING  DeviceName,
IN PVOID  SystemSpecific1,
IN PVOID  SystemSpecific2 
)

Definition at line 932 of file lan.c.

948{
949 TI_DbgPrint(DEBUG_DATALINK, ("Called with registry path %wZ for %wZ\n", SystemSpecific1, DeviceName));
950 *Status = LANRegisterAdapter(DeviceName, SystemSpecific1);
951}
NDIS_STATUS LANRegisterAdapter(PNDIS_STRING AdapterName, PNDIS_STRING RegistryPath)
Registers protocol with an NDIS adapter.
Definition: lan.c:637
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275

◆ ProtocolCloseAdapterComplete()

VOID NTAPI ProtocolCloseAdapterComplete ( NDIS_HANDLE  BindingContext,
NDIS_STATUS  Status 
)

Definition at line 229 of file lan.c.

238{
239 PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
240
241 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
242
243 Adapter->NdisStatus = Status;
244
245 KeSetEvent(&Adapter->Event, 0, FALSE);
246}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476

◆ ProtocolOpenAdapterComplete()

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

Definition at line 207 of file lan.c.

218{
219 PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
220
221 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
222
223 Adapter->NdisStatus = Status;
224
225 KeSetEvent(&Adapter->Event, 0, FALSE);
226}

◆ ProtocolPnPEvent()

NDIS_STATUS NTAPI ProtocolPnPEvent ( NDIS_HANDLE  NdisBindingContext,
PNET_PNP_EVENT  PnPEvent 
)

Definition at line 904 of file lan.c.

907{
908 switch(PnPEvent->NetEvent)
909 {
910 case NetEventSetPower:
911 DbgPrint("Device transitioned to power state %ld\n", PnPEvent->Buffer);
912 return NDIS_STATUS_SUCCESS;
913
915 DbgPrint("Device wants to go into power state %ld\n", PnPEvent->Buffer);
916 return NDIS_STATUS_SUCCESS;
917
919 DbgPrint("Device is about to be removed\n");
920 return NDIS_STATUS_SUCCESS;
921
923 DbgPrint("Device removal cancelled\n");
924 return NDIS_STATUS_SUCCESS;
925
926 default:
927 DbgPrint("Unhandled event type: %ld\n", PnPEvent->NetEvent);
928 return NDIS_STATUS_SUCCESS;
929 }
930}
#define DbgPrint
Definition: hal.h:12
@ NetEventSetPower
Definition: netpnp.h:15
@ NetEventQueryRemoveDevice
Definition: netpnp.h:17
@ NetEventCancelRemoveDevice
Definition: netpnp.h:18
@ NetEventQueryPower
Definition: netpnp.h:16
PVOID Buffer
Definition: netpnp.h:33
NET_PNP_EVENT_CODE NetEvent
Definition: netpnp.h:32

Referenced by LANRegisterProtocol().

◆ ProtocolReceive()

NDIS_STATUS NTAPI ProtocolReceive ( NDIS_HANDLE  BindingContext,
NDIS_HANDLE  MacReceiveContext,
PVOID  HeaderBuffer,
UINT  HeaderBufferSize,
PVOID  LookaheadBuffer,
UINT  LookaheadBufferSize,
UINT  PacketSize 
)

Definition at line 462 of file lan.c.

483{
484 ULONG PacketType;
486 PCHAR BufferData;
487 NDIS_STATUS NdisStatus;
488 PNDIS_PACKET NdisPacket;
489 PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
490
491 TI_DbgPrint(DEBUG_DATALINK, ("Called. (packetsize %d)\n",PacketSize));
492
493 if (Adapter->State != LAN_STATE_STARTED) {
494 TI_DbgPrint(DEBUG_DATALINK, ("Adapter is stopped.\n"));
496 }
497
498 if (HeaderBufferSize < Adapter->HeaderSize) {
499 TI_DbgPrint(DEBUG_DATALINK, ("Runt frame received.\n"));
501 }
502
503 NdisStatus = GetPacketTypeFromHeaderBuffer(Adapter,
504 HeaderBuffer,
505 HeaderBufferSize,
506 &PacketType);
507 if (NdisStatus != NDIS_STATUS_SUCCESS)
509
510 TI_DbgPrint(DEBUG_DATALINK, ("Adapter: %x (MTU %d)\n",
511 Adapter, Adapter->MTU));
512
513 /* Get a transfer data packet */
514 NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL,
515 PacketSize );
516 if( NdisStatus != NDIS_STATUS_SUCCESS ) {
518 }
519
520 PC(NdisPacket)->PacketType = PacketType;
521
522 TI_DbgPrint(DEBUG_DATALINK, ("pretransfer LookaheadBufferSize %d packsize %d\n",LookaheadBufferSize,PacketSize));
523
524 GetDataPtr( NdisPacket, 0, &BufferData, &PacketSize );
525
527
528 if (LookaheadBufferSize == PacketSize)
529 {
530 /* Optimized code path for packets that are fully contained in
531 * the lookahead buffer. */
532 NdisCopyLookaheadData(BufferData,
533 LookaheadBuffer,
534 LookaheadBufferSize,
535 Adapter->MacOptions);
536 }
537 else
538 {
539 NdisTransferData(&NdisStatus, Adapter->NdisHandle,
540 MacReceiveContext, 0, PacketSize,
541 NdisPacket, &BytesTransferred);
542 }
543 TI_DbgPrint(DEBUG_DATALINK, ("Calling complete\n"));
544
545 if (NdisStatus != NDIS_STATUS_PENDING)
546 ProtocolTransferDataComplete(BindingContext,
547 NdisPacket,
548 NdisStatus,
549 PacketSize);
550
551 TI_DbgPrint(DEBUG_DATALINK, ("leaving\n"));
552
553 return NDIS_STATUS_SUCCESS;
554}
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
#define NdisCopyLookaheadData(Destination, Source, Length, MacOptions)
Definition: ndis.h:3289
UINT MacOptions
Definition: lan.h:78
_In_ USHORT PacketSize
Definition: iofuncs.h:1058

◆ ProtocolReceiveComplete()

VOID NTAPI ProtocolReceiveComplete ( NDIS_HANDLE  BindingContext)

Definition at line 557 of file lan.c.

564{
565 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
566}

◆ ProtocolReceivePacket()

INT NTAPI ProtocolReceivePacket ( NDIS_HANDLE  BindingContext,
PNDIS_PACKET  NdisPacket 
)

Definition at line 442 of file lan.c.

445{
446 PLAN_ADAPTER Adapter = BindingContext;
447
448 if (Adapter->State != LAN_STATE_STARTED) {
449 TI_DbgPrint(DEBUG_DATALINK, ("Adapter is stopped.\n"));
450 return 0;
451 }
452
453 LanSubmitReceiveWork(BindingContext,
454 NdisPacket,
455 0, /* Unused */
456 FALSE);
457
458 /* Hold 1 reference on this packet */
459 return 1;
460}

Referenced by LANRegisterProtocol().

◆ ProtocolRequestComplete()

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

Definition at line 269 of file lan.c.

280{
281 PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
282
283 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
284
285 /* Save status of request and signal an event */
286 Adapter->NdisStatus = Status;
287
288 KeSetEvent(&Adapter->Event, 0, FALSE);
289}

◆ ProtocolResetComplete()

VOID NTAPI ProtocolResetComplete ( NDIS_HANDLE  BindingContext,
NDIS_STATUS  Status 
)

Definition at line 249 of file lan.c.

258{
259 PLAN_ADAPTER Adapter = (PLAN_ADAPTER)BindingContext;
260
261 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
262
263 Adapter->NdisStatus = Status;
264
265 KeSetEvent(&Adapter->Event, 0, FALSE);
266}

◆ ProtocolSendComplete()

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

Definition at line 292 of file lan.c.

303{
305}
#define FreeNdisPacket(x)
Definition: memtrack.h:8

◆ ProtocolStatus()

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

Definition at line 815 of file lan.c.

828{
829 PLAN_ADAPTER Adapter = BindingContext;
831
832 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
833
834 /* Ignore the status indication if we have no context yet. We'll get another later */
835 if (!Adapter->Context)
836 return;
837
839 if (!Context)
840 return;
841
842 Context->Adapter = Adapter;
843
844 switch(GeneralStatus)
845 {
847 DbgPrint("NDIS_STATUS_MEDIA_CONNECT\n");
848
849 if (Adapter->State == LAN_STATE_STARTED)
850 {
852 return;
853 }
854
855 Context->State = LAN_STATE_STARTED;
856 break;
857
859 DbgPrint("NDIS_STATUS_MEDIA_DISCONNECT\n");
860
861 if (Adapter->State == LAN_STATE_STOPPED)
862 {
864 return;
865 }
866
867 Context->State = LAN_STATE_STOPPED;
868 break;
869
871 Adapter->OldState = Adapter->State;
872 Adapter->State = LAN_STATE_RESETTING;
873 /* Nothing else to do here */
875 return;
876
878 Adapter->CompletingReset = TRUE;
879 Context->State = Adapter->OldState;
880 break;
881
882 default:
883 DbgPrint("Unhandled status: %x", GeneralStatus);
885 return;
886 }
887
888 /* Queue the work item */
891}
#define CONTEXT_TAG
Definition: tags.h:43
#define NDIS_STATUS_RESET_START
Definition: ndis.h:354
#define NDIS_STATUS_RESET_END
Definition: ndis.h:355
_In_opt_ NDIS_HANDLE _In_ NDIS_STATUS GeneralStatus
Definition: ndis.h:1556
UCHAR OldState
Definition: lan.h:42
BOOLEAN CompletingReset
Definition: lan.h:43

◆ ProtocolStatusComplete()

VOID NTAPI ProtocolStatusComplete ( NDIS_HANDLE  NdisBindingContext)

Definition at line 893 of file lan.c.

899{
900 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
901}

◆ ProtocolTransferDataComplete()

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

Definition at line 410 of file lan.c.

426{
428
429 TI_DbgPrint(DEBUG_DATALINK,("called\n"));
430
433
434 if( Status != NDIS_STATUS_SUCCESS ) return;
435
436 LanSubmitReceiveWork(BindingContext,
437 Packet,
439 TRUE);
440}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696

◆ ProtocolUnbindAdapter()

VOID NTAPI ProtocolUnbindAdapter ( PNDIS_STATUS  Status,
NDIS_HANDLE  ProtocolBindingContext,
NDIS_HANDLE  UnbindContext 
)

Definition at line 1687 of file lan.c.

1691{
1692 /* We don't pend any unbinding so we can just ignore UnbindContext */
1694}
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT _In_ NDIS_HANDLE _In_ NDIS_HANDLE ProtocolBindingContext
Definition: ndis.h:6015

Referenced by LANRegisterProtocol().

◆ ReadIpConfiguration()

BOOLEAN ReadIpConfiguration ( PIP_INTERFACE  Interface)

Definition at line 568 of file lan.c.

569{
571 HANDLE ParameterHandle;
573 ULONG KeyValueInfoLength;
574 WCHAR Buffer[150];
575 UNICODE_STRING IPAddress = RTL_CONSTANT_STRING(L"IPAddress");
576 UNICODE_STRING Netmask = RTL_CONSTANT_STRING(L"SubnetMask");
577 UNICODE_STRING Gateway = RTL_CONSTANT_STRING(L"DefaultGateway");
578 UNICODE_STRING EnableDhcp = RTL_CONSTANT_STRING(L"EnableDHCP");
579 UNICODE_STRING Prefix = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\");
580 UNICODE_STRING TcpipRegistryPath;
581 UNICODE_STRING RegistryDataU;
582 ANSI_STRING RegistryDataA;
585 IP_ADDRESS DefaultMask, Router;
586
587 AddrInitIPv4(&DefaultMask, 0);
588
589 TcpipRegistryPath.MaximumLength = sizeof(WCHAR) * 150;
590 TcpipRegistryPath.Length = 0;
591 TcpipRegistryPath.Buffer = Buffer;
592
593 /* Build the registry path */
594 RtlAppendUnicodeStringToString(&TcpipRegistryPath, &Prefix);
595 RtlAppendUnicodeStringToString(&TcpipRegistryPath, &Interface->Name);
596
598 &TcpipRegistryPath,
600 0,
601 NULL);
602
603 /* Open a handle to the adapter parameters */
604 Status = ZwOpenKey(&ParameterHandle, KEY_READ, &ObjectAttributes);
605
606 if (!NT_SUCCESS(Status))
607 {
608 return FALSE;
609 }
610 else
611 {
612 KeyValueInfoLength = FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + 16 * sizeof(WCHAR);
613 KeyValueInfo = ExAllocatePoolWithTag(PagedPool,
614 KeyValueInfoLength,
616 if (!KeyValueInfo)
617 {
618 ZwClose(ParameterHandle);
619 return FALSE;
620 }
621
622 /* Read the EnableDHCP entry */
623 Status = ZwQueryValueKey(ParameterHandle,
624 &EnableDhcp,
626 KeyValueInfo,
627 KeyValueInfoLength,
628 &Unused);
629 if (NT_SUCCESS(Status) && KeyValueInfo->DataLength == sizeof(ULONG) && (*(PULONG)KeyValueInfo->Data) == 0)
630 {
631 RegistryDataU.MaximumLength = KeyValueInfoLength - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
632 RegistryDataU.Buffer = (PWCHAR)KeyValueInfo->Data;
633
634 /* Read the IP address */
635 Status = ZwQueryValueKey(ParameterHandle,
636 &IPAddress,
638 KeyValueInfo,
639 KeyValueInfoLength,
640 &Unused);
641 if (NT_SUCCESS(Status))
642 {
643 RegistryDataU.Length = KeyValueInfo->DataLength;
644
645 Status = RtlUnicodeStringToAnsiString(&RegistryDataA,
646 &RegistryDataU,
647 TRUE);
648 if (NT_SUCCESS(Status))
649 {
650 AddrInitIPv4(&Interface->Unicast,
651 inet_addr(RegistryDataA.Buffer));
652 RtlFreeAnsiString(&RegistryDataA);
653 }
654 }
655
656 Status = ZwQueryValueKey(ParameterHandle,
657 &Netmask,
659 KeyValueInfo,
660 KeyValueInfoLength,
661 &Unused);
662 if (NT_SUCCESS(Status))
663 {
664 RegistryDataU.Length = KeyValueInfo->DataLength;
665
666 Status = RtlUnicodeStringToAnsiString(&RegistryDataA,
667 &RegistryDataU,
668 TRUE);
669 if (NT_SUCCESS(Status))
670 {
671 AddrInitIPv4(&Interface->Netmask,
672 inet_addr(RegistryDataA.Buffer));
673 RtlFreeAnsiString(&RegistryDataA);
674 }
675 }
676
677 /* We have to wait until both IP address and subnet mask
678 * are read to add the interface route, but we must do it
679 * before we add the default gateway */
680 if (!AddrIsUnspecified(&Interface->Unicast) &&
681 !AddrIsUnspecified(&Interface->Netmask))
683
684 /* Read default gateway info */
685 Status = ZwQueryValueKey(ParameterHandle,
686 &Gateway,
688 KeyValueInfo,
689 KeyValueInfoLength,
690 &Unused);
691 if (NT_SUCCESS(Status))
692 {
693 RegistryDataU.Length = KeyValueInfo->DataLength;
694
695 Status = RtlUnicodeStringToAnsiString(&RegistryDataA,
696 &RegistryDataU,
697 TRUE);
698 if (NT_SUCCESS(Status))
699 {
700 AddrInitIPv4(&Router, inet_addr(RegistryDataA.Buffer));
701
702 if (!AddrIsUnspecified(&Router))
703 RouterCreateRoute(&DefaultMask, &DefaultMask, &Router, Interface, 1);
704
705 RtlFreeAnsiString(&RegistryDataA);
706 }
707 }
708 }
709
710 ExFreePoolWithTag(KeyValueInfo, KEY_VALUE_TAG);
711 ZwClose(ParameterHandle);
712 }
713
714 return TRUE;
715}
#define AddrInitIPv4(IPAddress, RawAddress)
Definition: address.h:16
BOOLEAN AddrIsUnspecified(PIP_ADDRESS Address)
Definition: address.c:113
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
VOID IPAddInterfaceRoute(PIP_INTERFACE IF)
Definition: ip.c:262
#define KEY_VALUE_TAG
Definition: tags.h:44
#define inet_addr(cp)
Definition: inet.h:98
#define Unused(x)
Definition: atlwin.h:28
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
@ KeyValuePartialInformation
Definition: nt_native.h:1182
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define KEY_READ
Definition: nt_native.h:1023
PFIB_ENTRY RouterCreateRoute(PIP_ADDRESS NetworkAddress, PIP_ADDRESS Netmask, PIP_ADDRESS RouterAddress, PIP_INTERFACE Interface, UINT Metric)
Definition: router.c:421
Definition: ip.h:23
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1630

Referenced by ReconfigureAdapter().

◆ ReadStringFromRegistry()

static NTSTATUS ReadStringFromRegistry ( HANDLE  RegHandle,
PWCHAR  RegistryValue,
PUNICODE_STRING  String 
)
static

Definition at line 1094 of file lan.c.

1096 {
1101 UCHAR buf[1024];
1103
1104 RtlInitUnicodeString(&ValueName, RegistryValue);
1105 Status =
1106 ZwQueryValueKey(RegHandle,
1107 &ValueName,
1110 sizeof(buf),
1111 &ResultLength);
1112
1113 if (!NT_SUCCESS(Status))
1114 return Status;
1115 /* IP address is stored as a REG_MULTI_SZ - we only pay attention to the first one though */
1116 TI_DbgPrint(MIN_TRACE, ("Information DataLength: 0x%x\n", Information->DataLength));
1117
1118 UnicodeString.Buffer = (PWCHAR)&Information->Data;
1119 UnicodeString.Length = Information->DataLength - sizeof(WCHAR);
1120 UnicodeString.MaximumLength = Information->DataLength;
1121
1122 String->Buffer =
1124 UnicodeString.MaximumLength + sizeof(WCHAR), REG_STR_TAG );
1125
1126 if( !String->Buffer ) return STATUS_NO_MEMORY;
1127
1128 String->MaximumLength = UnicodeString.MaximumLength;
1130
1131 return STATUS_SUCCESS;
1132}
#define REG_STR_TAG
Definition: tags.h:46
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by CheckForDeviceDesc().

◆ ReconfigureAdapter()

BOOLEAN ReconfigureAdapter ( PRECONFIGURE_CONTEXT  Context)

Definition at line 717 of file lan.c.

718{
719 PLAN_ADAPTER Adapter = Context->Adapter;
721 //NDIS_STATUS NdisStatus;
722 IP_ADDRESS DefaultMask;
723
724 /* Initialize the default unspecified address (0.0.0.0) */
725 AddrInitIPv4(&DefaultMask, 0);
726 if (Context->State == LAN_STATE_STARTED &&
727 !Context->Adapter->CompletingReset)
728 {
729 /* Read the IP configuration */
731
732 /* Compute the broadcast address */
733 Interface->Broadcast.Type = IP_ADDRESS_V4;
734 Interface->Broadcast.Address.IPv4Address = Interface->Unicast.Address.IPv4Address |
735 ~Interface->Netmask.Address.IPv4Address;
736 }
737 else if (!Context->Adapter->CompletingReset)
738 {
739 /* Clear IP configuration */
740 Interface->Unicast = DefaultMask;
741 Interface->Netmask = DefaultMask;
742 Interface->Broadcast = DefaultMask;
743
744 /* Remove all interface routes */
746
747 /* Destroy all cached neighbors */
749 }
750
751 Context->Adapter->CompletingReset = FALSE;
752
753 /* Update the IP and link status information cached in TCP */
756
757 /* We're done here if the adapter isn't connected */
758 if (Context->State != LAN_STATE_STARTED)
759 {
760 Adapter->State = Context->State;
761 return TRUE;
762 }
763
764 /* NDIS Bug! */
765#if 0
766 /* Get maximum link speed */
767 NdisStatus = NDISCall(Adapter,
770 &Interface->Speed,
771 sizeof(UINT));
772
773 if (!NT_SUCCESS(NdisStatus))
775
776 Adapter->Speed = Interface->Speed * 100L;
777
778 /* Get maximum frame size */
779 NdisStatus = NDISCall(Adapter,
782 &Adapter->MTU,
783 sizeof(UINT));
784 if (NdisStatus != NDIS_STATUS_SUCCESS)
785 return FALSE;
786
787 Interface->MTU = Adapter->MTU;
788
789 /* Get maximum packet size */
790 NdisStatus = NDISCall(Adapter,
793 &Adapter->MaxPacketSize,
794 sizeof(UINT));
795 if (NdisStatus != NDIS_STATUS_SUCCESS)
796 return FALSE;
797#endif
798
799 Adapter->State = Context->State;
800
801 return TRUE;
802}
#define IP_ADDRESS_V4
Definition: ip.h:32
VOID TCPUpdateInterfaceIPInformation(PIP_INTERFACE IF)
Definition: if.c:145
VOID TCPUpdateInterfaceLinkStatus(PIP_INTERFACE IF)
Definition: if.c:81
VOID NBDestroyNeighborsForInterface(PIP_INTERFACE Interface)
Definition: neighbor.c:237
VOID RouterRemoveRoutesForInterface(PIP_INTERFACE Interface)
Definition: router.c:341

Referenced by ReconfigureAdapterWorker().

◆ ReconfigureAdapterWorker()

VOID ReconfigureAdapterWorker ( PVOID  Context)

Definition at line 804 of file lan.c.

805{
806 PRECONFIGURE_CONTEXT ReconfigureContext = Context;
807
808 /* Complete the reconfiguration asynchronously */
809 ReconfigureAdapter(ReconfigureContext);
810
811 /* Free the context */
812 ExFreePool(ReconfigureContext);
813}
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by ProtocolStatus().

◆ TcpipLanGetDwordOid()

NTSTATUS TcpipLanGetDwordOid ( PIP_INTERFACE  Interface,
NDIS_OID  Oid,
PULONG  Result 
)

Definition at line 183 of file lan.c.

186 {
187 /* Get maximum frame size */
188 if( Interface->Context ) {
189 return NDISCall((PLAN_ADAPTER)Interface->Context,
191 Oid,
192 Result,
193 sizeof(ULONG));
194 } else switch( Oid ) { /* Loopback Case */
197 return STATUS_SUCCESS;
200 return STATUS_SUCCESS;
201 default:
203 }
204}
@ NdisHardwareStatusReady
Definition: ntddndis.h:450
#define OID_GEN_HARDWARE_STATUS
Definition: ntddndis.h:234
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

◆ UnbindAdapter()

VOID UnbindAdapter ( PLAN_ADAPTER  Adapter)

Definition at line 1455 of file lan.c.

1462{
1463 TI_DbgPrint(DEBUG_DATALINK, ("Called.\n"));
1464
1465 if (Adapter->State == LAN_STATE_STARTED) {
1466 PIP_INTERFACE IF = Adapter->Context;
1467
1469
1471 }
1472}

Referenced by LANUnregisterAdapter().

Variable Documentation

◆ AdapterListHead

◆ AdapterListLock

KSPIN_LOCK AdapterListLock

Definition at line 39 of file lan.c.

Referenced by DriverEntry(), LANRegisterAdapter(), LANRegisterProtocol(), and LANUnregisterProtocol().

◆ NdisProtocolHandle

◆ ProtocolRegistered

BOOLEAN ProtocolRegistered = FALSE

Definition at line 37 of file lan.c.

Referenced by LANRegisterProtocol(), and LANUnregisterProtocol().

◆ TransferDataCalled

UINT TransferDataCalled = 0

Definition at line 17 of file lan.c.

Referenced by ProtocolReceive(), and ProtocolTransferDataComplete().

◆ TransferDataCompleteCalled

UINT TransferDataCompleteCalled = 0

Definition at line 18 of file lan.c.

Referenced by ProtocolTransferDataComplete().