Main Page Modules Data Structures File List Data Fields Globals Related Pages

# Openclos.c File Reference

`#include "ntddk.h"`
`#include "ntiologc.h"`
`#include "ndis.h"`
`#include "debug.h"`
`#include "packet.h"`

Go to the source code of this file.

## Defines
#define | NUM_NDIS_MEDIA (sizeof MediumArray / sizeof MediumArray[0])
## Functions
void | PacketItoa (UINT n, PUCHAR buf)
NTSTATUS | NPF_Open (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
| Opens a new instance of the driver.
VOID | NPF_OpenAdapterComplete (IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_STATUS Status, IN NDIS_STATUS OpenErrorStatus)
| Ends the opening of an adapter.
NTSTATUS | NPF_Close (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
| Closes an instance of the driver.
VOID | NPF_CloseAdapterComplete (IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_STATUS Status)
| Ends the closing of an adapter.
VOID | NPF_BindAdapter (OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindContext, IN PNDIS_STRING DeviceName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2)
| Callback for NDIS BindAdapterHandler. Not used by NPF.
VOID | NPF_UnbindAdapter (OUT PNDIS_STATUS Status, IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_HANDLE UnbindContext)
| Callback for NDIS UnbindAdapterHandler.
VOID | NPF_ResetComplete (IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_STATUS Status)
| Ends a reset of the adapter.
## Variables
NDIS_MEDIUM | MediumArray []
ULONG | NamedEventsCounter = 0
time_conv | G_Start_Time
| Global start time. Used as an absolute reference for timestamp conversion.
UINT | n_Opened_Instances = 0
NDIS_SPIN_LOCK | Opened_Instances_Lock

## Define Documentation

#define NUM_NDIS_MEDIA (sizeof MediumArray / sizeof MediumArray[0])

| Definition at line 38 of file Openclos.c.

## Function Documentation

VOID NPF_BindAdapter | ( | OUT PNDIS_STATUS | Status,
|  | IN NDIS_HANDLE | BindContext,
|  | IN PNDIS_STRING | DeviceName,
|  | IN PVOID | SystemSpecific1,
|  | IN PVOID | SystemSpecific2
| ) |

| Callback for NDIS BindAdapterHandler. Not used by NPF. Function called by NDIS when a new adapter is installed on the machine With Plug and Play. Definition at line 577 of file Openclos.c. Referenced by DriverEntry().

NTSTATUS NPF_Close | ( | IN PDEVICE_OBJECT | DeviceObject,
|  | IN PIRP | Irp
| ) |

  | Closes an instance of the driver. Parameters:
  DeviceObject | Pointer to the device object utilized by the user.
  Irp | Pointer to the IRP containing the user request.
Returns: The status of the operation. See ntstatus.h in the DDK. This function is called when a running instance of the driver is closed by the user with a CloseHandle(). It stops the capture/monitoring/dump process, deallocates the memory and the objects associated with the instance and closing the files. The network adapter is then closed with a call to NdisCloseAdapter. Definition at line 380 of file Openclos.c. References _OPEN_INSTANCE::AdapterHandle, _OPEN_INSTANCE::Bound, BPF_Destroy_JIT_Filter(), _OPEN_INSTANCE::bpfprogram, __CPU_Private_Data::Buffer, _OPEN_INSTANCE::CpuData, _OPEN_INSTANCE::DumpEvent, _OPEN_INSTANCE::DumpFileHandle, _OPEN_INSTANCE::DumpFileName, _OPEN_INSTANCE::DumpThreadObject, _OPEN_INSTANCE::Filter, _OPEN_INSTANCE::IOEvent, _OPEN_INSTANCE::mem_ex, _OPEN_INSTANCE::mode, MODE_DUMP, NPF_CloseAdapterComplete(), NPF_CloseDumpFile(), _OPEN_INSTANCE::OpenCloseIrp, _OPEN_INSTANCE::PacketPool, _OPEN_INSTANCE::ReadEvent, _OPEN_INSTANCE::ReadEventHandle, _OPEN_INSTANCE::ReadEventName, and _OPEN_INSTANCE::Size. Referenced by DriverEntry().

VOID NPF_CloseAdapterComplete | ( | IN NDIS_HANDLE | ProtocolBindingContext,
|  | IN NDIS_STATUS | Status
| ) |

  | Ends the closing of an adapter. Parameters:
  ProtocolBindingContext | Context of the function. Contains a pointer to the OPEN_INSTANCE structure associated with the current instance.
  Status | Status of the close operation performed by NDIS.
Callback function associated with the NdisCloseAdapter() NDIS function. It is invoked by NDIS when the NIC driver has finished a close operation that was previously started by NPF_Close(). Definition at line 492 of file Openclos.c. References _OPEN_INSTANCE::Bound, BPF_Destroy_JIT_Filter(), _OPEN_INSTANCE::bpfprogram, __CPU_Private_Data::Buffer, _OPEN_INSTANCE::CpuData, _OPEN_INSTANCE::DumpFileName, _OPEN_INSTANCE::Filter, _OPEN_INSTANCE::IOEvent, _OPEN_INSTANCE::mem_ex, n_Opened_Instances, _OPEN_INSTANCE::OpenCloseIrp, _OPEN_INSTANCE::PacketPool, _OPEN_INSTANCE::ReadEventName, and _OPEN_INSTANCE::Size. Referenced by DriverEntry(), NPF_Close(), and NPF_UnbindAdapter().

NTSTATUS NPF_Open | ( | IN PDEVICE_OBJECT | DeviceObject,
|  | IN PIRP | Irp
| ) |

  | Opens a new instance of the driver. Parameters:
  DeviceObject | Pointer to the device object utilized by the user.
  Irp | Pointer to the IRP containing the user request.
Returns: The status of the operation. See ntstatus.h in the DDK. This function is called by the OS when a new instance of the driver is opened, i.e. when a user application performs a CreateFile on a device created by NPF. NPF_Open allocates and initializes variables, objects and buffers needed by the new instance, fills the OPEN_INSTANCE structure associated with it and opens the adapter with a call to NdisOpenAdapter. Definition at line 66 of file Openclos.c. References _OPEN_INSTANCE::AdapterHandle, _DEVICE_EXTENSION::AdapterName, _OPEN_INSTANCE::Bound, _OPEN_INSTANCE::bpfprogram, _OPEN_INSTANCE::CountersLock, _OPEN_INSTANCE::DeviceExtension, _OPEN_INSTANCE::DumpEvent, _OPEN_INSTANCE::DumpFileHandle, _OPEN_INSTANCE::DumpFileName, _OPEN_INSTANCE::DumpLimitReached, _OPEN_INSTANCE::IOEvent, _INTERNAL_REQUEST::ListElement, _OPEN_INSTANCE::MachineLock, MAX_REQUESTS, _OPEN_INSTANCE::MaxFrameSize, _OPEN_INSTANCE::Medium, _OPEN_INSTANCE::mem_ex, _OPEN_INSTANCE::MinToCopy, _OPEN_INSTANCE::mode, MODE_CAPT, _OPEN_INSTANCE::Multiple_Write_Counter, _OPEN_INSTANCE::Nbytes, _DEVICE_EXTENSION::NdisProtocolHandle, _OPEN_INSTANCE::Npackets, NPF_OpenAdapterComplete(), _OPEN_INSTANCE::Nwrites, _OPEN_INSTANCE::OpenCloseIrp, PacketItoa(), _OPEN_INSTANCE::PacketPool, _OPEN_INSTANCE::ReaderSN, _OPEN_INSTANCE::ReadEvent, _OPEN_INSTANCE::ReadEventHandle, _OPEN_INSTANCE::ReadEventName, _OPEN_INSTANCE::RequestList, _OPEN_INSTANCE::Requests, _OPEN_INSTANCE::RequestSpinLock, _OPEN_INSTANCE::ResetIrpList, _OPEN_INSTANCE::Size, _OPEN_INSTANCE::TimeOut, _OPEN_INSTANCE::tme, _OPEN_INSTANCE::WriteEvent, and _OPEN_INSTANCE::WriterSN. Referenced by DriverEntry().

VOID NPF_OpenAdapterComplete | ( | IN NDIS_HANDLE | ProtocolBindingContext,
|  | IN NDIS_STATUS | Status,
|  | IN NDIS_STATUS | OpenErrorStatus
| ) |

  | Ends the opening of an adapter. Parameters:
  ProtocolBindingContext | Context of the function. Contains a pointer to the OPEN_INSTANCE structure associated with the current instance.
  Status | Status of the opening operation performed by NDIS.
  OpenErrorStatus | not used by NPF.
Callback function associated with the NdisOpenAdapter() NDIS function. It is invoked by NDIS when the NIC driver has finished an open operation that was previously started by NPF_Open(). Definition at line 277 of file Openclos.c. References _OPEN_INSTANCE::AdapterHandle, _INTERNAL_REQUEST::Internal, _INTERNAL_REQUEST::Irp, _OPEN_INSTANCE::MaxFrameSize, _OPEN_INSTANCE::mem_ex, n_Opened_Instances, NPF_RequestComplete(), _OPEN_INSTANCE::OpenCloseIrp, _OPEN_INSTANCE::PacketPool, _OPEN_INSTANCE::ReadEventHandle, _OPEN_INSTANCE::ReadEventName, _INTERNAL_REQUEST::Request, _OPEN_INSTANCE::RequestList, and _OPEN_INSTANCE::RequestSpinLock. Referenced by DriverEntry(), and NPF_Open().

VOID NPF_ResetComplete | ( | IN NDIS_HANDLE | ProtocolBindingContext,
|  | IN NDIS_STATUS | Status
| ) |

  | Ends a reset of the adapter. Parameters:
  ProtocolBindingContext | Context of the function. Contains a pointer to the OPEN_INSTANCE structure associated with the current instance.
  Status | Status of the operation.
Callback function associated with the NdisReset() NDIS function. It is invoked by NDIS when the NIC driver has finished an OID request operation that was previously started by NPF_IoControl(), in an IOCTL_PROTOCOL_RESET command. Definition at line 648 of file Openclos.c. References _OPEN_INSTANCE::RequestSpinLock, and _OPEN_INSTANCE::ResetIrpList. Referenced by DriverEntry(), and NPF_IoControl().

VOID NPF_UnbindAdapter | ( | OUT PNDIS_STATUS | Status,
|  | IN NDIS_HANDLE | ProtocolBindingContext,
|  | IN NDIS_HANDLE | UnbindContext
| ) |

  | Callback for NDIS UnbindAdapterHandler. Parameters:
  Status | out variable filled by NPF_UnbindAdapter with the status of the unbind operation.
  ProtocolBindingContext | Context of the function. Contains a pointer to the OPEN_INSTANCE structure associated with current instance.
  UnbindContext | Specifies a handle, supplied by NDIS, that NPF can use to complete the opration.
Function called by NDIS when a new adapter is removed from the machine without shutting it down. NPF_UnbindAdapter closes the adapter calling NdisCloseAdapter() and frees the memory and the structures associated with it. It also releases the waiting user-level app and closes the dump thread if the instance is in dump mode. Definition at line 591 of file Openclos.c. References _OPEN_INSTANCE::AdapterHandle, _OPEN_INSTANCE::Bound, _OPEN_INSTANCE::DumpEvent, _OPEN_INSTANCE::DumpFileHandle, _OPEN_INSTANCE::IOEvent, _OPEN_INSTANCE::mode, MODE_DUMP, NPF_CloseAdapterComplete(), NPF_CloseDumpFile(), _OPEN_INSTANCE::ReadEvent, and _OPEN_INSTANCE::ReadEventHandle. Referenced by DriverEntry().

void PacketItoa | ( | UINT | n,
|  | PUCHAR | buf
| ) |

| Definition at line 43 of file Openclos.c. References n. Referenced by NPF_Open().

## Variable Documentation

struct time_conv G_Start_Time

| Initial value:
     {
        0,
        {0, 0},
    }
Global start time. Used as an absolute reference for timestamp conversion. Definition at line 55 of file Openclos.c.

NDIS_MEDIUM MediumArray[]`[static]`

| Initial value:
     {
        NdisMedium802_3,

        NdisMediumFddi,
        NdisMediumArcnet878_2,
        NdisMediumAtm,
        NdisMedium802_5
    }
Definition at line 29 of file Openclos.c.

UINT n_Opened_Instances = 0

| Definition at line 60 of file Openclos.c. Referenced by NPF_CloseAdapterComplete(), and NPF_OpenAdapterComplete().

ULONG NamedEventsCounter = 0

| Definition at line 40 of file Openclos.c.

NDIS_SPIN_LOCK Opened_Instances_Lock

| Definition at line 62 of file Openclos.c.

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.