Add EUI64 display type for Source/Target Link-layer Address (RFC4861)
[obnox/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 // __MINGW32__
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 // __MINGW32__
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 worng 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 // __MINGW32__
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 doesn't contain any key, so be careful to allocate a buffer
172   with the size of the key, like in the following example:
173
174   \code
175         PAirpcapKeysCollection KeysCollection;
176         guint KeysCollectionSize;
177
178         KeysCollectionSize = sizeof(AirpcapKeysCollection) + NumKeys * sizeof(AirpcapKey);
179
180         KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
181         if(!KeysCollection)
182         {
183                 // Error
184         }
185   \endcode
186 */
187 typedef struct _AirpcapKeysCollection
188 {
189         guint nKeys;                                                                                            ///< Number of keys in the collection
190         AirpcapKey Keys[0];                                                                             ///< Array of nKeys keys.
191 } AirpcapKeysCollection, *PAirpcapKeysCollection;
192
193 /*!
194   \brief Packet header.
195
196   This structure defines the BPF that preceeds every packet delivered to the application.
197 */
198 typedef struct _AirpcapBpfHeader
199 {
200         guint TsSec;                    ///< Timestamp associated with the captured packet. SECONDS.
201         guint TsUsec;           ///< Timestamp associated with the captured packet. MICROSECONDS.
202         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.
203         guint Originallen;      ///< Original length of packet
204         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.
205 }
206 #ifdef __MINGW32__
207 __attribute__((__packed__))
208 #endif // __MINGW32__
209 AirpcapBpfHeader, *PAirpcapBpfHeader;
210
211 /// Helper macros to extract packets coming from the driver. Rounds up to the next even multiple of AIRPCAP_ALIGNMENT.
212 #define AIRPCAP_ALIGNMENT sizeof(int)
213 #define AIRPCAP_WORDALIGN(x) (((x)+(AIRPCAP_ALIGNMENT-1))&~(AIRPCAP_ALIGNMENT-1))
214
215 #ifdef _WIN32
216 #ifndef __MINGW32__
217 #pragma pack(pop)
218 #endif // __MINGW32__
219 #endif
220
221 #define AIRPCAP_ERRBUF_SIZE 512         ///< Size of the error buffer, in bytes
222
223 #ifndef __AIRPCAP_DRIVER__
224
225 /*!
226   \brief Link type.
227    AirPcap supports two kind of 802.11 linktypes: plain 802.11 and radiotap.
228 */
229 #undef _AirpcapLinkType
230 typedef enum _AirpcapLinkType
231 {
232     AIRPCAP_LT_802_11 = 1,                              ///< plain 802.11 linktype. Every packet in the buffer contains the raw 802.11 frame, including MAC FCS.
233     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.
234         AIRPCAP_LT_UNKNOWN = 3,                         ///< Unknown linktype. You should see it only in case of error.
235         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.
236 }AirpcapLinkType, *PAirpcapLinkType;
237
238 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
239 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
240 /*!
241   \brief Adapter handle.
242 */
243 typedef struct _AirpcapHandle AirpcapHandle, *PAirpcapHandle;
244 #endif
245
246 /*!
247   \brief Capture statistics.
248    Returned by \ref AirpcapGetStats();
249 */
250 typedef struct _AirpcapStats
251 {
252         guint Recvs;                    ///< Number of packets that the driver received by the adapter
253                                                 ///< from the beginning of the current capture. This value includes the packets
254                                                 ///< dropped because of buffer full.
255         guint Drops;                    ///< number of packets that the driver dropped from the beginning of a capture.
256                                                 ///< A packet is lost when the the buffer of the driver is full.
257         guint IfDrops;          ///< Packets dropped by the card before going to the USB bus.
258                                                 ///< Not supported at the moment.
259         guint Capt;                     ///< number of packets that pass the BPF filter, find place in the kernel buffer and
260                                                 ///< therefore reach the application.
261 }AirpcapStats, *PAirpcapStats;
262
263 /*!
264   \brief Channel information.
265   Used by \ref AirpcapSetDeviceChannelEx(), \ref AirpcapGetDeviceChannelEx(), \ref AirpcapGetDeviceSupportedChannels()
266 */
267 typedef struct _AirpcapChannelInfo
268 {
269         guint Frequency;        ///< Channel frequency, in MHz.
270         /*!
271                 \brief 802.11n specific. Offset of the extension channel in case of 40MHz channels.
272
273                 Possible values are -1, 0 +1:
274                 - -1 means that the extension channel should be below the control channel (e.g. Control = 5 and Extension = 1)
275                 - 0 means that no extension channel should be used (20MHz channels or legacy mode)
276                 - +1 means that the extension channel should be above the control channel (e.g. Control = 1 and Extension = 5)
277
278                 In case of 802.11a/b/g channels (802.11n legacy mode), this field should be set to 0.
279         */
280         gchar ExtChannel;
281         guint8 Reserved[3];     ///< Reserved. It should be set to {0,0,0}.
282 }
283         AirpcapChannelInfo, *PAirpcapChannelInfo;
284
285
286 /*@}*/
287
288 /** @defgroup airpcapfuncs AirPcap functions
289  *  @{
290  */
291
292 /*!
293   \brief Return a string with the API version
294   \param VersionMajor Pointer to a variable that will be filled with the major version number.
295   \param VersionMinor Pointer to a variable that will be filled with the minor version number.
296   \param VersionRev Pointer to a variable that will be filled with the revision number.
297   \param VersionBuild Pointer to a variable that will be filled with the build number.
298 */
299 void AirpcapGetVersion(guint * VersionMajor, guint * VersionMinor, guint * VersionRev, guint * VersionBuild);
300
301 /*!
302   \brief Return the last error related to the specified handle
303   \param AdapterHandle Handle to an open adapter.
304   \return The string with the last error.
305 */
306 gchar * AirpcapGetLastError(PAirpcapHandle AdapterHandle);
307
308 /*!
309   \brief Return the list of available devices
310   \param PPAllDevs Address to a caller allocated pointer. On success this pointer will receive the head of a list of available devices.
311   \param Ebuf String that will contain error information if FALSE is returned. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
312   \return TRUE on success. FALSE is returned on failure, in which case Ebuf is filled in with an appropriate error message.
313
314         Here's a snippet of code that shows how to use AirpcapGetDeviceList():
315
316         \code
317         gchar Ebuf[AIRPCAP_ERRBUF_SIZE];
318         AirpcapDeviceDescription *Desc, *tDesc;
319
320         if(AirpcapGetDeviceList(&Desc, Ebuf) == -1)
321         {
322                 printf("Unable to get the list of devices: %s\n", Ebuf);
323                 return -1;
324         }
325
326         for(tDesc = Desc; tDesc; tDesc = tDesc->next)
327         {
328                 printf("%u) %s (%s)\n",
329                 ++i,
330                 tDesc->Name,
331                 tDesc->Description);
332         }
333
334         AirpcapFreeDeviceList(Desc);
335         \endcode
336 */
337 gboolean AirpcapGetDeviceList(PAirpcapDeviceDescription *PPAllDevs, gchar * Ebuf);
338
339 /*!
340   \brief Free a list of devices returned by AirpcapGetDeviceList()
341   \param PAllDevs Head of the list of devices returned by \ref AirpcapGetDeviceList().
342 */
343 void AirpcapFreeDeviceList(PAirpcapDeviceDescription PAllDevs);
344
345 /*!
346   \brief Open an adapter
347   \param DeviceName Name of the device to open. Use \ref AirpcapGetDeviceList() to get the list of devices.
348   \param Ebuf String that will contain error information in case of failure. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
349   \return A PAirpcapHandle handle on success. NULL is returned on failure, in which case Ebuf is filled in with an appropriate error message.
350 */
351 PAirpcapHandle AirpcapOpen(gchar * DeviceName, gchar * Ebuf);
352
353 /*!
354   \brief Close an adapter
355   \param AdapterHandle Handle to the adapter to close.
356 */
357 void AirpcapClose(PAirpcapHandle AdapterHandle);
358
359 /*!
360   \brief Sets the monitor mode for the specified adapter
361   \param AdapterHandle Handle to the adapter.
362   \param MonitorModeEnabled If TRUE, the adapter will be put in monitor mode. If FALSE, the adapter will be configured
363          for normal operation.
364   \return TRUE on success.
365
366   When monitor mode is on, the adapter captures all the packets transmitted on the channel. This includes:
367
368    - unicast packets
369    - multicast packets
370    - broadcast packets
371    - control and management packets
372
373   When monitor mode is off, the adapter has a filter on unicast packets to capture only the packets whose MAC
374   destination address equals to the adapter's address. This means the following frames will be received:
375
376    - unicast packets with the address of the adapter
377    - multicast packets
378    - broadcast packets
379    - beacons and probe requests
380
381   The main reason to turn monitor mode off is that, when not in monitor mode, the adapter will acknowledge the
382   data frames sent to its address. This is useful when the adapter needs to interact with other devices on the
383   802.11 network, bacause handling the ACKs in software is too slow.
384
385   \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
386         configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
387                 every time you open the adapter.
388 */
389 gboolean AirpcapSetMonitorMode(PAirpcapHandle AdapterHandle, gboolean MonitorModeEnabled);
390
391 /*!
392   \brief Returns TRUE if the specified adapter is in monitor mode.
393   \param AdapterHandle Handle to the adapter.
394   \param PMonitorModeEnabled User-provided variable that will be set to true if the adapter is in monitor mode.
395   \return TRUE if the operation is successful. FALSE otherwise.
396
397   \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
398         configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
399                 every time you open the adapter.
400 */
401 gboolean AirpcapGetMonitorMode(PAirpcapHandle AdapterHandle, gboolean * PMonitorModeEnabled);
402
403 /*!
404   \brief Set the link type of an adapter
405   \param AdapterHandle Handle to the adapter.
406   \param NewLinkType the "link type", i.e. the format of the frames that will be received from the adapter.
407   \return TRUE on success.
408
409   the "link type" determines how the driver will encode the packets captured from the network.
410   Aircap supports two link types:
411   - \ref AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
412    power information. Look at the Capture_no_radio example application in the developer's pack
413    for a reference on how to decode 802.11 frames with this link type.
414   - \ref AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
415   that contains power and channel information. More information about the radiotap header can be found in the
416   \ref radiotap section. Moreover, the "Capture_radio" example application in
417   the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
418   - \ref AIRPCAP_LT_802_11_PLUS_PPI, to capture 802.11 frames (including control frames) with a Per Packet Information (PPI)
419         header that contains per-packet meta information like channel and power information. More details on the PPI header can
420         be founf in the PPI online documentation (TODO).
421 */
422 gboolean AirpcapSetLinkType(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
423
424 /*!
425   \brief Get the link type of the specified adapter
426   \param AdapterHandle Handle to the adapter.
427   \param PLinkType Pointer to a caller allocated AirpcapLinkType variable that will contain the link type of the adapter.
428   \return TRUE on success.
429
430   the "link type" determines how the driver will encode the packets captured from the network.
431   Aircap supports two link types:
432   - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
433    power information. Look at the Capture_no_radio example application in the developer's pack
434    for a reference on how to decode 802.11 frames with this link type.
435   - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
436   that contains power and channel information. More information about the radiotap header can be found int the
437   \ref radiotap section. Moreover, the "Capture_radio" example application in
438   the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
439 */
440 gboolean AirpcapGetLinkType(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
441
442 /*!
443   \brief Configures the adapter on whether to include the MAC Frame Check Sequence in the captured packets.
444   \param AdapterHandle Handle to the adapter.
445   \param IsFcsPresent TRUE if the packets should include the FCS. FALSE otherwise
446   \return TRUE on success.
447
448   In the default configuration, the adapter includes the FCS in the captured packets. The MAC Frame Check Sequence
449   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
450   link types.
451   When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
452   that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
453   when FCS inclusion is off.
454 */
455 gboolean AirpcapSetFcsPresence(PAirpcapHandle AdapterHandle, gboolean IsFcsPresent);
456
457 /*!
458   \brief Returns TRUE if the specified adapter includes the MAC Frame Check Sequence in the captured packets
459   \param AdapterHandle Handle to the adapter.
460   \param PIsFcsPresent User-provided variable that will be set to true if the adapter is including the FCS.
461   \return TRUE if the operation is successful. FALSE otherwise.
462
463   In the default configuration, the adatper has FCS inclusion turned on. The MAC Frame Check Sequence is 4 bytes
464   and is located at the end of the 802.11 packet, with both AIRPCAP_LT_802_11 and AIRPCAP_LT_802_11_PLUS_RADIO
465   link types.
466   When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
467   that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
468   when FCS inclusion is off.
469 */
470 gboolean AirpcapGetFcsPresence(PAirpcapHandle AdapterHandle, gboolean * PIsFcsPresent);
471
472 /*!
473   \brief Configures the adapter to accept or drop frames with an incorrect Frame Check sequence (FCS).
474   \param AdapterHandle Handle to the adapter.
475   \param ValidationType The type of validation the driver will perform. See the documentation of \ref AirpcapValidationType for details.
476   \return TRUE on success.
477
478   \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
479 */
480 gboolean AirpcapSetFcsValidation(PAirpcapHandle AdapterHandle, AirpcapValidationType ValidationType);
481
482 /*!
483   \brief Checks if the specified adapter is configured to capture frames with incorrect an incorrect Frame Check Sequence (FCS).
484   \param AdapterHandle Handle to the adapter.
485   \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.
486   \return TRUE if the operation is succesful. FALSE otherwise.
487
488   \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
489 */
490 gboolean AirpcapGetFcsValidation(PAirpcapHandle AdapterHandle, PAirpcapValidationType ValidationType);
491
492 /*!
493   \brief Set the list of decryption keys that the driver is going to use with the specified device.
494   \param AdapterHandle Handle an open adapter instance.
495   \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
496   \return TRUE if the operation is successful. FALSE otherwise.
497
498   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
499   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
500   to the application.
501
502   This function allows to set the <b>adapter-specific</b> set of keys. These keys will be used by the specified adapter only,
503   and will not be used by other airpcap devices besides the specified one.
504
505   At this time, the only supported decryption method is WEP.
506
507   The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
508   correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
509
510   \note: when you change the set of keys from an open capture instance, the change will be
511          immediately reflected on all the other capture instances.
512 */
513 gboolean AirpcapSetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
514
515 /*!
516   \brief Returns the list of decryption keys in the driver that are currently associated with the specified device
517   \param AdapterHandle Handle to an open adapter instance.
518   \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
519   \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
520                                                 \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
521   \return TRUE if the operation is succesful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
522   If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
523   needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
524   KeysCollectionSize will be zero.
525
526   This function returns the <b>adapter-specific</b> set of keys. These keys are used by the specified adapter only,
527   and not by other airpcap devices besides the specified one.
528
529   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
530   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
531   to the application.
532   The driver supports, for every device, multiple keys at the same time.
533
534   The configured decryption keys are device-specific, therefore AirpcapGetDeviceKeys() will return a different set of keys
535   when called on different devices.
536
537   At this time, the only supported decryption method is WEP.
538 */
539 gboolean AirpcapGetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
540
541 /*!
542   \brief Set the global list of decryption keys that the driver is going to use with all the devices.
543   \param AdapterHandle Handle an open adapter instance.
544   \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
545   \return TRUE if the operation is successful. FALSE otherwise.
546
547   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
548   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
549   to the application.
550
551   This function allows to set the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
552   the machine.
553
554   At this time, the only supported decryption method is WEP.
555
556   The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
557   correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
558
559   \note: when you change the set of keys from an open capture instance, the change will be
560          immediately reflected on all the other capture instances.
561 */
562 gboolean AirpcapSetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
563
564 /*!
565   \brief Returns the global list of decryption keys in the driver that are associated with all the devices.
566   \param AdapterHandle Handle to an open adapter instance.
567   \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
568   \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
569                                                 \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
570   \return TRUE if the operation is succesful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
571   If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
572   needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
573   KeysCollectionSize will be zero.
574
575   This function returns the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
576   the machine.
577
578   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
579   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
580   to the application.
581
582   At this time, the only supported decryption method is WEP.
583 */
584 gboolean AirpcapGetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
585
586 /*!
587   \brief Turns on or off the decryption of the incoming frames with the <b>adapter-specific</b> keys.
588   \param AdapterHandle Handle to the adapter.
589   \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
590   \return TRUE on success.
591
592   The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
593   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
594 */
595 gboolean AirpcapSetDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
596
597 /*!
598   \brief Tells if this open instance is configured to perform the decryption of the incoming frames with the <b>adapter-specific</b> keys.
599   \param AdapterHandle Handle to the adapter.
600   \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
601   \return TRUE if the operation is succesful. FALSE otherwise.
602
603   The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
604   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
605 */
606 gboolean AirpcapGetDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
607
608 /*!
609   \brief Turns on or off the decryption of the incoming frames with the <b>global driver</b> set of keys.
610   \param AdapterHandle Handle to the adapter.
611   \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
612   \return TRUE on success.
613
614   The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
615   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
616 */
617 gboolean AirpcapSetDriverDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
618
619 /*!
620   \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.
621   \param AdapterHandle Handle to the adapter.
622   \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
623   \return TRUE if the operation is succesful. FALSE otherwise.
624
625   The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
626   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
627 */
628 gboolean AirpcapGetDriverDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
629
630 /*!
631   \brief Set the radio channel of a device
632   \param AdapterHandle Handle to the adapter.
633   \param Channel the new channel to set.
634   \return TRUE on success.
635
636   The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
637
638   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
639          immediately reflected on all the other capture instances.
640 */
641 gboolean AirpcapSetDeviceChannel(PAirpcapHandle AdapterHandle, guint Channel);
642
643 /*!
644   \brief Get the radio channel of a device
645   \param AdapterHandle Handle to the adapter.
646   \param PChannel Pointer to a user-supplied variable into which the function will copy the currently configured radio channel.
647   \return TRUE on success.
648
649   The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
650
651   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
652          immediately reflected on all the other capture instances.
653 */
654 gboolean AirpcapGetDeviceChannel(PAirpcapHandle AdapterHandle, guint * PChannel);
655
656 /*!
657   \brief Set the size of the kernel packet buffer for this adapter
658   \param AdapterHandle Handle to the adapter.
659   \param BufferSize New size, in bytes.
660   \return TRUE on success.
661
662   Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
663   This function can be used to change the size of this buffer, and can be called at any time.
664   A bigger kernel buffer size decreases the risk of dropping packets during network bursts or when the
665   application is busy, at the cost of higher kernel memory usage.
666
667   \note don't use this function unless you know what you are doing. Due to caching issues and bigger non-paged
668   memory consumption, bigger buffer sizes can decrease the capture performace instead of improving it.
669 */
670 gboolean AirpcapSetKernelBuffer(PAirpcapHandle AdapterHandle, guint BufferSize);
671
672 /*!
673   \brief Get the size of the kernel packet buffer for this adapter
674   \param AdapterHandle Handle to the adapter.
675   \param PSizeBytes User-allocated variable that will be filled with the size of the kernel buffer.
676   \return TRUE on success.
677
678   Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
679   This function can be used to get the size of this buffer.
680 */
681 gboolean AirpcapGetKernelBufferSize(PAirpcapHandle AdapterHandle, guint * PSizeBytes);
682
683 /*!
684   \brief Saves the configuration of the specified adapter in the registry, so that it becomes the default for this adapter.
685   \param AdapterHandle Handle to the adapter.
686   \return TRUE on success. FALSE on failure.
687
688   Almost all the AirPcap calls that modify the configuration (\ref AirpcapSetLinkType(), \ref AirpcapSetFcsPresence(),
689   \ref AirpcapSetFcsValidation(), \ref AirpcapSetKernelBuffer(), \ref AirpcapSetMinToCopy())
690   affect only the referenced AirPcap open instance. This means that if you do another \ref AirpcapOpen() on the same
691   adapter, the configuration changes will not be remembered, and the new adapter handle will have default configuration
692   settings.
693
694   Exceptions to this rule are the \ref AirpcapSetDeviceChannel() and \ref AirpcapSetDeviceKeys() functions: a channel change is
695   reflected on all the open instances, and remembered until the next call to \ref AirpcapSetDeviceChannel(), until the adapter
696   is unplugged, or until the machine is powered off. Same thing for the configuration of the WEP keys.
697
698   AirpcapStoreCurConfigAsAdapterDefault() stores the configuration of the give open instance as the default for the adapter:
699   all the instances opened in the future will have the same configuration that this adapter currently has.
700   The configuration is stored in the registry, therefore it is remembered even when the adapter is unplugged or the
701   machine is turned off. However, an adapter doesn't bring its configuration with it from machine to machine.
702
703   the configuration information saved in the registry includes the following parameters:
704    - channel
705    - kernel buffer size
706    - mintocopy
707    - link type
708    - CRC presence
709    - Encryption keys
710    - Encryption Enabled/Disabled state
711
712   The configuration is adapter-specific. This means that changing the configuration of an adapter
713   doesn't modify the one of the other adapters that are currently used or that will be used in the future.
714
715   \note AirpcapStoreCurConfigAsAdapterDefault() must have exclusive access to the adapter -- it
716    will fail if more than one AirPcap handle is opened at the same time for this adapter.
717    AirpcapStoreCurConfigAsAdapterDefault() needs administrator privileges. It will fail if the calling user
718    is not a local machine administrator.
719 */
720 gboolean AirpcapStoreCurConfigAsAdapterDefault(PAirpcapHandle AdapterHandle);
721
722 /*!
723   \brief Set the BPF kernel filter for an adapter
724   \param AdapterHandle Handle to the adapter.
725   \param Instructions pointer to the first BPF instruction in the array. Corresponds to the  bf_insns
726    in a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
727   \param Len Number of instructions in the array pointed by the previous field. Corresponds to the bf_len in
728   a a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
729   \return TRUE on success.
730
731   The AirPcap driver is able to perform kernel-level filtering using the standard BPF pseudo-machine format. You can read
732   the WinPcap documentation at http://www.winpcap.org/devel.htm for more details on the BPF filtering mechaism.
733
734   A filter can be automatically created by using the pcap_compile() function of the WinPcap API. This function
735   converts a human readable text expression with the tcpdump/libpcap syntax into a BPF program.
736   If your program doesn't link wpcap, but you need to generate the code for a particular filter, you can run WinDump
737   with the -d or -dd or -ddd flags to obtain the pseudocode.
738
739 */
740 gboolean AirpcapSetFilter(PAirpcapHandle AdapterHandle, void * Instructions, guint Len);
741
742 /*!
743   \brief Return the MAC address of an adapter.
744   \param AdapterHandle Handle to the adapter.
745   \param PMacAddress Pointer to a user allocated MAC address.
746    The size of this buffer needs to be at least 6 bytes.
747   \return TRUE on success.
748 */
749 gboolean AirpcapGetMacAddress(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
750
751 /*!
752   \brief Set the mintocopy parameter for an open adapter
753   \param AdapterHandle Handle to the adapter.
754   \param MinToCopy is the mintocopy size in bytes.
755   \return TRUE on success.
756
757   When the number of bytes in the kernel buffer changes from less than mintocopy bytes to greater than or equal to mintocopy bytes,
758   the read event is signalled (see \ref AirpcapGetReadEvent()). A high value for mintocopy results in poor responsiveness since the
759   driver may signal the application "long" after the arrival of the packet. And a high value results in low CPU loading
760   by minimizing the number of user/kernel context switches.
761   A low MinToCopy results in good responsiveness since the driver will signal the application close to the arrival time of
762   the packet. This has higher CPU loading over the first approach.
763 */
764 gboolean AirpcapSetMinToCopy(PAirpcapHandle AdapterHandle, guint MinToCopy);
765
766 /*!
767   \brief Gets an event that is signaled when that is signalled when packets are available in the kernel buffer (see \ref AirpcapSetMinToCopy()).
768   \param AdapterHandle Handle to the adapter.
769   \param PReadEvent Pointer to a user-supplied handle that in which the read event will be copied.
770   \return TRUE on success.
771
772   \note the event is signalled when at least mintocopy bytes are present in the kernel buffer (see \ref AirpcapSetMinToCopy()).
773   This event can be used by WaitForSingleObject() and WaitForMultipleObjects() to create blocking behavior when reading
774   packets from one or more adapters (see \ref AirpcapRead()).
775 */
776 gboolean AirpcapGetReadEvent(PAirpcapHandle AdapterHandle, void *** PReadEvent);
777
778 /*!
779   \brief Fills a user-provided buffer with zero or more packets that have been captured on the referenced adapter.
780   \param AdapterHandle Handle to the adapter.
781   \param Buffer pointer to the buffer that will be filled with captured packets.
782   \param BufSize size of the input buffer that will contain the packets, in bytes.
783   \param PReceievedBytes Pointer to a user supplied variable that will receive the number of bytes copied by AirpcapRead.
784   Can be smaller than BufSize.
785   \return TRUE on success.
786
787   802.11 frames are returned by the driver in buffers. Every 802.11 frame in the buffer is preceded by a \ref AirpcapBpfHeader structure.
788   The suggested way to use an AirPcap adapter is through the pcap API exported by wpcap.dll. If this is not
789   possible, the Capture_radio and Capture_no_radio examples in the AirPcap developer's pack show how to properly decode the
790   packets in the read buffer returned by AirpcapRead().
791
792   \note this function is NOT blocking. Blocking behavior can be obtained using the event returned
793    by \ref AirpcapGetReadEvent(). See also \ref AirpcapSetMinToCopy().
794 */
795 gboolean AirpcapRead(PAirpcapHandle AdapterHandle, guint8 * Buffer, guint BufSize, guint * PReceievedBytes);
796
797 /*!
798   \brief Transmits a packet.
799   \param AdapterHandle Handle to the adapter.
800   \param TxPacket Pointer to a buffer that contains the packet to be transmitted.
801   \param PacketLen Length of the buffer pointed by the TxPacket argument, in bytes.
802   \return TRUE on success.
803
804   The packet will be transmitted on the channel the device is currently set. To change the device adapter, use the
805   \ref AirpcapSetDeviceChannel() function.
806
807   If the linktype of the adapter is AIRPCAP_LT_802_11, the buffer pointed by TxPacket should contain just the 802.11
808   packet, without additional information. The packet will be transmitted at 1Mbps.
809
810   If the linktype of the adapter is AIRPCAP_LT_802_11_PLUS_RADIO, the buffer pointed by TxPacket should contain a radiotap
811   header followed by the 802.11 packet. AirpcapWrite will use the rate information in the radiotap header when
812   transmitting the packet.
813 */
814 gboolean AirpcapWrite(PAirpcapHandle AdapterHandle, gchar * TxPacket, guint32 PacketLen);
815
816 /*!
817   \brief Get per-adapter WinPcap-compatible capture statistics.
818   \param AdapterHandle Handle to the adapter.
819   \param PStats pointer to a user-allocated AirpcapStats structure that will be filled with statistical information.
820   \return TRUE on success.
821 */
822 gboolean AirpcapGetStats(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
823
824 /*!
825   \brief Get the number of LEDs the referenced adapter has available.
826   \param AdapterHandle Handle to the adapter.
827   \param NumberOfLeds Number of LEDs available on this adapter.
828   \return TRUE on success.
829 */
830 gboolean AirpcapGetLedsNumber(PAirpcapHandle AdapterHandle, guint * NumberOfLeds);
831
832 /*!
833   \brief Turn on one of the adapter's LEDs.
834   \param AdapterHandle Handle to the adapter.
835   \param LedNumber zero-based identifier of the LED to turn on.
836   \return TRUE on success.
837 */
838 gboolean AirpcapTurnLedOn(PAirpcapHandle AdapterHandle, guint LedNumber);
839
840 /*!
841   \brief Turn off one of the adapter's LEDs.
842   \param AdapterHandle Handle to the adapter.
843   \param LedNumber zero-based identifier of the LED to turn off.
844   \return TRUE on success.
845 */
846 gboolean AirpcapTurnLedOff(PAirpcapHandle AdapterHandle, guint LedNumber);
847
848 /*!
849   \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.
850   \param AdapterHandle Handle to the adapter.
851   \param ChannelInfo The new channel information to set.
852   \return TRUE on success.
853
854   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
855          immediately reflected on all the other capture instances.
856 */
857 gboolean AirpcapSetDeviceChannelEx(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo);
858
859 /*!
860   \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.
861   \param AdapterHandle Handle to the adapter.
862   \param PChannelInfo Pointer to a user-supplied variable into which the function will copy the currently configured channel information.
863   \return TRUE on success.
864
865   \note this is a device-related function: when you change the channel from an open capture instance, the change will be
866          immediately reflected on all the other capture instances.
867 */
868 gboolean AirpcapGetDeviceChannelEx(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo);
869
870 /*!
871   \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.
872
873   Every control channel is listed multiple times, one for each different supported extension channel. For example channel 6 (2437MHz)  is usually listed three times:
874         - <b>Frequency 2437 Extension +1</b>. Control channel is 6, extension channel is 10.
875         - <b>Frequency 2437 Extension 0</b>. Control channel is 6, no extension channel is used (20MHz channel and legacy mode).
876         - <b>Frequency 2437 Extension -1</b>. Control channel is 6, extension channel is 2.
877   \param AdapterHandle Handle to the adapter.
878   \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
879   \param pNumChannelInfo Number of channels returned in the array.
880   \return TRUE on success.
881
882   \note The supported channels are not listed in any specific order.
883 */
884 gboolean AirpcapGetDeviceSupportedChannels(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo *ppChannelInfo, guint * pNumChannelInfo);
885
886 /*!
887   \brief Converts a given frequency to the corresponding channel.
888
889   \param Frequency Frequency of the channel, in MHz.
890   \param PChannel Pointer to a user-supplied variable that will contain the channel number on success.
891   \param PBand Pointer to a user-supplied variable that will contain the band (a or b/g) of the given channel.
892   \return TRUE on success, i.e. the frequency corresponds to a valid a or b/g channel.
893 */
894 gboolean AirpcapConvertFrequencyToChannel(guint Frequency, guint * PChannel, PAirpcapChannelBand PBand);
895
896 /*!
897   \brief Converts a given channel to the corresponding frequency.
898
899   \param Channel Channel number to be converted.
900   \param PFrequency Pointer to a user-supplied variable that will contain the channel frequency in MHz on success.
901   \return TRUE on success, i.e. the given channel number exists.
902 */
903 gboolean AirpcapConvertChannelToFrequency(guint Channel, guint * PFrequency);
904
905
906 /*@}*/
907
908 #endif // __AIRPCAP_DRIVER__
909
910 #ifdef __cplusplus
911 }
912 #endif
913
914 #endif // !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_)