From Patrick vd Lageweg:
[obnox/wireshark/wip.git] / airpcap.h
1 /*
2  * Copyright (c) 2006 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 /* This disables a VS warning for zero-sized arrays. All the compilers we support have that feature */
26 #pragma warning( disable : 4200)
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /*!
33         \mainpage AirPcap interface documentation
34
35         \section Introduction
36
37         This document describes the data structures and the functions exported by the CACE Technologies AirPcap library.
38         The AirPcap library provides low-level access to the AirPcap driver including advanced capabilities such as channel setting,
39         link type control and WEP configuration.<br>
40         This manual includes the following sections:
41
42         \note throughout this documentation, \i device refers to a physical USB AirPcap device, wile \i adapter is an open API
43         instance. Most of the AirPcap API operations are adapter-specific but some of them, like setting the channel, are
44         per-device and will be reflected on all the open adapters. These functions will have "Device" in their name, e.g.
45         AirpcapSetDeviceChannel().
46
47         \b Sections:
48
49         - \ref airpcapfuncs
50         - \ref airpcapdefs
51         - \ref radiotap
52 */
53
54 /** @defgroup airpcapdefs AirPcap definitions and data structures
55  *  @{
56  */
57
58 /*!
59   \brief This string is the fixed prefix in the airpcap adapter name.
60   It can be used to parse the name field in an AirpcapDeviceDescription structure.
61 */
62 #define AIRPCAP_DEVICE_NAME_PREFIX "\\\\.\\airpcap"
63
64 /*!
65   \brief This string is the scanf modifier to extract the adapter number from an adapter name.
66   It can be used to parse the name field in an AirpcapDeviceDescription structure with scanf.
67 */
68 #define AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING "\\\\.\\airpcap%u"
69
70 /*!
71   \brief This string is the scanf modifier to extract the adapter "Any" string from an adapter name.
72   It can be used to parse the name field in an AirpcapDeviceDescription structure with scanf.
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 Type of frame validation the adapter performs.
117    An adapter can be instructed to accept different kind of frames: correct frames only, frames with wrong Frame Check Sequence (FCS) only, all frames.
118 */
119 typedef enum _AirpcapValidationType
120 {
121     AIRPCAP_VT_ACCEPT_EVERYTHING = 1,           /* Accept all the frames the device captures */
122     AIRPCAP_VT_ACCEPT_CORRECT_FRAMES = 2,       /* Accept correct frames only, i.e. frames with correct Frame Check Sequence (FCS). */
123     AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES = 3,       /* Accept corrupt frames only, i.e. frames with worng Frame Check Sequence (FCS). */
124         AIRPCAP_VT_UNKNOWN = 4                                  /* Unknown validation type. You should see it only in case of error. */
125 }AirpcapValidationType, *PAirpcapValidationType;
126
127 /*!
128   \brief Type of decryption the adapter performs.
129    An adapter can be instructed to turn decryption (based on the device-configured keys configured
130    with \ref AirpcapSetDeviceKeys()) on or off.
131 */
132 typedef enum _AirpcapDecryptionState
133 {
134     AIRPCAP_DECRYPTION_ON = 1,                          /* This adapter performs decryption */
135     AIRPCAP_DECRYPTION_OFF = 2                          /* This adapter does not perform decryption */
136 }AirpcapDecryptionState, *PAirpcapDecryptionState;
137
138
139 /*!
140   \brief Storage for a MAC address
141 */
142 typedef struct _AirpcapMacAddress
143 {
144         BYTE Address[6];                /* MAC address bytes */
145 }
146 #ifdef __MINGW32__
147 __attribute__((__packed__))
148 #endif /* __MINGW32__ */
149 AirpcapMacAddress, *PAirpcapMacAddress;
150
151 /*!
152   \brief This structure is used to store a collection of WEP keys.
153   Note that the definition of the structure doesn't contain any key, so be careful to allocate a buffer
154   with the size of the key, like in the following example:
155
156   \code
157         PAirpcapKeysCollection KeysCollection;
158         UINT KeysCollectionSize;
159
160         KeysCollectionSize = sizeof(AirpcapKeysCollection) + NumKeys * sizeof(AirpcapKey);
161
162         KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
163         if(!KeysCollection)
164         {
165                 // Error
166         }
167   \endcode
168 */
169 typedef struct _AirpcapKeysCollection
170 {
171         UINT nKeys;                                                                                             /* Number of keys in the collection */
172         AirpcapKey Keys[0];                                                                             /* Array of nKeys keys.  */
173 } AirpcapKeysCollection, *PAirpcapKeysCollection;
174
175 /*!
176   \brief Packet header.
177
178   This structure defines the BPF that preceeds every packet delivered to the application.
179 */
180 typedef struct _AirpcapBpfHeader
181 {
182         UINT TsSec;                     /* Timestamp associated with the captured packet. SECONDS. */
183         UINT TsUsec;            /* Timestamp associated with the captured packet. MICROSECONDS. */
184         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. */
185         UINT Originallen;       /* Original length of packet */
186         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. */
187 }
188 #ifdef __MINGW32__
189 __attribute__((__packed__))
190 #endif /* __MINGW32__ */
191 AirpcapBpfHeader, *PAirpcapBpfHeader;
192
193 /* Helper macros to extract packets coming from the driver. Rounds up to the next even multiple of AIRPCAP_ALIGNMENT.  */
194 #define AIRPCAP_ALIGNMENT sizeof(int)
195 #define AIRPCAP_WORDALIGN(x) (((x)+(AIRPCAP_ALIGNMENT-1))&~(AIRPCAP_ALIGNMENT-1))
196
197 #ifndef __MINGW32__
198 #pragma pack(pop)
199 #endif /* __MINGW32__ */
200
201 #define AIRPCAP_ERRBUF_SIZE 512         /* Size of the error buffer, in bytes */
202
203 #ifndef __AIRPCAP_DRIVER__
204
205 /*!
206   \brief Link type.
207    AirPcap supports two kind of 802.11 linktypes: plain 802.11 and radiotap.
208 */
209 typedef enum _AirpcapLinkType
210 {
211     AIRPCAP_LT_802_11 = 1,                              /* plain 802.11 linktype. Every packet in the buffer contains the raw 802.11 frame, including MAC FCS. */
212     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. */
213         AIRPCAP_LT_UNKNOWN = 3                          /* Unknown linktype. You should see it only in case of error. */
214 }AirpcapLinkType, *PAirpcapLinkType;
215
216 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
217 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
218 /*!
219   \brief Adapter handle.
220 */
221 typedef struct _AirpcapHandle AirpcapHandle, *PAirpcapHandle;
222 #endif
223
224 /*!
225   \brief Capture statistics.
226    Returned by \ref AirpcapGetStats();
227 */
228 typedef struct _AirpcapStats
229 {
230         UINT Recvs;                     /* Number of packets that the driver received by the adapter  */
231                                                 /* from the beginning of the current capture. This value includes the packets  */
232                                                 /* dropped because of buffer full. */
233         UINT Drops;                     /* number of packets that the driver dropped from the beginning of a capture.  */
234                                                 /* A packet is lost when the the buffer of the driver is full.  */
235         UINT IfDrops;           /* Packets dropped by the card before going to the USB bus.  */
236                                                 /* Not supported at the moment. */
237         UINT Capt;                      /* number of packets that pass the BPF filter, find place in the kernel buffer and */
238                                                 /* therefore reach the application. */
239 }AirpcapStats, *PAirpcapStats;
240
241 /*@}*/
242
243 /** @defgroup airpcapfuncs AirPcap functions
244  *  @{
245  */
246
247 /*!
248   \brief Return a string with the API version
249   \param VersionMajor Pointer to a variable that will be filled with the major version number.
250   \param VersionMinor Pointer to a variable that will be filled with the minor version number.
251   \param VersionRev Pointer to a variable that will be filled with the revision number.
252   \param VersionBuild Pointer to a variable that will be filled with the build number.
253 */
254 void AirpcapGetVersion(PUINT VersionMajor, PUINT VersionMinor, PUINT VersionRev, PUINT VersionBuild);
255
256 /*!
257   \brief Return the last error related to the specified handle
258   \param AdapterHandle Handle to an open adapter.
259   \return The string with the last error.
260 */
261 PCHAR AirpcapGetLastError(PAirpcapHandle AdapterHandle);
262
263 /*!
264   \brief Return the list of available devices
265   \param PPAllDevs Address to a caller allocated pointer. On success this pointer will receive the head of a list of available devices.
266   \param Ebuf String that will contain error information if FALSE is returned. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
267   \return TRUE on success. FALSE is returned on failure, in which case Ebuf is filled in with an appropriate error message.
268
269         Here's a snppet of code that shows how to use AirpcapGetDeviceList():
270
271         \code
272         CHAR Ebuf[AIRPCAP_ERRBUF_SIZE];
273         AirpcapDeviceDescription *Desc, *tDesc;
274
275         if(AirpcapGetDeviceList(&Desc, Ebuf) == -1)
276         {
277                 printf("Unable to get the list of devices: %s\n", Ebuf);
278                 return -1;
279         }
280
281         for(tDesc = Desc; tDesc; tDesc = tDesc->next)
282         {
283                 printf("%u) %s (%s)\n",
284                 ++i,
285                 tDesc->Name,
286                 tDesc->Description);
287         }
288         \endcode
289 */
290 BOOL AirpcapGetDeviceList(PAirpcapDeviceDescription *PPAllDevs, PCHAR Ebuf);
291
292 /*!
293   \brief Free a list of devices returned by AirpcapGetDeviceList()
294   \param PAllDevs Head of the list of devices returned by \ref AirpcapGetDeviceList().
295 */
296 VOID AirpcapFreeDeviceList(PAirpcapDeviceDescription PAllDevs);
297
298 /*!
299   \brief Open an adapter
300   \param DeviceName Name of the device to open. Use \ref AirpcapGetDeviceList() to get the list of devices.
301   \param Ebuf String that will contain error information in case of failure. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
302   \return A PAirpcapHandle handle on success. NULL is returned on failure, in which case Ebuf is filled in with an appropriate error message.
303 */
304 PAirpcapHandle AirpcapOpen(PCHAR DeviceName, PCHAR Ebuf);
305
306 /*!
307   \brief Close an adapter
308   \param AdapterHandle Handle to the adapter to close.
309 */
310 VOID AirpcapClose(PAirpcapHandle AdapterHandle);
311
312 /*!
313   \brief Set the link type of an adapter
314   \param AdapterHandle Handle to the adapter.
315   \param NewLinkType the "link type", i.e. the format of the frames that will be received from the adapter.
316   \return TRUE on success.
317
318   the "link type" determines how the driver will encode the packets captured from the network.
319   Aircap supports two link types:
320   - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
321    power information. Look at the Capture_no_radio example application in the developer's pack
322    for a reference on how to decode 802.11 frames with this link type.
323   - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
324   that contains power and channel information. More information about the radiotap header can be found int the
325   \ref radiotap section. Moreover, the "Capture_radio" example application in
326   the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
327 */
328 BOOL AirpcapSetLinkType(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
329
330 /*!
331   \brief Get the link type of the specified adapter
332   \param AdapterHandle Handle to the adapter.
333   \param PLinkType Pointer to a caller allocated AirpcapLinkType variable that will contain the link type of the adapter.
334   \return TRUE on success.
335
336   the "link type" determines how the driver will encode the packets captured from the network.
337   Aircap supports two link types:
338   - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
339    power information. Look at the Capture_no_radio example application in the developer's pack
340    for a reference on how to decode 802.11 frames with this link type.
341   - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
342   that contains power and channel information. More information about the radiotap header can be found int the
343   \ref radiotap section. Moreover, the "Capture_radio" example application in
344   the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
345 */
346 BOOL AirpcapGetLinkType(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
347
348 /*!
349   \brief Configures the adapter on whether to include the MAC Frame Check Sequence in the captured packets.
350   \param AdapterHandle Handle to the adapter.
351   \param IsFcsPresent TRUE if the packets should include the FCS. FALSE otherwise
352   \return TRUE on success.
353
354   In the default configuration, the adapter includes the FCS in the captured packets. The MAC Frame Check Sequence
355   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
356   link types.
357   When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
358   that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
359   when FCS inclusion is off.
360 */
361 BOOL AirpcapSetFcsPresence(PAirpcapHandle AdapterHandle, BOOL IsFcsPresent);
362
363 /*!
364   \brief Returns TRUE if the specified adapter includes the MAC Frame Check Sequence in the captured packets
365   \param AdapterHandle Handle to the adapter.
366   \param PIsFcsPresent User-provided variable that will be set to true if the adapter is including the FCS.
367   \return TRUE if the operation is successful. FALSE otherwise.
368
369   In the default configuration, the adatper has FCS inclusion turned on. The MAC Frame Check Sequence is 4 bytes
370   and is located at the end of the 802.11 packet, with both AIRPCAP_LT_802_11 and AIRPCAP_LT_802_11_PLUS_RADIO
371   link types.
372   When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
373   that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
374   when FCS inclusion is off.
375 */
376 BOOL AirpcapGetFcsPresence(PAirpcapHandle AdapterHandle, PBOOL PIsFcsPresent);
377
378 /*!
379   \brief Configures the adapter to accept or drop frames with an incorrect Frame Check sequence (FCS).
380   \param AdapterHandle Handle to the adapter.
381   \param ValidationType The type of validation the driver will perform. See the documentation of \ref AirpcapValidationType for details.
382   \return TRUE on success.
383
384   \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
385 */
386 BOOL AirpcapSetFcsValidation(PAirpcapHandle AdapterHandle, AirpcapValidationType ValidationType);
387
388 /*!
389   \brief Checks if the specified adapter is configured to capture frames with incorrect an incorrect Frame Check Sequence (FCS).
390   \param AdapterHandle Handle to the adapter.
391   \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.
392   \return TRUE if the operation is succesful. FALSE otherwise.
393
394   \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
395 */
396 BOOL AirpcapGetFcsValidation(PAirpcapHandle AdapterHandle, PAirpcapValidationType ValidationType);
397
398 /*!
399   \brief Set the list of decryption keys that the driver is going to use with the specified device.
400   \param AdapterHandle Handle an open adapter instance.
401   \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
402   \return TRUE if the operation is successful. FALSE otherwise.
403
404   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
405   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
406   to the application.
407   The driver supports, for every device, multiple keys at the same time.
408
409   At this time, the only supported decryption method is WEP.
410
411   The configured decryption keys are device-specific: they will not be used by other airpcap devices besides the specified one.
412
413   The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
414   correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
415
416   \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be
417          immediately reflected on all the other capture instances.
418 */
419 BOOL AirpcapSetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
420
421 /*!
422   \brief Returns the list of decryption keys in the driver that are currently associated with the specified device
423   \param AdapterHandle Handle to an open adapter instance.
424   \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
425   \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
426                                                 \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
427   \return TRUE if the operation is succesful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
428   If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
429   needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
430   KeysCollectionSize will be zero.
431
432   This function returns the list of decryption keys in the driver that are associated with the specified device.
433   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
434   keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
435   to the application.
436   The driver supports, for every device, multiple keys at the same time.
437
438   The configured decryption keys are device-specific, therefore AirpcapGetDeviceKeys() will return a different set of keys
439   when called on different devices.
440
441   At this time, the only supported decryption method is WEP.
442
443   \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be
444          immediately reflected on all the other capture instances.
445 */
446 BOOL AirpcapGetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
447
448 /*!
449   \brief Turns on or off the decryption of the incoming frames
450   \param AdapterHandle Handle to the adapter.
451   \param ValidationType Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
452   \return TRUE on success.
453
454   The decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
455   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
456 */
457 BOOL AirpcapSetDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
458
459 /*!
460   \brief Tells if this open instance is configured to perform the decryption of the incoming frames
461   \param AdapterHandle Handle to the adapter.
462   \param ValidationType Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
463   \return TRUE if the operation is succesful. FALSE otherwise.
464
465   The decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
466   \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
467 */
468 BOOL AirpcapGetDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
469
470 /*!
471   \brief Set the radio channel of a device
472   \param AdapterHandle Handle to the adapter.
473   \param Channel the new channel to set.
474   \return TRUE on success.
475
476   Valid channels are in the range 1-14. The default channel setting is 6.
477
478   \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be
479          immediately reflected on all the other capture instances.
480 */
481 BOOL AirpcapSetDeviceChannel(PAirpcapHandle AdapterHandle, UINT Channel);
482
483 /*!
484   \brief Get the radio channel of a device
485   \param AdapterHandle Handle to the adapter.
486   \param PChannel Pointer to a user-supplied variable into which the function will copy the currently configured radio channel.
487   \return TRUE on success.
488
489   Valid channels are in the range 1-14. The default channel setting is 6.
490
491   \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be
492          immediately reflected on all the other capture instances.
493 */
494 BOOL AirpcapGetDeviceChannel(PAirpcapHandle AdapterHandle, PUINT PChannel);
495
496 /*!
497   \brief Set the size of the kernel packet buffer for this adapter
498   \param AdapterHandle Handle to the adapter.
499   \param BufferSize New size, in bytes.
500   \return TRUE on success.
501
502   Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
503   This function can be used to change the size of this buffer, and can be called at any time.
504   A bigger kernel buffer size decreases the risk of dropping packets during network bursts or when the
505   application is busy, at the cost of higher kernel memory usage.
506
507   \note: don't use this function unless you know what you are doing. Due to chaching issues and bigger non-paged
508   memory consumption, Bigger buffer sizes can decrease the capture performace instead of improving it.
509 */
510 BOOL AirpcapSetKernelBuffer(PAirpcapHandle AdapterHandle, UINT BufferSize);
511
512 /*!
513   \brief Get the size of the kernel packet buffer for this adapter
514   \param AdapterHandle Handle to the adapter.
515   \param PSizeBytes User-allocated variable that will be filled with the size of the kernel buffer.
516   \return TRUE on success.
517
518   Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
519   This function can be used to get the size of this buffer.
520 */
521 BOOL AirpcapGetKernelBufferSize(PAirpcapHandle AdapterHandle, PUINT PSizeBytes);
522
523 /*!
524   \brief Saves the configuration of the specified adapter in the registry, so that it becomes the default for this adapter.
525   \param AdapterHandle Handle to the adapter.
526   \return TRUE on success. FALSE on failure.
527
528   Almost all the AirPcap calls that modify the configuration (\ref AirpcapSetLinkType(), \ref AirpcapSetFcsPresence(),
529   \ref AirpcapSetFcsValidation(), \ref AirpcapSetKernelBuffer(), \ref AirpcapSetMinToCopy())
530   affect only the referenced AirPcap open instance. This means that if you do another \ref AirpcapOpen() on the same
531   adapter, the configuration changes will not be remembered, and the new adapter handle will have default configuration
532   settings.
533
534   Exceptions to this rule are the \ref AirpcapSetDeviceChannel() and \ref AirpcapSetDeviceKeys() functions: a channel change is
535   reflected on all the open instances, and remembered until the next call to \ref AirpcapSetDeviceChannel(), until the adapter
536   is unplugged, or until the machine is powered off. Same thing for the configuration of the WEP keys.
537
538   AirpcapStoreCurConfigAsAdapterDefault() stores the configuration of the give open instance as the default for the adapter:
539   all the instances opened in the future will have the same configuration that this adapter currently has.
540   The configuration is stored in the registry, therefore it is remembered even when the adapter is unplugged or the
541   machine is turned off. However, an adapter doesn't bring its configuration with it from machine to machine.
542
543   the configuration information saved in the registry includes the following parameters:
544    - channel
545    - kernel buffer size
546    - mintocopy
547    - link type
548    - CRC presence
549    - Encryption keys
550    - Encryption Enabled/Disabled state
551
552   The configuration is adapter-specific. This means that changing the configuration of an adapter
553   doesn't modify the one of the other adapters that are currently used or that will be used in the future.
554
555   \note AirpcapStoreCurConfigAsAdapterDefault() must have exclusive access to the adapter -- it
556    will fail if more than one AirPcap handle is opened at the same time for this adapter.
557    AirpcapStoreCurConfigAsAdapterDefault() needs administrator privileges. It will fail if the calling user
558    is not a local machine administrator.
559 */
560 BOOL AirpcapStoreCurConfigAsAdapterDefault(PAirpcapHandle AdapterHandle);
561
562 /*!
563   \brief Set the BPF kernel filter for an adapter
564   \param AdapterHandle Handle to the adapter.
565   \param Instructions pointer to the first BPF instruction in the array. Corresponds to the  bf_insns
566    in a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
567   \param Len Number of instructions in the array pointed by the previous field. Corresponds to the bf_len in
568   a a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
569   \return TRUE on success.
570
571   The AirPcap driver is able to perform kernel-level filtering using the standard BPF pseudo-machine format. You can read
572   the WinPcap documentation at http://www.winpcap.org/devel.htm for more details on the BPF filtering mechaism.
573
574   A filter can be automatically created by using the pcap_compile() function of the WinPcap API. This function
575   converts a human readable text expression with the tcpdump/libpcap syntax into a BPF program.
576   If your program doesn't link wpcap, but you need to generate the code for a particular filter, you can run WinDump
577   with the -d or -dd or -ddd flags to obtain the pseudocode.
578
579 */
580 BOOL AirpcapSetFilter(PAirpcapHandle AdapterHandle, PVOID Instructions, UINT Len);
581
582 /*!
583   \brief Return the MAC address of an adapter.
584   \param AdapterHandle Handle to the adapter.
585   \param PMacAddress Pointer to a user allocated MAC address.
586    The size of this buffer needs to be at least 6 bytes.
587   \return TRUE on success.
588 */
589 BOOL AirpcapGetMacAddress(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
590
591 /*!
592   \brief Set the mintocopy parameter for an open adapter
593   \param AdapterHandle Handle to the adapter.
594   \param MinToCopy is the mintocopy size in bytes.
595   \return TRUE on success.
596
597   When the number of bytes in the kernel buffer changes from less than mintocopy bytes to greater than or equal to mintocopy bytes,
598   the read event is signalled (see \ref AirpcapGetReadEvent()). A high value for mintocopy results in poor responsiveness since the
599   driver may signal the application "long" after the arrival of the packet. And a high value results in low CPU loading
600   by minimizing the number of user/kernel context switches.
601   A low MinToCopy results in good responsiveness since the driver will signal the application close to the arrival time of
602   the packet. This has higher CPU loading over the first approach.
603 */
604 BOOL AirpcapSetMinToCopy(PAirpcapHandle AdapterHandle, UINT MinToCopy);
605
606 /*!
607   \brief Gets an event that is signaled when that is signalled when packets are available in the kernel buffer (see \ref AirpcapSetMinToCopy()).
608   \param AdapterHandle Handle to the adapter.
609   \param PReadEvent Pointer to a user-supplied handle that in which the read event will be copied.
610   \return TRUE on success.
611
612   \note the event is signalled when at least mintocopy bytes are present in the kernel buffer (see \ref AirpcapSetMinToCopy()).
613   This event can be used by WaitForSingleObject() and WaitForMultipleObjects() to create blocking behavior when reading
614   packets from one or more adapters (see \ref AirpcapRead()).
615 */
616 BOOL AirpcapGetReadEvent(PAirpcapHandle AdapterHandle, HANDLE* PReadEvent);
617
618 /*!
619   \brief Fills a user-provided buffer with zero or more packets that have been captured on the referenced adapter.
620   \param AdapterHandle Handle to the adapter.
621   \param Buffer pointer to the buffer that will be filled with captured packets.
622   \param BufSize size of the input buffer that will contain the packets, in bytes.
623   \param PReceievedBytes Pointer to a user supplied variable that will receive the number of bytes copied by AirpcapRead.
624   Can be smaller than BufSize.
625   \return TRUE on success.
626
627   802.11 frames are returned by the driver in buffers. Every 802.11 frame in the buffer is preceded by a \ref AirpcapBpfHeader structure.
628   The suggested way to use an AirPcap adapter is through the pcap API exported by wpcap.dll. If this is not
629   possible, the Capture_radio and Capture_no_radio examples in the AirPcap developer's pack show how to properly decode the
630   packets in the read buffer returned by AirpcapRead().
631
632   \note this function is NOT blocking. Blocking behavior can be obtained using the event returned
633    by \ref AirpcapGetReadEvent(). See also \ref AirpcapSetMinToCopy().
634 */
635 BOOL AirpcapRead(PAirpcapHandle AdapterHandle, PBYTE Buffer, UINT BufSize, PUINT PReceievedBytes);
636
637 /*!
638   \brief Get per-adapter WinPcap-compatible capture statistics.
639   \param AdapterHandle Handle to the adapter.
640   \param PStats pointer to a user-allocated AirpcapStats structure that will be filled with statistical information.
641   \return TRUE on success.
642 */
643 BOOL AirpcapGetStats(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
644
645 /*!
646   \brief Get the number of LEDs the referenced adapter has available.
647   \param AdapterHandle Handle to the adapter.
648   \param NumberOfLeds Number of LEDs available on this adapter.
649   \return TRUE on success.
650 */
651 BOOL AirpcapGetLedsNumber(PAirpcapHandle AdapterHandle, PUINT NumberOfLeds);
652
653 /*!
654   \brief Turn on one of the adapter's LEDs.
655   \param AdapterHandle Handle to the adapter.
656   \param LedNumber zero-based identifier of the LED to turn on.
657   \return TRUE on success.
658 */
659 BOOL AirpcapTurnLedOn(PAirpcapHandle AdapterHandle, UINT LedNumber);
660
661 /*!
662   \brief Turn off one of the adapter's LEDs.
663   \param AdapterHandle Handle to the adapter.
664   \param LedNumber zero-based identifier of the LED to turn off.
665   \return TRUE on success.
666 */
667 BOOL AirpcapTurnLedOff(PAirpcapHandle AdapterHandle, UINT LedNumber);
668
669 /*@}*/
670
671 #endif /* __AIRPCAP_DRIVER__ */
672
673 #ifdef __cplusplus
674 }
675 #endif
676
677 #endif /* !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_) */