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