Revisted the packet capture driver and updated with fixes in latest 3.0a4 release.

Seems I'll need to do some work on the SCM before this'll be running for me.

svn path=/trunk/; revision=3883
This commit is contained in:
Robert Dickenson 2002-12-21 04:46:09 +00:00
parent 5f09dd1402
commit 05a8cab618
24 changed files with 1948 additions and 1614 deletions

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.2 2002/09/24 15:16:46 robd Exp $
# $Id: Makefile,v 1.3 2002/12/21 04:46:09 robd Exp $
PATH_TO_TOP = ../../..
@ -7,7 +7,9 @@ TARGET_TYPE = driver
TARGET_NAME = packet
TARGET_CFLAGS = -DDBG -DWIN_NT_DRIVER -DKQPC_TS
#TARGET_CFLAGS = -DDBG -DWIN_NT_DRIVER -DKQPC_TS -I$(PATH_TO_TOP)/ntoskrnl/include
TARGET_CFLAGS = -DDBG -DWIN_NT_DRIVER -DKQPC_TS -DUSE_KLOCKS -I$(PATH_TO_TOP)/ntoskrnl/include
TARGET_OBJECTS = \
packet.o \

View file

@ -27,6 +27,8 @@
#else
#include <ddk/ntddk.h>
#include <net/ndis.h>
//#define PsGetCurrentProcess() IoGetCurrentProcess()
#define PsGetCurrentThread() ((PETHREAD) (KeGetCurrentThread()))
#endif
#include "debug.h"
@ -66,9 +68,10 @@ NPF_OpenDumpFile(POPEN_INSTANCE Open , PUNICODE_STRING fileName, BOOLEAN Append)
// Insert the correct path prefix.
FullFileNameLength = PathLen + fileName->MaximumLength;
#define NPF_TAG_FILENAME TAG('0', 'D', 'W', 'A')
FullFileName.Buffer = ExAllocatePoolWithTag(NonPagedPool,
FullFileNameLength,
'0DWA');
NPF_TAG_FILENAME);
if (FullFileName.Buffer == NULL) {
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
@ -124,7 +127,7 @@ NPF_OpenDumpFile(POPEN_INSTANCE Open , PUNICODE_STRING fileName, BOOLEAN Append)
IoFileObjectType,
#endif
KernelMode,
&Open->DumpFileObject,
(PVOID)&Open->DumpFileObject,
0);
if ( !NT_SUCCESS( ntStatus ) )
@ -229,7 +232,7 @@ NPF_StartDump(POPEN_INSTANCE Open)
(ACCESS_MASK)0L,
0,
0,
NPF_DumpThread,
(PKSTART_ROUTINE)NPF_DumpThread,
Open);
if ( !NT_SUCCESS( ntStatus ) )
@ -241,15 +244,12 @@ NPF_StartDump(POPEN_INSTANCE Open)
return ntStatus;
}
#ifndef __GNUC__
ntStatus = ObReferenceObjectByHandle(Open->DumpThreadHandle,
THREAD_ALL_ACCESS,
NULL,
KernelMode,
&Open->DumpThreadObject,
0);
#else
#endif
if ( !NT_SUCCESS( ntStatus ) )
{
IF_LOUD(DbgPrint("NPF: Error creating dump thread, status=%x\n", ntStatus);)
@ -261,7 +261,6 @@ NPF_StartDump(POPEN_INSTANCE Open)
return ntStatus;
}
return ntStatus;
}
@ -510,7 +509,12 @@ DbgPrint("3\n");
//-------------------------------------------------------------------
static NTSTATUS PacketDumpCompletion(PDEVICE_OBJECT DeviceObject,
#ifndef __GNUC__
static NTSTATUS
#else
NTSTATUS STDCALL
#endif
PacketDumpCompletion(PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context)
{
@ -583,5 +587,4 @@ VOID NPF_WriteDumpFile(PFILE_OBJECT FileObject,
IoFreeIrp(irp);
return;
}

View file

@ -86,7 +86,8 @@ BPF_filter_function BPFtoX86(struct bpf_insn *prog, UINT nins, INT *mem)
// Allocate the reference table for the jumps
#ifdef NTKERNEL
stream.refs=(UINT *)ExAllocatePoolWithTag(NonPagedPool, (nins + 1)*sizeof(UINT), '0JWA');
#define NPF_TAG_REFTABLE TAG('0', 'J', 'W', 'A')
stream.refs=(UINT *)ExAllocatePoolWithTag(NonPagedPool, (nins + 1)*sizeof(UINT), NPF_TAG_REFTABLE);
#else
stream.refs=(UINT *)malloc((nins + 1)*sizeof(UINT));
#endif
@ -573,7 +574,8 @@ BPF_filter_function BPFtoX86(struct bpf_insn *prog, UINT nins, INT *mem)
if(pass == 2) break;
#ifdef NTKERNEL
stream.ibuf=(CHAR*)ExAllocatePoolWithTag(NonPagedPool, stream.cur_ip, '1JWA');
#define NPF_TAG_STREAMBUF TAG('1', 'J', 'W', 'A')
stream.ibuf=(CHAR*)ExAllocatePoolWithTag(NonPagedPool, stream.cur_ip, NPF_TAG_STREAMBUF);
#else
stream.ibuf=(CHAR*)malloc(stream.cur_ip);
#endif
@ -617,7 +619,8 @@ JIT_BPF_Filter* BPF_jitter(struct bpf_insn *fp, INT nins)
// Allocate the filter structure
#ifdef NTKERNEL
Filter=(struct JIT_BPF_Filter*)ExAllocatePoolWithTag(NonPagedPool, sizeof(struct JIT_BPF_Filter), '2JWA');
#define NPF_TAG_FILTSTRUCT TAG('2', 'J', 'W', 'A')
Filter=(struct JIT_BPF_Filter*)ExAllocatePoolWithTag(NonPagedPool, sizeof(struct JIT_BPF_Filter), NPF_TAG_FILTSTRUCT);
#else
Filter=(struct JIT_BPF_Filter*)malloc(sizeof(struct JIT_BPF_Filter));
#endif
@ -628,7 +631,8 @@ JIT_BPF_Filter* BPF_jitter(struct bpf_insn *fp, INT nins)
// Allocate the filter's memory
#ifdef NTKERNEL
Filter->mem=(INT*)ExAllocatePoolWithTag(NonPagedPool, BPF_MEMWORDS*sizeof(INT), '3JWA');
#define NPF_TAG_FILTMEM TAG('3', 'J', 'W', 'A')
Filter->mem=(INT*)ExAllocatePoolWithTag(NonPagedPool, BPF_MEMWORDS*sizeof(INT), NPF_TAG_FILTMEM);
#else
Filter->mem=(INT*)malloc(BPF_MEMWORDS*sizeof(INT));
#endif

View file

@ -373,7 +373,7 @@ JIT_BPF_Filter* BPF_jitter(struct bpf_insn *fp, INT nins);
through the instruction macros defined in jitter.h it is able to create an function directly executable
by NPF.
*/
BPF_filter_function BPFtoX86(struct bpf_insn *prog, UINT nins, INT *mem);
BPF_filter_function BPFtoX86(struct bpf_insn *ins, UINT nins, INT *mem);
/*!
\brief Deletes a filtering function that was previously created by BPF_jitter().
\param Filter The filter to destroy.

View file

@ -22,6 +22,7 @@
#include "tme.h"
#include "memory_t.h"
#ifdef _USE_SW_FUNCS_
int32 SW_LONG_AT(void *b, uint32 c)
{
@ -62,4 +63,6 @@ VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
}
#endif /*_USE_SW_FUNCS_*/
void assert(void* assert, const char* file, int line, void* msg) { };

View file

@ -47,14 +47,19 @@ typedef struct __MEM_TYPE
#define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
#ifdef __GNUC__
#define __inline inline
#define _USE_SW_FUNCS_
#endif
int32 SW_LONG_AT(void *b, uint32 c);
uint32 SW_ULONG_AT(void *b, uint32 c);
int16 SW_SHORT_AT(void *b, uint32 os);
uint16 SW_USHORT_AT(void *b, uint32 os);
VOID SW_ULONG_ASSIGN(void *dst, uint32 src);
#ifdef _USE_SW_FUNCS_
#else /* __GNUC__ */
inline int32 SW_LONG_AT(void *b, uint32 c);
inline uint32 SW_ULONG_AT(void *b, uint32 c);
inline int16 SW_SHORT_AT(void *b, uint32 os);
inline uint16 SW_USHORT_AT(void *b, uint32 os);
inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src);
#else /*_USE_SW_FUNCS_*/
__inline int32 SW_LONG_AT(void *b, uint32 c)
{
@ -95,7 +100,7 @@ __inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
}
#endif /* __GNUC__ */
#endif /*_USE_SW_FUNCS_*/
#ifdef WIN_NT_DRIVER

View file

@ -67,8 +67,7 @@ NDIS_SPIN_LOCK Opened_Instances_Lock;
//-------------------------------------------------------------------
NTSTATUS
NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
NTSTATUS NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PDEVICE_EXTENSION DeviceExtension;
@ -84,7 +83,6 @@ NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
PLIST_ENTRY PacketListEntry;
PCHAR EvName;
IF_LOUD(DbgPrint("NPF: OpenAdapter\n");)
DeviceExtension = DeviceObject->DeviceExtension;
@ -93,7 +91,8 @@ NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
IrpSp = IoGetCurrentIrpStackLocation(Irp);
// allocate some memory for the open structure
Open=ExAllocatePoolWithTag(NonPagedPool, sizeof(OPEN_INSTANCE), '0OWA');
#define NPF_TAG_OPENSTRUCT TAG('0', 'O', 'W', 'A')
Open=ExAllocatePoolWithTag(NonPagedPool, sizeof(OPEN_INSTANCE), NPF_TAG_OPENSTRUCT);
if (Open==NULL) {
@ -109,7 +108,8 @@ NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
);
EvName=ExAllocatePoolWithTag(NonPagedPool, sizeof(L"\\BaseNamedObjects\\NPF0000000000"), '1OWA');
#define NPF_TAG_EVNAME TAG('1', 'O', 'W', 'A')
EvName=ExAllocatePoolWithTag(NonPagedPool, sizeof(L"\\BaseNamedObjects\\NPF0000000000"), NPF_TAG_EVNAME);
if (EvName==NULL) {
// no memory
@ -187,7 +187,8 @@ NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
InitializeListHead(&Open->RequestList);
// Initializes the extended memory of the NPF machine
Open->mem_ex.buffer = ExAllocatePoolWithTag(NonPagedPool, DEFAULT_MEM_EX_SIZE, '2OWA');
#define NPF_TAG_MACHINE TAG('2', 'O', 'W', 'A')
Open->mem_ex.buffer = ExAllocatePoolWithTag(NonPagedPool, DEFAULT_MEM_EX_SIZE, NPF_TAG_MACHINE);
if((Open->mem_ex.buffer) == NULL)
{
// no memory
@ -208,7 +209,7 @@ NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Open->Buffer = NULL;
Open->Bhead = 0;
Open->Btail = 0;
Open->BLastByte = 0;
(INT)Open->BLastByte = -1;
Open->Dropped = 0; //reset the dropped packets counter
Open->Received = 0; //reset the received packets counter
Open->Accepted = 0; //reset the accepted packets counter
@ -225,6 +226,7 @@ NPF_Open(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Open->DumpFileHandle = NULL;
Open->tme.active = TME_NONE_ACTIVE;
Open->DumpLimitReached = FALSE;
Open->MaxFrameSize = 0;
//allocate the spinlock for the statistic counters
NdisAllocateSpinLock(&Open->CountersLock);
@ -284,6 +286,10 @@ VOID NPF_OpenAdapterComplete(
PIRP Irp;
POPEN_INSTANCE Open;
PLIST_ENTRY RequestListEntry;
PINTERNAL_REQUEST MaxSizeReq;
NDIS_STATUS ReqStatus;
IF_LOUD(DbgPrint("NPF: OpenAdapterComplete\n");)
@ -306,6 +312,9 @@ VOID NPF_OpenAdapterComplete(
ExFreePool(Open->ReadEventName.Buffer);
ZwClose(Open->ReadEventHandle);
ExFreePool(Open);
}
else {
@ -318,6 +327,47 @@ VOID NPF_OpenAdapterComplete(
// Get the absolute value of the system boot time.
// This is used for timestamp conversion.
TIME_SYNCHRONIZE(&G_Start_Time);
// Extract a request from the list of free ones
RequestListEntry=ExInterlockedRemoveHeadList(&Open->RequestList, &Open->RequestSpinLock);
if (RequestListEntry == NULL)
{
Open->MaxFrameSize = 1514; // Assume Ethernet
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return;
}
MaxSizeReq = CONTAINING_RECORD(RequestListEntry, INTERNAL_REQUEST, ListElement);
MaxSizeReq->Irp = Irp;
MaxSizeReq->Internal = TRUE;
MaxSizeReq->Request.RequestType = NdisRequestQueryInformation;
MaxSizeReq->Request.DATA.QUERY_INFORMATION.Oid = OID_GEN_MAXIMUM_TOTAL_SIZE;
MaxSizeReq->Request.DATA.QUERY_INFORMATION.InformationBuffer = &Open->MaxFrameSize;
MaxSizeReq->Request.DATA.QUERY_INFORMATION.InformationBufferLength = 4;
// submit the request
NdisRequest(
&ReqStatus,
Open->AdapterHandle,
&MaxSizeReq->Request);
if (ReqStatus != NDIS_STATUS_PENDING) {
NPF_RequestComplete(Open, &MaxSizeReq->Request, ReqStatus);
}
return;
}
Irp->IoStatus.Status = Status;
@ -397,7 +447,6 @@ NPF_Close(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
// If this instance is in dump mode, complete the dump and close the file
if((Open->mode & MODE_DUMP) && Open->DumpFileHandle != NULL){
#ifndef __GNUC__
NTSTATUS wres;
ThreadDelay.QuadPart = -50000000;
@ -413,7 +462,6 @@ NPF_Close(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
// Flush and close the dump file
NPF_CloseDumpFile(Open);
#endif
}
// Destroy the read Event

View file

@ -82,6 +82,9 @@ extern NDIS_SPIN_LOCK Opened_Instances_Lock;
// Packet Driver's entry routine.
//
NTSTATUS
#ifdef __GNUC__
STDCALL
#endif
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
@ -111,7 +114,7 @@ DriverEntry(
return STATUS_IMAGE_MP_UP_MISMATCH;
}
IF_LOUD(DbgPrint("\n\nPacket: DriverEntry\n");)
IF_LOUD(DbgPrint("Packet: DriverEntry\n");)
RtlZeroMemory(&ProtocolChar,sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
@ -123,17 +126,24 @@ DriverEntry(
ProtocolChar.MinorNdisVersion = 0;
#ifndef __GNUC__
ProtocolChar.Reserved = 0;
#else
ProtocolChar.u1.Reserved = 0;
#endif
ProtocolChar.OpenAdapterCompleteHandler = NPF_OpenAdapterComplete;
ProtocolChar.CloseAdapterCompleteHandler = NPF_CloseAdapterComplete;
#ifndef __GNUC__
ProtocolChar.SendCompleteHandler = NPF_SendComplete;
ProtocolChar.TransferDataCompleteHandler = NPF_TransferDataComplete;
#else
ProtocolChar.u2.SendCompleteHandler = NPF_SendComplete;
ProtocolChar.u3.TransferDataCompleteHandler = NPF_TransferDataComplete;
#endif
ProtocolChar.ResetCompleteHandler = NPF_ResetComplete;
ProtocolChar.RequestCompleteHandler = NPF_RequestComplete;
#ifndef __GNUC__
ProtocolChar.ReceiveHandler = NPF_tap;
#else
ProtocolChar.u4.ReceiveHandler = NPF_tap;
#endif
ProtocolChar.ReceiveCompleteHandler = NPF_ReceiveComplete;
ProtocolChar.StatusHandler = NPF_Status;
@ -170,6 +180,7 @@ DriverEntry(
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NPF_IoControl;
DriverObject->DriverUnload = NPF_Unload;
/*
// Get the name of the Packet driver and the name of the NIC driver
// to bind to from the registry
Status=NPF_ReadRegistry(
@ -181,7 +192,7 @@ DriverEntry(
if (Status != STATUS_SUCCESS) {
IF_LOUD(DbgPrint("Trying dynamic binding\n");)
*/
bindP = getAdaptersList();
if (bindP == NULL) {
@ -198,7 +209,6 @@ DriverEntry(
bindT = (WCHAR*)(tcpBindingsP->Data);
} else {
bindT = bindP;
}
for (; *bindT != UNICODE_NULL; bindT += (macName.Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR)) {
@ -207,13 +217,10 @@ DriverEntry(
}
return STATUS_SUCCESS;
/*
}
BindStringSave = BindString;
ExportStringSave = ExportString;
//
// create a device object for each entry
//
@ -223,23 +230,16 @@ DriverEntry(
//
RtlInitUnicodeString(
&MacDriverName,
BindString
);
BindString);
RtlInitUnicodeString(
&UnicodeDeviceName,
ExportString
);
ExportString);
//
// Advance to the next string of the MULTI_SZ string
//
BindString += (MacDriverName.Length+sizeof(UNICODE_NULL))/sizeof(WCHAR);
ExportString += (UnicodeDeviceName.Length+sizeof(UNICODE_NULL))/sizeof(WCHAR);
IF_LOUD(DbgPrint("NPF: DeviceName=%ws MacName=%ws\n",UnicodeDeviceName.Buffer,MacDriverName.Buffer);)
//
// Create the device object
//
@ -250,40 +250,25 @@ DriverEntry(
FILE_DEVICE_PROTOCOL,
0,
FALSE,
&DeviceObject
);
&DeviceObject);
if (Status != STATUS_SUCCESS) {
IF_LOUD(DbgPrint("NPF: IoCreateDevice() failed:\n");)
break;
}
DevicesCreated++;
DeviceObject->Flags |= DO_DIRECT_IO;
DeviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
DeviceExtension->DeviceObject = DeviceObject;
//
// Save the the name of the MAC driver to open in the Device Extension
//
DeviceExtension->AdapterName=MacDriverName;
if (DevicesCreated == 1) {
DeviceExtension->BindString = NULL;
DeviceExtension->ExportString = NULL;
}
DeviceExtension->NdisProtocolHandle=NdisProtocolHandle;
}
if (DevicesCreated > 0) {
//
// Managed to create at least one device.
@ -291,11 +276,9 @@ DriverEntry(
IF_LOUD(DbgPrint("NPF: Managed to create at least one device.\n");)
return STATUS_SUCCESS;
}
ExFreePool(BindStringSave);
ExFreePool(ExportStringSave);
*/
RegistryError:
IF_LOUD(DbgPrint("NPF: RegistryError: calling NdisDeregisterProtocol()\n");)
@ -320,7 +303,8 @@ PWCHAR getAdaptersList(void)
HANDLE keyHandle;
UINT BufPos=0;
PWCHAR DeviceNames = (PWCHAR) ExAllocatePoolWithTag(PagedPool, 4096, '0PWA');
#define NPF_TAG_DEVICENAME TAG('0', 'P', 'W', 'A')
PWCHAR DeviceNames = (PWCHAR) ExAllocatePoolWithTag(PagedPool, 4096, NPF_TAG_DEVICENAME);
if (DeviceNames == NULL) {
IF_LOUD(DbgPrint("Unable the allocate the buffer for the list of the network adapters\n");)
@ -331,7 +315,10 @@ PWCHAR getAdaptersList(void)
OBJ_CASE_INSENSITIVE, NULL, NULL);
status = ZwOpenKey(&keyHandle, KEY_READ, &objAttrs);
if (!NT_SUCCESS(status)) {
IF_LOUD(DbgPrint("\n\nStatus of %x opening %ws\n", status, tcpLinkageKeyName.Buffer);)
//IF_LOUD(DbgPrint("Status of %x opening %ws\n", status, tcpLinkageKeyName.Buffer);)
IF_LOUD(DbgPrint("Status of %x opening %ws\n", status, AdapterListKey.Buffer);)
} else { //OK
ULONG resultLength;
KEY_VALUE_PARTIAL_INFORMATION valueInfo;
@ -389,7 +376,8 @@ PWCHAR getAdaptersList(void)
IF_LOUD(DbgPrint("\n\nStatus of %x querying key value for size\n", status);)
} else { // We know how big it needs to be.
ULONG valueInfoLength = valueInfo.DataLength + FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[0]);
PKEY_VALUE_PARTIAL_INFORMATION valueInfoP = (PKEY_VALUE_PARTIAL_INFORMATION) ExAllocatePoolWithTag(PagedPool, valueInfoLength, '1PWA');
#define NPF_TAG_KEYVALUE TAG('1', 'P', 'W', 'A')
PKEY_VALUE_PARTIAL_INFORMATION valueInfoP = (PKEY_VALUE_PARTIAL_INFORMATION) ExAllocatePoolWithTag(PagedPool, valueInfoLength, NPF_TAG_KEYVALUE);
if (valueInfoP != NULL) {
status = ZwQueryValueKey(ExportKeyHandle, &FinalExportKey,
KeyValuePartialInformation,
@ -458,8 +446,9 @@ PKEY_VALUE_PARTIAL_INFORMATION getTcpBindings(void)
IF_LOUD(DbgPrint("\n\nStatus of %x querying key value for size\n", status);)
} else { // We know how big it needs to be.
ULONG valueInfoLength = valueInfo.DataLength + FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data[0]);
#define NPF_TAG_KEYVALUE2 TAG('2', 'P', 'W', 'A')
PKEY_VALUE_PARTIAL_INFORMATION valueInfoP =
(PKEY_VALUE_PARTIAL_INFORMATION)ExAllocatePoolWithTag(PagedPool, valueInfoLength, '2PWA');
(PKEY_VALUE_PARTIAL_INFORMATION)ExAllocatePoolWithTag(PagedPool, valueInfoLength, NPF_TAG_KEYVALUE2);
if (valueInfoP != NULL) {
status = ZwQueryValueKey(keyHandle, &bindValueName,
@ -509,51 +498,97 @@ BOOLEAN createDevice(IN OUT PDRIVER_OBJECT adriverObjectP,
NTSTATUS status;
PDEVICE_OBJECT devObjP;
UNICODE_STRING deviceName;
BOOLEAN result = FALSE;
UNICODE_STRING deviceSymLink;
IF_LOUD(DbgPrint("\n\ncreateDevice for MAC %ws\n", amacNameP->Buffer);)
IF_LOUD(DbgPrint("\n\ncreateDevice for MAC %ws\n", amacNameP->Buffer););
if (RtlCompareMemory(amacNameP->Buffer, devicePrefix.Buffer,
devicePrefix.Length) < devicePrefix.Length) {
return result;
return FALSE;
}
deviceName.Length = 0;
deviceName.MaximumLength = (USHORT)(amacNameP->Length + NPF_Prefix.Length + sizeof(UNICODE_NULL));
deviceName.Buffer = ExAllocatePoolWithTag(PagedPool, deviceName.MaximumLength, '3PWA');
#define NPF_TAG_DEVICENAMEBUF TAG('3', 'P', 'W', 'A')
deviceName.Buffer = ExAllocatePoolWithTag(PagedPool, deviceName.MaximumLength, NPF_TAG_DEVICENAMEBUF);
if (deviceName.Buffer == NULL)
return FALSE;
deviceSymLink.Length = 0;
deviceSymLink.MaximumLength =(USHORT)(amacNameP->Length-devicePrefix.Length
+ symbolicLinkPrefix.Length
+ NPF_Prefix.Length
+ sizeof(UNICODE_NULL));
#define NPF_TAG_SYMLINKBUF TAG('3', 'P', 'W', 'A')
deviceSymLink.Buffer = ExAllocatePoolWithTag(NonPagedPool, deviceSymLink.MaximumLength, NPF_TAG_SYMLINKBUF);
if (deviceSymLink.Buffer == NULL)
{
ExFreePool(deviceName.Buffer);
return FALSE;
}
if (deviceName.Buffer != NULL) {
RtlAppendUnicodeStringToString(&deviceName, &devicePrefix);
RtlAppendUnicodeStringToString(&deviceName, &NPF_Prefix);
RtlAppendUnicodeToString(&deviceName, amacNameP->Buffer +
devicePrefix.Length / sizeof(WCHAR));
IF_LOUD(DbgPrint("\n\nDevice name: %ws\n", deviceName.Buffer);)
RtlAppendUnicodeStringToString(&deviceSymLink, &symbolicLinkPrefix);
RtlAppendUnicodeStringToString(&deviceSymLink, &NPF_Prefix);
RtlAppendUnicodeToString(&deviceSymLink, amacNameP->Buffer +
devicePrefix.Length / sizeof(WCHAR));
status = IoCreateDevice(adriverObjectP, sizeof(PDEVICE_EXTENSION),
&deviceName, FILE_DEVICE_TRANSPORT, 0, FALSE,
IF_LOUD(DbgPrint("Creating device name: %ws\n", deviceName.Buffer);)
status = IoCreateDevice(adriverObjectP,
sizeof(PDEVICE_EXTENSION),
&deviceName,
FILE_DEVICE_TRANSPORT,
0,
FALSE,
&devObjP);
if (NT_SUCCESS(status)) {
PDEVICE_EXTENSION devExtP = (PDEVICE_EXTENSION)devObjP->DeviceExtension;
IF_LOUD(DbgPrint("\n\nDevice created succesfully\n");)
IF_LOUD(DbgPrint("Device created successfully\n"););
devObjP->Flags |= DO_DIRECT_IO;
devExtP->DeviceObject = devObjP;
RtlInitUnicodeString(&devExtP->AdapterName,amacNameP->Buffer);
devExtP->BindString = NULL;
devExtP->ExportString = NULL;
devExtP->NdisProtocolHandle=aProtoHandle;
}
IF_LOUD(DbgPrint("Trying to create SymLink %ws\n",deviceSymLink.Buffer););
else IF_LOUD(DbgPrint("\n\nIoCreateDevice status = %x\n", status););
if (IoCreateSymbolicLink(&deviceSymLink,&deviceName) != STATUS_SUCCESS) {
IF_LOUD(DbgPrint("\n\nError creating SymLink %ws\nn", deviceSymLink.Buffer););
ExFreePool(deviceName.Buffer);
ExFreePool(deviceSymLink.Buffer);
devExtP->ExportString = NULL;
return FALSE;
}
return result;
IF_LOUD(DbgPrint("SymLink %ws successfully created.\n\n", deviceSymLink.Buffer););
devExtP->ExportString = deviceSymLink.Buffer;
ExFreePool(deviceName.Buffer);
return TRUE;
}
else
{
IF_LOUD(DbgPrint("\n\nIoCreateDevice status = %x\n", status););
ExFreePool(deviceName.Buffer);
ExFreePool(deviceSymLink.Buffer);
return FALSE;
}
}
//-------------------------------------------------------------------
@ -561,7 +596,6 @@ BOOLEAN createDevice(IN OUT PDRIVER_OBJECT adriverObjectP,
VOID
NPF_Unload(IN PDRIVER_OBJECT DriverObject)
{
PDEVICE_OBJECT DeviceObject;
PDEVICE_OBJECT OldDeviceObject;
PDEVICE_EXTENSION DeviceExtension;
@ -569,27 +603,38 @@ NPF_Unload(IN PDRIVER_OBJECT DriverObject)
NDIS_HANDLE NdisProtocolHandle;
NDIS_STATUS Status;
IF_LOUD(DbgPrint("NPF: Unload\n");)
NDIS_STRING SymLink;
IF_LOUD(DbgPrint("NPF: Unload\n"););
DeviceObject = DriverObject->DeviceObject;
while (DeviceObject != NULL) {
DeviceExtension = DeviceObject->DeviceExtension;
NdisProtocolHandle=DeviceExtension->NdisProtocolHandle;
OldDeviceObject=DeviceObject;
DeviceObject=DeviceObject->NextDevice;
DeviceExtension = OldDeviceObject->DeviceExtension;
NdisProtocolHandle=DeviceExtension->NdisProtocolHandle;
IF_LOUD(DbgPrint("Deleting Adapter %ws, Protocol Handle=%x, Device Obj=%x (%x)\n",
DeviceExtension->AdapterName.Buffer,
NdisProtocolHandle,
DeviceObject,
OldDeviceObject);)
OldDeviceObject););
if (DeviceExtension->ExportString)
{
RtlInitUnicodeString(&SymLink , DeviceExtension->ExportString);
IF_LOUD(DbgPrint("Deleting SymLink at %p\n", SymLink.Buffer););
IoDeleteSymbolicLink(&SymLink);
ExFreePool(DeviceExtension->ExportString);
}
IoDeleteDevice(OldDeviceObject);
}
NdisDeregisterProtocol(
@ -599,7 +644,6 @@ NPF_Unload(IN PDRIVER_OBJECT DriverObject)
// Free the adapters names
ExFreePool( bindP );
}
//-------------------------------------------------------------------
@ -754,7 +798,8 @@ NPF_IoControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
// Allocate the memory to contain the new filter program
// We could need the original BPF binary if we are forced to use bpf_filter_with_2_buffers()
TmpBPFProgram=(PUCHAR)ExAllocatePoolWithTag(NonPagedPool, cnt*sizeof(struct bpf_insn), '4PWA');
#define NPF_TAG_BPFPROG TAG('4', 'P', 'W', 'A')
TmpBPFProgram=(PUCHAR)ExAllocatePoolWithTag(NonPagedPool, cnt*sizeof(struct bpf_insn), NPF_TAG_BPFPROG);
if (TmpBPFProgram==NULL){
IF_LOUD(DbgPrint("Error - No memory for filter");)
// no memory
@ -766,11 +811,8 @@ NPF_IoControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
Open->bpfprogram=TmpBPFProgram;
// Create the new JIT filter function
if(!IsExtendedFilter)
if((Open->Filter=BPF_jitter((struct bpf_insn*)Open->bpfprogram,cnt))
== NULL)
{
if((Open->Filter=BPF_jitter((struct bpf_insn*)Open->bpfprogram,cnt)) == NULL) {
IF_LOUD(DbgPrint("Error jittering filter");)
EXIT_FAILURE(0);
}
@ -778,9 +820,10 @@ NPF_IoControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
//return
Open->Bhead = 0;
Open->Btail = 0;
Open->BLastByte = 0;
(INT)Open->BLastByte = -1;
Open->Received = 0;
Open->Dropped = 0;
Open->Accepted = 0;
EXIT_SUCCESS(IrpSp->Parameters.DeviceIoControl.InputBufferLength);
@ -839,7 +882,8 @@ NPF_IoControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
}
// Allocate the buffer that will contain the string
DumpNameBuff=ExAllocatePoolWithTag(NonPagedPool, IrpSp->Parameters.DeviceIoControl.InputBufferLength, '5PWA');
#define NPF_TAG_DUMPNAMEBUF TAG('5', 'P', 'W', 'A')
DumpNameBuff=ExAllocatePoolWithTag(NonPagedPool, IrpSp->Parameters.DeviceIoControl.InputBufferLength, NPF_TAG_DUMPNAMEBUF);
if(DumpNameBuff==NULL || Open->DumpFileName.Buffer!=NULL){
IF_LOUD(DbgPrint("NPF: unable to allocate the dump filename: not enough memory or name already set\n");)
EXIT_FAILURE(0);
@ -908,7 +952,8 @@ NPF_IoControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
}
// Allocate the new buffer
if(dim!=0){
tpointer = ExAllocatePoolWithTag(NonPagedPool, dim, '6PWA');
#define NPF_TAG_TPOINTER TAG('6', 'P', 'W', 'A')
tpointer = ExAllocatePoolWithTag(NonPagedPool, dim, NPF_TAG_TPOINTER);
if (tpointer==NULL) {
// no memory
Open->BufSize = 0;
@ -922,7 +967,7 @@ NPF_IoControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
Open->Buffer = tpointer;
Open->Bhead = 0;
Open->Btail = 0;
Open->BLastByte = 0;
(INT)Open->BLastByte = -1;
Open->BufSize = (UINT)dim;
EXIT_SUCCESS(dim);
@ -990,6 +1035,8 @@ NPF_IoControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
pRequest=CONTAINING_RECORD(RequestListEntry,INTERNAL_REQUEST,ListElement);
pRequest->Irp=Irp;
pRequest->Internal = FALSE;
//
// See if it is an Ndis request
@ -1094,11 +1141,18 @@ NPF_RequestComplete(
pRequest=CONTAINING_RECORD(NdisRequest,INTERNAL_REQUEST,Request);
Irp=pRequest->Irp;
if(Irp == NULL){
if(pRequest->Internal == TRUE){
// Put the request in the list of the free ones
ExInterlockedInsertTailList(&Open->RequestList, &pRequest->ListElement, &Open->RequestSpinLock);
if(Status != NDIS_STATUS_SUCCESS)
Open->MaxFrameSize = 1514; // Assume Ethernet
// We always return success, because the adapter has been already opened
Irp->IoStatus.Status = NDIS_STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return;
}
@ -1138,7 +1192,7 @@ NPF_RequestComplete(
IoCompleteRequest(Irp, IO_NO_INCREMENT);
// Unlock the IOCTL call
// Unlock the caller
NdisSetEvent(&Open->IOEvent);
return;
@ -1200,7 +1254,8 @@ NPF_ReadRegistry(
PWCHAR Path;
Path=ExAllocatePoolWithTag(PagedPool, RegistryPath->Length+sizeof(WCHAR), '7PWA');
#define NPF_TAG_PATH TAG('7', 'P', 'W', 'A')
Path=ExAllocatePoolWithTag(PagedPool, RegistryPath->Length+sizeof(WCHAR), NPF_TAG_PATH);
if (Path == NULL) {
IF_LOUD(DbgPrint("\nPacketReadRegistry: returing STATUS_INSUFFICIENT_RESOURCES\n");)
@ -1311,7 +1366,8 @@ NPF_QueryRegistryRoutine(
}
Buffer=ExAllocatePoolWithTag(NonPagedPool, ValueLength, '8PWA');
#define NPF_TAG_REGBUF TAG('8', 'P', 'W', 'A')
Buffer=ExAllocatePoolWithTag(NonPagedPool, ValueLength, NPF_TAG_REGBUF);
if (Buffer==NULL) {

View file

@ -32,9 +32,13 @@
#define NTKERNEL ///< Forces the compilation of the jitter with kernel calls
#ifdef __GNUC__
#undef EXIT_SUCCESS
#undef EXIT_FAILURE
#define UNICODE_NULL ((WCHAR)0) // winnt
#include "win_bpf.h"
#include <internal/ps.h>
#endif
#include "jitter.h"
#include "tme.h"
@ -44,6 +48,8 @@
#define Packet_ALIGNMENT sizeof(int) ///< Alignment macro. Defines the alignment size.
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1)) ///< Alignment macro. Rounds up to the next
///< even multiple of Packet_ALIGNMENT.
/***************************/
/* IOCTLs */
/***************************/
@ -231,6 +237,7 @@ struct sf_pkthdr {
typedef struct _INTERNAL_REQUEST {
LIST_ENTRY ListElement; ///< Used to handle lists of requests.
PIRP Irp; ///< Irp that performed the request
BOOLEAN Internal; ///< True if the request is for internal use of npf.sys. False if the request is performed by the user through an IOCTL.
NDIS_REQUEST Request; ///< The structure with the actual request, that will be passed to NdisRequest().
} INTERNAL_REQUEST, *PINTERNAL_REQUEST;
@ -257,10 +264,8 @@ typedef struct _PACKET_RESERVED {
Structure containing some data relative to every adapter on which NPF is bound.
*/
typedef struct _DEVICE_EXTENSION {
PDEVICE_OBJECT DeviceObject; ///< Adapter's device.
NDIS_HANDLE NdisProtocolHandle; ///< NDIS handle of NPF.
NDIS_STRING AdapterName; ///< Name of the adapter.
PWSTR BindString; ///< Original device name of the adapter.
PWSTR ExportString; ///< Name of the exported device, i.e. name that the applications will use
///< to open this adapter through WinPcap.
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
@ -337,7 +342,7 @@ typedef struct _OPEN_INSTANCE
///< FALSE if a Plug and Play adapter has been removed or disabled by the user.
HANDLE DumpFileHandle; ///< Handle of the file used in dump mode.
PFILE_OBJECT DumpFileObject; ///< Pointer to the object of the file used in dump mode.
// PKTHREAD DumpThreadObject; ///< Pointer to the object of the thread used in dump mode.
PKTHREAD DumpThreadObject; ///< Pointer to the object of the thread used in dump mode.
HANDLE DumpThreadHandle; ///< Handle of the thread created by dump mode to asynchronously move the buffer to disk.
NDIS_EVENT DumpEvent; ///< Event used to synchronize the dump thread with the tap when the instance is in dump mode.
LARGE_INTEGER DumpOffset; ///< Current offset in the dump file.
@ -352,28 +357,26 @@ typedef struct _OPEN_INSTANCE
MEM_TYPE mem_ex; ///< Memory used by the TME virtual co-processor
TME_CORE tme; ///< Data structure containing the virtualization of the TME co-processor
NDIS_SPIN_LOCK machine_lock; ///< SpinLock that protects the mem_ex buffer
UINT MaxFrameSize; ///< Maximum frame size that the underlying MAC acceptes. Used to perform a check on the
///< size of the frames sent with NPF_Write() or NPF_BufferedWrite().
} OPEN_INSTANCE, *POPEN_INSTANCE;
#define TRANSMIT_PACKETS 256 ///< Maximum number of packets in the transmit packet pool. This value is an upper bound to the number
///< of packets that can be transmitted at the same time or with a single call to NdisSendPackets.
#ifdef __GNUC__
#undef EXIT_SUCCESS
#undef EXIT_FAILURE
#endif
/// Macro used in the I/O routines to return the control to user-mode with a success status.
#define EXIT_SUCCESS(quantity) Irp->IoStatus.Information=quantity;\
Irp->IoStatus.Status = STATUS_SUCCESS;\
IoCompleteRequest(Irp, IO_NO_INCREMENT);\
return STATUS_SUCCESS;\
Irp->IoStatus.Status = STATUS_SUCCESS;\
IoCompleteRequest(Irp, IO_NO_INCREMENT);\
return STATUS_SUCCESS;\
/// Macro used in the I/O routines to return the control to user-mode with a failure status.
#define EXIT_FAILURE(quantity) Irp->IoStatus.Information=quantity;\
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;\
IoCompleteRequest(Irp, IO_NO_INCREMENT);\
return STATUS_UNSUCCESSFUL;\
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;\
IoCompleteRequest(Irp, IO_NO_INCREMENT);\
return STATUS_UNSUCCESSFUL;\
/**
* @}
@ -400,11 +403,11 @@ return STATUS_UNSUCCESSFUL;\
performing all the allocations and the setup. In particular, DriverEntry registers all the driver's I/O
callbacks, creates the devices, defines NPF as a protocol inside NDIS.
*/
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
);
//NTSTATUS
//DriverEntry(
// IN PDRIVER_OBJECT DriverObject,
// IN PUNICODE_STRING RegistryPath
// );
/*!
\brief Returns the list of the MACs available on the system.
@ -954,4 +957,3 @@ NDIS_STATUS NPF_PowerChange(IN NDIS_HANDLE ProtocolBindingContext, IN PNET_PNP_E
*/
#endif /*main ifndef/define*/

View file

@ -27,6 +27,16 @@
#else
#include <ddk/ntddk.h>
#include <net/ndis.h>
#define NdisMoveMappedMemory(Destination,Source,Length) RtlCopyMemory(Destination,Source,Length)
#define NdisZeroMappedMemory(Destination,Length) RtlZeroMemory(Destination,Length)
#define NdisReinitializePacket(Packet) \
{ \
(Packet)->Private.Head = (PNDIS_BUFFER)NULL; \
(Packet)->Private.ValidCounts = FALSE; \
}
#endif
#include "debug.h"
@ -92,20 +102,19 @@ NPF_Read(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
POPEN_INSTANCE Open;
PIO_STACK_LOCATION IrpSp;
PUCHAR packp;
UINT i;
ULONG Input_Buffer_Length;
UINT Thead;
UINT Ttail;
UINT TLastByte;
PUCHAR CurrBuff;
UINT cplen;
UINT CpStart;
LARGE_INTEGER CapTime;
LARGE_INTEGER TimeFreq;
struct bpf_hdr *header;
KIRQL Irql;
PUCHAR UserPointer;
ULONG bytecopy;
UINT SizeToCopy;
UINT PktLen;
IF_LOUD(DbgPrint("NPF: Read\n");)
@ -255,7 +264,7 @@ NPF_Read(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
NdisReleaseSpinLock( &Open->BufLock );
Input_Buffer_Length=IrpSp->Parameters.Read.Length;
packp=(PUCHAR)MmGetMdlVirtualAddress(Irp->MdlAddress);
packp=(PUCHAR)MmGetSystemAddressForMdl(Irp->MdlAddress);
//
@ -283,47 +292,38 @@ NPF_Read(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)
}
//the buffer must be scannned to determine the number of bytes to copy
CpStart=Thead;
i=0;
SizeToCopy = 0;
while(TRUE){
if(Thead == Ttail)break;
if(Thead + SizeToCopy == Ttail)
break;
if(Thead == TLastByte){
// Copy the portion between thead and TLastByte
PacketMoveMem(packp,CurrBuff+CpStart,Thead-CpStart,&(Open->Bhead));
packp+=(Thead-CpStart);
if(Thead + SizeToCopy == TLastByte && TLastByte != Ttail){
PacketMoveMem(packp, CurrBuff+Thead, SizeToCopy, &(Open->Bhead));
// Reset the buffer
NdisAcquireSpinLock( &Open->BufLock );
Open->BLastByte = Open->Btail;
(INT)Open->BLastByte = -1;
Open->Bhead = 0;
NdisReleaseSpinLock( &Open->BufLock );
Thead=0;
CpStart=0;
}
cplen=((struct bpf_hdr*)(CurrBuff+Thead))->bh_caplen+sizeof(struct bpf_hdr);
if((i+cplen > Input_Buffer_Length)){//no more space in the application's buffer
PacketMoveMem(packp,CurrBuff+CpStart,Thead-CpStart,&(Open->Bhead));
EXIT_SUCCESS(i);
}
cplen=Packet_WORDALIGN(cplen);
i+=cplen;
Thead+=cplen;
EXIT_SUCCESS(SizeToCopy);
}
// Get the size of the next packet in the buffer
PktLen = ((struct bpf_hdr*)(CurrBuff + Thead + SizeToCopy))->bh_caplen + sizeof(struct bpf_hdr);
KeResetEvent(Open->ReadEvent);
// The length is aligned to 32-bit boundary
PktLen = Packet_WORDALIGN(PktLen);
PacketMoveMem(packp,CurrBuff+CpStart,Thead-CpStart,&(Open->Bhead));
if(SizeToCopy + PktLen > Input_Buffer_Length)
break;
Open->Bhead=Thead;
SizeToCopy += PktLen;
}
PacketMoveMem(packp, CurrBuff+Thead, SizeToCopy, &(Open->Bhead));
EXIT_SUCCESS(SizeToCopy);
EXIT_SUCCESS(i);
}
//-------------------------------------------------------------------
@ -350,8 +350,14 @@ NDIS_STATUS NPF_tap (IN NDIS_HANDLE ProtocolBindingContext,IN NDIS_HANDLE MacRec
UINT maxbufspace;
USHORT NPFHdrSize;
UINT BufOccupation;
BOOLEAN ResetBuff = FALSE;
IF_VERY_LOUD(DbgPrint("NPF: tap\n");)
IF_VERY_LOUD(DbgPrint("HeaderBufferSize=%d, LookAheadBuffer=%d, LookaheadBufferSize=%d, PacketSize=%d\n",
HeaderBufferSize,
LookAheadBuffer,
LookaheadBufferSize,
PacketSize);)
Open= (POPEN_INSTANCE)ProtocolBindingContext;
@ -401,6 +407,7 @@ NDIS_STATUS NPF_tap (IN NDIS_HANDLE ProtocolBindingContext,IN NDIS_HANDLE MacRec
#ifndef __GNUC__
_asm add esp,12
#else
asm("add $0x12,%esp;");
#endif
}
else
@ -489,9 +496,16 @@ NDIS_STATUS NPF_tap (IN NDIS_HANDLE ProtocolBindingContext,IN NDIS_HANDLE MacRec
}
else{
Ttail=0;
ResetBuff = TRUE;
}
}
if (Thead > Ttail && (Thead-Ttail) <= maxbufspace)
{
Open->Dropped++;
return NDIS_STATUS_NOT_ACCEPTED;
}
CurrBuff=Open->Buffer+Ttail;
if(LookaheadBufferSize != PacketSize || (UINT)LookAheadBuffer-(UINT)HeaderBuffer != HeaderBufferSize)
@ -568,15 +582,17 @@ NDIS_STATUS NPF_tap (IN NDIS_HANDLE ProtocolBindingContext,IN NDIS_HANDLE MacRec
HeaderBuffer,
HeaderBufferSize + LookaheadBufferSize);
BytesTransfered = 0;
Open->TransferMdl = NULL;
Status = NDIS_STATUS_SUCCESS;
}
Open->Accepted++; // Increase the accepted packets counter
if (Status != NDIS_STATUS_FAILURE)
{
Open->Accepted++; // Increase the accepted packets counter
if( fres > (BytesTransfered+HeaderBufferSize+LookaheadBufferSize) )
fres = BytesTransfered+HeaderBufferSize+LookaheadBufferSize;
@ -596,12 +612,12 @@ NDIS_STATUS NPF_tap (IN NDIS_HANDLE ProtocolBindingContext,IN NDIS_HANDLE MacRec
Ttail+=fres+NPFHdrSize;
//update the buffer
if(Ttail > Thead)TLastByte = Ttail;
NdisAcquireSpinLock( &Open->BufLock );
if(ResetBuff){
Open->BLastByte = Open->Btail;
}
Open->Btail=Ttail;
Open->BLastByte=TLastByte;
NdisReleaseSpinLock( &Open->BufLock );
}

View file

@ -26,11 +26,9 @@
void TIME_DESYNCHRONIZE(struct time_conv *data)
{
#ifndef __GNUC__
data->reference = 0;
data->start.tv_sec = 0;
data->start.tv_usec = 0;
#endif
}
#ifdef KQPC_TS
@ -39,7 +37,6 @@ void TIME_DESYNCHRONIZE(struct time_conv *data)
VOID TIME_SYNCHRONIZE(struct time_conv *data)
{
#ifndef __GNUC__
struct timeval tmp;
LARGE_INTEGER SystemTime;
LARGE_INTEGER i;
@ -52,17 +49,20 @@ VOID TIME_SYNCHRONIZE(struct time_conv *data)
// get the absolute value of the system boot time.
PTime=KeQueryPerformanceCounter(&TimeFreq);
KeQuerySystemTime(&SystemTime);
#ifndef __GNUC__
tmp.tv_sec=(LONG)(SystemTime.QuadPart/10000000-11644473600);
tmp.tv_usec=(LONG)((SystemTime.QuadPart%10000000)/10);
tmp.tv_sec-=(ULONG)(PTime.QuadPart/TimeFreq.QuadPart);
tmp.tv_usec-=(LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
#else
// TODO FIXME:
#endif
if (tmp.tv_usec<0) {
tmp.tv_sec--;
tmp.tv_usec+=1000000;
}
data->start=tmp;
data->reference=1;
#endif
}
void FORCE_TIME(struct timeval *src, struct time_conv *dest)
@ -72,29 +72,30 @@ void FORCE_TIME(struct timeval *src, struct time_conv *dest)
void GET_TIME(struct timeval *dst, struct time_conv *data)
{
#ifndef __GNUC__
LARGE_INTEGER PTime, TimeFreq;
LONG tmp;
PTime=KeQueryPerformanceCounter(&TimeFreq);
#ifndef __GNUC__
tmp=(LONG)(PTime.QuadPart/TimeFreq.QuadPart);
dst->tv_sec=data->start.tv_sec+tmp;
dst->tv_usec=data->start.tv_usec+(LONG)((PTime.QuadPart%TimeFreq.QuadPart)*1000000/TimeFreq.QuadPart);
#else
// TODO FIXME:
#endif
if (dst->tv_usec>=1000000) {
dst->tv_sec++;
dst->tv_usec-=1000000;
}
#endif
}
#else
#else /*KQPC_TS*/
/*RDTSC timestamps*/
/* callers must be at IRQL=PASSIVE_LEVEL */
VOID TIME_SYNCHRONIZE(struct time_conv *data)
{
#ifndef __GNUC__
struct timeval tmp;
LARGE_INTEGER system_time;
ULONGLONG curr_ticks;
@ -128,6 +129,17 @@ VOID TIME_SYNCHRONIZE(struct time_conv *data)
pop eax
}
#else
asm("push %%eax;"
"push %%edx;"
"push %%ecx;"
"rdtsc;"
"lea %0,%%ecx;"
"mov %%edx,(%%ecx+4);"
"mov %%eax,(%%ecx);"
"pop %%ecx;"
"pop %%edx;"
"pop %%eax;"
:"=c"(start_ticks): );
#endif
KeLowerIrql(old);
KeWaitForSingleObject(&event,UserRequest,KernelMode,TRUE ,&i);
@ -148,6 +160,17 @@ VOID TIME_SYNCHRONIZE(struct time_conv *data)
pop eax
}
#else
asm("push %%eax;"
"push %%edx;"
"push %%ecx;"
"rdtsc;"
"lea %0,%%ecx;"
"mov %%edx,(%%ecx+4);"
"mov %%eax,(%%ecx);"
"pop %%ecx;"
"pop %%edx;"
"pop %%eax;"
:"=c"(stop_ticks): );
#endif
KeLowerIrql(old);
delta=stop_ticks-start_ticks;
@ -178,6 +201,17 @@ VOID TIME_SYNCHRONIZE(struct time_conv *data)
pop eax
}
#else
asm("push %%eax;"
"push %%edx;"
"push %%ecx;"
"rdtsc;"
"lea %0,%%ecx;"
"mov %%edx,(%%ecx+4);"
"mov %%eax,(%%ecx);"
"pop %%ecx;"
"pop %%edx;"
"pop %%eax;"
:"=c"(curr_ticks): );
#endif
tmp.tv_sec=-(LONG)(curr_ticks/reference);
tmp.tv_usec=-(LONG)((curr_ticks%reference)*1000000/reference);
@ -190,8 +224,6 @@ VOID TIME_SYNCHRONIZE(struct time_conv *data)
}
data->start=tmp;
IF_LOUD(DbgPrint("Frequency %I64u MHz\n",data->reference);)
#else
#endif
}
void FORCE_TIME(struct timeval *src, struct time_conv *dest)
@ -201,7 +233,6 @@ void FORCE_TIME(struct timeval *src, struct time_conv *dest)
void GET_TIME(struct timeval *dst, struct time_conv *data)
{
#ifndef __GNUC__
ULONGLONG tmp;
#ifndef __GNUC__
__asm
@ -218,6 +249,17 @@ void GET_TIME(struct timeval *dst, struct time_conv *data)
pop eax
}
#else
asm("push %%eax;"
"push %%edx;"
"push %%ecx;"
"rdtsc;"
"lea %0,%%ecx;"
"mov %%edx,(%%ecx+4);"
"mov %%eax,(%%ecx);"
"pop %%ecx;"
"pop %%edx;"
"pop %%eax;"
:"=c"(tmp): );
#endif
if (data->reference==0) {
return;
@ -230,7 +272,6 @@ void GET_TIME(struct timeval *dst, struct time_conv *data)
dst->tv_sec++;
dst->tv_usec-=1000000;
}
#endif
}
#endif /*KQPC_TS*/

View file

@ -92,11 +92,6 @@ __inline VOID TIME_SYNCHRONIZE(struct time_conv *data)
data->reference=1;
}
__inline void FORCE_TIME(struct timeval *src, struct time_conv *dest)
{
dest->start=*src;
}
__inline void GET_TIME(struct timeval *dst, struct time_conv *data)
{
LARGE_INTEGER PTime, TimeFreq;
@ -112,6 +107,11 @@ __inline void GET_TIME(struct timeval *dst, struct time_conv *data)
}
}
__inline void FORCE_TIME(struct timeval *src, struct time_conv *dest)
{
dest->start=*src;
}
#else
/*RDTSC timestamps*/

View file

@ -37,7 +37,7 @@
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
* @(#) $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/drivers/net/packet/win_bpf.h,v 1.2 2002/09/24 15:16:46 robd Exp $ (LBL)
* @(#) $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/drivers/net/packet/win_bpf.h,v 1.3 2002/12/21 04:46:09 robd Exp $ (LBL)
*/
#ifndef BPF_MAJOR_VERSION

View file

@ -135,6 +135,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp2): );
#endif
continue;
@ -154,6 +164,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(X),"=c"(tmp2): );
#endif
continue;
@ -172,6 +192,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp): );
#endif
continue;
@ -190,6 +220,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(X),"=c"(tmp): );
#endif
continue;
@ -221,6 +261,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp2): );
#endif
continue;
@ -243,6 +293,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp): );
#endif
continue;
/* END LD NO PACKET INSTRUCTIONS */
@ -279,6 +339,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp): );
#endif
continue;
@ -297,6 +367,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(X),"=c"(tmp): );
#endif
continue;
@ -315,6 +395,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp2): );
#endif
continue;
@ -333,6 +423,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(X),"=c"(tmp2): );
#endif
continue;
@ -354,6 +454,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp): );
#endif
continue;
@ -372,6 +482,16 @@ uint32 bpf_filter_init(register struct bpf_insn *pc, MEM_TYPE *mem_ex, TME_CORE
pop eax
}
#else
asm("push %%eax;"
"push %%ebx;"
"mov %1,%%ebx;"
"xor %%eax, %%eax;"
"mov (%%ebx), %%ax;"
"bswap %%eax;"
"mov %%eax, %0;"
"pop %%ebx;"
"pop %%eax;"
:"=a"(A),"=c"(tmp2): );
#endif
continue;
/* END STORE INSTRUCTIONS */

View file

@ -27,6 +27,12 @@
#else
#include <ddk/ntddk.h>
#include <net/ndis.h>
#define NdisReinitializePacket(Packet) \
{ \
(Packet)->Private.Head = (PNDIS_BUFFER)NULL; \
(Packet)->Private.ValidCounts = FALSE; \
}
#endif
#include "debug.h"
@ -34,8 +40,8 @@
//-------------------------------------------------------------------
NTSTATUS
//STDCALL
NPF_Write(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
@ -48,17 +54,22 @@ NPF_Write(
UINT i;
NDIS_STATUS Status;
IF_LOUD(DbgPrint("Packet: SendAdapter\n");)
IF_LOUD(DbgPrint("NPF_Write\n");)
IrpSp = IoGetCurrentIrpStackLocation(Irp);
Open=IrpSp->FileObject->FsContext;
// Check the length of the packet to avoid to use an empty packet
if(IrpSp->Parameters.Write.Length==0)
IF_LOUD(DbgPrint("Max frame size = %d\n", Open->MaxFrameSize);)
if(IrpSp->Parameters.Write.Length == 0 || // Check that the buffer provided by the user is not empty
Open->MaxFrameSize == 0 || // Check that the MaxFrameSize is correctly initialized
IrpSp->Parameters.Write.Length > Open->MaxFrameSize) // Check that the fame size is smaller that the MTU
{
IF_LOUD(DbgPrint("frame size out of range, send aborted\n");)
Irp->IoStatus.Status = NDIS_STATUS_SUCCESS;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return NDIS_STATUS_SUCCESS;
@ -159,6 +170,15 @@ NPF_BufferedWrite(
return 0;
}
// Check that the MaxFrameSize is correctly initialized
if(Open->MaxFrameSize == 0)
{
IF_LOUD(DbgPrint("BufferedWrite: Open->MaxFrameSize not initialized, probably because of a problem in the OID query\n");)
return 0;
}
// Start from the first packet
winpcap_hdr = (struct sf_pkthdr*)UserBuff;
@ -181,10 +201,10 @@ NPF_BufferedWrite(
// Main loop: send the buffer to the wire
while( TRUE ){
if(winpcap_hdr->caplen ==0 || winpcap_hdr->caplen > 65536)
if(winpcap_hdr->caplen ==0 || winpcap_hdr->caplen > Open->MaxFrameSize)
{
// Malformed header
IF_LOUD(DbgPrint("NPF_BufferedWrite: malformed user buffer, aborting write.\n");)
IF_LOUD(DbgPrint("NPF_BufferedWrite: malformed or bogus user buffer, aborting write.\n");)
return -1;
}
@ -247,7 +267,6 @@ NPF_BufferedWrite(
if( Sync ){
#if 0
// Release the application if it has been blocked for approximately more than 1 seconds
if( winpcap_hdr->ts.tv_sec - BufStartTime.tv_sec > 1 )
{
@ -256,6 +275,7 @@ NPF_BufferedWrite(
return (PCHAR)winpcap_hdr - UserBuff;
}
#ifndef __GNUC__
// Calculate the time interval to wait before sending the next packet
TargetTicks.QuadPart = StartTicks.QuadPart +
(LONGLONG)((winpcap_hdr->ts.tv_sec - BufStartTime.tv_sec) * 1000000 +
@ -265,8 +285,8 @@ NPF_BufferedWrite(
// Wait until the time interval has elapsed
while( CurTicks.QuadPart <= TargetTicks.QuadPart )
CurTicks = KeQueryPerformanceCounter(NULL);
#else
#endif
}
}
@ -330,3 +350,17 @@ NPF_SendComplete(
return;
}
#ifdef __GNUC__
/*
__divdi3()
{
//_alldiv();
}
//_allmul();
//_allrem();
*/
#endif