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