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, 2000
    00003  *  Politecnico di Torino.  All rights reserved.
    00004  *
    00005  * Redistribution and use in source and binary forms, with or without
    00006  * modification, are permitted provided that: (1) source code distributions
    00007  * retain the above copyright notice and this paragraph in its entirety, (2)
    00008  * distributions including binary code include the above copyright notice and
    00009  * this paragraph in its entirety in the documentation or other materials
    00010  * provided with the distribution, and (3) all advertising materials mentioning
    00011  * features or use of this software display the following acknowledgement:
    00012  * ``This product includes software developed by the Politecnico
    00013  * di Torino, and its contributors.'' Neither the name of
    00014  * the University nor the names of its contributors may be used to endorse
    00015  * or promote products derived from this software without specific prior
    00016  * written permission.
    00017  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
    00018  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
    00019  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00020  */
    00021
    00030 #ifndef __PACKET_INCLUDE______
    00031 #define __PACKET_INCLUDE______
    00032
    00033 #define NTKERNEL
    00034
    00035 #include "jitter.h"
    00036 #include "tme.h"
    00037 #include "win_bpf.h"
    00038
    00039 #define  MAX_REQUESTS   32
    00040
    00041 #define Packet_ALIGNMENT sizeof(int)
    00042 #define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
    00043
    00044 /***************************/
    00045 /*         IOCTLs          */
    00046 /***************************/
    00047
    00056 #define  BIOCSETBUFFERSIZE 9592
    00057
    00068 #define  BIOCSETF 9030
    00069
    00076 #define  BIOCGSTATS 9031
    00077
    00083 #define  BIOCSRTIMEOUT 7416
    00084
    00092 #define  BIOCSMODE 7412
    00093
    00100 #define  BIOCSWRITEREP 7413
    00101
    00107 #define  BIOCSMINTOCOPY 7414
    00108
    00114 #define  BIOCSETOID 2147483648
    00115
    00121 #define  BIOCQUERYOID 2147483652
    00122
    00130 #define  BIOCSETDUMPFILENAME 9029
    00131
    00138 #define  BIOCGEVNAME 7415
    00139
    00147 #define  BIOCSENDPACKETSNOSYNC 9032
    00148
    00157 #define  BIOCSENDPACKETSSYNC 9033
    00158
    00165 #define  BIOCSETDUMPLIMITS 9034
    00166
    00173 #define BIOCISDUMPENDED 7411
    00174
    00175 // Working modes
    00176 #define MODE_CAPT 0x0
    00177 #define MODE_STAT 0x1
    00178 #define MODE_MON  0x2
    00179 #define MODE_DUMP 0x10
    00180
    00181
    00182 #define IMMEDIATE 1
    00183
    00184
    00185 // The following definitions are used to provide compatibility
    00186 // of the dump files with the ones of libpcap
    00187 #define TCPDUMP_MAGIC 0xa1b2c3d4
    00188 #define PCAP_VERSION_MAJOR 2
    00189 #define PCAP_VERSION_MINOR 4
    00190
    00191
    00196 struct packet_file_header
    00197 {
    00198     UINT magic;
    00199     USHORT version_major;
    00200     USHORT version_minor;
    00201     UINT thiszone;
    00202     UINT sigfigs;
    00203     UINT snaplen;
    00204     UINT linktype;
    00205 };
    00206
    00211 struct sf_pkthdr {
    00212     struct timeval  ts;
    00213     UINT            caplen;
    00214
    00215
    00216     UINT            len;
    00217 };
    00218
    00228 typedef struct _INTERNAL_REQUEST {
    00229     LIST_ENTRY      ListElement;
    00230     PIRP            Irp;
    00231     BOOLEAN         Internal;
    00232     NDIS_REQUEST    Request;
    00233 } INTERNAL_REQUEST, *PINTERNAL_REQUEST;
    00234
    00242 typedef struct _PACKET_RESERVED {
    00243     LIST_ENTRY      ListElement;
    00244     PIRP            Irp;
    00245     PMDL            pMdl;
    00246     BOOLEAN         FreeBufAfterWrite;
    00247
    00248     ULONG           Cpu;
    00249 }  PACKET_RESERVED, *PPACKET_RESERVED;
    00250
    00251 #define RESERVED(_p) ((PPACKET_RESERVED)((_p)->ProtocolReserved))
    00252
    00253
    00258 typedef struct _DEVICE_EXTENSION {
    00259     NDIS_HANDLE    NdisProtocolHandle;
    00260     NDIS_STRING    AdapterName;
    00261     PWSTR          ExportString;
    00262
    00263 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
    00264
    00270 typedef struct __CPU_Private_Data
    00271 {
    00272     ULONG   P;
    00273     ULONG   C;
    00274     ULONG   Free;
    00275     PUCHAR  Buffer;
    00276     ULONG   Accepted;
    00277
    00278
    00279
    00280     ULONG   Received;
    00281
    00282
    00283
    00284     ULONG   Dropped;
    00285
    00286
    00287
    00288     ULONG   Processing;
    00289     PMDL    TransferMdl1;
    00290     PMDL    TransferMdl2;
    00291     ULONG   NewP;
    00292 }
    00293     CpuPrivateData;
    00294
    00295
    00303 typedef struct _OPEN_INSTANCE
    00304 {
    00305     PDEVICE_EXTENSION   DeviceExtension;
    00306
    00307     NDIS_HANDLE         AdapterHandle;
    00308     UINT                Medium;
    00309
    00310     NDIS_HANDLE         PacketPool;
    00311     PIRP                OpenCloseIrp;
    00312
    00313     KSPIN_LOCK          RequestSpinLock;
    00314     LIST_ENTRY          RequestList;
    00315     LIST_ENTRY          ResetIrpList;
    00316     INTERNAL_REQUEST    Requests[MAX_REQUESTS];
    00317     PMDL                BufferMdl;
    00318     PKEVENT             ReadEvent;
    00319     HANDLE              ReadEventHandle;
    00320     UNICODE_STRING      ReadEventName;
    00321
    00322
    00323
    00324     PUCHAR              bpfprogram;
    00325
    00326
    00327
    00328
    00329     JIT_BPF_Filter      *Filter;
    00330
    00331     UINT                MinToCopy;
    00332
    00333     LARGE_INTEGER       TimeOut;
    00334
    00335
    00336     int                 mode;
    00337     LARGE_INTEGER       Nbytes;
    00338     LARGE_INTEGER       Npackets;
    00339     NDIS_SPIN_LOCK      CountersLock;
    00340     UINT                Nwrites;
    00341
    00342     UINT                Multiple_Write_Counter;
    00343     NDIS_EVENT          WriteEvent;
    00344     NDIS_EVENT          IOEvent;
    00345     NDIS_STATUS         IOStatus;
    00346     BOOLEAN             Bound;
    00347
    00348     HANDLE              DumpFileHandle;
    00349     PFILE_OBJECT        DumpFileObject;
    00350     PKTHREAD            DumpThreadObject;
    00351     HANDLE              DumpThreadHandle;
    00352     NDIS_EVENT          DumpEvent;
    00353     LARGE_INTEGER       DumpOffset;
    00354     UNICODE_STRING      DumpFileName;
    00355     UINT                MaxDumpBytes;
    00356
    00357     UINT                MaxDumpPacks;
    00358
    00359
    00360     BOOLEAN             DumpLimitReached;
    00361
    00362     MEM_TYPE            mem_ex;
    00363     TME_CORE            tme;
    00364     NDIS_SPIN_LOCK      MachineLock;
    00365     UINT                MaxFrameSize;
    00366
    00367     CpuPrivateData      CpuData[32];
    00368     ULONG               ReaderSN;
    00369     ULONG               WriterSN;
    00370
    00371     ULONG               Size;
    00372     ULONG               SkipProcessing;
    00373
    00374
    00375
    00376 }
    00377 OPEN_INSTANCE, *POPEN_INSTANCE;
    00378
    00386 struct PacketHeader
    00387 {
    00388     ULONG SN;
    00389     struct bpf_hdr header;
    00390 };
    00391
    00392
    00393 #define TRANSMIT_PACKETS 256
    00394
    00395
    00396
    00398 #define EXIT_SUCCESS(quantity) Irp->IoStatus.Information=quantity;\
    00399     Irp->IoStatus.Status = STATUS_SUCCESS;\
    00400     IoCompleteRequest(Irp, IO_NO_INCREMENT);\
    00401     return STATUS_SUCCESS;\
    00402
    00403
    00404 #define EXIT_FAILURE(quantity) Irp->IoStatus.Information=quantity;\
    00405     Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;\
    00406     IoCompleteRequest(Irp, IO_NO_INCREMENT);\
    00407     return STATUS_UNSUCCESSFUL;\
    00408
    00409
    00414 /***************************/
    00415 /*       Prototypes        */
    00416 /***************************/
    00417
    00434 NTSTATUS
    00435 DriverEntry(
    00436     IN PDRIVER_OBJECT DriverObject,
    00437     IN PUNICODE_STRING RegistryPath
    00438     );
    00439
    00449 PWCHAR getAdaptersList(VOID);
    00450
    00457 PKEY_VALUE_PARTIAL_INFORMATION getTcpBindings(VOID);
    00458
    00470 BOOLEAN createDevice(
    00471     IN OUT PDRIVER_OBJECT adriverObjectP,
    00472     IN PUNICODE_STRING amacNameP,
    00473     NDIS_HANDLE aProtoHandle);
    00474
    00486 NTSTATUS
    00487 NPF_Open(
    00488     IN PDEVICE_OBJECT DeviceObject,
    00489     IN PIRP Irp
    00490     );
    00491
    00501 VOID
    00502 NPF_OpenAdapterComplete(
    00503     IN NDIS_HANDLE  ProtocolBindingContext,
    00504     IN NDIS_STATUS  Status,
    00505     IN NDIS_STATUS  OpenErrorStatus
    00506     );
    00507
    00518 NTSTATUS
    00519 NPF_Close(
    00520     IN PDEVICE_OBJECT DeviceObject,
    00521     IN PIRP Irp
    00522     );
    00523
    00532 VOID
    00533 NPF_CloseAdapterComplete(
    00534     IN NDIS_HANDLE  ProtocolBindingContext,
    00535     IN NDIS_STATUS  Status
    00536     );
    00537
    00560 NDIS_STATUS
    00561 NPF_tap(
    00562     IN NDIS_HANDLE ProtocolBindingContext,
    00563     IN NDIS_HANDLE MacReceiveContext,
    00564     IN PVOID HeaderBuffer,
    00565     IN UINT HeaderBufferSize,
    00566     IN PVOID LookAheadBuffer,
    00567     IN UINT LookaheadBufferSize,
    00568     IN UINT PacketSize
    00569     );
    00570
    00581 VOID
    00582 NPF_TransferDataComplete(
    00583     IN NDIS_HANDLE ProtocolBindingContext,
    00584     IN PNDIS_PACKET Packet,
    00585     IN NDIS_STATUS Status,
    00586     IN UINT BytesTransferred
    00587     );
    00588
    00595 VOID
    00596 NPF_ReceiveComplete(IN NDIS_HANDLE  ProtocolBindingContext);
    00597
    00621 NTSTATUS
    00622 NPF_IoControl(
    00623     IN PDEVICE_OBJECT DeviceObject,
    00624     IN PIRP Irp
    00625     );
    00626
    00627 VOID
    00628
    00638 NPF_RequestComplete(
    00639     IN NDIS_HANDLE   ProtocolBindingContext,
    00640     IN PNDIS_REQUEST pRequest,
    00641     IN NDIS_STATUS   Status
    00642     );
    00643
    00656 NTSTATUS
    00657 NPF_Write(
    00658             IN PDEVICE_OBJECT DeviceObject,
    00659             IN PIRP Irp
    00660             );
    00661
    00662
    00681 INT NPF_BufferedWrite(IN PIRP Irp,
    00682                         IN PCHAR UserBuff,
    00683                         IN ULONG UserBuffSize,
    00684                         BOOLEAN sync);
    00685
    00695 VOID
    00696 NPF_SendComplete(
    00697     IN NDIS_HANDLE   ProtocolBindingContext,
    00698     IN PNDIS_PACKET  pPacket,
    00699     IN NDIS_STATUS   Status
    00700     );
    00701
    00711 VOID
    00712 NPF_ResetComplete(
    00713     IN NDIS_HANDLE  ProtocolBindingContext,
    00714     IN NDIS_STATUS  Status
    00715     );
    00716
    00720 VOID
    00721 NPF_Status(
    00722     IN NDIS_HANDLE   ProtocolBindingContext,
    00723     IN NDIS_STATUS   Status,
    00724     IN PVOID         StatusBuffer,
    00725     IN UINT          StatusBufferSize
    00726     );
    00727
    00728
    00732 VOID
    00733 NPF_StatusComplete(IN NDIS_HANDLE  ProtocolBindingContext);
    00734
    00743 VOID
    00744 NPF_Unload(IN PDRIVER_OBJECT DriverObject);
    00745
    00746
    00765 NTSTATUS
    00766 NPF_Read(
    00767     IN PDEVICE_OBJECT DeviceObject,
    00768     IN PIRP Irp
    00769     );
    00770
    00776 NTSTATUS
    00777 NPF_ReadRegistry(
    00778     IN  PWSTR              *MacDriverName,
    00779     IN  PWSTR              *PacketDriverName,
    00780     IN  PUNICODE_STRING     RegistryPath
    00781     );
    00782
    00789 NTSTATUS
    00790 NPF_QueryRegistryRoutine(
    00791     IN PWSTR     ValueName,
    00792     IN ULONG     ValueType,
    00793     IN PVOID     ValueData,
    00794     IN ULONG     ValueLength,
    00795     IN PVOID     Context,
    00796     IN PVOID     EntryContext
    00797     );
    00798
    00804 VOID NPF_BindAdapter(
    00805     OUT PNDIS_STATUS            Status,
    00806     IN  NDIS_HANDLE             BindContext,
    00807     IN  PNDIS_STRING            DeviceName,
    00808     IN  PVOID                   SystemSpecific1,
    00809     IN  PVOID                   SystemSpecific2
    00810     );
    00811
    00823 VOID
    00824 NPF_UnbindAdapter(
    00825     OUT PNDIS_STATUS        Status,
    00826     IN  NDIS_HANDLE         ProtocolBindingContext,
    00827     IN  NDIS_HANDLE         UnbindContext
    00828     );
    00829
    00842 int bpf_validate(struct bpf_insn *f,int len, uint32 mem_ex_size);
    00843
    00860 UINT bpf_filter(register struct bpf_insn *pc,
    00861                 register UCHAR *p,
    00862                 UINT wirelen,
    00863                 register UINT buflen,
    00864                 PMEM_TYPE mem_ex,
    00865                 PTME_CORE tme,
    00866                 struct time_conv *time_ref);
    00867
    00885 UINT bpf_filter_with_2_buffers(register struct bpf_insn *pc,
    00886                                register UCHAR *p,
    00887                                register UCHAR *pd,
    00888                                register int headersize,
    00889                                UINT wirelen,
    00890                                register UINT buflen,
    00891                                PMEM_TYPE mem_ex,
    00892                                PTME_CORE tme,
    00893                                struct time_conv *time_ref);
    00894
    00902 NTSTATUS NPF_OpenDumpFile(POPEN_INSTANCE Open , PUNICODE_STRING fileName, BOOLEAN append);
    00903
    00912 NTSTATUS NPF_StartDump(POPEN_INSTANCE Open);
    00913
    00921 VOID NPF_DumpThread(PVOID Open);
    00922
    00929 NTSTATUS NPF_SaveCurrentBuffer(POPEN_INSTANCE Open);
    00930
    00943 VOID NPF_WriteDumpFile(PFILE_OBJECT FileObject,
    00944                                 PLARGE_INTEGER Offset,
    00945                                 ULONG Length,
    00946                                 PMDL Mdl,
    00947                                 PIO_STATUS_BLOCK IoStatusBlock);
    00948
    00949
    00950
    00956 NTSTATUS NPF_CloseDumpFile(POPEN_INSTANCE Open);
    00957
    00962 UINT GetBuffOccupation(POPEN_INSTANCE Open);
    00963
    00975 #ifdef NDIS50
    00976 NDIS_STATUS NPF_PowerChange(IN NDIS_HANDLE ProtocolBindingContext, IN PNET_PNP_EVENT pNetPnPEvent);
    00977 #endif
    00978
    00987 #endif  /*main ifndef/define*/

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