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