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

# Packet.h

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 1999 - 2003
    00003  * NetGroup, Politecnico di Torino (Italy)
    00004  * All rights reserved.
    00005  *
    00006  * Redistribution and use in source and binary forms, with or without
    00007  * modification, are permitted provided that the following conditions
    00008  * are met:
    00009  *
    00010  * 1. Redistributions of source code must retain the above copyright
    00011  * notice, this list of conditions and the following disclaimer.
    00012  * 2. Redistributions in binary form must reproduce the above copyright
    00013  * notice, this list of conditions and the following disclaimer in the
    00014  * documentation and/or other materials provided with the distribution.
    00015  * 3. Neither the name of the Politecnico di Torino nor the names of its
    00016  * contributors may be used to endorse or promote products derived from
    00017  * this software without specific prior written permission.
    00018  *
    00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    00023  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030  *
    00031  */
    00032
    00041 #ifndef __PACKET_INCLUDE______
    00042 #define __PACKET_INCLUDE______
    00043
    00044 #define NTKERNEL
    00045
    00046 #include "jitter.h"
    00047 #include "win_bpf.h"
    00048
    00049 #define  MAX_REQUESTS   32
    00050
    00051 #define Packet_ALIGNMENT sizeof(int)
    00052 #define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
    00053
    00054 /***************************/
    00055 /*         IOCTLs          */
    00056 /***************************/
    00057
    00066 #define  BIOCSETBUFFERSIZE 9592
    00067
    00078 #define  BIOCSETF 9030
    00079
    00086 #define  BIOCGSTATS 9031
    00087
    00093 #define  BIOCSRTIMEOUT 7416
    00094
    00102 #define  BIOCSMODE 7412
    00103
    00110 #define  BIOCSWRITEREP 7413
    00111
    00117 #define  BIOCSMINTOCOPY 7414
    00118
    00124 #define  BIOCSETOID 2147483648
    00125
    00131 #define  BIOCQUERYOID 2147483652
    00132
    00140 #define  BIOCSETDUMPFILENAME 9029
    00141
    00148 #define  BIOCGEVNAME 7415
    00149
    00157 #define  BIOCSENDPACKETSNOSYNC 9032
    00158
    00167 #define  BIOCSENDPACKETSSYNC 9033
    00168
    00175 #define  BIOCSETDUMPLIMITS 9034
    00176
    00183 #define BIOCISDUMPENDED 7411
    00184
    00185 // Working modes
    00186 #define MODE_CAPT 0x0
    00187 #define MODE_STAT 0x1
    00188 #define MODE_MON  0x2
    00189 #define MODE_DUMP 0x10
    00190
    00191
    00192 #define IMMEDIATE 1
    00193
    00194
    00195 // The following definitions are used to provide compatibility
    00196 // of the dump files with the ones of libpcap
    00197 #define TCPDUMP_MAGIC 0xa1b2c3d4
    00198 #define PCAP_VERSION_MAJOR 2
    00199 #define PCAP_VERSION_MINOR 4
    00200
    00201
    00206 struct packet_file_header
    00207 {
    00208     UINT magic;
    00209     USHORT version_major;
    00210     USHORT version_minor;
    00211     UINT thiszone;
    00212     UINT sigfigs;
    00213     UINT snaplen;
    00214     UINT linktype;
    00215 };
    00216
    00221 struct sf_pkthdr {
    00222     struct timeval  ts;
    00223     UINT            caplen;
    00224
    00225
    00226     UINT            len;
    00227 };
    00228
    00238 typedef struct _INTERNAL_REQUEST {
    00239     LIST_ENTRY      ListElement;
    00240     PIRP            Irp;
    00241     BOOLEAN         Internal;
    00242     NDIS_REQUEST    Request;
    00243 } INTERNAL_REQUEST, *PINTERNAL_REQUEST;
    00244
    00252 typedef struct _PACKET_RESERVED {
    00253     LIST_ENTRY      ListElement;
    00254     PIRP            Irp;
    00255     PMDL            pMdl;
    00256     BOOLEAN         FreeBufAfterWrite;
    00257
    00258     ULONG           Cpu;
    00259 }  PACKET_RESERVED, *PPACKET_RESERVED;
    00260
    00261 #define RESERVED(_p) ((PPACKET_RESERVED)((_p)->ProtocolReserved))
    00262
    00263
    00268 typedef struct _DEVICE_EXTENSION {
    00269     NDIS_HANDLE    NdisProtocolHandle;
    00270     NDIS_STRING    AdapterName;
    00271     PWSTR          ExportString;
    00272
    00273 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
    00274
    00280 typedef struct __CPU_Private_Data
    00281 {
    00282     ULONG   P;
    00283     ULONG   C;
    00284     ULONG   Free;
    00285     PUCHAR  Buffer;
    00286     ULONG   Accepted;
    00287
    00288
    00289
    00290     ULONG   Received;
    00291
    00292
    00293
    00294     ULONG   Dropped;
    00295
    00296
    00297
    00298     ULONG   Processing;
    00299     PMDL    TransferMdl1;
    00300     PMDL    TransferMdl2;
    00301     ULONG   NewP;
    00302 }
    00303     CpuPrivateData;
    00304
    00305
    00313 typedef struct _OPEN_INSTANCE
    00314 {
    00315     PDEVICE_EXTENSION   DeviceExtension;
    00316
    00317     NDIS_HANDLE         AdapterHandle;
    00318     UINT                Medium;
    00319
    00320     NDIS_HANDLE         PacketPool;
    00321     PIRP                OpenCloseIrp;
    00322
    00323     KSPIN_LOCK          RequestSpinLock;
    00324     LIST_ENTRY          RequestList;
    00325     LIST_ENTRY          ResetIrpList;
    00326     INTERNAL_REQUEST    Requests[MAX_REQUESTS];
    00327     PMDL                BufferMdl;
    00328     PKEVENT             ReadEvent;
    00329     HANDLE              ReadEventHandle;
    00330     UNICODE_STRING      ReadEventName;
    00331
    00332
    00333
    00334     PUCHAR              bpfprogram;
    00335
    00336
    00337
    00338
    00339     JIT_BPF_Filter      *Filter;
    00340
    00341     UINT                MinToCopy;
    00342
    00343     LARGE_INTEGER       TimeOut;
    00344
    00345
    00346     int                 mode;
    00347     LARGE_INTEGER       Nbytes;
    00348     LARGE_INTEGER       Npackets;
    00349     NDIS_SPIN_LOCK      CountersLock;
    00350     UINT                Nwrites;
    00351
    00352     ULONG               Multiple_Write_Counter;
    00353     NDIS_EVENT          WriteEvent;
    00354     BOOLEAN             WriteInProgress;
    00355
    00356     NDIS_SPIN_LOCK      WriteLock;
    00357     NDIS_EVENT          IOEvent;
    00358     NDIS_STATUS         IOStatus;
    00359     BOOLEAN             Bound;
    00360
    00361     HANDLE              DumpFileHandle;
    00362     PFILE_OBJECT        DumpFileObject;
    00363     PKTHREAD            DumpThreadObject;
    00364     HANDLE              DumpThreadHandle;
    00365     NDIS_EVENT          DumpEvent;
    00366     LARGE_INTEGER       DumpOffset;
    00367     UNICODE_STRING      DumpFileName;
    00368     UINT                MaxDumpBytes;
    00369
    00370     UINT                MaxDumpPacks;
    00371
    00372
    00373     BOOLEAN             DumpLimitReached;
    00374
    00375     MEM_TYPE            mem_ex;
    00376     TME_CORE            tme;
    00377     NDIS_SPIN_LOCK      MachineLock;
    00378     UINT                MaxFrameSize;
    00379
    00380     CpuPrivateData      CpuData[32];
    00381     ULONG               ReaderSN;
    00382     ULONG               WriterSN;
    00383
    00384     ULONG               Size;
    00385     ULONG               SkipProcessing;
    00386
    00387
    00388
    00389 }
    00390 OPEN_INSTANCE, *POPEN_INSTANCE;
    00391
    00399 struct PacketHeader
    00400 {
    00401     ULONG SN;
    00402     struct bpf_hdr header;
    00403 };
    00404
    00405
    00406 #define TRANSMIT_PACKETS 256
    00407
    00408
    00409
    00411 #define EXIT_SUCCESS(quantity) Irp->IoStatus.Information=quantity;\
    00412     Irp->IoStatus.Status = STATUS_SUCCESS;\
    00413     IoCompleteRequest(Irp, IO_NO_INCREMENT);\
    00414     return STATUS_SUCCESS;\
    00415
    00416
    00417 #define EXIT_FAILURE(quantity) Irp->IoStatus.Information=quantity;\
    00418     Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;\
    00419     IoCompleteRequest(Irp, IO_NO_INCREMENT);\
    00420     return STATUS_UNSUCCESSFUL;\
    00421
    00422
    00427 /***************************/
    00428 /*       Prototypes        */
    00429 /***************************/
    00430
    00447 NTSTATUS
    00448 DriverEntry(
    00449     IN PDRIVER_OBJECT DriverObject,
    00450     IN PUNICODE_STRING RegistryPath
    00451     );
    00452
    00462 PWCHAR getAdaptersList(VOID);
    00463
    00470 PKEY_VALUE_PARTIAL_INFORMATION getTcpBindings(VOID);
    00471
    00483 BOOLEAN createDevice(
    00484     IN OUT PDRIVER_OBJECT adriverObjectP,
    00485     IN PUNICODE_STRING amacNameP,
    00486     NDIS_HANDLE aProtoHandle);
    00487
    00499 NTSTATUS
    00500 NPF_Open(
    00501     IN PDEVICE_OBJECT DeviceObject,
    00502     IN PIRP Irp
    00503     );
    00504
    00514 VOID
    00515 NPF_OpenAdapterComplete(
    00516     IN NDIS_HANDLE  ProtocolBindingContext,
    00517     IN NDIS_STATUS  Status,
    00518     IN NDIS_STATUS  OpenErrorStatus
    00519     );
    00520
    00531 NTSTATUS
    00532 NPF_Close(
    00533     IN PDEVICE_OBJECT DeviceObject,
    00534     IN PIRP Irp
    00535     );
    00536
    00545 VOID
    00546 NPF_CloseAdapterComplete(
    00547     IN NDIS_HANDLE  ProtocolBindingContext,
    00548     IN NDIS_STATUS  Status
    00549     );
    00550
    00573 NDIS_STATUS
    00574 NPF_tap(
    00575     IN NDIS_HANDLE ProtocolBindingContext,
    00576     IN NDIS_HANDLE MacReceiveContext,
    00577     IN PVOID HeaderBuffer,
    00578     IN UINT HeaderBufferSize,
    00579     IN PVOID LookAheadBuffer,
    00580     IN UINT LookaheadBufferSize,
    00581     IN UINT PacketSize
    00582     );
    00583
    00594 VOID
    00595 NPF_TransferDataComplete(
    00596     IN NDIS_HANDLE ProtocolBindingContext,
    00597     IN PNDIS_PACKET Packet,
    00598     IN NDIS_STATUS Status,
    00599     IN UINT BytesTransferred
    00600     );
    00601
    00608 VOID
    00609 NPF_ReceiveComplete(IN NDIS_HANDLE  ProtocolBindingContext);
    00610
    00634 NTSTATUS
    00635 NPF_IoControl(
    00636     IN PDEVICE_OBJECT DeviceObject,
    00637     IN PIRP Irp
    00638     );
    00639
    00640 VOID
    00641
    00651 NPF_RequestComplete(
    00652     IN NDIS_HANDLE   ProtocolBindingContext,
    00653     IN PNDIS_REQUEST pRequest,
    00654     IN NDIS_STATUS   Status
    00655     );
    00656
    00669 NTSTATUS
    00670 NPF_Write(
    00671             IN PDEVICE_OBJECT DeviceObject,
    00672             IN PIRP Irp
    00673             );
    00674
    00675
    00694 INT NPF_BufferedWrite(IN PIRP Irp,
    00695                         IN PCHAR UserBuff,
    00696                         IN ULONG UserBuffSize,
    00697                         BOOLEAN sync);
    00698
    00706 VOID NPF_WaitEndOfBufferedWrite(POPEN_INSTANCE Open);
    00707
    00717 VOID
    00718 NPF_SendComplete(
    00719     IN NDIS_HANDLE   ProtocolBindingContext,
    00720     IN PNDIS_PACKET  pPacket,
    00721     IN NDIS_STATUS   Status
    00722     );
    00723
    00733 VOID
    00734 NPF_ResetComplete(
    00735     IN NDIS_HANDLE  ProtocolBindingContext,
    00736     IN NDIS_STATUS  Status
    00737     );
    00738
    00742 VOID
    00743 NPF_Status(
    00744     IN NDIS_HANDLE   ProtocolBindingContext,
    00745     IN NDIS_STATUS   Status,
    00746     IN PVOID         StatusBuffer,
    00747     IN UINT          StatusBufferSize
    00748     );
    00749
    00750
    00754 VOID
    00755 NPF_StatusComplete(IN NDIS_HANDLE  ProtocolBindingContext);
    00756
    00765 VOID
    00766 NPF_Unload(IN PDRIVER_OBJECT DriverObject);
    00767
    00768
    00787 NTSTATUS
    00788 NPF_Read(
    00789     IN PDEVICE_OBJECT DeviceObject,
    00790     IN PIRP Irp
    00791     );
    00792
    00798 NTSTATUS
    00799 NPF_ReadRegistry(
    00800     IN  PWSTR              *MacDriverName,
    00801     IN  PWSTR              *PacketDriverName,
    00802     IN  PUNICODE_STRING     RegistryPath
    00803     );
    00804
    00811 NTSTATUS
    00812 NPF_QueryRegistryRoutine(
    00813     IN PWSTR     ValueName,
    00814     IN ULONG     ValueType,
    00815     IN PVOID     ValueData,
    00816     IN ULONG     ValueLength,
    00817     IN PVOID     Context,
    00818     IN PVOID     EntryContext
    00819     );
    00820
    00826 VOID NPF_BindAdapter(
    00827     OUT PNDIS_STATUS            Status,
    00828     IN  NDIS_HANDLE             BindContext,
    00829     IN  PNDIS_STRING            DeviceName,
    00830     IN  PVOID                   SystemSpecific1,
    00831     IN  PVOID                   SystemSpecific2
    00832     );
    00833
    00845 VOID
    00846 NPF_UnbindAdapter(
    00847     OUT PNDIS_STATUS        Status,
    00848     IN  NDIS_HANDLE         ProtocolBindingContext,
    00849     IN  NDIS_HANDLE         UnbindContext
    00850     );
    00851
    00852
    00860 NTSTATUS NPF_OpenDumpFile(POPEN_INSTANCE Open , PUNICODE_STRING fileName, BOOLEAN append);
    00861
    00870 NTSTATUS NPF_StartDump(POPEN_INSTANCE Open);
    00871
    00879 VOID NPF_DumpThread(PVOID Open);
    00880
    00887 NTSTATUS NPF_SaveCurrentBuffer(POPEN_INSTANCE Open);
    00888
    00901 VOID NPF_WriteDumpFile(PFILE_OBJECT FileObject,
    00902                                 PLARGE_INTEGER Offset,
    00903                                 ULONG Length,
    00904                                 PMDL Mdl,
    00905                                 PIO_STATUS_BLOCK IoStatusBlock);
    00906
    00907
    00908
    00914 NTSTATUS NPF_CloseDumpFile(POPEN_INSTANCE Open);
    00915
    00920 UINT GetBuffOccupation(POPEN_INSTANCE Open);
    00921
    00933 #ifdef NDIS50
    00934 NDIS_STATUS NPF_PowerChange(IN NDIS_HANDLE ProtocolBindingContext, IN PNET_PNP_EVENT pNetPnPEvent);
    00935 #endif
    00936
    00945 #endif  /*main ifndef/define*/

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