2 * Copyright (c) 2006-2007 CACE Technologies, Davis (California)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted.
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.
22 #if !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_)
23 #define AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_
26 // This disables a VS warning for zero-sized arrays.
27 #pragma warning( disable : 4200)
28 // This stops VS2005 ranting against stdio.
29 #pragma warning( disable : 4996)
32 #ifdef HAVE_WINSOCK2_H
41 \mainpage AirPcap interface documentation
45 This document describes the data structures and the functions exported by the CACE Technologies AirPcap library.
46 The AirPcap library provides low-level access to the AirPcap driver including advanced capabilities such as channel setting,
47 link type control and WEP configuration.<br>
48 This manual includes the following sections:
50 \note throughout this documentation, \e device refers to a physical USB AirPcap device, while \e adapter is an open API
51 instance. Most of the AirPcap API operations are adapter-specific but some of them, like setting the channel, are
52 per-device and will be reflected on all the open adapters. These functions will have "Device" in their name, e.g.
53 AirpcapSetDeviceChannel().
62 /** @defgroup airpcapdefs AirPcap definitions and data structures
67 \brief This string is the fixed prefix in the airpcap adapter name.
68 It can be used to parse the name field in an AirpcapDeviceDescription structure.
70 #define AIRPCAP_DEVICE_NAME_PREFIX "\\\\.\\airpcap"
73 \brief This string is the scanf modifier to extract the adapter number from an adapter name.
74 It can be used to parse the name field in an AirpcapDeviceDescription structure with scanf.
76 #define AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING "\\\\.\\airpcap%u"
78 #define AIRPCAP_DEVICE_ANY_EXTRACT_STRING "\\\\.\\airpcap_any"
81 \brief Entry in the list returned by \ref AirpcapGetDeviceList();
83 typedef struct _AirpcapDeviceDescription
85 struct _AirpcapDeviceDescription *next; ///< Next element in the list
86 gchar * Name; ///< Device name
87 gchar * Description; ///< Device description
88 } AirpcapDeviceDescription, *PAirpcapDeviceDescription;
90 #define MAX_ENCRYPTION_KEYS 64
92 #define WEP_KEY_MAX_SIZE 32 ///< Maximum size of a WEP key, in bytes. This is the size of an entry in the
93 ///< AirpcapWepKeysCollection structure
102 #define AIRPCAP_KEYTYPE_WEP 0 ///< Key type: WEP. The key can have an arbitrary length smaller than 32 bytes.
103 #define AIRPCAP_KEYTYPE_TKIP 1 ///< Key type: TKIP (WPA). NOT SUPPORTED YET.
104 #define AIRPCAP_KEYTYPE_CCMP 2 ///< Key type: CCMP (WPA2). NOT SUPPORTED YET.
107 \brief WEP key container
109 typedef struct _AirpcapKey
111 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.
112 guint KeyLen; ///< Length of the key, in bytes
113 guint8 KeyData[WEP_KEY_MAX_SIZE]; ///< Key Data
116 __attribute__((__packed__))
117 #endif // __MINGW32__
118 AirpcapKey, *PAirpcapKey;
121 \brief frequency Band.
122 802.11 adapters can support different frequency bands, the most important of which are: 2.4GHz (802.11b/g/n)
123 and 5GHz (802.11a/n).
125 typedef enum _AirpcapChannelBand
127 AIRPCAP_CB_AUTO = 1, ///< Automatically pick the best frequency band
128 AIRPCAP_CB_2_4_GHZ = 2, ///< 2.4 GHz frequency band
129 AIRPCAP_CB_4_GHZ = 4, ///< 4 GHz frequency band
130 AIRPCAP_CB_5_GHZ = 5 ///< 5 GHz frequency band
131 }AirpcapChannelBand, *PAirpcapChannelBand;
134 \brief Type of frame validation the adapter performs.
135 An adapter can be instructed to accept different kind of frames: correct frames only, frames with wrong Frame Check Sequence (FCS) only, all frames.
137 typedef enum _AirpcapValidationType
139 AIRPCAP_VT_ACCEPT_EVERYTHING = 1, ///< Accept all the frames the device captures
140 AIRPCAP_VT_ACCEPT_CORRECT_FRAMES = 2, ///< Accept correct frames only, i.e. frames with correct Frame Check Sequence (FCS).
141 AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES = 3, ///< Accept corrupt frames only, i.e. frames with worng Frame Check Sequence (FCS).
142 AIRPCAP_VT_UNKNOWN = 4 ///< Unknown validation type. You should see it only in case of error.
143 }AirpcapValidationType, *PAirpcapValidationType;
146 \brief Type of decryption the adapter performs.
147 An adapter can be instructed to turn decryption (based on the device-configured keys configured
148 with \ref AirpcapSetDeviceKeys()) on or off.
150 typedef enum _AirpcapDecryptionState
152 AIRPCAP_DECRYPTION_ON = 1, ///< This adapter performs decryption
153 AIRPCAP_DECRYPTION_OFF = 2 ///< This adapter does not perform decryption
154 }AirpcapDecryptionState, *PAirpcapDecryptionState;
158 \brief Storage for a MAC address
160 typedef struct _AirpcapMacAddress
162 guint8 Address[6]; ///< MAC address bytes
165 __attribute__((__packed__))
166 #endif // __MINGW32__
167 AirpcapMacAddress, *PAirpcapMacAddress;
170 \brief This structure is used to store a collection of WEP keys.
171 Note that the definition of the structure doesn't contain any key, so be careful to allocate a buffer
172 with the size of the key, like in the following example:
175 PAirpcapKeysCollection KeysCollection;
176 guint KeysCollectionSize;
178 KeysCollectionSize = sizeof(AirpcapKeysCollection) + NumKeys * sizeof(AirpcapKey);
180 KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
187 typedef struct _AirpcapKeysCollection
189 guint nKeys; ///< Number of keys in the collection
190 AirpcapKey Keys[0]; ///< Array of nKeys keys.
191 } AirpcapKeysCollection, *PAirpcapKeysCollection;
194 \brief Packet header.
196 This structure defines the BPF that preceeds every packet delivered to the application.
198 typedef struct _AirpcapBpfHeader
200 guint TsSec; ///< Timestamp associated with the captured packet. SECONDS.
201 guint TsUsec; ///< Timestamp associated with the captured packet. MICROSECONDS.
202 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.
203 guint Originallen; ///< Original length of packet
204 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.
207 __attribute__((__packed__))
208 #endif // __MINGW32__
209 AirpcapBpfHeader, *PAirpcapBpfHeader;
211 /// Helper macros to extract packets coming from the driver. Rounds up to the next even multiple of AIRPCAP_ALIGNMENT.
212 #define AIRPCAP_ALIGNMENT sizeof(int)
213 #define AIRPCAP_WORDALIGN(x) (((x)+(AIRPCAP_ALIGNMENT-1))&~(AIRPCAP_ALIGNMENT-1))
218 #endif // __MINGW32__
221 #define AIRPCAP_ERRBUF_SIZE 512 ///< Size of the error buffer, in bytes
223 #ifndef __AIRPCAP_DRIVER__
227 AirPcap supports two kind of 802.11 linktypes: plain 802.11 and radiotap.
229 #undef _AirpcapLinkType
230 typedef enum _AirpcapLinkType
232 AIRPCAP_LT_802_11 = 1, ///< plain 802.11 linktype. Every packet in the buffer contains the raw 802.11 frame, including MAC FCS.
233 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.
234 AIRPCAP_LT_UNKNOWN = 3, ///< Unknown linktype. You should see it only in case of error.
235 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.
236 }AirpcapLinkType, *PAirpcapLinkType;
238 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
239 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
241 \brief Adapter handle.
243 typedef struct _AirpcapHandle AirpcapHandle, *PAirpcapHandle;
247 \brief Capture statistics.
248 Returned by \ref AirpcapGetStats();
250 typedef struct _AirpcapStats
252 guint Recvs; ///< Number of packets that the driver received by the adapter
253 ///< from the beginning of the current capture. This value includes the packets
254 ///< dropped because of buffer full.
255 guint Drops; ///< number of packets that the driver dropped from the beginning of a capture.
256 ///< A packet is lost when the the buffer of the driver is full.
257 guint IfDrops; ///< Packets dropped by the card before going to the USB bus.
258 ///< Not supported at the moment.
259 guint Capt; ///< number of packets that pass the BPF filter, find place in the kernel buffer and
260 ///< therefore reach the application.
261 }AirpcapStats, *PAirpcapStats;
264 \brief Channel information.
265 Used by \ref AirpcapSetDeviceChannelEx(), \ref AirpcapGetDeviceChannelEx(), \ref AirpcapGetDeviceSupportedChannels()
267 typedef struct _AirpcapChannelInfo
269 guint Frequency; ///< Channel frequency, in MHz.
271 \brief 802.11n specific. Offset of the extension channel in case of 40MHz channels.
273 Possible values are -1, 0 +1:
274 - -1 means that the extension channel should be below the control channel (e.g. Control = 5 and Extension = 1)
275 - 0 means that no extension channel should be used (20MHz channels or legacy mode)
276 - +1 means that the extension channel should be above the control channel (e.g. Control = 1 and Extension = 5)
278 In case of 802.11a/b/g channels (802.11n legacy mode), this field should be set to 0.
281 guint8 Reserved[3]; ///< Reserved. It should be set to {0,0,0}.
283 AirpcapChannelInfo, *PAirpcapChannelInfo;
288 /** @defgroup airpcapfuncs AirPcap functions
293 \brief Return a string with the API version
294 \param VersionMajor Pointer to a variable that will be filled with the major version number.
295 \param VersionMinor Pointer to a variable that will be filled with the minor version number.
296 \param VersionRev Pointer to a variable that will be filled with the revision number.
297 \param VersionBuild Pointer to a variable that will be filled with the build number.
299 void AirpcapGetVersion(guint * VersionMajor, guint * VersionMinor, guint * VersionRev, guint * VersionBuild);
302 \brief Return the last error related to the specified handle
303 \param AdapterHandle Handle to an open adapter.
304 \return The string with the last error.
306 gchar * AirpcapGetLastError(PAirpcapHandle AdapterHandle);
309 \brief Return the list of available devices
310 \param PPAllDevs Address to a caller allocated pointer. On success this pointer will receive the head of a list of available devices.
311 \param Ebuf String that will contain error information if FALSE is returned. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
312 \return TRUE on success. FALSE is returned on failure, in which case Ebuf is filled in with an appropriate error message.
314 Here's a snippet of code that shows how to use AirpcapGetDeviceList():
317 gchar Ebuf[AIRPCAP_ERRBUF_SIZE];
318 AirpcapDeviceDescription *Desc, *tDesc;
320 if(AirpcapGetDeviceList(&Desc, Ebuf) == -1)
322 printf("Unable to get the list of devices: %s\n", Ebuf);
326 for(tDesc = Desc; tDesc; tDesc = tDesc->next)
328 printf("%u) %s (%s)\n",
334 AirpcapFreeDeviceList(Desc);
337 gboolean AirpcapGetDeviceList(PAirpcapDeviceDescription *PPAllDevs, gchar * Ebuf);
340 \brief Free a list of devices returned by AirpcapGetDeviceList()
341 \param PAllDevs Head of the list of devices returned by \ref AirpcapGetDeviceList().
343 void AirpcapFreeDeviceList(PAirpcapDeviceDescription PAllDevs);
346 \brief Open an adapter
347 \param DeviceName Name of the device to open. Use \ref AirpcapGetDeviceList() to get the list of devices.
348 \param Ebuf String that will contain error information in case of failure. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
349 \return A PAirpcapHandle handle on success. NULL is returned on failure, in which case Ebuf is filled in with an appropriate error message.
351 PAirpcapHandle AirpcapOpen(gchar * DeviceName, gchar * Ebuf);
354 \brief Close an adapter
355 \param AdapterHandle Handle to the adapter to close.
357 void AirpcapClose(PAirpcapHandle AdapterHandle);
360 \brief Sets the monitor mode for the specified adapter
361 \param AdapterHandle Handle to the adapter.
362 \param MonitorModeEnabled If TRUE, the adapter will be put in monitor mode. If FALSE, the adapter will be configured
363 for normal operation.
364 \return TRUE on success.
366 When monitor mode is on, the adapter captures all the packets transmitted on the channel. This includes:
371 - control and management packets
373 When monitor mode is off, the adapter has a filter on unicast packets to capture only the packets whose MAC
374 destination address equals to the adapter's address. This means the following frames will be received:
376 - unicast packets with the address of the adapter
379 - beacons and probe requests
381 The main reason to turn monitor mode off is that, when not in monitor mode, the adapter will acknowledge the
382 data frames sent to its address. This is useful when the adapter needs to interact with other devices on the
383 802.11 network, bacause handling the ACKs in software is too slow.
385 \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
386 configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
387 every time you open the adapter.
389 gboolean AirpcapSetMonitorMode(PAirpcapHandle AdapterHandle, gboolean MonitorModeEnabled);
392 \brief Returns TRUE if the specified adapter is in monitor mode.
393 \param AdapterHandle Handle to the adapter.
394 \param PMonitorModeEnabled User-provided variable that will be set to true if the adapter is in monitor mode.
395 \return TRUE if the operation is successful. FALSE otherwise.
397 \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
398 configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
399 every time you open the adapter.
401 gboolean AirpcapGetMonitorMode(PAirpcapHandle AdapterHandle, gboolean * PMonitorModeEnabled);
404 \brief Set the link type of an adapter
405 \param AdapterHandle Handle to the adapter.
406 \param NewLinkType the "link type", i.e. the format of the frames that will be received from the adapter.
407 \return TRUE on success.
409 the "link type" determines how the driver will encode the packets captured from the network.
410 Aircap supports two link types:
411 - \ref AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
412 power information. Look at the Capture_no_radio example application in the developer's pack
413 for a reference on how to decode 802.11 frames with this link type.
414 - \ref AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
415 that contains power and channel information. More information about the radiotap header can be found in the
416 \ref radiotap section. Moreover, the "Capture_radio" example application in
417 the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
418 - \ref AIRPCAP_LT_802_11_PLUS_PPI, to capture 802.11 frames (including control frames) with a Per Packet Information (PPI)
419 header that contains per-packet meta information like channel and power information. More details on the PPI header can
420 be founf in the PPI online documentation (TODO).
422 gboolean AirpcapSetLinkType(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
425 \brief Get the link type of the specified adapter
426 \param AdapterHandle Handle to the adapter.
427 \param PLinkType Pointer to a caller allocated AirpcapLinkType variable that will contain the link type of the adapter.
428 \return TRUE on success.
430 the "link type" determines how the driver will encode the packets captured from the network.
431 Aircap supports two link types:
432 - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
433 power information. Look at the Capture_no_radio example application in the developer's pack
434 for a reference on how to decode 802.11 frames with this link type.
435 - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
436 that contains power and channel information. More information about the radiotap header can be found int the
437 \ref radiotap section. Moreover, the "Capture_radio" example application in
438 the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
440 gboolean AirpcapGetLinkType(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
443 \brief Configures the adapter on whether to include the MAC Frame Check Sequence in the captured packets.
444 \param AdapterHandle Handle to the adapter.
445 \param IsFcsPresent TRUE if the packets should include the FCS. FALSE otherwise
446 \return TRUE on success.
448 In the default configuration, the adapter includes the FCS in the captured packets. The MAC Frame Check Sequence
449 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
451 When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
452 that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
453 when FCS inclusion is off.
455 gboolean AirpcapSetFcsPresence(PAirpcapHandle AdapterHandle, gboolean IsFcsPresent);
458 \brief Returns TRUE if the specified adapter includes the MAC Frame Check Sequence in the captured packets
459 \param AdapterHandle Handle to the adapter.
460 \param PIsFcsPresent User-provided variable that will be set to true if the adapter is including the FCS.
461 \return TRUE if the operation is successful. FALSE otherwise.
463 In the default configuration, the adatper has FCS inclusion turned on. The MAC Frame Check Sequence is 4 bytes
464 and is located at the end of the 802.11 packet, with both AIRPCAP_LT_802_11 and AIRPCAP_LT_802_11_PLUS_RADIO
466 When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
467 that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
468 when FCS inclusion is off.
470 gboolean AirpcapGetFcsPresence(PAirpcapHandle AdapterHandle, gboolean * PIsFcsPresent);
473 \brief Configures the adapter to accept or drop frames with an incorrect Frame Check sequence (FCS).
474 \param AdapterHandle Handle to the adapter.
475 \param ValidationType The type of validation the driver will perform. See the documentation of \ref AirpcapValidationType for details.
476 \return TRUE on success.
478 \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
480 gboolean AirpcapSetFcsValidation(PAirpcapHandle AdapterHandle, AirpcapValidationType ValidationType);
483 \brief Checks if the specified adapter is configured to capture frames with incorrect an incorrect Frame Check Sequence (FCS).
484 \param AdapterHandle Handle to the adapter.
485 \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.
486 \return TRUE if the operation is succesful. FALSE otherwise.
488 \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
490 gboolean AirpcapGetFcsValidation(PAirpcapHandle AdapterHandle, PAirpcapValidationType ValidationType);
493 \brief Set the list of decryption keys that the driver is going to use with the specified device.
494 \param AdapterHandle Handle an open adapter instance.
495 \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
496 \return TRUE if the operation is successful. FALSE otherwise.
498 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
499 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
502 This function allows to set the <b>adapter-specific</b> set of keys. These keys will be used by the specified adapter only,
503 and will not be used by other airpcap devices besides the specified one.
505 At this time, the only supported decryption method is WEP.
507 The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
508 correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
510 \note: when you change the set of keys from an open capture instance, the change will be
511 immediately reflected on all the other capture instances.
513 gboolean AirpcapSetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
516 \brief Returns the list of decryption keys in the driver that are currently associated with the specified device
517 \param AdapterHandle Handle to an open adapter instance.
518 \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
519 \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
520 \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
521 \return TRUE if the operation is succesful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
522 If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
523 needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
524 KeysCollectionSize will be zero.
526 This function returns the <b>adapter-specific</b> set of keys. These keys are used by the specified adapter only,
527 and not by other airpcap devices besides the specified one.
529 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
530 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
532 The driver supports, for every device, multiple keys at the same time.
534 The configured decryption keys are device-specific, therefore AirpcapGetDeviceKeys() will return a different set of keys
535 when called on different devices.
537 At this time, the only supported decryption method is WEP.
539 gboolean AirpcapGetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
542 \brief Set the global list of decryption keys that the driver is going to use with all the devices.
543 \param AdapterHandle Handle an open adapter instance.
544 \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
545 \return TRUE if the operation is successful. FALSE otherwise.
547 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
548 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
551 This function allows to set the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
554 At this time, the only supported decryption method is WEP.
556 The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
557 correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
559 \note: when you change the set of keys from an open capture instance, the change will be
560 immediately reflected on all the other capture instances.
562 gboolean AirpcapSetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
565 \brief Returns the global list of decryption keys in the driver that are associated with all the devices.
566 \param AdapterHandle Handle to an open adapter instance.
567 \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
568 \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
569 \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
570 \return TRUE if the operation is succesful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
571 If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
572 needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
573 KeysCollectionSize will be zero.
575 This function returns the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
578 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
579 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
582 At this time, the only supported decryption method is WEP.
584 gboolean AirpcapGetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
587 \brief Turns on or off the decryption of the incoming frames with the <b>adapter-specific</b> keys.
588 \param AdapterHandle Handle to the adapter.
589 \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
590 \return TRUE on success.
592 The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
593 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
595 gboolean AirpcapSetDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
598 \brief Tells if this open instance is configured to perform the decryption of the incoming frames with the <b>adapter-specific</b> keys.
599 \param AdapterHandle Handle to the adapter.
600 \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
601 \return TRUE if the operation is succesful. FALSE otherwise.
603 The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
604 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
606 gboolean AirpcapGetDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
609 \brief Turns on or off the decryption of the incoming frames with the <b>global driver</b> set of keys.
610 \param AdapterHandle Handle to the adapter.
611 \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
612 \return TRUE on success.
614 The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
615 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
617 gboolean AirpcapSetDriverDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
620 \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.
621 \param AdapterHandle Handle to the adapter.
622 \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
623 \return TRUE if the operation is succesful. FALSE otherwise.
625 The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
626 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
628 gboolean AirpcapGetDriverDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
631 \brief Set the radio channel of a device
632 \param AdapterHandle Handle to the adapter.
633 \param Channel the new channel to set.
634 \return TRUE on success.
636 The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
638 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
639 immediately reflected on all the other capture instances.
641 gboolean AirpcapSetDeviceChannel(PAirpcapHandle AdapterHandle, guint Channel);
644 \brief Get the radio channel of a device
645 \param AdapterHandle Handle to the adapter.
646 \param PChannel Pointer to a user-supplied variable into which the function will copy the currently configured radio channel.
647 \return TRUE on success.
649 The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
651 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
652 immediately reflected on all the other capture instances.
654 gboolean AirpcapGetDeviceChannel(PAirpcapHandle AdapterHandle, guint * PChannel);
657 \brief Set the size of the kernel packet buffer for this adapter
658 \param AdapterHandle Handle to the adapter.
659 \param BufferSize New size, in bytes.
660 \return TRUE on success.
662 Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
663 This function can be used to change the size of this buffer, and can be called at any time.
664 A bigger kernel buffer size decreases the risk of dropping packets during network bursts or when the
665 application is busy, at the cost of higher kernel memory usage.
667 \note don't use this function unless you know what you are doing. Due to caching issues and bigger non-paged
668 memory consumption, bigger buffer sizes can decrease the capture performace instead of improving it.
670 gboolean AirpcapSetKernelBuffer(PAirpcapHandle AdapterHandle, guint BufferSize);
673 \brief Get the size of the kernel packet buffer for this adapter
674 \param AdapterHandle Handle to the adapter.
675 \param PSizeBytes User-allocated variable that will be filled with the size of the kernel buffer.
676 \return TRUE on success.
678 Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
679 This function can be used to get the size of this buffer.
681 gboolean AirpcapGetKernelBufferSize(PAirpcapHandle AdapterHandle, guint * PSizeBytes);
684 \brief Saves the configuration of the specified adapter in the registry, so that it becomes the default for this adapter.
685 \param AdapterHandle Handle to the adapter.
686 \return TRUE on success. FALSE on failure.
688 Almost all the AirPcap calls that modify the configuration (\ref AirpcapSetLinkType(), \ref AirpcapSetFcsPresence(),
689 \ref AirpcapSetFcsValidation(), \ref AirpcapSetKernelBuffer(), \ref AirpcapSetMinToCopy())
690 affect only the referenced AirPcap open instance. This means that if you do another \ref AirpcapOpen() on the same
691 adapter, the configuration changes will not be remembered, and the new adapter handle will have default configuration
694 Exceptions to this rule are the \ref AirpcapSetDeviceChannel() and \ref AirpcapSetDeviceKeys() functions: a channel change is
695 reflected on all the open instances, and remembered until the next call to \ref AirpcapSetDeviceChannel(), until the adapter
696 is unplugged, or until the machine is powered off. Same thing for the configuration of the WEP keys.
698 AirpcapStoreCurConfigAsAdapterDefault() stores the configuration of the give open instance as the default for the adapter:
699 all the instances opened in the future will have the same configuration that this adapter currently has.
700 The configuration is stored in the registry, therefore it is remembered even when the adapter is unplugged or the
701 machine is turned off. However, an adapter doesn't bring its configuration with it from machine to machine.
703 the configuration information saved in the registry includes the following parameters:
710 - Encryption Enabled/Disabled state
712 The configuration is adapter-specific. This means that changing the configuration of an adapter
713 doesn't modify the one of the other adapters that are currently used or that will be used in the future.
715 \note AirpcapStoreCurConfigAsAdapterDefault() must have exclusive access to the adapter -- it
716 will fail if more than one AirPcap handle is opened at the same time for this adapter.
717 AirpcapStoreCurConfigAsAdapterDefault() needs administrator privileges. It will fail if the calling user
718 is not a local machine administrator.
720 gboolean AirpcapStoreCurConfigAsAdapterDefault(PAirpcapHandle AdapterHandle);
723 \brief Set the BPF kernel filter for an adapter
724 \param AdapterHandle Handle to the adapter.
725 \param Instructions pointer to the first BPF instruction in the array. Corresponds to the bf_insns
726 in a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
727 \param Len Number of instructions in the array pointed by the previous field. Corresponds to the bf_len in
728 a a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
729 \return TRUE on success.
731 The AirPcap driver is able to perform kernel-level filtering using the standard BPF pseudo-machine format. You can read
732 the WinPcap documentation at http://www.winpcap.org/devel.htm for more details on the BPF filtering mechaism.
734 A filter can be automatically created by using the pcap_compile() function of the WinPcap API. This function
735 converts a human readable text expression with the tcpdump/libpcap syntax into a BPF program.
736 If your program doesn't link wpcap, but you need to generate the code for a particular filter, you can run WinDump
737 with the -d or -dd or -ddd flags to obtain the pseudocode.
740 gboolean AirpcapSetFilter(PAirpcapHandle AdapterHandle, void * Instructions, guint Len);
743 \brief Return the MAC address of an adapter.
744 \param AdapterHandle Handle to the adapter.
745 \param PMacAddress Pointer to a user allocated MAC address.
746 The size of this buffer needs to be at least 6 bytes.
747 \return TRUE on success.
749 gboolean AirpcapGetMacAddress(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
752 \brief Set the mintocopy parameter for an open adapter
753 \param AdapterHandle Handle to the adapter.
754 \param MinToCopy is the mintocopy size in bytes.
755 \return TRUE on success.
757 When the number of bytes in the kernel buffer changes from less than mintocopy bytes to greater than or equal to mintocopy bytes,
758 the read event is signalled (see \ref AirpcapGetReadEvent()). A high value for mintocopy results in poor responsiveness since the
759 driver may signal the application "long" after the arrival of the packet. And a high value results in low CPU loading
760 by minimizing the number of user/kernel context switches.
761 A low MinToCopy results in good responsiveness since the driver will signal the application close to the arrival time of
762 the packet. This has higher CPU loading over the first approach.
764 gboolean AirpcapSetMinToCopy(PAirpcapHandle AdapterHandle, guint MinToCopy);
767 \brief Gets an event that is signaled when that is signalled when packets are available in the kernel buffer (see \ref AirpcapSetMinToCopy()).
768 \param AdapterHandle Handle to the adapter.
769 \param PReadEvent Pointer to a user-supplied handle that in which the read event will be copied.
770 \return TRUE on success.
772 \note the event is signalled when at least mintocopy bytes are present in the kernel buffer (see \ref AirpcapSetMinToCopy()).
773 This event can be used by WaitForSingleObject() and WaitForMultipleObjects() to create blocking behavior when reading
774 packets from one or more adapters (see \ref AirpcapRead()).
776 gboolean AirpcapGetReadEvent(PAirpcapHandle AdapterHandle, void *** PReadEvent);
779 \brief Fills a user-provided buffer with zero or more packets that have been captured on the referenced adapter.
780 \param AdapterHandle Handle to the adapter.
781 \param Buffer pointer to the buffer that will be filled with captured packets.
782 \param BufSize size of the input buffer that will contain the packets, in bytes.
783 \param PReceievedBytes Pointer to a user supplied variable that will receive the number of bytes copied by AirpcapRead.
784 Can be smaller than BufSize.
785 \return TRUE on success.
787 802.11 frames are returned by the driver in buffers. Every 802.11 frame in the buffer is preceded by a \ref AirpcapBpfHeader structure.
788 The suggested way to use an AirPcap adapter is through the pcap API exported by wpcap.dll. If this is not
789 possible, the Capture_radio and Capture_no_radio examples in the AirPcap developer's pack show how to properly decode the
790 packets in the read buffer returned by AirpcapRead().
792 \note this function is NOT blocking. Blocking behavior can be obtained using the event returned
793 by \ref AirpcapGetReadEvent(). See also \ref AirpcapSetMinToCopy().
795 gboolean AirpcapRead(PAirpcapHandle AdapterHandle, guint8 * Buffer, guint BufSize, guint * PReceievedBytes);
798 \brief Transmits a packet.
799 \param AdapterHandle Handle to the adapter.
800 \param TxPacket Pointer to a buffer that contains the packet to be transmitted.
801 \param PacketLen Length of the buffer pointed by the TxPacket argument, in bytes.
802 \return TRUE on success.
804 The packet will be transmitted on the channel the device is currently set. To change the device adapter, use the
805 \ref AirpcapSetDeviceChannel() function.
807 If the linktype of the adapter is AIRPCAP_LT_802_11, the buffer pointed by TxPacket should contain just the 802.11
808 packet, without additional information. The packet will be transmitted at 1Mbps.
810 If the linktype of the adapter is AIRPCAP_LT_802_11_PLUS_RADIO, the buffer pointed by TxPacket should contain a radiotap
811 header followed by the 802.11 packet. AirpcapWrite will use the rate information in the radiotap header when
812 transmitting the packet.
814 gboolean AirpcapWrite(PAirpcapHandle AdapterHandle, gchar * TxPacket, guint32 PacketLen);
817 \brief Get per-adapter WinPcap-compatible capture statistics.
818 \param AdapterHandle Handle to the adapter.
819 \param PStats pointer to a user-allocated AirpcapStats structure that will be filled with statistical information.
820 \return TRUE on success.
822 gboolean AirpcapGetStats(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
825 \brief Get the number of LEDs the referenced adapter has available.
826 \param AdapterHandle Handle to the adapter.
827 \param NumberOfLeds Number of LEDs available on this adapter.
828 \return TRUE on success.
830 gboolean AirpcapGetLedsNumber(PAirpcapHandle AdapterHandle, guint * NumberOfLeds);
833 \brief Turn on one of the adapter's LEDs.
834 \param AdapterHandle Handle to the adapter.
835 \param LedNumber zero-based identifier of the LED to turn on.
836 \return TRUE on success.
838 gboolean AirpcapTurnLedOn(PAirpcapHandle AdapterHandle, guint LedNumber);
841 \brief Turn off one of the adapter's LEDs.
842 \param AdapterHandle Handle to the adapter.
843 \param LedNumber zero-based identifier of the LED to turn off.
844 \return TRUE on success.
846 gboolean AirpcapTurnLedOff(PAirpcapHandle AdapterHandle, guint LedNumber);
849 \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.
850 \param AdapterHandle Handle to the adapter.
851 \param ChannelInfo The new channel information to set.
852 \return TRUE on success.
854 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
855 immediately reflected on all the other capture instances.
857 gboolean AirpcapSetDeviceChannelEx(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo);
860 \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.
861 \param AdapterHandle Handle to the adapter.
862 \param PChannelInfo Pointer to a user-supplied variable into which the function will copy the currently configured channel information.
863 \return TRUE on success.
865 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
866 immediately reflected on all the other capture instances.
868 gboolean AirpcapGetDeviceChannelEx(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo);
871 \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.
873 Every control channel is listed multiple times, one for each different supported extension channel. For example channel 6 (2437MHz) is usually listed three times:
874 - <b>Frequency 2437 Extension +1</b>. Control channel is 6, extension channel is 10.
875 - <b>Frequency 2437 Extension 0</b>. Control channel is 6, no extension channel is used (20MHz channel and legacy mode).
876 - <b>Frequency 2437 Extension -1</b>. Control channel is 6, extension channel is 2.
877 \param AdapterHandle Handle to the adapter.
878 \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
879 \param pNumChannelInfo Number of channels returned in the array.
880 \return TRUE on success.
882 \note The supported channels are not listed in any specific order.
884 gboolean AirpcapGetDeviceSupportedChannels(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo *ppChannelInfo, guint * pNumChannelInfo);
887 \brief Converts a given frequency to the corresponding channel.
889 \param Frequency Frequency of the channel, in MHz.
890 \param PChannel Pointer to a user-supplied variable that will contain the channel number on success.
891 \param PBand Pointer to a user-supplied variable that will contain the band (a or b/g) of the given channel.
892 \return TRUE on success, i.e. the frequency corresponds to a valid a or b/g channel.
894 gboolean AirpcapConvertFrequencyToChannel(guint Frequency, guint * PChannel, PAirpcapChannelBand PBand);
897 \brief Converts a given channel to the corresponding frequency.
899 \param Channel Channel number to be converted.
900 \param PFrequency Pointer to a user-supplied variable that will contain the channel frequency in MHz on success.
901 \return TRUE on success, i.e. the given channel number exists.
903 gboolean AirpcapConvertChannelToFrequency(guint Channel, guint * PFrequency);
908 #endif // __AIRPCAP_DRIVER__
914 #endif // !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_)