From LI Hai via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8708 :
[metze/wireshark/wip.git] / airpcap.h
1 /*
2  * Copyright (c) 2006-2007 CACE Technologies, Davis (California)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted.
7  *
8  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
10  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
15  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
16  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
17  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
18  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19  *
20  */
21
22 #if !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_)
23 #define AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_
24
25 #ifdef _MSC_VER
26 /* This disables a VS warning for zero-sized arrays. */
27 #pragma warning( disable : 4200)
28 /* This stops VS2005 ranting against stdio. */
29 #pragma warning( disable : 4996)
30 #endif
31
32 #ifdef HAVE_WINSOCK2_H
33 #include <winsock2.h>
34 #endif
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /*
41     \mainpage AirPcap interface documentation
42
43     \section Introduction
44
45     This document describes the data structures and the functions exported by the CACE Technologies AirPcap library.
46     The AirPcap library provides low-level access to the AirPcap driver including advanced capabilities such as channel setting,
47     link type control and WEP configuration.<br>
48     This manual includes the following sections:
49
50     \note throughout this documentation, \e device refers to a physical USB AirPcap device, while \e adapter is an open API
51     instance. Most of the AirPcap API operations are adapter-specific but some of them, like setting the channel, are
52     per-device and will be reflected on all the open adapters. These functions will have "Device" in their name, e.g.
53     AirpcapSetDeviceChannel().
54
55     \b Sections:
56
57     - \ref airpcapfuncs
58     - \ref airpcapdefs
59     - \ref radiotap
60 */
61
62 /** @defgroup airpcapdefs AirPcap definitions and data structures
63  *  @{
64  */
65
66 /*!
67   \brief This string is the fixed prefix in the airpcap adapter name.
68   It can be used to parse the name field in an AirpcapDeviceDescription structure.
69 */
70 #define AIRPCAP_DEVICE_NAME_PREFIX        "\\\\.\\airpcap"
71
72 /*!
73   \brief This string is the scanf modifier to extract the adapter number from an adapter name.
74   It can be used to parse the name field in an AirpcapDeviceDescription structure with scanf.
75 */
76 #define AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING         "\\\\.\\airpcap%u"
77
78 #define AIRPCAP_DEVICE_ANY_EXTRACT_STRING "\\\\.\\airpcap_any"
79
80 /*!
81   \brief Entry in the list returned by \ref AirpcapGetDeviceList();
82 */
83 typedef struct _AirpcapDeviceDescription
84 {
85     struct    _AirpcapDeviceDescription *next;  /* < Next element in the list */
86     gchar *    Name;                            /* < Device name */
87     gchar *    Description;                     /* < Device description */
88 } AirpcapDeviceDescription, *PAirpcapDeviceDescription;
89
90 #define MAX_ENCRYPTION_KEYS 64
91
92 #define WEP_KEY_MAX_SIZE 32        /* < Maximum size of a WEP key, in bytes. This is the size of an entry in the
93                                       < AirpcapWepKeysCollection structure. */
94
95 #ifdef _WIN32
96 #ifndef __MINGW32__
97 #pragma pack(push)
98 #pragma pack(1)
99 #endif
100 #endif
101
102 #define AIRPCAP_KEYTYPE_WEP    0    /* < Key type: WEP. The key can have an arbitrary length smaller than 32 bytes. */
103 #define AIRPCAP_KEYTYPE_TKIP   1    /* < Key type: TKIP (WPA). NOT SUPPORTED YET. */
104 #define AIRPCAP_KEYTYPE_CCMP   2    /* < Key type: CCMP (WPA2). NOT SUPPORTED YET. */
105
106 /*!
107   \brief WEP key container
108 */
109 typedef struct _AirpcapKey
110 {
111     guint KeyType;                    /* < Type of key, can be on of: \ref AIRPCAP_KEYTYPE_WEP, \ref AIRPCAP_KEYTYPE_TKIP, \ref AIRPCAP_KEYTYPE_CCMP. Only AIRPCAP_KEYTYPE_WEP is supported by the driver at the moment. */
112     guint KeyLen;                     /* < Length of the key, in bytes */
113     guint8 KeyData[WEP_KEY_MAX_SIZE]; /* < Key Data */
114 }
115 #ifdef __MINGW32__
116 __attribute__((__packed__))
117 #endif
118 AirpcapKey, *PAirpcapKey;
119
120 /*!
121   \brief frequency Band.
122    802.11 adapters can support different frequency bands, the most important of which are: 2.4GHz (802.11b/g/n)
123    and 5GHz (802.11a/n).
124 */
125 typedef enum _AirpcapChannelBand
126 {
127     AIRPCAP_CB_AUTO = 1,                /* < Automatically pick the best frequency band */
128     AIRPCAP_CB_2_4_GHZ = 2,             /* < 2.4 GHz frequency band */
129     AIRPCAP_CB_4_GHZ = 4,               /* < 4 GHz frequency band */
130     AIRPCAP_CB_5_GHZ = 5                /* < 5 GHz frequency band */
131 }AirpcapChannelBand, *PAirpcapChannelBand;
132
133 /*!
134   \brief Type of frame validation the adapter performs.
135    An adapter can be instructed to accept different kind of frames: correct frames only, frames with wrong Frame Check Sequence (FCS) only, all frames.
136 */
137 typedef enum _AirpcapValidationType
138 {
139     AIRPCAP_VT_ACCEPT_EVERYTHING = 1,     /* < Accept all the frames the device captures */
140     AIRPCAP_VT_ACCEPT_CORRECT_FRAMES = 2, /* < Accept correct frames only, i.e. frames with correct Frame Check Sequence (FCS). */
141     AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES = 3, /* < Accept corrupt frames only, i.e. frames with wrong Frame Check Sequence (FCS). */
142     AIRPCAP_VT_UNKNOWN = 4                /* < Unknown validation type. You should see it only in case of error. */
143 }AirpcapValidationType, *PAirpcapValidationType;
144
145 /*!
146   \brief Type of decryption the adapter performs.
147    An adapter can be instructed to turn decryption (based on the device-configured keys configured
148    with \ref AirpcapSetDeviceKeys()) on or off.
149 */
150 typedef enum _AirpcapDecryptionState
151 {
152     AIRPCAP_DECRYPTION_ON = 1,        /* < This adapter performs decryption */
153     AIRPCAP_DECRYPTION_OFF = 2        /* < This adapter does not perform decryption */
154 }AirpcapDecryptionState, *PAirpcapDecryptionState;
155
156
157 /*!
158   \brief Storage for a MAC address
159 */
160 typedef struct _AirpcapMacAddress
161 {
162     guint8 Address[6];        /* < MAC address bytes */
163 }
164 #ifdef __MINGW32__
165 __attribute__((__packed__))
166 #endif
167 AirpcapMacAddress, *PAirpcapMacAddress;
168
169 /*!
170   \brief This structure is used to store a collection of WEP keys.
171   Note that the definition of the structure has one key in it
172   (so that this code can be compiled by compilers that don't
173   support zero-length arrays), so be careful to allocate a buffer
174   with the size of the set of keys, as per the following example:
175
176   \code
177     PAirpcapKeysCollection KeysCollection;
178     guint KeysCollectionSize;
179
180     KeysCollectionSize = AirpcapKeysCollectionSize(NumKeys);
181
182     KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
183     if(!KeysCollection)
184     {
185         Error
186     }
187   \endcode
188 */
189 typedef struct _AirpcapKeysCollection
190 {
191     guint nKeys;                    /* < Number of keys in the collection */
192     AirpcapKey Keys[1];             /* < Array of nKeys keys. */
193 } AirpcapKeysCollection, *PAirpcapKeysCollection;
194
195 #define AirpcapKeysCollectionSize(nKeys) \
196         ((sizeof(AirpcapKeysCollection) - sizeof(AirpcapKey)) + ((nKeys) * sizeof(AirpcapKey)))
197 #define AirpcapKeysCollectionSizeToKeyCount(size) \
198         (guint)(((size) - AirpcapKeysCollectionSize(0))/sizeof(AirpcapKey))
199
200 /*!
201   \brief Packet header.
202
203   This structure defines the BPF that precedes every packet delivered to the application.
204 */
205 typedef struct _AirpcapBpfHeader
206 {
207     guint TsSec;        /* < Timestamp associated with the captured packet. SECONDS. */
208     guint TsUsec;       /* < Timestamp associated with the captured packet. MICROSECONDS. */
209     guint Caplen;       /* < Length of captured portion. The captured portion <b>can be different</b> from the original packet, because it is possible (with a proper filter) to instruct the driver to capture only a portion of the packets. */
210     guint Originallen;  /* < Original length of packet */
211     guint16 Hdrlen;     /* < Length of bpf header (this struct plus alignment padding). In some cases, a padding could be added between the end of this structure and the packet data for performance reasons. This field can be used to retrieve the actual data of the packet. */
212 }
213 #ifdef __MINGW32__
214 __attribute__((__packed__))
215 #endif
216 AirpcapBpfHeader, *PAirpcapBpfHeader;
217
218 /* Helper macros to extract packets coming from the driver. Rounds up to the next even multiple of AIRPCAP_ALIGNMENT. */
219 #define AIRPCAP_ALIGNMENT sizeof(int)
220 #define AIRPCAP_WORDALIGN(x) (((x)+(AIRPCAP_ALIGNMENT-1))&~(AIRPCAP_ALIGNMENT-1))
221
222 #ifdef _WIN32
223 #ifndef __MINGW32__
224 #pragma pack(pop)
225 #endif
226 #endif
227
228 #define AIRPCAP_ERRBUF_SIZE 512        /* < Size of the error buffer, in bytes */
229
230 #ifndef __AIRPCAP_DRIVER__
231
232 /*!
233   \brief Link type.
234    AirPcap supports two kind of 802.11 linktypes: plain 802.11 and radiotap.
235 */
236 #undef _AirpcapLinkType
237 typedef enum _AirpcapLinkType
238 {
239     AIRPCAP_LT_802_11 = 1,            /* < plain 802.11 linktype. Every packet in the buffer contains the raw 802.11 frame, including MAC FCS. */
240     AIRPCAP_LT_802_11_PLUS_RADIO = 2, /* < 802.11 plus radiotap linktype. Every packet in the buffer contains a radiotap header followed by the 802.11 frame. MAC FCS is included. */
241     AIRPCAP_LT_UNKNOWN = 3,           /* < Unknown linktype. You should see it only in case of error. */
242     AIRPCAP_LT_802_11_PLUS_PPI = 4    /* < 802.11 plus PPI header linktype. Every packet in the buffer contains a PPI header followed by the 802.11 frame. MAC FCS is included. */
243 }AirpcapLinkType, *PAirpcapLinkType;
244
245 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
246 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
247 /*!
248   \brief Adapter handle.
249 */
250 typedef struct _AirpcapHandle AirpcapHandle, *PAirpcapHandle;
251 #endif
252
253 /*!
254   \brief Capture statistics.
255    Returned by \ref AirpcapGetStats();
256 */
257 typedef struct _AirpcapStats
258 {
259     guint Recvs;        /* < Number of packets that the driver received by the adapter */
260                         /* < from the beginning of the current capture. This value includes the packets */
261                         /* < dropped because of buffer full. */
262     guint Drops;        /* < number of packets that the driver dropped from the beginning of a capture. */
263                         /* < A packet is lost when the the buffer of the driver is full. */
264     guint IfDrops;      /* < Packets dropped by the card before going to the USB bus. */
265                         /* < Not supported at the moment. */
266     guint Capt;         /* < number of packets that pass the BPF filter, find place in the kernel buffer and */
267                         /* < therefore reach the application. */
268 }AirpcapStats, *PAirpcapStats;
269
270 /*!
271   \brief Channel information.
272   Used by \ref AirpcapSetDeviceChannelEx(), \ref AirpcapGetDeviceChannelEx(), \ref AirpcapGetDeviceSupportedChannels()
273 */
274 typedef struct _AirpcapChannelInfo
275 {
276     guint Frequency;    /* < Channel frequency, in MHz. */
277     /*!
278         \brief 802.11n specific. Offset of the extension channel in case of 40MHz channels.
279
280         Possible values are -1, 0 +1:
281         - -1 means that the extension channel should be below the control channel (e.g. Control = 5 and Extension = 1)
282         - 0 means that no extension channel should be used (20MHz channels or legacy mode)
283         - +1 means that the extension channel should be above the control channel (e.g. Control = 1 and Extension = 5)
284
285         In case of 802.11a/b/g channels (802.11n legacy mode), this field should be set to 0.
286     */
287     gchar ExtChannel;
288     guint8 Reserved[3]; /* < Reserved. It should be set to {0,0,0}. */
289 }
290     AirpcapChannelInfo, *PAirpcapChannelInfo;
291
292
293 /*@}*/
294
295 /** @defgroup airpcapfuncs AirPcap functions
296  *  @{
297  */
298
299 /*!
300   \brief Return a string with the API version
301   \param VersionMajor Pointer to a variable that will be filled with the major version number.
302   \param VersionMinor Pointer to a variable that will be filled with the minor version number.
303   \param VersionRev Pointer to a variable that will be filled with the revision number.
304   \param VersionBuild Pointer to a variable that will be filled with the build number.
305 */
306 void AirpcapGetVersion(guint * VersionMajor, guint * VersionMinor, guint * VersionRev, guint * VersionBuild);
307
308 /*!
309   \brief Return the last error related to the specified handle
310   \param AdapterHandle Handle to an open adapter.
311   \return The string with the last error.
312 */
313 gchar * AirpcapGetLastError(PAirpcapHandle AdapterHandle);
314
315 /*!
316   \brief Return the list of available devices
317   \param PPAllDevs Address to a caller allocated pointer. On success this pointer will receive the head of a list of available devices.
318   \param Ebuf String that will contain error information if FALSE is returned. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
319   \return TRUE on success. FALSE is returned on failure, in which case Ebuf is filled in with an appropriate error message.
320
321     Here's a snippet of code that shows how to use AirpcapGetDeviceList():
322
323     \code
324     gchar Ebuf[AIRPCAP_ERRBUF_SIZE];
325     AirpcapDeviceDescription *Desc, *tDesc;
326
327     if(AirpcapGetDeviceList(&Desc, Ebuf) == -1)
328     {
329         printf("Unable to get the list of devices: %s\n", Ebuf);
330         return -1;
331     }
332
333     for(tDesc = Desc; tDesc; tDesc = tDesc->next)
334     {
335         printf("%u) %s (%s)\n",
336         ++i,
337         tDesc->Name,
338         tDesc->Description);
339     }
340
341     AirpcapFreeDeviceList(Desc);
342     \endcode
343 */
344 gboolean AirpcapGetDeviceList(PAirpcapDeviceDescription *PPAllDevs, gchar * Ebuf);
345
346 /*!
347   \brief Free a list of devices returned by AirpcapGetDeviceList()
348   \param PAllDevs Head of the list of devices returned by \ref AirpcapGetDeviceList().
349 */
350 void AirpcapFreeDeviceList(PAirpcapDeviceDescription PAllDevs);
351
352 /*!
353   \brief Open an adapter
354   \param DeviceName Name of the device to open. Use \ref AirpcapGetDeviceList() to get the list of devices.
355   \param Ebuf String that will contain error information in case of failure. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
356   \return A PAirpcapHandle handle on success. NULL is returned on failure, in which case Ebuf is filled in with an appropriate error message.
357 */
358 PAirpcapHandle AirpcapOpen(gchar * DeviceName, gchar * Ebuf);
359
360 /*!
361   \brief Close an adapter
362   \param AdapterHandle Handle to the adapter to close.
363 */
364 void AirpcapClose(PAirpcapHandle AdapterHandle);
365
366 /*!
367   \brief Sets the monitor mode for the specified adapter
368   \param AdapterHandle Handle to the adapter.
369   \param MonitorModeEnabled If TRUE, the adapter will be put in monitor mode. If FALSE, the adapter will be configured
370          for normal operation.
371   \return TRUE on success.
372
373   When monitor mode is on, the adapter captures all the packets transmitted on the channel. This includes:
374
375    - unicast packets
376    - multicast packets
377    - broadcast packets
378    - control and management packets
379
380   When monitor mode is off, the adapter has a filter on unicast packets to capture only the packets whose MAC
381   destination address equals to the adapter's address. This means the following frames will be received:
382
383    - unicast packets with the address of the adapter
384    - multicast packets
385    - broadcast packets
386    - beacons and probe requests
387
388   The main reason to turn monitor mode off is that, when not in monitor mode, the adapter will acknowledge the
389   data frames sent to its address. This is useful when the adapter needs to interact with other devices on the
390   802.11 network, because handling the ACKs in software is too slow.
391
392   \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
393         configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
394         every time you open the adapter.
395 */
396 gboolean AirpcapSetMonitorMode(PAirpcapHandle AdapterHandle, gboolean MonitorModeEnabled);
397
398 /*!
399   \brief Returns TRUE if the specified adapter is in monitor mode.
400   \param AdapterHandle Handle to the adapter.
401   \param PMonitorModeEnabled User-provided variable that will be set to true if the adapter is in monitor mode.
402   \return TRUE if the operation is successful. FALSE otherwise.
403
404   \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
405         configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
406         every time you open the adapter.
407 */
408 gboolean AirpcapGetMonitorMode(PAirpcapHandle AdapterHandle, gboolean * PMonitorModeEnabled);
409
410 /*!
411   \brief Set the link type of an adapter
412   \param AdapterHandle Handle to the adapter.
413   \param NewLinkType the "link type", i.e. the format of the frames that will be received from the adapter.
414   \return TRUE on success.
415
416   the "link type" determines how the driver will encode the packets captured from the network.
417   Aircap supports two link types:
418   - \ref AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
419    power information. Look at the Capture_no_radio example application in the developer's pack
420    for a reference on how to decode 802.11 frames with this link type.
421   - \ref AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
422   that contains power and channel information. More information about the radiotap header can be found in the
423   \ref radiotap section. Moreover, the "Capture_radio" example application in
424   the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
425   - \ref AIRPCAP_LT_802_11_PLUS_PPI, to capture 802.11 frames (including control frames) with a Per Packet Information (PPI)
426     header that contains per-packet meta information like channel and power information. More details on the PPI header can
427     be found in the PPI online documentation (TODO).
428 */
429 gboolean AirpcapSetLinkType(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
430
431 /*!
432   \brief Get the link type of the specified adapter
433   \param AdapterHandle Handle to the adapter.
434   \param PLinkType Pointer to a caller allocated AirpcapLinkType variable that will contain the link type of the adapter.
435   \return TRUE on success.
436
437   the "link type" determines how the driver will encode the packets captured from the network.
438   Aircap supports two link types:
439   - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
440    power information. Look at the Capture_no_radio example application in the developer's pack
441    for a reference on how to decode 802.11 frames with this link type.
442   - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
443   that contains power and channel information. More information about the radiotap header can be found int the
444   \ref radiotap section. Moreover, the "Capture_radio" example application in
445   the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
446 */
447 gboolean AirpcapGetLinkType(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
448
449 /*!
450   \brief Configures the adapter on whether to include the MAC Frame Check Sequence in the captured packets.
451   \param AdapterHandle Handle to the adapter.
452   \param IsFcsPresent TRUE if the packets should include the FCS. FALSE otherwise
453   \return TRUE on success.
454
455   In the default configuration, the adapter includes the FCS in the captured packets. The MAC Frame Check Sequence
456   is 4 bytes and is located at the end of the 802.11 packet, with both AIRPCAP_LT_802_11 and AIRPCAP_LT_802_11_PLUS_RADIO
457   link types.
458   When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
459   that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
460   when FCS inclusion is off.
461 */
462 gboolean AirpcapSetFcsPresence(PAirpcapHandle AdapterHandle, gboolean IsFcsPresent);
463
464 /*!
465   \brief Returns TRUE if the specified adapter includes the MAC Frame Check Sequence in the captured packets
466   \param AdapterHandle Handle to the adapter.
467   \param PIsFcsPresent User-provided variable that will be set to true if the adapter is including the FCS.
468   \return TRUE if the operation is successful. FALSE otherwise.
469
470   In the default configuration, the adapter has FCS inclusion turned on. The MAC Frame Check Sequence is 4 bytes
471   and is located at the end of the 802.11 packet, with both AIRPCAP_LT_802_11 and AIRPCAP_LT_802_11_PLUS_RADIO
472   link types.
473   When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
474   that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
475   when FCS inclusion is off.
476 */
477 gboolean AirpcapGetFcsPresence(PAirpcapHandle AdapterHandle, gboolean * PIsFcsPresent);
478
479 /*!
480   \brief Configures the adapter to accept or drop frames with an incorrect Frame Check sequence (FCS).
481   \param AdapterHandle Handle to the adapter.
482   \param ValidationType The type of validation the driver will perform. See the documentation of \ref AirpcapValidationType for details.
483   \return TRUE on success.
484
485   \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
486 */
487 gboolean AirpcapSetFcsValidation(PAirpcapHandle AdapterHandle, AirpcapValidationType ValidationType);
488
489 /*!
490   \brief Checks if the specified adapter is configured to capture frames with incorrect an incorrect Frame Check Sequence (FCS).
491   \param AdapterHandle Handle to the adapter.
492   \param ValidationType Pointer to a user supplied variable that will contain the type of validation the driver will perform. See the documentation of \ref AirpcapValidationType for details.
493   \return TRUE if the operation is successful. FALSE otherwise.
494
495   \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
496 */
497 gboolean AirpcapGetFcsValidation(PAirpcapHandle AdapterHandle, PAirpcapValidationType ValidationType);
498
499 /*!
500   \brief Set the list of decryption keys that the driver is going to use with the specified device.
501   \param AdapterHandle Handle an open adapter instance.
502   \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
503   \return TRUE if the operation is successful. FALSE otherwise.
504
505   The AirPcap driver is able to use a set of decryption keys to decrypt the traffic transmitted on a specific SSID. If one of the
506   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
507   to the application.
508
509   This function allows to set the <b>adapter-specific</b> set of keys. These keys will be used by the specified adapter only,
510   and will not be used by other airpcap devices besides the specified one.
511
512   At this time, the only supported decryption method is WEP.
513
514   The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
515   correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
516
517   \note: when you change the set of keys from an open capture instance, the change will be
518          immediately reflected on all the other capture instances.
519 */
520 gboolean AirpcapSetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
521
522 /*!
523   \brief Returns the list of decryption keys in the driver that are currently associated with the specified device
524   \param AdapterHandle Handle to an open adapter instance.
525   \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
526   \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
527                             \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
528   \return TRUE if the operation is successful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
529   If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
530   needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
531   KeysCollectionSize will be zero.
532
533   This function returns the <b>adapter-specific</b> set of keys. These keys are used by the specified adapter only,
534   and not by other airpcap devices besides the specified one.
535
536   The AirPcap driver is able to use a set of decryption keys to decrypt the traffic transmitted on a specific SSID. If one of the
537   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
538   to the application.
539   The driver supports, for every device, multiple keys at the same time.
540
541   The configured decryption keys are device-specific, therefore AirpcapGetDeviceKeys() will return a different set of keys
542   when called on different devices.
543
544   At this time, the only supported decryption method is WEP.
545 */
546 gboolean AirpcapGetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
547
548 /*!
549   \brief Set the global list of decryption keys that the driver is going to use with all the devices.
550   \param AdapterHandle Handle an open adapter instance.
551   \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
552   \return TRUE if the operation is successful. FALSE otherwise.
553
554   The AirPcap driver is able to use a set of decryption keys to decrypt the traffic transmitted on a specific SSID. If one of the
555   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
556   to the application.
557
558   This function allows to set the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
559   the machine.
560
561   At this time, the only supported decryption method is WEP.
562
563   The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
564   correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
565
566   \note: when you change the set of keys from an open capture instance, the change will be
567          immediately reflected on all the other capture instances.
568 */
569 gboolean AirpcapSetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
570
571 /*!
572   \brief Returns the global list of decryption keys in the driver that are associated with all the devices.
573   \param AdapterHandle Handle to an open adapter instance.
574   \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
575   \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
576                             \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
577   \return TRUE if the operation is successful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
578   If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
579   needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
580   KeysCollectionSize will be zero.
581
582   This function returns the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
583   the machine.
584
585   The AirPcap driver is able to use a set of decryption keys to decrypt the traffic transmitted on a specific SSID. If one of the
586   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
587   to the application.
588
589   At this time, the only supported decryption method is WEP.
590 */
591 gboolean AirpcapGetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
592
593 /*!
594   \brief Turns on or off the decryption of the incoming frames with the <b>adapter-specific</b> keys.
595   \param AdapterHandle Handle to the adapter.
596   \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
597   \return TRUE on success.
598
599   The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
600   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
601 */
602 gboolean AirpcapSetDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
603
604 /*!
605   \brief Tells if this open instance is configured to perform the decryption of the incoming frames with the <b>adapter-specific</b> keys.
606   \param AdapterHandle Handle to the adapter.
607   \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
608   \return TRUE if the operation is successful. FALSE otherwise.
609
610   The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
611   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
612 */
613 gboolean AirpcapGetDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
614
615 /*!
616   \brief Turns on or off the decryption of the incoming frames with the <b>global driver</b> set of keys.
617   \param AdapterHandle Handle to the adapter.
618   \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
619   \return TRUE on success.
620
621   The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
622   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
623 */
624 gboolean AirpcapSetDriverDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
625
626 /*!
627   \brief Tells if this open instance is configured to perform the decryption of the incoming frames with the <b>global driver</b> set of keys.
628   \param AdapterHandle Handle to the adapter.
629   \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
630   \return TRUE if the operation is successful. FALSE otherwise.
631
632   The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
633   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
634 */
635 gboolean AirpcapGetDriverDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
636
637 /*!
638   \brief Set the radio channel of a device
639   \param AdapterHandle Handle to the adapter.
640   \param Channel the new channel to set.
641   \return TRUE on success.
642
643   The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
644
645   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
646          immediately reflected on all the other capture instances.
647 */
648 gboolean AirpcapSetDeviceChannel(PAirpcapHandle AdapterHandle, guint Channel);
649
650 /*!
651   \brief Get the radio channel of a device
652   \param AdapterHandle Handle to the adapter.
653   \param PChannel Pointer to a user-supplied variable into which the function will copy the currently configured radio channel.
654   \return TRUE on success.
655
656   The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
657
658   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
659          immediately reflected on all the other capture instances.
660 */
661 gboolean AirpcapGetDeviceChannel(PAirpcapHandle AdapterHandle, guint * PChannel);
662
663 /*!
664   \brief Set the size of the kernel packet buffer for this adapter
665   \param AdapterHandle Handle to the adapter.
666   \param BufferSize New size, in bytes.
667   \return TRUE on success.
668
669   Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
670   This function can be used to change the size of this buffer, and can be called at any time.
671   A bigger kernel buffer size decreases the risk of dropping packets during network bursts or when the
672   application is busy, at the cost of higher kernel memory usage.
673
674   \note don't use this function unless you know what you are doing. Due to caching issues and bigger non-paged
675   memory consumption, bigger buffer sizes can decrease the capture performance instead of improving it.
676 */
677 gboolean AirpcapSetKernelBuffer(PAirpcapHandle AdapterHandle, guint BufferSize);
678
679 /*!
680   \brief Get the size of the kernel packet buffer for this adapter
681   \param AdapterHandle Handle to the adapter.
682   \param PSizeBytes User-allocated variable that will be filled with the size of the kernel buffer.
683   \return TRUE on success.
684
685   Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
686   This function can be used to get the size of this buffer.
687 */
688 gboolean AirpcapGetKernelBufferSize(PAirpcapHandle AdapterHandle, guint * PSizeBytes);
689
690 /*!
691   \brief Saves the configuration of the specified adapter in the registry, so that it becomes the default for this adapter.
692   \param AdapterHandle Handle to the adapter.
693   \return TRUE on success. FALSE on failure.
694
695   Almost all the AirPcap calls that modify the configuration (\ref AirpcapSetLinkType(), \ref AirpcapSetFcsPresence(),
696   \ref AirpcapSetFcsValidation(), \ref AirpcapSetKernelBuffer(), \ref AirpcapSetMinToCopy())
697   affect only the referenced AirPcap open instance. This means that if you do another \ref AirpcapOpen() on the same
698   adapter, the configuration changes will not be remembered, and the new adapter handle will have default configuration
699   settings.
700
701   Exceptions to this rule are the \ref AirpcapSetDeviceChannel() and \ref AirpcapSetDeviceKeys() functions: a channel change is
702   reflected on all the open instances, and remembered until the next call to \ref AirpcapSetDeviceChannel(), until the adapter
703   is unplugged, or until the machine is powered off. Same thing for the configuration of the WEP keys.
704
705   AirpcapStoreCurConfigAsAdapterDefault() stores the configuration of the give open instance as the default for the adapter:
706   all the instances opened in the future will have the same configuration that this adapter currently has.
707   The configuration is stored in the registry, therefore it is remembered even when the adapter is unplugged or the
708   machine is turned off. However, an adapter doesn't bring its configuration with it from machine to machine.
709
710   the configuration information saved in the registry includes the following parameters:
711    - channel
712    - kernel buffer size
713    - mintocopy
714    - link type
715    - CRC presence
716    - Encryption keys
717    - Encryption Enabled/Disabled state
718
719   The configuration is adapter-specific. This means that changing the configuration of an adapter
720   doesn't modify the one of the other adapters that are currently used or that will be used in the future.
721
722   \note AirpcapStoreCurConfigAsAdapterDefault() must have exclusive access to the adapter -- it
723    will fail if more than one AirPcap handle is opened at the same time for this adapter.
724    AirpcapStoreCurConfigAsAdapterDefault() needs administrator privileges. It will fail if the calling user
725    is not a local machine administrator.
726 */
727 gboolean AirpcapStoreCurConfigAsAdapterDefault(PAirpcapHandle AdapterHandle);
728
729 /*!
730   \brief Set the BPF kernel filter for an adapter
731   \param AdapterHandle Handle to the adapter.
732   \param Instructions pointer to the first BPF instruction in the array. Corresponds to the  bf_insns
733    in a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
734   \param Len Number of instructions in the array pointed by the previous field. Corresponds to the bf_len in
735   a a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
736   \return TRUE on success.
737
738   The AirPcap driver is able to perform kernel-level filtering using the standard BPF pseudo-machine format. You can read
739   the WinPcap documentation at http://www.winpcap.org/devel.htm for more details on the BPF filtering mechanism.
740
741   A filter can be automatically created by using the pcap_compile() function of the WinPcap API. This function
742   converts a human readable text expression with the tcpdump/libpcap syntax into a BPF program.
743   If your program doesn't link wpcap, but you need to generate the code for a particular filter, you can run WinDump
744   with the -d or -dd or -ddd flags to obtain the pseudocode.
745
746 */
747 gboolean AirpcapSetFilter(PAirpcapHandle AdapterHandle, void * Instructions, guint Len);
748
749 /*!
750   \brief Return the MAC address of an adapter.
751   \param AdapterHandle Handle to the adapter.
752   \param PMacAddress Pointer to a user allocated MAC address.
753    The size of this buffer needs to be at least 6 bytes.
754   \return TRUE on success.
755 */
756 gboolean AirpcapGetMacAddress(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
757
758 /*!
759   \brief Set the mintocopy parameter for an open adapter
760   \param AdapterHandle Handle to the adapter.
761   \param MinToCopy is the mintocopy size in bytes.
762   \return TRUE on success.
763
764   When the number of bytes in the kernel buffer changes from less than mintocopy bytes to greater than or equal to mintocopy bytes,
765   the read event is signalled (see \ref AirpcapGetReadEvent()). A high value for mintocopy results in poor responsiveness since the
766   driver may signal the application "long" after the arrival of the packet. And a high value results in low CPU loading
767   by minimizing the number of user/kernel context switches.
768   A low MinToCopy results in good responsiveness since the driver will signal the application close to the arrival time of
769   the packet. This has higher CPU loading over the first approach.
770 */
771 gboolean AirpcapSetMinToCopy(PAirpcapHandle AdapterHandle, guint MinToCopy);
772
773 /*!
774   \brief Gets an event that is signaled when that is signalled when packets are available in the kernel buffer (see \ref AirpcapSetMinToCopy()).
775   \param AdapterHandle Handle to the adapter.
776   \param PReadEvent Pointer to a user-supplied handle that in which the read event will be copied.
777   \return TRUE on success.
778
779   \note the event is signalled when at least mintocopy bytes are present in the kernel buffer (see \ref AirpcapSetMinToCopy()).
780   This event can be used by WaitForSingleObject() and WaitForMultipleObjects() to create blocking behavior when reading
781   packets from one or more adapters (see \ref AirpcapRead()).
782 */
783 gboolean AirpcapGetReadEvent(PAirpcapHandle AdapterHandle, void *** PReadEvent);
784
785 /*!
786   \brief Fills a user-provided buffer with zero or more packets that have been captured on the referenced adapter.
787   \param AdapterHandle Handle to the adapter.
788   \param Buffer pointer to the buffer that will be filled with captured packets.
789   \param BufSize size of the input buffer that will contain the packets, in bytes.
790   \param PReceievedBytes Pointer to a user supplied variable that will receive the number of bytes copied by AirpcapRead.
791   Can be smaller than BufSize.
792   \return TRUE on success.
793
794   802.11 frames are returned by the driver in buffers. Every 802.11 frame in the buffer is preceded by a \ref AirpcapBpfHeader structure.
795   The suggested way to use an AirPcap adapter is through the pcap API exported by wpcap.dll. If this is not
796   possible, the Capture_radio and Capture_no_radio examples in the AirPcap developer's pack show how to properly decode the
797   packets in the read buffer returned by AirpcapRead().
798
799   \note this function is NOT blocking. Blocking behavior can be obtained using the event returned
800    by \ref AirpcapGetReadEvent(). See also \ref AirpcapSetMinToCopy().
801 */
802 gboolean AirpcapRead(PAirpcapHandle AdapterHandle, guint8 * Buffer, guint BufSize, guint * PReceievedBytes);
803
804 /*!
805   \brief Transmits a packet.
806   \param AdapterHandle Handle to the adapter.
807   \param TxPacket Pointer to a buffer that contains the packet to be transmitted.
808   \param PacketLen Length of the buffer pointed by the TxPacket argument, in bytes.
809   \return TRUE on success.
810
811   The packet will be transmitted on the channel the device is currently set. To change the device adapter, use the
812   \ref AirpcapSetDeviceChannel() function.
813
814   If the linktype of the adapter is AIRPCAP_LT_802_11, the buffer pointed by TxPacket should contain just the 802.11
815   packet, without additional information. The packet will be transmitted at 1Mbps.
816
817   If the linktype of the adapter is AIRPCAP_LT_802_11_PLUS_RADIO, the buffer pointed by TxPacket should contain a radiotap
818   header followed by the 802.11 packet. AirpcapWrite will use the rate information in the radiotap header when
819   transmitting the packet.
820 */
821 gboolean AirpcapWrite(PAirpcapHandle AdapterHandle, gchar * TxPacket, guint32 PacketLen);
822
823 /*!
824   \brief Get per-adapter WinPcap-compatible capture statistics.
825   \param AdapterHandle Handle to the adapter.
826   \param PStats pointer to a user-allocated AirpcapStats structure that will be filled with statistical information.
827   \return TRUE on success.
828 */
829 gboolean AirpcapGetStats(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
830
831 /*!
832   \brief Get the number of LEDs the referenced adapter has available.
833   \param AdapterHandle Handle to the adapter.
834   \param NumberOfLeds Number of LEDs available on this adapter.
835   \return TRUE on success.
836 */
837 gboolean AirpcapGetLedsNumber(PAirpcapHandle AdapterHandle, guint * NumberOfLeds);
838
839 /*!
840   \brief Turn on one of the adapter's LEDs.
841   \param AdapterHandle Handle to the adapter.
842   \param LedNumber zero-based identifier of the LED to turn on.
843   \return TRUE on success.
844 */
845 gboolean AirpcapTurnLedOn(PAirpcapHandle AdapterHandle, guint LedNumber);
846
847 /*!
848   \brief Turn off one of the adapter's LEDs.
849   \param AdapterHandle Handle to the adapter.
850   \param LedNumber zero-based identifier of the LED to turn off.
851   \return TRUE on success.
852 */
853 gboolean AirpcapTurnLedOff(PAirpcapHandle AdapterHandle, guint LedNumber);
854
855 /*!
856   \brief Set the channel of a device through its radio frequency. In case of 802.11n enabled devices, it sets the extension channel, if used.
857   \param AdapterHandle Handle to the adapter.
858   \param ChannelInfo The new channel information to set.
859   \return TRUE on success.
860
861   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
862          immediately reflected on all the other capture instances.
863 */
864 gboolean AirpcapSetDeviceChannelEx(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo);
865
866 /*!
867   \brief Get the channel of a device through its radiofrequency. In case of 802.11n enabled devices, it gets the extension channel, if in use.
868   \param AdapterHandle Handle to the adapter.
869   \param PChannelInfo Pointer to a user-supplied variable into which the function will copy the currently configured channel information.
870   \return TRUE on success.
871
872   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
873          immediately reflected on all the other capture instances.
874 */
875 gboolean AirpcapGetDeviceChannelEx(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo);
876
877 /*!
878   \brief Get the list of supported channels for a given device. In case of a 802.11n capable device, information related to supported extension channels is also reported.
879
880   Every control channel is listed multiple times, one for each different supported extension channel. For example channel 6 (2437MHz)  is usually listed three times:
881     - <b>Frequency 2437 Extension +1</b>. Control channel is 6, extension channel is 10.
882     - <b>Frequency 2437 Extension 0</b>. Control channel is 6, no extension channel is used (20MHz channel and legacy mode).
883     - <b>Frequency 2437 Extension -1</b>. Control channel is 6, extension channel is 2.
884   \param AdapterHandle Handle to the adapter.
885   \param ppChannelInfo Pointer to a user-supplied variable that will point to an array of supported channel. Such list must not be freed by the caller
886   \param pNumChannelInfo Number of channels returned in the array.
887   \return TRUE on success.
888
889   \note The supported channels are not listed in any specific order.
890 */
891 gboolean AirpcapGetDeviceSupportedChannels(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo *ppChannelInfo, guint * pNumChannelInfo);
892
893 /*!
894   \brief Converts a given frequency to the corresponding channel.
895
896   \param Frequency Frequency of the channel, in MHz.
897   \param PChannel Pointer to a user-supplied variable that will contain the channel number on success.
898   \param PBand Pointer to a user-supplied variable that will contain the band (a or b/g) of the given channel.
899   \return TRUE on success, i.e. the frequency corresponds to a valid a or b/g channel.
900 */
901 gboolean AirpcapConvertFrequencyToChannel(guint Frequency, guint * PChannel, PAirpcapChannelBand PBand);
902
903 /*!
904   \brief Converts a given channel to the corresponding frequency.
905
906   \param Channel Channel number to be converted.
907   \param PFrequency Pointer to a user-supplied variable that will contain the channel frequency in MHz on success.
908   \return TRUE on success, i.e. the given channel number exists.
909 */
910 gboolean AirpcapConvertChannelToFrequency(guint Channel, guint * PFrequency);
911
912
913 /*@}*/
914
915 #endif /* __AIRPCAP_DRIVER__ */
916
917 #ifdef __cplusplus
918 }
919 #endif
920
921 #endif /* !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_) */