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 "tme.h"
    00048 #include "win_bpf.h"
    00049
    00050 #define  MAX_REQUESTS   32
    00051
    00052 #define Packet_ALIGNMENT sizeof(int)
    00053 #define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
    00054
    00055 /***************************/
    00056 /*         IOCTLs          */
    00057 /***************************/
    00058
    00067 #define  BIOCSETBUFFERSIZE 9592
    00068
    00079 #define  BIOCSETF 9030
    00080
    00087 #define  BIOCGSTATS 9031
    00088
    00094 #define  BIOCSRTIMEOUT 7416
    00095
    00103 #define  BIOCSMODE 7412
    00104
    00111 #define  BIOCSWRITEREP 7413
    00112
    00118 #define  BIOCSMINTOCOPY 7414
    00119
    00125 #define  BIOCSETOID 2147483648
    00126
    00132 #define  BIOCQUERYOID 2147483652
    00133
    00141 #define  BIOCSETDUMPFILENAME 9029
    00142
    00149 #define  BIOCGEVNAME 7415
    00150
    00158 #define  BIOCSENDPACKETSNOSYNC 9032
    00159
    00168 #define  BIOCSENDPACKETSSYNC 9033
    00169
    00176 #define  BIOCSETDUMPLIMITS 9034
    00177
    00184 #define BIOCISDUMPENDED 7411
    00185
    00186 // Working modes
    00187 #define MODE_CAPT 0x0
    00188 #define MODE_STAT 0x1
    00189 #define MODE_MON  0x2
    00190 #define MODE_DUMP 0x10
    00191
    00192
    00193 #define IMMEDIATE 1
    00194
    00195
    00196 // The following definitions are used to provide compatibility
    00197 // of the dump files with the ones of libpcap
    00198 #define TCPDUMP_MAGIC 0xa1b2c3d4
    00199 #define PCAP_VERSION_MAJOR 2
    00200 #define PCAP_VERSION_MINOR 4
    00201
    00202
    00207 struct packet_file_header
    00208 {
    00209     UINT magic;
    00210     USHORT version_major;
    00211     USHORT version_minor;
    00212     UINT thiszone;
    00213     UINT sigfigs;
    00214     UINT snaplen;
    00215     UINT linktype;
    00216 };
    00217
    00222 struct sf_pkthdr {
    00223     struct timeval  ts;
    00224     UINT            caplen;
    00225
    00226
    00227     UINT            len;
    00228 };
    00229
    00239 typedef struct _INTERNAL_REQUEST {
    00240     LIST_ENTRY      ListElement;
    00241     PIRP            Irp;
    00242     BOOLEAN         Internal;
    00243     NDIS_REQUEST    Request;
    00244 } INTERNAL_REQUEST, *PINTERNAL_REQUEST;
    00245
    00253 typedef struct _PACKET_RESERVED {
    00254     LIST_ENTRY      ListElement;
    00255     PIRP            Irp;
    00256     PMDL            pMdl;
    00257     BOOLEAN         FreeBufAfterWrite;
    00258
    00259     ULONG           Cpu;
    00260 }  PACKET_RESERVED, *PPACKET_RESERVED;
    00261
    00262 #define RESERVED(_p) ((PPACKET_RESERVED)((_p)->ProtocolReserved))
    00263
    00264
    00269 typedef struct _DEVICE_EXTENSION {
    00270     NDIS_HANDLE    NdisProtocolHandle;
    00271     NDIS_STRING    AdapterName;
    00272     PWSTR          ExportString;
    00273
    00274 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
    00275
    00281 typedef struct __CPU_Private_Data
    00282 {
    00283     ULONG   P;
    00284     ULONG   C;
    00285     ULONG   Free;
    00286     PUCHAR  Buffer;
    00287     ULONG   Accepted;
    00288
    00289
    00290
    00291     ULONG   Received;
    00292
    00293
    00294
    00295     ULONG   Dropped;
    00296
    00297
    00298
    00299     ULONG   Processing;
    00300     PMDL    TransferMdl1;
    00301     PMDL    TransferMdl2;
    00302     ULONG   NewP;
    00303 }
    00304     CpuPrivateData;
    00305
    00306
    00314 typedef struct _OPEN_INSTANCE
    00315 {
    00316     PDEVICE_EXTENSION   DeviceExtension;
    00317
    00318     NDIS_HANDLE         AdapterHandle;
    00319     UINT                Medium;
    00320
    00321     NDIS_HANDLE         PacketPool;
    00322     PIRP                OpenCloseIrp;
    00323
    00324     KSPIN_LOCK          RequestSpinLock;
    00325     LIST_ENTRY          RequestList;
    00326     LIST_ENTRY          ResetIrpList;
    00327     INTERNAL_REQUEST    Requests[MAX_REQUESTS];
    00328     PMDL                BufferMdl;
    00329     PKEVENT             ReadEvent;
    00330     HANDLE              ReadEventHandle;
    00331     UNICODE_STRING      ReadEventName;
    00332
    00333
    00334
    00335     PUCHAR              bpfprogram;
    00336
    00337
    00338
    00339
    00340     JIT_BPF_Filter      *Filter;
    00341
    00342     UINT                MinToCopy;
    00343
    00344     LARGE_INTEGER       TimeOut;
    00345
    00346
    00347     int                 mode;
    00348     LARGE_INTEGER       Nbytes;
    00349     LARGE_INTEGER       Npackets;
    00350     NDIS_SPIN_LOCK      CountersLock;
    00351     UINT                Nwrites;
    00352
    00353     UINT                Multiple_Write_Counter;
    00354     NDIS_EVENT          WriteEvent;
    00355     NDIS_EVENT          IOEvent;
    00356     NDIS_STATUS         IOStatus;
    00357     BOOLEAN             Bound;
    00358
    00359     HANDLE              DumpFileHandle;
    00360     PFILE_OBJECT        DumpFileObject;
    00361     PKTHREAD            DumpThreadObject;
    00362     HANDLE              DumpThreadHandle;
    00363     NDIS_EVENT          DumpEvent;
    00364     LARGE_INTEGER       DumpOffset;
    00365     UNICODE_STRING      DumpFileName;
    00366     UINT                MaxDumpBytes;
    00367
    00368     UINT                MaxDumpPacks;
    00369
    00370
    00371     BOOLEAN             DumpLimitReached;
    00372
    00373     MEM_TYPE            mem_ex;
    00374     TME_CORE            tme;
    00375     NDIS_SPIN_LOCK      MachineLock;
    00376     UINT                MaxFrameSize;
    00377
    00378     CpuPrivateData      CpuData[32];
    00379     ULONG               ReaderSN;
    00380     ULONG               WriterSN;
    00381
    00382     ULONG               Size;
    00383     ULONG               SkipProcessing;
    00384
    00385
    00386
    00387 }
    00388 OPEN_INSTANCE, *POPEN_INSTANCE;
    00389
    00397 struct PacketHeader
    00398 {
    00399     ULONG SN;
    00400     struct bpf_hdr header;
    00401 };
    00402
    00403
    00404 #define TRANSMIT_PACKETS 256
    00405
    00406
    00407
    00409 #define EXIT_SUCCESS(quantity) Irp->IoStatus.Information=quantity;\
    00410     Irp->IoStatus.Status = STATUS_SUCCESS;\
    00411     IoCompleteRequest(Irp, IO_NO_INCREMENT);\
    00412     return STATUS_SUCCESS;\
    00413
    00414
    00415 #define EXIT_FAILURE(quantity) Irp->IoStatus.Information=quantity;\
    00416     Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;\
    00417     IoCompleteRequest(Irp, IO_NO_INCREMENT);\
    00418     return STATUS_UNSUCCESSFUL;\
    00419
    00420
    00425 /***************************/
    00426 /*       Prototypes        */
    00427 /***************************/
    00428
    00445 NTSTATUS
    00446 DriverEntry(
    00447     IN PDRIVER_OBJECT DriverObject,
    00448     IN PUNICODE_STRING RegistryPath
    00449     );
    00450
    00460 PWCHAR getAdaptersList(VOID);
    00461
    00468 PKEY_VALUE_PARTIAL_INFORMATION getTcpBindings(VOID);
    00469
    00481 BOOLEAN createDevice(
    00482     IN OUT PDRIVER_OBJECT adriverObjectP,
    00483     IN PUNICODE_STRING amacNameP,
    00484     NDIS_HANDLE aProtoHandle);
    00485
    00497 NTSTATUS
    00498 NPF_Open(
    00499     IN PDEVICE_OBJECT DeviceObject,
    00500     IN PIRP Irp
    00501     );
    00502
    00512 VOID
    00513 NPF_OpenAdapterComplete(
    00514     IN NDIS_HANDLE  ProtocolBindingContext,
    00515     IN NDIS_STATUS  Status,
    00516     IN NDIS_STATUS  OpenErrorStatus
    00517     );
    00518
    00529 NTSTATUS
    00530 NPF_Close(
    00531     IN PDEVICE_OBJECT DeviceObject,
    00532     IN PIRP Irp
    00533     );
    00534
    00543 VOID
    00544 NPF_CloseAdapterComplete(
    00545     IN NDIS_HANDLE  ProtocolBindingContext,
    00546     IN NDIS_STATUS  Status
    00547     );
    00548
    00571 NDIS_STATUS
    00572 NPF_tap(
    00573     IN NDIS_HANDLE ProtocolBindingContext,
    00574     IN NDIS_HANDLE MacReceiveContext,
    00575     IN PVOID HeaderBuffer,
    00576     IN UINT HeaderBufferSize,
    00577     IN PVOID LookAheadBuffer,
    00578     IN UINT LookaheadBufferSize,
    00579     IN UINT PacketSize
    00580     );
    00581
    00592 VOID
    00593 NPF_TransferDataComplete(
    00594     IN NDIS_HANDLE ProtocolBindingContext,
    00595     IN PNDIS_PACKET Packet,
    00596     IN NDIS_STATUS Status,
    00597     IN UINT BytesTransferred
    00598     );
    00599
    00606 VOID
    00607 NPF_ReceiveComplete(IN NDIS_HANDLE  ProtocolBindingContext);
    00608
    00632 NTSTATUS
    00633 NPF_IoControl(
    00634     IN PDEVICE_OBJECT DeviceObject,
    00635     IN PIRP Irp
    00636     );
    00637
    00638 VOID
    00639
    00649 NPF_RequestComplete(
    00650     IN NDIS_HANDLE   ProtocolBindingContext,
    00651     IN PNDIS_REQUEST pRequest,
    00652     IN NDIS_STATUS   Status
    00653     );
    00654
    00667 NTSTATUS
    00668 NPF_Write(
    00669             IN PDEVICE_OBJECT DeviceObject,
    00670             IN PIRP Irp
    00671             );
    00672
    00673
    00692 INT NPF_BufferedWrite(IN PIRP Irp,
    00693                         IN PCHAR UserBuff,
    00694                         IN ULONG UserBuffSize,
    00695                         BOOLEAN sync);
    00696
    00706 VOID
    00707 NPF_SendComplete(
    00708     IN NDIS_HANDLE   ProtocolBindingContext,
    00709     IN PNDIS_PACKET  pPacket,
    00710     IN NDIS_STATUS   Status
    00711     );
    00712
    00722 VOID
    00723 NPF_ResetComplete(
    00724     IN NDIS_HANDLE  ProtocolBindingContext,
    00725     IN NDIS_STATUS  Status
    00726     );
    00727
    00731 VOID
    00732 NPF_Status(
    00733     IN NDIS_HANDLE   ProtocolBindingContext,
    00734     IN NDIS_STATUS   Status,
    00735     IN PVOID         StatusBuffer,
    00736     IN UINT          StatusBufferSize
    00737     );
    00738
    00739
    00743 VOID
    00744 NPF_StatusComplete(IN NDIS_HANDLE  ProtocolBindingContext);
    00745
    00754 VOID
    00755 NPF_Unload(IN PDRIVER_OBJECT DriverObject);
    00756
    00757
    00776 NTSTATUS
    00777 NPF_Read(
    00778     IN PDEVICE_OBJECT DeviceObject,
    00779     IN PIRP Irp
    00780     );
    00781
    00787 NTSTATUS
    00788 NPF_ReadRegistry(
    00789     IN  PWSTR              *MacDriverName,
    00790     IN  PWSTR              *PacketDriverName,
    00791     IN  PUNICODE_STRING     RegistryPath
    00792     );
    00793
    00800 NTSTATUS
    00801 NPF_QueryRegistryRoutine(
    00802     IN PWSTR     ValueName,
    00803     IN ULONG     ValueType,
    00804     IN PVOID     ValueData,
    00805     IN ULONG     ValueLength,
    00806     IN PVOID     Context,
    00807     IN PVOID     EntryContext
    00808     );
    00809
    00815 VOID NPF_BindAdapter(
    00816     OUT PNDIS_STATUS            Status,
    00817     IN  NDIS_HANDLE             BindContext,
    00818     IN  PNDIS_STRING            DeviceName,
    00819     IN  PVOID                   SystemSpecific1,
    00820     IN  PVOID                   SystemSpecific2
    00821     );
    00822
    00834 VOID
    00835 NPF_UnbindAdapter(
    00836     OUT PNDIS_STATUS        Status,
    00837     IN  NDIS_HANDLE         ProtocolBindingContext,
    00838     IN  NDIS_HANDLE         UnbindContext
    00839     );
    00840
    00853 int bpf_validate(struct bpf_insn *f,int len, uint32 mem_ex_size);
    00854
    00871 UINT bpf_filter(register struct bpf_insn *pc,
    00872                 register UCHAR *p,
    00873                 UINT wirelen,
    00874                 register UINT buflen,
    00875                 PMEM_TYPE mem_ex,
    00876                 PTME_CORE tme,
    00877                 struct time_conv *time_ref);
    00878
    00896 UINT bpf_filter_with_2_buffers(register struct bpf_insn *pc,
    00897                                register UCHAR *p,
    00898                                register UCHAR *pd,
    00899                                register int headersize,
    00900                                UINT wirelen,
    00901                                register UINT buflen,
    00902                                PMEM_TYPE mem_ex,
    00903                                PTME_CORE tme,
    00904                                struct time_conv *time_ref);
    00905
    00913 NTSTATUS NPF_OpenDumpFile(POPEN_INSTANCE Open , PUNICODE_STRING fileName, BOOLEAN append);
    00914
    00923 NTSTATUS NPF_StartDump(POPEN_INSTANCE Open);
    00924
    00932 VOID NPF_DumpThread(PVOID Open);
    00933
    00940 NTSTATUS NPF_SaveCurrentBuffer(POPEN_INSTANCE Open);
    00941
    00954 VOID NPF_WriteDumpFile(PFILE_OBJECT FileObject,
    00955                                 PLARGE_INTEGER Offset,
    00956                                 ULONG Length,
    00957                                 PMDL Mdl,
    00958                                 PIO_STATUS_BLOCK IoStatusBlock);
    00959
    00960
    00961
    00967 NTSTATUS NPF_CloseDumpFile(POPEN_INSTANCE Open);
    00968
    00973 UINT GetBuffOccupation(POPEN_INSTANCE Open);
    00974
    00986 #ifdef NDIS50
    00987 NDIS_STATUS NPF_PowerChange(IN NDIS_HANDLE ProtocolBindingContext, IN PNET_PNP_EVENT pNetPnPEvent);
    00988 #endif
    00989
    00998 #endif  /*main ifndef/define*/

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