sec_vt_header: dissect cont_id + opnum
[wireshark-wip.git] / airpcap.h
bloba55fc5550f9201730b53e75d1015970ee53c9609
1 /*
2 * Copyright (c) 2006-2007 CACE Technologies, Davis (California)
3 * All rights reserved.
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_
25 #ifdef _MSC_VER
26 /* This disables a VS warning for zero-sized arrays. */
27 #pragma warning( disable : 4200)
28 /* This stops VS2005 ranting against stdio. */
29 #pragma warning( disable : 4996)
30 #endif
32 #ifdef HAVE_WINSOCK2_H
33 #include <winsock2.h>
34 #endif
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
41 \mainpage AirPcap interface documentation
43 \section Introduction
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().
55 \b Sections:
57 - \ref airpcapfuncs
58 - \ref airpcapdefs
59 - \ref radiotap
62 /** @defgroup airpcapdefs AirPcap definitions and data structures
63 * @{
66 /*!
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"
72 /*!
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"
80 /*!
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. */
95 #ifdef _WIN32
96 #ifndef __MINGW32__
97 #pragma pack(push)
98 #pragma pack(1)
99 #endif
100 #endif
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 */
115 #ifdef __MINGW32__
116 __attribute__((__packed__))
117 #endif
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 wrong 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 */
164 #ifdef __MINGW32__
165 __attribute__((__packed__))
166 #endif
167 AirpcapMacAddress, *PAirpcapMacAddress;
170 \brief This structure is used to store a collection of WEP keys.
171 Note that the definition of the structure has one key in it
172 (so that this code can be compiled by compilers that don't
173 support zero-length arrays), so be careful to allocate a buffer
174 with the size of the set of keys, as per the following example:
176 \code
177 PAirpcapKeysCollection KeysCollection;
178 guint KeysCollectionSize;
180 KeysCollectionSize = AirpcapKeysCollectionSize(NumKeys);
182 KeysCollection = (PAirpcapKeysCollection)malloc(KeysCollectionSize);
183 if(!KeysCollection)
185 Error
187 \endcode
189 typedef struct _AirpcapKeysCollection
191 guint nKeys; /* < Number of keys in the collection */
192 AirpcapKey Keys[1]; /* < Array of nKeys keys. */
193 } AirpcapKeysCollection, *PAirpcapKeysCollection;
195 #define AirpcapKeysCollectionSize(nKeys) \
196 ((sizeof(AirpcapKeysCollection) - sizeof(AirpcapKey)) + ((nKeys) * sizeof(AirpcapKey)))
197 #define AirpcapKeysCollectionSizeToKeyCount(size) \
198 (guint)(((size) - AirpcapKeysCollectionSize(0))/sizeof(AirpcapKey))
201 \brief Packet header.
203 This structure defines the BPF that precedes every packet delivered to the application.
205 typedef struct _AirpcapBpfHeader
207 guint TsSec; /* < Timestamp associated with the captured packet. SECONDS. */
208 guint TsUsec; /* < Timestamp associated with the captured packet. MICROSECONDS. */
209 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. */
210 guint Originallen; /* < Original length of packet */
211 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. */
213 #ifdef __MINGW32__
214 __attribute__((__packed__))
215 #endif
216 AirpcapBpfHeader, *PAirpcapBpfHeader;
218 /* Helper macros to extract packets coming from the driver. Rounds up to the next even multiple of AIRPCAP_ALIGNMENT. */
219 #define AIRPCAP_ALIGNMENT sizeof(int)
220 #define AIRPCAP_WORDALIGN(x) (((x)+(AIRPCAP_ALIGNMENT-1))&~(AIRPCAP_ALIGNMENT-1))
222 #ifdef _WIN32
223 #ifndef __MINGW32__
224 #pragma pack(pop)
225 #endif
226 #endif
228 #define AIRPCAP_ERRBUF_SIZE 512 /* < Size of the error buffer, in bytes */
230 #ifndef __AIRPCAP_DRIVER__
233 \brief Link type.
234 AirPcap supports two kind of 802.11 linktypes: plain 802.11 and radiotap.
236 #undef _AirpcapLinkType
237 typedef enum _AirpcapLinkType
239 AIRPCAP_LT_802_11 = 1, /* < plain 802.11 linktype. Every packet in the buffer contains the raw 802.11 frame, including MAC FCS. */
240 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. */
241 AIRPCAP_LT_UNKNOWN = 3, /* < Unknown linktype. You should see it only in case of error. */
242 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. */
243 }AirpcapLinkType, *PAirpcapLinkType;
245 #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
246 #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
248 \brief Adapter handle.
250 typedef struct _AirpcapHandle AirpcapHandle, *PAirpcapHandle;
251 #endif
254 \brief Capture statistics.
255 Returned by \ref AirpcapGetStats();
257 typedef struct _AirpcapStats
259 guint Recvs; /* < Number of packets that the driver received by the adapter */
260 /* < from the beginning of the current capture. This value includes the packets */
261 /* < dropped because of buffer full. */
262 guint Drops; /* < number of packets that the driver dropped from the beginning of a capture. */
263 /* < A packet is lost when the the buffer of the driver is full. */
264 guint IfDrops; /* < Packets dropped by the card before going to the USB bus. */
265 /* < Not supported at the moment. */
266 guint Capt; /* < number of packets that pass the BPF filter, find place in the kernel buffer and */
267 /* < therefore reach the application. */
268 }AirpcapStats, *PAirpcapStats;
271 \brief Channel information.
272 Used by \ref AirpcapSetDeviceChannelEx(), \ref AirpcapGetDeviceChannelEx(), \ref AirpcapGetDeviceSupportedChannels()
274 typedef struct _AirpcapChannelInfo
276 guint Frequency; /* < Channel frequency, in MHz. */
278 \brief 802.11n specific. Offset of the extension channel in case of 40MHz channels.
280 Possible values are -1, 0 +1:
281 - -1 means that the extension channel should be below the control channel (e.g. Control = 5 and Extension = 1)
282 - 0 means that no extension channel should be used (20MHz channels or legacy mode)
283 - +1 means that the extension channel should be above the control channel (e.g. Control = 1 and Extension = 5)
285 In case of 802.11a/b/g channels (802.11n legacy mode), this field should be set to 0.
287 gchar ExtChannel;
288 guint8 Reserved[3]; /* < Reserved. It should be set to {0,0,0}. */
290 AirpcapChannelInfo, *PAirpcapChannelInfo;
293 /*@}*/
295 /** @defgroup airpcapfuncs AirPcap functions
296 * @{
300 \brief Return a string with the API version
301 \param VersionMajor Pointer to a variable that will be filled with the major version number.
302 \param VersionMinor Pointer to a variable that will be filled with the minor version number.
303 \param VersionRev Pointer to a variable that will be filled with the revision number.
304 \param VersionBuild Pointer to a variable that will be filled with the build number.
306 void AirpcapGetVersion(guint * VersionMajor, guint * VersionMinor, guint * VersionRev, guint * VersionBuild);
309 \brief Return the last error related to the specified handle
310 \param AdapterHandle Handle to an open adapter.
311 \return The string with the last error.
313 gchar * AirpcapGetLastError(PAirpcapHandle AdapterHandle);
316 \brief Return the list of available devices
317 \param PPAllDevs Address to a caller allocated pointer. On success this pointer will receive the head of a list of available devices.
318 \param Ebuf String that will contain error information if FALSE is returned. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
319 \return TRUE on success. FALSE is returned on failure, in which case Ebuf is filled in with an appropriate error message.
321 Here's a snippet of code that shows how to use AirpcapGetDeviceList():
323 \code
324 gchar Ebuf[AIRPCAP_ERRBUF_SIZE];
325 AirpcapDeviceDescription *Desc, *tDesc;
327 if(AirpcapGetDeviceList(&Desc, Ebuf) == -1)
329 printf("Unable to get the list of devices: %s\n", Ebuf);
330 return -1;
333 for(tDesc = Desc; tDesc; tDesc = tDesc->next)
335 printf("%u) %s (%s)\n",
336 ++i,
337 tDesc->Name,
338 tDesc->Description);
341 AirpcapFreeDeviceList(Desc);
342 \endcode
344 gboolean AirpcapGetDeviceList(PAirpcapDeviceDescription *PPAllDevs, gchar * Ebuf);
347 \brief Free a list of devices returned by AirpcapGetDeviceList()
348 \param PAllDevs Head of the list of devices returned by \ref AirpcapGetDeviceList().
350 void AirpcapFreeDeviceList(PAirpcapDeviceDescription PAllDevs);
353 \brief Open an adapter
354 \param DeviceName Name of the device to open. Use \ref AirpcapGetDeviceList() to get the list of devices.
355 \param Ebuf String that will contain error information in case of failure. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes.
356 \return A PAirpcapHandle handle on success. NULL is returned on failure, in which case Ebuf is filled in with an appropriate error message.
358 PAirpcapHandle AirpcapOpen(gchar * DeviceName, gchar * Ebuf);
361 \brief Close an adapter
362 \param AdapterHandle Handle to the adapter to close.
364 void AirpcapClose(PAirpcapHandle AdapterHandle);
367 \brief Sets the monitor mode for the specified adapter
368 \param AdapterHandle Handle to the adapter.
369 \param MonitorModeEnabled If TRUE, the adapter will be put in monitor mode. If FALSE, the adapter will be configured
370 for normal operation.
371 \return TRUE on success.
373 When monitor mode is on, the adapter captures all the packets transmitted on the channel. This includes:
375 - unicast packets
376 - multicast packets
377 - broadcast packets
378 - control and management packets
380 When monitor mode is off, the adapter has a filter on unicast packets to capture only the packets whose MAC
381 destination address equals to the adapter's address. This means the following frames will be received:
383 - unicast packets with the address of the adapter
384 - multicast packets
385 - broadcast packets
386 - beacons and probe requests
388 The main reason to turn monitor mode off is that, when not in monitor mode, the adapter will acknowledge the
389 data frames sent to its address. This is useful when the adapter needs to interact with other devices on the
390 802.11 network, because handling the ACKs in software is too slow.
392 \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
393 configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
394 every time you open the adapter.
396 gboolean AirpcapSetMonitorMode(PAirpcapHandle AdapterHandle, gboolean MonitorModeEnabled);
399 \brief Returns TRUE if the specified adapter is in monitor mode.
400 \param AdapterHandle Handle to the adapter.
401 \param PMonitorModeEnabled User-provided variable that will be set to true if the adapter is in monitor mode.
402 \return TRUE if the operation is successful. FALSE otherwise.
404 \note When an adapter is plugged into the system, it's always configured with monitor mode ON. The monitor mode
405 configuration is not stored persistently, so if you want to turn monitor mode off, you will need to do it
406 every time you open the adapter.
408 gboolean AirpcapGetMonitorMode(PAirpcapHandle AdapterHandle, gboolean * PMonitorModeEnabled);
411 \brief Set the link type of an adapter
412 \param AdapterHandle Handle to the adapter.
413 \param NewLinkType the "link type", i.e. the format of the frames that will be received from the adapter.
414 \return TRUE on success.
416 the "link type" determines how the driver will encode the packets captured from the network.
417 Aircap supports two link types:
418 - \ref AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
419 power information. Look at the Capture_no_radio example application in the developer's pack
420 for a reference on how to decode 802.11 frames with this link type.
421 - \ref AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
422 that contains power and channel information. More information about the radiotap header can be found in the
423 \ref radiotap section. Moreover, the "Capture_radio" example application in
424 the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
425 - \ref AIRPCAP_LT_802_11_PLUS_PPI, to capture 802.11 frames (including control frames) with a Per Packet Information (PPI)
426 header that contains per-packet meta information like channel and power information. More details on the PPI header can
427 be found in the PPI online documentation (TODO).
429 gboolean AirpcapSetLinkType(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
432 \brief Get the link type of the specified adapter
433 \param AdapterHandle Handle to the adapter.
434 \param PLinkType Pointer to a caller allocated AirpcapLinkType variable that will contain the link type of the adapter.
435 \return TRUE on success.
437 the "link type" determines how the driver will encode the packets captured from the network.
438 Aircap supports two link types:
439 - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any
440 power information. Look at the Capture_no_radio example application in the developer's pack
441 for a reference on how to decode 802.11 frames with this link type.
442 - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header
443 that contains power and channel information. More information about the radiotap header can be found int the
444 \ref radiotap section. Moreover, the "Capture_radio" example application in
445 the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers.
447 gboolean AirpcapGetLinkType(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
450 \brief Configures the adapter on whether to include the MAC Frame Check Sequence in the captured packets.
451 \param AdapterHandle Handle to the adapter.
452 \param IsFcsPresent TRUE if the packets should include the FCS. FALSE otherwise
453 \return TRUE on success.
455 In the default configuration, the adapter includes the FCS in the captured packets. The MAC Frame Check Sequence
456 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
457 link types.
458 When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
459 that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
460 when FCS inclusion is off.
462 gboolean AirpcapSetFcsPresence(PAirpcapHandle AdapterHandle, gboolean IsFcsPresent);
465 \brief Returns TRUE if the specified adapter includes the MAC Frame Check Sequence in the captured packets
466 \param AdapterHandle Handle to the adapter.
467 \param PIsFcsPresent User-provided variable that will be set to true if the adapter is including the FCS.
468 \return TRUE if the operation is successful. FALSE otherwise.
470 In the default configuration, the adapter has FCS inclusion turned on. The MAC Frame Check Sequence is 4 bytes
471 and is located at the end of the 802.11 packet, with both AIRPCAP_LT_802_11 and AIRPCAP_LT_802_11_PLUS_RADIO
472 link types.
473 When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header
474 that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present
475 when FCS inclusion is off.
477 gboolean AirpcapGetFcsPresence(PAirpcapHandle AdapterHandle, gboolean * PIsFcsPresent);
480 \brief Configures the adapter to accept or drop frames with an incorrect Frame Check sequence (FCS).
481 \param AdapterHandle Handle to the adapter.
482 \param ValidationType The type of validation the driver will perform. See the documentation of \ref AirpcapValidationType for details.
483 \return TRUE on success.
485 \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
487 gboolean AirpcapSetFcsValidation(PAirpcapHandle AdapterHandle, AirpcapValidationType ValidationType);
490 \brief Checks if the specified adapter is configured to capture frames with incorrect an incorrect Frame Check Sequence (FCS).
491 \param AdapterHandle Handle to the adapter.
492 \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.
493 \return TRUE if the operation is successful. FALSE otherwise.
495 \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode.
497 gboolean AirpcapGetFcsValidation(PAirpcapHandle AdapterHandle, PAirpcapValidationType ValidationType);
500 \brief Set the list of decryption keys that the driver is going to use with the specified device.
501 \param AdapterHandle Handle an open adapter instance.
502 \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
503 \return TRUE if the operation is successful. FALSE otherwise.
505 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
506 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
507 to the application.
509 This function allows to set the <b>adapter-specific</b> set of keys. These keys will be used by the specified adapter only,
510 and will not be used by other airpcap devices besides the specified one.
512 At this time, the only supported decryption method is WEP.
514 The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
515 correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
517 \note: when you change the set of keys from an open capture instance, the change will be
518 immediately reflected on all the other capture instances.
520 gboolean AirpcapSetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
523 \brief Returns the list of decryption keys in the driver that are currently associated with the specified device
524 \param AdapterHandle Handle to an open adapter instance.
525 \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
526 \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
527 \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
528 \return TRUE if the operation is successful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
529 If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
530 needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
531 KeysCollectionSize will be zero.
533 This function returns the <b>adapter-specific</b> set of keys. These keys are used by the specified adapter only,
534 and not by other airpcap devices besides the specified one.
536 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
537 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
538 to the application.
539 The driver supports, for every device, multiple keys at the same time.
541 The configured decryption keys are device-specific, therefore AirpcapGetDeviceKeys() will return a different set of keys
542 when called on different devices.
544 At this time, the only supported decryption method is WEP.
546 gboolean AirpcapGetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
549 \brief Set the global list of decryption keys that the driver is going to use with all the devices.
550 \param AdapterHandle Handle an open adapter instance.
551 \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver.
552 \return TRUE if the operation is successful. FALSE otherwise.
554 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
555 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
556 to the application.
558 This function allows to set the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
559 the machine.
561 At this time, the only supported decryption method is WEP.
563 The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is
564 correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance.
566 \note: when you change the set of keys from an open capture instance, the change will be
567 immediately reflected on all the other capture instances.
569 gboolean AirpcapSetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
572 \brief Returns the global list of decryption keys in the driver that are associated with all the devices.
573 \param AdapterHandle Handle to an open adapter instance.
574 \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys.
575 \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes.
576 \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes.
577 \return TRUE if the operation is successful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero.
578 If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the
579 needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and
580 KeysCollectionSize will be zero.
582 This function returns the <b>global driver</b> set of keys. These keys will be used by all the adapters plugged in
583 the machine.
585 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
586 keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames
587 to the application.
589 At this time, the only supported decryption method is WEP.
591 gboolean AirpcapGetDriverKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
594 \brief Turns on or off the decryption of the incoming frames with the <b>adapter-specific</b> keys.
595 \param AdapterHandle Handle to the adapter.
596 \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
597 \return TRUE on success.
599 The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
600 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
602 gboolean AirpcapSetDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
605 \brief Tells if this open instance is configured to perform the decryption of the incoming frames with the <b>adapter-specific</b> keys.
606 \param AdapterHandle Handle to the adapter.
607 \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
608 \return TRUE if the operation is successful. FALSE otherwise.
610 The adapter-specific decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function.
611 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
613 gboolean AirpcapGetDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
616 \brief Turns on or off the decryption of the incoming frames with the <b>global driver</b> set of keys.
617 \param AdapterHandle Handle to the adapter.
618 \param Enable Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF
619 \return TRUE on success.
621 The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
622 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
624 gboolean AirpcapSetDriverDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
627 \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.
628 \param AdapterHandle Handle to the adapter.
629 \param PEnable Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details.
630 \return TRUE if the operation is successful. FALSE otherwise.
632 The global decryption keys can be configured with the \ref AirpcapSetDriverKeys() function.
633 \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON.
635 gboolean AirpcapGetDriverDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
638 \brief Set the radio channel of a device
639 \param AdapterHandle Handle to the adapter.
640 \param Channel the new channel to set.
641 \return TRUE on success.
643 The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
645 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
646 immediately reflected on all the other capture instances.
648 gboolean AirpcapSetDeviceChannel(PAirpcapHandle AdapterHandle, guint Channel);
651 \brief Get the radio channel of a device
652 \param AdapterHandle Handle to the adapter.
653 \param PChannel Pointer to a user-supplied variable into which the function will copy the currently configured radio channel.
654 \return TRUE on success.
656 The list of available channels can be retrieved with \ref AirpcapGetDeviceSupportedChannels(). The default channel setting is 6.
658 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
659 immediately reflected on all the other capture instances.
661 gboolean AirpcapGetDeviceChannel(PAirpcapHandle AdapterHandle, guint * PChannel);
664 \brief Set the size of the kernel packet buffer for this adapter
665 \param AdapterHandle Handle to the adapter.
666 \param BufferSize New size, in bytes.
667 \return TRUE on success.
669 Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
670 This function can be used to change the size of this buffer, and can be called at any time.
671 A bigger kernel buffer size decreases the risk of dropping packets during network bursts or when the
672 application is busy, at the cost of higher kernel memory usage.
674 \note don't use this function unless you know what you are doing. Due to caching issues and bigger non-paged
675 memory consumption, bigger buffer sizes can decrease the capture performance instead of improving it.
677 gboolean AirpcapSetKernelBuffer(PAirpcapHandle AdapterHandle, guint BufferSize);
680 \brief Get the size of the kernel packet buffer for this adapter
681 \param AdapterHandle Handle to the adapter.
682 \param PSizeBytes User-allocated variable that will be filled with the size of the kernel buffer.
683 \return TRUE on success.
685 Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte.
686 This function can be used to get the size of this buffer.
688 gboolean AirpcapGetKernelBufferSize(PAirpcapHandle AdapterHandle, guint * PSizeBytes);
691 \brief Saves the configuration of the specified adapter in the registry, so that it becomes the default for this adapter.
692 \param AdapterHandle Handle to the adapter.
693 \return TRUE on success. FALSE on failure.
695 Almost all the AirPcap calls that modify the configuration (\ref AirpcapSetLinkType(), \ref AirpcapSetFcsPresence(),
696 \ref AirpcapSetFcsValidation(), \ref AirpcapSetKernelBuffer(), \ref AirpcapSetMinToCopy())
697 affect only the referenced AirPcap open instance. This means that if you do another \ref AirpcapOpen() on the same
698 adapter, the configuration changes will not be remembered, and the new adapter handle will have default configuration
699 settings.
701 Exceptions to this rule are the \ref AirpcapSetDeviceChannel() and \ref AirpcapSetDeviceKeys() functions: a channel change is
702 reflected on all the open instances, and remembered until the next call to \ref AirpcapSetDeviceChannel(), until the adapter
703 is unplugged, or until the machine is powered off. Same thing for the configuration of the WEP keys.
705 AirpcapStoreCurConfigAsAdapterDefault() stores the configuration of the give open instance as the default for the adapter:
706 all the instances opened in the future will have the same configuration that this adapter currently has.
707 The configuration is stored in the registry, therefore it is remembered even when the adapter is unplugged or the
708 machine is turned off. However, an adapter doesn't bring its configuration with it from machine to machine.
710 the configuration information saved in the registry includes the following parameters:
711 - channel
712 - kernel buffer size
713 - mintocopy
714 - link type
715 - CRC presence
716 - Encryption keys
717 - Encryption Enabled/Disabled state
719 The configuration is adapter-specific. This means that changing the configuration of an adapter
720 doesn't modify the one of the other adapters that are currently used or that will be used in the future.
722 \note AirpcapStoreCurConfigAsAdapterDefault() must have exclusive access to the adapter -- it
723 will fail if more than one AirPcap handle is opened at the same time for this adapter.
724 AirpcapStoreCurConfigAsAdapterDefault() needs administrator privileges. It will fail if the calling user
725 is not a local machine administrator.
727 gboolean AirpcapStoreCurConfigAsAdapterDefault(PAirpcapHandle AdapterHandle);
730 \brief Set the BPF kernel filter for an adapter
731 \param AdapterHandle Handle to the adapter.
732 \param Instructions pointer to the first BPF instruction in the array. Corresponds to the bf_insns
733 in a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
734 \param Len Number of instructions in the array pointed by the previous field. Corresponds to the bf_len in
735 a a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm).
736 \return TRUE on success.
738 The AirPcap driver is able to perform kernel-level filtering using the standard BPF pseudo-machine format. You can read
739 the WinPcap documentation at http://www.winpcap.org/devel.htm for more details on the BPF filtering mechanism.
741 A filter can be automatically created by using the pcap_compile() function of the WinPcap API. This function
742 converts a human readable text expression with the tcpdump/libpcap syntax into a BPF program.
743 If your program doesn't link wpcap, but you need to generate the code for a particular filter, you can run WinDump
744 with the -d or -dd or -ddd flags to obtain the pseudocode.
747 gboolean AirpcapSetFilter(PAirpcapHandle AdapterHandle, void * Instructions, guint Len);
750 \brief Return the MAC address of an adapter.
751 \param AdapterHandle Handle to the adapter.
752 \param PMacAddress Pointer to a user allocated MAC address.
753 The size of this buffer needs to be at least 6 bytes.
754 \return TRUE on success.
756 gboolean AirpcapGetMacAddress(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
759 \brief Set the mintocopy parameter for an open adapter
760 \param AdapterHandle Handle to the adapter.
761 \param MinToCopy is the mintocopy size in bytes.
762 \return TRUE on success.
764 When the number of bytes in the kernel buffer changes from less than mintocopy bytes to greater than or equal to mintocopy bytes,
765 the read event is signalled (see \ref AirpcapGetReadEvent()). A high value for mintocopy results in poor responsiveness since the
766 driver may signal the application "long" after the arrival of the packet. And a high value results in low CPU loading
767 by minimizing the number of user/kernel context switches.
768 A low MinToCopy results in good responsiveness since the driver will signal the application close to the arrival time of
769 the packet. This has higher CPU loading over the first approach.
771 gboolean AirpcapSetMinToCopy(PAirpcapHandle AdapterHandle, guint MinToCopy);
774 \brief Gets an event that is signaled when that is signalled when packets are available in the kernel buffer (see \ref AirpcapSetMinToCopy()).
775 \param AdapterHandle Handle to the adapter.
776 \param PReadEvent Pointer to a user-supplied handle that in which the read event will be copied.
777 \return TRUE on success.
779 \note the event is signalled when at least mintocopy bytes are present in the kernel buffer (see \ref AirpcapSetMinToCopy()).
780 This event can be used by WaitForSingleObject() and WaitForMultipleObjects() to create blocking behavior when reading
781 packets from one or more adapters (see \ref AirpcapRead()).
783 gboolean AirpcapGetReadEvent(PAirpcapHandle AdapterHandle, void *** PReadEvent);
786 \brief Fills a user-provided buffer with zero or more packets that have been captured on the referenced adapter.
787 \param AdapterHandle Handle to the adapter.
788 \param Buffer pointer to the buffer that will be filled with captured packets.
789 \param BufSize size of the input buffer that will contain the packets, in bytes.
790 \param PReceievedBytes Pointer to a user supplied variable that will receive the number of bytes copied by AirpcapRead.
791 Can be smaller than BufSize.
792 \return TRUE on success.
794 802.11 frames are returned by the driver in buffers. Every 802.11 frame in the buffer is preceded by a \ref AirpcapBpfHeader structure.
795 The suggested way to use an AirPcap adapter is through the pcap API exported by wpcap.dll. If this is not
796 possible, the Capture_radio and Capture_no_radio examples in the AirPcap developer's pack show how to properly decode the
797 packets in the read buffer returned by AirpcapRead().
799 \note this function is NOT blocking. Blocking behavior can be obtained using the event returned
800 by \ref AirpcapGetReadEvent(). See also \ref AirpcapSetMinToCopy().
802 gboolean AirpcapRead(PAirpcapHandle AdapterHandle, guint8 * Buffer, guint BufSize, guint * PReceievedBytes);
805 \brief Transmits a packet.
806 \param AdapterHandle Handle to the adapter.
807 \param TxPacket Pointer to a buffer that contains the packet to be transmitted.
808 \param PacketLen Length of the buffer pointed by the TxPacket argument, in bytes.
809 \return TRUE on success.
811 The packet will be transmitted on the channel the device is currently set. To change the device adapter, use the
812 \ref AirpcapSetDeviceChannel() function.
814 If the linktype of the adapter is AIRPCAP_LT_802_11, the buffer pointed by TxPacket should contain just the 802.11
815 packet, without additional information. The packet will be transmitted at 1Mbps.
817 If the linktype of the adapter is AIRPCAP_LT_802_11_PLUS_RADIO, the buffer pointed by TxPacket should contain a radiotap
818 header followed by the 802.11 packet. AirpcapWrite will use the rate information in the radiotap header when
819 transmitting the packet.
821 gboolean AirpcapWrite(PAirpcapHandle AdapterHandle, gchar * TxPacket, guint32 PacketLen);
824 \brief Get per-adapter WinPcap-compatible capture statistics.
825 \param AdapterHandle Handle to the adapter.
826 \param PStats pointer to a user-allocated AirpcapStats structure that will be filled with statistical information.
827 \return TRUE on success.
829 gboolean AirpcapGetStats(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
832 \brief Get the number of LEDs the referenced adapter has available.
833 \param AdapterHandle Handle to the adapter.
834 \param NumberOfLeds Number of LEDs available on this adapter.
835 \return TRUE on success.
837 gboolean AirpcapGetLedsNumber(PAirpcapHandle AdapterHandle, guint * NumberOfLeds);
840 \brief Turn on one of the adapter's LEDs.
841 \param AdapterHandle Handle to the adapter.
842 \param LedNumber zero-based identifier of the LED to turn on.
843 \return TRUE on success.
845 gboolean AirpcapTurnLedOn(PAirpcapHandle AdapterHandle, guint LedNumber);
848 \brief Turn off one of the adapter's LEDs.
849 \param AdapterHandle Handle to the adapter.
850 \param LedNumber zero-based identifier of the LED to turn off.
851 \return TRUE on success.
853 gboolean AirpcapTurnLedOff(PAirpcapHandle AdapterHandle, guint LedNumber);
856 \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.
857 \param AdapterHandle Handle to the adapter.
858 \param ChannelInfo The new channel information to set.
859 \return TRUE on success.
861 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
862 immediately reflected on all the other capture instances.
864 gboolean AirpcapSetDeviceChannelEx(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo);
867 \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.
868 \param AdapterHandle Handle to the adapter.
869 \param PChannelInfo Pointer to a user-supplied variable into which the function will copy the currently configured channel information.
870 \return TRUE on success.
872 \note this is a device-related function: when you change the channel from an open capture instance, the change will be
873 immediately reflected on all the other capture instances.
875 gboolean AirpcapGetDeviceChannelEx(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo);
878 \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.
880 Every control channel is listed multiple times, one for each different supported extension channel. For example channel 6 (2437MHz) is usually listed three times:
881 - <b>Frequency 2437 Extension +1</b>. Control channel is 6, extension channel is 10.
882 - <b>Frequency 2437 Extension 0</b>. Control channel is 6, no extension channel is used (20MHz channel and legacy mode).
883 - <b>Frequency 2437 Extension -1</b>. Control channel is 6, extension channel is 2.
884 \param AdapterHandle Handle to the adapter.
885 \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
886 \param pNumChannelInfo Number of channels returned in the array.
887 \return TRUE on success.
889 \note The supported channels are not listed in any specific order.
891 gboolean AirpcapGetDeviceSupportedChannels(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo *ppChannelInfo, guint * pNumChannelInfo);
894 \brief Converts a given frequency to the corresponding channel.
896 \param Frequency Frequency of the channel, in MHz.
897 \param PChannel Pointer to a user-supplied variable that will contain the channel number on success.
898 \param PBand Pointer to a user-supplied variable that will contain the band (a or b/g) of the given channel.
899 \return TRUE on success, i.e. the frequency corresponds to a valid a or b/g channel.
901 gboolean AirpcapConvertFrequencyToChannel(guint Frequency, guint * PChannel, PAirpcapChannelBand PBand);
904 \brief Converts a given channel to the corresponding frequency.
906 \param Channel Channel number to be converted.
907 \param PFrequency Pointer to a user-supplied variable that will contain the channel frequency in MHz on success.
908 \return TRUE on success, i.e. the given channel number exists.
910 gboolean AirpcapConvertChannelToFrequency(guint Channel, guint * PFrequency);
913 /*@}*/
915 #endif /* __AIRPCAP_DRIVER__ */
917 #ifdef __cplusplus
919 #endif
921 #endif /* !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_) */