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