]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WinPCap/Packet32.h
Fix spelling issues.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_IoT_Libraries / mqtt / WinPCap / Packet32.h
1 /*\r
2  * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)\r
3  * Copyright (c) 2005 - 2007 CACE Technologies, Davis (California)\r
4  * All rights reserved.\r
5  *\r
6  * Redistribution and use in source and binary forms, with or without\r
7  * modification, are permitted provided that the following conditions\r
8  * are met:\r
9  *\r
10  * 1. Redistributions of source code must retain the above copyright\r
11  * notice, this list of conditions and the following disclaimer.\r
12  * 2. Redistributions in binary form must reproduce the above copyright\r
13  * notice, this list of conditions and the following disclaimer in the\r
14  * documentation and/or other materials provided with the distribution.\r
15  * 3. Neither the name of the Politecnico di Torino, CACE Technologies \r
16  * nor the names of its contributors may be used to endorse or promote \r
17  * products derived from this software without specific prior written \r
18  * permission.\r
19  *\r
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31  *\r
32  */\r
33 \r
34 /** @ingroup packetapi\r
35  *  @{ \r
36  */\r
37 \r
38 /** @defgroup packet32h Packet.dll definitions and data structures\r
39  *  Packet32.h contains the data structures and the definitions used by packet.dll.\r
40  *  The file is used both by the Win9x and the WinNTx versions of packet.dll, and can be included\r
41  *  by the applications that use the functions of this library\r
42  *  @{\r
43  */\r
44 \r
45 #ifndef __PACKET32\r
46 #define __PACKET32\r
47 \r
48 #include <winsock2.h>\r
49 \r
50 #ifdef HAVE_AIRPCAP_API\r
51 #include <airpcap.h>\r
52 #else\r
53 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)\r
54 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_\r
55 typedef struct _AirpcapHandle *PAirpcapHandle;\r
56 #endif /* AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ */\r
57 #endif /* HAVE_AIRPCAP_API */\r
58 \r
59 #ifdef HAVE_DAG_API\r
60 #include <dagc.h>\r
61 #endif /* HAVE_DAG_API */\r
62 \r
63 // Working modes\r
64 #define PACKET_MODE_CAPT 0x0 ///< Capture mode\r
65 #define PACKET_MODE_STAT 0x1 ///< Statistical mode\r
66 #define PACKET_MODE_MON 0x2 ///< Monitoring mode\r
67 #define PACKET_MODE_DUMP 0x10 ///< Dump mode\r
68 #define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT ///< Statistical dump Mode\r
69 \r
70 \r
71 /// Alignment macro. Defines the alignment size.\r
72 #define Packet_ALIGNMENT sizeof(int)\r
73 /// Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT. \r
74 #define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))\r
75 \r
76 #define NdisMediumNull  -1              ///< Custom linktype: NDIS doesn't provide an equivalent\r
77 #define NdisMediumCHDLC -2              ///< Custom linktype: NDIS doesn't provide an equivalent\r
78 #define NdisMediumPPPSerial     -3      ///< Custom linktype: NDIS doesn't provide an equivalent\r
79 #define NdisMediumBare80211     -4      ///< Custom linktype: NDIS doesn't provide an equivalent\r
80 #define NdisMediumRadio80211    -5      ///< Custom linktype: NDIS doesn't provide an equivalent\r
81 #define NdisMediumPpi           -6      ///< Custom linktype: NDIS doesn't provide an equivalent\r
82 \r
83 // Loopback behaviour definitions\r
84 #define NPF_DISABLE_LOOPBACK    1       ///< Drop the packets sent by the NPF driver\r
85 #define NPF_ENABLE_LOOPBACK             2       ///< Capture the packets sent by the NPF driver\r
86 \r
87 /*!\r
88   \brief Network type structure.\r
89 \r
90   This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.\r
91 */\r
92 typedef struct NetType\r
93 {\r
94         UINT LinkType;  ///< The MAC of the current network adapter (see function PacketGetNetType() for more information)\r
95         ULONGLONG LinkSpeed;    ///< The speed of the network in bits per second\r
96 }NetType;\r
97 \r
98 \r
99 //some definitions stolen from libpcap\r
100 \r
101 #ifndef BPF_MAJOR_VERSION\r
102 \r
103 /*!\r
104   \brief A BPF pseudo-assembly program.\r
105 \r
106   The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet. \r
107 */\r
108 struct bpf_program \r
109 {\r
110         UINT bf_len;                            ///< Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow.\r
111         struct bpf_insn *bf_insns;      ///< A pointer to the first instruction of the program.\r
112 };\r
113 \r
114 /*!\r
115   \brief A single BPF pseudo-instruction.\r
116 \r
117   bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver.\r
118 */\r
119 struct bpf_insn \r
120 {\r
121         USHORT  code;           ///< Instruction type and addressing mode.\r
122         UCHAR   jt;                     ///< Jump if true\r
123         UCHAR   jf;                     ///< Jump if false\r
124         int k;                          ///< Generic field used for various purposes.\r
125 };\r
126 \r
127 /*!\r
128   \brief Structure that contains a couple of statistics values on the current capture.\r
129 \r
130   It is used by packet.dll to return statistics about a capture session.\r
131 */\r
132 struct bpf_stat \r
133 {\r
134         UINT bs_recv;           ///< Number of packets that the driver received from the network adapter \r
135                                                 ///< from the beginning of the current capture. This value includes the packets \r
136                                                 ///< lost by the driver.\r
137         UINT bs_drop;           ///< number of packets that the driver lost from the beginning of a capture. \r
138                                                 ///< Basically, a packet is lost when the the buffer of the driver is full. \r
139                                                 ///< In this situation the packet cannot be stored and the driver rejects it.\r
140         UINT ps_ifdrop;         ///< drops by interface. XXX not yet supported\r
141         UINT bs_capt;           ///< number of packets that pass the filter, find place in the kernel buffer and\r
142                                                 ///< thus reach the application.\r
143 };\r
144 \r
145 /*!\r
146   \brief Packet header.\r
147 \r
148   This structure defines the header associated with every packet delivered to the application.\r
149 */\r
150 struct bpf_hdr \r
151 {\r
152         struct timeval  bh_tstamp;      ///< The timestamp associated with the captured packet. \r
153                                                                 ///< It is stored in a TimeVal structure.\r
154         UINT    bh_caplen;                      ///< Length of captured portion. The captured portion <b>can be different</b>\r
155                                                                 ///< from the original packet, because it is possible (with a proper filter)\r
156                                                                 ///< to instruct the driver to capture only a portion of the packets.\r
157         UINT    bh_datalen;                     ///< Original length of packet\r
158         USHORT          bh_hdrlen;              ///< Length of bpf header (this struct plus alignment padding). In some cases,\r
159                                                                 ///< a padding could be added between the end of this structure and the packet\r
160                                                                 ///< data for performance reasons. This filed can be used to retrieve the actual data \r
161                                                                 ///< of the packet.\r
162 };\r
163 \r
164 /*!\r
165   \brief Dump packet header.\r
166 \r
167   This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets().\r
168   It is simpler than the bpf_hdr, because it corresponds to the header associated by WinPcap and libpcap to a\r
169   packet in a dump file. This makes straightforward sending WinPcap dump files to the network.\r
170 */\r
171 struct dump_bpf_hdr{\r
172     struct timeval      ts;                     ///< Time stamp of the packet\r
173     UINT                        caplen;         ///< Length of captured portion. The captured portion can smaller than the \r
174                                                                 ///< the original packet, because it is possible (with a proper filter) to \r
175                                                                 ///< instruct the driver to capture only a portion of the packets. \r
176     UINT                        len;            ///< Length of the original packet (off wire).\r
177 };\r
178 \r
179 \r
180 #endif\r
181 \r
182 struct bpf_stat;\r
183 \r
184 #define        DOSNAMEPREFIX   TEXT("Packet_")  ///< Prefix added to the adapters device names to create the WinPcap devices\r
185 #define        MAX_LINK_NAME_LENGTH     64                      //< Maximum length of the devices symbolic links\r
186 #define        NMAX_PACKET 65535\r
187 \r
188 /*!\r
189   \brief Addresses of a network adapter.\r
190 \r
191   This structure is used by the PacketGetNetInfoEx() function to return the IP addresses associated with \r
192   an adapter.\r
193 */\r
194 typedef struct npf_if_addr {\r
195         struct sockaddr_storage IPAddress;      ///< IP address.\r
196         struct sockaddr_storage SubnetMask;     ///< Netmask for that address.\r
197         struct sockaddr_storage Broadcast;      ///< Broadcast address.\r
198 }npf_if_addr;\r
199 \r
200 \r
201 #define ADAPTER_NAME_LENGTH 256 + 12    ///<  Maximum length for the name of an adapter. The value is the same used by the IP Helper API.\r
202 #define ADAPTER_DESC_LENGTH 128                 ///<  Maximum length for the description of an adapter. The value is the same used by the IP Helper API.\r
203 #define MAX_MAC_ADDR_LENGTH 8                   ///<  Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.\r
204 #define MAX_NETWORK_ADDRESSES 16                ///<  Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.\r
205 \r
206 \r
207 typedef struct WAN_ADAPTER_INT WAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API\r
208 typedef WAN_ADAPTER *PWAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API\r
209 \r
210 #define INFO_FLAG_NDIS_ADAPTER          0       ///< Flag for ADAPTER_INFO: this is a traditional ndis adapter\r
211 #define INFO_FLAG_NDISWAN_ADAPTER       1       ///< Flag for ADAPTER_INFO: this is a NdisWan adapter, and it's managed by WANPACKET\r
212 #define INFO_FLAG_DAG_CARD                      2       ///< Flag for ADAPTER_INFO: this is a DAG card\r
213 #define INFO_FLAG_DAG_FILE                      6       ///< Flag for ADAPTER_INFO: this is a DAG file\r
214 #define INFO_FLAG_DONT_EXPORT           8       ///< Flag for ADAPTER_INFO: when this flag is set, the adapter will not be listed or openend by winpcap. This allows to prevent exporting broken network adapters, like for example FireWire ones.\r
215 #define INFO_FLAG_AIRPCAP_CARD          16      ///< Flag for ADAPTER_INFO: this is an airpcap card\r
216 #define INFO_FLAG_NPFIM_DEVICE          32\r
217 \r
218 /*!\r
219   \brief Describes an opened network adapter.\r
220 \r
221   This structure is the most important for the functioning of packet.dll, but the great part of its fields\r
222   should be ignored by the user, since the library offers functions that avoid to cope with low-level parameters\r
223 */\r
224 typedef struct _ADAPTER  { \r
225         HANDLE hFile;                           ///< \internal Handle to an open instance of the NPF driver.\r
226         CHAR  SymbolicLink[MAX_LINK_NAME_LENGTH]; ///< \internal A string containing the name of the network adapter currently opened.\r
227         int NumWrites;                          ///< \internal Number of times a packets written on this adapter will be repeated \r
228                                                                 ///< on the wire.\r
229         HANDLE ReadEvent;                       ///< A notification event associated with the read calls on the adapter.\r
230                                                                 ///< It can be passed to standard Win32 functions (like WaitForSingleObject\r
231                                                                 ///< or WaitForMultipleObjects) to wait until the driver's buffer contains some \r
232                                                                 ///< data. It is particularly useful in GUI applications that need to wait \r
233                                                                 ///< concurrently on several events. In Windows NT/2000 the PacketSetMinToCopy()\r
234                                                                 ///< function can be used to define the minimum amount of data in the kernel buffer\r
235                                                                 ///< that will cause the event to be signalled. \r
236         \r
237         UINT ReadTimeOut;                       ///< \internal The amount of time after which a read on the driver will be released and \r
238                                                                 ///< ReadEvent will be signaled, also if no packets were captured\r
239         CHAR Name[ADAPTER_NAME_LENGTH];\r
240         PWAN_ADAPTER pWanAdapter;\r
241         UINT Flags;                                     ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.\r
242 \r
243 #ifdef HAVE_AIRPCAP_API\r
244         PAirpcapHandle  AirpcapAd;\r
245 #endif // HAVE_AIRPCAP_API\r
246 \r
247 #ifdef HAVE_NPFIM_API\r
248         void* NpfImHandle;\r
249 #endif // HAVE_NPFIM_API\r
250 \r
251 #ifdef HAVE_DAG_API\r
252         dagc_t *pDagCard;                       ///< Pointer to the dagc API adapter descriptor for this adapter\r
253         PCHAR DagBuffer;                        ///< Pointer to the buffer with the packets that is received from the DAG card\r
254         struct timeval DagReadTimeout;  ///< Read timeout. The dagc API requires a timeval structure\r
255         unsigned DagFcsLen;                     ///< Length of the frame check sequence attached to any packet by the card. Obtained from the registry\r
256         DWORD DagFastProcess;           ///< True if the user requests fast capture processing on this card. Higher level applications can use this value to provide a faster but possibly unprecise capture (for example, libpcap doesn't convert the timestamps).\r
257 #endif // HAVE_DAG_API\r
258 }  ADAPTER, *LPADAPTER;\r
259 \r
260 /*!\r
261   \brief Structure that contains a group of packets coming from the driver.\r
262 \r
263   This structure defines the header associated with every packet delivered to the application.\r
264 */\r
265 typedef struct _PACKET {  \r
266         HANDLE       hEvent;            ///< \deprecated Still present for compatibility with old applications.\r
267         OVERLAPPED   OverLapped;        ///< \deprecated Still present for compatibility with old applications.\r
268         PVOID        Buffer;            ///< Buffer with containing the packets. See the PacketReceivePacket() for\r
269                                                                 ///< details about the organization of the data in this buffer\r
270         UINT         Length;            ///< Length of the buffer\r
271         DWORD        ulBytesReceived;   ///< Number of valid bytes present in the buffer, i.e. amount of data\r
272                                                                         ///< received by the last call to PacketReceivePacket()\r
273         BOOLEAN      bIoComplete;       ///< \deprecated Still present for compatibility with old applications.\r
274 }  PACKET, *LPPACKET;\r
275 \r
276 /*!\r
277   \brief Structure containing an OID request.\r
278 \r
279   It is used by the PacketRequest() function to send an OID to the interface card driver. \r
280   It can be used, for example, to retrieve the status of the error counters on the adapter, its MAC address, \r
281   the list of the multicast groups defined on it, and so on.\r
282 */\r
283 struct _PACKET_OID_DATA {\r
284     ULONG Oid;                                  ///< OID code. See the Microsoft DDK documentation or the file ntddndis.h\r
285                                                                 ///< for a complete list of valid codes.\r
286     ULONG Length;                               ///< Length of the data field\r
287     UCHAR Data[1];                              ///< variable-lenght field that contains the information passed to or received \r
288                                                                 ///< from the adapter.\r
289 }; \r
290 typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;\r
291 \r
292 #ifdef __cplusplus\r
293 extern "C" {\r
294 #endif\r
295 \r
296 /**\r
297  *  @}\r
298  */\r
299 \r
300 /*\r
301 BOOLEAN QueryWinPcapRegistryStringA(CHAR *SubKeyName,\r
302                                                                  CHAR *Value,\r
303                                                                  UINT *pValueLen,\r
304                                                                  CHAR *DefaultVal);\r
305 \r
306 BOOLEAN QueryWinPcapRegistryStringW(WCHAR *SubKeyName,\r
307                                                                  WCHAR *Value,\r
308                                                                  UINT *pValueLen,\r
309                                                                  WCHAR *DefaultVal);\r
310 */\r
311                                                                  \r
312 //---------------------------------------------------------------------------\r
313 // EXPORTED FUNCTIONS\r
314 //---------------------------------------------------------------------------\r
315 \r
316 PCHAR PacketGetVersion();\r
317 PCHAR PacketGetDriverVersion();\r
318 BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);\r
319 BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);\r
320 BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);\r
321 BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);\r
322 BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);\r
323 BOOLEAN PacketSetLoopbackBehavior(LPADAPTER  AdapterObject, UINT LoopbackBehavior);\r
324 INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);\r
325 BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);\r
326 BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);\r
327 BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);\r
328 BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);\r
329 LPADAPTER PacketOpenAdapter(PCHAR AdapterName);\r
330 BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);\r
331 INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);\r
332 LPPACKET PacketAllocatePacket(void);\r
333 VOID PacketInitPacket(LPPACKET lpPacket,PVOID  Buffer,UINT  Length);\r
334 VOID PacketFreePacket(LPPACKET lpPacket);\r
335 BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);\r
336 BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);\r
337 BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG  BufferSize);\r
338 BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);\r
339 BOOLEAN PacketRequest(LPADAPTER  AdapterObject,BOOLEAN Set,PPACKET_OID_DATA  OidData);\r
340 HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);\r
341 BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);\r
342 BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);\r
343 BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);\r
344 BOOL PacketStopDriver();\r
345 VOID PacketCloseAdapter(LPADAPTER lpAdapter);\r
346 BOOLEAN PacketStartOem(PCHAR errorString, UINT errorStringLength);\r
347 BOOLEAN PacketStartOemEx(PCHAR errorString, UINT errorStringLength, ULONG flags);\r
348 PAirpcapHandle PacketGetAirPcapHandle(LPADAPTER AdapterObject);\r
349 \r
350 //\r
351 // Used by PacketStartOemEx\r
352 //\r
353 #define PACKET_START_OEM_NO_NETMON      0x00000001\r
354 \r
355 #ifdef __cplusplus\r
356 }\r
357 #endif \r
358 \r
359 #endif //__PACKET32\r